+## 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<mailto: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
#=========================================================================
aStartPoint2.setValue(10., 100.)
aEndPoint2.setValue(100., 25.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Make end point of second line middle point on first line
#=========================================================================
reflistB.setObject(aLine1.lastResult())
aConstraint.execute()
aSession.finishOperation()
+#=========================================================================
+# Check error message (this message is not a error but a limitation of PlaneGCS)
+# If the problem will be resolved, following block may be removed
+#=========================================================================
+assert aSketchFeature.string("SolverError").value() != "", "PlaneGCS limitation: if you see this message, then PlaneGCS has solved conflicting constraints when applying Middle constraint for the point out of the segment"
+aSession.startOperation()
+aDocument.removeFeature(aConstraint)
+aSession.finishOperation()
+aSession.startOperation()
+aEndPoint2.setValue(80., 25.)
+aConstraint = aSketchFeature.addFeature("SketchConstraintMiddle")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
+reflistA.setAttr(aEndPoint2)
+reflistB.setObject(aLine1.lastResult())
+aConstraint.execute()
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 6)
+
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
aStartPoint1.setValue(aStartPoint1.x() + deltaX, aStartPoint1.y() + deltaY)
aSession.finishOperation()
checkMiddlePoint(aEndPoint2, aLine1)
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Remove constraint and move the line
#=========================================================================
aSession.startOperation()
aDocument.removeFeature(aConstraint)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
aSession.startOperation()
aEndPoint1.setValue(90., 0.)
aSession.finishOperation()
assert (aEndPoint2.x() == aCurX and aEndPoint2.y() == aCurY)
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Set external point as a middle point
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) == 8)
# middle point constraint
aSession.startOperation()
aConstraint = aSketchFeature.addFeature("SketchConstraintMiddle")
reflistB.setObject(anOrigin.lastResult())
aSession.finishOperation()
checkMiddlePoint(anOriginCoord, aLine2)
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Check origin coordinates does not changed
#=========================================================================
assert (anOriginCoord.x() == 0. and anOriginCoord.y() == 0.)
+
+#=========================================================================
+# Add other line with one extremity coincident to the first line
+#=========================================================================
+aSession.startOperation()
+aLine3 = aSketchFeature.addFeature("SketchLine")
+aStartPoint3 = geomDataAPI_Point2D(aLine3.attribute("StartPoint"))
+aEndPoint3 = geomDataAPI_Point2D(aLine3.attribute("EndPoint"))
+aStartPoint3.setValue(50., 50.)
+aEndPoint3.setValue(50., 0.)
+aCoincidence = aSketchFeature.addFeature("SketchConstraintCoincidence")
+reflistA = aCoincidence.refattr("ConstraintEntityA")
+reflistB = aCoincidence.refattr("ConstraintEntityB")
+reflistA.setAttr(aEndPoint3)
+reflistB.setObject(aLine1.lastResult())
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
+#=========================================================================
+# Set Middle point
+#=========================================================================
+aSession.startOperation()
+aMiddle = aSketchFeature.addFeature("SketchConstraintMiddle")
+reflistA = aMiddle.refattr("ConstraintEntityA")
+reflistB = aMiddle.refattr("ConstraintEntityB")
+reflistA.setAttr(aEndPoint3)
+reflistB.setObject(aLine1.lastResult())
+aSession.finishOperation()
+# check the point, and no error message
+assert aSketchFeature.string("SolverError").value() == ""
+assert (model.dof(aSketchFeature) == 8)
+checkMiddlePoint(aEndPoint3, aLine1)
+#=========================================================================
+# Remove coincidence and move one line
+#=========================================================================
+aSession.startOperation()
+aDocument.removeFeature(aCoincidence)
+aSession.finishOperation()
+deltaX, deltaY = 10.0, -10.0
+aSession.startOperation()
+aStartPoint1.setValue(aStartPoint1.x() + deltaX, aStartPoint1.y() + deltaY)
+aEndPoint1.setValue(aEndPoint1.x() + deltaX, aEndPoint1.y() + deltaY)
+aSession.finishOperation()
+checkMiddlePoint(aEndPoint3, aLine1)
+assert (model.dof(aSketchFeature) == 8)
+
#=========================================================================
# End of test
#=========================================================================
-import model
assert(model.checkPythonDump())