From d25d525b4321bcc0c2559beb30966952cd0bcc6c Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 11 Jun 2015 17:41:03 +0300 Subject: [PATCH] Class structure modification for composite features. --- src/FeaturesPlugin/CMakeLists.txt | 7 +- src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp | 5 - .../FeaturesPlugin_CompositeBoolean.cpp | 208 ++++++++++++++++++ .../FeaturesPlugin_CompositeBoolean.h | 79 +++++++ .../FeaturesPlugin_ExtrusionBoolean.cpp | 63 ++++++ .../FeaturesPlugin_ExtrusionBoolean.h | 57 +++++ .../FeaturesPlugin_ExtrusionCut.cpp | 208 ------------------ .../FeaturesPlugin_ExtrusionCut.h | 93 +------- src/FeaturesPlugin/extrusioncut_widget.xml | 2 +- 9 files changed, 422 insertions(+), 300 deletions(-) create mode 100644 src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h create mode 100644 src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h delete mode 100755 src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 6447870d7..8e30c5499 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -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 diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 80effcb20..1593759e9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -98,8 +98,6 @@ void FeaturesPlugin_Boolean::execute() } int aResultIndex = 0; - ListOfMakeShape aListOfMakeShape; - std::shared_ptr aDataMapOfShapes; switch(aType) { case GeomAlgoAPI_Boolean::BOOL_CUT: @@ -159,9 +157,6 @@ void FeaturesPlugin_Boolean::execute() } std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - std::shared_ptr aMakeShapeList = std::shared_ptr( - 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 index 000000000..7d922390e --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -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 + +#include +#include +#include +#include + +#include + +//================================================================================================= +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 FeaturesPlugin_CompositeBoolean::addFeature(std::string theID) +{ + std::shared_ptr 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 FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex) const +{ + if (theIndex == 0) + return std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); + return std::shared_ptr(); +} + +//================================================================================================= +int FeaturesPlugin_CompositeBoolean::subFeatureId(const int theIndex) const +{ + std::shared_ptr 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(theObject); + if (!aFeature) + return false; + + ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value(); + return aSub == theObject; +} + +//================================================================================================= +void FeaturesPlugin_CompositeBoolean::removeFeature(std::shared_ptr theFeature) +{ +} + +//================================================================================================= +void FeaturesPlugin_CompositeBoolean::execute() +{ + // Getting faces to create solids. + std::shared_ptr aSketchFeature = std::dynamic_pointer_cast( + reference(SKETCH_OBJECT_ID())->value()); + if(!aSketchFeature) { + return; + } + ResultPtr aSketchRes = aSketchFeature->results().front(); + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(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 aFace = std::dynamic_pointer_cast(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 anObjectAttr = anObjectsSelList->value(anObjectsIndex); + std::shared_ptr 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 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 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 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 theResultBody, + const std::shared_ptr& 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 index 000000000..88a586040 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h @@ -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 + +#include + +#include + +/** \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 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 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 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 theResultBody, + const std::shared_ptr& 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 index 000000000..7ce64731f --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp @@ -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 + +#include +#include +#include +#include + +#include + +//================================================================================================= +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 aFromShape; + std::shared_ptr aToShape; + std::shared_ptr anObjRef = selection(FROM_OBJECT_ID()); + if (anObjRef) { + aFromShape = std::dynamic_pointer_cast(anObjRef->value()); + } + anObjRef = selection(TO_OBJECT_ID()); + if (anObjRef) { + aToShape = std::dynamic_pointer_cast(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 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 index 000000000..a5963a348 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h @@ -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 + +/** \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 index 2f8704e02..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp +++ /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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -//================================================================================================= -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 FeaturesPlugin_ExtrusionCut::addFeature(std::string theID) -{ - std::shared_ptr 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 FeaturesPlugin_ExtrusionCut::subFeature(const int theIndex) const -{ - if (theIndex == 0) - return std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); - return std::shared_ptr(); -} - -int FeaturesPlugin_ExtrusionCut::subFeatureId(const int theIndex) const -{ - std::shared_ptr 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(theObject); - if (!aFeature) - return false; - - ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value(); - return aSub == theObject; -} - -void FeaturesPlugin_ExtrusionCut::removeFeature(std::shared_ptr theFeature) -{ -} - -//================================================================================================= -void FeaturesPlugin_ExtrusionCut::execute() -{ - // Getting extrusion bounding planes. - std::shared_ptr aFromShape; - std::shared_ptr aToShape; - std::shared_ptr anObjRef = selection(FROM_OBJECT_ID()); - if (anObjRef) { - aFromShape = std::dynamic_pointer_cast(anObjRef->value()); - } - anObjRef = selection(TO_OBJECT_ID()); - if (anObjRef) { - aToShape = std::dynamic_pointer_cast(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 aSketchFeature = std::dynamic_pointer_cast( - reference(SKETCH_OBJECT_ID())->value()); - if(!aSketchFeature) { - return; - } - ResultPtr aSketchRes = aSketchFeature->results().front(); - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSketchRes); - if(!aConstruction.get()) { - return; - } - int aSketchFacesNum = aConstruction->facesNum(); - - // Extrude faces. - ListOfShape anExtrusionList; - for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) { - std::shared_ptr aBaseShape = std::dynamic_pointer_cast(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 anObjectAttr = anObjectsSelList->value(anObjectsIndex); - std::shared_ptr 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 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 aResultBody = document()->createBody(data(), aResultIndex); - LoadNamingDS(aResultBody, anObject, anExtrusionList, aBoolAlgo); - setResult(aResultBody, aResultIndex); - aResultIndex++; - } - } -} - -//================================================================================================= -void FeaturesPlugin_ExtrusionCut::LoadNamingDS(std::shared_ptr theResultBody, - const std::shared_ptr& 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_ExtrusionCut.h b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.h index 5735242fa..4879a0eb9 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.h +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.h @@ -1,114 +1,39 @@ // 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 - -#include - -#include +#include /** \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 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 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 theFeature); - -private: - void LoadNamingDS(std::shared_ptr theResultBody, - const std::shared_ptr& theBaseShape, - const ListOfShape& theTools, - const GeomAlgoAPI_Boolean& theAlgo); + FeaturesPlugin_ExtrusionCut() + { + myBooleanOperationType = GeomAlgoAPI_Boolean::BOOL_CUT; + } }; #endif diff --git a/src/FeaturesPlugin/extrusioncut_widget.xml b/src/FeaturesPlugin/extrusioncut_widget.xml index aa168a1d2..a480b3cba 100755 --- a/src/FeaturesPlugin/extrusioncut_widget.xml +++ b/src/FeaturesPlugin/extrusioncut_widget.xml @@ -38,7 +38,7 @@ -