]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added test model.
authordbv <dbv@opencascade.com>
Wed, 18 Jan 2017 13:54:18 +0000 (16:54 +0300)
committerdbv <dbv@opencascade.com>
Wed, 18 Jan 2017 13:55:59 +0000 (16:55 +0300)
build_Salome_deb.bat
src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h
src/PythonAPI/model/__init__.py
src/PythonAPI/model/tests/__init__.py [new file with mode: 0644]
src/PythonAPI/model/tests/tests.py [new file with mode: 0644]
test.models/bobine_film_reel.py [new file with mode: 0644]

index 76a4b4c805d0db0eea5d321927efa22a175badb4..ddcc88b9b7b11c81c52c9554d4caa22e11597ead 100644 (file)
@@ -14,6 +14,7 @@ call %SRC_DIR%\env_Salome.bat d
 mkdir %ROOT_DIR%\build
 cd %ROOT_DIR%\build
 
+REM Add -DADD_MODELS_TESTS=TRUE to enable test models
 cmake %SRC_DIR% -G "Visual Studio 10 Win64" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
 
 start "" %MSVC_EXE% SHAPER.sln
index e7b448bc39d2453618b32173645607a3ce7551b1..734b426bba8a7f445acbe7be204f097ca8150828 100644 (file)
@@ -28,6 +28,7 @@
 // standard definitions
 %include "typemaps.i"
 %include "std_list.i"
+%include "std_pair.i"
 %include "std_string.i"
 %include "std_shared_ptr.i"
 
 %template(RefAttrList) std::list<ModelHighAPI_RefAttr>;
 %template(RefList) std::list<ModelHighAPI_Reference>;
 
+// std::pair -> []
+%template(ResultSubShapePair) std::pair<std::shared_ptr<ModelAPI_Result>, std::shared_ptr<GeomAPI_Shape> >;
+
 
 // fix compilarion error: ‘res*’ was not declared in this scope
 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
index e63c40ec8b3b1c5d1577dc4045d1d2c67286983a..6b2862ae6fb411962ecfa86e6ed44df0efff4b59 100644 (file)
@@ -132,7 +132,20 @@ void ModelHighAPI_Selection::setDeflection(double theValue)
   aDeflectionAttr->setValue(theValue);
 }
 
-ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex)
+int ModelHighAPI_Selection::numberOfSubs() const
+{
+  if (myVariantType != VT_ResultSubShapePair)
+    return 0;
+
+  ResultCompSolidPtr aCompSolid =
+      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
+  if (!aCompSolid)
+    return 0;
+
+  return aCompSolid->numberOfSubs();
+}
+
+ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const
 {
   if (myVariantType != VT_ResultSubShapePair)
     return ModelHighAPI_Selection();
index 7d898698397a0e4b75e0cf2fbe11ebe585867873..c807cb19c4d65fef8596cde12d27889426390a8a 100644 (file)
@@ -91,9 +91,13 @@ public:
   MODELHIGHAPI_EXPORT
   void setDeflection(double theValue);
 
-  /// Return sub-result for ResultCompSolid
+  /// Returns the number of sub-elements.
   MODELHIGHAPI_EXPORT
-  ModelHighAPI_Selection subResult(int theIndex);
+  int numberOfSubs() const;
+
+  /// Returns the sub-result by zero-base index.
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Selection subResult(int theIndex) const;
 
 private:
   VariantType myVariantType;
index 34d537d597987739fb1cd85f025ad8d437cdfbc3..29364c692b38edf4074740ddaec6a2129bd1ce8b 100644 (file)
@@ -24,3 +24,4 @@ from parameter import *
 from partset import *
 from primitives import *
 from gdml import *
+from tests import *
diff --git a/src/PythonAPI/model/tests/__init__.py b/src/PythonAPI/model/tests/__init__.py
new file mode 100644 (file)
index 0000000..f853b10
--- /dev/null
@@ -0,0 +1 @@
+from tests import *
\ No newline at end of file
diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py
new file mode 100644 (file)
index 0000000..cb2ce66
--- /dev/null
@@ -0,0 +1,66 @@
+from GeomAlgoAPI import *
+import math
+
+
+def generateTests(theFeature, theFeatureName, theTestsList = []):
+  """ Generates tests for theFeature.
+  :param theFeature: feature to test. Should be ModelHighAPI_Interface.
+  :param theFeatureName: feature name to put in test commands.
+  :param theTestsList: list of test to be generated. If empty generates all tests.
+  """
+  if "testNbResults" in theTestsList or len(theTestsList) == 0:
+    aNbResults = len(theFeature.results())
+    print "model.testNbResults({}, {})".format(theFeatureName, aNbResults)
+
+  if "testNbSubResults" in theTestsList or len(theTestsList) == 0:
+    aNbResults = len(theFeature.results())
+    aNbSubResults = []
+    for anIndex in range(0, aNbResults):
+      aNbSubResults.append(theFeature.results()[anIndex].numberOfSubs())
+    print "model.testNbSubResults({}, {})".format(theFeatureName, aNbSubResults)
+
+  if "testResultsVolumes" in theTestsList or len(theTestsList) == 0:
+    aNbResults = len(theFeature.results())
+    aResultsVolumes = []
+    for anIndex in range(0, aNbResults):
+      aResultsVolumes.append(GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape()))
+    print "model.testResultsVolumes({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes))
+
+
+def testNbResults(theFeature, theExpectedNbResults):
+  """ Tests number of feature results.
+  :param theFeature: feature to test.
+  :param theExpectedNbResults: expected number of results.
+  """
+  aNbResults = len(theFeature.results())
+  assert (aNbResults == theExpectedNbResults), "Number of results: {}. Expected: {}.".format(aNbResults, theExpectedNbResults)
+
+
+def testNbSubResults(theFeature, theExpectedNbSubResults):
+  """ Tests number of feature sub-results for each result.
+  :param theFeature: feature to test.
+  :param theExpectedNbSubResults: list of sub-results numbers. Size of list should be equal to len(theFeature.results()).
+  """
+  aNbResults = len(theFeature.results())
+  aListSize = len(theExpectedNbSubResults)
+  assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
+  for anIndex in range(0, aNbResults):
+    aNbSubResults = theFeature.results()[anIndex].numberOfSubs()
+    anExpectedNbSubResults = theExpectedNbSubResults[anIndex]
+    assert (aNbSubResults == anExpectedNbSubResults), "Number of sub-results for result[{}]: {}. Expected: {}.".format(anIndex, aNbSubResults, anExpectedNbSubResults)
+
+
+def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDigits = 10):
+  """ Tests results volumes.
+  :param theFeature: feature to test.
+  :param theExpectedResultsVolumes: list of results volumes. Size of list should be equal to len(theFeature.results()).
+  """
+  aNbResults = len(theFeature.results())
+  aListSize = len(theExpectedResultsVolumes)
+  assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
+  for anIndex in range(0, aNbResults):
+    aResultVolume = GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape())
+    aResultVolumeStr = "{:0.27f}".format(aResultVolume).lstrip("0").lstrip(".").lstrip("0")
+    anExpectedResultVolume = theExpectedResultsVolumes[anIndex]
+    anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0")
+    assert (aResultVolumeStr[:theNbSignificantDigits] == anExpectedResultVolumeStr[:theNbSignificantDigits]), "Volume of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits)
diff --git a/test.models/bobine_film_reel.py b/test.models/bobine_film_reel.py
new file mode 100644 (file)
index 0000000..bbd0dde
--- /dev/null
@@ -0,0 +1,114 @@
+from SketchAPI import *
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+model.addParameter(Part_1_doc, "R", "40")
+model.addParameter(Part_1_doc, "h", "3")
+model.addParameter(Part_1_doc, "R2", "33.5")
+model.addParameter(Part_1_doc, "h2", "4")
+model.addParameter(Part_1_doc, "R3", "25.9")
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchCircle_1 = Sketch_1.addCircle(0, 0, 40)
+SketchPoint_1 = Sketch_1.addPoint(model.selection("VERTEX", "PartSet/Origin"))
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchPoint_1.result())
+SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "R")
+SketchLine_1 = Sketch_1.addLine(0, 0, -20.88093073029438, 34.1172497695333)
+SketchLine_1.setAuxiliary(True)
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.startPoint())
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchLine_1.startPoint())
+SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchCircle_1.results()[1])
+model.do()
+Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), "h", 0)
+Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face_1"))
+SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"))
+SketchLine_2 = SketchProjection_1.createdFeature()
+SketchCircle_2 = Sketch_2.addCircle(0, 0, 33.5)
+SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_2.results()[1], "R2")
+SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_2).startPoint(), SketchCircle_2.center())
+SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_14")
+model.do()
+Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection(), "h2", 0)
+Extrusion_3 = model.addExtrusion(Part_1_doc, [], model.selection(), "h2*3", 0)
+Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_2_1/To_Face_1"))
+SketchCircle_3 = Sketch_3.addCircle(0, 0, 28.25)
+SketchConstraintRadius_3 = Sketch_3.setRadius(SketchCircle_3.results()[1], 28.25)
+SketchProjection_2 = Sketch_3.addProjection(model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"))
+SketchLine_3 = SketchProjection_2.createdFeature()
+SketchConstraintCoincidence_6 = Sketch_3.setCoincident(SketchCircle_3.center(), SketchAPI_Line(SketchLine_3).startPoint())
+Extrusion_3.setNestedSketch(Sketch_3)
+Extrusion_4 = model.addExtrusion(Part_1_doc, [], model.selection(), "h2", 0)
+Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_3_1/To_Face_1"))
+SketchProjection_3 = Sketch_4.addProjection(model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"))
+SketchLine_4 = SketchProjection_3.createdFeature()
+SketchCircle_4 = Sketch_4.addCircle(0, 0, 25.9)
+SketchConstraintRadius_4 = Sketch_4.setRadius(SketchCircle_4.results()[1], "R3")
+SketchConstraintCoincidence_7 = Sketch_4.setCoincident(SketchAPI_Line(SketchLine_4).startPoint(), SketchCircle_4.center())
+SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_15")
+Extrusion_4.setNestedSketch(Sketch_4)
+Extrusion_5 = model.addExtrusion(Part_1_doc, [], model.selection(), "h2", 0)
+Sketch_5 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_4_1/To_Face_1"))
+SketchProjection_4 = Sketch_5.addProjection(model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"))
+SketchLine_5 = SketchProjection_4.createdFeature()
+SketchCircle_5 = Sketch_5.addCircle(0, 0, 8)
+SketchConstraintRadius_5 = Sketch_5.setRadius(SketchCircle_5.results()[1], 8)
+SketchConstraintCoincidence_8 = Sketch_5.setCoincident(SketchAPI_Line(SketchLine_5).startPoint(), SketchCircle_5.center())
+SketchConstraintCoincidence_8.setName("SketchConstraintCoincidence_16")
+Extrusion_5.setNestedSketch(Sketch_5)
+Boolean_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Extrusion_4_1"), model.selection("SOLID", "Extrusion_5_1"), model.selection("SOLID", "Extrusion_1_1"), model.selection("SOLID", "Extrusion_2_1"), model.selection("SOLID", "Extrusion_3_1")], [])
+ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection("FACE", "Extrusion_5_1/To_Face_1"), 0, model.selection(), 0, [model.selection("SOLID", "Boolean_1_1")])
+Sketch_6 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/From_Face_1"))
+SketchCircle_6 = Sketch_6.addCircle(0, 0, 4.2)
+SketchConstraintRadius_6 = Sketch_6.setRadius(SketchCircle_6.results()[1], 4.2)
+SketchPoint_2 = Sketch_6.addPoint(model.selection("VERTEX", "PartSet/Origin"))
+SketchConstraintCoincidence_9 = Sketch_6.setCoincident(SketchPoint_2.coordinates(), SketchCircle_6.center())
+SketchConstraintCoincidence_9.setName("SketchConstraintCoincidence_17")
+ExtrusionCut_1.setNestedSketch(Sketch_6)
+Sketch_7 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_1_1/Modfied_1"))
+SketchCircle_7 = Sketch_7.addCircle(0, -85, 66)
+SketchLine_6 = Sketch_7.addLine(model.selection("EDGE", "PartSet/OY"))
+SketchConstraintCoincidence_10 = Sketch_7.setCoincident(SketchCircle_7.center(), SketchLine_6.result())
+SketchConstraintRadius_7 = Sketch_7.setRadius(SketchCircle_7.results()[1], 66)
+SketchConstraintDistance_1 = Sketch_7.setDistance(SketchCircle_7.center(), SketchLine_6.startPoint(), 85)
+SketchMultiRotation_1 = Sketch_7.addRotation([SketchCircle_7.results()[1]], SketchLine_6.startPoint(), 120, 3)
+[SketchCircle_8, SketchCircle_9] = SketchMultiRotation_1.rotated()
+model.do()
+ExtrusionCut_2 = model.addExtrusionCut(Part_1_doc, [model.selection("COMPOUND", "Sketch_7")], model.selection(), model.selection("FACE", "ExtrusionCut_1_1/Modfied_2"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_1_1")])
+Sketch_8 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_2_1/Modfied_22"))
+SketchLine_7 = Sketch_8.addLine(-2.320957096353877e-016, 11.00000001704673, -7, 11.00000001704673)
+SketchConstraintHorizontal_1 = Sketch_8.setHorizontal(SketchLine_7.result())
+SketchLine_8 = Sketch_8.addLine(-7, 11.00000001704673, -6.329882773485103e-016, 30.00000001704673)
+SketchConstraintCoincidence_11 = Sketch_8.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
+SketchLine_9 = Sketch_8.addLine(model.selection("EDGE", "PartSet/OY"))
+SketchConstraintCoincidence_12 = Sketch_8.setCoincident(SketchLine_7.startPoint(), SketchLine_9.result())
+SketchConstraintCoincidence_13 = Sketch_8.setCoincident(SketchLine_8.endPoint(), SketchLine_9.result())
+SketchConstraintMirror_1 = Sketch_8.addMirror(SketchLine_9.result(), [SketchLine_7.result(), SketchLine_8.result()])
+[SketchLine_10, SketchLine_11] = SketchConstraintMirror_1.mirrored()
+SketchConstraintLength_1 = Sketch_8.setLength(SketchLine_7.result(), 7)
+SketchConstraintDistance_2 = Sketch_8.setDistance(SketchLine_9.startPoint(), SketchLine_7.result(), 11)
+SketchConstraintDistance_3 = Sketch_8.setDistance(SketchLine_8.endPoint(), SketchLine_9.startPoint(), 30)
+SketchMultiRotation_2_objects = [SketchLine_11.result(), SketchLine_10.result(), SketchLine_8.result(), SketchLine_7.result()]
+SketchMultiRotation_2 = Sketch_8.addRotation(SketchMultiRotation_2_objects, SketchLine_9.startPoint(), 120, 3)
+[SketchLine_11, SketchLine_12, SketchLine_13, SketchLine_10, SketchLine_14, SketchLine_15, SketchLine_16, SketchLine_17, SketchLine_18, SketchLine_19] = SketchMultiRotation_2.rotated()
+SketchLine_18.setName("SketchLine_15")
+SketchLine_18.result().setName("SketchLine_15")
+SketchLine_17.setName("SketchLine_18")
+SketchLine_17.result().setName("SketchLine_18")
+SketchLine_16.setName("SketchLine_14")
+SketchLine_16.result().setName("SketchLine_14")
+SketchLine_15.setName("SketchLine_17")
+SketchLine_15.result().setName("SketchLine_17")
+SketchLine_14.setName("SketchLine_13")
+SketchLine_14.result().setName("SketchLine_13")
+SketchLine_13.setName("SketchLine_16")
+SketchLine_13.result().setName("SketchLine_16")
+model.do()
+ExtrusionCut_3 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_8/Face-SketchLine_7r-SketchLine_8r-SketchLine_10f-SketchLine_11f"), model.selection("FACE", "Sketch_8/Face-SketchLine_16f-SketchLine_17f-SketchLine_18r-SketchLine_19r"), model.selection("FACE", "Sketch_8/Face-SketchLine_12f-SketchLine_13f-SketchLine_14r-SketchLine_15r")], model.selection(), model.selection("FACE", "ExtrusionCut_2_1/Modfied_23"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_2_1")])
+model.end()
+
+model.testNbResults(ExtrusionCut_3, 1)
+model.testNbSubResults(ExtrusionCut_3, [0])
+model.testResultsVolumes(ExtrusionCut_3, [34439.077343526856566313654184341])