]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add construction plugin without tests.
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 27 Oct 2015 08:18:02 +0000 (11:18 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Tue, 27 Oct 2015 08:18:02 +0000 (11:18 +0300)
src/PythonAPI/model/__init__.py
src/PythonAPI/model/construction/__init__.py [new file with mode: 0644]
src/PythonAPI/model/construction/axis.py [new file with mode: 0644]
src/PythonAPI/model/construction/plane.py [new file with mode: 0644]
src/PythonAPI/model/construction/point.py [new file with mode: 0644]

index f4fafd41b5d13c430c9bfce2e1a831d6c29b93a5..1f90375a49a0758b9fbb3800a30aab3ffe477bb0 100644 (file)
@@ -10,7 +10,8 @@ from roots     import *
 
 from part      import Part            as addPart
 from sketcher.sketch  import addSketch
-from features  import *
+from construction import *
+from features import *
 
 # Custom exceptions
 
diff --git a/src/PythonAPI/model/construction/__init__.py b/src/PythonAPI/model/construction/__init__.py
new file mode 100644 (file)
index 0000000..e56746d
--- /dev/null
@@ -0,0 +1,6 @@
+"""Package for Construction plugin for the Parametric Geometry API of the Modeler.
+"""
+
+from point import addPoint
+from axis import addAxis
+from plane import addPlane
diff --git a/src/PythonAPI/model/construction/axis.py b/src/PythonAPI/model/construction/axis.py
new file mode 100644 (file)
index 0000000..498ca56
--- /dev/null
@@ -0,0 +1,77 @@
+"""Axis Interface
+Author: Sergey Pokhodenko
+Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+"""
+
+from model.roots import Interface
+
+
+def addAxis(part, *args):
+    """Add an Axis feature to the Part and return Axis.
+
+    Pass all args to Axis __init__ function.
+    """
+    feature = part.addFeature("Axis")
+    return Axis(feature, *args)
+
+
+class Axis(Interface):
+    """Interface on an Axis feature."""
+
+    def __init__(self, feature, *args):
+        """Initialize an Axis feature with given parameters.
+
+        Expected arguments for all modes:
+        feature -- a Axis feature
+
+        For AxisByPointsCase mode (expect 2 arguments):
+        p1 -- FirstPoint
+        p2 -- SecondPoint
+
+        For AxisByCylindricalFaceCase mode (expect 1 argument):
+        face -- CylindricalFace
+        """
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == "Axis")
+
+        self._CreationMethod = self._feature.data().string("CreationMethod")
+        self._FirstPoint = self._feature.data().selection("FirstPoint")
+        self._SecondPoint = self._feature.data().selection("SecondPoint")
+        self._CylindricalFace = self._feature.data().selection("CylindricalFace")
+
+        if not args:
+            return
+
+        assert(len(args) == 2 or len(args) == 1)
+        if len(args) == 2:
+            self.setPoints(*args)
+        elif len(args) == 1:
+            self.setCylindricalFace(*args)
+        pass
+
+    def __clear(self):
+        self._fill_attribute(self._CreationMethod, "AxisByPointsCase")
+        self._fill_attribute(self._FirstPoint, None)
+        self._fill_attribute(self._SecondPoint, None)
+        self._fill_attribute(self._CylindricalFace, None)
+
+    def setPoints(self, p1, p2):
+        """Modify points attribute of the feature.
+
+        See __init__.
+        """
+        self.__clear()
+        self._fill_attribute(self._CreationMethod, "AxisByPointsCase")
+        self._fill_attribute(self._FirstPoint, p1)
+        self._fill_attribute(self._SecondPoint, p2)
+        pass
+
+    def setCylindricalFace(self, face):
+        """Modify CylindricalFace attribute of the feature.
+
+        See __init__.
+        """
+        self.__clear()
+        self._fill_attribute(self._CreationMethod, "AxisByCylindricalFaceCase")
+        self._fill_attribute(self._CylindricalFace, face)
+        pass
diff --git a/src/PythonAPI/model/construction/plane.py b/src/PythonAPI/model/construction/plane.py
new file mode 100644 (file)
index 0000000..caacbf6
--- /dev/null
@@ -0,0 +1,86 @@
+"""Plane Interface
+Author: Sergey Pokhodenko
+Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+"""
+
+from model.roots import Interface
+
+
+def addPlane(part, *args):
+    """Add a Plane feature to the Part and return Plane.
+
+    Pass all args to Plane __init__ function.
+    """
+    feature = part.addFeature("Plane")
+    return Plane(feature, *args)
+
+
+class Plane(Interface):
+    """Interface on a Plane feature."""
+
+    def __init__(self, feature, *args):
+        """Initialize a Plane feature with given parameters.
+
+        Expected arguments for all modes:
+        feature -- a Plane feature
+
+        For PlaneByFaceAndDistance mode (expect 2 arguments):
+        face -- planeFace
+        distance -- distance
+
+        For PlaneByGeneralEquation mode (expect 4 arguments):
+        A, B, C, D -- GeneralEquation parameters
+        """
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == "Plane")
+
+        self._CreationMethod = self._feature.data().string("CreationMethod")
+        self._plane_face = self._feature.data().selection("planeFace")
+        self._distance = self._feature.data().real("distance")
+        self._a = self._feature.data().real("A")
+        self._b = self._feature.data().real("B")
+        self._c = self._feature.data().real("C")
+        self._d = self._feature.data().real("D")
+
+        if not args:
+            return
+
+        assert(len(args) == 2 or len(args) == 4)
+        if len(args) == 2:
+            self.setFaceAndDistance(*args)
+        elif len(args) == 4:
+            self.setGeneralEquation(*args)
+        pass
+
+    def __clear(self):
+        self._fill_attribute(self._CreationMethod, "PlaneByFaceAndDistance")
+        self._fill_attribute(self._plane_face, None)
+        self._fill_attribute(self._distance, 0)
+        self._fill_attribute(self._a, 0)
+        self._fill_attribute(self._b, 0)
+        self._fill_attribute(self._c, 0)
+        self._fill_attribute(self._d, 0)
+
+    def setFaceAndDistance(self, face, distance):
+        """Modify face and distance attribute of the feature.
+
+        See __init__.
+        """
+        self.__clear()
+        self._fill_attribute(self._CreationMethod, "PlaneByFaceAndDistance")
+        self._fill_attribute(self._plane_face, face)
+        self._fill_attribute(self._distance, distance)
+        pass
+
+    def setGeneralEquation(self, a, b, c, d):
+        """Modify GeneralEquation parameters of the feature.
+
+        See __init__.
+        """
+        self.__clear()
+        self._fill_attribute(self._CreationMethod, "PlaneByGeneralEquation")
+        self._fill_attribute(self._a, a)
+        self._fill_attribute(self._b, b)
+        self._fill_attribute(self._c, c)
+        self._fill_attribute(self._d, d)
+        pass
diff --git a/src/PythonAPI/model/construction/point.py b/src/PythonAPI/model/construction/point.py
new file mode 100644 (file)
index 0000000..ad7ef42
--- /dev/null
@@ -0,0 +1,51 @@
+"""Point Interface
+Author: Sergey Pokhodenko
+Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+"""
+
+from model.roots import Interface
+
+
+def addPoint(part, *args):
+    """Add an Point feature to the Part and return Point.
+
+    Pass all args to Point __init__ function.
+    """
+    feature = part.addFeature("Point")
+    return Point(feature, *args)
+
+
+class Point(Interface):
+    """Interface on an Point feature."""
+
+    def __init__(self, feature, *args):
+        """Initialize an Point feature with given parameters.
+
+        Expected arguments for all modes:
+        feature -- a Point feature
+
+        Expected arguments for initializing the feature:
+        x, y, z -- x, y, z coordinates for the point.
+        """
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == "Point")
+
+        self._x = self._feature.data().real("x")
+        self._y = self._feature.data().real("y")
+        self._z = self._feature.data().real("z")
+
+        if not args:
+            return
+
+        self.setPoint(*args)
+        pass
+
+    def setPoint(self, x, y, z):
+        """Modify base attribute of the feature.
+
+        See __init__.
+        """
+        self._fill_attribute(self._x, x)
+        self._fill_attribute(self._y, y)
+        self._fill_attribute(self._z, z)
+        pass