X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FTest%2FTestConstraintCoincidence.py;h=5a7c5a1e893da1c6a80845cc7c2384c8028cfd12;hb=fc72d43b677baa05ae7fd317346fd8b723b799ed;hp=c7ba672dacf33e0a5bddb32dcda1f3d48a8d598a;hpb=b6a827b5f2b1c61957dc2b22bfa11eba72175413;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/Test/TestConstraintCoincidence.py b/src/SketchPlugin/Test/TestConstraintCoincidence.py index c7ba672da..5a7c5a1e8 100644 --- a/src/SketchPlugin/Test/TestConstraintCoincidence.py +++ b/src/SketchPlugin/Test/TestConstraintCoincidence.py @@ -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") +geomDataAPI_Point(aFeature.attribute("point3d")).setValue(0., 0., 0.) aFeature.string("creation_method").setValue("by_xyz") -aFeature.real("x").setValue(0.) -aFeature.real("y").setValue(0.) -aFeature.real("z").setValue(0.) anOriginName = aFeature.name() aSession.finishOperation() #========================================================================= @@ -84,10 +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.) @@ -98,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 #========================================================================= @@ -109,13 +128,12 @@ reflistA.setAttr(anArcEndPoint) 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() @@ -127,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 #========================================================================= @@ -137,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 @@ -150,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)) @@ -168,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") @@ -180,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") @@ -190,6 +214,7 @@ reflistB.setAttr(aLineEndPoint) aConstraint.execute() aSession.finishOperation() checkPointOnCircle(aLineEndPoint, aSketchCircle) +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Add constraint point-on-arc #========================================================================= @@ -202,10 +227,105 @@ reflistB.setObject(aSketchArc.lastResult()) 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 #========================================================================= + +assert(model.checkPythonDump())