1 // Copyright (C) 2010-2016 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 : Anthony Geay
21 #include "pqMEDReaderTimesFlagsWidget.h"
23 #include "VectBoolWidget.h"
24 #include "pqMEDReaderGraphUtils.h"
25 #include "vtkMEDReader.h"
26 #include "vtkPVMetaDataInformation.h"
28 #include "pqCoreUtilities.h"
29 #include "pqArrayListDomain.h"
30 #include "pqPropertiesPanel.h"
32 #include "vtkGraphWriter.h"
33 #include "vtkInformationDataObjectMetaDataKey.h"
35 #include "vtkSMDoubleVectorProperty.h"
36 #include "vtkSMStringVectorProperty.h"
39 #include <QGridLayout>
40 #include <QStringList>
42 //-----------------------------------------------------------------------------
43 pqMEDReaderTimesFlagsWidget::pqMEDReaderTimesFlagsWidget(
44 vtkSMProxy *smproxy, vtkSMProperty *smproperty, QWidget *parentObject)
45 : Superclass(smproxy, parentObject)
47 this->CachedTsId = -1;
48 this->TimesVectWidget = NULL;
49 this->setShowLabel(false);
52 this->TimesVectLayout = new QGridLayout(this);
55 this->CreateTimesVectWidget();
56 this->UpdateTimeSteps();
58 // Connect timeStepStatus property to update time steps method
59 vtkSMProperty* prop = smproxy? smproxy->GetProperty("FieldsStatus") : NULL;
62 qDebug("Could not locate property named 'FieldsStatus'. "
63 "pqMEDReaderTimesFlagsWidget will have no updated labels.");
67 pqCoreUtilities::connect(prop, vtkCommand::UncheckedPropertyModifiedEvent,
68 this, SLOT(UpdateTimeSteps()));
71 // Connect Property Domain to the timeStepDomain property,
72 // so setTimeStepDomain is called when the domain changes.
73 vtkSMDomain* arraySelectionDomain = smproperty->GetDomain("array_list");
74 new pqArrayListDomain(this,"timeStepsDomain", smproxy, smproperty, arraySelectionDomain);
76 // Connect property to timeStep QProperty using a biderectionnal property link
77 this->addPropertyLink(this, "timeSteps", SIGNAL(timeStepsChanged()),
80 if(!this->TimesVectWidget) // In case of error right at the begining of loading process (empty MED file)
83 const QMap<QString, VectBoolItem*>& items(this->TimesVectWidget->getItems());
84 QMap<QString, VectBoolItem*>::const_iterator it;
85 for (it = items.begin(); it != items.end(); it++)
87 QObject::connect(it.value(), SIGNAL(changed()), this, SLOT(onItemChanged()));
91 //-----------------------------------------------------------------------------
92 pqMEDReaderTimesFlagsWidget::~pqMEDReaderTimesFlagsWidget()
94 delete this->TimesVectWidget;
97 //-----------------------------------------------------------------------------
98 void pqMEDReaderTimesFlagsWidget::onItemChanged() const
100 emit timeStepsChanged();
103 //-----------------------------------------------------------------------------
104 QList< QList< QVariant> > pqMEDReaderTimesFlagsWidget::getTimeSteps() const
106 // Put together a TimeStep list, using ItemMap
107 QList< QList< QVariant> > ret;
108 QList< QVariant > timeStep;
109 if(!this->TimesVectWidget) // In case of error right at the begining of loading process (empty MED file)
111 const QMap<QString, VectBoolItem*>& items(this->TimesVectWidget->getItems());
112 QMap<QString, VectBoolItem*>::const_iterator it;
113 for (it = items.begin(); it != items.end(); it++)
116 timeStep.append(it.key());
117 timeStep.append(it.value()->isActivated());
118 ret.append(timeStep);
123 //-----------------------------------------------------------------------------
124 void pqMEDReaderTimesFlagsWidget::setTimeSteps(QList< QList< QVariant> > timeSteps)
126 // Update each item checkboxes, using timeSteps names and ItemMap
127 const QMap<QString, VectBoolItem *>& items(this->TimesVectWidget->getItems());
128 QMap<QString, VectBoolItem*>::const_iterator it;
129 foreach (QList< QVariant> timeStep, timeSteps)
131 it = items.find(timeStep[0].toString());
132 if (it == items.end())
134 qDebug("Found an unknow TimeStep in pqMEDReaderTimesFlagsWidget::setTimeSteps, ignoring");
137 it.value()->activated(timeStep[1].toBool());
141 //-----------------------------------------------------------------------------
142 void pqMEDReaderTimesFlagsWidget::setTimeStepsDomain(QList< QList< QVariant> > timeSteps)
144 cout<<"TimeStepsDomai"<<endl;
145 // Block signals so the reloading does not trigger
146 // UncheckPropertyModified event
147 this->blockSignals(true);
149 // Load the tree widget
150 this->CreateTimesVectWidget();
152 // Set timeSteps checkboxes
153 this->setTimeSteps(timeSteps);
156 this->blockSignals(false);
159 //-----------------------------------------------------------------------------
160 void pqMEDReaderTimesFlagsWidget::CreateTimesVectWidget()
163 vtkPVMetaDataInformation *info(vtkPVMetaDataInformation::New());
164 this->proxy()->GatherInformation(info);
165 vtkGraph* graph = vtkGraph::SafeDownCast(info->GetInformationData());
168 if (this->TimesVectWidget != NULL)
170 delete this->TimesVectWidget;
174 return ;// In case of error right at the begining of loading process (empty MED file)
176 // (Re)cretate widget
177 this->TimesVectWidget = new VectBoolWidget(this,
178 pqMedReaderGraphUtils::getMaxNumberOfTS(graph));
179 this->TimesVectLayout->addWidget(this->TimesVectWidget);
182 //-----------------------------------------------------------------------------
183 void pqMEDReaderTimesFlagsWidget::UpdateTimeSteps()
186 vtkSMStringVectorProperty* prop = this->proxy()?
187 vtkSMStringVectorProperty::SafeDownCast(this->proxy()->GetProperty("FieldsStatus")) : NULL;
191 // Searching first activated leaf id
192 for (int i = 1; i < prop->GetNumberOfElements(); i += 2)
194 if (prop->GetElement(i)[0] == '1')
196 const char* leafString = prop->GetElement(i - 1);
197 const char* tmp = strchr(leafString, '/');
198 size_t num = tmp - leafString;
199 char* dest = new char[num];
200 strncpy(dest, leafString, num);
202 tsId = strtol(dest + 2, NULL, 10);
209 if (tsId != -1 && tsId != this->CachedTsId)
212 this->CachedTsId = tsId;
213 vtkPVMetaDataInformation *info(vtkPVMetaDataInformation::New());
214 this->proxy()->GatherInformation(info);
215 vtkGraph* g = vtkGraph::SafeDownCast(info->GetInformationData());
217 // Updating times steps using leaf id
218 QStringList dts, its, tts;
219 pqMedReaderGraphUtils::getCurrentTS(g, tsId, dts, its, tts);
220 this->TimesVectWidget->setItems(dts, its, tts);