]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[PythonAPI / sketcher] first try for mirror constraint interface (not working) and...
authorRenaud NEDELEC <renaud.nedelec@opencascade.com>
Thu, 5 Nov 2015 12:58:39 +0000 (13:58 +0100)
committerRenaud NEDELEC <renaud.nedelec@opencascade.com>
Thu, 5 Nov 2015 12:58:39 +0000 (13:58 +0100)
src/PythonAPI/Test/TestSketcherAddMirror.py [new file with mode: 0644]
src/PythonAPI/model/sketcher/circle.py
src/PythonAPI/model/sketcher/mirror.py [new file with mode: 0644]
src/PythonAPI/model/sketcher/sketch.py

diff --git a/src/PythonAPI/Test/TestSketcherAddMirror.py b/src/PythonAPI/Test/TestSketcherAddMirror.py
new file mode 100644 (file)
index 0000000..dc23f09
--- /dev/null
@@ -0,0 +1,29 @@
+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
index b6ce45e8a33197fd84a3f922726f9428ad7958e6..c815ab110c230c5f1cabbc8aec775f0228616b40 100644 (file)
@@ -5,7 +5,7 @@ from model.roots import Interface
 
 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")
         
@@ -13,8 +13,18 @@ class Circle(Interface):
             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):
diff --git a/src/PythonAPI/model/sketcher/mirror.py b/src/PythonAPI/model/sketcher/mirror.py
new file mode 100644 (file)
index 0000000..dba62b4
--- /dev/null
@@ -0,0 +1,32 @@
+"""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()
+                    #)
+                
index 9e92a8e26e234ee1c22068b6b7e2940bdb485957..1efd09d1d5a678e59fbd430f0952d308c125a0a8 100644 (file)
@@ -1,7 +1,13 @@
+# 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
@@ -12,6 +18,7 @@ from model.sketcher.point import Point
 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
 
@@ -22,6 +29,7 @@ def addSketch(doc, plane):
 
     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"))
@@ -108,7 +116,7 @@ class Sketch(Interface):
         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")
@@ -236,6 +244,8 @@ class Sketch(Interface):
     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)
@@ -258,6 +268,25 @@ class Sketch(Interface):
         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
+        
 
     #-------------------------------------------------------------
     #