1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <XCAFDoc.hxx>
15 #include <XCAFDoc_ColorType.hxx>
17 #include <TCollection_HAsciiString.hxx>
18 #include <TDF_Reference.hxx>
19 #include <TDF_Tool.hxx>
20 #include <TDataStd_AsciiString.hxx>
21 #include <TDataStd_Integer.hxx>
22 #include <TDataStd_Comment.hxx>
23 #include <TDataStd_ByteArray.hxx>
24 #include <TDataStd_IntegerArray.hxx>
25 #include <TDataStd_Name.hxx>
26 #include <XCAFDoc_LengthUnit.hxx>
27 #include <TDataStd_RealArray.hxx>
28 #include <TDataStd_TreeNode.hxx>
29 #include <TDataStd_UAttribute.hxx>
30 #include <TDocStd_Document.hxx>
31 #include <TNaming_NamedShape.hxx>
32 #include <XCAFDoc_Area.hxx>
33 #include <XCAFDoc_Centroid.hxx>
34 #include <XCAFDoc_Color.hxx>
35 #include <XCAFDoc_DimTol.hxx>
36 #include <XCAFDoc_GraphNode.hxx>
37 #include <XCAFDoc_Material.hxx>
38 #include <XCAFDoc_ShapeMapTool.hxx>
39 #include <XCAFDoc_Volume.hxx>
41 //=======================================================================
42 //function : ShapeRefGUID
44 //=======================================================================
46 const Standard_GUID& XCAFDoc::ShapeRefGUID ()
48 static const Standard_GUID ID ("5b896afe-3adf-11d4-b9b7-0060b0ee281b");
53 //=======================================================================
54 //function : AssemblyGUID
56 //=======================================================================
58 const Standard_GUID& XCAFDoc::AssemblyGUID ()
60 static const Standard_GUID ID ("5b896b00-3adf-11d4-b9b7-0060b0ee281b");
65 //=======================================================================
66 //function : ExternRefGUID
68 //=======================================================================
70 const Standard_GUID& XCAFDoc::ExternRefGUID ()
72 static const Standard_GUID ID ("6b896b01-3adf-11d4-b9b7-0060b0ee281b");
77 //=======================================================================
78 //function : ColorRefGUID
80 //=======================================================================
82 const Standard_GUID& XCAFDoc::ColorRefGUID (const XCAFDoc_ColorType type)
84 static const Standard_GUID IDcol ("efd212e4-6dfd-11d4-b9c8-0060b0ee281b");
85 static const Standard_GUID IDcolSurf ("efd212e5-6dfd-11d4-b9c8-0060b0ee281b");
86 static const Standard_GUID IDcolCurv ("efd212e6-6dfd-11d4-b9c8-0060b0ee281b");
90 case XCAFDoc_ColorGen : return IDcol;
91 case XCAFDoc_ColorSurf: return IDcolSurf;
92 case XCAFDoc_ColorCurv: return IDcolCurv;
97 //=======================================================================
98 //function : DimTolRefGUID
100 //=======================================================================
102 const Standard_GUID& XCAFDoc::DimTolRefGUID()
104 //static const Standard_GUID IDDimTol("58ed092d-44de-11d8-8776-001083004c77");
105 static const Standard_GUID ID("efd212e9-6dfd-11d4-b9c8-0060b0ee281b");
110 //=======================================================================
111 //function : DimensionRefGUID
113 //=======================================================================
115 const Standard_GUID& XCAFDoc::DimensionRefFirstGUID()
117 static const Standard_GUID ID("efd212e3-6dfd-11d4-b9c8-0060b0ee281b");
121 //=======================================================================
122 //function : DimensionRefGUID
124 //=======================================================================
126 const Standard_GUID& XCAFDoc::DimensionRefSecondGUID()
128 static const Standard_GUID ID("efd212e0-6dfd-11d4-b9c8-0060b0ee281b");
132 //=======================================================================
133 //function : GeomToleranceRefGUID
135 //=======================================================================
137 const Standard_GUID& XCAFDoc::GeomToleranceRefGUID()
139 static const Standard_GUID ID("efd213e3-6dfd-11d4-b9c8-0060b0ee281b");
143 //=======================================================================
144 //function : DatumRefGUID
146 //=======================================================================
148 const Standard_GUID& XCAFDoc::DatumRefGUID()
150 static const Standard_GUID ID("efd212e2-6dfd-11d4-b9c8-0060b0ee281b");
155 //=======================================================================
156 //function : DatumTolRefGUID
158 //=======================================================================
160 const Standard_GUID& XCAFDoc::DatumTolRefGUID()
162 //static const Standard_GUID IDDimTol("58ed092d-44de-11d8-8776-001083004c77");
163 static const Standard_GUID ID("efd212e7-6dfd-11d4-b9c8-0060b0ee281b");
169 //=======================================================================
170 //function : LayerRefGUID
172 //=======================================================================
174 const Standard_GUID& XCAFDoc::LayerRefGUID ()
176 static const Standard_GUID ID ("efd212e8-6dfd-11d4-b9c8-0060b0ee281b");
181 //=======================================================================
182 //function : MaterialRefGUID
184 //=======================================================================
186 const Standard_GUID& XCAFDoc::MaterialRefGUID ()
188 static const Standard_GUID ID ("efd212f7-6dfd-11d4-b9c8-0060b0ee281b");
192 //=======================================================================
193 //function : VisMaterialRefGUID
195 //=======================================================================
196 const Standard_GUID& XCAFDoc::VisMaterialRefGUID()
198 static const Standard_GUID ID ("936F4070-5369-405D-A7AD-2AC76C860EC8");
202 //=======================================================================
203 //function : NoteRefGUID
205 //=======================================================================
207 const Standard_GUID& XCAFDoc::NoteRefGUID()
209 static const Standard_GUID ID ("F3599E50-F84A-493e-8D1B-1284E79322F1");
213 //=======================================================================
214 //function : InvisibleGUID
216 //=======================================================================
218 const Standard_GUID& XCAFDoc::InvisibleGUID ()
220 static const Standard_GUID ID ("5b896aff-3adf-11d4-b9b7-0060b0ee281b");
225 //=======================================================================
226 //function : ColorByLayerGUID
228 //=======================================================================
230 const Standard_GUID& XCAFDoc::ColorByLayerGUID ()
232 static const Standard_GUID ID ("279e8c1e-70af-4130-b626-9cc52a537db8");
237 //=======================================================================
238 //function : SHUORefGUID
240 //=======================================================================
242 const Standard_GUID& XCAFDoc::SHUORefGUID ()
244 static const Standard_GUID ID ("efd212ea-6dfd-11d4-b9c8-0060b0ee281b");
248 //=======================================================================
249 //function : ViewRefGUID
251 //=======================================================================
253 const Standard_GUID& XCAFDoc::ViewRefGUID()
255 static const Standard_GUID ID("efd213e5-6dfd-11d4-b9c8-0060b0ee281b");
259 //=======================================================================
260 //function : ViewRefShapeGUID
262 //=======================================================================
264 const Standard_GUID& XCAFDoc::ViewRefShapeGUID()
266 static const Standard_GUID ID("efd213e6-6dfd-11d4-b9c8-0060b0ee281b");
270 //=======================================================================
271 //function : ViewRefGDTGUID
273 //=======================================================================
275 const Standard_GUID& XCAFDoc::ViewRefGDTGUID()
277 static const Standard_GUID ID("efd213e7-6dfd-11d4-b9c8-0060b0ee281b");
281 //=======================================================================
282 //function : ViewRefPlaneGUID
284 //=======================================================================
286 const Standard_GUID& XCAFDoc::ViewRefPlaneGUID()
288 static const Standard_GUID ID("efd213e9-6dfd-11d4-b9c8-0060b0ee281b");
292 //=======================================================================
293 //function : ViewRefPlaneGUID
295 //=======================================================================
297 const Standard_GUID& XCAFDoc::ViewRefNoteGUID()
299 static const Standard_GUID ID("C814ACC6-43AC-4812-9B2A-4E9A2A549354");
303 //=======================================================================
304 //function : ViewRefPlaneGUID
306 //=======================================================================
308 const Standard_GUID& XCAFDoc::ViewRefAnnotationGUID()
310 static const Standard_GUID ID("A2B5BA42-DD00-43f5-8882-4B5F8E76B9D2");
314 //=======================================================================
315 //function : LockGUID
317 //=======================================================================
319 const Standard_GUID& XCAFDoc::LockGUID()
321 static const Standard_GUID ID("efd213eb-6dfd-11d4-b9c8-0060b0ee281b");
325 //=======================================================================
326 //function : AttributeInfo
328 //=======================================================================
329 TCollection_AsciiString XCAFDoc::AttributeInfo (const Handle(TDF_Attribute)& theAtt)
331 TCollection_AsciiString anInfo;
333 if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
334 Standard_CString type = "";
335 if ( theAtt->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
336 else if ( theAtt->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
337 else if ( theAtt->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
338 else if ( theAtt->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
339 else if ( theAtt->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
340 else if ( theAtt->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
341 else if ( theAtt->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
342 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(theAtt);
343 TCollection_AsciiString ref;
344 if ( TN->HasFather() ) {
345 TDF_Tool::Entry ( TN->Father()->Label(), ref );
347 anInfo += TCollection_AsciiString (" ==> ") + ref;
351 anInfo += TCollection_AsciiString (" <== (") + ref;
352 Handle(TDataStd_TreeNode) child = TN->First();
353 while ( ! child.IsNull() ) {
354 TDF_Tool::Entry ( child->Label(), ref );
355 if ( child != TN->First() ) anInfo += ", " ;
357 child = child->Next();
362 else if ( theAtt->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
363 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( theAtt );
364 TCollection_AsciiString ref;
365 TDF_Tool::Entry ( val->Get(), ref );
366 anInfo += TCollection_AsciiString ("==> ") + ref;
368 else if ( theAtt->IsKind(STANDARD_TYPE(TDF_TagSource)) ) {
369 Handle(TDF_TagSource) val = Handle(TDF_TagSource)::DownCast ( theAtt );
370 anInfo += TCollection_AsciiString ( val->Get() );
372 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
373 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( theAtt );
374 anInfo = TCollection_AsciiString ( val->Get() );
376 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
377 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( theAtt );
378 anInfo = TCollection_AsciiString ( val->Get() );
380 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
381 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( theAtt );
382 anInfo = TCollection_AsciiString ( val->Get(), '?' );
384 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
385 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( theAtt );
386 anInfo = TCollection_AsciiString ( val->Get(), '?' );
388 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
389 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( theAtt );
390 anInfo = TCollection_AsciiString ( val->Get(), '?' );
392 else if (theAtt->IsKind(STANDARD_TYPE(XCAFDoc_LengthUnit))) {
393 Handle(XCAFDoc_LengthUnit) aVal = Handle(XCAFDoc_LengthUnit)::DownCast(theAtt);
394 anInfo = TCollection_AsciiString(aVal->GetUnitValue());
395 anInfo += " "; anInfo += aVal->GetUnitName();
397 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
398 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( theAtt );
399 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
400 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
401 anInfo += TCollection_AsciiString ( val->Value(j) );
404 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
405 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( theAtt );
406 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
407 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
408 anInfo += TCollection_AsciiString ( val->Value(j) );
411 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
412 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( theAtt );
413 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
414 if ( j > val->Lower() ) anInfo += TCollection_AsciiString ( ", " );
415 anInfo += TCollection_AsciiString ( val->Value(j) );
418 else if ( theAtt->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
419 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( theAtt );
420 TopoDS_Shape S = val->Get();
422 anInfo = S.TShape()->DynamicType()->Name();
424 anInfo = "Empty Shape";
425 if ( ! S.Location().IsIdentity() ) anInfo += TCollection_AsciiString ( "(located)" );
427 else if ( theAtt->IsKind(STANDARD_TYPE(XCAFDoc_ShapeMapTool)) ) {
429 Handle(XCAFDoc_ShapeMapTool) anAttr = Handle(XCAFDoc_ShapeMapTool)::DownCast ( theAtt );
430 anInfo += TCollection_AsciiString (anAttr->GetMap().Extent());
432 else if ( theAtt->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
433 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( theAtt );
434 anInfo += TCollection_AsciiString ( val->Get() );
436 else if ( theAtt->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
437 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( theAtt );
438 anInfo = TCollection_AsciiString ( val->Get() );
440 else if ( theAtt->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
441 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( theAtt );
442 gp_Pnt myCentroid = val->Get();
444 anInfo += TCollection_AsciiString ( myCentroid.X() );
445 anInfo += TCollection_AsciiString ( " , " );
446 anInfo += TCollection_AsciiString ( TCollection_AsciiString ( myCentroid.Y() ) );
447 anInfo += TCollection_AsciiString ( " , " );
448 anInfo += TCollection_AsciiString ( myCentroid.Z() );
449 anInfo += TCollection_AsciiString ( ")" );
451 else if ( theAtt->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
452 if ( theAtt->ID() == XCAFDoc::AssemblyGUID() ) anInfo += TCollection_AsciiString ( "is assembly" );
453 if ( theAtt->ID() == XCAFDoc::InvisibleGUID() ) anInfo += TCollection_AsciiString ( "invisible" );
455 else if ( theAtt->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
456 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( theAtt );
457 Quantity_ColorRGBA C = val->GetColorRGBA();
459 Sprintf ( string, "%s (%g, %g, %g, %g)", C.GetRGB().StringName ( C.GetRGB().Name() ),
460 C.GetRGB().Red(), C.GetRGB().Green(), C.GetRGB().Blue(), C.Alpha());
463 else if ( theAtt->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
464 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( theAtt );
465 Standard_Integer kind = val->GetKind();
466 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
467 if(kind<20) { //dimension
468 anInfo = "Diameter (ValueRange[";
469 anInfo += TCollection_AsciiString ( HAR->Value(1) );
470 anInfo += TCollection_AsciiString ( "," );
471 anInfo += TCollection_AsciiString ( HAR->Value(2) );
472 anInfo += TCollection_AsciiString ( "])" );
476 case 21: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1"; break;
477 case 22: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2"; break;
478 case 23: anInfo = "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3"; break;
479 case 24: anInfo = "AngularityTolerance"; break;
480 case 25: anInfo = "CircularRunoutTolerance"; break;
481 case 26: anInfo = "CoaxialityTolerance"; break;
482 case 27: anInfo = "ConcentricityTolerance"; break;
483 case 28: anInfo = "ParallelismTolerance"; break;
484 case 29: anInfo = "PerpendicularityTolerance"; break;
485 case 30: anInfo = "SymmetryTolerance"; break;
486 case 31: anInfo = "TotalRunoutTolerance"; break;
487 case 35: anInfo = "ModifiedGeometricTolerance_1"; break;
488 case 36: anInfo = "ModifiedGeometricTolerance_2"; break;
489 case 37: anInfo = "ModifiedGeometricTolerance_3"; break;
490 case 38: anInfo = "CylindricityTolerance"; break;
491 case 39: anInfo = "FlatnessTolerance"; break;
492 case 40: anInfo = "LineProfileTolerance"; break;
493 case 41: anInfo = "PositionTolerance"; break;
494 case 42: anInfo = "RoundnessTolerance"; break;
495 case 43: anInfo = "StraightnessTolerance"; break;
496 case 44: anInfo = "SurfaceProfileTolerance"; break;
498 if (anInfo.Length() > 0) {
499 anInfo += " (Value=";
500 anInfo += TCollection_AsciiString (HAR->Value (1));
505 else if ( theAtt->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
506 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( theAtt );
507 Standard_Real dens = val->GetDensity();
508 Standard_CString dimdens = "g/cu sm";
510 anInfo = val->GetName()->ToCString();
512 anInfo = val->GetName()->ToCString();
513 anInfo += "(density=";
514 anInfo += TCollection_AsciiString ( dens );
519 else if ( theAtt->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
520 Standard_CString type;
521 if ( theAtt->ID() == XCAFDoc::LayerRefGUID() ) {
522 type = "Layer Instance Link";
524 else if ( theAtt->ID() == XCAFDoc::SHUORefGUID() ) {
525 type = "SHUO Instance Link";
527 else if ( theAtt->ID() == XCAFDoc::DatumTolRefGUID() ) {
528 type = "DatumToler Link";
530 else if ( theAtt->ID() == XCAFDoc::DimensionRefFirstGUID() ) {
531 type = "Dimension Link First";
533 else if ( theAtt->ID() == XCAFDoc::DimensionRefSecondGUID() ) {
534 type = "Dimension Link Second";
536 else if ( theAtt->ID() == XCAFDoc::GeomToleranceRefGUID() ){
537 type = "GeomTolerance Link";
539 else if ( theAtt->ID() == XCAFDoc::DatumRefGUID() ){
542 else if (theAtt->ID() == XCAFDoc::ViewRefShapeGUID()){
543 type = "View Shape Link";
545 else if (theAtt->ID() == XCAFDoc::ViewRefGDTGUID()){
546 type = "View GD&T Link";
548 else if (theAtt->ID() == XCAFDoc::ViewRefPlaneGUID()) {
549 type = "View Clipping Plane Link";
552 return TCollection_AsciiString();
554 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(theAtt);
555 TCollection_AsciiString ref;
556 Standard_Integer ii = 1;
557 if (DETGN->NbFathers()!=0) {
559 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
563 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
564 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
571 if (DETGN->NbChildren()!=0) {
572 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
576 for (ii = 2; ii <= DETGN->NbChildren (); ii++) {
577 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );