Salome HOME
Debug of CMake build procedure
[modules/gui.git] / src / LightApp / LightApp_Application.cxx
index 8880510ceb7385349396b8f42e4c36a3dc6fb176..e6970b23f1ab05c57bb867e79a67664ae00294f8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  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"
@@ -49,7 +50,6 @@
 #include "LightApp_AboutDlg.h"
 #include "LightApp_ModuleAction.h"
 // temporary commented
-//#include "LightApp_OBFilter.h"
 #include "LightApp_EventFilter.h"
 #include "LightApp_OBSelector.h"
 #include "LightApp_SelectionMgr.h"
   #include <VTKViewer_ViewModel.h>
 #endif
 
-//#ifndef DISABLE_SUPERVGRAPHVIEWER
-//  #include <SUPERVGraph_ViewModel.h>
-//  #include <SUPERVGraph_ViewFrame.h>
-//  #include <SUPERVGraph_ViewManager.h>
-//#endif
-
 #ifndef DISABLE_QXGRAPHVIEWER
-//VSR: QxGraph has been replaced by QxScene
-//  #include <QxGraph_ViewModel.h>
-//  #include <QxGraph_ViewWindow.h>
-//  #include <QxGraph_ViewManager.h>
   #include <QxScene_ViewManager.h>
   #include <QxScene_ViewModel.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
 
@@ -221,6 +216,55 @@ static const char* imageEmptyIcon[] = {
 
 int LightApp_Application::lastStudyId = 0;
 
+
+// Markers used to parse array with dockable windows and toolbars state.
+// For more details please see the qdockarealayout.cpp && qtoolbararealayout.cpp
+// in the Qt source code.
+
+#define QDockWidgetMarker 0xfd // = DockWidgetStateMarker
+#define QToolBarMarker 0xfc    // = ToolBarStateMarkerEx
+
+// Format of the Byte array with the windows and toolbar state is:
+// VersionMarker|version|DockWidgetStateMarker|nbDockWidgetLines|...DocWidgetData...|ToolBarStateMarkerEx|nbToolBarLines|...ToolBarData...
+
+//Find toolbar marker position in the array in the following way:
+//since the 'toolbar marker' is not unique, find index of first occurrence of the
+//'toolbar marker' in the array and check that next string is name of the toolbar
+
+int getToolbarMarkerIndex(QByteArray input, const QStringList& aFlags) {
+  int aResult = -1,tmp = 0;
+  int inputLen = input.length();
+  QDataStream anInputData(&input, QIODevice::ReadOnly);
+  while(tmp < inputLen) {
+      tmp = input.indexOf(QToolBarMarker, tmp + 1);
+      if(tmp < 0 )
+       break;
+      anInputData.device()->seek(tmp);
+      uchar mark;
+      anInputData>>mark;
+      int lines;
+      anInputData >> lines;
+
+      if(lines == 0 && anInputData.atEnd()){
+       //Case then array doesn't contain information about toolbars,
+       aResult = tmp;
+       break;
+      }
+
+      int pos;
+      anInputData >> pos;
+      int cnt;
+      anInputData >> cnt;
+      QString str;
+      anInputData>>str;
+      if(aFlags.contains(str)) {
+       aResult = tmp;
+       break;
+      }
+    }        
+  return aResult;
+}
+
 /*!
   \return last global id of study
 */
@@ -254,6 +298,7 @@ LightApp_Application::LightApp_Application()
 
   STD_TabDesktop* desk = new STD_TabDesktop();
   desk->setFullScreenAllowed(false);
+  desk->setMinimizeAllowed(false);
 
   setDesktop( desk );
 
@@ -265,6 +310,7 @@ LightApp_Application::LightApp_Application()
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
   QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
 
+  QtxWebBrowser::setResourceManager( aResMgr );
   QtxWebBrowser::setData("browser:icon",          aResMgr->loadPixmap( "LightApp", tr( "BROWSER_ICON" ) ) );
   QtxWebBrowser::setData("browser:title",         tr( "BROWSER_TITLE" ) );
   QtxWebBrowser::setData("toolbar:title",         tr( "BROWSER_TOOLBAR_TITLE" ) );
@@ -300,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() );
@@ -313,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() );
@@ -326,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() ) );
@@ -469,14 +518,14 @@ void LightApp_Application::createActionForViewer( const int id,
   QString vtlt = tr( QString( "NEW_WINDOW_%1" ).arg( suffix ).toLatin1().constData() );
   QString tip = tr( "CREATING_NEW_WINDOW" ).arg( vtlt.remove( "&" ) );
   QAction* a = createAction( id,                      // menu action id
-                            tip,                     // status tip
-                            QIcon(),                 // icon
-                            vtlt,                    // menu text
+                             tip,                     // status tip
+                             QIcon(),                 // icon
+                             vtlt,                    // menu text
                              tip,                     // tooltip
                              accel,                   // shortcut
-                            desktop(),               // parent
+                             desktop(),               // parent
                              false,                   // toggle flag
-                            this,                    // receiver
+                             this,                    // receiver
                              SLOT( onNewWindow() ) ); // slot
   createMenu( a, parentId, -1 );
 }
@@ -485,19 +534,22 @@ void LightApp_Application::createActionForViewer( const int id,
 
 void LightApp_Application::createActions()
 {
-  STD_Application::createActions();
+  CAM_Application::createActions();
 
   SUIT_Desktop* desk = desktop();
   SUIT_ResourceMgr* resMgr = resourceMgr();
 
-  //! Preferences
+  // Preferences
   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIcon(),
                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
                 Qt::CTRL+Qt::Key_R, desk, false, this, SLOT( onPreferences() ) );
 
-  //! Help for modules
+  // Help menu:
+
+  // - Help for modules
+
   int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
-  createMenu( separator(), helpMenu, -1, 1 );
+  createMenu( separator(), helpMenu, -1, 10 );
   QStringList aModuleList;
   modules( aModuleList, false );
   aModuleList.prepend( "GUI" );
@@ -505,8 +557,6 @@ void LightApp_Application::createActions()
 
   int id = LightApp_Application::UserID + FIRST_HELP_ID;
 
-  // help for other existing modules
-
   QString aModule;
   foreach( aModule, aModuleList ) {
     if ( aModule.isEmpty() )                                         // module title (user name)
@@ -549,7 +599,7 @@ void LightApp_Application::createActions()
       QString helpFileName = fileIt.key();
       // remove all '//' occurances 
       while ( helpFileName.contains( "//" ) )
-       helpFileName.replace( "//", "" );
+        helpFileName.replace( "//", "" );
       // obtain submenus hierarchy if given
       QStringList smenus = helpFileName.split( "/" );
       helpFileName = smenus.last();
@@ -560,7 +610,7 @@ void LightApp_Application::createActions()
                                  0, desk, false, this, SLOT( onHelpContentsModule() ) );
       a->setData( fileIt.value() );
       if ( !helpSubMenu.isEmpty() ) {
-       smenus.prepend( helpSubMenu );
+        smenus.prepend( helpSubMenu );
       }
       // create sub-menus hierarchy
       int menuId = helpMenu;
@@ -572,6 +622,24 @@ void LightApp_Application::createActions()
     }
   }
 
