Salome HOME
fix bug 12361. In SetName(): there may be no study
[modules/smesh.git] / src / SMESH_SWIG / smesh.py
index ec24cadfa1999533434d241ea8538fa1c6ee47bc..6b95891c7b07192fd00a02938010890048c4ab08 100644 (file)
@@ -60,8 +60,9 @@ def GetName(obj):
 def SetName(obj, name):
     ior  = salome.orb.object_to_string(obj)
     sobj = salome.myStudy.FindObjectIOR(ior)
-    attr = sobj.FindAttribute("AttributeName")[1]
-    attr.SetValue(name)
+    if not sobj is None:
+        attr = sobj.FindAttribute("AttributeName")[1]
+        attr.SetValue(name)
 
 # Algorithms and hypothesis
 # =========================
@@ -128,6 +129,8 @@ class Mesh_Algorithm:
         """
          Private method
         """
+        if geom is None:
+            raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
         self.mesh = mesh
         piece = mesh.geom
         if geom==0:
@@ -381,6 +384,37 @@ class Mesh_Hexahedron(Mesh_Algorithm):
         """
         self.Create(mesh, geom, "Hexa_3D")
 
+# Public class: Mesh_Netgen
+# ------------------------------
+
+class Mesh_Netgen(Mesh_Algorithm):
+    """
+    Class to define a NETGEN-based 2D or 3D algorithm
+    that need no discrete boundary (i.e. independent)
+    """
+
+    is3D = 0
+
+    def __init__(self, mesh, is3D, geom=0):
+        """
+         Private constructor
+        """
+        self.is3D = is3D
+        if is3D:
+            self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
+        else:
+            self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
+
+    def Parameters(self):
+        """
+         Define hypothesis containing parameters of the algorithm
+        """
+        if self.is3D:
+            hyp = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
+        else:
+            hyp = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
+        return hyp
+
 # Public class: Mesh
 # ==================
 
@@ -497,6 +531,17 @@ class Mesh:
         """
         return Mesh_Hexahedron(self, geom)
 
+    def Netgen(self, is3D, geom=0):
+        """
+         Creates a NETGEN-based 2D or 3D independent algorithm (i.e. needs no
+         discrete boundary).
+         If the optional \a geom parameter is not sets, this algorithm is global.
+         Otherwise, this algorithm defines a submesh based on \a geom subshape.
+         \param is3D If 0 then algorithm is 2D, otherwise 3D
+         \param geom If defined, subshape to be meshed
+        """
+        return Mesh_Netgen(self, is3D, geom)
+
     def Compute(self):
         """
         Compute the mesh and return the status of the computation
@@ -606,6 +651,9 @@ class Mesh:
         elif tgeo == "SHELL":
             type = SMESH.VOLUME
         elif tgeo == "COMPOUND":
+            if len( geompy.GetObjectIDs( grp )) == 0:
+                print "Mesh.Group: empty geometric group", GetName( grp )
+                return 0
             tgeo = geompy.GetType(grp)
             if tgeo == geompy.ShapeType["VERTEX"]:
                 type = SMESH.NODE