Salome HOME
Copyright update 2022
[modules/paravis.git] / src / PVGUI / PVGUI_Module_widgets.cxx
index 5818927896aa6a2d2c3f3c85acf79cd99b092152..7f65637000c279dc3c479844ffd04d92550dd48b 100644 (file)
@@ -1,11 +1,11 @@
 // PARAVIS : ParaView wrapper SALOME module
 //
-// Copyright (C) 2010-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2010-2022  CEA/DEN, EDF R&D
 //
 // 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
@@ -23,6 +23,8 @@
 //
 
 #include "PVGUI_Module.h"
+#include "PVViewer_ViewManager.h"
+#include "PVViewer_GUIElements.h"
 
 #include <QtxActionToolMgr.h>
 #include <LightApp_Application.h>
 #include <pqApplicationCore.h>
 #include <pqComparativeVisPanel.h>
 #include <pqPipelineBrowserWidget.h>
-//#include <pqProxyTabWidget.h>
 #include <pqProxyInformationWidget.h>
-#include <pqSettings.h>
 #include <pqDataInformationWidget.h>
 #include <pqPVAnimationWidget.h>
-#include <pqSelectionInspectorWidget.h>
+#include <pqFindDataSelectionDisplayFrame.h>
+#include <pqMultiBlockInspectorWidget.h>
 #include <pqProgressWidget.h>
 #include <pqProgressManager.h>
+#include <pqPropertiesPanel.h>
+#include <pqPVApplicationCore.h>
+#include <pqAnimationManager.h>
 
-#include <pqAlwaysConnectedBehavior.h>
 #include <pqApplicationCore.h>
-#include <pqAutoLoadPluginXMLBehavior.h>
-#include <pqCommandLineOptionsBehavior.h>
-#include <pqCrashRecoveryBehavior.h>
-#include <pqDataTimeStepBehavior.h>
-#include <pqDefaultViewBehavior.h>
-#include <pqDeleteBehavior.h>
-#include <pqPersistentMainWindowStateBehavior.h>
-#include <pqPluginActionGroupBehavior.h>
-#include <pqPluginDockWidgetsBehavior.h>
 #include <pqPluginManager.h>
-#include <pqPVNewSourceBehavior.h>
-#include <pqSpreadSheetVisibilityBehavior.h>
-#include <pqStandardViewModules.h>
-#include <pqUndoRedoBehavior.h>
-#include <pqViewFrameActionsBehavior.h>
 #include <pqParaViewMenuBuilders.h>
 #include <pqCollaborationPanel.h>
 #include <pqMemoryInspectorPanel.h>
-#include <pqPropertiesPanel.h>
+#include <pqColorMapEditor.h>
+#include <pqDeleteReaction.h>
+
+#include <vtkPVGeneralSettings.h>
+#include <vtkSMSettings.h>
+#include <vtkPVConfig.h>
 
 class ResizeHelper : public pqPVAnimationWidget
 {
-  // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG:
+  // TEMPORARY WORKAROUND AROUND PARAVIEW 3.14 BUG:
   // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
   // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
-  // THIS BUG IS NATURALLY FIXED BY ADDING 
+  // THIS BUG IS NATURALLY FIXED BY ADDING
   //      this->updateGeometries();
   // TO THE
   //     void pqAnimationWidget::resizeEvent(QResizeEvent* e);
@@ -94,7 +88,7 @@ protected:
   void resizeEvent(QResizeEvent* e)
   {
     pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
-    if ( w ) { 
+    if ( w ) {
       QShowEvent e;
       QApplication::sendEvent( w, &e );
     }
@@ -104,42 +98,121 @@ protected:
 
 /*!
   \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
-  ParaView pqMainWIndowCore class is fully responsible for these dock widgets' contents.
+  ParaView pqMainWindowCore class is fully responsible for these dock widgets' contents.
+  ==> To update this function, see the reference set up of ParaView in Application/Paraview/ParaviewMainWindow.ui
 */
 void PVGUI_Module::setupDockWidgets()
 {
   SUIT_Desktop* desk = application()->desktop();
+  PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance(desk);
  
   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
+  desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
 
   // Pipeline
   QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
   pipelineBrowserDock->setObjectName("pipelineBrowserDock");
   pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
   desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
-  pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
-  pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
+  pqPipelineBrowserWidget* browser = guiElements->getPipelineBrowserWidget();
   pipelineBrowserDock->setWidget(browser);
   myDockWidgets[pipelineBrowserDock] = true;
+  pipelineBrowserDock->hide();
+
+  // PROPERTIES, DISPLAY and VIEW:
+  // See ParaViewMainWindow.cxx - those three panels can be separated or grouped.
+  vtkSMSettings* settings = vtkSMSettings::GetInstance();
 
-  // Properties dock
-  QDockWidget* propertiesDock = new QDockWidget(tr( "TTL_OBJECT_INSPECTOR" ), desk);
+  //    Properties dock (previously called OBJECT_INSPECTOR)
+  QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
   propertiesDock->setObjectName("propertiesDock");
-  pqPropertiesPanel* propertiesPanel = new pqPropertiesPanel();
-  propertiesPanel->setObjectName("propertiesPanel");
+  propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
+  desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
+
+  pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
   propertiesDock->setWidget(propertiesPanel);
-  desk->addDockWidget(Qt::LeftDockWidgetArea, propertiesDock);
   connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ),  this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
+  //            hook delete to pqDeleteReaction.
+  QAction* tempDeleteAction = new QAction(this);
+  pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
+#if PARAVIEW_VERSION_MAJOR==5 && PARAVIEW_VERSION_MINOR<9
+  handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
+#else
+  handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqProxy*)), SLOT(deleteSource(pqProxy*)));
+#endif
   myDockWidgets[propertiesDock] = true;
