# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
#
# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
find,RefSO = CSO.ReferencedObject()
if find:
a=a+":"+RefSO.GetID()
- print a
- DumpComponent(Study, CSO, Builder,offset+2)
+ print(a)
+ DumpComponent(CSO, Builder,offset+2)
it.Next()
#--------------------------------------------------------------------------
while itcomp.More():
SC = itcomp.Value()
name = SC.ComponentDataType()
- print "-> ComponentDataType is " + name
+ print("-> ComponentDataType is " + name)
DumpComponent(SC,Builder, 1)
itcomp.Next()
aStudyPersist = PersistentPresentation(aRoot, 1)
if not myStudy.CanCopy(theSO):
- raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
+ raise RuntimeError("<CanCopy> for "+theInfo+" returns false")
if not myStudy.Copy(theSO):
- raise RuntimeError, "<Copy> for "+theInfo+" returns false"
+ raise RuntimeError("<Copy> for "+theInfo+" returns false")
if not myStudy.CanPaste(theSO):
- raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
+ raise RuntimeError("<CanPaste> for "+theInfo+" returns false")
# check: before paste study is not changed check
if aStudyPersist != PersistentPresentation(aRoot, 1):
- raise RuntimeError, "Study is changed before Paste calling for "+theInfo
+ raise RuntimeError("Study is changed before Paste calling for "+theInfo)
aSObj = theSO
if theComponentPaste:
aSObj = theSO.GetFatherComponent()
theInfo = theInfo + "(paste for component)"
if myStudy.Paste(aSObj) == None:
- raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
+ raise RuntimeError("<Paste> for "+theInfo+" returns None object")
aNewTree = GetTree(aRoot)
aLen = len(aTree)
for a in range(0,aLen):
if aLen < len(aNewTree):
return myStudy.FindObjectID(aNewTree[aLen])
- raise RuntimeError, "After Copy calling the tree is not changed"
+ raise RuntimeError("After Copy calling the tree is not changed")
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
def openStudy(theStudyPath):
- print "openStudy"
- global myStudy
+ if verbose(): print("openStudy (begin)")
+ global myStudy, myStudyName
myStudy.Open(theStudyPath)
- print theStudyPath, myStudy._get_Name()
+ myStudyName = myStudy._get_Name()
+ if verbose(): print("openStudy (end):", theStudyPath, myStudy._get_Name())
+
+ #--------------------------------------------------------------------------
+
+def salome_study_init_without_session(theStudyPath=None):
+ """
+ Performs only once study creation or connection.
+ optional argument : theStudyPath
+ None : attach to the currently active single study;
+ create new empty study if there is active study
+ <URL> (str) : open study with the given file name
+ """
+ global myStudy, myStudyName
+ global orb, lcc, naming_service, cm
+
+ if verbose(): print("theStudyPath:", theStudyPath)
+ if not myStudy:
+ import CORBA
+ orb = CORBA.ORB_init([''])
+
+ # get Study reference
+ if verbose(): print("looking for study...")
+ import KernelDS
+ myStudy = KernelDS.myStudy()
+ if verbose(): print("Study found")
+ pass
+
+ import types
+ if theStudyPath and isinstance(theStudyPath, (str, bytes)):
+ if isinstance(theStudyPath, bytes):
+ theStudyPath = str(theStudyPath, 'UTF8')
+ openStudy(theStudyPath)
+ else:
+ myStudy.Init()
+
+ myStudyName = myStudy._get_Name()
+
+ return myStudy, myStudyName
#--------------------------------------------------------------------------
global myStudy, myStudyName
global orb, lcc, naming_service, cm
- if verbose(): print "theStudyPath:", theStudyPath
+ if verbose(): print("theStudyPath:", theStudyPath)
if not myStudy:
- orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init()
+ orb, lcc, naming_service, cm, _, _, _ = salome_kernel.salome_kernel_init()
# get Study reference
- if verbose(): print "looking for study..."
- obj = naming_service.Resolve('Study')
+ if verbose(): print("looking for study...")
+ obj = naming_service.Resolve('/Study')
myStudy = obj._narrow(SALOMEDS.Study)
- if verbose(): print "Study found"
+ if verbose(): print("Study found")
pass
import types
- if theStudyPath and type(theStudyPath) == types.StringType:
+ if theStudyPath and isinstance(theStudyPath, (str, bytes)):
+ if isinstance(theStudyPath, bytes):
+ theStudyPath = str(theStudyPath, 'UTF8')
openStudy(theStudyPath)
+ else:
+ myStudy.Init()
myStudyName = myStudy._get_Name()
return myStudy, myStudyName
+
+def salome_study_close():
+ global myStudy, myStudyName
+ myStudy, myStudyName = None, None