0030690: Draw Harness - provide XDisplay command for displaying XDE document
[occt.git] / src / XDEDRAW / XDEDRAW.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 02819ba..e624f1c
 // Created on: 2000-08-04
 // Created by: Pavel TELKOV
-// Copyright (c) 2000-2012 OPEN CASCADE SAS
+// Copyright (c) 2000-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 
-#include <XDEDRAW.ixx>
-#include <stdio.h>
-
-#include <TCollection_ExtendedString.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TColStd_HSequenceOfExtendedString.hxx>
-#include <TCollection_HAsciiString.hxx>
-#include <Quantity_Color.hxx>
-
-#include <TopoDS_Shape.hxx>
-
-#include <Draw.hxx>
-#include <DBRep.hxx>
-#include <V3d_Viewer.hxx>
-#include <V3d_View.hxx>
 #include <AIS_InteractiveContext.hxx>
-#include <ViewerTest_Tool.hxx>
-
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Trihedron.hxx>
+#include <Aspect_TypeOfLine.hxx>
+#include <DBRep.hxx>
 #include <DDF_Browser.hxx>
 #include <DDocStd.hxx>
 #include <DDocStd_DrawDocument.hxx>
-
-#include <TDF_Tool.hxx>
+#include <Draw.hxx>
+#include <Draw_PluginMacro.hxx>
+#include <Geom_Axis2Placement.hxx>
+#include <Prs3d_Drawer.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Quantity_Color.hxx>
+#include <STEPCAFControl_Controller.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TCollection_HAsciiString.hxx>
+#include <TColStd_HArray1OfInteger.hxx>
+#include <TColStd_HArray1OfReal.hxx>
+#include <TColStd_HSequenceOfExtendedString.hxx>
+#include <TDataStd_AsciiString.hxx>
+#include <TDataStd_ByteArray.hxx>
+#include <TDataStd_Comment.hxx>
+#include <TDataStd_Integer.hxx>
+#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_Name.hxx>
+#include <TDataStd_Real.hxx>
+#include <TDataStd_RealArray.hxx>
+#include <TDataStd_TreeNode.hxx>
+#include <TDataStd_UAttribute.hxx>
+#include <TDF_AttributeIterator.hxx>
+#include <TDF_ChildIterator.hxx>
 #include <TDF_Data.hxx>
 #include <TDF_LabelSequence.hxx>
-#include <TDF_AttributeIterator.hxx>
 #include <TDF_Reference.hxx>
+#include <TDF_Tool.hxx>
+#include <TDocStd_Application.hxx>
 #include <TDocStd_Document.hxx>
-#include <TDataStd_UAttribute.hxx>
-#include <TDataStd_TreeNode.hxx>
-#include <TDataStd_Integer.hxx>
-#include <TDataStd_Real.hxx>
-#include <TDataStd_Name.hxx>
-#include <TDataStd_Comment.hxx>
-#include <TDataStd_AsciiString.hxx>
+#include <TDocStd_Owner.hxx>
 #include <TNaming_NamedShape.hxx>
-#include <TDataStd_IntegerArray.hxx>
-#include <TDataStd_RealArray.hxx>
-#include <TDataStd_ByteArray.hxx>
+#include <TopoDS_Shape.hxx>
 #include <TPrsStd_AISPresentation.hxx>
-#include <TPrsStd_NamedShapeDriver.hxx>
 #include <TPrsStd_AISViewer.hxx>
-
+#include <TPrsStd_DriverTable.hxx>
+#include <TPrsStd_NamedShapeDriver.hxx>
+#include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
+#include <ViewerTest.hxx>
+#include <ViewerTest_AutoUpdater.hxx>
 #include <XCAFDoc.hxx>
-#include <XCAFDoc_Color.hxx>
-#include <XCAFDoc_Volume.hxx>
 #include <XCAFDoc_Area.hxx>
 #include <XCAFDoc_Centroid.hxx>
-#include <XCAFDoc_ShapeTool.hxx>
+#include <XCAFDoc_Color.hxx>
 #include <XCAFDoc_ColorTool.hxx>
+#include <XCAFDoc_DimTol.hxx>
+#include <XCAFDoc_Dimension.hxx>
+#include <XCAFDoc_Datum.hxx>
+#include <XCAFDoc_GeomTolerance.hxx>
 #include <XCAFDoc_DocumentTool.hxx>
 #include <XCAFDoc_GraphNode.hxx>
 #include <XCAFDoc_LayerTool.hxx>
-#include <XCAFDoc_DimTol.hxx>
 #include <XCAFDoc_Material.hxx>
+#include <XCAFDoc_ShapeTool.hxx>
+#include <XCAFDoc_Volume.hxx>
+#include <XCAFPrs.hxx>
+#include <XCAFPrs_AISObject.hxx>
 #include <XCAFPrs_Driver.hxx>
-#include <XCAFApp_Application.hxx>
-
-#include <XDEDRAW_Shapes.hxx>
+#include <XDEDRAW.hxx>
 #include <XDEDRAW_Colors.hxx>
+#include <XDEDRAW_Common.hxx>
 #include <XDEDRAW_Layers.hxx>
 #include <XDEDRAW_Props.hxx>
