]> SALOME platform Git repositories - modules/paravis.git/commitdiff
Salome HOME
0023021: [CEA 1440] Setting the field to display in python with reader.AllArrays...
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 14 Apr 2015 14:04:08 +0000 (16:04 +0200)
committervsr <vsr@opencascade.com>
Thu, 16 Apr 2015 09:57:26 +0000 (12:57 +0300)
src/Plugins/MEDReader/IO/vtkMEDReader.cxx
src/Plugins/MEDReader/IO/vtkMEDReader.h
src/Plugins/MEDReader/ParaViewPlugin/Resources/MEDReaderServer.xml
src/Plugins/MEDReader/ParaViewPlugin/pqMEDReaderPanel.cxx
src/Plugins/MEDReader/ParaViewPlugin/pqMEDReaderPanel.h

index 338c961c601d04199a3d10fad82a9cf97dabcb65..0dca27f6632c39e7400d36212368977d7251a12b 100644 (file)
@@ -150,7 +150,7 @@ class vtkMEDReader::vtkMEDReaderInternal
 {
 
 public:
-  vtkMEDReaderInternal(vtkMEDReader *master):TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2),PK(master)
+  vtkMEDReaderInternal(vtkMEDReader *master):TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2),PK(master),MyMTime(0)
   {
   }
   
@@ -184,6 +184,8 @@ public:
   int LastLev0;
   // The property keeper is usable only in pvsm mode.
   PropertyKeeper PK;
+  int MyMTime;
+  std::set<std::string> _wonderful_set;// this set is used by SetFieldsStatus method to detect the fact that SetFieldsStatus has been called for all items ! Great !
 private:
   unsigned char FirstCall0;
 };
@@ -212,6 +214,11 @@ void vtkMEDReader::Reload(int a)
   this->SetFileName(fName.c_str());
 }
 