+  // - Additional help items
+
+  createMenu( separator(), helpMenu, -1, 5 );
+
+  QStringList addHelpItems = resMgr->parameters( "add_help" );
+  foreach ( QString addHelpItem, addHelpItems ) {
+    QString valueStr = resMgr->stringValue( "add_help", addHelpItem );
+    if ( !valueStr.isEmpty() && QFile::exists( valueStr ) ) {
+      QAction* a = createAction( id, addHelpItem,
+                                 resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false ),
+                                 addHelpItem, addHelpItem,
+                                 0, desk, false, this, SLOT( onHelpContentsModule() ) );
+      a->setData( valueStr );
+      createMenu( a, helpMenu, -1, 5 );
+      id++;
+    }
+  }
+
   //! MRU
   static QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), 0 );
   connect( mru, SIGNAL( activated( const QString& ) ), this, SLOT( onMRUActivated( const QString& ) ) );
@@ -619,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 );
@@ -664,10 +732,11 @@ void LightApp_Application::createActions()
   createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), Qt::ALT+Qt::Key_K );
 #endif
 #ifndef DISABLE_QXGRAPHVIEWER
-//VSR: QxGraph has been replaced by QxScene
-//  createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_C );
   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() ) );
@@ -778,13 +847,14 @@ void LightApp_Application::onNewWindow()
     break;
 #endif
 #ifndef DISABLE_QXGRAPHVIEWER
-//VSR: QxGraph has been replaced by QxScene
-//  case NewQxGraphViewId:
-//    type = QxGraph_Viewer::Type();
-//    break;
   case NewQxSceneViewId:
     type = QxScene_Viewer::Type();
     break;
+#endif
+#ifndef DISABLE_GRAPHICSVIEW
+  case NewGraphicsViewId:
+    type = GraphicsView_Viewer::Type();
+    break;
 #endif
   }
 
@@ -905,12 +975,16 @@ void LightApp_Application::updateCommandsStatus()
 #endif
 
 #ifndef DISABLE_QXGRAPHVIEWER
-//VSR: QxGraph has been replaced by QxScene
-//  a = action( NewQxGraphViewId );
   a = action( NewQxSceneViewId );
   if( a )
     a->setEnabled( activeStudy() );
 #endif
+
+#ifndef DISABLE_GRAPHICSVIEW
+  a = action( NewGraphicsViewId );
+  if( a )
+    a->setEnabled( activeStudy() );
+#endif
 }
 
 /*!
@@ -1006,7 +1080,7 @@ void LightApp_Application::onHelpContentsModule()
     // is defined. On Linux platform QWebKit doesn't work correctly without 'file://' protocol.
     QtxWebBrowser::loadUrl(helpFile);
 #else
-       QtxWebBrowser::loadUrl(QString("file://%1").arg(helpFile));
+    QtxWebBrowser::loadUrl(QString("file://%1").arg(helpFile));
 #endif
   }
 }
@@ -1077,9 +1151,9 @@ void LightApp_Application::onHelpContextModule( const QString& theComponentName,
 #ifdef WIN32
     // On Win32 platform QWebKit of the Qt 4.6.3 hang up in case 'file://' protocol 
     // is defined. On Linux platform QWebKit doesn't work correctly without 'file://' protocol.
-       QtxWebBrowser::loadUrl(helpFile, context);
+    QtxWebBrowser::loadUrl(helpFile, context);
 #else
-       QtxWebBrowser::loadUrl(QString("file://%1").arg(helpFile),context);
+    QtxWebBrowser::loadUrl(QString("file://%1").arg(helpFile), context);
 #endif
     
   }
@@ -1279,11 +1353,21 @@ LogWindow* LightApp_Application::logWindow()
 
 #ifndef DISABLE_PYCONSOLE
 /*!
+  This returns the python console integrated to the GUI. Depending
+  when you request the python console, this function could return
+  null. Then the optional parameter force (default to false) can be
+  set to force the creation of the python console if it is not done
+  already. 
+  \param force - if true, the pythonConsole is created if it does not exist yet
   \return Python Console
 */
-PyConsole_Console* LightApp_Application::pythonConsole()
+PyConsole_Console* LightApp_Application::pythonConsole(const bool force)
 {
-  return qobject_cast<PyConsole_Console*>( dockWindow( WT_PyConsole ) );
+  QWidget* wid = dockWindow( WT_PyConsole );
+  if ( !wid && force==true) {
+    wid = getWindow(WT_PyConsole);
+  }
+  return qobject_cast<PyConsole_Console*>( wid );
 }
 #endif
 
@@ -1393,18 +1477,7 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType
     }
   }
 #endif
-  //#ifndef DISABLE_SUPERVGRAPHVIEWER
-  //  if( vmType == SUPERVGraph_Viewer::Type() )
-  //  {
-  //    viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop(), new SUPERVGraph_Viewer() );
-  //  }
-  //#endif
 #ifndef DISABLE_QXGRAPHVIEWER
