]> SALOME platform Git repositories - modules/paravis.git/blob - src/Plugins/MEDReader/ParaViewPlugin/pqMEDReaderPanel.cxx
Salome HOME
0022921: [CEA 1438] Remove the checkbox in the "time steps"
[modules/paravis.git] / src / Plugins / MEDReader / ParaViewPlugin / pqMEDReaderPanel.cxx
1 // Copyright (C) 2010-2015  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 "pqMEDReaderPanel.h"
22 #include "ui_MEDReaderPanel.h"
23 #include "VectBoolWidget.h"
24
25 #include "vtkProcessModule.h"
26 #include "vtkMultiBlockDataSet.h"
27 #include "vtkInformation.h"
28 #include "vtkIntArray.h"
29 #include "vtkSMDoubleVectorProperty.h"
30 #include "vtkSMIntVectorProperty.h"
31 #include "vtkSMStringVectorProperty.h"
32 #include "vtkSMProxy.h"
33 #include "vtkEventQtSlotConnect.h"
34 #include "vtkPVSILInformation.h"
35 #include "vtkGraph.h"
36 #include "vtkMutableDirectedGraph.h"
37 #include "vtkAdjacentVertexIterator.h"
38 #include "vtkSMPropertyHelper.h"
39 #include "vtkStringArray.h"
40 #include "vtkDataSetAttributes.h"
41 #include "vtkMEDReader.h"
42 #include "vtkSMSourceProxy.h"
43
44 #include "pqTreeWidgetItemObject.h"
45 #include "pqSMAdaptor.h"
46 #include "pqProxy.h"
47 #include "pqPropertyManager.h"
48 #include "pqSILModel.h"
49 #include "pqProxySILModel.h"
50 #include "pqTreeViewSelectionHelper.h"
51 #include "pqTreeWidgetSelectionHelper.h"
52
53 #include <QHeaderView>
54
55 #include <sstream>
56
57 static const char ZE_SEP[]="@@][@@";
58
59 class PixSingle
60 {
61 public:
62   static const PixSingle &GetInstance();
63   QPixmap getPixFromStr(const std::string& st) const;
64   QPixmap getWholeMeshPix() const;
65   PixSingle();
66 private:
67   static const int NB_OF_DISCR=4;
68   static PixSingle *UNIQUE_PIX_SINGLE;
69   QPixmap _pixmaps[NB_OF_DISCR];
70   std::map<std::string,int> _ze_map;
71   QPixmap _whole_mesh;
72 };
73
74 PixSingle *PixSingle::UNIQUE_PIX_SINGLE=0;
75
76 const PixSingle &PixSingle::GetInstance()
77 {
78   if(!UNIQUE_PIX_SINGLE)
79     UNIQUE_PIX_SINGLE=new PixSingle;
80   return *UNIQUE_PIX_SINGLE;
81 }
82
83 PixSingle::PixSingle()
84 {
85   _pixmaps[0]=QPixmap(":/ParaViewResources/Icons/pqCellData16.png");
86   _pixmaps[1]=QPixmap(":/ParaViewResources/Icons/pqPointData16.png");
87   _pixmaps[2]=QPixmap(":/ParaViewResources/Icons/pqQuadratureData16.png");
88   _pixmaps[3]=QPixmap(":/ParaViewResources/Icons/pqElnoData16.png");
89   _ze_map[std::string("P0")]=0;
90   _ze_map[std::string("P1")]=1;
91   _ze_map[std::string("GAUSS")]=2;
92   _ze_map[std::string("GSSNE")]=3;
93   _whole_mesh=QPixmap(":/ParaViewResources/Icons/pqCellDataForWholeMesh16.png");
94 }
95
96 QPixmap PixSingle::getPixFromStr(const std::string& st) const
97 {
98   std::map<std::string,int>::const_iterator it(_ze_map.find(st));
99   if(it!=_ze_map.end())
100     return _pixmaps[(*it).second];
101   else
102     return QPixmap();
103 }
104
105 QPixmap PixSingle::getWholeMeshPix() const
106 {
107   return _whole_mesh;
108 }
109
110 class pqMEDReaderPanel::pqUI: public QObject, public Ui::MEDReaderPanel
111 {
112 public:
113   pqUI(pqMEDReaderPanel *p):QObject(p)
114   {
115     this->VTKConnect = vtkSmartPointer<vtkEventQtSlotConnect>::New();
116   }
117
118   ~pqUI() { }
119   
120   vtkSmartPointer<vtkEventQtSlotConnect> VTKConnect;
121   QMap<QTreeWidgetItem*, QString> TreeItemToPropMap;
122 };
123
124 pqMEDReaderPanel::pqMEDReaderPanel(pqProxy *object_proxy, QWidget *p):Superclass(object_proxy,p),_reload_req(false),_is_fields_status_changed(false),_optional_widget(0)
125 {
126   initAll();
127 }
128
129 // VSR, 16/03/2015, PAL22921
130 // Below is the helper class which is implemented a workaround about ugly pqTreeWidgetItemObject class.
131 // We use this helper class to make 1st and 2nd level tree items uncheckable.
132 class pqMyTreeWidgetItemObject : public pqTreeWidgetItemObject
133 {
134 public:
135   pqMyTreeWidgetItemObject(const QStringList& t, int type=QTreeWidgetItem::UserType): pqTreeWidgetItemObject(t, type){}
136   pqMyTreeWidgetItemObject(QTreeWidget* p, const QStringList& t, int type=QTreeWidgetItem::UserType): pqTreeWidgetItemObject(p, t, type){}
137   pqMyTreeWidgetItemObject(QTreeWidgetItem* p, const QStringList& t, int type=QTreeWidgetItem::UserType): pqTreeWidgetItemObject(p, t, type){}
138   virtual void  setData ( int column, int role, const QVariant & value )
139   {
140     if ( role != Qt::CheckStateRole)
141       pqTreeWidgetItemObject::setData(column, role, value );
142   }
143 };
144
145 void pqMEDReaderPanel::initAll()
146 {
147   _all_lev4.clear();
148   this->UI=new pqUI(this);
149   this->UI->setupUi(this);
150   this->UI->Fields->setHeaderHidden(true);
151   this->updateSIL();
152   ////////////////////
153   vtkSMProxy *reader(this->referenceProxy()->getProxy());
154   vtkPVSILInformation *info(vtkPVSILInformation::New());
155   reader->GatherInformation(info);
156   vtkGraph *g(info->GetSIL());
157   if(!g)//something wrong server side...
158     return ;
159   //vtkMutableDirectedGraph *g2(vtkMutableDirectedGraph::SafeDownCast(g));// agy: this line does not work in client/server mode ! but it works in standard mode ! Don't know why. ParaView bug ?
160   vtkMutableDirectedGraph *g2(static_cast<vtkMutableDirectedGraph *>(g));
161   int idNames(0);
162   vtkAbstractArray *verticesNames(g2->GetVertexData()->GetAbstractArray("Names",idNames));
163   vtkStringArray *verticesNames2(vtkStringArray::SafeDownCast(verticesNames));
164   vtkIdType id0;
165   bool found(false);
166   for(int i=0;i<verticesNames2->GetNumberOfValues();i++)
167     {
168       vtkStdString &st(verticesNames2->GetValue(i));
169       if(st=="FieldsStatusTree")
170         {
171           id0=i;
172           found=true;
173         }
174     }
175   if(!found)
176     std::cerr << "There is an internal error ! The tree on server side has not the expected look !" << std::endl;
177   vtkAdjacentVertexIterator *it0(vtkAdjacentVertexIterator::New());
178   g2->GetAdjacentVertices(id0,it0);
179   int kk(0),ll(0);
180   while(it0->HasNext())
181     {
182       vtkIdType idToolTipForTS(it0->Next());
183       QString toolTipName0(QString::fromStdString((const char *)verticesNames2->GetValue(idToolTipForTS)));
184       QString nbTS;
185       QList<QString> dts,its,tts;
186       {
187         vtkAdjacentVertexIterator *itForTS(vtkAdjacentVertexIterator::New());
188         g2->GetAdjacentVertices(idToolTipForTS,itForTS);
189         vtkIdType idForNbTS(itForTS->Next());
190         nbTS=QString::fromStdString((const char *)verticesNames2->GetValue(idForNbTS));
191         itForTS->Delete();
192         int nbTSInt(nbTS.toInt());
193         for(int ii=0;ii<nbTSInt;ii++)
194           {
195             dts.push_back(QString::fromStdString((const char *)verticesNames2->GetValue(idForNbTS+3*ii+1)));
196             its.push_back(QString::fromStdString((const char *)verticesNames2->GetValue(idForNbTS+3*ii+2)));
197             tts.push_back(QString::fromStdString((const char *)verticesNames2->GetValue(idForNbTS+3*ii+3)));
198           }
199       }
200       vtkIdType id1(it0->Next());
201       //
202       vtkSMProperty *SMProperty(this->proxy()->GetProperty("FieldsStatus"));
203       SMProperty->ResetToDefault();//this line is very important !
204       //
205       QString name0(QString::fromStdString((const char *)verticesNames2->GetValue(id1))); QList<QString> strs0; strs0.append(name0);
206       pqTreeWidgetItemObject *item0(new pqMyTreeWidgetItemObject(this->UI->Fields,strs0));
207       item0->setData(0,Qt::UserRole,name0);
208       item0->setData(0,Qt::ToolTipRole,toolTipName0);
209       //
210       QList<QVariant> modulesAct;
211       for(int i=0;i<nbTS.toInt();i++)
212         modulesAct.push_back(QVariant(true));
213       item0->setProperty("NbOfTS",nbTS);
214       item0->setProperty("DTS",QVariant(dts));
215       item0->setProperty("ITS",QVariant(its));
216       item0->setProperty("TTS",QVariant(tts));
217       item0->setProperty("ChosenTS",QVariant(modulesAct));
218       //
219       vtkAdjacentVertexIterator *it1(vtkAdjacentVertexIterator::New());//mesh
220       g2->GetAdjacentVertices(id1,it1);
221       while(it1->HasNext())
222         {
223           vtkIdType id2(it1->Next());
224           QString name1(QString::fromStdString((const char *)verticesNames2->GetValue(id2))); QList<QString> strs1; strs1.append(name1);
225           QString toolTipName1(name1);
226           pqTreeWidgetItemObject *item1(new pqMyTreeWidgetItemObject(item0,strs1));
227           item1->setData(0,Qt::UserRole,name1);
228           item1->setData(0,Qt::ToolTipRole,toolTipName1);
229           vtkAdjacentVertexIterator *it2(vtkAdjacentVertexIterator::New());//common support
230           g2->GetAdjacentVertices(id2,it2);
231           while(it2->HasNext())
232             {
233               vtkIdType id3(it2->Next());
234               QString name2(QString::fromStdString((const char *)verticesNames2->GetValue(id3))); QList<QString> strs2; strs2.append(name2);
235               pqTreeWidgetItemObject *item2(new pqTreeWidgetItemObject(item1,strs2));
236               item2->setData(0,Qt::UserRole,name2);
237               item2->setChecked(false);
238               vtkAdjacentVertexIterator *it3(vtkAdjacentVertexIterator::New());//fields !
239               g2->GetAdjacentVertices(id3,it3);
240               vtkIdType id3Arrs(it3->Next());
241               vtkAdjacentVertexIterator *it3Arrs(vtkAdjacentVertexIterator::New());//arrs in fields !
242               g2->GetAdjacentVertices(id3Arrs,it3Arrs);
243               while(it3Arrs->HasNext())
244                 {
245                   vtkIdType id4(it3Arrs->Next());
246                   std::string name3CppFull((const char *)verticesNames2->GetValue(id4));
247                   std::size_t pos(name3CppFull.find(ZE_SEP));
248                   std::string name3Only(name3CppFull.substr(0,pos)); std::string spatialDiscr(name3CppFull.substr(pos+sizeof(ZE_SEP)-1));
249                   QString name3(QString::fromStdString(name3Only)); QList<QString> strs3; strs3.append(name3);
250                   QString toolTipName3(name3+QString(" (")+spatialDiscr.c_str()+QString(")"));
251                   //
252                   vtkAdjacentVertexIterator *it4(vtkAdjacentVertexIterator::New());// is it a special field ? A field mesh ?
253                   g2->GetAdjacentVertices(id4,it4);
254                   bool isSpecial(it4->HasNext());
255                   it4->Delete();
256                   //
257                   pqTreeWidgetItemObject *item3(new pqTreeWidgetItemObject(item2,strs3));
258                   _all_lev4.push_back(item3);
259                   item3->setData(0,Qt::UserRole,name3);
260                   item3->setChecked(false);
261                   if(isSpecial)
262                     {
263                       QFont font; font.setItalic(true); font.setUnderline(true);
264                       item3->setData(0,Qt::FontRole,QVariant(font));
265                       item3->setData(0,Qt::ToolTipRole,QString("Whole \"%1\" mesh").arg(name3));
266                       item3->setData(0,Qt::DecorationRole,PixSingle::GetInstance().getWholeMeshPix());
267                     }
268                   else
269                     {
270                       item3->setData(0,Qt::ToolTipRole,toolTipName3);
271                       item3->setData(0,Qt::DecorationRole,PixSingle::GetInstance().getPixFromStr(spatialDiscr));
272                     }
273                   _leaves.insert(std::pair<pqTreeWidgetItemObject *,int>(item3,ll));
274                   std::ostringstream pdm; pdm << name0.toStdString() << "/" << name1.toStdString() << "/" << name2.toStdString() << "/" << name3CppFull;
275                   (static_cast<vtkSMStringVectorProperty *>(SMProperty))->SetElement(2*ll,pdm.str().c_str());
276                   char tmp2[2]; tmp2[0]=(kk==0?'1':'0'); tmp2[1]='\0';
277                   std::string tmp(tmp2);
278                   (static_cast<vtkSMStringVectorProperty *>(SMProperty))->SetElement(2*ll+1,tmp.c_str());
279                   //SMProperty->ResetToDefault();
280                   item2->setChecked(kk==0);
281                   item3->setChecked(kk==0);
282                   item3->setProperty("PosInStringVector",QVariant(ll));
283                   connect(item3,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev4HasBeenFired()));
284                   ll++;
285                 }
286                 connect(item2,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev3HasBeenFired(bool)));
287                 vtkIdType id3Gts(it3->Next());
288                 vtkAdjacentVertexIterator *it3Gts(vtkAdjacentVertexIterator::New());//geo types in fields !
289                 g2->GetAdjacentVertices(id3Gts,it3Gts);
290                 QString toolTipName2(name2);
291                 while(it3Gts->HasNext())
292                   {
293                     vtkIdType idGt(it3Gts->Next());
294                     std::string gtName((const char *)verticesNames2->GetValue(idGt));
295                     toolTipName2=QString("%1\n- %2").arg(toolTipName2).arg(QString(gtName.c_str()));
296                   }
297                 item2->setData(0,Qt::ToolTipRole,toolTipName2);
298                 it3Gts->Delete();
299                 it3->Delete();
300                 it3Arrs->Delete();
301                 kk++;
302               }
303             it2->Delete();
304           }
305         it1->Delete();
306       }
307   it0->Delete();
308   this->UI->Fields->header()->setStretchLastSection(true);
309   this->UI->Fields->expandAll();
310   info->Delete();
311   this->UI->stdMode->setChecked(true);
312   this->UI->VTKConnect->Connect(this->proxy(),vtkCommand::UpdateInformationEvent, this, SLOT(updateSIL()));
313   ///
314   this->UI->Reload->setProperty("NbOfReloadDynProp",QVariant(1));
315   vtkSMProperty *SMProperty(this->proxy()->GetProperty("ReloadReq"));
316   connect(this->UI->Reload,SIGNAL(pressed()),this,SLOT(reloadFired()));
317   this->propertyManager()->registerLink(this->UI->Reload,"NbOfReloadDynProp",SIGNAL(pressed()),this->proxy(),SMProperty);
318   ///
319   vtkSMProperty *SMProperty0(this->proxy()->GetProperty("GenerateVectors"));
320   this->propertyManager()->registerLink(this->UI->GenerateVects,"checked",SIGNAL(stateChanged(int)),this->proxy(),SMProperty0);
321   ///
322   vtkSMProperty *SMProperty2(this->proxy()->GetProperty("TimeOrModal"));
323   SMProperty2->ResetToDefault();//this line is very important !
324   this->propertyManager()->registerLink(this->UI->modeMode,"checked",SIGNAL(toggled(bool)),this->proxy(),SMProperty2);
325   ///
326   delete _optional_widget;
327   _optional_widget=new VectBoolWidget(this->UI->timeStepsInspector,getMaxNumberOfTS());
328   _optional_widget->hide();
329   this->UI->timeStepsInspector->setMinimumSize(QSize(0,0));
330   connect(this->UI->modeMode,SIGNAL(toggled(bool)),this,SLOT(vectOfBoolWidgetRequested(bool)));
331   vtkSMProperty *SMProperty3(this->proxy()->GetProperty("TimesFlagsStatus"));
332   SMProperty3->ResetToDefault();
333   const QVector<VectBoolItem *>& items(_optional_widget->getItems());
334   int itt(0);
335   foreach(VectBoolItem *item,items)
336     {
337       this->propertyManager()->registerLink(item,"activated",SIGNAL(changed()),this->proxy(),SMProperty3,itt++);
338     }
339 }
340
341 pqMEDReaderPanel::~pqMEDReaderPanel()
342 {
343   delete _optional_widget;
344 }
345
346 void pqMEDReaderPanel::linkServerManagerProperties()
347 {
348   this->Superclass::linkServerManagerProperties();
349 }
350
351 void pqMEDReaderPanel::updateSIL()
352 {
353   if(_reload_req)
354     {
355       _reload_req=false;
356       this->UI->geometryGroupBox->hide();
357       delete this->UI;
358       foreach(QObject *child,children())
359         {
360           QLayout *layout(qobject_cast<QLayout *>(child));
361           if(layout)
362             delete layout;
363         }
364       initAll();
365     }
366 }
367
368 void pqMEDReaderPanel::aLev3HasBeenFired(bool v)
369 {
370   pqTreeWidgetItemObject *zeItem(qobject_cast<pqTreeWidgetItemObject *>(sender()));
371   if(!zeItem)
372     return;
373   for(int i=0;i<zeItem->childCount();i++)
374     {
375       QTreeWidgetItem *elt(zeItem->child(i));
376       pqTreeWidgetItemObject *eltC(dynamic_cast<pqTreeWidgetItemObject *>(elt));
377       if(eltC)
378         {
379           eltC->setChecked(v);
380           aLev4HasBeenFiredBy(eltC);
381         }
382     }
383   putLev3InOrder();
384   somethingChangedInFieldRepr();
385 }
386
387 void pqMEDReaderPanel::aLev4HasBeenFired()
388 {
389   pqTreeWidgetItemObject *zeItem(qobject_cast<pqTreeWidgetItemObject *>(sender()));
390   if(zeItem)
391     aLev4HasBeenFiredBy(zeItem);
392   putLev3InOrder();
393   somethingChangedInFieldRepr();
394 }
395
396 void pqMEDReaderPanel::aLev4HasBeenFiredBy(pqTreeWidgetItemObject *zeItem)
397 {
398   pqTreeWidgetItemObject *father(dynamic_cast<pqTreeWidgetItemObject *>(zeItem->QTreeWidgetItem::parent()));
399   QTreeWidgetItem *godFather(father->QTreeWidgetItem::parent()->parent());
400   if(!father)
401     return ;
402   if(zeItem->isChecked())
403     {
404       bool isActivatedTSChanged(false);
405       // This part garantees that all leaves having not the same father than zeItem are desactivated
406       foreach(pqTreeWidgetItemObject* elt,this->_all_lev4)
407       {
408         QTreeWidgetItem *testFath(elt->QTreeWidgetItem::parent());
409         if(testFath!=father)
410           if(elt->isChecked())
411             {
412               {
413                 disconnect(elt,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev4HasBeenFired()));
414                 elt->setChecked(false);
415                 connect(elt,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev4HasBeenFired()));
416               }
417               if(godFather!=testFath->parent()->parent())
418                 isActivatedTSChanged=true;
419             }
420       }
421       // the user by clicking to a new entry has changed of TimeStepSeries -> notify it to thee time step selector widget
422       if(isActivatedTSChanged)
423         {
424           QStringList its,dts,tts;
425           getCurrentTS(its,dts,tts);
426           _optional_widget->setItems(its,dts,tts);
427         }
428     }
429   else
430     {
431       // if all are unchecked - check it again
432       bool allItemsAreUnChked(true);
433       foreach(pqTreeWidgetItemObject* elt,this->_all_lev4)
434         {
435           if(elt && elt->isChecked())
436             allItemsAreUnChked=false;
437         }
438       if(allItemsAreUnChked)
439         {
440           disconnect(zeItem,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev4HasBeenFired()));
441           zeItem->setChecked(true);// OK zeItem was required to be unchecked but as it is the last one. Recheck it !
442           connect(zeItem,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev4HasBeenFired()));
443         }
444     }
445 }
446
447 void pqMEDReaderPanel::putLev3InOrder()
448 {
449   std::vector<pqTreeWidgetItemObject *>::iterator it0(_all_lev4.begin()),it1;
450   while(it0!=_all_lev4.end())
451     {
452       QTreeWidgetItem *curFather((*it0)->QTreeWidgetItem::parent());
453       for(it1=it0+1;it1!=_all_lev4.end() && (*it1)->QTreeWidgetItem::parent()==curFather;it1++);
454       bool isAllFalse(true),isAllTrue(true);
455       for(std::vector<pqTreeWidgetItemObject *>::iterator it=it0;it!=it1;it++)
456         {
457           if((*it)->isChecked())
458             isAllFalse=false;
459           else
460             isAllTrue=false;
461         }
462       if(isAllFalse || isAllTrue)
463         {
464           pqTreeWidgetItemObject *father(dynamic_cast<pqTreeWidgetItemObject *>(curFather));
465           if(father)
466             {
467               disconnect(father,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev3HasBeenFired(bool)));
468               father->setChecked(isAllTrue);
469               connect(father,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev3HasBeenFired(bool)));
470             }
471         }
472       it0=it1;
473     }
474 }
475
476 void pqMEDReaderPanel::reloadFired()
477 {
478   static int iii(1);
479   QVariant v(iii++);
480   this->UI->Reload->setProperty("NbOfReloadDynProp",v);
481   _reload_req=true;
482   for(std::set<std::pair<pqTreeWidgetItemObject *,int> >::const_iterator it=_leaves.begin();it!=_leaves.end();it++)
483     ((*it).first)->disconnect(SIGNAL(checkedStateChanged(bool)));
484   //
485   vtkSMProperty *SMProperty(this->proxy()->GetProperty("FieldsStatus"));
486   for(std::set<std::pair<pqTreeWidgetItemObject *,int> >::const_iterator it=_leaves.begin();it!=_leaves.end();it++)
487     this->propertyManager()->unregisterLink((*it).first,"checked",SIGNAL(checkedStateChanged(bool)),this->proxy(),SMProperty,(*it).second);
488   this->propertyManager()->propertyChanged();
489   vtkSMProperty *SMProperty3(this->proxy()->GetProperty("TimeOrModal"));
490   this->propertyManager()->unregisterLink(this->UI->modeMode,"checked",SIGNAL(toggled(bool)),this->proxy(),SMProperty3);
491 }
492
493 void pqMEDReaderPanel::vectOfBoolWidgetRequested(bool isMode)
494 {
495   if(isMode)
496     {
497       this->UI->timeStepsInspector->setMinimumSize(QSize(200,250));
498       _optional_widget->show();
499       QStringList its,dts,tts;
500       getCurrentTS(its,dts,tts);
501       _optional_widget->setItems(its,dts,tts);
502     }
503   else
504     {
505       _optional_widget->hide();
506       this->UI->timeStepsInspector->setMinimumSize(QSize(0,0));
507     }
508 }
509
510 void pqMEDReaderPanel::getCurrentTS(QStringList& its, QStringList& dts, QStringList& tts) const
511 {
512   
513   for(std::vector<pqTreeWidgetItemObject *>::const_iterator it=_all_lev4.begin();it!=_all_lev4.end();it++)
514     {
515       if((*it)->property("checked").toInt())
516         {
517           QTreeWidgetItem *obj((*it)->QTreeWidgetItem::parent()->QTreeWidgetItem::parent()->QTreeWidgetItem::parent());
518           pqTreeWidgetItemObject *objC(dynamic_cast<pqTreeWidgetItemObject *>(obj));
519           its=objC->property("ITS").toStringList();
520           dts=objC->property("DTS").toStringList();
521           tts=objC->property("TTS").toStringList();
522           return;
523         }
524     }
525   std::cerr << "pqMEDReaderPanel::getCurrentTS : internal error ! Something is going wrong !" << std::endl;
526 }
527
528 int pqMEDReaderPanel::getMaxNumberOfTS() const
529 {
530   int ret(0);
531   for(std::vector<pqTreeWidgetItemObject *>::const_iterator it=_all_lev4.begin();it!=_all_lev4.end();it++)
532     {
533       QTreeWidgetItem *obj((*it)->QTreeWidgetItem::parent()->QTreeWidgetItem::parent()->QTreeWidgetItem::parent());
534       pqTreeWidgetItemObject *objC(dynamic_cast<pqTreeWidgetItemObject *>(obj));
535       ret=std::max(ret,objC->property("NbOfTS").toInt());
536     }
537   return ret;
538 }
539
540 void pqMEDReaderPanel::updateInformationAndDomains()
541 {
542   pqNamedObjectPanel::updateInformationAndDomains();
543   if(_is_fields_status_changed)
544     {
545       vtkSMProxy *proxy(this->proxy());
546       vtkSMProperty *SMProperty(proxy->GetProperty("FieldsStatus"));
547       SMProperty->Modified();// agy : THE LINE FOR 7.5.1 !
548       _is_fields_status_changed=false;
549     }
550 }
551
552 /*!
553  * This slot is called by this->UI->Fields when one/several leaves have been modified.
554  */
555 void pqMEDReaderPanel::somethingChangedInFieldRepr()
556 {
557   ///
558   vtkSMProxy *proxy(this->proxy());
559   vtkSMProperty *SMProperty(proxy->GetProperty("FieldsStatus"));
560   vtkSMStringVectorProperty *sm(dynamic_cast<vtkSMStringVectorProperty *>(SMProperty));
561   unsigned int nb(sm->GetNumberOfElements());
562   std::vector<std::string> sts(nb);
563   for(unsigned int i=0;i<nb;i++)
564     sts[i]=sm->GetElement(i);
565   ///
566   pqExodusIIVariableSelectionWidget *sc(this->UI->Fields);
567   for(int i0=0;i0<sc->topLevelItemCount();i0++)
568     {
569       QTreeWidgetItem *lev0(sc->topLevelItem(i0));//TS
570       for(int i1=0;i1<lev0->childCount();i1++)
571         {
572           QTreeWidgetItem *lev1(lev0->child(i1));//Mesh
573           for(int i2=0;i2<lev1->childCount();i2++)
574             {
575               QTreeWidgetItem *lev2(lev1->child(i2));//Comp
576               for(int i3=0;i3<lev2->childCount();i3++)
577                 {
578                   QTreeWidgetItem *lev3(lev2->child(i3));
579                   pqTreeWidgetItemObject *scc(dynamic_cast<pqTreeWidgetItemObject *>(lev3));
580                   int ll(scc->property("PosInStringVector").toInt());
581                   int v(scc->isChecked());
582                   std::ostringstream oss; oss << v;
583                   sts[2*ll+1]=oss.str();
584                 }
585             }
586         }
587     }
588   ///
589   const char **args=new const char *[nb];
590   for(unsigned int i=0;i<nb;i++)
591     {
592       args[i]=sts[i].c_str();
593     }
594   {//agy : let's go to put info in property FieldsStatus
595     int iup(sm->GetImmediateUpdate());
596     //sm->SetNumberOfElements(0);
597     sm->SetElements(args,nb);
598     proxy->UpdateVTKObjects(); // push properties states abroad
599     sm->SetImmediateUpdate(iup);
600   }
601   delete [] args;
602   //
603   ((vtkSMSourceProxy *)proxy)->UpdatePipelineInformation();//performs an update of all properties of proxy and proxy itself
604   // here wonderful proxy is declared modified right after FieldsStatus and FieldsTreeInfo -> IMPORTANT : The updated MTime of proxy will be the ref
605   // to detect modified properties.
606   _is_fields_status_changed=true;
607   setModified();
608 }
609