]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestConstraintTangent.py
Salome HOME
Constraint Tangent is added
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintTangent.py
1 """
2     TestConstraintTangent.py
3     Unit test of SketchPlugin_ConstraintTangent class
4         
5     SketchPlugin_ConstraintTangent
6         static const std::string MY_CONSTRAINT_TANGENT_ID("SketchConstraintTangent");
7         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
8         data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
9
10 """
11 from GeomDataAPI import *
12 from GeomAPI import *
13 from ModelAPI import *
14 import math
15 #=========================================================================
16 # Initialization of the test
17 #=========================================================================
18
19 __updated__ = "2015-03-17"
20
21 aSession = ModelAPI_Session.get()
22 aDocument = aSession.moduleDocument()
23 #=========================================================================
24 # Creation of a sketch
25 #=========================================================================
26 aSession.startOperation()
27 aSketchCommonFeature = aDocument.addFeature("Sketch")
28 aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
29 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
30 origin.setValue(0, 0, 0)
31 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
32 dirx.setValue(1, 0, 0)
33 diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
34 diry.setValue(0, 1, 0)
35 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
36 norm.setValue(0, 0, 1)
37 aSession.finishOperation()
38 #=========================================================================
39 # Creation of an arc and a line
40 #=========================================================================
41 # Arc
42 aSession.startOperation()
43 aSketchArc1 = aSketchFeature.addFeature("SketchArc")
44 anArcCentr = geomDataAPI_Point2D(aSketchArc1.attribute("ArcCenter"))
45 anArcCentr.setValue(10., 10.)
46 anArcStartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcStartPoint"))
47 anArcStartPoint.setValue(0., 50.)
48 anArcEndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcEndPoint"))
49 anArcEndPoint.setValue(50., 0.)
50 aSession.finishOperation()
51 # Line
52 aSession.startOperation()
53 aSketchLine1 = aSketchFeature.addFeature("SketchLine")
54 aLineStartPoint = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint"))
55 aLineEndPoint = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint"))
56 aLineStartPoint.setValue(0., 50.)
57 aLineEndPoint.setValue(0., 100.)
58 aSession.finishOperation()
59 #=========================================================================
60 # Link arc start point and line's point by the coincidence constraint
61 #=========================================================================
62 aSession.startOperation()
63 aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
64 reflistA = aConstraint.refattr("ConstraintEntityA")
65 reflistB = aConstraint.refattr("ConstraintEntityB")
66 reflistA.setAttr(anArcStartPoint)
67 reflistB.setAttr(aLineStartPoint)
68 aConstraint.execute()
69 aSession.finishOperation()
70 #=========================================================================
71 # Add tangency constraint and check correctness
72 #=========================================================================
73 aSession.startOperation()
74 aTangency = aSketchFeature.addFeature("SketchConstraintTangent")
75 aRefObjectA = aTangency.refattr("ConstraintEntityA")
76 aRefObjectB = aTangency.refattr("ConstraintEntityB")
77 anObjectA = modelAPI_ResultConstruction(aSketchArc1.firstResult())
78 anObjectB = modelAPI_ResultConstruction(aSketchLine1.firstResult())
79 assert (anObjectA is not None)
80 assert (anObjectB is not None)
81 aRefObjectA.setObject(anObjectA)
82 aRefObjectB.setObject(anObjectB)
83 aTangency.execute()
84 aSession.finishOperation()
85 anArcVecX = anArcStartPoint.x() - anArcCentr.x()
86 anArcVecY = anArcStartPoint.y() - anArcCentr.y()
87 aLineVecX = aLineEndPoint.x() - aLineStartPoint.x()
88 aLineVecY = aLineEndPoint.y() - aLineStartPoint.y()
89 aDot = anArcVecX * aLineVecX + anArcVecY * aLineVecY
90 print anArcVecX, anArcVecY
91 print aLineVecX, aLineVecY
92 print aDot
93 print aLineStartPoint.x(), aLineStartPoint.y(), aLineEndPoint.x(), aLineEndPoint.y()
94 assert(aDot == 0.)
95 #=========================================================================
96 # End of test
97 #=========================================================================