1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <inspector/DFBrowserPaneXDE_XDEDRAW.hxx>
18 #include <TCollection_AsciiString.hxx>
19 #include <TCollection_HAsciiString.hxx>
20 #include <TColStd_HArray1OfReal.hxx>
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>
33 #include <TDF_Reference.hxx>
34 #include <TDF_Tool.hxx>
36 #include <TNaming_NamedShape.hxx>
37 #include <TopoDS_Shape.hxx>
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>
45 #include <Standard_Version.hxx>
46 #if OCC_VERSION_HEX > 0x060901
47 #include <XCAFDoc_Dimension.hxx>
48 #include <XCAFDoc_GeomTolerance.hxx>
50 #include <XCAFDoc_Datum.hxx>
51 #include <XCAFDoc_DocumentTool.hxx>
52 #include <XCAFDoc_GraphNode.hxx>
53 #include <XCAFDoc_LayerTool.hxx>
54 #include <XCAFDoc_Material.hxx>
55 #include <XCAFDoc_ShapeTool.hxx>
56 #include <XCAFDoc_Volume.hxx>
58 // =======================================================================
59 // function : GetAttributeInfo
61 // =======================================================================
62 TCollection_AsciiString DFBrowserPaneXDE_XDEDRAW::GetAttributeInfo (Handle(TDF_Attribute) att)
64 TCollection_AsciiString anInfo;
66 if ( att->IsKind(STANDARD_TYPE (TDataStd_TreeNode)) ) {
67 Standard_CString type = "";
68 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
69 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
70 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
71 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
72 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
73 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
74 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
75 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast (att);
76 TCollection_AsciiString ref;
77 if ( TN->HasFather() ) {
78 TDF_Tool::Entry ( TN->Father()->Label(), ref );
80 anInfo += TCollection_AsciiString (" ==> ") + ref.ToCString();
84 anInfo += TCollection_AsciiString (" <== (") + ref.ToCString();
85 Handle(TDataStd_TreeNode) child = TN->First();
86 while ( ! child.IsNull() ) {
87 TDF_Tool::Entry ( child->Label(), ref );
88 if ( child != TN->First() ) anInfo += ", " ;
89 anInfo += ref.ToCString();
90 child = child->Next();
95 else if ( att->IsKind(STANDARD_TYPE (TDF_Reference)) ) {
96 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
97 TCollection_AsciiString ref;
98 TDF_Tool::Entry ( val->Get(), ref );
99 anInfo += TCollection_AsciiString ("==> ") + ref.ToCString();
101 else if ( att->IsKind(STANDARD_TYPE (TDataStd_Integer)) ) {
102 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
103 anInfo = TCollection_AsciiString ( val->Get() );
105 else if ( att->IsKind(STANDARD_TYPE (TDataStd_Real)) ) {
106 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
107 anInfo = TCollection_AsciiString ( val->Get() );
109 else if ( att->IsKind(STANDARD_TYPE (TDataStd_Name)) ) {
110 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
111 anInfo = TCollection_AsciiString ( val->Get(), '?' );
113 else if ( att->IsKind(STANDARD_TYPE (TDataStd_Comment)) ) {
114 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
115 anInfo = TCollection_AsciiString ( val->Get(), '?' );
117 else if ( att->IsKind(STANDARD_TYPE (TDataStd_AsciiString)) ) {
118 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
119 anInfo = TCollection_AsciiString ( val->Get(), '?' );
121 else if ( att->IsKind(STANDARD_TYPE (TDataStd_IntegerArray)) ) {
122 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
123 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
124 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
125 anInfo += TCollection_AsciiString ( val->Value(j) );
128 else if ( att->IsKind(STANDARD_TYPE (TDataStd_RealArray)) ) {
129 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
130 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
131 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
132 anInfo += TCollection_AsciiString ( val->Value(j) );
135 else if ( att->IsKind(STANDARD_TYPE (TDataStd_ByteArray)) ) {
136 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
137 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
138 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
139 anInfo += TCollection_AsciiString ( val->Value(j) );
142 else if ( att->IsKind(STANDARD_TYPE (TNaming_NamedShape)) ) {
143 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
144 TopoDS_Shape S = val->Get();
146 anInfo = S.TShape()->DynamicType()->Name();
148 anInfo = "Empty Shape";
149 if ( ! S.Location().IsIdentity() ) anInfo += TCollection_AsciiString ( "(located)" );
151 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Volume)) ) {
152 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
153 anInfo += TCollection_AsciiString ( val->Get() );
155 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Area)) ) {
156 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
157 TCollection_AsciiString str ( val->Get() );
158 anInfo = str.ToCString();
160 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Centroid)) ) {
161 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
162 gp_Pnt myCentroid = val->Get();
164 anInfo += TCollection_AsciiString ( myCentroid.X() ).ToCString();
165 anInfo += TCollection_AsciiString ( " , " );
166 anInfo += TCollection_AsciiString ( TCollection_AsciiString ( myCentroid.Y() ).ToCString() );
167 anInfo += TCollection_AsciiString ( " , " );
168 anInfo += TCollection_AsciiString ( myCentroid.Z() ).ToCString();
169 anInfo += TCollection_AsciiString ( ")" );
171 else if ( att->IsKind(STANDARD_TYPE (TDataStd_UAttribute)) ) {
172 if ( att->ID() == XCAFDoc::AssemblyGUID() ) anInfo += TCollection_AsciiString ( "is assembly" );
173 if ( att->ID() == XCAFDoc::InvisibleGUID() ) anInfo += TCollection_AsciiString ( "invisible" );
175 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Color)) ) {
176 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
177 Quantity_Color C = val->GetColor();
179 Sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
180 C.Red(), C.Green(), C.Blue() );
183 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_DimTol)) ) {
184 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
185 Standard_Integer kind = val->GetKind();
186 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
187 if(kind<20) { //dimension
188 anInfo = "Diameter (ValueRange[";
189 anInfo += TCollection_AsciiString ( HAR->Value(1) );
190 anInfo += TCollection_AsciiString ( "," );
191 anInfo += TCollection_AsciiString ( HAR->Value(2) );
192 anInfo += TCollection_AsciiString ( "])" );
196 case 21: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1"; break;
197 case 22: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2"; break;
198 case 23: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3"; break;
199 case 24: anInfo = "AngularityTolerance"; break;
200 case 25: anInfo = "CircularRunoutTolerance"; break;
201 case 26: anInfo = "CoaxialityTolerance"; break;
202 case 27: anInfo = "ConcentricityTolerance"; break;
203 case 28: anInfo = "ParallelismTolerance"; break;
204 case 29: anInfo = "PerpendicularityTolerance"; break;
205 case 30: anInfo = "SymmetryTolerance"; break;
206 case 31: anInfo = "TotalRunoutTolerance"; break;
207 case 35: anInfo = "ModifiedGeometricTolerance_1"; break;
208 case 36: anInfo = "ModifiedGeometricTolerance_2"; break;
209 case 37: anInfo = "ModifiedGeometricTolerance_3"; break;
210 case 38: anInfo = "CylindricityTolerance"; break;
211 case 39: anInfo = "FlatnessTolerance"; break;
212 case 40: anInfo = "LineProfileTolerance"; break;
213 case 41: anInfo = "PositionTolerance"; break;
214 case 42: anInfo = "RoundnessTolerance"; break;
215 case 43: anInfo = "StraightnessTolerance"; break;
216 case 44: anInfo = "SurfaceProfileTolerance"; break;
218 if (anInfo.Length() > 0) {
219 anInfo += " (Value=";
220 anInfo += TCollection_AsciiString (HAR->Value (1));
225 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_Material)) ) {
226 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
227 Standard_Real dens = val->GetDensity();
228 Standard_CString dimdens = "g/cu sm";
230 anInfo = val->GetName()->ToCString();
232 anInfo = val->GetName()->ToCString();
233 anInfo += "(density=";
234 anInfo += TCollection_AsciiString ( dens );
239 else if ( att->IsKind(STANDARD_TYPE (XCAFDoc_GraphNode)) ) {
240 Standard_CString type;
241 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
242 type = "Layer Instance Link";
244 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
245 type = "SHUO Instance Link";
247 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
248 type = "DatumToler Link";
250 #if OCC_VERSION_HEX > 0x060901
251 else if ( att->ID() == XCAFDoc::DimensionRefFirstGUID() ) {
252 type = "Dimension Link First";
254 else if ( att->ID() == XCAFDoc::DimensionRefSecondGUID() ) {
255 type = "Dimension Link Second";
257 else if ( att->ID() == XCAFDoc::GeomToleranceRefGUID() ){
258 type = "GeomTolerance Link";
262 return TCollection_AsciiString();
264 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast (att);
265 TCollection_AsciiString ref;
266 Standard_Integer ii = 1;
267 if (DETGN->NbFathers()!=0) {
269 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
273 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
274 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
276 anInfo += ref.ToCString();
281 if (DETGN->NbChildren ()!=0) {
282 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
286 for (ii = 2; ii <= DETGN->NbChildren (); ii++) {
287 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );