]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/Test/TestMultiBoolean.py
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / FeaturesPlugin / Test / TestMultiBoolean.py
1 """
2       TestExtrusion.py
3       Unit test of FeaturesPlugin_Boolean class: many Boolean operations performance
4       
5       class FeaturesPlugin_Extrusion : public ModelAPI_Feature
6         static const std::string MY_EXTRUSION_ID("Extrusion");
7         static const std::string MY_FACE_ID("base");
8         static const std::string MY_SIZE_ID("size");
9         static const std::string MY_REVERSE_ID("reverse");
10           
11         data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
12         data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
13         data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
14 """
15
16 # Number rows and columns of cylinders that cuts the big box. Number of Boolena operations is N*N
17 N = 5
18
19 #=========================================================================
20 # Initialization of the test
21 #=========================================================================
22 from ModelAPI import *
23 from GeomDataAPI import *
24 from GeomAlgoAPI import *
25 from GeomAPI import *
26
27 __updated__ = "2015-02-25"
28
29 aSession = ModelAPI_Session.get()
30 aDocument = aSession.moduleDocument()
31 # Create a part for extrusion
32 aSession.startOperation()
33 aPartFeature = aDocument.addFeature("Part")
34 aSession.finishOperation()
35 assert (len(aPartFeature.results()) == 1)
36 # Another way is:
37 # aPart = aSession.activeDocument()
38 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
39 aPart = aPartResult.partDoc()
40
41 #=========================================================================
42 # Create a list of sketches with one circle inside of each to extrude
43 #=========================================================================
44 step = 99. / N
45 radius = 95. / N / 2.
46
47 aSession.startOperation()
48 aSketchFeatures = []
49 for i in xrange(0, N):
50   for j in xrange(0, N):
51     # Create circle
52     aSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
53     origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
54     origin.setValue(0, 0, 0)
55     dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
56     dirx.setValue(1, 0, 0)
57     diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
58     diry.setValue(0, 1, 0)
59     norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
60     norm.setValue(0, 0, 1)
61     aSketchCircle = aSketchFeature.addFeature("SketchCircle")
62     anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
63     aCircleRadius = aSketchCircle.real("CircleRadius")
64     anCircleCentr.setValue(0.5 + step * (0.5 + i), 0.5 + step * (0.5 + j))
65     aCircleRadius.setValue(radius)
66     aSketchFeatures.append(aSketchFeature)
67
68 aSession.finishOperation()
69
70 #=========================================================================
71 # Make extrusions on circles
72 #=========================================================================
73 # Build shape from sketcher results
74
75 # Create extrusions
76 aSession.startOperation()
77
78 anExtrusions = []
79 for i in xrange(0, N * N):
80   aSketchResult = aSketchFeatures[i].firstResult()
81   aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
82   origin = geomDataAPI_Point(aSketchFeatures[i].attribute("Origin")).pnt()
83   dirX = geomDataAPI_Dir(aSketchFeatures[i].attribute("DirX")).dir()
84   dirY = geomDataAPI_Dir(aSketchFeatures[i].attribute("DirY")).dir()
85   norm = geomDataAPI_Dir(aSketchFeatures[i].attribute("Norm")).dir()
86   aSketchFaces = ShapeList()
87   GeomAlgoAPI_SketchBuilder.createFaces(
88       origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
89
90   anExtrusionFt = aPart.addFeature("Extrusion")
91   assert (anExtrusionFt.getKind() == "Extrusion")
92
93   anExtrusionFt.selectionList("base").append(
94       aSketchResult, aSketchFaces[0])
95   anExtrusionFt.real("size").setValue(10)
96   anExtrusionFt.boolean("reverse").setValue(False)
97   anExtrusions.append(anExtrusionFt)
98
99 aSession.finishOperation()
100
101 #=========================================================================
102 # Make rectangle sketch: base for the box, size 100x100
103 #=========================================================================
104 aSession.startOperation()
105 aQuadrangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
106 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin"))
107 origin.setValue(0, 0, 0)
108 dirx = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX"))
109 dirx.setValue(1, 0, 0)
110 diry = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirY"))
111 diry.setValue(0, 1, 0)
112 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm"))
113 norm.setValue(0, 0, 1)
114 aSketchLineA = aQuadrangleSketchFeature.addFeature("SketchLine")
115 aSketchLineB = aQuadrangleSketchFeature.addFeature("SketchLine")
116 aSketchLineC = aQuadrangleSketchFeature.addFeature("SketchLine")
117 aSketchLineD = aQuadrangleSketchFeature.addFeature("SketchLine")
118 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
119 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
120 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
121 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
122 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
123 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
124 aLineDStartPoint = geomDataAPI_Point2D(aSketchLineD.attribute("StartPoint"))
125 aLineDEndPoint = geomDataAPI_Point2D(aSketchLineD.attribute("EndPoint"))
126 aLineAStartPoint.setValue(0., 0.)
127 aLineAEndPoint.setValue(0., 100.)
128 aLineBStartPoint.setValue(0., 100.)
129 aLineBEndPoint.setValue(100., 100.)
130 aLineCStartPoint.setValue(100., 100.)
131 aLineCEndPoint.setValue(100., 0.)
132 aLineDStartPoint.setValue(100., 0.)
133 aLineDEndPoint.setValue(0., 0.)
134
135 aSession.finishOperation()
136 aSession.startOperation()
137
138 #=========================================================================
139 # Build a big box extrusion
140 #=========================================================================
141 aSketchResult = aQuadrangleSketchFeature.firstResult()
142 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
143 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin")).pnt()
144 dirX = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX")).dir()
145 dirY = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirY")).dir()
146 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm")).dir()
147 aSketchFaces = ShapeList()
148 GeomAlgoAPI_SketchBuilder.createFaces(
149     origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
150 # Create extrusion on them
151 aBox = aPart.addFeature("Extrusion")
152 aBox.selectionList("base").append(
153     aSketchResult, aSketchFaces[0])
154 aBox.real("size").setValue(10)
155 aBox.boolean("reverse").setValue(False)
156 aSession.finishOperation()
157
158
159 #=========================================================================
160 # Create a boolean cut of cylinders from the box: 
161 # result of Boolean is the first argument of the next Boolean
162 #=========================================================================
163 aCurrentResult = aBox.firstResult()
164 aSession.startOperation()
165 for i in xrange(0, N * N):
166   aBooleanFt = aPart.addFeature("Boolean")
167   aBooleanFt.reference("main_object").setValue(modelAPI_ResultBody(aCurrentResult))
168   aBooleanFt.reference("tool_object").setValue(modelAPI_ResultBody(anExtrusions[i].firstResult()))
169   kBooleanTypeCut = 0
170   aBooleanFt.integer("bool_type").setValue(kBooleanTypeCut)
171   aBooleanFt.execute()
172   aCurrentResult = aBooleanFt.firstResult()
173 aSession.finishOperation()
174
175 #=========================================================================
176 # End of test
177 #=========================================================================