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_VersionedBoolean.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 <GeomAlgoAPI_UnifySameDomain.h>
42 #include <GeomAPI_Face.h>
43 #include <GeomAPI_ShapeExplorer.h>
44 #include <GeomAPI_ShapeIterator.h>
49 static void performBoolean(const GeomAlgoAPI_Tools::BOPType theBooleanType,
50 GeomMakeShapePtr& theBooleanAlgo,
51 const ListOfShape& theObjects,
52 const ListOfShape& theTools)
54 if (theBooleanType == GeomAlgoAPI_Tools::BOOL_PARTITION)
55 theBooleanAlgo.reset(new GeomAlgoAPI_Partition(theObjects, theTools));
57 // separate processing of FUSE, if only objects are given
58 if (theBooleanType == GeomAlgoAPI_Tools::BOOL_FUSE && theTools.empty()) {
59 if (theObjects.front()->shapeType() == GeomAPI_Shape::FACE)
60 theBooleanAlgo.reset(new GeomAlgoAPI_UnifySameDomain(theObjects));
62 ListOfShape anObjects = theObjects;
64 aTools.splice(aTools.begin(), anObjects, anObjects.begin());
65 theBooleanAlgo.reset(new GeomAlgoAPI_Boolean(anObjects, aTools, theBooleanType));
69 theBooleanAlgo.reset(new GeomAlgoAPI_Boolean(theObjects, theTools, theBooleanType));
73 //=================================================================================================
74 void FeaturesPlugin_VersionedBoolean::initVersion(const int theVersion,
75 const AttributePtr theObjectsAttr,
76 const AttributePtr theToolsAttr)
78 AttributePtr aVerAttr = data()->addAttribute(VERSION_ID(), ModelAPI_AttributeInteger::typeId());
79 aVerAttr->setIsArgument(false);
80 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VERSION_ID());
81 if (!integer(VERSION_ID())->isInitialized() &&
82 (!theObjectsAttr || !theObjectsAttr->isInitialized()) &&
83 (!theToolsAttr || !theToolsAttr->isInitialized())) {
84 // this is a newly created feature (not read from file),
85 // so, initialize the latest version
86 integer(VERSION_ID())->setValue(theVersion);
90 //=================================================================================================
91 void FeaturesPlugin_VersionedBoolean::parentForShape(const GeomShapePtr& theShape,
92 const ResultPtr& theContext,
93 ObjectHierarchy& theShapesHierarchy)
95 ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(theContext);
96 if (aResCompSolidPtr.get()) {
97 std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
98 if (aContextShape->shapeType() <= GeomAPI_Shape::COMPSOLID) {
99 theShapesHierarchy.AddParent(theShape, aContextShape);
100 parentForShape(aContextShape, aResCompSolidPtr, theShapesHierarchy);
105 bool FeaturesPlugin_VersionedBoolean::processAttribute(const std::string& theAttributeName,
106 ObjectHierarchy& theObjects,
107 ListOfShape& thePlanesList)
109 AttributeSelectionListPtr anObjectsSelList = selectionList(theAttributeName);
110 for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
111 AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
112 GeomShapePtr anObject = anObjectAttr->value();
113 if (!anObject.get()) {
114 // It could be a construction plane.
115 ResultPtr aContext = anObjectAttr->context();
116 anObject = anObjectAttr->context()->shape();
117 if (anObject.get()) {
118 thePlanesList.push_back(anObject);
124 theObjects.AddObject(anObject);
126 ResultPtr aContext = anObjectAttr->context();
127 parentForShape(anObject, aContext, theObjects);
132 //=================================================================================================
133 bool FeaturesPlugin_VersionedBoolean::processObject(
134 const GeomAlgoAPI_Tools::BOPType theBooleanType,
135 const GeomShapePtr& theObject,
136 const ListOfShape& theTools,
137 const ListOfShape& thePlanes,
139 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
140 ListOfShape& theResultShapesList,
141 GeomShapePtr theResultCompound)
143 ListOfShape aListWithObject;
144 aListWithObject.push_back(theObject);
145 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
146 std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
147 GeomShapePtr aResShape;
150 ListOfShape aToolsWithPlanes = theTools;
151 ListOfShape aPlanesCopy = thePlanes;
152 resizePlanes(aListWithObject, aPlanesCopy, aMakeShapeList);
153 aToolsWithPlanes.insert(aToolsWithPlanes.end(), aPlanesCopy.begin(), aPlanesCopy.end());
155 if (theBooleanType == GeomAlgoAPI_Tools::BOOL_PARTITION)
156 aBoolAlgo.reset(new GeomAlgoAPI_Partition(aListWithObject, aToolsWithPlanes));
158 aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject,
162 // Checking that the algorithm worked properly.
164 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) {
169 aResShape = aBoolAlgo->shape();
170 if (aResShape.get() && aResShape->shapeType() == GeomAPI_Shape::COMPOUND) {
171 int aSubResultsNb = 0;
172 GeomAPI_ShapeIterator anIt(aResShape);
173 for (; anIt.more(); anIt.next())
176 if (aSubResultsNb == 1) {
177 anIt.init(aResShape);
179 aResShape = anIt.current();
183 aMakeShapeList->appendAlgo(aBoolAlgo);
185 GeomAPI_ShapeIterator aShapeIt(aResShape);
186 if (aShapeIt.more() || aResShape->shapeType() == GeomAPI_Shape::VERTEX) {
187 std::shared_ptr<ModelAPI_ResultBody> aResultBody;
189 if (theResultCompound) { // store BOP result to the compound
190 std::shared_ptr<GeomAlgoAPI_ShapeBuilder> aBuilder(new GeomAlgoAPI_ShapeBuilder);
191 aBuilder->add(theResultCompound, aResShape);
192 aMakeShapeList->appendAlgo(aBuilder);
194 else { // create a separate ResultBody
195 aResultBody = document()->createBody(data(), theResultIndex);
197 // tools should be added to the list to fulfill the correct history of modification
198 aListWithObject.insert(aListWithObject.end(), theTools.begin(), theTools.end());
200 ListOfShape aUsedTools = theTools;
201 aUsedTools.insert(aUsedTools.end(), thePlanes.begin(), thePlanes.end());
203 FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
208 setResult(aResultBody, theResultIndex);
213 FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
214 aRBA.resultBody = aResultBody;
215 aRBA.baseShape = theObject;
216 aRBA.makeShape = aMakeShapeList;
217 theResultBaseAlgoList.push_back(aRBA);
218 theResultShapesList.push_back(aResShape);
223 //=================================================================================================
224 bool FeaturesPlugin_VersionedBoolean::processCompsolid(
225 const GeomAlgoAPI_Tools::BOPType theBooleanType,
226 ObjectHierarchy& theCompsolidHierarchy,
227 const GeomShapePtr& theCompsolid,
228 const ListOfShape& theTools,
229 const ListOfShape& thePlanes,
231 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
232 ListOfShape& theResultShapesList,
233 GeomShapePtr theResultCompound)
235 ListOfShape aUsedInOperationSolids;
236 ListOfShape aNotUsedSolids;
237 theCompsolidHierarchy.SplitCompound(theCompsolid, aUsedInOperationSolids, aNotUsedSolids);
239 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
242 ListOfShape aToolsWithPlanes = theTools;
243 ListOfShape aPlanesCopy = thePlanes;
244 resizePlanes(aUsedInOperationSolids, aPlanesCopy, aMakeShapeList);
245 aToolsWithPlanes.insert(aToolsWithPlanes.end(), aPlanesCopy.begin(), aPlanesCopy.end());
247 std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
248 performBoolean(theBooleanType, aBoolAlgo, aUsedInOperationSolids, aToolsWithPlanes);
250 // Checking that the algorithm worked properly.
252 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) {
257 aMakeShapeList->appendAlgo(aBoolAlgo);
258 GeomShapePtr aResultShape = aBoolAlgo->shape();
260 // Add result to not used solids from compsolid.
261 if (!aNotUsedSolids.empty()) {
262 theCompsolidHierarchy.MarkProcessed(aNotUsedSolids);
264 ListOfShape aShapesToAdd = aNotUsedSolids;
265 aShapesToAdd.push_back(aBoolAlgo->shape());
266 std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(
267 new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
268 if (!aFillerAlgo->isDone()) {
269 std::string aFeatureError = "Error: PaveFiller algorithm failed.";
270 setError(aFeatureError);
274 aMakeShapeList->appendAlgo(aFillerAlgo);
275 aResultShape = aFillerAlgo->shape();
278 GeomAPI_ShapeIterator aShapeIt(aResultShape);
279 if (aShapeIt.more() || aResultShape->shapeType() == GeomAPI_Shape::VERTEX)
281 std::shared_ptr<ModelAPI_ResultBody> aResultBody;
283 if (theResultCompound) { // store BOP result to the compound
284 std::shared_ptr<GeomAlgoAPI_ShapeBuilder> aBuilder(new GeomAlgoAPI_ShapeBuilder);
285 aBuilder->add(theResultCompound, aResultShape);
286 aMakeShapeList->appendAlgo(aBuilder);
288 else { // create a separate ResultBody
289 aResultBody = document()->createBody(data(), theResultIndex);
291 ListOfShape aCompSolidList;
292 aCompSolidList.push_back(theCompsolid);
293 // tools should be added to the list to fulfill the correct history of modification
294 aCompSolidList.insert(aCompSolidList.end(), theTools.begin(), theTools.end());
296 ListOfShape aUsedTools = theTools;
297 aUsedTools.insert(aUsedTools.end(), thePlanes.begin(), thePlanes.end());
299 FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
304 setResult(aResultBody, theResultIndex);
308 FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
309 aRBA.resultBody = aResultBody;
310 aRBA.baseShape = theCompsolid;
311 aRBA.makeShape = aMakeShapeList;
312 theResultBaseAlgoList.push_back(aRBA);
313 theResultShapesList.push_back(aResultShape);
318 //=================================================================================================
319 bool FeaturesPlugin_VersionedBoolean::processCompound(
320 const GeomAlgoAPI_Tools::BOPType theBooleanType,
321 ObjectHierarchy& theCompoundHierarchy,
322 const GeomShapePtr& theCompound,
323 const ListOfShape& theTools,
325 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
326 ListOfShape& theResultShapesList,
327 GeomShapePtr theResultCompound)
329 ListOfShape aUsedInOperationShapes;
330 ListOfShape aNotUsedShapes;
331 theCompoundHierarchy.SplitCompound(theCompound, aUsedInOperationShapes, aNotUsedShapes);
332 if (theResultCompound) {
333 // Not necessary to keep all subs of the current compound,
334 // all unused solids are already stored in the result compound.
335 aNotUsedShapes.clear();
338 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
339 std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
340 performBoolean(theBooleanType, aBoolAlgo, aUsedInOperationShapes, theTools);
342 // Checking that the algorithm worked properly.
344 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) {
349 aMakeShapeList->appendAlgo(aBoolAlgo);
350 GeomShapePtr aResultShape = aBoolAlgo->shape();
352 // Add result to not used shape from compound.
353 if (!aNotUsedShapes.empty()) {
354 theCompoundHierarchy.MarkProcessed(aNotUsedShapes);
356 ListOfShape aShapesForResult = aNotUsedShapes;
357 if (aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) {
358 for (GeomAPI_ShapeIterator aResultIt(aResultShape); aResultIt.more(); aResultIt.next()) {
359 aShapesForResult.push_back(aResultIt.current());
363 aShapesForResult.push_back(aResultShape);
366 if (aShapesForResult.size() == 1) {
367 aResultShape = aShapesForResult.front();
370 aResultShape = GeomAlgoAPI_CompoundBuilder::compound(aShapesForResult);
374 GeomAPI_ShapeIterator aShapeIt(aResultShape);
375 if (aShapeIt.more() || aResultShape->shapeType() == GeomAPI_Shape::VERTEX) {
376 std::shared_ptr<ModelAPI_ResultBody> aResultBody;
378 if (theResultCompound) { // store BOP result to the compound
379 std::shared_ptr<GeomAlgoAPI_ShapeBuilder> aBuilder(new GeomAlgoAPI_ShapeBuilder);
380 aBuilder->add(theResultCompound, aResultShape);
381 aMakeShapeList->appendAlgo(aBuilder);
383 else { // create a separate ResultBody
384 aResultBody = document()->createBody(data(), theResultIndex);
386 ListOfShape aCompoundList;
387 aCompoundList.push_back(theCompound);
388 FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
393 setResult(aResultBody, theResultIndex);
397 FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
398 aRBA.resultBody = aResultBody;
399 aRBA.baseShape = theCompound;
400 aRBA.makeShape = aMakeShapeList;
401 theResultBaseAlgoList.push_back(aRBA);
402 theResultShapesList.push_back(aResultShape);
407 //==================================================================================================
408 GeomShapePtr FeaturesPlugin_VersionedBoolean::keepUnusedSubsOfCompound(
409 const GeomShapePtr& theResult,
410 const ObjectHierarchy& theObjectsHierarchy,
411 const ObjectHierarchy& theToolsHierarchy,
412 std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList)
414 ListOfShape aCompounds;
415 theObjectsHierarchy.CompoundsOfUnusedObjects(aCompounds);
416 theToolsHierarchy.CompoundsOfUnusedObjects(aCompounds);
418 GeomShapePtr aResultShape = theResult;
419 if (!aCompounds.empty()) {
420 aResultShape = GeomAlgoAPI_CompoundBuilder::compound(aCompounds);
422 std::shared_ptr<GeomAlgoAPI_ShapeBuilder> aBuilder(new GeomAlgoAPI_ShapeBuilder);
423 aBuilder->add(aResultShape, theResult);
424 theMakeShapeList->appendAlgo(aBuilder);
430 //=================================================================================================
431 void FeaturesPlugin_VersionedBoolean::resizePlanes(
432 const ListOfShape& theObjects,
433 ListOfShape& thePlanes,
434 std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList)
436 if (thePlanes.empty())
439 std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
440 GeomAlgoAPI_ShapeTools::getBoundingBox(theObjects, 1.0);
442 // Resize planes to fit in bounding box
443 for (ListOfShape::iterator anIt = thePlanes.begin(); anIt != thePlanes.end(); ++anIt) {
444 GeomShapePtr aPlane = *anIt;
445 GeomShapePtr aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPlane, aBoundingPoints);
446 std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aMkShCustom(new GeomAlgoAPI_MakeShapeCustom);
447 aMkShCustom->addModified(aPlane, aTool);
448 theMakeShapeList->appendAlgo(aMkShCustom);
453 //=================================================================================================
454 int FeaturesPlugin_VersionedBoolean::version()
456 AttributeIntegerPtr aVersionAttr = integer(VERSION_ID());
458 if (aVersionAttr && aVersionAttr->isInitialized())
459 aVersion = aVersionAttr->value();
463 //=================================================================================================
465 void FeaturesPlugin_VersionedBoolean::ObjectHierarchy::AddObject(const GeomShapePtr& theObject)
467 myObjects.push_back(theObject);
470 void FeaturesPlugin_VersionedBoolean::ObjectHierarchy::AddParent(const GeomShapePtr& theShape,
471 const GeomShapePtr& theParent)
473 myParent[theShape] = theParent;
475 MapShapeToIndex::iterator aFound = myParentIndices.find(theParent);
476 size_t anIndex = myParentIndices.size();
477 if (aFound == myParentIndices.end()) {
478 myParentIndices[theParent] = anIndex;
479 mySubshapes.push_back(ShapeAndSubshapes(theParent, ListOfShape()));
481 anIndex = aFound->second;
483 mySubshapes[anIndex].second.push_back(theShape);
486 GeomShapePtr FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Parent(const GeomShapePtr& theShape,
487 bool theMarkProcessed)
489 MapShapeToParent::const_iterator aFound = myParent.find(theShape);
490 GeomShapePtr aParent;
491 if (aFound != myParent.end()) {
492 aParent = aFound->second;
493 if (theMarkProcessed) {
494 // mark the parent and all its subs as processed by Boolean algorithm
495 myProcessedObjects.insert(aParent);
496 const ListOfShape& aSubs = mySubshapes[myParentIndices[aParent]].second;
497 for (ListOfShape::const_iterator anIt = aSubs.begin(); anIt != aSubs.end(); ++anIt)
498 myProcessedObjects.insert(*anIt);
504 void FeaturesPlugin_VersionedBoolean::ObjectHierarchy::MarkProcessed(const GeomShapePtr& theShape)
506 myProcessedObjects.insert(theShape);
509 void FeaturesPlugin_VersionedBoolean::ObjectHierarchy::MarkProcessed(const ListOfShape& theShapes)
511 for (ListOfShape::const_iterator anIt = theShapes.begin(); anIt != theShapes.end(); ++anIt)
512 MarkProcessed(*anIt);
515 void FeaturesPlugin_VersionedBoolean::ObjectHierarchy::ObjectsByType(
516 ListOfShape& theShapesByType,
517 ListOfShape& theOtherShapes,
518 const GeomAPI_Shape::ShapeType theMinType,
519 const GeomAPI_Shape::ShapeType theMaxType) const
521 if (theMinType > theMaxType)
522 return ObjectsByType(theShapesByType, theOtherShapes, theMaxType, theMinType);
524 // no need to select objects if whole range is specified
525 if (theMinType == GeomAPI_Shape::COMPOUND && theMaxType == GeomAPI_Shape::SHAPE) {
526 theShapesByType.insert(theShapesByType.end(), myObjects.begin(), myObjects.end());
530 for (ListOfShape::const_iterator anIt = myObjects.begin(); anIt != myObjects.end(); ++anIt) {
531 GeomAPI_Shape::ShapeType aType = (*anIt)->shapeType();
532 if (aType >= theMinType && aType <= theMaxType)
533 theShapesByType.push_back(*anIt);
535 theOtherShapes.push_back(*anIt);
540 void FeaturesPlugin_VersionedBoolean::ObjectHierarchy::SplitCompound(
541 const GeomShapePtr& theCompShape,
542 ListOfShape& theUsed,
543 ListOfShape& theNotUsed) const
548 MapShapeToIndex::const_iterator aFoundIndex = myParentIndices.find(theCompShape);
549 if (aFoundIndex == myParentIndices.end())
550 return; // no such shape
552 theUsed = mySubshapes[aFoundIndex->second].second;
554 aSubsSet.insert(theUsed.begin(), theUsed.end());
556 for (GeomAPI_ShapeIterator anExp(theCompShape); anExp.more(); anExp.next()) {
557 GeomShapePtr aCurrent = anExp.current();
558 if (aSubsSet.find(aCurrent) == aSubsSet.end())
559 theNotUsed.push_back(aCurrent);
563 bool FeaturesPlugin_VersionedBoolean::ObjectHierarchy::IsEmpty() const
565 return myObjects.empty();
568 void FeaturesPlugin_VersionedBoolean::ObjectHierarchy::CompoundsOfUnusedObjects(
569 ListOfShape& theDestination) const
571 SetOfShape aUsedObjects = myProcessedObjects;
572 aUsedObjects.insert(myObjects.begin(), myObjects.end());
574 for (std::vector<ShapeAndSubshapes>::const_iterator anIt = mySubshapes.begin();
575 anIt != mySubshapes.end(); ++anIt) {
576 MapShapeToParent::const_iterator aParent = myParent.find(anIt->first);
577 if ((aParent == myParent.end() || !aParent->second) &&
578 anIt->first->shapeType() == GeomAPI_Shape::COMPOUND) {
579 // this is a top-level compound
580 GeomShapePtr aCompound = collectUnusedSubs(anIt->first, aUsedObjects);
581 // add to destination non-empty compounds only
583 theDestination.push_back(aCompound);
588 GeomShapePtr FeaturesPlugin_VersionedBoolean::ObjectHierarchy::collectUnusedSubs(
589 GeomShapePtr theTopLevelCompound,
590 const SetOfShape& theUsed) const
592 GeomShapePtr aResult = theTopLevelCompound->emptyCopied();
593 bool isResultEmpty = true;
595 for (GeomAPI_ShapeIterator aSub(theTopLevelCompound); aSub.more(); aSub.next()) {
596 GeomShapePtr aCurrent = aSub.current();
597 if (theUsed.find(aCurrent) != theUsed.end())
598 continue; // already used
600 MapShapeToIndex::const_iterator aFoundIndex = myParentIndices.find(aCurrent);
601 if (aCurrent->shapeType() > GeomAPI_Shape::COMPOUND ||
602 aFoundIndex == myParentIndices.end()) {
603 bool isAddShape = true;
604 // check compsolid is fully unused in the Boolean operation
605 if (aCurrent->shapeType() == GeomAPI_Shape::COMPSOLID) {
606 for (GeomAPI_ShapeIterator anIt(aCurrent); isAddShape && anIt.more(); anIt.next())
607 isAddShape = theUsed.find(anIt.current()) == theUsed.end();
610 if (isAddShape) { // low-level shape, add it
611 GeomAlgoAPI_ShapeBuilder::add(aResult, aCurrent);
612 isResultEmpty = false;
615 GeomShapePtr aCompound = collectUnusedSubs(aCurrent, theUsed);
617 GeomAlgoAPI_ShapeBuilder::add(aResult, aCompound);
618 isResultEmpty = false;
622 return isResultEmpty ? GeomShapePtr() : aResult;
626 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator
627 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Begin()
629 return Iterator(this);
632 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator
633 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::End()
635 return Iterator(this, false);
638 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator::Iterator(
639 FeaturesPlugin_VersionedBoolean::ObjectHierarchy* theHierarchy, bool isBegin)
640 : myHierarchy(theHierarchy)
643 myObject = myHierarchy->myObjects.begin();
644 SkipAlreadyProcessed();
646 myObject = myHierarchy->myObjects.end();
649 void FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator::SkipAlreadyProcessed()
651 while (myObject != myHierarchy->myObjects.end() &&
652 myHierarchy->myProcessedObjects.find(*myObject) != myHierarchy->myProcessedObjects.end())
656 bool FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator::operator==(
657 const Iterator& theOther) const
659 return myObject == theOther.myObject;
662 bool FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator::operator!=(
663 const Iterator& theOther) const
665 return !operator==(theOther);
668 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator&
669 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator::operator++()
672 SkipAlreadyProcessed();
676 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator
677 FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator::operator++(int)
680 aCurrent.myHierarchy = myHierarchy;
681 aCurrent.myObject = myObject;
689 GeomShapePtr FeaturesPlugin_VersionedBoolean::ObjectHierarchy::Iterator::operator*() const
691 myHierarchy->myProcessedObjects.insert(*myObject);