+# 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
#=========================================================================
-assert (anArcEndPoint.x() == 50)
-assert (anArcEndPoint.y() == 0)
-assert (aLineStartPoint.x() == 50)
-assert (aLineStartPoint.y() == 0)
+assert (anArcEndPoint.x() == aLineStartPoint.x())
+assert (anArcEndPoint.y() == aLineStartPoint.y())
deltaX = deltaY = 40.
# move line
aSession.startOperation()
# 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
#=========================================================================
aConstraint.execute()
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)
+
#=========================================================================
-# Check center of circle is still in origin
+# Create two more lines and set multi-coincidence between their extremities
#=========================================================================
-assert (aCircleCenter.x() == 0. and aCircleCenter.y() == 0.)
+aSession.startOperation()
+# line 2
+aLine2 = aSketchFeature.addFeature("SketchLine")
+aLine2StartPoint = geomDataAPI_Point2D(aLine2.attribute("StartPoint"))
+aLine2EndPoint = geomDataAPI_Point2D(aLine2.attribute("EndPoint"))
+aLine2StartPoint.setValue(50., 0.)
+aLine2EndPoint.setValue(100., 0.)
+# line 3
+aLine3 = aSketchFeature.addFeature("SketchLine")
+aLine3StartPoint = geomDataAPI_Point2D(aLine3.attribute("StartPoint"))
+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")
+refAttrA = aConstraint12.refattr("ConstraintEntityA")
+refAttrB = aConstraint12.refattr("ConstraintEntityB")
+refAttrA.setAttr(aLineStartPoint)
+refAttrB.setAttr(aLine2StartPoint)
+aConstraint23 = aSketchFeature.addFeature("SketchConstraintCoincidence")
+refAttrA = aConstraint23.refattr("ConstraintEntityA")
+refAttrB = aConstraint23.refattr("ConstraintEntityB")
+refAttrA.setAttr(aLine2StartPoint)
+refAttrB.setAttr(aLine3StartPoint)
+aConstraint31 = aSketchFeature.addFeature("SketchConstraintCoincidence")
+refAttrA = aConstraint31.refattr("ConstraintEntityA")
+refAttrB = aConstraint31.refattr("ConstraintEntityB")
+refAttrA.setAttr(aLine3StartPoint)
+refAttrB.setAttr(aLineStartPoint)
+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
+#=========================================================================
+aSession.startOperation()
+aLine3StartPoint.setValue(aLine3StartPoint.x() + deltaX,
+ aLine3StartPoint.y() + deltaY)
+aLine3EndPoint.setValue(aLine3EndPoint.x() + deltaX,
+ aLine3EndPoint.y() + deltaY)
+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
+#=========================================================================
+coordX = aLineStartPoint.x()
+coordY = aLineStartPoint.y()
+aSession.startOperation()
+aFixed = aSketchFeature.addFeature("SketchConstraintRigid")
+refAttrA = aFixed.refattr("ConstraintEntityA")
+refAttrA.setObject(aLine2.lastResult())
+aSession.finishOperation()
+# move another line
+aSession.startOperation()
+aLine3StartPoint.setValue(aLine3StartPoint.x() + deltaX,
+ aLine3StartPoint.y() + deltaY)
+aLine3EndPoint.setValue(aLine3EndPoint.x() + deltaX,
+ aLine3EndPoint.y() + deltaY)
+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
+#=========================================================================
+aSession.startOperation()
+aDocument.removeFeature(aConstraint12)
+aDocument.removeFeature(aConstraint23)
+aSession.finishOperation()
+# move line
+deltaX = 1.
+deltaY = 0.
+aSession.startOperation()
+aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
+ aLineStartPoint.y() + deltaY)
+aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
+ aLineEndPoint.y() + deltaY)
+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())