3 Unit test of FeaturesPlugin_Boolean class: many Boolean operations performance
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");
11 data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::typeId());
12 data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::typeId());
13 data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId());
16 # Number rows and columns of cylinders that cuts the big box. Number of Boolena operations is N*N
19 #=========================================================================
20 # Initialization of the test
21 #=========================================================================
23 from GeomAlgoAPI import *
24 from GeomDataAPI import *
25 from ModelAPI import *
28 __updated__ = "2015-03-26"
30 aSession = ModelAPI_Session.get()
31 aDocument = aSession.moduleDocument()
32 # Create a part for extrusion
33 aSession.startOperation()
34 aPartFeature = aDocument.addFeature("Part")
35 aSession.finishOperation()
36 assert (len(aPartFeature.results()) == 1)
38 # aPart = aSession.activeDocument()
39 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
40 aPart = aPartResult.partDoc()
42 #=========================================================================
43 # Create a list of sketches with one circle inside of each to extrude
44 #=========================================================================
48 aSession.startOperation()
50 for i in xrange(0, N):
51 for j in xrange(0, N):
53 aSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
54 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
55 origin.setValue(0, 0, 0)
56 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
57 dirx.setValue(1, 0, 0)
58 diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
59 diry.setValue(0, 1, 0)
60 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
61 norm.setValue(0, 0, 1)
62 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
63 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
64 aCircleRadius = aSketchCircle.real("CircleRadius")
65 anCircleCentr.setValue(0.5 + step * (0.5 + i), 0.5 + step * (0.5 + j))
66 aCircleRadius.setValue(radius)
67 aSketchFeatures.append(aSketchFeature)
69 aSession.finishOperation()
71 #=========================================================================
72 # Make extrusions on circles
73 #=========================================================================
74 # Build shape from sketcher results
77 aSession.startOperation()
80 for i in xrange(0, N * N):
81 aSketchResult = aSketchFeatures[i].firstResult()
82 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
83 origin = geomDataAPI_Point(aSketchFeatures[i].attribute("Origin")).pnt()
84 dirX = geomDataAPI_Dir(aSketchFeatures[i].attribute("DirX")).dir()
85 dirY = geomDataAPI_Dir(aSketchFeatures[i].attribute("DirY")).dir()
86 norm = geomDataAPI_Dir(aSketchFeatures[i].attribute("Norm")).dir()
87 aSketchFaces = ShapeList()
88 GeomAlgoAPI_SketchBuilder.createFaces(
89 origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
91 anExtrusionFt = aPart.addFeature("Extrusion")
92 assert (anExtrusionFt.getKind() == "Extrusion")
94 anExtrusionFt.selectionList("base").append(
95 aSketchResult, aSketchFaces[0])
96 anExtrusionFt.real("size").setValue(10)
97 anExtrusionFt.boolean("reverse").setValue(False)
99 # anExtrusionFt.selection("extrusion_face").setValue(
100 # aSketchResult, aSketchFaces[0])
101 # anExtrusionFt.real("extrusion_size").setValue(10)
102 # anExtrusionFt.boolean("extrusion_reverse").setValue(False)
103 anExtrusions.append(anExtrusionFt)
105 aSession.finishOperation()
107 #=========================================================================
108 # Make rectangle sketch: base for the box, size 100x100
109 #=========================================================================
110 aSession.startOperation()
111 aQuadrangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
112 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin"))
113 origin.setValue(0, 0, 0)
114 dirx = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX"))
115 dirx.setValue(1, 0, 0)
116 diry = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirY"))
117 diry.setValue(0, 1, 0)
118 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm"))
119 norm.setValue(0, 0, 1)
120 aSketchLineA = aQuadrangleSketchFeature.addFeature("SketchLine")
121 aSketchLineB = aQuadrangleSketchFeature.addFeature("SketchLine")
122 aSketchLineC = aQuadrangleSketchFeature.addFeature("SketchLine")
123 aSketchLineD = aQuadrangleSketchFeature.addFeature("SketchLine")
124 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
125 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
126 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
127 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
128 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
129 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
130 aLineDStartPoint = geomDataAPI_Point2D(aSketchLineD.attribute("StartPoint"))
131 aLineDEndPoint = geomDataAPI_Point2D(aSketchLineD.attribute("EndPoint"))
132 aLineAStartPoint.setValue(0., 0.)
133 aLineAEndPoint.setValue(0., 100.)
134 aLineBStartPoint.setValue(0., 100.)
135 aLineBEndPoint.setValue(100., 100.)
136 aLineCStartPoint.setValue(100., 100.)
137 aLineCEndPoint.setValue(100., 0.)
138 aLineDStartPoint.setValue(100., 0.)
139 aLineDEndPoint.setValue(0., 0.)
141 aSession.finishOperation()
142 aSession.startOperation()
144 #=========================================================================
145 # Build a big box extrusion
146 #=========================================================================
147 aSketchResult = aQuadrangleSketchFeature.firstResult()
148 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
149 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin")).pnt()
150 dirX = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX")).dir()
151 dirY = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirY")).dir()
152 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm")).dir()
153 aSketchFaces = ShapeList()
154 GeomAlgoAPI_SketchBuilder.createFaces(
155 origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
156 # Create extrusion on them
157 aBox = aPart.addFeature("Extrusion")
158 aBox.selectionList("base").append(
159 aSketchResult, aSketchFaces[0])
160 aBox.real("size").setValue(10)
161 aBox.boolean("reverse").setValue(False)
162 # v 1.0.2 from master
163 # aBox.selection("extrusion_face").setValue(
164 # aSketchResult, aSketchFaces[0])
165 # aBox.real("extrusion_size").setValue(10)
166 # aBox.boolean("extrusion_reverse").setValue(False)
168 aSession.finishOperation()
171 #=========================================================================
172 # Create a boolean cut of cylinders from the box:
173 # result of Boolean is the first argument of the next Boolean
174 #=========================================================================
175 aCurrentResult = aBox.firstResult()
176 aSession.startOperation()
177 for i in xrange(0, N * N):
178 aBooleanFt = aPart.addFeature("Boolean")
179 aBooleanFt.reference("main_object").setValue(modelAPI_ResultBody(aCurrentResult))
180 aBooleanFt.reference("tool_object").setValue(modelAPI_ResultBody(anExtrusions[i].firstResult()))
182 aBooleanFt.integer("bool_type").setValue(kBooleanTypeCut)
184 aCurrentResult = aBooleanFt.firstResult()
185 aSession.finishOperation()
187 #=========================================================================
189 #=========================================================================