Salome HOME
Fix the test because path-objects of pipe can not be reused anymore (issue #18352)
[modules/shaper.git] / src / FeaturesPlugin / Test / TestMultiBoolean.py
index 594c3af72a88068cb7c417781e5a794c26a0fdfd..fce6e9979cd626e96c5881a0eb6da04c39b3cd92 100644 (file)
@@ -1,16 +1,35 @@
+# Copyright (C) 2014-2019  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
+#
+
 """
       TestExtrusion.py
       Unit test of FeaturesPlugin_Boolean class: many Boolean operations performance
-      
+
       class FeaturesPlugin_Extrusion : public ModelAPI_Feature
         static const std::string MY_EXTRUSION_ID("Extrusion");
         static const std::string MY_FACE_ID("base");
         static const std::string MY_SIZE_ID("size");
         static const std::string MY_REVERSE_ID("reverse");
-          
-        data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
-        data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
-        data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
+
+        data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::typeId());
+        data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::typeId());
+        data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId());
 """
 
 # Number rows and columns of cylinders that cuts the big box. Number of Boolena operations is N*N
@@ -19,12 +38,13 @@ N = 5
 #=========================================================================
 # Initialization of the test
 #=========================================================================
-from ModelAPI import *
-from GeomDataAPI import *
-from GeomAlgoAPI import *
 from GeomAPI import *
+from GeomAlgoAPI import *
+from GeomDataAPI import *
+from ModelAPI import *
+
 
-__updated__ = "2015-02-25"
+__updated__ = "2015-03-26"
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -46,24 +66,22 @@ radius = 95. / N / 2.
 
 aSession.startOperation()
 aSketchFeatures = []
-for i in xrange(0, N):
-  for j in xrange(0, N):
-    # Create circle
-    aSketchFeature = modelAPI_CompositeFeature(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)
-    diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
-    diry.setValue(0, 1, 0)
-    norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
-    norm.setValue(0, 0, 1)
-    aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-    anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-    aCircleRadius = aSketchCircle.real("CircleRadius")
-    anCircleCentr.setValue(0.5 + step * (0.5 + i), 0.5 + step * (0.5 + j))
-    aCircleRadius.setValue(radius)
-    aSketchFeatures.append(aSketchFeature)
+for i in range(0, N):
+    for j in range(0, N):
+        # Create circle
+        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)
+        aSketchCircle = aSketchFeature.addFeature("SketchCircle")
+        anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+        aCircleRadius = aSketchCircle.real("circle_radius")
+        anCircleCentr.setValue(0.5 + step * (0.5 + i), 0.5 + step * (0.5 + j))
+        aCircleRadius.setValue(radius)
+        aSketchFeatures.append(aSketchFeature)
 
 aSession.finishOperation()
 
@@ -76,25 +94,19 @@ aSession.finishOperation()
 aSession.startOperation()
 
 anExtrusions = []