+  propertiesDock->hide();
 
-  // information dock
+  int propertiesPanelMode = settings->GetSettingAsInt(
+      ".settings.GeneralSettings.PropertiesPanelMode", vtkPVGeneralSettings::ALL_IN_ONE);
+
+  // Display dock
+  QDockWidget* displayPropertiesDock = 0;
+  if (propertiesPanelMode == vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES ||
+      propertiesPanelMode == vtkPVGeneralSettings::ALL_SEPARATE )
+  {
+    displayPropertiesDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
+    displayPropertiesDock->setObjectName("displayPropertiesDock");
+    displayPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
+    desk->addDockWidget( Qt::LeftDockWidgetArea, displayPropertiesDock );
+    
+    pqPropertiesPanel* displayPropertiesPanel = new pqPropertiesPanel();
+    displayPropertiesPanel->setObjectName("displayPropertiesPanel");
+    displayPropertiesPanel->setProperty("panelMode", QVariant(2));  // probably to have only the Display part
+    displayPropertiesDock->setWidget(displayPropertiesPanel);
+    myDockWidgets[displayPropertiesDock] = false;
+    displayPropertiesDock->hide();
+  }
+
+  // View dock
+  QDockWidget* viewPropertiesDock = 0;
+  if (propertiesPanelMode == vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES ||
+      propertiesPanelMode == vtkPVGeneralSettings::ALL_SEPARATE )
+  {
+    viewPropertiesDock = new QDockWidget( tr( "TTL_VIEW_PANEL" ), desk );
+    viewPropertiesDock->setObjectName("viewPropertiesDock");
+    viewPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
+    desk->addDockWidget( Qt::LeftDockWidgetArea, viewPropertiesDock );
+    
+    pqPropertiesPanel* viewPropertiesPanel = new pqPropertiesPanel();
+    viewPropertiesPanel->setObjectName("viewPropertiesPanel");
+    viewPropertiesPanel->setProperty("panelMode", QVariant(4)); // probably to have only the View part
+    viewPropertiesDock->setWidget(viewPropertiesPanel);
+    myDockWidgets[viewPropertiesDock] = false;
+    viewPropertiesDock->hide();
+  }
+
+  switch (propertiesPanelMode)
+  {
+    case vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES:
+      propertiesPanel->setPanelMode(
+          pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES);
+      break;
+
+    case vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES:
+      propertiesPanel->setPanelMode(
+          pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
+      break;
+
+    case vtkPVGeneralSettings::ALL_SEPARATE:
+      propertiesPanel->setPanelMode(pqPropertiesPanel::SOURCE_PROPERTIES);
+      break;
+
+    case vtkPVGeneralSettings::ALL_IN_ONE:
+    default:
+      propertiesPanel->setPanelMode(
+                pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
+      break;
+  }
+
+  // Information dock
   QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
   informationDock->setObjectName("informationDock");
 
   QWidget* informationWidgetFrame = new QWidget(informationDock);
   informationWidgetFrame->setObjectName("informationWidgetFrame");
-  
+
   QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
   verticalLayout_2->setSpacing(0);
   verticalLayout_2->setContentsMargins(0, 0, 0, 0);
@@ -156,11 +229,12 @@ void PVGUI_Module::setupDockWidgets()
   verticalLayout_2->addWidget(informationScrollArea);
   informationDock->setWidget(informationWidgetFrame);
 
-  desk->addDockWidget(Qt::LeftDockWidgetArea, informationDock);
   myDockWidgets[informationDock] = true;
 
-  // put 'Properties' and 'Information' widgets into tabs
-  desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
+  if ( viewPropertiesDock )
+  desk->tabifyDockWidget(propertiesDock, viewPropertiesDock);
+  if ( displayPropertiesDock )
+    desk->tabifyDockWidget(propertiesDock, displayPropertiesDock);
   desk->tabifyDockWidget(propertiesDock, informationDock);
   propertiesDock->raise();
 
@@ -178,20 +252,34 @@ void PVGUI_Module::setupDockWidgets()
   QDockWidget* animationViewDock     = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
   animationViewDock->setObjectName("animationViewDock");
   desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
-  pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
+  pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); // [ABN] was resizeHelper
+
+  // RNV: Emit signal in order to make sure that animation scene is set
+  QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
+                            "activeSceneChanged",
+                            Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
+
   animationViewDock->setWidget(animation_panel);
   myDockWidgets[animationViewDock] = false; // hidden by default
 
   desk->tabifyDockWidget(animationViewDock,  statisticsViewDock);
 
-  // Selection view
-  QDockWidget* selectionInspectorDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
-  selectionInspectorDock->setObjectName("selectionInspectorDock");
-  selectionInspectorDock->setAllowedAreas( Qt::AllDockWidgetAreas );
-  desk->addDockWidget( Qt::LeftDockWidgetArea, selectionInspectorDock );
-  pqSelectionInspectorPanel* aSelInspector = new pqSelectionInspectorWidget(selectionInspectorDock);
-  selectionInspectorDock->setWidget(aSelInspector);
-  myDockWidgets[selectionInspectorDock] = false; // hidden by default
+  // Selection inspector
+  QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
+  selectionDisplayDock->setObjectName("selectionInspectorDock");
+  selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
+  desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
+  pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
+  selectionDisplayDock->setWidget(aSelInspector);
+  myDockWidgets[selectionDisplayDock] = false; // hidden by default
+
+  // Multi-block inspector
+  QDockWidget* multiBlockInspectorPanelDock  = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
+  multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
+  desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
+  pqMultiBlockInspectorWidget* mbi_panel = new pqMultiBlockInspectorWidget( multiBlockInspectorPanelDock );
+  multiBlockInspectorPanelDock->setWidget(mbi_panel);
+  myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
 
   // Comparative View
   QDockWidget* comparativePanelDock  = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
@@ -209,13 +297,27 @@ void PVGUI_Module::setupDockWidgets()
   collaborationPanelDock->setWidget(collaborationPanel);
   desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
   myDockWidgets[collaborationPanelDock] = false; // hidden by default
+
+  // Color map editor
+  QDockWidget* colorMapEditorDock  = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
+  colorMapEditorDock->setObjectName("colorMapEditorDock");
+  desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
+  pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
+  colorMapEditorDock->setWidget(cmed_panel);
+  myDockWidgets[colorMapEditorDock] = false; // hidden by default
+
+  // Provide access to the color-editor panel for the application.
+  pqApplicationCore::instance()->registerManager(
+    "COLOR_EDITOR_PANEL", colorMapEditorDock);
   
   // Memory inspector dock
   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
   memoryInspectorDock->setObjectName("memoryInspectorDock");
+#ifndef WIN32
   pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
   dockWidgetContents->setObjectName("dockWidgetContents");
   memoryInspectorDock->setWidget(dockWidgetContents);
+#endif
   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
   myDockWidgets[memoryInspectorDock] = false; // hidden by default
 
@@ -244,22 +346,24 @@ void PVGUI_Module::setupDockWidgets()
   aProgress->setEnabled(true);
 
   // Set up the dock window corners to give the vertical docks more room.
-  desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
-  desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
-  
+//  desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
+//  desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
+
   // Setup the default dock configuration ...
   statisticsViewDock->hide();
   comparativePanelDock->hide();
   animationViewDock->hide();
-  selectionInspectorDock->hide();
+  multiBlockInspectorPanelDock->hide();
+  selectionDisplayDock->hide();
   collaborationPanelDock->hide();
   memoryInspectorDock->hide();
+  colorMapEditorDock->hide();
 }
 
 /*!
   \brief Save states of dockable ParaView widgets.
 */
