Salome HOME
Updated copyright comment
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_CompositeBoolean.cpp
1 // Copyright (C) 2014-2024  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "FeaturesPlugin_CompositeBoolean.h"
21
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_Tools.h>
24
25 #include <GeomAlgoAPI_Boolean.h>
26 #include <GeomAlgoAPI_CompoundBuilder.h>
27 #include <GeomAlgoAPI_MakeShapeList.h>
28 #include <GeomAlgoAPI_PaveFiller.h>
29 #include <GeomAlgoAPI_ShapeTools.h>
30 #include <GeomAlgoAPI_MakeShapeCustom.h>
31
32 #include <GeomAPI_ShapeIterator.h>
33
34 #include <map>
35
36 //=================================================================================================
37 void FeaturesPlugin_CompositeBoolean::initBooleanAttributes()
38 {
39   myFeature->data()->addAttribute(OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
40 }
41
42 //=================================================================================================
43 void FeaturesPlugin_CompositeBoolean::executeCompositeBoolean()
44 {
45   // Make generation.
46   ListOfShape aGenBaseShapes;
47   ListOfMakeShape aGenMakeShapes;
48   if(!makeGeneration(aGenBaseShapes, aGenMakeShapes)) {
49     return;
50   }
51
52   // Getting tools.
53   ListOfShape aTools;
54   for(ListOfMakeShape::const_iterator
55       anIt = aGenMakeShapes.cbegin(); anIt != aGenMakeShapes.cend(); ++anIt) {
56     aTools.push_back((*anIt)->shape());
57   }
58
59   // Make boolean.
60   ListOfShape aBooleanObjects;
61   ListOfMakeShape aBooleanMakeShapes;
62   if(!makeBoolean(aTools, aBooleanObjects, aBooleanMakeShapes)) {
63     return;
64   }
65
66   if(myOperationType == BOOL_FUSE) {
67     aTools.splice(aTools.begin(), aBooleanObjects);
68     aBooleanObjects.splice(aBooleanObjects.begin(), aTools, aTools.begin());
69   }
70
71   // Store result.
72   int aResultIndex = 0;
73   std::vector<ResultBaseAlgo> aResultBaseAlgoList;
74   ListOfShape aResultShapesList;
75   ListOfShape::const_iterator aBoolObjIt = aBooleanObjects.cbegin();
76   ListOfMakeShape::const_iterator aBoolMSIt = aBooleanMakeShapes.cbegin();
77   for(; aBoolObjIt != aBooleanObjects.cend() && aBoolMSIt != aBooleanMakeShapes.cend();
78       ++aBoolObjIt, ++aBoolMSIt) {
79
80     ResultBodyPtr aResultBody = myFeature->document()->createBody(myFeature->data(), aResultIndex);
81
82     if((*aBoolObjIt)->isEqual((*aBoolMSIt)->shape())) {
83       aResultBody->store((*aBoolMSIt)->shape(), false);
84     }
85     else
86     {
87       aResultBody->storeModified(*aBoolObjIt, (*aBoolMSIt)->shape());
88
89       // Store generation history.
90       ListOfShape::const_iterator aGenBaseIt = aGenBaseShapes.cbegin();
91       ListOfMakeShape::const_iterator aGenMSIt = aGenMakeShapes.cbegin();
92       for(; aGenBaseIt != aGenBaseShapes.cend() && aGenMSIt != aGenMakeShapes.cend();
93           ++aGenBaseIt, ++aGenMSIt) {
94         std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMSList(new GeomAlgoAPI_MakeShapeList());
95         aMSList->appendAlgo(*aGenMSIt);
96         aMSList->appendAlgo(*aBoolMSIt);
97         storeGenerationHistory(aResultBody, *aGenBaseIt, aMSList);
98       }
99
100       storeModificationHistory(aResultBody, *aBoolObjIt, aTools, *aBoolMSIt);
101
102       ResultBaseAlgo aRBA;
103       aRBA.resultBody = aResultBody;
104       aRBA.baseShape = *aBoolObjIt;
105       aRBA.makeShape = *aBoolMSIt;
106       aResultBaseAlgoList.push_back(aRBA);
107       aResultShapesList.push_back((*aBoolMSIt)->shape());
108     }
109
110     myFeature->setResult(aResultBody, aResultIndex++);
111   }
112
113   // Store deleted shapes after all results has been proceeded. This is to avoid issue when in one
114   // result shape has been deleted, but in another it was modified or stayed.
115   GeomShapePtr aResultShapesCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
116   storeDeletedShapes(aResultBaseAlgoList, aTools, aResultShapesCompound);
117
118   myFeature->removeResults(aResultIndex);
119 }
120
121 //=================================================================================================
122 bool FeaturesPlugin_CompositeBoolean::cutRecursiveCompound(const GeomShapePtr theCompound,
123                                                            const ListOfShape& theTools,
124                                  std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList,
125                                                            GeomShapePtr& theResult)
126 {
127   // I. If theCompound is among the selected objects,
128   //    cut it by all tools and return result through theResult.
129   // It can be a SOLID, ?COMPOUND?, ?COMPSOLID?
130   AttributeSelectionListPtr anObjectsSelList = myFeature->selectionList(OBJECTS_ID());
131   for (int anObjIndex = 0; anObjIndex < anObjectsSelList->size(); anObjIndex++) {
132     AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjIndex);
133     GeomShapePtr anObject = anObjectAttr->value();
134     if (theCompound->isEqual(anObject)) {
135       // Cut theCompound itself
136       ListOfShape aListWithObject;
137       aListWithObject.push_back(anObject);
138       std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo
139         (new GeomAlgoAPI_Boolean(aListWithObject, theTools, GeomAlgoAPI_Tools::BOOL_CUT));
140
141       // Checking that the algorithm worked properly.
142       if (!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) {
143         myFeature->setError("Error: Boolean algorithm failed.");
144         return false;
145       }
146
147       if (GeomAlgoAPI_ShapeTools::area(aBoolAlgo->shape()) > 1.e-27) {
148         theMakeShapeList->appendAlgo(aBoolAlgo);
149         theResult = aBoolAlgo->shape();
150         return true;
151       }
152       return false;
153     }
154   }
155
156   // II. Iterate the COMPOUND or COMPSOLID
157   //     to find and cut Objects among its sub-shapes
158   if (theCompound->shapeType() == GeomAPI_Shape::COMPOUND ||
159       theCompound->shapeType() == GeomAPI_Shape::COMPSOLID) {
160
161     bool hasCut = false;
162     ListOfShape aShapesToAdd;
163     for (GeomAPI_ShapeIterator it (theCompound); it.more(); it.next()) {
164       GeomShapePtr aSubShape = it.current();
165       GeomShapePtr aResult;
166       if (cutRecursiveCompound(aSubShape, theTools, theMakeShapeList, aResult)) {
167         hasCut = true;
168         aShapesToAdd.push_back(aResult);
169       }
170       else {
171         aShapesToAdd.push_back(aSubShape);
172       }
173     }
174
175     if (hasCut) {
176       if (theCompound->shapeType() == GeomAPI_Shape::COMPSOLID) {
177         // Build COMPSOLID
178         std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo
179           (new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
180         if (!aFillerAlgo->isDone() || aFillerAlgo->shape()->isNull() || !aFillerAlgo->isValid()) {
181           myFeature->setError("Error: PaveFiller algorithm failed.");
182           return false;
183         }
184         theResult = aFillerAlgo->shape();
185         theMakeShapeList->appendAlgo(aFillerAlgo);
186       }
187       else {
188         // Build COMPOUND
189         theResult = GeomAlgoAPI_CompoundBuilder::compound(aShapesToAdd);
190         std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aCompMkr (new GeomAlgoAPI_MakeShapeCustom);
191         aCompMkr->setResult(theResult);
192         aCompMkr->addModified(theCompound, theResult); // ??
193         theMakeShapeList->appendAlgo(aCompMkr);
194       }
195       return true;
196     }
197   }
198
199   return false; // no cuts
200 }
201
202 //=================================================================================================
203 void FeaturesPlugin_CompositeBoolean::addSubShapes (const GeomShapePtr theCompound,
204                                                     const ListOfShape& theSubShapesToAvoid,
205                                                     ListOfShape& theSubShapesToAdd) {
206   for (GeomAPI_ShapeIterator aCompoundIt (theCompound);
207        aCompoundIt.more();
208        aCompoundIt.next()) {
209     GeomShapePtr aCompoundSS = aCompoundIt.current();
210     ListOfShape::const_iterator aUseIt = theSubShapesToAvoid.cbegin();
211     for (; aUseIt != theSubShapesToAvoid.cend(); aUseIt++) {
212       if (aCompoundSS->isEqual(*aUseIt)) {
213         break;
214       }
215     }
216     if (aUseIt == theSubShapesToAvoid.cend()) {
217       if (aCompoundSS->shapeType() == GeomAPI_Shape::COMPSOLID ||
218           aCompoundSS->shapeType() == GeomAPI_Shape::COMPOUND) {
219         addSubShapes(aCompoundSS, theSubShapesToAvoid, theSubShapesToAdd);
220       }
221       else {
222         theSubShapesToAdd.push_back(aCompoundSS);
223       }
224     }
225   }
226 }
227
228 //=================================================================================================
229 bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools,
230                                                   ListOfShape& theObjects,
231                                                   ListOfMakeShape& theMakeShapes)
232 {
233   // Getting objects.
234   ListOfShape anObjects, anEdgesAndFaces, aCompSolids;
235   std::map<GeomShapePtr, ListOfShape> aCompSolidsObjects;
236   bool aCompoundsOnly = true;// if there are only compounds, do not use filler restoring compsolids
237
238   AttributeSelectionListPtr anObjectsSelList = myFeature->selectionList(OBJECTS_ID());
239
240   // collect recursive (complex) compounds, if any
241   ListOfShape aCompounds; // recursive compounds
242   GeomAPI_DataMapOfShapeShape aCompoundsMap; // recursive compounds map
243   for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
244     AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
245     ResultPtr aContext = anObjectAttr->context();
246     ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
247     if (aResCompSolidPtr.get()) {
248       // Root body owner (true)
249       ResultBodyPtr aResRootPtr = ModelAPI_Tools::bodyOwner(aContext, true);
250       if (!aResRootPtr->isSame(aResCompSolidPtr)) {
251         aCompoundsMap.bind(aResRootPtr->shape(), aResRootPtr->shape());
252         aCompounds.push_back(aResRootPtr->shape());
253       }
254     }
255   }
256
257   for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
258     AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
259     GeomShapePtr anObject = anObjectAttr->value();
260     if(!anObject.get()) {
261       myFeature->setError("Error: Could not get object.");
262       return false;
263     }
264     ResultPtr aContext = anObjectAttr->context();
265     ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
266     if(aResCompSolidPtr.get()) {
267       ResultBodyPtr aResRootPtr = ModelAPI_Tools::bodyOwner(aContext, true);
268       if (!aCompoundsMap.isBound(aResRootPtr->shape())) {
269         // Compsolid or a simple (one-level) compound
270         GeomShapePtr aContextShape = aResCompSolidPtr->shape();
271         std::map<GeomShapePtr, ListOfShape>::iterator anIt = aCompSolidsObjects.begin();
272         for(; anIt != aCompSolidsObjects.end(); anIt++) {
273           if(anIt->first->isEqual(aContextShape)) {
274             aCompSolidsObjects[anIt->first].push_back(anObject);
275             break;
276           }
277         }
278         if(anIt == aCompSolidsObjects.end()) {
279           aCompSolidsObjects[aContextShape].push_back(anObject);
280           aCompSolids.push_back(aContextShape);
281           if (aContextShape->shapeType() != GeomAPI_Shape::COMPOUND)
282             aCompoundsOnly = false;
283         }
284       }
285     } else {
286       if(anObject->shapeType() == GeomAPI_Shape::EDGE ||
287          anObject->shapeType() == GeomAPI_Shape::FACE) {
288         anEdgesAndFaces.push_back(anObject);
289       } else {
290         anObjects.push_back(anObject);
291       }
292     }
293   }
294
295   switch(myOperationType) {
296     case BOOL_CUT: {
297       if((anObjects.empty() && aCompSolidsObjects.empty()
298           && aCompoundsMap.size() < 1) || theTools.empty()) {
299         myFeature->setError("Error: Not enough objects for boolean operation.");
300         return false;
301       }
302
303       // For solids cut each object with all tools.
304       for(ListOfShape::const_iterator
305           anIt = anObjects.cbegin(); anIt != anObjects.cend(); ++anIt) {
306         GeomShapePtr anObject = *anIt;
307         ListOfShape aListWithObject;
308         aListWithObject.push_back(anObject);
309         std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo(new GeomAlgoAPI_Boolean(aListWithObject,
310                                                                 theTools,
311                                                                 GeomAlgoAPI_Tools::BOOL_CUT));
312
313         // Checking that the algorithm worked properly.
314         if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) {
315           myFeature->setError("Error: Boolean algorithm failed.");
316           return false;
317         }
318
319         if(GeomAlgoAPI_ShapeTools::area(aBoolAlgo->shape()) > 1.e-27) {
320           theObjects.push_back(anObject);
321           theMakeShapes.push_back(aBoolAlgo);
322         }
323       }
324
325       // Compsolids handling
326       for(std::map<GeomShapePtr, ListOfShape>::const_iterator anIt = aCompSolidsObjects.cbegin();
327           anIt != aCompSolidsObjects.cend(); ++anIt) {
328         GeomShapePtr aCompSolid = anIt->first;
329         const ListOfShape& aUsedShapes = anIt->second;
330
331         // Collecting solids from compsolids which will not be modified in boolean operation.
332         ListOfShape aShapesToAdd;
333         for (GeomAPI_ShapeIterator aCompSolidIt(aCompSolid);
334              aCompSolidIt.more();
335              aCompSolidIt.next())
336         {
337           GeomShapePtr aSolidInCompSolid = aCompSolidIt.current();
338           ListOfShape::const_iterator aUsedShapesIt = aUsedShapes.cbegin();
339           for(; aUsedShapesIt != aUsedShapes.cend(); ++aUsedShapesIt) {
340             if(aSolidInCompSolid->isEqual(*aUsedShapesIt)) {
341               break;
342             }
343           }
344           if(aUsedShapesIt == aUsedShapes.end()) {
345             aShapesToAdd.push_back(aSolidInCompSolid);
346           }
347         }
348
349         std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo(new GeomAlgoAPI_Boolean(aUsedShapes,
350                                                                   theTools,
351                                                                   GeomAlgoAPI_Tools::BOOL_CUT));
352
353         // Checking that the algorithm worked properly.
354         if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) {
355           myFeature->setError("Error: Boolean algorithm failed.");
356           return false;
357         }
358
359         std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
360         aMakeShapeList->appendAlgo(aBoolAlgo);
361
362         // Add result to not used solids from compsolid.
363         GeomShapePtr aBoolRes = aBoolAlgo->shape();
364         if (!aShapesToAdd.empty()) {
365           aShapesToAdd.push_back(aBoolRes);
366           if (aCompoundsOnly)
367           {  // 23885: if there are no compsolids in input, do not use filler to make compsolids
368             aBoolRes = GeomAlgoAPI_CompoundBuilder::compound(aShapesToAdd);
369             std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aCompMkr(new GeomAlgoAPI_MakeShapeCustom);
370             aCompMkr->setResult(aBoolRes);
371             for(ListOfShape::iterator aCS = aCompSolids.begin(); aCS != aCompSolids.end(); aCS++)
372               aCompMkr->addModified(*aCS, aBoolRes);
373             aMakeShapeList->appendAlgo(aCompMkr);
374           }
375           else
376           {
377             std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(
378               new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
379             if (!aFillerAlgo->isDone() || aFillerAlgo->shape()->isNull() || !aFillerAlgo->isValid())
380             {
381               myFeature->setError("Error: PaveFiller algorithm failed.");
382               return false;
383             }
384             aBoolRes = aFillerAlgo->shape();
385             aMakeShapeList->appendAlgo(aFillerAlgo);
386           }
387         }
388
389         if(GeomAlgoAPI_ShapeTools::area(aBoolRes) > 1.e-27) {
390           theObjects.push_back(aCompSolid);
391           theMakeShapes.push_back(aMakeShapeList);
392         }
393       }
394
395       // Complex (recursive) compounds handling
396       for(ListOfShape::const_iterator anIt = aCompounds.cbegin();
397           anIt != aCompounds.cend(); ++anIt) {
398         GeomShapePtr aCompound = (*anIt);
399         GeomShapePtr aRes;
400         std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList (new GeomAlgoAPI_MakeShapeList());
401         cutRecursiveCompound(aCompound, theTools, aMakeShapeList, aRes);
402         theObjects.push_back(aCompound);
403         theMakeShapes.push_back(aMakeShapeList);
404       }
405
406       break;
407     }
408     case BOOL_FUSE: {
409       // Set objects.
410       theObjects.insert(theObjects.end(), anEdgesAndFaces.begin(), anEdgesAndFaces.end());
411       theObjects.insert(theObjects.end(), anObjects.begin(), anObjects.end());
412       theObjects.insert(theObjects.end(), aCompSolids.begin(), aCompSolids.end());
413       theObjects.insert(theObjects.end(), aCompounds.begin(), aCompounds.end());
414
415       // Filter edges and faces in tools.
416       ListOfShape aTools;
417       for(ListOfShape::const_iterator anIt = theTools.cbegin(); anIt != theTools.cend(); ++anIt) {
418         if((*anIt)->shapeType() == GeomAPI_Shape::EDGE ||
419            (*anIt)->shapeType() == GeomAPI_Shape::FACE) {
420           anEdgesAndFaces.push_back(*anIt);
421         } else {
422           aTools.push_back(*anIt);
423         }
424       }
425
426       if((anObjects.size() + aTools.size() + aCompounds.size() +
427           aCompSolidsObjects.size() + anEdgesAndFaces.size()) < 2) {
428         myFeature->setError("Error: Not enough objects for boolean operation.");
429         return false;
430       }
431
432       // Collecting all solids which will be fused.
433       ListOfShape aSolidsToFuse;
434       aSolidsToFuse.insert(aSolidsToFuse.end(), anObjects.begin(), anObjects.end());
435       aSolidsToFuse.insert(aSolidsToFuse.end(), aTools.begin(), aTools.end());
436
437       // Collecting solids and compsolids from compounds which will not be
438       // modified in boolean operation and will be added to result.
439       ListOfShape aShapesToAdd;
440       for (ListOfShape::iterator anIt = aCompounds.begin();
441            anIt != aCompounds.end(); anIt++) {
442         GeomShapePtr aCompound = (*anIt);
443         addSubShapes(aCompound, anObjects, aShapesToAdd);
444       }
445
446       // Collecting solids from compsolids which will not be
447       // modified in boolean operation and will be added to result.
448       for (std::map<GeomShapePtr, ListOfShape>::iterator anIt = aCompSolidsObjects.begin();
449            anIt != aCompSolidsObjects.end(); anIt++) {
450         GeomShapePtr aCompSolid = anIt->first;
451         ListOfShape& aUsedShapes = anIt->second;
452         aSolidsToFuse.insert(aSolidsToFuse.end(), aUsedShapes.begin(), aUsedShapes.end()); //???
453         addSubShapes(aCompSolid, aUsedShapes, aShapesToAdd);
454       }
455
456       // Cut edges and faces(if we have any) with solids.
457       ListOfShape aCutTools;
458       aCutTools.insert(aCutTools.end(), anObjects.begin(), anObjects.end());
459       aCutTools.insert(aCutTools.end(), aCompSolids.begin(), aCompSolids.end());
460       aCutTools.insert(aCutTools.end(), aTools.begin(), aTools.end());
461
462       std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
463       if(!anEdgesAndFaces.empty() && !aCutTools.empty()) {
464         std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(new GeomAlgoAPI_Boolean(anEdgesAndFaces,
465                                                               aCutTools,
466                                                               GeomAlgoAPI_Tools::BOOL_CUT));
467         if(aCutAlgo->isDone() && !aCutAlgo->shape()->isNull() && aCutAlgo->isValid()) {
468           anEdgesAndFaces.clear();
469           anEdgesAndFaces.push_back(aCutAlgo->shape());
470           aMakeShapeList->appendAlgo(aCutAlgo);
471         }
472       }
473
474       // If we have compsolids then cut with not used solids all others.
475       if(!aShapesToAdd.empty()) {
476         std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(new GeomAlgoAPI_Boolean(aSolidsToFuse,
477                                                               aShapesToAdd,
478                                                               GeomAlgoAPI_Tools::BOOL_CUT));
479         if(aCutAlgo->isDone() && GeomAlgoAPI_ShapeTools::area(aCutAlgo->shape()) > 1.e-27) {
480           aSolidsToFuse.clear();
481           aSolidsToFuse.push_back(aCutAlgo->shape());
482           aMakeShapeList->appendAlgo(aCutAlgo);
483         }
484       }
485
486       // Fuse all objects and all tools.
487       GeomShapePtr aFusedShape;
488       if(aSolidsToFuse.size() == 1) {
489         aFusedShape = aSolidsToFuse.front();
490       } else if(aSolidsToFuse.size() > 1){
491         anObjects.clear();
492         anObjects.push_back(aSolidsToFuse.front());
493         aSolidsToFuse.pop_front();
494         aTools = aSolidsToFuse;
495
496         std::shared_ptr<GeomAlgoAPI_Boolean> aFuseAlgo(new GeomAlgoAPI_Boolean(anObjects,
497                                                           aTools,
498                                                           GeomAlgoAPI_Tools::BOOL_FUSE));
499
500         // Checking that the algorithm worked properly.
501         if(!aFuseAlgo->isDone() || aFuseAlgo->shape()->isNull() || !aFuseAlgo->isValid()) {
502           myFeature->setError("Error: Boolean algorithm failed.");
503           return false;
504         }
505
506         aFusedShape = aFuseAlgo->shape();
507         aMakeShapeList->appendAlgo(aFuseAlgo);
508       }
509
510       // Combine result with not used solids from compsolid and edges and faces (if we have any).
511       aShapesToAdd.insert(aShapesToAdd.end(), anEdgesAndFaces.begin(), anEdgesAndFaces.end());
512       if(!aShapesToAdd.empty()) {
513         if(aFusedShape.get()) {
514           aShapesToAdd.push_back(aFusedShape);
515         }
516
517         std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(
518           new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
519         if(!aFillerAlgo->isDone() || aFillerAlgo->shape()->isNull() || !aFillerAlgo->isValid()) {
520           myFeature->setError("Error: PaveFiller algorithm failed.");
521           return false;
522         }
523
524         aMakeShapeList->appendAlgo(aFillerAlgo);
525       }
526
527       theMakeShapes.push_back(aMakeShapeList);
528       break;
529     }
530     default: // [to avoid compilation warnings]
531       break;
532   }
533
534   return true;
535 }
536
537 //=================================================================================================
538 void FeaturesPlugin_CompositeBoolean::storeModificationHistory(ResultBodyPtr theResultBody,
539                                 const GeomShapePtr theObject,
540                                 const ListOfShape& theTools,
541                                 const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
542 {
543   ListOfShape aTools = theTools;
544   aTools.push_back(theObject);
545
546   for(ListOfShape::const_iterator anIt = aTools.begin(); anIt != aTools.end(); anIt++) {
547     theResultBody->loadModifiedShapes(theMakeShape, *anIt,
548                                       (*anIt)->shapeType() == GeomAPI_Shape::EDGE ?
549                                                               GeomAPI_Shape::EDGE :
550                                                               GeomAPI_Shape::FACE);
551   }
552 }
553
554 //==================================================================================================
555 void FeaturesPlugin_CompositeBoolean::storeDeletedShapes(
556   std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
557   const ListOfShape& theTools,
558   const GeomShapePtr theResultShapesCompound)
559 {
560   for (std::vector<ResultBaseAlgo>::iterator anIt = theResultBaseAlgoList.begin();
561     anIt != theResultBaseAlgoList.end();
562     ++anIt)
563   {
564     ResultBaseAlgo& aRCA = *anIt;
565     aRCA.resultBody->loadDeletedShapes(aRCA.makeShape,
566       aRCA.baseShape,
567       GeomAPI_Shape::FACE,
568       theResultShapesCompound);
569
570     for (ListOfShape::const_iterator anIter = theTools.begin(); anIter != theTools.end(); anIter++)
571     {
572       aRCA.resultBody->loadDeletedShapes(aRCA.makeShape,
573         *anIter,
574         GeomAPI_Shape::FACE,
575         theResultShapesCompound);
576     }
577   }
578 }