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_B(), ModelAPI_AttributeRefList::typeId());
29 data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefAttrList::typeId());
32 from GeomDataAPI import *
33 from ModelAPI import *
35 from salome.shaper import model
37 #=========================================================================
39 #=========================================================================
42 def createSketch1(theSketch):
43 global aEndPoint1, aEndPoint2
44 # Initialize sketch by three lines with coincident boundaries
47 aSession.startOperation()
49 aSketchLine1 = theSketch.addFeature("SketchLine")
50 aStartPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint"))
51 aEndPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint"))
52 aStartPoint1.setValue(-10., -10.)
53 aEndPoint1.setValue(-10., 10.)
54 allFeatures.append(aSketchLine1)
56 aSketchLine2 = theSketch.addFeature("SketchLine")
57 aStartPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("StartPoint"))
58 aEndPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint"))
59 aStartPoint2.setValue(-10., 10.)
60 aEndPoint2.setValue(10., 10.)
61 allFeatures.append(aSketchLine2)
63 aSketchLine3 = theSketch.addFeature("SketchLine")
64 aStartPoint3 = geomDataAPI_Point2D(aSketchLine3.attribute("StartPoint"))
65 aEndPoint3 = geomDataAPI_Point2D(aSketchLine3.attribute("EndPoint"))
66 aStartPoint3.setValue(10., 10.)
67 aEndPoint3.setValue(10., -10.)
68 allFeatures.append(aSketchLine3)
70 aCoincidence1 = theSketch.addFeature("SketchConstraintCoincidence")
71 aCoincidence1.refattr("ConstraintEntityA").setAttr(aEndPoint1)
72 aCoincidence1.refattr("ConstraintEntityB").setAttr(aStartPoint2)
74 aCoincidence2 = theSketch.addFeature("SketchConstraintCoincidence")
75 aCoincidence2.refattr("ConstraintEntityA").setAttr(aEndPoint2)
76 aCoincidence2.refattr("ConstraintEntityB").setAttr(aStartPoint3)
78 aSession.finishOperation()
82 def createSketch2(theSketch):
84 # Initialize sketch by line and arc with coincident boundary
87 aSession.startOperation()
89 aSketchLine = theSketch.addFeature("SketchLine")
90 aStartPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
91 aEndPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
92 aStartPoint1.setValue(10., 10.)
93 aEndPoint1.setValue(30., 15.)
94 allFeatures.append(aSketchLine)
96 aSketchArc = theSketch.addFeature("SketchArc")
97 aStartPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
98 aEndPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
99 aCenterPoint = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
100 aCenterPoint.setValue(20., 10.)
101 aStartPoint2.setValue(10., 10.)
102 aEndPoint2.setValue(20., 0.)
103 allFeatures.append(aSketchArc)
105 aCoincidence = theSketch.addFeature("SketchConstraintCoincidence")
106 aCoincidence.refattr("ConstraintEntityA").setAttr(aStartPoint1)
107 aCoincidence.refattr("ConstraintEntityB").setAttr(aStartPoint2)
109 aSession.finishOperation()
112 def checkSmoothness(theSketch):
113 aPtPtCoincidences = getCoincidences(theSketch)
114 for coinc in aPtPtCoincidences:
115 aConnectedFeatures = connectedFeatures(coinc)
116 assert(len(aConnectedFeatures) == 2)
117 if aConnectedFeatures[0].getKind() == "SketchArc":
118 if aConnectedFeatures[1].getKind() == "SketchArc":
119 checkArcArcSmoothness(aConnectedFeatures[0], aConnectedFeatures[1])
120 elif aConnectedFeatures[1].getKind() == "SketchLine":
121 checkArcLineSmoothness(aConnectedFeatures[0], aConnectedFeatures[1])
122 elif aConnectedFeatures[0].getKind() == "SketchLine" and aConnectedFeatures[1].getKind() == "SketchArc":
123 checkArcLineSmoothness(aConnectedFeatures[1], aConnectedFeatures[0])
125 def checkArcLineSmoothness(theArc, theLine):
126 aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
127 aDistance = model.distancePointLine(aCenter, theLine)
128 aRadius = arcRadius(theArc)
129 assert(math.fabs(aRadius - aDistance) < TOLERANCE)
131 def checkArcArcSmoothness(theArc1, theArc2):
132 aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point"))
133 aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point"))
134 aDistance = model.distancePointPoint(aCenter1, aCenter2)
135 aRadius1 = arcRadius(theArc1)
136 aRadius2 = arcRadius(theArc2)
137 aRadSum = aRadius1 + aRadius2
138 aRadDiff = math.fabs(aRadius1 - aRadius2)
139 assert(math.fabs(aDistance - aRadSum) < TOLERANCE or math.fabs(aDistance - aRadDiff) < TOLERANCE)
141 def getCoincidences(theSketch):
143 for anIndex in range(0, theSketch.numberOfSubs()):
144 aSubFeature = theSketch.subFeature(anIndex)
145 if aSubFeature.getKind() == "SketchConstraintCoincidence":
146 anEntityA = aSubFeature.refattr("ConstraintEntityA")
147 anEntityB = aSubFeature.refattr("ConstraintEntityB")
148 if not anEntityA.isObject() and not anEntityB.isObject():
149 aCoincidences.append(aSubFeature)
152 def connectedFeatures(theCoincidence):
153 anEntityA = theCoincidence.refattr("ConstraintEntityA")
154 anEntityB = theCoincidence.refattr("ConstraintEntityB")
155 aFeatureA = ModelAPI.ModelAPI_Feature.feature(anEntityA.attr().owner())
156 aFeatureB = ModelAPI.ModelAPI_Feature.feature(anEntityB.attr().owner())
157 return [aFeatureA, aFeatureB]
159 def arcRadius(theArc):
160 aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
161 aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
162 return model.distancePointPoint(aCenter, aStart)
165 #=========================================================================
166 # Initialization of the test
167 #=========================================================================
169 __updated__ = "2015-09-18"
171 aSession = ModelAPI_Session.get()
172 aDocument = aSession.moduleDocument()
173 #=========================================================================
174 # Creation of a sketch
175 #=========================================================================
176 aSession.startOperation()
177 aSketchCommonFeature = aDocument.addFeature("Sketch")
178 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
179 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
180 origin.setValue(0, 0, 0)
181 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
182 dirx.setValue(1, 0, 0)
183 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
184 norm.setValue(0, 0, 1)
185 aSession.finishOperation()
186 #=========================================================================
187 # Initialize sketch by three connected lines
188 #=========================================================================
189 createSketch1(aSketchFeature)
190 assert (model.dof(aSketchFeature) == 8)
191 #=========================================================================
193 #=========================================================================
194 aSession.startOperation()
195 aFillet = aSketchFeature.addFeature("SketchFillet")
196 aFillet.refattr("fillet_point").setAttr(aEndPoint1);
197 aSession.finishOperation()
198 aSession.startOperation()
199 aFillet = aSketchFeature.addFeature("SketchFillet")
200 aFillet.refattr("fillet_point").setAttr(aEndPoint2);
201 aSession.finishOperation()
202 #=========================================================================
203 # Verify the objects of fillet are created
204 #=========================================================================
205 checkSmoothness(aSketchFeature)
206 assert (model.dof(aSketchFeature) == 10)
207 #=========================================================================
208 # Move a line and check the fillet is correct
209 #=========================================================================
210 DELTA_X = DELTA_Y = 10.
211 aSession.startOperation()
212 aEndPoint1.setValue(aEndPoint1.x() + DELTA_X, aEndPoint1.y() + DELTA_Y)
213 aSession.finishOperation()
214 checkSmoothness(aSketchFeature)
215 assert (model.dof(aSketchFeature) == 10)
218 #=========================================================================
219 # Create another sketch
220 #=========================================================================
221 aSession.startOperation()
222 aSketchCommonFeature = aDocument.addFeature("Sketch")
223 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
224 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
225 origin.setValue(0, 0, 0)
226 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
227 dirx.setValue(1, 0, 0)
228 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
229 norm.setValue(0, 1, 0)
230 aSession.finishOperation()
231 #=========================================================================
232 # Initialize sketch by line and arc
233 #=========================================================================
234 createSketch2(aSketchFeature)
235 assert (model.dof(aSketchFeature) == 7)
236 #=========================================================================
238 #=========================================================================
239 aSession.startOperation()
240 aFillet = aSketchFeature.addFeature("SketchFillet")
241 aFillet.refattr("fillet_point").setAttr(aStartPoint1)
242 aSession.finishOperation()
243 #=========================================================================
244 # Verify the objects of fillet are created
245 #=========================================================================
246 checkSmoothness(aSketchFeature)
247 assert (model.dof(aSketchFeature) == 8)
248 #=========================================================================
249 # Move a line and check the fillet is correct
250 #=========================================================================
253 aSession.startOperation()
254 aStartPoint1.setValue(aStartPoint1.x() + DELTA_X, aStartPoint1.y() + DELTA_Y)
255 aSession.finishOperation()
256 checkSmoothness(aSketchFeature)
257 assert (model.dof(aSketchFeature) == 8)
258 #=========================================================================
260 #=========================================================================
262 # TODO: Improve Fillet test case by moving one of filleted objectes and check coincidence and tangency are correct
264 assert(model.checkPythonDump())