Salome HOME
65df8848fd831e847d067953d886f103e6ed65ad
[modules/shaper.git] / src / FeaturesPlugin / Test / TestRemoveSubShapes.py
1 # Copyright (C) 2014-2023  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 email : webmaster.salome@opencascade.com
18 #
19
20 #=========================================================================
21 # Initialization of the test
22 #=========================================================================
23 from ModelAPI import *
24 from GeomDataAPI import *
25 from GeomAlgoAPI import *
26 from GeomAPI import *
27 import math
28
29 aSession = ModelAPI_Session.get()
30 aDocument = aSession.moduleDocument()
31
32 # Create a part for extrusion
33 aSession.startOperation()
34 aPartFeature = aDocument.addFeature("Part")
35 aSession.finishOperation()
36 assert (len(aPartFeature.results()) == 1)
37
38 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
39 aPart = aPartResult.partDoc()
40
41 #=========================================================================
42 # Create a sketch to extrude
43 #=========================================================================
44 aSession.startOperation()
45 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
46 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
47 origin.setValue(0, 0, 0)
48 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
49 dirx.setValue(1, 0, 0)
50 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
51 norm.setValue(0, 0, 1)
52
53 # Create circles
54 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
55 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
56 aCircleRadius = aSketchCircle.real("circle_radius")
57 anCircleCentr.setValue(-25, 0)
58 aCircleRadius.setValue(50)
59 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
60 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
61 aCircleRadius = aSketchCircle.real("circle_radius")
62 anCircleCentr.setValue(25, 0)
63 aCircleRadius.setValue(50)
64 aSession.finishOperation()
65 aSketchResult = aSketchFeature.firstResult()
66
67 #=========================================================================
68 # Make extrusion on sketch
69 #=========================================================================
70 # Create extrusion
71 aSession.startOperation()
72 anExtrusionFeature = aPart.addFeature("Extrusion")
73 anExtrusionFeature.selectionList("base").append(aSketchResult, None)
74 anExtrusionFeature.string("CreationMethod").setValue("BySizes")
75 anExtrusionFeature.real("to_size").setValue(50)
76 anExtrusionFeature.real("from_size").setValue(0)
77 anExtrusionFeature.real("to_offset").setValue(0) #TODO: remove
78 anExtrusionFeature.real("from_offset").setValue(0) #TODO: remove
79 anExtrusionFeature.execute()
80 aSession.finishOperation()
81 anExtrusionResult = modelAPI_ResultBody(anExtrusionFeature.firstResult())
82
83 #=========================================================================
84 # Remove sub-shapes
85 #=========================================================================
86 aSession.startOperation()
87 aRemoveSubShapesFeature = aPart.addFeature("Remove_SubShapes")
88 aRemoveSubShapesFeature.selection("base_shape").setValue(anExtrusionResult, None)
89 aRemoveSubShapesFeature.string("creation_method").setValue("by_keep_subshapes")
90 aRemoveSubShapesFeature.selectionList("subshapes_to_keep").removeLast();
91 aSession.finishOperation()
92 assert (len(aRemoveSubShapesFeature.results()) > 0)
93 anUnionResult = modelAPI_ResultBody(aRemoveSubShapesFeature.firstResult())
94 assert (anUnionResult.numberOfSubs() == 2)
95
96 from salome.shaper import model
97 assert(model.checkPythonDump())