Salome HOME
Copyright update 2020
[modules/shaper.git] / src / ConnectorPlugin / ConnectorPlugin_PublishToStudyFeature.py
index cdda96119bdf44a4b10c197584c045d4d0724f8a..6e3629fbfb2b0c14257852073c92b8d89ff800e8 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+# Copyright (C) 2014-2020  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -86,11 +86,19 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
             EventsAPI.Events_InfoMessage("PublishToStudy", "For publish to SHAPER-STUDY some Part is not activated", self).send()
             break
           aPartFeatureId = aPartSet.feature(aPartRes).data().featureId()
+          # Collects all features of exported results to find results of the same features and extend id.
+          # Map from feature index to index of result. If index is zero (initial), no surrfix to entry is added.
+          aFeaturesIndices = {}
           for aResId in range(aPartDoc.size(model.ModelAPI_ResultBody_group())):
             aResObject = aPartDoc.object(model.ModelAPI_ResultBody_group(), aResId)
             aRes = model.objectToResult(aResObject)
-            aResFeatureId = aPartDoc.feature(aRes).data().featureId()
-            aSSEntry = str(aPartFeatureId) + ":" + str(aResFeatureId)
+            aResFeatureId = str(aPartDoc.feature(aRes).data().featureId())
+            if aResFeatureId in aFeaturesIndices:
+              aFeaturesIndices[aResFeatureId] += 1
+              aResFeatureId += ":" + str(aFeaturesIndices[aResFeatureId])
+            else:
+              aFeaturesIndices[aResFeatureId] = 0
+            aSSEntry = str(aPartFeatureId) + ":" + aResFeatureId
             aSShape = anEngine.FindOrCreateShape(aSSEntry)
             aSShape.SetShapeByStream(aRes.shape().getShapeStream(False))
             if not aSShape.GetSO(): # publish in case it is a new shape
@@ -112,6 +120,7 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
         aSOIter = SHAPERSTUDY_utils.getStudy().NewChildIterator(aComponent)
         while aSOIter.More():
           aSO = aSOIter.Value()
+          aSOIter.Next() # here because there is continue inside the loop
           anIOR = aSO.GetIOR()
           if len(anIOR):
             anObj = salome.orb.string_to_object(anIOR)
@@ -127,7 +136,25 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
                   if aRes:
                     aBuilder = SHAPERSTUDY_utils.getStudy().NewBuilder()
                     aBuilder.RemoveReference(aSO2)
-          aSOIter.Next()
+                # if the object is not marked as dead, mark it (#3201) to make all entries unique
+                aDeadEntry = anObj.GetEntry()
+                if not aDeadEntry.startswith("dead"):
+                  anIndex = aSO.Tag()
+                  anObj.SetEntry("dead0" + str(anIndex) + "_" + aDeadEntry)
+
+                  # also for groups
+                  aGrSOIter = SHAPERSTUDY_utils.getStudy().NewChildIterator(aSO)
+                  while aGrSOIter.More():
+                    aGroupSO = aGrSOIter.Value()
+                    aGrSOIter.Next()
+                    anIOR = aGroupSO.GetIOR()
+                    if len(anIOR):
+                      aGroup = salome.orb.string_to_object(anIOR)
+                      if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
+                         isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
+                        if not aGroup.GetEntry().startswith("dead"):
+                          aDeadGroupEntry = "dead0" + str(anIndex) + "_" + aGroup.GetEntry()
+                          aGroup.SetEntry(aDeadGroupEntry)
 
     # Part of the "execute" method: processes the Groups of theRes result publication.
     # If theFields is true, the same is performed for Fields.
@@ -152,7 +179,7 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
             aShape = aSelection.value()
             if aShape:
               allShapesList = [] # collect all sub-shapes selected in the group
-              if aShape.shapeType() == 0: # compound
+              if aShape.shapeType() == 0 or aShape.shapeType() != aSelType: # compound or whole res
                 anExplorer = GeomAPI_ShapeExplorer(aShape, aSelType)
                 while anExplorer.more():
                   allShapesList.append(anExplorer.current())
@@ -181,7 +208,7 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
             else:
               aGroup = aGroupOp.CreateGroup(theStudyShape, aSelType)
             aGroup.SetEntry(aGroupEntry)
-            theEngine.AddInStudy(aGroup, aRef.firstResult().data().name(), theStudyShape.GetSO())
+            theEngine.AddInStudy(aGroup, aRef.firstResult().data().name(), theStudyShape)
           aGroup.SetSelection(aGroupIndices)
           if theFields:
             self.fillField(aGroup, aRef, theEngine, aGroupIndices)