1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
23 Unit test of SketchPlugin_Fillet class
26 static const std::string MY_CONSTRAINT_FILLET_ID("SketchFillet");
27 data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
28 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());
29 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId());
30 data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefAttrList::typeId());
33 from GeomDataAPI import *
34 from ModelAPI import *
36 from salome.shaper import model
38 #=========================================================================
40 #=========================================================================
43 def createSketch1(theSketch):
44 global aEndPoint1, aEndPoint2
45 # Initialize sketch by three lines with coincident boundaries
48 aSession.startOperation()
50 aSketchLine1 = theSketch.addFeature("SketchLine")
51 aStartPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint"))
52 aEndPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint"))
53 aStartPoint1.setValue(-10., -10.)
54 aEndPoint1.setValue(-10., 10.)
55 allFeatures.append(aSketchLine1)
57 aSketchLine2 = theSketch.addFeature("SketchLine")
58 aStartPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("StartPoint"))
59 aEndPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint"))
60 aStartPoint2.setValue(-10., 10.)
61 aEndPoint2.setValue(10., 10.)
62 allFeatures.append(aSketchLine2)
64 aSketchLine3 = theSketch.addFeature("SketchLine")
65 aStartPoint3 = geomDataAPI_Point2D(aSketchLine3.attribute("StartPoint"))
66 aEndPoint3 = geomDataAPI_Point2D(aSketchLine3.attribute("EndPoint"))
67 aStartPoint3.setValue(10., 10.)
68 aEndPoint3.setValue(10., -10.)
69 allFeatures.append(aSketchLine3)
71 aCoincidence1 = theSketch.addFeature("SketchConstraintCoincidence")
72 aCoincidence1.refattr("ConstraintEntityA").setAttr(aEndPoint1)
73 aCoincidence1.refattr("ConstraintEntityB").setAttr(aStartPoint2)
75 aCoincidence2 = theSketch.addFeature("SketchConstraintCoincidence")
76 aCoincidence2.refattr("ConstraintEntityA").setAttr(aEndPoint2)
77 aCoincidence2.refattr("ConstraintEntityB").setAttr(aStartPoint3)
79 aSession.finishOperation()
83 def createSketch2(theSketch):
85 # Initialize sketch by line and arc with coincident boundary
88 aSession.startOperation()
90 aSketchLine = theSketch.addFeature("SketchLine")
91 aStartPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
92 aEndPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
93 aStartPoint1.setValue(10., 10.)
94 aEndPoint1.setValue(30., 15.)
95 allFeatures.append(aSketchLine)
97 aSketchArc = theSketch.addFeature("SketchArc")
98 aStartPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
99 aEndPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
100 aCenterPoint = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
101 aCenterPoint.setValue(20., 10.)
102 aStartPoint2.setValue(10., 10.)
103 aEndPoint2.setValue(20., 0.)
104 allFeatures.append(aSketchArc)
106 aCoincidence = theSketch.addFeature("SketchConstraintCoincidence")
107 aCoincidence.refattr("ConstraintEntityA").setAttr(aStartPoint1)
108 aCoincidence.refattr("ConstraintEntityB").setAttr(aStartPoint2)
110 aSession.finishOperation()
113 def checkSmoothness(theSketch):
114 aPtPtCoincidences = getCoincidences(theSketch)
115 for coinc in aPtPtCoincidences:
116 aConnectedFeatures = connectedFeatures(coinc)
117 assert(len(aConnectedFeatures) == 2)
118 if aConnectedFeatures[0].getKind() == "SketchArc":
119 if aConnectedFeatures[1].getKind() == "SketchArc":
120 checkArcArcSmoothness(aConnectedFeatures[0], aConnectedFeatures[1])
121 elif aConnectedFeatures[1].getKind() == "SketchLine":
122 checkArcLineSmoothness(aConnectedFeatures[0], aConnectedFeatures[1])
123 elif aConnectedFeatures[0].getKind() == "SketchLine" and aConnectedFeatures[1].getKind() == "SketchArc":
124 checkArcLineSmoothness(aConnectedFeatures[1], aConnectedFeatures[0])
126 def checkArcLineSmoothness(theArc, theLine):
127 aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
128 aDistance = model.distancePointLine(aCenter, theLine)
129 aRadius = arcRadius(theArc)
130 assert(math.fabs(aRadius - aDistance) < TOLERANCE)
132 def checkArcArcSmoothness(theArc1, theArc2):
133 aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point"))
134 aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point"))
135 aDistance = model.distancePointPoint(aCenter1, aCenter2)
136 aRadius1 = arcRadius(theArc1)
137 aRadius2 = arcRadius(theArc2)
138 aRadSum = aRadius1 + aRadius2
139 aRadDiff = math.fabs(aRadius1 - aRadius2)
140 assert(math.fabs(aDistance - aRadSum) < TOLERANCE or math.fabs(aDistance - aRadDiff) < TOLERANCE)
142 def getCoincidences(theSketch):
144 for anIndex in range(0, theSketch.numberOfSubs()):
145 aSubFeature = theSketch.subFeature(anIndex)
146 if aSubFeature.getKind() == "SketchConstraintCoincidence":
147 anEntityA = aSubFeature.refattr("ConstraintEntityA")
148 anEntityB = aSubFeature.refattr("ConstraintEntityB")
149 if not anEntityA.isObject() and not anEntityB.isObject():
150 aCoincidences.append(aSubFeature)
153 def connectedFeatures(theCoincidence):
154 anEntityA = theCoincidence.refattr("ConstraintEntityA")
155 anEntityB = theCoincidence.refattr("ConstraintEntityB")
156 aFeatureA = ModelAPI.ModelAPI_Feature.feature(anEntityA.attr().owner())
157 aFeatureB = ModelAPI.ModelAPI_Feature.feature(anEntityB.attr().owner())
158 return [aFeatureA, aFeatureB]
160 def arcRadius(theArc):
161 aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
162 aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
163 return model.distancePointPoint(aCenter, aStart)
166 #=========================================================================
167 # Initialization of the test
168 #=========================================================================
170 __updated__ = "2015-09-18"
172 aSession = ModelAPI_Session.get()
173 aDocument = aSession.moduleDocument()
174 #=========================================================================
175 # Creation of a sketch
176 #=========================================================================
177 aSession.startOperation()
178 aSketchCommonFeature = aDocument.addFeature("Sketch")
179 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
180 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
181 origin.setValue(0, 0, 0)
182 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
183 dirx.setValue(1, 0, 0)
184 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
185 norm.setValue(0, 0, 1)
186 aSession.finishOperation()
187 #=========================================================================
188 # Initialize sketch by three connected lines
189 #=========================================================================
190 createSketch1(aSketchFeature)
191 assert (model.dof(aSketchFeature) == 8)
192 #=========================================================================
194 #=========================================================================
195 aSession.startOperation()
196 aFillet = aSketchFeature.addFeature("SketchFillet")
197 aFillet.refattr("fillet_point").setAttr(aEndPoint1);
198 aSession.finishOperation()
199 aSession.startOperation()
200 aFillet = aSketchFeature.addFeature("SketchFillet")
201 aFillet.refattr("fillet_point").setAttr(aEndPoint2);
202 aSession.finishOperation()
203 #=========================================================================
204 # Verify the objects of fillet are created
205 #=========================================================================
206 checkSmoothness(aSketchFeature)
207 assert (model.dof(aSketchFeature) == 10)
208 #=========================================================================
209 # Move a line and check the fillet is correct
210 #=========================================================================
211 DELTA_X = DELTA_Y = 10.
212 aSession.startOperation()
213 aEndPoint1.setValue(aEndPoint1.x() + DELTA_X, aEndPoint1.y() + DELTA_Y)
214 aSession.finishOperation()
215 checkSmoothness(aSketchFeature)
216 assert (model.dof(aSketchFeature) == 10)
219 #=========================================================================
220 # Create another sketch
221 #=========================================================================
222 aSession.startOperation()
223 aSketchCommonFeature = aDocument.addFeature("Sketch")
224 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
225 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
226 origin.setValue(0, 0, 0)
227 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
228 dirx.setValue(1, 0, 0)
229 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
230 norm.setValue(0, 1, 0)
231 aSession.finishOperation()
232 #=========================================================================
233 # Initialize sketch by line and arc
234 #=========================================================================
235 createSketch2(aSketchFeature)
236 assert (model.dof(aSketchFeature) == 7)
237 #=========================================================================
239 #=========================================================================
240 aSession.startOperation()
241 aFillet = aSketchFeature.addFeature("SketchFillet")
242 aFillet.refattr("fillet_point").setAttr(aStartPoint1)
243 aSession.finishOperation()
244 #=========================================================================
245 # Verify the objects of fillet are created
246 #=========================================================================
247 checkSmoothness(aSketchFeature)
248 assert (model.dof(aSketchFeature) == 8)
249 #=========================================================================
250 # Move a line and check the fillet is correct
251 #=========================================================================
254 aSession.startOperation()
255 aStartPoint1.setValue(aStartPoint1.x() + DELTA_X, aStartPoint1.y() + DELTA_Y)
256 aSession.finishOperation()
257 checkSmoothness(aSketchFeature)
258 assert (model.dof(aSketchFeature) == 8)
259 #=========================================================================
261 #=========================================================================
263 # TODO: Improve Fillet test case by moving one of filleted objectes and check coincidence and tangency are correct
265 assert(model.checkPythonDump())