X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSMESH_SWIG%2FsmeshBuilder.py;h=f2bbcaccc85618c7ab66d1124a8f8c405393f377;hb=ccb5e3c25bf204e839c0094f50f543eacedba5e6;hp=f289a5fe7ed72eebc569d9026d39fcc631b1ccfd;hpb=e613ea2b8d537a9d7e94fda51e290cb9225e935b;p=modules%2Fsmesh.git diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index f289a5fe7..f2bbcaccc 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -1469,7 +1469,7 @@ class Mesh: errText = "code %s" % -err.code if errText: errText += ". " errText += err.comment - if allReasons != "":allReasons += "\n" + if allReasons: allReasons += "\n" if ok: allReasons += '- "%s"%s - %s' %(err.algoName, shapeText, errText) else: @@ -1507,7 +1507,7 @@ class Mesh: reason = ("For unknown reason. " "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!") pass - if allReasons != "":allReasons += "\n" + if allReasons: allReasons += "\n" allReasons += "- " + reason pass if not ok or allReasons != "": @@ -1630,7 +1630,7 @@ class Mesh: def GetMeshOrder(self): return self.mesh.GetMeshOrder() - ## Set order in which concurrent sub-meshes sould be meshed + ## Set order in which concurrent sub-meshes should be meshed # @param submeshes list of lists of sub-meshes # @ingroup l2_construct def SetMeshOrder(self, submeshes): @@ -1793,9 +1793,14 @@ class Mesh: # @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 version MED format version + # - MED_V2_1 is obsolete. + # - MED_V2_2 means current version (kept for compatibility reasons) + # - MED_LATEST means current version. + # - MED_MINOR_x where x from 0 to 9 indicates the minor version of MED + # to use for writing MED files, for backward compatibility : + # for instance, with SALOME 8.4 use MED 3.2 (minor=2) instead of 3.3, + # to allow the file to be read with SALOME 8.3. # @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 @@ -1811,7 +1816,7 @@ class Mesh: # - 'f' stands for "_faces _" field; # - 's' stands for "_solids _" field. # @ingroup l2_impexp - def ExportMED(self, f, auto_groups=0, version=MED_V2_2, + def ExportMED(self, f, auto_groups=0, version=MED_LATEST, overwrite=1, meshPart=None, autoDimension=True, fields=[], geomAssocFields=''): if meshPart or fields or geomAssocFields: unRegister = genObjUnRegister() @@ -1879,8 +1884,11 @@ class Mesh: # @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 ) @@ -1889,7 +1897,7 @@ class Mesh: 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 @@ -1912,9 +1920,14 @@ class Mesh: # 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 version MED format version: + # - MED_V2_1 is obsolete. + # - MED_V2_2 means current version (kept for compatibility reasons) + # - MED_LATEST means current version. + # - MED_MINOR_x where x from 0 to 9 indicates the minor version of MED + # to use for writing MED files, for backward compatibility : + # for instance, with SALOME 8.4 use MED 3.2 (minor=2) instead of 3.3, + # to allow the file to be read with SALOME 8.3. # @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 @@ -1924,7 +1937,7 @@ class Mesh: # - 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): + def ExportToMED(self, f, version=MED_LATEST, opt=0, overwrite=1, autoDimension=True): self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension) # Operations with groups: @@ -2010,6 +2023,8 @@ class Mesh: # @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() ) @@ -2687,9 +2702,14 @@ class Mesh: ## 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): @@ -3882,6 +3902,7 @@ class Mesh: # - 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() @@ -3922,6 +3943,7 @@ class Mesh: # @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 @@ -3948,6 +3970,7 @@ class Mesh: # @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() @@ -3977,6 +4000,7 @@ class Mesh: # @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 @@ -3993,6 +4017,7 @@ class Mesh: # @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) @@ -4006,6 +4031,7 @@ class Mesh: # @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) @@ -4050,6 +4076,7 @@ class Mesh: # @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): @@ -4093,6 +4120,7 @@ class Mesh: # @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, @@ -4125,6 +4153,7 @@ class Mesh: # @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): @@ -4155,6 +4184,7 @@ class Mesh: # @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): @@ -4184,6 +4214,7 @@ class Mesh: # @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): @@ -4213,6 +4244,7 @@ class Mesh: # @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): @@ -4566,10 +4598,12 @@ class Mesh: # @param NodesToKeep nodes to keep in the mesh: a list of groups, sub-meshes or node IDs. # If @a NodesToKeep does not include a node to keep for some group to merge, # then the first node in the group is kept. + # @param AvoidMakingHoles prevent merging nodes which cause removal of elements becoming + # invalid # @ingroup l2_modif_trsf - def MergeNodes (self, GroupsOfNodes, NodesToKeep=[]): + def MergeNodes (self, GroupsOfNodes, NodesToKeep=[], AvoidMakingHoles=False): # NodesToKeep are converted to SMESH_IDSource in meshEditor.MergeNodes() - self.editor.MergeNodes(GroupsOfNodes,NodesToKeep) + self.editor.MergeNodes( GroupsOfNodes, NodesToKeep, AvoidMakingHoles ) ## Find the elements built on the same nodes. # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching @@ -5125,17 +5159,18 @@ class meshEditor(SMESH._objref_SMESH_MeshEditor): def FindCoincidentNodesOnPart(self,*args): # a 3d arg added (SeparateCornerAndMediumNodes) if len( args ) == 2: args += False, return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodesOnPart( self, *args ) - def MergeNodes(self,*args): # a 2nd arg added (NodesToKeep) + def MergeNodes(self,*args): # 2 args added (NodesToKeep,AvoidMakingHoles) if len( args ) == 1: - return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [] ) + return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [], False ) NodesToKeep = args[1] + AvoidMakingHoles = args[2] if len( args ) == 3 else False unRegister = genObjUnRegister() if NodesToKeep: if isinstance( NodesToKeep, list ) and isinstance( NodesToKeep[0], int ): NodesToKeep = self.MakeIDSource( NodesToKeep, SMESH.NODE ) if not isinstance( NodesToKeep, list ): NodesToKeep = [ NodesToKeep ] - return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep ) + return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep, AvoidMakingHoles ) pass omniORB.registerObjref(SMESH._objref_SMESH_MeshEditor._NP_RepositoryId, meshEditor) @@ -5174,10 +5209,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): @@ -5191,25 +5227,48 @@ 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 = self.algoTypeToClass.keys()[0] if self.algoTypeToClass.has_key( algoType ): #print "Create algo",algoType - return self.algoTypeToClass[ algoType ]( self.mesh, geom ) + return self.algoTypeToClass[ algoType ]( self.mesh, shape ) raise RuntimeError, "No class found for algo type %s" % algoType return None @@ -5291,7 +5350,7 @@ for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ): if type( algo ).__name__ == 'classobj' 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