]> 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("extrusion_face");
8         static const std::string MY_SIZE_ID("extrusion_size");
9         static const std::string MY_REVERSE_ID("extrusion_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   anExtrusionFt.selection("extrusion_face").setValue(
93       aSketchResult, aSketchFaces[0])
94   anExtrusionFt.real("extrusion_size").setValue(10)
95   anExtrusionFt.boolean("extrusion_reverse").setValue(False)
96   anExtrusions.append(anExtrusionFt)
97
98 aSession.finishOperation()
99
100 #=========================================================================
101 # Make rectangle sketch: base for the box, size 100x100
102 #=========================================================================
103 aSession.startOperation()
104 aQuadrangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
105 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin"))
106 origin.setValue(0, 0, 0)
107 dirx = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX"))
108 dirx.setValue(1, 0, 0)
109 diry = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirY"))
110 diry.setValue(0, 1, 0)
111 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm"))
112 norm.setValue(0, 0, 1)
113 aSketchLineA = aQuadrangleSketchFeature.addFeature("SketchLine")
114 aSketchLineB = aQuadrangleSketchFeature.addFeature("SketchLine")
115 aSketchLineC = aQuadrangleSketchFeature.addFeature("SketchLine")
116 aSketchLineD = aQuadrangleSketchFeature.addFeature("SketchLine")
117 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
118 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
119 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
120 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
121 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
122 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
123 aLineDStartPoint = geomDataAPI_Point2D(aSketchLineD.attribute("StartPoint"))
124 aLineDEndPoint = geomDataAPI_Point2D(aSketchLineD.attribute("EndPoint"))
125 aLineAStartPoint.setValue(0., 0.)
126 aLineAEndPoint.setValue(0., 100.)
127 aLineBStartPoint.setValue(0., 100.)
128 aLineBEndPoint.setValue(100., 100.)
129 aLineCStartPoint.setValue(100., 100.)
130 aLineCEndPoint.setValue(100., 0.)
131 aLineDStartPoint.setValue(100., 0.)
132 aLineDEndPoint.setValue(0., 0.)
133
134 aSession.finishOperation()
135 aSession.startOperation()
136
137 #=========================================================================
138 # Build a big box extrusion
139 #=========================================================================
140 aSketchResult = aQuadrangleSketchFeature.firstResult()
141 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
142 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin")).pnt()
143 dirX = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX")).dir()
144 dirY = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirY")).dir()
145 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm")).dir()
146 aSketchFaces = ShapeList()
147 GeomAlgoAPI_SketchBuilder.createFaces(
148     origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
149 # Create extrusion on them
150 aBox = aPart.addFeature("Extrusion")
151 aBox.selection("extrusion_face").setValue(
152     aSketchResult, aSketchFaces[0])
153 aBox.real("extrusion_size").setValue(10)
154 aBox.boolean("extrusion_reverse").setValue(False)
155
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 #=========================================================================