TestSketcherSetPerpendicular.py
TestSketcherSetHorizontal.py
TestSketcherSetVertical.py
+ TestSketcherSetLength.py
TestSketcherSetRadius.py
TestSketcherSetAngle.py
+ TestSketcherSetEqual.py
)
--- /dev/null
+import unittest
+import model
+import math
+import TestSketcher
+from TestSketcher import SketcherTestCase
+
+class SketcherSetEqual(SketcherTestCase):
+ def test_length_equality(self):
+ # Set the constraint
+ l1 = self.sketch.addLine(0, 0, 0, 1)
+ l2 = self.sketch.addLine(0, 0, 1, 1)
+ self.sketch.setEqual(l1.result(), l2.result())
+ # Commit the transaction
+ model.do()
+ # Check the result
+ length_1 = math.sqrt(
+ math.pow((l1.endPointData().x() - l1.startPointData().x()), 2) +
+ math.pow((l1.endPointData().y() - l1.startPointData().y()), 2)
+ )
+ length_2 = math.sqrt(
+ math.pow((l1.endPointData().x() - l1.startPointData().x()), 2) +
+ math.pow((l2.endPointData().y() - l2.startPointData().y()), 2)
+ )
+ self.assertAlmostEqual(length_1, length_2, delta=TestSketcher.DELTA)
+
+ def test_radius_equality(self):
+ # Set the constraint
+ circle_1 = self.sketch.addCircle(0, 0, 10.0)
+ circle_2 = self.sketch.addCircle(1, 2, 25.0)
+ self.sketch.setEqual(circle_1.result(), circle_2.result())
+ # Commit the transaction
+ model.do()
+ # Check the result
+ self.assertAlmostEqual(
+ circle_1.radiusData().value(),
+ circle_2.radiusData().value(),
+ delta=TestSketcher.DELTA
+ )
+
+if __name__ == "__main__":
+ suite = unittest.TestLoader().loadTestsFromTestCase(SketcherSetEqual)
+ unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
--- /dev/null
+import unittest
+import model
+import math
+import TestSketcher
+from TestSketcher import SketcherTestCase
+
+class SketcherSetLength(SketcherTestCase):
+ def runTest(self):
+ # Set the constraint
+ line = self.sketch.addLine(0, 0, 0, 1)
+ self.sketch.setLength(line.result(), 25.0)
+ # Commit the transaction
+ model.do()
+ # Check the result
+ length = math.sqrt(
+ math.pow((line.endPointData().x() - line.startPointData().x()), 2) +
+ math.pow((line.endPointData().y() - line.startPointData().y()), 2)
+ )
+ self.assertAlmostEqual(length, 25.0, delta=TestSketcher.DELTA)
+
+if __name__ == "__main__":
+ unittest.main()
\ No newline at end of file
self._feature.execute()
return constraint
+ def setRadius(self, circle, radius):
+ """Set the radius of the given circle and add the corresponding
+ constraint to this Sketch."""
+ constraint = self._feature.addFeature("SketchConstraintRadius")
+ constraint.data().refattr("ConstraintEntityA").setObject(circle)
+ constraint.data().real("ConstraintValue").setValue(radius)
+ return constraint
+
+ def setEqual(self, object_1, object_2):
+ """Set the radii of two circles or the length of two lines equal.
+
+ The corresponding constraint is added to the sketch"""
+ constraint = self._feature.addFeature("SketchConstraintEqual")
+ constraint.data().refattr("ConstraintEntityA").setObject(object_1)
+ constraint.data().refattr("ConstraintEntityB").setObject(object_2)
+ 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."""
self._feature.execute()
return constraint
- def setRadius(self, circle, radius):
- """Set the radius of the given circle and add the corresponding
- constraint to this Sketch."""
- constraint = self._feature.addFeature("SketchConstraintRadius")
- constraint.data().refattr("ConstraintEntityA").setObject(circle)
- constraint.data().real("ConstraintValue").setValue(radius)
- return constraint
-
#-------------------------------------------------------------
#
# Edition of Dimensional Constraints