-#include <XDEDRAW_Common.hxx>
+#include <XDEDRAW_Shapes.hxx>
+#include <XDEDRAW_GDTs.hxx>
+#include <XDEDRAW_Views.hxx>
+#include <XDEDRAW_Notes.hxx>
+#include <XSDRAW.hxx>
 #include <XSDRAWIGES.hxx>
 #include <XSDRAWSTEP.hxx>
-#include <SWDRAW.hxx>
-#include <XSDRAW.hxx>
-#include <XCAFPrs.hxx>
-#include <ViewerTest.hxx>
-#include <Draw_PluginMacro.hxx>
 
-#include <TColStd_HArray1OfInteger.hxx>
-#include <TColStd_HArray1OfReal.hxx>
+#include <BinXCAFDrivers.hxx>
+#include <XmlXCAFDrivers.hxx>
 
-#define ZVIEW_SIZE 1000000.0
-// avoid warnings on 'extern "C"' functions returning C++ classes
-#ifdef WNT
-#pragma warning(4:4190)
-#endif
+#include <stdio.h>
 
 //=======================================================================
 // Section: General commands
 //=======================================================================
 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc < 2) {di<<"Give document name"<<"\n";return 1;}
+  if (argc < 2) {di<<"Give document name\n";return 1;}
 
   Handle(TDocStd_Document) D;
   Handle(DDocStd_DrawDocument) DD;
-  Handle(TDocStd_Application) A;
-
-  if (!DDocStd::Find(A)) return 1;
+  Handle(TDocStd_Application) A = DDocStd::GetApplication();
 
   if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
-    A->NewDocument(  "MDTV-XCAF"  ,D);
+    A->NewDocument(  "BinXCAF"  ,D);
     DD = new DDocStd_DrawDocument(D);
     TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
     Draw::Set(argv[1],DD);
-    di << "document " << argv[1] << " created" << "\n";
+    di << "document " << argv[1] << " created\n";
     //DDocStd::ReturnLabel(di,D->Main());
   }
-  else di << argv[1] << " is already a document" << "\n";
+  else di << argv[1] << " is already a document\n";
 
   return 0;
 }
@@ -137,8 +137,7 @@ static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, con
 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   Handle(TDocStd_Document) D;
-  Handle(TDocStd_Application) A;
-  if (!DDocStd::Find(A)) return 1;
+  Handle(TDocStd_Application) A = DDocStd::GetApplication();
 
   if (argc == 1) {
     if (A->NbDocuments() < 1) return 1;
@@ -148,19 +147,88 @@ static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, co
     if (!DDocStd::GetDocument(argv[1],D)) return 1;
   }
 
-  if (argc == 3 ) {
+  PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull;
+  if (argc == 3)
+  {
     TCollection_ExtendedString path (argv[2]);
-    A->SaveAs(D,path);
-    return 0;
+    aStatus = A->SaveAs (D, path);
   }
-  if (!D->IsSaved()) {
-    di << "this document has never been saved" << "\n";
+  else if (!D->IsSaved())
+  {
+    std::cout << "Storage error: this document has never been saved\n";
     return 1;
   }
-  A->Save(D);
+  else
+  {
+    aStatus = A->Save(D);
+  }
+
+  switch (aStatus)
+  {
+    case PCDM_SS_OK:
+      break;
+    case PCDM_SS_DriverFailure:
+      di << "Storage error: driver failure\n";
+      break;
+    case PCDM_SS_WriteFailure:
+      di << "Storage error: write failure\n";
+      break;
+    case PCDM_SS_Failure:
+      di << "Storage error: general failure\n";
+      break;
+    case PCDM_SS_Doc_IsNull:
+      di << "Storage error: document is NULL\n";
+      break;
+    case PCDM_SS_No_Obj:
+      di << "Storage error: no object\n";
+      break;
+    case PCDM_SS_Info_Section_Error:
+      di << "Storage error: section error\n";
+      break;
+  }
+
   return 0;
 }
 
+//=======================================================================
+//function : openDoc
+//purpose  :
+//=======================================================================
+static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+  Handle(TDocStd_Document) D;
+  Handle(DDocStd_DrawDocument) DD;
+  Handle(TDocStd_Application) A = DDocStd::GetApplication();
+
+  if ( argc != 3 )
+  {
+    di << "invalid number of arguments. Usage:\t XOpen filename docname\n";
+    return 1;
+  }
+
+  Standard_CString Filename = argv[1];
+  Standard_CString DocName = argv[2];
+
+  if ( DDocStd::GetDocument(DocName, D, Standard_False) )
+  {
+    di << "document with name " << DocName << " already exists\n";
+    return 1;
+  }
+
+  if ( A->Open(Filename, D) != PCDM_RS_OK )
+  {
+    di << "cannot open XDE document\n";
+    return 1;
+  }
+
+  DD = new DDocStd_DrawDocument(D);
+  TDataStd_Name::Set(D->GetData()->Root(), DocName);
+  Draw::Set(DocName, DD);
+
+  di << "document " << DocName << " opened\n";
+
+  return 0;
+}
 
 //=======================================================================
 //function : dump
@@ -169,17 +237,19 @@ static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, co
 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   if (argc<2) {
-    di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n";
+    di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]\n";
     return 1;
   }
   Handle(TDocStd_Document) Doc;
   DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
