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 = modelAPI_ResultConstruction(aSketchFeatures[i].firstResult())
100 anExtrusionFt = aPart.addFeature("Extrusion")
101 assert (anExtrusionFt.getKind() == "Extrusion")
103 anExtrusionFt.selectionList("base").append(
104 aSketchResult, aSketchResult.face(0))
105 anExtrusionFt.string("CreationMethod").setValue("BySizes")
106 anExtrusionFt.real("from_size").setValue(0)
107 anExtrusionFt.real("to_size").setValue(10)
108 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
109 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
110 anExtrusions.append(anExtrusionFt)
112 aSession.finishOperation()
114 #=========================================================================
115 # Make rectangle sketch: base for the box, size 100x100
116 #=========================================================================
117 aSession.startOperation()
118 aQuadrangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
119 origin = geomDataAPI_Point(aQuadrangleSketchFeature.attribute("Origin"))
120 origin.setValue(0, 0, 0)
121 dirx = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("DirX"))
122 dirx.setValue(1, 0, 0)
123 norm = geomDataAPI_Dir(aQuadrangleSketchFeature.attribute("Norm"))
124 norm.setValue(0, 0, 1)
125 aSketchLineA = aQuadrangleSketchFeature.addFeature("SketchLine")
126 aSketchLineB = aQuadrangleSketchFeature.addFeature("SketchLine")
127 aSketchLineC = aQuadrangleSketchFeature.addFeature("SketchLine")
128 aSketchLineD = aQuadrangleSketchFeature.addFeature("SketchLine")
129 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
130 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
131 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
132 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
133 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
134 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
135 aLineDStartPoint = geomDataAPI_Point2D(aSketchLineD.attribute("StartPoint"))
136 aLineDEndPoint = geomDataAPI_Point2D(aSketchLineD.attribute("EndPoint"))
137 aLineAStartPoint.setValue(0., 0.)
138 aLineAEndPoint.setValue(0., 100.)
139 aLineBStartPoint.setValue(0., 100.)
140 aLineBEndPoint.setValue(100., 100.)
141 aLineCStartPoint.setValue(100., 100.)
142 aLineCEndPoint.setValue(100., 0.)
143 aLineDStartPoint.setValue(100., 0.)
144 aLineDEndPoint.setValue(0., 0.)
146 aSession.finishOperation()
147 aSession.startOperation()
149 #=========================================================================
150 # Build a big box extrusion
151 #=========================================================================
152 aSketchResult = modelAPI_ResultConstruction(aQuadrangleSketchFeature.firstResult())
153 # Create extrusion on them
154 aBox = aPart.addFeature("Extrusion")
155 aBox.selectionList("base").append(
156 aSketchResult, aSketchResult.face(0))
157 aBox.string("CreationMethod").setValue("BySizes")
158 aBox.real("from_size").setValue(0)
159 aBox.real("to_size").setValue(10)
160 aBox.real("to_offset").setValue(0) #TODO: remove
161 aBox.real("from_offset").setValue(0) #TODO: remove
163 aSession.finishOperation()
166 #=========================================================================
167 # Create a boolean cut of cylinders from the box:
168 #=========================================================================
169 aCurrentResult = modelAPI_ResultBody(aBox.firstResult())
170 aSession.startOperation()
172 aBooleanFt = aPart.addFeature("Cut")
173 aBooleanFt.selectionList("main_objects").append(aCurrentResult, aCurrentResult.shape())
174 for i in range(0, N * N):
175 anExtrusionResult = modelAPI_ResultBody(anExtrusions[i].firstResult())
176 aBooleanFt.selectionList("tool_objects").append(anExtrusionResult, anExtrusionResult.shape())
178 aFactory = ModelAPI_Session.get().validators()
179 assert (aFactory.validate(aBooleanFt))
180 assert (len(aBooleanFt.results()) > 0)
181 aCurrentResult = modelAPI_ResultBody(aBooleanFt.firstResult())
182 assert (aCurrentResult is not None)
183 aSession.finishOperation()
185 #=========================================================================
187 #=========================================================================
189 from salome.shaper import model
190 assert(model.checkPythonDump())