Salome HOME
Merge branch V7_3_1_BR
[modules/gui.git] / src / SalomeApp / SalomeApp_Application.cxx
index 532498db66374b037a69eaa47b1db93be9774e7f..2dfa32ca9f0dbc3fea452e524a8a2be617f1396a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // Author:    Sergey LITONIN
 
 #ifdef WIN32
-// E.A. : On windows with python 2.6, there is a conflict
-// E.A. : between pymath.h and Standard_math.h which define
-// E.A. : some same symbols : acosh, asinh, ...
-#include <Standard_math.hxx>
-#include <pymath.h>
+  // E.A. : On windows with python 2.6, there is a conflict
+  // E.A. : between pymath.h and Standard_math.h which define
+  // E.A. : some same symbols : acosh, asinh, ...
+  #include <Standard_math.hxx>
+  #ifndef DISABLE_PYCONSOLE
+    #include <pymath.h>
+  #endif
 #endif
 
-#include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
+#ifndef DISABLE_PYCONSOLE
+  #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
+  #include <PyConsole_Console.h>
+  #include "SalomeApp_NoteBook.h"
+#endif
 #include "SalomeApp_Application.h"
 #include "SalomeApp_Study.h"
 #include "SalomeApp_DataModel.h"
@@ -40,8 +46,6 @@
 #include "SalomeApp_VisualState.h"
 #include "SalomeApp_StudyPropertiesDlg.h"
 #include "SalomeApp_LoadStudiesDlg.h"
-#include "SalomeApp_NoteBook.h"
-
 #include "SalomeApp_ExitDlg.h"
 
 #include <LightApp_Application.h>
@@ -75,7 +79,6 @@
 // temporary commented
 //#include <OB_ListItem.h>
 
-#include <PyConsole_Console.h>
 
 #include <Utils_ORB_INIT.hxx>
 #include <Utils_SINGLETON.hxx>
@@ -238,6 +241,7 @@ void SalomeApp_Application::start()
         updateObjectBrowser(true);
     }
 
+#ifndef DISABLE_PYCONSOLE
     // import/execute python scripts
     if ( pyfiles.count() > 0 && activeStudy() ) {
       SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
@@ -274,6 +278,7 @@ void SalomeApp_Application::start()
         }
       }
     }
+#endif
   } else {
     LightApp_Application::start();
     SALOME_EventFilter::Init();
@@ -368,6 +373,8 @@ void SalomeApp_Application::createActions()
 
   createExtraActions();
 
+#ifndef DISABLE_PYCONSOLE
+#ifndef DISABLE_SALOMEOBJECT
   // import Python module that manages SALOME plugins
   {
     PyLockWrapper lck; // acquire GIL
@@ -377,6 +384,8 @@ void SalomeApp_Application::createActions()
       PyErr_Print();
   }
   // end of SALOME plugins loading
+#endif
+#endif
 
 }
 
@@ -477,10 +486,12 @@ void SalomeApp_Application::onNewWithScript()
 
     QString command = QString("execfile(r\"%1\")").arg(aFile);
 
+#ifndef DISABLE_PYCONSOLE
     PyConsole_Console* pyConsole = pythonConsole();
 
     if ( pyConsole )
       pyConsole->exec( command );
+#endif
   }
 }
 
@@ -716,9 +727,11 @@ SUIT_Study* SalomeApp_Application::createNewStudy()
   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
 
+#ifndef DISABLE_PYCONSOLE
   //to receive signal in application that NoteBook's variable was modified
   connect( aStudy, SIGNAL(notebookVarUpdated(QString)),
            this, SIGNAL(notebookVarUpdated(QString)) );
+#endif
 
   return aStudy;
 }
@@ -906,10 +919,12 @@ void SalomeApp_Application::onLoadScript( )
   {
     QString command = QString("execfile(r\"%1\")").arg(aFile);
 
+#ifndef DISABLE_PYCONSOLE
     PyConsole_Console* pyConsole = pythonConsole();
 
     if ( pyConsole )
       pyConsole->exec( command );
+#endif
   }
 }
 
@@ -971,7 +986,11 @@ QString SalomeApp_Application::getFileFilter() const
 QWidget* SalomeApp_Application::createWindow( const int flag )
 {
   QWidget* wid = 0;
+#ifndef DISABLE_PYCONSOLE
   if ( flag != WT_PyConsole ) wid = LightApp_Application::createWindow(flag);
+#else
+  wid = LightApp_Application::createWindow(flag);
+#endif
 
   SUIT_ResourceMgr* resMgr = resourceMgr();
 
@@ -1034,6 +1053,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag )
       */
     }
   }
+#ifndef DISABLE_PYCONSOLE
   else if ( flag == WT_PyConsole )
   {
     PyConsole_Console* pyCons = new PyConsole_EnhConsole( desktop(), new SalomeApp_PyInterp() );
@@ -1057,6 +1077,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag )
     }
     wid = getNoteBook();
   }
+#endif
   return wid;
 }
 
@@ -1502,7 +1523,7 @@ SUIT_ViewManager* SalomeApp_Application::newViewManager(const QString& type)
 }
 
 