-void PVGUI_Module::saveDockWidgetsState()
+void PVGUI_Module::saveDockWidgetsState(bool hideWidgets)
 {
   SUIT_Desktop* desk = application()->desktop();
 
@@ -278,8 +382,10 @@ void PVGUI_Module::saveDockWidgetsState()
     it1.next();
     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
     myDockWidgets[dw] = dw->isVisible();
-    dw->setVisible( false );
-    dw->toggleViewAction()->setVisible( false );
+    if ( hideWidgets ) {
+      dw->setVisible( false );
+      dw->toggleViewAction()->setVisible( false );
+    }
   }
   // store toolbar breaks state and remove all tollbar breaks 
   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
@@ -287,7 +393,7 @@ void PVGUI_Module::saveDockWidgetsState()
     it2.next();
     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
-    if ( myToolbarBreaks[tb] )
+    if ( myToolbarBreaks[tb] && hideWidgets )
       desk->removeToolBarBreak( tb );
   }
   // store toolbars visibility state and hide'em all
@@ -296,8 +402,10 @@ void PVGUI_Module::saveDockWidgetsState()
     it3.next();
     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
     myToolbars[tb] = tb->isVisible();
-    tb->setVisible( false );
-    tb->toggleViewAction()->setVisible( false );
+    if ( hideWidgets ) {
+      tb->setVisible( false );
+      tb->toggleViewAction()->setVisible( false );
+    }
   }
 }
 
