Salome HOME
updated copyright message
[modules/shaper.git] / src / ConnectorPlugin / ConnectorPlugin_PublishToStudyFeature.py
index 30be5591dba34a0696b703b035429463d7b985d6..af0a615c56f7de0a02859e4965d60f1b709c113f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+# Copyright (C) 2014-2023  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
@@ -64,8 +64,8 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
         aPartSet = aSession.moduleDocument()
         # check that the PartSet document current feature is the last to avoid problems with all
         # features update
-        if aPartSet.size(model.ModelAPI_Feature_group()) > 0:
-          aLastFeature = ModelAPI.objectToFeature(aPartSet.object(model.ModelAPI_Feature_group(), aPartSet.size(model.ModelAPI_Feature_group()) - 1))
+        if aPartSet.size(model.ModelAPI_Feature.group()) > 0:
+          aLastFeature = ModelAPI.objectToFeature(aPartSet.object(model.ModelAPI_Feature.group(), aPartSet.size(model.ModelAPI_Feature.group()) - 1))
           aCurrentFeature = aPartSet.currentFeature(True)
           if aLastFeature.data().featureId() != aCurrentFeature.data().featureId():
             EventsAPI.Events_InfoMessage("PublishToStudy", "Not all PartSet parts are up-to-date, nothing is published. Please, make the last PartSet feature as current.", self).send()
@@ -78,20 +78,23 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
         allProcessed = []
 
         # iterate all parts and all results to publish them in SHAPER_STUDY
-        for aPartId in range(aPartSet.size(model.ModelAPI_ResultPart_group())):
-          aPartObject = aPartSet.object(model.ModelAPI_ResultPart_group(), aPartId)
+        for aPartId in range(aPartSet.size(model.ModelAPI_ResultPart.group())):
+          aPartObject = aPartSet.object(model.ModelAPI_ResultPart.group(), aPartId)
           aPartRes = ModelAPI.modelAPI_ResultPart(ModelAPI.modelAPI_Result(aPartObject))
           aPartDoc = aPartRes.partDoc()
           if aPartDoc is None and aPartObject is not None:
-            EventsAPI.Events_InfoMessage("PublishToStudy", "For publish to SHAPER-STUDY some Part is not activated", self).send()
+            EventsAPI.Events_InfoMessage("PublishToStudy", "To publish to SHAPER-STUDY, activate Parts in SHAPER", self).send()
             break
-          aPartFeatureId = aPartSet.feature(aPartRes).data().featureId()
+          aPartFeatureId = aPartSet.feature(aPartRes.original()).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)
+          for aResId in range(aPartDoc.size(model.ModelAPI_ResultBody.group())):
+            aResObject = aPartDoc.object(model.ModelAPI_ResultBody.group(), aResId)
             aRes = model.objectToResult(aResObject)
+            #do not export images
+            if aRes.hasTexture() is True:
+              continue
             aResFeatureId = str(aPartDoc.feature(aRes).data().featureId())
             if aResFeatureId in aFeaturesIndices:
               aFeaturesIndices[aResFeatureId] += 1
@@ -160,51 +163,54 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
     # If theFields is true, the same is performed for Fields.
     def processGroups(self, theRes, theEngine, thePartFeatureId, theStudyShape, theFields):
       allGroupsProcessed = []
+      allRefGroups = []
       if theFields:
-        aRefGroups = ModelAPI.referencedFeatures(theRes, "Field", True)
+        allRefGroups.append(ModelAPI.referencedFeatures(theRes, "Field", True))
       else:
-        aRefGroups = ModelAPI.referencedFeatures(theRes, "Group", True)
-      for aRef in aRefGroups:
-        aGroupIndices = []
-        aGroupHasIndex = {}
-        aResShape = theRes.shape()
-        if theFields:
-          aSelList = aRef.selectionList("selected")
-        else:
-          aSelList = aRef.selectionList("group_list")
-        aSelType = GeomAPI_Shape.shapeTypeByStr(aSelList.selectionType())
-        for aGroupRes in aRef.results():
-          aShape = aGroupRes.shape()
-          anExplorer = GeomAPI_ShapeExplorer(aShape, aSelType)
-          while anExplorer.more():
-            anId = GeomAlgoAPI.GeomAlgoAPI_CompoundBuilder.id(aResShape, anExplorer.current())
-            if anId > 0 and not anId in aGroupHasIndex:
-              aGroupIndices.append(anId)
-              aGroupHasIndex[anId] = 0
-            anExplorer.next()
-        if len(aGroupIndices): # create group
-          aGroupFeatureId = aRef.data().featureId()
+        allRefGroups.append(ModelAPI.referencedFeatures(theRes, "Group", True))
+        allRefGroups.append(ModelAPI.referencedFeatures(theRes, "Shared_faces", True))
+      for aRefGroups in allRefGroups:
+        for aRef in aRefGroups:
+          aGroupIndices = []
+          aGroupHasIndex = {}
+          aResShape = theRes.shape()
           if theFields:
