X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Intersection.cpp;h=42dff80df439f7fa30c40b2e0b91aadb66620af4;hb=4656ef7be2170488c06dbc0586f71348be93b5fb;hp=6c8f51aff1447a0b9cd8e116e34777968892822a;hpb=77775df18b724470367a249096344f93fae039c4;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp b/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp index 6c8f51aff..42dff80df 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "FeaturesPlugin_Intersection.h" @@ -24,13 +23,20 @@ #include #include #include +#include #include +#include #include +#include +#include #include #include + +static const std::string INTERSECTION_VERSION_1("v9.5"); + //================================================================================================= FeaturesPlugin_Intersection::FeaturesPlugin_Intersection() { @@ -39,87 +45,72 @@ FeaturesPlugin_Intersection::FeaturesPlugin_Intersection() //================================================================================================= void FeaturesPlugin_Intersection::initAttributes() { - data()->addAttribute(OBJECT_LIST_ID(), + AttributePtr anObjectsAttr = data()->addAttribute(OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); + + data()->addAttribute(FUZZY_PARAM_ID(), ModelAPI_AttributeDouble::typeId()); + // Initialize the fuzzy parameter with a value below Precision::Confusion() to indicate, + // that the internal algorithms should use their default fuzzy value, if none was specified + // by the user. + real(FUZZY_PARAM_ID())->setValue(1.e-8); + + initVersion(INTERSECTION_VERSION_1, anObjectsAttr, AttributePtr()); } //================================================================================================= void FeaturesPlugin_Intersection::execute() { - ListOfShape anObjects; - + GeomAPI_ShapeHierarchy anObjectsHierarchy; + ListOfShape aPlanes; // Getting objects. - AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECT_LIST_ID()); - 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; - } - anObjects.push_back(anObject); - } - - if(anObjects.empty()) { + if (!processAttribute(OBJECT_LIST_ID(), anObjectsHierarchy, aPlanes)) { setError("Error: Objects or tools are empty."); return; } + // Getting fuzzy parameter. + // Used as additional tolerance to eliminate tiny results. + double aFuzzy = real(FUZZY_PARAM_ID())->value(); + int aResultIndex = 0; // Create result. - GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects)); + const ListOfShape& anObjects = anObjectsHierarchy.objects(); + GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects, aFuzzy)); // Checking that the algorithm worked properly. - if (!anIntersectionAlgo->isDone()) { - static const std::string aFeatureError = "Error: Intersection algorithm failed."; - setError(aFeatureError); + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anIntersectionAlgo, getKind(), anError)) { + setError(anError); return; } - if (anIntersectionAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!anIntersectionAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); - return; + + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + aMakeShapeList->appendAlgo(anIntersectionAlgo); + + GeomShapePtr aResShape = anIntersectionAlgo->shape(); + if (data()->version() == INTERSECTION_VERSION_1) { + // merge hierarchies of compounds containing objects and tools + // and append the result of the FUSE operation + aResShape = keepUnusedSubsOfCompound(aResShape, anObjectsHierarchy, + GeomAPI_ShapeHierarchy(), aMakeShapeList); } std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - loadNamingDS(aResultBody, anObjects, anIntersectionAlgo); + ModelAPI_Tools::loadModifiedShapes(aResultBody, + anObjects, + ListOfShape(), + aMakeShapeList, + aResShape); setResult(aResultBody, aResultIndex); aResultIndex++; + ModelAPI_Tools::loadDeletedShapes(aResultBody, + GeomShapePtr(), + anObjects, + aMakeShapeList, + aResShape); // remove the rest results if there were produced in the previous pass removeResults(aResultIndex); } - -//================================================================================================= -void FeaturesPlugin_Intersection::loadNamingDS(ResultBodyPtr theResultBody, - const ListOfShape& theObjects, - const GeomMakeShapePtr& theMakeShape) -{ - std::shared_ptr aResultShape = theMakeShape->shape(); - - if(theObjects.front()->isEqual(aResultShape)) { - theResultBody->store(aResultShape, false); - return; - } - - theResultBody->storeModified(theObjects.front(), aResultShape); - - const int aShapeTypesNb = 3; - const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] = {GeomAPI_Shape::VERTEX, - GeomAPI_Shape::EDGE, - GeomAPI_Shape::FACE }; - for (ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) { - const GeomShapePtr aShape = *anIt; - for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) { - theResultBody->loadModifiedShapes(theMakeShape, aShape, aShapeTypes[anIndex]); - theResultBody->loadGeneratedShapes(theMakeShape, aShape, aShapeTypes[anIndex]); - } - } -}