Salome HOME
updated copyright message
[modules/gui.git] / src / SPV3D / SPV3D_ViewManager.cxx
1 // Copyright (C) 2023  CEA, EDF
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
20 #include "SPV3D_ViewManager.h"
21 #include "SPV3D_ViewModel.h"
22 #include "SPV3D_ViewWindow.h"
23
24 #include <PV3DViewer_ViewManager.h>
25
26 #include "PVViewer_InitSingleton.h"
27 #include "PVViewer_GUIElements.h"
28 #include "PVServer_ServiceWrapper.h"
29
30 #include <SUIT_Desktop.h>
31
32 #include <pqObjectBuilder.h>
33 #include <pqApplicationCore.h>
34 #include <pqServerManagerModel.h>
35 #include <pqServerResource.h>
36 #include <pqView.h>
37 #include <pqPVApplicationCore.h>
38 #include <pqParaViewBehaviors.h>
39
40 #include <QVBoxLayout>
41 #include <QApplication>
42
43 /*!
44   Constructor
45 */
46 SPV3D_ViewManager::SPV3D_ViewManager( SUIT_Study* study, SUIT_Desktop* theDesktop ) 
47 : SUIT_ViewManager( study, theDesktop, new SPV3D_ViewModel() )
48 {
49   setTitle( SPV3D_ViewManager::tr( "PARAVIEW3D_VIEW_TITLE" ) );
50   /*QStringList args = QCoreApplication::arguments();
51   int argc = args.length();
52   char **argv = new char *[argc+1];
53   for(auto i = 0 ; i < argc ; ++i)
54     argv[i] = strdup(args[i].toStdString().c_str());
55   argv[argc] = nullptr;
56   pqPVApplicationCore appPV(argc,argv);
57   QApplication::instance()->installEventFilter(&appPV);
58   new pqParaViewBehaviors(theDesktop,theDesktop);
59   pqObjectBuilder *builder(pqApplicationCore::instance()->getObjectBuilder());
60   pqServer *serv(pqApplicationCore::instance()->getServerManagerModel()->findServer(pqServerResource("builtin:")));
61   pqView *view=builder->createView(QString("RenderView"),serv);
62   static_cast<SPV3D_ViewModel *>(this->getViewModel())->setView(view);*/
63   //QVBoxLayout *lay(new QVBoxLayout(theDesktop));
64   //lay->addWidget( view->widget() );
65   //view->widget()->setParent( theDesktop);
66   // Initialize minimal paraview stuff (if not already done)
67   //PVViewer_InitSingleton::Init(theDesktop);
68
69   connect( theDesktop, SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
70            this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
71
72   SPV3D_ViewModel *vm = dynamic_cast<SPV3D_ViewModel*>(getViewModel());
73   if (vm)
74     vm->initialize();
75 }
76
77 /*!
78   Destructor
79 */
80 SPV3D_ViewManager::~SPV3D_ViewManager()
81 {
82 }
83
84 /*!
85   \return corresponding main window
86 */
87 SUIT_Desktop* SPV3D_ViewManager::getDesktop()
88 {
89   return myDesktop;
90 }
91
92 /*!Enable toolbars if view \a view is ParaView viewer and disable otherwise.
93 */
94 void SPV3D_ViewManager::onWindowActivated(SUIT_ViewWindow* view)
95 {
96   if (view)
97   {
98     SPV3D_ViewWindow* pvWindow = dynamic_cast<SPV3D_ViewWindow*>(view);
99     PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance( myDesktop );
100     guiElements->setToolBarEnabled(pvWindow!=0);
101   }
102 }