Salome HOME
Debug of CMake build procedure
[modules/gui.git] / src / LightApp / LightApp_Application.cxx
index dd791b3a6050c6904afb399861250897d2846dad..e6970b23f1ab05c57bb867e79a67664ae00294f8 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
@@ -24,7 +24,7 @@
 // Created:   6/20/2005 18:39:45 PM
 // Author:    Natalia Donis
 
-#ifdef WNT
+#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, ...
@@ -42,6 +42,7 @@
 #include "LightApp_Application.h"
 #include "LightApp_Module.h"
 #include "LightApp_DataModel.h"
+#include "LightApp_DataOwner.h"
 #include "LightApp_Study.h"
 #include "LightApp_Preferences.h"
 #include "LightApp_PreferencesDlg.h"
   #include <QxScene_ViewWindow.h>
 #endif
 
+#ifndef DISABLE_GRAPHICSVIEW
+  #include "GraphicsView_Viewer.h"
+  #include "GraphicsView_ViewManager.h"
+  #include "LightApp_GVSelector.h"
+#endif
 
 #define VISIBILITY_COLUMN_WIDTH 25
 
@@ -340,6 +346,7 @@ LightApp_Application::LightApp_Application()
   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     OCCViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    OCCViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, OCCViewer_Viewer::Type() );
+  myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::Key_Space,             OCCViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::RotateLeft,  Qt::ALT+Qt::Key_Left,      OCCViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::RotateRight, Qt::ALT+Qt::Key_Right,     OCCViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::RotateUp,    Qt::ALT+Qt::Key_Up,        OCCViewer_Viewer::Type() );
@@ -353,6 +360,7 @@ LightApp_Application::LightApp_Application()
   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     VTKViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    VTKViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, VTKViewer_Viewer::Type() );
+  myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::Key_Space,             VTKViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::RotateLeft,  Qt::ALT+Qt::Key_Left,      VTKViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::RotateRight, Qt::ALT+Qt::Key_Right,     VTKViewer_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::RotateUp,    Qt::ALT+Qt::Key_Up,        VTKViewer_Viewer::Type() );
@@ -366,6 +374,7 @@ LightApp_Application::LightApp_Application()
   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     Plot2d_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    Plot2d_Viewer::Type() );
   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, Plot2d_Viewer::Type() );
+  myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::Key_Space,             Plot2d_Viewer::Type() );
 #endif
 
   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
@@ -678,7 +687,7 @@ void LightApp_Application::createActions()
       if ( icon.isNull() )
       {
         icon = modIcon;
-        INFOS ( "****************************************************************" << std::endl
+        INFOS ( "\n****************************************************************" << std::endl
                 <<  "*    Icon for " << (*it).toLatin1().constData()
                 << " not found. Using the default one." << std::endl
                 << "****************************************************************" << std::endl );
@@ -725,6 +734,9 @@ void LightApp_Application::createActions()
 #ifndef DISABLE_QXGRAPHVIEWER
   createActionForViewer( NewQxSceneViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_S );
 #endif
+#ifndef DISABLE_GRAPHICSVIEW
+  createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_R );
+#endif
 
   createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
                 Qt::ALT+Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) );
@@ -838,6 +850,11 @@ void LightApp_Application::onNewWindow()
   case NewQxSceneViewId:
     type = QxScene_Viewer::Type();
     break;
+#endif
+#ifndef DISABLE_GRAPHICSVIEW
+  case NewGraphicsViewId:
+    type = GraphicsView_Viewer::Type();
+    break;
 #endif
   }
 
@@ -962,6 +979,12 @@ void LightApp_Application::updateCommandsStatus()
   if( a )
     a->setEnabled( activeStudy() );
 #endif
