if session_server:
session = clt.waitNS("/Kernel/Session")
catalog = clt.waitNS("/Kernel/ModulCatalog")
- studyMgr = clt.waitNS("/myStudyManager")
+ study = clt.waitNS("/Study")
import salome
salome.salome_init()
myServer=SalomeDSServer(args)
myServer.run()
if sys.platform == "win32":
- clt.waitNS("/myStudyManager")
+ clt.waitNS("/Study")
else:
- clt.waitNSPID("/myStudyManager",myServer.PID)
+ clt.waitNSPID("/Study",myServer.PID)
#
# Launch LauncherServer
print " ------- We will save to", file, "-----------"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy=batchmode_geompy.myStudyManager.Open(file)
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy=batchmode_geompy.myStudy.Open(file)
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy = batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy = batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy=batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy=batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy = batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy = batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy=batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy=batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy = batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy = batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy = batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy = batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
raise RuntimeError, "Wrong value of AttributeSequenceOfInteger"
file1 = dir + "/test1.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file1, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file1)
# 1st Undo ---------------------------------------
batchmode_geompy.myBuilder.Undo()
raise RuntimeError, "Wrong value of AttributeSequenceOfInteger after the first 'undo'!"
# save
file2 = dir + "/test2.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file2, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file2)
#-------------------------------------------------
# 2nd Undo ---------------------------------------
batchmode_geompy.myBuilder.Undo()
if res !=0 or attr != None :
raise RuntimeError, "After the second 'undo' AttributeSequenceOfInteger exists but must not!"
file3 = dir + "/test3.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file3, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file3)
#-------------------------------------------------
#make redo twice ---------------------------------
#----------------------------------------------------------------------
-openedStudy=batchmode_geompy.myStudyManager.Open(file1);
+openedStudy=batchmode_geompy.myStudy.Open(file1);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
if A.Value(1) != 100 or A.Value(2) != 300 or A.Value(3) != 400 or A.Value(4) != 500:
print "Wrong value of AttributeSequenceOfInteger"
#----------------------------------------------------------------------
-openedStudy=batchmode_geompy.myStudyManager.Open(file2);
+openedStudy=batchmode_geompy.myStudy.Open(file2);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
raise RuntimeError, "Wrong value of AttributeSequenceOfInteger after the first 'undo'!"
#----------------------------------------------------------------------
-openedStudy=batchmode_geompy.myStudyManager.Open(file3);
+openedStudy=batchmode_geompy.myStudy.Open(file3);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
smesh = batchmode_smesh.smesh
# -- Init --
shape = batchmode_geompy.IDToObject(idbox)
-mesh=smesh.Init(geom, batchmode_geompy.myStudyId, shape)
+mesh=smesh.Init(geom, shape)
orb = batchmode_geompy.orb
print "-------------------------- create Hypothesis ----------------------"
print "-------------------------- LocalLength"
-hyp1 = smesh.CreateHypothesis("LocalLength", batchmode_geompy.myStudyId )
+hyp1 = smesh.CreateHypothesis("LocalLength")
hypLen1 = hyp1._narrow(SMESH.SMESH_LocalLength)
hypLen1.SetLength(100)
print hypLen1.GetName()
batchmode_smesh.SetName(idlength, "Local_Length_100");
print "-------------------------- NumberOfSegments"
-hyp2 = smesh.CreateHypothesis("NumberOfSegments", batchmode_geompy.myStudyId )
+hyp2 = smesh.CreateHypothesis("NumberOfSegments")
hypNbSeg1=hyp2._narrow(SMESH.SMESH_NumberOfSegments)
hypNbSeg1.SetNumberOfSegments(7)
print hypNbSeg1.GetName()
batchmode_smesh.SetName(idseg, "NumberOfSegments_7");
print "-------------------------- MaxElementArea"
-hyp3 = smesh.CreateHypothesis("MaxElementArea", batchmode_geompy.myStudyId)
+hyp3 = smesh.CreateHypothesis("MaxElementArea")
hypArea1=hyp3._narrow(SMESH.SMESH_MaxElementArea)
hypArea1.SetMaxElementArea(2500)
print hypArea1.GetName()
batchmode_smesh.SetName(idarea1, "MaxElementArea_2500");
print "-------------------------- MaxElementArea"
-hyp3 = smesh.CreateHypothesis("MaxElementArea", batchmode_geompy.myStudyId)
+hyp3 = smesh.CreateHypothesis("MaxElementArea")
hypArea2 = hyp3._narrow(SMESH.SMESH_MaxElementArea)
hypArea2.SetMaxElementArea(500)
print hypArea2.GetName()
batchmode_smesh.SetName(idarea2, "MaxElementArea_500");
print "-------------------------- Regular_1D"
-alg1 = smesh.CreateHypothesis("Regular_1D", batchmode_geompy.myStudyId)
+alg1 = smesh.CreateHypothesis("Regular_1D")
algo1 = alg1._narrow(SMESH.SMESH_Algo)
listHyp = algo1.GetCompatibleHypothesis()
for hyp in listHyp:
batchmode_smesh.SetName(idreg, "Regular_1D");
print "-------------------------- MEFISTO_2D"
-alg2 = smesh.CreateHypothesis("MEFISTO_2D", batchmode_geompy.myStudyId)
+alg2 = smesh.CreateHypothesis("MEFISTO_2D")
algo2 = alg2._narrow(SMESH.SMESH_Algo)
listHyp=algo2.GetCompatibleHypothesis()
for hyp in listHyp:
#==================================================
print " ------- We will save to", file, "-----------"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-batchmode_geompy.myStudyManager.Close(batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file)
+batchmode_geompy.myStudy.Clear()
#rename the file and try to reread it again
print " ------- We try to open " + str + "/test_dir/test_new.hdf"
try:
- openedStudy=batchmode_geompy.myStudyManager.Open(str+"/test_dir/test_new.hdf")
+ openedStudy=batchmode_geompy.myStudy.Open(str+"/test_dir/test_new.hdf")
except Exception:
raise RuntimeError, "Can't open saved study!"
#==================================================
#4. Save
#==================================================
-batchmode_geompy.myStudyManager.Save(openedStudy)
-batchmode_geompy.myStudyManager.Close(openedStudy)
+batchmode_geompy.myStudy.Save()
+batchmode_geompy.myStudy.Clear()
#==================================================
#5. Open
#==================================================
try:
- openedStudy = batchmode_geompy.myStudyManager.Open(str+"/test_dir/test_new.hdf")
+ openedStudy = batchmode_geompy.myStudy.Open(str+"/test_dir/test_new.hdf")
except Exception:
raise RuntimeError, "Can't open saved study!"
print " ------- We will save to", file, "-----------"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file)
#--------------------------------------------------------------------------#
print" -------------- Open " + file + "-------------- "
-openedStudy = batchmode_geompy.myStudyManager.Open(file)
+openedStudy = batchmode_geompy.myStudy.Open(file)
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
print " ------- We will save to", file, "-----------"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file)
#--------------------------------------------------------------------------#
#---------------------------- Open file -----------------------------------#
print" -------------- Open " + file + "-------------- "
-openedStudy=batchmode_geompy.myStudyManager.Open(file)
+openedStudy=batchmode_geompy.myStudy.Open(file)
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
print " ------- We will save to", file, "-----------"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file)
#--------------------------------------------------------------------------#
#---------------------------- Open file -----------------------------------#
print" -------------- Open " + file + "-------------- "
-openedStudy = batchmode_geompy.myStudyManager.Open(file)
+openedStudy = batchmode_geompy.myStudy.Open(file)
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy=batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy=batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
if str == None:
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy=batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy=batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy = batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy = batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy = batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy = batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy = batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy = batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy=batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy=batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
str = "/tmp"
file = str+"/test.hdf"
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
-openedStudy = batchmode_geompy.myStudyManager.Open(file);
+batchmode_geompy.myStudy.SaveAs(file)
+openedStudy = batchmode_geompy.myStudy.Open(file);
if openedStudy == None:
raise RuntimeError, "Can't open saved study!"
\b Note, that in the above example, \e "FactoryServer" is a name of the
SALOME container, where Geometry module engine should be loaded.
-\li \b myStudyManager Reference to the study manager
-
-SALOMEDS Study manager is used to manipulate with the studies: create,
-open, save, close. It also can be used to find the study by its
-numerical ID or name. The code below demonstrates main
-functionalities of a study manager:
-\code
-# create new study with the name "MyStudy"
-new_study = salome.myStudyManager.NewStudy("MyStudy")
-
-# open study from file /home/user/MyStudy.hdf
-study = salome.myStudyManager.OpenStudy("/home/user/MyStudy.hdf")
-
-# save study
-salome.myStudyManager.Save(study, False) # not using multifile save mode
-
-# save study in ASCII format
-salome.myStudyManager.SaveASCII(study, True) # using multifile save mode
-
-# save study with the new file path
-salome.myStudyManager.SaveAs("/home/user/MyStudy.hdf", study, False)
-
-# save study with the new file path in ASCII format
-salome.myStudyManager.SaveAsASCII("/home/user/MyStudy.hdf", study, False)
-
-# close study
-salome.myStudyManager.Close(study)
-
-# get list of all opened studies
-studies = salome.myStudyManager.GetOpenStudies()
-
-# find study by its numerical ID (integer value starting from 1)
-study = salome.myStudyManager.GetStudyByID(studyID)
-
-# find study by its name
-study = salome.myStudyManager.GetStudyByName("/home/user/MyStudy.hdf")
-
-# ...
-\endcode
-
\anchor salome_myStudy
\li \b myStudy Reference to the current (active) study
# get study name
studyName = salome.myStudy._get_Name()
-# get study numerical ID
-studyID = salome.myStudy._get_StudyId()
+# open study from file /home/user/MyStudy.hdf
+study = salome.myStudy.OpenStudy("/home/user/MyStudy.hdf")
+
+# save study
+salome.myStudy.Save(study, False) # not using multifile save mode
+
+# save study in ASCII format
+salome.myStudy.SaveASCII(study, True) # using multifile save mode
+
+# save study with the new file path
+salome.myStudy.SaveAs("/home/user/MyStudy.hdf", study, False)
+
+# save study with the new file path in ASCII format
+salome.myStudy.SaveAsASCII("/home/user/MyStudy.hdf", study, False)
+
+# clear study
+salome.myStudy.Clear()
# find SALOMEDS component by its type
scomponent = FindComponent("MyComponent")
# ...
\endcode
-\li \b myStudyId Identifier of the current (active) study
-
-This variable contains the numerical identifier of the current
-(active) study. It is an equivalent of \c
-salome.myStudy._get_StudyId() code.
-
\li \b myStudyName Name of the current (active) study
This variable contains the name of the current (active) study. It is
entry = ""
\endcode
-\li \b createNewStudy() Create new study
-
-This function can be used to create new SALOME study. Returns an ID of
-the created study.
-\code
-studyId = salome.createNewStudy()
-study = salome.myStudyManager.GetStudyByID(s)
-\endcode
-
\li \b generateName() Generate unique name
This function adds random numerical suffix to the passed string
extStudy_1.object
extStudy_2.object
extStudy_3.object
-myStudyManager.object
SalomeAppEngine.object
\endcode
\endcode
Import salome module. salome_init() without arguments creates a new study
-in the running session (note: salome_init(n) attachs to a running session whose
-studyId is n):
+in the running session:
\code
import salome
Warning: no internal registration is done, so it is up to the caller to
manage the various instanciation.
\param serviceName Name of the service
-
- >0 otherwise (== study id)
\param reason in case of error (return void string) a string explaining the error
\return the IOR of the loaded service.
*/
_orb = None
_poa = None
_fieldsDict = []
- _studyId = -1
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
- def getStudyId(self):
- return self._studyId
-
- #-------------------------------------------------------------------------
-
def hasObjectInfo(self):
return 0
#-------------------------------------------------------------------------
- def getObjectInfo(self, studyId, entry):
+ def getObjectInfo(self, entry):
return ""
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
- def create_component_instance_env(self, componentName, studyId, env):
- return self.create_component_instance(componentName, studyId), ""
-
- def create_component_instance(self, componentName, studyId):
- MESSAGE( "SALOME_ContainerPy_i::create_component_instance ==> " + str(componentName) + ' ' + str(studyId) )
- if studyId < 0:
- MESSAGE( "Study ID is lower than 0!" )
- return None
- else:
- self._numInstance = self._numInstance +1
- instanceName = componentName + "_inst_" + `self._numInstance`
- comp_iors=""
- try:
- component=__import__(componentName)
- factory=getattr(component,componentName)
- comp_i=factory(self._orb,
- self._poa,
- self._this(),
- self._containerName,
- instanceName,
- componentName)
-
- MESSAGE( "SALOME_Container_i::create_component_instance : OK")
- comp_o = comp_i._this()
- self._listInstances_map[instanceName] = comp_i
- except:
- import traceback
- traceback.print_exc()
- MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
- return comp_o
+ def create_component_instance_env(self, componentName, env):
+ return self.create_component_instance(componentName), ""
+
+ def create_component_instance(self, componentName):
+ MESSAGE( "SALOME_ContainerPy_i::create_component_instance ==> " + str(componentName) )
+ self._numInstance = self._numInstance +1
+ instanceName = componentName + "_inst_" + `self._numInstance`
+ comp_iors=""
+ try:
+ component=__import__(componentName)
+ factory=getattr(component,componentName)
+ comp_i=factory(self._orb,
+ self._poa,
+ self._this(),
+ self._containerName,
+ instanceName,
+ componentName)
+
+ MESSAGE( "SALOME_Container_i::create_component_instance : OK")
+ comp_o = comp_i._this()
+ self._listInstances_map[instanceName] = comp_i
+ except:
+ import traceback
+ traceback.print_exc()
+ MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
+ return comp_o
#-------------------------------------------------------------------------
- def find_component_instance(self, registeredName, studyId):
+ def find_component_instance(self, registeredName):
anEngine = None
keysList = self._listInstances_map.keys()
i = 0
instance = keysList[i]
if find(instance,registeredName) == 0:
anEngine = self._listInstances_map[instance]
- if studyId == anEngine.getStudyId():
- return anEngine._this()
+ return anEngine._this()
i = i + 1
return anEngine._this()
salome.sg
methods:
updateObjBrowser(bool):
- getActiveStudyId():
- getActiveStudyName():
+ getStudyName():
SelectedCount(): returns number of selected objects
getSelected(i): returns entry of selected object number i
IDToObject(Entry): returns CORBA reference from entry
- salome.myStudyName : active Study Name
- salome.myStudyId : active Study Id
+ salome.myStudyName : the Study Name
salome.myStudy : the active Study itself (CORBA ior)
methods : defined in SALOMEDS.idl
#create an naming service instance
naming_service = SALOME_NamingServicePy_i(orb)
-# get active study name and id
-myStudyName = sg.getActiveStudyName()
+# get active study name
+myStudyName = sg.getStudyName()
print myStudyName
-myStudyId = sg.getActiveStudyId()
-print myStudyId
-
-# get Study Manager reference
-obj = naming_service.Resolve('myStudyManager')
-myStudyManager = obj._narrow(SALOMEDS.StudyManager)
-
-# get active study
-myStudy = myStudyManager.GetStudyByName(myStudyName)
+# get Study reference
+obj = naming_service.Resolve('Study')
+myStudy = obj._narrow(SALOMEDS.Study)
- salome.sg : salome object to communicate with the graphical user interface (if any)
- methods:
- updateObjBrowser(bool):
- - getActiveStudyId():
- - getActiveStudyName():
- SelectedCount(): returns number of selected objects
- getSelected(i): returns entry of selected object number i
- IDToObject(Entry): returns CORBA reference from entry
- salome.myStudyName : active Study Name
- - salome.myStudyId : active Study Id
- salome.myStudy : the active Study itself (CORBA ior)
- methods : defined in SALOMEDS.idl
# \param salome.lcc : instance of lifeCycleCORBA class (SALOME_LifeCycleCORBA)
# \param salome.sg : Salome object to communicate with the graphical user interface, if running (see interface in salome_iapp::SalomeOutsideGUI)
# \param salome.myStudyName : active Study Name
-# \param salome.myStudyId : active Study Id
# \param salome.myStudy : the active Study (interface SALOMEDS::Study)
#
# pass
orb, lcc, naming_service, cm,sg=None,None,None,None,None
-myStudyManager, myStudyId, myStudy, myStudyName=None,None,None,None
-
-def setCurrentStudy(theStudy):
- """
- Change current study : an existing one given by a study object.
-
- :param theStudy: the study CORBA object to set as current study
- """
- global myStudyId, myStudy, myStudyName
- myStudyId, myStudy, myStudyName =salome_study.setCurrentStudy(theStudy)
-
-def setCurrentStudyId(theStudyId=0):
- """
- Change current study : an existing or new one given by Id.
-
- :param theStudyId: the study Id (optional argument)
- 0 : create a new study (default).
- n (>0) : try connection to study with Id = n, or create a new one
- if study not found.
- """
- global myStudyId, myStudy, myStudyName
- myStudyId, myStudy, myStudyName =salome_study.setCurrentStudyId(theStudyId)
+myStudy, myStudyName=None,None
salome_initial=1
-def salome_init(theStudyId=0,embedded=0):
+def salome_init(embedded=0):
"""
Performs only once SALOME general purpose intialisation for scripts.
- 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.
- If study creation, its Id may be different from theStudyId !
Provides:
orb reference to CORBA
lcc a LifeCycleCorba instance
naming_service a naming service instance
cm reference to the container manager
sg access to SALOME GUI (when linked with IAPP GUI)
- myStudyManager the study manager
- myStudyId active study identifier
myStudy active study itself (CORBA reference)
myStudyName active study name
"""
global salome_initial
global orb, lcc, naming_service, cm
global sg
- global myStudyManager, myStudyId, myStudy, myStudyName
+ global myStudy, myStudyName
try:
if salome_initial:
salome_initial=0
sg = salome_iapp_init(embedded)
orb, lcc, naming_service, cm = salome_kernel_init()
- myStudyManager, myStudyId, myStudy, myStudyName = salome_study_init(theStudyId)
+ myStudy, myStudyName = salome_study_init()
pass
pass
except RuntimeError, inst:
raise
def salome_close():
- global salome_initial, myStudy, myStudyId, myStudyName
+ global salome_initial, myStudy, myStudyName
try:
- # study can be closed either from GUI or directly with salome.myStudy.Close()
- myStudy.Close()
+ # study can be clear either from GUI or directly with salome.myStudy.Clear()
+ myStudy.Clear()
except:
pass
salome_initial=1
salome_iapp_close()
salome_study_close()
- myStudyId, myStudy, myStudyName=None,None,None
+ myStudy, myStudyName=None,None
pass
aTree = GetTree(aRoot)
aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
- if not myStudyManager.CanCopy(theSO):
+ if not myStudy.CanCopy(theSO):
raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
- if not myStudyManager.Copy(theSO):
+ if not myStudy.Copy(theSO):
raise RuntimeError, "<Copy> for "+theInfo+" returns false"
- if not myStudyManager.CanPaste(theSO):
+ if not myStudy.CanPaste(theSO):
raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
# check: before paste study is not changed check
if theComponentPaste:
aSObj = theSO.GetFatherComponent()
theInfo = theInfo + "(paste for component)"
- if myStudyManager.Paste(aSObj) == None:
+ if myStudy.Paste(aSObj) == None:
raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
aNewTree = GetTree(aRoot)
aLen = len(aTree)
#create a naming service instance
naming_service = SALOME_NamingServicePy_i(orb)
-# get Study Manager reference
+# get Study reference
obj = None
step = 0
sleeping_time = 0.01
sleeping_time_max = 1.0
while 1:
- obj = naming_service.Resolve('myStudyManager')
+ obj = naming_service.Resolve('Study')
if obj is not None:break
step = step + 1
if step > 100: break
sleeping_time = max(sleeping_time_max, 2*sleeping_time)
pass
-myStudyManager = obj._narrow(SALOMEDS.StudyManager)
+myStudy = obj._narrow(SALOMEDS.Study)
-if myStudyManager is None:
- print "Warning: SALOMEDS.StudyManager has not been created !!!"
-
-# create new study
-aListOfOpenStudies = myStudyManager.GetOpenStudies();
-myStudy = None;
-if len(aListOfOpenStudies) == 0 :
- myStudy = myStudyManager.NewStudy("Study1")
-else:
- myStudyName = aListOfOpenStudies[0]
- myStudy = myStudyManager.GetStudyByName(myStudyName)
+if myStudy is None:
+ print "Warning: SALOMEDS.Study has not been created !!!"
myStudyName = myStudy._get_Name()
-
-myStudyId = myStudy._get_StudyId()
-#print myStudyId
-
:return: the newly created SObject.
"""
- studyId = fatherSobj.GetStudy()._get_StudyId()
- editor = getStudyEditor(studyId)
+ editor = getStudyEditor()
sobj = editor.createItem(fatherSobj,
name = name,
icon = icon,
other parameters.
"""
- studyId = sobj.GetStudy()._get_StudyId()
- editor = getStudyEditor(studyId)
+ editor = getStudyEditor()
editor.setItem(sobj, name = name, icon = icon, typeId = typeId)
editor.builder.RemoveAttribute(sobj, "AttributeParameter")
_setSObjectForExchangeVariables(editor, sobj, exchangeVariables)
# Note that the salome module provides you with standard SALOME
# objects: CORBA broker (orb): salome.orb lyfe cycle (lcc) :
-# salome.lcc naming service : salome.naming_service study manager :
-# salome.myStudyManager The default study : salome.myStudy
+# salome.lcc naming service : salome.naming_service
+# The default study : salome.myStudy
#
# Alternatively, you may obtain these objects directly with the
# following instructions:
raise RuntimeError, "Can't accesss module catalog"
return catalog.GetComponentList()
-## Get a study manager to create and manage %SALOME studies
-# \ingroup service
-def getStudyManager():
- """Get a study manager to create and manage SALOME studies"""
- return salome.myStudyManager
-
import SALOMEDS
-## Get a study manager to create and manage SALOME studies.
-# \warning you should use instead the variable salome.myStudyManager.
+## Get a study to create SALOME study.
+# \warning you should use instead the variable salome.myStudy.
# This function is given for illustration of usage of the naming service
# \ingroup service
-def __getStudyManager_demo():
+def __getStudy_demo():
"""
- Get a study manager to create and manage SALOME studies. WARN: you
- should use instead the variable salome.myStudyManager. This
+ Get a study to create SALOME study. WARN: you
+ should use instead the variable salome.myStudy. This
function is given for illustration of usage of the naming service
"""
naming_service = SALOME_NamingServicePy_i( orb )
- obj = naming_service.Resolve( '/myStudyManager' )
- studyManager = obj._narrow( SALOMEDS.StudyManager)
- return studyManager
+ obj = naming_service.Resolve( '/Study' )
+ study = obj._narrow( SALOMEDS.Study)
+ return study
#
from salome.kernel import termcolor
logger = Logger("salome.kernel.studyedit", color = termcolor.PURPLE)
-_editors = {}
+_editor = None
_DEFAULT_CONTAINER = "FactoryServer"
# The codec to use for strings that are displayed in Salome study tree is Latin-1
ENCODING_FOR_SALOME_STUDY = "iso-8859-1"
-## Return the ID of the active study. In GUI mode, this function is equivalent
-# to salome.sg.getActiveStudyId(). Outside GUI, it returns <b> salome.myStudyId </b>
-# variable.
-# \ingroup studyedit
-def getActiveStudyId():
- """
- Return the ID of the active study. In GUI mode, this function is equivalent
- to ``salome.sg.getActiveStudyId()``. Outside GUI, it returns
- ``salome.myStudyId`` variable.
- """
- salome.salome_init()
- # Warning: we don't use salome.getActiveStudy() here because it doesn't
- # work properly when called from Salome modules (multi-study interpreter
- # issue)
- if salome.hasDesktop():
- return salome.sg.getActiveStudyId()
- else:
- return salome.myStudyId
-
-def getActiveStudy():
- return getStudyFromStudyId(getActiveStudyId())
-
-def getStudyFromStudyId(studyId):
- salome.salome_init()
- study = salome.myStudyManager.GetStudyByID(studyId)
- return study
-
-def getStudyIdFromStudy(study):
- studyId = study._get_StudyId()
- return studyId
-
-## Return a \b StudyEditor instance to edit the study with ID studyId.
-# If \b studyId is \b None, return an editor for the current study.
+def getStudy():
+ return salome.myStudy
+
+## Return a \b StudyEditor instance to edit the study.
# \ingroup studyedit
-def getStudyEditor(studyId = None):
+def getStudyEditor():
"""
- Return a :class:`StudyEditor` instance to edit the study with ID
- `studyId`. If `studyId` is :const:`None`, return an editor for the current
- study.
+ Return a :class:`StudyEditor` instance to edit the study.
"""
- if studyId is None:
- studyId = getActiveStudyId()
- if not _editors.has_key(studyId):
- _editors[studyId] = StudyEditor(studyId)
- return _editors[studyId]
+ if _editor is None:
+ _editor = StudyEditor()
+ return _editor
## This class provides utility methods to complement \b Study and
# \b StudyBuilder classes. Those methods may be moved in those classes
-# in the future. The parameter \b studyId defines the ID of the study to
-# edit. If it is \em None, the edited study will be the current study.
+# in the future.
# The preferred way to get a StudyEditor object is through the method
# \b getStudyEditor which allows to reuse existing instances.
#
-# \param studyId This instance attribute contains the ID of the edited study.
-# This attribute should not be modified.
-#
# \param study This instance attribute contains the underlying \b Study object.
# It can be used to access the study but the attribute itself should not
# be modified.
"""
This class provides utility methods to complement :class:`Study` and
:class:`StudyBuilder` classes. Those methods may be moved in those classes
- in the future. The parameter `studyId` defines the ID of the study to
- edit. If it is :const:`None`, the edited study will be the current study.
+ in the future.
The preferred way to get a StudyEditor object is through the method
:meth:`getStudyEditor` which allows to reuse existing instances.
- .. attribute:: studyId
-
- This instance attribute contains the ID of the edited study. This
- attribute should not be modified.
-
.. attribute:: study
This instance attribute contains the underlying :class:`Study` object.
should not be modified.
"""
- def __init__(self, studyId = None):
+ def __init__(self):
salome.salome_init()
- if studyId is None:
- studyId = getActiveStudyId()
- self.studyId = studyId
- self.study = salome.myStudyManager.GetStudyByID(studyId)
+ self.study = salome.myStudy
if self.study is None:
raise Exception("Can't create StudyEditor object: "
- "Study %d doesn't exist" % studyId)
+ "Study doesn't exist")
self.builder = self.study.NewBuilder()
## Find a component corresponding to the Salome module \b moduleName in
Provides a replacement for class SalomeGUI outside GUI process.
Do almost nothing
"""
- global myStudyId, myStudyName
+ global myStudyName
def hasDesktop(self):
"""Indicate if GUI is running"""
print "SalomeOutsideGUI: no objectBrowser update outside GUI"
pass
- def getActiveStudyId(self):
- """Get the active study id"""
- print "SalomeOutsideGUI.getActiveStudyId: avoid use outside GUI"
- return myStudyId
-
- def getActiveStudyName(self):
- """Get the active study name"""
- print "SalomeOutsideGUI.getActiveStudyName: avoid use outside GUI"
+ def getStudyName(self):
+ """Get the study name"""
+ print "SalomeOutsideGUI.getStudyName: avoid use outside GUI"
return myStudyName
def SelectedCount(self):
import salome_iapp
from launchConfigureParser import verbose
-myStudyManager = None
-myStudyId = None
myStudy = None
myStudyName = None
DumpComponent(Study, SC,Builder, 1)
itcomp.Next()
-def DumpStudies():
- """
- Dump all studies in a StudyManager
- """
- global myStudyManager
- for name in myStudyManager.GetOpenStudies():
- s = myStudyManager.GetStudyByName(name)
- print "study:",name, s._get_StudyId()
- DumpStudy(s)
-
-
#--------------------------------------------------------------------------
def IDToObject(id):
#--------------------------------------------------------------------------
def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
- global myStudyManager, myStudy
+ global myStudy
aRoot = theSO
while aRoot.GetID() != "0:":
aTree = GetTree(aRoot)
aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
- if not myStudyManager.CanCopy(theSO):
+ if not myStudy.CanCopy(theSO):
raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
- if not myStudyManager.Copy(theSO):
+ if not myStudy.Copy(theSO):
raise RuntimeError, "<Copy> for "+theInfo+" returns false"
- if not myStudyManager.CanPaste(theSO):
+ if not myStudy.CanPaste(theSO):
raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
# check: before paste study is not changed check
if theComponentPaste:
aSObj = theSO.GetFatherComponent()
theInfo = theInfo + "(paste for component)"
- if myStudyManager.Paste(aSObj) == None:
+ if myStudy.Paste(aSObj) == None:
raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
aNewTree = GetTree(aRoot)
aLen = len(aTree)
#--------------------------------------------------------------------------
-salome_study_ID = -1
-
-# *args are used here to support backward compatibility
-# previously it was possible to pass theStudyId parameter to this function
-# which is no more supported.
-def getActiveStudy(*args):
- global myStudyManager
- global salome_study_ID
-
- if not myStudyManager:
- print "No active study"
- return None
- pass
-
- if verbose(): print "getActiveStudy"
- if salome_study_ID == -1:
- listOpenStudies = myStudyManager.GetOpenStudies()
- if len(listOpenStudies) == 0:
- return None
- else:
- s = myStudyManager.GetStudyByName(listOpenStudies[0])
- salome_study_ID = s._get_StudyId()
- if verbose(): print"--- Study Id ", salome_study_ID
- return salome_study_ID
-
- #--------------------------------------------------------------------------
-
def setCurrentStudy(theStudy):
"""
Change current study : an existing one given by a study object.
corresponds to the currently opened study.
Kept for backward compatibility only.
"""
- global myStudyId, myStudy, myStudyName
- global salome_study_ID
+ global myStudy, myStudyName
myStudy = theStudy
- myStudyId = theStudy._get_StudyId()
myStudyName = theStudy._get_Name()
- return myStudyId, myStudy, myStudyName
-
- #--------------------------------------------------------------------------
-
-# *args are used here to support backward compatibility
-# previously it was possible to pass theStudyId parameter to this function
-# which is no more supported.
-def setCurrentStudyId(*args):
- """
- Change current study : an existing or new one.
-
- This function connects to the single opened study if there is any; otherwise
- new empty study is created.
-
- Obsolete: only one study can be opened at the moment.
- Kept for backward compatibility only.
- """
- global myStudyManager, myStudyId, myStudy, myStudyName
- global salome_study_ID
- salome_study_ID = -1
- myStudyId = getActiveStudy()
- if not myStudyId:
- myStudyId = createNewStudy()
- if verbose(): print "myStudyId",myStudyId
- myStudy = myStudyManager.GetStudyByID(myStudyId)
- myStudyName = myStudy._get_Name()
- return myStudyId, myStudy, myStudyName
-
- #--------------------------------------------------------------------------
-
-def createNewStudy():
- global myStudyManager
- print "createNewStudy"
- aStudyName = "extStudy"
- theStudy = myStudyManager.NewStudy(aStudyName)
- theStudyId = theStudy._get_StudyId()
- print aStudyName, theStudyId
- return theStudyId
+ return myStudy, myStudyName
#--------------------------------------------------------------------------
def openStudy(theStudyPath):
- global myStudyManager
+ global myStudy
print "openStudy"
- theStudy = myStudyManager.Open(theStudyPath)
- theStudyId = theStudy._get_StudyId()
- print theStudyPath, theStudyId
- return theStudyId
+ theStudy = myStudy.Open(theStudyPath)
+ theStudyName = theStudy._get_Name()
+ print theStudyPath, theStudyName
+ return theStudyName
+
+ #--------------------------------------------------------------------------
+def clearStudy():
+ global myStudy
+ print "clearStudy"
+ myStudy.Clear()
+ myStudy = None
+ pass
#--------------------------------------------------------------------------
create new empty study if there is active study
<URL> (str) : open study with the given file name
"""
- global myStudyManager, myStudyId, myStudy, myStudyName
+ global myStudy, myStudyName
global orb, lcc, naming_service, cm
if verbose(): print "theStudyPath:", theStudyPath
- if not myStudyManager:
+ if not myStudy:
orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init()
- # get Study Manager reference
- if verbose(): print "looking for studyManager ..."
- obj = naming_service.Resolve('myStudyManager')
- myStudyManager = obj._narrow(SALOMEDS.StudyManager)
- if verbose(): print "studyManager found"
+ # get Study reference
+ if verbose(): print "looking for study..."
+ obj = naming_service.Resolve('Study')
+ myStudy = obj._narrow(SALOMEDS.Study)
+ if verbose(): print "Study found"
pass
- # get active study Id, ref and name
- myStudy = None
- myStudyId = getActiveStudy()
- if myStudyId == None :
- import types
- if theStudyPath and type(theStudyPath) == types.StringType:
- myStudyId = openStudy(theStudyPath)
- else:
- myStudyId = createNewStudy()
- if verbose(): print "myStudyId", myStudyId
-
- if myStudy == None:
- myStudy = myStudyManager.GetStudyByID(myStudyId)
+ # get study name
myStudyName = myStudy._get_Name()
- return myStudyManager, myStudyId, myStudy, myStudyName
+ return myStudy, myStudyName
def salome_study_close():
- global salome_study_ID
- global myStudyId, myStudy, myStudyName
- salome_study_ID = -1
- myStudyId, myStudy, myStudyName = None, None, None
+ global myStudy, myStudyName
+ myStudy, myStudyName = None, None
pass
smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
if salome.hasDesktop():
smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(salome.myStudyId);
+ smeshgui.Init();
else:
smesh = smeshBuilder.New(salome.myStudy)
# job script
script_text = """<?xml version='1.0' encoding='iso-8859-1' ?>
<proc name="newSchema_1">
- <property name="DefaultStudyID" value="1"/>
<container name="DefaultContainer">
<property name="container_kind" value="Salome"/>
<property name="attached_on_cloning" value="0"/>
# job script
script_text = """<?xml version='1.0' encoding='iso-8859-1' ?>
<proc name="myschema">
- <property name="DefaultStudyID" value="1"/>
<type name="string" kind="string"/>
<type name="bool" kind="bool"/>
<type name="double" kind="double"/>