Salome HOME
Dump Python extension.
[modules/smesh.git] / src / SMESH_SWIG / smeshDC.py
index 218415f05030525808a8365bf4850d7758918ff3..d6e2f2ae9c188b1aa8d1e9a9edcb9aa7b228bef2 100644 (file)
@@ -112,6 +112,8 @@ except ImportError:
 REGULAR    = 1
 PYTHON     = 2
 COMPOSITE  = 3
+SOLE       = 0
+SIMPLE     = 1
 
 MEFISTO       = 3
 NETGEN        = 4
@@ -162,6 +164,8 @@ 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:
@@ -172,6 +176,8 @@ 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:
@@ -342,6 +348,17 @@ 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
@@ -940,7 +957,7 @@ class Mesh:
     #  @return SMESH.Hypothesis_Status
     #  @ingroup l2_hypotheses
     def AddHypothesis(self, hyp, geom=0):
-        if isinstance( hyp, Mesh_Algorithm ):
+        if isinstance( hyp, Mesh_Algorithm ) or isinstance( hyp, BaseWrapper):
             hyp = hyp.GetAlgorithm()
             pass
         if not geom:
@@ -959,7 +976,7 @@ class Mesh:
     #  @return SMESH.Hypothesis_Status
     #  @ingroup l2_hypotheses
     def RemoveHypothesis(self, hyp, geom=0):
-        if isinstance( hyp, Mesh_Algorithm ):
+        if isinstance( hyp, Mesh_Algorithm ) or isinstance( hyp, BaseWrapper):
             hyp = hyp.GetAlgorithm()
             pass
         if not geom:
@@ -2872,7 +2889,12 @@ class Mesh_Algorithm:
                 pass
             SetName(hypo, hyp + a)
             pass
-        status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
+        bhypo = None
+        if isinstance(hypo,BaseWrapper):
+            bhypo = hypo.GetAlgorithm()
+        else:
+            bhypo = hypo
+        status = self.mesh.mesh.AddHypothesis(self.geom, bhypo)
         TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
         return hypo
 
@@ -3185,11 +3207,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 +3226,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 +3342,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 +3429,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
 
 
@@ -3476,30 +3517,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
@@ -3546,6 +3596,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):
@@ -3949,3 +4032,69 @@ class Mesh_UseExisting(Mesh_Algorithm):
             self.Create(mesh, geom, "UseExisting_1D")
         else:
             self.Create(mesh, geom, "UseExisting_2D")
+
+
+
+
+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
+        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
+            
+       
+#Wrapper class for StdMeshers_LocalLength hypothesis
+class LocalLength(BaseWrapper):
+    def __init__(self, hypo):
+        self.hypo = hypo
+
+    def SetLength(self, length):
+        length,parameters = self.ParseParameters(self.hypo.GetParameters(),2,1,length)
+        self.hypo.SetParameters(parameters)
+        self.hypo.SetLength(length)
+
+    def SetPrecision(self, precision):
+        precision,parameters = self.ParseParameters(self.hypo.GetParameters(),2,2,precision)
+        self.hypo.SetParameters(parameters)
+        self.hypo.SetPrecision(precision)
+
+    def GetLength(self):
+        return self.hypo.GetLength()
+
+    def GetPrecision(self):
+        return self.hypo.GetLength()