-//VSR: QxGraph has been replaced by QxScene
-//  if( vmType == QxGraph_Viewer::Type() )
-//    {
-//      viewMgr = new QxGraph_ViewManager( activeStudy(), desktop(), new QxGraph_Viewer() );
-//    }
   if( vmType == QxScene_Viewer::Type() )
   {
     viewMgr = new QxScene_ViewManager( activeStudy(), desktop() );
@@ -1413,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() )
   {
@@ -1424,23 +1504,21 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType
     vm = new OCCViewer_Viewer( true );
 #endif
     vm->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
-                      resMgr->backgroundValue( "OCCViewer", "xz_background", vm->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
+                       resMgr->backgroundValue( "OCCViewer", "xz_background", vm->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
     vm->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
-                      resMgr->backgroundValue( "OCCViewer", "yz_background", vm->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
+                       resMgr->backgroundValue( "OCCViewer", "yz_background", vm->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
     vm->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
-                      resMgr->backgroundValue( "OCCViewer", "xy_background", vm->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
+                       resMgr->backgroundValue( "OCCViewer", "xy_background", vm->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
     vm->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
-                      resMgr->backgroundValue( "OCCViewer", "background", vm->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
-
-    vm->setTrihedronSize(  resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ),
-                           resMgr->booleanValue( "OCCViewer", "relative_size", vm->trihedronRelative() ));
-    int u( 1 ), v( 1 );
-    vm->isos( u, v );
-    u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
-    v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
-    vm->setIsos( u, v );
-    vm->setInteractionStyle( resMgr->integerValue( "OCCViewer", "navigation_mode", vm->interactionStyle() ) );
-    vm->setZoomingStyle( resMgr->integerValue( "OCCViewer", "zooming_mode", vm->zoomingStyle() ) );
+                       resMgr->backgroundValue( "OCCViewer", "background", vm->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
+
+    vm->setTrihedronSize(  resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
+                           resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ));
+    vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
+    vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
+    vm->enablePreselection( resMgr->booleanValue( "OCCViewer", "enable_preselection", vm->isPreselectionEnabled() ) );
+    vm->enableSelection(    resMgr->booleanValue( "OCCViewer", "enable_selection",    vm->isSelectionEnabled() ) );
+
     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
     new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
   }
@@ -1459,12 +1537,13 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType
     {
       vm->setProjectionMode( resMgr->integerValue( "VTKViewer", "projection_mode", vm->projectionMode() ) );
       vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) );
-      vm->setTrihedronSize( resMgr->doubleValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
-                            resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
-      vm->setStaticTrihedronVisible( resMgr->booleanValue( "VTKViewer", "show_static_trihedron", vm->isStaticTrihedronVisible() ) );
-      vm->setInteractionStyle( resMgr->integerValue( "VTKViewer", "navigation_mode", vm->interactionStyle() ) );
-      vm->setZoomingStyle( resMgr->integerValue( "VTKViewer", "zooming_mode", vm->zoomingStyle() ) );
-      vm->setDynamicPreSelection( resMgr->booleanValue( "VTKViewer", "dynamic_preselection", vm->dynamicPreSelection() ) );
+      vm->setTrihedronSize( resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
+                            resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ) );
+      vm->setStaticTrihedronVisible( resMgr->booleanValue( "3DViewer", "show_static_trihedron", vm->isStaticTrihedronVisible() ) );
+      vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
+      vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
+      vm->setPreSelectionMode(resMgr->integerValue( "VTKViewer", "preselection", vm->preSelectionMode() ) );
+      vm->enableSelection( resMgr->booleanValue( "VTKViewer", "enable_selection", vm->isSelectionEnabled() ) );
       vm->setIncrementalSpeed( resMgr->integerValue( "VTKViewer", "speed_value", vm->incrementalSpeed() ),
                                resMgr->integerValue( "VTKViewer", "speed_mode", vm->incrementalSpeedMode() ) );
       vm->setSpacemouseButtons( resMgr->integerValue( "VTKViewer", "spacemouse_func1_btn", vm->spacemouseBtn(1) ),
@@ -1749,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 );
 }
 
@@ -1808,7 +1890,7 @@ QWidget* LightApp_Application::createWindow( const int flag )
     SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
     if ( proxyModel ) {
       connect( proxyModel, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
-              this,       SLOT( onDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
+               this,       SLOT( onDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
     }
 
     // temporary commented
@@ -1816,8 +1898,6 @@ QWidget* LightApp_Application::createWindow( const int flag )
     OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
     if( ob_list )
       ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
-
-    ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
     */
 
     // Create OBSelector
@@ -1833,7 +1913,7 @@ QWidget* LightApp_Application::createWindow( const int flag )
 #ifndef DISABLE_PYCONSOLE
   else  if ( flag == WT_PyConsole )
   {
-    PyConsole_Console* pyCons = new PyConsole_Console( desktop(),new LightApp_PyInterp());
+    PyConsole_Console* pyCons = new PyConsole_EnhConsole( desktop(),new LightApp_PyInterp());
     pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) );
     pyCons->setFont(resourceMgr()->fontValue( "PyConsole", "font" ));
     pyCons->setIsShowBanner(resourceMgr()->booleanValue( "PyConsole", "show_banner", true ));
@@ -2020,6 +2100,9 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
 
   // ... "Look and feel" group <<start>>
   int lookGroup = pref->addPreference( tr( "PREF_GROUP_LOOK_AND_FEEL" ), genTab );
+  pref->setItemProperty( "columns", 2, lookGroup );
+  // .... -> show splash-screen
+  pref->addPreference( tr( "PREF_SHOW_SPLASH" ), lookGroup, LightApp_Preferences::Bool, "launch", "splash" );
   // .... -> opaque resize
   pref->addPreference( tr( "PREF_OPAQUE_RESIZE" ), lookGroup, LightApp_Preferences::Bool, "desktop", "opaque_resize" );
   // .... -> drop-down buttons 
@@ -2035,6 +2118,8 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
   // .... -> store windows geometry
   pref->addPreference( tr( "PREF_STORE_POS" ),  studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
+  pref->addPreference( "", studyGroup, LightApp_Preferences::Space );
+  pref->addPreference( tr( "PREF_STORE_TOOL_POS" ),  studyGroup, LightApp_Preferences::Bool, "Study", "store_tool_positions" );
   // .... -> auto-save
   int autoSaveInterval = pref->addPreference( tr( "PREF_AUTO_SAVE" ),  studyGroup,
                                               LightApp_Preferences::IntSpin, "Study", "auto_save_interval" );
@@ -2085,37 +2170,48 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   // ... "MRU" preferences group <<end>>
   // .. "General" preferences tab <<end>>
 
-  // .. "OCC viewer" group <<start>>
-  int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), salomeCat );
-
+  // .. "3D viewer" group <<start>>
+  int Viewer3DGroup = pref->addPreference( tr( "PREF_GROUP_3DVIEWER" ), salomeCat );
+  // ... -> navigation mode
+  int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), Viewer3DGroup,
+                                          LightApp_Preferences::Selector, "3DViewer", "navigation_mode" );
+  aValuesList.clear();
+  anIndicesList.clear();
+  aValuesList   << tr("PREF_STANDARD_STYLE") << tr("PREF_KEYFREE_STYLE");
+  anIndicesList << 0                         << 1;
+  pref->setItemProperty( "strings", aValuesList,   vtkStyleMode );
+  pref->setItemProperty( "indexes", anIndicesList, vtkStyleMode );
+  // ... -> zooming mode
+  #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
+    int occZoomingStyleMode = pref->addPreference( tr( "PREF_ZOOMING" ), Viewer3DGroup,
+                                                   LightApp_Preferences::Selector, "3DViewer", "zooming_mode" );
+    aValuesList.clear();
+    anIndicesList.clear();
+    aValuesList   << tr("PREF_ZOOMING_AT_CENTER") << tr("PREF_ZOOMING_AT_CURSOR");
+    anIndicesList << 0                            << 1;
+    pref->setItemProperty( "strings", aValuesList,   occZoomingStyleMode );
+    pref->setItemProperty( "indexes", anIndicesList, occZoomingStyleMode );
+  #endif
   // ... "Trihedron" group <<start>>
-  int occTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), occGroup );
+  int occTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), Viewer3DGroup );
   pref->setItemProperty( "columns", 2, occTriGroup );
   // .... -> trihedron size
   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occTriGroup,
-                                   LightApp_Preferences::DblSpin, "OCCViewer", "trihedron_size" );
+                                   LightApp_Preferences::DblSpin, "3DViewer", "trihedron_size" );
   pref->setItemProperty( "min", 1.0E-06, occTS );
   pref->setItemProperty( "max", 1000, occTS );
   // .... -> relative size of trihedron
-  pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), occTriGroup, LightApp_Preferences::Bool, "OCCViewer", "relative_size" );
+  pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "relative_size" );
   // .... -> show static trihedron
-  pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), occTriGroup, LightApp_Preferences::Bool, "OCCViewer", "show_static_trihedron" );
+  pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "show_static_trihedron" );
   // ... "Trihedron" group <<end>>
+  // .. "3D viewer" group <<end>>
 
-  // ... "Iso-lines" group <<start>>
-  int isoGroup = pref->addPreference( tr( "PREF_ISOS" ), occGroup );
-  pref->setItemProperty( "columns", 2, isoGroup );
-  // .... -> nb isos U
-  int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), isoGroup,
-                                  LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
-  pref->setItemProperty( "min", 0, isoU );
-  pref->setItemProperty( "max", 100000, isoU );
-  // .... -> nb isos V
-  int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), isoGroup,
-                                  LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
-  pref->setItemProperty( "min", 0, isoV );
-  pref->setItemProperty( "max", 100000, isoV );
-  // ... "Iso-lines" group <<end>>
+  QString formats;
+  int bgId;
+#ifndef DISABLE_OCCVIEWER
+  // .. "OCC viewer" group <<start>>
+  int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), salomeCat );
 
   // ... "Background" group <<start>>
   int bgGroup = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup );
@@ -2123,11 +2219,11 @@ 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,
-                                 LightApp_Preferences::Background, "OCCViewer", "background" );
+  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 );
   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