+
+#ifndef DISABLE_GRAPHICSVIEW
+  a = action( NewGraphicsViewId );
+  if( a )
+    a->setEnabled( activeStudy() );
+#endif
 }
 
 /*!
@@ -1463,6 +1486,13 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType
     //QxScene_ViewWindow* wnd = dynamic_cast<QxScene_ViewWindow*>( viewMgr->getActiveView() );
   }
 #endif
+#ifndef DISABLE_GRAPHICSVIEW
+  if( vmType == GraphicsView_Viewer::Type() )
+  {
+    viewMgr = new GraphicsView_ViewManager( activeStudy(), desktop() );
+    new LightApp_GVSelector( (GraphicsView_Viewer*)viewMgr->getViewModel(), mySelMgr );
+  }
+#endif
 #ifndef DISABLE_OCCVIEWER
   if( vmType == OCCViewer_Viewer::Type() )
   {
@@ -1798,6 +1828,9 @@ void LightApp_Application::onPreferenceChanged( QString& modName, QString& secti
 /*!Remove all windows from study.*/
 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
 {
+  if ( SUIT_DataBrowser* ob = objectBrowser() )
+    ob->setModel(0);
+
   CAM_Application::beforeCloseDoc( s );
 }
 
@@ -2174,6 +2207,9 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   // ... "Trihedron" group <<end>>
   // .. "3D viewer" group <<end>>
 
+  QString formats;
+  int bgId;
+#ifndef DISABLE_OCCVIEWER
   // .. "OCC viewer" group <<start>>
   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), salomeCat );
 
@@ -2183,10 +2219,10 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   aValuesList.clear();
   anIndicesList.clear();
   txtList.clear();
-  QString formats = OCCViewer_Viewer::backgroundData( aValuesList, idList, txtList );
+  formats = OCCViewer_Viewer::backgroundData( aValuesList, idList, txtList );
   foreach( int gid, idList ) anIndicesList << gid;
   // .... -> 3D viewer background
-  int bgId = pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup,
+  bgId = pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup,
                                   LightApp_Preferences::Background, "OCCViewer", "background" );
   pref->setItemProperty( "gradient_names", aValuesList, bgId );
   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
@@ -2249,7 +2285,9 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->setItemProperty( "columns", 2, occGen );
   // ... -> empty frame (for layout) <<end>>
   // .. "OCC viewer" group <<end>>
+#endif
 
+#ifndef DISABLE_VTKVIEWER
   // .. "VTK viewer" group <<start>>
   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), salomeCat ); //viewTab
 
@@ -2269,7 +2307,9 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   aValuesList.clear();
   anIndicesList.clear();
   txtList.clear();
+#ifndef DISABLE_SALOMEOBJECT
   formats = SVTK_Viewer::backgroundData( aValuesList, idList, txtList );
+#endif
   foreach( int gid, idList ) anIndicesList << gid;
   bgId = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen,
                               LightApp_Preferences::Background, "VTKViewer", "background" );
@@ -2280,7 +2320,9 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
   pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
   pref->setItemProperty( "custom_enabled", false, bgId );
+#ifndef DISABLE_SALOMEOBJECT
   pref->setItemProperty( "image_formats", formats, bgId );
+#endif
   // .... -> speed increment
   int vtkSpeed = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED" ), vtkGen,
                                       LightApp_Preferences::IntSpin, "VTKViewer", "speed_value" );
@@ -2386,6 +2428,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->setItemProperty( "step", 0.1, transPref );
   // ... -> group names sub-group <<end>>
   // .. "VTK viewer" group <<end>>
+#endif
 
   // .. "Plot2d viewer" group <<start>>
   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), salomeCat ); //viewTab
@@ -3223,7 +3266,7 @@ void LightApp_Application::loadDockWindowsState()
   if ( aResMgr->hasValue("windows_geometry" ,modName ) ) {
     QByteArray arr;
     aResMgr->value("windows_geometry", modName , arr );
-    QByteArray aTargetArray = processState(arr, storeWin, storeTb, aDefaultState);
+    QByteArray aTargetArray = processState(arr, storeWin, storeTb, true, aDefaultState);
     desktop()->restoreState( aTargetArray );
   }
 
@@ -3304,7 +3347,7 @@ void LightApp_Application::saveDockWindowsState()
     modName = activeModule()->name();
 
   QByteArray arr = desktop()->saveState();
-  resourceMgr()->setValue( "windows_geometry", modName, processState(arr, storeWin, storeTb) );
+  resourceMgr()->setValue( "windows_geometry", modName, processState(arr, storeWin, storeTb, false) );
 
   QByteArray visArr;
   if ( myWinVis.contains( modName ) )
@@ -3446,6 +3489,7 @@ void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopu
       a->setShortcut( ob->shortcutKey(SUIT_DataBrowser::UpdateShortcut) );
   }
 
