Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / ParaViewPlugin / pqMEDReaderReloadWidget.cxx
1 // Copyright (C) 2010-2022  CEA/DEN, EDF R&D
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 // Author : Anthony Geay
20
21 #include "pqMEDReaderReloadWidget.h"
22
23 #include "vtkSMProxy.h"
24 #include "vtkSMSourceProxy.h"
25 #include "vtkSMProperty.h"
26
27 #include "pqPropertiesPanel.h"
28
29 #include <QPushButton>
30 #include <QGridLayout>
31
32 pqMEDReaderReloadWidget::pqMEDReaderReloadWidget(vtkSMProxy *smProxy,
33                                                  vtkSMProperty *proxyProperty,
34                                                  QWidget *pWidget)
35 : pqPropertyWidget(smProxy, pWidget),
36   Property(proxyProperty)
37 {
38   this->setShowLabel(false);
39
40   // Grid Layout
41   QGridLayout* gridLayout = new QGridLayout(this);
42   gridLayout->setAlignment(Qt::AlignRight);
43
44   // Reload Button
45   QPushButton *button = new QPushButton();
46   button->setIcon(QIcon(":/ParaViewResources/Icons/pqReloadFile16.png"));
47   button->setFixedSize(button->sizeHint());
48   gridLayout->addWidget(button);
49
50   // Connection
51   connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
52 }
53
54 pqMEDReaderReloadWidget::~pqMEDReaderReloadWidget()
55 {
56 }
57
58 void pqMEDReaderReloadWidget::buttonClicked()
59 {
60   // Recovering Property Panel
61   pqPropertiesPanel* panel = NULL;
62   QObject* tmp = this;
63   while (panel == NULL)
64     {
65     tmp = tmp->parent();
66     if (!tmp)
67       {
68       break;
69       }
70     panel = qobject_cast<pqPropertiesPanel*>(tmp);
71     }
72
73   if (!panel)
74     {
75     qDebug() << "Cannot find pqPropertiesPanel, reload may not work";
76     }
77   else
78     {
79     // Restoring property to defaults, necessary when unchecked property are not applied
80     panel->propertiesRestoreDefaults();
81     }
82
83   // Reloading the data and associated properties
84   this->Property->Modified();
85   this->proxy()->UpdateProperty(this->proxy()->GetPropertyName(this->Property));
86   vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipelineInformation();
87
88   // Restting properties to dufault using domains and XML values
89   this->proxy()->ResetPropertiesToDefault();
90
91   if (panel)
92     {
93     // Disabled apply button inderectly
94     panel->propertiesRestoreDefaults();
95     }
96 }