@@ -2138,7 +2234,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->setItemProperty( "image_formats", formats, bgId );
   // .... -> XZ viewer background
   bgId = pref->addPreference( tr( "PREF_XZVIEWER_BACKGROUND" ), bgGroup,
-                             LightApp_Preferences::Background, "OCCViewer", "xz_background" );
+                              LightApp_Preferences::Background, "OCCViewer", "xz_background" );
   pref->setItemProperty( "gradient_names", aValuesList, bgId );
   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
@@ -2149,7 +2245,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->setItemProperty( "image_formats", formats, bgId );
   // .... -> YZ viewer background
   bgId = pref->addPreference( tr( "PREF_YZVIEWER_BACKGROUND" ), bgGroup,
-                             LightApp_Preferences::Background, "OCCViewer", "yz_background" );
+                              LightApp_Preferences::Background, "OCCViewer", "yz_background" );
   pref->setItemProperty( "gradient_names", aValuesList, bgId );
   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
@@ -2160,7 +2256,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->setItemProperty( "image_formats", formats, bgId );
   // .... -> XY viewer background
   bgId = pref->addPreference( tr( "PREF_XYVIEWER_BACKGROUND" ), bgGroup,
-                             LightApp_Preferences::Background, "OCCViewer", "xy_background" );
+                              LightApp_Preferences::Background, "OCCViewer", "xy_background" );
   pref->setItemProperty( "gradient_names", aValuesList, bgId );
   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
@@ -2171,33 +2267,27 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->setItemProperty( "image_formats", formats, bgId );
   // ... "Background" group <<end>>
 
+
+  // ... "Selection" group <<start>>
+  int occSelectionGroup = pref->addPreference( tr( "PREF_GROUP_SELECTION" ), occGroup );
+  pref->setItemProperty( "columns", 2, occSelectionGroup );
+  // .... -> enable preselection
+  pref->addPreference( tr( "PREF_ENABLE_PRESELECTION" ), occSelectionGroup, 
+                      LightApp_Preferences::Bool, "OCCViewer", "enable_preselection" );
+  // .... -> enable selection
+  pref->addPreference( tr( "PREF_ENABLE_SELECTION" ), occSelectionGroup, 
+                      LightApp_Preferences::Bool, "OCCViewer", "enable_selection" );
+  // ... "Selection" group <<end>>
+
   // ... -> empty frame (for layout) <<start>>
   int occGen = pref->addPreference( "", occGroup, LightApp_Preferences::Frame );
   pref->setItemProperty( "margin",  0, occGen );
   pref->setItemProperty( "columns", 2, occGen );
-  // .... -> navigation mode
-  int occStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), occGen,
-                                          LightApp_Preferences::Selector, "OCCViewer", "navigation_mode" );
-  aValuesList.clear();
-  anIndicesList.clear();
-  aValuesList   << tr("PREF_STANDARD_STYLE") << tr("PREF_KEYFREE_STYLE");
-  anIndicesList << 0                         << 1;
-  pref->setItemProperty( "strings", aValuesList,   occStyleMode );
-  pref->setItemProperty( "indexes", anIndicesList, occStyleMode );
-  // .... -> zooming mode
-#if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
-  int occZoomingStyleMode = pref->addPreference( tr( "PREF_ZOOMING" ), occGen,
-                                                 LightApp_Preferences::Selector, "OCCViewer", "zooming_mode" );
-  aValuesList.clear();
-  anIndicesList.clear();
-  aValuesList   << tr("PREF_ZOOMING_AT_CENTER") << tr("PREF_ZOOMING_AT_CURSOR");
-  anIndicesList << 0                            << 1;
-  pref->setItemProperty( "strings", aValuesList,   occZoomingStyleMode );
-  pref->setItemProperty( "indexes", anIndicesList, occZoomingStyleMode );
-#endif
   // ... -> 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
 
@@ -2217,10 +2307,12 @@ 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" );
+                              LightApp_Preferences::Background, "VTKViewer", "background" );
   pref->setItemProperty( "gradient_names", aValuesList, bgId );
   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
@@ -2228,25 +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 );
-  // .... -> navigation mode
-  int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), vtkGen,
-                                          LightApp_Preferences::Selector, "VTKViewer", "navigation_mode" );
-  aValuesList.clear();
-  anIndicesList.clear();
-  aValuesList   << tr("PREF_STANDARD_STYLE") << tr("PREF_KEYFREE_STYLE");
-  anIndicesList << 0                         << 1;
-  pref->setItemProperty( "strings", aValuesList,   vtkStyleMode );
-  pref->setItemProperty( "indexes", anIndicesList, vtkStyleMode );
-  // .... -> zooming mode
-  int vtkZoomingStyleMode = pref->addPreference( tr( "PREF_ZOOMING" ), vtkGen,
-                                                 LightApp_Preferences::Selector, "VTKViewer", "zooming_mode" );
-  aValuesList.clear();
-  anIndicesList.clear();
-  aValuesList   << tr("PREF_ZOOMING_AT_CENTER") << tr("PREF_ZOOMING_AT_CURSOR");
-  anIndicesList << 0                            << 1;
-  pref->setItemProperty( "strings", aValuesList,   vtkZoomingStyleMode );
-  pref->setItemProperty( "indexes", anIndicesList, vtkZoomingStyleMode );
+#endif
   // .... -> speed increment
   int vtkSpeed = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED" ), vtkGen,
                                       LightApp_Preferences::IntSpin, "VTKViewer", "speed_value" );
@@ -2261,23 +2337,24 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   anIndicesList << 0                     << 1;
   pref->setItemProperty( "strings", aValuesList,   vtkSpeedMode );
   pref->setItemProperty( "indexes", anIndicesList, vtkSpeedMode );
-  // .... -> dynamic pre-selection
-  pref->addPreference( tr( "PREF_DYNAMIC_PRESELECTION" ),  vtkGen, LightApp_Preferences::Bool, "VTKViewer", "dynamic_preselection" );
-  // ... -> empty frame (for layout) <<end>>
 
-  // ... "Trihedron" group <<start>>
-  int vtkTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), vtkGroup );
-  pref->setItemProperty( "columns", 2, vtkTriGroup );
-  // .... -> trihedron size
-  int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkTriGroup,
-                                   LightApp_Preferences::DblSpin, "VTKViewer", "trihedron_size" );
-  pref->setItemProperty( "min", 1.0E-06, vtkTS );
-  pref->setItemProperty( "max", 150, vtkTS );
-  // .... -> relative size of trihedron
-  pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkTriGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
-  // .... -> static trihedron
-  pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), vtkTriGroup, LightApp_Preferences::Bool, "VTKViewer", "show_static_trihedron" );
-  // ... "Trihedron" group <<end>>
+  // ... "Selection" group <<start>>
+  int vtkSelectionGroup = pref->addPreference( tr( "PREF_GROUP_SELECTION" ), vtkGroup );
+  pref->setItemProperty( "columns", 2, vtkSelectionGroup );
+  // .... -> preselection
+  int vtkPreselection = pref->addPreference( tr( "PREF_PRESELECTION" ),  vtkSelectionGroup, 
+                                             LightApp_Preferences::Selector, "VTKViewer", "preselection" );
+  aValuesList.clear();
+  anIndicesList.clear();
+  aValuesList   << tr("PREF_PRESELECTION_STANDARD") << tr("PREF_PRESELECTION_DYNAMIC") << tr("PREF_PRESELECTION_DISABLED");
+  anIndicesList << 0 << 1 << 2;
+  pref->setItemProperty( "strings", aValuesList,   vtkPreselection );
+  pref->setItemProperty( "indexes", anIndicesList, vtkPreselection );
+  // .... -> enable selection
+  pref->addPreference( tr( "PREF_ENABLE_SELECTION" ), vtkSelectionGroup, LightApp_Preferences::Bool, "VTKViewer", "enable_selection" );
+  // ... "Selection" group <<end>>
+
+  // ... -> empty frame (for layout) <<end>>
 
   // ... space mouse sub-group <<start>>
   int vtkSM = pref->addPreference( tr( "PREF_FRAME_SPACEMOUSE" ), vtkGroup, LightApp_Preferences::GroupBox );
