Salome HOME
Update copyrights
[modules/shaper.git] / src / SketchPlugin / Test / TestCreateArcByCenterStartEnd.py
index 4f05ecf69330f5b656ca40a459466a87984bc826..9dbd30803ea3a86c5019251cce8bd1ab32221ce0 100644 (file)
@@ -1,3 +1,22 @@
+# Copyright (C) 2014-2019  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
+#
+
 """
     TestCreateArc.py
 
@@ -32,22 +51,10 @@ def verifyLastArc(theSketch, theCenter, theStart, theEnd):
     subroutine to verify position of last arc in the sketch
     """
     aLastArc = model.lastSubFeature(theSketch, "SketchArc")
-    aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
-    aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point"))
-    aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point"))
-    if len(theCenter):
-        verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1])
-    if len(theStart):
-        verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
-    if len(theEnd):
-        verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
-    model.assertSketchArc(aLastArc)
-
-def verifyPointCoordinates(thePoint, theX, theY):
-    assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY)
+    model.assertArc(aLastArc, theCenter, theStart, theEnd)
 
 def verifyPointOnLine(thePoint, theLine):
-    aDistance = distancePointLine(thePoint, theLine)
+    aDistance = model.distancePointLine(thePoint, theLine)
     assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance)
 
 def verifyPointOnCircle(thePoint, theCircular):
@@ -63,15 +70,6 @@ def verifyPointOnCircle(thePoint, theCircular):
     assert math.fabs(model.distancePointPoint(aCenterPoint, thePoint) - aRadius) < TOLERANCE
 
 
-def distancePointLine(thePoint, theLine):
-    aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
-    aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
-    aLineDir = aLineEnd.decreased(aLineStart)
-    aLineLen = aLineEnd.distance(aLineStart)
-    aPntDir = thePoint.pnt().xy().decreased(aLineStart)
-    return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
-
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
 #=========================================================================
@@ -224,7 +222,7 @@ aEndRef.setObject(aLine.lastResult())
 aEnd.setValue(aLineStart[0], aLineStart[1])
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 8), "Number of subs {}".format(aSketchFeature.numberOfSubs())
-verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1])
+model.assertPoint(aPointCoord, aPointCoordinates)
 verifyLastArc(aSketchFeature, [aPrevArcStart.x(), aPrevArcStart.y()], aPointCoordinates, [])
 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
 
@@ -260,11 +258,8 @@ aEnd.setValue(aLineEndPoint.pnt())
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 12), "Number of subs {}".format(aSketchFeature.numberOfSubs())
 # check connected features do not change their positions
-verifyPointCoordinates(aPrevArcCenter, aPrevArcCenterXY[0], aPrevArcCenterXY[1])
-verifyPointCoordinates(aPrevArcStart, aPrevArcStartXY[0], aPrevArcStartXY[1])
-verifyPointCoordinates(aPrevArcEnd, aPrevArcEndXY[0], aPrevArcEndXY[1])
-verifyPointCoordinates(aLineStartPoint, aLineStart[0], aLineStart[1])
-verifyPointCoordinates(aLineEndPoint, aLineEnd[0], aLineEnd[1])
+model.assertArc(aPrevArc, aPrevArcCenterXY, aPrevArcStartXY, aPrevArcEndXY)
+model.assertLine(aLine, aLineStart, aLineEnd)
 # verify newly created arc
 anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
 aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
@@ -276,6 +271,116 @@ verifyPointOnCircle(aStart, aPrevArc)
 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 6)
 model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0)
 
