Salome HOME
Make SHAPEr STUDY fields exported in SMESH into MED file
[modules/shaper_study.git] / src / PY / SHAPERSTUDY_Object.py
index 147e801f0673ba849272f7d93256d5952cd5e154..1621cba439fe328d7553aa6332b0797691ed62c9 100644 (file)
@@ -34,10 +34,36 @@ __shape_types__ = {
   3:GEOM.SHELL, 4:GEOM.FACE, 5:GEOM.WIRE,
   6:GEOM.EDGE, 7:GEOM.VERTEX, 8:GEOM.SHAPE, 9:GEOM.FLAT}
 
+class SHAPERSTUDY_GenericObject:
+    """
+    Implement methods of SALOME::GenericObj
+    """
+
+    def Register(self):
+        """
+        Increase the reference count (mark as used by another object).
+        """
+        return
 
-class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object):
+    def UnRegister(self):
+        """
+        Decrease the reference count (release by another object)
+        """
+        return
+
+    def Destroy(self):
+        """
+        Obsolete, left for compatibility reasons only. Use UnRegister() instead
+        """
+        return
+
+    pass
+
+
+class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
+                         SHAPERSTUDY_GenericObject):
     """
-    Construct an instance of SHAPERSTUDY Object.
+    Constructs an instance of SHAPERSTUDY Object.
     """
     def __init__ ( self, *args):
         self.SO = None
@@ -192,7 +218,7 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object):
         Returns true if the current object has connection to a parametrical model
         which can be modified by parameters change.
         """
-        return not self.IsDead()
+        return not self.IsDead() and self.type == 1 # only break link for shapes are accessible now
 
     def IsDead(self):
         """
@@ -240,7 +266,8 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object):
               aDeadGroup.SetSelection(aGroup.GetSelection())
               aDeadGroupSO = aBuilder.NewObject(aDeadSO)
               aDeadGroup.SetSO(aDeadGroupSO)
-              aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
+              # 15.01.20 groups and fields names stays the same
+              #aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
               aDeadGroupObj = aDeadGroup._this()
               anIOR = salome.orb.object_to_string(aDeadGroupObj)
               aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
@@ -260,7 +287,7 @@ class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object):
 
 class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
     """
-    Construct an instance of SHAPERSTUDY Group
+    Constructs an instance of SHAPERSTUDY Group
     """
     def __init__ ( self, *args):
         self.seltype = None
@@ -268,6 +295,7 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
         self.SO = None
         self.data = None
         self.entry = None
+        self.type = 37 # a group type
         pass
 
     def SetSelectionType(self, theType):
@@ -313,3 +341,184 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
         for l in self.selection:
           anArg.append(l)
         return self.data.groupShape(self.GetMainShape().getShape(), anArg)
