+# 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
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
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)
# 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()
#=========================================================================
#=========================================================================
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.)
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
#=========================================================================
reflistB.setAttr(aLineStartPoint)
aConstraint.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 7)
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
# 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
#=========================================================================
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
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))
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")
reflistA.setAttr(aCircleCenter)
reflistB.setObject(anOrigin.lastResult())
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
# point-on-circle
aSession.startOperation()
aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
aConstraint.execute()
aSession.finishOperation()
checkPointOnCircle(aLineEndPoint, aSketchCircle)
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Add constraint point-on-arc
#=========================================================================
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
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")
# 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
#=========================================================================
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
#=========================================================================
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
#=========================================================================
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())