1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2020 CEA/DEN, EDF R&D
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : PVGUI_ParaViewSettingsPane.cxx
22 // Author : Vitaly Smetannikov
25 #include "PVGUI_ParaViewSettingsPane.h"
26 #include "ui_pqCustomSettingsWidget.h"
28 #include <LightApp_Application.h>
30 #include <QtxDialog.h>
35 #include "pqActiveObjects.h"
36 #include "pqApplicationCore.h"
37 #include "pqProxyWidget.h"
38 #include "pqSearchBox.h"
40 #include "pqSettings.h"
41 #include "pqUndoStack.h"
43 #include "vtkPVXMLElement.h"
44 #include "vtkSmartPointer.h"
45 #include "vtkSMProperty.h"
46 #include "vtkSMPropertyHelper.h"
47 #include "vtkSMPropertyIterator.h"
48 #include "vtkSMProxy.h"
49 #include "vtkSMProxyIterator.h"
50 #include "vtkSMSessionProxyManager.h"
51 #include "vtkSMSettings.h"
55 #include <QPushButton>
56 #include <QScrollArea>
57 #include <QSpacerItem>
58 #include <QVBoxLayout>
62 class PVGUI_ParaViewSettingsPane::pqInternals
65 Ui::CustomSettingsWidget Ui;
67 // Map from tab indices to stack widget indices. This is needed because there
68 // are more widgets in the stacked widgets than just what we add.
69 QMap<int, int> TabToStackedWidgets;
72 bool PVGUI_ParaViewSettingsPane::ShowRestartRequired = false;
74 //----------------------------------------------------------------------------
75 PVGUI_ParaViewSettingsPane::PVGUI_ParaViewSettingsPane(QWidget *widgetParent, LightApp_Application * app)
76 : QtxUserDefinedContent(widgetParent),
77 Internals (new PVGUI_ParaViewSettingsPane::pqInternals())
79 Ui::CustomSettingsWidget &ui = this->Internals->Ui;
81 ui.tabBar->setDocumentMode(false);
82 ui.tabBar->setDrawBase(false);
83 ui.tabBar->setExpanding(false);
84 ui.tabBar->setUsesScrollButtons(true);
86 // Hide restart message
87 ui.restartRequiredLabel->setVisible(PVGUI_ParaViewSettingsPane::ShowRestartRequired);
89 QList<vtkSMProxy*> proxies_to_show;
91 pqServer* server = pqActiveObjects::instance().activeServer();
92 vtkNew<vtkSMProxyIterator> iter;
93 iter->SetSession(server->session());
94 iter->SetModeToOneGroup();
95 for (iter->Begin("settings"); !iter->IsAtEnd(); iter->Next())
97 vtkSMProxy* proxy = iter->GetProxy();
100 proxies_to_show.push_back(proxy);
104 // Add color palette.
105 if (vtkSMProxy* proxy = server->proxyManager()->GetProxy("global_properties", "ColorPalette"))
107 proxies_to_show.push_back(proxy);
110 foreach (vtkSMProxy* proxy, proxies_to_show)
112 QString proxyName = proxy->GetXMLName();
114 QScrollArea *scrollArea = new QScrollArea(this);
115 scrollArea->setObjectName(QString("ScrollArea%1").arg(proxyName));
116 scrollArea->setWidgetResizable(true);
117 scrollArea->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
118 scrollArea->setFrameShape(QFrame::NoFrame);
120 QWidget* container = new QWidget(scrollArea);
121 container->setObjectName("Container");
122 container->setContentsMargins(6, 0, 6, 0);
124 QVBoxLayout* vbox = new QVBoxLayout(container);
128 pqProxyWidget* widget = new pqProxyWidget(proxy, container);
129 widget->setObjectName("ProxyWidget");
130 widget->setApplyChangesImmediately(false);
131 widget->setView(NULL);
133 widget->connect(this, SIGNAL(accepted()), SLOT(apply()));
134 widget->connect(this, SIGNAL(rejected()), SLOT(reset()));
135 this->connect(widget, SIGNAL(restartRequired()), SLOT(showRestartRequiredMessage()));
136 vbox->addWidget(widget);
138 QSpacerItem* spacer = new QSpacerItem(0, 0,QSizePolicy::Fixed,
139 QSizePolicy::MinimumExpanding);
140 vbox->addItem(spacer);
142 scrollArea->setWidget(container);
143 // show panel widgets
144 widget->updatePanel();
146 int tabIndex = ui.tabBar->addTab(proxy->GetXMLLabel());
147 int stackIndex = ui.stackedWidget->addWidget(scrollArea);
148 this->Internals->TabToStackedWidgets[tabIndex] = stackIndex;
150 this->connect(widget, SIGNAL(changeAvailable()), SLOT(onChangeAvailable()));
151 widget->connect(this, SIGNAL(filterWidgets(bool, QString)), SLOT(filterWidgets(bool, QString)));
154 // Disable some buttons to start
155 // ui.buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
156 // ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
158 // this->connect(ui.buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()),
159 // SLOT(onRestoreDefaults()));
160 // this->connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(clicked(QAbstractButton*)));
162 // [ABN] connect to reset to default emitted by Light_App:
163 this->connect(app, SIGNAL(preferenceResetToDefaults()), this, SLOT(onRestoreDefaults()));
165 this->connect(this, SIGNAL(accepted()), SLOT(onAccepted()));
166 this->connect(this, SIGNAL(rejected()), SLOT(onRejected()));
167 this->connect(ui.tabBar, SIGNAL(currentChanged(int)), this, SLOT(onTabIndexChanged(int)));
169 this->connect(ui.SearchBox, SIGNAL(advancedSearchActivated(bool)), SLOT(filterPanelWidgets()));
170 this->connect(ui.SearchBox, SIGNAL(textChanged(QString)), SLOT(filterPanelWidgets()));
172 // After all the tabs are set up, select the first
173 this->onTabIndexChanged(0);
175 this->filterPanelWidgets();
178 //-----------------------------------------------------------------------------
179 PVGUI_ParaViewSettingsPane::~PVGUI_ParaViewSettingsPane()
181 delete this->Internals;
182 this->Internals = NULL;
185 void PVGUI_ParaViewSettingsPane::store(QtxResourceMgr* , QtxPreferenceMgr* )
187 emit this->accepted();
190 void PVGUI_ParaViewSettingsPane::retrieve(QtxResourceMgr* , QtxPreferenceMgr* )
192 // onRestoreDefaults();
195 void PVGUI_ParaViewSettingsPane::showEvent(QShowEvent * ev)
197 // // Connect SALOME's default button to ParaView's default restore.
198 // LightApp_PreferencesDlg * prefDg;
199 // QWidget *w = this->parentWidget();
203 // LightApp_PreferencesDlg * prefDg = dynamic_cast<LightApp_PreferencesDlg *>( w );
206 // w = w->parentWidget();
209 // prefDg->connect(btn, SIGNAL(clicked()), this, SLOT(onRestoreDefaults()));
213 void PVGUI_ParaViewSettingsPane::hideEvent(QHideEvent * ev)
215 // Connect SALOME's default button to ParaView's default restore.
219 //-----------------------------------------------------------------------------
220 void PVGUI_ParaViewSettingsPane::clicked(QAbstractButton * /*button*/)
222 // Ui::CustomSettingsWidget &ui = this->Internals->Ui;
223 // QDialogButtonBox::ButtonRole role = ui.buttonBox->buttonRole(button);
226 // case QDialogButtonBox::AcceptRole:
227 // case QDialogButtonBox::ApplyRole:
228 // emit this->accepted();
231 // case QDialogButtonBox::ResetRole:
232 // case QDialogButtonBox::RejectRole:
233 // emit this->rejected();
240 //-----------------------------------------------------------------------------
241 void PVGUI_ParaViewSettingsPane::onAccepted()
243 // If there are any properties that needed to save their values in QSettings,
244 // do that. Otherwise, save to the vtkSMSettings singleton.
245 vtkSMSettings * settings = vtkSMSettings::GetInstance();
246 pqServer* server = pqActiveObjects::instance().activeServer();
247 vtkNew<vtkSMProxyIterator> iter;
248 iter->SetSession(server->session());
249 iter->SetModeToOneGroup();
250 for (iter->Begin("settings"); !iter->IsAtEnd(); iter->Next())
252 vtkSMProxy* proxy = iter->GetProxy();
253 settings->SetProxySettings(proxy);
254 vtkSmartPointer<vtkSMPropertyIterator> iter2;
255 iter2.TakeReference(proxy->NewPropertyIterator());
256 for (iter2->Begin(); !iter2->IsAtEnd(); iter2->Next())
258 vtkSMProperty* smproperty = iter2->GetProperty();
259 if (smproperty && smproperty->GetHints() &&
260 smproperty->GetHints()->FindNestedElementByName("SaveInQSettings"))
262 QString key = QString("%1.%2").arg(iter->GetKey()).arg(iter2->GetKey());
263 this->saveInQSettings(key.toLatin1().data(), smproperty);
268 // Save color palette settings
269 vtkSMProxy* paletteProxy = server->proxyManager()->GetProxy("global_properties", "ColorPalette");
272 settings->SetProxySettings(paletteProxy);
276 // Ui::CustomSettingsWidget &ui = this->Internals->Ui;
277 // ui.buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
278 // ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
280 // In theory, the above changes are undo-redo able, the only things that's not
281 // undo-able is the "serialized" values. Hence we just clear the undo stack.
285 //-----------------------------------------------------------------------------
286 void PVGUI_ParaViewSettingsPane::onRejected()
289 // Ui::CustomSettingsWidget &ui = this->Internals->Ui;
290 // ui.buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
291 // ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
294 //-----------------------------------------------------------------------------
295 void PVGUI_ParaViewSettingsPane::onRestoreDefaults()
297 pqServer* server = pqActiveObjects::instance().activeServer();
298 vtkSMSession * session = server->session();
300 vtkNew<vtkSMProxyIterator> iter;
301 iter->SetSession(session);
302 iter->SetModeToOneGroup();
303 for (iter->Begin("settings"); !iter->IsAtEnd(); iter->Next())
305 vtkSMProxy* proxy = iter->GetProxy();
308 proxy->ResetPropertiesToXMLDefaults();
312 vtkSMProxy* paletteProxy = server->proxyManager()->GetProxy("global_properties", "ColorPalette");
315 paletteProxy->ResetPropertiesToXMLDefaults();
319 //-----------------------------------------------------------------------------
320 void PVGUI_ParaViewSettingsPane::onTabIndexChanged(int index)
322 int stackWidgetIndex = this->Internals->TabToStackedWidgets[index];
323 Ui::CustomSettingsWidget &ui = this->Internals->Ui;
324 ui.stackedWidget->setCurrentIndex(stackWidgetIndex);
327 //-----------------------------------------------------------------------------
328 void PVGUI_ParaViewSettingsPane::filterPanelWidgets()
330 Ui::CustomSettingsWidget &ui = this->Internals->Ui;
331 emit this->filterWidgets(
332 ui.SearchBox->isAdvancedSearchActive(), ui.SearchBox->text());
335 //-----------------------------------------------------------------------------
336 void PVGUI_ParaViewSettingsPane::onChangeAvailable()
338 // Ui::CustomSettingsWidget &ui = this->Internals->Ui;
339 // ui.buttonBox->button(QDialogButtonBox::Reset)->setEnabled(true);
340 // ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
343 //-----------------------------------------------------------------------------
344 void PVGUI_ParaViewSettingsPane::showRestartRequiredMessage()
346 Ui::CustomSettingsWidget &ui = this->Internals->Ui;
347 ui.restartRequiredLabel->setVisible(true);
348 PVGUI_ParaViewSettingsPane::ShowRestartRequired = true;
351 //-----------------------------------------------------------------------------
352 void PVGUI_ParaViewSettingsPane::saveInQSettings(
353 const char* key, vtkSMProperty* smproperty)
355 pqSettings* settings = pqApplicationCore::instance()->settings();
357 // FIXME: handle all property types. This will only work for single value
359 if (smproperty->IsA("vtkSMIntVectorProperty") ||
360 smproperty->IsA("vtkSMIdTypeVectorProperty"))
362 settings->setValue(key, vtkSMPropertyHelper(smproperty).GetAsInt());
364 else if (smproperty->IsA("vtkSMDoubleVectorProperty"))
366 settings->setValue(key, vtkSMPropertyHelper(smproperty).GetAsDouble());
368 else if (smproperty->IsA("vtkSMStringVectorProperty"))
370 settings->setValue(key, vtkSMPropertyHelper(smproperty).GetAsString());