1 // Copyright (C) 2021 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 "pqElectroRotationGroupWidget.h"
23 #include "vtkElectromagnetismRotation.h"
24 #include "vtkPVMetaDataInformation.h"
26 #include "pqTreeWidget.h"
27 #include "pqTreeWidgetItemObject.h"
30 #include "vtkStringArray.h"
31 #include "vtkDataSetAttributes.h"
34 #include <QStringList>
36 //-----------------------------------------------------------------------------
37 pqElectroRotationGroupWidget::pqElectroRotationGroupWidget(
38 vtkSMProxy *smproxy, vtkSMProperty *smproperty, QWidget *parentObject)
39 : Superclass(smproxy, smproperty, parentObject)
41 this->TreeWidget->setHeaderLabel("Groups");
42 this->initializeTreeWidget(smproxy, smproperty);
45 //-----------------------------------------------------------------------------
46 pqElectroRotationGroupWidget::~pqElectroRotationGroupWidget()
50 //-----------------------------------------------------------------------------
51 void pqElectroRotationGroupWidget::loadTreeWidgetItems()
54 vtkPVMetaDataInformation *info(vtkPVMetaDataInformation::New());
55 this->proxy()->GatherInformation(info);
56 vtkGraph* graph = vtkGraph::SafeDownCast(info->GetInformationData());
63 this->TreeWidget->clear();
66 this->ItemMap.clear();
70 tree->CheckedShallowCopy(graph);
71 vtkStringArray* names = vtkStringArray::SafeDownCast(tree->GetVertexData()->GetAbstractArray("Names"));
73 vtkIdType root = tree->GetRoot();
74 vtkIdType mfg = tree->GetChild(root, 1); // MeshesFamsGrps
76 vtkIdType mesh = tree->GetChild(mfg, 0); // mesh
77 QString meshName = QString(names->GetValue(mesh));
81 vtkIdType grps = tree->GetChild(mesh, 0); // grps
82 pqTreeWidgetItemObject* grpsItem = new pqTreeWidgetItemObject(this->TreeWidget, QStringList());
84 grpsItem->setText(0, QString("Groups of \"" + meshName + "\""));
86 vtkIdType fams = tree->GetChild(mesh, 1); // fams
87 std::map<std::string, int> famDataTypeMap;
88 for (int i = 0; i < tree->GetNumberOfChildren(fams); i++)
90 vtkIdType fam = tree->GetChild(fams, i);
92 std::string str = names->GetValue(fam);
93 const char separator[]= "@@][@@";
94 size_t pos = str.find(separator);
95 std::string name = str.substr(0, pos);
97 int dataTypeFlag = atoi(str.substr(pos + strlen(separator)).c_str());
98 famDataTypeMap[name] = dataTypeFlag;
101 for (int i = 0; i < tree->GetNumberOfChildren(grps); i++)
104 vtkIdType grp = tree->GetChild(grps, i);
107 bool hasPoint = false;
108 bool hasCell = false;
109 int dataTypeFlag = 0;
110 for (int j = 0; j < tree->GetNumberOfChildren(grp); j++)
112 dataTypeFlag = famDataTypeMap[names->GetValue(tree->GetChild(grp, j))];
113 if (dataTypeFlag > 0)
117 else if (dataTypeFlag < 0)
127 if (hasPoint && hasCell)
136 if (dataTypeFlag<0) // if group on cells
138 pqTreeWidgetItemObject *grpItem = new pqTreeWidgetItemObject(grpsItem, QStringList());
142 QString name = QString(names->GetValue(grp));
143 grpItem->setText(0, name);
146 QString propertyName = QString(vtkElectromagnetismRotation::GetGrpStart()) + name;
147 this->ItemMap[propertyName] = grpItem;
150 grpItem->setFlags(grpItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
151 grpItem->setChecked(true);
154 grpItem->setData(0, Qt::ToolTipRole, name);
156 grpItem->setData(0, Qt::DecorationRole, QPixmap(":/ParaViewResources/Icons/pqCellData16.png"));
161 this->TreeWidget->expandAll();