1 # Copyright (C) 2014-2022 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 *
29 aSession = ModelAPI_Session.get()
30 aDocument = aSession.moduleDocument()
31 # Create a part for extrusion
32 aSession.startOperation()
33 aPartFeature = aDocument.addFeature("Part")
34 aSession.finishOperation()
35 assert (len(aPartFeature.results()) == 1)
37 # aPart = aSession.activeDocument()
38 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
39 aPart = aPartResult.partDoc()
41 #=========================================================================
42 # Create a sketch circle to extrude 1
43 #=========================================================================
44 aSession.startOperation()
45 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
46 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
47 origin.setValue(0, 0, 0)
48 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
49 dirx.setValue(1, 0, 0)
50 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
51 norm.setValue(0, 0, 1)
53 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
54 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
55 aCircleRadius = aSketchCircle.real("circle_radius")
56 anCircleCentr.setValue(-10, 0)
57 aCircleRadius.setValue(50)
58 aSession.finishOperation()
60 #=========================================================================
61 # Make extrusion on circle 1
62 #=========================================================================
63 # Build shape from sketcher results
64 aCircleSketchResult = modelAPI_ResultConstruction(aCircleSketchFeature.firstResult())
65 assert (aCircleSketchResult.facesNum() > 0)
67 aSession.startOperation()
68 anExtrusionFt = aPart.addFeature("Extrusion")
69 assert (anExtrusionFt.getKind() == "Extrusion")
70 # selection type FACE=4
71 anExtrusionFt.selectionList("base").append(
72 aCircleSketchResult, aCircleSketchResult.face(0))
73 anExtrusionFt.string("CreationMethod").setValue("BySizes")
74 anExtrusionFt.real("to_size").setValue(50)
75 anExtrusionFt.real("from_size").setValue(0)
76 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
77 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
78 anExtrusionFt.execute()
79 aSession.finishOperation()
80 assert (anExtrusionFt.real("to_size").value() == 50)
82 # Check extrusion results
83 assert (len(anExtrusionFt.results()) > 0)
84 anExtrusionResult1 = modelAPI_ResultBody(anExtrusionFt.firstResult())
85 assert (anExtrusionResult1 is not None)
87 #=========================================================================
88 # Create a sketch circle to extrude 2
89 #=========================================================================
90 aSession.startOperation()
91 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
92 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
93 origin.setValue(0, 0, 0)
94 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
95 dirx.setValue(1, 0, 0)
96 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
97 norm.setValue(0, 0, 1)
99 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
100 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
101 aCircleRadius = aSketchCircle.real("circle_radius")
102 anCircleCentr.setValue(10, 0)
103 aCircleRadius.setValue(50)
104 aSession.finishOperation()
106 #=========================================================================
107 # Make extrusion on circle 2
108 #=========================================================================
109 # Build shape from sketcher results
110 aCircleSketchResult = modelAPI_ResultConstruction(aCircleSketchFeature.firstResult())
111 assert (aCircleSketchResult.facesNum() > 0)
113 aSession.startOperation()
114 anExtrusionFt = aPart.addFeature("Extrusion")
115 assert (anExtrusionFt.getKind() == "Extrusion")
116 # selection type FACE=4
117 anExtrusionFt.selectionList("base").append(
118 aCircleSketchResult, aCircleSketchResult.face(0))
119 anExtrusionFt.string("CreationMethod").setValue("BySizes")
120 anExtrusionFt.real("to_size").setValue(50)
121 anExtrusionFt.real("from_size").setValue(0)
122 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
123 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
124 anExtrusionFt.execute()
125 aSession.finishOperation()
126 assert (anExtrusionFt.real("to_size").value() == 50)
128 # Check extrusion results
129 assert (len(anExtrusionFt.results()) > 0)
130 anExtrusionResult2 = modelAPI_ResultBody(anExtrusionFt.firstResult())
131 assert (anExtrusionResult2 is not None)
133 #=========================================================================
134 # Create an intersection
135 #=========================================================================
136 aSession.startOperation()
137 anIntersectionFt = aPart.addFeature("Intersection")
138 assert (anIntersectionFt.getKind() == "Intersection")
139 anIntersectionFt.selectionList("main_objects").append(anExtrusionResult1, None)
140 anIntersectionFt.selectionList("main_objects").append(anExtrusionResult2, None)
141 anIntersectionFt.execute()
142 aSession.finishOperation()
144 #=========================================================================
146 #=========================================================================
147 aFactory = ModelAPI_Session.get().validators()
148 assert (aFactory.validate(anIntersectionFt))
149 assert (len(anIntersectionFt.results()) > 0)
150 anItersectionResult = modelAPI_ResultBody(anIntersectionFt.firstResult())
151 assert (anItersectionResult is not None)
153 from salome.shaper import model
154 assert(model.checkPythonDump())