X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Partition.cpp;h=e7e74c68e91a6d69aab4e473bb11793e084df74c;hb=4fc2dc9fdc0c14fab5f2780598eccdc1368d81b9;hp=e165b5a760e3e7ad619a796e802d2e26a1a6a183;hpb=952efeb621c89406b5b4b2a7173ad42de4034fa8;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp index e165b5a76..e7e74c68e 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -16,11 +17,14 @@ #include #include +#include #include #include #include #include +#include + //================================================================================================= FeaturesPlugin_Partition::FeaturesPlugin_Partition() { @@ -39,22 +43,9 @@ void FeaturesPlugin_Partition::initAttributes() FeaturesPlugin_Partition::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); aSelection->setSelectionType("SOLID"); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID()); -} -//================================================================================================= -std::shared_ptr FeaturesPlugin_Partition::getShape(const std::string& theAttrName) -{ - std::shared_ptr aObjRef = - std::dynamic_pointer_cast(data()->attribute(theAttrName)); - if (aObjRef) { - std::shared_ptr aConstr = - std::dynamic_pointer_cast(aObjRef->value()); - if (aConstr) - return aConstr->shape(); - } - return std::shared_ptr(); + data()->addAttribute(COMBINE_ID(), ModelAPI_AttributeBoolean::typeId()); } //================================================================================================= @@ -74,6 +65,7 @@ void FeaturesPlugin_Partition::execute() } GeomAlgoAPI_MakeShapeList aMakeShapeList; + std::list > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0); // Getting tools. AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Partition::TOOL_LIST_ID()); @@ -84,10 +76,10 @@ void FeaturesPlugin_Partition::execute() // it could be a construction plane ResultPtr aContext = aToolAttr->context(); if(aContext.get()) { - aTool = GeomAlgoAPI_ShapeTools::faceToInfinitePlane(aContext->shape()); + aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aContext->shape(), aBoundingPoints); std::shared_ptr aMkShCustom(new GeomAlgoAPI_MakeShapeCustom); aMkShCustom->addModified(aContext->shape(), aTool); - aMakeShapeList.append(aMkShCustom); + aMakeShapeList.appendAlgo(aMkShCustom); aTools.push_back(aTool); aToolsForNaming.push_back(aContext->shape()); } @@ -97,45 +89,86 @@ void FeaturesPlugin_Partition::execute() } } - int aResultIndex = 0; + // Getting combine flag. + bool isCombine = boolean(COMBINE_ID())->value(); - if (anObjects.empty() || aTools.empty()) { + if(anObjects.empty()/* || aTools.empty()*/) { std::string aFeatureError = "Not enough objects for partition 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; - ListOfShape aListWithObject; aListWithObject.push_back(anObject); - GeomAlgoAPI_Partition aPartitionAlgo(aListWithObject, aTools); + int aResultIndex = 0; + + if(isCombine) { + // Create single result. + if(!aTools.empty()) { + // This is a workaround for naming. Passing compound of objects as argument instead each object separately. + std::shared_ptr aCompoud = GeomAlgoAPI_CompoundBuilder::compound(anObjects); + anObjects.clear(); + anObjects.push_back(aCompoud); + } + std::shared_ptr aPartitionAlgo(new GeomAlgoAPI_Partition(anObjects, aTools)); // Checking that the algorithm worked properly. - if (!aPartitionAlgo.isDone()) { + if (!aPartitionAlgo->isDone()) { static const std::string aFeatureError = "Partition algorithm failed"; setError(aFeatureError); return; } - if (aPartitionAlgo.shape()->isNull()) { + if (aPartitionAlgo->shape()->isNull()) { static const std::string aShapeError = "Resulting shape is Null"; setError(aShapeError); return; } - if (!aPartitionAlgo.isValid()) { + if (!aPartitionAlgo->isValid()) { std::string aFeatureError = "Warning: resulting shape is not valid"; setError(aFeatureError); return; } - if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo.shape()) > 1.e-7) { + if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo->shape()) > 1.e-7) { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - aMakeShapeList.append(aPartitionAlgo.makeShape()); - GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo.mapOfShapes().get(); - loadNamingDS(aResultBody, anObject, aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes); + aMakeShapeList.appendAlgo(aPartitionAlgo); + GeomAPI_DataMapOfShapeShape& aMapOfShapes = *aPartitionAlgo->mapOfSubShapes().get(); + loadNamingDS(aResultBody, anObjects.front(), aToolsForNaming, aPartitionAlgo->shape(), aMakeShapeList, aMapOfShapes); setResult(aResultBody, aResultIndex); aResultIndex++; } + } else { + // Create result for each object. + for (ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) { + std::shared_ptr anObject = *anObjectsIt; + ListOfShape aListWithObject; aListWithObject.push_back(anObject); + std::shared_ptr aPartitionAlgo(new GeomAlgoAPI_Partition(aListWithObject, aTools)); + + // Checking that the algorithm worked properly. + if (!aPartitionAlgo->isDone()) { + static const std::string aFeatureError = "Partition algorithm failed"; + setError(aFeatureError); + return; + } + if (aPartitionAlgo->shape()->isNull()) { + static const std::string aShapeError = "Resulting shape is Null"; + setError(aShapeError); + return; + } + if (!aPartitionAlgo->isValid()) { + std::string aFeatureError = "Warning: resulting shape is not valid"; + setError(aFeatureError); + return; + } + + if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo->shape()) > 1.e-7) { + std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); + GeomAlgoAPI_MakeShapeList aMakeShapeListCopy = aMakeShapeList; + aMakeShapeListCopy.appendAlgo(aPartitionAlgo); + GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo->mapOfSubShapes().get(); + loadNamingDS(aResultBody, anObject, aToolsForNaming, aPartitionAlgo->shape(), aMakeShapeListCopy, aMapOfShapes); + setResult(aResultBody, aResultIndex); + aResultIndex++; + } + } } // remove the rest results if there were produced in the previous pass @@ -154,21 +187,28 @@ void FeaturesPlugin_Partition::loadNamingDS(std::shared_ptr if(theBaseShape->isEqual(theResultShape)) { theResultBody->store(theResultShape); } else { - const int aModifyTag = 1; - const int aDeletedTag = 2; - const int aSubsolidsTag = 3; /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids + const int aDeletedTag = 1; + const int aSubsolidsTag = 2; /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids + const int aModifyTag = 100000; + int aModifyToolsTag = 200000; + std::ostringstream aStream; theResultBody->storeModified(theBaseShape, theResultShape, aSubsolidsTag); std::string aModName = "Modified"; theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::FACE, - aModifyTag, aModName, theMapOfShapes); + aModifyTag, aModName, theMapOfShapes, true); theResultBody->loadDeletedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::FACE, aDeletedTag); + int anIndex = 1; for(ListOfShape::const_iterator anIter = theTools.begin(); anIter != theTools.end(); anIter++) { + aStream.str(std::string()); + aStream.clear(); + aStream << aModName << "_" << anIndex++; theResultBody->loadAndOrientModifiedShapes(&theMakeShape, *anIter, GeomAPI_Shape::FACE, - aModifyTag, aModName, theMapOfShapes); + aModifyToolsTag, aStream.str(), theMapOfShapes, true); theResultBody->loadDeletedShapes(&theMakeShape, *anIter, GeomAPI_Shape::FACE, aDeletedTag); + aModifyToolsTag += 10000; } } }