Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBoolean1.py
1 # Copyright (C) 2014-2023  CEA, EDF
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 """
21       TestBoolean.py
22       Unit test of FeaturesPlugin_Boolean class
23
24       class FeaturesPlugin_Boolean
25         static const std::string MY_ID("Boolean");
26         static const std::string MY_OBJECT_ID("main_object");
27         static const std::string MY_TOOL_ID("tool_object");
28         static const std::string MY_TYPE_ID("bool_type");
29
30         data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::typeId());
31         data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::typeId());
32         data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::typeId());
33 """
34 #=========================================================================
35 # Initialization of the test
36 #=========================================================================
37 from ModelAPI import *
38 from GeomDataAPI import *
39 from GeomAlgoAPI import *
40 from GeomAPI import *
41
42 __updated__ = "2014-12-16"
43
44 aSession = ModelAPI_Session.get()
45 # Create a part for extrusions & boolean
46 aSession.startOperation()
47 aPartFeature = aSession.moduleDocument().addFeature("Part")
48 aSession.finishOperation()
49 aPart = aSession.activeDocument()
50 #=========================================================================
51 # Create a sketch with circle to extrude
52 #=========================================================================
53 aSession.startOperation()
54 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
55 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
56 origin.setValue(0, 0, 0)
57 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
58 dirx.setValue(1, 0, 0)
59 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
60 norm.setValue(0, 0, 1)
61 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
62 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
63 aCircleRadius = aSketchCircle.real("circle_radius")
64 anCircleCentr.setValue(10., 10.)
65 aCircleRadius.setValue(50.)
66 aSession.finishOperation()
67 #=========================================================================
68 # Create a sketch with triangle to extrude
69 #=========================================================================
70 aSession.startOperation()
71 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
72 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
73 origin.setValue(0, 0, 0)
74 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
75 dirx.setValue(1, 0, 0)
76 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
77 norm.setValue(0, 0, 1)
78 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
79 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
80 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
81 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
82 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
83 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
84 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
85 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
86 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
87 aLineAStartPoint.setValue(25., 25.)
88 aLineAEndPoint.setValue(100., 25.)
89 aLineBStartPoint.setValue(100., 25.)
90 aLineBEndPoint.setValue(60., 75.)
91 aLineCStartPoint.setValue(60., 75.)
92 aLineCEndPoint.setValue(25., 25.)
93 aSession.finishOperation()
94 #=========================================================================
95 # Make extrusion on circle (cylinder) and triangle (prism)
96 #=========================================================================
97 # Build shape from sketcher results
98 aSession.startOperation()
99 extrudedObjects = []
100 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
101     # Build sketch faces
102     aSketchResult = modelAPI_ResultConstruction(eachSketchFeature.firstResult())
103     # Create extrusion on them
104     anExtrusionFt = aPart.addFeature("Extrusion")
105     anExtrusionFt.selectionList("base").append(
106         aSketchResult, aSketchResult.face(0))
107     anExtrusionFt.string("CreationMethod").setValue("BySizes")
108     anExtrusionFt.real("from_size").setValue(0)
109     anExtrusionFt.real("to_size").setValue(50)
110     anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
111     anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
112     anExtrusionFt.execute()
113     extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
114 aSession.finishOperation()
115 #=========================================================================
116 # Create a pacman as boolean cut of the prism from the cylinder
117 #=========================================================================
118 aSession.startOperation()
119 aBooleanFt = aPart.addFeature("Cut")
120 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0], extrudedObjects[0].shape())
121 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], extrudedObjects[1].shape())
122 aBooleanFt.execute()
123 aSession.finishOperation()
124
125 assert (len(aBooleanFt.results()) > 0)
126 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
127 assert (aBooleanResult is not None)
128 #=========================================================================
129 # End of test
130 #=========================================================================
131
132 from salome.shaper import model
133 assert(model.checkPythonDump())