Salome HOME
Improve boolean feature.
authorspo <sergey.pokhodenko@opencascade.com>
Thu, 29 Oct 2015 14:30:03 +0000 (17:30 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 30 Oct 2015 12:55:40 +0000 (15:55 +0300)
src/PythonAPI/model/features/__init__.py
src/PythonAPI/model/features/boolean.py

index 41edaf3c99f578f5e3aab1fb674ec22a6be867b3..108d089074cfb3e1b3284b4cad670c10e3756292 100644 (file)
@@ -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
 
index adc8d661396d151e93a533507a9245e601eaffdb..ce04f2f31435ef650dae9e991592b2203d64b5fa 100644 (file)
@@ -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