#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
#include <GeomAlgoAPI_Boolean.h>
#include <GeomAlgoAPI_MakeShapeList.h>
#define FACE 4
#define _MODIFY_TAG 1
#define _DELETED_TAG 2
+#define _SUBSOLIDS_TAG 3 /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids
//=================================================================================================
FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
// extrusion works with faces always
aSelection->setSelectionType("SOLID");
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
}
//=================================================================================================
// Getting objects.
AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
- if (anObjectsSelList->size() == 0) {
- return;
- }
for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
// Getting tools.
AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
- if (aToolsSelList->size() == 0) {
- return;
- }
for(int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) {
std::shared_ptr<ModelAPI_AttributeSelection> aToolAttr = aToolsSelList->value(aToolsIndex);
std::shared_ptr<GeomAPI_Shape> aTool = aToolAttr->value();
}
int aResultIndex = 0;
- ListOfMakeShape aListOfMakeShape;
- std::shared_ptr<GeomAPI_DataMapOfShapeShape> aDataMapOfShapes;
switch(aType) {
case GeomAlgoAPI_Boolean::BOOL_CUT:
case GeomAlgoAPI_Boolean::BOOL_COMMON:{
+ if(anObjects.empty() || aTools.empty()) {
+ std::string aFeatureError = "Not enough objects for boolean operation";
+ setError(aFeatureError);
+ return;
+ }
+
// Cut each object with all tools
for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
- std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(
- new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
-
LoadNamingDS(aResultBody, anObject, aTools, aBoolAlgo);
setResult(aResultBody, aResultIndex);
aResultIndex++;
break;
}
case GeomAlgoAPI_Boolean::BOOL_FUSE: {
+ if(anObjects.empty() && aTools.size() > 1) {
+ anObjects.push_back(aTools.back());
+ aTools.pop_back();
+ }else if(aTools.empty() && anObjects.size() > 1) {
+ aTools.push_back(anObjects.back());
+ anObjects.pop_back();
+ }
+
+ if(anObjects.empty() || aTools.empty()) {
+ std::string aFeatureError = "Not enough objects for boolean operation";
+ setError(aFeatureError);
+ return;
+ }
+
// Fuse all objects and all tools.
GeomAlgoAPI_Boolean aBoolAlgo(anObjects, aTools, aType);
}
std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
- std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(
- new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
-
LoadNamingDS(aResultBody, anObjects.front(), aTools, aBoolAlgo);
setResult(aResultBody, aResultIndex);
aResultIndex++;
if(theBaseShape->isEqual(theAlgo.shape())) {
theResultBody->store(theAlgo.shape());
} else {
- theResultBody->storeModified(theBaseShape, theAlgo.shape());
+ theResultBody->storeModified(theBaseShape, theAlgo.shape(), _SUBSOLIDS_TAG);
GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();