X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2FSMESH_SWIG%2FsmeshBuilder.py;h=d1e2f3bb23584320f531ab0386672fb146f5d52f;hb=refs%2Ftags%2FV9_0_0;hp=775faa89aa85275c92fae2d2c5f9670e8414c8be;hpb=e8173b4ff130ddb26d165c92403ef847fdfb8be2;p=modules%2Fsmesh.git
diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py
index 775faa89a..d1e2f3bb2 100644
--- a/src/SMESH_SWIG/smeshBuilder.py
+++ b/src/SMESH_SWIG/smeshBuilder.py
@@ -84,6 +84,10 @@ import salome
from salome.geom import geomBuilder
import SMESH # This is necessary for back compatibility
+import omniORB # back compatibility
+SMESH.MED_V2_1 = omniORB.EnumItem("MED_V2_1", 0) # back compatibility
+SMESH.MED_V2_2 = omniORB.EnumItem("MED_V2_2", 1) # back compatibility
+
from SMESH import *
from salome.smesh.smesh_algorithm import Mesh_Algorithm
@@ -92,6 +96,80 @@ import SALOMEDS
import os
import inspect
+# In case the omniORBpy EnumItem class does not fully support Python 3
+# (for instance in version 4.2.1-2), the comparison ordering methods must be
+# defined
+#
+try:
+ SMESH.Entity_Triangle < SMESH.Entity_Quadrangle
+except TypeError:
+ def enumitem_eq(self, other):
+ try:
+ if isinstance(other, omniORB.EnumItem):
+ if other._parent_id == self._parent_id:
+ return self._v == other._v
+ else:
+ return self._parent_id == other._parent_id
+ else:
+ return id(self) == id(other)
+ except:
+ return id(self) == id(other)
+
+ def enumitem_lt(self, other):
+ try:
+ if isinstance(other, omniORB.EnumItem):
+ if other._parent_id == self._parent_id:
+ return self._v < other._v
+ else:
+ return self._parent_id < other._parent_id
+ else:
+ return id(self) < id(other)
+ except:
+ return id(self) < id(other)
+
+ def enumitem_le(self, other):
+ try:
+ if isinstance(other, omniORB.EnumItem):
+ if other._parent_id == self._parent_id:
+ return self._v <= other._v
+ else:
+ return self._parent_id <= other._parent_id
+ else:
+ return id(self) <= id(other)
+ except:
+ return id(self) <= id(other)
+
+ def enumitem_gt(self, other):
+ try:
+ if isinstance(other, omniORB.EnumItem):
+ if other._parent_id == self._parent_id:
+ return self._v > other._v
+ else:
+ return self._parent_id > other._parent_id
+ else:
+ return id(self) > id(other)
+ except:
+ return id(self) > id(other)
+
+ def enumitem_ge(self, other):
+ try:
+ if isinstance(other, omniORB.EnumItem):
+ if other._parent_id == self._parent_id:
+ return self._v >= other._v
+ else:
+ return self._parent_id >= other._parent_id
+ else:
+ return id(self) >= id(other)
+ except:
+ return id(self) >= id(other)
+
+ omniORB.EnumItem.__eq__ = enumitem_eq
+ omniORB.EnumItem.__lt__ = enumitem_lt
+ omniORB.EnumItem.__le__ = enumitem_le
+ omniORB.EnumItem.__gt__ = enumitem_gt
+ omniORB.EnumItem.__ge__ = enumitem_ge
+
+
## Private class used to workaround a problem that sometimes isinstance(m, Mesh) returns False
#
class MeshMeta(type):
@@ -189,13 +267,8 @@ def GetName(obj):
except:
ior = None
if ior:
- # CORBA object
- studies = salome.myStudyManager.GetOpenStudies()
- for sname in studies:
- s = salome.myStudyManager.GetStudyByName(sname)
- if not s: continue
- sobj = s.FindObjectIOR(ior)
- if not sobj: continue
+ sobj = salome.myStudy.FindObjectIOR(ior)
+ if sobj:
return sobj.GetName()
if hasattr(obj, "GetName"):
# unknown CORBA object, having GetName() method
@@ -219,21 +292,21 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
pass
reason = ""
if hasattr( status, "__getitem__" ):
- status,reason = status[0],status[1]
- if status == HYP_UNKNOWN_FATAL :
+ status, reason = status[0], status[1]
+ if status == HYP_UNKNOWN_FATAL:
reason = "for unknown reason"
- elif status == HYP_INCOMPATIBLE :
+ elif status == HYP_INCOMPATIBLE:
reason = "this hypothesis mismatches the algorithm"
- elif status == HYP_NOTCONFORM :
+ elif status == HYP_NOTCONFORM:
reason = "a non-conform mesh would be built"
- elif status == HYP_ALREADY_EXIST :
+ elif status == HYP_ALREADY_EXIST:
if isAlgo: return # it does not influence anything
reason = hypType + " of the same dimension is already assigned to this shape"
- elif status == HYP_BAD_DIM :
+ elif status == HYP_BAD_DIM:
reason = hypType + " mismatches the shape"
- elif status == HYP_CONCURENT :
+ elif status == HYP_CONCURENT:
reason = "there are concurrent hypotheses on sub-shapes"
- elif status == HYP_BAD_SUBSHAPE :
+ elif status == HYP_BAD_SUBSHAPE:
reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
elif status == HYP_BAD_GEOMETRY:
reason = "the algorithm is not applicable to this geometry"
@@ -266,12 +339,7 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
def AssureGeomPublished(mesh, geom, name=''):
if not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
return
- if not geom.GetStudyEntry() and \
- mesh.smeshpyD.GetCurrentStudy():
- ## set the study
- studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
- if studyID != mesh.geompyD.myStudyId:
- mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
+ if not geom.GetStudyEntry():
## get a name
if not name and geom.GetShapeType() != geomBuilder.GEOM.COMPOUND:
# for all groups SubShapeName() return "Compound_-1"
@@ -301,6 +369,10 @@ def FirstVertexOnCurve(mesh, edge):
else:
return vv[1]
+## Return a long value from enumeration
+def EnumToLong(theItem):
+ return theItem._v
+
# end of l1_auxiliary
## @}
@@ -380,8 +452,8 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
## Dump component to the Python script
# This method overrides IDL function to allow default values for the parameters.
# @ingroup l1_auxiliary
- def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
- return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
+ def DumpPython(self, theIsPublished=True, theIsMultiFile=True):
+ return SMESH._objref_SMESH_Gen.DumpPython(self, theIsPublished, theIsMultiFile)
## Set mode of DumpPython(), \a historical or \a snapshot.
# In the \a historical mode, the Python Dump script includes all commands
@@ -394,14 +466,14 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
else: val = "false"
SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
- ## Set the current study and Geometry component
+ ## Set Geometry component
# @ingroup l1_auxiliary
- def init_smesh(self,theStudy,geompyD = None):
+ def init_smesh(self,isPublished = True,geompyD = None):
#print "init_smesh"
- self.SetCurrentStudy(theStudy,geompyD)
- if theStudy:
+ self.UpdateStudy(geompyD)
+ if isPublished:
global notebook
- notebook.myStudy = theStudy
+ notebook.myStudy = salome.myStudy
## Create a mesh. This can be either an empty mesh, possibly having an underlying geometry,
# or a mesh wrapping a CORBA mesh given as a parameter.
@@ -417,11 +489,6 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
obj,name = name,obj
return Mesh(self,self.geompyD,obj,name)
- ## Return a long value from enumeration
- # @ingroup l1_auxiliary
- def EnumToLong(self,theItem):
- return theItem._v
-
## Return a string representation of the color.
# To be used with filters.
# @param c color value (SALOMEDS.Color)
@@ -523,34 +590,32 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
# @ingroup l1_auxiliary
def IsEmbeddedMode(self):
return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
-
- ## Set the current study. Calling SetCurrentStudy( None ) allows to
- # switch OFF automatic pubilishing in the Study of mesh objects.
+
+ ## Update the current study. Calling UpdateStudy() allows to
+ # update meshes at switching GEOM->SMESH
# @ingroup l1_auxiliary
- def SetCurrentStudy( self, theStudy, geompyD = None ):
+ def UpdateStudy( self, geompyD = None ):
+ #self.UpdateStudy()
if not geompyD:
from salome.geom import geomBuilder
geompyD = geomBuilder.geom
pass
self.geompyD=geompyD
self.SetGeomEngine(geompyD)
- SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
- global notebook
- if theStudy:
- notebook = salome_notebook.NoteBook( theStudy )
- else:
- notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
- if theStudy:
- sb = theStudy.NewBuilder()
- sc = theStudy.FindComponent("SMESH")
- if sc: sb.LoadWith(sc, self)
- pass
+ SMESH._objref_SMESH_Gen.UpdateStudy(self)
+ sb = salome.myStudy.NewBuilder()
+ sc = salome.myStudy.FindComponent("SMESH")
+ if sc: sb.LoadWith(sc, self)
pass
-
- ## Get the current study
+
+ ## Sets enable publishing in the study. Calling SetEnablePublish( false ) allows to
+ # switch OFF publishing in the Study of mesh objects.
# @ingroup l1_auxiliary
- def GetCurrentStudy(self):
- return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
+ def SetEnablePublish( self, theIsEnablePublish ):
+ #self.SetEnablePublish(theIsEnablePublish)
+ SMESH._objref_SMESH_Gen.SetEnablePublish(self,theIsEnablePublish)
+ global notebook
+ notebook = salome_notebook.NoteBook( theIsEnablePublish )
## Create a Mesh object importing data from the given UNV file
# @return an instance of Mesh class
@@ -675,13 +740,13 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
# @return SMESH.Filter.Criterion
# @ingroup l1_controls
def GetEmptyCriterion(self):
- Type = self.EnumToLong(FT_Undefined)
- Compare = self.EnumToLong(FT_Undefined)
+ Type = EnumToLong(FT_Undefined)
+ Compare = EnumToLong(FT_Undefined)
Threshold = 0
ThresholdStr = ""
ThresholdID = ""
- UnaryOp = self.EnumToLong(FT_Undefined)
- BinaryOp = self.EnumToLong(FT_Undefined)
+ UnaryOp = EnumToLong(FT_Undefined)
+ BinaryOp = EnumToLong(FT_Undefined)
Tolerance = 1e-07
TypeOfElement = ALL
Precision = -1 ##@1e-07
@@ -716,21 +781,21 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
raise TypeError("CritType should be of SMESH.FunctorType")
aCriterion = self.GetEmptyCriterion()
aCriterion.TypeOfElement = elementType
- aCriterion.Type = self.EnumToLong(CritType)
+ aCriterion.Type = EnumToLong(CritType)
aCriterion.Tolerance = Tolerance
aThreshold = Threshold
if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
- aCriterion.Compare = self.EnumToLong(Compare)
+ aCriterion.Compare = EnumToLong(Compare)
elif Compare == "=" or Compare == "==":
- aCriterion.Compare = self.EnumToLong(FT_EqualTo)
+ aCriterion.Compare = EnumToLong(FT_EqualTo)
elif Compare == "<":
- aCriterion.Compare = self.EnumToLong(FT_LessThan)
+ aCriterion.Compare = EnumToLong(FT_LessThan)
elif Compare == ">":
- aCriterion.Compare = self.EnumToLong(FT_MoreThan)
+ aCriterion.Compare = EnumToLong(FT_MoreThan)
elif Compare != FT_Undefined:
- aCriterion.Compare = self.EnumToLong(FT_EqualTo)
+ aCriterion.Compare = EnumToLong(FT_EqualTo)
aThreshold = Compare
if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
@@ -760,7 +825,7 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
raise ValueError("Group type mismatches Element type")
aCriterion.ThresholdStr = aThreshold.GetName()
aCriterion.ThresholdID = salome.orb.object_to_string( aThreshold )
- study = self.GetCurrentStudy()
+ study = salome.myStudy
if study:
so = study.FindObjectIOR( aCriterion.ThresholdID )
if so:
@@ -812,7 +877,7 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
elif CritType == FT_ElemGeomType:
# Check the Threshold
try:
- aCriterion.Threshold = self.EnumToLong(aThreshold)
+ aCriterion.Threshold = EnumToLong(aThreshold)
assert( aThreshold in SMESH.GeometryType._items )
except:
if isinstance(aThreshold, int):
@@ -824,7 +889,7 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
elif CritType == FT_EntityType:
# Check the Threshold
try:
- aCriterion.Threshold = self.EnumToLong(aThreshold)
+ aCriterion.Threshold = EnumToLong(aThreshold)
assert( aThreshold in SMESH.EntityType._items )
except:
if isinstance(aThreshold, int):
@@ -848,7 +913,7 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
# At this point the Threshold is unnecessary
if aThreshold == FT_LogicalNOT:
- aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
+ aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
aCriterion.BinaryOp = aThreshold
else:
@@ -861,16 +926,16 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
return None
if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
- aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
+ aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
if Threshold in [FT_LogicalAND, FT_LogicalOR]:
- aCriterion.BinaryOp = self.EnumToLong(Threshold)
+ aCriterion.BinaryOp = EnumToLong(Threshold)
if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
- aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
+ aCriterion.BinaryOp = EnumToLong(UnaryOp)
if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
- aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
+ aCriterion.BinaryOp = EnumToLong(BinaryOp)
return aCriterion
@@ -917,8 +982,8 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
# @ingroup l1_controls
def GetFilterFromCriteria(self,criteria, binOp=SMESH.FT_LogicalAND):
for i in range( len( criteria ) - 1 ):
- if criteria[i].BinaryOp == self.EnumToLong( SMESH.FT_Undefined ):
- criteria[i].BinaryOp = self.EnumToLong( binOp )
+ if criteria[i].BinaryOp == EnumToLong( SMESH.FT_Undefined ):
+ criteria[i].BinaryOp = EnumToLong( binOp )
aFilterMgr = self.CreateFilterManager()
aFilter = aFilterMgr.CreateFilter()
aFilter.SetCriteria(criteria)
@@ -964,6 +1029,8 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
functor = aFilterMgr.CreateLength()
elif theCriterion == FT_Length2D:
functor = aFilterMgr.CreateLength2D()
+ elif theCriterion == FT_Deflection2D:
+ functor = aFilterMgr.CreateDeflection2D()
elif theCriterion == FT_NodeConnectivityNumber:
functor = aFilterMgr.CreateNodeConnectivityNumber()
elif theCriterion == FT_BallDiameter:
@@ -1003,7 +1070,7 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
d = {}
if hasattr(obj, "GetMeshInfo"):
values = obj.GetMeshInfo()
- for i in range(SMESH.Entity_Last._v):
+ for i in range(EnumToLong(SMESH.Entity_Last)):
if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
pass
return d
@@ -1151,6 +1218,18 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
aMeasurements.UnRegister()
return value
+ ## Get gravity center of all nodes of the mesh object.
+ # @param obj mesh, submesh or group
+ # @return three components of the gravity center: x,y,z
+ # @ingroup l1_measurements
+ def GetGravityCenter(self, obj):
+ if isinstance(obj, Mesh): obj = obj.mesh
+ if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
+ aMeasurements = self.CreateMeasurements()
+ pointStruct = aMeasurements.GravityCenter(obj)
+ aMeasurements.UnRegister()
+ return pointStruct.x, pointStruct.y, pointStruct.z
+
pass # end of class smeshBuilder
import omniORB
@@ -1165,13 +1244,13 @@ omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
# import salome
# salome.salome_init()
# from salome.smesh import smeshBuilder
-# smesh = smeshBuilder.New(salome.myStudy)
+# smesh = smeshBuilder.New()
# \endcode
-# @param study SALOME study, generally obtained by salome.myStudy.
+# @param isPublished If False, the notebool will not be used.
# @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
# @return smeshBuilder instance
-def New( study, instance=None):
+def New( isPublished = True, instance=None):
"""
Create a new smeshBuilder instance.The smeshBuilder class provides the Python
interface to create or load meshes.
@@ -1180,10 +1259,10 @@ def New( study, instance=None):
import salome
salome.salome_init()
from salome.smesh import smeshBuilder
- smesh = smeshBuilder.New(salome.myStudy)
+ smesh = smeshBuilder.New()
Parameters:
- study SALOME study, generally obtained by salome.myStudy.
+ isPublished If False, the notebool will not be used.
instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
Returns:
smeshBuilder instance
@@ -1196,7 +1275,7 @@ def New( study, instance=None):
doLcc = True
smeshInst = smeshBuilder()
assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
- smeshInst.init_smesh(study)
+ smeshInst.init_smesh(isPublished)
return smeshInst
@@ -1233,12 +1312,9 @@ class Mesh(metaclass=MeshMeta):
self.geom = obj
objHasName = True
# publish geom of mesh (issue 0021122)
- if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
+ if not self.geom.GetStudyEntry():
objHasName = False
- studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
- if studyID != geompyD.myStudyId:
- geompyD.init_geom( smeshpyD.GetCurrentStudy())
- pass
+ geompyD.init_geom()
if name:
geo_name = name + " shape"
else:
@@ -1259,7 +1335,7 @@ class Mesh(metaclass=MeshMeta):
self.geom = self.mesh.GetShapeToMesh()
self.editor = self.mesh.GetMeshEditor()
- self.functors = [None] * SMESH.FT_Undefined._v
+ self.functors = [None] * EnumToLong(SMESH.FT_Undefined)
# set self to algoCreator's
for attrName in dir(self):
@@ -1515,12 +1591,12 @@ class Mesh(metaclass=MeshMeta):
print(msg)
print(allReasons)
pass
- if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
+ if salome.sg.hasDesktop():
if not isinstance( refresh, list): # not a call from subMesh.Compute()
smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(self.mesh.GetStudyId())
+ smeshgui.Init()
smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
- if refresh: salome.sg.updateObjBrowser(True)
+ if refresh: salome.sg.updateObjBrowser()
return ok
@@ -1545,11 +1621,9 @@ class Mesh(metaclass=MeshMeta):
try:
shapeText = ""
mainIOR = salome.orb.object_to_string( self.GetShape() )
- for sname in salome.myStudyManager.GetOpenStudies():
- s = salome.myStudyManager.GetStudyByName(sname)
- if not s: continue
- mainSO = s.FindObjectIOR(mainIOR)
- if not mainSO: continue
+ s = salome.myStudy
+ mainSO = s.FindObjectIOR(mainIOR)
+ if mainSO:
if subShapeID == 1:
shapeText = '"%s"' % mainSO.GetName()
subIt = s.NewChildIterator(mainSO)
@@ -1566,7 +1640,6 @@ class Mesh(metaclass=MeshMeta):
continue
if ids == subShapeID:
shapeText = '"%s"' % subSO.GetName()
- break
if not shapeText:
shape = self.geompyD.GetSubShape( self.GetShape(), [subShapeID])
if shape:
@@ -1598,7 +1671,7 @@ class Mesh(metaclass=MeshMeta):
groups = []
for algoName, shapes in list(algo2shapes.items()):
while shapes:
- groupType = self.smeshpyD.EnumToLong( shapes[0].GetShapeType() )
+ groupType = EnumToLong( shapes[0].GetShapeType() )
otherTypeShapes = []
sameTypeShapes = []
group = self.geompyD.CreateGroup( self.geom, groupType )
@@ -1637,12 +1710,11 @@ class Mesh(metaclass=MeshMeta):
# @ingroup l2_construct
def Clear(self, refresh=False):
self.mesh.Clear()
- if ( salome.sg.hasDesktop() and
- salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() ) ):
+ if ( salome.sg.hasDesktop() ):
smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(self.mesh.GetStudyId())
+ smeshgui.Init()
smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
- if refresh: salome.sg.updateObjBrowser(True)
+ if refresh: salome.sg.updateObjBrowser()
## Remove all nodes and elements of indicated shape
# @param refresh if @c True, Object browser is automatically updated (when running in GUI)
@@ -1652,9 +1724,9 @@ class Mesh(metaclass=MeshMeta):
self.mesh.ClearSubMesh(geomId)
if salome.sg.hasDesktop():
smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(self.mesh.GetStudyId())
+ smeshgui.Init()
smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
- if refresh: salome.sg.updateObjBrowser(True)
+ if refresh: salome.sg.updateObjBrowser()
## Compute a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron
# @param fineness [0.0,1.0] defines mesh fineness
@@ -1719,7 +1791,7 @@ class Mesh(metaclass=MeshMeta):
AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
status = self.mesh.AddHypothesis(geom, hyp)
else:
- status = HYP_BAD_GEOMETRY,""
+ status = HYP_BAD_GEOMETRY, ""
hyp_name = GetName( hyp )
geom_name = ""
if geom:
@@ -1785,13 +1857,10 @@ class Mesh(metaclass=MeshMeta):
## Export the mesh in a file in MED format
## allowing to overwrite the file if it exists or add the exported data to its contents
- # @param f is the file name
+ # @param fileName is the file name
# @param auto_groups boolean parameter for creating/not creating
# the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
# the typical use is auto_groups=False.
- # @param version MED format version (MED_V2_1 or MED_V2_2,
- # the latter meaning any current version). The parameter is
- # obsolete since MED_V2_1 is no longer supported.
# @param overwrite boolean parameter for overwriting/not overwriting the file
# @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
# @param autoDimension if @c True (default), a space dimension of a MED mesh can be either
@@ -1807,17 +1876,33 @@ class Mesh(metaclass=MeshMeta):
# - 'f' stands for "_faces _" field;
# - 's' stands for "_solids _" field.
# @ingroup l2_impexp
- def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
- overwrite=1, meshPart=None, autoDimension=True, fields=[], geomAssocFields=''):
+ def ExportMED(self, *args, **kwargs):
+ # process positional arguments
+ args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
+ fileName = args[0]
+ auto_groups = args[1] if len(args) > 1 else False
+ overwrite = args[2] if len(args) > 2 else True
+ meshPart = args[3] if len(args) > 3 else None
+ autoDimension = args[4] if len(args) > 4 else True
+ fields = args[5] if len(args) > 5 else []
+ geomAssocFields = args[6] if len(args) > 6 else ''
+ # process keywords arguments
+ auto_groups = kwargs.get("auto_groups", auto_groups)
+ overwrite = kwargs.get("overwrite", overwrite)
+ meshPart = kwargs.get("meshPart", meshPart)
+ autoDimension = kwargs.get("autoDimension", autoDimension)
+ fields = kwargs.get("fields", fields)
+ geomAssocFields = kwargs.get("geomAssocFields", geomAssocFields)
+ # invoke engine's function
if meshPart or fields or geomAssocFields:
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
unRegister.set( meshPart )
- self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension,
+ self.mesh.ExportPartToMED( meshPart, fileName, auto_groups, overwrite, autoDimension,
fields, geomAssocFields)
else:
- self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
+ self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension)
## Export the mesh in a file in SAUV format
# @param f is the file name
@@ -1875,8 +1960,11 @@ class Mesh(metaclass=MeshMeta):
# @param f is the file name
# @param overwrite boolean parameter for overwriting/not overwriting the file
# @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
+ # @param groupElemsByType if true all elements of same entity type are exported at ones,
+ # else elements are exported in order of their IDs which can cause creation
+ # of multiple cgns sections
# @ingroup l2_impexp
- def ExportCGNS(self, f, overwrite=1, meshPart=None):
+ def ExportCGNS(self, f, overwrite=1, meshPart=None, groupElemsByType=False):
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
@@ -1885,7 +1973,7 @@ class Mesh(metaclass=MeshMeta):
meshPart = meshPart.mesh
elif not meshPart:
meshPart = self.mesh
- self.mesh.ExportCGNS(meshPart, f, overwrite)
+ self.mesh.ExportCGNS(meshPart, f, overwrite, groupElemsByType)
## Export the mesh in a file in GMF format.
# GMF files must have .mesh extension for the ASCII format and .meshb for
@@ -1907,10 +1995,7 @@ class Mesh(metaclass=MeshMeta):
## Deprecated, used only for compatibility! Please, use ExportMED() method instead.
# Export the mesh in a file in MED format
# allowing to overwrite the file if it exists or add the exported data to its contents
- # @param f the file name
- # @param version MED format version (MED_V2_1 or MED_V2_2,
- # the latter meaning any current version). The parameter is
- # obsolete since MED_V2_1 is no longer supported.
+ # @param fileName the file name
# @param opt boolean parameter for creating/not creating
# the groups Group_On_All_Nodes, Group_On_All_Faces, ...
# @param overwrite boolean parameter for overwriting/not overwriting the file
@@ -1920,8 +2005,49 @@ class Mesh(metaclass=MeshMeta):
# - 3D in the rest cases.
# If @a autoDimension is @c False, the space dimension is always 3.
# @ingroup l2_impexp
- def ExportToMED(self, f, version=MED_V2_2, opt=0, overwrite=1, autoDimension=True):
- self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension)
+ def ExportToMED(self, *args, **kwargs):
+ print("WARNING: ExportToMED() is deprecated, use ExportMED() instead")
+ # process positional arguments
+ args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
+ fileName = args[0]
+ auto_groups = args[1] if len(args) > 1 else False
+ overwrite = args[2] if len(args) > 2 else True
+ autoDimension = args[3] if len(args) > 3 else True
+ # process keywords arguments
+ auto_groups = kwargs.get("opt", auto_groups) # old keyword name
+ auto_groups = kwargs.get("auto_groups", auto_groups) # new keyword name
+ overwrite = kwargs.get("overwrite", overwrite)
+ autoDimension = kwargs.get("autoDimension", autoDimension)
+ # invoke engine's function
+ self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension)
+
+ ## Deprecated, used only for compatibility! Please, use ExportMED() method instead.
+ # Export the mesh in a file in MED format
+ # allowing to overwrite the file if it exists or add the exported data to its contents
+ # @param fileName the file name
+ # @param opt boolean parameter for creating/not creating
+ # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
+ # @param overwrite boolean parameter for overwriting/not overwriting the file
+ # @param autoDimension if @c True (default), a space dimension of a MED mesh can be either
+ # - 1D if all mesh nodes lie on OX coordinate axis, or
+ # - 2D if all mesh nodes lie on XOY coordinate plane, or
+ # - 3D in the rest cases.
+ # If @a autoDimension is @c False, the space dimension is always 3.
+ # @ingroup l2_impexp
+ def ExportToMEDX(self, *args, **kwargs):
+ print("WARNING: ExportToMEDX() is deprecated, use ExportMED() instead")
+ # process positional arguments
+ args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility
+ fileName = args[0]
+ auto_groups = args[1] if len(args) > 1 else False
+ overwrite = args[2] if len(args) > 2 else True
+ autoDimension = args[3] if len(args) > 3 else True
+ # process keywords arguments
+ auto_groups = kwargs.get("auto_groups", auto_groups)
+ overwrite = kwargs.get("overwrite", overwrite)
+ autoDimension = kwargs.get("autoDimension", autoDimension)
+ # invoke engine's function
+ self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension)
# Operations with groups:
# ----------------------
@@ -2005,6 +2131,8 @@ class Mesh(metaclass=MeshMeta):
# @ingroup l2_grps_create
def MakeGroupByIds(self, groupName, elementType, elemIDs):
group = self.mesh.CreateGroup(elementType, groupName)
+ if isinstance( elemIDs, Mesh ):
+ elemIDs = elemIDs.GetMesh()
if hasattr( elemIDs, "GetIDs" ):
if hasattr( elemIDs, "SetMesh" ):
elemIDs.SetMesh( self.GetMesh() )
@@ -2254,12 +2382,6 @@ class Mesh(metaclass=MeshMeta):
def GetId(self):
return self.mesh.GetId()
- ## Get the study Id
- # @return integer value, which is the study Id of the mesh
- # @ingroup l1_auxiliary
- def GetStudyId(self):
- return self.mesh.GetStudyId()
-
## Check the group names for duplications.
# Consider the maximum group name length stored in MED file.
# @return True or False
@@ -2291,10 +2413,10 @@ class Mesh(metaclass=MeshMeta):
return self.editor.MakeIDSource(ids, elemType)
- # Get informations about mesh contents:
+ # Get information about mesh contents:
# ------------------------------------
- ## Get the mesh stattistic
+ ## Get the mesh statistic
# @return dictionary type element - count of elements
# @ingroup l1_meshinfo
def GetMeshInfo(self, obj = None):
@@ -2682,9 +2804,14 @@ class Mesh(metaclass=MeshMeta):
## Return an element based on all given nodes.
# @ingroup l1_meshinfo
- def FindElementByNodes(self,nodes):
+ def FindElementByNodes(self, nodes):
return self.mesh.FindElementByNodes(nodes)
+ ## Return elements including all given nodes.
+ # @ingroup l1_meshinfo
+ def GetElementsByNodes(self, nodes, elemType=SMESH.ALL):
+ return self.mesh.GetElementsByNodes( nodes, elemType )
+
## Return true if the given element is a polygon
# @ingroup l1_meshinfo
def IsPoly(self, id):
@@ -3102,6 +3229,16 @@ class Mesh(metaclass=MeshMeta):
def GetPointState(self, x, y, z):
return self.editor.GetPointState(x, y, z)
+ ## Check if a 2D mesh is manifold
+ # @ingroup l1_controls
+ def IsManifold(self):
+ return self.editor.IsManifold()
+
+ ## Check if orientation of 2D elements is coherent
+ # @ingroup l1_controls
+ def IsCoherentOrientation2D(self):
+ return self.editor.IsCoherentOrientation2D()
+
## Find the node closest to a point and moves it to a point location
# @param x the X coordinate of a point
# @param y the Y coordinate of a point
@@ -3222,7 +3359,7 @@ class Mesh(metaclass=MeshMeta):
# Type SMESH.FunctorType._items in the Python Console to see all items.
# Note that not all items correspond to numerical functors.
# @param MaxAngle is the maximum angle between element normals at which the fusion
- # is still performed; theMaxAngle is mesured in radians.
+ # is still performed; theMaxAngle is measured in radians.
# Also it could be a name of variable which defines angle in degrees.
# @return TRUE in case of success, FALSE otherwise.
# @ingroup l2_modif_unitetri
@@ -3241,7 +3378,7 @@ class Mesh(metaclass=MeshMeta):
# Type SMESH.FunctorType._items in the Python Console to see all items.
# Note that not all items correspond to numerical functors.
# @param MaxAngle a max angle between element normals at which the fusion
- # is still performed; theMaxAngle is mesured in radians.
+ # is still performed; theMaxAngle is measured in radians.
# @return TRUE in case of success, FALSE otherwise.
# @ingroup l2_modif_unitetri
def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
@@ -3253,7 +3390,7 @@ class Mesh(metaclass=MeshMeta):
return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
## Split quadrangles into triangles.
- # @param IDsOfElements the faces to be splitted.
+ # @param IDsOfElements the faces to be split.
# @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
# choose a diagonal for splitting. If @a theCriterion is None, which is a default
# value, then quadrangles will be split by the smallest diagonal.
@@ -3289,7 +3426,7 @@ class Mesh(metaclass=MeshMeta):
## Split each of given quadrangles into 4 triangles. A node is added at the center of
# a quadrangle.
- # @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
+ # @param theElements the faces to be split. This can be either mesh, sub-mesh,
# group or a list of face IDs. By default all quadrangles are split
# @ingroup l2_modif_cutquadr
def QuadTo4Tri (self, theElements=[]):
@@ -3304,7 +3441,7 @@ class Mesh(metaclass=MeshMeta):
return self.editor.QuadTo4Tri( theElements )
## Split quadrangles into triangles.
- # @param IDsOfElements the faces to be splitted
+ # @param IDsOfElements the faces to be split
# @param Diag13 is used to choose a diagonal for splitting.
# @return TRUE in case of success, FALSE otherwise.
# @ingroup l2_modif_cutquadr
@@ -3325,7 +3462,7 @@ class Mesh(metaclass=MeshMeta):
return self.editor.SplitQuadObject(theObject, Diag13)
## Find a better splitting of the given quadrangle.
- # @param IDOfQuad the ID of the quadrangle to be splitted.
+ # @param IDOfQuad the ID of the quadrangle to be split.
# @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
# choose a diagonal for splitting.
# Type SMESH.FunctorType._items in the Python Console to see all items.
@@ -3877,6 +4014,7 @@ class Mesh(metaclass=MeshMeta):
# - a GEOM point
# @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion example
def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False,
scaleFactors=[], linearVariation=False, basePoint=[] ):
unRegister = genObjUnRegister()
@@ -3917,6 +4055,7 @@ class Mesh(metaclass=MeshMeta):
# @param IsNodes is True if elements with given ids are nodes
# @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion example
def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
n,e,f = [],[],[]
if IsNodes: n = IDsOfElements
@@ -3943,6 +4082,7 @@ class Mesh(metaclass=MeshMeta):
# @return the list of created groups (SMESH_GroupBase) if \a MakeGroups=True,
# empty list otherwise.
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion example
def ExtrusionByNormal(self, Elements, StepSize, NbOfSteps,
ByAverageNormal=False, UseInputElemsOnly=True, MakeGroups=False, Dim = 2):
unRegister = genObjUnRegister()
@@ -3972,6 +4112,7 @@ class Mesh(metaclass=MeshMeta):
# @param IsNodes is True if elements to extrude are nodes
# @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion example
def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
n,e,f = [],[],[]
if IsNodes: n = theObject
@@ -3988,6 +4129,7 @@ class Mesh(metaclass=MeshMeta):
# @param MakeGroups to generate new groups from existing ones
# @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion example
def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
return self.ExtrusionSweepObjects([],theObject,[], StepVector, NbOfSteps, MakeGroups)
@@ -4001,6 +4143,7 @@ class Mesh(metaclass=MeshMeta):
# @param MakeGroups forces the generation of new groups from existing ones
# @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion example
def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
return self.ExtrusionSweepObjects([],[],theObject, StepVector, NbOfSteps, MakeGroups)
@@ -4045,6 +4188,7 @@ class Mesh(metaclass=MeshMeta):
# @param MakeGroups forces the generation of new groups from existing ones
# @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion_along_path example
def ExtrusionAlongPathObjects(self, Nodes, Edges, Faces, PathMesh, PathShape=None,
NodeStart=1, HasAngles=False, Angles=[], LinearVariation=False,
HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False):
@@ -4088,6 +4232,7 @@ class Mesh(metaclass=MeshMeta):
# @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
# only SMESH::Extrusion_Error otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion_along_path example
def ExtrusionAlongPathX(self, Base, Path, NodeStart,
HasAngles=False, Angles=[], LinearVariation=False,
HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False,
@@ -4120,6 +4265,7 @@ class Mesh(metaclass=MeshMeta):
# @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
# only SMESH::Extrusion_Error otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion_along_path example
def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
MakeGroups=False, LinearVariation=False):
@@ -4150,6 +4296,7 @@ class Mesh(metaclass=MeshMeta):
# @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
# only SMESH::Extrusion_Error otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion_along_path example
def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
MakeGroups=False, LinearVariation=False):
@@ -4179,6 +4326,7 @@ class Mesh(metaclass=MeshMeta):
# @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
# only SMESH::Extrusion_Error otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion_along_path example
def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
MakeGroups=False, LinearVariation=False):
@@ -4208,6 +4356,7 @@ class Mesh(metaclass=MeshMeta):
# @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
# only SMESH::Extrusion_Error otherwise
# @ingroup l2_modif_extrurev
+ # @ref tui_extrusion_along_path example
def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
MakeGroups=False, LinearVariation=False):
@@ -4592,6 +4741,24 @@ class Mesh(metaclass=MeshMeta):
def MergeEqualElements(self):
self.editor.MergeEqualElements()
+ ## Returns all or only closed free borders
+ # @return list of SMESH.FreeBorder's
+ # @ingroup l2_modif_trsf
+ def FindFreeBorders(self, ClosedOnly=True):
+ return self.editor.FindFreeBorders( ClosedOnly )
+
+ ## Fill with 2D elements a hole defined by a SMESH.FreeBorder.
+ # @param FreeBorder either a SMESH.FreeBorder or a list on node IDs. These nodes
+ # must describe all sequential nodes of the hole border. The first and the last
+ # nodes must be the same. Use FindFreeBorders() to get nodes of holes.
+ # @ingroup l2_modif_trsf
+ def FillHole(self, holeNodes):
+ if holeNodes and isinstance( holeNodes, list ) and isinstance( holeNodes[0], int ):
+ holeNodes = SMESH.FreeBorder(nodeIDs=holeNodes)
+ if not isinstance( holeNodes, SMESH.FreeBorder ):
+ raise TypeError("holeNodes must be either SMESH.FreeBorder or list of integer and not %s" % holeNodes)
+ self.editor.FillHole( holeNodes )
+
## Return groups of FreeBorder's coincident within the given tolerance.
# @param tolerance the tolerance. If the tolerance <= 0.0 then one tenth of an average
# size of elements adjacent to free borders being compared is used.
@@ -4867,12 +5034,12 @@ class Mesh(metaclass=MeshMeta):
## Identify the elements that will be affected by node duplication (actual duplication is not performed.
# This method is the first step of DoubleNodeElemGroupsInRegion.
- # @param theElems - list of groups of elements (edges or faces) to be replicated
+ # @param theElems - list of groups of nodes or elements (edges or faces) to be replicated
# @param theNodesNot - list of groups of nodes not to replicated
# @param theShape - shape to detect affected elements (element which geometric center
# located on or inside shape).
# The replicated nodes should be associated to affected elements.
- # @return groups of affected elements
+ # @return groups of affected elements in order: volumes, faces, edges
# @ingroup l2_modif_duplicat
def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
@@ -4907,12 +5074,45 @@ class Mesh(metaclass=MeshMeta):
def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
- def _getFunctor(self, funcType ):
+ ## Create a polyline consisting of 1D mesh elements each lying on a 2D element of
+ # the initial mesh. Positions of new nodes are found by cutting the mesh by the
+ # plane passing through pairs of points specified by each PolySegment structure.
+ # If there are several paths connecting a pair of points, the shortest path is
+ # selected by the module. Position of the cutting plane is defined by the two
+ # points and an optional vector lying on the plane specified by a PolySegment.
+ # By default the vector is defined by Mesh module as following. A middle point
+ # of the two given points is computed. The middle point is projected to the mesh.
+ # The vector goes from the middle point to the projection point. In case of planar
+ # mesh, the vector is normal to the mesh.
+ # @param segments - PolySegment's defining positions of cutting planes.
+ # Return the used vector which goes from the middle point to its projection.
+ # @param groupName - optional name of a group where created mesh segments will
+ # be added.
+ # @ingroup l2_modif_duplicat
+ def MakePolyLine(self, segments, groupName='', isPreview=False ):
+ editor = self.editor
+ if isPreview:
+ editor = self.mesh.GetMeshEditPreviewer()
+ segmentsRes = editor.MakePolyLine( segments, groupName )
+ for i, seg in enumerate( segmentsRes ):
+ segments[i].vector = seg.vector
+ if isPreview:
+ return editor.GetPreviewData()
+ return None
+
+ ## Return a cached numerical functor by its type.
+ # @param theCriterion functor type - an item of SMESH.FunctorType enumeration.
+ # Type SMESH.FunctorType._items in the Python Console to see all items.
+ # Note that not all items correspond to numerical functors.
+ # @return SMESH_NumericalFunctor. The functor is already initialized
+ # with a mesh
+ # @ingroup l1_measurements
+ def GetFunctor(self, funcType ):
fn = self.functors[ funcType._v ]
if not fn:
fn = self.smeshpyD.GetFunctor(funcType)
fn.SetMesh(self.mesh)
- self.functors[ funcType._v ] = fn
+ self.functors[ EnumToLong(funcType) ] = fn
return fn
## Return value of a functor for a given element
@@ -4923,7 +5123,7 @@ class Mesh(metaclass=MeshMeta):
# @return the functor value or zero in case of invalid arguments
# @ingroup l1_measurements
def FunctorValue(self, funcType, elemId, isElem=True):
- fn = self._getFunctor( funcType )
+ fn = self.GetFunctor( funcType )
if fn.GetElementType() == self.GetElementType(elemId, isElem):
val = fn.GetValue(elemId)
else:
@@ -5029,7 +5229,7 @@ class Mesh(metaclass=MeshMeta):
unRegister.set( meshPart )
if isinstance( meshPart, Mesh ):
meshPart = meshPart.mesh
- fun = self._getFunctor( funType )
+ fun = self.GetFunctor( funType )
if fun:
if meshPart:
if hasattr( meshPart, "SetMesh" ):
@@ -5051,12 +5251,30 @@ class meshProxy(SMESH._objref_SMESH_Mesh):
def __init__(self, *args):
SMESH._objref_SMESH_Mesh.__init__(self, *args)
def __deepcopy__(self, memo=None):
- new = self.__class__()
+ new = self.__class__(self)
return new
def CreateDimGroup(self,*args): # 2 args added: nbCommonNodes, underlyingOnly
if len( args ) == 3:
args += SMESH.ALL_NODES, True
- return SMESH._objref_SMESH_Mesh.CreateDimGroup( self, *args )
+ return SMESH._objref_SMESH_Mesh.CreateDimGroup(self, *args)
+ def ExportToMEDX(self, *args): # function removed
+ print("WARNING: ExportToMEDX() is deprecated, use ExportMED() instead")
+ args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
+ SMESH._objref_SMESH_Mesh.ExportMED(self, *args)
+ def ExportToMED(self, *args): # function removed
+ print("WARNING: ExportToMED() is deprecated, use ExportMED() instead")
+ args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
+ while len(args) < 4: # !!!! nb of parameters for ExportToMED IDL's method
+ args.append(True)
+ SMESH._objref_SMESH_Mesh.ExportMED(self, *args)
+ def ExportPartToMED(self, *args): # 'version' parameter removed
+ args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
+ SMESH._objref_SMESH_Mesh.ExportPartToMED(self, *args)
+ def ExportMED(self, *args): # signature of method changed
+ args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]]
+ while len(args) < 4: # !!!! nb of parameters for ExportToMED IDL's method
+ args.append(True)
+ SMESH._objref_SMESH_Mesh.ExportMED(self, *args)
pass
omniORB.registerObjref(SMESH._objref_SMESH_Mesh._NP_RepositoryId, meshProxy)
@@ -5068,7 +5286,7 @@ class submeshProxy(SMESH._objref_SMESH_subMesh):
SMESH._objref_SMESH_subMesh.__init__(self, *args)
self.mesh = None
def __deepcopy__(self, memo=None):
- new = self.__class__()
+ new = self.__class__(self)
return new
## Compute the sub-mesh and return the status of the computation
@@ -5084,11 +5302,11 @@ class submeshProxy(SMESH._objref_SMESH_subMesh):
ok = self.mesh.Compute( self.GetSubShape(),refresh=[] )
- if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
+ if salome.sg.hasDesktop():
smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(self.mesh.GetStudyId())
+ smeshgui.Init()
smeshgui.SetMeshIcon( salome.ObjectToID( self ), ok, (self.GetNumberOfElements()==0) )
- if refresh: salome.sg.updateObjBrowser(True)
+ if refresh: salome.sg.updateObjBrowser()
pass
return ok
@@ -5114,7 +5332,7 @@ class meshEditor(SMESH._objref_SMESH_MeshEditor):
print("meshEditor: attribute '%s' NOT FOUND" % name)
return None
def __deepcopy__(self, memo=None):
- new = self.__class__()
+ new = self.__class__(self)
return new
def FindCoincidentNodes(self,*args): # a 2nd arg added (SeparateCornerAndMediumNodes)
if len( args ) == 1: args += False,
@@ -5172,10 +5390,11 @@ omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
## Private class used to bind methods creating algorithms to the class Mesh
#
class algoCreator:
- def __init__(self):
+ def __init__(self, method):
self.mesh = None
self.defaultAlgoType = ""
self.algoTypeToClass = {}
+ self.method = method
# Store a python class of algorithm
def add(self, algoClass):
@@ -5189,26 +5408,50 @@ class algoCreator:
# Create a copy of self and assign mesh to the copy
def copy(self, mesh):
- other = algoCreator()
+ other = algoCreator( self.method )
other.defaultAlgoType = self.defaultAlgoType
- other.algoTypeToClass = self.algoTypeToClass
+ other.algoTypeToClass = self.algoTypeToClass
other.mesh = mesh
return other
# Create an instance of algorithm
def __call__(self,algo="",geom=0,*args):
- algoType = self.defaultAlgoType
- for arg in args + (algo,geom):
- if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
- geom = arg
- if isinstance( arg, str ) and arg:
+ algoType = ""
+ shape = 0
+ if isinstance( algo, str ):
+ algoType = algo
+ elif ( isinstance( algo, geomBuilder.GEOM._objref_GEOM_Object ) and \
+ not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object )):
+ shape = algo
+ elif algo:
+ args += (algo,)
+
+ if isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
+ shape = geom
+ elif not algoType and isinstance( geom, str ):
+ algoType = geom
+ elif geom:
+ args += (geom,)
+ for arg in args:
+ if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ) and not shape:
+ shape = arg
+ elif isinstance( arg, str ) and not algoType:
algoType = arg
+ else:
+ import traceback, sys
+ msg = "Warning. Unexpected argument in mesh.%s() ---> %s" % ( self.method, arg )
+ sys.stderr.write( msg + '\n' )
+ tb = traceback.extract_stack(None,2)
+ traceback.print_list( [tb[0]] )
+ if not algoType:
+ algoType = self.defaultAlgoType
if not algoType and self.algoTypeToClass:
- algoType = list(self.algoTypeToClass.keys())[0]
+ algoType = sorted( self.algoTypeToClass.keys() )[0]
if algoType in self.algoTypeToClass:
#print "Create algo",algoType
- return self.algoTypeToClass[ algoType ]( self.mesh, geom )
- raise RuntimeError("No class found for algo type %s" % algoType)
+
+ return self.algoTypeToClass[ algoType ]( self.mesh, shape )
+ raise RuntimeError( "No class found for algo type %s" % algoType)
return None
## Private class used to substitute and store variable parameters of hypotheses.
@@ -5289,7 +5532,7 @@ for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
if inspect.isclass(algo) and hasattr(algo, "meshMethod"):
#print " meshMethod:" , str(algo.meshMethod)
if not hasattr( Mesh, algo.meshMethod ):
- setattr( Mesh, algo.meshMethod, algoCreator() )
+ setattr( Mesh, algo.meshMethod, algoCreator( algo.meshMethod ))
pass
getattr( Mesh, algo.meshMethod ).add( algo )
pass