#include "CollectionPlugin_GroupAddition.h"
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_AttributeString.h>
-#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_ResultGroup.h>
-
-#include <GeomAPI_ShapeIterator.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
-
-CollectionPlugin_GroupAddition::CollectionPlugin_GroupAddition()
-{
-}
-
-void CollectionPlugin_GroupAddition::initAttributes()
-{
- data()->addAttribute(CollectionPlugin_GroupAddition::LIST_ID(),
- ModelAPI_AttributeSelectionList::typeId());
-}
-
-static void explodeCompound(const GeomShapePtr& theCompound, ListOfShape& theSubs)
-{
- if (theCompound->isCompound()) {
- GeomAPI_ShapeIterator anIt(theCompound);
- for (; anIt.more(); anIt.next())
- explodeCompound(anIt.current(), theSubs);
- }
- else
- theSubs.push_back(theCompound);
-}
-
-static void keepUniqueShapes(ListOfShape& theShapes)
-{
- ListOfShape::iterator anIt = theShapes.begin();
- while (anIt != theShapes.end()) {
- GeomShapePtr aCurrent = *anIt;
- ListOfShape::iterator anIt2 = theShapes.begin();
- for (; anIt2 != anIt; ++anIt2)
- if (aCurrent->isEqual(*anIt2))
- break;
- if (anIt2 != anIt) {
- // the same shape is found
- ListOfShape::iterator aRemoveIt = anIt++;
- theShapes.erase(aRemoveIt);
- }
- else
- ++anIt;
- }
-}
void CollectionPlugin_GroupAddition::execute()
{
- ResultGroupPtr aGroup = document()->createGroup(data());
- // clean the result of the operation
- aGroup->store(GeomShapePtr());
-
- // collect all unique sub-shapes
- GeomShapePtr aCompound = aGroup->shape();
- ListOfShape aSubs;
- explodeCompound(aCompound, aSubs);
- keepUniqueShapes(aSubs);
- aCompound = aSubs.empty() ? GeomShapePtr() : GeomAlgoAPI_CompoundBuilder::compound(aSubs);
- aGroup->store(aCompound);
-
- // update the type of selection
- updateGroupType(LIST_ID());
-
+ ResultGroupPtr aGroup;
+ CollectionPlugin_GroupMerge::execute(aGroup);
setResult(aGroup);
}