1 # Copyright (C) 2014-2019 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 aSession = ModelAPI_Session.get()
29 # Create a part for extrusions & boolean
30 aSession.startOperation()
31 aPartFeature = aSession.moduleDocument().addFeature("Part")
32 aSession.finishOperation()
33 aPart = aSession.activeDocument()
34 #=========================================================================
35 # Create a sketch with circle to extrude
36 #=========================================================================
37 aSession.startOperation()
38 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
39 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
40 origin.setValue(0, 0, 0)
41 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
42 dirx.setValue(1, 0, 0)
43 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
44 norm.setValue(0, 0, 1)
45 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
46 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
47 aCircleRadius = aSketchCircle.real("circle_radius")
48 anCircleCentr.setValue(10., 10.)
49 aCircleRadius.setValue(50.)
50 aSession.finishOperation()
51 #=========================================================================
52 # Create a sketch with triangle to extrude
53 #=========================================================================
54 aSession.startOperation()
55 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
56 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
57 origin.setValue(0, 0, 0)
58 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
59 dirx.setValue(1, 0, 0)
60 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
61 norm.setValue(0, 0, 1)
62 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
63 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
64 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
65 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
66 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
67 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
68 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
69 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
70 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
71 aLineAStartPoint.setValue(25., 25.)
72 aLineAEndPoint.setValue(100., 25.)
73 aLineBStartPoint.setValue(100., 25.)
74 aLineBEndPoint.setValue(60., 75.)
75 aLineCStartPoint.setValue(60., 75.)
76 aLineCEndPoint.setValue(25., 25.)
77 aSession.finishOperation()
78 #=========================================================================
79 # Make extrusion on circle (cylinder) and triangle (prism)
80 #=========================================================================
81 # Build shape from sketcher results
82 aSession.startOperation()
84 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
86 aSketchResult = modelAPI_ResultConstruction(eachSketchFeature.firstResult())
87 # Create extrusion on them
88 anExtrusionFt = aPart.addFeature("Extrusion")
89 anExtrusionFt.selectionList("base").append(
90 aSketchResult, aSketchResult.face(0))
91 anExtrusionFt.string("CreationMethod").setValue("BySizes")
92 anExtrusionFt.real("from_size").setValue(0)
93 anExtrusionFt.real("to_size").setValue(50)
94 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
95 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
96 anExtrusionFt.execute()
97 extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
98 aSession.finishOperation()
99 #=========================================================================
100 # Smash prism into the cylinder
101 #=========================================================================
102 aSession.startOperation()
103 aBooleanFt = aPart.addFeature("Smash")
104 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0], extrudedObjects[0].shape())
105 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], extrudedObjects[1].shape())
107 aSession.finishOperation()
109 assert (len(aBooleanFt.results()) > 0)
110 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
111 assert (aBooleanResult is not None)
112 #=========================================================================
114 #=========================================================================
116 from salome.shaper import model
117 assert(model.checkPythonDump())