Salome HOME
Merge branch 'abn/port_pv42'
[modules/paravis.git] / src / Plugins / MEDReader / ParaViewPlugin / pqExtractCellTypePanel.cxx
1 // Copyright (C) 2010-2014  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 "pqExtractCellTypePanel.h"
22 #include "ui_ExtractCellTypePanel.h"
23
24 #include "vtkProcessModule.h"
25 #include "vtkMultiBlockDataSet.h"
26 #include "vtkInformation.h"
27 #include "vtkIntArray.h"
28 #include "vtkSMDoubleVectorProperty.h"
29 #include "vtkSMIntVectorProperty.h"
30 #include "vtkSMStringVectorProperty.h"
31 #include "vtkSMProxy.h"
32 #include "vtkEventQtSlotConnect.h"
33 #include "vtkPVSILInformation.h"
34 #include "vtkGraph.h"
35 #include "vtkMutableDirectedGraph.h"
36 #include "vtkAdjacentVertexIterator.h"
37 #include "vtkSMPropertyHelper.h"
38 #include "vtkStringArray.h"
39 #include "vtkDataSetAttributes.h"
40 #include "vtkExtractCellType.h"
41
42 #include "pqTreeWidgetItemObject.h"
43 #include "pqSMAdaptor.h"
44 #include "pqProxy.h"
45 #include "pqPropertyManager.h"
46 #include "pqSILModel.h"
47 #include "pqProxySILModel.h"
48 #include "pqTreeViewSelectionHelper.h"
49 #include "pqTreeWidgetSelectionHelper.h"
50 #include "pqPropertyLinks.h"
51
52 #include <QHeaderView>
53
54 static const char ZE_SEP[]="@@][@@";
55
56 class pqExtractCellTypePanel::pqUI: public QObject, public Ui::ExtractCellTypePanel
57 {
58 public:
59   pqUI(pqExtractCellTypePanel* p):QObject(p)
60   {
61     this->VTKConnect = vtkSmartPointer<vtkEventQtSlotConnect>::New();
62     this->SILUpdateStamp = -1;
63   }
64
65   ~pqUI() { }
66
67   pqSILModel SILModel;
68   vtkSmartPointer<vtkEventQtSlotConnect> VTKConnect;
69   pqPropertyLinks Links;
70   QMap<QTreeWidgetItem*, QString> TreeItemToPropMap;
71   int SILUpdateStamp;
72 };
73
74 pqExtractCellTypePanel::pqExtractCellTypePanel(pqProxy* object_proxy, QWidget* p):Superclass(object_proxy, p)
75 {
76   this->UI=new pqUI(this);
77   this->UI->setupUi(this);
78   pqProxySILModel*proxyModel2 = new pqProxySILModel("GeoTypesStatusTree", &this->UI->SILModel);
79   proxyModel2->setSourceModel(&this->UI->SILModel);
80   this->UI->Fields->setHeaderHidden(true);
81   this->updateSIL();
82   this->linkServerManagerProperties();
83   ////////////////////
84   vtkSMProperty *SMProperty(this->proxy()->GetProperty("GeoTypesStatus"));
85   ////////////////////
86   vtkSMProxy* reader = this->referenceProxy()->getProxy();
87   vtkPVSILInformation* info=vtkPVSILInformation::New();
88   reader->GatherInformation(info);
89   vtkGraph *g(info->GetSIL());
90   //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 ?
91   vtkMutableDirectedGraph *g2(static_cast<vtkMutableDirectedGraph *>(g));
92   if(!g2)
93     return ;
94   int idNames(0);
95   vtkAbstractArray *verticesNames(g2->GetVertexData()->GetAbstractArray("Names",idNames));
96   vtkStringArray *verticesNames2(vtkStringArray::SafeDownCast(verticesNames));
97   vtkIdType id0;
98   bool found(false);
99   for(int i=0;i<verticesNames2->GetNumberOfValues();i++)
100     {
101       vtkStdString &st(verticesNames2->GetValue(i));
102       if(st=="CellTypesTree")
103         {
104           id0=i;
105           found=true;
106         }
107     }
108   if(!found)
109     std::cerr << "There is an internal error ! The tree on server side has not the expected look !" << std::endl;
110   vtkAdjacentVertexIterator *it0(vtkAdjacentVertexIterator::New());
111   g2->GetAdjacentVertices(id0,it0);
112   int kk(0),ll(0);
113   while(it0->HasNext())
114     {
115       vtkIdType id1(it0->Next());
116       QString geoTypeName(QString::fromStdString((const char *)verticesNames2->GetValue(id1)));
117       vtkAdjacentVertexIterator *it1(vtkAdjacentVertexIterator::New());
118       g2->GetAdjacentVertices(id1,it1);
119       QList<QString> strs0; strs0.append(QString("%1").arg(geoTypeName));
120       pqTreeWidgetItemObject *item0(new pqTreeWidgetItemObject(this->UI->Fields,strs0));
121       vtkAdjacentVertexIterator *itGrps(vtkAdjacentVertexIterator::New());
122       g2->GetAdjacentVertices(id1,itGrps);
123       vtkIdType idg(itGrps->Next());
124       QString name0(QString::fromStdString((const char *)verticesNames2->GetValue(idg)));
125       QString toolTipName0(QString("%1 (vtkId=%2)").arg(geoTypeName).arg(name0));
126       item0->setData(0,Qt::UserRole,geoTypeName);
127       item0->setData(0,Qt::ToolTipRole,toolTipName0);
128       item0->setData(0,Qt::CheckStateRole,0);
129       this->propertyManager()->registerLink(item0,"checked",SIGNAL(checkedStateChanged(bool)),this->proxy(),SMProperty,ll++);
130     }
131   it0->Delete(); 
132   this->UI->Fields->header()->setStretchLastSection(true);
133   this->UI->Fields->expandAll();
134   info->Delete();
135   ////////////////////
136   vtkSMProperty *SMPropertyExtractComp(this->proxy()->GetProperty("InsideOut"));
137   this->propertyManager()->registerLink(this->UI->ExtractComplementary,"checked",SIGNAL(stateChanged(int)),this->proxy(),SMPropertyExtractComp);
138   ////////////////////
139   this->UI->VTKConnect->Connect(this->proxy(),vtkCommand::UpdateInformationEvent,this,SLOT(updateSIL()));
140 }
141
142 pqExtractCellTypePanel::~pqExtractCellTypePanel()
143 {
144 }
145
146 void pqExtractCellTypePanel::linkServerManagerProperties()
147 {
148   this->Superclass::linkServerManagerProperties();
149 }
150
151 void pqExtractCellTypePanel::updateSIL()
152 {
153   vtkSMProxy* reader = this->referenceProxy()->getProxy();
154   reader->UpdatePropertyInformation(reader->GetProperty("SILUpdateStamp"));
155   int stamp = vtkSMPropertyHelper(reader, "SILUpdateStamp").GetAsInt();
156   if (stamp != this->UI->SILUpdateStamp)
157     {
158       this->UI->SILUpdateStamp = stamp;
159       vtkPVSILInformation* info = vtkPVSILInformation::New();
160       reader->GatherInformation(info);
161       vtkGraph *sil(info->GetSIL());
162       if(sil)
163         {
164           this->UI->SILModel.update(sil);
165           this->UI->Fields->expandAll();
166         }
167       info->Delete();
168     }
169 }