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