From: spo Date: Thu, 29 Oct 2015 14:30:03 +0000 (+0300) Subject: Improve boolean feature. X-Git-Tag: V_2.1.0~206^2~46 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=20b7b78042c57be54ed0e67d3df903f249266e27;p=modules%2Fshaper.git Improve boolean feature. --- diff --git a/src/PythonAPI/model/features/__init__.py b/src/PythonAPI/model/features/__init__.py index 41edaf3c9..108d08907 100644 --- a/src/PythonAPI/model/features/__init__.py +++ b/src/PythonAPI/model/features/__init__.py @@ -1,9 +1,7 @@ """Package for Features plugin for the Parametric Geometry API of the Modeler. """ -from boolean import Addition as addAddition -from boolean import Subtraction as addSubtraction -from boolean import Intersection as addIntersection +from boolean import addAddition, addSubtraction, addIntersection from partition import addPartition diff --git a/src/PythonAPI/model/features/boolean.py b/src/PythonAPI/model/features/boolean.py index adc8d6613..ce04f2f31 100644 --- a/src/PythonAPI/model/features/boolean.py +++ b/src/PythonAPI/model/features/boolean.py @@ -7,42 +7,60 @@ from ModelAPI import * from GeomAlgoAPI import * -class Boolean(): - """Abstract root class of Boolean Features.""" - def __init__(self, part, object, tool, type): - self.my = part.addFeature("Boolean") - self.my.data().reference("main_object").setValue(object) - self.my.data().reference("tool_object").setValue(tool) - self.my.data().integer("bool_type").setValue(type) +from model.roots import Interface - if ModelAPI_Session.get().validators().validate(self.my): - self.my.execute() - else: - raise Exception("cannot make the Boolean") - -class Addition(Boolean): - - def __init__(self, part, object, tool): +def addAddition(part, object, tool): """Inserts an addition to the given Part and executes the operation. This operation adds tool to the given object. """ - Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_FUSE) - + feature = part.addFeature("Boolean") + return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_FUSE) -class Subtraction(Boolean): - def __init__(self, part, object, tool): +def addSubtraction(part, object, tool): """Inserts a subtraction to the given Part and executes the operation. This operation subtracts tool to the given object. """ - Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_CUT) + feature = part.addFeature("Boolean") + return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_CUT) -class Intersection(Boolean): - - def __init__(self, part, object, tool): +def addIntersection(part, object, tool): """Inserts an intersection to the given Part and executes the operation. This operation intersects tool to the given object. """ - Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_COMMON) \ No newline at end of file + feature = part.addFeature("Boolean") + return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_COMMON) + + +class Boolean(Interface): + """Abstract root class of Boolean Features.""" + def __init__(self, feature, main_objects, tool_objects, bool_type): + 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) + + self.setMainObjects(main_objects) + self.setToolObjects(tool_objects) + self.setBoolType(bool_type) + pass + + def setMainObjects(self, main_objects): + self._fill_attribute(self._main_objects, main_objects) + pass + + def setToolObjects(self, tool_objects): + self._fill_attribute(self._tool_objects, tool_objects) + pass + + def setBoolType(self, bool_type): + self._fill_attribute(self._bool_type, bool_type) + pass