-/*!Global utility funciton, returns selected GUI Save point object's ID */
+/*!Global utility function, returns selected GUI Save point object's ID */
 int getSelectedSavePoint( const LightApp_SelectionMgr* selMgr )
 {
   SALOME_ListIO aList;
@@ -1548,8 +1569,10 @@ void SalomeApp_Application::onStudyCreated( SUIT_Study* study )
 {
   LightApp_Application::onStudyCreated( study );
 
+#ifndef DISABLE_PYCONSOLE
   desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ),
                                windowDock( getWindow( WT_ObjectBrowser ) ) );
+#endif
 
   loadDockWindowsState();
 
@@ -1577,8 +1600,10 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* study )
 {
   LightApp_Application::onStudyOpened( study );
 
+#ifndef DISABLE_PYCONSOLE
   desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ),
                                windowDock( getWindow( WT_ObjectBrowser ) ) );
+#endif
 
   loadDockWindowsState();
 
@@ -1712,6 +1737,7 @@ void SalomeApp_Application::objectBrowserColumnsVisibility()
     }
 }
 
+#ifndef DISABLE_PYCONSOLE
 /*! Set SalomeApp_NoteBook pointer */
 void SalomeApp_Application::setNoteBook( SalomeApp_NoteBook* theNoteBook )
 {
@@ -1723,6 +1749,7 @@ SalomeApp_NoteBook* SalomeApp_Application::getNoteBook() const
 {
   return myNoteBook;
 }
+#endif
 
 /*!
  * Define extra actions defined in module definition XML file.
@@ -1848,7 +1875,7 @@ void SalomeApp_Application::updateVisibilityState( DataObjectList& theList,
 
   SALOME_View* aView = dynamic_cast<SALOME_View*>( theViewModel );
 
-  if (theList.isEmpty() || !aView || !aStudy)
+  if (theList.isEmpty() || !aStudy)
     return;
 
   for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) {
@@ -1864,13 +1891,13 @@ void SalomeApp_Application::updateVisibilityState( DataObjectList& theList,
       LightApp_Displayer* aDisplayer = anObjModule->displayer();
       if(aDisplayer) {
         if( aDisplayer->canBeDisplayed(obj->entry(), theViewModel->getType()) ) {
-          if(aDisplayer->IsDisplayed(obj->entry(),aView))
+          if(aView && aDisplayer->IsDisplayed(obj->entry(),aView))
             anObjState = Qtx::ShownState;
           else
             anObjState = Qtx::HiddenState;
         }
+       aStudy->setVisibilityState( obj->entry(), anObjState );
       }
-      aStudy->setVisibilityState( obj->entry(), anObjState );
     }
   }
 }
@@ -1932,11 +1959,13 @@ bool SalomeApp_Application::renameObject( const QString& entry, const QString& n
 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
 {
   LightApp_Application::defaultWindows(aMap);
+#ifndef DISABLE_PYCONSOLE
   if ( !aMap.contains( WT_NoteBook ) ) {
     if ( !myNoteBook ) {
       aMap.insert( WT_NoteBook, Qt::LeftDockWidgetArea );
     }
   }
+#endif
 }
 
 /*!
@@ -1946,10 +1975,13 @@ void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
 void SalomeApp_Application::currentWindows(QMap<int, int>& aMap) const
 {
   LightApp_Application::currentWindows( aMap );
+#ifndef DISABLE_PYCONSOLE
   if ( !aMap.contains( WT_NoteBook) && myNoteBook )
     aMap.insert( WT_NoteBook, Qt::LeftDockWidgetArea );
+#endif
 }
 
+#ifndef DISABLE_PYCONSOLE
 //============================================================================
 /*! Function : onUpdateStudy
  *  Purpose  : Slot to update the study.
@@ -2050,6 +2082,7 @@ bool SalomeApp_Application::updateStudy()
 
   return ok;
 }
+#endif
 
 //============================================================================
 /*! Function : onRestoreStudy
@@ -2071,9 +2104,11 @@ bool SalomeApp_Application::onRestoreStudy( const QString& theDumpScript,
   // load study from the temporary directory
   QString command = QString( "execfile(r\"%1\")" ).arg( theDumpScript );
 
+#ifndef DISABLE_PYCONSOLE
   PyConsole_Console* pyConsole = app->pythonConsole();
   if ( pyConsole )
     pyConsole->execAndWait( command );
+#endif
 
   // remove temporary directory
   QFileInfo aScriptInfo = QFileInfo( theDumpScript );
@@ -2087,12 +2122,14 @@ bool SalomeApp_Application::onRestoreStudy( const QString& theDumpScript,
 
   if( SalomeApp_Study* newStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) )
   {
+#ifndef DISABLE_PYCONSOLE
     _PTR(Study) aStudyDS = newStudy->studyDS();
     app->getNoteBook()->Init( aStudyDS );
     newStudy->updateFromNotebook(theStudyName, theIsStudySaved);
     newStudy->Modified();
     updateDesktopTitle();
     updateActions();
+#endif
   }
   else
     ok = false;
@@ -2105,11 +2142,13 @@ bool SalomeApp_Application::onRestoreStudy( const QString& theDumpScript,
 */
 void SalomeApp_Application::afterCloseDoc()
 {
+#ifndef DISABLE_PYCONSOLE
   // emit signal to restore study from Python script
   if ( myNoteBook ) {
     emit dumpedStudyClosed( myNoteBook->getDumpedStudyScript(),
                             myNoteBook->getDumpedStudyName(),
                             myNoteBook->isDumpedStudySaved() );
   }
+#endif
   LightApp_Application::afterCloseDoc();
 }