0029025: TInspector include files are not installed to inc directory by CMake
[occt.git] / tools / DFBrowserPane / DFBrowserPane_TDataStdNamedData.cxx
CommitLineData
14bbbdcb 1// Created on: 2017-06-16
2// Created by: Natalia ERMOLAEVA
3// Copyright (c) 2017 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
0cb512c0 16#include <inspector/DFBrowserPane_TDataStdNamedData.hxx>
14bbbdcb 17
0cb512c0 18#include <inspector/DFBrowserPane_AttributePaneModel.hxx>
19#include <inspector/DFBrowserPane_HelperGroupContent.hxx>
20#include <inspector/DFBrowserPane_TableView.hxx>
21#include <inspector/DFBrowserPane_Tools.hxx>
14bbbdcb 22
23#include <TColStd_DataMapOfStringInteger.hxx>
24#include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx>
25#include <TColStd_HArray1OfInteger.hxx>
26#include <TColStd_HArray1OfReal.hxx>
27
28#include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx>
29#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx>
30#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx>
31#include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx>
32#include <TDataStd_DataMapIteratorOfDataMapOfStringString.hxx>
33#include <TDataStd_DataMapOfStringByte.hxx>
34#include <TDataStd_DataMapOfStringHArray1OfInteger.hxx>
35#include <TDataStd_DataMapOfStringReal.hxx>
36#include <TDataStd_DataMapOfStringString.hxx>
37#include <TDataStd_HDataMapOfStringHArray1OfInteger.hxx>
38#include <TDataStd_NamedData.hxx>
39
40#include <QVariant>
41#include <QVBoxLayout>
42#include <QWidget>
43
44static const QString VALUES_INTEGER = "values_integer";
45static const QString VALUES_REAL = "values_real";
46static const QString VALUES_STRING = "values_string";
47static const QString VALUES_BYTE = "values_byte";
48static const QString VALUES_INT_ARRAY = "values_int_array";
49static const QString VALUES_REAL_ARRAY = "values_real_array";
50
14bbbdcb 51// =======================================================================
52// function : Constructor
53// purpose :
54// =======================================================================
55DFBrowserPane_TDataStdNamedData::DFBrowserPane_TDataStdNamedData()
56 : DFBrowserPane_AttributePane()
57{
58 myPaneModel = createPaneModel();
59 myRealValuesModel = createPaneModel();
60 myStringValuesModel = createPaneModel();
61 myByteValuesModel = createPaneModel();
62 myIntArrayValuesModel = createPaneModel();
63 myRealArrayModel = createPaneModel();
64}
65
66// =======================================================================
67// function : createPaneModel
68// purpose :
69// =======================================================================
70DFBrowserPane_AttributePaneModel* DFBrowserPane_TDataStdNamedData::createPaneModel()
71{
72 DFBrowserPane_AttributePaneModel* aTableModel = new DFBrowserPane_AttributePaneModel();
73
74 aTableModel->SetOrientation (Qt::Horizontal);
75
76 QList<QVariant> aHeaderValues;
77 aHeaderValues << "Name" << "Value";
78 aTableModel->SetHeaderValues (aHeaderValues, Qt::Vertical);
79 aTableModel->SetColumnCount (2); // indeed these are rows as table orientation is Horizontal
80
81 return aTableModel;
82}
83
84// =======================================================================
85// function : CreateWidget
86// purpose :
87// =======================================================================
88QWidget* DFBrowserPane_TDataStdNamedData::CreateWidget (QWidget* theParent)
89{
90 QWidget* aMainWidget = new QWidget (theParent);
91 QVBoxLayout* aLay = new QVBoxLayout (aMainWidget);
92
93 myTableView = new DFBrowserPane_TableView (aMainWidget);
94 myTableView->SetModel (getPaneModel());
95 myIntValuesContent = new DFBrowserPane_HelperGroupContent ("Named integers", aMainWidget, myTableView);
96 aLay->addWidget (myIntValuesContent);
97
98 myRealValues = new DFBrowserPane_TableView (aMainWidget);
99 myRealValues->SetModel (myRealValuesModel);
100 myRealValuesContent = new DFBrowserPane_HelperGroupContent ("Named reals", aMainWidget, myRealValues);
101 aLay->addWidget (myRealValuesContent);
102
103 myStringValues = new DFBrowserPane_TableView (aMainWidget);
104 myStringValues->SetModel (myStringValuesModel);
105 myStringValuesContent = new DFBrowserPane_HelperGroupContent ("Named strings", aMainWidget, myStringValues);
106 aLay->addWidget (myStringValuesContent);
107
108 myByteValues = new DFBrowserPane_TableView (aMainWidget);
109 myByteValues->SetModel (myByteValuesModel);
110 myByteValuesContent = new DFBrowserPane_HelperGroupContent ("Named bytes", aMainWidget, myByteValues);
111 aLay->addWidget (myByteValuesContent);
112
113 myIntArrayValues = new DFBrowserPane_TableView (aMainWidget);
114 myIntArrayValues->SetModel (myIntArrayValuesModel);
115 myIntArrayValuesContent = new DFBrowserPane_HelperGroupContent ("Named integer arrays", aMainWidget, myIntArrayValues);
116 aLay->addWidget (myIntArrayValuesContent);
117
118 myRealArrayValues = new DFBrowserPane_TableView (aMainWidget);
119 myRealArrayValues->SetModel (myRealArrayModel);
120 myRealArrayValuesContent = new DFBrowserPane_HelperGroupContent ("Named real arrays", aMainWidget, myRealArrayValues);
121 aLay->addWidget (myRealArrayValuesContent);
122
123 aLay->addStretch (1);
124
125 return aMainWidget;
126}
127
128// =======================================================================
129// function : Init
130// purpose :
131// =======================================================================
132void DFBrowserPane_TDataStdNamedData::Init (const Handle(TDF_Attribute)& theAttribute)
133{
134 QList<QVariant> aValues;
135 GetValues (theAttribute, aValues);
136
137 getPaneModel()->Init (getPartOfValues (VALUES_INTEGER, VALUES_REAL, aValues));
138 myRealValuesModel->Init (getPartOfValues (VALUES_REAL, VALUES_STRING, aValues));
139 myStringValuesModel->Init (getPartOfValues (VALUES_STRING, VALUES_BYTE, aValues));
140 myByteValuesModel->Init (getPartOfValues (VALUES_BYTE, VALUES_INT_ARRAY, aValues));
141 myIntArrayValuesModel->Init (getPartOfValues (VALUES_INT_ARRAY, VALUES_REAL_ARRAY, aValues));
142 myRealArrayModel->Init (getPartOfValues (VALUES_REAL_ARRAY, "", aValues));
143}
144
145// =======================================================================
146// function : GetValues
147// purpose :
148// =======================================================================
149void DFBrowserPane_TDataStdNamedData::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
150{
151 Handle(TDataStd_NamedData) anAttribute = Handle(TDataStd_NamedData)::DownCast (theAttribute);
152 if (anAttribute.IsNull())
153 return;
154
155 theValues.append (VALUES_INTEGER);
156 for (TColStd_DataMapIteratorOfDataMapOfStringInteger anIntIter(anAttribute->GetIntegersContainer());
157 anIntIter.More(); anIntIter.Next())
158 {
159 theValues.append (DFBrowserPane_Tools::ToString (anIntIter.Key()));
160 theValues.append (anIntIter.Value());
161 }
162 theValues.append (VALUES_REAL);
163 for (TDataStd_DataMapIteratorOfDataMapOfStringReal aRealIter(anAttribute->GetRealsContainer());
164 aRealIter.More(); aRealIter.Next())
165 {
166 theValues.append (DFBrowserPane_Tools::ToString (aRealIter.Key()));
167 theValues.append (aRealIter.Value());
168 }
169 theValues.append (VALUES_STRING);
170 for (TDataStd_DataMapIteratorOfDataMapOfStringString aStrIter(anAttribute->GetStringsContainer());
171 aStrIter.More(); aStrIter.Next())
172 {
173 theValues.append (DFBrowserPane_Tools::ToString (aStrIter.Key()));
174 theValues.append (DFBrowserPane_Tools::ToString (aStrIter.Value()));
175 }
176 theValues.append (VALUES_BYTE);
177 for (TDataStd_DataMapIteratorOfDataMapOfStringByte aByteIter(anAttribute->GetBytesContainer());
178 aByteIter.More(); aByteIter.Next())
179 {
180 theValues.append (DFBrowserPane_Tools::ToString (aByteIter.Key()));
181 theValues.append (aByteIter.Value());
182 }
183 theValues.append (VALUES_INT_ARRAY);
184 QStringList anArrayValues;
185 for (TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger anIntArrayIter(anAttribute->GetArraysOfIntegersContainer());
186 anIntArrayIter.More(); anIntArrayIter.Next())
187 {
188 theValues.append (DFBrowserPane_Tools::ToString (anIntArrayIter.Key()));
189 anArrayValues.clear();
190 const Handle(TColStd_HArray1OfInteger)& aSubIt = anIntArrayIter.Value();
191 if (!aSubIt.IsNull())
192 {
193 for (Standard_Integer aLowerId = aSubIt->Lower(), i = aLowerId, anUpperId = aSubIt->Upper(); i <= anUpperId; i++)
194 anArrayValues.append (QString::number (aSubIt->Value (i)));
195 }
196 theValues.append (anArrayValues.join (QString (',')));
197 }
198 theValues.append (VALUES_REAL_ARRAY);
199 for (TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal aRealArrayIter (anAttribute->GetArraysOfRealsContainer());
200 aRealArrayIter.More(); aRealArrayIter.Next())
201 {
202 theValues.append (DFBrowserPane_Tools::ToString (aRealArrayIter.Key()));
203 anArrayValues.clear();
204 const Handle(TColStd_HArray1OfReal)& aSubIt = aRealArrayIter.Value();
205 if (!aSubIt.IsNull())
206 {
207 for (Standard_Integer aLowerId = aSubIt->Lower(), i = aLowerId, anUpperId = aSubIt->Upper(); i <= anUpperId; i++)
208 anArrayValues.append (QString::number (aSubIt->Value (i)));
209 }
210 theValues.append (anArrayValues.join (QString (',')));
211 }
212}
213
214// =======================================================================
215// function : getPartOfValues
216// purpose :
217// =======================================================================
218QList<QVariant> DFBrowserPane_TDataStdNamedData::getPartOfValues (const QString& theKey1, const QString& theKey2,
219 const QList<QVariant>& theValues) const
220{
221 QList<QVariant> aValues;
222
223 bool aFoundKey1 = false, aFoundKey2 = false;
224 for (int aValueId = 0; aValueId < theValues.size() && !aFoundKey2; aValueId++)
225 {
226 QString aValue = theValues[aValueId].toString();
227 if (!aFoundKey1)
228 aFoundKey1 = aValue == theKey1;
229 else
230 {
231 aFoundKey2 = aValue == theKey2;
232 if (!aFoundKey2)
233 aValues.append (aValue);
234 }
235 }
236 return aValues;
237}