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 #include <QtGui/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) :
55 _mainWindow.setupUi(this);
56 _autoApply = _mainWindow.actionAuto_apply->isChecked();
57 QObject::connect(this, SIGNAL(apply()), this, SLOT(onApply()));
58 QObject::connect(this, SIGNAL(changedCurrentFile(QString)), this, SLOT(onApply()));
62 // Called after ParaView application initialisation:
63 void PLMainWindow::finishUISetup()
65 _pAppC = PVViewer_Core::GetPVApplication();
66 PVViewer_GUIElements * pvgui = PVViewer_GUIElements::GetInstance(this);
67 QWidget * wprop = pvgui->getPropertiesPanel();
68 QWidget * wpipe = pvgui->getPipelineBrowserWidget();
69 wprop->setParent(_mainWindow.propFrame);
70 _mainWindow.verticalLayoutProp->addWidget(wprop);
71 wpipe->setParent(_mainWindow.pipelineFrame);
72 _mainWindow.verticalLayoutPipe->addWidget(wpipe);
74 PVViewer_GUIElements * pvge = PVViewer_GUIElements::GetInstance(this);
75 // pvge->setToolBarVisible(false);
77 // In this mockup, we play on the parent widget visibility (a QFrame), so show these:
78 pvge->getPipelineBrowserWidget()->show();
79 pvge->getPropertiesPanel()->show();
81 _mainWindow.propFrame->hide();
82 _mainWindow.pipelineFrame->hide();
83 // pvge->setToolBarEnabled(false);
84 // pvge->setToolBarVisible(false);
88 void PLMainWindow::autoApplyCheck(bool isChecked)
90 _autoApply = isChecked;
93 void PLMainWindow::onApply()
97 PVViewer_GUIElements * pvgui = PVViewer_GUIElements::GetInstance(this);
98 pqPropertiesPanel * wprop = pvgui->getPropertiesPanel();
103 void PLMainWindow::showProp(bool isChecked)
105 isChecked ? _mainWindow.propFrame->show() : _mainWindow.propFrame->hide();
108 void PLMainWindow::showPipeline(bool isChecked)
110 isChecked ? _mainWindow.pipelineFrame->show() : _mainWindow.pipelineFrame->hide();
113 void PLMainWindow::addTab()
115 int c = _mainWindow.tabWidget->count();
116 PLViewTab * newTab = new PLViewTab(_mainWindow.tabWidget);
117 int newIdx = _mainWindow.tabWidget->addTab(newTab, QString("Tab %1").arg(c+1));
118 _mainWindow.tabWidget->setCurrentIndex(newIdx);
121 QObject::connect(newTab, SIGNAL(onInsertSingleView(PLViewTab *)), this, SLOT(insertSingleView(PLViewTab *)));
122 QObject::connect(newTab, SIGNAL(onInsertMultiView(PLViewTab *)), this, SLOT(insertMultiView(PLViewTab *)));
125 void PLMainWindow::deleteTab()
127 int c = _mainWindow.tabWidget->currentIndex();
130 _mainWindow.tabWidget->removeTab(c);
134 void PLMainWindow::currentTabChanged(int tabIdx)
136 QWidget * w = _mainWindow.tabWidget->widget(tabIdx);
139 PLViewTab * viewtab = qobject_cast<PLViewTab *>(w);
140 if (viewtab && viewtab->getpqView())
142 pqActiveObjects::instance().setActiveView(viewtab->getpqView());
147 void PLMainWindow::doOpenFile()
152 // Load the stuff as wireframe in the main view:
153 QList<pqPipelineSource *> many = pqLoadDataReaction::loadData();
156 std::cout << "no file selected!" << std::endl;
159 if (many.count() > 1)
162 msgBox.setText("Select one file only!");
168 pqPipelineSource * src = many.at(0);
169 std::cout << "num of out ports: " << src->getNumberOfOutputPorts() << std::endl;
171 // A cone to start with:
172 // pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createSource(QString("sources"), QString("ConeSource"),
173 // this->_activeServer);
175 _simplePipeline.push(src);
177 // Retrieve loaded file name
178 vtkSMProperty * prop = src->getSourceProxy()->GetProperty("FileName");
179 vtkSMStringVectorProperty * prop2 = vtkSMStringVectorProperty::SafeDownCast(prop);
180 QString fName(prop2->GetElement(0));
183 emit changedCurrentFile(fName);
186 void PLMainWindow::insertSingleView(PLViewTab * tab)
188 // Create a new view proxy on the server
189 pqObjectBuilder* builder = _pAppC->getObjectBuilder();
190 pqServer* active_serv = pqActiveObjects::instance().activeServer();
192 std::cout << "About to create single view ..." << std::endl;
193 pqView * pqview = builder->createView(QString("RenderView"), active_serv);
194 std::cout << "Created: " << pqview << "!" << std::endl;
196 // Retrieve its widget and pass it to the Qt tab:
197 QWidget* viewWidget = pqview->getWidget();
199 // QWidget* viewWidget = new QPushButton("toto");
200 tab->hideAndReplace(viewWidget, pqview);
202 pqActiveObjects::instance().setActiveView(pqview);
205 void PLMainWindow::insertMultiView(PLViewTab * tab)
207 // Retrieve TabbedMultiView and see if it is already attached to someone:
208 PVViewer_GUIElements * pvgui = PVViewer_GUIElements::GetInstance(this);
209 pqTabbedMultiViewWidget * multiv = pvgui->getTabbedMultiViewWidget();
211 QWidget * parent = multiv->nativeParentWidget();
215 msgBox.setText("Multi-view already in use in another tab! Close it first.");
220 tab->hideAndReplace(multiv, NULL);
225 void PLMainWindow::doShrink()
227 if(!_simplePipeline.isEmpty())
231 pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createFilter(QString("filters"),
232 QString("ShrinkFilter"), _simplePipeline.top());
234 _simplePipeline.push(src);
241 void PLMainWindow::doSlice()
243 if(!_simplePipeline.isEmpty())
247 pqPipelineSource * src = this->_pAppC->getObjectBuilder()->createFilter(QString("filters"),
248 QString("Cut"), _simplePipeline.top());
250 _simplePipeline.push(src);
257 void PLMainWindow::doManagePlugins()
259 pqManagePluginsReaction::managePlugins();
262 void PLMainWindow::cleanAll()
264 this->_pAppC->getObjectBuilder()->destroyPipelineProxies();
265 _simplePipeline.resize(0);
268 void PLMainWindow::cleanAllButSource()
270 while(_simplePipeline.size() > 1)
271 this->_pAppC->getObjectBuilder()->destroy(_simplePipeline.pop());