1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## Lesser General Public License for more details.
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
23 Unit test of FeaturesPlugin_Boolean class: many Boolean operations performance
25 class FeaturesPlugin_Extrusion : public ModelAPI_Feature
26 static const std::string MY_EXTRUSION_ID("Extrusion");
27 static const std::string MY_FACE_ID("base");
28 static const std::string MY_SIZE_ID("size");
29 static const std::string MY_REVERSE_ID("reverse");
31 data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::typeId());
32 data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::typeId());
33 data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId());
36 # Number rows and columns of cylinders that cuts the big box. Number of Boolena operations is N*N
39 #=========================================================================
40 # Initialization of the test
41 #=========================================================================
43 from GeomAlgoAPI import *
44 from GeomDataAPI import *
45 from ModelAPI import *
48 __updated__ = "2015-03-26"
50 aSession = ModelAPI_Session.get()
51 aDocument = aSession.moduleDocument()
52 # Create a part for extrusion
53 aSession.startOperation()
54 aPartFeature = aDocument.addFeature("Part")
55 aSession.finishOperation()
56 assert (len(aPartFeature.results()) == 1)
58 # aPart = aSession.activeDocument()
59 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
60 aPart = aPartResult.partDoc()
62 #=========================================================================
63 # Create a list of sketches with one circle inside of each to extrude
64 #=========================================================================
68 aSession.startOperation()
73 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
74 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
75 origin.setValue(0, 0, 0)
76 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
77 dirx.setValue(1, 0, 0)
78 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
79 norm.setValue(0, 0, 1)
80 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
81 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
82 aCircleRadius = aSketchCircle.real("circle_radius")
83 anCircleCentr.setValue(0.5 + step * (0.5 + i), 0.5 + step * (0.5 + j))
84 aCircleRadius.setValue(radius)
85 aSketchFeatures.append(aSketchFeature)
87 aSession.finishOperation()
89 #=========================================================================
90 # Make extrusions on circles
91 #=========================================================================
92 # Build shape from sketcher results
95 aSession.startOperation()
98 for i in range(0, N * N):
99 aSketchResult = aSketchFeatures[i].firstResult()
100 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
101 origin = geomDataAPI_Point(aSketchFeatures[i].attribute("Origin")).pnt()
102 dirX = geomDataAPI_Dir(aSketchFeatures[i].attribute("DirX")).dir()
103 norm = geomDataAPI_Dir(aSketchFeatures[i].attribute("Norm")).dir()
104 aSketchFaces = ShapeList()
105 GeomAlgoAPI_SketchBuilder.createFaces(
106 origin, dirX, norm, aSketchEdges, aSketchFaces)
108 anExtrusionFt = aPart.addFeature("Extrusion")
109 assert (anExtrusionFt.getKind() == "Extrusion")
111 anExtrusionFt.selectionList("base").append(
112 aSketchResult, aSketchFaces[0])
113 anExtrusionFt.string("CreationMethod").setValue("BySizes")
114 anExtrusionFt.real("from_size").setValue(0)
115 anExtrusionFt.real("to_size").setValue(10)
116 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
117 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
119 # anExtrusionFt.selection("extrusion_face").setValue(
120 # aSketchResult, aSketchFaces[0])
121 # anExtrusionFt.real("extrusion_size").setValue(10)
122 # anExtrusionFt.boolean("extrusion_reverse").setValue(False)
123 anExtrusions.append(anExtrusionFt)
125 aSession.finishOperation()
127 #=========================================================================
128 # Make rectangle sketch: base for the box, size 100x100
129 #=========================================================================
130 aSession.startOperation()
131 aQuadrangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
132 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin"))
133 origin.setValue(0, 0, 0)
134 dirx = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX"))
135 dirx.setValue(1, 0, 0)
136 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm"))
137 norm.setValue(0, 0, 1)
138 aSketchLineA = aQuadrangleSketchFeature.addFeature("SketchLine")
139 aSketchLineB = aQuadrangleSketchFeature.addFeature("SketchLine")
140 aSketchLineC = aQuadrangleSketchFeature.addFeature("SketchLine")
141 aSketchLineD = aQuadrangleSketchFeature.addFeature("SketchLine")
142 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
143 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
144 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
145 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
146 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
147 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
148 aLineDStartPoint = geomDataAPI_Point2D(aSketchLineD.attribute("StartPoint"))
149 aLineDEndPoint = geomDataAPI_Point2D(aSketchLineD.attribute("EndPoint"))
150 aLineAStartPoint.setValue(0., 0.)
151 aLineAEndPoint.setValue(0., 100.)
152 aLineBStartPoint.setValue(0., 100.)
153 aLineBEndPoint.setValue(100., 100.)
154 aLineCStartPoint.setValue(100., 100.)
155 aLineCEndPoint.setValue(100., 0.)
156 aLineDStartPoint.setValue(100., 0.)
157 aLineDEndPoint.setValue(0., 0.)
159 aSession.finishOperation()
160 aSession.startOperation()
162 #=========================================================================
163 # Build a big box extrusion
164 #=========================================================================
165 aSketchResult = aQuadrangleSketchFeature.firstResult()
166 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
167 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin")).pnt()
168 dirX = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX")).dir()
169 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm")).dir()
170 aSketchFaces = ShapeList()
171 GeomAlgoAPI_SketchBuilder.createFaces(
172 origin, dirX, norm, aSketchEdges, aSketchFaces)
173 # Create extrusion on them
174 aBox = aPart.addFeature("Extrusion")
175 aBox.selectionList("base").append(
176 aSketchResult, aSketchFaces[0])
177 aBox.string("CreationMethod").setValue("BySizes")
178 aBox.real("from_size").setValue(0)
179 aBox.real("to_size").setValue(10)
180 aBox.real("to_offset").setValue(0) #TODO: remove
181 aBox.real("from_offset").setValue(0) #TODO: remove
182 # v 1.0.2 from master
183 # aBox.selection("extrusion_face").setValue(
184 # aSketchResult, aSketchFaces[0])
185 # aBox.real("extrusion_size").setValue(10)
186 # aBox.boolean("extrusion_reverse").setValue(False)
188 aSession.finishOperation()
191 #=========================================================================
192 # Create a boolean cut of cylinders from the box:
193 # result of Boolean is the first argument of the next Boolean
194 #=========================================================================
195 aCurrentResult = modelAPI_ResultBody(aBox.firstResult())
196 aSession.startOperation()
197 aFactory = ModelAPI_Session.get().validators()
198 for i in range(0, N * N):
199 anExtrusionResult = modelAPI_ResultBody(anExtrusions[i].firstResult())
200 aBooleanFt = aPart.addFeature("Cut")
201 aBooleanFt.selectionList("main_objects").append(aCurrentResult, aCurrentResult.shape())
202 aBooleanFt.selectionList("tool_objects").append(anExtrusionResult, anExtrusionResult.shape())
204 assert (aFactory.validate(aBooleanFt))
205 assert (len(aBooleanFt.results()) > 0)
206 aCurrentResult = modelAPI_ResultBody(aBooleanFt.firstResult())
207 assert (aCurrentResult is not None)
208 aSession.finishOperation()
210 #=========================================================================
212 #=========================================================================
214 from salome.shaper import model
215 assert(model.checkPythonDump())