-for i in xrange(0, N * N):
-  aSketchResult = aSketchFeatures[i].firstResult()
-  aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
-  origin = geomDataAPI_Point(aSketchFeatures[i].attribute("Origin")).pnt()
-  dirX = geomDataAPI_Dir(aSketchFeatures[i].attribute("DirX")).dir()
-  dirY = geomDataAPI_Dir(aSketchFeatures[i].attribute("DirY")).dir()
-  norm = geomDataAPI_Dir(aSketchFeatures[i].attribute("Norm")).dir()
-  aSketchFaces = ShapeList()
-  GeomAlgoAPI_SketchBuilder.createFaces(
-      origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
-
-  anExtrusionFt = aPart.addFeature("Extrusion")
-  assert (anExtrusionFt.getKind() == "Extrusion")
-
-  anExtrusionFt.selectionList("base").append(
-      aSketchResult, aSketchFaces[0])
-  anExtrusionFt.real("size").setValue(10)
-  anExtrusionFt.boolean("reverse").setValue(False)
-  anExtrusions.append(anExtrusionFt)
+for i in range(0, N * N):
+    aSketchResult = modelAPI_ResultConstruction(aSketchFeatures[i].firstResult())
+    anExtrusionFt = aPart.addFeature("Extrusion")
+    assert (anExtrusionFt.getKind() == "Extrusion")
+
+    anExtrusionFt.selectionList("base").append(
+        aSketchResult, aSketchResult.face(0))
+    anExtrusionFt.string("CreationMethod").setValue("BySizes")
+    anExtrusionFt.real("from_size").setValue(0)
+    anExtrusionFt.real("to_size").setValue(10)
+    anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
+    anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
+    anExtrusions.append(anExtrusionFt)
 
 aSession.finishOperation()
 
@@ -102,13 +114,11 @@ aSession.finishOperation()
 # Make rectangle sketch: base for the box, size 100x100
 #=========================================================================
 aSession.startOperation()
-aQuadrangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aQuadrangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirY"))
-diry.setValue(0, 1, 0)
 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSketchLineA = aQuadrangleSketchFeature.addFeature("SketchLine")
@@ -138,40 +148,42 @@ aSession.startOperation()
 #=========================================================================
 # Build a big box extrusion
 #=========================================================================
-aSketchResult = aQuadrangleSketchFeature.firstResult()
-aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
-origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin")).pnt()
-dirX = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX")).dir()
-dirY = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirY")).dir()
-norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm")).dir()
-aSketchFaces = ShapeList()
-GeomAlgoAPI_SketchBuilder.createFaces(
-    origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
+aSketchResult = modelAPI_ResultConstruction(aQuadrangleSketchFeature.firstResult())
 # Create extrusion on them
 aBox = aPart.addFeature("Extrusion")
 aBox.selectionList("base").append(
-    aSketchResult, aSketchFaces[0])
-aBox.real("size").setValue(10)
-aBox.boolean("reverse").setValue(False)
+    aSketchResult, aSketchResult.face(0))
+aBox.string("CreationMethod").setValue("BySizes")
+aBox.real("from_size").setValue(0)
+aBox.real("to_size").setValue(10)
+aBox.real("to_offset").setValue(0) #TODO: remove
+aBox.real("from_offset").setValue(0) #TODO: remove
+
 aSession.finishOperation()
 
 
 #=========================================================================
-# Create a boolean cut of cylinders from the box: 
-# result of Boolean is the first argument of the next Boolean
+# Create a boolean cut of cylinders from the box:
 #=========================================================================
-aCurrentResult = aBox.firstResult()
+aCurrentResult = modelAPI_ResultBody(aBox.firstResult())
 aSession.startOperation()
-for i in xrange(0, N * N):
-  aBooleanFt = aPart.addFeature("Boolean")
-  aBooleanFt.reference("main_object").setValue(modelAPI_ResultBody(aCurrentResult))
-  aBooleanFt.reference("tool_object").setValue(modelAPI_ResultBody(anExtrusions[i].firstResult()))
-  kBooleanTypeCut = 0
-  aBooleanFt.integer("bool_type").setValue(kBooleanTypeCut)
-  aBooleanFt.execute()
-  aCurrentResult = aBooleanFt.firstResult()
+
+aBooleanFt = aPart.addFeature("Cut")
+aBooleanFt.selectionList("main_objects").append(aCurrentResult, aCurrentResult.shape())
+for i in range(0, N * N):
+    anExtrusionResult = modelAPI_ResultBody(anExtrusions[i].firstResult())
+    aBooleanFt.selectionList("tool_objects").append(anExtrusionResult, anExtrusionResult.shape())
+aBooleanFt.execute()
+aFactory = ModelAPI_Session.get().validators()
+assert (aFactory.validate(aBooleanFt))
+assert (len(aBooleanFt.results()) > 0)
+aCurrentResult = modelAPI_ResultBody(aBooleanFt.firstResult())
+assert (aCurrentResult is not None)
 aSession.finishOperation()
 
 #=========================================================================
 # End of test
 #=========================================================================
+
+from salome.shaper import model
+assert(model.checkPythonDump())