]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[Code coverage FeaturesPlugin]: Improve coverage of Pipe algorithm
authorazv <azv@opencascade.com>
Sun, 9 Dec 2018 12:04:28 +0000 (15:04 +0300)
committerazv <azv@opencascade.com>
Sun, 9 Dec 2018 12:04:28 +0000 (15:04 +0300)
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp
src/FeaturesPlugin/Test/TestPipe_Compound.py [new file with mode: 0644]
src/FeaturesPlugin/Test/TestPipe_Edge.py [new file with mode: 0644]
src/FeaturesPlugin/Test/TestPipe_ErrorMsg.py [new file with mode: 0644]
src/FeaturesPlugin/Test/TestPipe_Wire.py [new file with mode: 0644]

index ce8169b385636b408069b08110d610f1d6c81d11..9896d68af33ac99f656d3b71f3b30c5fcd5ff43f 100644 (file)
@@ -215,6 +215,10 @@ ADD_UNIT_TESTS(TestExtrusion.py
                TestRemoveSubShapes5.py
                TestRemoveSubShapes6.py
                TestPipe.py
+               TestPipe_Edge.py
+               TestPipe_Wire.py
+               TestPipe_Compound.py
+               TestPipe_ErrorMsg.py
                TestRecover.py
                TestRecover1798.py
                TestFillEdgeVertex.py
index ff6815e168e531c5cc2c2032ba90b304ad140afc..425ac1f49b315a5c9664f81c9debb5ce4a1aacc1 100644 (file)
@@ -165,7 +165,7 @@ void FeaturesPlugin_Pipe::execute()
   }
   std::shared_ptr<GeomAPI_Shape> aPathShape =
     std::dynamic_pointer_cast<GeomAPI_Shape>(aPathSelection->value());
-  if(!aPathShape.get()) {
+  if(!aPathShape.get() && aPathSelection->context().get()) {
     // Probaply it is a construction.
     aPathShape = aPathSelection->context()->shape();
   }
@@ -183,7 +183,7 @@ void FeaturesPlugin_Pipe::execute()
       return;
     }
     aBiNormal = std::dynamic_pointer_cast<GeomAPI_Shape>(aBiNormalSelection->value());
-    if(!aBiNormal.get()) {
+    if(!aBiNormal.get() && aBiNormalSelection->context().get()) {
       // Probably it is a construction.
       aBiNormal = aBiNormalSelection->context()->shape();
     }
@@ -208,7 +208,7 @@ void FeaturesPlugin_Pipe::execute()
         return;
       }
       std::shared_ptr<GeomAPI_Shape> aLocationShape = aLocationSelection->value();
