Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 = eachSketchFeature.firstResult()
88     aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
89     origin = geomDataAPI_Point(eachSketchFeature.attribute("Origin")).pnt()
90     dirX = geomDataAPI_Dir(eachSketchFeature.attribute("DirX")).dir()
91     norm = geomDataAPI_Dir(eachSketchFeature.attribute("Norm")).dir()
92     aSketchFaces = ShapeList()
93     GeomAlgoAPI_SketchBuilder.createFaces(
94         origin, dirX, norm, aSketchEdges, aSketchFaces)
95     # Create extrusion on them
96     anExtrusionFt = aPart.addFeature("Extrusion")
97     anExtrusionFt.selectionList("base").append(
98         aSketchResult, aSketchFaces[0])
99     anExtrusionFt.string("CreationMethod").setValue("BySizes")
100     anExtrusionFt.real("from_size").setValue(0)
101     anExtrusionFt.real("to_size").setValue(50)
102     anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
103     anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
104     anExtrusionFt.execute()
105     extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
106 aSession.finishOperation()
107 #=========================================================================
108 # Smash prism into the cylinder
109 #=========================================================================
110 aSession.startOperation()
111 aBooleanFt = aPart.addFeature("Boolean")
112 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0], extrudedObjects[0].shape())
113 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], extrudedObjects[1].shape())
114 kBooleanTypeSmash = 3
115 aBooleanFt.integer("bool_type").setValue(kBooleanTypeSmash)
116 aBooleanFt.execute()
117 aSession.finishOperation()
118
119 assert (len(aBooleanFt.results()) > 0)
120 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
121 assert (aBooleanResult is not None)
122 #=========================================================================
123 # End of test
124 #=========================================================================
125
126 from salome.shaper import model
127 assert(model.checkPythonDump())