Salome HOME
Implementation NoteBook in SMESH module.
[modules/smesh.git] / src / SMESH_SWIG / smeshDC.py
index 9b77ceaa5b8a03569f31b557db2887536a27e975..0684cecc422ad664fe925ca0fb9137409c175cfb 100644 (file)
@@ -112,6 +112,8 @@ except ImportError:
 REGULAR    = 1
 PYTHON     = 2
 COMPOSITE  = 3
+SOLE       = 0
+SIMPLE     = 1
 
 MEFISTO       = 3
 NETGEN        = 4
@@ -153,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
@@ -2458,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
@@ -2475,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
@@ -3185,11 +3239,10 @@ class Mesh_Triangle(Mesh_Algorithm):
         if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
             hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
                                   CompareMethod=self.CompareMaxElementArea)
-            hyp.SetMaxElementArea(area)
-            return hyp
         elif self.algoType == NETGEN:
-            print "Netgen 1D-2D algo doesn't support this hypothesis"
-            return None
+            hyp = self.Parameters(SIMPLE)
+        hyp.SetMaxElementArea(area)
+        return hyp
 
     ## Checks if the given "MaxElementArea" hypothesis has the same parameters as the given arguments
     def CompareMaxElementArea(self, hyp, args):
@@ -3205,8 +3258,9 @@ class Mesh_Triangle(Mesh_Algorithm):
             hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
             return hyp
         elif self.algoType == NETGEN:
-            print "Netgen 1D-2D algo doesn't support this hypothesis"
-            return None
+            hyp = self.Parameters(SIMPLE)
+            hyp.LengthFromEdges()
+            return hyp
 
     ## Sets a way to define size of mesh elements to generate.
     #  @param thePhysicalMesh is: DefaultSize or Custom.
@@ -3320,28 +3374,33 @@ class Mesh_Triangle(Mesh_Algorithm):
             self.params.SetQuadAllowed(toAllow)
             return
 
-    ## Defines "Netgen 2D Parameters" hypothesis
+    ## Defines hypothesis having several parameters
     #
     #  @ingroup l3_hypos_netgen
-    def Parameters(self):
-        #  Only for algoType == NETGEN
+    def Parameters(self, which=SOLE):
         if self.params:
             return self.params
         if self.algoType == NETGEN:
-            self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
-                                          "libNETGENEngine.so", UseExisting=0)
+            if which == SIMPLE:
+                self.params = self.Hypothesis("NETGEN_SimpleParameters_2D", [],
+                                              "libNETGENEngine.so", UseExisting=0)
+            else:
+                self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
+                                              "libNETGENEngine.so", UseExisting=0)
             return self.params
         elif self.algoType == MEFISTO:
-            print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
+            print "Mefisto algo support no multi-parameter hypothesis"
             return None
         elif self.algoType == NETGEN_2D:
-            print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
+            print "NETGEN_2D_ONLY algo support no multi-parameter hypothesis"
             print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
             return None
         elif self.algoType == BLSURF:
             self.params = self.Hypothesis("BLSURF_Parameters", [],
                                           "libBLSURFEngine.so", UseExisting=0)
             return self.params
+        else:
+            print "Mesh_Triangle with algo type %s does not have such a parameter, check algo type"%self.algoType
         return None
 
     ## Sets MaxSize
@@ -3402,6 +3461,20 @@ class Mesh_Triangle(Mesh_Algorithm):
         if self.Parameters():
             self.params.SetNbSegPerRadius(theVal)
 
+    ## Sets number of segments overriding value set by SetLocalLength()
+    #
+    #  Only for algoType == NETGEN
+    #  @ingroup l3_hypos_netgen
+    def SetNumberOfSegments(self, theVal):
+        self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
+
+    ## Sets number of segments overriding value set by SetNumberOfSegments()
+    #
+    #  Only for algoType == NETGEN
+    #  @ingroup l3_hypos_netgen
+    def SetLocalLength(self, theVal):
+        self.Parameters(SIMPLE).SetLocalLength(theVal)
+
     pass
 
 
@@ -3428,6 +3501,16 @@ class Mesh_Quadrangle(Mesh_Algorithm):
                               CompareMethod=self.CompareEqualHyp)
         return hyp
 
+    ## Defines "TrianglePreference" hypothesis, forcing construction
+    #  of triangles in the refinement area if the number of nodes
+    #  on the opposite edges is not the same
+    #
+    #  @ingroup l3_hypos_additi
+    def TrianglePreference(self):
+        hyp = self.Hypothesis("TrianglePreference", UseExisting=1,
+                              CompareMethod=self.CompareEqualHyp)
+        return hyp
+
 # Public class: Mesh_Tetrahedron
 # ------------------------------
 