+int vtkMEDReader::GetServerModifTime()
+{
+  return this->Internal->MyMTime;
+}
+
 void vtkMEDReader::GenerateVectors(int val)
 {
   if(this->Internal->FileName.empty())
@@ -353,19 +360,26 @@ int vtkMEDReader::RequestData(vtkInformation *request, vtkInformationVector **in
 
 void vtkMEDReader::SetFieldsStatus(const char* name, int status)
 {
-  //std::cerr << "vtkMEDReader::SetFieldsStatus(" << name << "," << status << ") called !" << std::endl;
+  //this->Internal->_wonderful_set.insert(name);
   if(this->Internal->FileName.empty())
     {//pvsm mode
       this->Internal->PK.pushFieldStatusEntry(name,status);
       return ;
     }
+  this->Internal->_wonderful_set.insert(name);
   //not pvsm mode (general case)
   try
     {
       this->Internal->Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(this->Internal->Tree.getIdHavingZeName(name),status);
-      if(std::string(name)==GetFieldsTreeArrayName(GetNumberOfFieldsTreeArrays()-1))
-        if(!this->Internal->PluginStart0())
-          this->Modified();
+      if(this->Internal->_wonderful_set.size()==GetNumberOfFieldsTreeArrays())
+        {
+          if(!this->Internal->PluginStart0())
+            {
+              this->Modified();
+            }
+          this->Internal->MyMTime++;
+          this->Internal->_wonderful_set.clear();
+        }
     }
   catch(INTERP_KERNEL::Exception& e)
     {
@@ -381,9 +395,8 @@ int vtkMEDReader::GetNumberOfFieldsTreeArrays()
 {
   if(!this->Internal)
     return 0;
-  int ret(this->Internal->Tree.getNumberOfLeavesArrays());
+  return this->Internal->Tree.getNumberOfLeavesArrays();
   //std::cerr << "vtkMEDReader::GetNumberOfFieldsTreeArrays called ! " << ret << std::endl;
-  return ret;
 }
 
 const char *vtkMEDReader::GetFieldsTreeArrayName(int index)
index 3effd17ab1c4d7337ec606ee4314e162fc83e61b..8412f3a2e7847b0e922565b3209c0e6f8882c5d6 100644 (file)
@@ -53,6 +53,8 @@ class VTK_EXPORT vtkMEDReader : public vtkMultiBlockDataSetAlgorithm
   //! Build the graph used to pass information to the client on the supports
   virtual std::string BuildSIL(vtkMutableDirectedGraph*);
   virtual void Reload(int);
+  virtual int GetServerModifTime();
+  //
   virtual void GenerateVectors(int);
   virtual void ChangeMode(int);
   virtual const char *GetSeparator();
index 64b3169f29b4aedfa6abee0bf9527826f6e280d2..cf89105d40eb69d57e2851ed3757814d4423f9ca 100644 (file)
         <SimpleIntInformationHelper />
       </IntVectorProperty>
 
+      <IntVectorProperty command="GetServerModifTime" information_only="1" name="ServerModifTime">
+        <SimpleIntInformationHelper />
+      </IntVectorProperty>
+
       <IntVectorProperty
         name="GenerateVectors"
         command="GenerateVectors"
index d3d844b9987815b2cde8f2f945628f6230833d24..a7a357130ab43a26d410194ed5d2ec0314257ed9 100644 (file)
@@ -121,7 +121,7 @@ public:
   QMap<QTreeWidgetItem*, QString> TreeItemToPropMap;
 };
 
-pqMEDReaderPanel::pqMEDReaderPanel(pqProxy *object_proxy, QWidget *p):Superclass(object_proxy,p),_reload_req(false),_is_fields_status_changed(false),_optional_widget(0)
+pqMEDReaderPanel::pqMEDReaderPanel(pqProxy *object_proxy, QWidget *p):Superclass(object_proxy,p),_reload_req(false),_is_fields_status_changed(false),_optional_widget(0),_my_mtime(0),_sm_prop_remote_mtime(0)
 {
   initAll();
 }
@@ -149,7 +149,11 @@ void pqMEDReaderPanel::initAll()
   this->UI->setupUi(this);
   this->UI->Fields->setHeaderHidden(true);
   this->updateSIL();
-  ////////////////////
+  //
+  _sm_prop_remote_mtime=dynamic_cast<vtkSMIntVectorProperty *>(this->proxy()->GetProperty("ServerModifTime"));
+  if(_sm_prop_remote_mtime)
+    _sm_prop_remote_mtime->SetImmediateUpdate(1);
+  //
   vtkSMProxy *reader(this->referenceProxy()->getProxy());
   vtkPVSILInformation *info(vtkPVSILInformation::New());
   reader->GatherInformation(info);
@@ -200,6 +204,7 @@ void pqMEDReaderPanel::initAll()
       vtkIdType id1(it0->Next());
       //
       vtkSMProperty *SMProperty(this->proxy()->GetProperty("FieldsStatus"));
+      vtkSMProperty *SMPropertyRead(this->proxy()->GetProperty("FieldsTreeInfo"));
       SMProperty->ResetToDefault();//this line is very important !
       //
       QString name0(QString::fromStdString((const char *)verticesNames2->GetValue(id1))); QList<QString> strs0; strs0.append(name0);
@@ -257,7 +262,6 @@ void pqMEDReaderPanel::initAll()
                   pqTreeWidgetItemObject *item3(new pqTreeWidgetItemObject(item2,strs3));
                   _all_lev4.push_back(item3);
                   item3->setData(0,Qt::UserRole,name3);
-                  item3->setChecked(false);
                   if(isSpecial)
                     {
                       QFont font; font.setItalic(true);        font.setUnderline(true);
@@ -273,15 +277,10 @@ void pqMEDReaderPanel::initAll()
                   _leaves.insert(std::pair<pqTreeWidgetItemObject *,int>(item3,ll));
                   std::ostringstream pdm; pdm << name0.toStdString() << "/" << name1.toStdString() << "/" << name2.toStdString() << "/" << name3CppFull;
                   (static_cast<vtkSMStringVectorProperty *>(SMProperty))->SetElement(2*ll,pdm.str().c_str());
-                  ////char tmp2[2]; tmp2[0]=(kk==0?'1':'0'); tmp2[1]='\0';
-                  ////std::string tmp(tmp2);
-                  ////(static_cast<vtkSMStringVectorProperty *>(SMProperty))->SetElement(2*ll+1,tmp.c_str());
-                  //SMProperty->ResetToDefault();
-                  const char *tmp((static_cast<vtkSMStringVectorProperty *>(SMProperty))->GetElement(2*ll+1));
-                  ////item2->setChecked(kk==0);
-                  ////item3->setChecked(kk==0);
+                  const char *tmp((static_cast<vtkSMStringVectorProperty *>(SMPropertyRead))->GetElement(2*ll+1));
                   item3->setChecked(tmp[0]=='1');
                   item3->setProperty("PosInStringVector",QVariant(ll));
+                  item3->setProperty("ZeKey",QVariant(QString(pdm.str().c_str())));
                   connect(item3,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev4HasBeenFired()));
                   ll++;
                 }
@@ -350,6 +349,21 @@ void pqMEDReaderPanel::linkServerManagerProperties()
   this->Superclass::linkServerManagerProperties();
 }
 
+void pqMEDReaderPanel::paintEvent(QPaintEvent *event)
+{
+  if(_sm_prop_remote_mtime)
+    {
+      int remoteMTimeVal(_sm_prop_remote_mtime->GetElement(0));
+      if(remoteMTimeVal>_my_mtime)
+        {
+          //std::cout << "Refresh MEDReader panel due to external update." << std::endl;
+          updateCheckStatusOfLev4FromServerState();
+          _my_mtime=remoteMTimeVal;
+        }
+    }
+  pqNamedObjectPanel::paintEvent(event);
+}
+
 void pqMEDReaderPanel::updateSIL()
 {
   if(_reload_req)
@@ -509,6 +523,37 @@ void pqMEDReaderPanel::vectOfBoolWidgetRequested(bool isMode)
     }
 }
 
+void pqMEDReaderPanel::updateCheckStatusOfLev4FromServerState()
+{
+  this->proxy()->UpdatePropertyInformation();
+  vtkSMStringVectorProperty *SMProperty(static_cast<vtkSMStringVectorProperty *>(this->proxy()->GetProperty("FieldsTreeInfo")));
+  for(std::vector<pqTreeWidgetItemObject *>::const_iterator it=_all_lev4.begin();it!=_all_lev4.end();it++)
+    {
+      pqTreeWidgetItemObject *elt(*it);
+      if(!elt)
+        continue;
+      QVariant v(elt->property("PosInStringVector"));
+      if(v.isNull())
+        continue;
+      bool isOK;
+      int pos(v.toInt(&isOK));
+      if(!isOK)
+        continue;
+      const char *tmp(SMProperty->GetElement(2*pos+1));
+      bool posCheckTarget(tmp[0]=='1'),actualPos(elt->isChecked());
+      if(actualPos!=posCheckTarget)
+        {
+          QTreeWidgetItem *curFather(elt->QTreeWidgetItem::parent());
+          pqTreeWidgetItemObject *father(dynamic_cast<pqTreeWidgetItemObject *>(curFather));
+          disconnect(father,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev3HasBeenFired(bool)));
+          disconnect(elt,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev4HasBeenFired()));
+          elt->setChecked(posCheckTarget);
+          connect(elt,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev4HasBeenFired()));
+          connect(father,SIGNAL(checkedStateChanged(bool)),this,SLOT(aLev3HasBeenFired(bool)));
+        }
+    }
+}
+
 void pqMEDReaderPanel::getCurrentTS(QStringList& its, QStringList& dts, QStringList& tts) const
 {
   
@@ -562,8 +607,6 @@ void pqMEDReaderPanel::somethingChangedInFieldRepr()
   vtkSMStringVectorProperty *sm(dynamic_cast<vtkSMStringVectorProperty *>(SMProperty));
   unsigned int nb(sm->GetNumberOfElements());
   std::vector<std::string> sts(nb);
-  for(unsigned int i=0;i<nb;i++)
-    sts[i]=sm->GetElement(i);
   ///
   pqExodusIIVariableSelectionWidget *sc(this->UI->Fields);
   for(int i0=0;i0<sc->topLevelItemCount();i0++)
@@ -582,12 +625,13 @@ void pqMEDReaderPanel::somethingChangedInFieldRepr()
                   int ll(scc->property("PosInStringVector").toInt());
                   int v(scc->isChecked());
                   std::ostringstream oss; oss << v;
+                  sts[2*ll]=scc->property("ZeKey").toString().toStdString();
                   sts[2*ll+1]=oss.str();
                 }
             }
         }
     }
-  ///
+  //
   const char **args=new const char *[nb];
   for(unsigned int i=0;i<nb;i++)
     {
index 9a4a331feaee095893b56878d809b5486b1e1079..3d8792decd41a2a4b96c5ed6026126d2da65430d 100644 (file)
@@ -29,6 +29,7 @@ class pqTreeWidgetItemObject;
 class VectBoolWidget;
 
 class vtkSMProperty;
+class vtkSMIntVectorProperty;
 
 class pqMEDReaderPanel: public pqNamedObjectPanel
 {
@@ -46,6 +47,7 @@ protected slots:
   void updateSIL();
   void reloadFired();
   void vectOfBoolWidgetRequested(bool isMode);
+  void updateCheckStatusOfLev4FromServerState();
 private:
   int getMaxNumberOfTS() const;
   void getCurrentTS(QStringList& its, QStringList& dts, QStringList& tts) const;
@@ -54,6 +56,7 @@ protected:
   void somethingChangedInFieldRepr();
   /// populate widgets with properties from the server manager
   virtual void linkServerManagerProperties();
+  virtual void paintEvent(QPaintEvent *event);
   void initAll();
   class pqUI;
   pqUI* UI;
@@ -63,6 +66,8 @@ private:
   bool _is_fields_status_changed;
   std::set<std::pair<pqTreeWidgetItemObject *,int> > _leaves;
   VectBoolWidget *_optional_widget;
+  int _my_mtime;
+  vtkSMIntVectorProperty *_sm_prop_remote_mtime;
 };
 
 #endif