From 5f6c330407814e80848bb6b354fad1ff4c29ad28 Mon Sep 17 00:00:00 2001 From: spo Date: Tue, 27 Oct 2015 11:18:02 +0300 Subject: [PATCH] Add construction plugin without tests. --- src/PythonAPI/model/__init__.py | 3 +- src/PythonAPI/model/construction/__init__.py | 6 ++ src/PythonAPI/model/construction/axis.py | 77 ++++++++++++++++++ src/PythonAPI/model/construction/plane.py | 86 ++++++++++++++++++++ src/PythonAPI/model/construction/point.py | 51 ++++++++++++ 5 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 src/PythonAPI/model/construction/__init__.py create mode 100644 src/PythonAPI/model/construction/axis.py create mode 100644 src/PythonAPI/model/construction/plane.py create mode 100644 src/PythonAPI/model/construction/point.py diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index f4fafd41b..1f90375a4 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -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 index 000000000..e56746de6 --- /dev/null +++ b/src/PythonAPI/model/construction/__init__.py @@ -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 index 000000000..498ca567a --- /dev/null +++ b/src/PythonAPI/model/construction/axis.py @@ -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 index 000000000..caacbf654 --- /dev/null +++ b/src/PythonAPI/model/construction/plane.py @@ -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 index 000000000..ad7ef42b6 --- /dev/null +++ b/src/PythonAPI/model/construction/point.py @@ -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 -- 2.39.2