0030268: Inspectors - improvements in VInspector plugin
[occt.git] / tools / DFBrowserPaneXDE / DFBrowserPaneXDE_XDEDRAW.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/DFBrowserPaneXDE_XDEDRAW.hxx>
14bbbdcb 17
18#include <TCollection_AsciiString.hxx>
19#include <TCollection_HAsciiString.hxx>
20#include <TColStd_HArray1OfReal.hxx>
21
22#include <TDataStd_AsciiString.hxx>
23#include <TDataStd_ByteArray.hxx>
24#include <TDataStd_Comment.hxx>
25#include <TDataStd_Integer.hxx>
26#include <TDataStd_IntegerArray.hxx>
27#include <TDataStd_Name.hxx>
28#include <TDataStd_Real.hxx>
29#include <TDataStd_RealArray.hxx>
30#include <TDataStd_TreeNode.hxx>
31#include <TDataStd_UAttribute.hxx>
32
33#include <TDF_Reference.hxx>
34#include <TDF_Tool.hxx>
35
36#include <TNaming_NamedShape.hxx>
37#include <TopoDS_Shape.hxx>
38
39#include <XCAFDoc.hxx>
40#include <XCAFDoc_Area.hxx>
41#include <XCAFDoc_Centroid.hxx>
42#include <XCAFDoc_Color.hxx>
43#include <XCAFDoc_ColorTool.hxx>
44#include <XCAFDoc_DimTol.hxx>
14bbbdcb 45#include <XCAFDoc_Dimension.hxx>
46#include <XCAFDoc_GeomTolerance.hxx>
14bbbdcb 47#include <XCAFDoc_Datum.hxx>
48#include <XCAFDoc_DocumentTool.hxx>
49#include <XCAFDoc_GraphNode.hxx>
50#include <XCAFDoc_LayerTool.hxx>
51#include <XCAFDoc_Material.hxx>
52#include <XCAFDoc_ShapeTool.hxx>
53#include <XCAFDoc_Volume.hxx>
54
55// =======================================================================
56// function : GetAttributeInfo
57// purpose :
58// =======================================================================
59TCollection_AsciiString DFBrowserPaneXDE_XDEDRAW::GetAttributeInfo (Handle(TDF_Attribute) att)
60{
61 TCollection_AsciiString anInfo;
62
63 if ( att->IsKind(STANDARD_TYPE (TDataStd_TreeNode)) ) {
64 Standard_CString type = "";
65 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
66 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
67 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
68 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
69 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
70 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
71 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
72 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast (att);
73 TCollection_AsciiString ref;
74 if ( TN->HasFather() ) {
75 TDF_Tool::Entry ( TN->Father()->Label(), ref );
76 anInfo = type;
77 anInfo += TCollection_AsciiString (" ==> ") + ref.ToCString();
78 }
79 else {
80 anInfo = type;
81 anInfo += TCollection_AsciiString (" <== (") + ref.ToCString();
82 Handle(TDataStd_TreeNode) child = TN->First();
83 while ( ! child.IsNull() ) {
84 TDF_Tool::Entry ( child->Label(), ref );
85 if ( child != TN->First() ) anInfo += ", " ;
86 anInfo += ref.ToCString();
87 child = child->Next();
88 }
89 anInfo += ")";
90 }
91 }
92 else if ( att->IsKind(STANDARD_TYPE (TDF_Reference)) ) {
93 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
94 TCollection_AsciiString ref;
95 TDF_Tool::Entry ( val->Get(), ref );
96 anInfo += TCollection_AsciiString ("==> ") + ref.ToCString();
97 }
98 else if ( att->IsKind(STANDARD_TYPE (TDataStd_Integer)) ) {
99 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
100 anInfo = TCollection_AsciiString ( val->Get() );
101 }
102 else if ( att->IsKind(STANDARD_TYPE (TDataStd_Real)) ) {
103 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
104 anInfo = TCollection_AsciiString ( val->Get() );
105 }
106 else if ( att->IsKind(STANDARD_TYPE (TDataStd_Name)) ) {
107 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
108 anInfo = TCollection_AsciiString ( val->Get(), '?' );
109 }
110 else if ( att->IsKind(STANDARD_TYPE (TDataStd_Comment)) ) {
111 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
112 anInfo = TCollection_AsciiString ( val->Get(), '?' );
113 }
114 else if ( att->IsKind(STANDARD_TYPE (TDataStd_AsciiString)) ) {
115 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
116 anInfo = TCollection_AsciiString ( val->Get(), '?' );
117 }
118 else if ( att->IsKind(STANDARD_TYPE (TDataStd_IntegerArray)) ) {
119 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
120 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
121 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
122 anInfo += TCollection_AsciiString ( val->Value(j) );
123 }
124 }
125 else if ( att->IsKind(STANDARD_TYPE (TDataStd_RealArray)) ) {
126 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
127 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
128 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
129 anInfo += TCollection_AsciiString ( val->Value(j) );
130 }
131 }
132 else if ( att->IsKind(STANDARD_TYPE (TDataStd_ByteArray)) ) {
133 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
134 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
135 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
136 anInfo += TCollection_AsciiString ( val->Value(j) );
137 }
138 }
139 else if ( att->IsKind(STANDARD_TYPE (TNaming_NamedShape)) ) {
140 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
141 TopoDS_Shape S = val->Get();
142 if (!S.IsNull())
143 anInfo = S.TShape()->DynamicType()->Name();
144 else
145 anInfo = "Empty Shape";
146 if ( ! S.Location().IsIdentity() ) anInfo += TCollection_AsciiString ( "(located)" );
147 }
148 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Volume)) ) {
149 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
150 anInfo += TCollection_AsciiString ( val->Get() );
151 }
152 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Area)) ) {
153 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
154 TCollection_AsciiString str ( val->Get() );
155 anInfo = str.ToCString();
156 }
157 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Centroid)) ) {
158 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
159 gp_Pnt myCentroid = val->Get();
160 anInfo = "(" ;
161 anInfo += TCollection_AsciiString ( myCentroid.X() ).ToCString();
162 anInfo += TCollection_AsciiString ( " , " );
163 anInfo += TCollection_AsciiString ( TCollection_AsciiString ( myCentroid.Y() ).ToCString() );
164 anInfo += TCollection_AsciiString ( " , " );
165 anInfo += TCollection_AsciiString ( myCentroid.Z() ).ToCString();
166 anInfo += TCollection_AsciiString ( ")" );
167 }
168 else if ( att->IsKind(STANDARD_TYPE (TDataStd_UAttribute)) ) {
169 if ( att->ID() == XCAFDoc::AssemblyGUID() ) anInfo += TCollection_AsciiString ( "is assembly" );
170 if ( att->ID() == XCAFDoc::InvisibleGUID() ) anInfo += TCollection_AsciiString ( "invisible" );
171 }
172 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Color)) ) {
173 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
174 Quantity_Color C = val->GetColor();
175 char string[260];
176 Sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
177 C.Red(), C.Green(), C.Blue() );
178 anInfo = string;
179 }
180 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_DimTol)) ) {
181 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
182 Standard_Integer kind = val->GetKind();
183 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
184 if(kind<20) { //dimension
185 anInfo = "Diameter (ValueRange[";
186 anInfo += TCollection_AsciiString ( HAR->Value(1) );
187 anInfo += TCollection_AsciiString ( "," );
188 anInfo += TCollection_AsciiString ( HAR->Value(2) );
189 anInfo += TCollection_AsciiString ( "])" );
190 }
191 else {
192 switch (kind) {
193 case 21: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1"; break;
194 case 22: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2"; break;
195 case 23: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3"; break;
196 case 24: anInfo = "AngularityTolerance"; break;
197 case 25: anInfo = "CircularRunoutTolerance"; break;
198 case 26: anInfo = "CoaxialityTolerance"; break;
199 case 27: anInfo = "ConcentricityTolerance"; break;
200 case 28: anInfo = "ParallelismTolerance"; break;
201 case 29: anInfo = "PerpendicularityTolerance"; break;
202 case 30: anInfo = "SymmetryTolerance"; break;
203 case 31: anInfo = "TotalRunoutTolerance"; break;
204 case 35: anInfo = "ModifiedGeometricTolerance_1"; break;
205 case 36: anInfo = "ModifiedGeometricTolerance_2"; break;
206 case 37: anInfo = "ModifiedGeometricTolerance_3"; break;
207 case 38: anInfo = "CylindricityTolerance"; break;
208 case 39: anInfo = "FlatnessTolerance"; break;
209 case 40: anInfo = "LineProfileTolerance"; break;
210 case 41: anInfo = "PositionTolerance"; break;
211 case 42: anInfo = "RoundnessTolerance"; break;
212 case 43: anInfo = "StraightnessTolerance"; break;
213 case 44: anInfo = "SurfaceProfileTolerance"; break;
214 }
215 if (anInfo.Length() > 0) {
216 anInfo += " (Value=";
217 anInfo += TCollection_AsciiString (HAR->Value (1));
218 anInfo += ")";
219 }
220 }
221 }
222 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Material)) ) {
223 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
224 Standard_Real dens = val->GetDensity();
225 Standard_CString dimdens = "g/cu sm";
226 if(dens==0)
227 anInfo = val->GetName()->ToCString();
228 else {
229 anInfo = val->GetName()->ToCString();
230 anInfo += "(density=";
231 anInfo += TCollection_AsciiString ( dens );
232 anInfo += dimdens;
233 anInfo += ")";
234 }
235 }
236 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_GraphNode)) ) {
237 Standard_CString type;
238 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
239 type = "Layer Instance Link";
240 }
241 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
242 type = "SHUO Instance Link";
243 }
244 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
245 type = "DatumToler Link";
246 }
14bbbdcb 247 else if ( att->ID() == XCAFDoc::DimensionRefFirstGUID() ) {
248 type = "Dimension Link First";
249 }
250 else if ( att->ID() == XCAFDoc::DimensionRefSecondGUID() ) {
251 type = "Dimension Link Second";
252 }
253 else if ( att->ID() == XCAFDoc::GeomToleranceRefGUID() ){
254 type = "GeomTolerance Link";
255 }
14bbbdcb 256 else
257 return TCollection_AsciiString();
258
259 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast (att);
260 TCollection_AsciiString ref;
261 Standard_Integer ii = 1;
262 if (DETGN->NbFathers()!=0) {
263
264 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
265 anInfo = type;
266 anInfo += " ==> (";
267 anInfo += ref;
268 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
269 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
270 anInfo += ", ";
271 anInfo += ref.ToCString();
272 }
273 anInfo += ") ";
274 }
275 ii = 1;
276 if (DETGN->NbChildren ()!=0) {
277 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
278 anInfo += type;
279 anInfo += " <== (";
280 anInfo += ref;
281 for (ii = 2; ii <= DETGN->NbChildren (); ii++) {
282 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
283 anInfo += ", ";
284 anInfo += ref;
285 }
286 anInfo += ") ";
287 }
288 }
289 return anInfo;
290}