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