4959b408dbeb4fbbf2eaef1bbd60970070e5ba3a
[occt.git] / tools / DFBrowserPaneXDE / DFBrowserPaneXDE_AttributeCommonPane.cxx
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/DFBrowserPaneXDE_AttributeCommonPane.hxx>
17
18 #include <inspector/DFBrowserPane_ItemRole.hxx>
19 #include <inspector/DFBrowserPaneXDE_XDEDRAW.hxx>
20
21 #include <TDataStd_TreeNode.hxx>
22 #include <TDF_Reference.hxx>
23 #include <TNaming_NamedShape.hxx>
24 #include <XCAFDoc_Volume.hxx>
25 #include <XCAFDoc_Area.hxx>
26 #include <XCAFDoc_Centroid.hxx>
27 #include <TDataStd_UAttribute.hxx>
28 #include <XCAFDoc_Color.hxx>
29 #include <XCAFDoc_DimTol.hxx>
30 #include <XCAFDoc_Material.hxx>
31 #include <XCAFDoc_GraphNode.hxx>
32
33 #include <set>
34
35 #include <Standard_WarningsDisable.hxx>
36 #include <QStringList>
37 #include <Standard_WarningsRestore.hxx>
38
39 static std::set<Standard_CString> AttributeTypes;
40
41 // =======================================================================
42 // function : Constructor
43 // purpose :
44 // =======================================================================
45 DFBrowserPaneXDE_AttributeCommonPane::DFBrowserPaneXDE_AttributeCommonPane (DFBrowserPane_AttributePaneAPI* theStandardPane)
46 : DFBrowserPane_AttributePane()
47 {
48   myStandardPane = dynamic_cast<DFBrowserPane_AttributePane*> (theStandardPane);
49 }
50
51 // =======================================================================
52 // function : ProcessAttribute
53 // purpose :
54 // =======================================================================
55 bool DFBrowserPaneXDE_AttributeCommonPane::ProcessAttribute (const Standard_CString& theAttributeType)
56 {
57   if (AttributeTypes.empty())
58   {
59     AttributeTypes.insert (STANDARD_TYPE (TDataStd_TreeNode)->Name());
60     AttributeTypes.insert (STANDARD_TYPE (TDF_Reference)->Name());
61     AttributeTypes.insert (STANDARD_TYPE (TNaming_NamedShape)->Name());
62     AttributeTypes.insert (STANDARD_TYPE (XCAFDoc_Volume)->Name());
63     AttributeTypes.insert (STANDARD_TYPE (XCAFDoc_Area)->Name());
64     AttributeTypes.insert (STANDARD_TYPE (XCAFDoc_Centroid)->Name());
65     AttributeTypes.insert (STANDARD_TYPE (TDataStd_UAttribute)->Name());
66     AttributeTypes.insert (STANDARD_TYPE (XCAFDoc_Color)->Name());
67     AttributeTypes.insert (STANDARD_TYPE (XCAFDoc_DimTol)->Name());
68     AttributeTypes.insert (STANDARD_TYPE (XCAFDoc_Material)->Name());
69     AttributeTypes.insert (STANDARD_TYPE (XCAFDoc_GraphNode)->Name());
70   }
71   return AttributeTypes.find (theAttributeType) != AttributeTypes.end();
72 }
73
74 // =======================================================================
75 // function : CreateWidget
76 // purpose :
77 // =======================================================================
78 QWidget* DFBrowserPaneXDE_AttributeCommonPane::CreateWidget (QWidget* theParent)
79 {
80   return myStandardPane ? myStandardPane->CreateWidget (theParent) : 0;
81 }
82
83 // =======================================================================
84 // function : Init
85 // purpose :
86 // =======================================================================
87 void DFBrowserPaneXDE_AttributeCommonPane::Init (const Handle(TDF_Attribute)& theAttribute)
88 {
89   if (myStandardPane)
90     myStandardPane->Init (theAttribute);
91 }
92
93 // =======================================================================
94 // function : GetSelectionModels
95 // purpose :
96 // =======================================================================
97 std::list<QItemSelectionModel*> DFBrowserPaneXDE_AttributeCommonPane::GetSelectionModels()
98 {
99   return myStandardPane ? myStandardPane->GetSelectionModels() : std::list<QItemSelectionModel*>();
100 }
101
102 // =======================================================================
103 // function : GetValues
104 // purpose :
105 // =======================================================================
106 void DFBrowserPaneXDE_AttributeCommonPane::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
107 {
108   if (myStandardPane)
109     myStandardPane->GetValues (theAttribute, theValues);
110 }
111
112 // =======================================================================
113 // function : GetAttributeInfo
114 // purpose :
115 // =======================================================================
116 QVariant DFBrowserPaneXDE_AttributeCommonPane::GetAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
117                                                                  int theRole, int theColumnId)
118 {
119   QVariant aValue;
120   if (myStandardPane)
121   {
122     if (theRole == DFBrowserPane_ItemRole_ShortInfo)
123     {
124       QList<QVariant> aValues;
125       GetShortAttributeInfo (theAttribute, aValues);
126       QStringList anInfoList;
127       for (QList<QVariant>::const_iterator aValuesIt = aValues.begin(); aValuesIt != aValues.end(); aValuesIt++)
128         anInfoList.append (aValuesIt->toString());
129       aValue = anInfoList.join (", ");
130     }
131     else
132       aValue = myStandardPane->GetAttributeInfo (theAttribute, theRole, theColumnId);
133   }
134   else
135     aValue = DFBrowserPane_AttributePane::GetAttributeInfoByType (theAttribute->DynamicType()->Name(),
136                                                                   theRole, theColumnId);
137   return aValue;
138 }
139
140 // =======================================================================
141 // function : GetShortAttributeInfo
142 // purpose :
143 // =======================================================================
144 void DFBrowserPaneXDE_AttributeCommonPane::GetShortAttributeInfo (
145                           const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
146 {
147   theValues.append (DFBrowserPaneXDE_XDEDRAW::GetAttributeInfo (theAttribute).ToCString());
148 }
149
150 // =======================================================================
151 // function : GetSelectionKind
152 // purpose :
153 // =======================================================================
154 int DFBrowserPaneXDE_AttributeCommonPane::GetSelectionKind (QItemSelectionModel* theModel)
155 {
156   if (myStandardPane)
157     return myStandardPane->GetSelectionKind (theModel);
158
159   return DFBrowserPane_AttributePane::GetSelectionKind (theModel);
160 }
161
162 // =======================================================================
163 // function : GetSelectionParameters
164 // purpose :
165 // =======================================================================
166 void DFBrowserPaneXDE_AttributeCommonPane::GetSelectionParameters (QItemSelectionModel* theModel,
167                                     NCollection_List<Handle(Standard_Transient)>& theParameters)
168 {
169   if (myStandardPane)
170     myStandardPane->GetSelectionParameters (theModel, theParameters);
171
172   DFBrowserPane_AttributePane::GetSelectionParameters (theModel, theParameters);
173 }
174
175 // =======================================================================
176 // function : GetPresentation
177 // purpose :
178 // =======================================================================
179 Handle(Standard_Transient) DFBrowserPaneXDE_AttributeCommonPane::GetPresentation (
180                                            const Handle(TDF_Attribute)& theAttribute)
181 {
182   Handle(Standard_Transient) anIO;
183   if (myStandardPane)
184     anIO = myStandardPane->GetPresentation (theAttribute);
185   return anIO;
186 }
187
188 // =======================================================================
189 // function : GetReferences
190 // purpose :
191 // =======================================================================
192 void DFBrowserPaneXDE_AttributeCommonPane::GetReferences (
193                                        const Handle(TDF_Attribute)& theAttribute,
194                                        NCollection_List<TDF_Label>& theRefLabels,
195                                        Handle(Standard_Transient)& theRefPresentation)
196 {
197   Handle(Standard_Transient) anIO;
198   if (myStandardPane)
199     myStandardPane->GetReferences (theAttribute, theRefLabels, theRefPresentation);
200 }
201
202 // =======================================================================
203 // function : GetAttributeReferences
204 // purpose :
205 // =======================================================================
206 void DFBrowserPaneXDE_AttributeCommonPane::GetAttributeReferences (
207                                        const Handle(TDF_Attribute)& theAttribute,
208                                        NCollection_List<Handle(TDF_Attribute)>& theRefAttributes,
209                                        Handle(Standard_Transient)& theRefPresentation)
210 {
211   Handle(Standard_Transient) anIO;
212   if (myStandardPane)
213     myStandardPane->GetAttributeReferences (theAttribute, theRefAttributes, theRefPresentation);
214 }