-// Copyright (C) 2014-2021 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
#include "FeaturesPlugin_BooleanCut.h"
-#include "FeaturesPlugin_Tools.h"
-
#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Tools.h>
#include <GeomAPI_ShapeExplorer.h>
#include <GeomAPI_ShapeIterator.h>
+
+static const ListOfShape ExplodeCompounds(const ListOfShape &aList)
+{
+ ListOfShape subShapes;
+ for (auto shp = aList.cbegin(); shp != aList.cend(); ++shp)
+ {
+ if ((*shp).get() && (*shp)->isCompound()) {
+ // Use all sub shapes of the compound
+ for (GeomAPI_ShapeIterator anExp(*shp); anExp.more(); anExp.next()) {
+ GeomShapePtr aCurrent = anExp.current();
+ subShapes.push_back(aCurrent);
+ }
+ }
+ else
+ subShapes.push_back(*shp);
+ }
+
+ return subShapes;
+}
+
//==================================================================================================
FeaturesPlugin_BooleanCut::FeaturesPlugin_BooleanCut()
: FeaturesPlugin_Boolean(FeaturesPlugin_Boolean::BOOL_CUT)
return;
}
- std::vector<FeaturesPlugin_Tools::ResultBaseAlgo> aResultBaseAlgoList;
+ std::vector<ModelAPI_Tools::ResultBaseAlgo> aResultBaseAlgoList;
ListOfShape aResultShapesList;
std::string anError;
keepUnusedSubsOfCompound(GeomShapePtr(), anObjects, aTools, aMakeShapeList);
}
+ // 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);
+
+ // When selecting a compound tool object, use its exploded subshapes as tool object instead.
+ const ListOfShape aToolList = ExplodeCompounds(aTools.objects());
+
// For solids cut each object with all tools.
bool isOk = true;
for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin();
if (aShapeType == GeomAPI_Shape::COMPOUND) {
// Compound handling
isOk = processCompound(GeomAlgoAPI_Tools::BOOL_CUT,
- anObjects, aParent, aTools.objects(),
+ anObjects, aParent, aToolList,
+ aFuzzy,
aResultIndex, aResultBaseAlgoList, aResultShapesList,
aResultCompound);
}
else if (aShapeType == GeomAPI_Shape::COMPSOLID) {
// Compsolid handling
isOk = processCompsolid(GeomAlgoAPI_Tools::BOOL_CUT,
- anObjects, aParent, aTools.objects(), ListOfShape(),
+ anObjects, aParent, aToolList, ListOfShape(),
+ aFuzzy,
aResultIndex, aResultBaseAlgoList, aResultShapesList,
aResultCompound);
}
} else {
// process object as is
isOk = processObject(GeomAlgoAPI_Tools::BOOL_CUT,
- anObject, aTools.objects(), aPlanes,
+ anObject, aToolList, aPlanes,
+ aFuzzy,
aResultIndex, aResultBaseAlgoList, aResultShapesList,
aResultCompound);
}
}
- storeResult(anObjects.objects(), aTools.objects(), aResultCompound, aResultIndex,
+ storeResult(anObjects.objects(), aToolList, aResultCompound, aResultIndex,
aMakeShapeList, aResultBaseAlgoList);
// Store deleted shapes after all results has been proceeded. This is to avoid issue when in one
// result shape has been deleted, but in another it was modified or stayed.
if (!aResultCompound)
aResultCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
- FeaturesPlugin_Tools::loadDeletedShapes(aResultBaseAlgoList,
- aTools.objects(),
- aResultCompound);
+ ModelAPI_Tools::loadDeletedShapes(aResultBaseAlgoList,
+ aToolList,
+ aResultCompound);
// remove the rest results if there were produced in the previous pass
removeResults(aResultIndex);