Salome HOME
Implementation NoteBook in SMESH module.
[modules/smesh.git] / src / SMESH_SWIG / smeshDC.py
index d6e2f2ae9c188b1aa8d1e9a9edcb9aa7b228bef2..0684cecc422ad664fe925ca0fb9137409c175cfb 100644 (file)
@@ -155,6 +155,50 @@ DefaultSize, DefaultGeom, Custom = 0,0,1
 
 PrecisionConfusion = 1e-07
 
+# Salome notebook variable separator
+variable_separator = ":"
+
+# Parametrized substitute for PointStruct
+class PointStructStr:
+
+    x = 0
+    y = 0
+    z = 0
+    xStr = ""
+    yStr = ""
+    zStr = ""
+
+    def __init__(self, xStr, yStr, zStr):
+        self.xStr = xStr
+        self.yStr = yStr
+        self.zStr = zStr
+        if isinstance(xStr, str) and notebook.isVariable(xStr):
+            self.x = notebook.get(xStr)
+        else:
+            self.x = xStr
+        if isinstance(yStr, str) and notebook.isVariable(yStr):
+            self.y = notebook.get(yStr)
+        else:
+            self.y = yStr
+        if isinstance(zStr, str) and notebook.isVariable(zStr):
+            self.z = notebook.get(zStr)
+        else:
+            self.z = zStr
+
+# Parametrized substitute for DirStruct
+class DirStructStr:
+
+    def __init__(self, pointStruct):
+        self.pointStruct = pointStruct
+
+# Returns list of variable values from salome notebook
+def ParseDirStruct(Vector):
+    pntStr = Vector.pointStruct
+    pnt = PointStruct(pntStr.x, pntStr.y, pntStr.z)
+    Vector = DirStruct(pnt)
+    Parameters = str(pntStr.xStr) + ":" + str(pntStr.yStr) + ":" + str(pntStr.zStr)
+    return Vector, Parameters
+
 def IsEqual(val1, val2, tol=PrecisionConfusion):
     if abs(val1 - val2) < tol:
         return True
@@ -164,8 +208,6 @@ NO_NAME = "NoName"
 
 ## Gets object name
 def GetName(obj):
-    if isinstance(obj, BaseWrapper):
-        obj = obj.GetAlgorithm()
     ior  = salome.orb.object_to_string(obj)
     sobj = salome.myStudy.FindObjectIOR(ior)
     if sobj is None:
@@ -176,8 +218,6 @@ def GetName(obj):
 
 ## Sets a name to the object
 def SetName(obj, name):
-    if isinstance(obj, BaseWrapper):
-        obj = obj.GetAlgorithm()
     ior  = salome.orb.object_to_string(obj)
     sobj = salome.myStudy.FindObjectIOR(ior)
     if not sobj is None:
@@ -348,17 +388,6 @@ class smeshDC(SMESH._objref_SMESH_Gen):
         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
         return aMesh
 
-    ## Create hyporthesis
-    #  @return an instance of hypothesis
-    #  @ingroup l2_impexp
-    def CreateHypothesis(self, hyp, so):
-        hypo = SMESH._objref_SMESH_Gen.CreateHypothesis(self, hyp, so)
-        if hyp == "LocalLength":
-            hypo = LocalLength(hypo)
-            
-        return hypo
-        
-
     ## Creates a Mesh object(s) importing data from the given MED file
     #  @return a list of Mesh class instances
     #  @ingroup l2_impexp
@@ -957,7 +986,7 @@ class Mesh:
     #  @return SMESH.Hypothesis_Status
     #  @ingroup l2_hypotheses
     def AddHypothesis(self, hyp, geom=0):
-        if isinstance( hyp, Mesh_Algorithm ) or isinstance( hyp, BaseWrapper):
+        if isinstance( hyp, Mesh_Algorithm ):
             hyp = hyp.GetAlgorithm()
             pass
         if not geom:
@@ -976,7 +1005,7 @@ class Mesh:
     #  @return SMESH.Hypothesis_Status
     #  @ingroup l2_hypotheses
     def RemoveHypothesis(self, hyp, geom=0):
-        if isinstance( hyp, Mesh_Algorithm ) or isinstance( hyp, BaseWrapper):
+        if isinstance( hyp, Mesh_Algorithm ):
             hyp = hyp.GetAlgorithm()
             pass
         if not geom:
@@ -2475,13 +2504,17 @@ class Mesh:
     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
     #  @ingroup l2_modif_trsf
     def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
+        Parameters = ""
         if IDsOfElements == []:
             IDsOfElements = self.GetElementsId()
         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
             Vector = self.smeshpyD.GetDirStruct(Vector)
+        elif ( isinstance( Vector, DirStructStr ) ):
+            Vector,Parameters = ParseDirStruct(Vector)
         if Copy and MakeGroups:
             return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
         self.editor.Translate(IDsOfElements, Vector, Copy)
+        self.mesh.SetParameters(Parameters)
         return []
 
     ## Creates a new mesh of translated elements
@@ -2492,11 +2525,15 @@ class Mesh:
     #  @return instance of Mesh class
     #  @ingroup l2_modif_trsf
     def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
+        Parameters = ""
         if IDsOfElements == []:
             IDsOfElements = self.GetElementsId()
         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
             Vector = self.smeshpyD.GetDirStruct(Vector)
+        elif ( isinstance( Vector, DirStructStr ) ):
+            Vector,Parameters = ParseDirStruct(Vector)
         mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
+        mesh.SetParameters(Parameters)
         return Mesh ( self.smeshpyD, self.geompyD, mesh )
 
     ## Translates the object
@@ -2889,12 +2926,7 @@ class Mesh_Algorithm:
                 pass
             SetName(hypo, hyp + a)
             pass
-        bhypo = None
-        if isinstance(hypo,BaseWrapper):
-            bhypo = hypo.GetAlgorithm()
-        else:
-            bhypo = hypo
-        status = self.mesh.mesh.AddHypothesis(self.geom, bhypo)
+        status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
         TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
         return hypo
 
@@ -4034,67 +4066,81 @@ class Mesh_UseExisting(Mesh_Algorithm):
             self.Create(mesh, geom, "UseExisting_2D")
 
 
+import salome_notebook
+notebook = salome_notebook.notebook
 
-
-from salome_notebook import *
-
-##Base class for wrap all StdMeshers interfaces
-class BaseWrapper:
-    
-    ##Return instance of a _objref_StdMeshers hypothesis
-    def GetAlgorithm(self):
-        return self.hypo
-
-    ##Return values of the notebook variables
-    def ParseParameters(self, params ,nbParams, nbParam, arg):
-        result = None
-        strResult = ""
-        isVar = False
-        if isinstance(arg, str):
-            if notebook.isVariable(arg):
-                result = notebook.get(arg)
-                isVar = True
+##Return values of the notebook variables
+def ParseParameters(last, nbParams,nbParam, value):
+    result = None
+    strResult = ""
+    counter = 0
+    listSize = len(last)
+    for n in range(0,nbParams):
+        if n+1 != nbParam:
+            if counter < listSize:
+                strResult = strResult + last[counter]
+            else:
+                strResult = strResult + ""
         else:
-            result = arg
-
-        isEmpty = True
-        paramsList = []
-        if len(params) > 0:
-            paramsList = params.split(":")
-            isEmpty = False
-            
-        for n in range(1,nbParams+1):
-            if n != nbParam and not isEmpty and len(paramsList[n-1])> 0:
-                strResult = paramsList[n-1] + ":"
-                pass
-            if isVar and n == nbParam:
-                if len(strResult) == 0 and nbParam != 1:
-                    strResult = strResult + ":"
-                    pass
-                strResult = strResult+arg
-                if n != nbParams:
-                    strResult = strResult + ":"
-                    
-        return result, strResult
-            
-       
+            if isinstance(value, str) and notebook.isVariable(value):
+                result = notebook.get(value)
+                strResult=strResult+value 
+            else:
+                strResult=strResult+str(value)
+                result = value
+        if nbParams - 1 != counter:
+            strResult=strResult+variable_separator #":"
+        counter = counter+1
+    return result, strResult
+
 #Wrapper class for StdMeshers_LocalLength hypothesis
