X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Boolean.cpp;h=7fb46f2c998cac3abd103ee68124d04c81f45a1b;hb=57ca5f04d759387755c59382cf085f6c1c782c07;hp=555590596688b4b109c84552220276b6da397fa6;hpb=78bdd669b016f0432f876101189276e8558770ff;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 555590596..7fb46f2c9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -20,6 +22,7 @@ #define FACE 4 #define _MODIFY_TAG 1 #define _DELETED_TAG 2 +#define _SUBSOLIDS_TAG 3 /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids //================================================================================================= FeaturesPlugin_Boolean::FeaturesPlugin_Boolean() @@ -41,6 +44,9 @@ void FeaturesPlugin_Boolean::initAttributes() FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); // extrusion works with faces always aSelection->setSelectionType("SOLID"); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID()); } //================================================================================================= @@ -71,9 +77,6 @@ void FeaturesPlugin_Boolean::execute() // Getting objects. AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_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(); @@ -85,9 +88,6 @@ void FeaturesPlugin_Boolean::execute() // Getting tools. AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID()); - if (aToolsSelList->size() == 0) { - return; - } for(int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) { std::shared_ptr aToolAttr = aToolsSelList->value(aToolsIndex); std::shared_ptr aTool = aToolAttr->value(); @@ -98,12 +98,16 @@ void FeaturesPlugin_Boolean::execute() } int aResultIndex = 0; - ListOfMakeShape aListOfMakeShape; - std::shared_ptr aDataMapOfShapes; switch(aType) { case GeomAlgoAPI_Boolean::BOOL_CUT: case GeomAlgoAPI_Boolean::BOOL_COMMON:{ + if(anObjects.empty() || aTools.empty()) { + std::string aFeatureError = "Not enough objects for boolean operation"; + setError(aFeatureError); + return; + } + // Cut each object with all tools for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) { std::shared_ptr anObject = *anObjectsIt; @@ -130,9 +134,6 @@ void FeaturesPlugin_Boolean::execute() if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - std::shared_ptr aMakeShapeList = std::shared_ptr( - new GeomAlgoAPI_MakeShapeList(aListOfMakeShape)); - LoadNamingDS(aResultBody, anObject, aTools, aBoolAlgo); setResult(aResultBody, aResultIndex); aResultIndex++; @@ -141,6 +142,20 @@ void FeaturesPlugin_Boolean::execute() break; } case GeomAlgoAPI_Boolean::BOOL_FUSE: { + if(anObjects.empty() && aTools.size() > 1) { + anObjects.push_back(aTools.back()); + aTools.pop_back(); + }else if(aTools.empty() && anObjects.size() > 1) { + aTools.push_back(anObjects.back()); + anObjects.pop_back(); + } + + if(anObjects.empty() || aTools.empty()) { + std::string aFeatureError = "Not enough objects for boolean operation"; + setError(aFeatureError); + return; + } + // Fuse all objects and all tools. GeomAlgoAPI_Boolean aBoolAlgo(anObjects, aTools, aType); @@ -162,9 +177,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++; @@ -190,7 +202,7 @@ void FeaturesPlugin_Boolean::LoadNamingDS(std::shared_ptr t if(theBaseShape->isEqual(theAlgo.shape())) { theResultBody->store(theAlgo.shape()); } else { - theResultBody->storeModified(theBaseShape, theAlgo.shape()); + theResultBody->storeModified(theBaseShape, theAlgo.shape(), _SUBSOLIDS_TAG); GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();