@@ -3466,30 +3549,39 @@ class Mesh_Tetrahedron(Mesh_Algorithm):
     #                   the same parameters, else (default) - creates a new one
     #  @ingroup l3_hypos_maxvol
     def MaxElementVolume(self, vol, UseExisting=0):
-        hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
-                              CompareMethod=self.CompareMaxElementVolume)
-        hyp.SetMaxElementVolume(vol)
-        return hyp
+        if self.algoType == NETGEN:
+            hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
+                                  CompareMethod=self.CompareMaxElementVolume)
+            hyp.SetMaxElementVolume(vol)
+            return hyp
+        elif self.algoType == FULL_NETGEN:
+            self.Parameters(SIMPLE).SetMaxElementVolume(vol)
+        return None
 
     ## Checks if the given "MaxElementVolume" hypothesis has the same parameters as the given arguments
     def CompareMaxElementVolume(self, hyp, args):
         return IsEqual(hyp.GetMaxElementVolume(), args[0])
 
-    ## Defines "Netgen 3D Parameters" hypothesis
+    ## Defines hypothesis having several parameters
+    #
     #  @ingroup l3_hypos_netgen
-    def Parameters(self):
+    def Parameters(self, which=SOLE):
         if self.params:
             return self.params
-        if (self.algoType == FULL_NETGEN):
-            self.params = self.Hypothesis("NETGEN_Parameters", [],
-                                          "libNETGENEngine.so", UseExisting=0)
+        if self.algoType == FULL_NETGEN:
+            if which == SIMPLE:
+                self.params = self.Hypothesis("NETGEN_SimpleParameters_3D", [],
+                                              "libNETGENEngine.so", UseExisting=0)
+            else:
+                self.params = self.Hypothesis("NETGEN_Parameters", [],
+                                              "libNETGENEngine.so", UseExisting=0)
             return self.params
-        if (self.algoType == GHS3D):
+        if self.algoType == GHS3D:
             self.params = self.Hypothesis("GHS3D_Parameters", [],
                                           "libGHS3DEngine.so", UseExisting=0)
             return self.params
         
-        print "Algo doesn't support this hypothesis"
+        print "Algo supports no multi-parameter hypothesis"
         return None
 
     ## Sets MaxSize
@@ -3536,6 +3628,39 @@ class Mesh_Tetrahedron(Mesh_Algorithm):
     def SetNbSegPerRadius(self, theVal):
         self.Parameters().SetNbSegPerRadius(theVal)
 
+    ## Sets number of segments overriding value set by SetLocalLength()
+    #  Only for algoType == NETGEN_FULL
+    #  @ingroup l3_hypos_netgen
+    def SetNumberOfSegments(self, theVal):
+        self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
+
+    ## Sets number of segments overriding value set by SetNumberOfSegments()
+    #  Only for algoType == NETGEN_FULL
+    #  @ingroup l3_hypos_netgen
+    def SetLocalLength(self, theVal):
+        self.Parameters(SIMPLE).SetLocalLength(theVal)
+
+    ## Defines "MaxElementArea" parameter of NETGEN_SimpleParameters_3D hypothesis.
+    #  Overrides value set by LengthFromEdges()
+    #  Only for algoType == NETGEN_FULL
+    #  @ingroup l3_hypos_netgen
+    def MaxElementArea(self, area):
+        self.Parameters(SIMPLE).SetMaxElementArea(area)
+
+    ## Defines "LengthFromEdges" parameter of NETGEN_SimpleParameters_3D hypothesis
+    #  Overrides value set by MaxElementArea()
+    #  Only for algoType == NETGEN_FULL
+    #  @ingroup l3_hypos_netgen
+    def LengthFromEdges(self):
+        self.Parameters(SIMPLE).LengthFromEdges()
+
+    ## Defines "LengthFromFaces" parameter of NETGEN_SimpleParameters_3D hypothesis
+    #  Overrides value set by MaxElementVolume()
+    #  Only for algoType == NETGEN_FULL
+    #  @ingroup l3_hypos_netgen
+    def LengthFromFaces(self):
+        self.Parameters(SIMPLE).LengthFromFaces()
+
     ## To mesh "holes" in a solid or not. Default is to mesh.
     #  @ingroup l3_hypos_ghs3dh
     def SetToMeshHoles(self, toMesh):
@@ -3939,3 +4064,83 @@ class Mesh_UseExisting(Mesh_Algorithm):
             self.Create(mesh, geom, "UseExisting_1D")
         else:
             self.Create(mesh, geom, "UseExisting_2D")
+
+
+import salome_notebook
+notebook = salome_notebook.notebook
+
+##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:
+            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(StdMeshers._objref_StdMeshers_LocalLength):
+
+    ## Set length parameter value
+    #  @param length numerical value or name of variable from notebook
+    def SetLength(self, 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 = 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)
+
+
+#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)