--- /dev/null
+import unittest
+import model
+from TestSketcher import SketcherTestCase
+from GeomDataAPI import geomDataAPI_Point2D
+
+import logging
+
+class SketcherAddLine(SketcherTestCase):
+ def setUp(self):
+ SketcherTestCase.setUp(self)
+ self.line = self.sketch.addLine(0, 0, 0, 1)
+ self.circle_1 = self.sketch.addCircle(30, 0, 10)
+
+ def test_add_mirror(self):
+ mirror = self.sketch.addMirror(
+ self.line.result(), self.circle_1.result()
+ )
+ model.do()
+ mirrored_objects = mirror.mirroredObjects()
+ mirrored_circle = mirrored_objects.object(0)
+ center = geomDataAPI_Point2D(mirrored_circle.data().attribute("CircleCenter"))
+ self.assertTrue(False, msg="%s" % center.x())
+ #dir(mirrored_circle)
+ #center = geomDataAPI_Point2D(mirrored_circle.data().attribute("CircleCenter"))
+ #self.assertEqual(center.x(), -30, msg="%s"%(dir(mirrored_circle)))
+ #self.assertTrue(False, msg="%s" % (dir(mirrored_circle)))
+
+if __name__ == "__main__":
+ unittest.main(verbosity=2)
\ No newline at end of file
class Circle(Interface):
"""Interface for circle feature data manipulation."""
- def __init__(self, feature, x, y, radius):
+ def __init__(self, feature, *args):
Interface.__init__(self, feature)
assert(self._feature.getKind() == "SketchCircle")
self._feature.data().attribute("CircleCenter")
)
self._radius = self._feature.data().real("CircleRadius")
- self.setCenter(x, y)
- self.setRadius(radius)
+
+ if not args:
+ return
+
+ if len(args) != 3:
+ raise TypeError(
+ "Invalid number of arguments, 3 arguments needed (%s given)"
+ % len(args)
+ )
+
+ self.setCenter(args[0], args[1])
+ self.setRadius(args[2])
self.execute()
def setCenter(self, x, y):
--- /dev/null
+"""Sketch point feature interface."""
+
+from GeomDataAPI import geomDataAPI_Point2D
+from ModelAPI import ModelAPI_Feature
+from model.roots import Interface
+from model.errors import FeatureInputInvalid
+
+class Mirror(Interface):
+ """Interface on mirror constraint for data manipulation."""
+ def __init__(self, feature, mirror_line, *mirror_objects):
+ Interface.__init__(self, feature)
+ assert(self._feature.getKind() == "SketchConstraintMirror")
+
+ self._feature.data().refattr("ConstraintEntityA").setObject(mirror_line)
+ self._feature.data().reflist("ConstraintEntityB").clear()
+ for object_ in mirror_objects:
+ self._feature.data().reflist("ConstraintEntityB").append(object_)
+ self._feature.data().reflist("ConstraintMirrorList").append(object_)
+ self.execute()
+
+ def mirroredObjects(self):
+ return self._feature.data().reflist("ConstraintEntityC")
+ #feature = ModelAPI_Feature(object_)
+ #if feature.getKind() == "SketchCircle":
+ #objects.append(Circle(feature))
+ #elif feature.getKind() == "SketchLine":
+ #objects.append(Line(feature))
+ #else:
+ #raise TypeError(
+ #"%s is not a valid feature type" % feature.getKind()
+ #)
+
+# Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
+# finalized by Renaud Nedelec and Sergey Pokhodenko
+# Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
"""Sketch Feature Interface
-Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
- finalized by Renaud Nedelec and Sergey Pokhodenko
-Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+This interface allows to add a Sketch
+in a Part.
+The created sketch object provides all the needed methods
+for sketch modification and constraint edition.
"""
from ModelAPI import modelAPI_ResultConstruction, featureToCompositeFeature
from model.sketcher.line import Line
from model.sketcher.circle import Circle
from model.sketcher.arc import Arc
+from model.sketcher.mirror import Mirror
from model.roots import Interface
from model.tools import Selection
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"""
feature = featureToCompositeFeature(doc.addFeature("Sketch"))
return Circle(circle_feature, *args)
def addArc(self, *args):
- """Add an arc to this Sketch."""
+ """Add an arc to the sketch."""
if not args:
raise TypeError("No arguments given")
arc_feature = self._feature.addFeature("SketchArc")
def setTangent(self, object_1, object_2):
"""Set a tangential continuity between two objects
at their coincidence point."""
+ if object_1 is None or object_2 is None:
+ raise TypeError("NoneType argument given")
constraint = self._feature.addFeature("SketchConstraintTangent")
constraint.data().refattr("ConstraintEntityA").setObject(object_1)
constraint.data().refattr("ConstraintEntityB").setObject(object_2)
constraint.data().refattr("ConstraintEntityA").setObject(object_)
self.execute()
return constraint
+
+ #-------------------------------------------------------------
+ #
+ # Transformation constraints
+ #
+ #-------------------------------------------------------------
+
+ def addMirror(self, mirror_line, sketch_objects):
+ """Add a mirror transformation of the given objects to the sketch.
+
+ This transformation is a constraint.
+ :return: interface to the constraint
+ :rtype: Mirror object
+ """
+ mirror_constraint = self._feature.addFeature("SketchConstraintMirror")
+ mirror_interface = Mirror(mirror_constraint, mirror_line, sketch_objects)
+ self.execute()
+ return mirror_interface
+
#-------------------------------------------------------------
#