+  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
   Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
   Standard_Boolean deep = Standard_False;
-  if ( (argc==3) && (atoi(argv[2])==1) ) deep = Standard_True;
-  myAssembly->Dump(deep);
+  if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True;
+  Standard_SStream aDumpLog;
+  myAssembly->Dump(aDumpLog, deep);
+  di<<aDumpLog;
   return 0;
 }
 
@@ -237,21 +307,49 @@ static void StatAssembly(const TDF_Label L,
     NbAreaProp++;
   }
   Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
-  Quantity_Color col;
+  Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
+  Quantity_ColorRGBA col;
   Standard_Boolean IsColor = Standard_False;
+  Standard_Boolean IsByLayer = Standard_False;
   if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
     IsColor = Standard_True;
   else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
     IsColor = Standard_True;
   else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
     IsColor = Standard_True;
-  if(IsColor) {
-    TCollection_AsciiString Entry1;
-    Entry1 = col.StringName(col.Name());
-    if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
-    NbShapesWithColor++;
+  else if(CTool->IsColorByLayer(L))
+    IsByLayer = Standard_True;
+  if(IsColor || IsByLayer) {
+    if(IsByLayer)
+    {
+      Handle(TColStd_HSequenceOfExtendedString) aLayerS;
+      LTool->GetLayers(L, aLayerS);
+      // Currently for DXF pnly, thus
+      // only 1 Layer should be.
+      if(aLayerS->Length() == 1)
+      {
+        TDF_Label aLayer = LTool->FindLayer (aLayerS->First());
+        Quantity_ColorRGBA aColor;
+        if (CTool->GetColor (aLayer, XCAFDoc_ColorGen, aColor))
+        {
+          TCollection_AsciiString aColorName = aColor.GetRGB().StringName(aColor.GetRGB().Name());
+          di<<"Color(" << aColorName.ToCString() << ") ";
+        }
+        else
+        {
+          di<<"Color(ByLayer) ";
+        }
+      }
+      NbShapesWithColor++;
+    }
+    else
+    {
+      TCollection_AsciiString Entry1;
+      Entry1 = col.GetRGB().StringName(col.GetRGB().Name());
+      if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<" "<<col.Alpha()<<") ";
+      NbShapesWithColor++;
+    }
   }
-  Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
   Handle(TColStd_HSequenceOfExtendedString) aLayerS;
   LTool->GetLayers(L, aLayerS);
   if(!aLayerS.IsNull() && aLayerS->Length()>0) {
@@ -262,7 +360,7 @@ static void StatAssembly(const TDF_Label L,
         if(i==1)
           di<<"\""<<Entry2.ToCString()<<"\"";
         else
-          di<<" "<<"\""<<Entry2.ToCString()<<"\"";
+          di<<" \""<<Entry2.ToCString()<<"\"";
       }
       di<<") ";
     }
@@ -289,12 +387,12 @@ static void StatAssembly(const TDF_Label L,
 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   if (argc<2) {
-    di<<"Use: "<<argv[0]<<" Doc "<<"\n";
+    di<<"Use: "<<argv[0]<<" Doc \n";
     return 1;
   }
   Handle(TDocStd_Document) Doc;   
   DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
+  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
   Standard_Boolean PrintStructMode = (argc==3);
   Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
@@ -302,7 +400,7 @@ static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, co
   TDF_LabelSequence SeqLabels;
   aTool->GetShapes(SeqLabels);
   if(SeqLabels.Length()<=0) return 0;
-  if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n";
+  if(PrintStructMode) di<<"\nStructure of shapes in the document:\n";
   Standard_Integer level=0;
   Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
   Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
@@ -315,7 +413,7 @@ static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, co
                  NbShapesWithLayer, Doc, PrintStructMode, di);
   }
   Standard_Integer NbLabelsShape = 0;
