Back to index

salome-kernel  6.5.0
Functions | Variables
KERNEL_PY.salome_study Namespace Reference

Functions

def DumpComponent
def DumpStudy
def DumpStudies
def IDToObject
def ObjectToSObject
def ObjectToID
def IDToSObject
def generateName
def PersistentPresentation
def GetTree
def CheckCopyPaste
def FindFileInDataDir
def getActiveStudy
def setCurrentStudy
def setCurrentStudyId
def createNewStudy
def salome_study_init

Variables

int salome_study_ID = 1
int salome_study_initial = 1

Function Documentation

def KERNEL_PY.salome_study.CheckCopyPaste (   theSO,
  theInfo,
  theComponentPaste 
)

Definition at line 190 of file salome_study.py.

00190 
00191 def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
00192     aRoot = theSO
00193     while aRoot.GetID() != "0:":
00194         aRoot = aRoot.GetFather()
00195     aTree = GetTree(aRoot)
00196     aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
00197 
00198     if not myStudyManager.CanCopy(theSO):
00199         raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
00200     
00201     if not myStudyManager.Copy(theSO):
00202         raise RuntimeError, "<Copy> for "+theInfo+" returns false"
00203 
00204     
00205     if not myStudyManager.CanPaste(theSO):
00206         raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
00207 
00208     # check: before paste study is not changed check
00209     if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1):
00210         raise RuntimeError, "Study is changed before Paste calling for "+theInfo
00211     
00212     aSObj = theSO
00213     if theComponentPaste:
00214         aSObj = theSO.GetFatherComponent()
00215         theInfo = theInfo + "(paste for component)"
00216     if myStudyManager.Paste(aSObj) == None:
00217         raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
00218     aNewTree = GetTree(aRoot)
00219     aLen = len(aTree)
00220     for a in range(0,aLen):
00221         if aTree[a] != aNewTree[a]:
00222             return myStudy.FindObjectID(aNewTree[a])
00223         
00224     if aLen < len(aNewTree):
00225         return myStudy.FindObjectID(aNewTree[aLen])
00226     
00227     raise RuntimeError, "After Copy calling the tree is not changed"
00228     
00229     #--------------------------------------------------------------------------

Here is the call graph for this function:

Definition at line 308 of file salome_study.py.

00308 
00309 def createNewStudy():
00310     print "createNewStudy"
00311     i=1
00312     aStudyName = "noName"
00313     nameAlreadyInUse = 1
00314     listOfOpenStudies = myStudyManager.GetOpenStudies()
00315     print listOfOpenStudies
00316     while nameAlreadyInUse:
00317         aStudyName = "extStudy_%d"%i
00318         if aStudyName not in listOfOpenStudies:
00319             nameAlreadyInUse=0
00320         else:
00321             i = i+1
00322 
00323     theStudy = myStudyManager.NewStudy(aStudyName)
00324     theStudyId = theStudy._get_StudyId()
00325     print aStudyName, theStudyId
00326     return theStudyId
00327 
00328     #--------------------------------------------------------------------------

Here is the caller graph for this function:

def KERNEL_PY.salome_study.DumpComponent (   Study,
  SO,
  Builder,
  offset 
)

Definition at line 36 of file salome_study.py.

00036 
00037 def DumpComponent(Study, SO, Builder,offset):
00038   it = Study.NewChildIterator(SO)
00039   while it.More():
00040     CSO = it.Value()
00041     a=offset*"--" + ">" + CSO.GetID()
00042     find,AtName = Builder.FindAttribute(CSO, "AttributeName")
00043     if find:
00044       a=a+":"+AtName.Value()
00045     find,AtIOR = Builder.FindAttribute(CSO, "AttributeIOR")
00046     if find:
00047       a=a+":"+AtIOR.Value()
00048     find,RefSO = CSO.ReferencedObject()
00049     if find:
00050       a=a+":"+RefSO.GetID()
00051     print a
00052     DumpComponent(Study, CSO, Builder,offset+2)
00053     it.Next()
00054 
00055 #--------------------------------------------------------------------------

