1 // Copyright (C) 2010-2013 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.
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
20 #include "pqMedReaderPanel.h"
21 #include "ui_MedReaderPanel.h"
23 #include "vtkProcessModule.h"
24 #include "vtkMultiBlockDataSet.h"
25 #include "vtkInformation.h"
26 #include "vtkIntArray.h"
27 #include "vtkSMDoubleVectorProperty.h"
28 #include "vtkSMIntVectorProperty.h"
29 #include "vtkSMStringVectorProperty.h"
30 #include "vtkSMProxy.h"
31 #include "vtkEventQtSlotConnect.h"
32 #include "vtkPVSILInformation.h"
34 #include "vtkSMPropertyHelper.h"
35 #include "vtkStringArray.h"
36 #include "vtkDataSetAttributes.h"
37 #include "vtkMedReader.h"
39 #include "vtkMedUtilities.h"
41 #include "pqTreeWidgetItemObject.h"
42 #include "pqSMAdaptor.h"
44 #include "pqPropertyManager.h"
45 #include "pqSILModel.h"
46 #include "pqProxySILModel.h"
47 #include "pqTreeViewSelectionHelper.h"
48 #include "pqTreeWidgetSelectionHelper.h"
49 #include "pqPropertyLinks.h"
51 #include <QHeaderView>
53 class pqMedReaderPanel::pqUI: public QObject, public Ui::MedReaderPanel
56 pqUI(pqMedReaderPanel* p) :
59 this->VTKConnect = vtkSmartPointer<vtkEventQtSlotConnect>::New();
60 this->SILUpdateStamp = -1;
68 vtkSmartPointer<vtkEventQtSlotConnect> VTKConnect;
69 pqPropertyLinks Links;
70 QMap<QTreeWidgetItem*, QString> TreeItemToPropMap;
71 pqProxySILModel* entityModel;
72 pqProxySILModel* groupModel;
76 pqMedReaderPanel::pqMedReaderPanel(pqProxy* object_proxy, QWidget* p) :
77 Superclass(object_proxy, p)
79 this->UI = new pqUI(this);
80 this->UI->setupUi(this);
82 pqProxySILModel* proxyModel;
84 // connect groups to groupsRoot
85 proxyModel = new pqProxySILModel("GroupTree", &this->UI->SILModel);
86 proxyModel->setSourceModel(&this->UI->SILModel);
87 this->UI->Groups->setModel(proxyModel);
88 this->UI->Groups->setHeaderHidden(true);
90 this->UI->groupModel = new pqProxySILModel("Groups", &this->UI->SILModel);
91 this->UI->groupModel->setSourceModel(&this->UI->SILModel);
93 // connect cell types to "EntityRoot"
94 proxyModel = new pqProxySILModel("EntityTree", &this->UI->SILModel);
95 proxyModel->setSourceModel(&this->UI->SILModel);
96 this->UI->Entity->setModel(proxyModel);
97 this->UI->Entity->setHeaderHidden(true);
99 this->UI->entityModel = new pqProxySILModel("Entity", &this->UI->SILModel);
100 this->UI->entityModel->setSourceModel(&this->UI->SILModel);
104 this->UI->Groups->header()->setStretchLastSection(true);
105 this->UI->Entity->header()->setStretchLastSection(true);
107 this->linkServerManagerProperties();
109 QList<pqTreeWidget*> treeWidgets = this->findChildren<pqTreeWidget*> ();
110 foreach (pqTreeWidget* tree, treeWidgets)
112 new pqTreeWidgetSelectionHelper(tree);
115 QList<pqTreeView*> treeViews = this->findChildren<pqTreeView*> ();
116 foreach (pqTreeView* tree, treeViews)
118 new pqTreeViewSelectionHelper(tree);
121 this->connect(this->UI->groupModel, SIGNAL(valuesChanged()),
122 this, SLOT(setModified()));
123 this->connect(this->UI->entityModel, SIGNAL(valuesChanged()),
124 this, SLOT(setModified()));
125 this->connect(this->UI->TimeCombo, SIGNAL(currentIndexChanged(int)),
126 this, SLOT(setModified()));
127 this->connect(this->UI->GenerateVectors, SIGNAL(stateChanged(int)),
128 this, SLOT(setModified()));
130 this->UI->tabWidget->setCurrentIndex(0);
132 this->UI->VTKConnect->Connect(this->proxy(),
133 vtkCommand::UpdateInformationEvent, this, SLOT(updateSIL()));
136 pqMedReaderPanel::~pqMedReaderPanel()
140 void pqMedReaderPanel::addSelectionsToTreeWidget(const QString& prop,
141 QTreeWidget* tree, PixmapType pix)
143 vtkSMProperty* SMProperty = this->proxy()->GetProperty(prop.toAscii().data());
144 QList<QVariant> SMPropertyDomain;
145 SMPropertyDomain = pqSMAdaptor::getSelectionPropertyDomain(SMProperty);
147 for(j = 0; j < SMPropertyDomain.size(); j++)
149 QString varName = SMPropertyDomain[j].toString();
150 this->addSelectionToTreeWidget(varName, varName, tree, pix, prop, j);
154 void pqMedReaderPanel::addSelectionToTreeWidget(const QString& name,
155 const QString& realName, QTreeWidget* tree, PixmapType pix,
156 const QString& prop, int propIdx)
158 static QPixmap pixmaps[] = {
159 QPixmap(":/ParaViewResources/Icons/pqPointData16.png"),
160 QPixmap(":/ParaViewResources/Icons/pqCellData16.png"),
161 QPixmap(":/ParaViewResources/Icons/pqQuadratureData16.png"),
162 QPixmap(":/ParaViewResources/Icons/pqElnoData16.png") };
164 vtkSMProperty* SMProperty = this->proxy()->GetProperty(prop.toAscii().data());
166 if(!SMProperty || !tree)
173 pqTreeWidgetItemObject* item;
174 item = new pqTreeWidgetItemObject(tree, strs);
175 item->setData(0, Qt::ToolTipRole, name);
178 item->setData(0, Qt::DecorationRole, pixmaps[pix]);
180 item->setData(0, Qt::UserRole, QString("%1 %2").arg((int) pix).arg(realName));
181 this->propertyManager()->registerLink(item, "checked",
182 SIGNAL(checkedStateChanged(bool)), this->proxy(), SMProperty, propIdx);
184 this->UI->TreeItemToPropMap[item] = prop;
187 void pqMedReaderPanel::linkServerManagerProperties()
189 this->UI->Links.addPropertyLink(this->UI->groupModel, "values",
190 SIGNAL(valuesChanged()), this->proxy(), this->proxy()->GetProperty(
193 this->UI->Links.addPropertyLink(this->UI->entityModel, "values",
194 SIGNAL(valuesChanged()), this->proxy(), this->proxy()->GetProperty(
197 this->UI->Links.addPropertyLink(this->UI->GenerateVectors, "checked",
198 SIGNAL(toggled(bool)), this->proxy(), this->proxy()->GetProperty(
201 this->Superclass::linkServerManagerProperties();
203 // do the point variables
204 this->addSelectionsToTreeWidget("PointFieldsArrayStatus",
205 this->UI->Variables, PM_POINT);
206 // do the cell variables
207 this->addSelectionsToTreeWidget("CellFieldsArrayStatus", this->UI->Variables,
209 // do the quadrature variables
210 this->addSelectionsToTreeWidget("QuadratureFieldsArrayStatus",
211 this->UI->Variables, PM_QUADRATURE);
213 // do the Elno variables
214 this->addSelectionsToTreeWidget("ElnoFieldsArrayStatus",
215 this->UI->Variables, PM_ELNO);
216 this->setupAnimationModeWidget();
219 void pqMedReaderPanel::setupAnimationModeWidget()
221 this->UI->AnimationModeCombo->clear();
222 QList<QVariant> modes = pqSMAdaptor::getEnumerationPropertyDomain(
223 this->proxy()->GetProperty("AnimationMode"));
224 for(int mode = 0; mode < modes.size(); mode++)
226 QString modeName = modes[mode].toString();
227 this->UI->AnimationModeCombo->addItem(modeName);
230 this->UI->Links.addPropertyLink(this->UI->AnimationModeCombo, "currentIndex",
231 SIGNAL(currentIndexChanged(int)), this->proxy(),
232 this->proxy()->GetProperty("AnimationMode"));
234 this->connect(this->UI->AnimationModeCombo,
235 SIGNAL(currentIndexChanged(int)), this, SLOT(animationModeChanged(int)));
237 this->UI->Links.addPropertyLink(this->UI->TimeCombo, "currentIndex",
238 SIGNAL(currentIndexChanged(int)), this->proxy(),
239 this->proxy()->GetProperty("TimeIndexForIterations"));
241 this->addSelectionsToTreeWidget("FrequencyArrayStatus",
242 this->UI->Modes, PM_NONE);
244 vtkSMPropertyHelper helper(this->proxy(), "AnimationMode");
245 int mode = helper.GetAsInt(0);
246 this->animationModeChanged(mode);
247 this->updateAvailableTimes();
250 void pqMedReaderPanel::animationModeChanged(int mode)
252 if(mode == vtkMedReader::Default || mode == vtkMedReader::PhysicalTime)
254 this->UI->TimeCombo->hide();
255 this->UI->TimeLabel->hide();
256 this->UI->Modes->hide();
258 else if(mode == vtkMedReader::Iteration)
260 this->UI->TimeCombo->show();
261 this->UI->TimeLabel->show();
262 this->UI->Modes->hide();
264 else // vtkMedReader::Modes
266 this->UI->TimeCombo->hide();
267 this->UI->TimeLabel->hide();
268 this->UI->Modes->show();
270 vtkSMPropertyHelper(this->proxy(), "AnimationMode").Set(mode);
271 this->proxy()->UpdateVTKObjects();
275 void pqMedReaderPanel::updateAvailableTimes()
277 vtkSMDoubleVectorProperty* prop = vtkSMDoubleVectorProperty::SafeDownCast(
278 this->proxy()->GetProperty("AvailableTimes"));
280 this->proxy()->UpdatePropertyInformation(prop);
282 //prop->GetInformationHelper()->UpdateProperty(
283 // vtkProcessModuleConnectionManager::GetRootServerConnectionID(),
284 // vtkProcessModule::DATA_SERVER,
285 // this->proxy()->GetID(),
288 this->UI->TimeCombo->clear();
289 double *aux = prop->GetElements();
291 for(int tid = 0; tid < prop->GetNumberOfElements(); tid++)
293 this->UI->TimeCombo->addItem( QString::number(aux[tid]) );
298 void pqMedReaderPanel::updateSIL()
300 vtkSMProxy* reader = this->referenceProxy()->getProxy();
301 reader->UpdatePropertyInformation(reader->GetProperty("SILUpdateStamp"));
303 int stamp = vtkSMPropertyHelper(reader, "SILUpdateStamp").GetAsInt();
304 if (stamp != this->UI->SILUpdateStamp)
306 this->UI->SILUpdateStamp = stamp;
307 vtkPVSILInformation* info = vtkPVSILInformation::New();
308 reader->GatherInformation(info);
309 this->UI->SILModel.update(info->GetSIL());
311 this->UI->Groups->expandAll();
312 this->UI->Entity->expandAll();
318 this->proxy()->UpdatePropertyInformation(
319 this->proxy()->GetProperty("SILUpdateStamp"));
321 int stamp = vtkSMPropertyHelper(this->proxy(), "SILUpdateStamp").GetAsInt();
322 if(stamp != this->UI->SILUpdateStamp)
324 this->UI->SILUpdateStamp = stamp;
326 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
327 vtkPVSILInformation* info = vtkPVSILInformation::New();
328 pm->GatherInformation(this->proxy()->GetConnectionID(),
329 vtkProcessModule::DATA_SERVER, info, this->proxy()->GetID());
331 this->UI->SILModel.update(info->GetSIL());
333 this->UI->Groups->expandAll();
334 this->UI->Entity->expandAll();