Salome HOME
Make MEDReader compilable standalone. make test is still not working in standalone...
[modules/paravis.git] / src / Plugins / TableReader / ParaViewPlugin / pqTableReaderPanel.cxx
1 // Copyright (C) 2010-2016  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
20 #include "pqTableReaderPanel.h"
21
22 #include "vtkSMProxy.h"
23 #include "vtkSMStringVectorProperty.h"
24 #include "vtkProcessModule.h"
25
26 #include "pqPropertyLinks.h"
27
28 #include <QLayout>
29 #include <QSpinBox>
30
31
32 class pqTableReaderPanel::pqUI: public QObject, public Ui::TableReaderPanel
33 {
34 public:
35   pqUI(pqTableReaderPanel* p) : QObject(p)
36 {
37 }
38
39   ~pqUI()
40   {
41   }
42
43   pqPropertyLinks Links;
44 };
45
46
47 pqTableReaderPanel::pqTableReaderPanel(pqProxy* proxy, QWidget* p) :
48       Superclass(proxy, p)
49 {
50   this->UI = new pqUI(this);
51   this->UI->setupUi(this);
52
53   this->linkServerManagerProperties();
54   this->updateAvailableTables(false);
55
56   this->connect(this->UI->ValueDelimiter, SIGNAL(textChanged(const QString&)),
57       this, SLOT(onDelimiterChanged(const QString&)));
58   this->connect(this->UI->TableNames, SIGNAL(currentIndexChanged(int)),
59       this, SLOT(onCurrentTableChanged(int)));
60 }
61
62 pqTableReaderPanel::~pqTableReaderPanel()
63 {
64 }
65
66 void pqTableReaderPanel::onCurrentTableChanged(int currentTableIndex)
67 {
68   this->setModified();
69 }
70
71 void pqTableReaderPanel::onDelimiterChanged(const QString& value)
72 {
73   this->updateAvailableTables(true);
74 }
75
76 void pqTableReaderPanel::linkServerManagerProperties()
77 {
78   this->UI->Links.addPropertyLink(this->UI->TableNames, "currentIndex",
79       SIGNAL(currentIndexChanged(int)), this->proxy(),
80       this->proxy()->GetProperty("TableNumber"));
81
82   // To hook up the rest widgets
83   this->Superclass::linkServerManagerProperties();
84 }
85
86 void pqTableReaderPanel::updateAvailableTables(const bool keepCurrent)
87 {
88   vtkSMStringVectorProperty* prop = vtkSMStringVectorProperty::SafeDownCast(
89       this->proxy()->GetProperty("AvailableTables"));
90
91   int currentIndex = this->UI->TableNames->currentIndex();
92   QString currentText = this->UI->TableNames->currentText();
93
94   this->UI->TableNames->clear();
95
96   for(int id = 0; id < prop->GetNumberOfElements(); id++) 
97   {
98     QString text(prop->GetElement(id));
99     if (text.isEmpty())
100     {
101       text = QString("Table:%1").arg(id);
102     }
103     this->UI->TableNames->addItem(text);
104   }
105
106   if (keepCurrent && 
107       currentIndex < this->UI->TableNames->maxCount() &&
108       currentText == this->UI->TableNames->itemText(currentIndex)) 
109   {
110     this->UI->TableNames->setCurrentIndex(currentIndex);
111   }
112 }