Here is the caller graph for this function:

  Dump all studies in a StudyManager

Definition at line 69 of file salome_study.py.

00069 
00070 def DumpStudies():
00071   """
00072     Dump all studies in a StudyManager
00073   """
00074   for name in myStudyManager.GetOpenStudies():
00075     s=myStudyManager.GetStudyByName(name)
00076     print "study:",name, s._get_StudyId()
00077     DumpStudy(s)
00078 
00079 
00080 #--------------------------------------------------------------------------

Here is the call graph for this function:

Dump a study, given the ior

Definition at line 56 of file salome_study.py.

00056 
00057 def DumpStudy(Study):
00058     """
00059     Dump a study, given the ior
00060     """
00061     itcomp = Study.NewComponentIterator()
00062     Builder = Study.NewBuilder()
00063     while itcomp.More():
00064       SC = itcomp.Value()
00065       name = SC.ComponentDataType()
00066       print "-> ComponentDataType is " + name
00067       DumpComponent(Study, SC,Builder, 1)
00068       itcomp.Next()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 230 of file salome_study.py.

00230 
00231 def FindFileInDataDir(filename):
00232     import os
00233     datadir = os.getenv("DATA_DIR")
00234     if datadir is not None:
00235         import string
00236         dirs = string.split(datadir, ":")
00237         for dir in dirs:
00238             file = dir + "/" + filename
00239             if os.path.exists(file):
00240                 return file;
00241     datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
00242     file = datadir + filename
00243     if os.path.exists(file):
00244         return file;
00245 
00246     return None
00247 
00248     #--------------------------------------------------------------------------

def KERNEL_PY.salome_study.generateName (   prefix = None)

Definition at line 112 of file salome_study.py.

00112 
00113 def generateName(prefix = None):
00114     import random;
00115     int = random.randint(1,1000);
00116     if prefix is None:
00117         return "Study" + str(int)
00118     else :
00119         return prefix + str(int)
00120 
00121     #--------------------------------------------------------------------------

def KERNEL_PY.salome_study.getActiveStudy (   theStudyId = 0)

Definition at line 251 of file salome_study.py.

00251 
00252 def getActiveStudy(theStudyId=0):
00253     global salome_study_ID
00254 
00255     if verbose(): print "getActiveStudy"
00256     if salome_study_ID == -1:
00257         if salome_iapp.hasDesktop():
00258             if verbose(): print "---in gui"
00259             salome_study_ID = salome_iapp.sg.getActiveStudyId()
00260         else:
00261             if verbose(): print "---outside gui"
00262             if theStudyId:
00263                 aStudy=myStudyManager.GetStudyByID(theStudyId)
00264                 if aStudy:
00265                     if verbose(): print "connection to existing study ", theStudyId
00266                     salome_study_ID = theStudyId
00267             if salome_study_ID == -1:
00268                 salome_study_ID = createNewStudy()
00269             if verbose(): print"--- Study Id ", salome_study_ID
00270     return salome_study_ID
00271 
00272     #--------------------------------------------------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 179 of file salome_study.py.

00179 
00180 def GetTree(theSO):
00181     # returns the document list tree (as list)
00182     aResult = [theSO.GetID()]
00183     anIter = myStudy.NewChildIterator(theSO)
00184     while anIter.More():
00185         aResult += GetTree(anIter.Value())
00186         anIter.Next()
00187     return aResult
00188 
00189     #--------------------------------------------------------------------------

Here is the caller graph for this function:

Definition at line 81 of file salome_study.py.

00081 
00082 def IDToObject(id):
00083     myObj = None
00084     mySO = myStudy.FindObjectID(id);
00085     if mySO is not None:
00086         ok, anAttr = mySO.FindAttribute("AttributeIOR")
00087         if ok:
00088             AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
00089             if AtIOR.Value() != "":
00090                 myObj = orb.string_to_object(AtIOR.Value())
00091     return myObj

