X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FTest%2FTestConstraintFixed.py;h=db20680aa714465bfbadd81d379bedb5e9432668;hb=28038c772769f15a06376fa01d55529e7daa1aa9;hp=d3b631530a6de163af9f37a91654eaebfe227f4a;hpb=83e4015d7099a1f87aae13a2811590dac27a6344;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/Test/TestConstraintFixed.py b/src/SketchPlugin/Test/TestConstraintFixed.py index d3b631530..db20680aa 100644 --- a/src/SketchPlugin/Test/TestConstraintFixed.py +++ b/src/SketchPlugin/Test/TestConstraintFixed.py @@ -1,3 +1,23 @@ +## Copyright (C) 2014-2017 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 +## + """ TestConstraintRigid.py Unit test of SketchPlugin_ConstraintRigid class @@ -149,6 +169,141 @@ assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLi assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y())) assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y())) assert (model.dof(aSketchFeature) == 6) + +#========================================================================= +# Create circle, fix it and check the circle is not moved +#========================================================================= +aCenter = [10., 10.] +aRadius = 5. +aSession.startOperation() +aCircle = aSketchFeature.addFeature("SketchCircle") +aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) +aCircleRadius = aCircle.real("circle_radius") +aCircleCenter.setValue(aCenter[0], aCenter[1]) +aCircleRadius.setValue(aRadius) +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 9) +# fixed constraints +aSession.startOperation() +aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid") +aRigidConstraint.refattr("ConstraintEntityA").setObject(aCircle.lastResult()) +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 6) +# move center of circle +aSession.startOperation() +aCircleCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.) +aSession.finishOperation() +assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1]) +assert (aCircleRadius.value() == aRadius) +assert (model.dof(aSketchFeature) == 6) +# change radius of circle +aSession.startOperation() +aCircleRadius.setValue(aRadius + 3.) +aSession.finishOperation() +assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1]) +assert (aCircleRadius.value() == aRadius) +assert (model.dof(aSketchFeature) == 6) + +#========================================================================= +# Remove Fixed constraint and check the circle can be moved +#========================================================================= +aSession.startOperation() +aDocument.removeFeature(aRigidConstraint) +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 9) +# move center of circle +aCenter = [aCenter[0] + 1., aCenter[1] - 1.] +aSession.startOperation() +aCircleCenter.setValue(aCenter[0], aCenter[1]) +aSession.finishOperation() +assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1]) +assert (aCircleRadius.value() == aRadius) +assert (model.dof(aSketchFeature) == 9) +# change radius of circle +aRadius = aRadius + 3. +aSession.startOperation() +aCircleRadius.setValue(aRadius) +aSession.finishOperation() +assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1]) +assert (aCircleRadius.value() == aRadius) +assert (model.dof(aSketchFeature) == 9) + +#========================================================================= +# Create arc, fix it and check it is not moved +#========================================================================= +aCenter = [10., 10.] +aStart = [5., 10.] +aEnd = [10., 15.] +aSession.startOperation() +anArc = aSketchFeature.addFeature("SketchArc") +anArcCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) +anArcStart = geomDataAPI_Point2D(anArc.attribute("start_point")) +anArcEnd = geomDataAPI_Point2D(anArc.attribute("end_point")) +anArcCenter.setValue(aCenter[0], aCenter[1]) +anArcStart.setValue(aStart[0], aStart[1]) +anArcEnd.setValue(aEnd[0], aEnd[1]) +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 14) +# fixed constraints +aSession.startOperation() +aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid") +aRigidConstraint.refattr("ConstraintEntityA").setObject(anArc.lastResult()) +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 9) +# move center of arc +aSession.startOperation() +anArcCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.) +aSession.finishOperation() +assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1]) +assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1]) +assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1]) +assert (model.dof(aSketchFeature) == 9) +# move start point of arc +aSession.startOperation() +anArcStart.setValue(aStart[0] + 1., aStart[1] - 1.) +aSession.finishOperation() +assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1]) +assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1]) +assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1]) +assert (model.dof(aSketchFeature) == 9) +# move end point of arc +aSession.startOperation() +anArcEnd.setValue(aEnd[0] + 1., aEnd[1] - 1.) +aSession.finishOperation() +assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1]) +assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1]) +assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1]) +assert (model.dof(aSketchFeature) == 9) + +#========================================================================= +# Remove Fixed constraint and check the arc can be moved +#========================================================================= +aSession.startOperation() +aDocument.removeFeature(aRigidConstraint) +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 14) +# move center of arc +aCenter = [anArcCenter.x(), anArcCenter.y()] +aSession.startOperation() +anArcCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.) +aSession.finishOperation() +assert (anArcCenter.x() != aCenter[0] or anArcCenter.y() != aCenter[1]) +assert (model.dof(aSketchFeature) == 14) +# move start point of arc +aStart = [anArcStart.x(), anArcStart.y()] +aSession.startOperation() +anArcStart.setValue(aStart[0] + 1., aStart[1] - 1.) +aSession.finishOperation() +assert (anArcStart.x() != aStart[0] or anArcStart.y() != aStart[1]) +assert (model.dof(aSketchFeature) == 14) +# move end point of arc +aEnd = [anArcEnd.x(), anArcEnd.y()] +aSession.startOperation() +anArcEnd.setValue(aEnd[0] + 1., aEnd[1] - 1.) +aSession.finishOperation() +assert (anArcEnd.x() != aEnd[0] or anArcEnd.y() != aEnd[1]) +assert (model.dof(aSketchFeature) == 14) + #========================================================================= # End of test #=========================================================================