3 Base for all constaints tests.
5 SketchPlugin_ConstraintLength
6 static const std::string MY_CONSTRAINT_LENGTH_ID("SketchConstraintLength");
7 data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type());
8 data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
9 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
12 from GeomDataAPI import *
13 from ModelAPI import *
14 #=========================================================================
15 # Initialization of the test
16 #=========================================================================
18 __updated__ = "2014-07-28"
20 aPluginManager = ModelAPI_PluginManager.get()
21 aDocument = aPluginManager.rootDocument()
22 #=========================================================================
23 # Creation of a sketch
24 #=========================================================================
25 aDocument.startOperation()
26 aSketchFeature = aDocument.addFeature("Sketch")
27 aSketchFeatureData = aSketchFeature.data()
28 origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
29 origin.setValue(0, 0, 0)
30 dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
31 dirx.setValue(1, 0, 0)
32 diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
33 diry.setValue(0, 1, 0)
34 norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
35 norm.setValue(0, 0, 1)
36 aDocument.finishOperation()
37 #=========================================================================
38 # Create a line with length 100
39 #=========================================================================
40 aDocument.startOperation()
41 aSketchReflist = aSketchFeatureData.reflist("Features")
42 aSketchLineA = aDocument.addFeature("SketchLine")
43 aSketchReflist.append(aSketchLineA)
44 aLineAStartPoint = geomDataAPI_Point2D(
45 aSketchLineA.data().attribute("StartPoint"))
46 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.data().attribute("EndPoint"))
47 aLineAStartPoint.setValue(0., 25.)
48 aLineAEndPoint.setValue(100., 25.)
49 aDocument.finishOperation()
50 #=========================================================================
51 # Make a constraint to keep the length
52 #=========================================================================
53 aDocument.startOperation()
54 aCoincidenceConstraint = aDocument.addFeature("SketchConstraintLength")
55 aSketchReflist.append(aCoincidenceConstraint)
56 aConstraintData = aCoincidenceConstraint.data()
57 aLength = aConstraintData.real("ConstraintValue")
58 refattrA = aConstraintData.refattr("ConstraintEntityA")
59 assert (not aLength.isInitialized())
60 assert (not refattrA.isInitialized())
61 # aLength.setValue(100.)
62 # refattrA.setObject(aSketchLineA)
63 aResult = aSketchLineA.firstResult()
64 assert (aResult is not None)
65 refattrA.setObject(modelAPI_ResultConstruction(aResult))
66 aDocument.finishOperation()
67 assert (aLength.isInitialized())
68 assert (refattrA.isInitialized())
69 #=========================================================================
70 # Check values and move one constrainted object
71 #=========================================================================
73 # move start point, check that end point are moved also
74 assert (aLineAStartPoint.x() == 0)
75 assert (aLineAStartPoint.y() == 25)
76 assert (aLineAEndPoint.x() == 100)
77 assert (aLineAEndPoint.y() == 25)
78 aDocument.startOperation()
79 aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX,
81 aDocument.finishOperation()
82 assert (aLineAEndPoint.x() - aLineAStartPoint.x() == 100)
83 #assert (aLineAStartPoint.y() == 25)
84 #assert (aLineAEndPoint.x() == 140)
85 #assert (aLineAEndPoint.y() == 25)
86 #=========================================================================
88 # 1. remove constraint, move line's start point to
89 # check that constraint are not applied
90 #=========================================================================
91 #=========================================================================
93 #=========================================================================