Salome HOME
Revert "Synchronize adm files"
[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   int idNames(0);
93   vtkAbstractArray *verticesNames(g2->GetVertexData()->GetAbstractArray("Names",idNames));
94   vtkStringArray *verticesNames2(vtkStringArray::SafeDownCast(verticesNames));
95   vtkIdType id0;
96   bool found(false);
97   for(int i=0;i<verticesNames2->GetNumberOfValues();i++)
98     {
99       vtkStdString &st(verticesNames2->GetValue(i));
100       if(st=="CellTypesTree")
101         {
102           id0=i;
103           found=true;
104         }
105     }
106   if(!found)
107     std::cerr << "There is an internal error ! The tree on server side has not the expected look !" << std::endl;
108   vtkAdjacentVertexIterator *it0(vtkAdjacentVertexIterator::New());
109   g2->GetAdjacentVertices(id0,it0);
110   int kk(0),ll(0);
111   while(it0->HasNext())
112     {
113       vtkIdType id1(it0->Next());
114       QString geoTypeName(QString::fromStdString((const char *)verticesNames2->GetValue(id1)));
115       vtkAdjacentVertexIterator *it1(vtkAdjacentVertexIterator::New());
116       g2->GetAdjacentVertices(id1,it1);
117       QList<QString> strs0; strs0.append(QString("%1").arg(geoTypeName));
118       pqTreeWidgetItemObject *item0(new pqTreeWidgetItemObject(this->UI->Fields,strs0));
119       vtkAdjacentVertexIterator *itGrps(vtkAdjacentVertexIterator::New());
120       g2->GetAdjacentVertices(id1,itGrps);
121       vtkIdType idg(itGrps->Next());
122       QString name0(QString::fromStdString((const char *)verticesNames2->GetValue(idg)));
123       QString toolTipName0(QString("%1 (vtkId=%2)").arg(geoTypeName).arg(name0));
124       item0->setData(0,Qt::UserRole,geoTypeName);
125       item0->setData(0,Qt::ToolTipRole,toolTipName0);
126       item0->setData(0,Qt::CheckStateRole,0);
127       this->propertyManager()->registerLink(item0,"checked",SIGNAL(checkedStateChanged(bool)),this->proxy(),SMProperty,ll++);
128     }
129   it0->Delete(); 
130   this->UI->Fields->header()->setStretchLastSection(true);
131   this->UI->Fields->expandAll();
132   info->Delete();
133   ////////////////////
134   vtkSMProperty *SMPropertyExtractComp(this->proxy()->GetProperty("InsideOut"));
135   this->propertyManager()->registerLink(this->UI->ExtractComplementary,"checked",SIGNAL(stateChanged(int)),this->proxy(),SMPropertyExtractComp);
136   ////////////////////
137   this->UI->VTKConnect->Connect(this->proxy(),vtkCommand::UpdateInformationEvent,this,SLOT(updateSIL()));
138 }
139
140 pqExtractCellTypePanel::~pqExtractCellTypePanel()
141 {
142 }
143
144 void pqExtractCellTypePanel::linkServerManagerProperties()
145 {
146   this->Superclass::linkServerManagerProperties();
147 }
148
149 void pqExtractCellTypePanel::updateSIL()
150 {
151   vtkSMProxy* reader = this->referenceProxy()->getProxy();
152   reader->UpdatePropertyInformation(reader->GetProperty("SILUpdateStamp"));
153   int stamp = vtkSMPropertyHelper(reader, "SILUpdateStamp").GetAsInt();
154   if (stamp != this->UI->SILUpdateStamp)
155     {
156       this->UI->SILUpdateStamp = stamp;
157       vtkPVSILInformation* info = vtkPVSILInformation::New();
158       reader->GatherInformation(info);
159       this->UI->SILModel.update(info->GetSIL());
160       this->UI->Fields->expandAll();
161       info->Delete();
162     }
163 }