Back to index

salome-paravis  6.5.0
pqMedReaderPanel.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "pqMedReaderPanel.h"
00021 #include "ui_MedReaderPanel.h"
00022 
00023 #include "vtkProcessModule.h"
00024 #include "vtkMultiBlockDataSet.h"
00025 #include "vtkInformation.h"
00026 #include "vtkIntArray.h"
00027 #include "vtkSMDoubleVectorProperty.h"
00028 #include "vtkSMIntVectorProperty.h"
00029 #include "vtkSMStringVectorProperty.h"
00030 #include "vtkSMProxy.h"
00031 #include "vtkEventQtSlotConnect.h"
00032 #include "vtkPVSILInformation.h"
00033 #include "vtkGraph.h"
00034 #include "vtkSMPropertyHelper.h"
00035 #include "vtkStringArray.h"
00036 #include "vtkDataSetAttributes.h"
00037 #include "vtkMedReader.h"
00038 
00039 #include "vtkMedUtilities.h"
00040 
00041 #include "pqTreeWidgetItemObject.h"
00042 #include "pqSMAdaptor.h"
00043 #include "pqProxy.h"
00044 #include "pqPropertyManager.h"
00045 #include "pqSILModel.h"
00046 #include "pqProxySILModel.h"
00047 #include "pqTreeViewSelectionHelper.h"
00048 #include "pqTreeWidgetSelectionHelper.h"
00049 #include "pqPropertyLinks.h"
00050 
00051 #include <QHeaderView>
00052 
00053 class pqMedReaderPanel::pqUI: public QObject, public Ui::MedReaderPanel
00054 {
00055 public:
00056   pqUI(pqMedReaderPanel* p) :
00057     QObject(p)
00058   {
00059     this->VTKConnect = vtkSmartPointer<vtkEventQtSlotConnect>::New();
00060     this->SILUpdateStamp = -1;
00061   }
00062 
00063   ~pqUI()
00064   {
00065   }
00066 
00067   pqSILModel SILModel;
00068   vtkSmartPointer<vtkEventQtSlotConnect> VTKConnect;
00069   pqPropertyLinks Links;
00070   QMap<QTreeWidgetItem*, QString> TreeItemToPropMap;
00071   pqProxySILModel* entityModel;
00072   pqProxySILModel* groupModel;
00073   int SILUpdateStamp;
00074 };
00075 
00076 pqMedReaderPanel::pqMedReaderPanel(pqProxy* object_proxy, QWidget* p) :
00077   Superclass(object_proxy, p)
00078 {
00079   this->UI = new pqUI(this);
00080   this->UI->setupUi(this);
00081 
00082   pqProxySILModel* proxyModel;
00083 
00084   // connect groups to groupsRoot
00085   proxyModel = new pqProxySILModel("GroupTree", &this->UI->SILModel);
00086   proxyModel->setSourceModel(&this->UI->SILModel);
00087   this->UI->Groups->setModel(proxyModel);
00088   this->UI->Groups->setHeaderHidden(true);
00089 
00090   this->UI->groupModel = new pqProxySILModel("Groups", &this->UI->SILModel);
00091   this->UI->groupModel->setSourceModel(&this->UI->SILModel);
00092 
00093   // connect cell types to "EntityRoot"
00094   proxyModel = new pqProxySILModel("EntityTree", &this->UI->SILModel);
00095   proxyModel->setSourceModel(&this->UI->SILModel);
00096   this->UI->Entity->setModel(proxyModel);
00097   this->UI->Entity->setHeaderHidden(true);
00098 
00099   this->UI->entityModel = new pqProxySILModel("Entity", &this->UI->SILModel);
00100   this->UI->entityModel->setSourceModel(&this->UI->SILModel);
00101 
00102   this->updateSIL();
00103 
00104   this->UI->Groups->header()->setStretchLastSection(true);
00105   this->UI->Entity->header()->setStretchLastSection(true);
00106 
00107   this->linkServerManagerProperties();
00108 
00109   QList<pqTreeWidget*> treeWidgets = this->findChildren<pqTreeWidget*> ();
00110   foreach (pqTreeWidget* tree, treeWidgets)
00111       {
00112       new pqTreeWidgetSelectionHelper(tree);
00113       }
00114 
00115   QList<pqTreeView*> treeViews = this->findChildren<pqTreeView*> ();
00116   foreach (pqTreeView* tree, treeViews)
00117       {
00118       new pqTreeViewSelectionHelper(tree);
00119       }
00120 
00121   this->connect(this->UI->groupModel, SIGNAL(valuesChanged()),
00122                 this, SLOT(setModified()));
00123   this->connect(this->UI->entityModel, SIGNAL(valuesChanged()),
00124                 this, SLOT(setModified()));
00125   this->connect(this->UI->TimeCombo, SIGNAL(currentIndexChanged(int)),
00126                 this, SLOT(setModified()));
00127   this->connect(this->UI->GenerateVectors, SIGNAL(stateChanged(int)),
00128                 this, SLOT(setModified()));
00129 
00130   this->UI->tabWidget->setCurrentIndex(0);
00131 
00132   this->UI->VTKConnect->Connect(this->proxy(),
00133       vtkCommand::UpdateInformationEvent, this, SLOT(updateSIL()));
00134 }
00135 
00136 pqMedReaderPanel::~pqMedReaderPanel()
00137 {
00138 }
00139 
00140 void pqMedReaderPanel::addSelectionsToTreeWidget(const QString& prop,
00141     QTreeWidget* tree, PixmapType pix)
00142 {
00143   vtkSMProperty* SMProperty = this->proxy()->GetProperty(prop.toAscii().data());
00144   QList<QVariant> SMPropertyDomain;
00145   SMPropertyDomain = pqSMAdaptor::getSelectionPropertyDomain(SMProperty);
00146   int j;
00147   for(j = 0; j < SMPropertyDomain.size(); j++)
00148     {
00149     QString varName = SMPropertyDomain[j].toString();
00150     this->addSelectionToTreeWidget(varName, varName, tree, pix, prop, j);
00151     }
00152 }
00153 
00154 void pqMedReaderPanel::addSelectionToTreeWidget(const QString& name,
00155     const QString& realName, QTreeWidget* tree, PixmapType pix,
00156     const QString& prop, int propIdx)
00157 {
00158   static QPixmap pixmaps[] = {
00159     QPixmap(":/ParaViewResources/Icons/pqPointData16.png"),
00160     QPixmap(":/ParaViewResources/Icons/pqCellData16.png"),
00161     QPixmap(":/ParaViewResources/Icons/pqQuadratureData16.png"),
00162     QPixmap(":/ParaViewResources/Icons/pqElnoData16.png") };
00163 
00164   vtkSMProperty* SMProperty = this->proxy()->GetProperty(prop.toAscii().data());
00165 
00166   if(!SMProperty || !tree)
00167     {
00168     return;
00169     }
00170 
00171   QList<QString> strs;
00172   strs.append(name);
00173   pqTreeWidgetItemObject* item;
00174   item = new pqTreeWidgetItemObject(tree, strs);
00175   item->setData(0, Qt::ToolTipRole, name);
00176   if(pix >= 0)
00177     {
00178     item->setData(0, Qt::DecorationRole, pixmaps[pix]);
00179     }
00180   item->setData(0, Qt::UserRole, QString("%1 %2").arg((int) pix).arg(realName));
00181   this->propertyManager()->registerLink(item, "checked",
00182       SIGNAL(checkedStateChanged(bool)), this->proxy(), SMProperty, propIdx);
00183 
00184   this->UI->TreeItemToPropMap[item] = prop;
00185 }
00186 
00187 void pqMedReaderPanel::linkServerManagerProperties()
00188 {
00189   this->UI->Links.addPropertyLink(this->UI->groupModel, "values",
00190       SIGNAL(valuesChanged()), this->proxy(), this->proxy()->GetProperty(
00191           "Groups"));
00192 
00193   this->UI->Links.addPropertyLink(this->UI->entityModel, "values",
00194       SIGNAL(valuesChanged()), this->proxy(), this->proxy()->GetProperty(
00195           "Entity"));
00196 
00197   this->UI->Links.addPropertyLink(this->UI->GenerateVectors, "checked",
00198       SIGNAL(toggled(bool)), this->proxy(), this->proxy()->GetProperty(
00199           "GenerateVectors"));
00200 
00201   this->Superclass::linkServerManagerProperties();
00202 
00203   // do the point variables
00204   this->addSelectionsToTreeWidget("PointFieldsArrayStatus",
00205       this->UI->Variables, PM_POINT);
00206   // do the cell variables
00207   this->addSelectionsToTreeWidget("CellFieldsArrayStatus", this->UI->Variables,
00208       PM_CELL);
00209   // do the quadrature variables
00210   this->addSelectionsToTreeWidget("QuadratureFieldsArrayStatus",
00211       this->UI->Variables, PM_QUADRATURE);
00212 
00213   // do the Elno variables
00214   this->addSelectionsToTreeWidget("ElnoFieldsArrayStatus",
00215       this->UI->Variables, PM_ELNO);
00216   this->setupAnimationModeWidget();
00217 }
00218 
00219 void pqMedReaderPanel::setupAnimationModeWidget()
00220 {
00221   this->UI->AnimationModeCombo->clear();
00222   QList<QVariant> modes = pqSMAdaptor::getEnumerationPropertyDomain(
00223       this->proxy()->GetProperty("AnimationMode"));
00224   for(int mode = 0; mode < modes.size(); mode++)
00225     {
00226     QString modeName = modes[mode].toString();
00227     this->UI->AnimationModeCombo->addItem(modeName);
00228     }
00229 
00230   this->UI->Links.addPropertyLink(this->UI->AnimationModeCombo, "currentIndex",
00231       SIGNAL(currentIndexChanged(int)), this->proxy(),
00232       this->proxy()->GetProperty("AnimationMode"));
00233 
00234   this->connect(this->UI->AnimationModeCombo,
00235       SIGNAL(currentIndexChanged(int)), this, SLOT(animationModeChanged(int)));
00236 
00237   this->UI->Links.addPropertyLink(this->UI->TimeCombo, "currentIndex",
00238       SIGNAL(currentIndexChanged(int)), this->proxy(),
00239       this->proxy()->GetProperty("TimeIndexForIterations"));
00240 
00241   this->addSelectionsToTreeWidget("FrequencyArrayStatus",
00242       this->UI->Modes, PM_NONE);
00243 
00244   vtkSMPropertyHelper helper(this->proxy(), "AnimationMode");
00245   int mode = helper.GetAsInt(0);
00246   this->animationModeChanged(mode);
00247   this->updateAvailableTimes();
00248 }
00249 
00250 void pqMedReaderPanel::animationModeChanged(int mode)
00251 {
00252   if(mode == vtkMedReader::Default || mode == vtkMedReader::PhysicalTime)
00253     {
00254     this->UI->TimeCombo->hide();
00255     this->UI->TimeLabel->hide();
00256     this->UI->Modes->hide();
00257     }
00258   else if(mode == vtkMedReader::Iteration)
00259     {
00260     this->UI->TimeCombo->show();
00261     this->UI->TimeLabel->show();
00262     this->UI->Modes->hide();
00263     }
00264   else // vtkMedReader::Modes
00265     {
00266     this->UI->TimeCombo->hide();
00267     this->UI->TimeLabel->hide();
00268     this->UI->Modes->show();
00269     }
00270   vtkSMPropertyHelper(this->proxy(), "AnimationMode").Set(mode);
00271   this->proxy()->UpdateVTKObjects();
00272   this->setModified();
00273 }
00274 
00275 void pqMedReaderPanel::updateAvailableTimes()
00276 {
00277   vtkSMDoubleVectorProperty* prop = vtkSMDoubleVectorProperty::SafeDownCast(
00278       this->proxy()->GetProperty("AvailableTimes"));
00279 
00280   this->proxy()->UpdatePropertyInformation(prop);
00281 
00282   //prop->GetInformationHelper()->UpdateProperty(
00283   //    vtkProcessModuleConnectionManager::GetRootServerConnectionID(),
00284   //    vtkProcessModule::DATA_SERVER,
00285   //    this->proxy()->GetID(),
00286   //    prop);
00287 
00288   this->UI->TimeCombo->clear();
00289   double *aux = prop->GetElements();
00290 
00291   for(int tid = 0; tid < prop->GetNumberOfElements(); tid++)
00292     {
00293     this->UI->TimeCombo->addItem( QString::number(aux[tid]) );
00294     }
00295 
00296 }
00297 
00298 void pqMedReaderPanel::updateSIL()
00299 {
00300   vtkSMProxy* reader = this->referenceProxy()->getProxy();
00301   reader->UpdatePropertyInformation(reader->GetProperty("SILUpdateStamp"));
00302 
00303   int stamp = vtkSMPropertyHelper(reader, "SILUpdateStamp").GetAsInt();
00304   if (stamp != this->UI->SILUpdateStamp)
00305     {
00306     this->UI->SILUpdateStamp = stamp;
00307     vtkPVSILInformation* info = vtkPVSILInformation::New();
00308     reader->GatherInformation(info);
00309     this->UI->SILModel.update(info->GetSIL());
00310 
00311     this->UI->Groups->expandAll();
00312     this->UI->Entity->expandAll();
00313 
00314     info->Delete();
00315     }
00316 
00317   /*
00318   this->proxy()->UpdatePropertyInformation(
00319       this->proxy()->GetProperty("SILUpdateStamp"));
00320 
00321   int stamp = vtkSMPropertyHelper(this->proxy(), "SILUpdateStamp").GetAsInt();
00322   if(stamp != this->UI->SILUpdateStamp)
00323     {
00324     this->UI->SILUpdateStamp = stamp;
00325 
00326     vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
00327     vtkPVSILInformation* info = vtkPVSILInformation::New();
00328     pm->GatherInformation(this->proxy()->GetConnectionID(),
00329         vtkProcessModule::DATA_SERVER, info, this->proxy()->GetID());
00330 
00331     this->UI->SILModel.update(info->GetSIL());
00332 
00333     this->UI->Groups->expandAll();
00334     this->UI->Entity->expandAll();
00335 
00336     info->Delete();
00337     }*/
00338 }