Salome HOME
Merge branch 'Pre_2.8.0_development'
[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 # Create a sketch
39 aSession.startOperation()
40 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
41 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
42 anOrigin.setValue(0, 0, 0)
43 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
44 aDirX.setValue(1, 0, 0)
45 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
46 aNorm.setValue(0, 0, 1)
47
48 # Create lines
49 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
50 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
51 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
52 aSketchLineStartPoint.setValue(0, 0)
53 aSketchLineEndPoint.setValue(0, 50)
54 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
55 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
56 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
57 aSketchLineStartPoint.setValue(0, 50)
58 aSketchLineEndPoint.setValue(50, 50)
59 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
60 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
61 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
62 aSketchLineStartPoint.setValue(50, 50)
63 aSketchLineEndPoint.setValue(50, 0)
64 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
65 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
66 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
67 aSketchLineStartPoint.setValue(50, 0)
68 aSketchLineEndPoint.setValue(0, 0)
69 aSession.finishOperation()
70 aSketchResult = aSketchFeature.firstResult()
71 aSketchShape = aSketchResult.shape()
72
73 # Create wire
74 aSession.startOperation()
75 aWireFeature = aPart.addFeature("Wire")
76 aBaseObjectsList = aWireFeature.selectionList("base_objects")
77 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
78 if aShapeExplorer.more():
79     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
80 aWireFeature.customAction("add_contour")
81 aSession.finishOperation()
82
83 # Test results
84 assert (len(aWireFeature.results()) > 0)
85
86 from salome.shaper import model
87
88 model.begin()
89 partSet = model.moduleDocument()
90 Part_1 = model.addPart(partSet)
91 Part_1_doc = Part_1.document()
92 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
93 SketchLine_1 = Sketch_1.addLine(-68.61063464837, 232.418524871355, -488.85077186964, 232.418524871355)
94 SketchLine_2 = Sketch_1.addLine(-488.85077186964, 232.418524871355, -488.85077186964, -153.516295025729)
95 SketchLine_3 = Sketch_1.addLine(-488.85077186964, -153.516295025729, -68.61063464837, -153.516295025729)
96 SketchLine_4 = Sketch_1.addLine(-68.61063464837, -153.516295025729, -68.61063464837, 232.418524871355)
97 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
98 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
99 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
100 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
101 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
102 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
103 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
104 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
105 model.do()
106 Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/Edge-SketchLine_1")])
107 Wire_1.addContour()
108 model.end()
109
110 assert(model.checkPythonDump())