1 # Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
20 #=========================================================================
21 # Initialization of the test
22 #=========================================================================
23 from ModelAPI import *
24 from GeomDataAPI import *
25 from GeomAlgoAPI import *
28 __updated__ = "2014-12-16"
30 aSession = ModelAPI_Session.get()
31 # Create a part for extrusions & boolean
32 aSession.startOperation()
33 aPartFeature = aSession.moduleDocument().addFeature("Part")
34 aSession.finishOperation()
35 aPart = aSession.activeDocument()
36 #=========================================================================
37 # Create a sketch with circle to extrude
38 #=========================================================================
39 aSession.startOperation()
40 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
41 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
42 origin.setValue(0, 0, 0)
43 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
44 dirx.setValue(1, 0, 0)
45 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
46 norm.setValue(0, 0, 1)
48 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
49 aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
50 aCircleRadius = aSketchCircle.real("circle_radius")
51 aCircleCentr.setValue(0, 0)
52 aCircleRadius.setValue(50)
54 aSketchLine = aCircleSketchFeature.addFeature("SketchLine")
55 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
56 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
57 aLineStartPoint.setValue(0, -50)
58 aLineEndPoint.setValue(0, 50)
59 aSession.finishOperation()
60 #=========================================================================
61 # Create a sketch with triangle to extrude
62 #=========================================================================
63 aSession.startOperation()
64 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
65 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
66 origin.setValue(0, 0, 0)
67 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
68 dirx.setValue(1, 0, 0)
69 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
70 norm.setValue(0, 0, 1)
71 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
72 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
73 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
74 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
75 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
76 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
77 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
78 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
79 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
80 aLineAStartPoint.setValue(25., 25.)
81 aLineAEndPoint.setValue(100., 25.)
82 aLineBStartPoint.setValue(100., 25.)
83 aLineBEndPoint.setValue(60., 75.)
84 aLineCStartPoint.setValue(60., 75.)
85 aLineCEndPoint.setValue(25., 25.)
86 aSession.finishOperation()
87 #=========================================================================
88 # Make extrusion on circle (cylinder) and triangle (prism)
89 #=========================================================================
90 # Build shape from sketcher results
91 aSession.startOperation()
93 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
95 aSketchResult = modelAPI_ResultConstruction(eachSketchFeature.firstResult())
96 # Create extrusion on them
97 anExtrusionFt = aPart.addFeature("Extrusion")
98 anExtrusionFt.selectionList("base").append(
100 anExtrusionFt.string("CreationMethod").setValue("BySizes")
101 anExtrusionFt.real("from_size").setValue(0)
102 anExtrusionFt.real("to_size").setValue(50)
103 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
104 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
105 anExtrusionFt.execute()
106 extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
107 aSession.finishOperation()
108 #=========================================================================
109 # Create a pacman as boolean cut of the prism from the cylinder
110 #=========================================================================
111 aSession.startOperation()
112 aBooleanFt = aPart.addFeature("Cut")
113 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0].subResult(1), None)
114 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
116 aSession.finishOperation()
118 assert (len(aBooleanFt.results()) > 0)
119 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
120 assert (aBooleanResult is not None)
123 #=========================================================================
125 #=========================================================================
126 aSession.startOperation()
127 aBooleanFt = aPart.addFeature("Fuse")
128 aBooleanFt.string("creation_method").setValue("advanced")
129 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0].subResult(1), None)
130 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
131 aBooleanFt.boolean("remove_intersection_edges").setValue(False)
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
143 assert(model.checkPythonDump())