From: prascle Date: Thu, 20 Jan 2005 14:27:03 +0000 (+0000) Subject: PR: new design of salome.py (related to 7658 7659 ...) X-Git-Tag: V2_2_0_adev_23Jan05 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b84e7b40a6fdab58598b2c98126e4d7906068356;p=modules%2Fkernel.git PR: new design of salome.py (related to 7658 7659 ...) --- diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index 717815401..39eb410d9 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -159,7 +159,7 @@ else: 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"]: @@ -240,7 +240,7 @@ except: 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 @@ -251,24 +251,25 @@ if opts.has_key("h"): print """USAGE: runSalome.py [options] [command line options] : --help or -h : print this help - --gui or -g : lancement du GUI + --gui or -g : GUI launch --terminal -t : launching without gui (to deny --gui) - --logger or -l : redirection des messages via CORBA - --file=filename or -l=filename: redirection des messages dans un fichier - --xterm or -x : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre - --modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue + --logger or -l : trace collection via CORBA + --file=filename or -f=filename: trace collection in a file + --xterm or -x : each program in a separate xterm + --modules=module1,module2,... : list of salome modules to put into the module catalog or -m=module1,module2,... --embedded=registry,study,moduleCatalog,cppContainer or -e=registry,study,moduleCatalog,cppContainer - : serveurs CORBA embarqués (par defaut: registry,study,moduleCatalog,cppContainer) - : (logger,pyContainer,supervContainer ne peuvent pas être embarqués + : servers embedded in session server (default: registry,study,moduleCatalog,cppContainer) + : (logger,pyContainer,supervContainer can't be embedded) --standalone=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer or -s=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer - : executables serveurs CORBA indépendants (par défaut: pyContainer,supervContainer) - --containers=cpp,python,superv: (obsolete) lancement des containers cpp, python et de supervision - or -c=cpp,python,superv : = on prend les defauts de -e et -s + : standalone CORBA servers (default: pyContainer,supervContainer) + --containers=cpp,python,superv: obsolete ( cpp, python and supervision container launch) + or -c=cpp,python,superv : see --embedded, --standalone --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 La variable d'environnement _ROOT_DIR doit etre préalablement positionnée (modulen doit etre en majuscule). @@ -287,6 +288,8 @@ for opt in opts: 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': diff --git a/bin/runSalome.py b/bin/runSalome.py index d7ba78d8d..1bc604970 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -254,6 +254,22 @@ class Server: # --- +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 @@ -565,6 +581,18 @@ def startSalome(args, modules_list, modules_root_dir): 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 # ----------------------------------------------------------------------------- diff --git a/src/SALOMEGUI/SALOMEGUI_Swig.cxx b/src/SALOMEGUI/SALOMEGUI_Swig.cxx index 9edbd3bb1..0865d6b3c 100644 --- a/src/SALOMEGUI/SALOMEGUI_Swig.cxx +++ b/src/SALOMEGUI/SALOMEGUI_Swig.cxx @@ -44,14 +44,29 @@ using namespace std; +// 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){ - return theStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame(); + QAD_ViewFrame* GetViewFrame( QAD_Study* theStudy ) { + if ( theStudy ) + if ( QAD_StudyFrame* aSF = theStudy->getActiveStudyFrame() ) + if ( QAD_RightFrame* aRF = aSF->getRightFrame() ) + return aRF->getViewFrame(); + return 0; } - Handle(SALOME_InteractiveObject) FindIObject(QAD_Study* theStudy, const char *theEntry) + Handle(SALOME_InteractiveObject) FindIObject( QAD_Study* theStudy, const char *theEntry ) { - return GetViewFrame(theStudy)->FindIObject(theEntry); + if ( QAD_ViewFrame* aVF = GetViewFrame( theStudy ) ) + return aVF->FindIObject( theEntry ); + return Handle(SALOME_InteractiveObject)(); // NULL Handle } } @@ -72,13 +87,25 @@ SALOMEGUI_Swig::~SALOMEGUI_Swig() // 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 */ QAD_Study* SALOMEGUI_Swig::getActiveStudy() { - if(QAD_Application* app = QAD_Application::getDesktop()->getActiveApp()) - return app->getActiveStudy(); + if ( QAD_Desktop* aDT = QAD_Application::getDesktop() ) + if ( QAD_Application* anApp = aDT->getActiveApp() ) + return anApp->getActiveStudy(); return 0; } @@ -87,9 +114,9 @@ QAD_Study* SALOMEGUI_Swig::getActiveStudy() */ void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection ) { - if(QAD_Study* myActiveStudy = getActiveStudy()) - ProcessVoidEvent(new TVoidMemFun1ArgEvent - (myActiveStudy,&QAD_Study::updateObjBrowser,updateSelection)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) + ProcessVoidEvent( new TVoidMemFun1ArgEvent + ( myActiveStudy, &QAD_Study::updateObjBrowser,updateSelection) ); } /*! @@ -97,7 +124,7 @@ void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection ) */ int SALOMEGUI_Swig::getActiveStudyId() { - if(QAD_Study* myActiveStudy = getActiveStudy()) + if ( QAD_Study* myActiveStudy = getActiveStudy() ) return myActiveStudy->getStudyId(); return 0; } @@ -107,9 +134,9 @@ int SALOMEGUI_Swig::getActiveStudyId() */ const char *SALOMEGUI_Swig::getActiveStudyName() { - if(QAD_Study* myActiveStudy = getActiveStudy()) + if ( QAD_Study* myActiveStudy = getActiveStudy() ) return myActiveStudy->getTitle().latin1(); - return QString::null; + return NULL; } /*! @@ -117,14 +144,18 @@ const char *SALOMEGUI_Swig::getActiveStudyName() */ const char* SALOMEGUI_Swig::getComponentName( const char* ComponentUserName ) { - return QAD_Application::getDesktop()->getComponentName( ComponentUserName ); + if ( QAD_Desktop* aDT = QAD_Application::getDesktop() ) + return aDT->getComponentName( ComponentUserName ); + return NULL; } /*! Returns the user name of component. */ const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName ) { - return QAD_Application::getDesktop()->getComponentUserName( ComponentName ); + if ( QAD_Desktop* aDT = QAD_Application::getDesktop() ) + return aDT->getComponentUserName( ComponentName ); + return NULL; } /*! @@ -132,8 +163,8 @@ const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName ) */ int SALOMEGUI_Swig::SelectedCount() { - if(QAD_Study* myStudy = getActiveStudy()){ - SALOME_Selection* Sel = SALOME_Selection::Selection(myStudy->getSelection()); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); return Sel->IObjectCount(); } return 0; @@ -142,13 +173,13 @@ int SALOMEGUI_Swig::SelectedCount() /*! Returns the selected object at index i. */ -const char* SALOMEGUI_Swig::getSelected(int i) +const char* SALOMEGUI_Swig::getSelected( int i ) { - if(QAD_Study* myStudy = getActiveStudy()){ - SALOME_Selection* Sel = SALOME_Selection::Selection( myStudy->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()){ + for( ;It.More();It.Next() ) { Handle(SALOME_InteractiveObject) IObject = It.Value(); if( i == index++ ){ if ( IObject->hasEntry() ) @@ -162,17 +193,17 @@ const char* SALOMEGUI_Swig::getSelected(int i) /*! Add object with Entry into selection. */ -void SALOMEGUI_Swig::AddIObject(const char *theEntry) +void SALOMEGUI_Swig::AddIObject( const char *theEntry ) { - if(QAD_Study* myStudy = getActiveStudy()){ - SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() ); - if(IsInCurrentView(theEntry)){ - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry); - if(anIO.IsNull()) return; - ProcessEvent(new TMemFun2ArgEvent - (aSel,&SALOME_Selection::AddIObject,anIO,true)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); + if ( IsInCurrentView( theEntry ) ) { + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry ); + if ( anIO.IsNull() ) return; + ProcessEvent( new TMemFun2ArgEvent + ( aSel, &SALOME_Selection::AddIObject, anIO, true ) ); } } } @@ -181,17 +212,17 @@ void SALOMEGUI_Swig::AddIObject(const char *theEntry) /*! Removes object with Entry into selection. */ -void SALOMEGUI_Swig::RemoveIObject(const char *theEntry) +void SALOMEGUI_Swig::RemoveIObject( const char *theEntry ) { - if(QAD_Study* myStudy = getActiveStudy()){ - SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() ); - if(IsInCurrentView(theEntry)){ - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry); - if(anIO.IsNull()) return; - ProcessEvent(new TMemFun2ArgEvent - (aSel,&SALOME_Selection::RemoveIObject,anIO,true)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); + if ( IsInCurrentView( theEntry ) ) { + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry ); + if ( anIO.IsNull() ) return; + ProcessEvent( new TMemFun2ArgEvent + ( aSel, &SALOME_Selection::RemoveIObject, anIO, true ) ); } } } @@ -202,27 +233,27 @@ void SALOMEGUI_Swig::RemoveIObject(const char *theEntry) */ void SALOMEGUI_Swig::ClearIObjects() { - if(QAD_Study* myStudy = getActiveStudy()){ - SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() ); - ProcessVoidEvent(new TVoidMemFunEvent - (aSel,&SALOME_Selection::ClearIObjects)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); + ProcessVoidEvent( new TVoidMemFunEvent + ( aSel, &SALOME_Selection::ClearIObjects ) ); } } /*! Display */ -void SALOMEGUI_Swig::Display(const char *theEntry) +void SALOMEGUI_Swig::Display( const char *theEntry ) { - if(QAD_Study* myStudy = getActiveStudy()){ - if(IsInCurrentView(theEntry)){ - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry); - if(anIO.IsNull()) return; - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy); - ProcessVoidEvent(new TVoidMemFun2ArgEvent - (aViewFrame,&QAD_ViewFrame::Display,anIO,true)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + if ( IsInCurrentView( theEntry ) ) { + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry ); + if ( anIO.IsNull() ) return; + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); + ProcessVoidEvent( new TVoidMemFun2ArgEvent + ( aViewFrame, &QAD_ViewFrame::Display, anIO, true ) ); } } } @@ -230,17 +261,17 @@ void SALOMEGUI_Swig::Display(const char *theEntry) /*! Display only */ -void SALOMEGUI_Swig::DisplayOnly(const char *theEntry) +void SALOMEGUI_Swig::DisplayOnly( const char *theEntry ) { - if(QAD_Study* myStudy = getActiveStudy()){ - if(IsInCurrentView(theEntry)){ - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry); - if(anIO.IsNull()) return; - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy); - ProcessVoidEvent(new TVoidMemFun1ArgEvent - (aViewFrame,&QAD_ViewFrame::DisplayOnly,anIO)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + if ( IsInCurrentView( theEntry ) ) { + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry ); + if ( anIO.IsNull() ) return; + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); + ProcessVoidEvent( new TVoidMemFun1ArgEvent + ( aViewFrame, &QAD_ViewFrame::DisplayOnly, anIO ) ); } } } @@ -248,17 +279,17 @@ void SALOMEGUI_Swig::DisplayOnly(const char *theEntry) /*! Erase */ -void SALOMEGUI_Swig::Erase(const char *theEntry) +void SALOMEGUI_Swig::Erase( const char *theEntry ) { - if(QAD_Study* myStudy = getActiveStudy()){ - if(IsInCurrentView(theEntry)){ - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry); - if(anIO.IsNull()) return; - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy); - ProcessVoidEvent(new TVoidMemFun2ArgEvent - (aViewFrame,&QAD_ViewFrame::Erase,anIO,true)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + if ( IsInCurrentView( theEntry ) ) { + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry ); + if ( anIO.IsNull() ) return; + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); + ProcessVoidEvent( new TVoidMemFun2ArgEvent + ( aViewFrame, &QAD_ViewFrame::Erase, anIO, true ) ); } } } @@ -268,10 +299,10 @@ void SALOMEGUI_Swig::Erase(const char *theEntry) */ void SALOMEGUI_Swig::DisplayAll() { - if(QAD_Study* myStudy = getActiveStudy()){ - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy); - ProcessVoidEvent(new TVoidMemFunEvent - (aViewFrame,&QAD_ViewFrame::DisplayAll)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); + ProcessVoidEvent( new TVoidMemFunEvent + ( aViewFrame, &QAD_ViewFrame::DisplayAll ) ); } } @@ -281,19 +312,19 @@ void SALOMEGUI_Swig::DisplayAll() void SALOMEGUI_Swig::EraseAll() { ClearIObjects(); - if(QAD_Study* myStudy = getActiveStudy()){ - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy); - ProcessVoidEvent(new TVoidMemFunEvent - (aViewFrame,&QAD_ViewFrame::EraseAll)); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); + ProcessVoidEvent ( new TVoidMemFunEvent + ( aViewFrame, &QAD_ViewFrame::EraseAll ) ); } } /*! Checks if object is displayed in current viewer */ -bool SALOMEGUI_Swig::IsInCurrentView(const char *theEntry) +bool SALOMEGUI_Swig::IsInCurrentView( const char *theEntry ) { - if(QAD_Study* myStudy = getActiveStudy()) - return myStudy->isInViewer( theEntry, myStudy->getActiveStudyFrame()->entry() ); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) + return myActiveStudy->isInViewer( theEntry, myActiveStudy->getActiveStudyFrame()->entry() ); return false; } diff --git a/src/SALOMEGUI/SALOMEGUI_Swig.hxx b/src/SALOMEGUI/SALOMEGUI_Swig.hxx index f61d26fd0..967c09377 100644 --- a/src/SALOMEGUI/SALOMEGUI_Swig.hxx +++ b/src/SALOMEGUI/SALOMEGUI_Swig.hxx @@ -51,6 +51,8 @@ public: SALOMEGUI_Swig(); ~SALOMEGUI_Swig(); + bool hasDesktop(); + void updateObjBrowser( bool updateSelection ); QAD_Study* getActiveStudy(); int getActiveStudyId(); diff --git a/src/SALOMEGUI/SALOMEGUI_Swig.i b/src/SALOMEGUI/SALOMEGUI_Swig.i index d5c5a5007..1910dad02 100644 --- a/src/SALOMEGUI/SALOMEGUI_Swig.i +++ b/src/SALOMEGUI/SALOMEGUI_Swig.i @@ -57,6 +57,8 @@ class SALOMEGUI_Swig SALOMEGUI_Swig(); ~SALOMEGUI_Swig(); + bool hasDesktop(); + void updateObjBrowser(bool); int getActiveStudyId(); const char *getActiveStudyName(); diff --git a/src/SALOME_SWIG_WITHOUTIHM/Makefile.in b/src/SALOME_SWIG_WITHOUTIHM/Makefile.in index 1c42c1ad6..6df9f2893 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/Makefile.in +++ b/src/SALOME_SWIG_WITHOUTIHM/Makefile.in @@ -38,7 +38,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl 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 EXPORT_SHAREDPYSCRIPTS=kernel_shared_modules.py diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome.py b/src/SALOME_SWIG_WITHOUTIHM/salome.py index 2d5ae11cf..0beae6343 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/salome.py +++ b/src/SALOME_SWIG_WITHOUTIHM/salome.py @@ -24,133 +24,9 @@ # Module : SALOME # $Header$ -from omniORB import CORBA -from LifeCycleCORBA import * -from libSALOME_Swig import * -import SALOMEDS -from SALOME_NamingServicePy import * +from salome_kernel import * +from salome_study import * +from salome_iapp import * -from SALOME_utilities import * +IN_SALOME_GUI=sg.hasDesktop() -#-------------------------------------------------------------------------- - -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 - - #-------------------------------------------------------------------------- - -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) diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py b/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py new file mode 100644 index 000000000..d89536cff --- /dev/null +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py @@ -0,0 +1,56 @@ +# 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 * + + #-------------------------------------------------------------------------- + +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 + + #-------------------------------------------------------------------------- + +# create an SALOMEGUI_Swig instance +sg = SalomeGUI() + diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py b/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py new file mode 100644 index 000000000..27c4e58b0 --- /dev/null +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py @@ -0,0 +1,39 @@ +# 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 * + +# initialise the ORB +orb = CORBA.ORB_init([''], CORBA.ORB_ID) + +# create an LifeCycleCORBA instance +lcc = LifeCycleCORBA(orb) + +#create an naming service instance +naming_service = SALOME_NamingServicePy_i(orb) diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_study.py b/src/SALOME_SWIG_WITHOUTIHM/salome_study.py new file mode 100644 index 000000000..954830e24 --- /dev/null +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_study.py @@ -0,0 +1,155 @@ +# 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$ + +from salome_iapp import sg +from salome_kernel import * +import SALOMEDS + +#-------------------------------------------------------------------------- + +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 + + #-------------------------------------------------------------------------- + +salome_study_ID = -1 + +def getActiveStudy(): + global salome_study_ID + print "getActiveStudy" + if salome_study_ID == -1: + if sg.hasDesktop(): + print "---in gui" + salome_study_ID = sg.getActiveStudyId() + else: + print "---outside gui" + salome_study_ID = createNewStudy() + print"---", 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 + + #-------------------------------------------------------------------------- + +# 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() +print "myStudyId",myStudyId +myStudy = myStudyManager.GetStudyByID(myStudyId) +myStudyName = myStudy._get_Name() + + +