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 = featureToCompositeFeature(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 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
59 norm.setValue(0, 0, 1)
60 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
61 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
62 aCircleRadius = aSketchCircle.real("CircleRadius")
63 anCircleCentr.setValue(0.5 + step * (0.5 + i), 0.5 + step * (0.5 + j))
64 aCircleRadius.setValue(radius)
65 aSketchFeatures.append(aSketchFeature)
67 aSession.finishOperation()
69 #=========================================================================
70 # Make extrusions on circles
71 #=========================================================================
72 # Build shape from sketcher results
75 aSession.startOperation()
78 for i in xrange(0, N * N):
79 aSketchResult = aSketchFeatures[i].firstResult()
80 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
81 origin = geomDataAPI_Point(aSketchFeatures[i].attribute("Origin")).pnt()
82 dirX = geomDataAPI_Dir(aSketchFeatures[i].attribute("DirX")).dir()
83 norm = geomDataAPI_Dir(aSketchFeatures[i].attribute("Norm")).dir()
84 aSketchFaces = ShapeList()
85 GeomAlgoAPI_SketchBuilder.createFaces(
86 origin, dirX, norm, aSketchEdges, aSketchFaces)
88 anExtrusionFt = aPart.addFeature("Extrusion")
89 assert (anExtrusionFt.getKind() == "Extrusion")
91 anExtrusionFt.selectionList("base").append(
92 aSketchResult, aSketchFaces[0])
93 anExtrusionFt.real("from_size").setValue(0)
94 anExtrusionFt.real("to_size").setValue(10)
96 # anExtrusionFt.selection("extrusion_face").setValue(
97 # aSketchResult, aSketchFaces[0])
98 # anExtrusionFt.real("extrusion_size").setValue(10)
99 # anExtrusionFt.boolean("extrusion_reverse").setValue(False)
100 anExtrusions.append(anExtrusionFt)
102 aSession.finishOperation()
104 #=========================================================================
105 # Make rectangle sketch: base for the box, size 100x100
106 #=========================================================================
107 aSession.startOperation()
108 aQuadrangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
109 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin"))
110 origin.setValue(0, 0, 0)
111 dirx = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX"))
112 dirx.setValue(1, 0, 0)
113 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm"))
114 norm.setValue(0, 0, 1)
115 aSketchLineA = aQuadrangleSketchFeature.addFeature("SketchLine")
116 aSketchLineB = aQuadrangleSketchFeature.addFeature("SketchLine")
117 aSketchLineC = aQuadrangleSketchFeature.addFeature("SketchLine")
118 aSketchLineD = aQuadrangleSketchFeature.addFeature("SketchLine")
119 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
120 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
121 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
122 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
123 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
124 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
125 aLineDStartPoint = geomDataAPI_Point2D(aSketchLineD.attribute("StartPoint"))
126 aLineDEndPoint = geomDataAPI_Point2D(aSketchLineD.attribute("EndPoint"))
127 aLineAStartPoint.setValue(0., 0.)
128 aLineAEndPoint.setValue(0., 100.)
129 aLineBStartPoint.setValue(0., 100.)
130 aLineBEndPoint.setValue(100., 100.)
131 aLineCStartPoint.setValue(100., 100.)
132 aLineCEndPoint.setValue(100., 0.)
133 aLineDStartPoint.setValue(100., 0.)
134 aLineDEndPoint.setValue(0., 0.)
136 aSession.finishOperation()
137 aSession.startOperation()
139 #=========================================================================
140 # Build a big box extrusion
141 #=========================================================================
142 aSketchResult = aQuadrangleSketchFeature.firstResult()
143 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
144 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin")).pnt()
145 dirX = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX")).dir()
146 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm")).dir()
147 aSketchFaces = ShapeList()
148 GeomAlgoAPI_SketchBuilder.createFaces(
149 origin, dirX, 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("from_size").setValue(0)
155 aBox.real("to_size").setValue(10)
156 # v 1.0.2 from master
157 # aBox.selection("extrusion_face").setValue(
158 # aSketchResult, aSketchFaces[0])
159 # aBox.real("extrusion_size").setValue(10)
160 # aBox.boolean("extrusion_reverse").setValue(False)
162 aSession.finishOperation()
165 #=========================================================================
166 # Create a boolean cut of cylinders from the box:
167 # result of Boolean is the first argument of the next Boolean
168 #=========================================================================
169 aCurrentResult = aBox.firstResult()
170 aSession.startOperation()
171 for i in xrange(0, N * N):
172 aBooleanFt = aPart.addFeature("Boolean")
173 aBooleanFt.reference("main_object").setValue(modelAPI_ResultBody(aCurrentResult))
174 aBooleanFt.reference("tool_object").setValue(modelAPI_ResultBody(anExtrusions[i].firstResult()))
176 aBooleanFt.integer("bool_type").setValue(kBooleanTypeCut)
178 aCurrentResult = aBooleanFt.firstResult()
179 aSession.finishOperation()
181 #=========================================================================
183 #=========================================================================