X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FTest%2FTestCreateCircleByCenterAndPassed.py;h=7e5ba93c0f82b6b63f2d4fc5a82be2743dbe8992;hb=f64e1300ed35bb1e9a2486cdb5713355e832dd39;hp=35f55de79ea8ed822c220c1f2de6a493fbb5edde;hpb=1de75803e9baf3de59fa755f9eccb6ef60bb64e4;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py b/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py index 35f55de79..7e5ba93c0 100644 --- a/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py +++ b/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py @@ -1,3 +1,22 @@ +# Copyright (C) 2014-2023 CEA, EDF +# +# 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 +# + """ TestCreateCircleByCenterAndPassed.py @@ -14,7 +33,7 @@ from SketchAPI import SketchAPI_Sketch from salome.shaper import model import math -__updated__ = "2017-03-22" +__updated__ = "2023-06-28" #========================================================================= @@ -27,16 +46,10 @@ def verifyLastCircle(theSketch, theX, theY, theR): subroutine to verify position of last circle in the sketch """ aLastCircle = model.lastSubFeature(theSketch, "SketchCircle") - aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center")) - verifyPointCoordinates(aCenter, theX, theY) - aRadius = aLastCircle.real("circle_radius") - assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR) - -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.assertCircle(aLastCircle, [theX, theY], theR) 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 verifyTangentCircles(theCircle1, theCircle2): @@ -49,14 +62,19 @@ def verifyTangentCircles(theCircle1, theCircle2): aRDiff = math.fabs(aRadius1 - aRadius2) assert math.fabs(aRSum - aDistCC) < TOLERANCE or math.fabs(aRDiff - aDistCC) < TOLERANCE, "Circles do not tangent" -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) +def verifyTangentCircleLine(theCircle, theLine): + aCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center")) + aRadius = theCircle.real("circle_radius").value() + aDistCL = model.distancePointLine(aCenter, theLine) + assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent" +#========================================================================= +# Set old version of Circle for avoid create point. +#========================================================================= +def setVersionOfCircle(theCircle, theVersion): + aCircleVersion = theCircle.integer("version") + assert (type(aCircleVersion) == ModelAPI_AttributeInteger) + aCircleVersion.setValue(theVersion) #========================================================================= # Start of test @@ -89,6 +107,7 @@ aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) assert (not aCircleCenter.isInitialized()) aCircleRadius = aCircle.real("circle_radius") assert (type(aCircleRadius) == ModelAPI_AttributeDouble) +setVersionOfCircle(aCircle, 0) # ModelAPI_AttributeDouble.typeId() is checked in ModelAPI_TestConstants assert (aCircleRadius.attributeType() == ModelAPI_AttributeDouble.typeId()) aCircleCenter.setValue(-25., -25) @@ -122,6 +141,7 @@ assert (not aCirclePassed.isInitialized()) aCircleType = aCircle.string("circle_type") assert (not aCircleType.isInitialized()) aCircleType.setValue("circle_type_by_center_and_passed_points") +setVersionOfCircle(aCircle, 0) aCircleCenter.setValue(-25., -25) aCirclePassed.setValue(0., -25.) aRadius = model.distancePointPoint(aCircleCenter, aCirclePassed) @@ -136,11 +156,11 @@ verifyLastCircle(aSketchFeature, -25., -25., aRadius) aPrevCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") aPrevCenter = geomDataAPI_Point2D(aPrevCircle.attribute("circle_center")) # create additional point -aPointCoodinates = [0., 0.] +aPointCoordinates = [0., 0.] aSession.startOperation() aPoint = aSketchFeature.addFeature("SketchPoint") aPointCoord = geomDataAPI_Point2D(aPoint.attribute("PointCoordinates")) -aPointCoord.setValue(aPointCoodinates[0], aPointCoodinates[1]) +aPointCoord.setValue(aPointCoordinates[0], aPointCoordinates[1]) aSession.finishOperation() # create new circle aSession.startOperation() @@ -155,6 +175,7 @@ aCircleType = aCircle.string("circle_type") assert (not aCircleType.isInitialized()) # initialize attributes aCircleType.setValue("circle_type_by_center_and_passed_points") +setVersionOfCircle(aCircle, 0) aCenterRef.setObject(aPoint.lastResult()) aCenter.setValue(aPointCoord.pnt()) aPassedRef.setAttr(aPrevCenter) @@ -162,7 +183,7 @@ aPassed.setValue(aPrevCenter.pnt()) aRadius = model.distancePointPoint(aPrevCenter, aPointCoord) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 6) -verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1]) +model.assertPoint(aPointCoord, aPointCoordinates) verifyLastCircle(aSketchFeature, aPointCoord.x(), aPointCoord.y(), aRadius) model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 2) @@ -194,6 +215,7 @@ aPassedRef = aCircle.refattr("passed_point_ref") aCircleType = aCircle.string("circle_type") # initialize attributes aCircleType.setValue("circle_type_by_center_and_passed_points") +setVersionOfCircle(aCircle, 0) aCenterRef.setObject(aLine.lastResult()) anExpectedCenter = [(aLineStart[0] + aLineEnd[0]) * 0.5, (aLineStart[1] + aLineEnd[1]) * 0.5] aCenter.setValue(anExpectedCenter[0], anExpectedCenter[1]) @@ -203,19 +225,48 @@ aRadius = model.distancePointPoint(aCenter, aPassed) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 10) # check connected features do not change their positions -verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1]) +model.assertPoint(aPrevCenter, aPrevCenterXY) assert(aPrevCircle.real("circle_radius").value() == aPrevRadius) -verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1]) -verifyPointCoordinates(aEndPnt, aLineEnd[0], aLineEnd[1]) +model.assertLine(aLine, aLineStart, aLineEnd) # verify newly created circle aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) -verifyPointCoordinates(aCenter, anExpectedCenter[0], anExpectedCenter[1]) +model.assertPoint(aCenter, anExpectedCenter) verifyPointOnLine(aCenter, aLine) verifyTangentCircles(aCircle, aPrevCircle) model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3) model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 1) +#========================================================================= +# Test 5. Create a circle as a macro-feature by center and passed point on line +#========================================================================= +# create new circle +aSession.startOperation() +aCircle = aSketchFeature.addFeature("SketchMacroCircle") +aCenter = geomDataAPI_Point2D(aCircle.attribute("center_point")) +aCenterRef = aCircle.refattr("center_point_ref") +aPassed = geomDataAPI_Point2D(aCircle.attribute("passed_point")) +aPassedRef = aCircle.refattr("passed_point_ref") +aCircleType = aCircle.string("circle_type") +# initialize attributes +aCircleType.setValue("circle_type_by_center_and_passed_points") +setVersionOfCircle(aCircle, 0) +anExpectedCenter = [(aLineStart[0] + aLineEnd[0]) * 0.5 + 10., (aLineStart[1] + aLineEnd[1]) * 0.5] +aCenter.setValue(anExpectedCenter[0], anExpectedCenter[1]) +aPassedRef.setObject(aLine.lastResult()) +aPassed.setValue(aLineStart[0], aLineStart[1]) +aSession.finishOperation() +assert (aSketchFeature.numberOfSubs() == 12) +# check connected features do not change their positions +model.assertLine(aLine, aLineStart, aLineEnd) +# verify newly created circle +aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") +aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) +model.assertPoint(aCenter, anExpectedCenter) +verifyTangentCircleLine(aCircle, aLine) +model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3) +model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 2) + #========================================================================= # Test 5. Create a circle as a macro-feature by center and passed point placed on the same line # Check the circle is not created @@ -229,6 +280,7 @@ aPassedRef = aCircle.refattr("passed_point_ref") aCircleType = aCircle.string("circle_type") # initialize attributes aCircleType.setValue("circle_type_by_center_and_passed_points") +setVersionOfCircle(aCircle, 0) aCenterRef.setObject(aLine.lastResult()) aCenter.setValue(anExpectedCenter[0], anExpectedCenter[1]) aPassedRef.setObject(aLine.lastResult()) @@ -239,7 +291,38 @@ assert aLastFeature.getKind() == "SketchMacroCircle", "ERROR: SketchMacroCircle aSession.startOperation() aDocument.removeFeature(aCircle) aSession.finishOperation() -assert (aSketchFeature.numberOfSubs() == 10) +assert (aSketchFeature.numberOfSubs() == 12) + +#========================================================================= +# Test 6. Create a circle with point on circle line (addCircleWithPoint) +#========================================================================= +# create new circle +aSession.startOperation() +aCircle = aSketchFeature.addFeature("SketchMacroCircle") +aCenter = geomDataAPI_Point2D(aCircle.attribute("center_point")) +aCenterRef = aCircle.refattr("center_point_ref") +aPassed = geomDataAPI_Point2D(aCircle.attribute("passed_point")) +aPassedRef = aCircle.refattr("passed_point_ref") +aCircleType = aCircle.string("circle_type") +aCircleAngle = aCircle.real("circle_angle") +# initialize attributes +aCircleType.setValue("circle_type_by_center_and_passed_points") +setVersionOfCircle(aCircle, 20232206) +aCenter.setValue(35., -35) +anExpectedCenter = [35., -35] +aPassed.setValue(45., -35) +aCircleAngle.setValue(90.) +anExpectedRot = [45., -35] +aSession.finishOperation() +assert (aSketchFeature.numberOfSubs() == 15) +# verify newly created circle +aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") +aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) +aRotPoint = geomDataAPI_Point2D(aCircle.attribute("circle_rotate")) +model.assertPoint(aCenter, anExpectedCenter) +model.assertPoint(aRotPoint, anExpectedRot) +model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3) +model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 2) #========================================================================= # End of test