-  di<<"\n"<<"Statistis of shapes in the document:"<<"\n";
+  di<<"\nStatistis of shapes in the document:\n";
   for(i=0; i<=20; i++) {
     if(HAI->Value(i)==0) break;
     //di<<"level N "<<i<<" :  number of labels with shape = "<<HAI->Value(i)<<"\n";
@@ -327,7 +425,7 @@ static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, co
   di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
   di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
 
-  di<<"\n"<<"Statistis of Props in the document:"<<"\n";
+  di<<"\nStatistis of Props in the document:\n";
   di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
   di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
   di<<"Number of Area Props = "<<NbAreaProp<<"\n";
@@ -335,7 +433,7 @@ static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, co
   Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
   TDF_LabelSequence CLabels;
   CTool->GetColors(CLabels);
-  di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n";
+  di<<"\nNumber of colors = "<<CLabels.Length()<<"\n";
   if(CLabels.Length()>0) {
     for(i=1; i<=CLabels.Length(); i++) {
       TDF_Label aLabel = CLabels.Value(i);
@@ -349,7 +447,7 @@ static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, co
   Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
   TDF_LabelSequence LLabels;
   LTool->GetLayerLabels(LLabels);
-  di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n";
+  di<<"\nNumber of layers = "<<LLabels.Length()<<"\n";
   if(LLabels.Length()>0) {
     for(i=1; i<=LLabels.Length(); i++) {
       TDF_Label aLabel = LLabels.Value(i);
@@ -373,13 +471,13 @@ static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, co
 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   if (argc <2) {
-    di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
+    di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
     return 1;
   }
 
   Handle(TDocStd_Document) Doc;
   DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
+  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
   // collect sequence of labels to set presentation
   Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
@@ -424,41 +522,35 @@ static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, con
 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   if (argc <2) {
-    di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
+    di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
     return 1;
   }
 
-  Handle(TDocStd_Document) Doc;
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << argv[1] << " is not a document\n";
+    return 1;
+  }
 
   // init viewer
-//  char string[260];
-//  sprintf ( string, "AISInitViewer %s", argv[1] );
-//  di.Eval ( string );
-  TDF_Label acces = Doc->GetData()->Root();
-  Handle(TPrsStd_AISViewer) viewer;
-  if (!TPrsStd_AISViewer::Find (acces,viewer)) {
-    TCollection_AsciiString title;
-    title.Prepend(argv[1]);
-    title.Prepend("_");
-    title.Prepend("Document");
-    Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString());
-    viewer = TPrsStd_AISViewer::New (acces,vw);
-  }
-  ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
-
-  //szv:CAX-TRJ7 c2-pe-214.stp was clipped
-  viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE);
-  //DDF::ReturnLabel(di,viewer->Label());
+  TDF_Label aRoot = aDoc->GetData()->Root();
+  Handle(TPrsStd_AISViewer) aDocViewer;
+  TCollection_AsciiString   aViewName = TCollection_AsciiString ("Driver1/Document_") + argv[1] + "/View1";
+  if (!TPrsStd_AISViewer::Find (aRoot, aDocViewer))
+  {
+    ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), "");
+    aDocViewer = TPrsStd_AISViewer::New (aRoot, ViewerTest::GetAISContext());
+  }
 
   // collect sequence of labels to display
-  Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
+  Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
   TDF_LabelSequence seq;
   if ( argc >2 ) {
     for ( Standard_Integer i=2; i < argc; i++ ) {
       TDF_Label aLabel;
-      TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
+      TDF_Tool::Label (aDoc->GetData(), argv[i], aLabel);
       if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
        di << argv[i] << " is not a valid shape label!";
        continue;
@@ -485,10 +577,292 @@ static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const
 //      prs->SetColor ( Col.Name() );
     prs->Display(Standard_True);
   }
-  TPrsStd_AISViewer::Update(Doc->GetData()->Root());
+  TPrsStd_AISViewer::Update (aDoc->GetData()->Root());
   return 0;
 }
 
