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
16 #include <inspector/DFBrowserPane_TDataStdReferenceArray.hxx>
17
18 #include <inspector/DFBrowserPane_AttributePaneModel.hxx>
19 #include <inspector/DFBrowserPane_HelperArray.hxx>
20 #include <inspector/DFBrowserPane_TableView.hxx>
21 #include <inspector/DFBrowserPane_Tools.hxx>
22
23 #include <TDataStd_ReferenceArray.hxx>
24
25 #include <Standard_WarningsDisable.hxx>
26 #include <QGridLayout>
27 #include <QItemSelectionModel>
28 #include <QTableView>
29 #include <QVariant>
30 #include <QWidget>
31 #include <Standard_WarningsRestore.hxx>
32
33 // =======================================================================
34 // function : CreateWidget
35 // purpose :
36 // =======================================================================
CreateWidget(QWidget * theParent)37 QWidget* DFBrowserPane_TDataStdReferenceArray::CreateWidget (QWidget* theParent)
38 {
39 QWidget* aMainWidget = new QWidget (theParent);
40 myTableView = new DFBrowserPane_TableView (aMainWidget);
41 myTableView->SetModel (getPaneModel());
42 myTableView->GetTableView()->setSelectionModel (mySelectionModels.front());
43
44 myArrayTableHelper.CreateWidget (aMainWidget, myTableView);
45
46 return aMainWidget;
47 }
48
49 // =======================================================================
50 // function : Init
51 // purpose :
52 // =======================================================================
Init(const Handle (TDF_Attribute)& theAttribute)53 void DFBrowserPane_TDataStdReferenceArray::Init (const Handle(TDF_Attribute)& theAttribute)
54 {
55 QList<QVariant> aValues;
56 GetValues (theAttribute, aValues);
57 myArrayTableHelper.Init (aValues);
58 }
59
60 // =======================================================================
61 // function : GetValues
62 // purpose :
63 // =======================================================================
GetValues(const Handle (TDF_Attribute)& theAttribute,QList<QVariant> & theValues)64 void DFBrowserPane_TDataStdReferenceArray::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
65 {
66 Handle(TDataStd_ReferenceArray) anAttribute = Handle(TDataStd_ReferenceArray)::DownCast (theAttribute);
67 if (anAttribute.IsNull())
68 return;
69
70 theValues.append (anAttribute->Lower());
71 theValues.append (anAttribute->Upper());
72 for (int aValueId = anAttribute->Lower(); aValueId <= anAttribute->Upper(); aValueId++)
73 theValues.append (DFBrowserPane_Tools::GetEntry (anAttribute->Value(aValueId)).ToCString());
74 }
75
76 // =======================================================================
77 // function : GetShortAttributeInfo
78 // purpose :
79 // =======================================================================
GetShortAttributeInfo(const Handle (TDF_Attribute)& theAttribute,QList<QVariant> & theValues)80 void DFBrowserPane_TDataStdReferenceArray::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
81 QList<QVariant>& theValues)
82 {
83 QList<QVariant> aValues;
84 GetValues (theAttribute, aValues);
85 myArrayTableHelper.Init (aValues);
86 return myArrayTableHelper.GetShortAttributeInfo (theAttribute, theValues);
87 }
88
89 // =======================================================================
90 // function : GetReferences
91 // purpose :
92 // =======================================================================
GetReferences(const Handle (TDF_Attribute)& theAttribute,NCollection_List<TDF_Label> & theRefLabels,Handle (Standard_Transient)&)93 void DFBrowserPane_TDataStdReferenceArray::GetReferences (const Handle(TDF_Attribute)& theAttribute,
94 NCollection_List<TDF_Label>& theRefLabels,
95 Handle(Standard_Transient)& /*theRefPresentation*/)
96 {
97 if (!getTableView())
98 return;
99 QStringList aSelectedEntries = DFBrowserPane_TableView::GetSelectedColumnValues (getTableView()->GetTableView(), 1);
100
101 Handle(TDataStd_ReferenceArray) anAttribute = Handle(TDataStd_ReferenceArray)::DownCast (theAttribute);
102 if (anAttribute.IsNull())
103 return;
104
105 for (int aValueId = anAttribute->Lower(); aValueId <= anAttribute->Upper(); aValueId++)
106 {
107 TDF_Label aLabel = anAttribute->Value (aValueId);
108 if (aSelectedEntries.contains (DFBrowserPane_Tools::GetEntry (aLabel).ToCString()))
109 theRefLabels.Append (aLabel);
110 }
111 }
112