From 757c9ee61ec3483996e12bbb85f904275d5626be Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 12 Dec 2019 12:20:34 +0300 Subject: [PATCH] Task 5.1.3 Sketcher: angle dimension (issue #3061) Additional unit-tests for Angle behavior. --- .../ModelHighAPI_FeatureStore.cpp | 6 +- src/SketchPlugin/CMakeLists.txt | 5 + .../TestConstraintAngleBehaviorBackward_1.py | 113 ++++++++++++++++++ .../TestConstraintAngleBehaviorBackward_2.py | 107 +++++++++++++++++ .../Test/TestConstraintAngleBehaviorDirect.py | 107 +++++++++++++++++ ...tConstraintAngleBehaviorSupplementary_1.py | 113 ++++++++++++++++++ ...tConstraintAngleBehaviorSupplementary_2.py | 107 +++++++++++++++++ 7 files changed, 556 insertions(+), 2 deletions(-) create mode 100644 src/SketchPlugin/Test/TestConstraintAngleBehaviorBackward_1.py create mode 100644 src/SketchPlugin/Test/TestConstraintAngleBehaviorBackward_2.py create mode 100644 src/SketchPlugin/Test/TestConstraintAngleBehaviorDirect.py create mode 100644 src/SketchPlugin/Test/TestConstraintAngleBehaviorSupplementary_1.py create mode 100644 src/SketchPlugin/Test/TestConstraintAngleBehaviorSupplementary_2.py diff --git a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp index d8f6752ad..7565c5913 100644 --- a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp +++ b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp @@ -374,8 +374,10 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { double aValues[3] = {anAttr->x(), anAttr->y(), anAttr->z()}; dumpArray(aResult, aValues, 3); } else if (aType == GeomDataAPI_Point2D::typeId()) { - // do not dump flyout point for constraints as it may be changed unexpectedly - if (theAttr->id() == "ConstraintFlyoutValuePnt") + // do not dump flyout point for constraints as it may be changed unexpectedly, + // also do not dump selection points controlled by GUI + if (theAttr->id() == "ConstraintFlyoutValuePnt" || + theAttr->id() == "SelectedPointA" || theAttr->id() == "SelectedPointB") return "__notinitialized__"; AttributePoint2DPtr anAttr = std::dynamic_pointer_cast(theAttr); double aValues[2] = {anAttr->x(), anAttr->y()}; diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index ca43e4d40..10105e1ca 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -215,6 +215,11 @@ ADD_UNIT_TESTS( TestConstraintAngle_v0_2.py TestConstraintAngle_v20191210_1.py TestConstraintAngle_v20191210_2.py + TestConstraintAngleBehaviorDirect.py + TestConstraintAngleBehaviorSupplementary_1.py + TestConstraintAngleBehaviorSupplementary_2.py + TestConstraintAngleBehaviorBackward_1.py + TestConstraintAngleBehaviorBackward_2.py TestConstraintAngleEllipse.py TestConstraintCoincidence.py TestConstraintCoincidenceEllipse.py diff --git a/src/SketchPlugin/Test/TestConstraintAngleBehaviorBackward_1.py b/src/SketchPlugin/Test/TestConstraintAngleBehaviorBackward_1.py new file mode 100644 index 000000000..086b7796f --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintAngleBehaviorBackward_1.py @@ -0,0 +1,113 @@ +# 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 +# + +from GeomDataAPI import * +from ModelAPI import * +import math +from salome.shaper import model + + +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2019-12-12" + +ANGLE_DIRECT = 0 +ANGLE_COMPLEMENTARY = 1 +ANGLE_BACKWARD = 2 + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSession.finishOperation() +#========================================================================= +# Create two lines +#========================================================================= +aSession.startOperation() +aSketchLineA = aSketchFeature.addFeature("SketchLine") +aStartPointA = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aEndPointA = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) +aStartPointA.setValue(-100., 25.) +aEndPointA.setValue(100., -25.) + +aSketchLineB = aSketchFeature.addFeature("SketchLine") +aStartPointB = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) +aEndPointB = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) +aStartPointB.setValue(-100., -25.) +aEndPointB.setValue(100., 25.) +aSession.finishOperation() +#========================================================================= +# Make a constraint to keep the angle +#========================================================================= +ANGLE_DEGREE = 330. +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintAngle") +anAngleType = aConstraint.integer("AngleType") +anAngleType.setValue(ANGLE_DIRECT) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointA")).setValue(aStartPointA.pnt()) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointB")).setValue(aStartPointB.pnt()) +aConstraint.refattr("ConstraintEntityA").setObject(aSketchLineA.firstResult()) +aConstraint.refattr("ConstraintEntityB").setObject(aSketchLineB.firstResult()) +anAngleVal = aConstraint.real("AngleValue") +anAngleVal.setValue(360. - ANGLE_DEGREE) +aSession.finishOperation() +#========================================================================= +# Change the type of the constraint +#========================================================================= +aSession.startOperation() +anAngleType.setValue(ANGLE_BACKWARD) +aSession.finishOperation() +#========================================================================= +# Move presentation of the angle and check the angle value +#========================================================================= +pointsA = [aStartPointA.pnt(), aEndPointA.pnt()] +pointsB = [aStartPointB.pnt(), aEndPointB.pnt()] +refs = [(pointsA[0], pointsB[1], 540. - ANGLE_DEGREE), + (pointsA[1], pointsB[1], ANGLE_DEGREE), + (pointsA[1], pointsB[0], 540. - ANGLE_DEGREE), + (pointsA[0], pointsB[0], ANGLE_DEGREE) + ] +aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) +for ref in refs: + aSession.startOperation() + aFlyoutPoint.setValue(0.5 * (ref[0].x() + ref[1].x()), 0.5 * (ref[0].y() + ref[1].y())) + aSession.finishOperation() + assert(anAngleType.value() == ANGLE_BACKWARD) + assert(anAngleVal.value() == ref[2]) + assert(aStartPointA.x() == pointsA[0].x() and aStartPointA.y() == pointsA[0].y()) + assert(aEndPointA.x() == pointsA[1].x() and aEndPointA.y() == pointsA[1].y()) + assert(aStartPointB.x() == pointsB[0].x() and aStartPointB.y() == pointsB[0].y()) + assert(aEndPointB.x() == pointsB[1].x() and aEndPointB.y() == pointsB[1].y()) +#========================================================================= +# End of test +#========================================================================= + +assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintAngleBehaviorBackward_2.py b/src/SketchPlugin/Test/TestConstraintAngleBehaviorBackward_2.py new file mode 100644 index 000000000..f64610988 --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintAngleBehaviorBackward_2.py @@ -0,0 +1,107 @@ +# 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 +# + +from GeomDataAPI import * +from ModelAPI import * +import math +from salome.shaper import model + + +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2019-12-12" + +ANGLE_DIRECT = 0 +ANGLE_COMPLEMENTARY = 1 +ANGLE_BACKWARD = 2 + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSession.finishOperation() +#========================================================================= +# Create two lines +#========================================================================= +aSession.startOperation() +aSketchLineA = aSketchFeature.addFeature("SketchLine") +aStartPointA = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aEndPointA = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) +aStartPointA.setValue(-100., 25.) +aEndPointA.setValue(100., -25.) + +aSketchLineB = aSketchFeature.addFeature("SketchLine") +aStartPointB = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) +aEndPointB = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) +aStartPointB.setValue(-100., -25.) +aEndPointB.setValue(100., 25.) +aSession.finishOperation() +#========================================================================= +# Make a constraint to keep the angle +#========================================================================= +ANGLE_DEGREE = 330. +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintAngle") +anAngleType = aConstraint.integer("AngleType") +anAngleType.setValue(ANGLE_BACKWARD) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointA")).setValue(aStartPointA.pnt()) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointB")).setValue(aStartPointB.pnt()) +aConstraint.refattr("ConstraintEntityA").setObject(aSketchLineA.firstResult()) +aConstraint.refattr("ConstraintEntityB").setObject(aSketchLineB.firstResult()) +anAngleVal = aConstraint.real("AngleValue") +anAngleVal.setValue(ANGLE_DEGREE) +aSession.finishOperation() +#========================================================================= +# Move presentation of the angle and check the angle value +#========================================================================= +pointsA = [aStartPointA.pnt(), aEndPointA.pnt()] +pointsB = [aStartPointB.pnt(), aEndPointB.pnt()] +refs = [(pointsA[0], pointsB[1], 540. - ANGLE_DEGREE), + (pointsA[1], pointsB[1], ANGLE_DEGREE), + (pointsA[1], pointsB[0], 540. - ANGLE_DEGREE), + (pointsA[0], pointsB[0], ANGLE_DEGREE) + ] +aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) +for ref in refs: + aSession.startOperation() + aFlyoutPoint.setValue(0.5 * (ref[0].x() + ref[1].x()), 0.5 * (ref[0].y() + ref[1].y())) + aSession.finishOperation() + assert(anAngleType.value() == ANGLE_BACKWARD) + assert(anAngleVal.value() == ref[2]) + assert(aStartPointA.x() == pointsA[0].x() and aStartPointA.y() == pointsA[0].y()) + assert(aEndPointA.x() == pointsA[1].x() and aEndPointA.y() == pointsA[1].y()) + assert(aStartPointB.x() == pointsB[0].x() and aStartPointB.y() == pointsB[0].y()) + assert(aEndPointB.x() == pointsB[1].x() and aEndPointB.y() == pointsB[1].y()) +#========================================================================= +# End of test +#========================================================================= + +assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintAngleBehaviorDirect.py b/src/SketchPlugin/Test/TestConstraintAngleBehaviorDirect.py new file mode 100644 index 000000000..51c10dd86 --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintAngleBehaviorDirect.py @@ -0,0 +1,107 @@ +# 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 +# + +from GeomDataAPI import * +from ModelAPI import * +import math +from salome.shaper import model + + +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2019-12-12" + +ANGLE_DIRECT = 0 +ANGLE_COMPLEMENTARY = 1 +ANGLE_BACKWARD = 2 + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSession.finishOperation() +#========================================================================= +# Create two lines +#========================================================================= +aSession.startOperation() +aSketchLineA = aSketchFeature.addFeature("SketchLine") +aStartPointA = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aEndPointA = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) +aStartPointA.setValue(-100., 25.) +aEndPointA.setValue(100., -25.) + +aSketchLineB = aSketchFeature.addFeature("SketchLine") +aStartPointB = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) +aEndPointB = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) +aStartPointB.setValue(-100., -25.) +aEndPointB.setValue(100., 25.) +aSession.finishOperation() +#========================================================================= +# Make a constraint to keep the angle +#========================================================================= +ANGLE_DEGREE = 30. +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintAngle") +anAngleType = aConstraint.integer("AngleType") +anAngleType.setValue(ANGLE_DIRECT) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointA")).setValue(aStartPointA.pnt()) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointB")).setValue(aStartPointB.pnt()) +aConstraint.refattr("ConstraintEntityA").setObject(aSketchLineA.firstResult()) +aConstraint.refattr("ConstraintEntityB").setObject(aSketchLineB.firstResult()) +anAngleVal = aConstraint.real("AngleValue") +anAngleVal.setValue(ANGLE_DEGREE) +aSession.finishOperation() +#========================================================================= +# Move presentation of the angle and check the angle value +#========================================================================= +pointsA = [aStartPointA.pnt(), aEndPointA.pnt()] +pointsB = [aStartPointB.pnt(), aEndPointB.pnt()] +refs = [(pointsA[0], pointsB[1], 180. - ANGLE_DEGREE), + (pointsA[1], pointsB[1], ANGLE_DEGREE), + (pointsA[1], pointsB[0], 180. - ANGLE_DEGREE), + (pointsA[0], pointsB[0], ANGLE_DEGREE) + ] +aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) +for ref in refs: + aSession.startOperation() + aFlyoutPoint.setValue(0.5 * (ref[0].x() + ref[1].x()), 0.5 * (ref[0].y() + ref[1].y())) + aSession.finishOperation() + assert(anAngleType.value() == ANGLE_DIRECT) + assert(anAngleVal.value() == ref[2]) + assert(aStartPointA.x() == pointsA[0].x() and aStartPointA.y() == pointsA[0].y()) + assert(aEndPointA.x() == pointsA[1].x() and aEndPointA.y() == pointsA[1].y()) + assert(aStartPointB.x() == pointsB[0].x() and aStartPointB.y() == pointsB[0].y()) + assert(aEndPointB.x() == pointsB[1].x() and aEndPointB.y() == pointsB[1].y()) +#========================================================================= +# End of test +#========================================================================= + +assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintAngleBehaviorSupplementary_1.py b/src/SketchPlugin/Test/TestConstraintAngleBehaviorSupplementary_1.py new file mode 100644 index 000000000..542ebffa5 --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintAngleBehaviorSupplementary_1.py @@ -0,0 +1,113 @@ +# 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 +# + +from GeomDataAPI import * +from ModelAPI import * +import math +from salome.shaper import model + + +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2019-12-12" + +ANGLE_DIRECT = 0 +ANGLE_COMPLEMENTARY = 1 +ANGLE_BACKWARD = 2 + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSession.finishOperation() +#========================================================================= +# Create two lines +#========================================================================= +aSession.startOperation() +aSketchLineA = aSketchFeature.addFeature("SketchLine") +aStartPointA = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aEndPointA = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) +aStartPointA.setValue(-100., 25.) +aEndPointA.setValue(100., -25.) + +aSketchLineB = aSketchFeature.addFeature("SketchLine") +aStartPointB = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) +aEndPointB = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) +aStartPointB.setValue(-100., -25.) +aEndPointB.setValue(100., 25.) +aSession.finishOperation() +#========================================================================= +# Make a constraint to keep the angle +#========================================================================= +ANGLE_DEGREE = 30. +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintAngle") +anAngleType = aConstraint.integer("AngleType") +anAngleType.setValue(ANGLE_DIRECT) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointA")).setValue(aStartPointA.pnt()) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointB")).setValue(aStartPointB.pnt()) +aConstraint.refattr("ConstraintEntityA").setObject(aSketchLineA.firstResult()) +aConstraint.refattr("ConstraintEntityB").setObject(aSketchLineB.firstResult()) +anAngleVal = aConstraint.real("AngleValue") +anAngleVal.setValue(ANGLE_DEGREE) +aSession.finishOperation() +#========================================================================= +# Change the type of the constraint +#========================================================================= +aSession.startOperation() +anAngleType.setValue(ANGLE_COMPLEMENTARY) +aSession.finishOperation() +#========================================================================= +# Move presentation of the angle and check the angle value +#========================================================================= +pointsA = [aStartPointA.pnt(), aEndPointA.pnt()] +pointsB = [aStartPointB.pnt(), aEndPointB.pnt()] +refs = [(pointsA[0], pointsB[0], ANGLE_DEGREE), + (pointsA[0], pointsB[1], 180. - ANGLE_DEGREE), + (pointsA[1], pointsB[1], ANGLE_DEGREE), + (pointsA[1], pointsB[0], 180. - ANGLE_DEGREE), + ] +aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) +for ref in refs: + aSession.startOperation() + aFlyoutPoint.setValue(0.5 * (ref[0].x() + ref[1].x()), 0.5 * (ref[0].y() + ref[1].y())) + aSession.finishOperation() + assert(anAngleType.value() == ANGLE_COMPLEMENTARY) + assert(anAngleVal.value() == ref[2]) + assert(aStartPointA.x() == pointsA[0].x() and aStartPointA.y() == pointsA[0].y()) + assert(aEndPointA.x() == pointsA[1].x() and aEndPointA.y() == pointsA[1].y()) + assert(aStartPointB.x() == pointsB[0].x() and aStartPointB.y() == pointsB[0].y()) + assert(aEndPointB.x() == pointsB[1].x() and aEndPointB.y() == pointsB[1].y()) +#========================================================================= +# End of test +#========================================================================= + +assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintAngleBehaviorSupplementary_2.py b/src/SketchPlugin/Test/TestConstraintAngleBehaviorSupplementary_2.py new file mode 100644 index 000000000..1d431da02 --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintAngleBehaviorSupplementary_2.py @@ -0,0 +1,107 @@ +# 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 +# + +from GeomDataAPI import * +from ModelAPI import * +import math +from salome.shaper import model + + +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2019-12-12" + +ANGLE_DIRECT = 0 +ANGLE_COMPLEMENTARY = 1 +ANGLE_BACKWARD = 2 + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSession.finishOperation() +#========================================================================= +# Create two lines +#========================================================================= +aSession.startOperation() +aSketchLineA = aSketchFeature.addFeature("SketchLine") +aStartPointA = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aEndPointA = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) +aStartPointA.setValue(-100., 25.) +aEndPointA.setValue(100., -25.) + +aSketchLineB = aSketchFeature.addFeature("SketchLine") +aStartPointB = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) +aEndPointB = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) +aStartPointB.setValue(-100., -25.) +aEndPointB.setValue(100., 25.) +aSession.finishOperation() +#========================================================================= +# Make a constraint to keep the angle +#========================================================================= +ANGLE_DEGREE = 30. +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintAngle") +anAngleType = aConstraint.integer("AngleType") +anAngleType.setValue(ANGLE_COMPLEMENTARY) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointA")).setValue(aStartPointA.pnt()) +geomDataAPI_Point2D(aConstraint.attribute("SelectedPointB")).setValue(aStartPointB.pnt()) +aConstraint.refattr("ConstraintEntityA").setObject(aSketchLineA.firstResult()) +aConstraint.refattr("ConstraintEntityB").setObject(aSketchLineB.firstResult()) +anAngleVal = aConstraint.real("AngleValue") +anAngleVal.setValue(ANGLE_DEGREE) +aSession.finishOperation() +#========================================================================= +# Move presentation of the angle and check the angle value +#========================================================================= +pointsA = [aStartPointA.pnt(), aEndPointA.pnt()] +pointsB = [aStartPointB.pnt(), aEndPointB.pnt()] +refs = [(pointsA[0], pointsB[0], ANGLE_DEGREE), + (pointsA[0], pointsB[1], 180. - ANGLE_DEGREE), + (pointsA[1], pointsB[1], ANGLE_DEGREE), + (pointsA[1], pointsB[0], 180. - ANGLE_DEGREE), + ] +aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) +for ref in refs: + aSession.startOperation() + aFlyoutPoint.setValue(0.5 * (ref[0].x() + ref[1].x()), 0.5 * (ref[0].y() + ref[1].y())) + aSession.finishOperation() + assert(anAngleType.value() == ANGLE_COMPLEMENTARY) + assert(anAngleVal.value() == ref[2]) + assert(aStartPointA.x() == pointsA[0].x() and aStartPointA.y() == pointsA[0].y()) + assert(aEndPointA.x() == pointsA[1].x() and aEndPointA.y() == pointsA[1].y()) + assert(aStartPointB.x() == pointsB[0].x() and aStartPointB.y() == pointsB[0].y()) + assert(aEndPointB.x() == pointsB[1].x() and aEndPointB.y() == pointsB[1].y()) +#========================================================================= +# End of test +#========================================================================= + +assert(model.checkPythonDump()) -- 2.39.2