--- /dev/null
+import unittest
+import model
+import math
+import TestSketcher
+from TestSketcher import SketcherTestCase
+
+class SketcherSetAngle(SketcherTestCase):
+ def runTest(self):
+ # Set the constraint
+ l1 = self.sketch.addLine(0, 0, 0, 1)
+ l2 = self.sketch.addLine(0, 0, 1, 1)
+ self.sketch.setAngle(l1.result(), l2.result(), 30.0)
+ # Commit the transaction
+ model.do()
+ # Check the result
+ dot_product = (l1.endPointData().x() - l1.startPointData().x()) * \
+ (l2.endPointData().x() - l2.startPointData().x()) + \
+ (l1.endPointData().y() - l1.startPointData().y()) * \
+ (l2.endPointData().y() - l2.startPointData().y())
+ norm_1 = math.sqrt(
+ math.pow((l1.endPointData().x() - l1.startPointData().x()), 2) +
+ math.pow((l1.endPointData().y() - l1.startPointData().y()), 2)
+ )
+ norm_2 = math.sqrt(
+ math.pow((l2.endPointData().x() - l2.startPointData().x()), 2) +
+ math.pow((l2.endPointData().y() - l2.startPointData().y()), 2)
+ )
+ angle = math.acos(dot_product / (norm_1 * norm_2))
+ self.assertAlmostEqual(
+ angle * 180 / math.pi, 30.0, delta=TestSketcher.DELTA
+ )
+
+if __name__ == "__main__":
+ unittest.main()
\ No newline at end of file
Copyright (C) 2014-20xx CEA/DEN, EDF R&D
"""
-from ModelAPI import modelAPI_ResultConstruction, featureToCompositeFeature
+from ModelAPI import modelAPI_ResultConstruction, featureToCompositeFeature
from GeomDataAPI import geomDataAPI_Point, geomDataAPI_Dir
from GeomAlgoAPI import GeomAlgoAPI_SketchBuilder
from model.sketcher.point import Point
A Sketch object is instanciated with a feature as input parameter
it provides an interface for manipulation of the feature data.
:return: interface on the feature
- :rtype: Sketch object"""
+ :rtype: Sketch"""
feature = featureToCompositeFeature(doc.addFeature("Sketch"))
return Sketch(feature, plane)
self.__sketchOnPlane(plane)
def __sketchOnPlane(self, plane):
- o = plane.location()
- d = plane.direction()
- dx = plane.xDirection()
+ """Create the sketch on a plane."""
+ origin = plane.location()
+ normal = plane.direction()
+ x_direction = plane.xDirection()
geomDataAPI_Point(
self._feature.data().attribute("Origin")
- ).setValue( o.x(), o.y(), o.z() )
+ ).setValue(origin.x(), origin.y(), origin.z())
geomDataAPI_Dir(
self._feature.data().attribute("DirX")
- ).setValue( dx.x(), dx.y(), dx.z() )
+ ).setValue(x_direction.x(), x_direction.y(), x_direction.z())
geomDataAPI_Dir(
self._feature.data().attribute("Norm")
- ).setValue( d.x(), d.y(), d.z() )
+ ).setValue(normal.x(), normal.y(), normal.z() )
- def __sketchOnFace(self, plane):
- self._feature.data().selection("External").selectSubShape("FACE", plane)
+ def __sketchOnFace(self, name):
+ """Initialize the sketch on a face given by its name."""
+ self._feature.data().selection("External").selectSubShape("FACE", name)
#-------------------------------------------------------------
#
def addLine(self, *args):
"""Add a line to this Sketch."""
line_feature = self._feature.addFeature("SketchLine")
- return Line(line_feature, *args)
+ line_interface = Line(line_feature, *args)
+ # if the line is created by name add a rigid constraint
+ # to the created line
+ if len(args) == 1 and isinstance(args[0], str):
+ constraint = sketch.addFeature("SketchConstraintRigid")
+ constraint.refattr("ConstraintEntityA").setObject(
+ line_feature.firstResult()
+ )
+ return line_interface
def addCircle(self, *args):
"""Add a circle to this Sketch."""
constraint.data().real("ConstraintValue").setValue(length)
self._feature.execute()
return constraint
+
+ def setAngle(self, line_1, line_2, angle):
+ """Set the angle between the given 2 lines and add the corresponding
+ constraint to the sketch."""
+ constraint = self._feature.addFeature("SketchConstraintAngle")
+ constraint.data().refattr("ConstraintEntityA").setObject(line_1)
+ constraint.data().refattr("ConstraintEntityB").setObject(line_2)
+ constraint.data().real("ConstraintValue").setValue(angle)
+ self._feature.execute()
+ return constraint
def setRadius(self, circle, radius):
"""Set the radius of the given circle and add the corresponding