1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesPlugin_Boolean.h"
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Document.h>
25 #include <ModelAPI_AttributeReference.h>
26 #include <ModelAPI_AttributeInteger.h>
27 #include <ModelAPI_ResultBody.h>
28 #include <ModelAPI_AttributeSelectionList.h>
29 #include <ModelAPI_Session.h>
30 #include <ModelAPI_Validator.h>
31 #include <ModelAPI_Tools.h>
33 #include <GeomAlgoAPI_Boolean.h>
34 #include <GeomAlgoAPI_MakeShapeCustom.h>
35 #include <GeomAlgoAPI_MakeShapeList.h>
36 #include <GeomAlgoAPI_Partition.h>
37 #include <GeomAlgoAPI_PaveFiller.h>
38 #include <GeomAlgoAPI_ShapeTools.h>
39 #include <GeomAPI_Face.h>
40 #include <GeomAPI_ShapeExplorer.h>
41 #include <GeomAPI_ShapeIterator.h>
46 //=================================================================================================
47 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean(const OperationType theOperationType)
48 : myOperationType(theOperationType)
52 //=================================================================================================
53 void FeaturesPlugin_Boolean::initAttributes()
55 AttributeSelectionListPtr aSelection =
56 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
57 FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
59 aSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
60 FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
62 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
63 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
66 //=================================================================================================
67 std::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::string& theAttrName)
69 std::shared_ptr<ModelAPI_AttributeReference> aObjRef = std::dynamic_pointer_cast<
70 ModelAPI_AttributeReference>(data()->attribute(theAttrName));
72 std::shared_ptr<ModelAPI_ResultBody> aConstr = std::dynamic_pointer_cast<
73 ModelAPI_ResultBody>(aObjRef->value());
75 return aConstr->shape();
77 return std::shared_ptr<GeomAPI_Shape>();
80 //=================================================================================================
81 FeaturesPlugin_Boolean::OperationType FeaturesPlugin_Boolean::operationType()
83 return myOperationType;
86 //=================================================================================================
87 void FeaturesPlugin_Boolean::execute()
89 ListOfShape anObjects, aTools, anEdgesAndFaces, aPlanes;
90 std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape> aCompSolidsObjects;
93 AttributeSelectionListPtr anObjectsSelList =
94 selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
95 for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
96 AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
97 std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
101 ResultPtr aContext = anObjectAttr->context();
102 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
103 if(aResCompSolidPtr.get()
104 && aResCompSolidPtr->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) {
105 std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
106 std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape>::iterator
107 anIt = aCompSolidsObjects.begin();
108 for(; anIt != aCompSolidsObjects.end(); anIt++) {
109 if(anIt->first->isEqual(aContextShape)) {
110 aCompSolidsObjects[anIt->first].push_back(anObject);
114 if(anIt == aCompSolidsObjects.end()) {
115 aCompSolidsObjects[aContextShape].push_back(anObject);
118 if(myOperationType != BOOL_FILL
119 && (anObject->shapeType() == GeomAPI_Shape::EDGE
120 || anObject->shapeType() == GeomAPI_Shape::FACE))
122 anEdgesAndFaces.push_back(anObject);
126 anObjects.push_back(anObject);
132 AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
133 for(int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) {
134 AttributeSelectionPtr aToolAttr = aToolsSelList->value(aToolsIndex);
135 GeomShapePtr aTool = aToolAttr->value();
137 // It could be a construction plane.
138 ResultPtr aContext = aToolAttr->context();
139 aPlanes.push_back(aToolAttr->context()->shape());
141 else if (myOperationType != BOOL_FILL
142 && (aTool->shapeType() == GeomAPI_Shape::EDGE
143 || aTool->shapeType() == GeomAPI_Shape::FACE))
145 anEdgesAndFaces.push_back(aTool);
147 aTools.push_back(aTool);
151 int aResultIndex = 0;
153 switch(myOperationType) {
157 if((anObjects.empty() && aCompSolidsObjects.empty())
158 || (aTools.empty() && aPlanes.empty())) {
159 std::string aFeatureError = "Error: Not enough objects for boolean operation.";
160 setError(aFeatureError);
164 // For solids cut each object with all tools.
165 for(ListOfShape::iterator
166 anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
167 std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
168 ListOfShape aListWithObject;
169 aListWithObject.push_back(anObject);
170 GeomAlgoAPI_MakeShapeList aMakeShapeList;
171 std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
172 GeomShapePtr aResShape;
174 switch(myOperationType) {
176 aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject,
178 GeomAlgoAPI_Boolean::BOOL_CUT));
179 aResShape = aBoolAlgo->shape();
183 aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject,
185 GeomAlgoAPI_Boolean::BOOL_COMMON));
186 aResShape = aBoolAlgo->shape();
190 std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
191 GeomAlgoAPI_ShapeTools::getBoundingBox(aListWithObject, 1.0);
194 ListOfShape aToolsWithPlanes = aTools;
195 for(ListOfShape::const_iterator anIt = aPlanes.cbegin();
196 anIt != aPlanes.cend();
199 GeomShapePtr aPlane = *anIt;
200 GeomShapePtr aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPlane, aBoundingPoints);
201 std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aMkShCustom(
202 new GeomAlgoAPI_MakeShapeCustom);
203 aMkShCustom->addModified(aPlane, aTool);
204 aMakeShapeList.appendAlgo(aMkShCustom);
205 aToolsWithPlanes.push_back(aTool);
208 aBoolAlgo.reset(new GeomAlgoAPI_Partition(aListWithObject, aToolsWithPlanes));
209 aResShape = aBoolAlgo->shape();
210 if (aResShape.get() && aResShape->shapeType() == GeomAPI_Shape::COMPOUND) {
211 int aSubResultsNb = 0;
212 GeomAPI_ShapeIterator anIt(aResShape);
213 for(; anIt.more(); anIt.next()) {
216 if(aSubResultsNb == 1) {
217 anIt.init(aResShape);
219 aResShape = anIt.current();
227 // Checking that the algorithm worked properly.
228 if(!aBoolAlgo->isDone()) {
229 static const std::string aFeatureError = "Error: Boolean algorithm failed.";
230 setError(aFeatureError);
233 if(aResShape->isNull()) {
234 static const std::string aShapeError = "Error: Resulting shape is Null.";
235 setError(aShapeError);
238 if(!aBoolAlgo->isValid()) {
239 std::string aFeatureError = "Error: Resulting shape is not valid.";
240 setError(aFeatureError);
244 aMakeShapeList.appendAlgo(aBoolAlgo);
246 if(GeomAlgoAPI_ShapeTools::volume(aResShape) > 1.e-27
247 || (myOperationType != BOOL_CUT && myOperationType != BOOL_COMMON))
249 std::shared_ptr<ModelAPI_ResultBody> aResultBody =
250 document()->createBody(data(), aResultIndex);
252 ListOfShape aUsedTools = aTools;
253 if (myOperationType == BOOL_FILL) {
254 aUsedTools.insert(aUsedTools.end(), aPlanes.begin(), aPlanes.end());
257 loadNamingDS(aResultBody, anObject, aUsedTools, aResShape,
258 aMakeShapeList, *(aBoolAlgo->mapOfSubShapes()),
259 myOperationType == BOOL_FILL);
260 setResult(aResultBody, aResultIndex);
265 // Compsolids handling
266 for(std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape>::iterator
267 anIt = aCompSolidsObjects.begin();
268 anIt != aCompSolidsObjects.end(); anIt++) {
269 std::shared_ptr<GeomAPI_Shape> aCompSolid = anIt->first;
270 ListOfShape& aUsedInOperationSolids = anIt->second;
272 // Collecting solids from compsolids which will not be modified in boolean operation.
273 ListOfShape aNotUsedSolids;
274 for(GeomAPI_ShapeExplorer
275 anExp(aCompSolid, GeomAPI_Shape::SOLID); anExp.more(); anExp.next()) {
276 std::shared_ptr<GeomAPI_Shape> aSolidInCompSolid = anExp.current();
277 ListOfShape::iterator anIt = aUsedInOperationSolids.begin();
278 for(; anIt != aUsedInOperationSolids.end(); anIt++) {
279 if(aSolidInCompSolid->isEqual(*anIt)) {
283 if(anIt == aUsedInOperationSolids.end()) {
284 aNotUsedSolids.push_back(aSolidInCompSolid);
288 GeomAlgoAPI_MakeShapeList aMakeShapeList;
289 std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
291 switch(myOperationType) {
293 aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
295 GeomAlgoAPI_Boolean::BOOL_CUT));
299 aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
301 GeomAlgoAPI_Boolean::BOOL_COMMON));
305 std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
306 GeomAlgoAPI_ShapeTools::getBoundingBox(aUsedInOperationSolids, 1.0);
309 ListOfShape aToolsWithPlanes = aTools;
310 for(ListOfShape::const_iterator anIt = aPlanes.cbegin();
311 anIt != aPlanes.cend();
314 GeomShapePtr aPlane = *anIt;
315 GeomShapePtr aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPlane, aBoundingPoints);
316 std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aMkShCustom(
317 new GeomAlgoAPI_MakeShapeCustom);
318 aMkShCustom->addModified(aPlane, aTool);
319 aMakeShapeList.appendAlgo(aMkShCustom);
320 aToolsWithPlanes.push_back(aTool);
323 aBoolAlgo.reset(new GeomAlgoAPI_Partition(aUsedInOperationSolids, aToolsWithPlanes));
328 // Checking that the algorithm worked properly.
329 if(!aBoolAlgo->isDone()) {
330 static const std::string aFeatureError = "Error: Boolean algorithm failed.";
331 setError(aFeatureError);
334 if(aBoolAlgo->shape()->isNull()) {
335 static const std::string aShapeError = "Error: Resulting shape is Null.";
336 setError(aShapeError);
339 if(!aBoolAlgo->isValid()) {
340 std::string aFeatureError = "Error: Resulting shape is not valid.";
341 setError(aFeatureError);
345 aMakeShapeList.appendAlgo(aBoolAlgo);
346 GeomAPI_DataMapOfShapeShape aMapOfShapes;
347 aMapOfShapes.merge(aBoolAlgo->mapOfSubShapes());
348 GeomShapePtr aResultShape = aBoolAlgo->shape();
350 // Add result to not used solids from compsolid.
351 if(!aNotUsedSolids.empty()) {
352 ListOfShape aShapesToAdd = aNotUsedSolids;
353 aShapesToAdd.push_back(aBoolAlgo->shape());
354 std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(
355 new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
356 if(!aFillerAlgo->isDone()) {
357 std::string aFeatureError = "Error: PaveFiller algorithm failed.";
358 setError(aFeatureError);
362 aMakeShapeList.appendAlgo(aFillerAlgo);
363 aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
364 aResultShape = aFillerAlgo->shape();
367 if(GeomAlgoAPI_ShapeTools::volume(aResultShape) > 1.e-27
368 || (myOperationType != BOOL_CUT && myOperationType != BOOL_COMMON))
370 std::shared_ptr<ModelAPI_ResultBody> aResultBody =
371 document()->createBody(data(), aResultIndex);
373 ListOfShape aUsedTools = aTools;
374 if (myOperationType == BOOL_FILL) {
375 aUsedTools.insert(aUsedTools.end(), aPlanes.begin(), aPlanes.end());
378 loadNamingDS(aResultBody,
384 myOperationType == BOOL_FILL);
385 setResult(aResultBody, aResultIndex);
392 if((anObjects.size() + aTools.size() +
393 aCompSolidsObjects.size() + anEdgesAndFaces.size()) < 2) {
394 std::string aFeatureError = "Error: Not enough objects for boolean operation.";
395 setError(aFeatureError);
399 // Collecting all solids which will be fused.
400 ListOfShape aSolidsToFuse;
401 aSolidsToFuse.insert(aSolidsToFuse.end(), anObjects.begin(), anObjects.end());
402 aSolidsToFuse.insert(aSolidsToFuse.end(), aTools.begin(), aTools.end());
404 // Collecting solids from compsolids which will not be modified
405 // in boolean operation and will be added to result.
406 ListOfShape aShapesToAdd;
407 for(std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape>::iterator
408 anIt = aCompSolidsObjects.begin();
409 anIt != aCompSolidsObjects.end(); anIt++) {
410 std::shared_ptr<GeomAPI_Shape> aCompSolid = anIt->first;
411 ListOfShape& aUsedInOperationSolids = anIt->second;
412 aSolidsToFuse.insert(aSolidsToFuse.end(), aUsedInOperationSolids.begin(),
413 aUsedInOperationSolids.end());
415 // Collect solids from compsolid which will not be modified in boolean operation.
416 for(GeomAPI_ShapeExplorer
417 anExp(aCompSolid, GeomAPI_Shape::SOLID); anExp.more(); anExp.next()) {
418 std::shared_ptr<GeomAPI_Shape> aSolidInCompSolid = anExp.current();
419 ListOfShape::iterator anIt = aUsedInOperationSolids.begin();
420 for(; anIt != aUsedInOperationSolids.end(); anIt++) {
421 if(aSolidInCompSolid->isEqual(*anIt)) {
425 if(anIt == aUsedInOperationSolids.end()) {
426 aShapesToAdd.push_back(aSolidInCompSolid);
431 ListOfShape anOriginalShapes = aSolidsToFuse;
432 anOriginalShapes.insert(anOriginalShapes.end(), aShapesToAdd.begin(), aShapesToAdd.end());
434 // Cut edges and faces(if we have any) with solids.
435 GeomAlgoAPI_MakeShapeList aMakeShapeList;
436 GeomAPI_DataMapOfShapeShape aMapOfShapes;
437 std::shared_ptr<GeomAPI_Shape> aCuttedEdgesAndFaces;
438 if(!anEdgesAndFaces.empty()) {
439 std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(new GeomAlgoAPI_Boolean(anEdgesAndFaces,
440 anOriginalShapes, GeomAlgoAPI_Boolean::BOOL_CUT));
441 if(aCutAlgo->isDone()) {
442 aCuttedEdgesAndFaces = aCutAlgo->shape();
443 aMakeShapeList.appendAlgo(aCutAlgo);
444 aMapOfShapes.merge(aCutAlgo->mapOfSubShapes());
447 anOriginalShapes.insert(anOriginalShapes.end(), anEdgesAndFaces.begin(),
448 anEdgesAndFaces.end());
450 // If we have compsolids then cut with not used solids all others.
451 if(!aShapesToAdd.empty()) {
452 aSolidsToFuse.clear();
453 for(ListOfShape::iterator
454 anIt = anOriginalShapes.begin(); anIt != anOriginalShapes.end(); anIt++) {
455 ListOfShape aOneObjectList;
456 aOneObjectList.push_back(*anIt);
457 std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(
458 new GeomAlgoAPI_Boolean(aOneObjectList, aShapesToAdd, GeomAlgoAPI_Boolean::BOOL_CUT));
460 if(GeomAlgoAPI_ShapeTools::volume(aCutAlgo->shape()) > 1.e-27) {
461 aSolidsToFuse.push_back(aCutAlgo->shape());
462 aMakeShapeList.appendAlgo(aCutAlgo);
463 aMapOfShapes.merge(aCutAlgo->mapOfSubShapes());
468 if(!aSolidsToFuse.empty()) {
470 anObjects.push_back(aSolidsToFuse.back());
471 aSolidsToFuse.pop_back();
472 aTools = aSolidsToFuse;
475 // Fuse all objects and all tools.
476 std::shared_ptr<GeomAPI_Shape> aShape;
477 if(anObjects.size() == 1 && aTools.empty()) {
478 aShape = anObjects.front();
479 } else if(anObjects.empty() && aTools.size() == 1) {
480 aShape = aTools.front();
481 } else if((anObjects.size() + aTools.size()) > 1){
482 std::shared_ptr<GeomAlgoAPI_Boolean> aFuseAlgo(new GeomAlgoAPI_Boolean(anObjects,
484 GeomAlgoAPI_Boolean::BOOL_FUSE));
486 // Checking that the algorithm worked properly.
487 if(!aFuseAlgo->isDone()) {
488 static const std::string aFeatureError = "Error: Boolean algorithm failed.";
489 setError(aFeatureError);
492 if(aFuseAlgo->shape()->isNull()) {
493 static const std::string aShapeError = "Error: Resulting shape is Null.";
494 setError(aShapeError);
497 if(!aFuseAlgo->isValid()) {
498 std::string aFeatureError = "Error: Resulting shape is not valid.";
499 setError(aFeatureError);
503 aShape = aFuseAlgo->shape();
504 aMakeShapeList.appendAlgo(aFuseAlgo);
505 aMapOfShapes.merge(aFuseAlgo->mapOfSubShapes());
508 // Combine result with not used solids from compsolid and edges and faces (if we have any).
509 if(aCuttedEdgesAndFaces.get() && !aCuttedEdgesAndFaces->isNull()) {
510 aShapesToAdd.push_back(aCuttedEdgesAndFaces);
512 aShapesToAdd.insert(aShapesToAdd.end(), anEdgesAndFaces.begin(), anEdgesAndFaces.end());
514 if(!aShapesToAdd.empty()) {
516 aShapesToAdd.push_back(aShape);
518 std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(
519 new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
520 if(!aFillerAlgo->isDone()) {
521 std::string aFeatureError = "Error: PaveFiller algorithm failed.";
522 setError(aFeatureError);
525 if(aFillerAlgo->shape()->isNull()) {
526 static const std::string aShapeError = "Error: Resulting shape is Null.";
527 setError(aShapeError);
530 if(!aFillerAlgo->isValid()) {
531 std::string aFeatureError = "Error: Resulting shape is not valid.";
532 setError(aFeatureError);
536 aShape = aFillerAlgo->shape();
537 aMakeShapeList.appendAlgo(aFillerAlgo);
538 aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
541 std::shared_ptr<GeomAPI_Shape> aBackShape = anOriginalShapes.back();
542 anOriginalShapes.pop_back();
543 std::shared_ptr<ModelAPI_ResultBody> aResultBody =
544 document()->createBody(data(), aResultIndex);
545 loadNamingDS(aResultBody, aBackShape, anOriginalShapes,
546 aShape, aMakeShapeList, aMapOfShapes);
547 setResult(aResultBody, aResultIndex);
552 if((anObjects.empty() && aCompSolidsObjects.empty()) || aTools.empty()) {
553 std::string aFeatureError = "Error: Not enough objects for boolean operation.";
554 setError(aFeatureError);
558 // List of original solids for naming.
559 ListOfShape anOriginalShapes;
560 anOriginalShapes.insert(anOriginalShapes.end(), anObjects.begin(), anObjects.end());
561 anOriginalShapes.insert(anOriginalShapes.end(), aTools.begin(), aTools.end());
563 // Collecting all solids which will be smashed.
564 ListOfShape aShapesToSmash;
565 aShapesToSmash.insert(aShapesToSmash.end(), anObjects.begin(), anObjects.end());
567 // Collecting solids from compsolids which will not be modified in
568 // boolean operation and will be added to result.
569 ListOfShape aShapesToAdd;
570 for(std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape>::iterator
571 anIt = aCompSolidsObjects.begin();
572 anIt != aCompSolidsObjects.end(); anIt++) {
573 std::shared_ptr<GeomAPI_Shape> aCompSolid = anIt->first;
574 ListOfShape& aUsedInOperationSolids = anIt->second;
575 anOriginalShapes.push_back(aCompSolid);
576 aShapesToSmash.insert(aShapesToSmash.end(), aUsedInOperationSolids.begin(),
577 aUsedInOperationSolids.end());
579 // Collect solids from compsolid which will not be modified in boolean operation.
580 for(GeomAPI_ShapeExplorer
581 anExp(aCompSolid, GeomAPI_Shape::SOLID); anExp.more(); anExp.next()) {
582 std::shared_ptr<GeomAPI_Shape> aSolidInCompSolid = anExp.current();
583 ListOfShape::iterator anIt = aUsedInOperationSolids.begin();
584 for(; anIt != aUsedInOperationSolids.end(); anIt++) {
585 if(aSolidInCompSolid->isEqual(*anIt)) {
589 if(anIt == aUsedInOperationSolids.end()) {
590 aShapesToAdd.push_back(aSolidInCompSolid);
595 GeomAlgoAPI_MakeShapeList aMakeShapeList;
596 GeomAPI_DataMapOfShapeShape aMapOfShapes;
597 if(!aShapesToAdd.empty()) {
598 // Cut objects with not used solids.
599 std::shared_ptr<GeomAlgoAPI_Boolean> anObjectsCutAlgo(new GeomAlgoAPI_Boolean(
602 GeomAlgoAPI_Boolean::BOOL_CUT));
604 if(GeomAlgoAPI_ShapeTools::volume(anObjectsCutAlgo->shape()) > 1.e-27) {
605 aShapesToSmash.clear();
606 aShapesToSmash.push_back(anObjectsCutAlgo->shape());
607 aMakeShapeList.appendAlgo(anObjectsCutAlgo);
608 aMapOfShapes.merge(anObjectsCutAlgo->mapOfSubShapes());
611 // Cut tools with not used solids.
612 std::shared_ptr<GeomAlgoAPI_Boolean> aToolsCutAlgo(new GeomAlgoAPI_Boolean(aTools,
614 GeomAlgoAPI_Boolean::BOOL_CUT));
616 if(GeomAlgoAPI_ShapeTools::volume(aToolsCutAlgo->shape()) > 1.e-27) {
618 aTools.push_back(aToolsCutAlgo->shape());
619 aMakeShapeList.appendAlgo(aToolsCutAlgo);
620 aMapOfShapes.merge(aToolsCutAlgo->mapOfSubShapes());
624 // Cut objects with tools.
625 std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo(new GeomAlgoAPI_Boolean(aShapesToSmash,
627 GeomAlgoAPI_Boolean::BOOL_CUT));
629 // Checking that the algorithm worked properly.
630 if(!aBoolAlgo->isDone()) {
631 static const std::string aFeatureError = "Error: Boolean algorithm failed.";
632 setError(aFeatureError);
635 if(aBoolAlgo->shape()->isNull()) {
636 static const std::string aShapeError = "Error: Resulting shape is Null.";
637 setError(aShapeError);
640 if(!aBoolAlgo->isValid()) {
641 std::string aFeatureError = "Error: Resulting shape is not valid.";
642 setError(aFeatureError);
645 aMakeShapeList.appendAlgo(aBoolAlgo);
646 aMapOfShapes.merge(aBoolAlgo->mapOfSubShapes());
648 // Put all (cut result, tools and not used solids) to PaveFiller.
649 aShapesToAdd.push_back(aBoolAlgo->shape());
650 aShapesToAdd.insert(aShapesToAdd.end(), aTools.begin(), aTools.end());
652 std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(new GeomAlgoAPI_PaveFiller(aShapesToAdd,
654 if(!aFillerAlgo->isDone()) {
655 std::string aFeatureError = "Error: PaveFiller algorithm failed.";
656 setError(aFeatureError);
659 if(aFillerAlgo->shape()->isNull()) {
660 static const std::string aShapeError = "Error: Resulting shape is Null.";
661 setError(aShapeError);
664 if(!aFillerAlgo->isValid()) {
665 std::string aFeatureError = "Error: Resulting shape is not valid.";
666 setError(aFeatureError);
670 std::shared_ptr<GeomAPI_Shape> aShape = aFillerAlgo->shape();
671 aMakeShapeList.appendAlgo(aFillerAlgo);
672 aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
674 std::shared_ptr<GeomAPI_Shape> aFrontShape = anOriginalShapes.front();
675 anOriginalShapes.pop_front();
676 std::shared_ptr<ModelAPI_ResultBody> aResultBody =
677 document()->createBody(data(), aResultIndex);
678 loadNamingDS(aResultBody, aFrontShape, anOriginalShapes,
679 aShape, aMakeShapeList, aMapOfShapes);
680 setResult(aResultBody, aResultIndex);
686 std::string anOperationError = "Error: Wrong type of operation";
687 setError(anOperationError);
691 // remove the rest results if there were produced in the previous pass
692 removeResults(aResultIndex);
695 //=================================================================================================
696 void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
697 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
698 const ListOfShape& theTools,
699 const std::shared_ptr<GeomAPI_Shape> theResultShape,
700 GeomAlgoAPI_MakeShape& theMakeShape,
701 GeomAPI_DataMapOfShapeShape& theMapOfShapes,
702 const bool theIsStoreAsGenerated)
705 if(theBaseShape->isEqual(theResultShape)) {
706 theResultBody->store(theResultShape, false);
708 const int aModifyTag = 1;
709 const int aModifyEdgeTag = 2;
710 const int aModifyFaceTag = 3;
711 const int aDeletedTag = 4;
712 /// sub solids will be placed at labels 5, 6, etc. if result is compound of solids
713 const int aSubsolidsTag = 5;
715 theResultBody->storeModified(theBaseShape, theResultShape, aSubsolidsTag);
717 const std::string aModName = "Modified";
718 const std::string aModEName = "Modified_Edge";
719 const std::string aModFName = "Modified_Face";
721 theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::EDGE,
722 aModifyEdgeTag, aModEName, theMapOfShapes, false, theIsStoreAsGenerated, true);
723 theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::FACE,
724 aModifyFaceTag, aModFName, theMapOfShapes, false, theIsStoreAsGenerated, true);
725 theResultBody->loadDeletedShapes(&theMakeShape, theBaseShape,
726 GeomAPI_Shape::FACE, aDeletedTag);
730 for(ListOfShape::const_iterator
731 anIter = theTools.begin(); anIter != theTools.end(); anIter++) {
732 if((*anIter)->shapeType() <= GeomAPI_Shape::FACE) {
733 aTag = aModifyFaceTag;
736 aTag = aModifyEdgeTag;
739 theResultBody->loadAndOrientModifiedShapes(&theMakeShape, *anIter,
740 aName == aModEName ? GeomAPI_Shape::EDGE : GeomAPI_Shape::FACE,
741 aTag, aName, theMapOfShapes, false, theIsStoreAsGenerated, true);
742 theResultBody->loadDeletedShapes(&theMakeShape, *anIter, GeomAPI_Shape::FACE, aDeletedTag);