Salome HOME
8c5b4de3260b7e7fe73a582f10b1f8724756467d
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintAngleBehaviorDirect.py
1 # Copyright (C) 2014-2022  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from GeomDataAPI import *
21 from ModelAPI import *
22 import math
23 from salome.shaper import model
24
25
26 #=========================================================================
27 # Initialization of the test
28 #=========================================================================
29
30 __updated__ = "2019-12-12"
31
32 ANGLE_DIRECT = 0
33 ANGLE_COMPLEMENTARY = 1
34 ANGLE_BACKWARD = 2
35
36 aSession = ModelAPI_Session.get()
37 aDocument = aSession.moduleDocument()
38 #=========================================================================
39 # Creation of a sketch
40 #=========================================================================
41 aSession.startOperation()
42 aSketchCommonFeature = aDocument.addFeature("Sketch")
43 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
44 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
45 origin.setValue(0, 0, 0)
46 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
47 dirx.setValue(1, 0, 0)
48 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
49 norm.setValue(0, 0, 1)
50 aSession.finishOperation()
51 #=========================================================================
52 # Create two lines
53 #=========================================================================
54 aSession.startOperation()
55 aSketchLineA = aSketchFeature.addFeature("SketchLine")
56 aStartPointA = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
57 aEndPointA = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
58 aStartPointA.setValue(-100., 25.)
59 aEndPointA.setValue(100., -25.)
60
61 aSketchLineB = aSketchFeature.addFeature("SketchLine")
62 aStartPointB = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
63 aEndPointB = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
64 aStartPointB.setValue(-100., -25.)
65 aEndPointB.setValue(100., 25.)
66 aSession.finishOperation()
67 #=========================================================================
68 # Make a constraint to keep the angle
69 #=========================================================================
70 ANGLE_DEGREE = 30.
71 aSession.startOperation()
72 aConstraint = aSketchFeature.addFeature("SketchConstraintAngle")
73 anAngleType = aConstraint.integer("AngleType")
74 anAngleType.setValue(ANGLE_DIRECT)
75 geomDataAPI_Point2D(aConstraint.attribute("SelectedPointA")).setValue(aStartPointA.pnt())
76 geomDataAPI_Point2D(aConstraint.attribute("SelectedPointB")).setValue(aStartPointB.pnt())
77 aConstraint.refattr("ConstraintEntityA").setObject(aSketchLineA.firstResult())
78 aConstraint.refattr("ConstraintEntityB").setObject(aSketchLineB.firstResult())
79 anAngleVal = aConstraint.real("AngleValue")
80 anAngleVal.setValue(ANGLE_DEGREE)
81 aSession.finishOperation()
82 #=========================================================================
83 # Move presentation of the angle and check the angle value
84 #=========================================================================
85 pointsA = [aStartPointA.pnt(), aEndPointA.pnt()]
86 pointsB = [aStartPointB.pnt(), aEndPointB.pnt()]
87 refs = [(pointsA[0], pointsB[1], 180. - ANGLE_DEGREE),
88         (pointsA[1], pointsB[1], ANGLE_DEGREE),
89         (pointsA[1], pointsB[0], 180. - ANGLE_DEGREE),
90         (pointsA[0], pointsB[0], ANGLE_DEGREE)
91        ]
92 aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt"))
93 for ref in refs:
94     aSession.startOperation()
95     aFlyoutPoint.setValue(0.5 * (ref[0].x() + ref[1].x()), 0.5 * (ref[0].y() + ref[1].y()))
96     aSession.finishOperation()
97     assert(anAngleType.value() == ANGLE_DIRECT)
98     assert(anAngleVal.value() == ref[2])
99     assert(aStartPointA.x() == pointsA[0].x() and aStartPointA.y() == pointsA[0].y())
100     assert(aEndPointA.x() == pointsA[1].x() and aEndPointA.y() == pointsA[1].y())
101     assert(aStartPointB.x() == pointsB[0].x() and aStartPointB.y() == pointsB[0].y())
102     assert(aEndPointB.x() == pointsB[1].x() and aEndPointB.y() == pointsB[1].y())
103 #=========================================================================
104 # End of test
105 #=========================================================================
106
107 assert(model.checkPythonDump())