Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / ParaViewPlugin / pqMEDReaderGraphUtils.cxx
1 // Copyright (C) 2010-2022  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 "pqMEDReaderGraphUtils.h"
22
23 #include "vtkGraph.h"
24 #include "vtkTree.h"
25 #include "vtkNew.h"
26 #include "vtkStringArray.h"
27 #include "vtkDataSetAttributes.h"
28
29 namespace pqMedReaderGraphUtils
30 {
31 void getCurrentTS(vtkGraph* graph, vtkIdType id, QStringList& dts, QStringList& its,
32                   QStringList& tts)
33 {
34   vtkNew<vtkTree> tree;
35   tree->CheckedShallowCopy(graph);
36   vtkStringArray* names = vtkStringArray::SafeDownCast(
37     tree->GetVertexData()->GetAbstractArray("Names"));
38   vtkIdType root = tree->GetRoot();
39   vtkIdType fst = tree->GetChild(root, 0); // FieldsStatusTree
40   vtkIdType tsr = tree->GetChild(tree->GetChild(fst, id*2), 0); //Time Step root node
41   vtkIdType tmp;
42   for (int i = 0; i < tree->GetNumberOfChildren(tsr); i++)
43     {
44     // Each Time Step
45     // Recover step
46     tmp = tree->GetChild(tsr, i);
47     dts << QString(names->GetValue(tmp));
48
49     // Recover mode
50     tmp = tree->GetChild(tmp, 0);
51     its << QString(names->GetValue(tmp));
52
53     // Recover value
54     tmp = tree->GetChild(tmp, 0);
55     tts << QString(names->GetValue(tmp));
56     }
57 }
58
59 int getMaxNumberOfTS(vtkGraph* graph)
60 {
61   vtkNew<vtkTree> tree;
62   tree->CheckedShallowCopy(graph);
63   vtkStringArray* names = vtkStringArray::SafeDownCast(
64     tree->GetVertexData()->GetAbstractArray("Names"));
65   vtkIdType root = tree->GetRoot();
66   vtkIdType fst = tree->GetChild(root, 0); // FieldsStatusTree
67   vtkIdType tmp;
68   int nbTS = 0;
69   for (int i = 0; i < tree->GetNumberOfChildren(fst); i += 2)
70     {
71     // Look for max time steps
72     tmp = tree->GetChild(tree->GetChild(fst, i), 0);
73     nbTS = std::max(nbTS, names->GetVariantValue(tmp).ToInt());
74     }
75   return nbTS;
76 }
77 }