From 30a17e379531d6858712a651b847b3b079d212f2 Mon Sep 17 00:00:00 2001 From: spo Date: Mon, 2 Nov 2015 17:15:36 +0300 Subject: [PATCH] Improve PythonAPI documentstion. --- src/PythonAPI/extension/box.py | 20 +++++++-- src/PythonAPI/model/__init__.py | 1 + src/PythonAPI/model/construction/axis.py | 25 +++++------ src/PythonAPI/model/construction/plane.py | 25 +++++------ src/PythonAPI/model/construction/point.py | 17 ++++--- src/PythonAPI/model/exchange/exchange.py | 38 ++++++++-------- src/PythonAPI/model/features/boolean.py | 18 +++++++- src/PythonAPI/model/features/extrusion.py | 44 ++++++++++--------- .../model/features/extrusion_boolean.py | 29 ++++++++++++ .../model/features/extrusion_sketch.py | 24 +++++++++- src/PythonAPI/model/features/group.py | 8 ++++ src/PythonAPI/model/features/partition.py | 21 +++++---- src/PythonAPI/model/features/placement.py | 13 ++++++ src/PythonAPI/model/features/revolution.py | 41 +++++++++-------- .../model/features/revolution_boolean.py | 29 ++++++++++++ .../model/features/revolution_sketch.py | 23 ++++++++++ src/PythonAPI/model/features/roots.py | 25 +++++++++++ src/PythonAPI/model/features/rotation.py | 10 +++++ src/PythonAPI/model/features/translation.py | 10 +++++ src/PythonAPI/model/parameter/parameter.py | 19 ++++---- src/PythonAPI/model/partset/part.py | 6 ++- src/PythonAPI/model/roots.py | 17 +++++-- src/PythonAPI/model/sketcher/sketch.py | 2 +- src/PythonAPI/model/tools.py | 14 +++++- src/PythonAddons/addons_Features.py | 6 +++ src/PythonAddons/macros/box/feature.py | 22 ++++++++-- 26 files changed, 374 insertions(+), 133 deletions(-) diff --git a/src/PythonAPI/extension/box.py b/src/PythonAPI/extension/box.py index 4cdfa75a2..6808cd441 100644 --- a/src/PythonAPI/extension/box.py +++ b/src/PythonAPI/extension/box.py @@ -7,15 +7,26 @@ from model import Interface from macros.box.feature import BoxFeature as MY -def addBox(container, *args): - feature = container.addFeature(MY.ID()) +def addBox(part, *args): + """Add Box feature to the part and return Box. + + Pass all args to Box __init__ function. + """ + feature = part.addFeature(MY.ID()) return Box(feature, *args) class Box(Interface): - """Executes the macro-feature Box.""" + """Executes the macro-feature Box. + + Box(feature) -> feature interface without initialization + Extrusion(feature, dx, dy, dz) -> + feature interface initialized from arguments: + - dx, dy, dz -- box dimensions + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == MY.ID()) @@ -40,13 +51,16 @@ class Box(Interface): pass def setWidth(self, width): + """B.setWidth(float) -- modify width attribute""" self._fill_attribute(self._width, width) pass def setLength(self, length): + """B.setLength(float) -- modify length attribute""" self._fill_attribute(self._length, length) pass def setHeight(self, height): + """B.setHeight(float) -- modify height attribute""" self._fill_attribute(self._height, height) pass diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index 26c520ca0..3a8c553ae 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -15,6 +15,7 @@ from tools import Selection # Built-in features from sketcher.sketch import addSketch +from connection import * from construction import * from exchange import * from features import * diff --git a/src/PythonAPI/model/construction/axis.py b/src/PythonAPI/model/construction/axis.py index 9152310b6..0afedf9bb 100644 --- a/src/PythonAPI/model/construction/axis.py +++ b/src/PythonAPI/model/construction/axis.py @@ -16,21 +16,20 @@ def addAxis(part, *args): class Axis(Interface): - """Interface on an Axis feature.""" + """Interface class for Axis feature. + + Axis(feature) -> feature interface without initialization + Axis(feature, p1, p2) -> + feature interface initialized from arguments: + - p1 -- FirstPoint + - p2 -- SecondPoint + Axis(feature, face) -> + feature interface initialized from arguments: + - face -- CylindricalFace + """ def __init__(self, feature, *args): - """Initialize an Axis feature with given parameters. - - Expected arguments for all modes: - feature -- a Axis feature - - For AxisByPointsCase mode (expect 2 arguments): - p1 -- FirstPoint - p2 -- SecondPoint - - For AxisByCylindricalFaceCase mode (expect 1 argument): - face -- CylindricalFace - """ + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Axis") diff --git a/src/PythonAPI/model/construction/plane.py b/src/PythonAPI/model/construction/plane.py index 0da506006..b2144d9ec 100644 --- a/src/PythonAPI/model/construction/plane.py +++ b/src/PythonAPI/model/construction/plane.py @@ -16,21 +16,20 @@ def addPlane(part, *args): class Plane(Interface): - """Interface on a Plane feature.""" + """Interface class for Plane feature. + + Plane(feature) -> feature interface without initialization + Plane(feature, face, distance) -> + feature interface initialized from arguments: + - face -- planeFace + - distance -- distance + Plane(feature, a, b, c, d) -> + feature interface initialized from arguments: + - A, B, C, D -- GeneralEquation parameters + """ def __init__(self, feature, *args): - """Initialize a Plane feature with given parameters. - - Expected arguments for all modes: - feature -- a Plane feature - - For PlaneByFaceAndDistance mode (expect 2 arguments): - face -- planeFace - distance -- distance - - For PlaneByGeneralEquation mode (expect 4 arguments): - A, B, C, D -- GeneralEquation parameters - """ + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Plane") diff --git a/src/PythonAPI/model/construction/point.py b/src/PythonAPI/model/construction/point.py index fa81fcf1f..d2448bc67 100644 --- a/src/PythonAPI/model/construction/point.py +++ b/src/PythonAPI/model/construction/point.py @@ -16,17 +16,16 @@ def addPoint(part, *args): class Point(Interface): - """Interface on an Point feature.""" + """Interface class for Point feature. - def __init__(self, feature, *args): - """Initialize an Point feature with given parameters. - - Expected arguments for all modes: - feature -- a Point feature + Point(feature) -> feature interface without initialization + Point(feature, x, y, z) -> + feature interface initialized from arguments: + - x, y, z -- coordinates for the point + """ - Expected arguments for initializing the feature: - x, y, z -- x, y, z coordinates for the point. - """ + def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Point") diff --git a/src/PythonAPI/model/exchange/exchange.py b/src/PythonAPI/model/exchange/exchange.py index 375c6fd01..a7b7daa0e 100644 --- a/src/PythonAPI/model/exchange/exchange.py +++ b/src/PythonAPI/model/exchange/exchange.py @@ -16,17 +16,16 @@ def addImport(part, *args): class Import(Interface): - """Interface on an Import feature.""" + """Interface class for Import feature. - def __init__(self, feature, *args): - """Initialize an Import feature with given parameters. - - Expected arguments for all modes: - feature -- an Import feature + Import(feature) -> feature interface without initialization + Import(feature, file_path) -> + feature interface initialized from arguments: + - file_path -- path to the imported file + """ - For initialization (expect 1 argument): - file_path -- path to the imported file - """ + def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Import") @@ -62,19 +61,18 @@ def exportToFile(part, *args): class Export(Interface): - """Interface on an Export feature.""" + """Interface class for Export feature. + + Export(feature) -> feature interface without initialization + Export(feature, file_path, file_format, selection_list) -> + feature interface initialized from arguments: + - file_path -- path to the exported file + - file_format -- format of to the exported file + - selection_list -- objects to export + """ def __init__(self, feature, *args): - """Initialize an Export feature with given parameters. - - Expected arguments for all modes: - feature -- an Export feature - - For initialization (expect 3 argument): - file_path -- path to the exported file - file_format -- format of to the exported file - objects -- objects to export - """ + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Export") diff --git a/src/PythonAPI/model/features/boolean.py b/src/PythonAPI/model/features/boolean.py index 78cfbefb8..d746ffefd 100644 --- a/src/PythonAPI/model/features/boolean.py +++ b/src/PythonAPI/model/features/boolean.py @@ -35,8 +35,15 @@ def addIntersection(part, object, tool): class Boolean(Interface): - """Abstract root class of Boolean Features.""" + """Interface class for Boolean features. + + Boolean(feature) -> feature interface without initialization + Boolean(feature, main_objects, tool_objects, bool_type) -> + feature interface initialized from 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") @@ -62,13 +69,22 @@ class Boolean(Interface): pass def setMainObjects(self, main_objects): + """F.setMainObjects(iterable) -- modify main_objects attribute""" self._fill_attribute(self._main_objects, main_objects) pass def setToolObjects(self, tool_objects): + """F.setToolObjects(iterable) -- modify tool_objects attribute""" self._fill_attribute(self._tool_objects, tool_objects) pass def setBoolType(self, bool_type): + """F.setBoolType(integer) -- modify bool_type attribute. + + Available types: + - GeomAlgoAPI_Boolean.BOOL_FUSE + - GeomAlgoAPI_Boolean.BOOL_CUT + - GeomAlgoAPI_Boolean.BOOL_COMMON + """ self._fill_attribute(self._bool_type, bool_type) pass diff --git a/src/PythonAPI/model/features/extrusion.py b/src/PythonAPI/model/features/extrusion.py index 0f1cbea83..a6a18ee02 100644 --- a/src/PythonAPI/model/features/extrusion.py +++ b/src/PythonAPI/model/features/extrusion.py @@ -18,28 +18,29 @@ def addExtrusion(part, *args): class Extrusion(Interface): - """Interface on an Extrusion feature.""" + """Interface class for Extrusion feature. + + 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 + """ def __init__(self, feature, *args): - """Initialize an Extrusion feature with given parameters. - - Expected arguments for all modes: - feature -- an Extrusion feature - - Expected arguments for initializing the feature: - base -- name, sketch or list of names and sketches. - If base is None then don't change the feature. - - For BySize mode (expect 2 arguments): - to_size -- upper size - from_size -- lower size - - For ByPlanesAndOffsets mode (expect 4 arguments): - to_object -- upper object (plane) - to_offset -- offset from upper object - from_object -- lower object (plane) - from_offset -- offset from lower object - """ + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Extrusion") @@ -104,7 +105,7 @@ class Extrusion(Interface): See __init__. """ self.__clear() - self._CreationMethod.setValue("BySizes") + self._fill_attribute(self._CreationMethod, "BySizes") self._fill_attribute(self._to_size, to_size) self._fill_attribute(self._from_size, from_size) pass @@ -139,4 +140,5 @@ class Extrusion(Interface): 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 index f7e168fde..a5b4d1e09 100644 --- a/src/PythonAPI/model/features/extrusion_boolean.py +++ b/src/PythonAPI/model/features/extrusion_boolean.py @@ -26,8 +26,37 @@ def addExtrusionFuse(part, *args): class ExtrusionBoolean(CompositeBoolean): + """Interface class for ExtrusionBoolean features. + + Supported features: + - ExtrusionCut + - ExtrusionFuse + + ExtrusionBoolean(feature) -> feature interface without initialization + ExtrusionBoolean(feature, + sketch, sketch_selection, boolean_objects, + to_size, from_size) -> + feature interface initialized from arguments: + - sketch + - sketch_selection + - boolean_objects + - to_size + - from_size + ExtrusionBoolean(feature, + sketch, sketch_selection, boolean_objects, + to_object, to_offset, from_object, from_offset) -> + feature interface initialized from arguments: + - sketch + - sketch_selection + - boolean_objects + - to_object + - to_offset + - from_object + - from_offset + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" CompositeBoolean.__init__(self, feature, *args[:3]) args = args[3:] diff --git a/src/PythonAPI/model/features/extrusion_sketch.py b/src/PythonAPI/model/features/extrusion_sketch.py index bf8ae8fe1..fdd436874 100644 --- a/src/PythonAPI/model/features/extrusion_sketch.py +++ b/src/PythonAPI/model/features/extrusion_sketch.py @@ -17,8 +17,30 @@ def addExtrusionSketch(part, *args): class ExtrusionSketch(CompositeSketch): - + """Interface class for ExtrusionSketch feature. + + ExtrusionSketch(feature) -> feature interface without initialization + ExtrusionSketch(feature, + sketch, sketch_selection, + to_size, from_size) -> + feature interface initialized from arguments: + - sketch + - sketch_selection + - to_size + - from_size + ExtrusionSketch(feature, + sketch, sketch_selection, + to_object, to_offset, from_object, from_offset) -> + feature interface initialized from arguments: + - sketch + - sketch_selection + - to_object + - to_offset + - from_object + - from_offset + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" CompositeSketch.__init__(self, feature, *args[:2]) args = args[2:] diff --git a/src/PythonAPI/model/features/group.py b/src/PythonAPI/model/features/group.py index e6a7602ac..d0c4207e6 100644 --- a/src/PythonAPI/model/features/group.py +++ b/src/PythonAPI/model/features/group.py @@ -17,8 +17,16 @@ def addGroup(part, *args): class Group(Interface): + """Interface class for Group feature. + + Group(feature) -> feature interface without initialization + Group(feature, group_list) -> + feature interface initialized from arguments: + - group_list + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Group") diff --git a/src/PythonAPI/model/features/partition.py b/src/PythonAPI/model/features/partition.py index f1064152c..04876d232 100644 --- a/src/PythonAPI/model/features/partition.py +++ b/src/PythonAPI/model/features/partition.py @@ -17,19 +17,18 @@ def addPartition(part, *args): class Partition(Interface): - """Interface on an Partition feature.""" + """Interface class for Partition feature. + + Partition(feature) -> feature interface without initialization + Partition(feature, main_objects, tool_objects, partition_combine) -> + feature interface initialized from arguments: + - main_objects -- list of solids + - tool_objects -- list of solids + - partition_combine -- boolean value + """ def __init__(self, feature, *args): - """Initialize an Partition feature with given parameters. - - Expected arguments: - feature -- an Partition feature - - Expected arguments for initializing the feature: - main_objects -- list of solids. - tool_objects -- list of solids. - partition_combine -- boolean value. - """ + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Partition") diff --git a/src/PythonAPI/model/features/placement.py b/src/PythonAPI/model/features/placement.py index ab8ac046f..258389e97 100644 --- a/src/PythonAPI/model/features/placement.py +++ b/src/PythonAPI/model/features/placement.py @@ -17,8 +17,21 @@ def addPlacement(part, *args): class Placement(Interface): + """Interface class for Placement feature. + + Placement(feature) -> feature interface without initialization + Placement(feature, objects_list, start_shape, end_shape, + reverse_direction, centering) -> + feature interface initialized from arguments: + - objects_list + - start_shape + - end_shape + - reverse_direction + - centering + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Placement") diff --git a/src/PythonAPI/model/features/revolution.py b/src/PythonAPI/model/features/revolution.py index 6b0fdd21a..662190a1b 100644 --- a/src/PythonAPI/model/features/revolution.py +++ b/src/PythonAPI/model/features/revolution.py @@ -17,29 +17,28 @@ def addRevolution(part, *args): class Revolution(Interface): - """Interface on an Revolution feature.""" + """Interface class for Revolution features. + + Revolution(feature) -> feature interface without initialization + Revolution(feature, base, axis_object, to_angle, from_angle) -> + feature interface initialized from arguments: + - base -- name, sketch or list of names and sketches + - axis_object -- name, edge for axis + - to_angle -- upper angle + - from_angle -- lower angle + Revolution(feature, base, axis_object, + to_object, to_offset, from_object, from_offset) -> + feature interface initialized from arguments: + - base -- name, sketch or list of names and sketches + - axis_object -- name, edge for axis + - to_object -- upper object (plane) + - to_offset -- offset from upper object + - from_object -- lower object (plane) + - from_offset -- offset from lower object + """ def __init__(self, feature, *args): - """Initialize an Revolution feature with given parameters. - - Expected arguments for all modes: - feature -- an Revolution feature - - Expected arguments for initializing the feature: - base -- name, sketch or list of names and sketches. - If base is None then don't change the feature. - axis_object -- name, edge for axis - - For ByAngles mode (expect 2 arguments): - to_angle -- upper angle - from_angle -- lower angle - - For ByPlanesAndOffsets mode (expect 4 arguments): - to_object -- upper object (plane) - to_offset -- offset from upper object - from_object -- lower object (plane) - from_offset -- offset from lower object - """ + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Revolution") diff --git a/src/PythonAPI/model/features/revolution_boolean.py b/src/PythonAPI/model/features/revolution_boolean.py index d93b9f034..2b80d0c88 100644 --- a/src/PythonAPI/model/features/revolution_boolean.py +++ b/src/PythonAPI/model/features/revolution_boolean.py @@ -26,8 +26,37 @@ def addRevolutionFuse(part, *args): class RevolutionBoolean(CompositeBoolean): + """Interface class for RevolutionBoolean features. + + Supported features: + - RevolutionCut + - RevolutionFuse + + RevolutionBoolean(feature) -> feature interface without initialization + RevolutionBoolean(feature, + sketch, sketch_selection, boolean_objects, + to_angle, from_angle) -> + feature interface initialized from arguments: + - sketch + - sketch_selection + - boolean_objects + - to_angle + - from_angle + RevolutionBoolean(feature, + sketch, sketch_selection, boolean_objects, + to_object, to_offset, from_object, from_offset) -> + feature interface initialized from arguments: + - sketch + - sketch_selection + - boolean_objects + - to_object + - to_offset + - from_object + - from_offset + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" CompositeBoolean.__init__(self, feature, *args[:3]) args = args[3:] diff --git a/src/PythonAPI/model/features/revolution_sketch.py b/src/PythonAPI/model/features/revolution_sketch.py index 20d896e74..55e751cc4 100644 --- a/src/PythonAPI/model/features/revolution_sketch.py +++ b/src/PythonAPI/model/features/revolution_sketch.py @@ -17,8 +17,31 @@ def addRevolutionSketch(part, *args): class RevolutionSketch(CompositeSketch): + """Interface class for RevolutionSketch features. + + RevolutionSketch(feature) -> feature interface without initialization + RevolutionSketch(feature, + sketch, sketch_selection, + to_angle, from_angle) -> + feature interface initialized from arguments: + - sketch + - sketch_selection + - to_angle + - from_angle + RevolutionSketch(feature, + sketch, sketch_selection, + to_object, to_offset, from_object, from_offset) -> + feature interface initialized from arguments: + - sketch + - sketch_selection + - to_object + - to_offset + - from_object + - from_offset + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" CompositeSketch.__init__(self, feature, *args[:2]) args = args[2:] diff --git a/src/PythonAPI/model/features/roots.py b/src/PythonAPI/model/features/roots.py index a69cdd734..3aa27d42c 100644 --- a/src/PythonAPI/model/features/roots.py +++ b/src/PythonAPI/model/features/roots.py @@ -3,8 +3,18 @@ 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") @@ -27,21 +37,34 @@ class CompositeBoolean(Interface): pass def setSketch(self, sketch): + """Modify sketch attribute""" self._fill_attribute(self._sketch, sketch) pass def setSketchSelection(self, sketch_selection): + """Modify sketch_selection attribute""" self._fill_attribute(self._sketch_selection, sketch_selection) pass def setBooleanObjects(self, boolean_objects): + """Modify boolean_objects attribute""" self._fill_attribute(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") @@ -61,9 +84,11 @@ class CompositeSketch(Interface): pass def setSketch(self, sketch): + """Modify sketch attribute""" self._fill_attribute(self._sketch, sketch) pass def setSketchSelection(self, sketch_selection): + """Modify sketch_selection attribute""" self._fill_attribute(self._sketch_selection, sketch_selection) pass diff --git a/src/PythonAPI/model/features/rotation.py b/src/PythonAPI/model/features/rotation.py index 3318cd16b..2c8b044a0 100644 --- a/src/PythonAPI/model/features/rotation.py +++ b/src/PythonAPI/model/features/rotation.py @@ -17,8 +17,18 @@ def addRotation(part, *args): class Rotation(Interface): + """Interface class for Rotation features. + + Rotation(feature) -> feature interface without initialization + Rotation(feature, main_objects, axis_object, angle) -> + feature interface initialized from arguments: + - main_objects + - axis_object + - angle + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Rotation") diff --git a/src/PythonAPI/model/features/translation.py b/src/PythonAPI/model/features/translation.py index 1004b8ea6..802b4d8e8 100644 --- a/src/PythonAPI/model/features/translation.py +++ b/src/PythonAPI/model/features/translation.py @@ -17,8 +17,18 @@ def addTranslation(part, *args): class Translation(Interface): + """Interface class for Translation features. + + Translation(feature) -> feature interface without initialization + Translation(feature, main_objects, axis_object, distance) -> + feature interface initialized from arguments: + - main_objects + - axis_object + - distance + """ def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Translation") diff --git a/src/PythonAPI/model/parameter/parameter.py b/src/PythonAPI/model/parameter/parameter.py index 51c9024fd..7dfe03c44 100644 --- a/src/PythonAPI/model/parameter/parameter.py +++ b/src/PythonAPI/model/parameter/parameter.py @@ -16,18 +16,17 @@ def addParameter(part, *args): class Parameter(Interface): - """Interface on a Parameter feature.""" + """Interface class for Parameter feature. - def __init__(self, feature, *args): - """Initialize a Parameter feature with given parameters. - - Expected arguments for all modes: - feature -- a Parameter feature + Parameter(feature) -> feature interface without initialization + Parameter(feature, variable, expression) -> + feature interface initialized from arguments: + - variable -- variable name + - expression -- Python expression + """ - For initialization (expect 2 arguments): - name -- variable name - expression -- Python expression - """ + def __init__(self, feature, *args): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Parameter") diff --git a/src/PythonAPI/model/partset/part.py b/src/PythonAPI/model/partset/part.py index e916975ff..a9bce9b3b 100644 --- a/src/PythonAPI/model/partset/part.py +++ b/src/PythonAPI/model/partset/part.py @@ -29,9 +29,13 @@ def removePart(part): class Part(Interface): + """Interface class for Part feature. + + Part(feature) -> feature interface without initialization + """ def __init__(self, feature): - """Adds a new Part to the given Partset and activates the Part.""" + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" Interface.__init__(self, feature) assert(self._feature.getKind() == "Part") diff --git a/src/PythonAPI/model/roots.py b/src/PythonAPI/model/roots.py index e3d794efa..1fa83ee57 100644 --- a/src/PythonAPI/model/roots.py +++ b/src/PythonAPI/model/roots.py @@ -12,16 +12,20 @@ class Feature(ModelAPI.ModelAPI_Feature): """Base class of user-defined Python features.""" def __init__(self): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" ModelAPI.ModelAPI_Feature.__init__(self) - def addRealInput (self, inputid): + def addRealInput(self, inputid): + """F.addRealInput(str) -- add real attribute""" self.data().addAttribute(inputid, ModelAPI.ModelAPI_AttributeDouble_typeId()) - def getRealInput (self, inputid): + def getRealInput(self, inputid): + """F.getRealInput(str) -- get real value of the attribute""" return self.data().real(inputid).value() - def addResult (self, result): + def addResult(self, result): + """F.addResult(ModelAPI_Result) -- add ModelAPI_Result shape as a result""" shape = result.shape() body = self.document().createBody(self.data()) body.store(shape) @@ -32,6 +36,7 @@ class Interface(): """Base class of high level Python interfaces to features.""" def __init__(self, feature): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" self._feature = feature self._attribute_white_list = [ "execute", @@ -69,13 +74,19 @@ class Interface(): tools.fill_attribute(attribute, value) def setRealInput(self, inputid, value): + """I.setRealInput(str, float) -- set real value to the attribute""" self._feature.data().real(inputid).setValue(value) def areInputValid(self): + """I.areInputValid() -> True or False validation result""" validators = ModelAPI.ModelAPI_Session.get().validators() return validators.validate(self._feature) def _execute(self): + """I._execute() -- validate and execute the feature. + + Raises RuntimeError if validation fails. + """ if self.areInputValid(): self._feature.execute() else: diff --git a/src/PythonAPI/model/sketcher/sketch.py b/src/PythonAPI/model/sketcher/sketch.py index a47759071..636ccd5db 100644 --- a/src/PythonAPI/model/sketcher/sketch.py +++ b/src/PythonAPI/model/sketcher/sketch.py @@ -27,7 +27,7 @@ def addSketch(doc, plane): return Sketch(feature, plane) class Sketch(Interface): - """Interface on a Sketch feature.""" + """Interface class for Sketch feature.""" def __init__(self, feature, *args): """Initialize a 2D Sketch on the given plane. diff --git a/src/PythonAPI/model/tools.py b/src/PythonAPI/model/tools.py index fe300d990..9971e4b69 100644 --- a/src/PythonAPI/model/tools.py +++ b/src/PythonAPI/model/tools.py @@ -20,10 +20,20 @@ def convert_to_underscore(name): class Selection: - """Class for storing 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): - """Initialize selection.""" + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" + if not args: self.args = (None, None) return diff --git a/src/PythonAddons/addons_Features.py b/src/PythonAddons/addons_Features.py index 90b23b9a9..3ff9f26dd 100644 --- a/src/PythonAddons/addons_Features.py +++ b/src/PythonAddons/addons_Features.py @@ -6,14 +6,20 @@ from macros.box.feature import BoxFeature class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin): + """Class for Python features plugin. + + PythonFeaturesPlugin() -> plugin object + """ def __init__(self): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" ModelAPI.ModelAPI_Plugin.__init__(self) aSession = ModelAPI.ModelAPI_Session.get() aSession.registerPlugin(self) pass def createFeature(self, theFeatureID): + """Override ModelAPI_Plugin.createFeature()""" aFeature = None if theFeatureID == BoxFeature.ID(): diff --git a/src/PythonAddons/macros/box/feature.py b/src/PythonAddons/macros/box/feature.py index f160a396e..8c6687c77 100644 --- a/src/PythonAddons/macros/box/feature.py +++ b/src/PythonAddons/macros/box/feature.py @@ -8,37 +8,46 @@ import geom class BoxFeature(model.Feature): + """Box feature. + BoxFeature() -> Box + """ # Initializations def __init__(self): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" model.Feature.__init__(self) @staticmethod def ID(): + """String constant.""" return "Box" @staticmethod def WIDTH_ID(): + """String constant.""" return "width" @staticmethod def LENGTH_ID(): + """String constant.""" return "length" @staticmethod def HEIGHT_ID(): + """String constant.""" return "height" def getKind(self): + """Override Feature.getKind()""" return BoxFeature.ID() # Creation of the box at default size def initAttributes(self): - + """Override Feature.initAttributes()""" # Creating the input arguments of the feature self.addRealInput(self.WIDTH_ID()) self.addRealInput(self.LENGTH_ID()) @@ -72,9 +81,11 @@ class BoxFeature(model.Feature): # Edition of the box at user size def execute(self): + """F.execute() -- execute the feature""" # Retrieving the user inputs width = self.getRealInput(self.WIDTH_ID()) - length = self.getRealInput(self.LENGTH_ID()) + length = self.getRealInpuut(self.WIDTH_ID()) + length = self.getRealInt(self.LENGTH_ID()) height = self.getRealInput(self.HEIGHT_ID()) # Editing the box @@ -86,5 +97,10 @@ class BoxFeature(model.Feature): # self.addResult( self.box.result() ) def isMacro(self): - # Box feature is macro: removes itself on the creation transaction finish + """Override Feature.initAttributes(). + F.isMacro() -> True + + Box feature is macro: removes itself on the creation transaction + finish. + """ return True -- 2.39.2