1 // Copyright (C) 2010-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay
21 #include "pqExtractCellTypePanel.h"
22 #include "ui_ExtractCellTypePanel.h"
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"
35 #include "vtkMutableDirectedGraph.h"
36 #include "vtkAdjacentVertexIterator.h"
37 #include "vtkSMPropertyHelper.h"
38 #include "vtkStringArray.h"
39 #include "vtkDataSetAttributes.h"
40 #include "vtkExtractCellType.h"
42 #include "pqTreeWidgetItemObject.h"
43 #include "pqSMAdaptor.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"
52 #include <QHeaderView>
54 static const char ZE_SEP[]="@@][@@";
56 class pqExtractCellTypePanel::pqUI: public QObject, public Ui::ExtractCellTypePanel
59 pqUI(pqExtractCellTypePanel* p):QObject(p)
61 this->VTKConnect = vtkSmartPointer<vtkEventQtSlotConnect>::New();
62 this->SILUpdateStamp = -1;
68 vtkSmartPointer<vtkEventQtSlotConnect> VTKConnect;
69 pqPropertyLinks Links;
70 QMap<QTreeWidgetItem*, QString> TreeItemToPropMap;
74 pqExtractCellTypePanel::pqExtractCellTypePanel(pqProxy* object_proxy, QWidget* p):Superclass(object_proxy, p)
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);
82 this->linkServerManagerProperties();
84 vtkSMProperty *SMProperty(this->proxy()->GetProperty("GeoTypesStatus"));
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));
93 vtkAbstractArray *verticesNames(g2->GetVertexData()->GetAbstractArray("Names",idNames));
94 vtkStringArray *verticesNames2(vtkStringArray::SafeDownCast(verticesNames));
97 for(int i=0;i<verticesNames2->GetNumberOfValues();i++)
99 vtkStdString &st(verticesNames2->GetValue(i));
100 if(st=="CellTypesTree")
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);
111 while(it0->HasNext())
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++);
130 this->UI->Fields->header()->setStretchLastSection(true);
131 this->UI->Fields->expandAll();
134 vtkSMProperty *SMPropertyExtractComp(this->proxy()->GetProperty("InsideOut"));
135 this->propertyManager()->registerLink(this->UI->ExtractComplementary,"checked",SIGNAL(stateChanged(int)),this->proxy(),SMPropertyExtractComp);
137 this->UI->VTKConnect->Connect(this->proxy(),vtkCommand::UpdateInformationEvent,this,SLOT(updateSIL()));
140 pqExtractCellTypePanel::~pqExtractCellTypePanel()
144 void pqExtractCellTypePanel::linkServerManagerProperties()
146 this->Superclass::linkServerManagerProperties();
149 void pqExtractCellTypePanel::updateSIL()
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)
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();