+
+    pass
+
+class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
+    """
+    Constructs an instance of SHAPERSTUDY Field (inherits selection from a Group object)
+    """
+    def __init__ ( self, *args):
+        self.seltype = None
+        self.selection = []
+        self.SO = None
+        self.data = None
+        self.entry = None
+        self.type = 52 # a field type
+        self.valtype = None # type of the values
+        self.steps = [] # list of long
+        self.components = [] # string array, names of the components
+        self.name = None # name, string
+        self.fieldsteps = {} # FieldSteps objects identified by step ID
+        pass
+
+    def SetValuesType( self, theType ):
+      """
+      Sets the type of values in the field
+      """
+      self.valtype = theType
+
+    def GetDataType( self ):
+      """
+      Returns the type of values in the field in terms of GEOM enumeration
+      """
+      if self.valtype == 0:
+        return GEOM.FDT_Bool
+      elif self.valtype == 1:
+        return GEOM.FDT_Int
+      elif self.valtype == 2:
+        return GEOM.FDT_Double
+      elif self.valtype == 3:
+        return GEOM.FDT_String
+      return None # unknown case
+
+    def GetShape ( self ):
+      """
+      Returns the shape the field lies on
+      """
+      return super().GetMainShape()
+
+    def SetSteps( self, theSteps ):
+      self.steps = theSteps
+
+    def GetSteps( self ):
+      return self.steps
+
+    def SetComponents( self, theComponents ):
+      self.components = theComponents
+    
+    def GetComponents( self ):
+      return self.components
+
+    def GetDimension( self ):
+      aShapeType = super().GetSelectionType()
+      if aShapeType == 8:
+        return -1 # whole part
+      elif aShapeType == 7:
+        return 0 # vertex
+      elif aShapeType == 6:
+        return 1 # edge
+      elif aShapeType == 4:
+        return 2 # face
+      elif aShapeType == 2:
+        return 3 # solid
+      return None # unknown case
+
+    def ClearFieldSteps( self ):
+       self.fieldsteps = {}
+
+    def AddFieldStep( self, theStampID, theStepID, theValues):
+      aFieldStep = None
+      if self.valtype == 0:
+        aFieldStep = SHAPER_BoolFieldStep()
+      elif self.valtype == 1:
+        aFieldStep = SHAPER_IntFieldStep()
+      elif self.valtype == 2:
+        aFieldStep = SHAPER_DoubleFieldStep()
+      
+      aFieldStep.SetStep(theStampID, theStepID, theValues)
+      self.fieldsteps[theStepID] = aFieldStep._this()
+
+    def GetStep( self, theStepID ):
+       return self.fieldsteps[theStepID]
+
+    pass
+
+class SHAPER_FieldStep:
+    """
+    Base class for all step-classes
+    """
+    def __init__ ( self, *args):
+        self.stamp = None  # long, ID of stamp
+        self.step = None   # long, ID of step
+        self.values = None # array of values of the needed type
+
+    """
+    Defines all parameters of the step
+    """
+    def SetStep( self, theStamp, theStep, theValues ):
+        self.stamp = theStamp
+        self.step = theStep
+        self.values = theValues
+     
+    """
+    Returns stamp ID
+    """
+    def GetStamp( self ):
+        return self.stamp
+    """
+    Returns step ID
+    """
+    def GetID( self ):
+        return self.step
+    """
+    Returns a name of a sub-shape if the sub-shape is published in the study
+    """
+    def GetSubShape(self, theSubID):
+        # the SHAPER study does not support sub-shapes for now
+        return ""
+        
+
+class SHAPER_DoubleFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_DoubleFieldStep, SHAPER_FieldStep):
+    """
+    Constructs an instance of SHAPERSTUDY Field step of type Double
+    """
+    def __init__ ( self, *args):
+        pass
+
+    """
+    Returns values as an array of the needed type
+    """
+    def GetValues( self ):
+        aResult = [] # to make any type of result, create a corba-type
+        for i in self.values:
+          aResult.append(float(i))
+        return aResult
+
+    pass
+
+class SHAPER_IntFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_IntFieldStep, SHAPER_FieldStep):
+    """
+    Constructs an instance of SHAPERSTUDY Field step of type Double
+    """
+    def __init__ ( self, *args):
+        pass
+
+    """
+    Returns values as an array of the needed type
+    """
+    def GetValues( self ):
+        aResult = [] # to make any type of result, create a corba-type
+        for i in self.values:
+          aResult.append(int(i))
+        return aResult
+
+    pass
+
+class SHAPER_BoolFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_BoolFieldStep, SHAPER_FieldStep):
+    """
+    Constructs an instance of SHAPERSTUDY Field step of type Double
+    """
+    def __init__ ( self, *args):
+        pass
+
+    """
+    Returns values as an array of the needed type
+    """
+    def GetValues( self ):
+        aResult = [] # to make any type of result, create a corba-type
+        for i in self.values:
+          aResult.append(int(i))
+        return aResult
+
+    pass