From a55a4383f6d574dd143cf549551adc4a439f6e52 Mon Sep 17 00:00:00 2001 From: spo Date: Fri, 17 Jun 2016 17:43:11 +0300 Subject: [PATCH] Remove PythonAPI implementation --- src/PythonAPI/Test/TestSketcherAddArc.py | 7 - src/PythonAPI/model/__init__.py | 6 - src/PythonAPI/model/connection/connection.py | 16 - src/PythonAPI/model/construction/__init__.py | 4 +- src/PythonAPI/model/construction/axis.py | 101 ---- src/PythonAPI/model/construction/plane.py | 116 ----- src/PythonAPI/model/construction/point.py | 70 --- src/PythonAPI/model/errors.py | 22 - src/PythonAPI/model/exchange/exchange.py | 142 ------ src/PythonAPI/model/features/__init__.py | 2 +- src/PythonAPI/model/features/boolean.py | 156 ------ src/PythonAPI/model/features/extrusion.py | 185 ------- .../model/features/extrusion_boolean.py | 162 ------- src/PythonAPI/model/features/group.py | 62 --- src/PythonAPI/model/features/partition.py | 89 ---- src/PythonAPI/model/features/placement.py | 110 ----- src/PythonAPI/model/features/revolution.py | 149 ------ .../model/features/revolution_boolean.py | 184 ------- src/PythonAPI/model/features/roots.py | 94 ---- src/PythonAPI/model/features/rotation.py | 86 ---- src/PythonAPI/model/features/translation.py | 86 ---- src/PythonAPI/model/parameter/parameter.py | 76 --- src/PythonAPI/model/partset/part.py | 65 --- src/PythonAPI/model/services.py | 3 - src/PythonAPI/model/sketcher/arc.py | 100 ---- src/PythonAPI/model/sketcher/circle.py | 52 -- src/PythonAPI/model/sketcher/entity.py | 15 - src/PythonAPI/model/sketcher/line.py | 78 --- src/PythonAPI/model/sketcher/mirror.py | 32 -- src/PythonAPI/model/sketcher/point.py | 30 -- src/PythonAPI/model/sketcher/sketch.py | 458 ------------------ src/PythonAPI/model/tools.py | 139 ------ 32 files changed, 2 insertions(+), 2895 deletions(-) delete mode 100644 src/PythonAPI/model/connection/connection.py delete mode 100644 src/PythonAPI/model/construction/axis.py delete mode 100644 src/PythonAPI/model/construction/plane.py delete mode 100644 src/PythonAPI/model/construction/point.py delete mode 100644 src/PythonAPI/model/errors.py delete mode 100644 src/PythonAPI/model/exchange/exchange.py delete mode 100644 src/PythonAPI/model/features/boolean.py delete mode 100644 src/PythonAPI/model/features/extrusion.py delete mode 100644 src/PythonAPI/model/features/extrusion_boolean.py delete mode 100644 src/PythonAPI/model/features/group.py delete mode 100644 src/PythonAPI/model/features/partition.py delete mode 100644 src/PythonAPI/model/features/placement.py delete mode 100644 src/PythonAPI/model/features/revolution.py delete mode 100644 src/PythonAPI/model/features/revolution_boolean.py delete mode 100644 src/PythonAPI/model/features/roots.py delete mode 100644 src/PythonAPI/model/features/rotation.py delete mode 100644 src/PythonAPI/model/features/translation.py delete mode 100644 src/PythonAPI/model/parameter/parameter.py delete mode 100644 src/PythonAPI/model/partset/part.py delete mode 100644 src/PythonAPI/model/sketcher/arc.py delete mode 100644 src/PythonAPI/model/sketcher/circle.py delete mode 100644 src/PythonAPI/model/sketcher/entity.py delete mode 100644 src/PythonAPI/model/sketcher/line.py delete mode 100644 src/PythonAPI/model/sketcher/mirror.py delete mode 100644 src/PythonAPI/model/sketcher/point.py delete mode 100644 src/PythonAPI/model/sketcher/sketch.py delete mode 100644 src/PythonAPI/model/tools.py diff --git a/src/PythonAPI/Test/TestSketcherAddArc.py b/src/PythonAPI/Test/TestSketcherAddArc.py index 922078d2c..551c4a880 100644 --- a/src/PythonAPI/Test/TestSketcherAddArc.py +++ b/src/PythonAPI/Test/TestSketcherAddArc.py @@ -2,7 +2,6 @@ import unittest import model import geom -from model import WrongNumberOfArguments from TestSketcher import SketcherTestCase @@ -22,12 +21,6 @@ class SketcherAddArc(SketcherTestCase): self.assertEqual(arc.startPoint().x(), 0) self.assertEqual(arc.startPoint().y(), 0) - # def test_number_of_args(self): - # with self.assertRaises(WrongNumberOfArguments): - # self.sketch.addArc(0, 1, 1, 1) - # with self.assertRaises(WrongNumberOfArguments): - # self.sketch.addArc(0, 1) - def test_modify_arc(self): # Note: arc will modify startPoint and endPoint to be in circle arc = self.sketch.addArc(0, 1, 0, 0, 1, 1, 0) diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index c5b71cbf4..e359630fe 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -10,7 +10,6 @@ All features are available via model.add*() functions. Exceptions are: from services import * from roots import * -from tools import Selection # Built-in features @@ -21,8 +20,3 @@ from exchange import * from features import * from parameter import * from partset import * - -# Custom exceptions - -from errors import WrongNumberOfArguments -from errors import FeatureInputInvalid diff --git a/src/PythonAPI/model/connection/connection.py b/src/PythonAPI/model/connection/connection.py deleted file mode 100644 index da54458bc..000000000 --- a/src/PythonAPI/model/connection/connection.py +++ /dev/null @@ -1,16 +0,0 @@ -"""Export to GEOM Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def exportToGEOM(part): - """Export the Part to GEOM module. - - Args: - part (ModelAPI_Document): part document - """ - feature = part.addFeature("ExportToGEOM") - feature.execute() diff --git a/src/PythonAPI/model/construction/__init__.py b/src/PythonAPI/model/construction/__init__.py index 9273672b9..01b17593c 100644 --- a/src/PythonAPI/model/construction/__init__.py +++ b/src/PythonAPI/model/construction/__init__.py @@ -1,6 +1,4 @@ """Package for Construction plugin for the Parametric Geometry API of the Modeler. """ -from ConstructionAPI import addAxis -from ConstructionAPI import addPlane -from ConstructionAPI import addPoint +from ConstructionAPI import addAxis, addPlane, addPoint diff --git a/src/PythonAPI/model/construction/axis.py b/src/PythonAPI/model/construction/axis.py deleted file mode 100644 index ee92f4a37..000000000 --- a/src/PythonAPI/model/construction/axis.py +++ /dev/null @@ -1,101 +0,0 @@ -"""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. - - .. function:: addAxis(part, p1, p2) - - Args: - part (ModelAPI_Document): part document - p1 (Selection): first point - p2 (Selection): second point - - .. function:: addAxis(part, face) - - Args: - part (ModelAPI_Document): part document - face (Selection): cylindrical face - - Returns: - Axis: axis object - """ - assert(args) - feature = part.addFeature("Axis") - return Axis(feature, *args) - - -class Axis(Interface): - """Interface class for Axis feature. - - .. function:: Axis(feature) - - Create interface for the feature without initialization. - - .. function:: Axis(feature, p1, p2) - - Create interface for the feature and initialize the feature with arguments. - - .. function:: Axis(feature, face) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - 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") - - assert(self._CreationMethod) - assert(self._FirstPoint) - assert(self._SecondPoint) - assert(self._CylindricalFace) - - if not args: - return - - assert(len(args) in (1, 2)) - if len(args) == 2: - self.setPoints(*args) - elif len(args) == 1: - self.setCylindricalFace(*args) - - self.execute() - pass - - def __clear(self): - self._fillAttribute(self._CreationMethod, "AxisByPointsCase") - self._fillAttribute(self._FirstPoint, None) - self._fillAttribute(self._SecondPoint, None) - self._fillAttribute(self._CylindricalFace, None) - - def setPoints(self, p1, p2): - """Modify points attribute of the feature. - - See __init__. - """ - self.__clear() - self._fillAttribute(self._CreationMethod, "AxisByPointsCase") - self._fillAttribute(self._FirstPoint, p1) - self._fillAttribute(self._SecondPoint, p2) - pass - - def setCylindricalFace(self, face): - """Modify CylindricalFace attribute of the feature. - - See __init__. - """ - self.__clear() - self._fillAttribute(self._CreationMethod, "AxisByCylindricalFaceCase") - self._fillAttribute(self._CylindricalFace, face) - pass diff --git a/src/PythonAPI/model/construction/plane.py b/src/PythonAPI/model/construction/plane.py deleted file mode 100644 index c51e53032..000000000 --- a/src/PythonAPI/model/construction/plane.py +++ /dev/null @@ -1,116 +0,0 @@ -"""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. - - .. function:: addPartition(part, face, distance) - - Args: - part (ModelAPI_Document): part document - face (Selection): plane face - distance (double): distance - - .. function:: addPartition(part, a, b, c, d) - - Args: - part (ModelAPI_Document): part document - a (double): general equation parameter - b (double): general equation parameter - c (double): general equation parameter - d (double): general equation parameter - - Returns: - Plane: plane object - """ - assert(args) - feature = part.addFeature("Plane") - return Plane(feature, *args) - - -class Plane(Interface): - """Interface class for Plane feature. - - .. function:: Plane(feature) - - Create interface for the feature without initialization. - - .. function:: Plane(feature, face, distance) - - Create interface for the feature and initialize the feature with arguments. - - .. function:: Plane(feature, a, b, c, d) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - 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") - - assert(self._CreationMethod) - assert(self._plane_face) - assert(self._distance) - assert(self._a) - assert(self._b) - assert(self._c) - assert(self._d) - - if not args: - return - - assert(len(args) in (2, 4)) - if len(args) == 2: - self.setFaceAndDistance(*args) - elif len(args) == 4: - self.setGeneralEquation(*args) - - self.execute() - pass - - def __clear(self): - self._fillAttribute(self._CreationMethod, "PlaneByFaceAndDistance") - self._fillAttribute(self._plane_face, None) - self._fillAttribute(self._distance, 0) - self._fillAttribute(self._a, 0) - self._fillAttribute(self._b, 0) - self._fillAttribute(self._c, 0) - self._fillAttribute(self._d, 0) - - def setFaceAndDistance(self, face, distance): - """Modify face and distance attribute of the feature. - - See __init__. - """ - self.__clear() - self._fillAttribute(self._CreationMethod, "PlaneByFaceAndDistance") - self._fillAttribute(self._plane_face, face) - self._fillAttribute(self._distance, distance) - pass - - def setGeneralEquation(self, a, b, c, d): - """Modify GeneralEquation parameters of the feature. - - See __init__. - """ - self.__clear() - self._fillAttribute(self._CreationMethod, "PlaneByGeneralEquation") - self._fillAttribute(self._a, a) - self._fillAttribute(self._b, b) - self._fillAttribute(self._c, c) - self._fillAttribute(self._d, d) - pass diff --git a/src/PythonAPI/model/construction/point.py b/src/PythonAPI/model/construction/point.py deleted file mode 100644 index db3405fb4..000000000 --- a/src/PythonAPI/model/construction/point.py +++ /dev/null @@ -1,70 +0,0 @@ -"""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. - - .. function:: addPoint(part, x, y, z) - - Args: - part (ModelAPI_Document): part document - x (double): X coordinate for the point - y (double): Y coordinate for the point - z (double): Z coordinate for the point - - Returns: - Point: point object - """ - assert(args) - feature = part.addFeature("Point") - return Point(feature, *args) - - -class Point(Interface): - """Interface class for Point feature. - - .. function:: Point(feature) - - Create interface for the feature without initialization. - - .. function:: Point(feature, x, y, z) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - 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") - - assert(self._x) - assert(self._y) - assert(self._z) - - if not args: - return - - assert(len(args) == 3) - self.setPoint(*args) - - self.execute() - pass - - def setPoint(self, x, y, z): - """Modify base attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._x, x) - self._fillAttribute(self._y, y) - self._fillAttribute(self._z, z) - pass diff --git a/src/PythonAPI/model/errors.py b/src/PythonAPI/model/errors.py deleted file mode 100644 index e10ec92ee..000000000 --- a/src/PythonAPI/model/errors.py +++ /dev/null @@ -1,22 +0,0 @@ -# Package exceptions - -class ModelError(Exception): - """Base class for exceptions in this package.""" - pass - -class WrongNumberOfArguments(ModelError): - """Exception raised when a wrong number of arguments is given.""" - pass - -class FeatureInputInvalid(ModelError): - """Exception raised if a feature input is invalid.""" - pass - - #Attributes: - #expr -- input expression in which the error occurred - #msg -- explanation of the error - #""" - - #def __init__(self, expr, msg): - #self.expr = expr - #self.msg = msg diff --git a/src/PythonAPI/model/exchange/exchange.py b/src/PythonAPI/model/exchange/exchange.py deleted file mode 100644 index c884451af..000000000 --- a/src/PythonAPI/model/exchange/exchange.py +++ /dev/null @@ -1,142 +0,0 @@ -"""Import Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def addImport(part, *args): - """Add an Import feature to the Part. - - .. function:: addImport(part, file_path) - - Args: - part (ModelAPI_Document): part document - file_path (string): path to the imported file - - Returns: - Import: import object - """ - assert(args) - feature = part.addFeature("Import") - return Import(feature, *args) - - -class Import(Interface): - """Interface class for Import feature. - - .. function:: Import(feature) - - Create interface for the feature without initialization. - - .. function:: Import(feature, file_path) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Import") - - self._file_path = self._feature.data().string("file_path") - - assert(self._file_path) - - if not args: - return - - assert(len(args) == 1) - self.setFilePath(args[0]) - - self.execute() - pass - - def setFilePath(self, file_path): - """Modify file path attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._file_path, file_path) - pass - - -def exportToFile(part, *args): - """Perform export from the Part to file. - - .. function:: exportToFile(part, file_path, file_format, selection_list) - - Args: - part (ModelAPI_Document): part document - file_path (string): path to the exported file - file_format (string): format of to the exported file - selection_list (list of Selection): objects to export - - Returns: - Export: export object - """ - assert(args) - feature = part.addFeature("Export") - return Export(feature, *args) - - -class Export(Interface): - """Interface class for Export feature. - - .. function:: Export(feature) - - Create interface for the feature without initialization. - - .. function:: Export(feature, file_path, file_format, selection_list) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Export") - - self._file_path = self._feature.data().string("file_path") - self._file_format = self._feature.data().string("file_format") - self._objects = self._feature.data().selectionList("selection_list") - - assert(self._file_path) - assert(self._file_format) - assert(self._objects) - - if not args: - return - - assert(len(args) == 3) - self.setFilePath(args[0]) - self.setFileFormat(args[1]) - self.setObjects(args[2]) - - self.execute() - pass - - def setFilePath(self, file_path): - """Modify file path attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._file_path, file_path) - pass - - def setFileFormat(self, file_format): - """Modify file path attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._file_format, file_format) - pass - - def setObjects(self, objects): - """Modify file path attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._objects, object) - pass diff --git a/src/PythonAPI/model/features/__init__.py b/src/PythonAPI/model/features/__init__.py index 5fdf4c72d..b4266e76b 100644 --- a/src/PythonAPI/model/features/__init__.py +++ b/src/PythonAPI/model/features/__init__.py @@ -5,7 +5,7 @@ from FeaturesAPI import addPlacement, addRotation, addTranslation from FeaturesAPI import addFuse, addCut, addCommon -from partition import addPartition +from FeaturesAPI import addPartition from FeaturesAPI import addExtrusion, addExtrusionCut, addExtrusionFuse from FeaturesAPI import addRevolution, addRevolutionCut, addRevolutionFuse diff --git a/src/PythonAPI/model/features/boolean.py b/src/PythonAPI/model/features/boolean.py deleted file mode 100644 index aab909faa..000000000 --- a/src/PythonAPI/model/features/boolean.py +++ /dev/null @@ -1,156 +0,0 @@ -"""Boolean operations Interface -Author: Daniel Brunier-Coulin with contribution by Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from GeomAlgoAPI import GeomAlgoAPI_Boolean - -from model.roots import Interface -from model import Selection - -def addAddition(part, *args): - """Perform addition in the Part. - - .. function:: addAddition(part, main_objects, tool_objects) - - This operation adds tools to the given objects. - - Args: - part (ModelAPI_Document): part document - main_objects (list of :class:`model.Selection`): main objects - tool_objects (list of :class:`model.Selection`): (optional) tool_objects objects - - Returns: - Boolean: boolean object - """ - assert(args) - feature = part.addFeature("Boolean") - return Boolean( - feature, GeomAlgoAPI_Boolean.BOOL_FUSE, *args) - - -def addSubtraction(part, *args): - """Perform subtraction in the Part. - - .. function:: addSubtraction(part, main_objects, tool_objects) - - This operation subtracts tools from the given objects. - - Args: - part (ModelAPI_Document): part document - main_objects (list of :class:`model.Selection`): main objects - tool_objects (list of :class:`model.Selection`): tool_objects objects - - Returns: - Boolean: boolean object - """ - assert(args) - main_objects, tool_objects = args - feature = part.addFeature("Boolean") - return Boolean( - feature, GeomAlgoAPI_Boolean.BOOL_CUT, main_objects, tool_objects) - - -def addIntersection(part, *args): - """Perform intersection in the Part. - - .. function:: addIntersection(part, main_objects, tool_objects) - - This operation intersects tools with the given objects. - - Args: - part (ModelAPI_Document): part document - main_objects (list of :class:`model.Selection`): main objects - tool_objects (list of :class:`model.Selection`): tool_objects objects - - Returns: - Boolean: boolean object - """ - assert(args) - main_objects, tool_objects = args - feature = part.addFeature("Boolean") - return Boolean( - feature, GeomAlgoAPI_Boolean.BOOL_COMMON, main_objects, tool_objects) - - -class Boolean(Interface): - """Interface class for Boolean features. - - .. function:: Boolean(feature) - - Create interface for the feature without initialization. - - .. function:: Boolean(feature, bool_type, main_objects) - - Create interface for the feature and initialize the feature with arguments. - - .. function:: Boolean(feature, bool_type, main_objects, tool_objects) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Boolean") - - self._main_objects = self._feature.selectionList("main_objects") - self._tool_objects = self._feature.selectionList("tool_objects") - self._bool_type = self._feature.integer("bool_type") - - assert(self._main_objects) - assert(self._tool_objects) - assert(self._bool_type) - - if not args: - return - - assert(len(args) in (2, 3)) - bool_type, main_objects = args[:2] - - self.setBoolType(bool_type) - self.setMainObjects(main_objects) - - if len(args) == 3: - tool_objects = args[2] - self.setToolObjects(tool_objects) - - self.execute() - pass - - def setMainObjects(self, main_objects): - """Modify main_objects attribute of the feature. - - Args: - main_objects (list of :class:`model.Selection`): main objects - """ - self._fillAttribute(self._main_objects, main_objects) - pass - - def setToolObjects(self, tool_objects): - """Modify tool_objects attribute of the feature. - - Args: - tool_objects (list of :class:`model.Selection`): tool objects - """ - self._fillAttribute(self._tool_objects, tool_objects) - pass - - def setBoolType(self, bool_type): - """Modify bool_type attribute of the feature. - - Args: - bool_type (integer): type of operation - - Available types: - - * GeomAlgoAPI_Boolean.BOOL_FUSE - * GeomAlgoAPI_Boolean.BOOL_CUT - * GeomAlgoAPI_Boolean.BOOL_COMMON - """ - self._fillAttribute(self._bool_type, bool_type) - pass - - def result(self): - """F.result() -> list of Selection objects""" - return [Selection(result, result.shape()) for result in (self.firstResult(),)] diff --git a/src/PythonAPI/model/features/extrusion.py b/src/PythonAPI/model/features/extrusion.py deleted file mode 100644 index 7e87ace83..000000000 --- a/src/PythonAPI/model/features/extrusion.py +++ /dev/null @@ -1,185 +0,0 @@ -"""Extrusion Interface -Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov - and Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface -from model import Selection - -def addExtrusion(part, *args): - """Add an Extrusion feature to the Part and return Extrusion. - - This function has *3 signatures*: - - .. function:: addExtrusion(base, size) - - Arguments: - base(str, Sketch or list): base object(s) - size(double): size of the extrusion, the side is decided by the sign - - .. function:: addExtrusion(base, to_size, from_size) - - Arguments: - base(str, Sketch or list): base object(s) - to_size(double): upper size of the extrusion - from_size(double): lower size of the extrusion - - .. function:: addExtrusion(base, to_object, to_offset, from_object, from_offset) - - Arguments: - base(str, Sketch or list): base object(s) - to_object(plane): upper plane - to_offset(double): offset from upper object - from_object(plane): lower plane - from_offset(double): offset from lower plane - - In all three cases the function returns an extrusion object - - Returns: - Extrusion: extrusion object - """ - assert(args) - feature = part.addFeature("Extrusion") - return Extrusion(feature, *args) - - -class Extrusion(Interface): - """Interface class for Extrusion feature. - """ - - def __init__(self, feature, *args): - """ - Extrusion(feature) -> feature interface without initialization - Extrusion(feature, base, size) -> - feature interface initialized from arguments: - - base -- name, sketch or list of names and sketches - - size -- if positive -> to_size, if negative -> from_size - Extrusion(feature, base, to_size, from_size) -> - feature interface initialized from arguments: - - base -- name, sketch or list of names and sketches - - to_size -- upper size - - from_size -- lower size - Extrusion(feature, base, to_object, to_offset, from_object, from_offset) -> - feature interface initialized from arguments: - - base -- name, sketch or list of names and sketches - - to_object -- upper object (plane) - - to_offset -- offset from upper object - - from_object -- lower object (plane) - - from_offset -- offset from lower object - """ - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Extrusion") - - self._base = self._feature.data().selectionList("base") - self._CreationMethod = self._feature.string("CreationMethod") - self._to_size = self._feature.data().real("to_size") - self._from_size = self._feature.data().real("from_size") - self._to_object = self._feature.data().selection("to_object") - self._to_offset = self._feature.data().real("to_offset") - self._from_object = self._feature.data().selection("from_object") - self._from_offset = self._feature.data().real("from_offset") - - assert(self._base) - assert(self._CreationMethod) - assert(self._to_size) - assert(self._from_size) - assert(self._to_object) - assert(self._to_offset) - assert(self._from_object) - assert(self._from_offset) - - if not args: - return - - assert(len(args) in (2, 3, 5)) - base = args[0] - args = args[1:] - - self.setBase(base) - - if len(args) == 4: - self.setPlanesAndOffsets(*args) - elif len(args) == 2: - self.setSizes(*args) - elif len(args) == 1: - self.setSize(args[0]) - - self.execute() - pass - - def __clear(self): - self._CreationMethod.setValue("BySizes") - self._fillAttribute(self._to_size, 0) - self._fillAttribute(self._from_size, 0) - self._fillAttribute(self._to_object, None) - self._fillAttribute(self._to_offset, 0) - self._fillAttribute(self._from_object, None) - self._fillAttribute(self._from_offset, 0) - pass - - def setBase(self, base): - """Modify base attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._base, base) - pass - - def setSizes(self, to_size, from_size, to_size_text="", from_size_text=""): - """Modify the to_size, from_size attributes of the feature. - - See __init__. - """ - # MPV: with "clear" calling here the extrusion all the time becomes modificed (height is set to - # zero and then to actual value, but this function is used in macro Bax, that causes "modified" - # values without changes that causes cyclic dependency - #self.__clear() - self._fillAttribute(self._CreationMethod, "BySizes") - if to_size_text == "": - self._fillAttribute(self._to_size, to_size) - else: - self._fillAttribute(self._to_size, to_size_text) - - if from_size_text == "": - self._fillAttribute(self._from_size, from_size) - else: - self._fillAttribute(self._to_size, from_size_text) - pass - - def setSize(self, size, text=""): - """Modify the size of the feature. - - If size is positive then initialize to_size with size. - If size is negative then initialize from_size with -size. - """ - to_size, from_size = 0, 0 - to_size_text, from_size_text = "", "" - if size >= 0: - to_size = size - to_size_text = text - else: - from_size = -size - from_size_text = text - - self.setSizes(to_size, from_size, to_size_text, from_size_text) - - pass - - def setPlanesAndOffsets(self, to_object, to_offset, - from_object, from_offset): - """Modify planes and offsets attributes of the feature. - - See __init__. - """ - self.__clear() - self._CreationMethod.setValue("ByPlanesAndOffsets") - self._fillAttribute(self._to_object, to_object) - self._fillAttribute(self._to_offset, to_offset) - self._fillAttribute(self._from_object, from_object) - self._fillAttribute(self._from_offset, from_offset) - pass - - def result(self): - """F.result() -> list of Selection objects""" - return [Selection(result, result.shape()) for result in (self.firstResult(),)] diff --git a/src/PythonAPI/model/features/extrusion_boolean.py b/src/PythonAPI/model/features/extrusion_boolean.py deleted file mode 100644 index 199d1e1d9..000000000 --- a/src/PythonAPI/model/features/extrusion_boolean.py +++ /dev/null @@ -1,162 +0,0 @@ -"""ExtrusionCut and ExtrusionFuse Interfaces -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from .roots import CompositeBoolean - - -def addExtrusionCut(part, *args): - """Add an ExtrusionCut feature to the Part. - - .. function:: addExtrusionCut(part, sketch, sketch_selection, boolean_objects, to_size, from_size) - - Args: - part (ModelAPI_Document): part document - sketch (ModelAPI_Object): sketch feature - sketch_selection (Selection): sketch objects - boolean_objects (list of Selection): boolean objects - to_size (double): upper size of the extrusion - from_size (double): lower size of the extrusion - - .. function:: addExtrusionCut(part, sketch, sketch_selection, boolean_objects, to_object, to_offset, from_object, from_offset) - - Args: - part (ModelAPI_Document): part document - sketch (ModelAPI_Object): sketch feature - sketch_selection (Selection): sketch objects - boolean_objects (list of Selection): boolean objects - to_object (Selection): upper plane - to_offset (double): offset from upper plane - from_object (Selection): lower plane - from_offset (double): offset from lower plane - - Returns: - ExtrusionBoolean: extrusion boolean object - """ - assert(args) - feature = part.addFeature("ExtrusionCut") - return ExtrusionBoolean(feature, *args) - -def addExtrusionFuse(part, *args): - """Add an ExtrusionFuse feature to the Part and return ExtrusionBoolean. - - .. function:: addExtrusionFuse(part, sketch, sketch_selection, boolean_objects, to_size, from_size) - - Args: - part (ModelAPI_Document): part document - sketch (ModelAPI_Object): sketch feature - sketch_selection (Selection): sketch objects - boolean_objects (list of Selection): boolean objects - to_size (double): upper size of the extrusion - from_size (double): lower size of the extrusion - - .. function:: addExtrusionFuse(part, sketch, sketch_selection, boolean_objects, to_object, to_offset, from_object, from_offset) - - Args: - part (ModelAPI_Document): part document - sketch (ModelAPI_Object): sketch feature - sketch_selection (Selection): sketch objects - boolean_objects (list of Selection): boolean objects - to_object (Selection): upper plane - to_offset (double): offset from upper plane - from_object (Selection): lower plane - from_offset (double): offset from lower plane - - Returns: - ExtrusionBoolean: extrusion boolean object - """ - assert(args) - feature = part.addFeature("ExtrusionFuse") - return ExtrusionBoolean(feature, *args) - - -class ExtrusionBoolean(CompositeBoolean): - """Interface class for ExtrusionBoolean features. - - Supported features: - - * ExtrusionCut - * ExtrusionFuse - - .. function:: ExtrusionBoolean(feature) - - Create interface for the feature without initialization. - - .. function:: ExtrusionBoolean(feature, sketch, sketch_selection, boolean_objects, to_size, from_size) - - Create interface for the feature and initialize the feature with arguments. - - .. function:: ExtrusionBoolean(feature, sketch, sketch_selection, boolean_objects, to_object, to_offset, from_object, from_offset) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - CompositeBoolean.__init__(self, feature, *args[:3]) - args = args[3:] - - self._CreationMethod = self._feature.string("CreationMethod") - self._to_size = self._feature.data().real("to_size") - self._from_size = self._feature.data().real("from_size") - self._to_object = self._feature.data().selection("to_object") - self._to_offset = self._feature.data().real("to_offset") - self._from_object = self._feature.data().selection("from_object") - self._from_offset = self._feature.data().real("from_offset") - - assert(self._CreationMethod) - assert(self._to_size) - assert(self._from_size) - assert(self._to_object) - assert(self._to_offset) - assert(self._from_object) - assert(self._from_offset) - - if not args: - return - - assert(len(args) in (2, 4)) - if len(args) == 4: - self.setPlanesAndOffsets(*args) - elif len(args) == 2: - self.setSizes(*args) - - self.execute() - pass - - def __clear(self): - self._CreationMethod.setValue("BySizes") - self._fillAttribute(self._to_size, 0) - self._fillAttribute(self._from_size, 0) - self._fillAttribute(self._to_object, None) - self._fillAttribute(self._to_offset, 0) - self._fillAttribute(self._from_object, None) - self._fillAttribute(self._from_offset, 0) - pass - - def setSizes(self, to_size, from_size): - """Modify the to_size, from_size attributes of the feature. - - See __init__. - """ - self.__clear() - self._CreationMethod.setValue("BySizes") - self._fillAttribute(self._to_size, to_size) - self._fillAttribute(self._from_size, from_size) - pass - - def setPlanesAndOffsets(self, to_object, to_offset, - from_object, from_offset): - """Modify planes and offsets attributes of the feature. - - See __init__. - """ - self.__clear() - self._CreationMethod.setValue("ByPlanesAndOffsets") - self._fillAttribute(self._to_object, to_object) - self._fillAttribute(self._to_offset, to_offset) - self._fillAttribute(self._from_object, from_object) - self._fillAttribute(self._from_offset, from_offset) - pass - diff --git a/src/PythonAPI/model/features/group.py b/src/PythonAPI/model/features/group.py deleted file mode 100644 index 68567bd2b..000000000 --- a/src/PythonAPI/model/features/group.py +++ /dev/null @@ -1,62 +0,0 @@ -"""Group Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def addGroup(part, *args): - """Add a Group feature to the Part. - - .. function:: addGroup(part, group_list) - - Args: - part (ModelAPI_Document): part document - group_list (list of Selection): list of objects - - Returns: - Group: group object - """ - assert(args) - feature = part.addFeature("Group") - return Group(feature, *args) - - -class Group(Interface): - """Interface class for Group feature. - - .. function:: Group(feature) - - Create interface for the feature without initialization. - - .. function:: Group(feature, group_list) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Group") - - self._group_list = self._feature.data().selectionList("group_list") - - assert(self._group_list) - - if not args: - return - - assert(len(args) == 1) - self.setGroupList(args[0]) - - self.execute() - pass - - def setGroupList(self, main_objects): - """Modify group_list attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._group_list, group_list) - pass diff --git a/src/PythonAPI/model/features/partition.py b/src/PythonAPI/model/features/partition.py deleted file mode 100644 index 26173e0d6..000000000 --- a/src/PythonAPI/model/features/partition.py +++ /dev/null @@ -1,89 +0,0 @@ -"""Partition Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def addPartition(part, *args): - """Add a Partition feature to the Part. - - .. function:: addPartition(part, main_objects, tool_objects, partition_combine) - - Args: - part (ModelAPI_Document): part document - main_objects (list of Selection): main objects - tool_objects (list of Selection): tool objects - partition_combine (boolean): - If True combines all results to one. If False builds separate result for each object. - - Returns: - Partition: partition object - """ - assert(len(args) > 0 and args[0] is not None) - feature = part.addFeature("Partition") - return Partition(feature, *args) - - -class Partition(Interface): - """Interface class for Partition feature. - - .. function:: Partition(feature) - - Create interface for the feature without initialization. - - .. function:: Partition(feature, main_objects, tool_objects, partition_combine) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Partition") - - self._main_objects = self._feature.data().selectionList("main_objects") - self._tool_objects = self._feature.data().selectionList("tool_objects") - self._partition_combine = self._feature.data().boolean("partition_combine") - - assert(self._main_objects) - assert(self._tool_objects) - assert(self._partition_combine) - - if not args: - return - - assert(len(args) == 3) - main_objects, tool_objects, partition_combine = args - - self.setMainObjects(main_objects) - self.setToolObjects(tool_objects) - self.setPartitionCombine(partition_combine) - - self.execute() - pass - - def setMainObjects(self, main_objects): - """Modify base attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._main_objects, main_objects) - pass - - def setToolObjects(self, tool_objects): - """Modify the to_size, from_size attributes of the feature. - - See __init__. - """ - self._fillAttribute(self._tool_objects, tool_objects) - pass - - def setPartitionCombine(self, partition_combine): - """Modify planes and offsets attributes of the feature. - - See __init__. - """ - self._fillAttribute(self._partition_combine, partition_combine) - pass diff --git a/src/PythonAPI/model/features/placement.py b/src/PythonAPI/model/features/placement.py deleted file mode 100644 index 4da0998e5..000000000 --- a/src/PythonAPI/model/features/placement.py +++ /dev/null @@ -1,110 +0,0 @@ -"""Placement Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def addPlacement(part, *args): - """Add a Placement feature to the Part. - - .. function:: addPlacement(part, objects_list, start_shape, end_shape, reverse_direction, centering) - - Args: - part (ModelAPI_Document): part document - objects_list (list of Selection): solid objects - start_shape (Selection): start face, edge or vertex - end_shape (Selection): end face, edge or vertex - reverse_direction (boolean): reverse placement direction - centering (boolean): center faces under placement - - Returns: - Placement: placement object - """ - assert(args) - feature = part.addFeature("Placement") - return Placement(feature, *args) - - -class Placement(Interface): - """Interface class for Placement feature. - - .. function:: Placement(feature) - - Create interface for the feature without initialization. - - .. function:: Placement(feature, objects_list, start_shape, end_shape, reverse_direction, centering) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Placement") - - self._objects_list = self._feature.data().selectionList("placement_objects_list") - self._start_shape = self._feature.data().selection("placement_start_shape") - self._end_shape = self._feature.data().selection("placement_end_shape") - self._reverse_direction = self._feature.data().boolean("placement_reverse_direction") - self._centering = self._feature.data().boolean("placement_centering") - - assert(self._objects_list) - assert(self._start_shape) - assert(self._end_shape) - assert(self._reverse_direction) - assert(self._centering) - - if not args: - return - - assert(len(args) == 5) - self.setObjectList(args[0]) - self.setStartShape(args[1]) - self.setEndShape(args[2]) - self.setReverseDirection(args[3]) - self.setCentering(args[4]) - - self.execute() - pass - - def setObjectList(self, objects_list): - """Modify placement_objects_list attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._objects_list, objects_list) - pass - - def setStartShape(self, start_shape): - """Modify start_shape attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._start_shape, start_shape) - pass - - def setEndShape(self, end_shape): - """Modify end_shape attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._end_shape, end_shape) - pass - - def setReverseDirection(self, reverse_direction): - """Modify reverse_direction attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._reverse_direction, reverse_direction) - pass - - def setCentering(self, centering): - """Modify centering attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._centering, centering) - pass diff --git a/src/PythonAPI/model/features/revolution.py b/src/PythonAPI/model/features/revolution.py deleted file mode 100644 index 3ab420144..000000000 --- a/src/PythonAPI/model/features/revolution.py +++ /dev/null @@ -1,149 +0,0 @@ -"""Revolution Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def addRevolution(part, *args): - """Add a Revolution feature to the Part. - - .. function:: addRevolution(part, base, axis_object, to_angle, from_angle) - - Args: - part (ModelAPI_Document): part document - base (list of Selection): base objects - axis_object (Selection): axis object - to_angle (double): to angle - from_angle (double): from angle - - .. function:: addRevolution(feature, base, axis_object, to_object, to_offset, from_object, from_offset) - - Args: - part (ModelAPI_Document): part document - base (list of Selection): base objects - axis_object (Selection): axis object - to_object (plane): upper plane - to_offset (double): offset from upper object - from_object (plane): lower plane - from_offset (double): offset from lower plane - - Returns: - Revolution: revolution object - """ - assert(len(args) > 0 and args[0] is not None) - feature = part.addFeature("Revolution") - return Revolution(feature, *args) - - -class Revolution(Interface): - """Interface class for Revolution features. - - .. function:: Revolution(feature) - - Create interface for the feature without initialization. - - .. function:: Revolution(feature, base, axis_object, to_angle, from_angle) - - Create interface for the feature and initialize the feature with arguments. - - .. function:: Revolution(feature, base, axis_object, to_object, to_offset, from_object, from_offset) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Revolution") - - self._base = self._feature.data().selectionList("base") - self._axis_object = self._feature.data().selection("axis_object") - self._CreationMethod = self._feature.string("CreationMethod") - self._to_angle = self._feature.data().real("to_angle") - self._from_angle = self._feature.data().real("from_angle") - self._to_object = self._feature.data().selection("to_object") - self._to_offset = self._feature.data().real("to_offset") - self._from_object = self._feature.data().selection("from_object") - self._from_offset = self._feature.data().real("from_offset") - - assert(self._base) - assert(self._axis_object) - assert(self._CreationMethod) - assert(self._to_angle) - assert(self._from_angle) - assert(self._to_object) - assert(self._to_offset) - assert(self._from_object) - assert(self._from_offset) - - if not args: - return - - assert(len(args) in (4, 6)) - - base, axis_object = args[:2] - args = args[2:] - - self.setBase(base) - self.setAxisObject(axis_object) - - if len(args) == 4: - self.setPlanesAndOffsets(*args) - elif len(args) == 2: - self.setAngles(*args) - - self.execute() - pass - - def __clear(self): - self._CreationMethod.setValue("ByAngles") - self._fillAttribute(self._to_angle, 0) - self._fillAttribute(self._from_angle, 0) - self._fillAttribute(self._to_object, None) - self._fillAttribute(self._to_offset, 0) - self._fillAttribute(self._from_object, None) - self._fillAttribute(self._from_offset, 0) - pass - - def setBase(self, base): - """Modify base attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._base, base) - pass - - def setAxisObject(self, axis_object): - """Modify axis_object attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._axis_object, axis_object) - pass - - def setAngles(self, to_angle, from_angle): - """Modify the to_angle, from_angle attributes of the feature. - - See __init__. - """ - self.__clear() - self._CreationMethod.setValue("ByAngles") - self._fillAttribute(self._to_angle, to_angle) - self._fillAttribute(self._from_angle, from_angle) - pass - - def setPlanesAndOffsets(self, to_object, to_offset, - from_object, from_offset): - """Modify planes and offsets attributes of the feature. - - See __init__. - """ - self.__clear() - self._CreationMethod.setValue("ByPlanesAndOffsets") - self._fillAttribute(self._to_object, to_object) - self._fillAttribute(self._to_offset, to_offset) - self._fillAttribute(self._from_object, from_object) - self._fillAttribute(self._from_offset, from_offset) - pass diff --git a/src/PythonAPI/model/features/revolution_boolean.py b/src/PythonAPI/model/features/revolution_boolean.py deleted file mode 100644 index d83642d0c..000000000 --- a/src/PythonAPI/model/features/revolution_boolean.py +++ /dev/null @@ -1,184 +0,0 @@ -"""RevolutionCut and RevolutionFuse Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from .roots import CompositeBoolean - - -def addRevolutionCut(part, *args): - """Add a RevolutionCut feature to the Part. - - .. function:: addRevolutionCut(part, sketch, sketch_selection, boolean_objects, axis_object, to_angle, from_angle) - - Args: - part (ModelAPI_Document): part document - sketch (ModelAPI_Object): sketch feature - sketch_selection (Selection): sketch objects - boolean_objects (list of Selection): boolean objects - axis_object (Selection): axis object - to_size (double): upper size of the extrusion - from_size (double): lower size of the extrusion - - .. function:: addRevolutionCut(part, sketch, sketch_selection, boolean_objects, axis_object, to_object, to_offset, from_object, from_offset) - - Args: - part (ModelAPI_Document): part document - sketch (ModelAPI_Object): sketch feature - sketch_selection (Selection): sketch objects - boolean_objects (list of Selection): boolean objects - axis_object (Selection): axis object - to_object (Selection): upper plane - to_offset (double): offset from upper plane - from_object (Selection): lower plane - from_offset (double): offset from lower plane - - Returns: - RevolutionBoolean: revolution boolean object - """ - assert(args) - feature = part.addFeature("RevolutionCut") - return RevolutionBoolean(feature, *args) - -def addRevolutionFuse(part, *args): - """Add a RevolutionFuse feature to the Part. - - .. function:: addRevolutionFuse(part, sketch, sketch_selection, boolean_objects, axis_object, to_angle, from_angle) - - Args: - part (ModelAPI_Document): part document - sketch (ModelAPI_Object): sketch feature - sketch_selection (Selection): sketch objects - boolean_objects (list of Selection): boolean objects - axis_object (Selection): axis object - to_size (double): upper size of the extrusion - from_size (double): lower size of the extrusion - - .. function:: addRevolutionFuse(part, sketch, sketch_selection, boolean_objects, axis_object, to_object, to_offset, from_object, from_offset) - - Args: - part (ModelAPI_Document): part document - sketch (ModelAPI_Object): sketch feature - sketch_selection (Selection): sketch objects - boolean_objects (list of Selection): boolean objects - axis_object (Selection): axis object - to_object (Selection): upper plane - to_offset (double): offset from upper plane - from_object (Selection): lower plane - from_offset (double): offset from lower plane - - - Pass all args to RevolutionFuse __init__ function. - - Returns: - RevolutionBoolean: revolution boolean object - """ - assert(args) - feature = part.addFeature("RevolutionFuse") - return RevolutionBoolean(feature, *args) - - -class RevolutionBoolean(CompositeBoolean): - """Interface class for RevolutionBoolean features. - - Supported features: - - * RevolutionCut - * RevolutionFuse - - .. function:: RevolutionBoolean(feature) - - Create interface for the feature without initialization. - - .. function:: RevolutionBoolean(feature, sketch, sketch_selection, boolean_objects, axis_object, to_angle, from_angle) - - Create interface for the feature and initialize the feature with arguments. - - .. function:: RevolutionBoolean(feature, sketch, sketch_selection, boolean_objects, axis_object, to_object, to_offset, from_object, from_offset) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - CompositeBoolean.__init__(self, feature, *args[:3]) - args = args[3:] - - self._axis_object = self._feature.data().selection("axis_object") - self._CreationMethod = self._feature.string("CreationMethod") - self._to_angle = self._feature.data().real("to_angle") - self._from_angle = self._feature.data().real("from_angle") - self._to_object = self._feature.data().selection("to_object") - self._to_offset = self._feature.data().real("to_offset") - self._from_object = self._feature.data().selection("from_object") - self._from_offset = self._feature.data().real("from_offset") - - assert(self._axis_object) - assert(self._CreationMethod) - assert(self._to_angle) - assert(self._from_angle) - assert(self._to_object) - assert(self._to_offset) - assert(self._from_object) - assert(self._from_offset) - - if not args: - return - - assert(len(args) in (3, 5)) - axis_object = args[0] - args = args[1:] - - self.setAxisObject(axis_object) - - if len(args) == 4: - self.setPlanesAndOffsets(*args) - elif len(args) == 2: - self.setAngles(*args) - - self.execute() - pass - - def __clear(self): - self._CreationMethod.setValue("ByAngles") - self._fillAttribute(self._to_angle, 0) - self._fillAttribute(self._from_angle, 0) - self._fillAttribute(self._to_object, None) - self._fillAttribute(self._to_offset, 0) - self._fillAttribute(self._from_object, None) - self._fillAttribute(self._from_offset, 0) - pass - - def setAxisObject(self, axis_object): - """Modify axis_object attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._axis_object, axis_object) - pass - - def setAngles(self, to_angle, from_angle): - """Modify the to_angle, from_angle attributes of the feature. - - See __init__. - """ - self.__clear() - self._CreationMethod.setValue("ByAngles") - self._fillAttribute(self._to_angle, to_angle) - self._fillAttribute(self._from_angle, from_angle) - pass - - def setPlanesAndOffsets(self, to_object, to_offset, - from_object, from_offset): - """Modify planes and offsets attributes of the feature. - - See __init__. - """ - self.__clear() - self._CreationMethod.setValue("ByPlanesAndOffsets") - self._fillAttribute(self._to_object, to_object) - self._fillAttribute(self._to_offset, to_offset) - self._fillAttribute(self._from_object, from_object) - self._fillAttribute(self._from_offset, from_offset) - pass - diff --git a/src/PythonAPI/model/features/roots.py b/src/PythonAPI/model/features/roots.py deleted file mode 100644 index 2aeacfe17..000000000 --- a/src/PythonAPI/model/features/roots.py +++ /dev/null @@ -1,94 +0,0 @@ - -from model.roots import Interface - - -class CompositeBoolean(Interface): - """Interface class for CompositeBoolean features. - - CompositeBoolean(feature) -> feature interface without initialization - CompositeBoolean(feature, sketch, sketch_selection, boolean_objects) -> - feature interface initialized from arguments: - - sketch - - sketch_selection - - boolean_objects - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - - self._sketch = self._feature.reference("sketch") - self._sketch_selection = self._feature.selection("sketch_selection") - self._boolean_objects = self._feature.selectionList("boolean_objects") - - assert(self._sketch) - assert(self._sketch_selection) - assert(self._boolean_objects) - - if not args: - return - - assert(len(args) == 3) - sketch, sketch_selection, boolean_objects = args - - self.setSketch(sketch) - self.setSketchSelection(sketch_selection) - self.setBooleanObjects(boolean_objects) - pass - - def setSketch(self, sketch): - """Modify sketch attribute""" - self._fillAttribute(self._sketch, sketch) - pass - - def setSketchSelection(self, sketch_selection): - """Modify sketch_selection attribute""" - self._fillAttribute(self._sketch_selection, sketch_selection) - pass - - def setBooleanObjects(self, boolean_objects): - """Modify boolean_objects attribute""" - self._fillAttribute(self._boolean_objects, boolean_objects) - pass - - -class CompositeSketch(Interface): - """Interface class for CompositeSketch features. - - CompositeSketch(feature) -> feature interface without initialization - CompositeSketch(feature, sketch, sketch_selection) -> - feature interface initialized from arguments: - - sketch - - sketch_selection - """ - - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - - self._sketch = self._feature.reference("sketch") - self._sketch_selection = self._feature.selection("sketch_selection") - - assert(self._sketch) - assert(self._sketch_selection) - - if not args: - return - - assert(len(args) == 2) - sketch, sketch_selection = args - - self.setSketch(sketch) - self.setSketchSelection(sketch_selection) - pass - - def setSketch(self, sketch): - """Modify sketch attribute""" - self._fillAttribute(self._sketch, sketch) - pass - - def setSketchSelection(self, sketch_selection): - """Modify sketch_selection attribute""" - self._fillAttribute(self._sketch_selection, sketch_selection) - pass diff --git a/src/PythonAPI/model/features/rotation.py b/src/PythonAPI/model/features/rotation.py deleted file mode 100644 index 4ec174535..000000000 --- a/src/PythonAPI/model/features/rotation.py +++ /dev/null @@ -1,86 +0,0 @@ -"""Rotation Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def addRotation(part, *args): - """Add a Rotation feature to the Part. - - .. function:: addRotation(part, main_objects, axis_object, angle) - - Args: - part (ModelAPI_Document): part document - main_objects (list of Selection): main objects - axis_object (list of Selection): axis object - angle (double): angle - - Returns: - Rotation: rotation object - """ - assert(args) - feature = part.addFeature("Rotation") - return Rotation(feature, *args) - - -class Rotation(Interface): - """Interface class for Rotation features. - - .. function:: Rotation(feature) - - Create interface for the feature without initialization. - - .. function:: Rotation(feature, main_objects, axis_object, angle) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Rotation") - - self._main_objects = self._feature.data().selectionList("main_objects") - self._axis_object = self._feature.data().selection("axis_object") - self._angle = self._feature.data().real("angle") - - assert(self._main_objects) - assert(self._axis_object) - assert(self._angle) - - if not args: - return - - assert(len(args) == 3) - self.setMainObjects(args[0]) - self.setAxisObject(args[1]) - self.setAngle(args[2]) - - self.execute() - pass - - def setMainObjects(self, main_objects): - """Modify main_objects attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._main_objects, main_objects) - pass - - def setAxisObject(self, axis_object): - """Modify axis_object attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._axis_object, axis_object) - pass - - def setAngle(self, angle): - """Modify angle attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._angle, angle) - pass diff --git a/src/PythonAPI/model/features/translation.py b/src/PythonAPI/model/features/translation.py deleted file mode 100644 index 171c988d4..000000000 --- a/src/PythonAPI/model/features/translation.py +++ /dev/null @@ -1,86 +0,0 @@ -"""Translation Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def addTranslation(part, *args): - """Add a Translation feature to the Part. - - .. function:: addTranslation(part, main_objects, axis_object, distance) - - Args: - part (ModelAPI_Document): part document - main_objects (list of Selection): main objects - axis_object (Selection): axis objects - distance (double): distance - - Returns: - Translation: translation object - """ - assert(args) - feature = part.addFeature("Translation") - return Translation(feature, *args) - - -class Translation(Interface): - """Interface class for Translation features. - - .. function:: Translation(feature) - - Create interface for the feature without initialization. - - .. function:: Translation(feature, main_objects, axis_object, distance) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Translation") - - self._main_objects = self._feature.data().selectionList("main_objects") - self._axis_object = self._feature.data().selection("axis_object") - self._distance = self._feature.data().real("distance") - - assert(self._main_objects) - assert(self._axis_object) - assert(self._distance) - - if not args: - return - - assert(len(args) == 3) - self.setMainObjects(args[0]) - self.setAxisObject(args[1]) - self.setDistance(args[2]) - - self.execute() - pass - - def setMainObjects(self, main_objects): - """Modify main_objects attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._main_objects, main_objects) - pass - - def setAxisObject(self, axis_object): - """Modify axis_object attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._axis_object, axis_object) - pass - - def setDistance(self, distance): - """Modify distance attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._distance, distance) - pass diff --git a/src/PythonAPI/model/parameter/parameter.py b/src/PythonAPI/model/parameter/parameter.py deleted file mode 100644 index 9bc5b5a07..000000000 --- a/src/PythonAPI/model/parameter/parameter.py +++ /dev/null @@ -1,76 +0,0 @@ -"""Parameter Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from model.roots import Interface - - -def addParameter(part, *args): - """Add a Parameter feature to the Part and return Parameter. - - .. function:: addParameter(part, variable, expression) - - Args: - part (ModelAPI_Document): part document - variable (string): variable name - expression (string): Python expression - - Returns: - Parameter: parameter object - - Pass all args to Parameter __init__ function. - """ - assert(args) - feature = part.addFeature("Parameter") - return Parameter(feature, *args) - - -class Parameter(Interface): - """Interface class for Parameter feature. - - .. function:: Point(feature) - - Create interface for the feature without initialization. - - .. function:: Point(feature, variable, expression) - - Create interface for the feature and initialize the feature with arguments. - """ - - def __init__(self, feature, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Parameter") - - self._variable = self._feature.string("variable") - self._expression = self._feature.string("expression") - - assert(self._variable) - assert(self._expression) - - if not args: - return - - assert(len(args) == 2) - self.setName(args[0]) - self.setExpression(args[1]) - - self.execute() - pass - - def setName(self, name): - """Modify variable name attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._variable, name) - pass - - def setExpression(self, expression): - """Modify expression attribute of the feature. - - See __init__. - """ - self._fillAttribute(self._expression, expression) - pass diff --git a/src/PythonAPI/model/partset/part.py b/src/PythonAPI/model/partset/part.py deleted file mode 100644 index 79548308d..000000000 --- a/src/PythonAPI/model/partset/part.py +++ /dev/null @@ -1,65 +0,0 @@ -"""Part Feature Interface -Author: Daniel Brunier-Coulin -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -import ModelAPI - -from model.roots import Interface - - -def addPart(partset): - """Add a Part feature to the Part and return Part. - - Args: - partset (ModelAPI_Document): partset document - - Returns: - Part: part object - """ - feature = partset.addFeature("Part") - return Part(feature) - -def duplicatePart(part): - """Create a copy of the Part. - - Args: - part (ModelAPI_Document): part document - - Returns: - Part: part object - """ - feature = part.addFeature("Duplicate") - feature.execute() - return Part(feature) - -def removePart(part): - """Remove the Part. - - Args: - part (ModelAPI_Document): part document - """ - feature = part.addFeature("Remove") - feature.execute() - - -class Part(Interface): - """Interface class for Part feature. - - .. function:: Part(feature) - - Create interface for the feature without initialization. - """ - - def __init__(self, feature): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Part") - - self.execute() - pass - - def document(self): - """Returns the Part document created by this feature.""" - result_part = ModelAPI.modelAPI_ResultPart(self._feature.firstResult()) - return result_part.partDoc() diff --git a/src/PythonAPI/model/services.py b/src/PythonAPI/model/services.py index 9fcbe3c74..e328621ea 100644 --- a/src/PythonAPI/model/services.py +++ b/src/PythonAPI/model/services.py @@ -6,9 +6,6 @@ Copyright (C) 2014-20xx CEA/DEN, EDF R&D import ModelAPI import GeomAPI -import geom # To be removed when gp_Ax3 will be Pythonized - - def moduleDocument (): """Return the main document (the Partset) created or open from the Modeler. diff --git a/src/PythonAPI/model/sketcher/arc.py b/src/PythonAPI/model/sketcher/arc.py deleted file mode 100644 index 7502a6b56..000000000 --- a/src/PythonAPI/model/sketcher/arc.py +++ /dev/null @@ -1,100 +0,0 @@ -"""Sketch circle feature interface.""" - -from GeomDataAPI import geomDataAPI_Point2D -from model.errors import WrongNumberOfArguments -from model.roots import Interface - -class Arc(Interface): - """Interface to a sketch arc feature.""" - def __init__(self, feature, *args, **kwargs): - Interface.__init__(self, feature) - assert(self._feature.getKind() == "SketchArc") - - self._center = geomDataAPI_Point2D( - self._feature.data().attribute("ArcCenter") - ) - self._start_point = geomDataAPI_Point2D( - self._feature.data().attribute("ArcStartPoint") - ) - self._end_point = geomDataAPI_Point2D( - self._feature.data().attribute("ArcEndPoint") - ) - self._inversed = self._feature.boolean("InversedArc") - if len(args) == 6: - self.__createByCoordinates(*args) - elif len(args) == 3: - self.__createByPoints(*args) - else: - raise WrongNumberOfArguments( - "Arc takes 3 or 6 arguments (%s given)" % len(args) - ) - if "inversed" in kwargs: - self.setInversed(kwargs["inversed"]) - self.execute() - - - ######## - # - # Getters - # - ######## - - - def center(self): - """Return the center point.""" - return self._center - - def startPoint(self): - """Return the start point.""" - return self._start_point - - def endPoint(self): - """Return the end point.""" - return self._end_point - - def result(self): - """Return the arc circular line attribute.""" - return self._feature.lastResult() - - - ######## - # - # Set methods - # - ######## - - def setCenter(self, x, y): - """Set arc center.""" - self._center.setValue(x, y) - - def setStartPoint(self, x, y): - """Set start point.""" - self._start_point.setValue(x, y) - - def setEndPoint(self, x, y): - """Set end point value.""" - self._end_point.setValue(x, y) - - def setInversed(self, inversed): - self._fillAttribute(self._inversed, inversed) - - ######## - # - # Private methods - # - ######## - - - def __createByCoordinates(self, center_x, center_y, - start_x, start_y, - end_x, end_y): - """Create an arc by point coordinates.""" - self.setCenter(center_x, center_y) - self.setStartPoint(start_x, start_y) - self.setEndPoint(end_x, end_y) - - def __createByPoints(self, center, start, end): - """Create an arc with point objects.""" - self.setCenter(center.x(), center.y()) - self.setStartPoint(start.x(), start.y()) - self.setEndPoint(end.x(), end.y()) diff --git a/src/PythonAPI/model/sketcher/circle.py b/src/PythonAPI/model/sketcher/circle.py deleted file mode 100644 index a3ba89a1e..000000000 --- a/src/PythonAPI/model/sketcher/circle.py +++ /dev/null @@ -1,52 +0,0 @@ -"""Sketch circle feature interface.""" - -from GeomDataAPI import geomDataAPI_Point2D -from model.roots import Interface - -class Circle(Interface): - """Interface for circle feature data manipulation.""" - def __init__(self, feature, *args): - Interface.__init__(self, feature) - assert(self._feature.getKind() == "SketchCircle") - - self._center = geomDataAPI_Point2D( - self._feature.data().attribute("CircleCenter") - ) - self._radius = self._feature.data().real("CircleRadius") - - 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): - """Set the center of the circle.""" - self._center.setValue(x, y) - - def setRadius(self, radius): - """Set the radius of the circle.""" - self._radius.setValue(radius) - - def center(self): - """Return the center attribute of the circle.""" - return self._center - - def radius(self): - """Return the radius value. - - :return: radius - :rtype: double - """ - return self._radius.value() - - def result(self): - """Return the cicular line attribute.""" - return self._feature.lastResult() diff --git a/src/PythonAPI/model/sketcher/entity.py b/src/PythonAPI/model/sketcher/entity.py deleted file mode 100644 index b2cea8803..000000000 --- a/src/PythonAPI/model/sketcher/entity.py +++ /dev/null @@ -1,15 +0,0 @@ - -from model.roots import Interface - -class Entity(Interface): - """Interface for editing of a sketch entity feature.""" - - def __init__(self, feature): - Interface.__init__(self, feature) - - # Initialize attributes - self._auxiliary = self._feature.boolean("Auxiliary") - - def setAuxiliary(self, a): - """Set the Auxiliarity.""" - self._auxiliary.setValue(a) diff --git a/src/PythonAPI/model/sketcher/line.py b/src/PythonAPI/model/sketcher/line.py deleted file mode 100644 index 128e7b3c8..000000000 --- a/src/PythonAPI/model/sketcher/line.py +++ /dev/null @@ -1,78 +0,0 @@ -from GeomDataAPI import geomDataAPI_Point2D -from model.roots import Interface -from model.errors import WrongNumberOfArguments - -from .entity import Entity - -class Line(Entity): - """Interface for editing of a sketch line feature.""" - def __init__(self, feature, *args): - Entity.__init__(self, feature) - assert(self._feature.getKind() == "SketchLine") - - # Initialize attributes - self._start_point = geomDataAPI_Point2D( - self._feature.data().attribute("StartPoint") - ) - self._end_point = geomDataAPI_Point2D( - self._feature.data().attribute("EndPoint") - ) - self._external = self._feature.selection("External") - - # If no arguments are given the attributes of the feature - # are'nt initialized - if args is None: - return - - # Set attribute values and execute - if len(args) == 4: - self.__createByCoordinates(*args) - elif len(args) == 2: - self.__createByPoints(*args) - elif len(args) == 1: - self.__createByName(*args) - else: - raise WrongNumberOfArguments( - "Arc takes 1, 2 or 4 arguments (%s given)" % len(args) - ) - self.execute() - - def __createByCoordinates(self, x1, y1, x2, y2): - self.setStartPoint(x1, y1) - self.setEndPoint(x2, y2) - - def __createByPoints(self, p1, p2): - self.setStartPoint(p1.x(), p1.y()) - self.setEndPoint(p2.x(), p2.y()) - - def __createByName(self, name): - self.setExternal(name) - - ####### - # - # Set methods - # - ####### - - def setStartPoint(self, x, y): - """Set the start point of the line.""" - self._start_point.setValue(x, y) - - def setEndPoint(self, x, y): - """Set the end point of the line.""" - self._end_point.setValue(x, y) - - # TODO : methods below will be removed. - # Kept until all tests have been updated - def startPoint(self): - return self._start_point - - def endPoint(self): - return self._end_point - - def setExternal(self, name): - """Set external edge""" - self._external.selectSubShape("EDGE", name) - - def result(self): - return self._feature.firstResult() diff --git a/src/PythonAPI/model/sketcher/mirror.py b/src/PythonAPI/model/sketcher/mirror.py deleted file mode 100644 index dba62b4ad..000000000 --- a/src/PythonAPI/model/sketcher/mirror.py +++ /dev/null @@ -1,32 +0,0 @@ -"""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() - #) - diff --git a/src/PythonAPI/model/sketcher/point.py b/src/PythonAPI/model/sketcher/point.py deleted file mode 100644 index ce6c2839a..000000000 --- a/src/PythonAPI/model/sketcher/point.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Sketch point feature interface.""" - -from GeomDataAPI import geomDataAPI_Point2D -from model.roots import Interface -from model.errors import FeatureInputInvalid - -class Point(Interface): - """Interface on point feature for data manipulation.""" - def __init__(self, feature, x, y): - Interface.__init__(self, feature) - assert(self._feature.getKind() == "SketchPoint") - - # Initialize attributes of the feature - self._point_data = geomDataAPI_Point2D( - self._feature.data().attribute("PointCoordindates") - ) - self.setValue(x, y) - self.execute() - - def setValue(self, x, y): - """Set point coordinates.""" - self._point_data.setValue(x, y) - - def pointData (self): - """Return the point data.""" - return self._point_data - - def result (self): - """Return the feature result.""" - return self._point_feature.firstResult() diff --git a/src/PythonAPI/model/sketcher/sketch.py b/src/PythonAPI/model/sketcher/sketch.py deleted file mode 100644 index 611e5d2ac..000000000 --- a/src/PythonAPI/model/sketcher/sketch.py +++ /dev/null @@ -1,458 +0,0 @@ -# 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 - -"""Sketcher interface. -This interface allows to add a sketch -in a part or partset. -The created sketch object provides all the needed methods -for sketch modification and constraint edition. - -Example of code: - -.. doctest:: - - >>> import model - >>> model.begin() - >>> partset = model.moduleDocument() - >>> part = model.addPart(partset).document() - >>> plane = model.defaultPlane("XOY") - >>> sketch = model.addSketch(part, plane) - >>> line = sketch.addLine(0, 0, 0, 1) - >>> line.endPoint().x() - 0.0 - >>> line.endPoint().y() - 1.0 -""" - -from ModelAPI import modelAPI_ResultConstruction, featureToCompositeFeature -from GeomDataAPI import geomDataAPI_Point, geomDataAPI_Dir -from GeomAlgoAPI import GeomAlgoAPI_SketchBuilder, ShapeList - -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 - - -def addSketch(document, plane): - """Add a sketch to a Part or PartSet. - - Arguments: - document(ModelAPI_Document): part or partset document - plane(geom.Ax3): plane on wich the sketch is built - - Returns: - Sketch: sketch object - """ - feature = featureToCompositeFeature(document.addFeature("Sketch")) - return Sketch(feature, plane) - -class Sketch(Interface): - """Interface class for Sketch feature.""" - def __init__(self, feature, *args): - """Initialize a 2D Sketch on the given plane. - - The plane can be defined either by: - - a 3D axis system (geom.Ax3), - - an existing face identified by its topological name. - """ - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Sketch") - - self._origin = geomDataAPI_Point( - self._feature.data().attribute("Origin") - ) - self._dir_x = geomDataAPI_Dir( - self._feature.data().attribute("DirX") - ) - self._norm = geomDataAPI_Dir( - self._feature.data().attribute("Norm") - ) - self._external = self._feature.data().selection("External") - - # If no arguments are given the attributes of the feature - # are not Initialized - if args is not None: - plane = args[0] - if isinstance(plane, str): - self.__sketchOnFace(plane) - else: - self.__sketchOnPlane(plane) - - def __sketchOnPlane(self, plane): - """Create the sketch on a plane.""" - origin = plane.location() - normal = plane.direction() - x_direction = plane.xDirection() - self._origin.setValue(origin.x(), origin.y(), origin.z()) - self._norm.setValue(normal.x(), normal.y(), normal.z()) - self._dir_x.setValue(x_direction.x(), x_direction.y(), x_direction.z()) - - def __sketchOnFace(self, name): - """Initialize the sketch on a face given by its name.""" - self._external.selectSubShape("FACE", name) - - #------------------------------------------------------------- - # - # Creation of Geometries - # - #------------------------------------------------------------- - - def addPoint(self, *args): - """Add a point to the sketch.""" - if not args: - raise TypeError("No arguments given") - point_feature = self._feature.addFeature("SketchPoint") - return Point(point_feature, *args) - - def addLine(self, *args): - """Add a line to the sketch. - - .. function:: addLine(name) - Select an existing line. The line is added to the sketch with a rigid - constraint (it cannot be modified by the sketch) - - Arguments: - name(str): name of an existing line - - .. function:: addLine(start, end) - Create a line by points - - Arguments: - start(point): start point of the line - end(point): end point of the line - - .. function:: addLine(start_x, start_y, end_x, end_y) - Create a line by coordinates - - Arguments: - start_x(double): start point x coordinate - """ - if not args: - raise TypeError("No arguments given") - line_feature = self._feature.addFeature("SketchLine") - line_interface = Line(line_feature, *args) - # if the line is created by name add a rigid constraint - # to the created line - if len(args) == 1 and isinstance(args[0], str): - constraint = self._feature.addFeature("SketchConstraintRigid") - constraint.refattr("ConstraintEntityA").setObject( - line_feature.firstResult() - ) - return line_interface - - def addCircle(self, *args): - """Add a circle to this Sketch.""" - if not args: - raise TypeError("No arguments given") - circle_feature = self._feature.addFeature("SketchCircle") - return Circle(circle_feature, *args) - - def addArc(self, *args, **kwargs): - """Add an arc of circle to the sketch and return an arc object. - - Two different syntaxes are allowed: - - .. function:: addArc(center, start, end) - - Arguments: - center (point): center of the arc - start (point): start point of the arc - end (point): end point of the arc - - .. function:: addArc(center_x, center_y, start_x, start_y, end_x, end_y) - - Same as above but with coordinates - - Returns: - Arc: arc object - Raises: - TypeError: if no argument is provided - """ - if not args: - raise TypeError("No arguments given") - arc_feature = self._feature.addFeature("SketchArc") - return Arc(arc_feature, *args, **kwargs) - - #------------------------------------------------------------- - # - # Creation of Geometrical and Dimensional Constraints - # - #------------------------------------------------------------- - - def setCoincident(self, p1, p2): - """Set coincident the two given points and add the corresponding - constraint to this Sketch.""" - # assert(p1 and p2) NOTE : if an argument is missing python - # will raise TypeError by itself. - # It seems better to check only that provided arguments are not - # None - if p1 is None or p2 is None: - raise TypeError("NoneType argument given") - constraint = self._feature.addFeature("SketchConstraintCoincidence") - self._fillAttribute(constraint.refattr("ConstraintEntityA"), p1) - self._fillAttribute(constraint.refattr("ConstraintEntityB"), p2) - self.execute() - return constraint - - def setParallel(self, l1, l2): - """Set parallel the two given lines and add the corresponding - constraint to this Sketch.""" - if l1 is None or l2 is None: - raise TypeError("NoneType argument given") - constraint = self._feature.addFeature("SketchConstraintParallel") - constraint.data().refattr("ConstraintEntityA").setObject(l1) - constraint.data().refattr("ConstraintEntityB").setObject(l2) - self.execute() - return constraint - - def setPerpendicular(self, l1, l2): - """Set perpendicular the two given lines and add the corresponding - constraint to this Sketch.""" - if l1 is None or l2 is None: - raise TypeError("NoneType argument given") - constraint = self._feature.addFeature("SketchConstraintPerpendicular") - constraint.data().refattr("ConstraintEntityA").setObject(l1) - constraint.data().refattr("ConstraintEntityB").setObject(l2) - self.execute() - return constraint - - def setHorizontal(self, line): - """Set horizontal the given line and add the corresponding - constraint to this Sketch.""" - if line is None: - raise TypeError("NoneType argument given") - constraint = self._feature.addFeature("SketchConstraintHorizontal") - constraint.data().refattr("ConstraintEntityA").setObject(line) - self.execute() - return constraint - - def setVertical(self, line): - """Set vertical the given line and add the corresponding - constraint to this Sketch.""" - if line is None: - raise TypeError("NoneType argument given") - constraint = self._feature.addFeature("SketchConstraintVertical") - constraint.data().refattr("ConstraintEntityA").setObject(line) - self.execute() - return constraint - - def setDistance(self, point, line, length): - """Set the distance between the given point and line, and add - the corresponding constraint to this Sketch.""" - if point is None or line is None: - raise TypeError("NoneType argument given") - constraint = self._feature.addFeature("SketchConstraintDistance") - if isinstance(line, basestring): - # Add the edge identified by the given topological name - # to this Sketch - line = self.addLine(line).result() - constraint.data().refattr("ConstraintEntityA").setAttr(point) - constraint.data().refattr("ConstraintEntityB").setObject(line) - constraint.data().real("ConstraintValue").setValue(length) - self.execute() - return constraint - - def setLength(self, line, length): - """Set the length of the given line and add the corresponding - constraint to this Sketch.""" - if line is None: - raise TypeError("NoneType argument given") - constraint = self._feature.addFeature("SketchConstraintLength") - constraint.data().refattr("ConstraintEntityA").setObject(line) - self._fillAttribute(constraint.real("ConstraintValue"), length) - self.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") - self._fillAttribute(constraint.refattr("ConstraintEntityA"), circle) - self._fillAttribute(constraint.real("ConstraintValue"), radius) - self.execute() - 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.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.""" - constraint = self._feature.addFeature("SketchConstraintAngle") - constraint.data().refattr("ConstraintEntityA").setObject(line_1) - constraint.data().refattr("ConstraintEntityB").setObject(line_2) - constraint.data().real("ConstraintValue").setValue(angle) - self.execute() - return constraint - - 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) - self.execute() - return constraint - - def setFillet(self, *args): - """Set a fillet constraint between the 2 given lines with the given - filleting radius.""" - assert(args) - constraint = self._feature.addFeature("SketchConstraintFillet") - if len(args) == 3: - line_1, line_2, radius = args - constraint.data().refattr("ConstraintEntityA").setObject(line_1) - constraint.data().reflist("ConstraintEntityB").clear() - constraint.data().reflist("ConstraintEntityB").append(line_2) - elif len(args) == 2: - point, radius = args - self._fillAttribute(constraint.data().refattrlist("ConstraintEntityA"), [point]) - self._fillAttribute(constraint.real("ConstraintValue"), radius) - self.execute() - return constraint - - def setRigid(self, object_): - """Set a rigid constraint on a given object.""" - constraint = self._feature.addFeature("SketchConstraintRigid") - self._fillAttribute(constraint.refattr("ConstraintEntityA"), 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 - - - #------------------------------------------------------------- - # - # Edition of Dimensional Constraints - # - #------------------------------------------------------------- - - def setValue(self, constraint, value): - """Modify the value of the given dimensional constraint.""" - constraint.data().real("ConstraintValue").setValue(value) - - #------------------------------------------------------------- - # - # Edition of Dimensional Constraints - # - #------------------------------------------------------------- - - def setText(self, constraint, text): - """Modify the value of the given dimensional constraint.""" - constraint.data().real("ConstraintValue").setText(text) - - #------------------------------------------------------------- - # - # Macro functions combining geometry creation and constraints - # - #------------------------------------------------------------- - - def addPolyline(self, *coords): - """Add a poly-line to this Sketch. - - The end of consecutive segments are defined as coincident. - """ - c0 = coords[0] - c1 = coords[1] - polyline = [] - line_1 = self.addLine(c0, c1) - polyline.append(line_1) - # Adding and connecting next lines - for c2 in coords[2:]: - line_2 = self.addLine(c1, c2) - self.setCoincident(line_1.endPoint(), line_2.startPoint()) - polyline.append(line_2) - c1 = c2 - line_1 = line_2 - return polyline - - def addPolygon(self, *coords): - """Add a polygon to this Sketch. - - The end of consecutive segments are defined as coincident. - """ - pg = self.addPolyline(*coords) - # Closing the poly-line supposed being defined by at least 3 points - c0 = coords[0] - cn = coords[len(coords) - 1] - ln = self.addLine(cn, c0) - self.setCoincident( - pg[len(coords) - 2].endPoint(), ln.startPoint() - ) - self.setCoincident( - ln.endPoint(), pg[0].startPoint() - ) - pg.append(ln) - return pg - - #------------------------------------------------------------- - # - # Getters - # - #------------------------------------------------------------- - - def selectFace(self, *args): - """Select the geometrical entities of this Sketch on which - the result Face must be built. - - When no entity is given, the face is based on all existing - geometry of this Sketch. - """ - if len(args) == 0: - wire = modelAPI_ResultConstruction( - self._feature.firstResult() - ).shape() - elif len(args) == 1: - wire = args[0].shape() - else: - raise Exception("not yet implemented") - # TODO: simple version now, should be a list of selected faces - return [Selection(self.result(), self.buildShape(wire))] - - def buildShape(self, wire): - """Build the result Shape of this Sketch according to the - selected geometrical entities.""" - o = self._origin.pnt() - dx = self._dir_x.dir() - n = self._norm.dir() - - # The faces are kept otherwise they are destroyed at exit - faces = ShapeList() - GeomAlgoAPI_SketchBuilder.createFaces(o, dx, n, wire, faces) - # TODO: Deal with several faces - return faces[0] - - def result(self): - """Returns the result data of this Feature.""" - return self._feature.firstResult() diff --git a/src/PythonAPI/model/tools.py b/src/PythonAPI/model/tools.py deleted file mode 100644 index cde3e64bf..000000000 --- a/src/PythonAPI/model/tools.py +++ /dev/null @@ -1,139 +0,0 @@ -"""Common tools for other modules. -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -import re -import collections - -import ModelAPI -import GeomAPI -import GeomDataAPI - -# from .sketcher.sketch import Sketch - - -def convert_to_underscore(name): - """Convert CamelCase to underscore_case.""" - s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) - return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() - - -class Selection: - """Class for selection. - - Selection() -> empty selection - Selection(name, type) -> selection initialized with arguments: - - name -- topological name - - type -- type of the object - Selection(context, shape) -> selection initialized with arguments: - - context -- ModelAPI_Result object - - shape -- GeomAPI_Shape shape - """ - - def __init__(self, *args): - """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" - - if not args: - self.args = (None, None) - return - - if len(args) == 1 and isinstance(args[0], basestring): - self.args = args - return - - assert(len(args) > 1 and len(args) < 4) - assert(isinstance(args[0], basestring) or - isinstance(args[0], ModelAPI.ModelAPI_Result)) - if isinstance(args[0], basestring): - assert(isinstance(args[1], basestring)) - elif isinstance(args[0], ModelAPI.ModelAPI_Result) or args[0] is None: - assert(isinstance(args[1], GeomAPI.GeomAPI_Shape)) - self.args = args - - -def fill_attribute(attribute, value): - """Set value to attribure. - - This function processes complex cases. - ModelAPI_AttributeSelectionList can accept string, result + shape, list of - strings and [result + shape]... - ModelAPI_AttributeDouble can accept float and string - """ - if (isinstance(attribute, ModelAPI.ModelAPI_AttributeBoolean) or - isinstance(attribute, ModelAPI.ModelAPI_AttributeDocRef) or - isinstance(attribute, ModelAPI.ModelAPI_AttributeReference) - ): - attribute.setValue(value) - - elif isinstance(attribute, ModelAPI.ModelAPI_AttributeString): - attribute.setValue(str(value)) - - elif (isinstance(attribute, ModelAPI.ModelAPI_AttributeDouble) or - isinstance(attribute, ModelAPI.ModelAPI_AttributeInteger) - ): - if isinstance(value, basestring): - attribute.setText(value) - else: - attribute.setValue(value) - - elif isinstance(attribute, ModelAPI.ModelAPI_AttributeIntArray): - attrubute.setSize(len(value)) - for i in range(len(value)): - attrubute.setValue(i, value[i]) - - elif isinstance(attribute, ModelAPI.ModelAPI_AttributeRefAttr): - assert(isinstance(value, ModelAPI.ModelAPI_Attribute) or - isinstance(value, ModelAPI.ModelAPI_Object)) - if isinstance(value, ModelAPI.ModelAPI_Attribute): - attribute.setAttr(value) - elif isinstance(value, ModelAPI.ModelAPI_Object): - attribute.setObject(value) - - elif isinstance(attribute, ModelAPI.ModelAPI_AttributeRefList): - attribute.clear() - if not value: - return - - assert(isinstance(value, collections.Iterable)) - for item in value: - assert(isinstance(item, ModelAPI.ModelAPI_Object)) - attribute.append(item) - - elif isinstance(attribute, ModelAPI.ModelAPI_AttributeRefAttrList): - attribute.clear() - if not value: - return - - assert(isinstance(value, collections.Iterable)) - for item in value: - assert(isinstance(item, ModelAPI.ModelAPI_Attribute)) - attribute.append(item) - - elif isinstance(attribute, ModelAPI.ModelAPI_AttributeSelection): - if value is None: - attribute.setValue(None, None) - return - - assert(isinstance(value, Selection)) - attribute.setValue(*value.args) - - elif isinstance(attribute, ModelAPI.ModelAPI_AttributeSelectionList): - attribute.clear() - if not value: - return - - assert(isinstance(value, collections.Iterable)) - for item in value: - assert(isinstance(item, Selection)) - attribute.append(*item.args) - - elif (isinstance(attribute, GeomDataAPI.GeomDataAPI_Dir) or - isinstance(attribute, GeomDataAPI.GeomDataAPI_Point) or - isinstance(attribute, GeomDataAPI.GeomDataAPI_Point2D) - ): - assert(isinstance(value, collections.Iterable)) - attribute.setValue(*value) - - else: - raise AssertionError("Wrong attribute type: %s" % type(attribute)) -- 2.39.2