+//! XDisplay command implementation.
+class XDEDRAW_XDisplayTool
+{
+public:
+  //! XDisplay command interface.
+  static Standard_Integer XDisplay (Draw_Interpretor& theDI,
+                                    Standard_Integer theNbArgs,
+                                    const char** theArgVec)
+  {
+    XDEDRAW_XDisplayTool aTool;
+    return aTool.xdisplay (theDI, theNbArgs, theArgVec);
+  }
+
+private:
+  //! Constructor.
+  XDEDRAW_XDisplayTool()
+  : myDispMode(-2),
+    myHiMode  (-2),
+    myToPrefixDocName (Standard_True),
+    myToGetNames (Standard_True),
+    myToExplore  (Standard_False) {}
+
+  //! Display single label.
+  Standard_Integer displayLabel (Draw_Interpretor& theDI,
+                                 const TDF_Label& theLabel,
+                                 const TCollection_AsciiString& theNamePrefix,
+                                 const TopLoc_Location& theLoc)
+  {
+    TCollection_AsciiString aName;
+    if (myToGetNames)
+    {
+      Handle(TDataStd_Name) aNodeName;
+      if (theLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
+      {
+        aName = aNodeName->Get();
+      }
+      if (aName.IsEmpty())
+      {
+        TDF_Label aRefLabel;
+        if (XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel)
+         && aRefLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
+        {
+          aName = aNodeName->Get();
+        }
+      }
+
+      if (aName.IsEmpty())
+      {
+        TDF_Tool::Entry (theLabel, aName);
+      }
+      for (Standard_Integer aNameIndex = 1;; ++aNameIndex)
+      {
+        if (myNameMap.Add (aName))
+        {
+          break;
+        }
+        aName = aNodeName->Get() + "_" + aNameIndex;
+      }
+    }
+    else
+    {
+      TDF_Tool::Entry (theLabel, aName);
+    }
+    aName = theNamePrefix + aName;
+
+    if (myToExplore)
+    {
+      TDF_Label aRefLabel = theLabel;
+      XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel);
+      if (XCAFDoc_ShapeTool::IsAssembly (aRefLabel))
+      {
+        aName += "/";
+        const TopLoc_Location aLoc = theLoc * XCAFDoc_ShapeTool::GetLocation (theLabel);
+        for (TDF_ChildIterator aChildIter (aRefLabel); aChildIter.More(); aChildIter.Next())
+        {
+          if (displayLabel (theDI, aChildIter.Value(), aName, aLoc) == 1)
+          {
+            return 1;
+          }
+        }
+        return 0;
+      }
+    }
+
+    Handle(XCAFPrs_AISObject) aPrs = new XCAFPrs_AISObject (theLabel);
+    if (!theLoc.IsIdentity())
+    {
+      aPrs->SetLocalTransformation (theLoc);
+    }
+    if (myDispMode != -2)
+    {
+      if (myDispMode == -1)
+      {
+        aPrs->UnsetDisplayMode();
+      }
+      if (!aPrs->AcceptDisplayMode (myDispMode))
+      {
+        std::cout << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myDispMode << " display mode\n";
+        return 1;
+      }
+      else
+      {
+        aPrs->SetDisplayMode (myDispMode);
+      }
+    }
+    if (myHiMode != -2)
+    {
+      if (myHiMode != -1
+      && !aPrs->AcceptDisplayMode (myHiMode))
+      {
+        std::cout << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myHiMode << " display mode\n";
+        return 1;
+      }
+      aPrs->SetHilightMode (myHiMode);
+    }
+
+    ViewerTest::Display (aName, aPrs, false);
+    theDI << aName << " ";
+    return 0;
+  }
+
+  //! XDisplay command implementation.
+  Standard_Integer xdisplay (Draw_Interpretor& theDI,
+                             Standard_Integer theNbArgs,
+                             const char** theArgVec)
+  {
+    Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+    if (aContext.IsNull())
+    {
+      std::cout << "Error: no active view!\n";
+      return 1;
+    }
+
+    ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
+    for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
+    {
+      TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+      anArgCase.LowerCase();
+      if (anAutoUpdater.parseRedrawMode (anArgCase))
+      {
+        continue;
+      }
+      else if (anArgIter + 1 < theNbArgs
+            && myDispMode == -2
+            && (anArgCase == "-dispmode"
+             || anArgCase == "-displaymode")
+            && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
+      {
+        myDispMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue();
+      }
+      else if (anArgIter + 1 < theNbArgs
+            && myHiMode == -2
+            && (anArgCase == "-himode"
+             || anArgCase == "-highmode"
+             || anArgCase == "-highlightmode")
+            && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
+      {
+        myHiMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue();
+      }
+      else if (anArgCase == "-docprefix"
+            || anArgCase == "-nodocprefix")
+      {
+        myToPrefixDocName = Standard_True;
+        if (anArgIter + 1 < theNbArgs
+         && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToPrefixDocName))
+        {
+          ++anArgIter;
+        }
+        if (anArgCase.StartsWith ("-no"))
+        {
+          myToPrefixDocName = !myToPrefixDocName;
+        }
+      }
+      else if (anArgCase == "-names"
+            || anArgCase == "-nonames")
+      {
+        myToGetNames = Standard_True;
+        if (anArgIter + 1 < theNbArgs
+         && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToGetNames))
+        {
+          ++anArgIter;
+        }
+        if (anArgCase.StartsWith ("-no"))
+        {
+          myToGetNames = !myToGetNames;
+        }
+      }
+      else if (anArgCase == "-explore"
+            || anArgCase == "-noexplore")
+      {
+        myToExplore = Standard_True;
+        if (anArgIter + 1 < theNbArgs
+         && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToExplore))
+        {
+          ++anArgIter;
+        }
+        if (anArgCase.StartsWith ("-no"))
+        {
+          myToExplore = !myToExplore;
+        }
+      }
+      else
+      {
+        if (myDoc.IsNull()
+         && DDocStd::GetDocument (theArgVec[anArgIter], myDoc, Standard_False))
+        {
+          myDocName = theArgVec[anArgIter];
+          continue;
+        }
+
+        TCollection_AsciiString aValue (theArgVec[anArgIter]);
+        const Standard_Integer aFirstSplit = aValue.Search (":");
+        if (!IsDigit (aValue.Value (1))
+          && aFirstSplit >= 2
+          && aFirstSplit < aValue.Length())
+        {
+          TCollection_AsciiString aDocName = aValue.SubString (1, aFirstSplit - 1);
+          Standard_CString aDocNameStr = aDocName.ToCString();
+          Handle(TDocStd_Document) aDoc;
+          if (DDocStd::GetDocument (aDocNameStr, aDoc, Standard_False))
+          {
+            aValue = aValue.SubString (aFirstSplit + 1, aValue.Length());
+            if (!myDoc.IsNull()
+              && myDoc != aDoc)
+            {
+              std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
+              return 1;
+            }
+            myDoc = aDoc;
+            myDocName = aDocName;
+          }
+        }
+        if (myDoc.IsNull())
+        {
+          std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
+          return 1;
+        }
+
+        TDF_Label aLabel;
+        TDF_Tool::Label (myDoc->GetData(), aValue.ToCString(), aLabel);
+        if (aLabel.IsNull()
+        || !XCAFDoc_ShapeTool::IsShape (aLabel))
+        {
+          std::cout << "Syntax error: " << aValue << " is not a valid shape label\n";
+          return 1;
+        }
+        myLabels.Append (aLabel);
+      }
+    }
+    if (myDoc.IsNull())
+    {
+      std::cout << "Syntax error: not enough arguments\n";
+      return 1;
+    }
+    if (myLabels.IsEmpty())
+    {
+      XCAFDoc_DocumentTool::ShapeTool (myDoc->Main())->GetFreeShapes (myLabels);
+    }
+
+    for (TDF_LabelSequence::Iterator aLabIter (myLabels); aLabIter.More(); aLabIter.Next())
+    {
+      const TDF_Label& aLabel = aLabIter.Value();
+      if (displayLabel (theDI, aLabel, myToPrefixDocName ? myDocName + ":" : "", TopLoc_Location()) == 1)
+      {
+        return 1;
+      }
+    }
+    return 0;
+  }
+
+private:
+  NCollection_Map<TCollection_AsciiString, TCollection_AsciiString>
+                           myNameMap;         //!< names map to handle collisions
+  Handle(TDocStd_Document) myDoc;             //!< document
+  TCollection_AsciiString  myDocName;         //!< document name
+  TDF_LabelSequence        myLabels;          //!< labels to display
+  Standard_Integer         myDispMode;        //!< shape display mode
+  Standard_Integer         myHiMode;          //!< shape highlight mode
+  Standard_Boolean         myToPrefixDocName; //!< flag to prefix objects with document name
+  Standard_Boolean         myToGetNames;      //!< flag to use label names or tags
+  Standard_Boolean         myToExplore;       //!< flag to explore assembles
+};
 
 //=======================================================================
 //function : xwd
