+ # Groups
+ allGroupsProcessed = []
+ aRefGroups = ModelAPI.referencedFeatures(aRes, "Group", True)
+ for aRef in aRefGroups:
+ aGroupIndices = []
+ aGroupHasIndex = {}
+ aResShape = aRes.shape()
+ aSelList = aRef.selectionList("group_list")
+ aSelType = GeomAPI_Shape.shapeTypeByStr(aSelList.selectionType())
+ for aSelIndex in range(aSelList.size()):
+ aSelection = aSelList.value(aSelIndex)
+ if aSelection.contextObject():
+ aShape = aSelection.value()
+ if aShape:
+ allShapesList = [] # collect all sub-shapes selected in the group
+ if aShape.shapeType() == 0: # compound
+ anExplorer = GeomAPI_ShapeExplorer(aShape, aSelType)
+ while anExplorer.more():
+ allShapesList.append(anExplorer.current())
+ anExplorer.next()
+ else:
+ allShapesList.append(aShape)
+ # get index of each selected shape: if 0, this sub-shape is not in our result
+ for aSelected in allShapesList:
+ anId = GeomAlgoAPI.GeomAlgoAPI_CompoundBuilder.id(aResShape, aSelected)
+ if anId > 0 and not anId in aGroupHasIndex:
+ aGroupIndices.append(anId)
+ aGroupHasIndex[anId] = 0
+ if len(aGroupIndices): # create group
+ aGroupOp = anEngine.GetIGroupOperations()
+ aGroupFeatureId = aRef.data().featureId()
+ aGroupEntry = "group" + str(aPartFeatureId) + ":" + str(aGroupFeatureId)
+ aGroup = aGroupOp.FindGroup(aSShape, aGroupEntry)
+ if not aGroup: # create a new
+ aGroup = aGroupOp.CreateGroup(aSShape, aSelType)
+ aGroup.SetEntry(aGroupEntry)
+ anEngine.AddInStudy(aGroup, aRef.firstResult().data().name(), aSShape.GetSO())
+ aGroup.SetSelection(aGroupIndices)
+ # a group takes shape from the main result
+ #aGroup.SetShapeByStream(aRef.firstResult().shape().getShapeStream(False)) # group shape
+ allGroupsProcessed.append(aGroupEntry)
+ # check all existing groups: if some does not processed, remove it from the tree
+ aSOIter = SHAPERSTUDY_utils.getStudy().NewChildIterator(aSShape.GetSO())
+ while aSOIter.More():
+ aSO = aSOIter.Value()
+ anIOR = aSO.GetIOR()
+ if len(anIOR):
+ anObj = salome.orb.string_to_object(anIOR)
+ if isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Group):
+ anEntry = anObj.GetEntry()
+ if anEntry not in allGroupsProcessed: # found a removed group => remove
+ aBuilder = SHAPERSTUDY_utils.getStudy().NewBuilder()
+ aBuilder.RemoveObject(anObj.GetSO())
+ aSOIter.Next()