-class LocalLength(BaseWrapper):
-    def __init__(self, hypo):
-        self.hypo = hypo
+class LocalLength(StdMeshers._objref_StdMeshers_LocalLength):
 
+    ## Set length parameter value
+    #  @param length numerical value or name of variable from notebook
     def SetLength(self, length):
-        length,parameters = self.ParseParameters(self.hypo.GetParameters(),2,1,length)
-        self.hypo.SetParameters(parameters)
-        self.hypo.SetLength(length)
+        length,parameters = ParseParameters(StdMeshers._objref_StdMeshers_LocalLength.GetLastParameters(self),2,1,length)
+        StdMeshers._objref_StdMeshers_LocalLength.SetParameters(self,parameters)
+        StdMeshers._objref_StdMeshers_LocalLength.SetLength(self,length)
 
+   ## Set precision parameter value
+   #  @param precision numerical value or name of variable from notebook
     def SetPrecision(self, precision):
-        precision,parameters = self.ParseParameters(self.hypo.GetParameters(),2,2,precision)
-        self.hypo.SetParameters(parameters)
-        self.hypo.SetPrecision(precision)
+        precision,parameters = ParseParameters(StdMeshers._objref_StdMeshers_LocalLength.GetLastParameters(self),2,2,precision)
+        StdMeshers._objref_StdMeshers_LocalLength.SetParameters(self,parameters)
+        StdMeshers._objref_StdMeshers_LocalLength.SetPrecision(self, precision)
+
+#Registering the new proxy for LocalLength
+omniORB.registerObjref(StdMeshers._objref_StdMeshers_LocalLength._NP_RepositoryId, LocalLength)
 
-    def GetLength(self):
-        return self.hypo.GetLength()
 
-    def GetPrecision(self):
-        return self.hypo.GetLength()
+#Wrapper class for StdMeshers_SegmentLengthAroundVertex hypothesis
+class SegmentLengthAroundVertex(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex):
+    
+    ## Set length parameter value
+    #  @param length numerical value or name of variable from notebook    
+    def SetLength(self, length):
+        length,parameters = ParseParameters(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex.GetLastParameters(self),1,1,length)
+        StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex.SetParameters(self,parameters)
+        StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex.SetLength(self,length)
+
+#Registering the new proxy for SegmentLengthAroundVertex
+omniORB.registerObjref(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex._NP_RepositoryId, SegmentLengthAroundVertex)
+
+
+#Wrapper class for StdMeshers_Arithmetic1D hypothesis
+class Arithmetic1D(StdMeshers._objref_StdMeshers_Arithmetic1D):
+    
+    ## Set length parameter value
+    #  @param length   numerical value or name of variable from notebook
+    #  @param isStart  true is length is Start Length, otherwise false
+    def SetLength(self, length, isStart):
+        nb = 2
+        if isStart:
+            nb = 1
+        length,parameters = ParseParameters(StdMeshers._objref_StdMeshers_Arithmetic1D.GetLastParameters(self),2,nb,length)
+        StdMeshers._objref_StdMeshers_Arithmetic1D.SetParameters(self,parameters)
+        StdMeshers._objref_StdMeshers_Arithmetic1D.SetLength(self,length,isStart)
+        
+#Registering the new proxy for LocalLength
+omniORB.registerObjref(StdMeshers._objref_StdMeshers_Arithmetic1D._NP_RepositoryId, Arithmetic1D)