0029310: Coding - multiple compiler warnings in Inspectors
[occt.git] / tools / DFBrowserPane / DFBrowserPane_Tools.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_Tools.hxx>
14bbbdcb 17
18#include <AIS_DisplayMode.hxx>
d2c90917 19#include <CDM_CanCloseStatus.hxx>
14bbbdcb 20#include <Graphic3d_MaterialAspect.hxx>
21#include <Graphic3d_NameOfMaterial.hxx>
22#include <Standard_Version.hxx>
23#include <TCollection_AsciiString.hxx>
24#include <TDataStd.hxx>
25#include <TDataStd_RealEnum.hxx>
26#include <TDataXtd.hxx>
27#include <TDataXtd_ConstraintEnum.hxx>
28#include <TDataXtd_GeometryEnum.hxx>
29#include <TDF_Tool.hxx>
30#include <TNaming.hxx>
31#include <TNaming_NameType.hxx>
32#include <TNaming_Evolution.hxx>
33#include <TopAbs.hxx>
34#include <TopAbs_ShapeEnum.hxx>
35#include <TopAbs_Orientation.hxx>
36
130eb114 37#include <Standard_WarningsDisable.hxx>
14bbbdcb 38#include <QApplication>
d2c90917 39#include <QPalette>
14bbbdcb 40#include <QStringList>
41#include <QStyle>
d2c90917 42#include <QWidget>
130eb114 43#include <Standard_WarningsRestore.hxx>
14bbbdcb 44
45#include <sstream>
46
14bbbdcb 47const int TABLE_COLUMN_0_WIDTH = 200;
48const int TABLE_COLUMN_OTHER_WIDTH = 120;
49
50// =======================================================================
51// function : DefaultPanelColumnWidth
52// purpose :
53// =======================================================================
54int DFBrowserPane_Tools::DefaultPanelColumnWidth (const int theColumnId)
55{
56 return theColumnId == 0 ? TABLE_COLUMN_0_WIDTH : TABLE_COLUMN_OTHER_WIDTH;
57}
58
59// =======================================================================
60// function : GetEntry
61// purpose :
62// =======================================================================
63TCollection_AsciiString DFBrowserPane_Tools::GetEntry (const TDF_Label& theLabel)
64{
65 if (theLabel.IsNull())
66 return "Null";
67
68 TCollection_AsciiString anAsciiEntry;
69 TDF_Tool::Entry(theLabel, anAsciiEntry);
70 return anAsciiEntry;
71}
72
73// =======================================================================
74// function : GetPointerInfo
75// purpose :
76// =======================================================================
77TCollection_AsciiString DFBrowserPane_Tools::GetPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo)
78{
79 std::ostringstream aPtrStr;
80 aPtrStr << thePointer.operator->();
81 if (!isShortInfo)
82 return aPtrStr.str().c_str();
83
84 TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str());
85 for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++)
86 {
87 if (anInfoPtr.Value(aSymbolId) != '0')
88 {
89 anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length());
90 anInfoPtr.Prepend("0x");
91 return anInfoPtr;
92 }
93 }
94 return aPtrStr.str().c_str();
95}
96
97// =======================================================================
98// function : ShapeTypeInfo
99// purpose :
100// =======================================================================
101QVariant DFBrowserPane_Tools::ShapeTypeInfo (const TopoDS_Shape& theShape)
102{
103 return theShape.IsNull() ? QString ("Empty")
104 : QString (DFBrowserPane_Tools::ToName (DB_SHAPE_TYPE, theShape.ShapeType()).ToCString());
105}
106
d2c90917 107// =======================================================================
108// function : LightHighlightColor
109// purpose :
110// =======================================================================
111QColor DFBrowserPane_Tools::LightHighlightColor()
112{
113 QWidget aWidget;
114 QPalette aPalette = aWidget.palette();
115 return aPalette.highlight().color().lighter();
116}
117
14bbbdcb 118// =======================================================================
119// function : ToName
120// purpose :
121// =======================================================================
122TCollection_AsciiString DFBrowserPane_Tools::ToName (const DFBrowserPane_OcctEnumType& theType,
123 const Standard_Integer& theEnumId)
124{
125 Standard_SStream aSStream;
126 switch (theType)
127 {
128 case DB_CONSTRAINT_TYPE: { TDataXtd::Print ((TDataXtd_ConstraintEnum)theEnumId, aSStream); break; }
129 case DB_NAMING_TYPE: { TNaming::Print ((TNaming_NameType)theEnumId, aSStream); break; }
130 case DB_SHAPE_TYPE: { TopAbs::Print ((TopAbs_ShapeEnum)theEnumId, aSStream); break; }
131 case DB_NS_TYPE: { TNaming::Print ((TNaming_Evolution)theEnumId, aSStream); break; }
132 case DB_GEOM_TYPE: { TDataXtd::Print ((TDataXtd_GeometryEnum)theEnumId, aSStream); break; }
133 case DB_DIMENSION_TYPE: { TDataStd::Print ((TDataStd_RealEnum)theEnumId, aSStream); break; }
134 case DB_MATERIAL_TYPE: return Graphic3d_MaterialAspect::MaterialName (theEnumId+1);
135 case DB_DISPLAY_MODE:
136 {
137 switch (theEnumId)
138 {
139 case AIS_WireFrame: return "WireFrame";
140 case AIS_Shaded: return "Shaded";
141 default: return "UNKNOWN DISPLAY MODE";
142 }
143 break;
144 }
145 case DB_ORIENTATION_TYPE: { TopAbs::Print((TopAbs_Orientation)theEnumId, aSStream); break; }
d2c90917 146 case DB_CDM_CAN_CLOSE_STATUS:
147 {
148 switch (theEnumId)
149 {
150 case CDM_CCS_OK: return "OK";
151 case CDM_CCS_NotOpen: return "NotOpen";
152 case CDM_CCS_UnstoredReferenced: return "UnstoredReferenced";
153 case CDM_CCS_ReferenceRejection: return "ReferenceRejection";
154 default: return "UNKNOWN CDM_CanCloseStatus";
155 }
156 break;
157 }
14bbbdcb 158 default: return "UNKNOWN PARAMETER";
159 }
160 return aSStream.str().c_str();
161}