]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
PR: new design of salome.py (related to 7658 7659 ...) V2_2_0_adev_23Jan05
authorprascle <prascle>
Thu, 20 Jan 2005 14:27:03 +0000 (14:27 +0000)
committerprascle <prascle>
Thu, 20 Jan 2005 14:27:03 +0000 (14:27 +0000)
bin/launchConfigureParser.py
bin/runSalome.py
src/SALOMEGUI/SALOMEGUI_Swig.cxx
src/SALOMEGUI/SALOMEGUI_Swig.hxx
src/SALOMEGUI/SALOMEGUI_Swig.i
src/SALOME_SWIG_WITHOUTIHM/Makefile.in
src/SALOME_SWIG_WITHOUTIHM/salome.py
src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py [new file with mode: 0644]
src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py [new file with mode: 0644]
src/SALOME_SWIG_WITHOUTIHM/salome_study.py [new file with mode: 0644]

index 71781540164a504094444c0075af96fb1a22137b..39eb410d9dfec65c67c0181a5830d81ff888f95d 100755 (executable)
@@ -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 <modulen>_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':
index d7ba78d8d888bb800a35a498622b538e0241ccfb..1bc6049700e6f3497fb5e5c641c34f5a84cff7f1 100755 (executable)
@@ -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
 
 # -----------------------------------------------------------------------------
index 9edbd3bb18dc79e8a7f92e94846f8938a639f476..0865d6b3c08180009d9930d7bcc40cfd54e202de 100644 (file)
 
 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<QAD_Study,bool>
-                    (myActiveStudy,&QAD_Study::updateObjBrowser,updateSelection));
+  if ( QAD_Study* myActiveStudy = getActiveStudy() )
+    ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_Study,bool>
+                    ( 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<SALOME_Selection,int,
-                  const Handle(SALOME_InteractiveObject)&,bool,
-                  Handle(SALOME_InteractiveObject)>
-                  (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<SALOME_Selection,int,
+                   const Handle(SALOME_InteractiveObject)&,bool,
+                   Handle(SALOME_InteractiveObject)>
+                   ( 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<SALOME_Selection,int,
-                  const Handle(SALOME_InteractiveObject)&,bool,
-                  Handle(SALOME_InteractiveObject)>
-                  (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<SALOME_Selection,int,
+                   const Handle(SALOME_InteractiveObject)&, bool,
+                   Handle(SALOME_InteractiveObject)>
+                   ( 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<SALOME_Selection>
-                    (aSel,&SALOME_Selection::ClearIObjects));
+  if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+    SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
+    ProcessVoidEvent( new TVoidMemFunEvent<SALOME_Selection>
+                    ( 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<QAD_ViewFrame,
-                      const Handle(SALOME_InteractiveObject)&,bool,
-                      Handle(SALOME_InteractiveObject)>
-                      (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<QAD_ViewFrame,
+                       const Handle(SALOME_InteractiveObject)&, bool,
+                       Handle(SALOME_InteractiveObject)>
+                       ( 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<QAD_ViewFrame,
-                      const Handle(SALOME_InteractiveObject)&,
-                      Handle(SALOME_InteractiveObject)>
-                      (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<QAD_ViewFrame,
+                       const Handle(SALOME_InteractiveObject)&,
+                       Handle(SALOME_InteractiveObject)>
+                       ( 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<QAD_ViewFrame,
-                      const Handle(SALOME_InteractiveObject)&,bool,
-                      Handle(SALOME_InteractiveObject)>
-                      (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<QAD_ViewFrame,
+                       const Handle(SALOME_InteractiveObject)&, bool,
+                       Handle(SALOME_InteractiveObject)>
+                       ( 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<QAD_ViewFrame>
-                    (aViewFrame,&QAD_ViewFrame::DisplayAll));
+  if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+    QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
+    ProcessVoidEvent( new TVoidMemFunEvent<QAD_ViewFrame>
+                     ( 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<QAD_ViewFrame>
-                    (aViewFrame,&QAD_ViewFrame::EraseAll));
+  if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+    QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
+    ProcessVoidEvent ( new TVoidMemFunEvent<QAD_ViewFrame>
+                     ( 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;
 }
index f61d26fd0bd39b83c08245c186b2ad7e7f9677a7..967c0937727d5023aa4e482ef637fd7a9c3ac770 100644 (file)
@@ -51,6 +51,8 @@ public:
   SALOMEGUI_Swig();
   ~SALOMEGUI_Swig();
 
+  bool hasDesktop();
+
   void         updateObjBrowser( bool updateSelection );
   QAD_Study*   getActiveStudy();
   int          getActiveStudyId();
index d5c5a5007d75ea05a0da6c33922f9807ebc34a3a..1910dad02cb460353348900a89c08d3a44d6498b 100644 (file)
@@ -57,6 +57,8 @@ class SALOMEGUI_Swig
   SALOMEGUI_Swig();
   ~SALOMEGUI_Swig();
 
+  bool hasDesktop();
+
   void updateObjBrowser(bool);
   int getActiveStudyId();
   const char *getActiveStudyName();
index 1c42c1ad6ffbb78847eaa3afe98e3631d7ae6842..6df9f28930fa7418eee06ba1d4dcd0f52cddea10 100755 (executable)
@@ -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
 
index 2d5ae11cf189da858acb36d85b9c61a4bbfbf56f..0beae634331c022c0a59c116e6d86ae2f6877734 100755 (executable)
 #  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 (file)
index 0000000..d89536c
--- /dev/null
@@ -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 (file)
index 0000000..27c4e58
--- /dev/null
@@ -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 (file)
index 0000000..954830e
--- /dev/null
@@ -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()
+
+
+