Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintLength.py
1 """
2     TestConstraints.py
3     Base for all constaints tests.
4         
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());
10
11 """
12 from GeomDataAPI import *
13 from ModelAPI import *
14 #=========================================================================
15 # Initialization of the test
16 #=========================================================================
17
18 __updated__ = "2014-07-28"
19
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 aConstraintData = aCoincidenceConstraint.data()
56 aLength = aConstraintData.real("ConstraintValue")
57 refattrA = aConstraintData.refattr("ConstraintEntityA")
58 assert (not aLength.isInitialized())
59 assert (not refattrA.isInitialized())
60 # aLength.setValue(100.)
61 # refattrA.setObject(aSketchLineA)
62 aResult = aSketchLineA.firstResult()
63 assert (aResult is not None)
64 refattrA.setObject(modelAPI_ResultConstruction(aResult))
65 aDocument.finishOperation()
66 assert (aLength.isInitialized())
67 assert (refattrA.isInitialized())
68 #=========================================================================
69 # Check values and move one constrainted object
70 #=========================================================================
71 deltaX = 40.
72 # move start point, check that end point are moved also
73 assert (aLineAStartPoint.x() == 0)
74 assert (aLineAStartPoint.y() == 25)
75 assert (aLineAEndPoint.x() == 100)
76 assert (aLineAEndPoint.y() == 25)
77 aDocument.startOperation()
78 aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX,
79                           aLineAStartPoint.y())
80 aDocument.finishOperation()
81 assert (aLineAStartPoint.x() == 40)
82 assert (aLineAStartPoint.y() == 25)
83 assert (aLineAEndPoint.x() == 140)
84 assert (aLineAEndPoint.y() == 25)
85 #=========================================================================
86 # TODO: improve test
87 # 1. remove constraint, move line's start point to
88 #    check that constraint are not applied
89 #=========================================================================
90 #=========================================================================
91 # End of test
92 #=========================================================================