]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Class structure modification for composite features.
authordbv <dbv@opencascade.com>
Thu, 11 Jun 2015 14:41:03 +0000 (17:41 +0300)
committerdbv <dbv@opencascade.com>
Thu, 11 Jun 2015 14:41:03 +0000 (17:41 +0300)
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp [deleted file]
src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.h
src/FeaturesPlugin/extrusioncut_widget.xml

index 6447870d7e938dfbf27d516a13611cc6cca6bb09..8e30c5499084f433b043c4a553f40109dd135a69 100644 (file)
@@ -7,25 +7,28 @@ SET(PROJECT_HEADERS
     FeaturesPlugin.h
     FeaturesPlugin_Plugin.h
     FeaturesPlugin_Extrusion.h
-    FeaturesPlugin_ExtrusionCut.h
     FeaturesPlugin_Revolution.h
     FeaturesPlugin_Rotation.h
     FeaturesPlugin_Movement.h
     FeaturesPlugin_Boolean.h
     FeaturesPlugin_Group.h
     FeaturesPlugin_Placement.h
+    FeaturesPlugin_CompositeBoolean.h
+    FeaturesPlugin_ExtrusionBoolean.h
+    FeaturesPlugin_ExtrusionCut.h
 )
 
 SET(PROJECT_SOURCES
     FeaturesPlugin_Plugin.cpp
     FeaturesPlugin_Extrusion.cpp
-    FeaturesPlugin_ExtrusionCut.cpp
     FeaturesPlugin_Revolution.cpp
     FeaturesPlugin_Rotation.cpp
     FeaturesPlugin_Movement.cpp
     FeaturesPlugin_Boolean.cpp
     FeaturesPlugin_Group.cpp
     FeaturesPlugin_Placement.cpp
+    FeaturesPlugin_CompositeBoolean.cpp
+    FeaturesPlugin_ExtrusionBoolean.cpp
 )
 
 SET(XML_RESOURCES
index 80effcb208a36da33056c4d194cf01e8031f6fe5..1593759e94b007d2837845701bc0fb0ea4b508fd 100644 (file)
@@ -98,8 +98,6 @@ void FeaturesPlugin_Boolean::execute()
   }
 
   int aResultIndex = 0;
