X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_SWIG%2FsmeshBuilder.py;h=cec7eb822b0a6f608d7ecb4fbb38b067d94a0df4;hp=48e95e9a868844038e413cd7502e8703573f0981;hb=20d9e162bd67182cbfa841bbfc9319919f4703e3;hpb=87c954b31cfef2bbf53487b117221c4e46bec20f diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index 48e95e9a8..cec7eb822 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -32,7 +32,6 @@ ## @{ ## @defgroup l3_algos_basic Basic meshing algorithms ## @defgroup l3_algos_proj Projection Algorithms -## @defgroup l3_algos_radialp Radial Prism ## @defgroup l3_algos_segmarv Segments around Vertex ## @defgroup l3_algos_3dextr 3D extrusion meshing algorithm @@ -70,10 +69,9 @@ ## @defgroup l2_modif_trsf Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging) ## @defgroup l2_modif_movenode Moving nodes ## @defgroup l2_modif_throughp Mesh through point -## @defgroup l2_modif_invdiag Diagonal inversion of elements ## @defgroup l2_modif_unitetri Uniting triangles -## @defgroup l2_modif_changori Changing orientation of elements ## @defgroup l2_modif_cutquadr Cutting elements +## @defgroup l2_modif_changori Changing orientation of elements ## @defgroup l2_modif_smooth Smoothing ## @defgroup l2_modif_extrurev Extrusion and Revolution ## @defgroup l2_modif_patterns Pattern mapping @@ -252,7 +250,7 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh): if mesh: meshName = GetName( mesh ) if meshName and meshName != NO_NAME: - where = '"%s" in "%s"' % ( geomName, meshName ) + where = '"%s" shape in "%s" mesh ' % ( geomName, meshName ) if status < HYP_UNKNOWN_FATAL and where: print '"%s" was assigned to %s but %s' %( hypName, where, reason ) elif where: @@ -310,9 +308,9 @@ engine = None doLcc = False created = False -## This class allows to create, load or manipulate meshes -# It has a set of methods to create load or copy meshes, to combine several meshes. -# It also has methods to get infos on meshes. +## This class allows to create, load or manipulate meshes. +# It has a set of methods to create, load or copy meshes, to combine several meshes, etc. +# It also has methods to get infos and measure meshes. class smeshBuilder(object, SMESH._objref_SMESH_Gen): # MirrorType enumeration @@ -614,6 +612,7 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): # @param allGroups forces creation of groups corresponding to every input mesh # @param name name of a new mesh # @return an instance of Mesh class + # @ingroup l2_compounds def Concatenate( self, meshes, uniteIdenticalGroups, mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False, name = ""): @@ -965,6 +964,10 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): functor = aFilterMgr.CreateLength() elif theCriterion == FT_Length2D: functor = aFilterMgr.CreateLength2D() + elif theCriterion == FT_NodeConnectivityNumber: + functor = aFilterMgr.CreateNodeConnectivityNumber() + elif theCriterion == FT_BallDiameter: + functor = aFilterMgr.CreateBallDiameter() else: print "Error: given parameter is not numerical functor type." aFilterMgr.UnRegister() @@ -1162,7 +1165,7 @@ omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder) # import salome # salome.salome_init() # from salome.smesh import smeshBuilder -# smesh = smeshBuilder.New(theStudy) +# smesh = smeshBuilder.New(salome.myStudy) # \endcode # @param study SALOME study, generally obtained by salome.myStudy. # @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used. @@ -1177,7 +1180,7 @@ def New( study, instance=None): import salome salome.salome_init() from salome.smesh import smeshBuilder - smesh = smeshBuilder.New(theStudy) + smesh = smeshBuilder.New(salome.myStudy) Parameters: study SALOME study, generally obtained by salome.myStudy. @@ -1424,8 +1427,10 @@ class Mesh: # Treat compute errors computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom ) + shapeText = "" for err in computeErrors: - shapeText = " on %s" % self.GetSubShapeName( err.subShapeID ) + if self.mesh.HasShapeToMesh(): + shapeText = " on %s" % self.GetSubShapeName( err.subShapeID ) errText = "" stdErrors = ["OK", #COMPERR_OK "Invalid input mesh", #COMPERR_BAD_INPUT_MESH @@ -1496,13 +1501,20 @@ class Mesh: print allReasons pass if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0: - smeshgui = salome.ImportComponentGUI("SMESH") - smeshgui.Init(self.mesh.GetStudyId()) - smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) ) - if refresh: salome.sg.updateObjBrowser(1) - pass + if not isinstance( refresh, list): # not a call from subMesh.Compute() + smeshgui = salome.ImportComponentGUI("SMESH") + smeshgui.Init(self.mesh.GetStudyId()) + smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) ) + if refresh: salome.sg.updateObjBrowser(True) + return ok + ## Return a list of error messages (SMESH.ComputeError) of the last Compute() + def GetComputeErrors(self, shape=0 ): + if shape == 0: + shape = self.mesh.GetShapeToMesh() + return self.smeshpyD.GetComputeErrors( self.mesh, shape ) + ## Return a name of a sub-shape by its ID # @param subShapeID a unique ID of a sub-shape # @return a string describing the sub-shape; possible variants: @@ -1591,13 +1603,13 @@ class Mesh: return groups ## Return sub-mesh objects list in meshing order - # @return list of list of sub-meshes + # @return list of lists of sub-meshes # @ingroup l2_construct def GetMeshOrder(self): return self.mesh.GetMeshOrder() ## Set order in which concurrent sub-meshes sould be meshed - # @param submeshes list of sub-meshes + # @param submeshes list of lists of sub-meshes # @ingroup l2_construct def SetMeshOrder(self, submeshes): return self.mesh.SetMeshOrder(submeshes) @@ -1612,7 +1624,7 @@ class Mesh: smeshgui = salome.ImportComponentGUI("SMESH") smeshgui.Init(self.mesh.GetStudyId()) smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True ) - if refresh: salome.sg.updateObjBrowser(1) + if refresh: salome.sg.updateObjBrowser(True) ## Removes all nodes and elements of indicated shape # @param refresh if @c True, Object browser is automatically updated (when running in GUI) @@ -1624,7 +1636,7 @@ class Mesh: smeshgui = salome.ImportComponentGUI("SMESH") smeshgui.Init(self.mesh.GetStudyId()) smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True ) - if refresh: salome.sg.updateObjBrowser(1) + if refresh: salome.sg.updateObjBrowser(True) ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron # @param fineness [0.0,1.0] defines mesh fineness @@ -1680,9 +1692,10 @@ class Mesh: if self.mesh.HasShapeToMesh(): hyp_type = hyp.GetName() lib_name = hyp.GetLibName() - checkAll = ( not geom.IsSame( self.mesh.GetShapeToMesh() )) - if checkAll and geom: - checkAll = geom.GetType() == 37 + # checkAll = ( not geom.IsSame( self.mesh.GetShapeToMesh() )) + # if checkAll and geom: + # checkAll = geom.GetType() == 37 + checkAll = False isApplicable = self.smeshpyD.IsApplicable(hyp_type, lib_name, geom, checkAll) if isApplicable: AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName()) @@ -1967,7 +1980,7 @@ class Mesh: # @param groupName the name of the mesh group # @param elementType the type of elements in the group; either of # (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME). - # @param elemIDs the list of ids + # @param elemIDs either the list of ids, group, sub-mesh, or filter # @return SMESH_Group # @ingroup l2_grps_create def MakeGroupByIds(self, groupName, elementType, elemIDs): @@ -2150,7 +2163,7 @@ class Mesh: ## # Create a standalone group of entities basing on nodes of other groups. - # \param groups - list of groups, sub-meshes or filters, of any type. + # \param groups - list of reference groups, sub-meshes or filters, of any type. # \param elemType - a type of elements to include to the new group; either of # (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME). # \param name - a name of the new group. @@ -2162,7 +2175,10 @@ class Mesh: # - SMESH.AT_LEAST_ONE - include if one or more node is common, # - SMEHS.MAJORITY - include if half of nodes or more are common. # \param underlyingOnly - if \c True (default), an element is included to the - # new group provided that it is based on nodes of one element of \a groups. + # new group provided that it is based on nodes of an element of \a groups; + # in this case the reference \a groups are supposed to be of higher dimension + # than \a elemType, which can be useful for example to get all faces lying on + # volumes of the reference \a groups. # @return an instance of SMESH_Group # @ingroup l2_grps_operon def CreateDimGroup(self, groups, elemType, name, @@ -2173,7 +2189,7 @@ class Mesh: ## Convert group on geom into standalone group - # @ingroup l2_grps_delete + # @ingroup l2_grps_edit def ConvertToStandalone(self, group): return self.mesh.ConvertToStandalone(group) @@ -2248,6 +2264,8 @@ class Mesh: # idSrc.UnRegister() # @ingroup l1_auxiliary def GetIDSource(self, ids, elemType = SMESH.ALL): + if isinstance( ids, int ): + ids = [ids] return self.editor.MakeIDSource(ids, elemType) @@ -2812,10 +2830,11 @@ class Mesh: ## Creates a 0D element on a node with given number. # @param IDOfNode the ID of node for creation of the element. + # @param DuplicateElements to add one more 0D element to a node or not # @return the Id of the new 0D element # @ingroup l2_modif_add - def Add0DElement(self, IDOfNode): - return self.editor.Add0DElement(IDOfNode) + def Add0DElement( self, IDOfNode, DuplicateElements=True ): + return self.editor.Add0DElement( IDOfNode, DuplicateElements ) ## Create 0D elements on all nodes of the given elements except those # nodes on which a 0D element already exists. @@ -2824,18 +2843,19 @@ class Mesh: # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE ) # @param theGroupName optional name of a group to add 0D elements created # and/or found on nodes of \a theObject. + # @param DuplicateElements to add one more 0D element to a node or not # @return an object (a new group or a temporary SMESH_IDSource) holding # IDs of new and/or found 0D elements. IDs of 0D elements # can be retrieved from the returned object by calling GetIDs() # @ingroup l2_modif_add - def Add0DElementsToAllNodes(self, theObject, theGroupName=""): + def Add0DElementsToAllNodes(self, theObject, theGroupName="", DuplicateElements=False): unRegister = genObjUnRegister() if isinstance( theObject, Mesh ): theObject = theObject.GetMesh() - if isinstance( theObject, list ): + elif isinstance( theObject, list ): theObject = self.GetIDSource( theObject, SMESH.ALL ) unRegister.set( theObject ) - return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName ) + return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName, DuplicateElements ) ## Creates a ball element on a node with given ID. # @param IDOfNode the ID of node for creation of the element. @@ -3070,7 +3090,7 @@ class Mesh: # @param NodeID1 the ID of the first node # @param NodeID2 the ID of the second node # @return false if proper faces were not found - # @ingroup l2_modif_invdiag + # @ingroup l2_modif_cutquadr def InverseDiag(self, NodeID1, NodeID2): return self.editor.InverseDiag(NodeID1, NodeID2) @@ -3619,8 +3639,8 @@ class Mesh: ## Creates 2D mesh as skin on boundary faces of a 3D mesh # @return TRUE if operation has been completed successfully, FALSE otherwise # @ingroup l2_modif_edit - def Make2DMeshFrom3D(self): - return self.editor. Make2DMeshFrom3D() + def Make2DMeshFrom3D(self): + return self.editor.Make2DMeshFrom3D() ## Creates missing boundary elements # @param elements - elements whose boundary is to be checked: @@ -3809,17 +3829,27 @@ class Mesh: NbOfSteps, Tolerance, MakeGroups, TotalAngle) ## Generates new elements by extrusion of the given elements and nodes - # @param nodes - nodes to extrude: a list including ids, groups, sub-meshes or a mesh - # @param edges - edges to extrude: a list including ids, groups, sub-meshes or a mesh - # @param faces - faces to extrude: a list including ids, groups, sub-meshes or a mesh + # @param nodes nodes to extrude: a list including ids, groups, sub-meshes or a mesh + # @param edges edges to extrude: a list including ids, groups, sub-meshes or a mesh + # @param faces faces to extrude: a list including ids, groups, sub-meshes or a mesh # @param StepVector vector or DirStruct or 3 vector components, defining # the direction and value of extrusion for one step (the total extrusion # length will be NbOfSteps * ||StepVector||) # @param NbOfSteps the number of steps # @param MakeGroups forces the generation of new groups from existing ones + # @param scaleFactors optional scale factors to apply during extrusion + # @param linearVariation if @c True, scaleFactors are spread over all @a scaleFactors, + # else scaleFactors[i] is applied to nodes at the i-th extrusion step + # @param basePoint optional scaling center; if not provided, a gravity center of + # nodes and elements being extruded is used as the scaling center. + # It can be either + # - a list of tree components of the point or + # - a node ID or + # - a GEOM point # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise # @ingroup l2_modif_extrurev - def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False): + def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False, + scaleFactors=[], linearVariation=False, basePoint=[] ): unRegister = genObjUnRegister() nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister ) edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister ) @@ -3830,16 +3860,26 @@ class Mesh: if isinstance( StepVector, list ): StepVector = self.smeshpyD.MakeDirStruct(*StepVector) + if isinstance( basePoint, int): + xyz = self.GetNodeXYZ( basePoint ) + if not xyz: + raise RuntimeError, "Invalid node ID: %s" % basePoint + basePoint = xyz + if isinstance( basePoint, geomBuilder.GEOM._objref_GEOM_Object ): + basePoint = self.geompyD.PointCoordinates( basePoint ) + NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps) Parameters = StepVector.PS.parameters + var_separator + Parameters self.mesh.SetParameters(Parameters) return self.editor.ExtrusionSweepObjects( nodes, edges, faces, - StepVector, NbOfSteps, MakeGroups) + StepVector, NbOfSteps, + scaleFactors, linearVariation, basePoint, + MakeGroups) ## Generates new elements by extrusion of the elements with given ids - # @param IDsOfElements the list of elements ids for extrusion + # @param IDsOfElements the list of ids of elements or nodes for extrusion # @param StepVector vector or DirStruct or 3 vector components, defining # the direction and value of extrusion for one step (the total extrusion # length will be NbOfSteps * ||StepVector||) @@ -3855,8 +3895,8 @@ class Mesh: return self.ExtrusionSweepObjects(n,e,f, StepVector, NbOfSteps, MakeGroups) ## Generates new elements by extrusion along the normal to a discretized surface or wire - # @param Elements elements to extrude - a list including ids, groups, sub-meshes or a mesh - # Only faces can be extruded so far. Sub-mesh should be a sub-mesh on geom faces. + # @param Elements elements to extrude - a list including ids, groups, sub-meshes or a mesh. + # Only faces can be extruded so far. A sub-mesh should be a sub-mesh on geom faces. # @param StepSize length of one extrusion step (the total extrusion # length will be \a NbOfSteps * \a StepSize ). # @param NbOfSteps number of extrusion steps. @@ -3892,15 +3932,15 @@ class Mesh: return self.editor.ExtrusionByNormal(Elements, StepSize, NbOfSteps, ByAverageNormal, UseInputElemsOnly, MakeGroups, Dim) - ## Generates new elements by extrusion of the elements which belong to the object - # @param theObject the object which elements should be processed. - # It can be a mesh, a sub mesh or a group. + ## Generates new elements by extrusion of the elements or nodes which belong to the object + # @param theObject the object whose elements or nodes should be processed. + # It can be a mesh, a sub-mesh or a group. # @param StepVector vector or DirStruct or 3 vector components, defining # the direction and value of extrusion for one step (the total extrusion # length will be NbOfSteps * ||StepVector||) # @param NbOfSteps the number of steps # @param MakeGroups forces the generation of new groups from existing ones - # @param IsNodes is True if elements to extrude are nodes + # @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 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False): @@ -3909,9 +3949,9 @@ class Mesh: else : e,f, = theObject,theObject return self.ExtrusionSweepObjects(n,e,f, StepVector, NbOfSteps, MakeGroups) - ## Generates new elements by extrusion of the elements which belong to the object - # @param theObject object which elements should be processed. - # It can be a mesh, a sub mesh or a group. + ## Generates new elements by extrusion of edges which belong to the object + # @param theObject object whose 1D elements should be processed. + # It can be a mesh, a sub-mesh or a group. # @param StepVector vector or DirStruct or 3 vector components, defining # the direction and value of extrusion for one step (the total extrusion # length will be NbOfSteps * ||StepVector||) @@ -3922,9 +3962,9 @@ class Mesh: def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False): return self.ExtrusionSweepObjects([],theObject,[], StepVector, NbOfSteps, MakeGroups) - ## Generates new elements by extrusion of the elements which belong to the object - # @param theObject object which elements should be processed. - # It can be a mesh, a sub mesh or a group. + ## Generates new elements by extrusion of faces which belong to the object + # @param theObject object whose 2D elements should be processed. + # It can be a mesh, a sub-mesh or a group. # @param StepVector vector or DirStruct or 3 vector components, defining # the direction and value of extrusion for one step (the total extrusion # length will be NbOfSteps * ||StepVector||) @@ -3987,6 +4027,7 @@ class Mesh: if isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object): RefPoint = self.smeshpyD.GetPointStruct(RefPoint) if isinstance( RefPoint, list ): + if not RefPoint: RefPoint = [0,0,0] RefPoint = SMESH.PointStruct( *RefPoint ) if isinstance( PathMesh, Mesh ): PathMesh = PathMesh.GetMesh() @@ -4000,7 +4041,7 @@ class Mesh: ## Generates new elements by extrusion of the given elements # The path of extrusion must be a meshed edge. - # @param Base mesh or group, or submesh, or list of ids of elements for extrusion + # @param Base mesh or group, or sub-mesh, or list of ids of elements for extrusion # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion # @param NodeStart the start node from Path. Defines the direction of extrusion # @param HasAngles allows the shape to be rotated around the path @@ -4019,8 +4060,9 @@ class Mesh: # only SMESH::Extrusion_Error otherwise # @ingroup l2_modif_extrurev def ExtrusionAlongPathX(self, Base, Path, NodeStart, - HasAngles, Angles, LinearVariation, - HasRefPoint, RefPoint, MakeGroups, ElemType): + HasAngles=False, Angles=[], LinearVariation=False, + HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False, + ElemType=SMESH.FACE): n,e,f = [],[],[] if ElemType == SMESH.NODE: n = Base if ElemType == SMESH.EDGE: e = Base @@ -4050,7 +4092,7 @@ class Mesh: # only SMESH::Extrusion_Error otherwise # @ingroup l2_modif_extrurev def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart, - HasAngles, Angles, HasRefPoint, RefPoint, + HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[], MakeGroups=False, LinearVariation=False): n,e,f = [],IDsOfElements,IDsOfElements gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, @@ -4062,7 +4104,7 @@ class Mesh: ## Generates new elements by extrusion of the elements which belong to the object # The path of extrusion must be a meshed edge. - # @param theObject the object which elements should be processed. + # @param theObject the object whose elements should be processed. # It can be a mesh, a sub-mesh or a group. # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds # @param PathShape shape(edge) defines the sub-mesh for the path @@ -4080,7 +4122,7 @@ class Mesh: # only SMESH::Extrusion_Error otherwise # @ingroup l2_modif_extrurev def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart, - HasAngles, Angles, HasRefPoint, RefPoint, + HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[], MakeGroups=False, LinearVariation=False): n,e,f = [],theObject,theObject gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart, @@ -4089,10 +4131,10 @@ class Mesh: if MakeGroups: return gr,er return er - ## Generates new elements by extrusion of the elements which belong to the object + ## Generates new elements by extrusion of mesh segments which belong to the object # The path of extrusion must be a meshed edge. - # @param theObject the object which elements should be processed. - # It can be a mesh, a sub mesh or a group. + # @param theObject the object whose 1D elements should be processed. + # It can be a mesh, a sub-mesh or a group. # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds # @param PathShape shape(edge) defines the sub-mesh for the path # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion @@ -4109,7 +4151,7 @@ class Mesh: # only SMESH::Extrusion_Error otherwise # @ingroup l2_modif_extrurev def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart, - HasAngles, Angles, HasRefPoint, RefPoint, + HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[], MakeGroups=False, LinearVariation=False): n,e,f = [],theObject,[] gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart, @@ -4118,10 +4160,10 @@ class Mesh: if MakeGroups: return gr,er return er - ## Generates new elements by extrusion of the elements which belong to the object + ## Generates new elements by extrusion of faces which belong to the object # The path of extrusion must be a meshed edge. - # @param theObject the object which elements should be processed. - # It can be a mesh, a sub mesh or a group. + # @param theObject the object whose 2D elements should be processed. + # It can be a mesh, a sub-mesh or a group. # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds # @param PathShape shape(edge) defines the sub-mesh for the path # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion @@ -4138,7 +4180,7 @@ class Mesh: # only SMESH::Extrusion_Error otherwise # @ingroup l2_modif_extrurev def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart, - HasAngles, Angles, HasRefPoint, RefPoint, + HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[], MakeGroups=False, LinearVariation=False): n,e,f = [],[],theObject gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart, @@ -4463,7 +4505,7 @@ class Mesh: ## Finds groups of ajacent nodes within Tolerance. # @param Tolerance the value of tolerance - # @param SubMeshOrGroup SubMesh or Group + # @param SubMeshOrGroup SubMesh, Group or Filter # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search # @param SeparateCornerAndMediumNodes if @c True, in quadratic mesh puts # corner and medium nodes in separate groups thus preventing @@ -4519,6 +4561,52 @@ class Mesh: def MergeEqualElements(self): self.editor.MergeEqualElements() + ## Returns 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. + # @return SMESH.CoincidentFreeBorders structure + # @ingroup l2_modif_trsf + def FindCoincidentFreeBorders (self, tolerance=0.): + return self.editor.FindCoincidentFreeBorders( tolerance ) + + ## Sew FreeBorder's of each group + # @param freeBorders either a SMESH.CoincidentFreeBorders structure or a list of lists + # where each enclosed list contains node IDs of a group of coincident free + # borders such that each consequent triple of IDs within a group describes + # a free border in a usual way: n1, n2, nLast - i.e. 1st node, 2nd node and + # last node of a border. + # For example [[1, 2, 10, 20, 21, 40], [11, 12, 15, 55, 54, 41]] describes two + # groups of coincident free borders, each group including two borders. + # @param createPolygons if @c True faces adjacent to free borders are converted to + # polygons if a node of opposite border falls on a face edge, else such + # faces are split into several ones. + # @param createPolyhedra if @c True volumes adjacent to free borders are converted to + # polyhedra if a node of opposite border falls on a volume edge, else such + # volumes, if any, remain intact and the mesh becomes non-conformal. + # @return a number of successfully sewed groups + # @ingroup l2_modif_trsf + def SewCoincidentFreeBorders (self, freeBorders, createPolygons=False, createPolyhedra=False): + if freeBorders and isinstance( freeBorders, list ): + # construct SMESH.CoincidentFreeBorders + if isinstance( freeBorders[0], int ): + freeBorders = [freeBorders] + borders = [] + coincidentGroups = [] + for nodeList in freeBorders: + if not nodeList or len( nodeList ) % 3: + raise ValueError, "Wrong number of nodes in this group: %s" % nodeList + group = [] + while nodeList: + group.append ( SMESH.FreeBorderPart( len(borders), 0, 1, 2 )) + borders.append( SMESH.FreeBorder( nodeList[:3] )) + nodeList = nodeList[3:] + pass + coincidentGroups.append( group ) + pass + freeBorders = SMESH.CoincidentFreeBorders( borders, coincidentGroups ) + + return self.editor.SewCoincidentFreeBorders( freeBorders, createPolygons, createPolyhedra ) + ## Sews free borders # @return SMESH::Sew_Error # @ingroup l2_modif_trsf @@ -4910,6 +4998,8 @@ class Mesh: fun = self._getFunctor( funType ) if fun: if meshPart: + if hasattr( meshPart, "SetMesh" ): + meshPart.SetMesh( self.mesh ) # set mesh to filter hist = fun.GetLocalHistogram( 1, False, meshPart ) else: hist = fun.GetHistogram( 1, False ) @@ -4920,7 +5010,7 @@ class Mesh: pass # end of Mesh class -## class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility +## Class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility # with old dump scripts which call SMESH_Mesh directly and not via smeshBuilder.Mesh # class meshProxy(SMESH._objref_SMESH_Mesh): @@ -4936,7 +5026,40 @@ class meshProxy(SMESH._objref_SMESH_Mesh): pass omniORB.registerObjref(SMESH._objref_SMESH_Mesh._NP_RepositoryId, meshProxy) -## class used to compensate change of CORBA API of SMESH_MeshEditor for backward compatibility + +## Class wrapping SMESH_SubMesh in order to add Compute() +# +class submeshProxy(SMESH._objref_SMESH_subMesh): + def __init__(self): + SMESH._objref_SMESH_subMesh.__init__(self) + self.mesh = None + def __deepcopy__(self, memo=None): + new = self.__class__() + return new + + ## Computes the sub-mesh and returns the status of the computation + # @param refresh if @c True, Object browser is automatically updated (when running in GUI) + # @return True or False + # @ingroup l2_construct + def Compute(self,refresh=False): + if not self.mesh: + self.mesh = Mesh( smeshBuilder(), None, self.GetMesh()) + + ok = self.mesh.Compute( self.GetSubShape(),refresh=[] ) + + if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0: + smeshgui = salome.ImportComponentGUI("SMESH") + smeshgui.Init(self.mesh.GetStudyId()) + smeshgui.SetMeshIcon( salome.ObjectToID( self ), ok, (self.GetNumberOfElements()==0) ) + if refresh: salome.sg.updateObjBrowser(True) + pass + + return ok + pass +omniORB.registerObjref(SMESH._objref_SMESH_subMesh._NP_RepositoryId, submeshProxy) + + +## Class used to compensate change of CORBA API of SMESH_MeshEditor for backward compatibility # with old dump scripts which call SMESH_MeshEditor directly and not via smeshBuilder.Mesh # class meshEditor(SMESH._objref_SMESH_MeshEditor): @@ -4979,6 +5102,13 @@ omniORB.registerObjref(SMESH._objref_SMESH_MeshEditor._NP_RepositoryId, meshEdit # class Pattern(SMESH._objref_SMESH_Pattern): + def LoadFromFile(self, patternTextOrFile ): + text = patternTextOrFile + if os.path.exists( text ): + text = open( patternTextOrFile ).read() + pass + return SMESH._objref_SMESH_Pattern.LoadFromFile( self, text ) + def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse): decrFun = lambda i: i-1 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun) @@ -4991,6 +5121,11 @@ class Pattern(SMESH._objref_SMESH_Pattern): theMesh.SetParameters(Parameters) return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index ) + def MakeMesh(self, mesh, CreatePolygons=False, CreatePolyhedra=False): + if isinstance( mesh, Mesh ): + mesh = mesh.GetMesh() + return SMESH._objref_SMESH_Pattern.MakeMesh( self, mesh, CreatePolygons, CreatePolyhedra ) + # Registering the new proxy for Pattern omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern) @@ -5036,7 +5171,7 @@ class algoCreator: raise RuntimeError, "No class found for algo type %s" % algoType return None -# Private class used to substitute and store variable parameters of hypotheses. +## Private class used to substitute and store variable parameters of hypotheses. # class hypMethodWrapper: def __init__(self, hyp, method): @@ -5067,7 +5202,8 @@ class hypMethodWrapper: return result pass -# A helper class that call UnRegister() of SALOME.GenericObj'es stored in it +## A helper class that call UnRegister() of SALOME.GenericObj'es stored in it +# class genObjUnRegister: def __init__(self, genObj=None): @@ -5088,6 +5224,9 @@ class genObjUnRegister: if genObj and hasattr( genObj, "UnRegister" ): genObj.UnRegister() + +## Bind methods creating mesher plug-ins to the Mesh class +# for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ): # #print "pluginName: ", pluginName