Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestPlacement_Edge_Vertex.py
1 # Copyright (C) 2014-2023  CEA, EDF
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 __updated__ = "2014-12-16"
30
31 aSession = ModelAPI_Session.get()
32 aDocument = aSession.moduleDocument()
33
34 aSession.startOperation()
35 aPartFeature = aDocument.addFeature("Part")
36 aSession.finishOperation()
37 assert (len(aPartFeature.results()) == 1)
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 aLineA1 = aSketchFeature.addFeature("SketchLine")
53 aLineB1 = aSketchFeature.addFeature("SketchLine")
54 aLineC1 = aSketchFeature.addFeature("SketchLine")
55 aLineD1 = aSketchFeature.addFeature("SketchLine")
56 aLineA1StartPoint = geomDataAPI_Point2D(aLineA1.attribute("StartPoint"))
57 aLineA1EndPoint = geomDataAPI_Point2D(aLineA1.attribute("EndPoint"))
58 aLineB1StartPoint = geomDataAPI_Point2D(aLineB1.attribute("StartPoint"))
59 aLineB1EndPoint = geomDataAPI_Point2D(aLineB1.attribute("EndPoint"))
60 aLineC1StartPoint = geomDataAPI_Point2D(aLineC1.attribute("StartPoint"))
61 aLineC1EndPoint = geomDataAPI_Point2D(aLineC1.attribute("EndPoint"))
62 aLineD1StartPoint = geomDataAPI_Point2D(aLineD1.attribute("StartPoint"))
63 aLineD1EndPoint = geomDataAPI_Point2D(aLineD1.attribute("EndPoint"))
64 aLineA1StartPoint.setValue(-100, 0)
65 aLineA1EndPoint.setValue(-50, 0)
66 aLineB1StartPoint.setValue(-50, 0)
67 aLineB1EndPoint.setValue(-50, 50)
68 aLineC1StartPoint.setValue(-50, 50)
69 aLineC1EndPoint.setValue(-100, 50)
70 aLineD1StartPoint.setValue(-100, 50)
71 aLineD1EndPoint.setValue(-100, 0)
72 aLineA2 = aSketchFeature.addFeature("SketchLine")
73 aLineB2 = aSketchFeature.addFeature("SketchLine")
74 aLineC2 = aSketchFeature.addFeature("SketchLine")
75 aLineD2 = aSketchFeature.addFeature("SketchLine")
76 aLineA2StartPoint = geomDataAPI_Point2D(aLineA2.attribute("StartPoint"))
77 aLineA2EndPoint = geomDataAPI_Point2D(aLineA2.attribute("EndPoint"))
78 aLineB2StartPoint = geomDataAPI_Point2D(aLineB2.attribute("StartPoint"))
79 aLineB2EndPoint = geomDataAPI_Point2D(aLineB2.attribute("EndPoint"))
80 aLineC2StartPoint = geomDataAPI_Point2D(aLineC2.attribute("StartPoint"))
81 aLineC2EndPoint = geomDataAPI_Point2D(aLineC2.attribute("EndPoint"))
82 aLineD2StartPoint = geomDataAPI_Point2D(aLineD2.attribute("StartPoint"))
83 aLineD2EndPoint = geomDataAPI_Point2D(aLineD2.attribute("EndPoint"))
84 aLineA2StartPoint.setValue(100, 0)
85 aLineA2EndPoint.setValue(50, 0)
86 aLineB2StartPoint.setValue(50, 0)
87 aLineB2EndPoint.setValue(50, 50)
88 aLineC2StartPoint.setValue(50, 50)
89 aLineC2EndPoint.setValue(100, 50)
90 aLineD2StartPoint.setValue(100, 50)
91 aLineD2EndPoint.setValue(100, 0)
92 aSession.finishOperation()
93
94 #=========================================================================
95 # Make extrusion
96 #=========================================================================
97 aSketchResult = modelAPI_ResultConstruction(aSketchFeature.firstResult())
98 assert (aSketchResult.facesNum() > 1)
99
100 aSession.startOperation()
101 anExtrusionFt = aPart.addFeature("Extrusion")
102 assert (anExtrusionFt.getKind() == "Extrusion")
103 anExtrusionFt.selectionList("base").append(aSketchResult, aSketchResult.face(0))
104 anExtrusionFt.selectionList("base").append(aSketchResult, aSketchResult.face(1))
105 anExtrusionFt.string("CreationMethod").setValue("BySizes")
106 anExtrusionFt.real("to_size").setValue(50)
107 anExtrusionFt.real("from_size").setValue(0)
108 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
109 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
110 anExtrusionFt.execute()
111 aSession.finishOperation()
112 assert (anExtrusionFt.real("to_size").value() == 50.0)
113
114 # Check extrusion results
115 assert (len(anExtrusionFt.results()) > 0)
116 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
117 assert (anExtrusionResult is not None)
118
119 #=========================================================================
120 # Test placement by edge - vertex
121 #=========================================================================
122 aSession.startOperation()
123 aPlacementFt = aPart.addFeature("Placement")
124 aPlacementFt.selectionList("placement_objects_list").append(anExtrusionResult, anExtrusionResult.shape())
125 aPlacementFt.selection("placement_start_shape").selectSubShape("edge", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]")
126 aPlacementFt.selection("placement_end_shape").selectSubShape("vertex", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_2/To_Face]")
127 aPlacementFt.boolean("placement_reverse_direction").setValue(False)
128 aPlacementFt.boolean("placement_centering").setValue(True)
129 aPlacementFt.execute()
130 aSession.finishOperation()
131
132 # Check placement results
133 assert (len(aPlacementFt.results()) > 0)
134 aPlacementResult = modelAPI_ResultBody(aPlacementFt.firstResult())
135 assert (aPlacementResult is not None)
136
137 from salome.shaper import model
138 assert(model.checkPythonDump())