Definition at line 106 of file salome_study.py.

00106 
00107 def IDToSObject(id):
00108     mySO = myStudy.FindObjectID(id);
00109     return mySO
00110 
00111     #--------------------------------------------------------------------------

Definition at line 100 of file salome_study.py.

00100 
00101 def ObjectToID(obj):
00102     mySO = ObjectToSObject(obj)
00103     if mySO:
00104         return mySO.GetID()
00105     return ""

Here is the call graph for this function:

Definition at line 92 of file salome_study.py.

00092 
00093 def ObjectToSObject(obj):
00094     mySO = None
00095     if obj is not None:
00096         ior =  orb.object_to_string(obj)
00097         if ior != "":
00098             mySO = myStudy.FindObjectIOR(ior)
00099     return mySO

Here is the caller graph for this function:

def KERNEL_PY.salome_study.PersistentPresentation (   theStudy,
  theSO,
  theWithID 
)

Definition at line 122 of file salome_study.py.

00122 
00123 def PersistentPresentation(theStudy, theSO, theWithID):
00124     # put the sobject's content (with subchildren) to the string
00125     aResult = ""
00126     attrs = theSO.GetAllAttributes()
00127     aLen = len(attrs)
00128     anUncopied = 0
00129     for a in range(0,aLen):
00130         attr = attrs[a]
00131         if isinstance(attr,SALOMEDS._objref_AttributeTreeNode):
00132             anUncopied += 1
00133         elif isinstance(attr,SALOMEDS._objref_AttributeTarget):
00134             anUncopied += 1
00135         elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \
00136              isinstance(attr,SALOMEDS._objref_AttributeInteger) or \
00137              isinstance(attr,SALOMEDS._objref_AttributeName) or \
00138              isinstance(attr,SALOMEDS._objref_AttributeComment) or \
00139              isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \
00140              isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \
00141              isinstance(attr,SALOMEDS._objref_AttributeUserID):
00142             aResult += " attribute value: " + str(attr.Value())
00143         elif isinstance(attr,SALOMEDS._objref_AttributeIOR):
00144             aResult += " attribute: IOR"
00145         elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \
00146              isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger):
00147             aResult += " Sequence: " + str(attr.CorbaSequence())
00148         elif isinstance(attr,SALOMEDS._objref_AttributeDrawable):
00149             aResult += " Drawable: " + str(attr.IsDrawable())
00150         elif isinstance(attr,SALOMEDS._objref_AttributeSelectable):
00151             aResult += " Selectable: " + str(attr.IsSelectable())
00152         elif isinstance(attr,SALOMEDS._objref_AttributeExpandable):
00153             aResult += " Expandable: " + str(attr.IsExpandable())
00154         elif isinstance(attr,SALOMEDS._objref_AttributeOpened):
00155             aResult += " Opened: " + str(attr.IsOpened())
00156         elif isinstance(attr,SALOMEDS._objref_AttributeTextColor):
00157             aResult += " TextColor: " + str(attr.TextColor())
00158         elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor):
00159             aResult += " TextHighlightColor: " + str(attr.TextHighlightColor())
00160         elif isinstance(attr,SALOMEDS._objref_AttributePixMap):
00161             aResult += " PixMap: " + str(attr.GetPixMap())
00162         elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \
00163              isinstance(attr,SALOMEDS._objref_AttributeTableOfReal):
00164             aResult += " Table with title: " + attr.GetTitle()
00165         elif isinstance(attr,SALOMEDS._objref_AttributePythonObject):
00166             aResult += " PythonObject: " + attr.GetObject()
00167 
00168     if theWithID:
00169         aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
00170     else:
00171         aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
00172     anIter = theStudy.NewChildIterator(theSO)
00173     while anIter.More():
00174         aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID)
00175         anIter.Next()
00176     return aResult
00177 
00178     #--------------------------------------------------------------------------

