Version: 6.3.1

src/SMESH_SWIG/batchmode_smesh.py

Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  File   : batchmode_smesh.py
00025 #  Author : Oksana TCHEBANOVA
00026 #  Module : SMESH
00027 #  $Header: /home/server/cvs/SMESH/SMESH_SRC/src/SMESH_SWIG/batchmode_smesh.py,v 1.10.2.3.6.1.8.1 2011-06-02 05:57:31 vsr Exp $
00028 #
00029 from batchmode_salome import *
00030 from batchmode_geompy import ShapeType
00031 import SMESH
00032 
00033 #--------------------------------------------------------------------------
00034 modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
00035 
00036 smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
00037 smesh.SetCurrentStudy(myStudy)
00038 myStudyBuilder = myStudy.NewBuilder()
00039 
00040 if myStudyBuilder is None:
00041      raise RuntimeError, " Null myStudyBuilder"
00042 
00043 father = myStudy.FindComponent("SMESH")
00044 if father is None:
00045         father = myStudyBuilder.NewComponent("SMESH")
00046         FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName")
00047      Comp = modulecatalog.GetComponent("SMESH")
00048      FName.SetValue(Comp._get_componentusername())
00049           aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap")
00050      aPixmap.SetPixMap("ICON_OBJBROWSER_Mesh")
00051 
00052 myStudyBuilder.DefineComponentInstance(father,smesh)
00053 
00054 mySComponentMesh = father._narrow(SALOMEDS.SComponent)
00055 
00056 Tag_HypothesisRoot  = 1
00057 Tag_AlgorithmsRoot  = 2
00058   
00059 Tag_RefOnShape      = 1
00060 Tag_RefOnAppliedHypothesis = 2
00061 Tag_RefOnAppliedAlgorithms = 3
00062   
00063 Tag_SubMeshOnVertex = 4
00064 Tag_SubMeshOnEdge = 5
00065 Tag_SubMeshOnFace = 6
00066 Tag_SubMeshOnSolid = 7
00067 Tag_SubMeshOnCompound = 8
00068 
00069 Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
00070 
00071 #------------------------------------------------------------
00072 def Init():
00073       pass
00074 #------------------------------------------------------------
00075 def AddNewMesh(IOR):
00076      # VSR: added temporarily - objects are published automatically by the engine
00077      aSO = myStudy.FindObjectIOR( IOR )
00078      if aSO is not None:
00079           return aSO.GetID()
00080      # VSR ######################################################################
00081      
00082      res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
00083      if HypothesisRoot is None or res == 0:
00084           HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
00085           aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
00086           aName.SetValue("Hypotheses")
00087           aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
00088           aPixmap.SetPixMap( "mesh_tree_hypo.png" )
00089           aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
00090           aSelAttr.SetSelectable(0)
00091 
00092      res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
00093      if AlgorithmsRoot is None  or res == 0:
00094           AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
00095           aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
00096           aName.SetValue("Algorithms")
00097           aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
00098           aPixmap.SetPixMap( "mesh_tree_algo.png" )
00099           aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
00100           aSelAttr.SetSelectable(0)
00101 
00102      HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
00103      newMesh = myStudyBuilder.NewObject(mySComponentMesh)
00104      aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
00105      aPixmap.SetPixMap( "mesh_tree_mesh.png" )
00106      anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
00107      anIOR.SetValue(IOR)
00108      return newMesh.GetID()
00109 
00110 #------------------------------------------------------------    
00111 def AddNewHypothesis(IOR):
00112      # VSR: added temporarily - objects are published automatically by the engine
00113      aSO = myStudy.FindObjectIOR( IOR )
00114      if aSO is not None:
00115           return aSO.GetID()
00116      # VSR ######################################################################
00117 
00118      res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
00119      if HypothesisRoot is None or res == 0:
00120           HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
00121           aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
00122           aName.SetValue("Hypotheses")
00123           aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
00124           aSelAttr.SetSelectable(0)
00125           aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
00126           aPixmap.SetPixMap( "mesh_tree_hypo.png" )
00127  
00128      # Add New Hypothesis
00129      newHypo = myStudyBuilder.NewObject(HypothesisRoot)
00130      aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
00131      H = orb.string_to_object(IOR)
00132      aType = H.GetName()
00133      aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType )
00134      anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
00135      anIOR.SetValue(IOR)
00136      return newHypo.GetID()
00137 
00138 #------------------------------------------------------------
00139 def AddNewAlgorithms(IOR):
00140      # VSR: added temporarily - objects are published automatically by the engine
00141      aSO = myStudy.FindObjectIOR( IOR )
00142      if aSO is not None:
00143           return aSO.GetID()
00144      # VSR ######################################################################
00145 
00146      res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
00147      if  AlgorithmsRoot is None or res == 0:
00148           AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
00149           aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
00150           aName.SetValue("Algorithms")
00151           aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
00152           aSelAttr.SetSelectable(0)
00153           aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
00154           aPixmap.SetPixMap( "mesh_tree_algo.png" )
00155 
00156   # Add New Algorithms
00157      newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
00158      aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
00159      aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap)
00160      H = orb.string_to_object(IOR)
00161      aType = H.GetName();     #QString in fact
00162      aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType )
00163      anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
00164      anIOR.SetValue(IOR)
00165      return newHypo.GetID()
00166 
00167 
00168 #------------------------------------------------------------
00169 def SetShape(ShapeEntry, MeshEntry):
00170      SO_MorSM = myStudy.FindObjectID( MeshEntry )
00171      SO_GeomShape = myStudy.FindObjectID( ShapeEntry )
00172 
00173      if SO_MorSM is not None and SO_GeomShape is not None :
00174           # VSR: added temporarily - shape reference is published automatically by the engine
00175           res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape )
00176           if res == 1 :
00177                return
00178           # VSR ######################################################################
00179      
00180           SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape)
00181           myStudyBuilder.Addreference (SO,SO_GeomShape)
00182 
00183 
00184 #------------------------------------------------------------
00185 def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
00186   SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
00187   SO_Hypothesis =  myStudy.FindObjectID( Hypothesis_Entry )
00188 
00189   if  SO_MorSM is not None and SO_Hypothesis is not None : 
00190     
00191         #Find or Create Applied Hypothesis root
00192      res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
00193      if  AHR is None or res == 0: 
00194                AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis)
00195                aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
00196           
00197           # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
00198                aName.SetValue("Applied hypotheses")
00199           
00200                aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
00201                aSelAttr.SetSelectable(0)
00202                aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
00203                aPixmap.SetPixMap( "mesh_tree_hypo.png" )
00204           
00205      # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
00206      else :
00207           it = myStudy.NewChildIterator(AHR)
00208           while it.More() :
00209                res, Ref = it.Value().ReferencedObject()
00210                if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
00211                     return
00212                it.Next()
00213      # VSR ######################################################################
00214      
00215      SO = myStudyBuilder.NewObject(AHR)
00216      myStudyBuilder.Addreference (SO,SO_Hypothesis)
00217 
00218 #------------------------------------------------------------
00219 def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
00220     SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
00221     SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
00222     if  SO_MorSM != None and SO_Algorithms != None : 
00223      #Find or Create Applied Algorithms root
00224      res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms)
00225      if AHR is None or res == 0: 
00226                AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms)
00227                aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
00228 
00229           # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
00230                aName.SetValue("Applied algorithms")
00231           
00232                aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
00233                aSelAttr.SetSelectable(0)
00234                aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
00235                aPixmap.SetPixMap( "mesh_tree_algo.png" )
00236                
00237      # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
00238      else :
00239           it = myStudy.NewChildIterator(AHR)
00240           while it.More() :
00241                res, Ref = it.Value().ReferencedObject()
00242                if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
00243                     return
00244                it.Next()
00245      # VSR ######################################################################
00246      
00247      SO = myStudyBuilder.NewObject(AHR)
00248      myStudyBuilder.Addreference (SO,SO_Algorithms)
00249   
00250 
00251 #------------------------------------------------------------
00252 def UnSetHypothesis( Applied_Hypothesis_Entry ):
00253      SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry )
00254      if SO_Applied_Hypothesis : 
00255           myStudyBuilder.RemoveObject(SO_Applied_Hypothesis)
00256      
00257 
00258 #------------------------------------------------------------
00259 def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
00260      # VSR: added temporarily - objects are published automatically by the engine
00261      aSO = myStudy.FindObjectIOR( SM_IOR )
00262      if aSO is not None:
00263           return aSO.GetID()
00264      # VSR ######################################################################
00265      
00266      SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
00267      if ( SO_Mesh ) : 
00268     
00269           if  ST == ShapeType["COMPSOLID"] : 
00270                Tag_Shape = Tag_SubMeshOnSolid
00271                Name = "SubMeshes on Solid"
00272           elif ST == ShapeType["FACE"] :
00273                Tag_Shape = Tag_SubMeshOnFace
00274                Name = "SubMeshes on Face"
00275           elif ST == ShapeType["EDGE"] :
00276                Tag_Shape = Tag_SubMeshOnEdge
00277                Name = "SubMeshes on Edge"
00278           elif ST == ShapeType["VERTEX"] :
00279                Tag_Shape = Tag_SubMeshOnVertex
00280                Name = "SubMeshes on Vertex"
00281           else :
00282                     Tag_Shape = Tag_SubMeshOnCompound
00283                Name = "SubMeshes on Compound"
00284           
00285           res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
00286           if SubmeshesRoot is None or res == 0:
00287                     SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape)
00288                     aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName")
00289                     aName.SetValue(Name)
00290                     aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable")
00291                     aSelAttr.SetSelectable(0)
00292           
00293           SO = myStudyBuilder.NewObject (SubmeshesRoot)
00294           anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR")
00295           anIOR.SetValue(SM_IOR)
00296           return  SO.GetID()
00297 
00298      return None
00299 
00300 #------------------------------------------------------------
00301 def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
00302      # VSR: added temporarily - objects are published automatically by the engine
00303      aSO = myStudy.FindObjectIOR( SM_IOR )
00304      if aSO is not None:
00305           return aSO.GetID()
00306      # VSR ######################################################################
00307      SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry )
00308      if  SO_GeomShape != None : 
00309           SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST)
00310           SO_SM = myStudy.FindObjectID( SM_Entry )
00311 
00312           if  SO_SM != None :
00313                SetShape (GeomShape_Entry, SM_Entry)
00314                return SM_Entry
00315 
00316      return None
00317 
00318 
00319 #------------------------------------------------------------
00320 def SetName(Entry, Name):
00321      SO = myStudy.FindObjectID( Entry )
00322      if SO != None : 
00323           aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")
00324           aName.SetValue(Name)
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS