1 // Copyright (C) 2010-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author: Adrien Bruneton (CEA)
21 #include "PVViewer_GUIElements.h"
22 #include "PLMainWindow.hxx"
23 #include "PVViewer_Core.h"
24 #include "PLViewTab.hxx"
28 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
29 #include <QtGui/QFileDialog>
31 #include <QtWidgets/QFileDialog>
33 #include <QMessageBox>
35 #include <pqTabbedMultiViewWidget.h>
36 #include <pqApplicationCore.h>
37 #include <pqPVApplicationCore.h>
38 #include <pqObjectBuilder.h>
39 #include <pqLoadDataReaction.h>
40 #include <pqPipelineSource.h>
41 #include <pqManagePluginsReaction.h>
42 #include <pqPropertiesPanel.h>
43 #include <pqPipelineBrowserWidget.h>
44 #include <pqServerManagerModel.h>
45 #include <pqRenderView.h>
46 #include <pqActiveObjects.h>
49 #include <vtkSMSourceProxy.h>
50 #include <vtkSMProperty.h>
51 #include <vtkSMStringVectorProperty.h>
53 PLMainWindow::PLMainWindow(QWidget *parent) :
59 _mainWindow.setupUi(this);
60 _autoApply = _mainWindow.actionAuto_apply->isChecked();
61 QObject::connect(this, SIGNAL(apply()), this, SLOT(onApply()));
62 QObject::connect(this, SIGNAL(changedCurrentFile(QString)), this, SLOT(onApply()));
66 // Called after ParaView application initialisation:
67 void PLMainWindow::finishUISetup()
69 _pAppC = PVViewer_Core::GetPVApplication();
70 PVViewer_GUIElements * pvgui = PVViewer_GUIElements::GetInstance(this);
71 QWidget * wprop = pvgui->getPropertiesPanel();
72 QWidget * wpipe = pvgui->getPipelineBrowserWidget();
73 wprop->setParent(_mainWindow.propFrame);
74 _mainWindow.verticalLayoutProp->addWidget(wprop);
75 wpipe->setParent(_mainWindow.pipelineFrame);
76 _mainWindow.verticalLayoutPipe->addWidget(wpipe);
78 PVViewer_GUIElements * pvge = PVViewer_GUIElements::GetInstance(this);
79 // pvge->setToolBarVisible(false);
81 // In this mockup, we play on the parent widget visibility (a QFrame), so show these:
82 pvge->getPipelineBrowserWidget()->show();
83 pvge->getPropertiesPanel()->show();
85 _mainWindow.propFrame->hide();
86 _mainWindow.pipelineFrame->hide();
87 // pvge->setToolBarEnabled(false);
88 // pvge->setToolBarVisible(false);
92 void PLMainWindow::autoApplyCheck(bool isChecked)
94 _autoApply = isChecked;
97 void PLMainWindow::onApply()
101 PVViewer_GUIElements * pvgui = PVViewer_GUIElements::GetInstance(this);
102 pqPropertiesPanel * wprop = pvgui->getPropertiesPanel();
107 void PLMainWindow::showProp(bool isChecked)
109 isChecked ? _mainWindow.propFrame->show() : _mainWindow.propFrame->hide();
112 void PLMainWindow::showPipeline(bool isChecked)
114 isChecked ? _mainWindow.pipelineFrame->show() : _mainWindow.pipelineFrame->hide();
117 void PLMainWindow::addTab()
119 int c = _mainWindow.tabWidget->count();
120 PLViewTab * newTab = new PLViewTab(_mainWindow.tabWidget);
121 int newIdx = _mainWindow.tabWidget->addTab(newTab, QString("Tab %1").arg(c+1));
122 _mainWindow.tabWidget->setCurrentIndex(newIdx);
125 QObject::connect(newTab, SIGNAL(onInsertSingleView(PLViewTab *)), this, SLOT(insertSingleView(PLViewTab *)));
126 QObject::connect(newTab, SIGNAL(onInsertMultiView(PLViewTab *)), this, SLOT(insertMultiView(PLViewTab *)));
129 void PLMainWindow::deleteTab()
131 int c = _mainWindow.tabWidget->currentIndex();
134 _mainWindow.tabWidget->removeTab(c);
138 void PLMainWindow::currentTabChanged(int tabIdx)
140 QWidget * w = _mainWindow.tabWidget->widget(tabIdx);
143 PLViewTab * viewtab = qobject_cast<PLViewTab *>(w);
144 if (viewtab && viewtab->getpqView())
146 pqActiveObjects::instance().setActiveView(viewtab->getpqView());
151 void PLMainWindow::doOpenFile()
156 // Load the stuff as wireframe in the main view:
157 QList<pqPipelineSource *> many = pqLoadDataReaction::loadData();
160 std::cout << "no file selected!" << std::endl;
163 if (many.count() > 1)
166 msgBox.setText("Select one file only!");
172 pqPipelineSource * src = many.at(0);
173 std::cout << "num of out ports: " << src->getNumberOfOutputPorts() << std::endl;
175 // A cone to start with:
176 // pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createSource(QString("sources"), QString("ConeSource"),
177 // this->_activeServer);
179 _simplePipeline.push(src);
181 // Retrieve loaded file name
182 vtkSMProperty * prop = src->getSourceProxy()->GetProperty("FileName");
183 vtkSMStringVectorProperty * prop2 = vtkSMStringVectorProperty::SafeDownCast(prop);
184 QString fName(prop2->GetElement(0));
187 emit changedCurrentFile(fName);
190 void PLMainWindow::insertSingleView(PLViewTab * tab)
192 // Create a new view proxy on the server
193 pqObjectBuilder* builder = _pAppC->getObjectBuilder();
194 pqServer* active_serv = pqActiveObjects::instance().activeServer();
196 std::cout << "About to create single view ..." << std::endl;
197 pqView * pqview = builder->createView(QString("RenderView"), active_serv);
198 std::cout << "Created: " << pqview << "!" << std::endl;
200 // Retrieve its widget and pass it to the Qt tab:
201 QWidget* viewWidget = pqview->getWidget();
203 // QWidget* viewWidget = new QPushButton("toto");
204 tab->hideAndReplace(viewWidget, pqview);
206 pqActiveObjects::instance().setActiveView(pqview);
209 void PLMainWindow::insertMultiView(PLViewTab * tab)
211 // Retrieve TabbedMultiView and see if it is already attached to someone:
212 PVViewer_GUIElements * pvgui = PVViewer_GUIElements::GetInstance(this);
213 pqTabbedMultiViewWidget * multiv = pvgui->getTabbedMultiViewWidget();
215 QWidget * parent = multiv->nativeParentWidget();
219 msgBox.setText("Multi-view already in use in another tab! Close it first.");
224 tab->hideAndReplace(multiv, NULL);
229 void PLMainWindow::doShrink()
231 if(!_simplePipeline.isEmpty())
235 pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createFilter(QString("filters"),
236 QString("ShrinkFilter"), _simplePipeline.top());
238 _simplePipeline.push(src);
245 void PLMainWindow::doSlice()
247 if(!_simplePipeline.isEmpty())
251 pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createFilter(QString("filters"),
252 QString("Cut"), _simplePipeline.top());
254 _simplePipeline.push(src);
261 void PLMainWindow::doManagePlugins()
263 pqManagePluginsReaction::managePlugins();
266 void PLMainWindow::cleanAll()
268 this->_pAppC->getObjectBuilder()->destroyPipelineProxies();
269 _simplePipeline.resize(0);
272 void PLMainWindow::cleanAllButSource()
274 while(_simplePipeline.size() > 1)
275 this->_pAppC->getObjectBuilder()->destroy(_simplePipeline.pop());