Here is the caller graph for this function:

def KERNEL_PY.salome_study.salome_study_init (   theStudyId = 0)
Performs only once study creation or connection.
optional argument : theStudyId
  When in embedded interpreter inside IAPP, theStudyId is not used
  When used without GUI (external interpreter)
    0      : create a new study (default).
    n (>0) : try connection to study with Id = n, or create a new one
             if study not found.

Definition at line 331 of file salome_study.py.

00331 
00332 def salome_study_init(theStudyId=0):
00333     """
00334     Performs only once study creation or connection.
00335     optional argument : theStudyId
00336       When in embedded interpreter inside IAPP, theStudyId is not used
00337       When used without GUI (external interpreter)
00338         0      : create a new study (default).
00339         n (>0) : try connection to study with Id = n, or create a new one
00340                  if study not found.
00341     """
00342 
00343     global salome_study_initial
00344     global myStudyManager, myStudyId, myStudy, myStudyName
00345     global orb, lcc, naming_service, cm
00346 
00347     if salome_study_initial:
00348         salome_study_initial = 0
00349 
00350         orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init()
00351 
00352         # get Study Manager reference
00353         if verbose(): print "looking for studyManager ..."
00354         obj = naming_service.Resolve('myStudyManager')
00355         myStudyManager = obj._narrow(SALOMEDS.StudyManager)
00356         if verbose(): print "studyManager found"
00357 
00358         # get active study Id, ref and name
00359         myStudyId = getActiveStudy(theStudyId)
00360         if verbose(): print "myStudyId",myStudyId
00361         myStudy = myStudyManager.GetStudyByID(myStudyId)
00362         myStudyName = myStudy._get_Name()
00363 
00364     return myStudyManager, myStudyId, myStudy, myStudyName
00365 

Here is the call graph for this function:

Here is the caller graph for this function:

Change current study : an existing one given by a study object.

:param theStudy: the study CORBA object to set as current study

Definition at line 273 of file salome_study.py.

00273 
00274 def setCurrentStudy(theStudy):
00275     """
00276     Change current study : an existing one given by a study object.
00277 
00278     :param theStudy: the study CORBA object to set as current study
00279     """
00280     global myStudyId, myStudy, myStudyName
00281     global salome_study_ID
00282     myStudy=theStudy
00283     myStudyId=theStudy._get_StudyId()
00284     myStudyName=theStudy._get_Name()
00285     return myStudyId, myStudy, myStudyName
00286 
00287     #--------------------------------------------------------------------------

def KERNEL_PY.salome_study.setCurrentStudyId (   theStudyId = 0)
Change current study : an existing or new one.
optional argument : theStudyId
    0      : create a new study (default).
    n (>0) : try connection to study with Id = n, or create a new one
             if study not found.

Definition at line 288 of file salome_study.py.

00288 
00289 def setCurrentStudyId(theStudyId=0):
00290     """
00291     Change current study : an existing or new one.
00292     optional argument : theStudyId
00293         0      : create a new study (default).
00294         n (>0) : try connection to study with Id = n, or create a new one
00295                  if study not found.
00296     """
00297     global myStudyId, myStudy, myStudyName
00298     global salome_study_ID
00299     salome_study_ID = -1
00300     myStudyId = getActiveStudy(theStudyId)
00301     if verbose(): print "myStudyId",myStudyId
00302     myStudy = myStudyManager.GetStudyByID(myStudyId)
00303     myStudyName = myStudy._get_Name()
00304 
00305     return myStudyId, myStudy, myStudyName
00306 
00307     #--------------------------------------------------------------------------

Here is the call graph for this function:


Variable Documentation

Definition at line 249 of file salome_study.py.

Definition at line 329 of file salome_study.py.