From de115f80d6cb61058a53a20ba1a96ad77d35f661 Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 17 Sep 2015 17:37:24 +0300 Subject: [PATCH] New "Combine" flag for partition --- .../FeaturesPlugin_Partition.cpp | 54 +++++++++++++++---- src/FeaturesPlugin/FeaturesPlugin_Partition.h | 7 +++ src/FeaturesPlugin/partition_widget.xml | 14 +++-- src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp | 2 +- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp index e165b5a76..44ab7cc84 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -39,8 +40,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()); + + data()->addAttribute(COMBINE_ID(), ModelAPI_AttributeBoolean::typeId()); } //================================================================================================= @@ -97,19 +99,20 @@ 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. + GeomAlgoAPI_Partition aPartitionAlgo(anObjects, aTools); // Checking that the algorithm worked properly. if (!aPartitionAlgo.isDone()) { @@ -132,10 +135,43 @@ void FeaturesPlugin_Partition::execute() 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); + 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); + GeomAlgoAPI_Partition aPartitionAlgo(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); + aMakeShapeList.append(aPartitionAlgo.makeShape()); + GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo.mapOfShapes().get(); + loadNamingDS(aResultBody, anObject, aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes); + setResult(aResultBody, aResultIndex); + aResultIndex++; + } + } } // remove the rest results if there were produced in the previous pass diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.h b/src/FeaturesPlugin/FeaturesPlugin_Partition.h index 9ec475f44..eaa17dd23 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.h @@ -40,6 +40,13 @@ public: return MY_TOOL_LIST_ID; } + /// attribute name of combine flag + inline static const std::string& COMBINE_ID() + { + static const std::string MY_COMBINE_ID("partition_combine"); + return MY_COMBINE_ID; + } + /// Returns the kind of a feature FEATURESPLUGIN_EXPORT virtual const std::string& getKind() { diff --git a/src/FeaturesPlugin/partition_widget.xml b/src/FeaturesPlugin/partition_widget.xml index 7358bdc5b..ef693d086 100755 --- a/src/FeaturesPlugin/partition_widget.xml +++ b/src/FeaturesPlugin/partition_widget.xml @@ -10,14 +10,18 @@ - + concealment="true"> - + + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp index edc34324b..cf5dd741a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp @@ -40,7 +40,7 @@ GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects, void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects, const ListOfShape& theTools) { - if (theObjects.empty() || theTools.empty()) { + if (theObjects.empty()) { return; } -- 2.39.2