1 // Copyright (C) 2010-2020 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 "pqExtractGroupFieldsWidget.h"
23 #include "vtkMEDReader.h"
24 #include "vtkExtractGroup.h"
25 #include "vtkPVMetaDataInformation.h"
27 #include "pqTreeWidget.h"
28 #include "pqTreeWidgetItemObject.h"
31 #include "vtkStringArray.h"
32 #include "vtkDataSetAttributes.h"
35 #include <QStringList>
37 //-----------------------------------------------------------------------------
38 pqExtractGroupFieldsWidget::pqExtractGroupFieldsWidget(
39 vtkSMProxy *smproxy, vtkSMProperty *smproperty, QWidget *parentObject)
40 : Superclass(smproxy, smproperty, parentObject)
42 this->TreeWidget->setHeaderLabel("Groups And Families");
43 this->initializeTreeWidget(smproxy, smproperty);
46 //-----------------------------------------------------------------------------
47 pqExtractGroupFieldsWidget::~pqExtractGroupFieldsWidget()
51 //-----------------------------------------------------------------------------
52 void pqExtractGroupFieldsWidget::loadTreeWidgetItems()
55 vtkPVMetaDataInformation *info(vtkPVMetaDataInformation::New());
56 this->proxy()->GatherInformation(info);
57 vtkGraph* graph = vtkGraph::SafeDownCast(info->GetInformationData());
64 this->TreeWidget->clear();
67 this->ItemMap.clear();
71 tree->CheckedShallowCopy(graph);
72 vtkStringArray* names = vtkStringArray::SafeDownCast(tree->GetVertexData()->GetAbstractArray("Names"));
74 vtkIdType root = tree->GetRoot();
75 vtkIdType mfg = tree->GetChild(root, 1); // MeshesFamsGrps
77 vtkIdType mesh = tree->GetChild(mfg, 0); // mesh
78 QString meshName = QString(names->GetValue(mesh));
82 vtkIdType grps = tree->GetChild(mesh, 0); // grps
83 pqTreeWidgetItemObject* grpsItem = new pqTreeWidgetItemObject(this->TreeWidget, QStringList());
85 grpsItem->setText(0, QString("Groups of \"" + meshName + "\""));
87 vtkIdType fams = tree->GetChild(mesh, 1); // fams
88 pqTreeWidgetItemObject* famsItem = new pqTreeWidgetItemObject(this->TreeWidget, QStringList());
90 famsItem->setText(0, QString("Families of \"" + meshName + "\""));
92 std::map<std::string, int> famDataTypeMap;
94 for (int i = 0; i < tree->GetNumberOfChildren(fams); i++)
97 vtkIdType fam = tree->GetChild(fams, i);
98 pqTreeWidgetItemObject *famItem = new pqTreeWidgetItemObject(famsItem, QStringList());
102 std::string str = names->GetValue(fam);
103 const char* separator = vtkMEDReader::GetSeparator();
104 size_t pos = str.find(separator);
105 std::string name = str.substr(0, pos);
106 famItem->setText(0, QString(name.c_str()));
109 QString propertyName = QString(vtkExtractGroup::GetFamStart()) + QString(str.c_str());
110 this->ItemMap[propertyName] = famItem;
113 int dataTypeFlag = atoi(str.substr(pos + strlen(separator)).c_str());
114 famDataTypeMap[name] = dataTypeFlag;
117 famItem->setFlags(famItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
118 famItem->setChecked(true);
121 QString famToolTip(QString("%1 (%2)").arg(QString(name.c_str())).arg(dataTypeFlag));
122 famItem->setData(0, Qt::ToolTipRole, famToolTip);
127 famItem->setData(0, Qt::DecorationRole,
128 QPixmap(":/ParaViewResources/Icons/pqCellData16.png"));
132 famItem->setData(0, Qt::DecorationRole,
133 QPixmap(":/ParaViewResources/Icons/pqPointData16.png"));
137 for (int i = 0; i < tree->GetNumberOfChildren(grps); i++)
140 vtkIdType grp = tree->GetChild(grps, i);
141 pqTreeWidgetItemObject *grpItem = new pqTreeWidgetItemObject(grpsItem, QStringList());
145 QString name = QString(names->GetValue(grp));
146 grpItem->setText(0, name);
149 QString propertyName = QString(vtkExtractGroup::GetGrpStart()) + name;
150 this->ItemMap[propertyName] = grpItem;
153 bool hasPoint = false;
154 bool hasCell = false;
155 int dataTypeFlag = 0;
156 for (int j = 0; j < tree->GetNumberOfChildren(grp); j++)
158 dataTypeFlag = famDataTypeMap[names->GetValue(tree->GetChild(grp, j))];
159 if (dataTypeFlag > 0)
163 else if (dataTypeFlag < 0)
173 if (hasPoint && hasCell)
181 grpItem->setFlags(grpItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
182 grpItem->setChecked(true);
185 grpItem->setData(0, Qt::ToolTipRole, name);
190 grpItem->setData(0, Qt::DecorationRole,
191 QPixmap(":/ParaViewResources/Icons/pqCellData16.png"));
195 grpItem->setData(0, Qt::DecorationRole,
196 QPixmap(":/ParaViewResources/Icons/pqPointData16.png"));
201 this->TreeWidget->expandAll();