X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSketchPlugin%2FTest%2FTestConstraintDistance.py;h=13aeada6f9f4fd19c766a85a48a363509d28aa8e;hb=b565fcd859e5551d317233b9e8103b3987f1e79a;hp=bd978fa0393cf8460e75394f3353afcfeb8c7fb9;hpb=4d17967148788d2336a0f10530bc5eb739ae4ef1;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index bd978fa03..13aeada6f 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -12,10 +12,10 @@ SketchPlugin_ConstraintDistance static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistance"); - 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::ENTITY_B(), 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()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); """ @@ -26,7 +26,7 @@ import math # Initialization of the test #========================================================================= -__updated__ = "2014-07-29" +__updated__ = "2014-10-28" def distance(pointA, pointB): @@ -38,53 +38,46 @@ def distance(pointA, pointB): ydiff = math.pow((pointA.y() - pointB.y()), 2) return round(math.sqrt(xdiff + ydiff), 5) -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 = geomDataAPI_Dir(aSketchFeature.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 point and a line #========================================================================= -aDocument.startOperation() -aSketchReflist = aSketchFeatureData.reflist("Features") -aSketchPoint = aDocument.addFeature("SketchPoint") -aSketchReflist.append(aSketchPoint) -aSketchPointData = aSketchPoint.data() +aSession.startOperation() +aSketchPoint = aSketchFeature.addFeature("SketchPoint") aSketchPointCoords = geomDataAPI_Point2D( - aSketchPointData.attribute("PointCoordindates")) + aSketchPoint.attribute("PointCoordindates")) aSketchPointCoords.setValue(50., 50.) -aSketchLine = aDocument.addFeature("SketchLine") -aSketchReflist.append(aSketchLine) -aLineAStartPoint = geomDataAPI_Point2D( - aSketchLine.data().attribute("StartPoint")) -aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.data().attribute("EndPoint")) +aSketchLine = aSketchFeature.addFeature("SketchLine") +aLineAStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint")) +aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) aLineAStartPoint.setValue(0., 25.) aLineAEndPoint.setValue(100., 25.) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Make a constraint to keep the distance #========================================================================= assert (distance(aSketchPointCoords, aLineAStartPoint) != 25.) -aDocument.startOperation() -aConstraint = aDocument.addFeature("SketchConstraintDistance") -aSketchReflist.append(aConstraint) -aConstraintData = aConstraint.data() -aDistance = aConstraintData.real("ConstraintValue") -refattrA = aConstraintData.refattr("ConstraintEntityA") -refattrB = aConstraintData.refattr("ConstraintEntityB") +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintDistance") +aDistance = aConstraint.real("ConstraintValue") +refattrA = aConstraint.refattr("ConstraintEntityA") +refattrB = aConstraint.refattr("ConstraintEntityB") assert (not aDistance.isInitialized()) assert (not refattrA.isInitialized()) assert (not refattrB.isInitialized()) @@ -93,7 +86,7 @@ aLineResult = aSketchLine.firstResult() assert (aLineResult is not None) refattrA.setAttr(aSketchPointCoords) refattrB.setAttr(aLineAStartPoint) -aDocument.finishOperation() +aSession.finishOperation() assert (aDistance.isInitialized()) assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) @@ -101,10 +94,10 @@ assert (refattrB.isInitialized()) # Move line, check that distance is constant #========================================================================= assert (distance(aSketchPointCoords, aLineAStartPoint) == 25.) -aDocument.startOperation() +aSession.startOperation() aLineAStartPoint.setValue(0., 40.) aLineAEndPoint.setValue(100., 40.) -aDocument.finishOperation() +aSession.finishOperation() assert (distance(aSketchPointCoords, aLineAStartPoint) == 25.) #========================================================================= # TODO: improve test