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