Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestCreateCircleChangeType.py
index 52daff262dbdae4ee654dd088d7db8b6156885c3..803561bfc96db13ddb5b8370f7261d8efd164206 100644 (file)
@@ -1,3 +1,22 @@
+# Copyright (C) 2014-2023  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
 """
     TestCreateCircleChangeType.py
 
@@ -23,9 +42,7 @@ __updated__ = "2017-03-22"
 
 def assertNotInitializedByCenterAndPassed(theMacroCircle):
     # check points
-    aCenterPoint = geomDataAPI_Point2D(theMacroCircle.attribute("center_point"))
     aPassedPoint = geomDataAPI_Point2D(theMacroCircle.attribute("passed_point"))
-    assert (not aCenterPoint.isInitialized())
     assert (not aPassedPoint.isInitialized())
     # check references
     aCenterPointRef = theMacroCircle.refattr("center_point_ref")
@@ -49,31 +66,12 @@ def assertNotInitializedByThreePoints(theMacroCircle):
     assert (not aSecondPointRef.isInitialized())
     assert (not aThirdPointRef.isInitialized())
 
-def getLastCircle(theSketch):
-    """
-    obtains last feature from the sketch and generates error if the feature is not a circle
-    """
-    expectedKind = "SketchCircle"
-    for anIndex in range(theSketch.numberOfSubs() - 1, -1, -1):
-        aSub = theSketch.subFeature(anIndex)
-        if (aSub.getKind() == expectedKind):
-            return aSub
-
 def verifyLastCircle(theSketch, theX, theY, theR):
     """
     subroutine to verify position of last circle in the sketch
     """
-    aLastCircle = getLastCircle(theSketch)
-    aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
-    verifyPointCoordinates(aCenter, theX, theY)
-    aRadius = aLastCircle.real("circle_radius")
-    assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
-
-def verifyPointCoordinates(thePoint, theX, theY):
-    assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
-
-def distancePointPoint(thePoint1, thePoint2):
-    return thePoint1.pnt().distance(thePoint2.pnt())
+    aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
+    model.assertCircle(aLastCircle, [theX, theY], theR)
 
 
 #=========================================================================
@@ -182,7 +180,7 @@ aPassedPointRef.setAttr(aLineEnd)
 aPassedPoint.setValue(aLineEnd.pnt())
 aSession.finishOperation()
 
-aRadius = distancePointPoint(aLineStart, aLineEnd)
+aRadius = model.distancePointPoint(aLineStart, aLineEnd)
 NB_FEATURES_EXPECTED = 4 # line, circle and two coincidences
 assert (aSketchFeature.numberOfSubs() == NB_FEATURES_EXPECTED), "Number of features in sketch {}, expected {}".format(aSketchFeature.numberOfSubs(), NB_FEATURES_EXPECTED)
 verifyLastCircle(aSketchFeature, aLineStart.x(), aLineStart.y(), aRadius)