Salome HOME
High level objects history implementation for Translation, Rotation and Scale features.
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBooleanSmash.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 #=========================================================================
22 # Initialization of the test
23 #=========================================================================
24 from ModelAPI import *
25 from GeomDataAPI import *
26 from GeomAlgoAPI import *
27 from GeomAPI import *
28
29 aSession = ModelAPI_Session.get()
30 # Create a part for extrusions & boolean
31 aSession.startOperation()
32 aPartFeature = aSession.moduleDocument().addFeature("Part")
33 aSession.finishOperation()
34 aPart = aSession.activeDocument()
35 #=========================================================================
36 # Create a sketch with circle to extrude
37 #=========================================================================
38 aSession.startOperation()
39 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
40 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
41 origin.setValue(0, 0, 0)
42 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
43 dirx.setValue(1, 0, 0)
44 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
45 norm.setValue(0, 0, 1)
46 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
47 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
48 aCircleRadius = aSketchCircle.real("circle_radius")
49 anCircleCentr.setValue(10., 10.)
50 aCircleRadius.setValue(50.)
51 aSession.finishOperation()
52 #=========================================================================
53 # Create a sketch with triangle to extrude
54 #=========================================================================
55 aSession.startOperation()
56 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
57 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
58 origin.setValue(0, 0, 0)
59 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
60 dirx.setValue(1, 0, 0)
61 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
62 norm.setValue(0, 0, 1)
63 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
64 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
65 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
66 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
67 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
68 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
69 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
70 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
71 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
72 aLineAStartPoint.setValue(25., 25.)
73 aLineAEndPoint.setValue(100., 25.)
74 aLineBStartPoint.setValue(100., 25.)
75 aLineBEndPoint.setValue(60., 75.)
76 aLineCStartPoint.setValue(60., 75.)
77 aLineCEndPoint.setValue(25., 25.)
78 aSession.finishOperation()
79 #=========================================================================
80 # Make extrusion on circle (cylinder) and triangle (prism)
81 #=========================================================================
82 # Build shape from sketcher results
83 aSession.startOperation()
84 extrudedObjects = []
85 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
86     # Build sketch faces
87     aSketchResult = modelAPI_ResultConstruction(eachSketchFeature.firstResult())
88     # Create extrusion on them
89     anExtrusionFt = aPart.addFeature("Extrusion")
90     anExtrusionFt.selectionList("base").append(
91         aSketchResult, aSketchResult.face(0))
92     anExtrusionFt.string("CreationMethod").setValue("BySizes")
93     anExtrusionFt.real("from_size").setValue(0)
94     anExtrusionFt.real("to_size").setValue(50)
95     anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
96     anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
97     anExtrusionFt.execute()
98     extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
99 aSession.finishOperation()
100 #=========================================================================
101 # Smash prism into the cylinder
102 #=========================================================================
103 aSession.startOperation()
104 aBooleanFt = aPart.addFeature("Smash")
105 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0], extrudedObjects[0].shape())
106 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], extrudedObjects[1].shape())
107 aBooleanFt.execute()
108 aSession.finishOperation()
109
110 assert (len(aBooleanFt.results()) > 0)
111 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
112 assert (aBooleanResult is not None)
113 #=========================================================================
114 # End of test
115 #=========================================================================
116
117 from salome.shaper import model
118 assert(model.checkPythonDump())