From a3d263fc39996448910ac7155de337e9868cfa1f Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 27 Feb 2017 17:27:11 +0300 Subject: [PATCH] Receive DoF from the solver. Update test cases to check DoF. --- src/PythonAPI/model/sketcher/__init__.py | 2 +- src/PythonAPI/model/sketcher/tools.py | 7 ++- src/SketchAPI/SketchAPI_Projection.cpp | 4 +- src/SketchPlugin/CMakeLists.txt | 2 +- src/SketchPlugin/Test/TestConstraintAngle.py | 24 ++++++---- .../Test/TestConstraintCoincidence.py | 18 +++++++- .../Test/TestConstraintCollinear.py | 6 ++- .../Test/TestConstraintDistance.py | 13 +++++- src/SketchPlugin/Test/TestConstraintEqual.py | 12 ++++- ...straintRigid.py => TestConstraintFixed.py} | 26 ++++++++--- .../Test/TestConstraintHorizontal.py | 7 ++- src/SketchPlugin/Test/TestConstraintLength.py | 7 ++- .../Test/TestConstraintMiddlePoint.py | 13 +++++- src/SketchPlugin/Test/TestConstraintMirror.py | 32 +++++-------- .../Test/TestConstraintParallel.py | 7 ++- .../Test/TestConstraintPerpendicular.py | 7 ++- src/SketchPlugin/Test/TestConstraintRadius.py | 11 ++++- .../Test/TestConstraintTangent.py | 15 ++++++- .../Test/TestConstraintVertical.py | 7 ++- src/SketchPlugin/Test/TestFillet.py | 12 +++-- src/SketchPlugin/Test/TestHighload.py | 3 ++ src/SketchPlugin/Test/TestMultiRotation.py | 11 ++++- src/SketchPlugin/Test/TestMultiTranslation.py | 11 ++++- src/SketchPlugin/Test/TestProjection.py | 8 +++- src/SketchPlugin/Test/TestRectangle.py | 5 ++- .../PlaneGCSSolver_FeatureBuilder.cpp | 28 +++++++++++- .../PlaneGCSSolver/PlaneGCSSolver_Solver.cpp | 45 ++++++++++++++++--- .../PlaneGCSSolver/PlaneGCSSolver_Solver.h | 18 ++++---- .../PlaneGCSSolver/PlaneGCSSolver_Storage.cpp | 20 ++------- .../PlaneGCSSolver/PlaneGCSSolver_Storage.h | 4 -- .../SketchSolver_ConstraintEqual.cpp | 4 +- src/SketchSolver/SketchSolver_Group.cpp | 29 ++++++++++-- src/SketchSolver/SketchSolver_Group.h | 3 ++ src/SketchSolver/SketchSolver_ISolver.h | 2 +- src/SketchSolver/SketchSolver_Storage.h | 2 - 35 files changed, 323 insertions(+), 102 deletions(-) rename src/SketchPlugin/Test/{TestConstraintRigid.py => TestConstraintFixed.py} (90%) diff --git a/src/PythonAPI/model/sketcher/__init__.py b/src/PythonAPI/model/sketcher/__init__.py index 7aa993434..994ecc6f1 100644 --- a/src/PythonAPI/model/sketcher/__init__.py +++ b/src/PythonAPI/model/sketcher/__init__.py @@ -2,4 +2,4 @@ """ from SketchAPI import addSketch -from tools import addPolyline, addPolygon +from tools import addPolyline, addPolygon, dof diff --git a/src/PythonAPI/model/sketcher/tools.py b/src/PythonAPI/model/sketcher/tools.py index fc0e39a25..31efc0f28 100644 --- a/src/PythonAPI/model/sketcher/tools.py +++ b/src/PythonAPI/model/sketcher/tools.py @@ -39,4 +39,9 @@ def addPolygon(sketch, *coords): ln.endPoint(), pg[0].startPoint() ) pg.append(ln) - return pg \ No newline at end of file + return pg + +def dof(sketch): + """ Extract degrees of freedom for the given sketch + """ + return int(filter(str.isdigit, sketch.string("SolverDOF").value())) \ No newline at end of file diff --git a/src/SketchAPI/SketchAPI_Projection.cpp b/src/SketchAPI/SketchAPI_Projection.cpp index 0b3021f79..7a074c020 100644 --- a/src/SketchAPI/SketchAPI_Projection.cpp +++ b/src/SketchAPI/SketchAPI_Projection.cpp @@ -56,14 +56,14 @@ void SketchAPI_Projection::setExternalFeature(const ModelHighAPI_Selection & the { fillAttribute(theExternalFeature, externalFeature()); - execute(); + execute(true); } void SketchAPI_Projection::setByExternalName(const std::string& theExternalName) { fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external()); - execute(); + execute(true); } //-------------------------------------------------------------------------------------- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 90d57ff70..c72d4ef9e 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -127,7 +127,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestConstraintParallel.py TestConstraintPerpendicular.py TestConstraintRadius.py - TestConstraintRigid.py + TestConstraintFixed.py TestConstraintHorizontal.py TestConstraintVertical.py TestConstraintEqual.py diff --git a/src/SketchPlugin/Test/TestConstraintAngle.py b/src/SketchPlugin/Test/TestConstraintAngle.py index 83a333546..0d88ec14f 100644 --- a/src/SketchPlugin/Test/TestConstraintAngle.py +++ b/src/SketchPlugin/Test/TestConstraintAngle.py @@ -13,8 +13,8 @@ """ from GeomDataAPI import * from ModelAPI import * -import os import math +from salome.shaper import model #========================================================================= # Auxiliary functions @@ -81,6 +81,7 @@ aEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) aStartPoint.setValue(-10., 15.) aEndPoint.setValue(80., 50.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Make a constraint to keep the angle #========================================================================= @@ -108,6 +109,7 @@ assert (anAngleVal.isInitialized()) assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) assert (angle(aSketchLineA, aSketchLineB) == ANGLE_DEGREE) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Move line, check that angle is constant #========================================================================= @@ -117,6 +119,7 @@ aStartPoint.setValue(0., -30.) aConstraint.execute() aSession.finishOperation() assert (angle(aSketchLineA, aSketchLineB) == ANGLE_DEGREE) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Change angle value and check the lines are moved #========================================================================= @@ -126,6 +129,7 @@ anAngleVal.setValue(NEW_ANGLE_DEGREE) aConstraint.execute() aSession.finishOperation() assert (angle(aSketchLineA, aSketchLineB) == NEW_ANGLE_DEGREE) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Change angle type #========================================================================= @@ -137,17 +141,21 @@ aSession.startOperation() aConstraint.integer("AngleType").setValue(ANGLE_BACKWARD) aSession.finishOperation() assert (angle(aSketchLineA, aSketchLineB) == NEW_ANGLE_DEGREE) +assert (model.dof(aSketchFeature) == 7) #========================================================================= -# TODO: improve test -# 1. remove constraint, move line's start point to -# check that constraint are not applied -# 2. check constrained distance between: -# * point and line -# * two lines +# Remove constraint, move line's point to check the constraint is not applied #========================================================================= +aSession.startOperation() +aDocument.removeFeature(aConstraint) +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) +aSession.startOperation() +aStartPoint.setValue(-30., 0.) +aSession.finishOperation() +assert (angle(aSketchLineA, aSketchLineB) != NEW_ANGLE_DEGREE) +assert (model.dof(aSketchFeature) == 8) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintCoincidence.py b/src/SketchPlugin/Test/TestConstraintCoincidence.py index f416f5d26..0ee20f691 100644 --- a/src/SketchPlugin/Test/TestConstraintCoincidence.py +++ b/src/SketchPlugin/Test/TestConstraintCoincidence.py @@ -19,6 +19,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -97,6 +99,7 @@ aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) aLineStartPoint.setValue(50., 0.) aLineEndPoint.setValue(100., 25.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 9) #========================================================================= # Link arc's end and line's start points with concidence constraint #========================================================================= @@ -108,6 +111,7 @@ reflistA.setAttr(anArcEndPoint) reflistB.setAttr(aLineStartPoint) aConstraint.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Check values and move one constrainted object #========================================================================= @@ -124,6 +128,7 @@ aSession.finishOperation() # check that arc's points are moved also assert (anArcEndPoint.x() == aLineStartPoint.x()) assert (anArcEndPoint.y() == aLineStartPoint.y()) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Remove coincidence and move the line #========================================================================= @@ -134,6 +139,7 @@ aSession.startOperation() aLineStartPoint.setValue(70., 0.) aSession.finishOperation() assert (anArcEndPoint.x() != aLineStartPoint.x() or anArcEndPoint.y() != aLineStartPoint.y()) +assert (model.dof(aSketchFeature) == 9) #========================================================================= # Add constraint point-on-line @@ -147,6 +153,7 @@ reflistB.setObject(aSketchLine.lastResult()) aConstraint.execute() aSession.finishOperation() checkPointOnLine(anArcStartPoint, aSketchLine) +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Add constraint point-on-circle #========================================================================= @@ -158,6 +165,7 @@ aCircleRadius = aSketchCircle.real("CircleRadius") aCircleCenter.setValue(10., 10.) aCircleRadius.setValue(25.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 11) # create origin aSession.startOperation() anOrigRes = modelAPI_Result(aDocument.objectByName("Construction", anOriginName)) @@ -169,6 +177,7 @@ anOriginCoord = geomDataAPI_Point2D(anOrigin.attribute("PointCoordindates")) anOriginCoord.setValue(0., 0.) anOrigin.selection("External").setValue(anOrigRes, anOrigShape) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 11) # coincidence between center of circle and the origin aSession.startOperation() aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence") @@ -177,6 +186,7 @@ reflistB = aConstraint.refattr("ConstraintEntityB") reflistA.setAttr(aCircleCenter) reflistB.setObject(anOrigin.lastResult()) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 9) # point-on-circle aSession.startOperation() aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence") @@ -187,6 +197,7 @@ reflistB.setAttr(aLineEndPoint) aConstraint.execute() aSession.finishOperation() checkPointOnCircle(aLineEndPoint, aSketchCircle) +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Add constraint point-on-arc #========================================================================= @@ -201,6 +212,7 @@ aSession.finishOperation() checkPointOnArc(aCircleCenter, aSketchArc) # check center of circle is still in origin assert (aCircleCenter.x() == 0. and aCircleCenter.y() == 0.) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Create two more lines and set multi-coincidence between their extremities @@ -219,6 +231,7 @@ aLine3EndPoint = geomDataAPI_Point2D(aLine3.attribute("EndPoint")) aLine3StartPoint.setValue(50., 0.) aLine3EndPoint.setValue(0., 100.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 15) # coincidences between extremities of lines aSession.startOperation() aConstraint12 = aSketchFeature.addFeature("SketchConstraintCoincidence") @@ -240,6 +253,7 @@ aSession.finishOperation() # check the points have same coordinates assert (aLineStartPoint.x() == aLine2StartPoint.x() and aLineStartPoint.y() == aLine2StartPoint.y()) assert (aLineStartPoint.x() == aLine3StartPoint.x() and aLineStartPoint.y() == aLine3StartPoint.y()) +assert (model.dof(aSketchFeature) == 11) #========================================================================= # Move one line and check other have been updated too #========================================================================= @@ -251,6 +265,7 @@ aLine3EndPoint.setValue(aLine3EndPoint.x() + deltaX, aSession.finishOperation() assert (aLineStartPoint.x() == aLine2StartPoint.x() and aLineStartPoint.y() == aLine2StartPoint.y()) assert (aLineStartPoint.x() == aLine3StartPoint.x() and aLineStartPoint.y() == aLine3StartPoint.y()) +assert (model.dof(aSketchFeature) == 11) #========================================================================= # Fix a line and move another connected segment #========================================================================= @@ -271,6 +286,7 @@ aSession.finishOperation() assert (aLineStartPoint.x() == coordX and aLineStartPoint.y() == coordY) assert (aLine2StartPoint.x() == coordX and aLine2StartPoint.y() == coordY) assert (aLine3StartPoint.x() == coordX and aLine3StartPoint.y() == coordY) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Detach fixed line and move one of remaining #========================================================================= @@ -289,10 +305,10 @@ aLineEndPoint.setValue(aLineEndPoint.x() + deltaX, aSession.finishOperation() assert (aLineStartPoint.x() != aLine2StartPoint.x() or aLineStartPoint.y() != aLine2StartPoint.y()) assert (aLineStartPoint.x() == aLine3StartPoint.x() and aLineStartPoint.y() == aLine3StartPoint.y()) +assert (model.dof(aSketchFeature) == 9) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintCollinear.py b/src/SketchPlugin/Test/TestConstraintCollinear.py index cb7e090ec..8097c8e62 100644 --- a/src/SketchPlugin/Test/TestConstraintCollinear.py +++ b/src/SketchPlugin/Test/TestConstraintCollinear.py @@ -11,6 +11,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -71,6 +73,7 @@ aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) aLineBStartPoint.setValue(0., 50) aLineBEndPoint.setValue(80., 75) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Link lines with collinear constraint #========================================================================= @@ -83,6 +86,7 @@ refattrB.setObject(aSketchLineB.firstResult()) aParallelConstraint.execute() aSession.finishOperation() checkCollinear(aSketchLineA, aSketchLineB) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Check values and move one constrainted object #========================================================================= @@ -97,9 +101,9 @@ aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX, aLineAEndPoint.y() - deltaY) aSession.finishOperation() checkCollinear(aSketchLineA, aSketchLineB) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index 738bab161..2c8b5c6a0 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -22,6 +22,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -84,6 +86,7 @@ aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) aLineAStartPoint.setValue(0., 25.) aLineAEndPoint.setValue(100., 25.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Make a constraint to keep the distance #========================================================================= @@ -105,6 +108,7 @@ aConstraint.execute() refattrA.setAttr(aSketchPointCoords) refattrB.setAttr(aLineAStartPoint) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 5) # set flyout point then abort operation, after that check the Distance is correct aSession.startOperation() aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) @@ -114,6 +118,7 @@ assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) assert (aDistance.isInitialized()) assert math.fabs(aDistance.value() - aDist) < 1.e-4, "Distance values are different: {0} != {1}".format(aDistance.value(), aDist) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # Change distance value #========================================================================= @@ -121,6 +126,7 @@ aSession.startOperation() aDistance.setValue(PT_PT_DIST) aSession.finishOperation() assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # Move line, check that distance is constant #========================================================================= @@ -129,6 +135,7 @@ aLineAStartPoint.setValue(0., 40.) aLineAEndPoint.setValue(100., 40.) aSession.finishOperation() assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # Remove constraint, check the points are unconstrained now #========================================================================= @@ -139,6 +146,7 @@ aSession.startOperation() aSketchPointCoords.setValue(0., 0.) aSession.finishOperation() assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) > 1.e-10) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Add distance between point and line @@ -158,6 +166,7 @@ assert (aLineResult is not None) refattrA.setObject(aLineResult) refattrB.setAttr(aSketchPointCoords) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 5) # set flyout point then abort operation, after that check the Distance is correct aSession.startOperation() aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) @@ -167,6 +176,7 @@ assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) assert (aDistance.isInitialized()) assert math.fabs(aDistance.value() - aDist) < 1.e-4, "Distance values are different: {0} != {1}".format(aDistance.value(), aDist) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # Change distance value #========================================================================= @@ -174,6 +184,7 @@ aSession.startOperation() aDistance.setValue(PT_LINE_DIST) aSession.finishOperation() assert (math.fabs(distancePointLine(aSketchPointCoords, aSketchLine) - PT_LINE_DIST) < 1.e-10) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # Set distance between line boundaries #========================================================================= @@ -182,9 +193,9 @@ refattrA.setAttr(aLineAStartPoint) refattrB.setAttr(aLineAEndPoint) aSession.finishOperation() assert (math.fabs(distancePointPoint(aLineAStartPoint, aLineAEndPoint) - PT_LINE_DIST) < 1.e-10) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintEqual.py b/src/SketchPlugin/Test/TestConstraintEqual.py index e78dd6837..c8d4917b4 100644 --- a/src/SketchPlugin/Test/TestConstraintEqual.py +++ b/src/SketchPlugin/Test/TestConstraintEqual.py @@ -11,6 +11,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -85,6 +87,7 @@ anArcStartPoint.setValue(0., 50.) anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint")) anArcEndPoint.setValue(50., 0.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 5) # Circle aSession.startOperation() aSketchCircle = aSketchFeature.addFeature("SketchCircle") @@ -93,6 +96,7 @@ aCircleRadius = aSketchCircle.real("CircleRadius") anCircleCentr.setValue(-25., -25.) aCircleRadius.setValue(25.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) #========================================================================= # A constraint to make equal radii of arc and circle #========================================================================= @@ -113,6 +117,7 @@ anArcVecX = anArcStartPoint.x() - anArcCentr.x() anArcVecY = anArcStartPoint.y() - anArcCentr.y() anArcRadius = math.sqrt(anArcVecX**2 + anArcVecY**2) assert (math.fabs(aCircRadius - anArcRadius) <= 1.e-10) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # A constraint to make equal radii of arc and external circle #========================================================================= @@ -124,6 +129,7 @@ anExtCircleCenter.setValue(-50., 50.) anExtCircleRadius.setValue(10.) anExtCircle.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchCircle_1_2") aSession.finishOperation() +assert (model.dof(aSketchFeature) == 7) aSession.startOperation() aConstraintEqRad2 = aSketchFeature.addFeature("SketchConstraintEqual") aRefObjectA = aConstraintEqRad2.refattr("ConstraintEntityA") @@ -136,6 +142,7 @@ anArcVecX = anArcStartPoint.x() - anArcCentr.x() anArcVecY = anArcStartPoint.y() - anArcCentr.y() anArcRadius = math.sqrt(anArcVecX**2 + anArcVecY**2) assert (math.fabs(anExtCircleRadius.value() - anArcRadius) <= 1.e-10) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Creation of two different lines @@ -156,6 +163,7 @@ aLine2EndPoint = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint")) aLine2StartPoint.setValue(0., 0.) aLine2EndPoint.setValue(-1., 10.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 14) #========================================================================= # A constraint to make equal lengths of lines #========================================================================= @@ -174,6 +182,7 @@ aSession.finishOperation() aLine1Len = lineLength(aSketchLine1) aLine2Len = lineLength(aSketchLine2) assert (math.fabs(aLine1Len - aLine2Len) < 1.e-10) +assert (model.dof(aSketchFeature) == 13) #========================================================================= # A constraint to make equal length of line with external line #========================================================================= @@ -186,6 +195,7 @@ anExtLineEnd.setValue(-60., 25.) anExtLine.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchLine_1") anExtLineLen = lineLength(anExtLine) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 13) aSession.startOperation() aConstraintEqLen2 = aSketchFeature.addFeature("SketchConstraintEqual") aRefObjectA = aConstraintEqLen2.refattr("ConstraintEntityA") @@ -197,9 +207,9 @@ aLine1Len = lineLength(aSketchLine1) aLine2Len = lineLength(aSketchLine2) assert (math.fabs(aLine1Len - anExtLineLen) < 1.e-10) assert (math.fabs(aLine2Len - anExtLineLen) < 1.e-10) +assert (model.dof(aSketchFeature) == 12) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintRigid.py b/src/SketchPlugin/Test/TestConstraintFixed.py similarity index 90% rename from src/SketchPlugin/Test/TestConstraintRigid.py rename to src/SketchPlugin/Test/TestConstraintFixed.py index e3f43b513..d3b631530 100644 --- a/src/SketchPlugin/Test/TestConstraintRigid.py +++ b/src/SketchPlugin/Test/TestConstraintFixed.py @@ -1,7 +1,7 @@ """ TestConstraintRigid.py Unit test of SketchPlugin_ConstraintRigid class - + SketchPlugin_Constraint static const std::string MY_CONSTRAINT_VALUE("ConstraintValue"); static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); @@ -9,7 +9,7 @@ static const std::string MY_ENTITY_B("ConstraintEntityB"); static const std::string MY_ENTITY_C("ConstraintEntityC"); static const std::string MY_ENTITY_D("ConstraintEntityD"); - + SketchPlugin_ConstraintRigid static const std::string MY_CONSTRAINT_RIGID_ID("SketchConstraintRigid"); data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); @@ -18,6 +18,8 @@ from GeomDataAPI import * from ModelAPI import * from GeomAPI import * +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -59,6 +61,7 @@ aLineBEndPoint.setValue(60., 75.) aLineCStartPoint.setValue(60., 75.) aLineCEndPoint.setValue(25., 25.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 12) # Store initial values of lines kLineAStart = (aLineAStartPoint.x(), aLineAStartPoint.y()) kLineAEnd = (aLineAEndPoint.x(), aLineAEndPoint.y()) @@ -80,6 +83,7 @@ for eachLink in concidenceLinks: reflistB.setAttr(eachLink[1]) aConstraint.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 6) # Check that constarints doesn't affected lines' values assert (kLineAStart == (aLineAStartPoint.x(), aLineAStartPoint.y())) @@ -108,6 +112,8 @@ aSession.finishOperation() assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLineCEndPoint.y())) assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y())) assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y())) +assert (model.dof(aSketchFeature) == 2) + #========================================================================= # Check that moving line A does not affect lines #========================================================================= @@ -118,6 +124,8 @@ aSession.finishOperation() assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLineCEndPoint.y())) assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y())) assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y())) +assert (model.dof(aSketchFeature) == 2) + #========================================================================= # Check that moving line B does not affect lines #========================================================================= @@ -128,13 +136,21 @@ aSession.finishOperation() assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLineCEndPoint.y())) assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y())) assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y())) +assert (model.dof(aSketchFeature) == 2) + #========================================================================= -# TODO: improve test -# 1. remove constraint, move line to check that constraint are not applied +# Remove constraint, move line to check that it is not fixed #========================================================================= +aSession.startOperation() +aDocument.removeFeature(aRigidConstraint) +aLineBEndPoint.setValue(90., 150.) +aSession.finishOperation() +assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLineCEndPoint.y())) +assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y())) +assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y())) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintHorizontal.py b/src/SketchPlugin/Test/TestConstraintHorizontal.py index f0a55dfe7..fa7c6cc04 100644 --- a/src/SketchPlugin/Test/TestConstraintHorizontal.py +++ b/src/SketchPlugin/Test/TestConstraintHorizontal.py @@ -9,6 +9,8 @@ """ from GeomDataAPI import * from ModelAPI import * +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -40,6 +42,7 @@ aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) aLineStartPoint.setValue(0., 15.) aLineEndPoint.setValue(20., 25.) aSession.finishOperation() +assert(model.dof(aSketchFeature) == 4) #========================================================================= # Assign horizontal constraint for a line #========================================================================= @@ -52,6 +55,7 @@ refattrA.setObject(aResult) aHorizontalConstraint.execute() aSession.finishOperation() assert(aLineStartPoint.y() == aLineEndPoint.y()) +assert(model.dof(aSketchFeature) == 3) #========================================================================= # Move one of boundary points of a line #========================================================================= @@ -61,6 +65,7 @@ aLineStartPoint.setValue(aLineStartPoint.x() + deltaX, aLineStartPoint.y() + deltaY) aSession.finishOperation() assert(aLineStartPoint.y() == aLineEndPoint.y()) +assert(model.dof(aSketchFeature) == 3) #========================================================================= # Move other boundary point of a line #========================================================================= @@ -71,9 +76,9 @@ aLineEndPoint.setValue(aLineEndPoint.x() + deltaX, aLineEndPoint.y() + deltaY) aSession.finishOperation() assert(aLineStartPoint.y() == aLineEndPoint.y()) +assert(model.dof(aSketchFeature) == 3) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintLength.py b/src/SketchPlugin/Test/TestConstraintLength.py index 3d49d5317..ac1345d4d 100644 --- a/src/SketchPlugin/Test/TestConstraintLength.py +++ b/src/SketchPlugin/Test/TestConstraintLength.py @@ -12,6 +12,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -43,6 +45,7 @@ aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) aLineAStartPoint.setValue(0., 25.) aLineAEndPoint.setValue(100., 25.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 4) #========================================================================= # Make a constraint to keep the length #========================================================================= @@ -61,6 +64,7 @@ aLengthConstraint.execute() aSession.finishOperation() assert (aLength.isInitialized()) assert (refattrA.isInitialized()) +assert (model.dof(aSketchFeature) == 3) #========================================================================= # Check values and move one constrainted object #========================================================================= @@ -74,6 +78,7 @@ aSession.startOperation() aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, aLineAStartPoint.y()) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 3) assert (aLineAStartPoint.y() == 25) assert (aLineAEndPoint.y() == 25) # length of the line is the same @@ -86,6 +91,7 @@ aLength.setValue(140.) aLengthConstraint.execute() aSession.finishOperation() assert (math.fabs(aLineAEndPoint.x() - aLineAStartPoint.x() - 140) < 1.e-10) +assert (model.dof(aSketchFeature) == 3) #========================================================================= # TODO: improve test # 1. remove constraint, move line's start point to @@ -95,5 +101,4 @@ assert (math.fabs(aLineAEndPoint.x() - aLineAStartPoint.x() - 140) < 1.e-10) # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintMiddlePoint.py b/src/SketchPlugin/Test/TestConstraintMiddlePoint.py index b9b0e70b7..d8e69beb8 100644 --- a/src/SketchPlugin/Test/TestConstraintMiddlePoint.py +++ b/src/SketchPlugin/Test/TestConstraintMiddlePoint.py @@ -19,6 +19,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -78,6 +80,7 @@ aEndPoint2 = geomDataAPI_Point2D(aLine2.attribute("EndPoint")) 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 #========================================================================= @@ -106,6 +109,7 @@ reflistA.setAttr(aEndPoint2) reflistB.setObject(aLine1.lastResult()) aConstraint.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Check values and move one constrainted object @@ -116,6 +120,7 @@ aSession.startOperation() aStartPoint1.setValue(aStartPoint1.x() + deltaX, aStartPoint1.y() + deltaY) aSession.finishOperation() checkMiddlePoint(aEndPoint2, aLine1) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Remove constraint and move the line #========================================================================= @@ -123,10 +128,12 @@ aCurX, aCurY = aEndPoint2.x(), aEndPoint2.y() 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 @@ -142,6 +149,7 @@ anOriginCoord = geomDataAPI_Point2D(anOrigin.attribute("PointCoordindates")) 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") @@ -151,6 +159,7 @@ reflistA.setObject(aLine2.lastResult()) reflistB.setObject(anOrigin.lastResult()) aSession.finishOperation() checkMiddlePoint(anOriginCoord, aLine2) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Check origin coordinates does not changed #========================================================================= @@ -171,6 +180,7 @@ reflistB = aCoincidence.refattr("ConstraintEntityB") reflistA.setAttr(aEndPoint3) reflistB.setObject(aLine1.lastResult()) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 9) #========================================================================= # Set Middle point #========================================================================= @@ -183,6 +193,7 @@ 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 @@ -196,10 +207,10 @@ 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 #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintMirror.py b/src/SketchPlugin/Test/TestConstraintMirror.py index e357e3898..78fe2fbdc 100644 --- a/src/SketchPlugin/Test/TestConstraintMirror.py +++ b/src/SketchPlugin/Test/TestConstraintMirror.py @@ -12,6 +12,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -109,6 +111,7 @@ aLine2EndPoint = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint")) aLine2StartPoint.setValue(50., 0.) aLine2EndPoint.setValue(100., 0.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 13) #========================================================================= # Link arc points and lines points by the coincidence constraint #========================================================================= @@ -128,6 +131,7 @@ reflistA.setAttr(anArcEndPoint) reflistB.setAttr(aLine2StartPoint) aConstraint.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 9) #========================================================================= # Add tangency constraint and check correctness #========================================================================= @@ -143,6 +147,7 @@ aRefObjectA.setObject(anObjectA) aRefObjectB.setObject(anObjectB) aTangency.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Create mirror line #========================================================================= @@ -153,6 +158,7 @@ aLineEndPoint = geomDataAPI_Point2D(aMirrorLine.attribute("EndPoint")) aLineStartPoint.setValue(100., 0.) aLineEndPoint.setValue(100., 100.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 12) #========================================================================= # Make mirror for objects created above #========================================================================= @@ -166,6 +172,7 @@ aRefListInitial.append(aSketchArc1.lastResult()) aRefListInitial.append(aSketchLine2.lastResult()) aMirror.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 12) #========================================================================= # Verify the simmetricity of all mirrored objects #========================================================================= @@ -174,6 +181,7 @@ aRefListC = aMirror.reflist("ConstraintEntityC") assert (aRefListB.size() == 3) assert (aRefListC.size() == 3) checkMirror(aRefListB, aRefListC, aMirrorLine) +assert (model.dof(aSketchFeature) == 12) #========================================================================= # Remove object from mirror @@ -184,6 +192,7 @@ aSession.finishOperation() assert (aRefListB.size() == 2) assert (aRefListC.size() == 2) checkMirror(aRefListB, aRefListC, aMirrorLine) +assert (model.dof(aSketchFeature) == 12) #========================================================================= # Clear list of mirrored features @@ -198,30 +207,9 @@ aSession.finishOperation() assert (aRefListB.size() == 1) assert (aRefListC.size() == 1) checkMirror(aRefListB, aRefListC, aMirrorLine) +assert (model.dof(aSketchFeature) == 12) #========================================================================= # End of test #========================================================================= - -# make second line fixed -aSession.startOperation() -aFixed = aSketchFeature.addFeature("SketchConstraintRigid") -aRefObjectA = aFixed.refattr("ConstraintEntityA") -anObjectA = modelAPI_ResultConstruction(aSketchLine2.lastResult()) -assert (anObjectA is not None) -aRefObjectA.setObject(anObjectA) -aFixed.execute() -aSession.finishOperation() -# set mirror for first line to check dumping -aSession.startOperation() -aRefListInitial.clear() -assert (aRefListB.size() == 0) -assert (aRefListC.size() == 0) -aRefListInitial.append(aSketchLine1.lastResult()) -aSession.finishOperation() -assert (aRefListB.size() == 1) -assert (aRefListC.size() == 1) -checkMirror(aRefListB, aRefListC, aMirrorLine) - -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintParallel.py b/src/SketchPlugin/Test/TestConstraintParallel.py index 2dd6ce202..0570ec3fc 100644 --- a/src/SketchPlugin/Test/TestConstraintParallel.py +++ b/src/SketchPlugin/Test/TestConstraintParallel.py @@ -11,6 +11,8 @@ """ from GeomDataAPI import * from ModelAPI import * +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -49,6 +51,7 @@ aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) aLineBStartPoint.setValue(0., 50) aLineBEndPoint.setValue(80., 75) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Make a constraint to keep the length of the line constant # to parallel perpendicular constraint collapsing line to point @@ -71,6 +74,7 @@ assert (aLineBStartPoint.x() == 0) assert (aLineBStartPoint.y() == 50) assert (aLineBEndPoint.x() == 80) assert (aLineBEndPoint.y() == 75) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Link lines with parallel constraint #========================================================================= @@ -87,6 +91,7 @@ refattrA.setObject(aResultA) refattrB.setObject(aResultB) aParallelConstraint.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 5) #========================================================================= # Check values and move one constrainted object #========================================================================= @@ -105,9 +110,9 @@ aLineBEndPointNew = (aLineBEndPoint.x(), aLineBEndPoint.y()) assert (aLineBStartPointPrev != aLineBStartPointNew) assert (aLineBEndPointPrev != aLineBEndPointNew) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintPerpendicular.py b/src/SketchPlugin/Test/TestConstraintPerpendicular.py index f1d321362..43fa7aaf3 100644 --- a/src/SketchPlugin/Test/TestConstraintPerpendicular.py +++ b/src/SketchPlugin/Test/TestConstraintPerpendicular.py @@ -18,6 +18,8 @@ """ from GeomDataAPI import * from ModelAPI import * +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -56,6 +58,7 @@ aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) aLineBStartPoint.setValue(25., 40.) aLineBEndPoint.setValue(25., 125.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Make a constraint to keep the length of the line constant # to prevent perpendicular constraint collapsing line to point @@ -79,6 +82,7 @@ assert (aLineBStartPoint.x() == 25) assert (aLineBStartPoint.y() == 40) assert (aLineBEndPoint.x() == 25) assert (aLineBEndPoint.y() == 125) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Link lines with perpendicular constraint #========================================================================= @@ -94,6 +98,7 @@ refattrA.setObject(aResultA) refattrB.setObject(aResultB) aPerpendicularConstraint.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 5) #========================================================================= # Check values and move one constrainted object #========================================================================= @@ -118,9 +123,9 @@ aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX, aLineAEndPoint.y() - deltaY aSession.finishOperation() assert (aLineBStartPointPrev != (aLineBStartPoint.x(), aLineBStartPoint.y())) assert (aLineBEndPointPrev != (aLineBEndPoint.x(), aLineBEndPoint.y())) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintRadius.py b/src/SketchPlugin/Test/TestConstraintRadius.py index 9513b01ea..9ba906752 100644 --- a/src/SketchPlugin/Test/TestConstraintRadius.py +++ b/src/SketchPlugin/Test/TestConstraintRadius.py @@ -20,6 +20,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -63,6 +65,7 @@ anArcStartPoint.setValue(0., 50.) anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint")) anArcEndPoint.setValue(50., 0.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 5) # Test changing the arc start/end point aSession.startOperation() anArcStartPoint.setValue(anArcStartPoint.x(), 40.) @@ -74,6 +77,7 @@ anArcEndPoint.setValue(40., anArcEndPoint.y()) anArcEndPoint.setValue(50., 0.) assert (math.hypot(anArcEndPoint.x() - 50., anArcEndPoint.y() - 0.) < 1.e-10) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 5) # Circle aSession.startOperation() aSketchCircle = aSketchFeature.addFeature("SketchCircle") @@ -82,12 +86,14 @@ aCircleRadius = aSketchCircle.real("CircleRadius") anCircleCentr.setValue(-25., -25) aCircleRadius.setValue(25.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) # Change the radius of the arc aSession.startOperation() RADIUS = 40 anArcRadius = aSketchArc.real("ArcRadius") anArcRadius.setValue(RADIUS) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Make a constraint to keep the radius of the arc #========================================================================= @@ -102,6 +108,7 @@ aConstraint.execute() aSession.finishOperation() assert (aRadius.isInitialized()) assert (aRefObject.isInitialized()) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Make a constraint to keep the radius of the circle #========================================================================= @@ -116,6 +123,7 @@ aConstraint.execute() aSession.finishOperation() assert (aRadius.isInitialized()) assert (aRefObject.isInitialized()) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # Perform some actions and checks: # 1. Check that constraints does not changes values @@ -134,6 +142,7 @@ assert (anArcEndPoint.x() != anArcPrevEndPointX) assert (anArcEndPoint.y() != anArcPrevEndPointY) assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10) assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # 4. Move the centr or the point of the arc # 5. Check radius is the same @@ -147,9 +156,9 @@ aSession.finishOperation() assert (anCircleCentr.x() == 100) assert (anCircleCentr.y() == 100) assert (aCircleRadius.value() == 25) +assert (model.dof(aSketchFeature) == 6) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintTangent.py b/src/SketchPlugin/Test/TestConstraintTangent.py index 90d6cd8fa..03c9334f3 100644 --- a/src/SketchPlugin/Test/TestConstraintTangent.py +++ b/src/SketchPlugin/Test/TestConstraintTangent.py @@ -12,6 +12,8 @@ from GeomDataAPI import * from GeomAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -82,6 +84,7 @@ aLine2EndPoint = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint")) aLine2StartPoint.setValue(50., 0.) aLine2EndPoint.setValue(100., 0.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 13) #========================================================================= # Link arc points and lines points by the coincidence constraint #========================================================================= @@ -101,6 +104,7 @@ reflistA.setAttr(anArcEndPoint) reflistB.setAttr(aLine2StartPoint) aConstraint.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 9) #========================================================================= # Add tangency constraint and check correctness #========================================================================= @@ -124,6 +128,7 @@ aLineVecY = aLine1EndPoint.y() - aLine1StartPoint.y() aLen = aLen * math.sqrt(aLineVecX**2 + aLineVecY**2) aDot = anArcVecX * aLineVecX + anArcVecY * aLineVecY assert math.fabs(aDot) <= 2.e-6 * aLen, "Observed dot product: {0}".format(aDot) +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Add tangency constraint for arc and second line and check correctness #========================================================================= @@ -147,6 +152,7 @@ aLineVecY = aLine2EndPoint.y() - aLine2StartPoint.y() aLen = aLen * math.sqrt(aLineVecX**2 + aLineVecY**2) aDot = anArcVecX * aLineVecX + anArcVecY * aLineVecY assert math.fabs(aDot) <= 2.e-6 * aLen, "Observed dot product: {0}".format(aDot) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # TEST 2. Arc-arc tangency @@ -175,6 +181,7 @@ anArc2EndPoint.setValue(-50., 0.) anArc2PassedPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcPassedPoint")) anArc2PassedPoint.setValue(-40., 40.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 17) #========================================================================= # Link points of arcs by the coincidence constraint #========================================================================= @@ -186,6 +193,7 @@ reflistA.setAttr(anArc1EndPoint) reflistB.setAttr(anArc2StartPoint) aConstraint.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 15) #========================================================================= # Add tangency constraint and check correctness #========================================================================= @@ -209,6 +217,7 @@ anArc2VecY = anArc2StartPoint.y() - anArc2Centr.y() aLen = aLen * math.sqrt(anArc2VecX**2 + anArc2VecY**2) aCross = anArc1VecX * anArc2VecY - anArc1VecY * anArc2VecX assert math.fabs(aCross) <= 2.e-6 * aLen, "Observed cross product: {0}".format(aCross) +assert (model.dof(aSketchFeature) == 14) #========================================================================= # TEST 3. Tangency between non-connected objects should be wrong @@ -245,9 +254,11 @@ assert(aLine2EndPointNew == aLine2EndPointPrev) assert(anArc2CenterNew == anArc2CenterPrev) assert(anArc2StartPointNew == anArc2StartPointPrev) assert(anArc2EndPointNew == anArc2EndPointPrev) +assert (model.dof(aSketchFeature) == 14) aSession.startOperation() aDocument.removeFeature(aTangency) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 14) #========================================================================= # TEST 4. Creating of tangency arc by the option of the SketchArc feature @@ -271,6 +282,7 @@ anArc3VecY = anArc3StartPoint.y() - anArc3Center.y() aLen = aLen * math.sqrt(anArc3VecX**2 + anArc3VecY**2) aCross = anArc1VecX * anArc3VecY - anArc1VecY * anArc3VecX assert math.fabs(aCross) <= 2.e-6 * aLen, "Observed cross product: {0}".format(aCross) +assert (model.dof(aSketchFeature) == 19) #========================================================================= # TEST 5. Creating of tangency between line and circle @@ -287,6 +299,7 @@ aCircleRadius = aCircle.real("CircleRadius") aCircleCenter.setValue(150., 100.) aCircleRadius.setValue(20.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 26) aSession.startOperation() aTangency = aSketchFeature.addFeature("SketchConstraintTangent") @@ -302,9 +315,9 @@ aTangency.execute() aSession.finishOperation() assert(math.fabs(distancePointLine(aCircleCenter, aLine) - round(aCircleRadius.value(), 5)) < 1.e-10) +assert (model.dof(aSketchFeature) == 25) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestConstraintVertical.py b/src/SketchPlugin/Test/TestConstraintVertical.py index 8bbc541cd..1fe6af272 100644 --- a/src/SketchPlugin/Test/TestConstraintVertical.py +++ b/src/SketchPlugin/Test/TestConstraintVertical.py @@ -9,6 +9,8 @@ """ from GeomDataAPI import * from ModelAPI import * +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -40,6 +42,7 @@ aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) aLineStartPoint.setValue(0., 15.) aLineEndPoint.setValue(20., 25.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 4) #========================================================================= # Assign vertical constraint for a line #========================================================================= @@ -52,6 +55,7 @@ refattrA.setObject(aResult) aVerticalConstraint.execute() aSession.finishOperation() assert(aLineStartPoint.x() == aLineEndPoint.x()) +assert (model.dof(aSketchFeature) == 3) #========================================================================= # Move one of boundary points of a line #========================================================================= @@ -61,6 +65,7 @@ aLineStartPoint.setValue(aLineStartPoint.x() + deltaX, aLineStartPoint.y() + deltaY) aSession.finishOperation() assert(aLineStartPoint.x() == aLineEndPoint.x()) +assert (model.dof(aSketchFeature) == 3) #========================================================================= # Move other boundary point of a line #========================================================================= @@ -71,9 +76,9 @@ aLineEndPoint.setValue(aLineEndPoint.x() + deltaX, aLineEndPoint.y() + deltaY) aSession.finishOperation() assert(aLineStartPoint.x() == aLineEndPoint.x()) +assert (model.dof(aSketchFeature) == 3) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestFillet.py b/src/SketchPlugin/Test/TestFillet.py index e005bee4e..e58e27ba8 100644 --- a/src/SketchPlugin/Test/TestFillet.py +++ b/src/SketchPlugin/Test/TestFillet.py @@ -13,6 +13,7 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model #========================================================================= # Auxiliary functions @@ -21,7 +22,7 @@ aStartPoint1 = [] def createSketch1(theSketch): global aEndPoint1, aEndPoint2 - # Initialize sketch by two lines with coincident boundary + # Initialize sketch by three lines with coincident boundaries allFeatures = [] # Line1 aSketchLine1 = theSketch.addFeature("SketchLine") @@ -178,7 +179,7 @@ norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) norm.setValue(0, 0, 1) aSession.finishOperation() #========================================================================= -# Initialize sketch by two lines +# Initialize sketch by three connected lines #========================================================================= aSession.startOperation() aFeaturesList = createSketch1(aSketchFeature) @@ -186,6 +187,7 @@ aSession.finishOperation() aSketchSubFeatures = [] for aSubIndex in range(0, aSketchFeature.numberOfSubs()): aSketchSubFeatures.append(aSketchFeature.subFeature(aSubIndex)) +assert (model.dof(aSketchFeature) == 8) #========================================================================= # Global variables #========================================================================= @@ -215,6 +217,7 @@ for aSubIndex in range(0, aSketchFeature.numberOfSubs()): #========================================================================= assert(aResObjects) checkFillet(aResObjects, FILLET_RADIUS1) +assert model.dof(aSketchFeature) == 8, "PlaneGCS limitation: if you see this message, then PlaneGCS has solved DoF for sketch with fillet correctly (expected DoF = 10, observed = {0}".format(model.dof(aSketchFeature)) #========================================================================= # Change Fillet radius #========================================================================= @@ -222,6 +225,7 @@ aRadius.setValue(FILLET_RADIUS2) aFillet.execute() aSession.finishOperation() checkFillet(aResObjects, FILLET_RADIUS2) +assert model.dof(aSketchFeature) == 14, "PlaneGCS limitation: if you see this message, then PlaneGCS has solved DoF for sketch with fillet correctly (expected DoF = 10, observed = {0}".format(model.dof(aSketchFeature)) #========================================================================= # Create another sketch @@ -245,6 +249,7 @@ aSession.finishOperation() aSketchSubFeatures = [] for aSubIndex in range(0, aSketchFeature.numberOfSubs()): aSketchSubFeatures.append(aSketchFeature.subFeature(aSubIndex)) +assert (model.dof(aSketchFeature) == 7) #========================================================================= # Create the Fillet #========================================================================= @@ -268,6 +273,7 @@ for aSubIndex in range(0, aSketchFeature.numberOfSubs()): #========================================================================= assert(aResObjects) checkFillet(aResObjects, FILLET_RADIUS1) +assert model.dof(aSketchFeature) == 7, "PlaneGCS limitation: if you see this message, then PlaneGCS has solved DoF for sketch with fillet correctly (expected DoF = 8, observed = {0}".format(model.dof(aSketchFeature)) #========================================================================= # Change Fillet radius #========================================================================= @@ -275,9 +281,9 @@ aRadius.setValue(FILLET_RADIUS2) aFillet.execute() aSession.finishOperation() checkFillet(aResObjects, FILLET_RADIUS2) +assert model.dof(aSketchFeature) == 11, "PlaneGCS limitation: if you see this message, then PlaneGCS has solved DoF for sketch with fillet correctly (expected DoF = 8, observed = {0}".format(model.dof(aSketchFeature)) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestHighload.py b/src/SketchPlugin/Test/TestHighload.py index f78be7ff2..0825ff115 100644 --- a/src/SketchPlugin/Test/TestHighload.py +++ b/src/SketchPlugin/Test/TestHighload.py @@ -102,6 +102,7 @@ aSession.finishOperation() #========================================================================= # Create 4x4 polygons N = {5, 21} #========================================================================= +aDOF = 0 deltaX = deltaY = 50. n = 5 aSession.startOperation() @@ -110,6 +111,7 @@ for i in xrange(4): allNangleLines = createNAngle(aSketchFeature, n, 50) fixLineLength(aSketchFeature, allNangleLines) moveTo(allNangleLines, deltaX, deltaY) + aDOF += n n += 1 deltaX += 110. deltaY += 110. @@ -122,4 +124,5 @@ aSession.finishOperation() #========================================================================= from salome.shaper import model +assert(model.dof(aSketchFeature) == aDOF) assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestMultiRotation.py b/src/SketchPlugin/Test/TestMultiRotation.py index 2a61103ec..7328e497c 100644 --- a/src/SketchPlugin/Test/TestMultiRotation.py +++ b/src/SketchPlugin/Test/TestMultiRotation.py @@ -16,6 +16,7 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model #========================================================================= # Auxiliary functions @@ -114,6 +115,7 @@ aSession.finishOperation() aSession.startOperation() aFeaturesList = createSketch(aSketchFeature) aSession.finishOperation() +assert(model.dof(aSketchFeature) == 5) #========================================================================= # Global variables #========================================================================= @@ -128,6 +130,7 @@ aRotationPoint = aSketchFeature.addFeature("SketchPoint") aRotationPointPoint = geomDataAPI_Point2D(aRotationPoint.attribute("PointCoordindates")) aRotationPointPoint.setValue(CENTER_X, CENTER_Y) aSession.finishOperation() +assert(model.dof(aSketchFeature) == 7) #========================================================================= # Create the Rotation constraint #========================================================================= @@ -155,6 +158,7 @@ aNbCopies = aMultiRotation.integer("MultiRotationObjects") aNbCopies.setValue(2) aMultiRotation.execute() aSession.finishOperation() +assert(model.dof(aSketchFeature) == 7) #========================================================================= # Verify the objects are moved for the specified distance #========================================================================= @@ -168,6 +172,7 @@ aNbCopies.setValue(3) aSession.finishOperation() aRotated = aMultiRotation.reflist("ConstraintEntityB") checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE) +assert(model.dof(aSketchFeature) == 7) #========================================================================= # Create new feature and add it into the Rotation @@ -181,6 +186,7 @@ assert(aResult is not None) aRotList.append(aResult) aSession.finishOperation() checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE) +assert(model.dof(aSketchFeature) == 11) #========================================================================= # Move line and check the copies are moved too #========================================================================= @@ -189,6 +195,7 @@ aStartPoint = geomDataAPI_Point2D(aLine.attribute("StartPoint")) aStartPoint.setValue(12., 5.) aSession.finishOperation() checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE) +assert(model.dof(aSketchFeature) == 11) #========================================================================= # Change number of copies and verify Rotation #========================================================================= @@ -196,6 +203,7 @@ aSession.startOperation() aNbCopies.setValue(2) aSession.finishOperation() checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE) +assert(model.dof(aSketchFeature) == 11) #========================================================================= # Remove a feature from the Rotation @@ -205,6 +213,7 @@ aRemoveIt = aRotList.object(0) aRotList.remove(aRemoveIt) aSession.finishOperation() checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE) +assert(model.dof(aSketchFeature) == 11) #========================================================================= # Clear the list of rotated features @@ -216,9 +225,9 @@ checkRotation(aRotated, 1, CENTER_X, CENTER_Y, ANGLE) aRotList.append(aResult) aSession.finishOperation() checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE) +assert(model.dof(aSketchFeature) == 11) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestMultiTranslation.py b/src/SketchPlugin/Test/TestMultiTranslation.py index edb25d517..80eb90ed1 100644 --- a/src/SketchPlugin/Test/TestMultiTranslation.py +++ b/src/SketchPlugin/Test/TestMultiTranslation.py @@ -15,6 +15,7 @@ """ from GeomDataAPI import * from ModelAPI import * +from salome.shaper import model #========================================================================= # Auxiliary functions @@ -106,6 +107,7 @@ aSession.finishOperation() aSession.startOperation() aFeaturesList = createSketch(aSketchFeature) aSession.finishOperation() +assert(model.dof(aSketchFeature) == 5) #========================================================================= # Global variables #========================================================================= @@ -125,6 +127,7 @@ aTransLineEndPoint = geomDataAPI_Point2D(aTransLine.attribute("EndPoint")) aTransLineStartPoint.setValue(START_X, START_Y) aTransLineEndPoint.setValue(START_X + DELTA_X, START_Y + DELTA_Y) aSession.finishOperation() +assert(model.dof(aSketchFeature) == 9) #========================================================================= # Create the Translation constraint #========================================================================= @@ -146,6 +149,7 @@ aNbCopies = aMultiTranslation.integer("MultiTranslationObjects") aNbCopies.setValue(2) aMultiTranslation.execute() aSession.finishOperation() +assert(model.dof(aSketchFeature) == 9) #========================================================================= # Verify the objects are moved for the specified distance #========================================================================= @@ -159,6 +163,7 @@ aNbCopies.setValue(3) aSession.finishOperation() aTranslated = aMultiTranslation.reflist("ConstraintEntityB") checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y) +assert(model.dof(aSketchFeature) == 9) #========================================================================= # Create new feature and add it into the Rotation @@ -172,6 +177,7 @@ assert(aResult is not None) aTransList.append(aResult) aSession.finishOperation() checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y) +assert(model.dof(aSketchFeature) == 13) #========================================================================= # Move line and check the copies are moved too #========================================================================= @@ -180,6 +186,7 @@ aStartPoint = geomDataAPI_Point2D(aLine.attribute("StartPoint")) aStartPoint.setValue(12., 5.) aSession.finishOperation() checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y) +assert(model.dof(aSketchFeature) == 13) #========================================================================= # Change number of copies and verify Rotation #========================================================================= @@ -187,6 +194,7 @@ aSession.startOperation() aNbCopies.setValue(2) aSession.finishOperation() checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y) +assert(model.dof(aSketchFeature) == 13) #========================================================================= # Remove a feature from the Rotation @@ -196,6 +204,7 @@ aRemoveIt = aTransList.object(0) aTransList.remove(aRemoveIt) aSession.finishOperation() checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y) +assert(model.dof(aSketchFeature) == 13) #========================================================================= # Clear the list of rotated features @@ -207,9 +216,9 @@ checkTranslation(aTranslated, 1, DELTA_X, DELTA_Y) aTransList.append(aResult) aSession.finishOperation() checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y) +assert(model.dof(aSketchFeature) == 13) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestProjection.py b/src/SketchPlugin/Test/TestProjection.py index eddc1e744..9477cdc74 100644 --- a/src/SketchPlugin/Test/TestProjection.py +++ b/src/SketchPlugin/Test/TestProjection.py @@ -6,6 +6,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -54,6 +56,7 @@ anArcCenter.setValue(10., 10.) anArcStart.setValue(50., 0.) anArcEnd.setValue(0., 50.) aSession.finishOperation() +assert (model.dof(aSketchFeature) == 12) #========================================================================= # Create another sketch #========================================================================= @@ -82,6 +85,7 @@ anArcProjector = aSketchFeature.addFeature("SketchProjection") anArcProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchArc_1_2") anArcProjector.execute() aSession.finishOperation() +assert (model.dof(aSketchFeature) == 0) #========================================================================= # Check projection coordinates #========================================================================= @@ -122,9 +126,9 @@ assert(math.fabs(aProjLineStart.x() - aLineStart.x()) < 1.e-10) assert(math.fabs(aProjLineStart.y() - aLineStart.y()) < 1.e-10) assert(math.fabs(aProjLineEnd.x() - aLineEnd.x()) < 1.e-10) assert(math.fabs(aProjLineEnd.y() - aLineEnd.y()) < 1.e-10) +assert (model.dof(aSketchFeature) == 0) #========================================================================= # End of test #========================================================================= -#from salome.shaper import model -#assert(model.checkPythonDump()) +assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestRectangle.py b/src/SketchPlugin/Test/TestRectangle.py index a2edbe9d3..69ebc56a7 100644 --- a/src/SketchPlugin/Test/TestRectangle.py +++ b/src/SketchPlugin/Test/TestRectangle.py @@ -6,6 +6,8 @@ from GeomDataAPI import * from ModelAPI import * import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= @@ -66,6 +68,7 @@ for i in range (0, aNbSubs): assert (isHorizontal(aLastLine) or isVertical(aLastLine)) aNbLines = aNbLines + 1 assert (aNbLines == 4) +assert (model.dof(aSketchFeature) == 4) #========================================================================= # Move one of lines #========================================================================= @@ -85,9 +88,9 @@ for i in range (0, aNbSubs): assert (isHorizontal(aLastLine) or isVertical(aLastLine)) aNbLines = aNbLines + 1 assert (aNbLines == 4) +assert (model.dof(aSketchFeature) == 4) #========================================================================= # End of test #========================================================================= -from salome.shaper import model assert(model.checkPythonDump()) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_FeatureBuilder.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_FeatureBuilder.cpp index fdcc98b44..a0ffc362f 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_FeatureBuilder.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_FeatureBuilder.cpp @@ -19,6 +19,9 @@ #include #include +static bool isAttributeApplicable(const std::string& theAttrName, + const std::string& theOwnerName); + static EntityWrapperPtr createLine(const AttributeEntityMap& theAttributes); static EntityWrapperPtr createCircle(const AttributeEntityMap& theAttributes); static EntityWrapperPtr createArc(const AttributeEntityMap& theAttributes, @@ -40,7 +43,10 @@ PlaneGCSSolver_FeatureBuilder::PlaneGCSSolver_FeatureBuilder(const StoragePtr& t EntityWrapperPtr PlaneGCSSolver_FeatureBuilder::createAttribute( AttributePtr theAttribute) { - EntityWrapperPtr anAttr = PlaneGCSSolver_AttributeBuilder::createAttribute(theAttribute); + FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner()); + EntityWrapperPtr anAttr; + if (isAttributeApplicable(theAttribute->id(), anOwner->getKind())) + anAttr = PlaneGCSSolver_AttributeBuilder::createAttribute(theAttribute); if (anAttr) myAttributes[theAttribute] = anAttr; return anAttr; @@ -199,3 +205,23 @@ EntityWrapperPtr createArc(const AttributeEntityMap& theAttributes, return EntityWrapperPtr(new PlaneGCSSolver_EntityWrapper(aNewArc)); } + +bool isAttributeApplicable(const std::string& theAttrName, const std::string& theOwnerName) +{ + if (theOwnerName == SketchPlugin_Arc::ID()) { + return theAttrName == SketchPlugin_Arc::CENTER_ID() || + theAttrName == SketchPlugin_Arc::START_ID() || + theAttrName == SketchPlugin_Arc::END_ID(); + } + else if (theOwnerName == SketchPlugin_Circle::ID()) { + return theAttrName == SketchPlugin_Circle::CENTER_ID() || + theAttrName == SketchPlugin_Circle::RADIUS_ID(); + } + else if (theOwnerName == SketchPlugin_Line::ID()) { + return theAttrName == SketchPlugin_Line::START_ID() || + theAttrName == SketchPlugin_Line::END_ID(); + } + + // suppose that all remaining features are points + return theAttrName == SketchPlugin_Point::COORD_ID(); +} diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp index 9181f43dd..1193ad357 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp @@ -10,7 +10,8 @@ PlaneGCSSolver_Solver::PlaneGCSSolver_Solver() : myEquationSystem(new GCS::System), - myConfCollected(false) + myConfCollected(false), + myDOF(0) { } @@ -23,18 +24,46 @@ void PlaneGCSSolver_Solver::clear() { myEquationSystem->clear(); myParameters.clear(); - myEqualConstraints.clear(); - myEqualParameters.clear(); + myConstraints.clear(); + myConflictingIDs.clear(); + myDOF = 0; } void PlaneGCSSolver_Solver::addConstraint(GCSConstraintPtr theConstraint) { myEquationSystem->addConstraint(theConstraint.get()); + myConstraints[theConstraint->getTag()].insert(theConstraint); + myDOF = -1; } void PlaneGCSSolver_Solver::removeConstraint(ConstraintID theID) { - myEquationSystem->clearByTag(theID); + myConstraints.erase(theID); + if (myConstraints.empty()) { + myEquationSystem->clear(); + myDOF = (int)myParameters.size(); + } else { + myEquationSystem->clearByTag(theID); + myDOF = -1; + } +} + +double* PlaneGCSSolver_Solver::createParameter() +{ + double* aResult = new double(0); + myParameters.push_back(aResult); + if (myDOF >= 0) + ++myDOF; + return aResult; +} + +void PlaneGCSSolver_Solver::removeParameters(const GCS::SET_pD& theParams) +{ + for (int i = (int)myParameters.size() - 1; i >= 0; --i) + if (theParams.find(myParameters[i]) != theParams.end()) { + myParameters.erase(myParameters.begin() + i); + --myDOF; + } } SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve() @@ -56,6 +85,8 @@ SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve() SketchSolver_SolveStatus aStatus; if (aResult == GCS::Success) { myEquationSystem->applySolution(); + if (myDOF < 0) + myDOF = myEquationSystem->dofsNumber(); aStatus = STATUS_OK; } else aStatus = STATUS_FAILED; @@ -87,7 +118,9 @@ void PlaneGCSSolver_Solver::collectConflicting() myConfCollected = true; } -int PlaneGCSSolver_Solver::dof() const +int PlaneGCSSolver_Solver::dof() { - return const_cast(this)->myEquationSystem->dofsNumber(); + if (myDOF < 0 && !myConstraints.empty()) + solve(); + return myDOF; } diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h index 481cc0826..9c25caf72 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h @@ -29,9 +29,10 @@ public: /// \brief Remove constraint from the system of equations void removeConstraint(ConstraintID theID); - /// \brief Initialize list of unknowns - void setParameters(const GCS::VEC_pD& theParams) - { myParameters = theParams; } + /// \brief Initialize memory for new solver's parameter + double* createParameter(); + /// \brief Release memory occupied by parameters + void removeParameters(const GCS::SET_pD& theParams); /// \brief Solve the set of equations /// \return identifier whether solution succeeded @@ -48,13 +49,17 @@ public: virtual bool isConflicting(const ConstraintID& theConstraint) const; /// \brief Degrees of freedom - virtual int dof() const; + virtual int dof(); private: void collectConflicting(); private: + typedef std::map > ConstraintMap; + GCS::VEC_pD myParameters; ///< list of unknowns + ConstraintMap myConstraints; ///< list of constraints + std::shared_ptr myEquationSystem; ///< set of equations for solving in FreeGCS GCS::SET_I myConflictingIDs; ///< list of IDs of conflicting constraints @@ -62,10 +67,7 @@ private: /// specifies the conflicting constraints are already collected bool myConfCollected; - /// lists of parameters used in the Equal constraints (to avoid multiple equalities) - std::list myEqualParameters; - /// lists of the Equal constraints - std::map > myEqualConstraints; + int myDOF; ///< degrees of freedom }; #endif diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp index 89c5bd29f..67ada8770 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp @@ -246,8 +246,8 @@ bool PlaneGCSSolver_Storage::update(AttributePtr theAttribute, bool theForce) if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) return update(aFeature, theForce); // theAttribute has been processed while adding feature - PlaneGCSSolver_AttributeBuilder aBuilder(this); - aRelated = createAttribute(anAttribute, &aBuilder); +//// PlaneGCSSolver_AttributeBuilder aBuilder(this); +//// aRelated = createAttribute(anAttribute, &aBuilder); return aRelated.get() != 0; } @@ -338,16 +338,12 @@ void PlaneGCSSolver_Storage::removeInvalidEntities() double* PlaneGCSSolver_Storage::createParameter() { - double* aResult = new double(0); - myParameters.push_back(aResult); - return aResult; + return std::dynamic_pointer_cast(mySketchSolver)->createParameter(); } void PlaneGCSSolver_Storage::removeParameters(const GCS::SET_pD& theParams) { - for (int i = (int)myParameters.size() - 1; i >= 0; --i) - if (theParams.find(myParameters[i]) != theParams.end()) - myParameters.erase(myParameters.begin() + i); + std::dynamic_pointer_cast(mySketchSolver)->removeParameters(theParams); } @@ -404,14 +400,6 @@ bool PlaneGCSSolver_Storage::isRedundant( return false; } -void PlaneGCSSolver_Storage::initializeSolver() -{ - std::shared_ptr aSolver = - std::dynamic_pointer_cast(mySketchSolver); - if (aSolver) - aSolver->setParameters(myParameters); -} - // indicates attribute containing in the external feature bool isExternalAttribute(const AttributePtr& theAttribute) { diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h index 05139cf76..ca8fa2221 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h @@ -59,9 +59,6 @@ public: /// \brief Update SketchPlugin features after resolving constraints virtual void refresh() const; - /// \brief Initialize solver by constraints, entities and parameters - virtual void initializeSolver(); - /// \brief Initialize memory for new solver's parameter double* createParameter(); /// \brief Release memory occupied by parameters @@ -88,7 +85,6 @@ private: PlaneGCSSolver_EntityBuilder* theBuilder); private: - GCS::VEC_pD myParameters; ///< list of parameters ConstraintID myConstraintLastID; ///< identifier of last added constraint /// additional constraints for correct processing of the arcs diff --git a/src/SketchSolver/SketchSolver_ConstraintEqual.cpp b/src/SketchSolver/SketchSolver_ConstraintEqual.cpp index b2cfa0a71..d3317d9ac 100644 --- a/src/SketchSolver/SketchSolver_ConstraintEqual.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintEqual.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -59,9 +60,10 @@ void SketchSolver_ConstraintEqual::getAttributes( myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A()); FeaturePtr aLine1 = ModelAPI_Feature::feature(aRefLine1->object()); if (aLine1) { + PlaneGCSSolver_AttributeBuilder aBuilder(myStorage); // store length of first line as a value for constraint // (will be used to make equal lengths of lines) - theValue = myStorage->entity(aLine1->attribute(SketchPlugin_Line::LENGTH_ID())); + theValue = aBuilder.createAttribute(aLine1->attribute(SketchPlugin_Line::LENGTH_ID())); } break; } diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 8db65a337..c5418065b 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -123,7 +123,7 @@ bool SketchSolver_Group::resolveConstraints() //// mySketchSolver = SketchSolver_Manager::instance()->builder()->createSolver(); //// mySketchSolver->calculateFailedConstraints(false); - myStorage->initializeSolver(); +//// myStorage->initializeSolver(); //// mySketchSolver->prepare(); SketchSolver_SolveStatus aResult = STATUS_OK; @@ -144,7 +144,7 @@ bool SketchSolver_Group::resolveConstraints() removeTemporaryConstraints(); mySketchSolver->calculateFailedConstraints(true); // something failed => need to find it - myStorage->initializeSolver(); +//// myStorage->initializeSolver(); } } } catch (...) { @@ -176,6 +176,9 @@ bool SketchSolver_Group::resolveConstraints() // the error message should be changed before sending the message sendMessage(EVENT_SOLVER_REPAIRED, aConflicting); } + + // show degrees of freedom + computeDoF(); } else { mySketchSolver->undo(); if (!myConstraints.empty()) { @@ -217,12 +220,29 @@ bool SketchSolver_Group::resolveConstraints() } if (aCIt == myConstraints.end()) myStorage->refresh(); - } + } else if (isGroupEmpty) + computeDoF(); removeTemporaryConstraints(); myStorage->setNeedToResolve(false); return aResolved; } +// ============================================================================ +// Function: computeDoF +// Class: SketchSolver_Group +// Purpose: compute DoF of the sketch and set corresponding field +// ============================================================================ +void SketchSolver_Group::computeDoF() const +{ + std::ostringstream aDoFMsg; + int aDoF = /*isEmpty() ? myStorage->numberOfParameters() :*/ mySketchSolver->dof(); + if (aDoF == 0) + aDoFMsg << "Sketch is fully fixed (DoF = 0)"; + else + aDoFMsg << "DoF (degrees of freedom) = " << aDoF; + mySketch->string(SketchPlugin_Sketch::SOLVER_DOF())->setValue(aDoFMsg.str()); +} + // ============================================================================ // Function: repairConsistency // Class: SketchSolver_Group @@ -244,6 +264,9 @@ void SketchSolver_Group::repairConsistency() // remove invalid features myStorage->removeInvalidEntities(); + + // show DoF + computeDoF(); } } diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index c37524fa2..c795c5e9f 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -94,6 +94,9 @@ private: /// \brief Append given constraint to the group of temporary constraints void setTemporary(SolverConstraintPtr theConstraint); + /// \brief Compute DoF of the sketch and set corresponding field + void computeDoF() const; + private: CompositeFeaturePtr mySketch; ///< Sketch for this group ConstraintConstraintMap myConstraints; ///< List of constraints diff --git a/src/SketchSolver/SketchSolver_ISolver.h b/src/SketchSolver/SketchSolver_ISolver.h index c1c21bffa..da9c5041e 100644 --- a/src/SketchSolver/SketchSolver_ISolver.h +++ b/src/SketchSolver/SketchSolver_ISolver.h @@ -47,7 +47,7 @@ public: virtual bool isConflicting(const ConstraintID& theConstraint) const = 0; /// \brief Degrees of freedom - virtual int dof() const = 0; + virtual int dof() = 0; protected: bool myFindFaileds; ///< flag to find conflicting or inappropriate constraints diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 8c227cba5..332bd39af 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -108,8 +108,6 @@ public: void setNeedToResolve(bool theFlag) { myNeedToResolve = theFlag; } - /// \brief Initialize solver by constraints, entities and parameters - virtual void initializeSolver() = 0; /// \brief Return list of conflicting constraints std::set getConflictingConstraints(SolverPtr theSolver) const; -- 2.30.2