4 static const std::string MY_SKETCH_ARC_ID("SketchArc");
5 static const std::string MY_CENTER_ID = "center_point";
6 static const std::string MY_START_ID = "start_point";
7 static const std::string MY_END_ID = "end_point";
8 data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::typeId());
9 data()->addAttribute(SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D::typeId());
10 data()->addAttribute(SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D::typeId());
13 #=========================================================================
14 # Initialization of the test
15 #=========================================================================
16 from GeomDataAPI import *
17 from ModelAPI import *
19 from salome.shaper import model
21 __updated__ = "2017-03-28"
25 #=========================================================================
27 #=========================================================================
29 def verifyLastArc(theSketch, theCenter, theStart, theEnd):
31 subroutine to verify position of last arc in the sketch
33 aLastArc = model.lastSubFeature(theSketch, "SketchArc")
34 aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
35 aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point"))
36 aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point"))
38 verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1])
40 verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
42 verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
43 aRadius = aLastArc.real("radius")
44 aDistCS = model.distancePointPoint(aCenterPnt, aStartPnt)
45 aDistCE = model.distancePointPoint(aCenterPnt, aEndPnt)
46 assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
47 assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong radius {0}, expected {1}".format(aRadius.value(), aDistCS)
49 def verifyPointCoordinates(thePoint, theX, theY):
50 assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY)
53 aSession = ModelAPI_Session.get()
54 aDocument = aSession.moduleDocument()
55 #=========================================================================
56 # Creation of a sketch
57 #=========================================================================
58 aSession.startOperation()
59 aSketchCommonFeature = aDocument.addFeature("Sketch")
60 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
61 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
62 origin.setValue(0, 0, 0)
63 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
64 dirx.setValue(1, 0, 0)
65 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
66 norm.setValue(0, 0, 1)
67 aSession.finishOperation()
69 #=========================================================================
70 # Test 1. Create an arc by center, start and end points
71 #=========================================================================
75 aSession.startOperation()
76 aSketchArc = aSketchFeature.addFeature("SketchArc")
77 assert (aSketchArc.getKind() == "SketchArc")
78 anArcCenter = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
79 assert (not anArcCenter.isInitialized())
80 anArcCenter.setValue(aCenter[0], aCenter[1])
81 anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
82 assert (not anArcStartPoint.isInitialized())
83 anArcStartPoint.setValue(aStart[0], aStart[1])
84 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
85 assert (not anArcEndPoint.isInitialized())
86 anArcEndPoint.setValue(aEnd[0], aEnd[1])
87 aSession.finishOperation()
88 verifyLastArc(aSketchFeature, aCenter, aStart, aEnd)
91 aSession.startOperation()
92 anArcCenter.setValue(aCenter[0], aCenter[1])
93 aSession.finishOperation()
94 verifyLastArc(aSketchFeature, [], [], [])
96 deltaX, deltaY = 5., 2.
97 aStart = [anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY]
98 aSession.startOperation()
99 anArcStartPoint.setValue(aStart[0], aStart[1])
100 aSession.finishOperation()
101 verifyLastArc(aSketchFeature, [], [], [])
103 aEnd = [anArcEndPoint.x() - deltaX, anArcEndPoint.y() - deltaY]
104 aSession.startOperation()
105 anArcEndPoint.setValue(aEnd[0], aEnd[1])
106 aSession.finishOperation()
107 verifyLastArc(aSketchFeature, [], [], [])
108 # Check that changing the radius does not affect arc
109 aSession.startOperation()
110 anArcRadius = aSketchArc.real("radius")
111 aPrevRadius = anArcRadius.value();
112 anArcRadius.setValue(aPrevRadius + 10.)
113 aSession.finishOperation()
114 assert (math.fabs(anArcRadius.value() - aPrevRadius) < TOLERANCE)
115 verifyLastArc(aSketchFeature, [], [], [])
116 # Check that changing the angle does not affect arc
117 aSession.startOperation()
118 anArcAngle = aSketchArc.real("angle")
119 aPrevAngle = anArcAngle.value()
120 anArcAngle.setValue(aPrevAngle + 10.)
121 aSession.finishOperation()
122 assert (math.fabs(anArcAngle.value() - aPrevAngle) < TOLERANCE)
123 verifyLastArc(aSketchFeature, [], [], [])
125 #=========================================================================
127 #=========================================================================
129 assert(model.checkPythonDump())