"""
from SketchAPI import addSketch
-from tools import addPolyline, addPolygon
+from tools import addPolyline, addPolygon, dof
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
{
fillAttribute(theExternalFeature, externalFeature());
- execute();
+ execute(true);
}
void SketchAPI_Projection::setByExternalName(const std::string& theExternalName)
{
fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
- execute();
+ execute(true);
}
//--------------------------------------------------------------------------------------
TestConstraintParallel.py
TestConstraintPerpendicular.py
TestConstraintRadius.py
- TestConstraintRigid.py
+ TestConstraintFixed.py
TestConstraintHorizontal.py
TestConstraintVertical.py
TestConstraintEqual.py
"""
from GeomDataAPI import *
from ModelAPI import *
-import os
import math
+from salome.shaper import model
#=========================================================================
# Auxiliary functions
aStartPoint.setValue(-10., 15.)
aEndPoint.setValue(80., 50.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Make a constraint to keep the angle
#=========================================================================
assert (refattrA.isInitialized())
assert (refattrB.isInitialized())
assert (angle(aSketchLineA, aSketchLineB) == ANGLE_DEGREE)
+assert (model.dof(aSketchFeature) == 7)
#=========================================================================
# Move line, check that angle is constant
#=========================================================================
aConstraint.execute()
aSession.finishOperation()
assert (angle(aSketchLineA, aSketchLineB) == ANGLE_DEGREE)
+assert (model.dof(aSketchFeature) == 7)
#=========================================================================
# Change angle value and check the lines are moved
#=========================================================================
aConstraint.execute()
aSession.finishOperation()
assert (angle(aSketchLineA, aSketchLineB) == NEW_ANGLE_DEGREE)
+assert (model.dof(aSketchFeature) == 7)
#=========================================================================
# Change angle type
#=========================================================================
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
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
#=========================================================================
reflistB.setAttr(aLineStartPoint)
aConstraint.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 7)
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
# 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
#=========================================================================
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
aConstraint.execute()
aSession.finishOperation()
checkPointOnLine(anArcStartPoint, aSketchLine)
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Add constraint point-on-circle
#=========================================================================
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))
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")
reflistA.setAttr(aCircleCenter)
reflistB.setObject(anOrigin.lastResult())
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
# point-on-circle
aSession.startOperation()
aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
aConstraint.execute()
aSession.finishOperation()
checkPointOnCircle(aLineEndPoint, aSketchCircle)
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Add constraint point-on-arc
#=========================================================================
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
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")
# 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
#=========================================================================
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
#=========================================================================
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
#=========================================================================
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
aLineBStartPoint.setValue(0., 50)
aLineBEndPoint.setValue(80., 75)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Link lines with collinear constraint
#=========================================================================
aParallelConstraint.execute()
aSession.finishOperation()
checkCollinear(aSketchLineA, aSketchLineB)
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
aLineAEndPoint.y() - deltaY)
aSession.finishOperation()
checkCollinear(aSketchLineA, aSketchLineB)
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# End of test
#=========================================================================
-from salome.shaper import model
assert(model.checkPythonDump())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
aLineAStartPoint.setValue(0., 25.)
aLineAEndPoint.setValue(100., 25.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Make a constraint to keep the distance
#=========================================================================
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"))
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
#=========================================================================
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
#=========================================================================
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
#=========================================================================
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
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"))
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
#=========================================================================
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
#=========================================================================
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
anArcEndPoint.setValue(50., 0.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 5)
# Circle
aSession.startOperation()
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
anCircleCentr.setValue(-25., -25.)
aCircleRadius.setValue(25.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# A constraint to make equal radii of arc and circle
#=========================================================================
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
#=========================================================================
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")
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
aLine2StartPoint.setValue(0., 0.)
aLine2EndPoint.setValue(-1., 10.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 14)
#=========================================================================
# A constraint to make equal lengths of lines
#=========================================================================
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
#=========================================================================
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")
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())
--- /dev/null
+"""
+ 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");
+ static const std::string MY_ENTITY_A("ConstraintEntityA");
+ 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());
+
+"""
+from GeomDataAPI import *
+from ModelAPI import *
+from GeomAPI import *
+from salome.shaper import model
+
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+__updated__ = "2014-11-21"
+
+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 a triangle ABC
+#=========================================================================
+aSession.startOperation()
+aSketchLineA = aSketchFeature.addFeature("SketchLine")
+aSketchLineB = aSketchFeature.addFeature("SketchLine")
+aSketchLineC = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
+aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
+aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
+aLineAStartPoint.setValue(25., 25.)
+aLineAEndPoint.setValue(100., 25.)
+aLineBStartPoint.setValue(100., 25.)
+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())
+kLineBStart = (aLineBStartPoint.x(), aLineBStartPoint.y())
+kLineBEnd = (aLineBEndPoint.x(), aLineBEndPoint.y())
+kLineCStart = (aLineCStartPoint.x(), aLineCStartPoint.y())
+kLineCEnd = (aLineCEndPoint.x(), aLineCEndPoint.y())
+#=========================================================================
+# Link triange lines with concidence
+#=========================================================================
+concidenceLinks = zip([aLineBStartPoint, aLineCStartPoint, aLineAStartPoint],
+ [aLineAEndPoint, aLineBEndPoint, aLineCEndPoint])
+aSession.startOperation()
+for eachLink in concidenceLinks:
+ aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
+ reflistA = aConstraint.refattr("ConstraintEntityA")
+ reflistB = aConstraint.refattr("ConstraintEntityB")
+ reflistA.setAttr(eachLink[0])
+ 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()))
+assert (kLineAEnd == (aLineAEndPoint.x(), aLineAEndPoint.y()))
+assert (kLineBStart == (aLineBStartPoint.x(), aLineBStartPoint.y()))
+assert (kLineBEnd == (aLineBEndPoint.x(), aLineBEndPoint.y()))
+assert (kLineCStart == (aLineCStartPoint.x(), aLineCStartPoint.y()))
+assert (kLineCEnd == (aLineCEndPoint.x(), aLineCEndPoint.y()))
+#=========================================================================
+# Make line A rigid
+#=========================================================================
+aSession.startOperation()
+aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid")
+eachRefattr = aRigidConstraint.refattr("ConstraintEntityA")
+lineResults = aSketchLineA.results()
+for eachResult in lineResults:
+ if eachResult.shape().isEdge():
+ break
+aResult = modelAPI_ResultConstruction(eachResult)
+assert (aResult is not None)
+eachRefattr.setObject(aResult)
+# aRigidConstraint.execute()
+aSession.finishOperation()
+
+# Check that constarints doesn't affected lines' values
+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
+#=========================================================================
+aSession.startOperation()
+aLineAEndPoint.setValue(90., 0.)
+aSession.finishOperation()
+# Check that constarint keep features' values
+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
+#=========================================================================
+aSession.startOperation()
+aLineBEndPoint.setValue(90., 150.)
+aSession.finishOperation()
+# Check that constarint keep features' values
+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)
+
+#=========================================================================
+# 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
+#=========================================================================
+
+assert(model.checkPythonDump())
"""
from GeomDataAPI import *
from ModelAPI import *
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
aLineStartPoint.setValue(0., 15.)
aLineEndPoint.setValue(20., 25.)
aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 4)
#=========================================================================
# Assign horizontal constraint for a line
#=========================================================================
aHorizontalConstraint.execute()
aSession.finishOperation()
assert(aLineStartPoint.y() == aLineEndPoint.y())
+assert(model.dof(aSketchFeature) == 3)
#=========================================================================
# Move one of boundary points of a line
#=========================================================================
aLineStartPoint.y() + deltaY)
aSession.finishOperation()
assert(aLineStartPoint.y() == aLineEndPoint.y())
+assert(model.dof(aSketchFeature) == 3)
#=========================================================================
# Move other boundary point of a line
#=========================================================================
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
aLineAStartPoint.setValue(0., 25.)
aLineAEndPoint.setValue(100., 25.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 4)
#=========================================================================
# Make a constraint to keep the length
#=========================================================================
aSession.finishOperation()
assert (aLength.isInitialized())
assert (refattrA.isInitialized())
+assert (model.dof(aSketchFeature) == 3)
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
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
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
# End of test
#=========================================================================
-from salome.shaper import model
assert(model.checkPythonDump())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
aStartPoint2.setValue(10., 100.)
aEndPoint2.setValue(100., 25.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Make end point of second line middle point on first line
#=========================================================================
reflistB.setObject(aLine1.lastResult())
aConstraint.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Check values and move one constrainted object
aStartPoint1.setValue(aStartPoint1.x() + deltaX, aStartPoint1.y() + deltaY)
aSession.finishOperation()
checkMiddlePoint(aEndPoint2, aLine1)
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Remove constraint and move the line
#=========================================================================
aSession.startOperation()
aDocument.removeFeature(aConstraint)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
aSession.startOperation()
aEndPoint1.setValue(90., 0.)
aSession.finishOperation()
assert (aEndPoint2.x() == aCurX and aEndPoint2.y() == aCurY)
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Set external point as a middle point
anOriginCoord.setValue(0., 0.)
anOrigin.selection("External").setValue(anOrigRes, anOrigShape)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
# middle point constraint
aSession.startOperation()
aConstraint = aSketchFeature.addFeature("SketchConstraintMiddle")
reflistB.setObject(anOrigin.lastResult())
aSession.finishOperation()
checkMiddlePoint(anOriginCoord, aLine2)
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Check origin coordinates does not changed
#=========================================================================
reflistA.setAttr(aEndPoint3)
reflistB.setObject(aLine1.lastResult())
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
#=========================================================================
# Set Middle point
#=========================================================================
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
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
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
#=========================================================================
reflistB.setAttr(aLine2StartPoint)
aConstraint.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
#=========================================================================
# Add tangency constraint and check correctness
#=========================================================================
aRefObjectB.setObject(anObjectB)
aTangency.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Create mirror line
#=========================================================================
aLineStartPoint.setValue(100., 0.)
aLineEndPoint.setValue(100., 100.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 12)
#=========================================================================
# Make mirror for objects created above
#=========================================================================
aRefListInitial.append(aSketchLine2.lastResult())
aMirror.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 12)
#=========================================================================
# Verify the simmetricity of all mirrored objects
#=========================================================================
assert (aRefListB.size() == 3)
assert (aRefListC.size() == 3)
checkMirror(aRefListB, aRefListC, aMirrorLine)
+assert (model.dof(aSketchFeature) == 12)
#=========================================================================
# Remove object from mirror
assert (aRefListB.size() == 2)
assert (aRefListC.size() == 2)
checkMirror(aRefListB, aRefListC, aMirrorLine)
+assert (model.dof(aSketchFeature) == 12)
#=========================================================================
# Clear list of mirrored features
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())
"""
from GeomDataAPI import *
from ModelAPI import *
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
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
assert (aLineBStartPoint.y() == 50)
assert (aLineBEndPoint.x() == 80)
assert (aLineBEndPoint.y() == 75)
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Link lines with parallel constraint
#=========================================================================
refattrB.setObject(aResultB)
aParallelConstraint.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
assert (aLineBStartPointPrev != aLineBStartPointNew)
assert (aLineBEndPointPrev != aLineBEndPointNew)
+assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# End of test
#=========================================================================
-from salome.shaper import model
assert(model.checkPythonDump())
"""
from GeomDataAPI import *
from ModelAPI import *
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
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
assert (aLineBStartPoint.y() == 40)
assert (aLineBEndPoint.x() == 25)
assert (aLineBEndPoint.y() == 125)
+assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Link lines with perpendicular constraint
#=========================================================================
refattrB.setObject(aResultB)
aPerpendicularConstraint.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
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.)
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")
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
#=========================================================================
aSession.finishOperation()
assert (aRadius.isInitialized())
assert (aRefObject.isInitialized())
+assert (model.dof(aSketchFeature) == 7)
#=========================================================================
# Make a constraint to keep the radius of the circle
#=========================================================================
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
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
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())
+++ /dev/null
-"""
- 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");
- static const std::string MY_ENTITY_A("ConstraintEntityA");
- 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());
-
-"""
-from GeomDataAPI import *
-from ModelAPI import *
-from GeomAPI import *
-#=========================================================================
-# Initialization of the test
-#=========================================================================
-
-__updated__ = "2014-11-21"
-
-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 a triangle ABC
-#=========================================================================
-aSession.startOperation()
-aSketchLineA = aSketchFeature.addFeature("SketchLine")
-aSketchLineB = aSketchFeature.addFeature("SketchLine")
-aSketchLineC = aSketchFeature.addFeature("SketchLine")
-aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
-aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
-aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
-aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
-aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
-aLineAStartPoint.setValue(25., 25.)
-aLineAEndPoint.setValue(100., 25.)
-aLineBStartPoint.setValue(100., 25.)
-aLineBEndPoint.setValue(60., 75.)
-aLineCStartPoint.setValue(60., 75.)
-aLineCEndPoint.setValue(25., 25.)
-aSession.finishOperation()
-# Store initial values of lines
-kLineAStart = (aLineAStartPoint.x(), aLineAStartPoint.y())
-kLineAEnd = (aLineAEndPoint.x(), aLineAEndPoint.y())
-kLineBStart = (aLineBStartPoint.x(), aLineBStartPoint.y())
-kLineBEnd = (aLineBEndPoint.x(), aLineBEndPoint.y())
-kLineCStart = (aLineCStartPoint.x(), aLineCStartPoint.y())
-kLineCEnd = (aLineCEndPoint.x(), aLineCEndPoint.y())
-#=========================================================================
-# Link triange lines with concidence
-#=========================================================================
-concidenceLinks = zip([aLineBStartPoint, aLineCStartPoint, aLineAStartPoint],
- [aLineAEndPoint, aLineBEndPoint, aLineCEndPoint])
-aSession.startOperation()
-for eachLink in concidenceLinks:
- aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
- reflistA = aConstraint.refattr("ConstraintEntityA")
- reflistB = aConstraint.refattr("ConstraintEntityB")
- reflistA.setAttr(eachLink[0])
- reflistB.setAttr(eachLink[1])
- aConstraint.execute()
-aSession.finishOperation()
-
-# Check that constarints doesn't affected lines' values
-assert (kLineAStart == (aLineAStartPoint.x(), aLineAStartPoint.y()))
-assert (kLineAEnd == (aLineAEndPoint.x(), aLineAEndPoint.y()))
-assert (kLineBStart == (aLineBStartPoint.x(), aLineBStartPoint.y()))
-assert (kLineBEnd == (aLineBEndPoint.x(), aLineBEndPoint.y()))
-assert (kLineCStart == (aLineCStartPoint.x(), aLineCStartPoint.y()))
-assert (kLineCEnd == (aLineCEndPoint.x(), aLineCEndPoint.y()))
-#=========================================================================
-# Make line A rigid
-#=========================================================================
-aSession.startOperation()
-aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid")
-eachRefattr = aRigidConstraint.refattr("ConstraintEntityA")
-lineResults = aSketchLineA.results()
-for eachResult in lineResults:
- if eachResult.shape().isEdge():
- break
-aResult = modelAPI_ResultConstruction(eachResult)
-assert (aResult is not None)
-eachRefattr.setObject(aResult)
-# aRigidConstraint.execute()
-aSession.finishOperation()
-
-# Check that constarints doesn't affected lines' values
-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()))
-#=========================================================================
-# Check that moving line A does not affect lines
-#=========================================================================
-aSession.startOperation()
-aLineAEndPoint.setValue(90., 0.)
-aSession.finishOperation()
-# Check that constarint keep features' values
-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()))
-#=========================================================================
-# Check that moving line B does not affect lines
-#=========================================================================
-aSession.startOperation()
-aLineBEndPoint.setValue(90., 150.)
-aSession.finishOperation()
-# Check that constarint keep features' values
-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()))
-#=========================================================================
-# TODO: improve test
-# 1. remove constraint, move line to check that constraint are not applied
-#=========================================================================
-#=========================================================================
-# End of test
-#=========================================================================
-
-from salome.shaper import model
-assert(model.checkPythonDump())
from GeomAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
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
#=========================================================================
reflistB.setAttr(aLine2StartPoint)
aConstraint.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
#=========================================================================
# Add tangency constraint and check correctness
#=========================================================================
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
#=========================================================================
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
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
#=========================================================================
reflistB.setAttr(anArc2StartPoint)
aConstraint.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 15)
#=========================================================================
# Add tangency constraint and check correctness
#=========================================================================
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
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
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
aCircleCenter.setValue(150., 100.)
aCircleRadius.setValue(20.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 26)
aSession.startOperation()
aTangency = aSketchFeature.addFeature("SketchConstraintTangent")
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())
"""
from GeomDataAPI import *
from ModelAPI import *
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
aLineStartPoint.setValue(0., 15.)
aLineEndPoint.setValue(20., 25.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 4)
#=========================================================================
# Assign vertical constraint for a line
#=========================================================================
aVerticalConstraint.execute()
aSession.finishOperation()
assert(aLineStartPoint.x() == aLineEndPoint.x())
+assert (model.dof(aSketchFeature) == 3)
#=========================================================================
# Move one of boundary points of a line
#=========================================================================
aLineStartPoint.y() + deltaY)
aSession.finishOperation()
assert(aLineStartPoint.x() == aLineEndPoint.x())
+assert (model.dof(aSketchFeature) == 3)
#=========================================================================
# Move other boundary point of a line
#=========================================================================
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
#=========================================================================
# Auxiliary functions
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")
norm.setValue(0, 0, 1)
aSession.finishOperation()
#=========================================================================
-# Initialize sketch by two lines
+# Initialize sketch by three connected lines
#=========================================================================
aSession.startOperation()
aFeaturesList = createSketch1(aSketchFeature)
aSketchSubFeatures = []
for aSubIndex in range(0, aSketchFeature.numberOfSubs()):
aSketchSubFeatures.append(aSketchFeature.subFeature(aSubIndex))
+assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Global variables
#=========================================================================
#=========================================================================
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
#=========================================================================
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
aSketchSubFeatures = []
for aSubIndex in range(0, aSketchFeature.numberOfSubs()):
aSketchSubFeatures.append(aSketchFeature.subFeature(aSubIndex))
+assert (model.dof(aSketchFeature) == 7)
#=========================================================================
# Create the Fillet
#=========================================================================
#=========================================================================
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
#=========================================================================
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())
#=========================================================================
# Create 4x4 polygons N = {5, 21}
#=========================================================================
+aDOF = 0
deltaX = deltaY = 50.
n = 5
aSession.startOperation()
allNangleLines = createNAngle(aSketchFeature, n, 50)
fixLineLength(aSketchFeature, allNangleLines)
moveTo(allNangleLines, deltaX, deltaY)
+ aDOF += n
n += 1
deltaX += 110.
deltaY += 110.
#=========================================================================
from salome.shaper import model
+assert(model.dof(aSketchFeature) == aDOF)
assert(model.checkPythonDump())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
#=========================================================================
# Auxiliary functions
aSession.startOperation()
aFeaturesList = createSketch(aSketchFeature)
aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 5)
#=========================================================================
# Global variables
#=========================================================================
aRotationPointPoint = geomDataAPI_Point2D(aRotationPoint.attribute("PointCoordindates"))
aRotationPointPoint.setValue(CENTER_X, CENTER_Y)
aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 7)
#=========================================================================
# Create the Rotation constraint
#=========================================================================
aNbCopies.setValue(2)
aMultiRotation.execute()
aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 7)
#=========================================================================
# Verify the objects are moved for the specified distance
#=========================================================================
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
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
#=========================================================================
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
#=========================================================================
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
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
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())
"""
from GeomDataAPI import *
from ModelAPI import *
+from salome.shaper import model
#=========================================================================
# Auxiliary functions
aSession.startOperation()
aFeaturesList = createSketch(aSketchFeature)
aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 5)
#=========================================================================
# Global variables
#=========================================================================
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
#=========================================================================
aNbCopies.setValue(2)
aMultiTranslation.execute()
aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 9)
#=========================================================================
# Verify the objects are moved for the specified distance
#=========================================================================
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
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
#=========================================================================
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
#=========================================================================
aNbCopies.setValue(2)
aSession.finishOperation()
checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
+assert(model.dof(aSketchFeature) == 13)
#=========================================================================
# Remove a feature from the Rotation
aTransList.remove(aRemoveIt)
aSession.finishOperation()
checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
+assert(model.dof(aSketchFeature) == 13)
#=========================================================================
# Clear the list of rotated features
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
anArcStart.setValue(50., 0.)
anArcEnd.setValue(0., 50.)
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 12)
#=========================================================================
# Create another sketch
#=========================================================================
anArcProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchArc_1_2")
anArcProjector.execute()
aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 0)
#=========================================================================
# Check projection coordinates
#=========================================================================
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())
from GeomDataAPI import *
from ModelAPI import *
import math
+from salome.shaper import model
+
#=========================================================================
# Initialization of the test
#=========================================================================
assert (isHorizontal(aLastLine) or isVertical(aLastLine))
aNbLines = aNbLines + 1
assert (aNbLines == 4)
+assert (model.dof(aSketchFeature) == 4)
#=========================================================================
# Move one of lines
#=========================================================================
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())
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_XY.h>
+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,
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;
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();
+}
PlaneGCSSolver_Solver::PlaneGCSSolver_Solver()
: myEquationSystem(new GCS::System),
- myConfCollected(false)
+ myConfCollected(false),
+ myDOF(0)
{
}
{
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()
SketchSolver_SolveStatus aStatus;
if (aResult == GCS::Success) {
myEquationSystem->applySolution();
+ if (myDOF < 0)
+ myDOF = myEquationSystem->dofsNumber();
aStatus = STATUS_OK;
} else
aStatus = STATUS_FAILED;
myConfCollected = true;
}
-int PlaneGCSSolver_Solver::dof() const
+int PlaneGCSSolver_Solver::dof()
{
- return const_cast<PlaneGCSSolver_Solver*>(this)->myEquationSystem->dofsNumber();
+ if (myDOF < 0 && !myConstraints.empty())
+ solve();
+ return myDOF;
}
/// \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
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<ConstraintID, std::set<GCSConstraintPtr> > ConstraintMap;
+
GCS::VEC_pD myParameters; ///< list of unknowns
+ ConstraintMap myConstraints; ///< list of constraints
+
std::shared_ptr<GCS::System> myEquationSystem; ///< set of equations for solving in FreeGCS
GCS::SET_I myConflictingIDs; ///< list of IDs of conflicting constraints
/// specifies the conflicting constraints are already collected
bool myConfCollected;
- /// lists of parameters used in the Equal constraints (to avoid multiple equalities)
- std::list<GCS::SET_pD> myEqualParameters;
- /// lists of the Equal constraints
- std::map<ConstraintID, std::set<GCSConstraintPtr> > myEqualConstraints;
+ int myDOF; ///< degrees of freedom
};
#endif
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;
}
double* PlaneGCSSolver_Storage::createParameter()
{
- double* aResult = new double(0);
- myParameters.push_back(aResult);
- return aResult;
+ return std::dynamic_pointer_cast<PlaneGCSSolver_Solver>(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<PlaneGCSSolver_Solver>(mySketchSolver)->removeParameters(theParams);
}
return false;
}
-void PlaneGCSSolver_Storage::initializeSolver()
-{
- std::shared_ptr<PlaneGCSSolver_Solver> aSolver =
- std::dynamic_pointer_cast<PlaneGCSSolver_Solver>(mySketchSolver);
- if (aSolver)
- aSolver->setParameters(myParameters);
-}
-
// indicates attribute containing in the external feature
bool isExternalAttribute(const AttributePtr& theAttribute)
{
/// \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
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
#include <SketchSolver_ConstraintEqual.h>
#include <SketchSolver_Error.h>
+#include <PlaneGCSSolver_AttributeBuilder.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <SketchPlugin_Line.h>
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;
}
//// mySketchSolver = SketchSolver_Manager::instance()->builder()->createSolver();
//// mySketchSolver->calculateFailedConstraints(false);
- myStorage->initializeSolver();
+//// myStorage->initializeSolver();
//// mySketchSolver->prepare();
SketchSolver_SolveStatus aResult = STATUS_OK;
removeTemporaryConstraints();
mySketchSolver->calculateFailedConstraints(true); // something failed => need to find it
- myStorage->initializeSolver();
+//// myStorage->initializeSolver();
}
}
} catch (...) {
// 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()) {
}
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
// remove invalid features
myStorage->removeInvalidEntities();
+
+ // show DoF
+ computeDoF();
}
}
/// \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
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
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<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;