0027398: Integrate Qt Browser Widget to Open CASCADE Technology
[occt.git] / tools / DFBrowserPane / DFBrowserPane_Tools.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 <DFBrowserPane_Tools.hxx>
17
18 #include <AIS_DisplayMode.hxx>
19 #include <Graphic3d_MaterialAspect.hxx>
20 #include <Graphic3d_NameOfMaterial.hxx>
21 #include <Standard_Version.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TDataStd.hxx>
24 #include <TDataStd_RealEnum.hxx>
25 #include <TDataXtd.hxx>
26 #include <TDataXtd_ConstraintEnum.hxx>
27 #include <TDataXtd_GeometryEnum.hxx>
28 #include <TDF_Tool.hxx>
29 #include <TNaming.hxx>
30 #include <TNaming_NameType.hxx>
31 #include <TNaming_Evolution.hxx>
32 #include <TopAbs.hxx>
33 #include <TopAbs_ShapeEnum.hxx>
34 #include <TopAbs_Orientation.hxx>
35
36 #include <QApplication>
37 #include <QStringList>
38 #include <QStyle>
39
40 #include <sstream>
41
42 //#define REQUIRE_OCAF_REVIEW:8 : start
43 const int TABLE_COLUMN_0_WIDTH = 200;
44 const int TABLE_COLUMN_OTHER_WIDTH = 120;
45
46 // =======================================================================
47 // function : DefaultPanelColumnWidth
48 // purpose :
49 // =======================================================================
50 int DFBrowserPane_Tools::DefaultPanelColumnWidth (const int theColumnId)
51 {
52   return theColumnId == 0 ? TABLE_COLUMN_0_WIDTH : TABLE_COLUMN_OTHER_WIDTH;
53 }
54
55 // =======================================================================
56 // function : GetEntry
57 // purpose :
58 // =======================================================================
59 TCollection_AsciiString DFBrowserPane_Tools::GetEntry (const TDF_Label& theLabel)
60 {
61   if (theLabel.IsNull())
62     return "Null";
63
64   TCollection_AsciiString anAsciiEntry;
65   TDF_Tool::Entry(theLabel, anAsciiEntry);
66   return anAsciiEntry;
67 }
68
69 // =======================================================================
70 // function : GetPointerInfo
71 // purpose :
72 // =======================================================================
73 TCollection_AsciiString DFBrowserPane_Tools::GetPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo)
74 {
75   std::ostringstream aPtrStr;
76   aPtrStr << thePointer.operator->();
77   if (!isShortInfo)
78     return aPtrStr.str().c_str();
79
80   TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str());
81   for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++)
82   {
83     if (anInfoPtr.Value(aSymbolId) != '0')
84     {
85       anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length());
86       anInfoPtr.Prepend("0x");
87       return anInfoPtr;
88     }
89   }
90   return aPtrStr.str().c_str();
91 }
92
93 // =======================================================================
94 // function : ShapeTypeInfo
95 // purpose :
96 // =======================================================================
97 QVariant DFBrowserPane_Tools::ShapeTypeInfo (const TopoDS_Shape& theShape)
98 {
99   return theShape.IsNull() ? QString ("Empty")
100                            : QString (DFBrowserPane_Tools::ToName (DB_SHAPE_TYPE, theShape.ShapeType()).ToCString());
101 }
102
103 // =======================================================================
104 // function : ToName
105 // purpose :
106 // =======================================================================
107 TCollection_AsciiString DFBrowserPane_Tools::ToName (const DFBrowserPane_OcctEnumType& theType,
108                                                      const Standard_Integer& theEnumId)
109 {
110   Standard_SStream aSStream;
111   switch (theType)
112   {
113     case DB_CONSTRAINT_TYPE: { TDataXtd::Print ((TDataXtd_ConstraintEnum)theEnumId, aSStream); break; }
114     case DB_NAMING_TYPE:     { TNaming::Print ((TNaming_NameType)theEnumId, aSStream); break; }
115     case DB_SHAPE_TYPE:      { TopAbs::Print ((TopAbs_ShapeEnum)theEnumId, aSStream); break; }
116     case DB_NS_TYPE:         { TNaming::Print ((TNaming_Evolution)theEnumId, aSStream); break; }
117     case DB_GEOM_TYPE:       { TDataXtd::Print ((TDataXtd_GeometryEnum)theEnumId, aSStream); break; }
118     case DB_DIMENSION_TYPE:  { TDataStd::Print ((TDataStd_RealEnum)theEnumId, aSStream); break; }
119     case DB_MATERIAL_TYPE:   return Graphic3d_MaterialAspect::MaterialName (theEnumId+1);
120     case DB_DISPLAY_MODE:
121     {
122       switch (theEnumId)
123       {
124         case AIS_WireFrame: return "WireFrame";
125         case AIS_Shaded: return "Shaded";
126         default: return "UNKNOWN DISPLAY MODE";
127       }
128       break;
129     }
130     case DB_ORIENTATION_TYPE: { TopAbs::Print((TopAbs_Orientation)theEnumId, aSStream); break; }
131     default: return "UNKNOWN PARAMETER";
132   }
133   return aSStream.str().c_str();
134 }
135 //#define REQUIRE_OCAF_REVIEW:8 : end