norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0., 57.74)
aCircleRadius.setValue(50.)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(50)
aSession.finishOperation()
norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(10., 10.)
aCircleRadius.setValue(50.)
aSession.finishOperation()
norm.setValue(0, 0, 1)
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
aCircleCentr.setValue(0, 0)
aCircleRadius.setValue(50)
norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(10., 10.)
aCircleRadius.setValue(50.)
aSession.finishOperation()
norm.setValue(0, 0, 1)
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
aCircleCentr.setValue(0, 0)
aCircleRadius.setValue(50)
aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
aSession.startOperation()
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(10)
aSession.finishOperation()
aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
aSession.startOperation()
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(10)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(50., 50)
aCircleRadius.setValue(20.)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(20)
aSession.finishOperation()
aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
aSession.startOperation()
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(10)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(20)
aSession.finishOperation()
aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
aSession.startOperation()
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(10)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(-10, 0)
aCircleRadius.setValue(50)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(10, 0)
aCircleRadius.setValue(50)
aSession.finishOperation()
norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
- anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
- aCircleRadius = aSketchCircle.real("CircleRadius")
+ anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+ aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0.5 + step * (0.5 + i), 0.5 + step * (0.5 + j))
aCircleRadius.setValue(radius)
aSketchFeatures.append(aSketchFeature)
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(50)
aSession.finishOperation()
# Create circle
aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("CircleCenter"))
-aCircleRadius = aSketchCircleFeature.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("circle_center"))
+aCircleRadius = aSketchCircleFeature.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(10)
aSession.finishOperation()
# Create arc
aSketchArcFeature = aSketchFeature.addFeature("SketchArc")
-aSketchArcFeature.string("ArcType").setValue("CenterStartEnd")
-aSketchArcCenterPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("ArcCenter"))
-aSketchArcStartPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("ArcStartPoint"))
-aSketchArcEndPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("ArcEndPoint"))
+aSketchArcCenterPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("center_point"))
+aSketchArcStartPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("start_point"))
+aSketchArcEndPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("end_point"))
aSketchArcCenterPoint.setValue(100, 200)
aSketchArcStartPoint.setValue(200, 200)
aSketchArcEndPoint.setValue(0, 200)
# Create circle
aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("CircleCenter"))
-aCircleRadius = aSketchCircleFeature.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("circle_center"))
+aCircleRadius = aSketchCircleFeature.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(20)
aSession.finishOperation()
# Create circles
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(-25, 0)
aCircleRadius.setValue(50)
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(25, 0)
aCircleRadius.setValue(50)
aSession.finishOperation()
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0., 0.)
aCircleRadius.setValue(30.)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(20)
aSession.finishOperation()
aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
aSession.startOperation()
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(10)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(20)
aSession.finishOperation()
aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
aSession.startOperation()
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0, 0)
aCircleRadius.setValue(10)
aSession.finishOperation()
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(50, 50)
aCircleRadius.setValue(20)
aSession.finishOperation()
norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
- anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
- aCircleRadius = aSketchCircle.real("CircleRadius")
+ anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+ aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(0.5 + step * (0.5 + i), 0.5 + step * (0.5 + j))
aCircleRadius.setValue(radius)
aSketchFeatures.append(aSketchFeature)
norm.setValue(0, 0, 1)
# Create circle
aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(50, 50)
aCircleRadius.setValue(20)
aSession.finishOperation()
# Create circles
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(-25, 0)
aCircleRadius.setValue(50)
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(25, 0)
aCircleRadius.setValue(50)
aSession.finishOperation()
aSketchFeature2 = featureToCompositeFeature(aPart.addFeature("Sketch"))
aSketchFeature2.selection("External").setValue(aXOYPlane, None);
aCirc1 = aSketchFeature2.addFeature("SketchCircle")
-geomDataAPI_Point2D(aCirc1.attribute("CircleCenter")).setValue(100, 50)
-aCirc1.real("CircleRadius").setValue(40)
+geomDataAPI_Point2D(aCirc1.attribute("circle_center")).setValue(100, 50)
+aCirc1.real("circle_radius").setValue(40)
aSession.finishOperation()
#=========================================================================
aSketchFeature3 = featureToCompositeFeature(aPart.addFeature("Sketch"))
aSketchFeature3.selection("External").setValue(aXOYPlane, None);
aCirc2 = aSketchFeature3.addFeature("SketchCircle")
-geomDataAPI_Point2D(aCirc2.attribute("CircleCenter")).setValue(20, 20)
-aCirc2.real("CircleRadius").setValue(10)
+geomDataAPI_Point2D(aCirc2.attribute("circle_center")).setValue(20, 20)
+aCirc2.real("circle_radius").setValue(10)
aSession.finishOperation()
#=========================================================================
norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
- anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
- aRadiusAttr = aSketchCircle.real("CircleRadius")
+ anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+ aRadiusAttr = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(10., 20.)
aRadiusAttr.setValue(10.)
self.aSession.finishOperation()
#=========================================================================
aSession.startOperation()
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aRadiusAttr = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aRadiusAttr = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(250., 250)
aRadiusAttr.setValue(25.)
aSession.finishOperation()
norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
- anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
- aRadiusAttr = aSketchCircle.real("CircleRadius")
+ anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+ aRadiusAttr = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(10., 20.)
aRadiusAttr.setValue(10.)
self.aSession.finishOperation()
mirrored_objects = mirror.mirroredObjects()
mirrored_circle = mirrored_objects.object(0)
circle_feature = ModelAPI_Feature.feature(mirrored_circle)
- center = geomDataAPI_Point2D(circle_feature.attribute("CircleCenter"))
+ center = geomDataAPI_Point2D(circle_feature.attribute("circle_center"))
self.assertEqual(center.x(), -30)
# dir(mirrored_circle)
- # center = geomDataAPI_Point2D(mirrored_circle.data().attribute("CircleCenter"))
+ # center = geomDataAPI_Point2D(mirrored_circle.data().attribute("circle_center"))
# self.assertEqual(center.x(), -30, msg="%s"%(dir(mirrored_circle)))
# self.assertTrue(False, msg="%s" % (dir(mirrored_circle)))
def setUp(self):
SketcherTestCase.setUp(self)
self.line = self.sketch.addLine(0, 0, 0, 1)
- self.arc = self.sketch.addArc(0, 1, 0, 0, 1, 1)
+ self.arc = self.sketch.addArc(0, 1, 0, 0, 1, 1, False)
self.sketch.setCoincident(
- self.line.endPoint(), self.arc.startPoint()
+ self.line.startPoint(), self.arc.startPoint()
)
def test_set_tangent(self):
"""
from SketchAPI import addSketch
-from tools import addPolyline, addPolygon, dof
+from tools import *
# Copyright (C) 2014-20xx CEA/DEN, EDF R&D
import ModelHighAPI
+import GeomDataAPI
def addPolyline(sketch, *coords):
"""Add a poly-line to sketch.
aSketch = sketch
if issubclass(type(aSketch), ModelHighAPI.ModelHighAPI_Interface):
aSketch = sketch.feature()
- return int(filter(str.isdigit, aSketch.string("SolverDOF").value()))
\ No newline at end of file
+ return int(filter(str.isdigit, aSketch.string("SolverDOF").value()))
+
+def distancePointPoint(thePoint1, thePoint2):
+ aGeomPnt1 = thePoint1
+ aGeomPnt2 = thePoint2
+ if issubclass(type(thePoint1), GeomDataAPI.GeomDataAPI_Point2D):
+ aGeomPnt1 = thePoint1.pnt()
+ if issubclass(type(thePoint2), GeomDataAPI.GeomDataAPI_Point2D):
+ aGeomPnt2 = thePoint2.pnt()
+ return aGeomPnt1.distance(aGeomPnt2)
+
+def lastSubFeature(theSketch, theKind):
+ """
+ obtains last feature of given kind from the sketch
+ """
+ for anIndex in range(theSketch.numberOfSubs() - 1, -1, -1):
+ aSub = theSketch.subFeature(anIndex)
+ if (aSub.getKind() == theKind):
+ return aSub
INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
ADD_UNIT_TESTS(TestSketchPointLine.py
- TestCreateArc.py
+ TestCreateArcByCenterStartEnd.py
+ TestCreateArcByThreePoints.py
+ TestCreateArcByTangentEdge.py
+ TestCreateArcChangeType.py
TestCreateCircleByCenterAndPassed.py
TestCreateCircleByThreePoints.py
TestCreateCircleChangeType.py
TestConstraintVertical.py
TestConstraintEqual.py
TestConstraintTangent.py
- TestConstraintMirror.py
TestConstraintAngle.py
TestConstraintMiddlePoint.py
+ TestMirror.py
TestMultiRotation.py
TestMultiTranslation.py
TestFillet.py
aCirc->parameter(anEdge->firstPoint(), paramTolerance, aStartParam);
aCirc->parameter(aMinPnt, paramTolerance, aMidParam);
aCirc->parameter(anEdge->lastPoint(), paramTolerance, anEndParam);
+
+ // adjust period
+ anEndParam -= aStartParam;
+ aMidParam -= aStartParam;
+ if (anEndParam < 0.0)
+ anEndParam += 2.0 * PI;
+ if (aMidParam < 0.0)
+ aMidParam += 2.0 * PI;
+
aWasBlocked = data()->blockSendAttributeUpdated(true);
- if(aStartParam < aMidParam && aMidParam < anEndParam) {
+ if(aMidParam < anEndParam) {
setReversed(false);
} else {
setReversed(true);
<context>
<name>SketchMacroCircle:Model_FeatureValidator</name>
<message>
- <source>Attribute "CircleCenter" is not initialized.</source>
+ <source>Attribute "circle_center" is not initialized.</source>
<translation>A center point is not selected</translation>
</message>
</context>
<context>
<name>SketchMacroCircle:CircleCenter</name>
<message>
- <source>Attribute "CircleCenter" is locked by modification value in the viewer.</source>
+ <source>Attribute "circle_center" is locked by modification value in the viewer.</source>
<translation>Select a center point</translation>
</message>
</context>
<context>
<name>SketchMacroCircle:CircleRadius</name>
<message>
- <source>Attribute "CircleRadius" is locked by modification value in the viewer.</source>
+ <source>Attribute "circle_radius" is locked by modification value in the viewer.</source>
<translation>Select a radius distance</translation>
</message>
</context>
<context>
<name>SketchMacroCircle:Model_FeatureValidator</name>
<message>
- <source>Attribute "CircleRadius" is not initialized.</source>
+ <source>Attribute "circle_radius" is not initialized.</source>
<translation>Set the circle radius</translation>
</message>
</context>
<context>
<name>SketchArc:ArcCenter</name>
<message>
- <source>Attribute "ArcCenter" is locked by modification value in the viewer.</source>
+ <source>Attribute "center_point" is locked by modification value in the viewer.</source>
<translation>Select a center point</translation>
</message>
</context>
<context>
<name>SketchArc:ArcCenter</name>
<message>
- <source>Attribute "ArcCenter" is not initialized.</source>
+ <source>Attribute "center_point" is not initialized.</source>
<translation>Center point is not defined</translation>
</message>
</context>
<context>
<name>SketchArc:Model_FeatureValidator</name>
<message>
- <source>Attribute "ArcCenter" is not initialized.</source>
+ <source>Attribute "center_point" is not initialized.</source>
<translation>Select an arc center</translation>
</message>
</context>
<context>
<name>SketchArc:Model_FeatureValidator:ArcStartPoint</name>
<message>
- <source>Attribute "ArcStartPoint" is not initialized.</source>
+ <source>Attribute "start_point" is not initialized.</source>
<translation>Select an arc start point</translation>
</message>
</context>
<context>
<name>SketchArc:Model_FeatureValidator</name>
<message>
- <source>Attribute "ArcEndPoint" is not initialized.</source>
+ <source>Attribute "end_point" is not initialized.</source>
<translation>Select an arc end point</translation>
</message>
</context>
#=========================================================================
aSession.startOperation()
aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
anArcCentr.setValue(0., 0.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
anArcStartPoint.setValue(0., 10.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
anArcEndPoint.setValue(1., 10.)
aSession.finishOperation()
# the arc must be small, not near to the whole circle
# check from the scratch that from initial state to counterclockwise position also works
aSession.startOperation()
aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
anArcCentr.setValue(0., 0.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
anArcStartPoint.setValue(0., 10.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
anArcEndPoint.setValue(-1., 10.)
aSession.finishOperation()
# the arc must be small, not near to the whole circle
#=========================================================================
aSession.startOperation()
aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
anArcCentr.setValue(0., 0.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
anArcStartPoint.setValue(0., 10.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
anArcEndPoint.setValue(10, 0.)
aSession.finishOperation()
-anInversed = aSketchArc.boolean("InversedArc").value()
+anInversed = aSketchArc.boolean("reversed").value()
for aCenterCoords in range(1, 20):
aSession.startOperation()
anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
aSession.finishOperation()
- assert aSketchArc.boolean("InversedArc").value() == anInversed
+ assert aSketchArc.boolean("reversed").value() == anInversed
for aCenterCoords in range(20, -20, -1):
aSession.startOperation()
anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
aSession.finishOperation()
- assert aSketchArc.boolean("InversedArc").value() == anInversed
+ assert aSketchArc.boolean("reversed").value() == anInversed
for aCenterCoords in range(-20, 20):
aSession.startOperation()
anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
aSession.finishOperation()
- assert aSketchArc.boolean("InversedArc").value() == anInversed
+ assert aSketchArc.boolean("reversed").value() == anInversed
#=========================================================================
# Test that movement of start point of arc does not change central point
#=========================================================================
assert (math.fabs(aDirX * aVecY - aDirY * aVecX) <= TOLERANCE)
def checkPointOnCircle(point, circle):
- aCenter = geomDataAPI_Point2D(circle.attribute("CircleCenter"))
- aRadius = circle.real("CircleRadius").value()
+ aCenter = geomDataAPI_Point2D(circle.attribute("circle_center"))
+ aRadius = circle.real("circle_radius").value()
aDist = math.hypot(point.x() - aCenter.x(), point.y() - aCenter.y())
assert (math.fabs(aDist - aRadius) <= TOLERANCE)
def checkPointOnArc(point, arc):
- aStart = geomDataAPI_Point2D(arc.attribute("ArcStartPoint"))
- aCenter = geomDataAPI_Point2D(arc.attribute("ArcCenter"))
+ aStart = geomDataAPI_Point2D(arc.attribute("start_point"))
+ aCenter = geomDataAPI_Point2D(arc.attribute("center_point"))
aRadius = math.hypot(aStart.x() - aCenter.x(), aStart.y() - aCenter.y())
aDist = math.hypot(point.x() - aCenter.x(), point.y() - aCenter.y())
assert (math.fabs(aDist - aRadius) <= TOLERANCE)
#=========================================================================
aSession.startOperation()
aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
anArcCentr.setValue(10., 10.)
anArcStartPoint.setValue(0., 50.)
anArcEndPoint.setValue(50., 0.)
aSession.startOperation()
# create circle with center coincident with origin
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-aCircleCenter = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+aCircleCenter = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
aCircleCenter.setValue(10., 10.)
aCircleRadius.setValue(25.)
aSession.finishOperation()
__updated__ = "2014-10-28"
-def distancePointPoint(pointA, pointB):
- """
- subroutine to calculate distance between two points
- result of calculated distance is has 10**-5 precision
- """
- xdiff = math.pow((pointA.x() - pointB.x()), 2)
- ydiff = math.pow((pointA.y() - pointB.y()), 2)
- return round(math.sqrt(xdiff + ydiff), 5)
-
def distancePointLine(point, line):
"""
subroutine to calculate distance between point and line
# Make a constraint to keep the distance
#=========================================================================
PT_PT_DIST = 25.
-aDist = distancePointPoint(aSketchPointCoords, aLineAStartPoint);
+aDist = model.distancePointPoint(aSketchPointCoords, aLineAStartPoint);
assert (aDist != PT_PT_DIST)
aSession.startOperation()
aConstraint = aSketchFeature.addFeature("SketchConstraintDistance")
aSession.startOperation()
aDistance.setValue(PT_PT_DIST)
aSession.finishOperation()
-assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10)
+assert (math.fabs(model.distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10)
assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# Move line, check that distance is constant
aLineAStartPoint.setValue(0., 40.)
aLineAEndPoint.setValue(100., 40.)
aSession.finishOperation()
-assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10)
+assert (math.fabs(model.distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10)
assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# Remove constraint, check the points are unconstrained now
aSession.startOperation()
aSketchPointCoords.setValue(0., 0.)
aSession.finishOperation()
-assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) > 1.e-10)
+assert (math.fabs(model.distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) > 1.e-10)
assert (model.dof(aSketchFeature) == 6)
#=========================================================================
refattrA.setAttr(aLineAStartPoint)
refattrB.setAttr(aLineAEndPoint)
aSession.finishOperation()
-assert (math.fabs(distancePointPoint(aLineAStartPoint, aLineAEndPoint) - PT_LINE_DIST) < 1.e-10)
+assert (math.fabs(model.distancePointPoint(aLineAStartPoint, aLineAEndPoint) - PT_LINE_DIST) < 1.e-10)
assert (model.dof(aSketchFeature) == 5)
#=========================================================================
# End of test
norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
# add circle defined by 3 points
- circle = aSketchFeature.addFeature("SketchCircle")
- circle.string("CircleType").setValue("ThreePoints")
- geomDataAPI_Point2D(circle.attribute("FirstPoint")).setValue(-40., 50.)
- geomDataAPI_Point2D(circle.attribute("SecondPoint")).setValue(-50., 60.)
- geomDataAPI_Point2D(circle.attribute("ThirdPoint")).setValue(-60., 50.)
+ circle = aSketchFeature.addFeature("SketchMacroCircle")
+ circle.string("circle_type").setValue("circle_type_by_three_points")
+ geomDataAPI_Point2D(circle.attribute("first_point")).setValue(-40., 50.)
+ geomDataAPI_Point2D(circle.attribute("second_point")).setValue(-50., 60.)
+ geomDataAPI_Point2D(circle.attribute("third_point")).setValue(-60., 50.)
# add line
line = aSketchFeature.addFeature("SketchLine")
lineStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
#=========================================================================
aSession.startOperation()
aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
anArcEndPoint.setValue(50., 0.)
aSession.finishOperation()
assert (model.dof(aSketchFeature) == 5)
# Circle
aSession.startOperation()
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(-25., -25.)
aCircleRadius.setValue(25.)
aSession.finishOperation()
#=========================================================================
aSession.startOperation()
anExtCircle = aSketchFeature.addFeature("SketchCircle")
-anExtCircleCenter = geomDataAPI_Point2D(anExtCircle.attribute("CircleCenter"))
-anExtCircleRadius = anExtCircle.real("CircleRadius")
+anExtCircleCenter = geomDataAPI_Point2D(anExtCircle.attribute("circle_center"))
+anExtCircleRadius = anExtCircle.real("circle_radius")
anExtCircleCenter.setValue(-50., 50.)
anExtCircleRadius.setValue(10.)
anExtCircle.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchCircle_1_2")
+++ /dev/null
-"""
- TestConstraintMirror.py
- Unit test of SketchPlugin_ConstraintMirror class
-
- SketchPlugin_ConstraintMirror
- static const std::string MY_CONSTRAINT_MIRROR_ID("SketchConstraintMirror");
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefListAttr::typeId());
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefListAttr::typeId());
-
-"""
-from GeomDataAPI import *
-from ModelAPI import *
-import math
-from salome.shaper import model
-
-#=========================================================================
-# Initialization of the test
-#=========================================================================
-
-__updated__ = "2015-03-17"
-
-#=========================================================================
-# Auxiliary functions
-#=========================================================================
-def normalize(theDir):
- aLen = math.hypot(theDir[0], theDir[1])
- if aLen < 1.e-10:
- aLen = 1.0
- return [theDir[0] / aLen, theDir[1] / aLen]
-
-def checkMirror(theListInit, theListMirr, theMirrorLine):
- TOL = 6.e-5
- aListSize = theListInit.size()
-
- aLineStartPoint = geomDataAPI_Point2D(theMirrorLine.attribute("StartPoint"))
- aLineEndPoint = geomDataAPI_Point2D(theMirrorLine.attribute("EndPoint"))
- aLineDir = [aLineEndPoint.x() - aLineStartPoint.x(), aLineEndPoint.y() - aLineStartPoint.y()]
- aLineDir = normalize(aLineDir)
-
- for ind in range(0, aListSize):
- aFeatureB = ModelAPI_Feature.feature(theListInit.object(ind))
- aFeatureC = ModelAPI_Feature.feature(theListMirr.object(ind))
- assert(aFeatureB is not None)
- assert(aFeatureC is not None)
- assert(aFeatureB.getKind() == aFeatureC.getKind())
-
- anAttributes = []
- if (aFeatureB.getKind() == "SketchLine"):
- anAttributes = ['StartPoint', 'EndPoint']
- elif (aFeatureB.getKind() == "SketchArc"):
- anAttributes = ['ArcCenter', 'ArcStartPoint', 'ArcEndPoint']
-
- for key in anAttributes:
- aPointB = geomDataAPI_Point2D(aFeatureB.attribute(key))
- aPointC = geomDataAPI_Point2D(aFeatureC.attribute(key))
- aDir = [aPointC.x() - aPointB.x(), aPointC.y() - aPointB.y()]
- aDir = normalize(aDir)
- aDot = aLineDir[0] * aDir[0] + aLineDir[1] * aDir[1]
- assert math.fabs(aDot) < TOL, "aDot = {0}".format(aDot)
- aDir[0] = aLineEndPoint.x() - 0.5 * (aPointB.x() + aPointC.x())
- aDir[1] = aLineEndPoint.y() - 0.5 * (aPointB.y() + aPointC.y())
- aCross = aLineDir[0] * aDir[1] - aLineDir[1] * aDir[0]
- assert math.fabs(aCross) < TOL, "aCross = {0}".format(aCross)
-
-
-#=========================================================================
-# Start of test
-#=========================================================================
-aSession = ModelAPI_Session.get()
-aDocument = aSession.moduleDocument()
-#=========================================================================
-# Creation of a sketch
-#=========================================================================
-aSession.startOperation()
-aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
-origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
-origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
-dirx.setValue(1, 0, 0)
-norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
-norm.setValue(0, 0, 1)
-aSession.finishOperation()
-#=========================================================================
-# Creation of an arc and two lines
-#=========================================================================
-# Arc
-aSession.startOperation()
-aSketchArc1 = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc1.attribute("ArcCenter"))
-anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcStartPoint"))
-anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcEndPoint"))
-anArcEndPoint.setValue(50., 0.)
-aSession.finishOperation()
-# Line 1
-aSession.startOperation()
-aSketchLine1 = aSketchFeature.addFeature("SketchLine")
-aLine1StartPoint = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint"))
-aLine1EndPoint = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint"))
-aLine1StartPoint.setValue(0., 50.)
-aLine1EndPoint.setValue(0., 100.)
-aSession.finishOperation()
-# Line 2
-aSession.startOperation()
-aSketchLine2 = aSketchFeature.addFeature("SketchLine")
-aLine2StartPoint = geomDataAPI_Point2D(aSketchLine2.attribute("StartPoint"))
-aLine2EndPoint = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint"))
-aLine2StartPoint.setValue(50., 0.)
-aLine2EndPoint.setValue(100., 0.)
-aSession.finishOperation()
-assert (model.dof(aSketchFeature) == 13)
-#=========================================================================
-# Link arc points and lines points by the coincidence constraint
-#=========================================================================
-aSession.startOperation()
-aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
-reflistA = aConstraint.refattr("ConstraintEntityA")
-reflistB = aConstraint.refattr("ConstraintEntityB")
-reflistA.setAttr(anArcStartPoint)
-reflistB.setAttr(aLine1StartPoint)
-aConstraint.execute()
-aSession.finishOperation()
-aSession.startOperation()
-aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
-reflistA = aConstraint.refattr("ConstraintEntityA")
-reflistB = aConstraint.refattr("ConstraintEntityB")
-reflistA.setAttr(anArcEndPoint)
-reflistB.setAttr(aLine2StartPoint)
-aConstraint.execute()
-aSession.finishOperation()
-assert (model.dof(aSketchFeature) == 9)
-#=========================================================================
-# Add tangency constraint and check correctness
-#=========================================================================
-aSession.startOperation()
-aTangency = aSketchFeature.addFeature("SketchConstraintTangent")
-aRefObjectA = aTangency.refattr("ConstraintEntityA")
-aRefObjectB = aTangency.refattr("ConstraintEntityB")
-anObjectA = modelAPI_ResultConstruction(aSketchArc1.lastResult())
-anObjectB = modelAPI_ResultConstruction(aSketchLine1.lastResult())
-assert (anObjectA is not None)
-assert (anObjectB is not None)
-aRefObjectA.setObject(anObjectA)
-aRefObjectB.setObject(anObjectB)
-aTangency.execute()
-aSession.finishOperation()
-assert (model.dof(aSketchFeature) == 8)
-#=========================================================================
-# Create mirror line
-#=========================================================================
-aSession.startOperation()
-aMirrorLine = aSketchFeature.addFeature("SketchLine")
-aLineStartPoint = geomDataAPI_Point2D(aMirrorLine.attribute("StartPoint"))
-aLineEndPoint = geomDataAPI_Point2D(aMirrorLine.attribute("EndPoint"))
-aLineStartPoint.setValue(100., 0.)
-aLineEndPoint.setValue(100., 100.)
-aSession.finishOperation()
-assert (model.dof(aSketchFeature) == 12)
-#=========================================================================
-# Make mirror for objects created above
-#=========================================================================
-aSession.startOperation()
-aMirror = aSketchFeature.addFeature("SketchConstraintMirror")
-aRefObjectA = aMirror.refattr("ConstraintEntityA")
-aRefObjectA.setObject(modelAPI_ResultConstruction(aMirrorLine.firstResult()))
-aRefListInitial = aMirror.reflist("ConstraintMirrorList")
-aRefListInitial.append(aSketchLine1.lastResult())
-aRefListInitial.append(aSketchArc1.lastResult())
-aRefListInitial.append(aSketchLine2.lastResult())
-aMirror.execute()
-aSession.finishOperation()
-assert (model.dof(aSketchFeature) == 12)
-#=========================================================================
-# Verify the simmetricity of all mirrored objects
-#=========================================================================
-aRefListB = aMirror.reflist("ConstraintEntityB")
-aRefListC = aMirror.reflist("ConstraintEntityC")
-assert (aRefListB.size() == 3)
-assert (aRefListC.size() == 3)
-checkMirror(aRefListB, aRefListC, aMirrorLine)
-assert (model.dof(aSketchFeature) == 12)
-
-#=========================================================================
-# Remove object from mirror
-#=========================================================================
-aSession.startOperation()
-aRefListInitial.remove(aSketchLine2.lastResult())
-aSession.finishOperation()
-assert (aRefListB.size() == 2)
-assert (aRefListC.size() == 2)
-checkMirror(aRefListB, aRefListC, aMirrorLine)
-assert (model.dof(aSketchFeature) == 12)
-
-#=========================================================================
-# Clear list of mirrored features
-#=========================================================================
-aSession.startOperation()
-aRefListInitial.clear()
-assert (aRefListB.size() == 0)
-assert (aRefListC.size() == 0)
-# add arc once again
-aRefListInitial.append(aSketchArc1.lastResult())
-aSession.finishOperation()
-assert (aRefListB.size() == 1)
-assert (aRefListC.size() == 1)
-checkMirror(aRefListB, aRefListC, aMirrorLine)
-assert (model.dof(aSketchFeature) == 12)
-#=========================================================================
-# End of test
-#=========================================================================
-
-assert(model.checkPythonDump())
__updated__ = "2014-10-28"
-def distancePointPoint(pointA, pointB):
- """
- subroutine to calculate distance between two points
- result of calculated distance is has 10**-5 precision
- """
- xdiff = math.pow((pointA.x() - pointB.x()), 2)
- ydiff = math.pow((pointA.y() - pointB.y()), 2)
- return round(math.sqrt(xdiff + ydiff), 5)
-
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
#=========================================================================
aSession.startOperation()
aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
anArcEndPoint.setValue(50., 0.)
aSession.finishOperation()
assert (model.dof(aSketchFeature) == 5)
# Circle
aSession.startOperation()
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
anCircleCentr.setValue(-25., -25)
aCircleRadius.setValue(25.)
aSession.finishOperation()
assert (model.dof(aSketchFeature) == 8)
-# Change the radius of the arc
-aSession.startOperation()
-RADIUS = 40
-anArcRadius = aSketchArc.real("ArcRadius")
-anArcRadius.setValue(RADIUS)
-aSession.finishOperation()
-assert (model.dof(aSketchFeature) == 8)
#=========================================================================
# Make a constraint to keep the radius of the arc
#=========================================================================
+RADIUS = 40
aSession.startOperation()
aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
aRadius = aConstraint.real("ConstraintValue")
aResult = aSketchArc.lastResult()
assert (aResult is not None)
aRefObject.setObject(modelAPI_ResultConstruction(aResult))
-aConstraint.execute()
+aRadius.setValue(RADIUS)
aSession.finishOperation()
assert (aRadius.isInitialized())
assert (aRefObject.isInitialized())
aResult = aSketchCircle.lastResult()
assert (aResult is not None)
aRefObject.setObject(modelAPI_ResultConstruction(aResult))
-aConstraint.execute()
+aRadius.setValue(RADIUS)
aSession.finishOperation()
assert (aRadius.isInitialized())
assert (aRefObject.isInitialized())
assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# Perform some actions and checks:
-# 1. Check that constraints does not changes values
+# 1. Check that constraints does not change values
# 2. Move one point of the arc
# 3. Check that second point is moved also
#=========================================================================
-assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10)
-assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10)
+distCS = model.distancePointPoint(anArcCentr, anArcStartPoint)
+distCE = model.distancePointPoint(anArcCentr, anArcEndPoint)
+assert (math.fabs(distCS - RADIUS) < 1.e-10)
+assert (math.fabs(distCE - RADIUS) < 1.e-10)
anArcPrevEndPointX = anArcEndPoint.x()
anArcPrevEndPointY = anArcEndPoint.y()
# Move one point of the arc
aSession.finishOperation()
assert (anArcEndPoint.x() != anArcPrevEndPointX)
assert (anArcEndPoint.y() != anArcPrevEndPointY)
-assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10)
-assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10)
+distCS = model.distancePointPoint(anArcCentr, anArcStartPoint)
+distCE = model.distancePointPoint(anArcCentr, anArcEndPoint)
+assert (math.fabs(distCS - RADIUS) < 1.e-10)
+assert (math.fabs(distCE - RADIUS) < 1.e-10)
assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# 4. Move the centr or the point of the arc
#=========================================================================
assert (anCircleCentr.x() == -25)
assert (anCircleCentr.y() == -25)
-assert (aCircleRadius.value() == 25)
+assert (aCircleRadius.value() == RADIUS)
aSession.startOperation()
anCircleCentr.setValue(100., 100.)
aSession.finishOperation()
assert (anCircleCentr.x() == 100)
assert (anCircleCentr.y() == 100)
-assert (aCircleRadius.value() == 25)
+assert (aCircleRadius.value() == RADIUS)
assert (model.dof(aSketchFeature) == 6)
#=========================================================================
# End of test
__updated__ = "2015-03-17"
-def distancePointPoint(thePoint1, thePoint2):
- """
- subroutine to calculate distance between two points
- result of calculated distance is has 10**-5 precision
- """
- aDist = math.sqrt((thePoint1.x()-thePoint2.x())**2 + (thePoint1.y()-thePoint2.y())**2)
- return round(aDist, 5)
-
def distancePointLine(point, line):
"""
subroutine to calculate distance between point and line
subroutine to check that the line is tangent to arc/circle
"""
if (theArc.getKind() == "SketchCircle"):
- aCenter = geomDataAPI_Point2D(theArc.attribute("CircleCenter"))
- aRadius = theArc.real("CircleRadius").value()
+ aCenter = geomDataAPI_Point2D(theArc.attribute("circle_center"))
+ aRadius = theArc.real("circle_radius").value()
else:
- aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
- aStartPnt = geomDataAPI_Point2D(theArc.attribute("ArcStartPoint"))
- aRadius = distancePointPoint(aStartPnt, aCenter)
+ aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
+ aStartPnt = geomDataAPI_Point2D(theArc.attribute("start_point"))
+ aRadius = model.distancePointPoint(aStartPnt, aCenter)
aDist = distancePointLine(aCenter, theLine)
assert math.fabs(aDist - aRadius) < 2.e-5, "aDist = {0}, aRadius = {1}".format(aDist, aRadius)
aRadii = []
for anArc in anArcs:
if (anArc.getKind() == "SketchCircle"):
- aCenter = geomDataAPI_Point2D(anArc.attribute("CircleCenter"))
- aRadius = anArc.real("CircleRadius").value()
+ aCenter = geomDataAPI_Point2D(anArc.attribute("circle_center"))
+ aRadius = anArc.real("circle_radius").value()
else:
- aCenter = geomDataAPI_Point2D(anArc.attribute("ArcCenter"))
- aStartPnt = geomDataAPI_Point2D(anArc.attribute("ArcStartPoint"))
- aRadius = distancePointPoint(aStartPnt, aCenter)
+ aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
+ aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
+ aRadius = model.distancePointPoint(aStartPnt, aCenter)
aCenters.append(aCenter)
aRadii.append(aRadius)
- aDist = distancePointPoint(aCenters[0], aCenters[1])
+ aDist = model.distancePointPoint(aCenters[0], aCenters[1])
aRSum = aRadii[0] + aRadii[1]
aRDiff = math.fabs(aRadii[0] - aRadii[1])
assert math.fabs(aDist - aRSum) < 2.e-5 or math.fabs(aDist - aRDiff) < 2.e-5, "aDist = {0}, aRSum = {1}, aRDiff = {2}".format(aDist, aRSum, aRDiff)
# Arc
aSession.startOperation()
aSketchArc1 = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc1.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc1.attribute("center_point"))
anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("start_point"))
anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("end_point"))
anArcEndPoint.setValue(50., 0.)
aSession.finishOperation()
# Line 1
# Arc 1
aSession.startOperation()
aSketchArc1 = aSketchFeature.addFeature("SketchArc")
-anArc1Centr = geomDataAPI_Point2D(aSketchArc1.attribute("ArcCenter"))
+anArc1Centr = geomDataAPI_Point2D(aSketchArc1.attribute("center_point"))
anArc1Centr.setValue(10., 10.)
-anArc1StartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcStartPoint"))
+anArc1StartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("start_point"))
anArc1StartPoint.setValue(50., 0.)
-anArc1EndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcEndPoint"))
+anArc1EndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("end_point"))
anArc1EndPoint.setValue(0., 50.)
aSession.finishOperation()
# Arc 2
aSession.startOperation()
-aSketchArc2 = aSketchFeature.addFeature("SketchArc")
-aSketchArc2.string("ArcType").setValue("ThreePoints")
-anArc2Centr = geomDataAPI_Point2D(aSketchArc2.attribute("ArcCenter"))
-anArc2StartPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcStartPoint"))
+aSketchArc2 = aSketchFeature.addFeature("SketchMacroArc")
+aSketchArc2.string("arc_type").setValue("by_three_points")
+anArc2StartPoint = geomDataAPI_Point2D(aSketchArc2.attribute("start_point_2"))
anArc2StartPoint.setValue(0., 50.)
-anArc2EndPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcEndPoint"))
+anArc2EndPoint = geomDataAPI_Point2D(aSketchArc2.attribute("end_point_2"))
anArc2EndPoint.setValue(-50., 0.)
-anArc2PassedPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcPassedPoint"))
+anArc2PassedPoint = geomDataAPI_Point2D(aSketchArc2.attribute("passed_point"))
anArc2PassedPoint.setValue(-40., 40.)
aSession.finishOperation()
assert (model.dof(aSketchFeature) == 17)
+aSketchArc2 = model.lastSubFeature(aSketchFeature, "SketchArc")
+anArc2Centr = geomDataAPI_Point2D(aSketchArc2.attribute("center_point"))
+anArc2StartPoint = geomDataAPI_Point2D(aSketchArc2.attribute("start_point"))
#=========================================================================
# Link points of arcs by the coincidence constraint
#=========================================================================
# 3.2 tangency between non-connected arcs
aSession.startOperation()
aSketchArc3 = aSketchFeature.addFeature("SketchArc")
-anArc3Centr = geomDataAPI_Point2D(aSketchArc3.attribute("ArcCenter"))
+anArc3Centr = geomDataAPI_Point2D(aSketchArc3.attribute("center_point"))
anArc3Centr.setValue(100., -10.)
-anArc3StartPoint = geomDataAPI_Point2D(aSketchArc3.attribute("ArcStartPoint"))
+anArc3StartPoint = geomDataAPI_Point2D(aSketchArc3.attribute("start_point"))
anArc3StartPoint.setValue(70., -10.)
-anArc3EndPoint = geomDataAPI_Point2D(aSketchArc3.attribute("ArcEndPoint"))
+anArc3EndPoint = geomDataAPI_Point2D(aSketchArc3.attribute("end_point"))
anArc3EndPoint.setValue(100., 20.)
aSession.finishOperation()
assert (model.dof(aSketchFeature) == 19)
# 3.3 tangency between arc and circle
aSession.startOperation()
aCircle1 = aSketchFeature.addFeature("SketchCircle")
-aCircleCenter = geomDataAPI_Point2D(aCircle1.attribute("CircleCenter"))
-aCircleRadius = aCircle1.real("CircleRadius")
+aCircleCenter = geomDataAPI_Point2D(aCircle1.attribute("circle_center"))
+aCircleRadius = aCircle1.real("circle_radius")
aCircleCenter.setValue(150., 100.)
aCircleRadius.setValue(50.)
aSession.finishOperation()
# 3.4 tangency between two circles
aSession.startOperation()
aCircle2 = aSketchFeature.addFeature("SketchCircle")
-aCircleCenter = geomDataAPI_Point2D(aCircle2.attribute("CircleCenter"))
-aCircleRadius = aCircle2.real("CircleRadius")
+aCircleCenter = geomDataAPI_Point2D(aCircle2.attribute("circle_center"))
+aCircleRadius = aCircle2.real("circle_radius")
aCircleCenter.setValue(120., 70.)
aCircleRadius.setValue(20.)
aSession.finishOperation()
# TEST 4. Creating of tangency arc by the option of the SketchArc feature
#=========================================================================
aSession.startOperation()
-aSketchArc3 = aSketchFeature.addFeature("SketchArc")
-aSketchArc3.string("ArcType").setValue("Tangent")
-anArc3Start = aSketchArc3.refattr("ArcTangentPoint")
+aSketchArc3 = aSketchFeature.addFeature("SketchMacroArc")
+aSketchArc3.string("arc_type").setValue("by_tangent_edge")
+anArc3Start = aSketchArc3.refattr("tangent_point")
anArc3Start.setAttr(anArc1StartPoint)
-anArc3EndPoint = geomDataAPI_Point2D(aSketchArc3.attribute("ArcEndPoint"))
+anArc3EndPoint = geomDataAPI_Point2D(aSketchArc3.attribute("end_point_3"))
anArc3EndPoint.setValue(anArc1StartPoint.x()-5, anArc1StartPoint.y()-30)
aSession.finishOperation()
+aSketchArc3 = model.lastSubFeature(aSketchFeature, "SketchArc")
checkArcArcTangency(aSketchArc1, aSketchArc3)
# freeze radius of tangent arc
aSession.startOperation()
aLineStart.setValue(100., 100.)
aLineEnd.setValue(200., 200.)
aCircle = aSketchFeature.addFeature("SketchCircle")
-aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("CircleCenter"))
-aCircleRadius = aCircle.real("CircleRadius")
+aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
+aCircleRadius = aCircle.real("circle_radius")
aCircleCenter.setValue(150., 100.)
aCircleRadius.setValue(20.)
aSession.finishOperation()
--- /dev/null
+"""
+ TestCreateArc.py
+
+ static const std::string MY_SKETCH_ARC_ID("SketchArc");
+ static const std::string MY_CENTER_ID = "center_point";
+ static const std::string MY_START_ID = "start_point";
+ static const std::string MY_END_ID = "end_point";
+ data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D::typeId());
+"""
+
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from GeomDataAPI import *
+from ModelAPI import *
+import math
+from salome.shaper import model
+
+__updated__ = "2017-03-28"
+
+TOLERANCE = 1.e-7
+
+#=========================================================================
+# Auxiliary functions
+#=========================================================================
+
+def verifyLastArc(theSketch, theCenter, theStart, theEnd):
+ """
+ subroutine to verify position of last arc in the sketch
+ """
+ aLastArc = model.lastSubFeature(theSketch, "SketchArc")
+ aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
+ aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point"))
+ aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point"))
+ if len(theCenter):
+ verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1])
+ if len(theStart):
+ verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
+ if len(theEnd):
+ verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
+ aRadius = aLastArc.real("radius")
+ aDistCS = model.distancePointPoint(aCenterPnt, aStartPnt)
+ aDistCE = model.distancePointPoint(aCenterPnt, aEndPnt)
+ assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
+ assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong radius {0}, expected {1}".format(aRadius.value(), aDistCS)
+
+def verifyPointCoordinates(thePoint, theX, theY):
+ 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)
+
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSession.finishOperation()
+
+#=========================================================================
+# Test 1. Create an arc by center, start and end points
+#=========================================================================
+aCenter = [10., 10.]
+aStart = [0., 50.]
+aEnd = [50., 0.]
+aSession.startOperation()
+aSketchArc = aSketchFeature.addFeature("SketchArc")
+assert (aSketchArc.getKind() == "SketchArc")
+anArcCenter = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
+assert (not anArcCenter.isInitialized())
+anArcCenter.setValue(aCenter[0], aCenter[1])
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
+assert (not anArcStartPoint.isInitialized())
+anArcStartPoint.setValue(aStart[0], aStart[1])
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
+assert (not anArcEndPoint.isInitialized())
+anArcEndPoint.setValue(aEnd[0], aEnd[1])
+aSession.finishOperation()
+verifyLastArc(aSketchFeature, aCenter, aStart, aEnd)
+# Move center
+aCenter = [15., 20.]
+aSession.startOperation()
+anArcCenter.setValue(aCenter[0], aCenter[1])
+aSession.finishOperation()
+verifyLastArc(aSketchFeature, aCenter, [], [])
+# Move start point
+deltaX, deltaY = 5., 2.
+aStart = [anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY]
+aSession.startOperation()
+anArcStartPoint.setValue(aStart[0], aStart[1])
+aSession.finishOperation()
+verifyLastArc(aSketchFeature, [], aStart, [])
+# Move end point
+aEnd = [anArcEndPoint.x() - deltaX, anArcEndPoint.y() - deltaY]
+aSession.startOperation()
+anArcEndPoint.setValue(aEnd[0], aEnd[1])
+aSession.finishOperation()
+verifyLastArc(aSketchFeature, [], [], aEnd)
+# Check that changing the radius does not affect arc
+aSession.startOperation()
+anArcRadius = aSketchArc.real("radius")
+aPrevRadius = anArcRadius.value();
+anArcRadius.setValue(aPrevRadius + 10.)
+aSession.finishOperation()
+assert (math.fabs(anArcRadius.value - aPrevRadius) < TOLERANCE)
+verifyLastArc(aSketchFeature, [], [], [])
+# Check that changing the angle does not affect arc
+aSession.startOperation()
+anArcAngle = aSketchArc.real("angle")
+aPrevAngle = anArcAngle.value()
+anArcAngle.setValue(aPrevAngle + 10.)
+aSession.finishOperation()
+assert (math.fabs(anArcAngle.value - aPrevAngle) < TOLERANCE)
+verifyLastArc(aSketchFeature, [], [], [])
+
+#=========================================================================
+# End of test
+#=========================================================================
+
+assert(model.checkPythonDump())
#=========================================================================
TOLERANCE = 1.e-7
-def getLastCircle(theSketch):
- """
- obtains last feature from the sketch and generates error if the feature is not a circle
- """
- expectedKind = "SketchCircle"
- for anIndex in range(theSketch.numberOfSubs() - 1, -1, -1):
- aSub = theSketch.subFeature(anIndex)
- if (aSub.getKind() == expectedKind):
- return aSub
-
def verifyLastCircle(theSketch, theX, theY, theR):
"""
subroutine to verify position of last circle in the sketch
"""
- aLastCircle = getLastCircle(theSketch)
+ aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
verifyPointCoordinates(aCenter, theX, theY)
aRadius = aLastCircle.real("circle_radius")
assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
def verifyPointCoordinates(thePoint, theX, theY):
- assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
+ 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)
def verifyPointOnLine(thePoint, theLine):
aDistance = distancePointLine(thePoint, theLine)
def verifyTangentCircles(theCircle1, theCircle2):
aCenter1 = geomDataAPI_Point2D(theCircle1.attribute("circle_center"))
aCenter2 = geomDataAPI_Point2D(theCircle2.attribute("circle_center"))
- aDistCC = distancePointPoint(aCenter1, aCenter2)
+ aDistCC = model.distancePointPoint(aCenter1, aCenter2)
aRadius1 = theCircle1.real("circle_radius").value()
aRadius2 = theCircle2.real("circle_radius").value()
aRSum = aRadius1 + aRadius2
aRDiff = math.fabs(aRadius1 - aRadius2)
assert math.fabs(aRSum - aDistCC) < TOLERANCE or math.fabs(aRDiff - aDistCC) < TOLERANCE, "Circles do not tangent"
-def distancePointPoint(thePoint1, thePoint2):
- return thePoint1.pnt().distance(thePoint2.pnt())
-
def distancePointLine(thePoint, theLine):
aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
aCircleType.setValue("circle_type_by_center_and_passed_points")
aCircleCenter.setValue(-25., -25)
aCirclePassed.setValue(0., -25.)
-aRadius = distancePointPoint(aCircleCenter, aCirclePassed)
+aRadius = model.distancePointPoint(aCircleCenter, aCirclePassed)
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 2)
verifyLastCircle(aSketchFeature, -25., -25., aRadius)
# Test 3. Create a circle as a macro-feature by center and passed point coincident to other points
#=========================================================================
# get previous circle
-aPrevCircle = getLastCircle(aSketchFeature)
+aPrevCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
aPrevCenter = geomDataAPI_Point2D(aPrevCircle.attribute("circle_center"))
# create additional point
aPointCoodinates = [0., 0.]
aCenter.setValue(aPointCoord.pnt())
aPassedRef.setAttr(aPrevCenter)
aPassed.setValue(aPrevCenter.pnt())
-aRadius = distancePointPoint(aPrevCenter, aPointCoord)
+aRadius = model.distancePointPoint(aPrevCenter, aPointCoord)
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 6)
verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1])
# Test 4. Create a circle as a macro-feature by center on a line and passed point on another circle
#=========================================================================
# get previous circle
-aPrevCircle = getLastCircle(aSketchFeature)
+aPrevCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
aPrevCenter = geomDataAPI_Point2D(aPrevCircle.attribute("circle_center"))
aPrevCenterXY = [aPrevCenter.x(), aPrevCenter.y()]
aPrevRadius = aPrevCircle.real("circle_radius").value()
aCenter.setValue(anExpectedCenter[0], anExpectedCenter[1])
aPassedRef.setObject(aPrevCircle.lastResult())
aPassed.setValue(aPrevCenter.x() + aPrevRadius, aPrevCenter.y())
-aRadius = distancePointPoint(aCenter, aPassed)
+aRadius = model.distancePointPoint(aCenter, aPassed)
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 10)
# check connected features do not change their positions
verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
verifyPointCoordinates(aEndPnt, aLineEnd[0], aLineEnd[1])
# verify newly created circle
-aCircle = getLastCircle(aSketchFeature)
+aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
verifyPointCoordinates(aCenter, anExpectedCenter[0], anExpectedCenter[1])
verifyPointOnLine(aCenter, aLine)
#=========================================================================
TOLERANCE = 1.e-7
-def getLastCircle(theSketch):
- """
- obtains last feature from the sketch and generates error if the feature is not a circle
- """
- expectedKind = "SketchCircle"
- for anIndex in range(theSketch.numberOfSubs() - 1, -1, -1):
- aSub = theSketch.subFeature(anIndex)
- if (aSub.getKind() == expectedKind):
- return aSub
-
def verifyLastCircle(theSketch, theX, theY, theR):
"""
subroutine to verify position of last circle in the sketch
"""
- aLastCircle = getLastCircle(theSketch)
+ aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
verifyPointCoordinates(aCenter, theX, theY)
aRadius = aLastCircle.real("circle_radius")
def verifyPointOnCircle(thePoint, theCircle):
aCircleCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
- aDistCP = distancePointPoint(aCircleCenter, thePoint)
+ aDistCP = model.distancePointPoint(aCircleCenter, thePoint)
aCircleRadius = theCircle.real("circle_radius").value()
assert math.fabs(aDistCP - aCircleRadius) < TOLERANCE, "Point is not on circle, distance: {0}, radius of circle: {1}".format(aDistCP, aCircleRadius)
def verifyTangentCircles(theCircle1, theCircle2):
aCenter1 = geomDataAPI_Point2D(theCircle1.attribute("circle_center"))
aCenter2 = geomDataAPI_Point2D(theCircle2.attribute("circle_center"))
- aDistCC = distancePointPoint(aCenter1, aCenter2)
+ aDistCC = model.distancePointPoint(aCenter1, aCenter2)
aRadius1 = theCircle1.real("circle_radius").value()
aRadius2 = theCircle2.real("circle_radius").value()
verifyTangentCircular(aDistCC, aRadius1, aRadius2)
aCircleCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
anArcCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
anArcStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
- aDistCC = distancePointPoint(aCircleCenter, anArcCenter)
+ aDistCC = model.distancePointPoint(aCircleCenter, anArcCenter)
aCircleRadius = theCircle.real("circle_radius").value()
- anArcRadius = distancePointPoint(anArcCenter, anArcStart)
+ anArcRadius = model.distancePointPoint(anArcCenter, anArcStart)
verifyTangentCircular(aDistCC, aCircleRadius, anArcRadius)
def verifyTangentCircular(theDistBetweenCenters, theRadius1, theRadius2):
aDistCL = distancePointLine(aCenter, theLine)
assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent"
-def distancePointPoint(thePoint1, thePoint2):
- return thePoint1.pnt().distance(thePoint2.pnt())
-
def distancePointLine(thePoint, theLine):
aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
# Test 2. Create a circle by three points coincident to other points
#=========================================================================
# get previous circle
-aPrevCircle = getLastCircle(aSketchFeature)
+aPrevCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
aPrevCenter = geomDataAPI_Point2D(aPrevCircle.attribute("circle_center"))
aPrevCenterXY = [aPrevCenter.x(), aPrevCenter.y()]
aPrevCircleRadius = aPrevCircle.real("circle_radius").value()
verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1])
verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
# check newly created circle passes through the points
-aCircle = getLastCircle(aSketchFeature)
+aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
verifyPointOnCircle(aPrevCenter, aCircle)
verifyPointOnCircle(aPointCoord, aCircle)
verifyPointOnCircle(aStartPnt, aCircle)
verifyPointCoordinates(anArcStartPnt, anArcStart[0], anArcStart[1])
verifyPointCoordinates(anArcEndPnt, anArcEnd[0], anArcEnd[1])
# check newly created circle passes through the points
-aCircle = getLastCircle(aSketchFeature)
+aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
verifyTangentCircles(aCircle, aPrevCircle)
verifyTangentCircleArc(aCircle, anArc)
verifyTangentCircleLine(aCircle, aLine)
assert (not aSecondPointRef.isInitialized())
assert (not aThirdPointRef.isInitialized())
-def getLastCircle(theSketch):
- """
- obtains last feature from the sketch and generates error if the feature is not a circle
- """
- expectedKind = "SketchCircle"
- for anIndex in range(theSketch.numberOfSubs() - 1, -1, -1):
- aSub = theSketch.subFeature(anIndex)
- if (aSub.getKind() == expectedKind):
- return aSub
-
def verifyLastCircle(theSketch, theX, theY, theR):
"""
subroutine to verify position of last circle in the sketch
"""
- aLastCircle = getLastCircle(theSketch)
+ aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
verifyPointCoordinates(aCenter, theX, theY)
aRadius = aLastCircle.real("circle_radius")
def verifyPointCoordinates(thePoint, theX, theY):
assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
-def distancePointPoint(thePoint1, thePoint2):
- return thePoint1.pnt().distance(thePoint2.pnt())
-
#=========================================================================
# Start of test
aPassedPoint.setValue(aLineEnd.pnt())
aSession.finishOperation()
-aRadius = distancePointPoint(aLineStart, aLineEnd)
+aRadius = model.distancePointPoint(aLineStart, aLineEnd)
NB_FEATURES_EXPECTED = 4 # line, circle and two coincidences
assert (aSketchFeature.numberOfSubs() == NB_FEATURES_EXPECTED), "Number of features in sketch {}, expected {}".format(aSketchFeature.numberOfSubs(), NB_FEATURES_EXPECTED)
verifyLastCircle(aSketchFeature, aLineStart.x(), aLineStart.y(), aRadius)
allFeatures.append(aSketchLine)
# Arc
aSketchArc = theSketch.addFeature("SketchArc")
- aStartPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
- aEndPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
- aCenterPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+ aStartPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
+ aEndPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
+ aCenterPoint = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
aCenterPoint.setValue(20., 10.)
aStartPoint2.setValue(10., 10.)
aEndPoint2.setValue(20., 0.)
checkArcLineSmoothness(aConnectedFeatures[1], aConnectedFeatures[0])
def checkArcLineSmoothness(theArc, theLine):
- aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
+ aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
aDistance = distancePointLine(aCenter, theLine)
aRadius = arcRadius(theArc)
assert(math.fabs(aRadius - aDistance) < TOLERANCE)
def checkArcArcSmoothness(theArc1, theArc2):
- aCenter1 = geomDataAPI_Point2D(theArc1.attribute("ArcCenter"))
- aCenter2 = geomDataAPI_Point2D(theArc2.attribute("ArcCenter"))
- aDistance = distancePointPoint(aCenter1, aCenter2)
+ aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point"))
+ aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point"))
+ aDistance = model.distancePointPoint(aCenter1, aCenter2)
aRadius1 = arcRadius(theArc1)
aRadius2 = arcRadius(theArc2)
aRadSum = aRadius1 + aRadius2
return [aFeatureA, aFeatureB]
def arcRadius(theArc):
- aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
- aStart = geomDataAPI_Point2D(theArc.attribute("ArcStartPoint"))
- return distancePointPoint(aCenter, aStart)
-
-def distancePointPoint(thePoint1, thePoint2):
- return math.hypot(thePoint1.x() - thePoint2.x(), thePoint1.y() - thePoint2.y())
+ aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
+ aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
+ return model.distancePointPoint(aCenter, aStart)
def distancePointLine(thePoint, theLine):
aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint"))
aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint"))
- aLength = distancePointPoint(aLineStart, aLineEnd)
+ aLength = model.distancePointPoint(aLineStart, aLineEnd)
aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y()
aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y()
__updated__ = "2017-03-06"
def isArcLineSmooth(theArc, theLine, theTolerance):
- aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
+ aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
aDistance = distancePointLine(aCenter, theLine)
aRadius = arcRadius(theArc)
return math.fabs(aRadius - aDistance) < theTolerance
def isArcArcSmooth(theArc1, theArc2, theTolerance):
- aCenter1 = geomDataAPI_Point2D(theArc1.attribute("ArcCenter"))
- aCenter2 = geomDataAPI_Point2D(theArc2.attribute("ArcCenter"))
- aDistance = distancePointPoint(aCenter1, aCenter2)
+ aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point"))
+ aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point"))
+ aDistance = model.distancePointPoint(aCenter1, aCenter2)
aRadius1 = arcRadius(theArc1)
aRadius2 = arcRadius(theArc2)
aRadSum = aRadius1 + aRadius2
return math.fabs(aDistance - aRadSum) < theTolerance or math.fabs(aDistance - aRadDiff) < theTolerance
def arcRadius(theArc):
- aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
- aStart = geomDataAPI_Point2D(theArc.attribute("ArcStartPoint"))
- return distancePointPoint(aCenter, aStart)
-
-def distancePointPoint(thePoint1, thePoint2):
- return math.hypot(thePoint1.x() - thePoint2.x(), thePoint1.y() - thePoint2.y())
+ aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
+ aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
+ return model.distancePointPoint(aCenter, aStart)
def distancePointLine(thePoint, theLine):
aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint"))
aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint"))
- aLength = distancePointPoint(aLineStart, aLineEnd)
+ aLength = model.distancePointPoint(aLineStart, aLineEnd)
aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y()
aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y()
aCross = aDir1x * aDir2y - aDir1y * aDir2x
--- /dev/null
+"""
+ TestConstraintMirror.py
+ Unit test of SketchPlugin_ConstraintMirror class
+
+ SketchPlugin_ConstraintMirror
+ static const std::string MY_CONSTRAINT_MIRROR_ID("SketchConstraintMirror");
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefListAttr::typeId());
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefListAttr::typeId());
+
+"""
+from GeomDataAPI import *
+from ModelAPI import *
+import math
+from salome.shaper import model
+
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+__updated__ = "2015-03-17"
+
+#=========================================================================
+# Auxiliary functions
+#=========================================================================
+def normalize(theDir):
+ aLen = math.hypot(theDir[0], theDir[1])
+ if aLen < 1.e-10:
+ aLen = 1.0
+ return [theDir[0] / aLen, theDir[1] / aLen]
+
+def checkMirror(theListInit, theListMirr, theMirrorLine):
+ TOL = 6.e-5
+ aListSize = theListInit.size()
+
+ aLineStartPoint = geomDataAPI_Point2D(theMirrorLine.attribute("StartPoint"))
+ aLineEndPoint = geomDataAPI_Point2D(theMirrorLine.attribute("EndPoint"))
+ aLineDir = [aLineEndPoint.x() - aLineStartPoint.x(), aLineEndPoint.y() - aLineStartPoint.y()]
+ aLineDir = normalize(aLineDir)
+
+ for ind in range(0, aListSize):
+ aFeatureB = ModelAPI_Feature.feature(theListInit.object(ind))
+ aFeatureC = ModelAPI_Feature.feature(theListMirr.object(ind))
+ assert(aFeatureB is not None)
+ assert(aFeatureC is not None)
+ assert(aFeatureB.getKind() == aFeatureC.getKind())
+
+ anAttributes = []
+ if (aFeatureB.getKind() == "SketchLine"):
+ anAttributes = ['StartPoint', 'EndPoint']
+ elif (aFeatureB.getKind() == "SketchArc"):
+ anAttributes = ['center_point', 'start_point', 'end_point']
+
+ for key in anAttributes:
+ aPointB = geomDataAPI_Point2D(aFeatureB.attribute(key))
+ aPointC = geomDataAPI_Point2D(aFeatureC.attribute(key))
+ aDir = [aPointC.x() - aPointB.x(), aPointC.y() - aPointB.y()]
+ aDir = normalize(aDir)
+ aDot = aLineDir[0] * aDir[0] + aLineDir[1] * aDir[1]
+ assert math.fabs(aDot) < TOL, "aDot = {0}".format(aDot)
+ aDir[0] = aLineEndPoint.x() - 0.5 * (aPointB.x() + aPointC.x())
+ aDir[1] = aLineEndPoint.y() - 0.5 * (aPointB.y() + aPointC.y())
+ aCross = aLineDir[0] * aDir[1] - aLineDir[1] * aDir[0]
+ assert math.fabs(aCross) < TOL, "aCross = {0}".format(aCross)
+
+
+#=========================================================================
+# Start of test
+#=========================================================================
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSession.finishOperation()
+#=========================================================================
+# Creation of an arc and two lines
+#=========================================================================
+# Arc
+aSession.startOperation()
+aSketchArc1 = aSketchFeature.addFeature("SketchArc")
+anArcCentr = geomDataAPI_Point2D(aSketchArc1.attribute("center_point"))
+anArcCentr.setValue(10., 10.)
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("start_point"))
+anArcStartPoint.setValue(0., 50.)
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("end_point"))
+anArcEndPoint.setValue(50., 0.)
+aSession.finishOperation()
+# Line 1
+aSession.startOperation()
+aSketchLine1 = aSketchFeature.addFeature("SketchLine")
+aLine1StartPoint = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint"))
+aLine1EndPoint = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint"))
+aLine1StartPoint.setValue(0., 50.)
+aLine1EndPoint.setValue(0., 100.)
+aSession.finishOperation()
+# Line 2
+aSession.startOperation()
+aSketchLine2 = aSketchFeature.addFeature("SketchLine")
+aLine2StartPoint = geomDataAPI_Point2D(aSketchLine2.attribute("StartPoint"))
+aLine2EndPoint = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint"))
+aLine2StartPoint.setValue(50., 0.)
+aLine2EndPoint.setValue(100., 0.)
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 13)
+#=========================================================================
+# Link arc points and lines points by the coincidence constraint
+#=========================================================================
+aSession.startOperation()
+aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
+reflistA.setAttr(anArcStartPoint)
+reflistB.setAttr(aLine1StartPoint)
+aConstraint.execute()
+aSession.finishOperation()
+aSession.startOperation()
+aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
+reflistA.setAttr(anArcEndPoint)
+reflistB.setAttr(aLine2StartPoint)
+aConstraint.execute()
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 9)
+#=========================================================================
+# Add tangency constraint and check correctness
+#=========================================================================
+aSession.startOperation()
+aTangency = aSketchFeature.addFeature("SketchConstraintTangent")
+aRefObjectA = aTangency.refattr("ConstraintEntityA")
+aRefObjectB = aTangency.refattr("ConstraintEntityB")
+anObjectA = modelAPI_ResultConstruction(aSketchArc1.lastResult())
+anObjectB = modelAPI_ResultConstruction(aSketchLine1.lastResult())
+assert (anObjectA is not None)
+assert (anObjectB is not None)
+aRefObjectA.setObject(anObjectA)
+aRefObjectB.setObject(anObjectB)
+aTangency.execute()
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
+#=========================================================================
+# Create mirror line
+#=========================================================================
+aSession.startOperation()
+aMirrorLine = aSketchFeature.addFeature("SketchLine")
+aLineStartPoint = geomDataAPI_Point2D(aMirrorLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aMirrorLine.attribute("EndPoint"))
+aLineStartPoint.setValue(100., 0.)
+aLineEndPoint.setValue(100., 100.)
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 12)
+#=========================================================================
+# Make mirror for objects created above
+#=========================================================================
+aSession.startOperation()
+aMirror = aSketchFeature.addFeature("SketchConstraintMirror")
+aRefObjectA = aMirror.refattr("ConstraintEntityA")
+aRefObjectA.setObject(modelAPI_ResultConstruction(aMirrorLine.firstResult()))
+aRefListInitial = aMirror.reflist("ConstraintMirrorList")
+aRefListInitial.append(aSketchLine1.lastResult())
+aRefListInitial.append(aSketchArc1.lastResult())
+aRefListInitial.append(aSketchLine2.lastResult())
+aMirror.execute()
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 12)
+#=========================================================================
+# Verify the simmetricity of all mirrored objects
+#=========================================================================
+aRefListB = aMirror.reflist("ConstraintEntityB")
+aRefListC = aMirror.reflist("ConstraintEntityC")
+assert (aRefListB.size() == 3)
+assert (aRefListC.size() == 3)
+checkMirror(aRefListB, aRefListC, aMirrorLine)
+assert (model.dof(aSketchFeature) == 12)
+
+#=========================================================================
+# Remove object from mirror
+#=========================================================================
+aSession.startOperation()
+aRefListInitial.remove(aSketchLine2.lastResult())
+aSession.finishOperation()
+assert (aRefListB.size() == 2)
+assert (aRefListC.size() == 2)
+checkMirror(aRefListB, aRefListC, aMirrorLine)
+assert (model.dof(aSketchFeature) == 12)
+
+#=========================================================================
+# Clear list of mirrored features
+#=========================================================================
+aSession.startOperation()
+aRefListInitial.clear()
+assert (aRefListB.size() == 0)
+assert (aRefListC.size() == 0)
+# add arc once again
+aRefListInitial.append(aSketchArc1.lastResult())
+aSession.finishOperation()
+assert (aRefListB.size() == 1)
+assert (aRefListC.size() == 1)
+checkMirror(aRefListB, aRefListC, aMirrorLine)
+assert (model.dof(aSketchFeature) == 12)
+#=========================================================================
+# End of test
+#=========================================================================
+
+assert(model.checkPythonDump())
allFeatures = []
# Create arc
aSketchArc = theSketch.addFeature("SketchArc")
- aCenter = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
- aStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
- aEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+ aCenter = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
+ aStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
+ aEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
aCenter.setValue(5., 5.)
aStartPoint.setValue(10., 5.)
aEndPoint.setValue(5., 10.)
anAttributes.append('StartPoint')
anAttributes.append('EndPoint')
elif (feat.getKind() == "SketchArc"):
- anAttributes.append('ArcCenter')
- anAttributes.append('ArcStartPoint')
- anAttributes.append('ArcEndPoint')
+ anAttributes.append('center_point')
+ anAttributes.append('start_point')
+ anAttributes.append('end_point')
for attr in anAttributes:
aPoint1 = geomDataAPI_Point2D(feat.attribute(attr))
allFeatures = []
# Create arc
aSketchArc = theSketch.addFeature("SketchArc")
- aCenter = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
- aStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
- aEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+ aCenter = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
+ aStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
+ aEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
aCenter.setValue(5., 5.)
aStartPoint.setValue(10., 5.)
aEndPoint.setValue(5., 10.)
anAttributes.append('StartPoint')
anAttributes.append('EndPoint')
elif (feat.getKind() == "SketchArc"):
- anAttributes.append('ArcCenter')
- anAttributes.append('ArcStartPoint')
- anAttributes.append('ArcEndPoint')
+ anAttributes.append('center_point')
+ anAttributes.append('start_point')
+ anAttributes.append('end_point')
for attr in anAttributes:
aPoint1 = geomDataAPI_Point2D(feat.attribute(attr))
aLineEnd.setValue(40., 30.)
aCircle = aSketchFeature.addFeature("SketchCircle")
-aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("CircleCenter"))
-aCircleRadius = aCircle.real("CircleRadius")
+aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
+aCircleRadius = aCircle.real("circle_radius")
aCircleCenter.setValue(-25., -25)
aCircleRadius.setValue(25.)
anArc = aSketchFeature.addFeature("SketchArc")
-anArcCenter = geomDataAPI_Point2D(anArc.attribute("ArcCenter"))
-anArcStart = geomDataAPI_Point2D(anArc.attribute("ArcStartPoint"))
-anArcEnd = geomDataAPI_Point2D(anArc.attribute("ArcEndPoint"))
+anArcCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
+anArcStart = geomDataAPI_Point2D(anArc.attribute("start_point"))
+anArcEnd = geomDataAPI_Point2D(anArc.attribute("end_point"))
anArcCenter.setValue(10., 10.)
anArcStart.setValue(50., 0.)
anArcEnd.setValue(0., 50.)
aProjCircle = ModelAPI_Feature.feature(aCircleProjector.refattr("ProjectedFeature").object())
assert(aProjCircle)
-aProjCircleCenter = geomDataAPI_Point2D(aProjCircle.attribute("CircleCenter"))
-aProjCircleRadius = aProjCircle.real("CircleRadius")
+aProjCircleCenter = geomDataAPI_Point2D(aProjCircle.attribute("circle_center"))
+aProjCircleRadius = aProjCircle.real("circle_radius")
assert(math.fabs(aProjCircleCenter.x() - aCircleCenter.x()) < 1.e-10)
assert(math.fabs(aProjCircleCenter.y() - aCircleCenter.y()) < 1.e-10)
assert(math.fabs(aProjCircleRadius.value() - aCircleRadius.value()) < 1.e-10)
aProjArc = ModelAPI_Feature.feature(anArcProjector.refattr("ProjectedFeature").object())
-aProjArcCenter = geomDataAPI_Point2D(aProjArc.attribute("ArcCenter"))
-aProjArcStart = geomDataAPI_Point2D(aProjArc.attribute("ArcStartPoint"))
-aProjArcEnd = geomDataAPI_Point2D(aProjArc.attribute("ArcEndPoint"))
+aProjArcCenter = geomDataAPI_Point2D(aProjArc.attribute("center_point"))
+aProjArcStart = geomDataAPI_Point2D(aProjArc.attribute("start_point"))
+aProjArcEnd = geomDataAPI_Point2D(aProjArc.attribute("end_point"))
assert(math.fabs(aProjArcCenter.x() - anArcCenter.x()) < 1.e-10)
assert(math.fabs(aProjArcCenter.y() - anArcCenter.y()) < 1.e-10)
assert(math.fabs(aProjArcStart.x() - anArcStart.x()) < 1.e-10)