-            aFieldOp = theEngine.GetIFieldOperations()
-            aGroupEntry = "field" + str(thePartFeatureId) + ":" + str(aGroupFeatureId)
-            aGroup = aFieldOp.FindField(theStudyShape, aGroupEntry)
+            aSelList = aRef.selectionList("selected")
           else:
-            aGroupOp = theEngine.GetIGroupOperations()
-            aGroupEntry = "group" + str(thePartFeatureId) + ":" + str(aGroupFeatureId)
-            aGroup = aGroupOp.FindGroup(theStudyShape, aGroupEntry)
-          if not aGroup: # create a new
+            aSelList = aRef.selectionList("group_list")
+          aSelType = GeomAPI_Shape.shapeTypeByStr(aSelList.selectionType())
+          for aGroupRes in aRef.results():
+            aShape = aGroupRes.shape()
+            anExplorer = GeomAPI_ShapeExplorer(aShape, aSelType)
+            while anExplorer.more():
+              anId = GeomAlgoAPI.GeomAlgoAPI_CompoundBuilder.id(aResShape, anExplorer.current())
+              if anId > 0 and not anId in aGroupHasIndex:
+                aGroupIndices.append(anId)
+                aGroupHasIndex[anId] = 0
+              anExplorer.next()
+          if len(aGroupIndices): # create group
+            aGroupFeatureId = aRef.data().featureId()
             if theFields:
-              aGroup = aFieldOp.CreateFieldByType(theStudyShape, aSelType)
+              aFieldOp = theEngine.GetIFieldOperations()
+              aGroupEntry = "field" + str(thePartFeatureId) + ":" + str(aGroupFeatureId)
+              aGroup = aFieldOp.FindField(theStudyShape, aGroupEntry)
             else:
-              aGroup = aGroupOp.CreateGroup(theStudyShape, aSelType)
-            aGroup.SetEntry(aGroupEntry)
-            theEngine.AddInStudy(aGroup, aRef.firstResult().data().name(), theStudyShape)
-          aGroup.SetSelection(aGroupIndices)
-          if theFields:
-            self.fillField(aGroup, aRef, theEngine, aGroupIndices)
-          # a group takes shape from the main result
-          #aGroup.SetShapeByStream(aRef.firstResult().shape().getShapeStream(False)) # group shape
-          allGroupsProcessed.append(aGroupEntry)
+              aGroupOp = theEngine.GetIGroupOperations()
+              aGroupEntry = "group" + str(thePartFeatureId) + ":" + str(aGroupFeatureId)
+              aGroup = aGroupOp.FindGroup(theStudyShape, aGroupEntry)
+            if not aGroup: # create a new
+              if theFields:
+                aGroup = aFieldOp.CreateFieldByType(theStudyShape, aSelType)
+              else:
+                aGroup = aGroupOp.CreateGroup(theStudyShape, aSelType)
+              aGroup.SetEntry(aGroupEntry)
+              theEngine.AddInStudy(aGroup, aRef.firstResult().data().name(), theStudyShape)
+            aGroup.SetSelection(aGroupIndices)
+            if theFields:
+              self.fillField(aGroup, aRef, theEngine, 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(theStudyShape.GetSO())
       while aSOIter.More():
@@ -224,7 +230,10 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature):
     def fillField(self, theField, theFeature, theEngine, theSelectionIndices):
       aTables = theFeature.tables("values")
       aValType = aTables.type() # type of the values
-      theField.SetValuesType(aValType)
+      aValTypeToSet = aValType
+      if aValType == 3: # strings do not supported by SMESH, so, make them empty boolean table
+        aValTypeToSet = 0
+      theField.SetValuesType(aValTypeToSet)
       aNumSteps = aTables.tables() # number of steps is number of tables
       aSteps = []
       for aVal in range(aNumSteps):