Salome HOME
Bug 0020072: GHS3DPRLPLUGIN update. Integrating the attached patch.
[modules/smesh.git] / src / SMESH_SWIG / smeshDC.py
index 218415f05030525808a8365bf4850d7758918ff3..db8a34ccd929a4e40eed1366d45a9464810d2fe8 100644 (file)
@@ -1,4 +1,6 @@
-#  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+#  Copyright (C) 2007-2008  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
 #
 #  This library is free software; you can redistribute it and/or
@@ -20,7 +22,7 @@
 #  File   : smesh.py
 #  Author : Francis KLOSS, OCC
 #  Module : SMESH
-
+#
 """
  \namespace smesh
  \brief Module smesh
@@ -112,6 +114,8 @@ except ImportError:
 REGULAR    = 1
 PYTHON     = 2
 COMPOSITE  = 3
+SOLE       = 0
+SIMPLE     = 1
 
 MEFISTO       = 3
 NETGEN        = 4
@@ -124,6 +128,7 @@ NETGEN_FULL   = FULL_NETGEN
 Hexa    = 8
 Hexotic = 9
 BLSURF  = 10
+GHS3DPRL = 11
 
 # MirrorType enumeration
 POINT = SMESH_MeshEditor.POINT
@@ -172,6 +177,10 @@ def GetName(obj):
 
 ## Sets a name to the object
 def SetName(obj, name):
+    if isinstance( obj, Mesh ):
+        obj = obj.GetMesh()
+    elif isinstance( obj, Mesh_Algorithm ):
+        obj = obj.GetAlgorithm()
     ior  = salome.orb.object_to_string(obj)
     sobj = salome.myStudy.FindObjectIOR(ior)
     if not sobj is None:
@@ -231,9 +240,7 @@ class smeshDC(SMESH._objref_SMESH_Gen):
     ## Sets the current study and Geometry component
     #  @ingroup l1_auxiliary
     def init_smesh(self,theStudy,geompyD):
-        self.geompyD=geompyD
-        self.SetGeomEngine(geompyD)
-        self.SetCurrentStudy(theStudy)
+        self.SetCurrentStudy(theStudy,geompyD)
 
     ## Creates an empty Mesh. This mesh can have an underlying geometry.
     #  @param obj the Geometrical object on which the mesh is built. If not defined,
@@ -324,8 +331,14 @@ class smeshDC(SMESH._objref_SMESH_Gen):
 
     ## Sets the current study
     #  @ingroup l1_auxiliary
-    def SetCurrentStudy( self, theStudy ):
+    def SetCurrentStudy( self, theStudy, geompyD = None ):
         #self.SetCurrentStudy(theStudy)
+        if not geompyD:
+            import geompy
+            geompyD = geompy.geom
+            pass
+        self.geompyD=geompyD
+        self.SetGeomEngine(geompyD)
         SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
 
     ## Gets the current study
@@ -361,6 +374,24 @@ class smeshDC(SMESH._objref_SMESH_Gen):
         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
         return aMesh
 
+    ## Concatenate the given meshes into one mesh.
+    #  @return an instance of Mesh class
+    #  @param meshes the meshes to combine into one mesh
+    #  @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
+    #  @param mergeNodesAndElements if true, equal nodes and elements aremerged
+    #  @param mergeTolerance tolerance for merging nodes
+    #  @param allGroups forces creation of groups of all elements
+    def Concatenate( self, meshes, uniteIdenticalGroups,
+                     mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False):
+        if allGroups:
+            aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
+                self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
+        else:
+            aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
+                self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
+        aMesh = Mesh(self, self.geompyD, aSmeshMesh)
+        return aMesh
+
     ## From SMESH_Gen interface
     #  @return the list of integer values
     #  @ingroup l1_auxiliary
@@ -747,7 +778,7 @@ class Mesh:
     #  The parameter \a algo permits to choose the algorithm: NETGEN or GHS3D
     #  If the optional \a geom parameter is not set, this algorithm is global.
     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
-    #  @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
+    #  @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.GHS3DPRL, smesh.FULL_NETGEN
     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
     #  @return an instance of Mesh_Tetrahedron algorithm
     #  @ingroup l3_algos_basic
@@ -3092,7 +3123,7 @@ class Mesh_Segment(Mesh_Algorithm):
 # --------------------------
 
 ## Defines a segment 1D algorithm for discretization
-#  
+#
 #  @ingroup l3_algos_basic
 class Mesh_CompositeSegment(Mesh_Segment):
 
@@ -3185,11 +3216,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 +3235,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 +3351,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 +3438,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
 
 
@@ -3468,6 +3518,11 @@ class Mesh_Tetrahedron(Mesh_Algorithm):
             self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
             pass
 
+        elif algoType == GHS3DPRL:
+            import GHS3DPRLPlugin
+            self.Create(mesh, geom, "GHS3DPRL_3D" , "libGHS3DPRLEngine.so")
+            pass
+
         self.algoType = algoType
 
     ## Defines "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedron
@@ -3476,30 +3531,46 @@ 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"
+
+        if self.algoType == GHS3DPRL:
+            self.params = self.Hypothesis("GHS3DPRL_Parameters", [],
+                                          "libGHS3DPRLEngine.so", UseExisting=0)
+            return self.params
+
+        print "Algo supports no multi-parameter hypothesis"
         return None
 
     ## Sets MaxSize
@@ -3546,6 +3617,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):
@@ -3582,7 +3686,7 @@ class Mesh_Tetrahedron(Mesh_Algorithm):
     ## To keep working files or remove them. Log file remains in case of errors anyway.
     #  @ingroup l3_hypos_ghs3dh
     def SetKeepFiles(self, toKeep):
-        #  Advanced parameter of GHS3D
+        #  Advanced parameter of GHS3D and GHS3DPRL
         self.Parameters().SetKeepFiles(toKeep)
 
     ## To set verbose level [0-10]. <ul>
@@ -3611,12 +3715,24 @@ class Mesh_Tetrahedron(Mesh_Algorithm):
         #  Advanced parameter of GHS3D
         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
 
-    ## Sets command line option as text. 
+    ## Sets command line option as text.
     #  @ingroup l3_hypos_ghs3dh
     def SetTextOption(self, option):
         #  Advanced parameter of GHS3D
         self.Parameters().SetTextOption(option)
 
+    ## Sets MED files name and path.
+    def SetMEDName(self, value):
+        self.Parameters().SetMEDName(value)
+
+    ## Sets the number of partition of the initial mesh
+    def SetNbPart(self, value):
+        self.Parameters().SetNbPart(value)
+
+    ## When big mesh, start tepal in background
+    def SetBackground(self, value):
+        self.Parameters().SetBackground(value)
+
 # Public class: Mesh_Hexahedron
 # ------------------------------
 
@@ -3792,7 +3908,7 @@ class Mesh_Projection3D(Mesh_Algorithm):
         Mesh_Algorithm.__init__(self)
         self.Create(mesh, geom, "Projection_3D")
 
-    ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where 
+    ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
     #  the mesh pattern is taken, and, optionally, the  association of vertices
     #  between the source and the target solid  (to which a hipothesis is assigned)
     #  @param solid from where the mesh pattern is taken