Salome HOME
Make SMESH mesh not up-to-date if only group is updated.
[modules/shaper_study.git] / src / PY / SHAPERSTUDY_Object.py
index d0d2317eae418bd591344ce144410526e1b07f8c..c7b4ae195da7b0cfe409085a05ddbed9df7208c5 100755 (executable)
@@ -1,7 +1,4 @@
-# Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
-#
-# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+# Copyright (C) 2019-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
@@ -302,7 +299,10 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
               aDeadGroupEntry = "dead" + str(anIndex) + "_" + aGroup.GetEntry()
               aDeadGroup.SetEntry(aDeadGroupEntry)
               aDeadGroup.SetSelectionType(aGroup.GetSelectionType())
-              aDeadGroup.SetSelection(aGroup.GetSelection())
+              anOldSelection = aGroup.GetSelectionOld()
+              if len(anOldSelection) == 0: # in case there is no old modification, get the current, same as in shape
+                anOldSelection = aGroup.GetSelection()
+              aDeadGroup.SetSelection(anOldSelection)
               if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field): # additional field data
                 aDeadGroup.SetValuesType(aGroup.GetValuesType())
                 aDeadGroup.SetSteps(aGroup.GetSteps())
@@ -333,6 +333,22 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
         if not self.data:
           self.data = StudyData_Swig.StudyData_Object()
         self.data.SetShapeByPointer(theShape)
+        return
+
+    ### unnecessary methods that can be accidentally called from any module
+    def GetTopologyType(self, *args): return GEOM.SHAPE
+    def GetMinShapeType(self, *args): return GEOM.SHAPE
+    def GetMaxShapeType(self, *args): return GEOM.SHAPE
+    def GetSubShapeName(self, *args): return ""
+    def SetColor(self, *args): return
+    def GetColor(self, *args): import SALOMEDS; return SALOMEDS.Color( 0,0,0 )
+    def SetAutoColor(self, *args): return 
+    def GetAutoColor(self, *args): return False
+    def SetMarkerStd(self, *args): return 
+    def SetMarkerTexture(self, *args): return 
+    def GetMarkerType(self, *args): return GEOM.MT_NONE
+    def GetMarkerSize(self, *args): return GEOM.MS_NONE
+    def GetMarkerTexture(self, *args): return 0
 
     pass
 
@@ -344,6 +360,8 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
         SHAPERSTUDY_GenericObject.__init__(self)
         self.seltype = None
         self.selection = []
+        self.selectionTick = -2 # tick of the main shape when the current selection is set
+        self.selectionOld = [] # keep selection for breaking link
         self.SO = None
         self.data = None
         self.entry = ""
@@ -366,8 +384,25 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
         """
         Sets what is returned in the GEOM_IGroupOperations::GetObjects
         """
-        self.data = None # nullify the cashed shape when selection is changed
-        self.selection = theSelection
+        aTick = -2
+        if self.SO:
+          aMainShape = self.GetMainShape()
+          if aMainShape:
+            aTick = aMainShape.GetTick()
+        if aTick > self.selectionTick or aTick == -2:
+          self.selectionOld = self.selection
+          self.selection = theSelection
+          self.selectionTick = aTick
+          #print("Set selection " + self.entry + " old = " + str(self.selectionOld) + " new = " + str(self.selection) + " tick = " + str(aTick))
+        elif self.selection != theSelection:
+          self.selectionOld = self.selection
+          self.selection = theSelection
+          if self.selectionTick < 0:
+            self.selectionTick = aTick + 1
+          else:
+            self.selectionTick = self.selectionTick + 1 # when the group is changed, but the main shape stays the same, make tick + 1
+          #print("Set selection " + self.entry + " old = " + str(self.selectionOld) + " new = " + str(self.selection) + " tick = " + str(self.selectionTick))
+        pass
 
     def GetSelection(self):
         """
@@ -375,6 +410,13 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
         """
         return self.selection
 
+    def GetSelectionOld(self):
+        """
+        Returns the previously selected sub-shapes indices
+        """
+        #print("get selection OLD " + self.entry + " old = " + str(self.selectionOld) + " new = " + str(self.selection))
+        return self.selectionOld
+
     def IsMainShape( self ):
         """
         Returns True if this object is not a sub-shape of another object.
@@ -414,6 +456,19 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
 
     pass
 
+    def GetTick( self ):
+        """
+        Get value of a modification counter of the group
+        """
+        return self.selectionTick
+
+    def SetTick( self, theValue ):
+        """
+        Sets value of a modification counter of the group
+        """
+        #print("Set tick " + self.entry + " tick = " + str(theValue))
+        self.selectionTick = theValue
+
 class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
     """
     Constructs an instance of SHAPERSTUDY Field (inherits selection from a Group object)
@@ -422,6 +477,8 @@ class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
         SHAPERSTUDY_GenericObject.__init__(self)
         self.seltype = None
         self.selection = []
+        self.selectionTick = -2 # tick of the main shape when the current selection is set
+        self.selectionOld = [] # keep selection for breaking link
         self.SO = None
         self.data = None
         self.entry = None
@@ -600,3 +657,4 @@ class SHAPER_BoolFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_BoolFieldStep, SHAPER_Fie
         return aResult
 
     pass
+