@@ -2351,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
@@ -2500,17 +2578,17 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
     }
   }
 
-#ifndef DISABLE_OCCVIEWER
-  if ( sec == QString( "OCCViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )))
+  if ( sec == QString( "3DViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )))
   {
     double sz = resMgr->doubleValue( sec, "trihedron_size", -1 );
     bool relative = resMgr->booleanValue( sec, "relative_size", true );
     QList<SUIT_ViewManager*> lst;
+#ifndef DISABLE_OCCVIEWER
     viewManagers( OCCViewer_Viewer::Type(), lst );
-    QListIterator<SUIT_ViewManager*> it( lst );
-    while ( it.hasNext() && sz >= 0 )
+    QListIterator<SUIT_ViewManager*> itOCC( lst );
+    while ( itOCC.hasNext() && sz >= 0 )
     {
-      SUIT_ViewModel* vm = it.next()->getViewModel();
+      SUIT_ViewModel* vm = itOCC.next()->getViewModel();
       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
         continue;
 
@@ -2518,19 +2596,38 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
       occVM->setTrihedronSize( sz, relative );
       occVM->getAISContext()->UpdateCurrentViewer();
     }
-  }
 #endif
+#ifndef DISABLE_VTKVIEWER
+#ifndef DISABLE_SALOMEOBJECT
+    viewManagers( SVTK_Viewer::Type(), lst );
+    QListIterator<SUIT_ViewManager*> itVTK( lst );
+    while ( itVTK.hasNext() && sz >= 0 )
+    {
+      SUIT_ViewModel* vm = itVTK.next()->getViewModel();
+      if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
+        continue;
 
-#ifndef DISABLE_OCCVIEWER
-  if ( sec == QString( "OCCViewer" ) && param == QString( "show_static_trihedron" ) )
+      SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
+      if( vtkVM )
+      {
+        vtkVM->setTrihedronSize( sz, relative );
+        vtkVM->Repaint();
+      }
+    }
+#endif
+#endif
+  }
+
+  if ( sec == QString( "3DViewer" ) && param == QString( "show_static_trihedron" ) )
   {
-    bool isVisible = resMgr->booleanValue( "OCCViewer", "show_static_trihedron", true );
+    bool isVisible = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
     QList<SUIT_ViewManager*> lst;
+#ifndef DISABLE_OCCVIEWER
     viewManagers( OCCViewer_Viewer::Type(), lst );
-    QListIterator<SUIT_ViewManager*> it( lst );
-    while ( it.hasNext() )
+    QListIterator<SUIT_ViewManager*> itOCC( lst );
+    while ( itOCC.hasNext() )
     {
-      SUIT_ViewModel* vm = it.next()->getViewModel();
+      SUIT_ViewModel* vm = itOCC.next()->getViewModel();
       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
         continue;
 
@@ -2540,32 +2637,66 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
         occVM->setStaticTrihedronDisplayed( isVisible );
       }
     }
-  }
 #endif
+#ifndef DISABLE_VTKVIEWER
+#ifndef DISABLE_SALOMEOBJECT
+    viewManagers( SVTK_Viewer::Type(), lst );
+    QListIterator<SUIT_ViewManager*> itVTK( lst );
+    while ( itVTK.hasNext() )
+    {
+      SUIT_ViewModel* vm = itVTK.next()->getViewModel();
+      if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
+        continue;
 
-#ifndef DISABLE_OCCVIEWER
-  if ( sec == QString( "OCCViewer" ) && param == QString( "navigation_mode" ) )
+      SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
+      if( vtkVM )
+      {
+        vtkVM->setStaticTrihedronVisible( isVisible );
+        vtkVM->Repaint();
+      }
+    }
+#endif
+#endif
+  }
+
+  if ( sec == QString( "3DViewer" ) && param == QString( "navigation_mode" ) )
   {
-    int mode = resMgr->integerValue( "OCCViewer", "navigation_mode", 0 );
+    int mode = resMgr->integerValue( "3DViewer", "navigation_mode", 0 );
     QList<SUIT_ViewManager*> lst;
+#ifndef DISABLE_OCCVIEWER
     viewManagers( OCCViewer_Viewer::Type(), lst );
-    QListIterator<SUIT_ViewManager*> it( lst );
-    while ( it.hasNext() )
+    QListIterator<SUIT_ViewManager*> itOCC( lst );
+    while ( itOCC.hasNext() )
     {
-      SUIT_ViewModel* vm = it.next()->getViewModel();
+      SUIT_ViewModel* vm = itOCC.next()->getViewModel();
       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
         continue;
 
       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
       occVM->setInteractionStyle( mode );
     }
-  }
 #endif
+#ifndef DISABLE_VTKVIEWER
+#ifndef DISABLE_SALOMEOBJECT
+    viewManagers( SVTK_Viewer::Type(), lst );
+    QListIterator<SUIT_ViewManager*> itVTK( lst );
+    while ( itVTK.hasNext() )
+    {
+      SUIT_ViewModel* vm = itVTK.next()->getViewModel();
+      if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
+        continue;
+
+      SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
+      if( vtkVM ) vtkVM->setInteractionStyle( mode );
+    }
+#endif
+#endif
+  }
 
 #ifndef DISABLE_OCCVIEWER
-  if ( sec == QString( "OCCViewer" ) && param == QString( "zooming_mode" ) )
+  if ( sec == QString( "OCCViewer" ) && param == QString( "enable_preselection" ) )
   {
-    int mode = resMgr->integerValue( "OCCViewer", "zooming_mode", 0 );
+    bool isToEnablePreselection = resMgr->booleanValue( "OCCViewer", "enable_preselection", true );
     QList<SUIT_ViewManager*> lst;
     viewManagers( OCCViewer_Viewer::Type(), lst );
     QListIterator<SUIT_ViewManager*> it( lst );
@@ -2576,84 +2707,69 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
         continue;
 
       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
-      occVM->setZoomingStyle( mode );
+      occVM->enablePreselection( isToEnablePreselection );
     }
   }
 #endif
 
-#ifndef DISABLE_VTKVIEWER
-  if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
+#ifndef DISABLE_OCCVIEWER
+  if ( sec == QString( "OCCViewer" ) && param == QString( "enable_selection" ) )
   {
-    double sz = resMgr->doubleValue( "VTKViewer", "trihedron_size", -1 );
-    bool isRelative = resMgr->booleanValue( "VTKViewer", "relative_size", true );
+    bool isToEnableSelection = resMgr->booleanValue( "OCCViewer", "enable_selection", true );
     QList<SUIT_ViewManager*> lst;
-#ifndef DISABLE_SALOMEOBJECT
-    viewManagers( SVTK_Viewer::Type(), lst );
+    viewManagers( OCCViewer_Viewer::Type(), lst );
     QListIterator<SUIT_ViewManager*> it( lst );
-    while ( it.hasNext() && sz >= 0 )
+    while ( it.hasNext() )
     {
       SUIT_ViewModel* vm = it.next()->getViewModel();
-      if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
+      if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
         continue;
 
-      SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
-      if( vtkVM )
-      {
-        vtkVM->setTrihedronSize( sz, isRelative );
-        vtkVM->Repaint();
-      }
+      OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+      occVM->enableSelection( isToEnableSelection );
     }
-#endif
   }
 #endif
 
