Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintCoincidence.py
index f416f5d26a0d5f0a40cb65a3665e91c9447df479..5a7c5a1e893da1c6a80845cc7c2384c8028cfd12 100644 (file)
@@ -1,3 +1,22 @@
+# Copyright (C) 2014-2023  CEA/DEN, EDF R&D
+#
+# 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
+#
+
 """
     TestConstraintCoincidence.py
     Unit test of SketchPlugin_ConstraintCoincidence class
@@ -19,6 +38,8 @@
 from GeomDataAPI import *
 from ModelAPI import *
 import math
+from salome.shaper import model
+
 #=========================================================================
 # Initialization of the test
 #=========================================================================
@@ -40,14 +61,14 @@ def checkPointOnLine(point, line):
     assert (math.fabs(aDirX * aVecY - aDirY * aVecX) <= TOLERANCE)
 
 def checkPointOnCircle(point, circle):
-    aCenter = geomDataAPI_Point2D(circle.attribute("CircleCenter"))
-    aRadius = circle.real("CircleRadius").value()
+    aCenter = geomDataAPI_Point2D(circle.attribute("circle_center"))
+    aRadius = circle.real("circle_radius").value()
     aDist = math.hypot(point.x() - aCenter.x(), point.y() - aCenter.y())
     assert (math.fabs(aDist - aRadius) <= TOLERANCE)
 
 def checkPointOnArc(point, arc):
-    aStart  = geomDataAPI_Point2D(arc.attribute("ArcStartPoint"))
-    aCenter = geomDataAPI_Point2D(arc.attribute("ArcCenter"))
+    aStart  = geomDataAPI_Point2D(arc.attribute("start_point"))
+    aCenter = geomDataAPI_Point2D(arc.attribute("center_point"))
     aRadius = math.hypot(aStart.x() - aCenter.x(), aStart.y() - aCenter.y())
     aDist = math.hypot(point.x() - aCenter.x(), point.y() - aCenter.y())
     assert (math.fabs(aDist - aRadius) <= TOLERANCE)
@@ -61,10 +82,8 @@ aDocument = aSession.moduleDocument()
 # add an origin
 aSession.startOperation()
 aFeature = aDocument.addFeature("Point")
-# aFeature.string("creation_method").setValue("by_xyz")
-aFeature.real("x").setValue(0.)
-aFeature.real("y").setValue(0.)
-aFeature.real("z").setValue(0.)
+geomDataAPI_Point(aFeature.attribute("point3d")).setValue(0., 0., 0.)
+aFeature.string("creation_method").setValue("by_xyz")
 anOriginName = aFeature.name()
 aSession.finishOperation()
 #=========================================================================
@@ -84,9 +103,9 @@ aSession.finishOperation()
 #=========================================================================
 aSession.startOperation()
 aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
 anArcCentr.setValue(10., 10.)
 anArcStartPoint.setValue(0., 50.)
 anArcEndPoint.setValue(50., 0.)
@@ -97,6 +116,7 @@ aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
 aLineStartPoint.setValue(50., 0.)
 aLineEndPoint.setValue(100., 25.)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
 #=========================================================================
 # Link arc's end and line's start points with concidence constraint
 #=========================================================================
@@ -108,6 +128,7 @@ reflistA.setAttr(anArcEndPoint)
 reflistB.setAttr(aLineStartPoint)
 aConstraint.execute()
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 7)
 #=========================================================================
 # Check values and move one constrainted object
 #=========================================================================
@@ -124,6 +145,7 @@ aSession.finishOperation()
 # check that arc's points are moved also
 assert (anArcEndPoint.x() == aLineStartPoint.x())
 assert (anArcEndPoint.y() == aLineStartPoint.y())
+assert (model.dof(aSketchFeature) == 7)
 #=========================================================================
 # Remove coincidence and move the line
 #=========================================================================
@@ -134,6 +156,7 @@ aSession.startOperation()
 aLineStartPoint.setValue(70., 0.)
 aSession.finishOperation()
 assert (anArcEndPoint.x() != aLineStartPoint.x() or anArcEndPoint.y() != aLineStartPoint.y())
+assert (model.dof(aSketchFeature) == 9)
 
 #=========================================================================
 # Add constraint point-on-line
@@ -147,17 +170,19 @@ reflistB.setObject(aSketchLine.lastResult())
 aConstraint.execute()
 aSession.finishOperation()
 checkPointOnLine(anArcStartPoint, aSketchLine)
+assert (model.dof(aSketchFeature) == 8)
 #=========================================================================
 # Add constraint point-on-circle
 #=========================================================================
 aSession.startOperation()
 # create circle with center coincident with origin
 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-aCircleCenter = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+aCircleCenter = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
 aCircleCenter.setValue(10., 10.)
 aCircleRadius.setValue(25.)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 11)
 # create origin
 aSession.startOperation()
 anOrigRes = modelAPI_Result(aDocument.objectByName("Construction", anOriginName))
@@ -165,10 +190,11 @@ assert (anOrigRes)
 anOrigShape = anOrigRes.shape()
 assert (anOrigShape)
 anOrigin = aSketchFeature.addFeature("SketchPoint")
-anOriginCoord = geomDataAPI_Point2D(anOrigin.attribute("PointCoordindates"))
+anOriginCoord = geomDataAPI_Point2D(anOrigin.attribute("PointCoordinates"))
 anOriginCoord.setValue(0., 0.)
 anOrigin.selection("External").setValue(anOrigRes, anOrigShape)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 11)
 # coincidence between center of circle and the origin
 aSession.startOperation()
 aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
@@ -177,6 +203,7 @@ reflistB = aConstraint.refattr("ConstraintEntityB")
 reflistA.setAttr(aCircleCenter)
 reflistB.setObject(anOrigin.lastResult())
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
 # point-on-circle
 aSession.startOperation()
 aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
@@ -187,6 +214,7 @@ reflistB.setAttr(aLineEndPoint)
 aConstraint.execute()
 aSession.finishOperation()
 checkPointOnCircle(aLineEndPoint, aSketchCircle)
+assert (model.dof(aSketchFeature) == 8)
 #=========================================================================
 # Add constraint point-on-arc
 #=========================================================================
@@ -201,6 +229,7 @@ aSession.finishOperation()
 checkPointOnArc(aCircleCenter, aSketchArc)
 # check center of circle is still in origin
 assert (aCircleCenter.x() == 0. and aCircleCenter.y() == 0.)
+assert (model.dof(aSketchFeature) == 7)
 
 #=========================================================================
 # Create two more lines and set multi-coincidence between their extremities
@@ -219,6 +248,7 @@ aLine3EndPoint = geomDataAPI_Point2D(aLine3.attribute("EndPoint"))
 aLine3StartPoint.setValue(50., 0.)
 aLine3EndPoint.setValue(0., 100.)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 15)
 # coincidences between extremities of lines
 aSession.startOperation()
 aConstraint12 = aSketchFeature.addFeature("SketchConstraintCoincidence")
@@ -240,6 +270,7 @@ aSession.finishOperation()
 # check the points have same coordinates
 assert (aLineStartPoint.x() == aLine2StartPoint.x() and aLineStartPoint.y() == aLine2StartPoint.y())
 assert (aLineStartPoint.x() == aLine3StartPoint.x() and aLineStartPoint.y() == aLine3StartPoint.y())
+assert (model.dof(aSketchFeature) == 11)
 #=========================================================================
 # Move one line and check other have been updated too
 #=========================================================================
@@ -251,6 +282,7 @@ aLine3EndPoint.setValue(aLine3EndPoint.x() + deltaX,
 aSession.finishOperation()
 assert (aLineStartPoint.x() == aLine2StartPoint.x() and aLineStartPoint.y() == aLine2StartPoint.y())
 assert (aLineStartPoint.x() == aLine3StartPoint.x() and aLineStartPoint.y() == aLine3StartPoint.y())
+assert (model.dof(aSketchFeature) == 11)
 #=========================================================================
 # Fix a line and move another connected segment
 #=========================================================================
@@ -271,6 +303,7 @@ aSession.finishOperation()
 assert (aLineStartPoint.x() == coordX and aLineStartPoint.y() == coordY)
 assert (aLine2StartPoint.x() == coordX and aLine2StartPoint.y() == coordY)
 assert (aLine3StartPoint.x() == coordX and aLine3StartPoint.y() == coordY)
+assert (model.dof(aSketchFeature) == 7)
 #=========================================================================
 # Detach fixed line and move one of remaining
 #=========================================================================
@@ -289,10 +322,10 @@ aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
 aSession.finishOperation()
 assert (aLineStartPoint.x() != aLine2StartPoint.x() or aLineStartPoint.y() != aLine2StartPoint.y())
 assert (aLineStartPoint.x() == aLine3StartPoint.x() and aLineStartPoint.y() == aLine3StartPoint.y())
+assert (model.dof(aSketchFeature) == 9)
 
 #=========================================================================
 # End of test
 #=========================================================================
 
-from salome.shaper import model
 assert(model.checkPythonDump())