]> SALOME platform Git repositories - tools/paravisaddons_common.git/blob - src/ElectromagnetismRotation/plugin/ParaViewPlugin/pqElectroRotationGroupWidget.cxx
Salome HOME
Issues/Warnings detected by Paraview 5.9 in some plugins
[tools/paravisaddons_common.git] / src / ElectromagnetismRotation / plugin / ParaViewPlugin / pqElectroRotationGroupWidget.cxx
1 // Copyright (C) 2021  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 "pqElectroRotationGroupWidget.h"
22
23 #include "vtkElectromagnetismRotation.h"
24 #include "vtkPVMetaDataInformationERIO.h"
25
26 #include "pqTreeWidget.h"
27 #include "pqTreeWidgetItemObject.h"
28 #include "vtkGraph.h"
29 #include "vtkNew.h"
30 #include "vtkStringArray.h"
31 #include "vtkDataSetAttributes.h"
32 #include "vtkTree.h"
33
34 #include <QStringList>
35
36 //-----------------------------------------------------------------------------
37 pqElectroRotationGroupWidget::pqElectroRotationGroupWidget(
38   vtkSMProxy *smproxy, vtkSMProperty *smproperty, QWidget *parentObject)
39 : Superclass(smproxy, smproperty, parentObject)
40 {
41   this->TreeWidget->setHeaderLabel("Groups");
42   this->initializeTreeWidget(smproxy, smproperty);
43 }
44
45 //-----------------------------------------------------------------------------
46 pqElectroRotationGroupWidget::~pqElectroRotationGroupWidget()
47 {
48 }
49
50 //-----------------------------------------------------------------------------
51 void pqElectroRotationGroupWidget::loadTreeWidgetItems()
52 {
53   // Recover Graph
54   vtkPVMetaDataInformationERIO *info(vtkPVMetaDataInformationERIO::New());
55   this->proxy()->GatherInformation(info);
56   vtkGraph* graph = vtkGraph::SafeDownCast(info->GetInformationData());
57   if(!graph)
58     {
59     return;
60     }
61
62   // Clear Tree Widget
63   this->TreeWidget->clear();
64
65   // Clear Item Map
66   this->ItemMap.clear();
67
68   // Create a tree
69   vtkNew<vtkTree> tree;
70   tree->CheckedShallowCopy(graph);
71   vtkStringArray* names = vtkStringArray::SafeDownCast(tree->GetVertexData()->GetAbstractArray("Names"));
72
73   vtkIdType root = tree->GetRoot();
74   vtkIdType mfg = tree->GetChild(root, 1); // MeshesFamsGrps
75
76   vtkIdType mesh = tree->GetChild(mfg, 0); // mesh
77   QString meshName = QString(names->GetValue(mesh));
78
79   this->NItems = 0;
80
81   vtkIdType grps = tree->GetChild(mesh, 0); // grps
82   pqTreeWidgetItemObject* grpsItem = new pqTreeWidgetItemObject(this->TreeWidget, QStringList());
83   this->NItems++;
84   grpsItem->setText(0, QString("Groups of \"" + meshName + "\""));
85
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++)
89     {
90       vtkIdType fam = tree->GetChild(fams, i);
91       // Familly name
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);
96       // Datatype flag
97       int dataTypeFlag = atoi(str.substr(pos + strlen(separator)).c_str());
98       famDataTypeMap[name] = dataTypeFlag;
99     }
100
101   for (int i = 0; i < tree->GetNumberOfChildren(grps); i++)
102     {
103     // Grp Item
104     vtkIdType grp = tree->GetChild(grps, i);
105
106     // Datatype flag
107     bool hasPoint = false;
108     bool hasCell = false;
109     int dataTypeFlag = 0;
110     for (int j = 0; j < tree->GetNumberOfChildren(grp); j++)
111     {
112       dataTypeFlag = famDataTypeMap[names->GetValue(tree->GetChild(grp, j))];
113       if (dataTypeFlag > 0)
114         {
115         hasPoint = true;
116         }
117       else if (dataTypeFlag < 0)
118         {
119         hasCell = true;
120         }
121       else
122         {
123         dataTypeFlag = 0;
124         break;
125         }
126
127       if (hasPoint && hasCell)
128         {
129         dataTypeFlag = 0;
130         break;
131         }
132     }
133
134     //
135
136     if (dataTypeFlag<0) // if group on cells
137     {
138       pqTreeWidgetItemObject *grpItem = new pqTreeWidgetItemObject(grpsItem, QStringList());
139       this->NItems++;
140
141       // Group name
142       QString name = QString(names->GetValue(grp));
143       grpItem->setText(0, name);
144
145       // Property Name
146       QString propertyName = QString(vtkElectromagnetismRotation::GetGrpStart()) + name;
147       this->ItemMap[propertyName] = grpItem;
148
149       // Checkbox
150       grpItem->setFlags(grpItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
151       grpItem->setChecked(true);
152
153       // Tooltip
154       grpItem->setData(0, Qt::ToolTipRole, name);
155
156       grpItem->setData(0, Qt::DecorationRole, QPixmap(":/ParaViewResources/Icons/pqCellData16.png"));
157     }
158   }
159
160   // Expand Widget
161   this->TreeWidget->expandAll();
162 }