for aKey in ("containers","embedded","key","modules","standalone"):
if not args.has_key(aKey):
args[aKey]=[]
-for aKey in ("gui","logger","file","xterm","portkill","killall"):
+for aKey in ("gui","logger","file","xterm","portkill","killall","interp"):
if not args.has_key(aKey):
args[aKey]=0
if args["file"]:
opterror=0
for opt in opts:
- if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t"):
+ if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t","i"):
print "command line error: -", opt
opterror=1
--containers=cpp,python,superv: (obsolete) launching of containers cpp, python and supervision
or -c=cpp,python,superv : = get default from -e and -s
--portkill or -p : kill the salome with current port
- --killall or -k : kill salome
+ --killall or -k : kill all salome sessions
+ --interp=n or -i=n : number of additional xterm to open, with session environment
For each Salome module, the environment variable <modulen>_ROOT_DIR must be set.
The module name (<modulen>) must be uppercase.
args['file'] = opts['f']
elif opt == 'x':
args['xterm'] = 1
+ elif opt == 'i':
+ args['interp'] = opts['i']
elif opt == 'm':
args['modules'] = opts['m']
elif opt == 'e':
process_id[pid]=self.CMD
+class InterpServer(Server):
+ def __init__(self,args):
+ self.args=args
+ env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
+ #self.CMD=['xterm', '-iconic', '-sb', '-sl', '500', '-hold','-e']+ env_ld_library_path + ['python']
+ self.CMD=['xterm', '-e', 'python']
+
+ def run(self):
+ global process_id
+ command = self.CMD
+ print "command = ", command
+ pid = os.spawnvp(os.P_NOWAIT, command[0], command)
+ process_id[pid]=self.CMD
+
+# ---
+
class CatalogServer(Server):
def __init__(self,args):
self.args=args
print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
- init_time[4])
+ #
+ # additionnal external python interpreters
+ #
+
+ nbaddi = int(args['interp'][0])
+ print "additional external python interpreters: ", nbaddi
+ if nbaddi:
+ for i in range(nbaddi):
+ print "i=",i
+ anInterp=InterpServer(args)
+ anInterp.run()
+
return clt
# -----------------------------------------------------------------------------
_atFirst = false;
return ret;
}
+ ret = simpleRun("salome.salome_init()");
+ if (ret) {
+ _atFirst = false;
+ return ret;
+ }
_atFirst = false;
}
return simpleRun(command);
using namespace std;
-// asv : 3.12.04 : added checking for NULL GUI objects in almost all methods. In the scope
-// of fixing bug PAL6869. Instance of this class is created every time "import salome" line
-// is typed in stand-alone (Python console) or embedded (InLine nodes in Supervisor) python.
-// SALOME GUI may not be created at this time (desktop and other objects), so checking if they
-// are equal to NULL is neccessary.
+// asv : 3.12.04 : added checking for NULL GUI objects in almost all methods.
+// In the scope of fixing bug PAL6869.
+// (PR : modify comments)
+// Instance of this class is created every time "import salome" line is typed
+// - in IAPP embedded Python interpretor (SALOME_Session_Server executable),
+// - in inline Python nodes in Supervisor (in SALOME_Container executable),
+// - in stand-alone Python console outside any executable.
+// SALOME GUI(desktop and other objects) is only available in SALOME_Session_Server
namespace SALOME{
QAD_ViewFrame* GetViewFrame( QAD_Study* theStudy ) {
// MESSAGE("Destructeur");
}
+/*!
+ Check if GUI is available (if we are linked to IAPP)
+*/
+bool SALOMEGUI_Swig::hasDesktop()
+{
+ if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
+ return true;
+ else
+ return false;
+}
+
/*!
Gets active study or 0 if no study opened
*/
*/
void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection )
{
- if ( QAD_Study* aStudy = getActiveStudy() )
+ if ( QAD_Study* myActiveStudy = getActiveStudy() )
ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_Study,bool>
- ( aStudy, &QAD_Study::updateObjBrowser,updateSelection) );
+ ( myActiveStudy, &QAD_Study::updateObjBrowser,updateSelection) );
}
/*!
*/
int SALOMEGUI_Swig::getActiveStudyId()
{
- if ( QAD_Study* aStudy = getActiveStudy() )
- return aStudy->getStudyId();
+ if ( QAD_Study* myActiveStudy = getActiveStudy() )
+ return myActiveStudy->getStudyId();
return 0;
}
*/
const char *SALOMEGUI_Swig::getActiveStudyName()
{
- if ( QAD_Study* aStudy = getActiveStudy() )
- return aStudy->getTitle().latin1();
+ if ( QAD_Study* myActiveStudy = getActiveStudy() )
+ return myActiveStudy->getTitle().latin1();
return NULL;
}
*/
int SALOMEGUI_Swig::SelectedCount()
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
- SALOME_Selection* Sel = SALOME_Selection::Selection( aStudy->getSelection() );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
return Sel->IObjectCount();
}
return 0;
*/
const char* SALOMEGUI_Swig::getSelected( int i )
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
- SALOME_Selection* Sel = SALOME_Selection::Selection( aStudy->getSelection() );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
int index = 0;
for( ;It.More();It.Next() ) {
*/
void SALOMEGUI_Swig::AddIObject( const char *theEntry )
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
- SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
if ( IsInCurrentView( theEntry ) ) {
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy,theEntry );
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry );
if ( anIO.IsNull() ) return;
ProcessEvent( new TMemFun2ArgEvent<SALOME_Selection,int,
const Handle(SALOME_InteractiveObject)&,bool,
*/
void SALOMEGUI_Swig::RemoveIObject( const char *theEntry )
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
- SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
if ( IsInCurrentView( theEntry ) ) {
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy,theEntry );
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry );
if ( anIO.IsNull() ) return;
ProcessEvent( new TMemFun2ArgEvent<SALOME_Selection,int,
const Handle(SALOME_InteractiveObject)&, bool,
*/
void SALOMEGUI_Swig::ClearIObjects()
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
- SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
ProcessVoidEvent( new TVoidMemFunEvent<SALOME_Selection>
( aSel, &SALOME_Selection::ClearIObjects ) );
}
*/
void SALOMEGUI_Swig::Display( const char *theEntry )
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
if ( IsInCurrentView( theEntry ) ) {
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry );
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
if ( anIO.IsNull() ) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
ProcessVoidEvent( new TVoidMemFun2ArgEvent<QAD_ViewFrame,
const Handle(SALOME_InteractiveObject)&, bool,
Handle(SALOME_InteractiveObject)>
*/
void SALOMEGUI_Swig::DisplayOnly( const char *theEntry )
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
if ( IsInCurrentView( theEntry ) ) {
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry );
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
if ( anIO.IsNull() ) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_ViewFrame,
const Handle(SALOME_InteractiveObject)&,
Handle(SALOME_InteractiveObject)>
*/
void SALOMEGUI_Swig::Erase( const char *theEntry )
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
if ( IsInCurrentView( theEntry ) ) {
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry );
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
if ( anIO.IsNull() ) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
ProcessVoidEvent( new TVoidMemFun2ArgEvent<QAD_ViewFrame,
const Handle(SALOME_InteractiveObject)&, bool,
Handle(SALOME_InteractiveObject)>
*/
void SALOMEGUI_Swig::DisplayAll()
{
- if ( QAD_Study* aStudy = getActiveStudy() ) {
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
ProcessVoidEvent( new TVoidMemFunEvent<QAD_ViewFrame>
( aViewFrame, &QAD_ViewFrame::DisplayAll ) );
}
void SALOMEGUI_Swig::EraseAll()
{
ClearIObjects();
- if ( QAD_Study* aStudy = getActiveStudy() ) {
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
ProcessVoidEvent ( new TVoidMemFunEvent<QAD_ViewFrame>
( aViewFrame, &QAD_ViewFrame::EraseAll ) );
}
*/
bool SALOMEGUI_Swig::IsInCurrentView( const char *theEntry )
{
- if ( QAD_Study* aStudy = getActiveStudy() )
- return aStudy->isInViewer( theEntry, aStudy->getActiveStudyFrame()->entry() );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() )
+ return myActiveStudy->isInViewer( theEntry, myActiveStudy->getActiveStudyFrame()->entry() );
return false;
}
SALOMEGUI_Swig();
~SALOMEGUI_Swig();
+ bool hasDesktop();
+
void updateObjBrowser( bool updateSelection );
QAD_Study* getActiveStudy();
int getActiveStudyId();
SALOMEGUI_Swig();
~SALOMEGUI_Swig();
+ bool hasDesktop();
+
void updateObjBrowser(bool);
int getActiveStudyId();
const char *getActiveStudyName();
LIB_SRC =
#SWIG_DEF = libSALOME_Swig.i
-EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py
+EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py salome_kernel.py salome_study.py salome_iapp.py salome_ComponentGUI.py
EXPORT_SHAREDPYSCRIPTS=kernel_shared_modules.py
# Module : SALOME
# $Header$
-from omniORB import CORBA
-from LifeCycleCORBA import *
-from libSALOME_Swig import *
-import SALOMEDS
-import Engines
-from SALOME_NamingServicePy import *
-
-from SALOME_utilities import *
-
-#--------------------------------------------------------------------------
-
-def DumpComponent(Study, SO, offset):
- it = Study.NewChildIterator(SO)
- Builder = Study.NewBuilder()
- while it.More():
- CSO = it.Value()
- it.Next()
- anAttr = Builder.FindOrCreateAttribute(CSO, "AttributeName")
- AtName = anAttr._narrow(SALOMEDS.AttributeName)
- t_name = AtName.Value()
- if t_name[0] == 1:
- ofs = 1
- a = ""
- while ofs <= offset:
- a = a + "--"
- ofs = ofs +1
- MESSAGE( a + ">" + str(CSO.GetID()) + " " + str(t_name[1]) )
- t_RefSO = CSO.ReferencedObject()
- if t_RefSO[0] == 1:
- RefSO = t_RefSO[1]
- ofs = 1
- a = ""
- while ofs <= offset:
- a = a + " "
- ofs = ofs +1
- MESSAGE( a + ">" + str(RefSO.GetID()) )
- DumpComponent(Study, CSO, offset+2)
-
- #--------------------------------------------------------------------------
-
-def DumpStudy(Study):
- itcomp = Study.NewComponentIterator()
- while itcomp.More():
- SC = itcomp.Value()
- itcomp.Next()
- name = SC.ComponentDataType()
- MESSAGE( "-> ComponentDataType is " + name )
- DumpComponent(Study, SC, 1)
-
-
- #--------------------------------------------------------------------------
-
-def ImportComponentGUI(ComponentName):
- libName = "lib" + ComponentName + "_Swig"
- command = "from " + libName + " import *"
- exec ( command )
- constructor = ComponentName + "_Swig()"
- command = "gui = " + constructor
- exec ( command )
- return gui
-
- #--------------------------------------------------------------------------
-
-def SalomeGUIgetAllSelected(self):
- selNumber = self.SelectedCount()
- listSelected = []
- for i in range(selNumber):
- listSelected.append(self.getSelected(i))
- return listSelected
-
-class SalomeGUI(SALOMEGUI_Swig):
- getAllSelected = SalomeGUIgetAllSelected
+from salome_kernel import *
+from salome_study import *
+from salome_iapp import *
+
+salome_initial=1
+def salome_init(theStudyId=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
- #--------------------------------------------------------------------------
-
-def IDToObject(id):
- myObj = None
- mySO = myStudy.FindObjectID(id);
- if mySO is not None:
- ok, anAttr = mySO.FindAttribute("AttributeIOR")
- if ok:
- AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
- if AtIOR.Value() != "":
- myObj = orb.string_to_object(AtIOR.Value())
- return myObj
-
-def ObjectToSObject(obj):
- mySO = None
- if obj is not None:
- ior = orb.object_to_string(obj)
- if ior != "":
- mySO = myStudy.FindObjectIOR(ior)
- return mySO
-
-def ObjectToID(obj):
- mySO = ObjectToSObject(obj)
- if mySO:
- return mySO.GetID()
- return ""
-
-def IDToSObject(id):
- mySO = myStudy.FindObjectID(id);
- return mySO
-
- #--------------------------------------------------------------------------
-
-# initialise the ORB
-orb = CORBA.ORB_init([''], CORBA.ORB_ID)
-
-# create an LifeCycleCORBA instance
-lcc = LifeCycleCORBA(orb)
-
-# create an SALOMEGUI_Swig instance
-sg = SalomeGUI()
-
-#create an naming service instance
-naming_service = SALOME_NamingServicePy_i(orb)
-
-# get active study name and id
-myStudyName = sg.getActiveStudyName()
-MESSAGE( myStudyName )
-
-myStudyId = sg.getActiveStudyId()
-MESSAGE( str(myStudyId) )
-
-# get Study Manager reference
-obj = naming_service.Resolve('myStudyManager')
-myStudyManager = obj._narrow(SALOMEDS.StudyManager)
-
-# get active study
-myStudy = myStudyManager.GetStudyByName(myStudyName)
+ if salome_initial:
+ salome_initial=0
+ sg = salome_iapp_init()
+ orb, lcc, naming_service, cm = salome_kernel_init()
+ myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init(theStudyId)
-# get Container Manager
-obj = naming_service.Resolve('/ContainerManager')
-cm = obj._narrow(Engines.ContainerManager)
--- /dev/null
+# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+#
+#
+#
+# File : salome.py
+# Author : Paul RASCLE, EDF
+# Module : SALOME
+# $Header$
+
+
+# to replace some function from <MODULE>_SWIG, outside GUI
+
+# --- From GeometryGUI_SWIG
+
+ #--------------------------------------------------------------------------
+
+def getIndexTopology(aSubId, aMainId):
+ return 0
+
+ #--------------------------------------------------------------------------
+
+def getShapeTypeString(aSubId):
+ return "SubShape"
+
+ #--------------------------------------------------------------------------
+
+# --- From SMESHGUI_SWIG
+
+ #--------------------------------------------------------------------------
+
+def Init(studyId):
+ return
+
+ #--------------------------------------------------------------------------
+
+def SetName(objId, name):
+ return
+
+ #--------------------------------------------------------------------------
--- /dev/null
+# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+#
+#
+#
+# File : salome_iapp.py
+# Author : Paul RASCLE, EDF
+# Module : SALOME
+# $Header$
+
+from libSALOME_Swig import *
+import salome_ComponentGUI
+
+ #--------------------------------------------------------------------------
+
+IN_SALOME_GUI=0
+
+def ImportComponentGUI(ComponentName):
+ if IN_SALOME_GUI:
+ libName = "lib" + ComponentName + "_Swig"
+ command = "from " + libName + " import *"
+ exec ( command )
+ constructor = ComponentName + "_Swig()"
+ command = "gui = " + constructor
+ exec ( command )
+ return gui
+ else:
+ print "Warning: ImportComponentGUI(",ComponentName,") outside GUI !"
+ print "calls to GUI methods may crash..."
+ return salome_ComponentGUI
+
+ #--------------------------------------------------------------------------
+
+def SalomeGUIgetAllSelected(self):
+ selNumber = self.SelectedCount()
+ listSelected = []
+ for i in range(selNumber):
+ listSelected.append(self.getSelected(i))
+ return listSelected
+
+class SalomeGUI(SALOMEGUI_Swig):
+ getAllSelected = SalomeGUIgetAllSelected
+
+ #--------------------------------------------------------------------------
+
+salome_iapp_initial = 1
+
+def salome_iapp_init():
+ global salome_iapp_initial
+ global sg,IN_SALOME_GUI
+
+ if salome_iapp_initial:
+ salome_iapp_initial=0
+
+ # create a SALOMEGUI_Swig instance
+ sg = SalomeGUI()
+ IN_SALOME_GUI=sg.hasDesktop()
+ return sg
--- /dev/null
+# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+#
+#
+#
+# File : salome_kernel.py
+# Author : Paul RASCLE, EDF
+# Module : SALOME
+# $Header$
+
+from omniORB import CORBA
+from LifeCycleCORBA import *
+from SALOME_NamingServicePy import *
+from SALOME_utilities import *
+import Engines
+
+salome_kernel_initial=1
+
+def salome_kernel_init():
+ global salome_kernel_initial
+ global orb, lcc, naming_service, cm
+
+ if salome_kernel_initial:
+ salome_kernel_initial = 0
+
+ # initialise the ORB
+ orb = CORBA.ORB_init([''], CORBA.ORB_ID)
+
+ # create a LifeCycleCORBA instance
+ lcc = LifeCycleCORBA(orb)
+
+ #create a naming service instance
+ naming_service = SALOME_NamingServicePy_i(orb)
+
+ # get Container Manager
+ obj = naming_service.Resolve('/ContainerManager')
+ cm = obj._narrow(Engines.ContainerManager)
+
+ return orb, lcc, naming_service, cm
--- /dev/null
+# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+#
+#
+#
+# File : salome_study.py
+# Author : Paul RASCLE, EDF
+# Module : SALOME
+# $Header$
+
+import salome_kernel
+import SALOMEDS
+import salome_iapp
+
+#--------------------------------------------------------------------------
+
+def DumpComponent(Study, SO, offset):
+ it = Study.NewChildIterator(SO)
+ Builder = Study.NewBuilder()
+ while it.More():
+ CSO = it.Value()
+ it.Next()
+ anAttr = Builder.FindOrCreateAttribute(CSO, "AttributeName")
+ AtName = anAttr._narrow(SALOMEDS.AttributeName)
+ t_name = AtName.Value()
+ if t_name[0] == 1:
+ ofs = 1
+ a = ""
+ while ofs <= offset:
+ a = a + "--"
+ ofs = ofs +1
+ MESSAGE( a + ">" + str(CSO.GetID()) + " " + str(t_name[1]) )
+ t_RefSO = CSO.ReferencedObject()
+ if t_RefSO[0] == 1:
+ RefSO = t_RefSO[1]
+ ofs = 1
+ a = ""
+ while ofs <= offset:
+ a = a + " "
+ ofs = ofs +1
+ MESSAGE( a + ">" + str(RefSO.GetID()) )
+ DumpComponent(Study, CSO, offset+2)
+
+ #--------------------------------------------------------------------------
+
+def DumpStudy(Study):
+ itcomp = Study.NewComponentIterator()
+ while itcomp.More():
+ SC = itcomp.Value()
+ itcomp.Next()
+ name = SC.ComponentDataType()
+ MESSAGE( "-> ComponentDataType is " + name )
+ DumpComponent(Study, SC, 1)
+
+
+ #--------------------------------------------------------------------------
+
+def IDToObject(id):
+ myObj = None
+ mySO = myStudy.FindObjectID(id);
+ if mySO is not None:
+ ok, anAttr = mySO.FindAttribute("AttributeIOR")
+ if ok:
+ AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
+ if AtIOR.Value() != "":
+ myObj = orb.string_to_object(AtIOR.Value())
+ return myObj
+
+def ObjectToSObject(obj):
+ mySO = None
+ if obj is not None:
+ ior = orb.object_to_string(obj)
+ if ior != "":
+ mySO = myStudy.FindObjectIOR(ior)
+ return mySO
+
+def ObjectToID(obj):
+ mySO = ObjectToSObject(obj)
+ if mySO:
+ return mySO.GetID()
+ return ""
+
+def IDToSObject(id):
+ mySO = myStudy.FindObjectID(id);
+ return mySO
+
+ #--------------------------------------------------------------------------
+
+def generateName(prefix = None):
+ import whrandom;
+ int = whrandom.randint(1,1000);
+ if prefix is None:
+ return "Study" + str(int)
+ else :
+ return prefix + str(int)
+
+ #--------------------------------------------------------------------------
+
+def PersistentPresentation(theStudy, theSO, theWithID):
+ # put the sobject's content (with subchildren) to the string
+ aResult = ""
+ attrs = theSO.GetAllAttributes()
+ aLen = len(attrs)
+ anUncopied = 0
+ for a in range(0,aLen):
+ attr = attrs[a]
+ if isinstance(attr,SALOMEDS._objref_AttributeTreeNode):
+ anUncopied += 1
+ elif isinstance(attr,SALOMEDS._objref_AttributeTarget):
+ anUncopied += 1
+ elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \
+ isinstance(attr,SALOMEDS._objref_AttributeInteger) or \
+ isinstance(attr,SALOMEDS._objref_AttributeName) or \
+ isinstance(attr,SALOMEDS._objref_AttributeComment) or \
+ isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \
+ isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \
+ isinstance(attr,SALOMEDS._objref_AttributeUserID):
+ aResult += " attribute value: " + str(attr.Value())
+ elif isinstance(attr,SALOMEDS._objref_AttributeIOR):
+ aResult += " attribute: IOR"
+ elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \
+ isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger):
+ aResult += " Sequence: " + str(attr.CorbaSequence())
+ elif isinstance(attr,SALOMEDS._objref_AttributeDrawable):
+ aResult += " Drawable: " + str(attr.IsDrawable())
+ elif isinstance(attr,SALOMEDS._objref_AttributeSelectable):
+ aResult += " Selectable: " + str(attr.IsSelectable())
+ elif isinstance(attr,SALOMEDS._objref_AttributeExpandable):
+ aResult += " Expandable: " + str(attr.IsExpandable())
+ elif isinstance(attr,SALOMEDS._objref_AttributeOpened):
+ aResult += " Opened: " + str(attr.IsOpened())
+ elif isinstance(attr,SALOMEDS._objref_AttributeTextColor):
+ aResult += " TextColor: " + str(attr.TextColor())
+ elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor):
+ aResult += " TextHighlightColor: " + str(attr.TextHighlightColor())
+ elif isinstance(attr,SALOMEDS._objref_AttributePixMap):
+ aResult += " PixMap: " + str(attr.GetPixMap())
+ elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \
+ isinstance(attr,SALOMEDS._objref_AttributeTableOfReal):
+ aResult += " Table with title: " + attr.GetTitle()
+ elif isinstance(attr,SALOMEDS._objref_AttributePythonObject):
+ aResult += " PythonObject: " + attr.GetObject()
+
+ if theWithID:
+ aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
+ else:
+ aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
+ anIter = theStudy.NewChildIterator(theSO)
+ while anIter.More():
+ aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID)
+ anIter.Next()
+ return aResult
+
+ #--------------------------------------------------------------------------
+
+def GetTree(theSO):
+ # returns the document list tree (as list)
+ aResult = [theSO.GetID()]
+ anIter = myStudy.NewChildIterator(theSO)
+ while anIter.More():
+ aResult += GetTree(anIter.Value())
+ anIter.Next()
+ return aResult
+
+ #--------------------------------------------------------------------------
+
+def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
+ aRoot = theSO
+ while aRoot.GetID() != "0:":
+ aRoot = aRoot.GetFather()
+ aTree = GetTree(aRoot)
+ aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
+
+ if not myStudyManager.CanCopy(theSO):
+ raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
+
+ if not myStudyManager.Copy(theSO):
+ raise RuntimeError, "<Copy> for "+theInfo+" returns false"
+
+
+ if not myStudyManager.CanPaste(theSO):
+ raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
+
+ # check: before paste study is not changed check
+ if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1):
+ 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:
+ raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
+ aNewTree = GetTree(aRoot)
+ aLen = len(aTree)
+ for a in range(0,aLen):
+ if aTree[a] != aNewTree[a]:
+ return myStudy.FindObjectID(aNewTree[a])
+
+ if aLen < len(aNewTree):
+ return myStudy.FindObjectID(aNewTree[aLen])
+
+ raise RuntimeError, "After Copy calling the tree is not changed"
+
+ #--------------------------------------------------------------------------
+
+def FindFileInDataDir(filename):
+ import os
+ datadir = os.getenv("DATA_DIR")
+ if datadir is not None:
+ import string
+ dirs = string.split(datadir, ":")
+ for dir in dirs:
+ file = dir + "/" + filename
+ if os.path.exists(file):
+ return file;
+ datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
+ file = datadir + filename
+ if os.path.exists(file):
+ return file;
+
+ return None
+
+ #--------------------------------------------------------------------------
+
+salome_study_ID = -1
+
+def getActiveStudy(theStudyId=0):
+ global salome_study_ID
+
+ print "getActiveStudy"
+ sg = salome_iapp.salome_iapp_init()
+ if salome_study_ID == -1:
+ if sg.hasDesktop():
+ print "---in gui"
+ salome_study_ID = sg.getActiveStudyId()
+ else:
+ print "---outside gui"
+ if theStudyId:
+ aStudy=myStudyManager.GetStudyByID(theStudyId)
+ if aStudy:
+ print "connection to existing study ", theStudyId
+ salome_study_ID = theStudyId
+ if salome_study_ID == -1:
+ salome_study_ID = createNewStudy()
+ print"--- Study Id ", salome_study_ID
+ return salome_study_ID
+
+ #--------------------------------------------------------------------------
+
+def createNewStudy():
+ print "createNewStudy"
+ i=1
+ aStudyName = "noName"
+ nameAlreadyInUse = 1
+ listOfOpenStudies = myStudyManager.GetOpenStudies()
+ print listOfOpenStudies
+ while nameAlreadyInUse:
+ aStudyName = "extStudy_%d"%i
+ if aStudyName not in listOfOpenStudies:
+ nameAlreadyInUse=0
+ else:
+ i = i+1
+
+ theStudy = myStudyManager.NewStudy(aStudyName)
+ theStudyId = theStudy._get_StudyId()
+ print aStudyName, theStudyId
+ return theStudyId
+
+ #--------------------------------------------------------------------------
+
+salome_study_initial = 1
+
+def 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.
+ """
+
+ global salome_study_initial
+ global myStudyManager, myStudyId, myStudy, myStudyName
+ global orb, lcc, naming_service, cm
+
+ if salome_study_initial:
+ salome_study_initial = 0
+
+ orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init()
+
+ # get Study Manager reference
+ print "looking for studyManager ..."
+ obj = naming_service.Resolve('myStudyManager')
+ myStudyManager = obj._narrow(SALOMEDS.StudyManager)
+ print "studyManager found"
+
+ # get active study Id, ref and name
+ myStudyId = getActiveStudy(theStudyId)
+ print "myStudyId",myStudyId
+ myStudy = myStudyManager.GetStudyByID(myStudyId)
+ myStudyName = myStudy._get_Name()
+
+ return myStudyManager, myStudyId, myStudy, myStudyName
+