1 // Copyright (C) 2010-2016 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 #include <QFileDialog>
29 #include <QMessageBox>
31 #include <pqTabbedMultiViewWidget.h>
32 #include <pqApplicationCore.h>
33 #include <pqPVApplicationCore.h>
34 #include <pqObjectBuilder.h>
35 #include <pqLoadDataReaction.h>
36 #include <pqPipelineSource.h>
37 #include <pqManagePluginsReaction.h>
38 #include <pqPropertiesPanel.h>
39 #include <pqPipelineBrowserWidget.h>
40 #include <pqServerManagerModel.h>
41 #include <pqRenderView.h>
42 #include <pqActiveObjects.h>
45 #include <vtkSMSourceProxy.h>
46 #include <vtkSMProperty.h>
47 #include <vtkSMStringVectorProperty.h>
49 PLMainWindow::PLMainWindow(QWidget *parent) :
56 _mainWindow.setupUi(this);
57 _autoApply = _mainWindow.actionAuto_apply->isChecked();
58 QObject::connect(this, SIGNAL(apply()), this, SLOT(onApply()));
59 QObject::connect(this, SIGNAL(changedCurrentFile(QString)), this, SLOT(onApply()));
63 // Called after ParaView application initialisation:
64 void PLMainWindow::finishUISetup()
66 _pAppC = PVViewer_Core::GetPVApplication();
67 _pvgui = PVViewer_GUIElements::GetInstance(this);
69 QWidget * wprop = _pvgui->getPropertiesPanel();
70 QWidget * wpipe = _pvgui->getPipelineBrowserWidget();
71 wprop->setParent(_mainWindow.propFrame);
72 _mainWindow.verticalLayoutProp->addWidget(wprop);
73 wpipe->setParent(_mainWindow.pipelineFrame);
74 _mainWindow.verticalLayoutPipe->addWidget(wpipe);
76 // In this mockup, we play on the parent widget visibility (a QFrame), so show these:
77 _pvgui->getPipelineBrowserWidget()->show();
78 _pvgui->getPropertiesPanel()->show();
80 _mainWindow.propFrame->hide();
81 _mainWindow.pipelineFrame->hide();
82 // _pvgui->setToolBarEnabled(false);
83 // _pvgui->setToolBarVisible(false);
87 void PLMainWindow::autoApplyCheck(bool isChecked)
89 _autoApply = isChecked;
92 void PLMainWindow::onApply()
96 PVViewer_GUIElements * pvgui = PVViewer_GUIElements::GetInstance(this);
97 pqPropertiesPanel * wprop = pvgui->getPropertiesPanel();
102 void PLMainWindow::showProp(bool isChecked)
104 isChecked ? _mainWindow.propFrame->show() : _mainWindow.propFrame->hide();
107 void PLMainWindow::showPipeline(bool isChecked)
109 isChecked ? _mainWindow.pipelineFrame->show() : _mainWindow.pipelineFrame->hide();
112 void PLMainWindow::onBuildFilterMenu()
116 _filterMenu = _pvgui->getFiltersMenu();
117 // _filterMenu = new QMenu();
118 _filterMenu->setTitle("Filters");
119 this->menuBar()->addMenu(_filterMenu);
122 QMessageBox::warning(this, "Warning", "Filter menu already added!");
125 void PLMainWindow::addTab()
127 int c = _mainWindow.tabWidget->count();
128 PLViewTab * newTab = new PLViewTab(_mainWindow.tabWidget);
129 int newIdx = _mainWindow.tabWidget->addTab(newTab, QString("Tab %1").arg(c+1));
130 _mainWindow.tabWidget->setCurrentIndex(newIdx);
133 QObject::connect(newTab, SIGNAL(onInsertSingleView(PLViewTab *)), this, SLOT(insertSingleView(PLViewTab *)));
134 QObject::connect(newTab, SIGNAL(onInsertMultiView(PLViewTab *)), this, SLOT(insertMultiView(PLViewTab *)));
135 QObject::connect(newTab, SIGNAL(onInsertSpreadsheetView(PLViewTab *)), this, SLOT(insertSpreadsheetView(PLViewTab *)));
138 void PLMainWindow::deleteTab()
140 int c = _mainWindow.tabWidget->currentIndex();
143 _mainWindow.tabWidget->removeTab(c);
147 void PLMainWindow::currentTabChanged(int tabIdx)
149 QWidget * w = _mainWindow.tabWidget->widget(tabIdx);
152 PLViewTab * viewtab = qobject_cast<PLViewTab *>(w);
153 if (viewtab && viewtab->getpqView())
155 pqActiveObjects::instance().setActiveView(viewtab->getpqView());
160 void PLMainWindow::doOpenFile()
165 // Load the stuff as wireframe in the main view:
166 QList<pqPipelineSource *> many = pqLoadDataReaction::loadData();
169 std::cout << "no file selected!" << std::endl;
172 if (many.count() > 1)
175 msgBox.setText("Select one file only!");
181 pqPipelineSource * src = many.at(0);
182 std::cout << "num of out ports: " << src->getNumberOfOutputPorts() << std::endl;
184 // A cone to start with:
185 // pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createSource(QString("sources"), QString("ConeSource"),
186 // this->_activeServer);
188 _simplePipeline.push(src);
190 // Retrieve loaded file name
191 vtkSMProperty * prop = src->getSourceProxy()->GetProperty("FileName");
192 vtkSMStringVectorProperty * prop2 = vtkSMStringVectorProperty::SafeDownCast(prop);
193 QString fName(prop2->GetElement(0));
196 emit changedCurrentFile(fName);
199 void PLMainWindow::insertSingleView(PLViewTab * tab)
201 // Create a new view proxy on the server
202 pqObjectBuilder* builder = _pAppC->getObjectBuilder();
203 pqServer* active_serv = pqActiveObjects::instance().activeServer();
205 std::cout << "About to create single view ..." << std::endl;
206 pqView * pqview = builder->createView(QString("RenderView"), active_serv);
207 std::cout << "Created: " << pqview << "!" << std::endl;
209 // Retrieve its widget and pass it to the Qt tab:
210 QWidget* viewWidget = pqview->widget();
212 // QWidget* viewWidget = new QPushButton("toto");
213 tab->hideAndReplace(viewWidget, pqview);
215 pqActiveObjects::instance().setActiveView(pqview);
218 void PLMainWindow::insertSpreadsheetView(PLViewTab * tab)
220 // Create a new view proxy on the server
221 pqObjectBuilder* builder = _pAppC->getObjectBuilder();
222 pqServer* active_serv = pqActiveObjects::instance().activeServer();
224 std::cout << "About to create spreadsheet view ..." << std::endl;
225 pqView * pqview = builder->createView(QString("SpreadSheetView"), active_serv);
226 std::cout << "Created: " << pqview << "!" << std::endl;
228 // Retrieve its widget and pass it to the Qt tab:
229 QWidget* viewWidget = pqview->widget();
231 // QWidget* viewWidget = new QPushButton("toto");
232 tab->hideAndReplace(viewWidget, pqview);
234 pqActiveObjects::instance().setActiveView(pqview);
238 void PLMainWindow::insertMultiView(PLViewTab * tab)
240 // Retrieve TabbedMultiView and see if it is already attached to someone:
241 PVViewer_GUIElements * pvgui = PVViewer_GUIElements::GetInstance(this);
242 pqTabbedMultiViewWidget * multiv = pvgui->getTabbedMultiViewWidget();
244 QWidget * parent = multiv->nativeParentWidget();
248 msgBox.setText("Multi-view already in use in another tab! Close it first.");
253 tab->hideAndReplace(multiv, NULL);
257 void PLMainWindow::doShrink()
259 if(!_simplePipeline.isEmpty())
263 pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createFilter(QString("filters"),
264 QString("ShrinkFilter"), _simplePipeline.top());
266 _simplePipeline.push(src);
273 void PLMainWindow::doSlice()
275 if(!_simplePipeline.isEmpty())
279 pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createFilter(QString("filters"),
280 QString("Cut"), _simplePipeline.top());
282 _simplePipeline.push(src);
289 void PLMainWindow::doManagePlugins()
291 pqManagePluginsReaction::managePlugins();
294 void PLMainWindow::cleanAll()
296 this->_pAppC->getObjectBuilder()->destroyPipelineProxies();
297 _simplePipeline.resize(0);
300 void PLMainWindow::cleanAllButSource()
302 while(_simplePipeline.size() > 1)
303 this->_pAppC->getObjectBuilder()->destroy(_simplePipeline.pop());