p.join()
# Release port
- print "release port 2899"
- print("release port 2812")
- p = multiprocessing.Process(target=releasePort, args=(2812,))
++ print ("release port 2899")
+ p = multiprocessing.Process(target=releasePort, args=(2899,))
p.start()
p.join()
except:
pass
- if verbose(): print "Name Service... "
- if verbose(): print("Name Service... ", end=' ')
- #hname=os.environ["HOST"] #commands.getoutput("hostname")
- if sys.platform == "win32":
- hname = getShortHostName();
- else:
- hname = socket.gethostname();
- # print("hname=",hname)
++ if verbose(): print("Name Service... ", end =' ')
+ hname = getHostName()
with open(os.environ["OMNIORB_CONFIG"]) as f:
ss = re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
try:
res = getattr(self, command)(options) # run appropriate method
- return res or (None, None)
+ return res or 0
- except SystemExit, returncode:
+ except SystemExit as returncode:
if returncode != 0:
- self.getLogger().warning("SystemExit %s in method %s.", returncode, command)
+ self.getLogger().error("SystemExit %s in method %s.", returncode, command)
return returncode
- except StandardError:
- except SalomeContextException as e:
- self.getLogger().error(e)
- return 1
+ except Exception:
self.getLogger().error("Unexpected error:")
import traceback
traceback.print_exc()
return 1
- except SalomeContextException, e:
++ except SalomeContextException as e:
+ self.getLogger().error(e)
+ return 1
#
def __setContextFromConfigFile(self, filename, reserved=None):
if __name__ == "__main__":
if len(sys.argv) == 3:
- context = pickle.loads(sys.argv[1])
- args = pickle.loads(sys.argv[2])
+ context = pickle.loads(sys.argv[1].encode())
+ args = pickle.loads(sys.argv[2].encode())
- context._startSalome(args)
+ status = context._startSalome(args)
+ sys.exit(status)
else:
usage()
#
#file = "/tmp/ggg.hdf"
- print " ------- We will save to", file, "-----------"
+ 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!"
A = A._narrow(SALOMEDS.AttributeSequenceOfInteger)
if A.Length() != 4:
- print "Wrong length of SequenceOfInteger"
+ print("Wrong length of SequenceOfInteger")
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"
+ 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!"
# ---- create Hypothesis
- print "-------------------------- create Hypothesis ----------------------"
- print "-------------------------- LocalLength"
+ 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()
- print hypLen1.GetId()
- print hypLen1.GetLength()
+ print(hypLen1.GetName())
+ print(hypLen1.GetId())
+ print(hypLen1.GetLength())
idlength = batchmode_smesh.AddNewHypothesis( orb.object_to_string(hypLen1) );
batchmode_smesh.SetName(idlength, "Local_Length_100");
- print "-------------------------- NumberOfSegments"
+ 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()
- print hypNbSeg1.GetId()
- print hypNbSeg1.GetNumberOfSegments()
+ print(hypNbSeg1.GetName())
+ print(hypNbSeg1.GetId())
+ print(hypNbSeg1.GetNumberOfSegments())
idseg = batchmode_smesh.AddNewHypothesis( orb.object_to_string(hypNbSeg1) );
batchmode_smesh.SetName(idseg, "NumberOfSegments_7");
- print "-------------------------- MaxElementArea"
+ 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()
- print hypArea1.GetId()
- print hypArea1.GetMaxElementArea()
+ print(hypArea1.GetName())
+ print(hypArea1.GetId())
+ print(hypArea1.GetMaxElementArea())
idarea1 = batchmode_smesh.AddNewHypothesis( orb.object_to_string(hypArea1) );
batchmode_smesh.SetName(idarea1, "MaxElementArea_2500");
- print "-------------------------- MaxElementArea"
+ 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()
- print hypArea2.GetId()
- print hypArea2.GetMaxElementArea()
+ print(hypArea2.GetName())
+ print(hypArea2.GetId())
+ print(hypArea2.GetMaxElementArea())
idarea2 = batchmode_smesh.AddNewHypothesis( orb.object_to_string(hypArea2) );
batchmode_smesh.SetName(idarea2, "MaxElementArea_500");
- print "-------------------------- Regular_1D"
+ 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:
idreg = batchmode_smesh.AddNewAlgorithms( orb.object_to_string(algoReg) );
batchmode_smesh.SetName(idreg, "Regular_1D");
- print "-------------------------- MEFISTO_2D"
+ 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:
#==================================================
#1. SaveAs
#==================================================
- print " ------- We will save to", file, "-----------"
+ 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
#==================================================
#3. Open
#==================================================
- print " ------- We try to open " + str + "/test_dir/test_new.hdf"
+ 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!"
str = "/tmp"
file = str+"/test.hdf"
- print " ------- We will save to", file, "-----------"
+ print(" ------- We will save to", file, "-----------")
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file)
#--------------------------------------------------------------------------#
str = "/tmp"
file = str+"/test.hdf"
- print " ------- We will save to", file, "-----------"
+ print(" ------- We will save to", file, "-----------")
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file)
#--------------------------------------------------------------------------#
#---------------------------- Open file -----------------------------------#
str = "/tmp"
file = str+"/test.hdf"
- print " ------- We will save to", file, "-----------"
+ print(" ------- We will save to", file, "-----------")
-batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
+batchmode_geompy.myStudy.SaveAs(file)
#--------------------------------------------------------------------------#
#---------------------------- Open file -----------------------------------#
//=============================================================================
Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, const char* code)
{
- Engines::PyNode_var node= Engines::PyNode::_nil();
+ Engines::PyNode_var node= Engines::PyNode::_nil();
- PyGILState_STATE gstate = PyGILState_Ensure();
- PyObject *res = PyObject_CallMethod(_pyCont,
- (char*)"create_pynode",
- (char*)"ss",
- nodeName,
- code);
- if(res==NULL)
- {
- //internal error
- PyErr_Print();
- PyGILState_Release(gstate);
- SALOME::ExceptionStruct es;
- es.type = SALOME::INTERNAL_ERROR;
- es.text = "can not create a python node";
- throw SALOME::SALOME_Exception(es);
- }
- long ierr=PyLong_AsLong(PyTuple_GetItem(res,0));
- PyObject* result=PyTuple_GetItem(res,1);
- std::string astr=PyUnicode_AsUTF8(result);
- Py_DECREF(res);
+ PyGILState_STATE gstate = PyGILState_Ensure();
+ PyObject *res = PyObject_CallMethod(_pyCont,
+ (char*)"create_pynode",
+ (char*)"ss",
+ nodeName,
+ code);
+ if(res==NULL)
+ {
+ //internal error
+ PyErr_Print();
PyGILState_Release(gstate);
- if(ierr==0)
- {
- Utils_Locker lck(&_mutexForDftPy);
- CORBA::Object_var obj=_orb->string_to_object(astr.c_str());
- node=Engines::PyNode::_narrow(obj);
- std::map<std::string,Engines::PyNode_var>::iterator it(_dftPyNode.find(nodeName));
- if(it==_dftPyNode.end())
- {
- _dftPyNode[nodeName]=node;
- }
- else
- {
- Engines::PyNode_var oldNode((*it).second);
- if(!CORBA::is_nil(oldNode))
- oldNode->UnRegister();
- (*it).second=node;
- }
- if(!CORBA::is_nil(node))
- node->Register();
- return node._retn();
- }
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::INTERNAL_ERROR;
+ es.text = "can not create a python node";
+ throw SALOME::SALOME_Exception(es);
+ }
- long ierr=PyInt_AsLong(PyTuple_GetItem(res,0));
++ long ierr=PyLong_AsLong(PyTuple_GetItem(res,0));
+ PyObject* result=PyTuple_GetItem(res,1);
- std::string astr=PyString_AsString(result);
++ std::string astr=PyUnicode_AsUTF8(result);
+ Py_DECREF(res);
+ PyGILState_Release(gstate);
+ if(ierr==0)
+ {
+ Utils_Locker lck(&_mutexForDftPy);
+ CORBA::Object_var obj=_orb->string_to_object(astr.c_str());
+ node=Engines::PyNode::_narrow(obj);
+ std::map<std::string,Engines::PyNode_var>::iterator it(_dftPyNode.find(nodeName));
+ if(it==_dftPyNode.end())
+ {
+ _dftPyNode[nodeName]=node;
+ }
else
- {
- SALOME::ExceptionStruct es;
- es.type = SALOME::INTERNAL_ERROR;
- es.text = astr.c_str();
- throw SALOME::SALOME_Exception(es);
- }
+ {
+ Engines::PyNode_var oldNode((*it).second);
+ if(!CORBA::is_nil(oldNode))
+ oldNode->UnRegister();
+ (*it).second=node;
+ }
+ if(!CORBA::is_nil(node))
+ node->Register();
+ return node._retn();
+ }
+ else
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::INTERNAL_ERROR;
+ es.text = astr.c_str();
+ throw SALOME::SALOME_Exception(es);
+ }
}
//=============================================================================
//=============================================================================
Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* nodeName, const char* code)
{
- Engines::PyScriptNode_var node= Engines::PyScriptNode::_nil();
+ Engines::PyScriptNode_var node= Engines::PyScriptNode::_nil();
- PyGILState_STATE gstate = PyGILState_Ensure();
- PyObject *res = PyObject_CallMethod(_pyCont,
- (char*)"create_pyscriptnode",
- (char*)"ss",
- nodeName,
- code);
- if(res==NULL)
- {
- //internal error
- PyErr_Print();
- PyGILState_Release(gstate);
- SALOME::ExceptionStruct es;
- es.type = SALOME::INTERNAL_ERROR;
- es.text = "can not create a python node";
- throw SALOME::SALOME_Exception(es);
- }
- long ierr=PyLong_AsLong(PyTuple_GetItem(res,0));
- PyObject* result=PyTuple_GetItem(res,1);
- std::string astr=PyUnicode_AsUTF8(result);
- Py_DECREF(res);
+ PyGILState_STATE gstate = PyGILState_Ensure();
+ PyObject *res = PyObject_CallMethod(_pyCont,
+ (char*)"create_pyscriptnode",
+ (char*)"ss",
+ nodeName,
+ code);
+ if(res==NULL)
+ {
+ //internal error
+ PyErr_Print();
PyGILState_Release(gstate);
- long ierr=PyInt_AsLong(PyTuple_GetItem(res,0));
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::INTERNAL_ERROR;
+ es.text = "can not create a python node";
+ throw SALOME::SALOME_Exception(es);
+ }
- std::string astr=PyString_AsString(result);
++ long ierr=PyLong_AsLong(PyTuple_GetItem(res,0));
+ PyObject* result=PyTuple_GetItem(res,1);
++ std::string astr=PyUnicode_AsUTF8(result);
+ Py_DECREF(res);
+ PyGILState_Release(gstate);
- if(ierr==0)
- {
- Utils_Locker lck(&_mutexForDftPy);
- CORBA::Object_var obj=_orb->string_to_object(astr.c_str());
- node=Engines::PyScriptNode::_narrow(obj);
- std::map<std::string,Engines::PyScriptNode_var>::iterator it(_dftPyScriptNode.find(nodeName));
- if(it==_dftPyScriptNode.end())
- {
- _dftPyScriptNode[nodeName]=node;
- }
- else
- {
- Engines::PyScriptNode_var oldNode((*it).second);
- if(!CORBA::is_nil(oldNode))
- oldNode->UnRegister();
- (*it).second=node;
- }
- if(!CORBA::is_nil(node))
- node->Register();
- return node._retn();
- }
+ if(ierr==0)
+ {
+ Utils_Locker lck(&_mutexForDftPy);
+ CORBA::Object_var obj=_orb->string_to_object(astr.c_str());
+ node=Engines::PyScriptNode::_narrow(obj);
+ std::map<std::string,Engines::PyScriptNode_var>::iterator it(_dftPyScriptNode.find(nodeName));
+ if(it==_dftPyScriptNode.end())
+ {
+ _dftPyScriptNode[nodeName]=node;
+ }
else
- {
- SALOME::ExceptionStruct es;
- es.type = SALOME::INTERNAL_ERROR;
- es.text = astr.c_str();
- throw SALOME::SALOME_Exception(es);
- }
+ {
+ Engines::PyScriptNode_var oldNode((*it).second);
+ if(!CORBA::is_nil(oldNode))
+ oldNode->UnRegister();
+ (*it).second=node;
+ }
+ if(!CORBA::is_nil(node))
+ node->Register();
+ return node._retn();
+ }
+ else
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::INTERNAL_ERROR;
+ es.text = astr.c_str();
+ throw SALOME::SALOME_Exception(es);
+ }
}
//=============================================================================
#-------------------------------------------------------------------------
- def create_component_instance_env(self, componentName, studyId, env):
- return self.create_component_instance(componentName, studyId), ""
+ def create_component_instance_env(self, componentName, env):
+ return self.create_component_instance(componentName), ""
- 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_" + repr(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(self, componentName):
+ MESSAGE( "SALOME_ContainerPy_i::create_component_instance ==> " + str(componentName) )
+ self._numInstance = self._numInstance +1
- instanceName = componentName + "_inst_" + `self._numInstance`
++ instanceName = componentName + "_inst_" + repr(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()
+ keysList = list(self._listInstances_map.keys())
i = 0
while i < len(keysList):
instance = keysList[i]
methods : defined in SALOMEDS.idl
methods:
- salome.DumpStudy(study) : Dump a study, given the ior
+ salome.DumpStudy() : Dump a study, given the ior
---
'''
- print doc_salome
+ print(doc_salome)
def geompy(self):
doc_geompy = '''
while ofs <= offset:
a = a + " "
ofs = ofs +1
- print a + ">" + RefSO.GetID()
+ print(a + ">" + RefSO.GetID())
- DumpComponent(Study, CSO, offset+2)
+ DumpComponent(CSO, offset+2)
#--------------------------------------------------------------------------
SC = itcomp.Value()
itcomp.Next()
name = SC.ComponentDataType()
- print "-> ComponentDataType is " + name
+ print("-> ComponentDataType is " + name)
- DumpComponent(Study, SC, 1)
+ DumpComponent(SC, 1)
#--------------------------------------------------------------------------
#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
+ 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_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:
+ except RuntimeError as inst:
# wait a little to avoid trace mix
import time
time.sleep(0.2)
while aRoot.GetID() != "0:":
aRoot = aRoot.GetFather()
aTree = GetTree(aRoot)
- if not myStudyManager.CanCopy(theSO):
+ aStudyPersist = PersistentPresentation(aRoot, 1)
+
+ aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
+
- raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
+ 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"
+ raise RuntimeError("<Copy> for "+theInfo+" returns false")
- if not myStudyManager.CanPaste(theSO):
+ 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(myStudy, aRoot, 1):
+ 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 myStudyManager.Paste(aSObj) == None:
+ 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):
time.sleep(sleeping_time)
sleeping_time = max(sleeping_time_max, 2*sleeping_time)
pass
--
-myStudyManager = obj._narrow(SALOMEDS.StudyManager)
-
-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)
+
-myStudyName = myStudy._get_Name()
+myStudy = obj._narrow(SALOMEDS.Study)
-myStudyId = myStudy._get_StudyId()
-# print(myStudyId)
+
+if myStudy is None:
- print "Warning: SALOMEDS.Study has not been created !!!"
++ print("Warning: SALOMEDS.Study has not been created !!!")
+
+myStudyName = myStudy._get_Name()
obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
if not catalog:
- raise RuntimeError, "Can't accesss module catalog"
+ 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 )
import re
- import salome
- from salome.kernel.logger import Logger
from salome.kernel import termcolor
- logger = Logger("salome.kernel.studyedit", color = termcolor.PURPLE)
+ from salome.kernel.logger import Logger
+ import salome
+
+
+ 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.
+## 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 studyId not in _editors:
- _editors[studyId] = StudyEditor(studyId)
- return _editors[studyId]
+ global _editor
+ 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
"""Indicate if GUI is running"""
return False
- def updateObjBrowser(self, bid):
+ def updateObjBrowser(self):
"""update the GUI object browser"""
- print "SalomeOutsideGUI: no objectBrowser update outside GUI"
+ 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"
++ print("SalomeOutsideGUI.getStudyName: avoid use outside GUI")
return myStudyName
def SelectedCount(self):
find,RefSO = CSO.ReferencedObject()
if find:
a=a+":"+RefSO.GetID()
- print a
+ print(a)
- DumpComponent(Study, CSO, Builder,offset+2)
+ 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(Study, SC,Builder, 1)
+ DumpComponent(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):
while aRoot.GetID() != "0:":
aRoot = aRoot.GetFather()
aTree = GetTree(aRoot)
- aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
+ aStudyPersist = PersistentPresentation(aRoot, 1)
- if not myStudyManager.CanCopy(theSO):
+ if not myStudy.CanCopy(theSO):
- raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
+ raise RuntimeError("<CanCopy> for "+theInfo+" returns false")
- if not myStudyManager.Copy(theSO):
+ if not myStudy.Copy(theSO):
- raise RuntimeError, "<Copy> for "+theInfo+" returns false"
+ raise RuntimeError("<Copy> for "+theInfo+" returns false")
- if not myStudyManager.CanPaste(theSO):
+ 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(myStudy, aRoot, 1):
+ 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 myStudyManager.Paste(aSObj) == None:
+ 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):
#--------------------------------------------------------------------------
-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.
-
- :param theStudy: the study CORBA object to set as current study
-
- Obsolete: only one study can be opened at the moment.
- This function works properly if specified theStudy parameter
- corresponds to the currently opened study.
- Kept for backward compatibility only.
- """
- global myStudyId, myStudy, myStudyName
- global salome_study_ID
- 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
-
- #--------------------------------------------------------------------------
-
def openStudy(theStudyPath):
- print "openStudy"
- global myStudyManager
+ print("openStudy")
- theStudy = myStudyManager.Open(theStudyPath)
- theStudyId = theStudy._get_StudyId()
- print(theStudyPath, theStudyId)
- return theStudyId
+ global myStudy, myStudyName
+ myStudy.Open(theStudyPath)
+ myStudyName = myStudy._get_Name()
- print theStudyPath, myStudy._get_Name()
++ print(theStudyPath, myStudy._get_Name())
#--------------------------------------------------------------------------
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 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..."
++ 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
- # get active study Id, ref and name
- myStudy = None
- myStudyId = getActiveStudy()
- if myStudyId == None :
- import types
- if theStudyPath and (type(theStudyPath) == bytes or type(theStudyPath) == str):
- myStudyId = openStudy(theStudyPath)
- else:
- myStudyId = createNewStudy()
- if verbose(): print("myStudyId", myStudyId)
-
- if myStudy == None:
- myStudy = myStudyManager.GetStudyByID(myStudyId)
- myStudyName = myStudy._get_Name()
+ import types
+ if theStudyPath and type(theStudyPath) == types.StringType:
+ openStudy(theStudyPath)
- return myStudyManager, myStudyId, myStudy, myStudyName
+ myStudyName = myStudy._get_Name()
-def salome_study_close():
- global salome_study_ID
- global myStudyId, myStudy, myStudyName
- salome_study_ID = -1
- myStudyId, myStudy, myStudyName = None, None, None
- pass
+ return myStudy, myStudyName
obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
if not catalog:
- raise RuntimeError, "Can't accesss module catalog"
- print "OK"
+ raise RuntimeError("Can't accesss module catalog")
+ print("OK")
- print
+ print()
- print "======================================================================"
- print " %d. Check modules availability in the module catalog " % step; step+=1
- print "======================================================================"
+ print("======================================================================")
+ print(" %d. Check modules availability in the module catalog " % step); step+=1
+ print("======================================================================")
for module in [ "GEOM", "SMESH", "MEDFactory", "PVSERVER"]:
- print
- print "--- Check %s ..." % module
+ print()
+ print("--- Check %s ..." % module)
comp = catalog.GetComponent(module)
if not comp:
- raise RuntimeError, "Component %s is not found in Module Catalog." % module
- print "OK"
+ raise RuntimeError("Component %s is not found in Module Catalog." % module)
+ print("OK")
pass
- print
+ print()
- print "======================================================================"
- print " %d. Test Data Server " % step; step+=1
- print "======================================================================"
+ print("======================================================================")
+ print(" %d. Test Data Server " % step); step+=1
+ print("======================================================================")
- print
- print "--- Create new component ..."
+ print()
+ print("--- Create new component ...")
comp = builder.NewComponent("TEST")
if not comp:
- raise RuntimeError, "Can't create new component"
- print "OK"
+ raise RuntimeError("Can't create new component")
+ print("OK")
- print
- print "--- Create AttributeName ..."
+ print()
+ print("--- Create AttributeName ...")
A = builder.FindOrCreateAttribute(comp, "AttributeName")
if not A:
- raise RuntimeError, "Can't create AttributeName attribute"
+ raise RuntimeError("Can't create AttributeName attribute")
A.SetValue("TEST")
if A.Value() != "TEST":
- raise RuntimeError, "Error : wrong value of AttributeName"
- print "OK"
+ raise RuntimeError("Error : wrong value of AttributeName")
+ print("OK")
- print
- print "--- Create AttributeReal ..."
+ print()
+ print("--- Create AttributeReal ...")
A = builder.FindOrCreateAttribute(comp, "AttributeReal")
if not A:
- raise RuntimeError, "Can't create AttributeReal attribute"
+ raise RuntimeError("Can't create AttributeReal attribute")
A.SetValue(0.0001)
if A.Value() != 0.0001:
- raise RuntimeError, "Error : wrong value of AttributeReal"
- print "OK"
+ raise RuntimeError("Error : wrong value of AttributeReal")
+ print("OK")
- print
+ print()
- print "======================================================================"
- print " %d. Test Geometry " % step; step+=1
- print "======================================================================"
+ print("======================================================================")
+ print(" %d. Test Geometry " % step); step+=1
+ print("======================================================================")
from salome.geom import geomBuilder
-geompy = geomBuilder.New(salome.myStudy)
+geompy = geomBuilder.New()
ShapeTypeCompSolid = 1
ShapeTypeSolid = 2
# ---- update object browser
if salome.hasDesktop():
- salome.sg.updateObjBrowser(True);
+ salome.sg.updateObjBrowser();
- print
+ print()
- print "======================================================================"
- print " %d. Test Mesh " % step; step+=1
- print "======================================================================"
+ print("======================================================================")
+ print(" %d. Test Mesh " % step); step+=1
+ print("======================================================================")
from salome.StdMeshers import StdMeshersBuilder
import SMESH
# ---- update object browser
if salome.hasDesktop():
- salome.sg.updateObjBrowser(True);
+ salome.sg.updateObjBrowser();
- print
+ print()
- print "======================================================================"
- print " %d. Test Med " % step; step+=1
- print "======================================================================"
+ print("======================================================================")
+ print(" %d. Test Med " % step); step+=1
+ print("======================================================================")
import medcalc
#from medcalc import properties
job_params.out_files = ["result.txt", "subdir"]
job_params.resource_required = salome.ResourceParameters()
job_params.resource_required.nb_proc = 1
-
+
launcher = salome.naming_service.Resolve('/SalomeLauncher')
-
+
for resource in self.ressources:
- print "Testing python_salome job on ", resource
+ print("Testing python_salome job on ", resource)
job_params.result_directory = local_result_dir + resource
job_params.job_name = "PyJob" + resource
job_params.resource_required.name = resource
launcher = salome.naming_service.Resolve('/SalomeLauncher')
resManager= salome.lcc.getResourcesManager()
-
+
for resource in self.ressources:
- print "Testing yacs job on ", resource
+ print("Testing yacs job on ", resource)
job_params.result_directory = local_result_dir + resource
job_params.job_name = "YacsJob_" + resource
job_params.resource_required.name = resource
launcher = salome.naming_service.Resolve('/SalomeLauncher')
resManager= salome.lcc.getResourcesManager()
-
+
for resource in self.ressources:
- print "Testing yacs job with options on ", resource
+ print("Testing yacs job with options on ", resource)
job_params.result_directory = local_result_dir + resource
job_params.job_name = "YacsJobOpt_" + resource
job_params.resource_required.name = resource
common_data["COMP_NAME"] = getParamValue("name", "", args)
common_data["COMP_UNAME"] = getParamValue("username", "", args)
common_data["COMP_TYPE"] = getParamValue("type", "OTHER", args)
- common_data["COMP_MULT"] = getParamValue("multistudy", "1", args)
common_data["COMP_IMPL"] = getParamValue("impltype", "1", args)
- print common_data
+ print(common_data)
remove_comp = getParamValue("remove", "", args)
if __name__ == "__main__":
- print
- print "Usage : omniidl -bIDLparser [-I<catalog files directory>]* -Wbcatalog=<my_catalog.xml>[,icon=<pngfile>][,version=<num>][,author=<name>][,name=<component_name>][,username=<component_username>][,impltype=<implementation type : 0 (python), 1 (C++)>] <file.idl>"
- print
+ print()
- print("Usage : omniidl -bIDLparser [-I<catalog files directory>]* -Wbcatalog=<my_catalog.xml>[,icon=<pngfile>][,version=<num>][,author=<name>][,name=<component_name>][,username=<component_username>][,multistudy=<component_multistudy>][,impltype=<implementation type : 0 (python), 1 (C++)>] <file.idl>")
++ print("Usage : omniidl -bIDLparser [-I<catalog files directory>]* -Wbcatalog=<my_catalog.xml>[,icon=<pngfile>][,version=<num>][,author=<name>][,name=<component_name>][,username=<component_username>][,impltype=<implementation type : 0 (python), 1 (C++)>] <file.idl>")
+ print()
sfp << "import sys" << std::endl;
sfp << "import " << aBatchModeScript << std::endl << std::endl;
- std::string aStudyVar = "salome.myStudy";
// initialization function
sfp << aBatchModeScript << ".salome_init()" << std::endl;
- if ( !isMultiFile ) {
- sfp << "theStudy = " << aStudyVar << std::endl << std::endl;
- aStudyVar = "theStudy";
- }
+
// notebook initialization
- sfp << _GetNoteBookAccess(aStudyVar) << std::endl;
+ sfp << _GetNoteBookAccess() << std::endl;
// extend sys.path with the directory where the script is being dumped to
- sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl;
+ sfp << "sys.path.insert(0, r\'" << thePath << "\')" << std::endl << std::endl;
// dump NoteBook variables
sfp << _GetStudyVariablesScript();