-#ifndef DISABLE_VTKVIEWER
-  if ( sec == QString( "VTKViewer" ) && (param == QString( "speed_value" ) || param == QString( "speed_mode" )) )
+  if ( sec == QString( "3DViewer" ) && param == QString( "zooming_mode" ) )
   {
-    int speed = resMgr->integerValue( "VTKViewer", "speed_value", 10 );
-    int mode = resMgr->integerValue( "VTKViewer", "speed_mode", 0 );
+    int mode = resMgr->integerValue( "3DViewer", "zooming_mode", 0 );
     QList<SUIT_ViewManager*> lst;
-#ifndef DISABLE_SALOMEOBJECT
-    viewManagers( SVTK_Viewer::Type(), lst );
-    QListIterator<SUIT_ViewManager*> it( lst );
-    while ( it.hasNext() )
+#ifndef DISABLE_OCCVIEWER
+    viewManagers( OCCViewer_Viewer::Type(), lst );
+    QListIterator<SUIT_ViewManager*> itOCC( lst );
+    while ( itOCC.hasNext() )
     {
-      SUIT_ViewModel* vm = it.next()->getViewModel();
-      if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
+      SUIT_ViewModel* vm = itOCC.next()->getViewModel();
+      if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
         continue;
 
-      SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
-      if( vtkVM ) vtkVM->setIncrementalSpeed( speed, mode );
+      OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+      occVM->setZoomingStyle( mode );
     }
 #endif
-  }
-#endif
-
 #ifndef DISABLE_VTKVIEWER
-  if ( sec == QString( "VTKViewer" ) && param == QString( "projection_mode" ) )
-  {
-    int mode = resMgr->integerValue( "VTKViewer", "projection_mode", 0 );
-    QList<SUIT_ViewManager*> lst;
 #ifndef DISABLE_SALOMEOBJECT
     viewManagers( SVTK_Viewer::Type(), lst );
-    QListIterator<SUIT_ViewManager*> it( lst );
-    while ( it.hasNext() )
+    QListIterator<SUIT_ViewManager*> itVTK( lst );
+    while ( itVTK.hasNext() )
     {
-      SUIT_ViewModel* vm = it.next()->getViewModel();
+      SUIT_ViewModel* vm = itVTK.next()->getViewModel();
       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
         continue;
 
       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
-      if( vtkVM ) vtkVM->setProjectionMode( mode );
+      if( vtkVM ) vtkVM->setZoomingStyle( mode );
     }
 #endif
-  }
 #endif
+  }
 
 #ifndef DISABLE_VTKVIEWER
-  if ( sec == QString( "VTKViewer" ) && param == QString( "navigation_mode" ) )
+  if ( sec == QString( "VTKViewer" ) && (param == QString( "speed_value" ) || param == QString( "speed_mode" )) )
   {
-    int mode = resMgr->integerValue( "VTKViewer", "navigation_mode", 0 );
+    int speed = resMgr->integerValue( "VTKViewer", "speed_value", 10 );
+    int mode = resMgr->integerValue( "VTKViewer", "speed_mode", 0 );
     QList<SUIT_ViewManager*> lst;
 #ifndef DISABLE_SALOMEOBJECT
     viewManagers( SVTK_Viewer::Type(), lst );
@@ -2665,16 +2781,16 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
         continue;
 
       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
-      if( vtkVM ) vtkVM->setInteractionStyle( mode );
+      if( vtkVM ) vtkVM->setIncrementalSpeed( speed, mode );
     }
 #endif
   }
 #endif
 
 #ifndef DISABLE_VTKVIEWER
-  if ( sec == QString( "VTKViewer" ) && param == QString( "zooming_mode" ) )
+  if ( sec == QString( "VTKViewer" ) && param == QString( "projection_mode" ) )
   {
-    int mode = resMgr->integerValue( "VTKViewer", "zooming_mode", 0 );
+    int mode = resMgr->integerValue( "VTKViewer", "projection_mode", 0 );
     QList<SUIT_ViewManager*> lst;
 #ifndef DISABLE_SALOMEOBJECT
     viewManagers( SVTK_Viewer::Type(), lst );
@@ -2686,16 +2802,16 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
         continue;
 
       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
-      if( vtkVM ) vtkVM->setZoomingStyle( mode );
+      if( vtkVM ) vtkVM->setProjectionMode( mode );
     }
 #endif
   }
 #endif
 
 #ifndef DISABLE_VTKVIEWER
-  if ( sec == QString( "VTKViewer" ) && param == QString( "dynamic_preselection" ) )
+  if ( sec == QString( "VTKViewer" ) && param == QString( "preselection" ) )
   {
-    bool mode = resMgr->booleanValue( "VTKViewer", "dynamic_preselection", true );
+    int mode = resMgr->integerValue( "VTKViewer", "preselection", 0 );
     QList<SUIT_ViewManager*> lst;
 #ifndef DISABLE_SALOMEOBJECT
     viewManagers( SVTK_Viewer::Type(), lst );
@@ -2707,16 +2823,16 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
         continue;
 
       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
-      if( vtkVM ) vtkVM->setDynamicPreSelection( mode );
+      if( vtkVM ) vtkVM->setPreSelectionMode( mode );
     }
 #endif
   }
 #endif
 
 #ifndef DISABLE_VTKVIEWER
-  if ( sec == QString( "VTKViewer" ) && param == QString( "show_static_trihedron" ) )
+  if ( sec == QString( "VTKViewer" ) && param == QString( "enable_selection" ) )
   {
-    bool isVisible = resMgr->booleanValue( "VTKViewer", "show_static_trihedron", true );
+    bool isToEnableSelection = resMgr->booleanValue( "VTKViewer", "enable_selection", true );
     QList<SUIT_ViewManager*> lst;
 #ifndef DISABLE_SALOMEOBJECT
     viewManagers( SVTK_Viewer::Type(), lst );
@@ -2728,11 +2844,7 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
         continue;
 
       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
-      if( vtkVM )
-      {
-        vtkVM->setStaticTrihedronVisible( isVisible );
-        vtkVM->Repaint();
-      }
+      if( vtkVM ) vtkVM->enableSelection( isToEnableSelection );
     }
 #endif
   }
@@ -2762,24 +2874,6 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
 #endif
   }
 #endif