-  ListOfMakeShape aListOfMakeShape;
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aDataMapOfShapes;
 
   switch(aType) {
     case GeomAlgoAPI_Boolean::BOOL_CUT:
@@ -159,9 +157,6 @@ void FeaturesPlugin_Boolean::execute()
       }
 
       std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-      std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(
-        new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
-
       LoadNamingDS(aResultBody, anObjects.front(), aTools, aBoolAlgo);
       setResult(aResultBody, aResultIndex);
       aResultIndex++;
diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp
new file mode 100644 (file)
index 0000000..7d92239
--- /dev/null
@@ -0,0 +1,208 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        FeaturesPlugin_CompositeBoolean.cpp
+// Created:     11 June 2015
+// Author:      Dmitry Bobylev
+
+#include <FeaturesPlugin_CompositeBoolean.h>
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <GeomAlgoAPI_ShapeProps.h>
+
+//=================================================================================================
+void FeaturesPlugin_CompositeBoolean::initAttributes()
+{
+  data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
+
+  // Boolean works with solids always.
+  data()->addAttribute(BOOLEAN_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
+  AttributeSelectionListPtr aSelection = data()->selectionList(BOOLEAN_OBJECTS_ID());
+  aSelection->setSelectionType("SOLID");
+
+  initMakeSolidsAttributes();
+}
+
+//=================================================================================================
+std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::addFeature(std::string theID)
+{
+  std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
+  if (aNew) {
+    data()->reference(SKETCH_OBJECT_ID())->setValue(aNew);
+  }
+   // set as current also after it becomes sub to set correctly enabled for other sketch subs
+  document()->setCurrentFeature(aNew, false);
+  return aNew;
+}
+
+//=================================================================================================
+int FeaturesPlugin_CompositeBoolean::numberOfSubs() const
+{
+  ObjectPtr aObj = data()->reference(SKETCH_OBJECT_ID())->value();
+  return aObj.get()? 1 : 0;
+}
+
+//=================================================================================================
+std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex) const
+{
+  if (theIndex == 0)
+    return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
+  return std::shared_ptr<ModelAPI_Feature>();
+}
+
+//=================================================================================================
+int FeaturesPlugin_CompositeBoolean::subFeatureId(const int theIndex) const
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = subFeature(theIndex);
+  if (aFeature.get())
+    return aFeature->data()->featureId();
+  return -1;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_CompositeBoolean::isSub(ObjectPtr theObject) const
+{
+  // check is this feature of result
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+  if (!aFeature)
+    return false;
+  ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value();
+  return aSub == theObject;
+}
+
+//=================================================================================================
+void FeaturesPlugin_CompositeBoolean::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
+{
+}
+
+//=================================================================================================
+void FeaturesPlugin_CompositeBoolean::execute()
+{
+  // Getting faces to create solids.
+  std::shared_ptr<ModelAPI_Feature> aSketchFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
+                                                     reference(SKETCH_OBJECT_ID())->value());
+  if(!aSketchFeature) {
+    return;
+  }
+  ResultPtr aSketchRes = aSketchFeature->results().front();
+  ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSketchRes);
+  if(!aConstruction.get()) {
+    return;
+  }
+  int aSketchFacesNum = aConstruction->facesNum();
+  if(aSketchFacesNum == 0) {
+    return; //TODO: set error message
+  }
+  ListOfShape aSketchFacesList;
+  for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) {
+    std::shared_ptr<GeomAPI_Shape> aFace = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+    aSketchFacesList.push_back(aFace);
+  }
+
+  // Pass faces to soldis creation function.
+  ListOfShape aBooleanTools = MakeSolids(aSketchFacesList);
+  if(aBooleanTools.empty()) {
+    return;
+  }
+
+  // Getting objects for boolean operation.
+  ListOfShape aBooleanObjects;
+  AttributeSelectionListPtr anObjectsSelList = selectionList(BOOLEAN_OBJECTS_ID());
+  if (anObjectsSelList->size() == 0) {
+    return;
+  }
+  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
+    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+    if(!anObject.get()) {
+      return;
+    }
+    aBooleanObjects.push_back(anObject);
+  }
+
+  // Cut from each object solids.
+  int aResultIndex = 0;
+
+  switch(myBooleanOperationType) {
+    case GeomAlgoAPI_Boolean::BOOL_CUT:
+    case GeomAlgoAPI_Boolean::BOOL_COMMON:{
+      // Cut each object with all tools
+      for(ListOfShape::iterator anObjectsIt = aBooleanObjects.begin(); anObjectsIt != aBooleanObjects.end(); anObjectsIt++) {
+        std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
+        ListOfShape aListWithObject;
+        aListWithObject.push_back(anObject);
+        GeomAlgoAPI_Boolean aBoolAlgo(aListWithObject, aBooleanTools, myBooleanOperationType);
+
+        // Checking that the algorithm worked properly.
+        if(!aBoolAlgo.isDone() || aBoolAlgo.shape()->isNull() || !aBoolAlgo.isValid()) {
+          setError("Boolean algorithm failed");
+          return;
+        }
+
+        if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
+          std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+          LoadNamingDS(aResultBody, anObject, aBooleanTools, aBoolAlgo);
+          setResult(aResultBody, aResultIndex);
+          aResultIndex++;
+        }
+      }
+      break;
+    }
+    case GeomAlgoAPI_Boolean::BOOL_FUSE: {
+      // Fuse all objects and all tools.
+      GeomAlgoAPI_Boolean aBoolAlgo(aBooleanObjects, aBooleanTools, myBooleanOperationType);
+
+      // Checking that the algorithm worked properly.
+      if(!aBoolAlgo.isDone() || aBoolAlgo.shape()->isNull() || !aBoolAlgo.isValid()) {
+        setError("Boolean algorithm failed");
+        return;
+      }
+
+      std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+      LoadNamingDS(aResultBody, aBooleanObjects.front(), aBooleanTools, aBoolAlgo);
+      setResult(aResultBody, aResultIndex);
+      aResultIndex++;
+      break;
+    }
+    default: {
+      setError("Error: wrong type of boolean operation");
+      return;
+    }
+  }
+
+  // Remove the rest results if there were produced in the previous pass.
+  removeResults(aResultIndex);
+}
+
+//=================================================================================================
+void FeaturesPlugin_CompositeBoolean::LoadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+                                                   const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
+                                                   const ListOfShape& theTools,
+                                                   const GeomAlgoAPI_Boolean& theAlgo)
+{
+  //load result
+  if(theBaseShape->isEqual(theAlgo.shape())) {
+    theResultBody->store(theAlgo.shape());
+  } else {
+    theResultBody->storeModified(theBaseShape, theAlgo.shape());
+
+    GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
+
+    const int aModTag = 1;
+    const int aDeleteTag = 2;
+    const std::string aModName = "Modified";
+    theResultBody->loadAndOrientModifiedShapes(theAlgo.makeShape().get(), theBaseShape, GeomAPI_Shape::FACE,
+                                               aModTag, aModName, *theAlgo.mapOfShapes().get());
+    theResultBody->loadDeletedShapes(theAlgo.makeShape().get(), theBaseShape, GeomAPI_Shape::FACE, aDeleteTag);
+
+    for(ListOfShape::const_iterator anIter = theTools.begin(); anIter != theTools.end(); anIter++) {
+      theResultBody->loadAndOrientModifiedShapes(theAlgo.makeShape().get(), *anIter, GeomAPI_Shape::FACE,
+                                                 aModTag, aModName, *theAlgo.mapOfShapes().get());
+      theResultBody->loadDeletedShapes(theAlgo.makeShape().get(), *anIter, GeomAPI_Shape::FACE, aDeleteTag);
+    }
+  }
+}
diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h
new file mode 100644 (file)
index 0000000..88a5860
--- /dev/null
@@ -0,0 +1,79 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        FeaturesPlugin_CompositeBoolean.h
+// Created:     11 June 2015
+// Author:      Dmitry Bobylev
+
+#ifndef FeaturesPlugin_CompositeBoolean_H_
+#define FeaturesPlugin_CompositeBoolean_H_
+
+#include <FeaturesPlugin.h>
+
+#include <ModelAPI_CompositeFeature.h>
+
+#include <GeomAlgoAPI_Boolean.h>
+
+/** \class FeaturesPlugin_CompositeBoolean
+ *  \ingroup Plugins
+ */
+class FeaturesPlugin_CompositeBoolean : public ModelAPI_CompositeFeature
+{
+ public:
+  /// Attribute name of sketch feature.
+  inline static const std::string& SKETCH_OBJECT_ID()
+  {
+    static const std::string MY_SKETCH_OBJECT_ID("sketch");
+    return MY_SKETCH_OBJECT_ID;
+  }
+
+  /// Attribute name of objects for boolean operation.
+  inline static const std::string& BOOLEAN_OBJECTS_ID()
+  {
+    static const std::string MY_BOOLEAN_OBJECTS_ID("boolean_objects");
+    return MY_BOOLEAN_OBJECTS_ID;
+  }
+
+  /// Creates a new part document if needed.
+  FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes.
+  FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Appends a feature to the sketch sub-elements container.
+  FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
+
+  /// \return the number of sub-elements.
+  FEATURESPLUGIN_EXPORT virtual int numberOfSubs() const;
+
+  /// \return the sub-feature by zero-base index.
+  FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const;
+
+  /// \return the sub-feature unique identifier in this composite feature by zero-base index.
+  FEATURESPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
+
+  /// \return true if feature or reuslt belong to this composite feature as subs.
+  FEATURESPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
+
+  /// This method to inform that sub-feature is removed and must be removed from the internal data
+  /// structures of the owner (the remove from the document will be done outside just after)
+  FEATURESPLUGIN_EXPORT virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
+
+protected:
+  FeaturesPlugin_CompositeBoolean(){};
+
+  /// Define this function to init attributes for extrusion/revolution.
+  virtual void initMakeSolidsAttributes() = 0;
+
+  /// Define this function to create solids from faces with extrusion/revolution.
+  virtual ListOfShape MakeSolids(const ListOfShape& theFaces) = 0;
+
+  void LoadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+                    const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
+                    const ListOfShape& theTools,
+                    const GeomAlgoAPI_Boolean& theAlgo);
+
+protected:
+  GeomAlgoAPI_Boolean::OperationType myBooleanOperationType;
+};
+
+#endif
diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp
new file mode 100644 (file)
index 0000000..7ce6473
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        FeaturesPlugin_ExtrusionBoolean.h
+// Created:     11 June 2015
+// Author:      Dmitry Bobylev
+
+#include <FeaturesPlugin_ExtrusionBoolean.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <GeomAlgoAPI_Prism.h>
+
+//=================================================================================================
+void FeaturesPlugin_ExtrusionBoolean::initMakeSolidsAttributes()
+{
+  data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
+
+  data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
+}
+
+//=================================================================================================
+ListOfShape FeaturesPlugin_ExtrusionBoolean::MakeSolids(const ListOfShape& theFaces)
+{
+  // Getting extrusion bounding planes.
+  std::shared_ptr<GeomAPI_Shape> aFromShape;
+  std::shared_ptr<GeomAPI_Shape> aToShape;
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FROM_OBJECT_ID());
+  if (anObjRef) {
+    aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  }
+  anObjRef = selection(TO_OBJECT_ID());
+  if (anObjRef) {
+    aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  }
+
+  // Getting extrusion sizes.
+  double aFromSize = real(FROM_SIZE_ID())->value();
+  double aToSize = real(TO_SIZE_ID())->value();
+
+  // Extrude faces.
+  ListOfShape anExtrusionList;
+  for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
+    std::shared_ptr<GeomAPI_Shape> aBaseFace = *aFacesIt;
+    GeomAlgoAPI_Prism aPrismAlgo(aBaseFace, aFromShape, aFromSize, aToShape, aToSize);
+
+    // Checking that the algorithm worked properly.
+    if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
+      setError("Extrusion algorithm failed");
+      return ListOfShape();
+    }
+    anExtrusionList.push_back(aPrismAlgo.shape());
+  }
+
+  return anExtrusionList;
+}
\ No newline at end of file
diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h
new file mode 100644 (file)
index 0000000..a5963a3
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        FeaturesPlugin_ExtrusionBoolean.h
+// Created:     11 June 2015
+// Author:      Dmitry Bobylev
+
+#ifndef FeaturesPlugin_ExtrusionBoolean_H_
+#define FeaturesPlugin_ExtrusionBoolean_H_
+
+#include <FeaturesPlugin_CompositeBoolean.h>
+
+/** \class FeaturesPlugin_ExtrusionBoolean
+ *  \ingroup Plugins
+ */
+class FeaturesPlugin_ExtrusionBoolean : public FeaturesPlugin_CompositeBoolean
+{
+ public:
+  /// Attribute name of an object from which the extrusion grows.
+  inline static const std::string& FROM_OBJECT_ID()
+  {
+    static const std::string MY_FROM_OBJECT_ID("from_object");
+    return MY_FROM_OBJECT_ID;
+  }
+
+  /// Attribute name of extrusion from size.
+  inline static const std::string& FROM_SIZE_ID()
+  {
+    static const std::string MY_FROM_SIZE_ID("from_size");
+    return MY_FROM_SIZE_ID;
+  }
+
+  /// attribute name of an object to which the extrusion grows.
+  inline static const std::string& TO_OBJECT_ID()
+  {
+    static const std::string MY_TO_OBJECT_ID("to_object");
+    return MY_TO_OBJECT_ID;
+  }
+
+  /// Attribute name of extrusion to size.
+  inline static const std::string& TO_SIZE_ID()
+  {
+    static const std::string MY_TO_SIZE_ID("to_size");
+    return MY_TO_SIZE_ID;
+  }
+
+protected:
+  /// Init attributes for extrusion.
+  virtual void initMakeSolidsAttributes();
+
+  /// Create solids from faces with extrusion.
+  virtual ListOfShape MakeSolids(const ListOfShape& theFaces);
+
+protected:
+  FeaturesPlugin_ExtrusionBoolean(){};
+};
+
+#endif
diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp
deleted file mode 100755 (executable)
index 2f8704e..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        FeaturesPlugin_ExtrusionCut.cpp
-// Created:     12 May 2015
-// Author:      Dmitry Bobylev
-
-#include <FeaturesPlugin_ExtrusionCut.h>
-
-#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_AttributeReference.h>
-#include <ModelAPI_Validator.h>
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultConstruction.h>
-
-#include <GeomAlgoAPI_Boolean.h>
-#include <GeomAlgoAPI_Prism.h>
-#include <GeomAlgoAPI_ShapeProps.h>
-
-//=================================================================================================
-FeaturesPlugin_ExtrusionCut::FeaturesPlugin_ExtrusionCut()
-{
-}
-
-//=================================================================================================
-void FeaturesPlugin_ExtrusionCut::initAttributes()
-{
-
-  data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
-
-  data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
-  data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
-
-  data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
-  data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
-
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
-
-  data()->addAttribute(CUTLIST_ID(), ModelAPI_AttributeSelectionList::typeId());
-
-  // extrusion works with faces always
-  AttributeSelectionListPtr aSelection = data()->selectionList(CUTLIST_ID());
-  aSelection->setSelectionType("SOLID");
-}
-
-
-std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::addFeature(std::string theID)
-{
-  std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
-  if (aNew) {
-    data()->reference(SKETCH_OBJECT_ID())->setValue(aNew);
-  }
-   // set as current also after it becomes sub to set correctly enabled for other sketch subs
-  document()->setCurrentFeature(aNew, false);
-  return aNew;
-}
-
-  
-int FeaturesPlugin_ExtrusionCut::numberOfSubs() const
-{
-  ObjectPtr aObj = data()->reference(SKETCH_OBJECT_ID())->value();
-  return aObj.get()? 1 : 0;
-}
-
-std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::subFeature(const int theIndex) const
-{
-  if (theIndex == 0)
-    return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
-  return std::shared_ptr<ModelAPI_Feature>();
-}
-
-int FeaturesPlugin_ExtrusionCut::subFeatureId(const int theIndex) const
-{
-  std::shared_ptr<ModelAPI_Feature> aFeature = subFeature(theIndex);
-  if (aFeature.get())
-    return aFeature->data()->featureId();
-  return -1;
-}
-
-bool FeaturesPlugin_ExtrusionCut::isSub(ObjectPtr theObject) const
-{
-  // check is this feature of result
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
-  if (!aFeature)
-    return false;
-  ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value();
-  return aSub == theObject;
-}
-
-void FeaturesPlugin_ExtrusionCut::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
-{
-}
-
-//=================================================================================================
-void FeaturesPlugin_ExtrusionCut::execute()
-{
-  // Getting extrusion bounding planes.
-  std::shared_ptr<GeomAPI_Shape> aFromShape;
-  std::shared_ptr<GeomAPI_Shape> aToShape;
-  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FROM_OBJECT_ID());
-  if (anObjRef) {
-    aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
-  }
-  anObjRef = selection(TO_OBJECT_ID());
-  if (anObjRef) {
-    aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
-  }
-
-  // Getting extrusion sizes.
-  double aFromSize = real(FROM_SIZE_ID())->value();
-  double aToSize = real(TO_SIZE_ID())->value();
-
-  // Getting faces to extrude.
-  std::shared_ptr<ModelAPI_Feature> aSketchFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
-                                                     reference(SKETCH_OBJECT_ID())->value());
-  if(!aSketchFeature) {
-    return;
-  }
-  ResultPtr aSketchRes = aSketchFeature->results().front();
-  ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSketchRes);
-  if(!aConstruction.get()) {
-    return;
-  }
-  int aSketchFacesNum = aConstruction->facesNum();
-
-  // Extrude faces.
-  ListOfShape anExtrusionList;
-  for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) {
-    std::shared_ptr<GeomAPI_Shape> aBaseShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
-    GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aFromShape, aFromSize, aToShape, aToSize);
-
-    // Checking that the algorithm worked properly.
-    if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
-      return;
-    }
-    anExtrusionList.push_back(aPrismAlgo.shape());
-  }
-
-  // Getting objects to cut from.
-  ListOfShape aCutList;
-  AttributeSelectionListPtr anObjectsSelList = selectionList(CUTLIST_ID());
-  if (anObjectsSelList->size() == 0) {
-    return;
-  }
-  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
-    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
-    if(!anObject.get()) {
-      return;
-    }
-    aCutList.push_back(anObject);
-  }
-
-  // Cut from each objec result of extrusion.
-  int aResultIndex = 0;
-  for(ListOfShape::iterator aCutListIt = aCutList.begin(); aCutListIt != aCutList.end(); aCutListIt++) {
-    std::shared_ptr<GeomAPI_Shape> anObject = *aCutListIt;
-    ListOfShape aListWithObject;
-    aListWithObject.push_back(anObject);
-    GeomAlgoAPI_Boolean aBoolAlgo(aListWithObject, anExtrusionList, GeomAlgoAPI_Boolean::BOOL_CUT);
-
-    // Checking that the algorithm worked properly.
-    if(!aBoolAlgo.isDone() || aBoolAlgo.shape()->isNull() || !aBoolAlgo.isValid()) {
-      return;
-    }
-
-    if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
-      std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-      LoadNamingDS(aResultBody, anObject, anExtrusionList, aBoolAlgo);
-      setResult(aResultBody, aResultIndex);
-      aResultIndex++;
-    }
-  }
-}
-
-//=================================================================================================
-void FeaturesPlugin_ExtrusionCut::LoadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                                               const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
-                                               const ListOfShape& theTools,
-                                               const GeomAlgoAPI_Boolean& theAlgo)
-{
-  //load result
-  if(theBaseShape->isEqual(theAlgo.shape())) {
-    theResultBody->store(theAlgo.shape());
-  } else {
-    theResultBody->storeModified(theBaseShape, theAlgo.shape());
-
-    GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
-
-    const int aModTag = 1;
-    const int aDeleteTag = 2;
-    const std::string aModName = "Modified";
-    theResultBody->loadAndOrientModifiedShapes(theAlgo.makeShape().get(), theBaseShape, GeomAPI_Shape::FACE,
-                                               aModTag, aModName, *theAlgo.mapOfShapes().get());
-    theResultBody->loadDeletedShapes(theAlgo.makeShape().get(), theBaseShape, GeomAPI_Shape::FACE, aDeleteTag);
-
-    for(ListOfShape::const_iterator anIter = theTools.begin(); anIter != theTools.end(); anIter++) {
-      theResultBody->loadAndOrientModifiedShapes(theAlgo.makeShape().get(), *anIter, GeomAPI_Shape::FACE,
-                                                 aModTag, aModName, *theAlgo.mapOfShapes().get());
-      theResultBody->loadDeletedShapes(theAlgo.makeShape().get(), *anIter, GeomAPI_Shape::FACE, aDeleteTag);
-    }
-  }
-}
index 5735242fae2858bf382620e55440b30f76c25b49..4879a0eb9e74ecf1ecec1b7c6e0be6777401adbf 100755 (executable)
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
 // File:        FeaturesPlugin_ExtrusionCut.h
