1 // Copyright (C) 2010-2015 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 "vtkSMSourceProxy.h"
33 #include "vtkEventQtSlotConnect.h"
34 #include "vtkPVSILInformation.h"
36 #include "vtkMutableDirectedGraph.h"
37 #include "vtkAdjacentVertexIterator.h"
38 #include "vtkSMPropertyHelper.h"
39 #include "vtkStringArray.h"
40 #include "vtkDataSetAttributes.h"
41 #include "vtkExtractCellType.h"
43 #include "pqTreeWidgetItemObject.h"
44 #include "pqSMAdaptor.h"
46 #include "pqPropertyManager.h"
47 #include "pqSILModel.h"
48 #include "pqProxySILModel.h"
49 #include "pqTreeViewSelectionHelper.h"
50 #include "pqTreeWidgetSelectionHelper.h"
51 #include "pqPropertyLinks.h"
53 #include <QHeaderView>
57 static const char ZE_SEP[]="@@][@@";
59 class pqExtractCellTypePanel::pqUI: public QObject, public Ui::ExtractCellTypePanel
62 pqUI(pqExtractCellTypePanel* p):QObject(p)
64 this->VTKConnect = vtkSmartPointer<vtkEventQtSlotConnect>::New();
65 this->SILUpdateStamp = -1;
71 vtkSmartPointer<vtkEventQtSlotConnect> VTKConnect;
72 pqPropertyLinks Links;
73 QMap<QTreeWidgetItem*, QString> TreeItemToPropMap;
77 pqExtractCellTypePanel::pqExtractCellTypePanel(pqProxy* object_proxy, QWidget* p):Superclass(object_proxy, p)
79 this->UI=new pqUI(this);
80 this->UI->setupUi(this);
81 pqProxySILModel*proxyModel2 = new pqProxySILModel("GeoTypesStatusTree", &this->UI->SILModel);
82 proxyModel2->setSourceModel(&this->UI->SILModel);
83 this->UI->Fields->setHeaderHidden(true);
85 this->linkServerManagerProperties();
87 vtkSMProperty *SMProperty(this->proxy()->GetProperty("GeoTypesStatus"));
89 vtkSMProxy* reader = this->referenceProxy()->getProxy();
90 vtkPVSILInformation* info=vtkPVSILInformation::New();
91 reader->GatherInformation(info);
92 vtkGraph *g(info->GetSIL());
93 //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 ?
94 vtkMutableDirectedGraph *g2(static_cast<vtkMutableDirectedGraph *>(g));
98 vtkAbstractArray *verticesNames(g2->GetVertexData()->GetAbstractArray("Names",idNames));
99 vtkStringArray *verticesNames2(vtkStringArray::SafeDownCast(verticesNames));
102 for(int i=0;i<verticesNames2->GetNumberOfValues();i++)
104 vtkStdString &st(verticesNames2->GetValue(i));
105 if(st=="CellTypesTree")
112 std::cerr << "There is an internal error ! The tree on server side has not the expected look !" << std::endl;
113 vtkAdjacentVertexIterator *it0(vtkAdjacentVertexIterator::New());
114 g2->GetAdjacentVertices(id0,it0);
116 while(it0->HasNext())
118 vtkIdType id1(it0->Next());
119 QString geoTypeName(QString::fromStdString((const char *)verticesNames2->GetValue(id1)));
120 vtkAdjacentVertexIterator *it1(vtkAdjacentVertexIterator::New());
121 g2->GetAdjacentVertices(id1,it1);
122 QList<QString> strs0; strs0.append(QString("%1").arg(geoTypeName));
123 pqTreeWidgetItemObject *item0(new pqTreeWidgetItemObject(this->UI->Fields,strs0));
124 vtkAdjacentVertexIterator *itGrps(vtkAdjacentVertexIterator::New());
125 g2->GetAdjacentVertices(id1,itGrps);
126 vtkIdType idg(itGrps->Next());
127 QString name0(QString::fromStdString((const char *)verticesNames2->GetValue(idg)));
128 QString toolTipName0(QString("%1 (vtkId=%2)").arg(geoTypeName).arg(name0));
129 item0->setData(0,Qt::UserRole,geoTypeName);
130 item0->setData(0,Qt::ToolTipRole,toolTipName0);
131 item0->setData(0,Qt::CheckStateRole,0);
132 item0->setProperty("PosInStringVector",QVariant(ll++));
133 connect(item0,SIGNAL(checkedStateChanged(bool)),this,SLOT(anItemAsBeenFired()));
136 this->UI->Fields->header()->setStretchLastSection(true);
137 this->UI->Fields->expandAll();
140 vtkSMProperty *SMPropertyExtractComp(this->proxy()->GetProperty("InsideOut"));
141 this->propertyManager()->registerLink(this->UI->ExtractComplementary,"checked",SIGNAL(stateChanged(int)),this->proxy(),SMPropertyExtractComp);
143 this->UI->VTKConnect->Connect(this->proxy(),vtkCommand::UpdateInformationEvent,this,SLOT(updateSIL()));
146 pqExtractCellTypePanel::~pqExtractCellTypePanel()
150 void pqExtractCellTypePanel::linkServerManagerProperties()
152 this->Superclass::linkServerManagerProperties();
155 void pqExtractCellTypePanel::updateSIL()
157 vtkSMProxy* reader = this->referenceProxy()->getProxy();
158 reader->UpdatePropertyInformation(reader->GetProperty("SILUpdateStamp"));
159 int stamp = vtkSMPropertyHelper(reader, "SILUpdateStamp").GetAsInt();
160 if (stamp != this->UI->SILUpdateStamp)
162 this->UI->SILUpdateStamp = stamp;
163 vtkPVSILInformation* info = vtkPVSILInformation::New();
164 reader->GatherInformation(info);
165 vtkGraph *sil(info->GetSIL());
168 this->UI->SILModel.update(sil);
169 this->UI->Fields->expandAll();
175 void pqExtractCellTypePanel::anItemAsBeenFired()
178 vtkSMProxy *proxy(this->proxy());
179 vtkSMProperty *SMProperty(proxy->GetProperty("GeoTypesStatus"));
180 vtkSMStringVectorProperty *sm(dynamic_cast<vtkSMStringVectorProperty *>(SMProperty));
181 unsigned int nb(sm->GetNumberOfElements());
182 std::vector<std::string> sts(nb);
183 for(unsigned int i=0;i<nb;i++)
184 sts[i]=sm->GetElement(i);
186 pqTreeWidget *sc(this->UI->Fields);
187 for(int i0=0;i0<sc->topLevelItemCount();i0++)
189 QTreeWidgetItem *lev0(sc->topLevelItem(i0));
190 pqTreeWidgetItemObject *scc(dynamic_cast<pqTreeWidgetItemObject *>(lev0));
191 int ll(scc->property("PosInStringVector").toInt());
192 int v(scc->isChecked());
193 std::ostringstream oss; oss << v;
194 sts[2*ll+1]=oss.str();
197 const char **args=new const char *[nb];
198 for(unsigned int i=0;i<nb;i++)
200 args[i]=sts[i].c_str();
203 int iup(sm->GetImmediateUpdate());
204 //sm->SetNumberOfElements(0);
205 sm->SetElements(args,nb);
206 proxy->UpdateVTKObjects();
207 sm->SetImmediateUpdate(iup);
211 ((vtkSMSourceProxy *)proxy)->UpdatePipelineInformation();
215 void pqExtractCellTypePanel::updateInformationAndDomains()
217 pqNamedObjectPanel::updateInformationAndDomains();
218 vtkSMProxy *proxy(this->proxy());
219 vtkSMProperty *SMProperty(proxy->GetProperty("GeoTypesStatus"));
220 SMProperty->Modified();// agy : THE LINE FOR 7.5.1 !