+#=========================================================================
+# Test 5. Create another arc by center and points coincident to other features
+#=========================================================================
+# create new arc
+aSession.startOperation()
+anArc = aSketchFeature.addFeature("SketchMacroArc")
+aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
+aCenterRef = anArc.refattr("center_point_ref")
+aStart = geomDataAPI_Point2D(anArc.attribute("start_point_1"))
+aStartRef = anArc.refattr("start_point_ref")
+aEnd = geomDataAPI_Point2D(anArc.attribute("end_point_1"))
+aEndRef = anArc.refattr("end_point_ref")
+anArcType = anArc.string("arc_type")
+# initialize attributes
+anArcType.setValue("by_center_and_points")
+aCenterRef.setObject(aLine.lastResult())
+aCenter.setValue(aLineStartPoint.pnt())
+aStartRef.setObject(aLine.lastResult())
+aStart.setValue(aLineEndPoint.pnt())
+aEndRef.setObject(aPrevArc.lastResult())
+aEnd.setValue(aPrevArcStart.pnt())
+aSession.finishOperation()
+assert (aSketchFeature.numberOfSubs() == 16), "Number of subs {}".format(aSketchFeature.numberOfSubs())
+# check connected features do not change their positions
+model.assertArc(aPrevArc, aPrevArcCenterXY, aPrevArcStartXY, aPrevArcEndXY)
+model.assertLine(aLine, aLineStart, aLineEnd)
+# verify newly created arc
+anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
+aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
+aStart = geomDataAPI_Point2D(anArc.attribute("start_point"))
+aEnd = geomDataAPI_Point2D(anArc.attribute("end_point"))
+verifyPointOnLine(aCenter, aLine)
+verifyPointOnLine(aStart, aLine)
+verifyPointOnCircle(aEnd, aPrevArc)
+model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 9)
+model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0)
+
+#=========================================================================
+# Test 6. Create one more arc by center and points coincident to other features
+#=========================================================================
+# get previous arc
+aPrevArc = model.lastSubFeature(aSketchFeature, "SketchArc")
+aPrevArcCenter = geomDataAPI_Point2D(aPrevArc.attribute("center_point"))
+aPrevArcStart = geomDataAPI_Point2D(aPrevArc.attribute("start_point"))
+aPrevArcEnd = geomDataAPI_Point2D(aPrevArc.attribute("end_point"))
+aPrevArcCenterXY = [aPrevArcCenter.x(), aPrevArcCenter.y()]
+aPrevArcStartXY = [aPrevArcStart.x(), aPrevArcStart.y()]
+aPrevArcEndXY = [aPrevArcEnd.x(), aPrevArcEnd.y()]
+# create new arc
+aSession.startOperation()
+anArc = aSketchFeature.addFeature("SketchMacroArc")
+aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
+aCenterRef = anArc.refattr("center_point_ref")
+aStart = geomDataAPI_Point2D(anArc.attribute("start_point_1"))
+aStartRef = anArc.refattr("start_point_ref")
+aEnd = geomDataAPI_Point2D(anArc.attribute("end_point_1"))
+aEndRef = anArc.refattr("end_point_ref")
+anArcType = anArc.string("arc_type")
+# initialize attributes
+anArcType.setValue("by_center_and_points")
+delta = [aPrevArcEndXY[0] - aPrevArcCenterXY[0], aPrevArcEndXY[1] - aPrevArcCenterXY[1]]
+aCenter.setValue(aPrevArcCenterXY[0] + 2 * delta[0], aPrevArcCenterXY[1] + 2 * delta[1])
+aStart.setValue(aPrevArcCenterXY[0] + 2 * delta[0] - 0.9 * delta[1], aPrevArcCenterXY[1] + 2 * delta[1] + 0.9 * delta[0])
+aEndRef.setObject(aPrevArc.lastResult())
+aEnd.setValue(aPrevArcCenterXY[0] + 1.1 * delta[0], aPrevArcCenterXY[1] + 1.1 * delta[1])
+aSession.finishOperation()
+assert (aSketchFeature.numberOfSubs() == 18), "Number of subs {}".format(aSketchFeature.numberOfSubs())
+# verify newly created arc
+anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
+aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
+aStart = geomDataAPI_Point2D(anArc.attribute("start_point"))
+aEnd = geomDataAPI_Point2D(anArc.attribute("end_point"))
+verifyPointOnCircle(aEnd, aPrevArc)
+model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 10)
+model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0)
+
+#=========================================================================
+# Test 7. Create one more arc by center and points coincident to other features
+#=========================================================================
+aPrevArcCenterXY = [aPrevArcCenter.x(), aPrevArcCenter.y()]
+aPrevArcStartXY = [aPrevArcStart.x(), aPrevArcStart.y()]
+aPrevArcEndXY = [aPrevArcEnd.x(), aPrevArcEnd.y()]
+# create new arc
+aSession.startOperation()
+anArc = aSketchFeature.addFeature("SketchMacroArc")
+aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
+aCenterRef = anArc.refattr("center_point_ref")
+aStart = geomDataAPI_Point2D(anArc.attribute("start_point_1"))
+aStartRef = anArc.refattr("start_point_ref")
+aEnd = geomDataAPI_Point2D(anArc.attribute("end_point_1"))
+aEndRef = anArc.refattr("end_point_ref")
+anArcType = anArc.string("arc_type")
+# initialize attributes
+anArcType.setValue("by_center_and_points")
+delta = [aPrevArcEndXY[0] - aPrevArcCenterXY[0], aPrevArcEndXY[1] - aPrevArcCenterXY[1]]
+aCenter.setValue(aPrevArcCenterXY[0] + 2 * delta[0], aPrevArcCenterXY[1] + 2 * delta[1])
+aStart.setValue(aPrevArcCenterXY[0] + 2 * delta[0] - delta[1], aPrevArcCenterXY[1] + 2 * delta[1] + delta[0])
+aEndRef.setObject(aPrevArc.lastResult())
+aEnd.setValue(aPrevArcCenterXY[0] + delta[0], aPrevArcCenterXY[1] + delta[1])
+aSession.finishOperation()
+assert (aSketchFeature.numberOfSubs() == 20), "Number of subs {}".format(aSketchFeature.numberOfSubs())
+# verify newly created arc
+anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
+aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
+aStart = geomDataAPI_Point2D(anArc.attribute("start_point"))
+aEnd = geomDataAPI_Point2D(anArc.attribute("end_point"))
+verifyPointOnCircle(aEnd, aPrevArc)
+model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 11)
+model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0)
+
 #=========================================================================
 # End of test
 #=========================================================================