Salome HOME
Fix small issues found by regressions in unit tests
[modules/shaper.git] / src / BuildPlugin / Test / TestWire.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 # Initialization of the test
22 from ModelAPI import *
23 from GeomDataAPI import *
24 from GeomAlgoAPI import *
25 from GeomAPI import *
26
27 # Get document
28 aSession = ModelAPI_Session.get()
29 aDocument = aSession.moduleDocument()
30
31 # Create a part
32 aSession.startOperation()
33 aPartFeature = aDocument.addFeature("Part")
34 aSession.finishOperation()
35 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
36 aPart = aPartResult.partDoc()
37
38 # =============================================================================
39 # Test 1. Create wire from edges of sketch
40 # =============================================================================
41
42 # Create a sketch
43 aSession.startOperation()
44 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
45 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
46 anOrigin.setValue(0, 0, 0)
47 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
48 aDirX.setValue(1, 0, 0)
49 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
50 aNorm.setValue(0, 0, 1)
51
52 # Create lines
53 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
54 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
55 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
56 aSketchLineStartPoint.setValue(0, 0)
57 aSketchLineEndPoint.setValue(0, 50)
58 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
59 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
60 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
61 aSketchLineStartPoint.setValue(0, 50)
62 aSketchLineEndPoint.setValue(50, 50)
63 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
64 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
65 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
66 aSketchLineStartPoint.setValue(50, 50)
67 aSketchLineEndPoint.setValue(50, 0)
68 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
69 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
70 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
71 aSketchLineStartPoint.setValue(50, 0)
72 aSketchLineEndPoint.setValue(0, 0)
73 aSession.finishOperation()
74 aSketchResult = aSketchFeature.firstResult()
75 aSketchShape = aSketchResult.shape()
76
77 # Create wire
78 aSession.startOperation()
79 aWireFeature = aPart.addFeature("Wire")
80 aBaseObjectsList = aWireFeature.selectionList("base_objects")
81 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
82 if aShapeExplorer.more():
83     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
84 aWireFeature.customAction("add_contour")
85 aSession.finishOperation()
86
87 # Test results
88 assert (len(aWireFeature.results()) > 0)
89
90 from salome.shaper import model
91
92 # =============================================================================
93 # Test 2. Complete contour by selecting only one edge
94 # =============================================================================
95
96 model.begin()
97 partSet = model.moduleDocument()
98 Part_1 = model.addPart(partSet)
99 Part_1_doc = Part_1.document()
100 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
101 SketchLine_1 = Sketch_1.addLine(-68.61063464837, 232.418524871355, -488.85077186964, 232.418524871355)
102 SketchLine_2 = Sketch_1.addLine(-488.85077186964, 232.418524871355, -488.85077186964, -153.516295025729)
103 SketchLine_3 = Sketch_1.addLine(-488.85077186964, -153.516295025729, -68.61063464837, -153.516295025729)
104 SketchLine_4 = Sketch_1.addLine(-68.61063464837, -153.516295025729, -68.61063464837, 232.418524871355)
105 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
106 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
107 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
108 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
109 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
110 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
111 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
112 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
113 model.do()
114 Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1")])
115 Wire_1.addContour()
116 model.end()
117
118 # =============================================================================
119 # Test 3. Create wire from edges of solid
120 # =============================================================================
121
122 # Box
123 aSession.startOperation()
124 aBox = aPart.addFeature("Box")
125 aBox.string("CreationMethod").setValue("BoxByDimensions")
126 aBox.real("dx").setValue(20)
127 aBox.real("dy").setValue(20)
128 aBox.real("dz").setValue(20)
129 aSession.finishOperation()
130 aBoxResult = aBox.firstResult()
131 aBoxShape = aBoxResult.shape()
132
133 # Wire
134 aSession.startOperation()
135 aWireFeature2 = aPart.addFeature("Wire")
136 aBaseObjectsList = aWireFeature2.selectionList("base_objects")
137 aBaseObjectsList.append("[Box_1_1/Front][Box_1_1/Bottom]", "EDGE")
138 aBaseObjectsList.append("[Box_1_1/Front][Box_1_1/Right]", "EDGE")
139 aBaseObjectsList.append("[Box_1_1/Right][Box_1_1/Top]", "EDGE")
140 aBaseObjectsList.append("[Box_1_1/Back][Box_1_1/Top]", "EDGE")
141 aBaseObjectsList.append("[Box_1_1/Back][Box_1_1/Left]", "EDGE")
142 aBaseObjectsList.append("[Box_1_1/Left][Box_1_1/Bottom]", "EDGE")
143 aSession.finishOperation()
144
145 # Test results
146 assert (len(aWireFeature2.results()) == 1)
147
148 # =============================================================================
149 # Test 4. Check Wire feature failed on incorrect input
150 # =============================================================================
151
152 aSession.startOperation()
153 aWireFeature3 = aPart.addFeature("Wire")
154 aBaseObjectsList = aWireFeature3.selectionList("base_objects")
155 aBaseObjectsList.append(aSketchResult, None)
156 aSession.finishOperation()
157 assert (len(aWireFeature3.results()) == 0)
158
159 aSession.startOperation()
160 aBaseObjectsList.clear()
161 aShapeExplorer = GeomAPI_ShapeExplorer(aBoxShape, GeomAPI_Shape.VERTEX)
162 aShape = aShapeExplorer.current()
163 aBaseObjectsList.append(aBoxResult, aShape)
164 aSession.finishOperation()
165 assert (len(aWireFeature3.results()) == 0)
166
167 aSession.startOperation()
168 aBaseObjectsList.clear()
169 aShapeExplorer = GeomAPI_ShapeExplorer(aBoxShape, GeomAPI_Shape.FACE)
170 aShape = aShapeExplorer.current()
171 aBaseObjectsList.append(aBoxResult, aShape)
172 aSession.finishOperation()
173 assert (len(aWireFeature3.results()) == 0)
174
175 # remove failed feature
176 aSession.startOperation()
177 aPart.removeFeature(aWireFeature3)
178 aSession.finishOperation()
179
180 assert(model.checkPythonDump(model.ModelHighAPI.CHECK_NAMING))