Salome HOME
Make SHAPERSTUDY group never main shape
[modules/shaper_study.git] / src / PY / SHAPERSTUDY_Object.py
index 06160e306b5f8883fdab391a844b19a3deeedaa5..d0d2317eae418bd591344ce144410526e1b07f8c 100755 (executable)
@@ -61,6 +61,8 @@ class SHAPERSTUDY_GenericObject:
             poa = getPOA()
             oid=poa.servant_to_id(self)
             poa.deactivate_object(oid)
+            if hasattr(self,"SetSO"):
+                self.SetSO(None) # release a GenericObject SO
             #print("UnRegister() --------- OK")
         return
 
@@ -83,7 +85,7 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
         SHAPERSTUDY_GenericObject.__init__(self)
         self.SO = None
         self.data = None
-        self.entry = None
+        self.entry = ""
         self.type = 1 # by default it is a shape (Import feature in GEOMImpl_Types.hxx)
         pass
 
@@ -191,11 +193,21 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
           return self.data.getTick()
         return 0
 
+    def SetTick( self, theValue ):
+        """
+        Sets value of a modification counter of the object
+        """
+        if self.data:
+          return self.data.setTick(theValue)
+        return 0
+
     def GetStudyEntry( self ):
         """
         Get a Study entry where this object was published.
         """
-        return self.SO.GetID()
+        if self.SO:
+            return self.SO.GetID()
+        return ""
 
     def IsShape( self ):
         """
@@ -214,14 +226,19 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
         """
         Return the engine creating this object
         """
-        return getEngine()
+        e = getEngine()
+        return e._duplicate( e )
 
     def SetSO( self, theSO ):
         """
         Sets SObject of this object (when it is published)
         """
+        if theSO:
+            theSO.Register() # I hold a GenericObject!
+        if self.SO:
+            self.SO.UnRegister()
         self.SO = theSO
-        
+
     def GetSO( self ):
         """
         Returns SObject of this object
@@ -247,14 +264,18 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
         """
         aStudy = getStudy()
         aBuilder = aStudy.NewBuilder()
-        aRes, aHistSO = self.SO.FindSubObject(2)
+        aRes, aHistSO = self.SO.FindSubObject(10000)
         if not aRes: # create a "history" folder if it does not exist
-          aHistSO = aBuilder.NewObjectToTag(self.SO, 2)
+          aHistSO = aBuilder.NewObjectToTag(self.SO, 10000)
           aHistSO.SetAttrString("AttributeName", "History")
 
         aDeadSO = aBuilder.NewObject(aHistSO)
         anIndex = aDeadSO.Tag()
         aDeadSO.SetAttrString("AttributeName", self.SO.GetName() + " (" + str(anIndex) + ")")
+        aRes, aPixMap = aBuilder.FindAttribute(self.SO, "AttributePixMap")
+        if aRes:
+          aDeadPixMap = aBuilder.FindOrCreateAttribute(aDeadSO, "AttributePixMap")
+          aDeadPixMap.SetPixMap(aPixMap.GetPixMap())
         aDead = SHAPERSTUDY_Object()
         aDeadEntry = "dead" + str(anIndex) + "_" + self.GetEntry()
         aDead.SetEntry(aDeadEntry)
@@ -272,17 +293,32 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
           anIOR = aGroupSO.GetIOR()
           if len(anIOR):
             aGroup = salome.orb.string_to_object(anIOR)
-            if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
-              aDeadGroup = SHAPERSTUDY_Group()
+            if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
+               isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
+              if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
+                aDeadGroup = SHAPERSTUDY_Group()
+              else:
+                aDeadGroup = SHAPERSTUDY_Field()
               aDeadGroupEntry = "dead" + str(anIndex) + "_" + aGroup.GetEntry()
               aDeadGroup.SetEntry(aDeadGroupEntry)
-              aDeadGroup.SetShapeByPointer(aGroup.getShape())
               aDeadGroup.SetSelectionType(aGroup.GetSelectionType())
               aDeadGroup.SetSelection(aGroup.GetSelection())
+              if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field): # additional field data
+                aDeadGroup.SetValuesType(aGroup.GetValuesType())
+                aDeadGroup.SetSteps(aGroup.GetSteps())
+                aDeadGroup.SetComponents(aGroup.GetComponents())
+                for aStep in aGroup.GetSteps():
+                  aStepObj = aGroup.GetStep(aStep)
+                  aDeadGroup.AddFieldStep(aStepObj.GetStamp(), aStep, aStepObj.GetValues())
               aDeadGroupSO = aBuilder.NewObject(aDeadSO)
               aDeadGroup.SetSO(aDeadGroupSO)
               # 15.01.20 groups and fields names stays the same
               #aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
+              aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName())
+              aRes, aPixMap = aBuilder.FindAttribute(aGroupSO, "AttributePixMap")
+              if aRes:
+                aDeadPixMap = aBuilder.FindOrCreateAttribute(aDeadGroupSO, "AttributePixMap")
+                aDeadPixMap.SetPixMap(aPixMap.GetPixMap())
               aDeadGroupObj = aDeadGroup._this()
               anIOR = salome.orb.object_to_string(aDeadGroupObj)
               aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
@@ -310,7 +346,7 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
         self.selection = []
         self.SO = None
         self.data = None
-        self.entry = None
+        self.entry = ""
         self.type = 37 # a group type
         pass
 
@@ -339,12 +375,24 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
         """
         return self.selection
 
+    def IsMainShape( self ):
+        """
+        Returns True if this object is not a sub-shape of another object.
+        """
+        return False
+
     def GetMainShape( self ):
         """
         Main shape is groups owner
         """
         return self.SO.GetFather().GetObject()
 
+    def GetSubShapeIndices( self ):
+        """
+        Get a list of ID's of sub-shapes in the main shape.
+        """
+        return self.selection
+
     def getShape( self ):
         """
         Redefinition of the getShape method: here it creates a shape by the
@@ -358,6 +406,12 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
           anArg.append(l)
         return self.data.groupShape(self.GetMainShape().getShape(), anArg)
 
+    def GetShapeType( self ):
+        """
+        Group shape type is always compound.
+        """
+        return GEOM.COMPOUND;
+
     pass
 
 class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
@@ -385,6 +439,13 @@ class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
       """
       self.valtype = theType
 
+    def GetValuesType( self ):
+      """
+      Returns the type of values in the field
+      """
+      return self.valtype
+
+
     def GetDataType( self ):
       """
       Returns the type of values in the field in terms of GEOM enumeration