@@ -497,13 +871,13 @@ static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const
 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   if (argc <3) {
-    di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n";
+    di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}\n";
     return 1;
   }
 
   Handle(TDocStd_Document) Doc;
   DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
+  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
   Handle(AIS_InteractiveContext) IC;
   if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
@@ -511,10 +885,11 @@ static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const
     return 1;
   }
 
-  Handle(V3d_Viewer) viewer = IC->CurrentViewer();
-  viewer->InitActiveViews();
-  if ( viewer->MoreActiveViews() ) {
-    viewer->ActiveView()->Dump ( argv[2] );
+  Handle(V3d_Viewer) aViewer = IC->CurrentViewer();
+  V3d_ListOfViewIterator aViewIter = aViewer->ActiveViewIterator();
+  if (aViewIter.More())
+  {
+    aViewIter.Value()->Dump ( argv[2] );
   }
   else {
     di << "Cannot find an active view in a viewer " << argv[1] << "\n";
@@ -531,20 +906,19 @@ static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const
 //=======================================================================
 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; }
-  Handle(DDF_Browser) browser =
-    Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
-  if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
+  if ( argc < 4 ) { std::cout << "Syntax error: Too few args\n"; return 1; }
+  Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1]));
+  if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; }
 
   TDF_Label lab;
   TDF_Tool::Label(browser->Data(),argv[2],lab);
-  if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
+  if ( lab.IsNull() ) { std::cout << "Syntax error: label is Null: " << argv[2] << "\n"; return 1; }
 
-  Standard_Integer num = atoi ( argv[3] );
+  Standard_Integer num = Draw::Atoi ( argv[3] );
   TDF_AttributeIterator itr(lab,Standard_False);
   for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
 
-  if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; }
+  if ( ! itr.More() ) { std::cout << "Syntax error: Attribute #" << num << " not found\n"; return 1; }
 
   const Handle(TDF_Attribute)& att = itr.Value();
   if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
@@ -662,10 +1036,10 @@ static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer
   }
   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
     Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
-    Quantity_Color C = val->GetColor();
+    Quantity_ColorRGBA C = val->GetColorRGBA();
     char string[260];
-    sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
-             C.Red(), C.Green(), C.Blue() );
+    Sprintf ( string, "%s (%g, %g, %g, %g)", C.GetRGB().StringName ( C.GetRGB().Name() ),
+      C.GetRGB().Red(), C.GetRGB().Green(), C.GetRGB().Blue(), C.Alpha());
     di << string;
   }
   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
@@ -721,6 +1095,27 @@ static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer
     else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
       type = "DatumToler Link";
     }
+    else if ( att->ID() == XCAFDoc::DimensionRefFirstGUID() ) {
+      type = "Dimension Link First";
+    }
+    else if ( att->ID() == XCAFDoc::DimensionRefSecondGUID() ) {
+      type = "Dimension Link Second";
+    }
+    else if ( att->ID() == XCAFDoc::GeomToleranceRefGUID() ){
+      type = "GeomTolerance Link";
+    }
+    else if ( att->ID() == XCAFDoc::DatumRefGUID() ){
+      type = "Datum Link";
+    }
+    else if (att->ID() == XCAFDoc::ViewRefShapeGUID()){
+      type = "View Shape Link";
+    }
+    else if (att->ID() == XCAFDoc::ViewRefGDTGUID()){
+      type = "View GD&T Link";
+    }
+    else if (att->ID() == XCAFDoc::ViewRefPlaneGUID()) {
+      type = "View Clipping Plane Link";
+    }
     else return 0;
 
     Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
@@ -758,11 +1153,11 @@ static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer
 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   if (argc <2) {
-    di<<"Use: "<<argv[0]<<" (1/0)"<<"\n";
+    di<<"Use: "<<argv[0]<<" (1/0)\n";
     return 1;
   }
   Standard_Boolean mode = Standard_False;
-  if (atoi(argv[1]) == 1) mode = Standard_True;
+  if (Draw::Atoi(argv[1]) == 1) mode = Standard_True;
   XCAFPrs::SetViewNameMode(mode);
   return 0;
 }
