X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_SWIG%2FsmeshDC.py;h=f79bd99e8ac2ce342bd6ae6bf3bb86ecd60ba10b;hb=4ec1bfaca14d51dc1c0a166381947bff76aff278;hp=4ba900bf7ae3011407c3f64a8abce53484420104;hpb=1ed22ce0be9a04862d8213e29acd6633b58c360a;p=modules%2Fsmesh.git diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index 4ba900bf7..f79bd99e8 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2012 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 @@ -44,10 +44,6 @@ ## @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses ## @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses ## @defgroup l3_hypos_maxvol Max Element Volume hypothesis -## @defgroup l3_hypos_netgen Netgen 2D and 3D hypotheses -## @defgroup l3_hypos_ghs3dh GHS3D Parameters hypothesis -## @defgroup l3_hypos_blsurf BLSURF Parameters hypothesis -## @defgroup l3_hypos_hexotic Hexotic Parameters hypothesis ## @defgroup l3_hypos_quad Quadrangle Parameters hypothesis ## @defgroup l3_hypos_additi Additional Hypotheses @@ -260,7 +256,9 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo): def AssureGeomPublished(mesh, geom, name=''): if not isinstance( geom, geompyDC.GEOM._objref_GEOM_Object ): return - if not geom.IsSame( mesh.geom ) and not geom.GetStudyEntry(): + if not geom.IsSame( mesh.geom ) and \ + not geom.GetStudyEntry() and \ + mesh.smeshpyD.GetCurrentStudy(): ## set the study studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId() if studyID != mesh.geompyD.myStudyId: @@ -447,6 +445,11 @@ class smeshDC(SMESH._objref_SMESH_Gen): 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() ) ## Gets the current study # @ingroup l1_auxiliary @@ -961,15 +964,17 @@ class Mesh: if obj is None: obj = 0 if obj != 0: + objHasName = True if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object): self.geom = obj # publish geom of mesh (issue 0021122) - if not self.geom.GetStudyEntry(): + if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy(): + objHasName = False studyID = smeshpyD.GetCurrentStudy()._get_StudyId() if studyID != geompyD.myStudyId: geompyD.init_geom( smeshpyD.GetCurrentStudy()) pass - geo_name = "%s_%s"%(self.geom.GetShapeType(), id(self.geom)%100) + geo_name = "%s_%s_for_meshing"%(self.geom.GetShapeType(), id(self.geom)%100) geompyD.addToStudy( self.geom, geo_name ) self.mesh = self.smeshpyD.CreateMesh(self.geom) @@ -979,7 +984,7 @@ class Mesh: self.mesh = self.smeshpyD.CreateEmptyMesh() if name != 0: self.smeshpyD.SetName(self.mesh, name) - elif obj != 0: + elif obj != 0 and objHasName: self.smeshpyD.SetName(self.mesh, GetName(obj)) if not self.geom: @@ -1178,7 +1183,7 @@ class Mesh: if errText: errText += ". " errText += err.comment if allReasons != "":allReasons += "\n" - allReasons += '"%s" failed%s. Error: %s' %(err.algoName, shapeText, errText) + allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText) pass # Treat hyp errors @@ -1209,17 +1214,18 @@ class Mesh: " Revise Mesh.Compute() implementation in smeshDC.py!" pass if allReasons != "":allReasons += "\n" - allReasons += reason + allReasons += "- " + reason pass - if allReasons != "": - print '"' + GetName(self.mesh) + '"',"has not been computed:" + if not ok or allReasons != "": + msg = '"' + GetName(self.mesh) + '"' + if ok: msg += " has been computed with warnings" + else: msg += " has not been computed" + if allReasons != "": msg += ":" + else: msg += "." + print msg print allReasons - ok = False - elif not ok: - print '"' + GetName(self.mesh) + '"',"has not been computed." - pass pass - if salome.sg.hasDesktop(): + 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) ) @@ -1308,6 +1314,7 @@ class Mesh: if not geom: geom = self.mesh.GetShapeToMesh() pass + AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName()) status = self.mesh.AddHypothesis(geom, hyp) isAlgo = hyp._narrow( SMESH_Algo ) hyp_name = GetName( hyp ) @@ -2547,7 +2554,7 @@ class Mesh: flag = False if isinstance(MaxAngle,str): flag = True - MaxAngle,Parameters = ParseAngles(MaxAngle) + MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle) self.mesh.SetParameters(Parameters) if not IDsOfElements: IDsOfElements = self.GetElementsId() @@ -2566,7 +2573,7 @@ class Mesh: # @return TRUE in case of success, FALSE otherwise. # @ingroup l2_modif_unitetri def TriToQuadObject (self, theObject, theCriterion, MaxAngle): - MaxAngle,Parameters = ParseAngles(MaxAngle) + MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle) self.mesh.SetParameters(Parameters) if ( isinstance( theObject, Mesh )): theObject = theObject.GetMesh() @@ -2953,7 +2960,7 @@ class Mesh: IDsOfElements = self.GetElementsId() if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)): Axis = self.smeshpyD.GetAxisStruct(Axis) - AngleInRadians,AngleParameters = ParseAngles(AngleInRadians) + AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians) NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance) Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters self.mesh.SetParameters(Parameters) @@ -2983,7 +2990,7 @@ class Mesh: theObject = theObject.GetMesh() if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)): Axis = self.smeshpyD.GetAxisStruct(Axis) - AngleInRadians,AngleParameters = ParseAngles(AngleInRadians) + AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians) NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance) Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters self.mesh.SetParameters(Parameters) @@ -3013,7 +3020,7 @@ class Mesh: theObject = theObject.GetMesh() if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)): Axis = self.smeshpyD.GetAxisStruct(Axis) - AngleInRadians,AngleParameters = ParseAngles(AngleInRadians) + AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians) NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance) Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters self.mesh.SetParameters(Parameters) @@ -3043,7 +3050,7 @@ class Mesh: theObject = theObject.GetMesh() if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)): Axis = self.smeshpyD.GetAxisStruct(Axis) - AngleInRadians,AngleParameters = ParseAngles(AngleInRadians) + AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians) NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance) Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters self.mesh.SetParameters(Parameters) @@ -3199,7 +3206,7 @@ class Mesh: if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)): RefPoint = self.smeshpyD.GetPointStruct(RefPoint) pass - Angles,AnglesParameters = ParseAngles(Angles) + Angles,AnglesParameters,hasVars = ParseAngles(Angles) Parameters = AnglesParameters + var_separator + RefPoint.parameters self.mesh.SetParameters(Parameters) @@ -3250,7 +3257,7 @@ class Mesh: pass if ( isinstance( PathMesh, Mesh )): PathMesh = PathMesh.GetMesh() - Angles,AnglesParameters = ParseAngles(Angles) + Angles,AnglesParameters,hasVars = ParseAngles(Angles) Parameters = AnglesParameters + var_separator + RefPoint.parameters self.mesh.SetParameters(Parameters) if HasAngles and Angles and LinearVariation: @@ -3291,7 +3298,7 @@ class Mesh: RefPoint = self.smeshpyD.GetPointStruct(RefPoint) if ( isinstance( PathMesh, Mesh )): PathMesh = PathMesh.GetMesh() - Angles,AnglesParameters = ParseAngles(Angles) + Angles,AnglesParameters,hasVars = ParseAngles(Angles) Parameters = AnglesParameters + var_separator + RefPoint.parameters self.mesh.SetParameters(Parameters) if HasAngles and Angles and LinearVariation: @@ -3333,7 +3340,7 @@ class Mesh: RefPoint = self.smeshpyD.GetPointStruct(RefPoint) if ( isinstance( PathMesh, Mesh )): PathMesh = PathMesh.GetMesh() - Angles,AnglesParameters = ParseAngles(Angles) + Angles,AnglesParameters,hasVars = ParseAngles(Angles) Parameters = AnglesParameters + var_separator + RefPoint.parameters self.mesh.SetParameters(Parameters) if HasAngles and Angles and LinearVariation: @@ -3375,7 +3382,7 @@ class Mesh: RefPoint = self.smeshpyD.GetPointStruct(RefPoint) if ( isinstance( PathMesh, Mesh )): PathMesh = PathMesh.GetMesh() - Angles,AnglesParameters = ParseAngles(Angles) + Angles,AnglesParameters,hasVars = ParseAngles(Angles) Parameters = AnglesParameters + var_separator + RefPoint.parameters self.mesh.SetParameters(Parameters) if HasAngles and Angles and LinearVariation: @@ -3423,7 +3430,7 @@ class Mesh: IDsOfElements = self.GetElementsId() if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)): Mirror = self.smeshpyD.GetAxisStruct(Mirror) - mesh.SetParameters(Mirror.parameters) + self.mesh.SetParameters(Mirror.parameters) mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType, MakeGroups, NewMeshName) return Mesh(self.smeshpyD,self.geompyD,mesh) @@ -3592,7 +3599,7 @@ class Mesh: IDsOfElements = self.GetElementsId() if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)): Axis = self.smeshpyD.GetAxisStruct(Axis) - AngleInRadians,Parameters = ParseAngles(AngleInRadians) + AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians) Parameters = Axis.parameters + var_separator + Parameters self.mesh.SetParameters(Parameters) if Copy and MakeGroups: @@ -3613,7 +3620,7 @@ class Mesh: IDsOfElements = self.GetElementsId() if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)): Axis = self.smeshpyD.GetAxisStruct(Axis) - AngleInRadians,Parameters = ParseAngles(AngleInRadians) + AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians) Parameters = Axis.parameters + var_separator + Parameters self.mesh.SetParameters(Parameters) mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians, @@ -3633,7 +3640,7 @@ class Mesh: theObject = theObject.GetMesh() if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)): Axis = self.smeshpyD.GetAxisStruct(Axis) - AngleInRadians,Parameters = ParseAngles(AngleInRadians) + AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians) Parameters = Axis.parameters + ":" + Parameters self.mesh.SetParameters(Parameters) if Copy and MakeGroups: @@ -3654,7 +3661,7 @@ class Mesh: theObject = theObject.GetMesh() if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)): Axis = self.smeshpyD.GetAxisStruct(Axis) - AngleInRadians,Parameters = ParseAngles(AngleInRadians) + AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians) Parameters = Axis.parameters + ":" + Parameters mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians, MakeGroups, NewMeshName) @@ -3848,12 +3855,20 @@ class Mesh: # @param theAffectedElems - group of elements to which the replicated nodes # should be associated to. # @param theMakeGroup forces the generation of a group containing new elements. - # @return TRUE or a created group if operation has been completed successfully, + # @param theMakeNodeGroup forces the generation of a group containing new nodes. + # @return TRUE or created groups (one or two) if operation has been completed successfully, # FALSE or None otherwise # @ingroup l2_modif_edit - def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems, theMakeGroup=False): - if theMakeGroup: - return self.editor.DoubleNodeElemGroupNew(theElems, theNodesNot, theAffectedElems) + def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems, + theMakeGroup=False, theMakeNodeGroup=False): + if theMakeGroup or theMakeNodeGroup: + twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot, + theAffectedElems, + theMakeGroup, theMakeNodeGroup) + if theMakeGroup and theMakeNodeGroup: + return twoGroups + else: + return twoGroups[ int(theMakeNodeGroup) ] return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems) ## Creates a hole in a mesh by doubling the nodes of some particular elements @@ -3874,12 +3889,20 @@ class Mesh: # @param theAffectedElems - group of elements to which the replicated nodes # should be associated to. # @param theMakeGroup forces the generation of a group containing new elements. - # @return TRUE or a created group if operation has been completed successfully, + # @param theMakeNodeGroup forces the generation of a group containing new nodes. + # @return TRUE or created groups (one or two) if operation has been completed successfully, # FALSE or None otherwise # @ingroup l2_modif_edit - def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems, theMakeGroup=False): - if theMakeGroup: - return self.editor.DoubleNodeElemGroupsNew(theElems, theNodesNot, theAffectedElems) + def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems, + theMakeGroup=False, theMakeNodeGroup=False): + if theMakeGroup or theMakeNodeGroup: + twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot, + theAffectedElems, + theMakeGroup, theMakeNodeGroup) + if theMakeGroup and theMakeNodeGroup: + return twoGroups + else: + return twoGroups[ int(theMakeNodeGroup) ] return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems) ## Creates a hole in a mesh by doubling the nodes of some particular elements @@ -4068,6 +4091,7 @@ class Mesh_Algorithm: # @return SMESH.SMESH_Algo def FindAlgorithm (self, algoname, smeshpyD): study = smeshpyD.GetCurrentStudy() + if not study: return None #to do: find component by smeshpyD object, not by its data type scomp = study.FindComponent(smeshpyD.ComponentDataType()) if scomp is not None: @@ -4206,15 +4230,10 @@ class Mesh_Algorithm: ## Returns entry of the shape to mesh in the study def MainShapeEntry(self): - entry = "" - if not self.mesh or not self.mesh.GetMesh(): return entry - if not self.mesh.GetMesh().HasShapeToMesh(): return entry - study = self.mesh.smeshpyD.GetCurrentStudy() - ior = salome.orb.object_to_string( self.mesh.GetShape() ) - sobj = study.FindObjectIOR(ior) - if sobj: entry = sobj.GetID() - if not entry: return "" - return entry + if not self.mesh or not self.mesh.GetMesh(): return "" + if not self.mesh.GetMesh().HasShapeToMesh(): return "" + shape = self.mesh.GetShape() + return shape.GetStudyEntry() ## Defines "ViscousLayers" hypothesis to give parameters of layers of prisms to build # near mesh boundary. This hypothesis can be used by several 3D algorithms: @@ -4326,7 +4345,7 @@ class algoCreator: # creates an instance of algorithm def __call__(self,algo="",geom=0,*args): algoType = self.defaultAlgoType - for arg in args + (algo,): + for arg in args + (algo,geom): if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ): geom = arg if isinstance( arg, str ) and arg: @@ -4336,7 +4355,7 @@ class algoCreator: if self.algoTypeToClass.has_key( algoType ): #print "Create algo",algoType return self.algoTypeToClass[ algoType ]( self.mesh, geom ) - raise RuntimeError, "No class found for algo type" % algoType + raise RuntimeError, "No class found for algo type %s" % algoType return None # Private class used to substitute and store variable parameters of hypotheses.