-
-#ifndef DISABLE_OCCVIEWER
-  if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
-  {
-    QList<SUIT_ViewManager*> lst;
-    viewManagers( OCCViewer_Viewer::Type(), lst );
-    int u = resMgr->integerValue( sec, "iso_number_u" );
-    int v = resMgr->integerValue( sec, "iso_number_v" );
-    QListIterator<SUIT_ViewManager*> it( lst );
-    while ( it.hasNext() )
-    {
-      OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.next() );
-      if( mgr && mgr->getOCCViewer() )
-        mgr->getOCCViewer()->setIsos( u, v );
-    }
-  }
-#endif
-
   if( sec=="ObjectBrowser" )
   {
     SUIT_DataBrowser* ob = objectBrowser();
@@ -2810,8 +2904,6 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
 
   if( sec=="Study" )
   {
-    if( param=="store_positions" )
-      updateWindows();
     if( param=="auto_save_interval" ) {
       myAutoSaveTimer->stop();
       int autoSaveInterval = resMgr->integerValue( "Study", "auto_save_interval", 0 );
@@ -2866,10 +2958,9 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
 
   if ( sec == "ExternalBrowser" && param == "use_external_browser" ) {
     if ( resMgr->booleanValue("ExternalBrowser", "use_external_browser", false ) )
-      {
-        if(QtxWebBrowser::webBrowser())
-          QtxWebBrowser::webBrowser()->close();
-      }
+    {
+      QtxWebBrowser::shutdown();
+    }
   }
 
 #ifndef DISABLE_PLOT2DVIEWER
@@ -2914,17 +3005,8 @@ void LightApp_Application::loadPreferences()
     mru_load = false;
   }
 
-  myWinGeom.clear();
-  QStringList mods = aResMgr->parameters( "windows_geometry" );
-  for ( QStringList::const_iterator it = mods.begin(); it != mods.end(); ++it )
-  {
-    QByteArray arr;
-    if ( aResMgr->value( "windows_geometry", *it, arr ) )
-      myWinGeom.insert( *it, arr );
-  }
-
   myWinVis.clear();
-  mods = aResMgr->parameters( "windows_visibility" );
+  QStringList mods = aResMgr->parameters( "windows_visibility" );
   for ( QStringList::const_iterator itr = mods.begin(); itr != mods.end(); ++itr )
   {
     QByteArray arr;
@@ -2963,9 +3045,6 @@ void LightApp_Application::savePreferences()
   if ( mru )
     mru->saveLinks( aResMgr, "MRU" );
 
-  for ( WinGeom::const_iterator it = myWinGeom.begin(); it != myWinGeom.end(); ++it )
-    aResMgr->setValue( "windows_geometry", it.key(), it.value() );
-
   for ( WinVis::const_iterator itr = myWinVis.begin(); itr != myWinVis.end(); ++itr )
     aResMgr->setValue( "windows_visibility", itr.key(), itr.value() );
 
@@ -3164,51 +3243,91 @@ void LightApp_Application::loadDockWindowsState()
 {
   if ( !desktop() )
     return;
-
-  bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
-  if( !store )
-    return;
+  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+  bool storeWin = aResMgr->booleanValue( "Study", "store_positions", true );
+  bool storeTb = aResMgr->booleanValue( "Study", "store_tool_positions", true );
 
   QString modName;
   if ( activeModule() )
     modName = activeModule()->name();
 
-  if ( myWinGeom.contains( modName ) )
-    desktop()->restoreState( myWinGeom[modName] );
-
-  if ( !myWinVis.contains( modName ) )
+  QtxResourceMgr::WorkingMode prevMode = aResMgr->workingMode();
+  aResMgr->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
+  QByteArray aDefaultState;
+  aResMgr->value("windows_geometry", modName , aDefaultState );
+  QByteArray aDefaultVisibility;
+  aResMgr->value("windows_visibility", modName , aDefaultVisibility );
+  bool hasDefaultVisibility = !aDefaultVisibility.isEmpty();
+  aResMgr->setWorkingMode(prevMode);
+  
+  if( !storeWin && !storeTb && aDefaultState.isEmpty() && !hasDefaultVisibility)
     return;
 
-  QMap<QString, bool> tbMap, dwMap;
-  dockWindowsState( myWinVis[modName], tbMap, dwMap );
+  if ( aResMgr->hasValue("windows_geometry" ,modName ) ) {
+    QByteArray arr;
+    aResMgr->value("windows_geometry", modName , arr );
+    QByteArray aTargetArray = processState(arr, storeWin, storeTb, true, aDefaultState);
+    desktop()->restoreState( aTargetArray );
+  }
 
-  QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
-  for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit )
-  {
-    QToolBar* tb = *tit;
+  if ( !myWinVis.contains( modName ) && aDefaultVisibility.isEmpty())
+    return;
 
-    QObject* po = Qtx::findParent( tb, "QMainWindow" );
-    if ( po != desktop() )
-      continue;
+  QMap<QString, bool> *tbMap = 0;
+  QMap<QString, bool> *dwMap = 0;
+  
+  QMap<QString, bool> userTbMap, userDwMap;
+  dockWindowsState( myWinVis[modName], userTbMap, userDwMap );
 
-    if ( tbMap.contains( tb->objectName() ) )
-      tb->setVisible( tbMap[tb->objectName()] );
+  QMap<QString, bool> defaultTbMap, defaultDwMap;
+  if(hasDefaultVisibility) {
+    dockWindowsState( aDefaultVisibility, defaultTbMap, defaultDwMap);    
   }
 
-  QList<QDockWidget*> dwList = qFindChildren<QDockWidget*>( desktop() );
-  for ( QList<QDockWidget*>::iterator dit = dwList.begin(); dit != dwList.end(); ++dit )
-  {
-    QDockWidget* dw = *dit;
+  if(storeTb) {
+    tbMap =  &userTbMap;
+  } else {
+    if(hasDefaultVisibility){
+      tbMap =  &defaultTbMap;
+    }
+  }
 
-    QObject* po = Qtx::findParent( dw, "QMainWindow" );
-    if ( po != desktop() )
-      continue;
+  if(storeWin) {
+    dwMap =  &userDwMap;
+  } else {
+    if(hasDefaultVisibility){
+      dwMap =  &defaultDwMap;
+    }
+  }
+  
+  if(tbMap) {
+    QList<QToolBar*> tbList = findToolBars();
+    for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit )
+      {        
+       QToolBar* tb = *tit;
+       if ( tbMap->contains( tb->objectName() ) ) {      
+         tb->setVisible( (*tbMap)[tb->objectName()] );
+       }
+      }
+  }
 
-    if ( dwMap.contains( dw->objectName() ) )
-      dw->setVisible( dwMap[dw->objectName()] );
+  if(dwMap) {
+    QList<QDockWidget*> dwList = qFindChildren<QDockWidget*>( desktop() );
+    for ( QList<QDockWidget*>::iterator dit = dwList.begin(); dit != dwList.end(); ++dit )
+      {
+       QDockWidget* dw = *dit;
+       
+       QObject* po = Qtx::findParent( dw, "QMainWindow" );
+       if ( po != desktop() )
+         continue;
+       
+       if ( dwMap->contains( dw->objectName() ) )
+         dw->setVisible( (*dwMap)[dw->objectName()] );
+      }
   }
 }
 
+
 /*!
   Saves windows geometry
 */
@@ -3217,15 +3336,18 @@ void LightApp_Application::saveDockWindowsState()
   if ( !desktop() )
     return;
 
-  bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
-  if( !store )
+  bool storeWin = resourceMgr()->booleanValue( "Study", "store_positions", true );
+  bool storeTb = resourceMgr()->booleanValue( "Study", "store_tool_positions", true );
+
+  if( !storeWin && !storeTb )
     return;
 
   QString modName;
   if ( activeModule() )
     modName = activeModule()->name();
 
-  myWinGeom.insert( modName, desktop()->saveState() );
+  QByteArray arr = desktop()->saveState();
+  resourceMgr()->setValue( "windows_geometry", modName, processState(arr, storeWin, storeTb, false) );
 
   QByteArray visArr;
   if ( myWinVis.contains( modName ) )
@@ -3367,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 );
@@ -3385,6 +3508,7 @@ void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopu
       }
     }
   }
+#endif
 
   selMgr->setSelectionCacheEnabled( cacheIsOn );
 }