@@ -325,6 +433,7 @@ void PVGUI_Module::restoreDockWidgetsState()
     dw->setVisible( it1.value() );
     dw->toggleViewAction()->setVisible( true );
   }
+
   // restore toolbar breaks state
   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
   while( it2.hasNext() ) {
@@ -333,6 +442,7 @@ void PVGUI_Module::restoreDockWidgetsState()
     if ( myToolbarBreaks[tb] )
       desk->insertToolBarBreak( tb );
   }
+  
   // restore toolbar visibility state
   QMapIterator<QWidget*, bool> it3( myToolbars );
   while( it3.hasNext() ) {
@@ -342,3 +452,71 @@ void PVGUI_Module::restoreDockWidgetsState()
     tb->toggleViewAction()->setVisible( true );
   }
 }
+
+
+
+/*!
+  \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
+*/
+void PVGUI_Module::storeCommonWindowsState() {  
+  //rnv: Make behaviour of the dockable windows and toolbars coherent with others
+  //     modules: if 'Save position of the windows' or 'Save position of the toolbars' 
+  //     in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
+  //     are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
+  //     Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
+  //     configuration file.
+  //
+  //     But in contrast to others modules ParaVis module default settings hide some dockable
+  //     windows, so to restore it at the moment of the ParaVis de-activation we call 
+  //     restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call 
+  //     this method.
+
+  LightApp_Application* anApp = getApp();
+  if(!anApp)
+    return;
+
+  int begin = LightApp_Application::WT_ObjectBrowser;
+  int end = LightApp_Application::WT_User;
+  for( int i = begin; i <= end; i++ ) {
+    QWidget* wg = anApp->getWindow(i);
+    if(wg) {
+      QDockWidget* dock = 0;
+      QWidget* w = wg->parentWidget();
+      while ( w && !dock ) {
+        dock = ::qobject_cast<QDockWidget*>( w );
+        w = w->parentWidget();
+      }
+      if(dock){
+        if(!myCommonMap.contains(i)){
+          myCommonMap.insert(i,dock->isVisible());
+        } else {
+          myCommonMap[i] = dock->isVisible();
+        }
+      }
+    }
+  }
+}
+
+/*!
+  \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
+*/
+void PVGUI_Module::restoreCommonWindowsState() {
+  LightApp_Application* anApp = getApp();
+  if(!anApp)
+    return;
+  DockWindowMap::const_iterator it = myCommonMap.begin();
+  for( ;it != myCommonMap.end(); it++ ) {
+    QWidget* wg = anApp->getWindow(it.key());
+    if(wg) {
+      QDockWidget* dock = 0;
+      QWidget* w = wg->parentWidget();
+      while ( w && !dock ) {
+        dock = ::qobject_cast<QDockWidget*>( w );
+        w = w->parentWidget();
+      }
+      if(dock) {
+        dock->setVisible(it.value());
+      }
+    }
+  }
+}