+#ifndef DISABLE_SALOMEOBJECT
   if ( selMgr && ob ) {
     SALOME_ListIO selected;
     selMgr->selectedObjects( selected );
@@ -3464,6 +3508,7 @@ void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopu
       }
     }
   }
+#endif
 
   selMgr->setSelectionCacheEnabled( cacheIsOn );
 }
@@ -3698,7 +3743,7 @@ bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
 
   if ( !isLibFound )
     {
-      INFOS( "****************************************************************" << std::endl
+      INFOS( "\n****************************************************************" << std::endl
           << "*    Warning: library " << lib.toLatin1().constData() << " cannot be found" << std::endl
           << "*    Module " << moduleTitle.toLatin1().constData() << " will not be available in GUI mode" << std::endl
           << "****************************************************************" << std::endl );
@@ -3735,7 +3780,7 @@ bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
             return true;
         }
 
-      printf( "****************************************************************\n" );
+      printf( "\n****************************************************************\n" );
       printf( "*    Warning: python library for %s cannot be found:\n", moduleTitle.toLatin1().constData() );
       if (!isPyLib)
         printf( "*    No module named %s\n", moduleName( moduleTitle ).toLatin1().constData() );
@@ -4103,12 +4148,27 @@ QList<QToolBar*> LightApp_Application::findToolBars() {
 /*!
   Internal method to parse toolbars and dockable windows state.
  */
-QByteArray LightApp_Application::processState(QByteArray& input, const bool processWin,const bool processTb, QByteArray defaultState) {
+QByteArray LightApp_Application::processState(QByteArray& input, 
+                                             const bool processWin, 
+                                             const bool processTb, 
+                                             const bool isRestoring, 
+                                             QByteArray defaultState) {
 
   QByteArray aRes;
   bool hasDefaultState  = !defaultState.isEmpty();
   bool isDockWinWriten = false;
-  if(processWin && processTb) {
+  int nbDocWin = -1;
+  //Write date from users settings
+  if(isRestoring){
+    QDataStream tmpInputData(&input, QIODevice::ReadOnly);
+    int marker, version;
+    uchar dockmarker;
+    tmpInputData >> marker;
+    tmpInputData >> version;
+    tmpInputData >> dockmarker;
+    tmpInputData >> nbDocWin;
+  }  
+  if(processWin && processTb && !isRestoring) {
     aRes = input;
   } else if(!processWin && !processTb ) {
     if(hasDefaultState)
@@ -4139,15 +4199,24 @@ QByteArray LightApp_Application::processState(QByteArray& input, const bool proc
     QDataStream* aTargetData = 0;
     int          aTargetIndex = -1;
 
-    if(processWin) {
-      //Write date from users settings
+    QByteArray currentArr = desktop()->saveState();
+    QDataStream anInputDataCur(&currentArr, QIODevice::ReadOnly);
+    bool useInputData = !isRestoring || (isRestoring && nbDocWin > 0);
+    if(processWin && useInputData) {
       aTargetData = &anInputData;
       aTargetIndex = toolBarMarkerIndex;
     } else {
       //Write date from default settings
       if(hasDefaultState) {
        aTargetData = &anInputDataDef;
-       aTargetIndex = toolBarMarkerIndexDef;   
+       aTargetIndex = toolBarMarkerIndexDef;
+      } else {
+       //If no default state, write current snapshot of the dockable windows
+       if(isRestoring) {
+         aTargetData = &anInputDataCur;
+         int toolBarMarkerIndexCur = getToolbarMarkerIndex(currentArr, aNames);
+         aTargetIndex = toolBarMarkerIndexCur;
+       }         
       }
     }
 
@@ -4205,3 +4274,16 @@ QByteArray LightApp_Application::processState(QByteArray& input, const bool proc
   }
   return aRes;
 }
+
+/*!
+  \brief Emits operationFinished signal.
+  \param theModuleName the name of the module which perfomed the operation
+  \param theOperationName the operation name
+  \param theEntryList the list of the created objects entries
+*/
+void LightApp_Application::emitOperationFinished( const QString& theModuleName,
+                                                  const QString& theOperationName,
+                                                  const QStringList& theEntryList )
+{
+  emit operationFinished( theModuleName, theOperationName, theEntryList );
+}