@@ -3487,7 +3611,7 @@ void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
 {
   connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
-  STD_Application::addViewManager( vm );
+  CAM_Application::addViewManager( vm );
 }
 
 /*!
@@ -3501,7 +3625,16 @@ void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
   if (aStudy )
     aStudy->removeViewMgr(vm->getGlobalId());
 
-  STD_Application::removeViewManager( vm );
+  CAM_Application::removeViewManager( vm );
+
+  LightApp_SelectionMgr* selMgr = selectionMgr();
+  QList<SUIT_Selector*> selectors;
+  selMgr->selectors( selectors );
+  foreach( SUIT_Selector* selector, selectors ) {
+    if ( selector->owner() == vm->getViewModel() ) {
+      delete selector;
+    }
+  }
 
   // IPAL22894: Crash on closing OCC view
   //delete vm;
@@ -3586,7 +3719,7 @@ bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
 
   //abd: changed libSalomePyQtGUI to SalomePyQtGUI for WIN32
   bool isPythonModule = lib.contains("SalomePyQtGUI");
-  bool isPythonLightModule = lib.contains("libSalomePyQtGUILight");
+  bool isPythonLightModule = lib.contains("SalomePyQtGUILight");
 
   QStringList paths;
 #ifdef WIN32
@@ -3610,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 );
@@ -3624,11 +3757,11 @@ bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
       QString pylibgui = moduleName( moduleTitle ) + QString("GUI.py");
 
       // Check the python library
-#ifdef WIN32
-      paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
-#else
+// #ifdef WIN32
+//       paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
+// #else
       paths = QString(::getenv( "PYTHONPATH" )).split( ":", QString::SkipEmptyParts );
-#endif
+// #endif
       bool isPyLib = false, isPyGuiLib = false;
       QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
       for( ; anIt!=aLast; anIt++ )
@@ -3647,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() );
@@ -3876,7 +4009,7 @@ QString LightApp_Application::browseObjects( const QStringList& theEntryList,
   // scroll to each entry in the list
   // (in optimized mode - to the last entry only)
   QString anEntry;
-  LightApp_DataObject* anObject;
+  LightApp_DataObject* anObject = 0;
   while( anIter.hasNext() )
   {
     anEntry = anIter.next();
@@ -3971,25 +4104,186 @@ void LightApp_Application::onDesktopMessage( const QString& message )
       LightApp_Module* sMod = 0;
       CAM_Module* mod = module( msgType );
       if ( !mod )
-       mod = module( moduleTitle( msgType ) );
+        mod = module( moduleTitle( msgType ) );
       if ( mod && mod->inherits( "LightApp_Module" ) )
-       sMod = (LightApp_Module*)mod;
+        sMod = (LightApp_Module*)mod;
 
       if ( msgType.toLower() == "preferences" ) {
-       // requested preferences change: should be given as "preferences/<section>/<name>/<value>"
-       // for example "preferences/Study/multi_file_dump/true"
-       if ( data.count() > 3 ) {
-         QString section = data[1].trimmed();
-         QString param   = data[2].trimmed();
-         QString value   = QStringList( data.mid(3) ).join( sectionSeparator );
-         resourceMgr()->setValue( section, param, value );
-       }
+        // requested preferences change: should be given as "preferences/<section>/<name>/<value>"
+        // for example "preferences/Study/multi_file_dump/true"
+        if ( data.count() > 3 ) {
+          QString section = data[1].trimmed();
+          QString param   = data[2].trimmed();
+          QString value   = QStringList( data.mid(3) ).join( sectionSeparator );
+          resourceMgr()->setValue( section, param, value );
+        }
       }
       else if ( sMod ) {
-       // received message for the module
-       QString msg = QStringList( data.mid(1) ).join( sectionSeparator );
-       sMod->message( msg );
+        // received message for the module
+        QString msg = QStringList( data.mid(1) ).join( sectionSeparator );
+        sMod->message( msg );
       }
     }
   }
 }
+
+/*!
+  Internal method. 
+  Returns all top level toolbars.
+  Note : Result list contains only main window toolbars, not including toolbars from viewers.
+*/
+QList<QToolBar*> LightApp_Application::findToolBars() {
+  QList<QToolBar*> aResult;
+  QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
+  for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit ) {
+    QToolBar* tb = *tit;    
+    QObject* po = Qtx::findParent( tb, "QMainWindow" );
+    if ( po != desktop() )
+      continue;        
+    aResult.append(tb);
+  }
+  return aResult;
+}
+
+/*!
+  Internal method to parse toolbars and dockable windows state.
+ */
+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;
+  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)
+      aRes = defaultState;
+  } else {
+    QDataStream aData(&aRes, QIODevice::WriteOnly);
+    QList<QToolBar*> aToolBars = findToolBars();
+
+    QStringList aNames;
+    for ( QList<QToolBar*>::iterator tit = aToolBars.begin(); tit != aToolBars.end(); ++tit ) {        
+      QToolBar* tb = *tit;
+      aNames.append(tb->objectName());
+    }
+
+    int toolBarMarkerIndex = getToolbarMarkerIndex(input,aNames);
+    QDataStream anInputData(&input, QIODevice::ReadOnly);
+    if(toolBarMarkerIndex < 0)
+      return aRes;
+
+    int toolBarMarkerIndexDef;
+    if(hasDefaultState) {
+      toolBarMarkerIndexDef = getToolbarMarkerIndex(defaultState, aNames);
+      if(toolBarMarkerIndexDef < 0)
+       return aRes;      
+    }
+    QDataStream anInputDataDef(&defaultState, QIODevice::ReadOnly);
+
+    QDataStream* aTargetData = 0;
+    int          aTargetIndex = -1;
+
+    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;
+      } else {
+       //If no default state, write current snapshot of the dockable windows
+       if(isRestoring) {
+         aTargetData = &anInputDataCur;
+         int toolBarMarkerIndexCur = getToolbarMarkerIndex(currentArr, aNames);
+         aTargetIndex = toolBarMarkerIndexCur;
+       }         
+      }
+    }
+
+    if(aTargetData && aTargetIndex >= 0 ) {
+      aTargetData->device()->seek(0);
+      while( aTargetData->device()->pos() < aTargetIndex ) {
+       uchar ch;
+       *aTargetData >> ch;
+       aData<<ch;
+      }
+      isDockWinWriten = true;
+    }
+    
+    aTargetData = 0;
+    aTargetIndex = -1;
+
+    if(processTb) {
+      aTargetData = &anInputData;
+      aTargetIndex = toolBarMarkerIndex;
+    } else {
+      if(hasDefaultState) {
+       aTargetData = &anInputDataDef;
+       aTargetIndex = toolBarMarkerIndexDef;   
+      }      
+    }
+
+    if(aTargetData && aTargetIndex >= 0) {
+      int index;
+      if(!isDockWinWriten ) {
+       //Write version marker
+       int marker, version;
+       aTargetData->device()->seek(0);
+       *aTargetData >> marker;
+       *aTargetData >> version;
+       aData << marker;
+       aData << version;
+       aData << (uchar) QDockWidgetMarker;
+       aData << (int) 0;
+       int shift = 4*sizeof(int) + sizeof(QSize);
+       index = aTargetIndex - shift;
+      } else {
+       index = aTargetIndex;
+      }
+      
+      aTargetData->device()->seek(index);
+      while(!aTargetData->atEnd()) {
+       uchar ch;
+       *aTargetData >> ch;
+       aData << ch;
+      }
+    } else { // Not treat toolbars
+      aData << (uchar) QToolBarMarker;
+      aData << (int) 0; //Nb toolbars = 0
+    }
+  }
+  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 );
+}