-      if(!aLocationShape.get()) {
+      if(!aLocationShape.get() && aLocationSelection->context().get()) {
         // Probably it is a construction.
         aLocationShape = aLocationSelection->context()->shape();
       }
diff --git a/src/FeaturesPlugin/Test/TestPipe_Compound.py b/src/FeaturesPlugin/Test/TestPipe_Compound.py
new file mode 100644 (file)
index 0000000..192c400
--- /dev/null
@@ -0,0 +1,44 @@
+## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(50, 15, 100, 20)
+SketchLine_2 = Sketch_1.addLine(30, 10, 50, 0)
+SketchArc_1 = Sketch_1.addArc(30, 40, 60, 40, 30, 70, False)
+model.do()
+Compound_1 = model.addCompound(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")])
+model.do()
+Pipe_1 = model.addPipe(Part_1_doc, [model.selection("COMPOUND", "Compound_1_1")], model.selection("EDGE", "Sketch_1/SketchArc_1_2"))
+model.end()
+
+from GeomAPI import GeomAPI_Shape
+
+model.testNbResults(Pipe_1, 1)
+model.testNbSubResults(Pipe_1, [2])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.FACE, [2])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.EDGE, [8])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.VERTEX, [16])
diff --git a/src/FeaturesPlugin/Test/TestPipe_Edge.py b/src/FeaturesPlugin/Test/TestPipe_Edge.py
new file mode 100644 (file)
index 0000000..9e17782
--- /dev/null
@@ -0,0 +1,54 @@
+## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchArc_1 = Sketch_1.addArc(23.47558064206828, 28.1849874113521, 68.07028657666974, 20.97621888383109, 20.24058919303746, 73.24260576165612, False)
+SketchLine_1 = Sketch_1.addLine(67.41776169413798, 4.173199186912264, 102.8479480835664, 10.72004206910377)
+model.do()
+Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1")])
+Pipe_1 = model.addPipe(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("EDGE", "Sketch_1/SketchArc_1_2"))
+Edge_2 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1")])
+Pipe_2 = model.addPipe(Part_1_doc, [model.selection("EDGE", "Edge_2_1")], model.selection("EDGE", "PartSet/OY"), model.selection("EDGE", "PartSet/OZ"))
+model.do()
+model.end()
+
+from GeomAPI import GeomAPI_Shape
+
+model.testNbResults(Pipe_1, 1)
+model.testNbSubResults(Pipe_1, [0])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.FACE, [1])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.EDGE, [4])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.VERTEX, [8])
+model.testResultsVolumes(Pipe_1, [3693.366575752712378744035959244])
+
+model.testNbResults(Pipe_2, 1)
+model.testNbSubResults(Pipe_2, [0])
+model.testNbSubShapes(Pipe_2, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Pipe_2, GeomAPI_Shape.FACE, [1])
+model.testNbSubShapes(Pipe_2, GeomAPI_Shape.EDGE, [4])
+model.testNbSubShapes(Pipe_2, GeomAPI_Shape.VERTEX, [8])
+model.testResultsVolumes(Pipe_2, [3543.018638942841789685189723969])
diff --git a/src/FeaturesPlugin/Test/TestPipe_ErrorMsg.py b/src/FeaturesPlugin/Test/TestPipe_ErrorMsg.py
new file mode 100644 (file)
index 0000000..ea10665
--- /dev/null
@@ -0,0 +1,89 @@
+## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+from ModelAPI import *
+from GeomDataAPI import *
+
+# Get document
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+
+# Create a part
+aSession.startOperation()
+aPartFeature = aDocument.addFeature("Part")
+aSession.finishOperation()
+aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
+aPart = aPartResult.partDoc()
+
+# Create a sketch with circle for pipe profile
+aSession.startOperation()
+aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+
+# Create circle
+aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("circle_center"))
+aCircleRadius = aSketchCircleFeature.real("circle_radius")
+anCircleCentr.setValue(0, 0)
+aCircleRadius.setValue(10)
+aSession.finishOperation()
+
+aSketchResult = aSketchFeature.firstResult()
+aSketchShape = aSketchResult.shape()
+
+aSession.startOperation()
+aPipeFeature = aPart.addFeature("Pipe")
+aPipeFeature.string("creation_method").setValue("WrongCreationMethod")
+aPipeFeature.execute()
+assert(aPipeFeature.error() != "")
+aSession.finishOperation()
+
+aSession.startOperation()
+aBaseObjectsList = aPipeFeature.selectionList("base_objects")
+aBaseObjectsList.append(aSketchResult, None)
+aPipeFeature.execute()
+assert(aPipeFeature.error() != "")
+aSession.finishOperation()
+
+aSession.startOperation()
+aPathObjectSelection = aPipeFeature.selection("path_object")
+aPathObjectSelection.selectSubShape("EDGE", "PartSet/OZ")
+aPipeFeature.execute()
+assert(aPipeFeature.error() != "")
+aSession.finishOperation()
+
+aSession.startOperation()
+aPipeFeature.string("creation_method").setValue("binormal")
+aPipeFeature.execute()
+assert(aPipeFeature.error() != "")
+aSession.finishOperation()
+
+aSession.startOperation()
+aPipeFeature.string("creation_method").setValue("locations")
+aBaseObjectsList = aPipeFeature.selectionList("locations_objects")
+aBaseObjectsList.append(None, None)
+aPipeFeature.execute()
+assert(aPipeFeature.error() != "")
+aSession.finishOperation()
diff --git a/src/FeaturesPlugin/Test/TestPipe_Wire.py b/src/FeaturesPlugin/Test/TestPipe_Wire.py
new file mode 100644 (file)
index 0000000..34786b0
--- /dev/null
@@ -0,0 +1,69 @@
+## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(25, -20, -20, -20)
+SketchLine_2 = Sketch_1.addLine(-20, -20, -20, 15)
+SketchLine_3 = Sketch_1.addLine(-20, 15, 25, 15)
+SketchLine_4 = Sketch_1.addLine(25, 15, 25, -20)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
+SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
+SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
+SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
+SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
+SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
+SketchLine_5 = Sketch_1.addLine(75, 25, 95, 25)
+SketchLine_6 = Sketch_1.addLine(95, 25, 95, 45)
+SketchLine_7 = Sketch_1.addLine(95, 45, 75, 45)
+SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
+SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
+model.do()
+Pipe_1 = model.addPipe(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r_wire")], model.selection("EDGE", "PartSet/OZ"))
+Wire_1_objects = [model.selection("EDGE", "Sketch_1/SketchLine_5"), model.selection("EDGE", "Sketch_1/SketchLine_6"), model.selection("EDGE", "Sketch_1/SketchLine_7")]
+Wire_1 = model.addWire(Part_1_doc, Wire_1_objects)
+Pipe_2 = model.addPipe(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OZ"), [])
+model.do()
+model.end()
+
+from GeomAPI import GeomAPI_Shape
+
+model.testNbResults(Pipe_1, 1)
+model.testNbSubResults(Pipe_1, [0])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.FACE, [6])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.EDGE, [24])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.VERTEX, [48])
+model.testResultsVolumes(Pipe_1, [157500])
+
+model.testNbResults(Pipe_2, 1)
+model.testNbSubResults(Pipe_2, [0])
+model.testNbSubShapes(Pipe_2, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Pipe_2, GeomAPI_Shape.FACE, [3])
+model.testNbSubShapes(Pipe_2, GeomAPI_Shape.EDGE, [12])
+model.testNbSubShapes(Pipe_2, GeomAPI_Shape.VERTEX, [24])
+model.testResultsVolumes(Pipe_2, [6000])