Salome HOME
Update copyrights
[modules/shaper.git] / src / BuildPlugin / Test / TestFilling_ByWires.py
1 # Copyright (C) 2017-2019  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 # Initialization of the test
21 from ModelAPI import *
22 from GeomDataAPI import *
23 from GeomAlgoAPI import *
24 from GeomAPI import *
25
26 # Get document
27 aSession = ModelAPI_Session.get()
28 aDocument = aSession.moduleDocument()
29
30 # Create a part
31 aSession.startOperation()
32 aPartFeature = aDocument.addFeature("Part")
33 aSession.finishOperation()
34 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
35 aPart = aPartResult.partDoc()
36
37 # Create first wire in a sketch
38 aSession.startOperation()
39 aSketch1 = featureToCompositeFeature(aPart.addFeature("Sketch"))
40 anOrigin = geomDataAPI_Point(aSketch1.attribute("Origin"))
41 anOrigin.setValue(0, 0, 0)
42 aDirX = geomDataAPI_Dir(aSketch1.attribute("DirX"))
43 aDirX.setValue(1, 0, 0)
44 aNorm = geomDataAPI_Dir(aSketch1.attribute("Norm"))
45 aNorm.setValue(0, 0, 1)
46 # arc 1
47 anArc1 = aSketch1.addFeature("SketchArc")
48 anArcCenter = geomDataAPI_Point2D(anArc1.attribute("center_point"))
49 anArcCenter.setValue(1, 1)
50 anArcStartPoint = geomDataAPI_Point2D(anArc1.attribute("start_point"))
51 anArcStartPoint.setValue(20, 5)
52 anArcEndPoint = geomDataAPI_Point2D(anArc1.attribute("end_point"))
53 anArcEndPoint.setValue(5, 20)
54 # arc 2
55 anArc2 = aSketch1.addFeature("SketchArc")
56 anArcCenter = geomDataAPI_Point2D(anArc2.attribute("center_point"))
57 anArcCenter.setValue(12.5, 12.5)
58 anArcStartPoint = geomDataAPI_Point2D(anArc2.attribute("start_point"))
59 anArcStartPoint.setValue(5, 20)
60 anArcEndPoint = geomDataAPI_Point2D(anArc2.attribute("end_point"))
61 anArcEndPoint.setValue(20, 5)
62 aSession.finishOperation()
63 aSketch1Result = aSketch1.firstResult()
64 # a wire
65 aSession.startOperation()
66 aWire1 = aPart.addFeature("Wire")
67 aBaseObjectsList = aWire1.selectionList("base_objects")
68 aBaseObjectsList.append(aSketch1Result, anArc1.lastResult().shape())
69 aBaseObjectsList.append(aSketch1Result, anArc2.lastResult().shape())
70 aSession.finishOperation()
71
72 # Create second wire in another sketch
73 aSession.startOperation()
74 aSketch2 = featureToCompositeFeature(aPart.addFeature("Sketch"))
75 anOrigin = geomDataAPI_Point(aSketch2.attribute("Origin"))
76 anOrigin.setValue(0, 0, 0)
77 aDirX = geomDataAPI_Dir(aSketch2.attribute("DirX"))
78 aDirX.setValue(1, 0, 0)
79 aNorm = geomDataAPI_Dir(aSketch2.attribute("Norm"))
80 aNorm.setValue(0, 0.7071067811865475, 0.7071067811865475)
81 # line 1
82 aLine1 = aSketch2.addFeature("SketchLine")
83 aLineStartPoint = geomDataAPI_Point2D(aLine1.attribute("StartPoint"))
84 aLineStartPoint.setValue(30, 0)
85 aLineEndPoint = geomDataAPI_Point2D(aLine1.attribute("EndPoint"))
86 aLineEndPoint.setValue(20, 20)
87 # line 2
88 aLine2 = aSketch2.addFeature("SketchLine")
89 aLineStartPoint = geomDataAPI_Point2D(aLine2.attribute("StartPoint"))
90 aLineStartPoint.setValue(20, 20)
91 aLineEndPoint = geomDataAPI_Point2D(aLine2.attribute("EndPoint"))
92 aLineEndPoint.setValue(20, 0)
93 aSession.finishOperation()
94 aSketch2Result = aSketch2.firstResult()
95 # a wire
96 aSession.startOperation()
97 aWire2 = aPart.addFeature("Wire")
98 aBaseObjectsList = aWire2.selectionList("base_objects")
99 aBaseObjectsList.append(aSketch2Result, aLine1.lastResult().shape())
100 aBaseObjectsList.append(aSketch2Result, aLine2.lastResult().shape())
101 aSession.finishOperation()
102
103 # Create filling
104 aSession.startOperation()
105 aFillingFeature = aPart.addFeature("Filling")
106 aFillingFeature.string("advanced_options").setValue("")
107 aBaseObjectsList = aFillingFeature.selectionList("base_objects")
108 aBaseObjectsList.append(aWire1.lastResult(), None)
109 aSession.finishOperation()
110
111 # =============================================================================
112 # Test 1. Filling on one wire is failed (no result is built)
113 # =============================================================================
114 assert(len(aFillingFeature.results()) == 0)
115
116 # =============================================================================
117 # Test 2. Add another wire, filling should be completed
118 # =============================================================================
119 aSession.startOperation()
120 aBaseObjectsList.append(aWire2.lastResult(), None)
121 aSession.finishOperation()
122 assert(len(aFillingFeature.results()) > 0)
123
124 # =============================================================================
125 # Test 3. Change parameters one-by-one and check validity of result
126 # =============================================================================
127 aSession.startOperation()
128 aFillingFeature.string("advanced_options").setValue("true")
129 aSession.finishOperation()
130 orientations = ["auto_correct", "curve_info", "edge_orient"]
131 tolerances = [0.0001, 0.001]
132 for ori in orientations:
133   for minDeg in range(2, 4):
134     for maxDeg in range(5, 7):
135       for nbIter in range(0, 3, 2):
136         for tol2d in tolerances:
137           for tol3d in tolerances:
138             for approx in [False, True]:
139               aSession.startOperation()
140               aFillingFeature.string("orientation").setValue(ori)
141               aFillingFeature.integer("min_degree").setValue(minDeg)
142               aFillingFeature.integer("max_degree").setValue(maxDeg)
143               aFillingFeature.integer("nb_iter").setValue(nbIter)
144               aFillingFeature.real("tol_2d").setValue(tol2d)
145               aFillingFeature.real("tol_3d").setValue(tol3d)
146               aFillingFeature.boolean("approximation").setValue(approx)
147               aSession.finishOperation()
148               assert(len(aFillingFeature.results()) > 0), "Filling feature failed with parameters:\n  orientation={}\n  min deg={}\n  max deg={}\n  nb iter={}\n  tol 2d={}\n  tol 3d={}\n  approximation={}".format(ori, minDeg, maxDeg, nbIter, tol2d, tol3d, approx)
149
150 from salome.shaper import model
151 assert(model.checkPythonDump())