Salome HOME
cd8ed9ebc388bc14eda22c124adb89bbb8b13100
[modules/gui.git] / src / PVViewer / PVViewer_ViewWindow.cxx
1 // Copyright (C) 2014-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Adrien Bruneton (CEA)
20
21 #include "PVViewer_ViewWindow.h"
22 #include "PVViewer_Core.h"
23 #include "PVViewer_ViewModel.h"
24 #include "PVViewer_GUIElements.h"
25 #include "PVViewer_ViewManager.h"
26
27 #include "SUIT_ViewManager.h"
28 #include "SUIT_ResourceMgr.h"
29 #include "SUIT_Session.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Application.h"
32
33 #include <pqTabbedMultiViewWidget.h>
34 #include <pqApplicationCore.h>
35 #include "pqActiveObjects.h"
36
37 /*!
38   \class PVViewer_ViewWindow
39   \brief PVGUI view window.
40 */
41
42 /*!
43   \brief Constructor.
44   \param theDesktop parent desktop window
45   \param theModel view model
46 */
47 PVViewer_ViewWindow::PVViewer_ViewWindow( SUIT_Desktop* theDesktop, PVViewer_Viewer* theModel )
48   : SUIT_ViewWindow( theDesktop ), myPVMgr( 0 )
49 {
50   myDesktop = theDesktop;
51   myModel = theModel;
52   setViewManager(myModel->getViewManager());
53   pqActiveObjects::instance().setActiveView(nullptr);
54   myPVMgr = qobject_cast<pqTabbedMultiViewWidget*>(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET"));
55   if (myPVMgr) {
56     SUIT_Application* app = SUIT_Session::session()->activeApplication();
57     if ( app )
58       app->addPostRoutine(&PVViewer_ViewWindow::removePVMgr);
59     myPVMgr->setParent( this );
60     // This is mandatory, see setParent() method in Qt 4 documentation
61     myPVMgr->show();
62     setCentralWidget( myPVMgr );
63     // Hide toolbars
64     PVViewer_GUIElements * pvge = PVViewer_GUIElements::GetInstance(myDesktop);
65     pvge->setToolBarVisible(false);
66   } else
67     qDebug("No multiViewManager defined");
68 }
69
70 /*!
71   \brief Destructor.
72   As pqViewManager persists through the whole session,
73   the destructor first removes it from the children of this PVViewer_ViewWindow
74   to prevent its unexpected deletion.
75 */
76 PVViewer_ViewWindow::~PVViewer_ViewWindow()
77 {
78   if ( myPVMgr ) {
79     // Hide toolbars
80     PVViewer_GUIElements * pvge = PVViewer_GUIElements::GetInstance(myDesktop);
81     pvge->setToolBarEnabled(false);
82     myPVMgr->setParent( 0 );
83     myPVMgr->hide();
84     myPVMgr = 0;
85     setCentralWidget( 0 );
86   }
87 }
88
89 void PVViewer_ViewWindow::removePVMgr()
90 {
91   pqTabbedMultiViewWidget* aPVMgr = qobject_cast<pqTabbedMultiViewWidget*>(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET"));
92   delete aPVMgr;
93 }
94
95 /*!
96   \brief Get the visual parameters of the view window.
97   \return visual parameters of this view window formatted to the string
98 */
99 QString PVViewer_ViewWindow::getVisualParameters()
100 {
101   return SUIT_ViewWindow::getVisualParameters();
102 }
103
104 /*!
105   \brief Restore visual parameters of the view window from the formated string
106   \param parameters view window visual parameters
107 */
108 void PVViewer_ViewWindow::setVisualParameters( const QString& parameters )
109 {
110   SUIT_ViewWindow::setVisualParameters( parameters );
111 }
112
113 /*!
114   \brief Returns the ParaView multi-view manager previously set with setMultiViewManager()
115 */
116 pqTabbedMultiViewWidget* PVViewer_ViewWindow::getMultiViewManager() const
117 {
118   return myPVMgr;
119 }