1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "FeaturesPlugin_Boolean.h"
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_AttributeReference.h>
25 #include <ModelAPI_AttributeInteger.h>
26 #include <ModelAPI_ResultBody.h>
27 #include <ModelAPI_AttributeSelectionList.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Validator.h>
30 #include <ModelAPI_Tools.h>
32 #include <GeomAlgoAPI_Boolean.h>
33 #include <GeomAlgoAPI_CompoundBuilder.h>
34 #include <GeomAlgoAPI_MakeShapeCustom.h>
35 #include <GeomAlgoAPI_MakeShapeList.h>
36 #include <GeomAlgoAPI_Partition.h>
37 #include <GeomAlgoAPI_PaveFiller.h>
38 #include <GeomAlgoAPI_ShapeBuilder.h>
39 #include <GeomAlgoAPI_ShapeTools.h>
40 #include <GeomAlgoAPI_Tools.h>
41 #include <GeomAPI_Face.h>
42 #include <GeomAPI_ShapeExplorer.h>
43 #include <GeomAPI_ShapeIterator.h>
48 //=================================================================================================
49 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean(const OperationType theOperationType)
50 : myOperationType(theOperationType)
54 //=================================================================================================
55 void FeaturesPlugin_Boolean::initAttributes()
57 AttributeSelectionListPtr aSelection =
58 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
59 FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
61 aSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
62 FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
64 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
65 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
68 //=================================================================================================
69 FeaturesPlugin_Boolean::OperationType FeaturesPlugin_Boolean::operationType()
71 return myOperationType;
74 //=================================================================================================
75 void FeaturesPlugin_Boolean::parentForShape(const GeomShapePtr& theShape,
76 const ResultPtr& theContext,
77 ObjectHierarchy& theShapesHierarchy)
79 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(theContext);
80 if (aResCompSolidPtr.get()) {
81 std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
82 if (aContextShape->shapeType() <= GeomAPI_Shape::COMPSOLID) {
83 theShapesHierarchy.AddParent(theShape, aContextShape);
84 parentForShape(aContextShape, aResCompSolidPtr, theShapesHierarchy);
89 bool FeaturesPlugin_Boolean::processAttribute(const std::string& theAttributeName,
90 ObjectHierarchy& theObjects,
91 ListOfShape& thePlanesList)
93 AttributeSelectionListPtr anObjectsSelList = selectionList(theAttributeName);
94 for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
95 AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
96 GeomShapePtr anObject = anObjectAttr->value();
97 if (!anObject.get()) {
98 // It could be a construction plane.
99 ResultPtr aContext = anObjectAttr->context();
100 anObject = anObjectAttr->context()->shape();
101 if (anObject.get()) {
102 thePlanesList.push_back(anObject);
108 theObjects.AddObject(anObject);
110 ResultPtr aContext = anObjectAttr->context();
111 parentForShape(anObject, aContext, theObjects);
116 //=================================================================================================
117 void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
118 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
119 const ListOfShape& theTools,
120 const std::shared_ptr<GeomAPI_Shape> theResultShape,
121 const GeomMakeShapePtr& theMakeShape)
124 if(theBaseShape->isEqual(theResultShape)) {
125 theResultBody->store(theResultShape, false);
129 theResultBody->storeModified(theBaseShape, theResultShape);
131 theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::EDGE);
132 theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
134 theResultBody->loadDeletedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
136 for (ListOfShape::const_iterator anIter = theTools.begin();
137 anIter != theTools.end();
140 GeomAPI_Shape::ShapeType aShapeType =
141 (*anIter)->shapeType() <= GeomAPI_Shape::FACE ? GeomAPI_Shape::FACE
142 : GeomAPI_Shape::EDGE;
143 theResultBody->loadModifiedShapes(theMakeShape, *anIter, aShapeType);
145 theResultBody->loadDeletedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE);
149 //=================================================================================================
150 bool FeaturesPlugin_Boolean::processObject(
151 const GeomAlgoAPI_Tools::BOPType theBooleanType,
152 const GeomShapePtr& theObject,
153 const ListOfShape& theTools,
154 const ListOfShape& thePlanes,
156 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
157 ListOfShape& theResultShapesList,
158 GeomShapePtr theResultCompound)
160 ListOfShape aListWithObject;
161 aListWithObject.push_back(theObject);
162 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
163 std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
164 GeomShapePtr aResShape;
166 std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
167 GeomAlgoAPI_ShapeTools::getBoundingBox(aListWithObject, 1.0);
170 ListOfShape aToolsWithPlanes = theTools;
171 for (ListOfShape::const_iterator anIt = thePlanes.begin(); anIt != thePlanes.end(); ++anIt) {
172 GeomShapePtr aPlane = *anIt;
173 GeomShapePtr aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPlane, aBoundingPoints);
174 std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aMkShCustom(
175 new GeomAlgoAPI_MakeShapeCustom);
176 aMkShCustom->addModified(aPlane, aTool);
177 aMakeShapeList->appendAlgo(aMkShCustom);
178 aToolsWithPlanes.push_back(aTool);
181 if (theBooleanType == GeomAlgoAPI_Tools::BOOL_PARTITION)
182 aBoolAlgo.reset(new GeomAlgoAPI_Partition(aListWithObject, aToolsWithPlanes));
184 aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject,
188 // Checking that the algorithm worked properly.
190 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) {
195 aResShape = aBoolAlgo->shape();
196 if (aResShape.get() && aResShape->shapeType() == GeomAPI_Shape::COMPOUND) {
197 int aSubResultsNb = 0;
198 GeomAPI_ShapeIterator anIt(aResShape);
199 for (; anIt.more(); anIt.next())
202 if (aSubResultsNb == 1) {
203 anIt.init(aResShape);
205 aResShape = anIt.current();
209 aMakeShapeList->appendAlgo(aBoolAlgo);
211 GeomAPI_ShapeIterator aShapeIt(aResShape);
212 if (aShapeIt.more() || aResShape->shapeType() == GeomAPI_Shape::VERTEX) {
213 std::shared_ptr<ModelAPI_ResultBody> aResultBody;
215 if (theResultCompound) { // store BOP result to the compound
216 std::shared_ptr<GeomAlgoAPI_ShapeBuilder> aBuilder(new GeomAlgoAPI_ShapeBuilder);
217 aBuilder->add(theResultCompound, aResShape);
218 aMakeShapeList->appendAlgo(aBuilder);
220 else { // create a separate ResultBody
221 aResultBody = document()->createBody(data(), theResultIndex);
223 // tools should be added to the list to fulfill the correct history of modification
224 aListWithObject.insert(aListWithObject.end(), theTools.begin(), theTools.end());
226 ListOfShape aUsedTools = theTools;
227 aUsedTools.insert(aUsedTools.end(), thePlanes.begin(), thePlanes.end());
229 FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
234 setResult(aResultBody, theResultIndex);
239 FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
240 aRBA.resultBody = aResultBody;
241 aRBA.baseShape = theObject;
242 aRBA.makeShape = aMakeShapeList;
243 theResultBaseAlgoList.push_back(aRBA);
244 theResultShapesList.push_back(aResShape);
249 //=================================================================================================
250 bool FeaturesPlugin_Boolean::processCompsolid(
251 const GeomAlgoAPI_Tools::BOPType theBooleanType,
252 const ObjectHierarchy& theCompsolidHierarchy,
253 const GeomShapePtr& theCompsolid,
254 const ListOfShape& theTools,
255 const ListOfShape& thePlanes,
257 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
258 ListOfShape& theResultShapesList,
259 GeomShapePtr theResultCompound)
261 ListOfShape aUsedInOperationSolids;
262 ListOfShape aNotUsedSolids;
263 theCompsolidHierarchy.SplitCompound(theCompsolid, aUsedInOperationSolids, aNotUsedSolids);
265 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
267 std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
268 GeomAlgoAPI_ShapeTools::getBoundingBox(aUsedInOperationSolids, 1.0);
271 ListOfShape aToolsWithPlanes = theTools;
272 for (ListOfShape::const_iterator anIt = thePlanes.begin(); anIt != thePlanes.end(); ++anIt)
274 GeomShapePtr aPlane = *anIt;
275 GeomShapePtr aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPlane, aBoundingPoints);
276 std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aMkShCustom(
277 new GeomAlgoAPI_MakeShapeCustom);
278 aMkShCustom->addModified(aPlane, aTool);
279 aMakeShapeList->appendAlgo(aMkShCustom);
280 aToolsWithPlanes.push_back(aTool);
283 std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
284 if (theBooleanType == GeomAlgoAPI_Tools::BOOL_PARTITION)
285 aBoolAlgo.reset(new GeomAlgoAPI_Partition(aUsedInOperationSolids, aToolsWithPlanes));
287 aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
291 // Checking that the algorithm worked properly.
293 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) {
298 aMakeShapeList->appendAlgo(aBoolAlgo);
299 GeomShapePtr aResultShape = aBoolAlgo->shape();
301 // Add result to not used solids from compsolid.
302 if (!aNotUsedSolids.empty()) {
303 ListOfShape aShapesToAdd = aNotUsedSolids;
304 aShapesToAdd.push_back(aBoolAlgo->shape());
305 std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(
306 new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
307 if (!aFillerAlgo->isDone()) {
308 std::string aFeatureError = "Error: PaveFiller algorithm failed.";
309 setError(aFeatureError);
313 aMakeShapeList->appendAlgo(aFillerAlgo);
314 aResultShape = aFillerAlgo->shape();
317 GeomAPI_ShapeIterator aShapeIt(aResultShape);
318 if (aShapeIt.more() || aResultShape->shapeType() == GeomAPI_Shape::VERTEX)
320 std::shared_ptr<ModelAPI_ResultBody> aResultBody;
322 if (theResultCompound) { // store BOP result to the compound
323 std::shared_ptr<GeomAlgoAPI_ShapeBuilder> aBuilder(new GeomAlgoAPI_ShapeBuilder);
324 aBuilder->add(theResultCompound, aResultShape);
325 aMakeShapeList->appendAlgo(aBuilder);
327 else { // create a separate ResultBody
328 aResultBody = document()->createBody(data(), theResultIndex);
330 ListOfShape aCompSolidList;
331 aCompSolidList.push_back(theCompsolid);
332 // tools should be added to the list to fulfill the correct history of modification
333 aCompSolidList.insert(aCompSolidList.end(), theTools.begin(), theTools.end());
335 ListOfShape aUsedTools = theTools;
336 aUsedTools.insert(aUsedTools.end(), thePlanes.begin(), thePlanes.end());
338 FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
343 setResult(aResultBody, theResultIndex);
347 FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
348 aRBA.resultBody = aResultBody;
349 aRBA.baseShape = theCompsolid;
350 aRBA.makeShape = aMakeShapeList;
351 theResultBaseAlgoList.push_back(aRBA);
352 theResultShapesList.push_back(aResultShape);
357 //=================================================================================================
358 bool FeaturesPlugin_Boolean::processCompound(
359 const GeomAlgoAPI_Tools::BOPType theBooleanType,
360 const ObjectHierarchy& theCompoundHierarchy,
361 const GeomShapePtr& theCompound,
362 const ListOfShape& theTools,
364 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
365 ListOfShape& theResultShapesList,
366 GeomShapePtr theResultCompound)
368 ListOfShape aUsedInOperationShapes;
369 ListOfShape aNotUsedShapes;
370 theCompoundHierarchy.SplitCompound(theCompound, aUsedInOperationShapes, aNotUsedShapes);
372 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
373 std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo(
374 new GeomAlgoAPI_Boolean(aUsedInOperationShapes,
378 // Checking that the algorithm worked properly.
380 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) {
385 aMakeShapeList->appendAlgo(aBoolAlgo);
386 GeomShapePtr aResultShape = aBoolAlgo->shape();
388 // Add result to not used shape from compound.
389 if (!aNotUsedShapes.empty()) {
390 ListOfShape aShapesForResult = aNotUsedShapes;
391 if (aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) {
392 for (GeomAPI_ShapeIterator aResultIt(aResultShape); aResultIt.more(); aResultIt.next()) {
393 aShapesForResult.push_back(aResultIt.current());
397 aShapesForResult.push_back(aResultShape);
400 if (aShapesForResult.size() == 1) {
401 aResultShape = aShapesForResult.front();
404 aResultShape = GeomAlgoAPI_CompoundBuilder::compound(aShapesForResult);
408 GeomAPI_ShapeIterator aShapeIt(aResultShape);
409 if (aShapeIt.more() || aResultShape->shapeType() == GeomAPI_Shape::VERTEX) {
410 std::shared_ptr<ModelAPI_ResultBody> aResultBody;
412 if (theResultCompound) { // store BOP result to the compound
413 std::shared_ptr<GeomAlgoAPI_ShapeBuilder> aBuilder(new GeomAlgoAPI_ShapeBuilder);
414 aBuilder->add(theResultCompound, aResultShape);
415 aMakeShapeList->appendAlgo(aBuilder);
417 else { // create a separate ResultBody
418 aResultBody = document()->createBody(data(), theResultIndex);
420 ListOfShape aCompoundList;
421 aCompoundList.push_back(theCompound);
422 FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
427 setResult(aResultBody, theResultIndex);
431 FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
432 aRBA.resultBody = aResultBody;
433 aRBA.baseShape = theCompound;
434 aRBA.makeShape = aMakeShapeList;
435 theResultBaseAlgoList.push_back(aRBA);
436 theResultShapesList.push_back(aResultShape);
441 //==================================================================================================
442 GeomShapePtr FeaturesPlugin_Boolean::keepUnusedSubsOfCompound(
443 const GeomShapePtr& theResult,
444 const ObjectHierarchy& theObjectsHierarchy,
445 const ObjectHierarchy& theToolsHierarchy,
446 std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList)
448 ListOfShape aCompounds;
449 theObjectsHierarchy.CompoundsOfUnusedObjects(aCompounds);
450 theToolsHierarchy.CompoundsOfUnusedObjects(aCompounds);
452 GeomShapePtr aResultShape = theResult;
453 if (!aCompounds.empty()) {
454 aResultShape = aCompounds.front();
455 aCompounds.pop_front();
457 std::shared_ptr<GeomAlgoAPI_ShapeBuilder> aBuilder(new GeomAlgoAPI_ShapeBuilder);
458 for (ListOfShape::iterator anIt = aCompounds.begin(); anIt != aCompounds.end(); ++anIt) {
459 for (GeomAPI_ShapeIterator aSub(*anIt); aSub.more(); aSub.next())
460 aBuilder->add(aResultShape, aSub.current());
464 aBuilder->add(aResultShape, theResult);
466 theMakeShapeList->appendAlgo(aBuilder);
471 //=================================================================================================
472 int FeaturesPlugin_Boolean::version()
474 AttributeIntegerPtr aVersionAttr = integer(VERSION_ID());
476 if (aVersionAttr && aVersionAttr->isInitialized())
477 aVersion = aVersionAttr->value();
481 //=================================================================================================
483 void FeaturesPlugin_Boolean::ObjectHierarchy::AddObject(const GeomShapePtr& theObject)
485 myObjects.push_back(theObject);
488 void FeaturesPlugin_Boolean::ObjectHierarchy::AddParent(const GeomShapePtr& theShape,
489 const GeomShapePtr& theParent)
491 myParent[theShape] = theParent;
493 MapShapeToIndex::iterator aFound = myParentIndices.find(theParent);
494 size_t anIndex = myParentIndices.size();
495 if (aFound == myParentIndices.end()) {
496 myParentIndices[theParent] = anIndex;
497 mySubshapes.push_back(ShapeAndSubshapes(theParent, ListOfShape()));
499 anIndex = aFound->second;
501 mySubshapes[anIndex].second.push_back(theShape);
504 GeomShapePtr FeaturesPlugin_Boolean::ObjectHierarchy::Parent(const GeomShapePtr& theShape,
505 bool theMarkProcessed)
507 MapShapeToParent::const_iterator aFound = myParent.find(theShape);
508 GeomShapePtr aParent;
509 if (aFound != myParent.end()) {
510 aParent = aFound->second;
511 if (theMarkProcessed) {
512 // mark the parent and all its subs as processed by Boolean algorithm
513 myProcessedObjects.insert(aParent);
514 const ListOfShape& aSubs = mySubshapes[myParentIndices[aParent]].second;
515 for (ListOfShape::const_iterator anIt = aSubs.begin(); anIt != aSubs.end(); ++anIt)
516 myProcessedObjects.insert(*anIt);
522 void FeaturesPlugin_Boolean::ObjectHierarchy::ObjectsByType(
523 ListOfShape& theShapesByType,
524 ListOfShape& theOtherShapes,
525 const GeomAPI_Shape::ShapeType theMinType,
526 const GeomAPI_Shape::ShapeType theMaxType) const
528 if (theMinType > theMaxType)
529 return ObjectsByType(theShapesByType, theOtherShapes, theMaxType, theMinType);
531 // no need to select objects if whole range is specified
532 if (theMinType == GeomAPI_Shape::COMPOUND && theMaxType == GeomAPI_Shape::SHAPE) {
533 theShapesByType.insert(theShapesByType.end(), myObjects.begin(), myObjects.end());
537 for (ListOfShape::const_iterator anIt = myObjects.begin(); anIt != myObjects.end(); ++anIt) {
538 GeomAPI_Shape::ShapeType aType = (*anIt)->shapeType();
539 if (aType >= theMinType && aType <= theMaxType)
540 theShapesByType.push_back(*anIt);
542 theOtherShapes.push_back(*anIt);
547 void FeaturesPlugin_Boolean::ObjectHierarchy::SplitCompound(const GeomShapePtr& theCompShape,
548 ListOfShape& theUsed,
549 ListOfShape& theNotUsed) const
554 MapShapeToIndex::const_iterator aFoundIndex = myParentIndices.find(theCompShape);
555 if (aFoundIndex == myParentIndices.end())
556 return; // no such shape
558 const ListOfShape& aSubs = mySubshapes[aFoundIndex->second].second;
560 aSubsSet.insert(aSubs.begin(), aSubs.end());
562 for (GeomAPI_ShapeIterator anExp(theCompShape); anExp.more(); anExp.next()) {
563 GeomShapePtr aCurrent = anExp.current();
564 if (aSubsSet.find(aCurrent) == aSubsSet.end())
565 theNotUsed.push_back(aCurrent);
567 theUsed.push_back(aCurrent);
571 bool FeaturesPlugin_Boolean::ObjectHierarchy::IsEmpty() const
573 return myObjects.empty();
576 void FeaturesPlugin_Boolean::ObjectHierarchy::CompoundsOfUnusedObjects(
577 ListOfShape& theDestination) const
579 SetOfShape aUsedObjects;
580 aUsedObjects.insert(myObjects.begin(), myObjects.end());
582 for (std::vector<ShapeAndSubshapes>::const_iterator anIt = mySubshapes.begin();
583 anIt != mySubshapes.end(); ++anIt) {
584 MapShapeToParent::const_iterator aParent = myParent.find(anIt->first);
585 if ((aParent == myParent.end() || !aParent->second) &&
586 anIt->first->shapeType() == GeomAPI_Shape::COMPOUND) {
587 // this is a top-level compound
588 GeomShapePtr aCompound = collectUnusedSubs(anIt->first, aUsedObjects);
589 // add to destination non-empty compounds only
591 theDestination.push_back(aCompound);
596 GeomShapePtr FeaturesPlugin_Boolean::ObjectHierarchy::collectUnusedSubs(
597 GeomShapePtr theTopLevelCompound,
598 const SetOfShape& theUsed) const
600 GeomShapePtr aResult = theTopLevelCompound->emptyCopied();
601 bool isResultEmpty = true;
603 for (GeomAPI_ShapeIterator aSub(theTopLevelCompound); aSub.more(); aSub.next()) {
604 GeomShapePtr aCurrent = aSub.current();
605 if (theUsed.find(aCurrent) != theUsed.end())
606 continue; // already used
608 MapShapeToIndex::const_iterator aFoundIndex = myParentIndices.find(aCurrent);
609 if (aCurrent->shapeType() > GeomAPI_Shape::COMPOUND ||
610 aFoundIndex == myParentIndices.end()) {
611 bool isAddShape = true;
612 // check compsolid is fully unused in the Boolean operation
613 if (aCurrent->shapeType() == GeomAPI_Shape::COMPSOLID) {
614 for (GeomAPI_ShapeIterator anIt(aCurrent); isAddShape && anIt.more(); anIt.next())
615 isAddShape = theUsed.find(anIt.current()) == theUsed.end();
618 if (isAddShape) { // low-level shape, add it
619 GeomAlgoAPI_ShapeBuilder::add(aResult, aCurrent);
620 isResultEmpty = false;
623 GeomShapePtr aCompound = collectUnusedSubs(aCurrent, theUsed);
625 GeomAlgoAPI_ShapeBuilder::add(theTopLevelCompound, aCompound);
626 isResultEmpty = false;
630 return isResultEmpty ? GeomShapePtr() : aResult;
634 FeaturesPlugin_Boolean::ObjectHierarchy::Iterator FeaturesPlugin_Boolean::ObjectHierarchy::Begin()
636 return Iterator(this);
639 FeaturesPlugin_Boolean::ObjectHierarchy::Iterator FeaturesPlugin_Boolean::ObjectHierarchy::End()
641 return Iterator(this, false);
644 FeaturesPlugin_Boolean::ObjectHierarchy::Iterator::Iterator(
645 FeaturesPlugin_Boolean::ObjectHierarchy* theHierarchy, bool isBegin)
646 : myHierarchy(theHierarchy)
649 myObject = myHierarchy->myObjects.begin();
650 SkipAlreadyProcessed();
652 myObject = myHierarchy->myObjects.end();
655 void FeaturesPlugin_Boolean::ObjectHierarchy::Iterator::SkipAlreadyProcessed()
657 while (myObject != myHierarchy->myObjects.end() &&
658 myHierarchy->myProcessedObjects.find(*myObject) != myHierarchy->myProcessedObjects.end())
662 bool FeaturesPlugin_Boolean::ObjectHierarchy::Iterator::operator==(const Iterator& theOther) const
664 return myObject == theOther.myObject;
667 bool FeaturesPlugin_Boolean::ObjectHierarchy::Iterator::operator!=(const Iterator& theOther) const
669 return !operator==(theOther);
672 FeaturesPlugin_Boolean::ObjectHierarchy::Iterator&
673 FeaturesPlugin_Boolean::ObjectHierarchy::Iterator::operator++()
676 SkipAlreadyProcessed();
680 FeaturesPlugin_Boolean::ObjectHierarchy::Iterator
681 FeaturesPlugin_Boolean::ObjectHierarchy::Iterator::operator++(int)
684 aCurrent.myHierarchy = myHierarchy;
685 aCurrent.myObject = myObject;
693 GeomShapePtr FeaturesPlugin_Boolean::ObjectHierarchy::Iterator::operator*() const
695 myHierarchy->myProcessedObjects.insert(*myObject);