INCLUDE(tests.set)
+SET(TEST_REINIT_SALOME "False")
+SALOME_CONFIGURE_FILE(tests.py.in tests.py)
+
SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
-FOREACH(test ${GOOD_TESTS})
- GET_FILENAME_COMPONENT(testname ${test} NAME_WE)
- ADD_TEST(NAME ${testname}
- COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${test})
- SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
-ENDFOREACH()
+IF(GEOM_JOIN_TESTS)
+ ADD_TEST(NAME GEOM_examples COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py tests.py)
+ELSE(GEOM_JOIN_TESTS)
+ FOREACH(test ${GOOD_TESTS})
+ GET_FILENAME_COMPONENT(testname ${test} NAME_WE)
+ ADD_TEST(NAME ${testname}
+ COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${test})
+ SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
+ ENDFOREACH()
+ENDIF(GEOM_JOIN_TESTS)
# install Python scripts
SALOME_INSTALL_SCRIPTS("${EXAMPLES_TESTS}" ${SALOME_INSTALL_DOC}/examples/GEOM)
import salome
gg = salome.ImportComponentGUI("GEOM")
-# Add a section based on quadrangles
-# ----------------------------------
-def section(s, p1, p2=None, p3=None, p4=None):
- if p2==None:
- q = p1
- else:
- q = geompy.MakeQuad4Vertices(p1, p2, p3, p4)
- pass
- s.append(q)
- publish(q, "section")
- return q
-
-
-# find distance between two points
-# -------------------------------
-def Dist(p1,p2):
- c1 = geompy.PointCoordinates(p1)
- c2 = geompy.PointCoordinates(p2)
- return math.sqrt( (c2[0]-c1[0])*(c2[0]-c1[0]) +
- (c2[1]-c1[1])*(c2[1]-c1[1]) +
- (c2[2]-c1[2])*(c2[2]-c1[2]) )
-
-
-# return middle point
-# -------------------------------
-def MiddleVert(p1,p2):
- c1 = geompy.PointCoordinates(p1)
- c2 = geompy.PointCoordinates(p2)
- return geompy.MakeVertex( (c2[0]+c1[0])/2, (c2[1]+c1[1])/2, (c2[2]+c1[2])/2 )
-
-
# Complex section
# result - 16 quads from lines
# pnt - point from path
# vec - direction from path
-def MakeComplexSect(pnt,vec,rmax,rmin,nb):
+def MakeComplexSect(pnt, vec, rmax, rmin, nb, geom_builder):
dang = 1.0/nb/2
- cmax = geompy.MakeCircle(pnt,vec,rmax)
- cmin = geompy.MakeCircle(pnt,vec,rmin)
+ cmax = geom_builder.MakeCircle(pnt,vec,rmax)
+ cmin = geom_builder.MakeCircle(pnt,vec,rmin)
faces = []
for i in range(0,2*nb,2):
- p1 = geompy.MakeVertexOnCurve(cmin,dang*i)
- p2 = geompy.MakeVertexOnCurve(cmax,dang*(i+1))
- p3 = geompy.MakeVertexOnCurve(cmin,dang*(i+2))
- f = geompy.MakeQuad4Vertices(pnt,p1,p2,p3)
+ p1 = geom_builder.MakeVertexOnCurve(cmin,dang*i)
+ p2 = geom_builder.MakeVertexOnCurve(cmax,dang*(i+1))
+ p3 = geom_builder.MakeVertexOnCurve(cmin,dang*(i+2))
+ f = geom_builder.MakeQuad4Vertices(pnt,p1,p2,p3)
faces.append(f)
pass
- shell = geompy.MakeSewing(faces,1.e-6)
+ shell = geom_builder.MakeSewing(faces,1.e-6)
return shell
locs = []
# 1 section
-shell = MakeComplexSect(vs[0], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16)
+shell = MakeComplexSect(vs[0], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16, geom_builder=geompy)
shells.append(shell)
vs1 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
locs.append(vs1[17])
# 2 section
-shell = MakeComplexSect(vs[1], geompy.MakeVectorDXDYDZ(1,0,0), 80, 30, 16)
+shell = MakeComplexSect(vs[1], geompy.MakeVectorDXDYDZ(1,0,0), 80, 30, 16, geom_builder=geompy)
shells.append(shell)
vs2 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
locs.append(vs2[17])
# 3 section
-shell = MakeComplexSect(vs[2], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16)
+shell = MakeComplexSect(vs[2], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16, geom_builder=geompy)
shells.append(shell)
vs3 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
locs.append(vs3[17])
# 4 section
-shell = MakeComplexSect(vs[3], geompy.MakeVectorDXDYDZ(0,1,0), 40, 35, 16)
+shell = MakeComplexSect(vs[3], geompy.MakeVectorDXDYDZ(0,1,0), 40, 35, 16, geom_builder=geompy)
shells.append(shell)
vs4 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
locs.append(vs4[17])
from salome.geom import geomBuilder
geompy = geomBuilder.New()
-def MakeHelix(radius, height, rotation, direction):
- # - create a helix -
- radius = 1.0 * radius
- height = 1.0 * height
- rotation = 1.0 * rotation
- if direction > 0:
- direction = +1
- else:
- direction = -1
- pass
- from math import sqrt
- length_z = height
- length_xy = radius*rotation
- length = sqrt(length_z*length_z + length_xy*length_xy)
- nb_steps = 1
- epsilon = 1.0e-6
- while 1:
- z_step = height / nb_steps
- angle_step = rotation / nb_steps
- z = 0.0
- angle = 0.0
- helix_points = []
- for n in range(nb_steps+1):
- from math import cos, sin
- x = radius * cos(angle)
- y = radius * sin(angle)
- p = geompy.MakeVertex(x, y, z)
- helix_points.append( p )
- z += z_step
- angle += direction * angle_step
+def MakeSpring(radius, height, rotation, direction, thread_radius, base_rotation, geom_builder):
+
+ def MakeHelix(radius, height, rotation, direction, geom_builder):
+ # - create a helix -
+ radius = 1.0 * radius
+ height = 1.0 * height
+ rotation = 1.0 * rotation
+ if direction > 0:
+ direction = +1
+ else:
+ direction = -1
+ pass
+ from math import sqrt
+ length_z = height
+ length_xy = radius*rotation
+ length = sqrt(length_z*length_z + length_xy*length_xy)
+ nb_steps = 1
+ epsilon = 1.0e-6
+ while 1:
+ z_step = height / nb_steps
+ angle_step = rotation / nb_steps
+ z = 0.0
+ angle = 0.0
+ helix_points = []
+ for n in range(nb_steps+1):
+ from math import cos, sin
+ x = radius * cos(angle)
+ y = radius * sin(angle)
+ p = geom_builder.MakeVertex(x, y, z)
+ helix_points.append( p )
+ z += z_step
+ angle += direction * angle_step
+ pass
+ helix = geom_builder.MakeInterpol(helix_points)
+ length_test = geom_builder.BasicProperties(helix)[0]
+ prec = abs(length-length_test)/length
+ # print nb_steps, length_test, prec
+ if prec < epsilon:
+ break
+ nb_steps *= 2
pass
- helix = geompy.MakeInterpol(helix_points)
- length_test = geompy.BasicProperties(helix)[0]
- prec = abs(length-length_test)/length
- # print nb_steps, length_test, prec
- if prec < epsilon:
- break
- nb_steps *= 2
- pass
- return helix
+ return helix
-def MakeSpring(radius, height, rotation, direction, thread_radius, base_rotation=0.0):
# - create a pipe -
thread_radius = 1.0 * thread_radius
# create a helix
- helix = MakeHelix(radius, height, rotation, direction)
+ helix = MakeHelix(radius, height, rotation, direction, geom_builder=geom_builder)
# base in the (Ox, Oz) plane
- p0 = geompy.MakeVertex(radius-3*thread_radius, 0.0, -thread_radius)
- p1 = geompy.MakeVertex(radius+3*thread_radius, 0.0, -thread_radius)
- p2 = geompy.MakeVertex(radius+3*thread_radius, 0.0, +thread_radius)
- p3 = geompy.MakeVertex(radius-3*thread_radius, 0.0, +thread_radius)
- e0 = geompy.MakeEdge(p0, p1)
- e1 = geompy.MakeEdge(p1, p2)
- e2 = geompy.MakeEdge(p2, p3)
- e3 = geompy.MakeEdge(p3, p0)
- w = geompy.MakeWire([e0, e1, e2, e3])
+ p0 = geom_builder.MakeVertex(radius-3*thread_radius, 0.0, -thread_radius)
+ p1 = geom_builder.MakeVertex(radius+3*thread_radius, 0.0, -thread_radius)
+ p2 = geom_builder.MakeVertex(radius+3*thread_radius, 0.0, +thread_radius)
+ p3 = geom_builder.MakeVertex(radius-3*thread_radius, 0.0, +thread_radius)
+ e0 = geom_builder.MakeEdge(p0, p1)
+ e1 = geom_builder.MakeEdge(p1, p2)
+ e2 = geom_builder.MakeEdge(p2, p3)
+ e3 = geom_builder.MakeEdge(p3, p0)
+ w = geom_builder.MakeWire([e0, e1, e2, e3])
# create a base face
- base = geompy.MakeFace(w, True)
+ base = geom_builder.MakeFace(w, True)
# create a binormal vector
- binormal = geompy.MakeVectorDXDYDZ(0.0, 0.0, 10.0)
+ binormal = geom_builder.MakeVectorDXDYDZ(0.0, 0.0, 10.0)
# create a pipe
- spring = geompy.MakePipeBiNormalAlongVector(base, helix, binormal)
+ spring = geom_builder.MakePipeBiNormalAlongVector(base, helix, binormal)
# Publish in the study
- geompy.addToStudy(base, "base")
- geompy.addToStudy(helix, "helix")
- geompy.addToStudy(binormal, "binormal")
- geompy.addToStudy(spring, "spring")
+ geom_builder.addToStudy(base, "base")
+ geom_builder.addToStudy(helix, "helix")
+ geom_builder.addToStudy(binormal, "binormal")
+ geom_builder.addToStudy(spring, "spring")
return spring
from math import pi
-
-spring = MakeSpring(50, 100, 2*pi, 1, 5, pi/2)
+spring = MakeSpring(50, 100, 2*pi, 1, 5, pi/2, geom_builder=geompy)
# Point Coordinates
-import math
import salome
salome.salome_init()
import GEOM
coords = geompy.PointCoordinates(point)
# check the obtained coordinate values
-tolerance = 1.e-07
-def IsEqual(val1, val2): return (math.fabs(val1 - val2) < tolerance)
+def IsEqual(val1, val2, tolerance = 1.e-07):
+ import math
+ return (math.fabs(val1 - val2) < tolerance)
if IsEqual(coords[0], 15.) and IsEqual(coords[1], 23.) and IsEqual(coords[2], 80.):
print("All values are OK.")
--- /dev/null
+DIR='@CMAKE_CURRENT_SOURCE_DIR@'
+TESTS='@GOOD_TESTS@'
+REINIT_SALOME=@TEST_REINIT_SALOME@
+
+import os
+import unittest
+import salome
+
+class MyTest(unittest.TestCase):
+ def setUp(self):
+ if REINIT_SALOME:
+ salome.salome_init()
+ def tearDown(self):
+ if REINIT_SALOME:
+ salome.salome_close()
+ pass
+
+if __name__ == "__main__":
+ tests = TESTS.split(';')
+ for test in tests:
+ file_name = os.path.basename(test)
+ if os.path.isabs(test):
+ file_path = file_name
+ else:
+ file_path = os.path.join(DIR, file_name)
+ case_name = 'test_' + file_name[:-3]
+ code = """
+def func(self):
+ with open('{}') as f:
+ exec(f.read())
+"""
+ exec(code.format(file_path))
+ setattr(MyTest, case_name, func)
+
+ unittest.main()