@@ -775,8 +1170,8 @@ static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc
 
 static Standard_Integer getviewName (Draw_Interpretor&  di, Standard_Integer /*argc*/, const char** /*argv*/)
 {
-  if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n";
-  else di << "Display names OFF"<< "\n";
+  if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON\n";
+  else di << "Display names OFF\n";
   return 0;
 }
 
@@ -788,15 +1183,15 @@ static Standard_Integer getviewName (Draw_Interpretor&  di, Standard_Integer /*a
 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   if (argc < 3) {
-    di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] "<<"\n";
+    di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] \n";
     return 1;
   }
 
   Handle(TDocStd_Document) Doc;
   DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
+  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
-  const Standard_Real aTransparency = atof(argv[2]);
+  const Standard_Real aTransparency = Draw::Atof(argv[2]);
 
   // collect sequence of labels
   Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
@@ -829,6 +1224,184 @@ static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer
   return 0;
 }
 
+//=======================================================================
+//function : XShowFaceBoundary
+//purpose  : Set face boundaries on/off
+//=======================================================================
+static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
+                                           Standard_Integer argc,
+                                           const char ** argv)
+{
+  if (( argc != 4 && argc < 7 ) || argc > 9)
+  {
+    di << "Usage :\n " << argv[0]
+       << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
+       << "   Doc       - is the document name. \n"
+       << "   Label     - is the shape label. \n"
+       << "   IsOn      - flag indicating whether the boundaries\n"
+       << "                should be turned on or off (can be set\n"
+       << "                to 0 (off) or 1 (on)).\n"
+       << "   R, G, B   - red, green and blue components of boundary\n"
+       << "                color in range (0 - 255).\n"
+       << "                (default is (0, 0, 0)\n"
+       << "   LineWidth - line width\n"
+       << "                (default is 1)\n"
+       << "   LineStyle - line fill style :\n"
+       << "                 0 - solid  \n"
+       << "                 1 - dashed \n"
+       << "                 2 - dot    \n"
+       << "                 3 - dashdot\n"
+       << "                (default is solid)";
+
+    return 1;
+  }
+
+  // get specified document
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    di << argv[1] << " is not a document\n"; 
+    return 1;
+  }
+
+  Handle(AIS_InteractiveContext) aContext;
+  if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext)) 
+  {
+    di << "Cannot find viewer for document " << argv[1] << "\n";
+    return 1;
+  }
+
+  // get shape tool for shape verification
+  Handle(XCAFDoc_ShapeTool) aShapes =
+    XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
+
+  // get label and validate that it is a shape label
+  TDF_Label aLabel;
+  TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+  if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
+  {
+    di << argv[2] << " is not a valid shape label!";
+    return 1;
+  }
+
+  // get presentation from label
+  Handle(TPrsStd_AISPresentation) aPrs;
+  if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
+  {
+    aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
+  }
+
+  Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
+  if (anInteractive.IsNull ())
+  {
+    di << "Can't set drawer attributes.\n"
+          "Interactive object for shape label doesn't exists.";
+    return 1;
+  }
+
+  // get drawer
+  const Handle(Prs3d_Drawer)& aDrawer = anInteractive->Attributes ();
+
+  // default attributes
+  Standard_Real aRed   = 0.0;
+  Standard_Real aGreen = 0.0;
+  Standard_Real aBlue  = 0.0;
+  Standard_Real aWidth = 1.0;
+  Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
+  
+  // turn boundaries on/off
+  Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1);
+  aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
+  
+  // set boundary color
+  if (argc >= 7)
+  {
+    // Text color
+    aRed   = Draw::Atof (argv[4])/255.;
+    aGreen = Draw::Atof (argv[5])/255.;
+    aBlue  = Draw::Atof (argv[6])/255.;
+  }
+
+  // set line width
+  if (argc >= 8)
+  {
+    aWidth = (Standard_Real)Draw::Atof (argv[7]);
+  }
+
+  // select appropriate line type
+  if (argc == 9)
+  {
+    if (!ViewerTest::ParseLineType (argv[8], aLineType))
+    {
+      std::cout << "Syntax error: unknown line type '" << argv[8] << "'\n";
+    }
+  }
+
+  Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
+
+  Handle(Prs3d_LineAspect) aBoundaryAspect = 
+    new Prs3d_LineAspect (aColor, aLineType, aWidth);
+
+  aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
+
+  aContext->Redisplay (anInteractive, Standard_True);
+  
+  return 0;
+}
+
+//=======================================================================
+//function : testDoc
+//purpose  : Method to test destruction of document
+//=======================================================================
+static Standard_Integer testDoc (Draw_Interpretor&,
+                                 Standard_Integer argc,
+                                 const char ** argv)
+{
+  if( argc < 2 )
+  {
+    cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<endl;
+    return 1;
+  }
+  TopoDS_Shape shape = DBRep::Get(argv[1]);
+  if( shape.IsNull())
+    return 1;
+  Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
+  Handle(TDocStd_Document) aD1 = new TDocStd_Document("BinXCAF");
+  aD1->Open(anApp);
+  
+  TCollection_AsciiString  aViewName ("Driver1/DummyDocument/View1");
+  ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), "");
+  TPrsStd_AISViewer::New (aD1->GetData()->Root(), ViewerTest::GetAISContext());
+
+  // get shape tool for shape verification
+  Handle(XCAFDoc_ShapeTool) aShapes =
+    XCAFDoc_DocumentTool::ShapeTool (aD1->Main());
+  TDF_Label aLab = aShapes->AddShape(shape);
+
+  Handle(Geom_Axis2Placement) aPlacement = 
+    new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX());
+  Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement);
+  
+  Handle(TNaming_NamedShape) NS;
+  Handle(TPrsStd_AISPresentation) prs;
+  if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) {
+    prs = TPrsStd_AISPresentation::Set( NS );
+  }
+   
+  if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) ) 
+    prs->Display();
+
+  TPrsStd_AISViewer::Update(aLab);
+  ViewerTest::GetAISContext()->Display (aTriShape, Standard_True);
+  aD1->BeforeClose();
+  aD1->Close();
+  ViewerTest::RemoveView (aViewName);
+  return 0;
+}
+
 
 //=======================================================================
 //function : Init
@@ -837,23 +1410,24 @@ static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer
 
 void XDEDRAW::Init(Draw_Interpretor& di)
 {
-
   static Standard_Boolean initactor = Standard_False;
-  if (initactor) return;  initactor = Standard_True;
-
-  // OCAF *** szy: use <pload> command
+  if (initactor)
+  {
+    return;
+  }
+  initactor = Standard_True;
 
-//  DDF::AllCommands(di);
-//  DNaming::AllCommands(di);
-//  DDataStd::AllCommands(di);
-//  DPrsStd::AllCommands(di);
-  //DFunction::AllCommands(di);
-//  DDocStd::AllCommands(di);
+  // Load static variables for STEPCAF (ssv; 16.08.2012)
+  STEPCAFControl_Controller::Init();
 
-//  ViewerTest::Commands (di); *** szy: use <pload> command
+  // Initialize XCAF formats
+  Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
+  BinXCAFDrivers::DefineFormat(anApp);
+  XmlXCAFDrivers::DefineFormat(anApp);
 
-  // init XCAF application (if not yet done)
-  XCAFApp_Application::GetApplication();
+  // Register driver in global table for displaying XDE documents 
+  // in 3d viewer using OCAF mechanics
+  TPrsStd_DriverTable::Get()->AddDriver (XCAFPrs_Driver::GetID(), new XCAFPrs_Driver);
 
   //=====================================
   // General commands
@@ -867,6 +1441,9 @@ void XDEDRAW::Init(Draw_Interpretor& di)
   di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
                   __FILE__, saveDoc, g);
 
+  di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path",
+          __FILE__, openDoc, g);
+
   di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
                   __FILE__, dump, g);
 
@@ -879,6 +1456,17 @@ void XDEDRAW::Init(Draw_Interpretor& di)
   di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
                   __FILE__, show, g);
 
+  di.Add ("XDisplay",
+          "XDisplay Doc [label1 [label2 [...]]] [-explore {on|off}] [-docPrefix {on|off}] [-names {on|off}]"
+          "\n\t\t:      [-noupdate] [-dispMode Mode] [-highMode Mode]"
+          "\n\t\t: Displays document (parts) in 3D Viewer."
+          "\n\t\t:  -dispMode    Presentation display mode."
+          "\n\t\t:  -highMode    Presentation highlight mode."
+          "\n\t\t:  -docPrefix   Prepend document name to object names; TRUE by default."
+          "\n\t\t:  -names       Use object names instead of label tag; TRUE by default."
+          "\n\t\t:  -explore     Explode labels to leaves; FALSE by default.",
+          __FILE__, XDEDRAW_XDisplayTool::XDisplay, g);
+
   di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
                   __FILE__, xwd, g);
 
@@ -894,11 +1482,20 @@ void XDEDRAW::Init(Draw_Interpretor& di)
   di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
                   __FILE__, XSetTransparency, g);
 
+  di.Add ("XShowFaceBoundary", 
+          "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
+          "- turns on/off drawing of face boundaries and defines boundary line style",
+          __FILE__, XShowFaceBoundary, g);
+   di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g);
+
   // Specialized commands
   XDEDRAW_Shapes::InitCommands ( di );
   XDEDRAW_Colors::InitCommands ( di );
   XDEDRAW_Layers::InitCommands ( di );
   XDEDRAW_Props::InitCommands ( di );
+  XDEDRAW_GDTs::InitCommands ( di );
+  XDEDRAW_Views::InitCommands(di);
+  XDEDRAW_Notes::InitCommands(di);
   XDEDRAW_Common::InitCommands ( di );//moved from EXE
 
 }
@@ -915,13 +1512,12 @@ void XDEDRAW::Factory(Draw_Interpretor& theDI)
 
   XSDRAWSTEP::InitCommands(theDI);
 
-  SWDRAW::Init(theDI);
   XSDRAW::LoadDraw(theDI);
 
   XDEDRAW::Init(theDI);
 
-#ifdef DEB
-      theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n";
+#ifdef OCCT_DEBUG
+      theDI << "Draw Plugin : All TKXDEDRAW commands are loaded\n";
 #endif
 }