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::type());
12 data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
13 data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
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 #=========================================================================
22 from ModelAPI import *
23 from GeomDataAPI import *
24 from GeomAlgoAPI import *
27 __updated__ = "2015-02-25"
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)
37 # aPart = aSession.activeDocument()
38 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
39 aPart = aPartResult.partDoc()
41 #=========================================================================
42 # Create a list of sketches with one circle inside of each to extrude
43 #=========================================================================
47 aSession.startOperation()
49 for i in xrange(0, N):
50 for j in xrange(0, N):
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)
68 aSession.finishOperation()
70 #=========================================================================
71 # Make extrusions on circles
72 #=========================================================================
73 # Build shape from sketcher results
76 aSession.startOperation()
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)
90 anExtrusionFt = aPart.addFeature("Extrusion")
91 assert (anExtrusionFt.getKind() == "Extrusion")
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)
99 aSession.finishOperation()
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.)
135 aSession.finishOperation()
136 aSession.startOperation()
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()
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()))
170 aBooleanFt.integer("bool_type").setValue(kBooleanTypeCut)
172 aCurrentResult = aBooleanFt.firstResult()
173 aSession.finishOperation()
175 #=========================================================================
177 #=========================================================================