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
25 class FeaturesPlugin_Boolean
26 static const std::string MY_ID("Boolean");
27 static const std::string MY_OBJECT_ID("main_object");
28 static const std::string MY_TOOL_ID("tool_object");
29 static const std::string MY_TYPE_ID("bool_type");
31 data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::typeId());
32 data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::typeId());
33 data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::typeId());
35 #=========================================================================
36 # Initialization of the test
37 #=========================================================================
38 from ModelAPI import *
39 from GeomDataAPI import *
40 from GeomAlgoAPI import *
43 __updated__ = "2014-12-16"
45 aSession = ModelAPI_Session.get()
46 # Create a part for extrusions & boolean
47 aSession.startOperation()
48 aPartFeature = aSession.moduleDocument().addFeature("Part")
49 aSession.finishOperation()
50 aPart = aSession.activeDocument()
51 #=========================================================================
52 # Create a sketch with circle to extrude
53 #=========================================================================
54 aSession.startOperation()
55 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
56 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
57 origin.setValue(0, 0, 0)
58 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
59 dirx.setValue(1, 0, 0)
60 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
61 norm.setValue(0, 0, 1)
62 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
63 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
64 aCircleRadius = aSketchCircle.real("circle_radius")
65 anCircleCentr.setValue(10., 10.)
66 aCircleRadius.setValue(50.)
67 aSession.finishOperation()
68 #=========================================================================
69 # Create a sketch with triangle to extrude
70 #=========================================================================
71 aSession.startOperation()
72 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
73 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
74 origin.setValue(0, 0, 0)
75 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
76 dirx.setValue(1, 0, 0)
77 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
78 norm.setValue(0, 0, 1)
79 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
80 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
81 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
82 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
83 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
84 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
85 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
86 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
87 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
88 aLineAStartPoint.setValue(25., 25.)
89 aLineAEndPoint.setValue(100., 25.)
90 aLineBStartPoint.setValue(100., 25.)
91 aLineBEndPoint.setValue(60., 75.)
92 aLineCStartPoint.setValue(60., 75.)
93 aLineCEndPoint.setValue(25., 25.)
94 aSession.finishOperation()
95 #=========================================================================
96 # Make extrusion on circle (cylinder) and triangle (prism)
97 #=========================================================================
98 # Build shape from sketcher results
99 aSession.startOperation()
101 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
103 aSketchResult = eachSketchFeature.firstResult()
104 aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
105 origin = geomDataAPI_Point(eachSketchFeature.attribute("Origin")).pnt()
106 dirX = geomDataAPI_Dir(eachSketchFeature.attribute("DirX")).dir()
107 norm = geomDataAPI_Dir(eachSketchFeature.attribute("Norm")).dir()
108 aSketchFaces = ShapeList()
109 GeomAlgoAPI_SketchBuilder.createFaces(
110 origin, dirX, norm, aSketchEdges, aSketchFaces)
111 # Create extrusion on them
112 anExtrusionFt = aPart.addFeature("Extrusion")
113 anExtrusionFt.selectionList("base").append(
114 aSketchResult, aSketchFaces[0])
115 anExtrusionFt.string("CreationMethod").setValue("BySizes")
116 anExtrusionFt.real("from_size").setValue(0)
117 anExtrusionFt.real("to_size").setValue(50)
118 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
119 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
120 anExtrusionFt.execute()
121 extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
122 aSession.finishOperation()
123 #=========================================================================
124 # Create a pacman as boolean cut of the prism from the cylinder
125 #=========================================================================
126 aSession.startOperation()
127 aBooleanFt = aPart.addFeature("Boolean")
128 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0], extrudedObjects[0].shape())
129 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], extrudedObjects[1].shape())
131 aBooleanFt.integer("bool_type").setValue(kBooleanTypeCut)
133 aSession.finishOperation()
135 assert (len(aBooleanFt.results()) > 0)
136 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
137 assert (aBooleanResult is not None)
138 #=========================================================================
140 #=========================================================================
142 from salome.shaper import model
145 partSet = model.moduleDocument()
146 Part_1 = model.addPart(partSet)
147 Part_1_doc = Part_1.document()
148 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
149 SketchCircle_1 = Sketch_1.addCircle(-353.344768439108, 0.857632933105, 175.14200032067)
151 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
152 SketchCircle_2 = Sketch_2.addCircle(-126.929674099485, -2.572898799314, 176.971885556791)
154 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f"), model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection(), 10, 0)
155 Boolean_1 = model.addCommon(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_1_2")])
157 assert(len(Boolean_1.results()) > 0)
160 partSet = model.moduleDocument()
161 Part_1 = model.addPart(partSet)
162 Part_1_doc = Part_1.document()
163 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
164 SketchCircle_1 = Sketch_1.addCircle(-353.344768439108, 0.857632933105, 175.14200032067)
166 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
167 SketchCircle_2 = Sketch_2.addCircle(-126.929674099485, -2.572898799314, 176.971885556791)
169 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f"), model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection(), 10, 0)
170 Boolean_1 = model.addSmash(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_1_2")])
172 assert(len(Boolean_1.results()) > 0)
174 assert(model.checkPythonDump())