X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_BooleanSmash.cpp;h=92aff415c2594ebb88e8cfe06a39036480e0f956;hb=04e2497fc973f0afc95d0a4a6f95e37fb27f45e8;hp=11b47079e232ed19668b398edf1b95014b29fa4b;hpb=3662ff862dc48b187b48bafe3f3d1bfff5ae7345;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp index 11b47079e..92aff415c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 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 @@ -19,9 +19,9 @@ #include "FeaturesPlugin_BooleanSmash.h" -#include "FeaturesPlugin_Tools.h" - #include +#include +#include #include #include @@ -35,6 +35,10 @@ #include #include + +static const double DEFAULT_FUZZY = 1.e-5; + + //================================================================================================== FeaturesPlugin_BooleanSmash::FeaturesPlugin_BooleanSmash() : FeaturesPlugin_Boolean(FeaturesPlugin_Boolean::BOOL_SMASH) @@ -47,14 +51,19 @@ void FeaturesPlugin_BooleanSmash::initAttributes() data()->addAttribute(OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); data()->addAttribute(TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); - initVersion(THE_VERSION_1, selectionList(OBJECT_LIST_ID()), selectionList(TOOL_LIST_ID())); + data()->addAttribute(USE_FUZZY_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(FUZZY_PARAM_ID(), ModelAPI_AttributeDouble::typeId()); + boolean(USE_FUZZY_ID())->setValue(false); // Do NOT use the fuzzy parameter by default. + real(FUZZY_PARAM_ID())->setValue(DEFAULT_FUZZY); + + initVersion(BOP_VERSION_9_4(), selectionList(OBJECT_LIST_ID()), selectionList(TOOL_LIST_ID())); } //================================================================================================== void FeaturesPlugin_BooleanSmash::execute() { std::string anError; - ObjectHierarchy anObjectsHistory, aToolsHistory; + GeomAPI_ShapeHierarchy anObjectsHistory, aToolsHistory; ListOfShape aPlanes; // Getting objects and tools. @@ -64,53 +73,60 @@ void FeaturesPlugin_BooleanSmash::execute() int aResultIndex = 0; - if (anObjectsHistory.IsEmpty() || aToolsHistory.IsEmpty()) { + if (anObjectsHistory.empty() || aToolsHistory.empty()) { std::string aFeatureError = "Error: Not enough objects for boolean operation."; setError(aFeatureError); return; } // Collecting all shapes which will be smashed. - ListOfShape aShapesToSmash = anObjectsHistory.Objects(); + ListOfShape aShapesToSmash = anObjectsHistory.objects(); // List of original shapes for naming. ListOfShape anOriginalShapes; anOriginalShapes.insert(anOriginalShapes.end(), aShapesToSmash.begin(), aShapesToSmash.end()); - ListOfShape aTools = aToolsHistory.Objects(); + ListOfShape aTools = aToolsHistory.objects(); anOriginalShapes.insert(anOriginalShapes.end(), aTools.begin(), aTools.end()); // Collecting solids from compsolids which will not be modified in // boolean operation and will be added to result. ListOfShape aShapesToAdd; - for (ObjectHierarchy::Iterator anIt = anObjectsHistory.Begin(); - anIt != anObjectsHistory.End(); + for (GeomAPI_ShapeHierarchy::iterator anIt = anObjectsHistory.begin(); + anIt != anObjectsHistory.end(); ++anIt) { - GeomShapePtr aParent = anObjectsHistory.Parent(*anIt, false); + GeomShapePtr aParent = anObjectsHistory.parent(*anIt, false); if (aParent) { anOriginalShapes.push_back(aParent); ListOfShape aUsed, aNotUsed; - anObjectsHistory.SplitCompound(aParent, aUsed, aNotUsed); + anObjectsHistory.splitCompound(aParent, aUsed, aNotUsed); aShapesToAdd.insert(aShapesToAdd.end(), aNotUsed.begin(), aNotUsed.end()); // add unused shapes of compounds/compsolids to the history, // to avoid treating them as unused later when constructing a compound containing // the result of Smash and all unused sub-shapes of multi-level compounds - for (ListOfShape::iterator anIt = aNotUsed.begin(); anIt != aNotUsed.end(); ++anIt) - anObjectsHistory.AddObject(*anIt); + for (ListOfShape::iterator aNUIt = aNotUsed.begin(); aNUIt != aNotUsed.end(); ++aNUIt) + anObjectsHistory.addObject(*aNUIt); } } + // Getting fuzzy parameter. + // Used as additional tolerance to eliminate tiny results. + // Using -1 as fuzzy value in the GeomAlgoAPI means to ignore it during the boolean operation! + bool aUseFuzzy = boolean(USE_FUZZY_ID())->value(); + double aFuzzy = (aUseFuzzy ? real(FUZZY_PARAM_ID())->value() : -1); + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList()); if (!aShapesToAdd.empty()) { // Cut objects with not used solids. std::shared_ptr anObjectsCutAlgo( new GeomAlgoAPI_Boolean(aShapesToSmash, aShapesToAdd, - GeomAlgoAPI_Tools::BOOL_CUT)); + GeomAlgoAPI_Tools::BOOL_CUT, + aFuzzy)); - if (GeomAlgoAPI_ShapeTools::volume(anObjectsCutAlgo->shape()) > 1.e-27) { + if (GeomAlgoAPI_ShapeTools::area(anObjectsCutAlgo->shape()) > 1.e-27) { aShapesToSmash.clear(); aShapesToSmash.push_back(anObjectsCutAlgo->shape()); aMakeShapeList->appendAlgo(anObjectsCutAlgo); @@ -120,9 +136,10 @@ void FeaturesPlugin_BooleanSmash::execute() std::shared_ptr aToolsCutAlgo( new GeomAlgoAPI_Boolean(aTools, aShapesToAdd, - GeomAlgoAPI_Tools::BOOL_CUT)); + GeomAlgoAPI_Tools::BOOL_CUT, + aFuzzy)); - if (GeomAlgoAPI_ShapeTools::volume(aToolsCutAlgo->shape()) > 1.e-27) { + if (GeomAlgoAPI_ShapeTools::area(aToolsCutAlgo->shape()) > 1.e-27) { aTools.clear(); aTools.push_back(aToolsCutAlgo->shape()); aMakeShapeList->appendAlgo(aToolsCutAlgo); @@ -133,7 +150,8 @@ void FeaturesPlugin_BooleanSmash::execute() std::shared_ptr aBoolAlgo( new GeomAlgoAPI_Boolean(aShapesToSmash, aTools, - GeomAlgoAPI_Tools::BOOL_CUT)); + GeomAlgoAPI_Tools::BOOL_CUT, + aFuzzy)); // Checking that the algorithm worked properly. if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) { @@ -156,7 +174,7 @@ void FeaturesPlugin_BooleanSmash::execute() } else { std::shared_ptr aFillerAlgo( - new GeomAlgoAPI_PaveFiller(aShapesToAdd, true)); + new GeomAlgoAPI_PaveFiller(aShapesToAdd, true, aFuzzy)); if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFillerAlgo, getKind(), anError)) { setError(anError); return; @@ -167,8 +185,7 @@ void FeaturesPlugin_BooleanSmash::execute() } // take into account a version of SMASH feature - int aSmashVersion = version(); - if (aSmashVersion == THE_VERSION_1) { + if (data()->version() == BOP_VERSION_9_4()) { // merge hierarchies of compounds containing objects and tools // and append the result of the FUSE operation aShape = keepUnusedSubsOfCompound(aShape, anObjectsHistory, aToolsHistory, aMakeShapeList); @@ -176,20 +193,20 @@ void FeaturesPlugin_BooleanSmash::execute() std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, - anOriginalShapes, - anOriginalShapes, - aMakeShapeList, - aShape); + ModelAPI_Tools::loadModifiedShapes(aResultBody, + anOriginalShapes, + anOriginalShapes, + aMakeShapeList, + aShape); setResult(aResultBody, aResultIndex); aResultIndex++; - FeaturesPlugin_Tools::loadDeletedShapes(aResultBody, - GeomShapePtr(), - anOriginalShapes, - aMakeShapeList, - aShape); + ModelAPI_Tools::loadDeletedShapes(aResultBody, + GeomShapePtr(), + anOriginalShapes, + aMakeShapeList, + aShape); // remove the rest results if there were produced in the previous pass removeResults(aResultIndex);