X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FTest%2FTestConstraintLength.py;h=ac1345d4dfb1c7a381ce3f4cf23e027bc8d4d695;hb=cfe4bcc5b3ebf08f0f4f36a0df4067728f1a080a;hp=fe4539c39cbd8434db6ba2351b2b567f3c1b15ff;hpb=bf29d8da1316982792c55094be9a958d9da3fb46;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/Test/TestConstraintLength.py b/src/SketchPlugin/Test/TestConstraintLength.py index fe4539c39..ac1345d4d 100644 --- a/src/SketchPlugin/Test/TestConstraintLength.py +++ b/src/SketchPlugin/Test/TestConstraintLength.py @@ -1,71 +1,70 @@ """ - TestConstraints.py - Base for all constaints tests. + TestConstraintLength.py + Unit test of SketchPlugin_ConstraintLength class SketchPlugin_ConstraintLength static const std::string MY_CONSTRAINT_LENGTH_ID("SketchConstraintLength"); - data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type()); - data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); """ from GeomDataAPI import * from ModelAPI import * +import math +from salome.shaper import model + #========================================================================= # Initialization of the test #========================================================================= -__updated__ = "2014-07-28" +__updated__ = "2014-10-28" -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() -aSketchFeature = aDocument.addFeature("Sketch") -aSketchFeatureData = aSketchFeature.data() -origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) origin.setValue(0, 0, 0) -dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) dirx.setValue(1, 0, 0) -diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) -diry.setValue(0, 1, 0) -norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) norm.setValue(0, 0, 1) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Create a line with length 100 #========================================================================= -aDocument.startOperation() -aSketchReflist = aSketchFeatureData.reflist("Features") -aSketchLineA = aDocument.addFeature("SketchLine") -aSketchReflist.append(aSketchLineA) -aLineAStartPoint = geomDataAPI_Point2D( - aSketchLineA.data().attribute("StartPoint")) -aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.data().attribute("EndPoint")) +aSession.startOperation() +aSketchLineA = aSketchFeature.addFeature("SketchLine") +aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) aLineAStartPoint.setValue(0., 25.) aLineAEndPoint.setValue(100., 25.) -aDocument.finishOperation() +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 4) #========================================================================= # Make a constraint to keep the length #========================================================================= -aDocument.startOperation() -aConstraint = aDocument.addFeature("SketchConstraintLength") -aSketchReflist.append(aConstraint) -aConstraintData = aConstraint.data() -aLength = aConstraintData.real("ConstraintValue") -refattrA = aConstraintData.refattr("ConstraintEntityA") -assert (not aLength.isInitialized()) +aSession.startOperation() +aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength") +refattrA = aLengthConstraint.refattr("ConstraintEntityA") +aLength = aLengthConstraint.real("ConstraintValue") assert (not refattrA.isInitialized()) -# aLength.setValue(100.) -# refattrA.setObject(aSketchLineA) +assert (not aLength.isInitialized()) + aResult = aSketchLineA.firstResult() assert (aResult is not None) refattrA.setObject(modelAPI_ResultConstruction(aResult)) -aDocument.finishOperation() +# aLength.setValue(100.) +aLengthConstraint.execute() +aSession.finishOperation() assert (aLength.isInitialized()) assert (refattrA.isInitialized()) +assert (model.dof(aSketchFeature) == 3) #========================================================================= # Check values and move one constrainted object #========================================================================= @@ -75,14 +74,24 @@ assert (aLineAStartPoint.x() == 0) assert (aLineAStartPoint.y() == 25) assert (aLineAEndPoint.x() == 100) assert (aLineAEndPoint.y() == 25) -aDocument.startOperation() +aSession.startOperation() aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, aLineAStartPoint.y()) -aDocument.finishOperation() +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 3) assert (aLineAStartPoint.y() == 25) assert (aLineAEndPoint.y() == 25) # length of the line is the same -assert (aLineAEndPoint.x() - aLineAStartPoint.x() == 100) +assert (math.fabs(aLineAEndPoint.x() - aLineAStartPoint.x() - 100) < 1.e-10) +#========================================================================= +# Change the length value of the constraint +#========================================================================= +aSession.startOperation() +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 @@ -91,3 +100,5 @@ assert (aLineAEndPoint.x() - aLineAStartPoint.x() == 100) #========================================================================= # End of test #========================================================================= + +assert(model.checkPythonDump())