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