-// Created:     12 May 2015
+// Created:     11 June 2015
 // Author:      Dmitry Bobylev
 
 #ifndef FeaturesPlugin_ExtrusionCut_H_
 #define FeaturesPlugin_ExtrusionCut_H_
 
-#include <FeaturesPlugin.h>
-
-#include <ModelAPI_CompositeFeature.h>
-
-#include <GeomAlgoAPI_Boolean.h>
+#include <FeaturesPlugin_ExtrusionBoolean.h>
 
 /** \class FeaturesPlugin_ExtrusionCut
  *  \ingroup Plugins
  */
-class FeaturesPlugin_ExtrusionCut : public ModelAPI_CompositeFeature
+class FeaturesPlugin_ExtrusionCut : public FeaturesPlugin_ExtrusionBoolean
 {
  public:
-  /// Revolution kind.
+  /// Feature kind.
   inline static const std::string& ID()
   {
     static const std::string MY_REVOLUTION_ID("ExtrusionCut");
     return MY_REVOLUTION_ID;
   }
 
-  /// attribute name of references sketch entities list, it should contain a sketch result or
-  /// a pair a sketch result to sketch face
-  inline static const std::string& CUTLIST_ID()
-  {
-    static const std::string MY_CUT_LIST_ID("cut_objects");
-    return MY_CUT_LIST_ID;
-  }
-
-  /// attribute name of an object to which the extrusion grows
-  inline static const std::string& SKETCH_OBJECT_ID()
-  {
-    static const std::string MY_TO_OBJECT_ID("sketch");
-    return MY_TO_OBJECT_ID;
-  }
-
-  /// attribute name of extrusion size
-  inline static const std::string& TO_SIZE_ID()
-  {
-    static const std::string MY_TO_SIZE_ID("to_size");
-    return MY_TO_SIZE_ID;
-  }
-
-  /// attribute name of an object to which the extrusion grows
-  inline static const std::string& TO_OBJECT_ID()
-  {
-    static const std::string MY_TO_OBJECT_ID("to_object");
-    return MY_TO_OBJECT_ID;
-  }
-
-  /// attribute name of tool object
-  inline static const std::string& FROM_OBJECT_ID()
-  {
-    static const std::string MY_FROM_OBJECT_ID("from_object");
-    return MY_FROM_OBJECT_ID;
-  }
-
-  /// attribute name of extrusion size
-  inline static const std::string& FROM_SIZE_ID()
-  {
-    static const std::string MY_FROM_SIZE_ID("from_size");
-    return MY_FROM_SIZE_ID;
-  }
-
-  /// Returns the kind of a feature
+  /// \return the kind of a feature
   FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
   {
     static std::string MY_KIND = FeaturesPlugin_ExtrusionCut::ID();
     return MY_KIND;
   }
 
-  /// Creates a new part document if needed.
-  FEATURESPLUGIN_EXPORT virtual void execute();
-
-  /// Request for initialization of data model of the feature: adding all attributes.
-  FEATURESPLUGIN_EXPORT virtual void initAttributes();
-
   /// Use plugin manager for features creation.
-  FeaturesPlugin_ExtrusionCut();
-
-  /// appends a feature to the sketch sub-elements container
-  FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
-  
-  /// Returns the number of sub-elements
-  FEATURESPLUGIN_EXPORT virtual int numberOfSubs() const;
-
-  /// Returns the sub-feature by zero-base index
-  FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const;
-
-  /// Returns the sub-feature unique identifier in this composite feature by zero-base index
-  FEATURESPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
-
-  /// Returns true if feature or reuslt belong to this composite feature as subs
-  FEATURESPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
-
-  /// This method to inform that sub-feature is removed and must be removed from the internal data
-  /// structures of the owner (the remove from the document will be done outside just after)
-  FEATURESPLUGIN_EXPORT virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
-
-private:
-  void LoadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                    const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
-                    const ListOfShape& theTools,
-                    const GeomAlgoAPI_Boolean& theAlgo);
+  FeaturesPlugin_ExtrusionCut()
+  {
+    myBooleanOperationType = GeomAlgoAPI_Boolean::BOOL_CUT;
+  }
 };
 
 #endif
index aa168a1d2e179cf463e1d75aa97ffca2bb799c68..a480b3cbac760647e581c99ef55f927ded4fe927 100755 (executable)
@@ -38,7 +38,7 @@
       </doublevalue>
     </groupbox>
   </groupbox>
-  <multi_selector id="cut_objects"
+  <multi_selector id="boolean_objects"
     label="Cut from:"
     icon=":icons/cut_shape.png"
     tooltip="Objects to Cut"