Salome HOME
Copyright update: 2016
[modules/gui.git] / src / PVViewer / PVViewer_ViewWindow.cxx
1 // Copyright (C) 2014-2016  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
32 #include <pqTabbedMultiViewWidget.h>
33 #include <pqApplicationCore.h>
34
35
36 /*!
37   \class PVViewer_ViewWindow
38   \brief PVGUI view window.
39 */
40
41 /*!
42   \brief Constructor.
43   \param theDesktop parent desktop window
44   \param theModel view model
45 */
46 PVViewer_ViewWindow::PVViewer_ViewWindow( SUIT_Desktop* theDesktop, PVViewer_Viewer* theModel )
47   : SUIT_ViewWindow( theDesktop ), myPVMgr( 0 )
48 {
49   myDesktop = theDesktop;
50   myModel = theModel;
51   setViewManager(myModel->getViewManager());
52   myPVMgr = qobject_cast<pqTabbedMultiViewWidget*>(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET"));
53   if (myPVMgr) {
54     myPVMgr->setParent( this );
55     // This is mandatory, see setParent() method in Qt 4 documentation
56     myPVMgr->show();
57     setCentralWidget( myPVMgr );
58
59     // Finish ParaView set up: behaviors, connection and configurations.
60     const QString configPath(PVViewer_ViewManager::GetPVConfigPath());
61     PVViewer_Core::ParaviewInitBehaviors(true, theDesktop);
62     PVViewer_ViewManager::ConnectToExternalPVServer(theDesktop);
63     PVViewer_Core::ParaviewLoadConfigurations(configPath);
64
65     // Hide toolbars
66     PVViewer_GUIElements * pvge = PVViewer_GUIElements::GetInstance(myDesktop);
67     pvge->setToolBarVisible(false);
68   } else
69     qDebug("No multiViewManager defined");
70 }
71
72 /*!
73   \brief Destructor.
74   As pqViewManager persists through the whole session,
75   the destructor first removes it from the children of this PVViewer_ViewWindow
76   to prevent its unexpected deletion.
77 */
78 PVViewer_ViewWindow::~PVViewer_ViewWindow()
79 {
80   if ( myPVMgr ) {
81     // Hide toolbars
82     PVViewer_GUIElements * pvge = PVViewer_GUIElements::GetInstance(myDesktop);
83     pvge->setToolBarEnabled(false);
84     myPVMgr->setParent( 0 );
85     myPVMgr->hide();
86     myPVMgr = 0;
87     setCentralWidget( 0 );
88   }
89 }
90
91 /*!
92   \brief Get the visual parameters of the view window.
93   \return visual parameters of this view window formatted to the string
94 */
95 QString PVViewer_ViewWindow::getVisualParameters()
96 {
97   return SUIT_ViewWindow::getVisualParameters();
98 }
99
100 /*!
101   \brief Restore visual parameters of the view window from the formated string
102   \param parameters view window visual parameters
103 */
104 void PVViewer_ViewWindow::setVisualParameters( const QString& parameters )
105 {
106   SUIT_ViewWindow::setVisualParameters( parameters );
107 }
108
109
110 /*!
111   \brief Returns the ParaView multi-view manager previously set with setMultiViewManager()
112 */
113 pqTabbedMultiViewWidget* PVViewer_ViewWindow::getMultiViewManager() const
114 {
115   return myPVMgr;
116 }
117
118 //void PVViewer_ViewWindow::onEmulateApply()
119 //{
120 //  emit this->applyRequest();
121 //}