49d6c2685b3db12c14ff33e8606efd7c57d48994
[occt.git] / src / XDEDRAW / XDEDRAW.cxx
1 // Created on: 2000-08-04
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-2014 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 <XSDRAW.hxx>
17
18 #include <AIS_InteractiveContext.hxx>
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_Trihedron.hxx>
21 #include <Aspect_TypeOfLine.hxx>
22 #include <BRepBuilderAPI_Transform.hxx>
23 #include <DBRep.hxx>
24 #include <DDF_Browser.hxx>
25 #include <DDocStd.hxx>
26 #include <DDocStd_DrawDocument.hxx>
27 #include <DE_Wrapper.hxx>
28 #include <DEBRepCascade_ConfigurationNode.hxx>
29 #include <DEXCAFCascade_ConfigurationNode.hxx>
30 #include <Draw.hxx>
31 #include <Draw_PluginMacro.hxx>
32 #include <Draw_ProgressIndicator.hxx>
33 #include <Geom_Axis2Placement.hxx>
34 #include <IGESCAFControl_ConfigurationNode.hxx>
35 #include <Prs3d_Drawer.hxx>
36 #include <Prs3d_LineAspect.hxx>
37 #include <Quantity_Color.hxx>
38 #include <RWStl_ConfigurationNode.hxx>
39 #include <RWGltf_ConfigurationNode.hxx>
40 #include <RWObj_ConfigurationNode.hxx>
41 #include <RWPly_ConfigurationNode.hxx>
42 #include <STEPCAFControl_Controller.hxx>
43 #include <STEPCAFControl_ConfigurationNode.hxx>
44 #include <TCollection_AsciiString.hxx>
45 #include <TCollection_ExtendedString.hxx>
46 #include <TCollection_HAsciiString.hxx>
47 #include <TColStd_HArray1OfInteger.hxx>
48 #include <TColStd_HArray1OfReal.hxx>
49 #include <TColStd_HSequenceOfExtendedString.hxx>
50 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
51 #include <TDataStd_AsciiString.hxx>
52 #include <TDataStd_ByteArray.hxx>
53 #include <TDataStd_Comment.hxx>
54 #include <TDataStd_Integer.hxx>
55 #include <TDataStd_IntegerArray.hxx>
56 #include <XCAFDoc_LengthUnit.hxx>
57 #include <TDataStd_Name.hxx>
58 #include <TDataStd_Real.hxx>
59 #include <TDataStd_RealArray.hxx>
60 #include <TDataStd_TreeNode.hxx>
61 #include <TDataStd_UAttribute.hxx>
62 #include <TDF_AttributeIterator.hxx>
63 #include <TDF_ChildIterator.hxx>
64 #include <TDF_Data.hxx>
65 #include <TDF_LabelSequence.hxx>
66 #include <TDF_Reference.hxx>
67 #include <TDF_Tool.hxx>
68 #include <TDocStd_Application.hxx>
69 #include <TDocStd_Document.hxx>
70 #include <TDocStd_Owner.hxx>
71 #include <PCDM_ReaderFilter.hxx>
72 #include <TNaming_NamedShape.hxx>
73 #include <TopoDS_Shape.hxx>
74 #include <TPrsStd_AISPresentation.hxx>
75 #include <TPrsStd_AISViewer.hxx>
76 #include <TPrsStd_DriverTable.hxx>
77 #include <TPrsStd_NamedShapeDriver.hxx>
78 #include <V3d_View.hxx>
79 #include <V3d_Viewer.hxx>
80 #include <ViewerTest.hxx>
81 #include <ViewerTest_AutoUpdater.hxx>
82 #include <Vrml_ConfigurationNode.hxx>
83 #include <XCAFDoc.hxx>
84 #include <XCAFDoc_AssemblyIterator.hxx>
85 #include <XCAFDoc_AssemblyGraph.hxx>
86 #include <XCAFDoc_AssemblyTool.hxx>
87 #include <XCAFDoc_Area.hxx>
88 #include <XCAFDoc_Centroid.hxx>
89 #include <XCAFDoc_Color.hxx>
90 #include <XCAFDoc_ColorTool.hxx>
91 #include <XCAFDoc_DimTol.hxx>
92 #include <XCAFDoc_Dimension.hxx>
93 #include <XCAFDoc_Datum.hxx>
94 #include <XCAFDoc_Editor.hxx>
95 #include <XCAFDoc_GeomTolerance.hxx>
96 #include <XCAFDoc_DocumentTool.hxx>
97 #include <XCAFDoc_GraphNode.hxx>
98 #include <XCAFDoc_LayerTool.hxx>
99 #include <XCAFDoc_Material.hxx>
100 #include <XCAFDoc_ShapeTool.hxx>
101 #include <XCAFDoc_Volume.hxx>
102 #include <XCAFPrs.hxx>
103 #include <XCAFPrs_AISObject.hxx>
104 #include <XCAFPrs_Driver.hxx>
105 #include <XDEDRAW.hxx>
106 #include <XDEDRAW_Colors.hxx>
107 #include <XDEDRAW_Common.hxx>
108 #include <XDEDRAW_Layers.hxx>
109 #include <XDEDRAW_Props.hxx>
110 #include <XDEDRAW_Shapes.hxx>
111 #include <XDEDRAW_GDTs.hxx>
112 #include <XDEDRAW_Views.hxx>
113 #include <XDEDRAW_Notes.hxx>
114 #include <XSDRAWIGES.hxx>
115 #include <XSDRAWSTEP.hxx>
116 #include <UnitsMethods.hxx>
117
118 #include <BinXCAFDrivers.hxx>
119 #include <XmlXCAFDrivers.hxx>
120
121 #include <stdio.h>
122
123 //=======================================================================
124 // Section: General commands
125 //=======================================================================
126
127 //=======================================================================
128 //function : newDoc
129 //purpose  :
130 //=======================================================================
131 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
132 {
133   if (argc < 2) {di<<"Give document name\n";return 1;}
134
135   Handle(TDocStd_Document) D;
136   Handle(DDocStd_DrawDocument) DD;
137   Handle(TDocStd_Application) A = DDocStd::GetApplication();
138
139   if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
140     A->NewDocument(  "BinXCAF"  ,D);
141     DD = new DDocStd_DrawDocument(D);
142     TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
143     Draw::Set(argv[1],DD);
144     di << "document " << argv[1] << " created\n";
145     //DDocStd::ReturnLabel(di,D->Main());
146   }
147   else di << argv[1] << " is already a document\n";
148
149   return 0;
150 }
151
152
153 //=======================================================================
154 //function : saveDoc
155 //purpose  :
156 //=======================================================================
157 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
158 {
159   Handle(TDocStd_Document) D;
160   Handle(TDocStd_Application) A = DDocStd::GetApplication();
161
162   if (argc == 1) {
163     if (A->NbDocuments() < 1) return 1;
164     A->GetDocument(1, D);
165   }
166   else {
167     if (!DDocStd::GetDocument(argv[1],D)) return 1;
168   }
169
170   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
171
172   PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull;
173   if (argc == 3)
174   {
175     TCollection_ExtendedString path (argv[2]);
176     aStatus = A->SaveAs (D, path, aProgress->Start());
177   }
178   else if (!D->IsSaved())
179   {
180     std::cout << "Storage error: this document has never been saved\n";
181     return 1;
182   }
183   else
184   {
185     aStatus = A->Save (D, aProgress->Start());
186   }
187
188   switch (aStatus)
189   {
190     case PCDM_SS_OK:
191       break;
192     case PCDM_SS_DriverFailure:
193       di << "Storage error: driver failure\n";
194       break;
195     case PCDM_SS_WriteFailure:
196       di << "Storage error: write failure\n";
197       break;
198     case PCDM_SS_Failure:
199       di << "Storage error: general failure\n";
200       break;
201     case PCDM_SS_Doc_IsNull:
202       di << "Storage error: document is NULL\n";
203       break;
204     case PCDM_SS_No_Obj:
205       di << "Storage error: no object\n";
206       break;
207     case PCDM_SS_Info_Section_Error:
208       di << "Storage error: section error\n";
209       break;
210     case PCDM_SS_UserBreak:
211       di << "Storage error: user break\n";
212       break;
213     case PCDM_SS_UnrecognizedFormat:
214       di << "Storage error: unrecognized document storage format " << D->StorageFormat() << "\n";
215       break;
216   }
217
218   return 0;
219 }
220
221 //=======================================================================
222 //function : openDoc
223 //purpose  :
224 //=======================================================================
225 static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
226 {
227   Handle(TDocStd_Document) D;
228   Handle(DDocStd_DrawDocument) DD;
229   Handle(TDocStd_Application) A = DDocStd::GetApplication();
230
231   if ( argc < 3 )
232   {
233     di << "invalid number of arguments. Usage:\t XOpen filename docname [-skipAttribute] [-readAttribute] [-readPath] [-append|-overwrite]\n";
234     return 1;
235   }
236
237   TCollection_AsciiString Filename = argv[1];
238   Standard_CString DocName = argv[2];
239
240   Handle(PCDM_ReaderFilter) aFilter = new PCDM_ReaderFilter;
241   for (Standard_Integer i = 3; i < argc; i++)
242   {
243     TCollection_AsciiString anArg(argv[i]);
244     if (anArg == "-append")
245     {
246       aFilter->Mode() = PCDM_ReaderFilter::AppendMode_Protect;
247     }
248     else if (anArg == "-overwrite")
249     {
250       aFilter->Mode() = PCDM_ReaderFilter::AppendMode_Overwrite;
251     }
252     else if (anArg.StartsWith("-skip"))
253     {
254       TCollection_AsciiString anAttrType = anArg.SubString(6, anArg.Length());
255       aFilter->AddSkipped(anAttrType);
256     }
257     else if (anArg.StartsWith("-read"))
258     {
259       TCollection_AsciiString aValue = anArg.SubString(6, anArg.Length());
260       if (aValue.Value(1) == '0') // path
261       {
262         aFilter->AddPath(aValue);
263       }
264       else // attribute to read
265       {
266         aFilter->AddRead(aValue);
267       }
268     }
269   }
270
271   if (aFilter->IsAppendMode() && !DDocStd::GetDocument (DocName, D, Standard_False))
272   {
273     di << "for append mode document " << DocName << " must be already created\n";
274     return 1;
275   }
276
277   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
278   if ( A->Open (Filename, D, aFilter, aProgress->Start()) != PCDM_RS_OK )
279   {
280     di << "cannot open XDE document\n";
281     return 1;
282   }
283
284   if (!aFilter->IsAppendMode())
285   {
286     DD = new DDocStd_DrawDocument (D);
287     TDataStd_Name::Set (D->GetData()->Root(), DocName);
288     Draw::Set (DocName, DD);
289   }
290
291   di << "document " << DocName << " opened\n";
292
293   return 0;
294 }
295
296 //=======================================================================
297 //function : dump
298 //purpose  :
299 //=======================================================================
300 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
301 {
302   if (argc<2) {
303     di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]\n";
304     return 1;
305   }
306   Handle(TDocStd_Document) Doc;
307   DDocStd::GetDocument(argv[1], Doc);
308   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
309
310   Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
311   Standard_Boolean deep = Standard_False;
312   if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True;
313   Standard_SStream aDumpLog;
314   myAssembly->Dump(aDumpLog, deep);
315   di<<aDumpLog;
316   return 0;
317 }
318
319
320 //=======================================================================
321 //function : StatAssembly
322 //purpose  : recursive part of statistics
323 //=======================================================================
324
325 static void StatAssembly(const TDF_Label L,
326                          const Standard_Integer level,
327                          Handle(TColStd_HArray1OfInteger) &HAI,
328                          Standard_Integer &NbCentroidProp,
329                          Standard_Integer &NbVolumeProp,
330                          Standard_Integer &NbAreaProp,
331                          Standard_Integer &NbShapesWithName,
332                          Standard_Integer &NbShapesWithColor,
333                          Standard_Integer &NbShapesWithLayer,
334                          Handle(TDocStd_Document) &aDoc,
335                          Standard_Boolean &PrintStructMode,
336                          Draw_Interpretor& di)
337 {
338   if(PrintStructMode) {
339     for(Standard_Integer j=0; j<=level; j++)
340       di<<"  ";
341   }
342   TCollection_AsciiString Entry;
343   TDF_Tool::Entry(L, Entry);
344   if(PrintStructMode) di<<Entry.ToCString();
345
346   Handle(TDataStd_Name) Name;
347   if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
348     NbShapesWithName++;
349     if(PrintStructMode) {
350       di << " " << Name->Get() << "  has attributes: ";
351     }
352   }
353   else {
354     if(PrintStructMode) di<<" NoName  has attributes: ";
355   }
356
357   Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
358   if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
359     if(PrintStructMode) di<<"Centroid ";
360     NbCentroidProp++;
361   }
362   Standard_Real tmp;
363   if(XCAFDoc_Volume::Get(L,tmp)) {
364     if(PrintStructMode) di<<"Volume("<<tmp<<") ";
365     NbVolumeProp++;
366   }
367   if(XCAFDoc_Area::Get(L,tmp)) {
368     if(PrintStructMode) di<<"Area("<<tmp<<") ";
369     NbAreaProp++;
370   }
371   Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
372   Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
373   Quantity_ColorRGBA col;
374   Standard_Boolean IsColor = Standard_False;
375   Standard_Boolean IsByLayer = Standard_False;
376   if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
377     IsColor = Standard_True;
378   else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
379     IsColor = Standard_True;
380   else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
381     IsColor = Standard_True;
382   else if(CTool->IsColorByLayer(L))
383     IsByLayer = Standard_True;
384   if(IsColor || IsByLayer) {
385     if(IsByLayer)
386     {
387       Handle(TColStd_HSequenceOfExtendedString) aLayerS;
388       LTool->GetLayers(L, aLayerS);
389       // Currently for DXF pnly, thus
390       // only 1 Layer should be.
391       if(aLayerS->Length() == 1)
392       {
393         TDF_Label aLayer = LTool->FindLayer (aLayerS->First());
394         Quantity_ColorRGBA aColor;
395         if (CTool->GetColor (aLayer, XCAFDoc_ColorGen, aColor))
396         {
397           TCollection_AsciiString aColorName = aColor.GetRGB().StringName(aColor.GetRGB().Name());
398           di<<"Color(" << aColorName.ToCString() << ") ";
399         }
400         else
401         {
402           di<<"Color(ByLayer) ";
403         }
404       }
405       NbShapesWithColor++;
406     }
407     else
408     {
409       TCollection_AsciiString Entry1;
410       Entry1 = col.GetRGB().StringName(col.GetRGB().Name());
411       if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<" "<<col.Alpha()<<") ";
412       NbShapesWithColor++;
413     }
414   }
415   Handle(TColStd_HSequenceOfExtendedString) aLayerS;
416   LTool->GetLayers(L, aLayerS);
417   if(!aLayerS.IsNull() && aLayerS->Length()>0) {
418     if(PrintStructMode) {
419       di<<"Layer(";
420       for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
421         TCollection_AsciiString Entry2(aLayerS->Value(i));
422         if(i==1)
423           di<<"\""<<Entry2.ToCString()<<"\"";
424         else
425           di<<" \""<<Entry2.ToCString()<<"\"";
426       }
427       di<<") ";
428     }
429     NbShapesWithLayer++;
430   }
431   if(PrintStructMode) di<<"\n";
432   
433   HAI->SetValue(level, HAI->Value(level)+1 );
434   if(L.HasChild()) {
435     for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
436       StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
437                    NbAreaProp, NbShapesWithName, NbShapesWithColor,
438                    NbShapesWithLayer, aDoc, PrintStructMode, di);
439     }
440   }
441
442 }
443
444
445 //=======================================================================
446 //function : statdoc
447 //purpose  : 
448 //=======================================================================
449 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
450 {
451   if (argc<2) {
452     di<<"Use: "<<argv[0]<<" Doc \n";
453     return 1;
454   }
455   Handle(TDocStd_Document) Doc;   
456   DDocStd::GetDocument(argv[1], Doc);
457   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
458
459   Standard_Boolean PrintStructMode = (argc==3);
460   Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
461
462   TDF_LabelSequence SeqLabels;
463   aTool->GetShapes(SeqLabels);
464   if(SeqLabels.Length()<=0) return 0;
465   if(PrintStructMode) di<<"\nStructure of shapes in the document:\n";
466   Standard_Integer level=0;
467   Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
468   Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
469   Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
470   Standard_Integer i=0;
471   for(i=0; i<=20; i++) HAI->SetValue(i,0);
472   for(i=1; i<=SeqLabels.Length(); i++) {
473     StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
474                  NbAreaProp, NbShapesWithName, NbShapesWithColor,
475                  NbShapesWithLayer, Doc, PrintStructMode, di);
476   }
477   Standard_Integer NbLabelsShape = 0;
478   di<<"\nStatistis of shapes in the document:\n";
479   for(i=0; i<=20; i++) {
480     if(HAI->Value(i)==0) break;
481     //di<<"level N "<<i<<" :  number of labels with shape = "<<HAI->Value(i)<<"\n";
482     di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
483     NbLabelsShape = NbLabelsShape + HAI->Value(i);
484   }
485   di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
486   di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
487   di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
488   di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
489
490   di<<"\nStatistis of Props in the document:\n";
491   di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
492   di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
493   di<<"Number of Area Props = "<<NbAreaProp<<"\n";
494
495   Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
496   TDF_LabelSequence CLabels;
497   CTool->GetColors(CLabels);
498   di<<"\nNumber of colors = "<<CLabels.Length()<<"\n";
499   if(CLabels.Length()>0) {
500     for(i=1; i<=CLabels.Length(); i++) {
501       TDF_Label aLabel = CLabels.Value(i);
502       Quantity_Color col;
503       CTool->GetColor(aLabel, col);
504       di<<col.StringName(col.Name())<<" ";
505     }
506     di<<"\n";
507   }
508
509   Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
510   TDF_LabelSequence LLabels;
511   LTool->GetLayerLabels(LLabels);
512   di<<"\nNumber of layers = "<<LLabels.Length()<<"\n";
513   if(LLabels.Length()>0) {
514     for(i=1; i<=LLabels.Length(); i++) {
515       TDF_Label aLabel = LLabels.Value(i);
516       TCollection_ExtendedString layerName;
517       LTool->GetLayer(aLabel, layerName);
518       di << "\"" << layerName << "\" ";
519     }
520     di<<"\n";
521   }
522
523   di<<"\n";
524   return 0;
525 }
526
527
528 //=======================================================================
529 //function : setPrs
530 //purpose  :
531 //=======================================================================
532 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
533 {
534   if (argc <2) {
535     di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
536     return 1;
537   }
538
539   Handle(TDocStd_Document) Doc;
540   DDocStd::GetDocument(argv[1], Doc);
541   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
542
543   // collect sequence of labels to set presentation
544   Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
545   TDF_LabelSequence seq;
546   if ( argc >2 ) {
547     for ( Standard_Integer i=2; i < argc; i++ ) {
548       TDF_Label aLabel;
549       TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
550       if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
551         di << argv[i] << " is not a valid shape label!";
552         continue;
553       }
554       seq.Append ( aLabel );
555     }
556   }
557   else {
558     shapes->GetShapes ( seq );
559   }
560
561   // set presentations
562   Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
563   for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
564     Handle(TPrsStd_AISPresentation) prs;
565     if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
566       prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
567       prs->SetMaterial (Graphic3d_NameOfMaterial_Plastified);
568     }
569 //    Quantity_Color Col;
570 //    if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
571 //      prs->SetColor ( Col.Name() );
572 //    else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
573 //      prs->SetColor ( Col.Name() );
574   }
575   return 0;
576 }
577
578
579 //=======================================================================
580 //function : show
581 //purpose  :
582 //=======================================================================
583 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
584 {
585   if (argc <2) {
586     di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
587     return 1;
588   }
589
590   Handle(TDocStd_Document) aDoc;
591   DDocStd::GetDocument (argv[1], aDoc);
592   if (aDoc.IsNull())
593   {
594     std::cout << argv[1] << " is not a document\n";
595     return 1;
596   }
597
598   // init viewer
599   TDF_Label aRoot = aDoc->GetData()->Root();
600   Handle(TPrsStd_AISViewer) aDocViewer;
601   TCollection_AsciiString   aViewName = TCollection_AsciiString ("Driver1/Document_") + argv[1] + "/View1";
602   if (!TPrsStd_AISViewer::Find (aRoot, aDocViewer))
603   {
604     ViewerTest::ViewerInit (aViewName);
605     aDocViewer = TPrsStd_AISViewer::New (aRoot, ViewerTest::GetAISContext());
606   }
607
608   // collect sequence of labels to display
609   Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
610   TDF_LabelSequence seq;
611   if ( argc >2 ) {
612     for ( Standard_Integer i=2; i < argc; i++ ) {
613       TDF_Label aLabel;
614       TDF_Tool::Label (aDoc->GetData(), argv[i], aLabel);
615       if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
616         di << argv[i] << " is not a valid shape label!";
617         continue;
618       }
619       seq.Append ( aLabel );
620     }
621   }
622   else {
623     shapes->GetFreeShapes ( seq );
624   }
625
626   // set presentations and show
627   //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
628   for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
629     Handle(TPrsStd_AISPresentation) prs;
630     if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
631       prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
632       prs->SetMaterial (Graphic3d_NameOfMaterial_Plastified);
633     }
634 //    Quantity_Color Col;
635 //    if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
636 //      prs->SetColor ( Col.Name() );
637 //    else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
638 //      prs->SetColor ( Col.Name() );
639     prs->Display(Standard_True);
640   }
641   TPrsStd_AISViewer::Update (aDoc->GetData()->Root());
642   return 0;
643 }
644
645 //! XDisplay command implementation.
646 class XDEDRAW_XDisplayTool
647 {
648 public:
649   //! XDisplay command interface.
650   static Standard_Integer XDisplay (Draw_Interpretor& theDI,
651                                     Standard_Integer theNbArgs,
652                                     const char** theArgVec)
653   {
654     XDEDRAW_XDisplayTool aTool;
655     return aTool.xdisplay (theDI, theNbArgs, theArgVec);
656   }
657
658 private:
659   //! Constructor.
660   XDEDRAW_XDisplayTool()
661   : myDispMode(-2),
662     myHiMode  (-2),
663     myIsAutoTriang (-1),
664     myToPrefixDocName (Standard_True),
665     myToGetNames (Standard_True),
666     myToExplore  (Standard_False) {}
667
668   //! Display single label.
669   Standard_Integer displayLabel (Draw_Interpretor& theDI,
670                                  const TDF_Label& theLabel,
671                                  const TCollection_AsciiString& theNamePrefix,
672                                  const TopLoc_Location& theLoc,
673                                  TCollection_AsciiString& theOutDispList)
674   {
675     TCollection_AsciiString aName;
676     if (myToGetNames)
677     {
678       Handle(TDataStd_Name) aNodeName;
679       if (theLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
680       {
681         aName = aNodeName->Get();
682       }
683       if (aName.IsEmpty())
684       {
685         TDF_Label aRefLabel;
686         if (XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel)
687          && aRefLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
688         {
689           aName = aNodeName->Get();
690         }
691       }
692
693       if (aName.IsEmpty())
694       {
695         TDF_Tool::Entry (theLabel, aName);
696       }
697       for (Standard_Integer aNameIndex = 1;; ++aNameIndex)
698       {
699         if (myNameMap.Add (aName))
700         {
701           break;
702         }
703         aName = aNodeName->Get() + "_" + aNameIndex;
704       }
705     }
706     else
707     {
708       TDF_Tool::Entry (theLabel, aName);
709     }
710     aName = theNamePrefix + aName;
711
712     if (myToExplore)
713     {
714       TDF_Label aRefLabel = theLabel;
715       XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel);
716       if (XCAFDoc_ShapeTool::IsAssembly (aRefLabel))
717       {
718         aName += "/";
719         const TopLoc_Location aLoc = theLoc * XCAFDoc_ShapeTool::GetLocation (theLabel);
720         for (TDF_ChildIterator aChildIter (aRefLabel); aChildIter.More(); aChildIter.Next())
721         {
722           if (displayLabel (theDI, aChildIter.Value(), aName, aLoc, theOutDispList) == 1)
723           {
724             return 1;
725           }
726         }
727         return 0;
728       }
729     }
730
731     Handle(XCAFPrs_AISObject) aPrs = new XCAFPrs_AISObject (theLabel);
732     if (!theLoc.IsIdentity())
733     {
734       aPrs->SetLocalTransformation (theLoc);
735     }
736     if (myDispMode != -2)
737     {
738       if (myDispMode == -1)
739       {
740         aPrs->UnsetDisplayMode();
741       }
742       if (!aPrs->AcceptDisplayMode (myDispMode))
743       {
744         theDI << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myDispMode << " display mode";
745         return 1;
746       }
747       else
748       {
749         aPrs->SetDisplayMode (myDispMode);
750       }
751     }
752     if (myHiMode != -2)
753     {
754       if (myHiMode != -1
755       && !aPrs->AcceptDisplayMode (myHiMode))
756       {
757         theDI << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myHiMode << " display mode";
758         return 1;
759       }
760       aPrs->SetHilightMode (myHiMode);
761     }
762     if (myIsAutoTriang != -1)
763     {
764       aPrs->Attributes()->SetAutoTriangulation (myIsAutoTriang == 1);
765     }
766
767     ViewerTest::Display (aName, aPrs, false);
768     theOutDispList += aName + " ";
769     return 0;
770   }
771
772   //! XDisplay command implementation.
773   Standard_Integer xdisplay (Draw_Interpretor& theDI,
774                              Standard_Integer theNbArgs,
775                              const char** theArgVec)
776   {
777     Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
778     if (aContext.IsNull())
779     {
780       theDI << "Error: no active viewer";
781       return 1;
782     }
783
784     ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
785     for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
786     {
787       TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
788       anArgCase.LowerCase();
789       if (anAutoUpdater.parseRedrawMode (anArgCase))
790       {
791         continue;
792       }
793       else if (anArgIter + 1 < theNbArgs
794             && myDispMode == -2
795             && (anArgCase == "-dispmode"
796              || anArgCase == "-displaymode")
797             && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
798       {
799         myDispMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue();
800       }
801       else if (anArgIter + 1 < theNbArgs
802             && myHiMode == -2
803             && (anArgCase == "-himode"
804              || anArgCase == "-highmode"
805              || anArgCase == "-highlightmode")
806             && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
807       {
808         myHiMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue();
809       }
810       else if (anArgCase == "-autotr"
811             || anArgCase == "-autotrian"
812             || anArgCase == "-autotriang"
813             || anArgCase == "-autotriangulation"
814             || anArgCase == "-noautotr"
815             || anArgCase == "-noautotrian"
816             || anArgCase == "-noautotriang"
817             || anArgCase == "-noautotriangulation")
818       {
819         myIsAutoTriang = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter) ? 1 : 0;
820       }
821       else if (anArgCase == "-docprefix"
822             || anArgCase == "-nodocprefix")
823       {
824         myToPrefixDocName = Standard_True;
825         if (anArgIter + 1 < theNbArgs
826          && Draw::ParseOnOff (theArgVec[anArgIter + 1], myToPrefixDocName))
827         {
828           ++anArgIter;
829         }
830         if (anArgCase.StartsWith ("-no"))
831         {
832           myToPrefixDocName = !myToPrefixDocName;
833         }
834       }
835       else if (anArgCase == "-names"
836             || anArgCase == "-nonames")
837       {
838         myToGetNames = Standard_True;
839         if (anArgIter + 1 < theNbArgs
840          && Draw::ParseOnOff (theArgVec[anArgIter + 1], myToGetNames))
841         {
842           ++anArgIter;
843         }
844         if (anArgCase.StartsWith ("-no"))
845         {
846           myToGetNames = !myToGetNames;
847         }
848       }
849       else if (anArgCase == "-explore"
850             || anArgCase == "-noexplore")
851       {
852         myToExplore = Standard_True;
853         if (anArgIter + 1 < theNbArgs
854          && Draw::ParseOnOff (theArgVec[anArgIter + 1], myToExplore))
855         {
856           ++anArgIter;
857         }
858         if (anArgCase.StartsWith ("-no"))
859         {
860           myToExplore = !myToExplore;
861         }
862       }
863       else if (anArgCase == "-outdisplist"
864             && anArgIter + 1 < theNbArgs)
865       {
866         myOutDispListVar = theArgVec[++anArgIter];
867         myOutDispList.Clear();
868       }
869       else
870       {
871         if (myDoc.IsNull()
872          && DDocStd::GetDocument (theArgVec[anArgIter], myDoc, Standard_False))
873         {
874           myDocName = theArgVec[anArgIter];
875           continue;
876         }
877
878         TCollection_AsciiString aValue (theArgVec[anArgIter]);
879         const Standard_Integer aFirstSplit = aValue.Search (":");
880         if (!IsDigit (aValue.Value (1))
881           && aFirstSplit >= 2
882           && aFirstSplit < aValue.Length())
883         {
884           TCollection_AsciiString aDocName = aValue.SubString (1, aFirstSplit - 1);
885           Standard_CString aDocNameStr = aDocName.ToCString();
886           Handle(TDocStd_Document) aDoc;
887           if (DDocStd::GetDocument (aDocNameStr, aDoc, Standard_False))
888           {
889             aValue = aValue.SubString (aFirstSplit + 1, aValue.Length());
890             if (!myDoc.IsNull()
891               && myDoc != aDoc)
892             {
893               theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
894               return 1;
895             }
896             myDoc = aDoc;
897             myDocName = aDocName;
898           }
899         }
900         if (myDoc.IsNull())
901         {
902           theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
903           return 1;
904         }
905
906         TDF_Label aLabel;
907         TDF_Tool::Label (myDoc->GetData(), aValue.ToCString(), aLabel);
908         if (aLabel.IsNull()
909         || !XCAFDoc_ShapeTool::IsShape (aLabel))
910         {
911           theDI << "Syntax error: " << aValue << " is not a valid shape label";
912           return 1;
913         }
914         myLabels.Append (aLabel);
915       }
916     }
917     if (myDoc.IsNull())
918     {
919       theDI << "Syntax error: not enough arguments";
920       return 1;
921     }
922     if (myLabels.IsEmpty())
923     {
924       XCAFDoc_DocumentTool::ShapeTool (myDoc->Main())->GetFreeShapes (myLabels);
925     }
926
927     for (TDF_LabelSequence::Iterator aLabIter (myLabels); aLabIter.More(); aLabIter.Next())
928     {
929       const TDF_Label& aLabel = aLabIter.Value();
930       if (displayLabel (theDI, aLabel, myToPrefixDocName ? myDocName + ":" : "", TopLoc_Location(), myOutDispList) == 1)
931       {
932         return 1;
933       }
934     }
935     if (myOutDispListVar.IsEmpty())
936     {
937       theDI << myOutDispList;
938     }
939     else
940     {
941       Draw::Set (myOutDispListVar.ToCString(), myOutDispList.ToCString());
942     }
943     return 0;
944   }
945
946 private:
947   NCollection_Map<TCollection_AsciiString>
948                            myNameMap;         //!< names map to handle collisions
949   Handle(TDocStd_Document) myDoc;             //!< document
950   TCollection_AsciiString  myDocName;         //!< document name
951   TCollection_AsciiString  myOutDispListVar;  //!< tcl variable to print the result objects
952   TCollection_AsciiString  myOutDispList;     //!< string with list of all displayed object names
953   TDF_LabelSequence        myLabels;          //!< labels to display
954   Standard_Integer         myDispMode;        //!< shape display mode
955   Standard_Integer         myHiMode;          //!< shape highlight mode
956   Standard_Integer         myIsAutoTriang;    //!< auto-triangulation mode
957   Standard_Boolean         myToPrefixDocName; //!< flag to prefix objects with document name
958   Standard_Boolean         myToGetNames;      //!< flag to use label names or tags
959   Standard_Boolean         myToExplore;       //!< flag to explore assembles
960 };
961
962 //=======================================================================
963 //function : xwd
964 //purpose  :
965 //=======================================================================
966 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
967 {
968   if (argc <3) {
969     di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}\n";
970     return 1;
971   }
972
973   Handle(TDocStd_Document) Doc;
974   DDocStd::GetDocument(argv[1], Doc);
975   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
976
977   Handle(AIS_InteractiveContext) IC;
978   if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
979     di << "Cannot find viewer for document " << argv[1] << "\n";
980     return 1;
981   }
982
983   Handle(V3d_Viewer) aViewer = IC->CurrentViewer();
984   V3d_ListOfViewIterator aViewIter = aViewer->ActiveViewIterator();
985   if (aViewIter.More())
986   {
987     aViewIter.Value()->Dump ( argv[2] );
988   }
989   else {
990     di << "Cannot find an active view in a viewer " << argv[1] << "\n";
991     return 1;
992   }
993
994   return 0;
995 }
996
997
998 //=======================================================================
999 //function : XAttributeValue
1000 //purpose  :
1001 //=======================================================================
1002 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1003 {
1004   if ( argc < 4 ) { std::cout << "Syntax error: Too few args\n"; return 1; }
1005   Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1]));
1006   if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; }
1007
1008   TDF_Label lab;
1009   TDF_Tool::Label(browser->Data(),argv[2],lab);
1010   if ( lab.IsNull() ) { std::cout << "Syntax error: label is Null: " << argv[2] << "\n"; return 1; }
1011
1012   Standard_Integer num = Draw::Atoi ( argv[3] );
1013   TDF_AttributeIterator itr(lab,Standard_False);
1014   for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
1015
1016   if ( ! itr.More() ) { std::cout << "Syntax error: Attribute #" << num << " not found\n"; return 1; }
1017
1018   TCollection_AsciiString anInfo = XCAFDoc::AttributeInfo ( itr.Value() );
1019   if (!anInfo.IsEmpty())
1020   {
1021     di << anInfo.ToCString();
1022   }
1023   return 0;
1024 }
1025
1026
1027 //=======================================================================
1028 //function : setviewName
1029 //purpose  :
1030 //=======================================================================
1031 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1032 {
1033   if (argc <2) {
1034     di<<"Use: "<<argv[0]<<" (1/0)\n";
1035     return 1;
1036   }
1037   Standard_Boolean mode = Standard_False;
1038   if (Draw::Atoi(argv[1]) == 1) mode = Standard_True;
1039   XCAFPrs::SetViewNameMode(mode);
1040   return 0;
1041 }
1042
1043
1044 //=======================================================================
1045 //function : getviewName
1046 //purpose  : auxiliary
1047 //=======================================================================
1048
1049 static Standard_Integer getviewName (Draw_Interpretor&  di, Standard_Integer /*argc*/, const char** /*argv*/)
1050 {
1051   if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON\n";
1052   else di << "Display names OFF\n";
1053   return 0;
1054 }
1055
1056
1057 //=======================================================================
1058 //function : XSetTransparency
1059 //purpose  :
1060 //=======================================================================
1061 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1062 {
1063   if (argc < 3) {
1064     di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] \n";
1065     return 1;
1066   }
1067
1068   Handle(TDocStd_Document) Doc;
1069   DDocStd::GetDocument(argv[1], Doc);
1070   if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1071
1072   const Standard_Real aTransparency = Draw::Atof(argv[2]);
1073
1074   // collect sequence of labels
1075   Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1076   TDF_LabelSequence seq;
1077   if ( argc > 3 ) {
1078     for ( Standard_Integer i=3; i < argc; i++ ) {
1079       TDF_Label aLabel;
1080       TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
1081       if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
1082         di << argv[i] << " is not a valid shape label!";
1083         continue;
1084       }
1085       seq.Append ( aLabel );
1086     }
1087   }
1088   else {
1089     shapes->GetFreeShapes ( seq );
1090   }
1091
1092   // find presentations and set transparency
1093   for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
1094     Handle(TPrsStd_AISPresentation) prs;
1095     if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
1096       prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
1097       prs->SetMaterial (Graphic3d_NameOfMaterial_Plastified);
1098     }
1099     prs->SetTransparency( aTransparency );
1100   }
1101   TPrsStd_AISViewer::Update(Doc->GetData()->Root());
1102   return 0;
1103 }
1104
1105 //=======================================================================
1106 //function : setLengthUnit
1107 //purpose  :
1108 //=======================================================================
1109 static Standard_Integer setLengthUnit(Draw_Interpretor& di,
1110                                       Standard_Integer argc,
1111                                       const char** argv)
1112 {
1113   if (argc != 3)
1114   {
1115     di << "Use: " << argv[0] << " Doc {unitName|scaleFactor} \n";
1116     return 1;
1117   }
1118
1119   Handle(TDocStd_Document) aDoc;
1120   DDocStd::GetDocument(argv[1], aDoc);
1121   if (aDoc.IsNull())
1122   {
1123     di << "Error: " << argv[1] << " is not a document\n"; return 1;
1124   }
1125
1126   TCollection_AsciiString anUnit(argv[2]);
1127   Standard_Real anUnitValue = 1.;
1128   TCollection_AsciiString anUnitName;
1129   if (!anUnit.IsRealValue(true))
1130   {
1131     UnitsMethods_LengthUnit aTypeUnit = UnitsMethods::LengthUnitFromString(anUnit.ToCString(), Standard_False);
1132     if (aTypeUnit == UnitsMethods_LengthUnit_Undefined)
1133     {
1134       di << "Error: " << anUnit
1135          << " is incorrect unit, use m, mm, km, cm, micron, mille, in, min, nin, ft, stat.mile\n";
1136       return 1;
1137     }
1138     anUnitName = anUnit;
1139     anUnitValue = UnitsMethods::GetLengthFactorValue(aTypeUnit) * 0.001;
1140   }
1141   else
1142   {
1143     anUnitValue = anUnit.RealValue();
1144     anUnitName = UnitsMethods::DumpLengthUnit(anUnitValue, UnitsMethods_LengthUnit_Meter);
1145   }
1146   XCAFDoc_LengthUnit::Set(aDoc->Main().Root(), anUnitName, anUnitValue);
1147   return 0;
1148 }
1149
1150 //=======================================================================
1151 //function : dumpLengthUnit
1152 //purpose  :
1153 //=======================================================================
1154 static Standard_Integer dumpLengthUnit(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1155 {
1156   if (argc != 2 && argc != 3) {
1157     di << "Use: " << argv[0] << " Doc [-scale]\n";
1158     return 1;
1159   }
1160
1161   Handle(TDocStd_Document) aDoc;
1162   DDocStd::GetDocument(argv[1], aDoc);
1163   if (aDoc.IsNull()) 
1164   { 
1165     di << "Error: " << argv[1] << " is not a document\n"; return 1;
1166   }
1167   Handle(XCAFDoc_LengthUnit) aUnits;
1168   if (!aDoc->Main().Root().FindAttribute(XCAFDoc_LengthUnit::GetID(), aUnits))
1169   {
1170     di << "Error: Document doesn't contain a Length Unit\n";
1171     return 1;
1172   }
1173   if (argc == 3)
1174   {
1175     TCollection_AsciiString anOption(argv[2]);
1176     anOption.LowerCase();
1177     if (anOption.IsEqual("-scale"))
1178     {
1179       di << aUnits->GetUnitValue();
1180       return 0;
1181     }
1182     else
1183     {
1184       di << "Error: Incorrect option, use -scale\n";
1185       return 1;
1186     }
1187   }
1188   di << aUnits->GetUnitName();
1189   return 0;
1190 }
1191
1192 //=======================================================================
1193 //function : XShowFaceBoundary
1194 //purpose  : Set face boundaries on/off
1195 //=======================================================================
1196 static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
1197                                            Standard_Integer argc,
1198                                            const char ** argv)
1199 {
1200   if (( argc != 4 && argc < 7 ) || argc > 9)
1201   {
1202     di << "Usage :\n " << argv[0]
1203        << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
1204        << "   Doc       - is the document name. \n"
1205        << "   Label     - is the shape label. \n"
1206        << "   IsOn      - flag indicating whether the boundaries\n"
1207        << "                should be turned on or off (can be set\n"
1208        << "                to 0 (off) or 1 (on)).\n"
1209        << "   R, G, B   - red, green and blue components of boundary\n"
1210        << "                color in range (0 - 255).\n"
1211        << "                (default is (0, 0, 0)\n"
1212        << "   LineWidth - line width\n"
1213        << "                (default is 1)\n"
1214        << "   LineStyle - line fill style :\n"
1215        << "                 0 - solid  \n"
1216        << "                 1 - dashed \n"
1217        << "                 2 - dot    \n"
1218        << "                 3 - dashdot\n"
1219        << "                (default is solid)";
1220
1221     return 1;
1222   }
1223
1224   // get specified document
1225   Handle(TDocStd_Document) aDoc;
1226   DDocStd::GetDocument (argv[1], aDoc);
1227   if (aDoc.IsNull())
1228   {
1229     di << argv[1] << " is not a document\n"; 
1230     return 1;
1231   }
1232
1233   Handle(AIS_InteractiveContext) aContext;
1234   if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext)) 
1235   {
1236     di << "Cannot find viewer for document " << argv[1] << "\n";
1237     return 1;
1238   }
1239
1240   // get shape tool for shape verification
1241   Handle(XCAFDoc_ShapeTool) aShapes =
1242     XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
1243
1244   // get label and validate that it is a shape label
1245   TDF_Label aLabel;
1246   TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
1247   if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
1248   {
1249     di << argv[2] << " is not a valid shape label!";
1250     return 1;
1251   }
1252
1253   // get presentation from label
1254   Handle(TPrsStd_AISPresentation) aPrs;
1255   if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
1256   {
1257     aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
1258   }
1259
1260   Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
1261   if (anInteractive.IsNull ())
1262   {
1263     di << "Can't set drawer attributes.\n"
1264           "Interactive object for shape label doesn't exists.";
1265     return 1;
1266   }
1267
1268   // get drawer
1269   const Handle(Prs3d_Drawer)& aDrawer = anInteractive->Attributes ();
1270
1271   // default attributes
1272   Standard_Real aRed   = 0.0;
1273   Standard_Real aGreen = 0.0;
1274   Standard_Real aBlue  = 0.0;
1275   Standard_Real aWidth = 1.0;
1276   Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
1277   
1278   // turn boundaries on/off
1279   Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1);
1280   aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
1281   
1282   // set boundary color
1283   if (argc >= 7)
1284   {
1285     // Text color
1286     aRed   = Draw::Atof (argv[4])/255.;
1287     aGreen = Draw::Atof (argv[5])/255.;
1288     aBlue  = Draw::Atof (argv[6])/255.;
1289   }
1290
1291   // set line width
1292   if (argc >= 8)
1293   {
1294     aWidth = (Standard_Real)Draw::Atof (argv[7]);
1295   }
1296
1297   // select appropriate line type
1298   if (argc == 9)
1299   {
1300     if (!ViewerTest::ParseLineType (argv[8], aLineType))
1301     {
1302       std::cout << "Syntax error: unknown line type '" << argv[8] << "'\n";
1303     }
1304   }
1305
1306   Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
1307
1308   Handle(Prs3d_LineAspect) aBoundaryAspect = 
1309     new Prs3d_LineAspect (aColor, aLineType, aWidth);
1310
1311   aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
1312
1313   aContext->Redisplay (anInteractive, Standard_True);
1314   
1315   return 0;
1316 }
1317
1318 //=======================================================================
1319 //function : XAssemblyTreeDump
1320 //purpose  : Prints assembly tree structure up to the specified level
1321 //=======================================================================
1322
1323 static Standard_Integer XDumpAssemblyTree(Draw_Interpretor& di,
1324                                           Standard_Integer argc,
1325                                           const char ** argv)
1326 {
1327   if (argc < 2)
1328   {
1329     di << "Usage :\n " << argv[0] << " Doc [-root label] [-level l] [-names]\n"
1330       << "   Doc         - document name. \n"
1331       << "   -root label - starting root label. \n"
1332       << "   -level l    - depth level (infinite by default). \n"
1333       << "   -names      - prints names instead of entries. \n";
1334
1335     return 1;
1336   }
1337
1338   // get specified document
1339   Handle(TDocStd_Document) aDoc;
1340   DDocStd::GetDocument(argv[1], aDoc);
1341   if (aDoc.IsNull())
1342   {
1343     di << argv[1] << " is not a document\n";
1344     return 1;
1345   }
1346
1347   XCAFDoc_AssemblyItemId aRoot;
1348   Standard_Integer aLevel = INT_MAX;
1349   Standard_Boolean aPrintNames = Standard_False;
1350   for (Standard_Integer iarg = 2; iarg < argc; ++iarg)
1351   {
1352     if (strcmp(argv[iarg], "-root") == 0)
1353     {
1354       Standard_ProgramError_Raise_if(iarg + 1 >= argc, "Root is expected!");
1355       aRoot.Init(argv[++iarg]);
1356     }
1357     else if (strcmp(argv[iarg], "-level") == 0)
1358     {
1359       Standard_ProgramError_Raise_if(iarg + 1 >= argc, "Level is expected!");
1360       TCollection_AsciiString anArg = argv[++iarg];
1361       Standard_ProgramError_Raise_if(!anArg.IsIntegerValue(), "Integer value is expected!");
1362       aLevel = anArg.IntegerValue();
1363     }
1364     else if (strcmp(argv[iarg], "-names") == 0)
1365     {
1366       aPrintNames = Standard_True;
1367     }
1368   }
1369
1370   Standard_SStream aSS;
1371
1372   XCAFDoc_AssemblyIterator anIt = aRoot.IsNull() ? XCAFDoc_AssemblyIterator(aDoc, aLevel) 
1373                                                  : XCAFDoc_AssemblyIterator(aDoc, aRoot, aLevel);
1374   XCAFDoc_AssemblyTool::Traverse(anIt, [&](const XCAFDoc_AssemblyItemId& theItem) -> Standard_Boolean
1375   {
1376     if (aPrintNames)
1377     {
1378       Standard_Boolean aFirst = Standard_True;
1379       for (TColStd_ListOfAsciiString::Iterator anIt(theItem.GetPath()); anIt.More(); 
1380            anIt.Next(), aFirst = Standard_False)
1381       {
1382         if (!aFirst) aSS << "/";
1383         TDF_Label aL;
1384         TDF_Tool::Label(aDoc->GetData(), anIt.Value(), aL, Standard_False);
1385         if (!aL.IsNull())
1386         {
1387           TCollection_ExtendedString aName;
1388           Handle(TDataStd_Name) aNameAttr;
1389           if (aL.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
1390           {
1391             aName = aNameAttr->Get();
1392             aSS << aName;
1393             continue;
1394           }
1395         }
1396         aSS << anIt.Value();
1397       }
1398       aSS << std::endl;
1399     }
1400     else
1401     {
1402       aSS << theItem.ToString() << std::endl;
1403     }
1404     return Standard_True;
1405   });
1406
1407   di << aSS.str().c_str();
1408   return 0;
1409 }
1410
1411 //=======================================================================
1412 //function : graphNodeTypename
1413 //purpose  : Returns node type name
1414 //=======================================================================
1415
1416 static 
1417 const char* graphNodeTypename(const XCAFDoc_AssemblyGraph::NodeType theNodeType)
1418 {
1419   switch (theNodeType)
1420   {
1421   case XCAFDoc_AssemblyGraph::NodeType_AssemblyRoot: return "R";
1422   case XCAFDoc_AssemblyGraph::NodeType_Subassembly:  return "A";
1423   case XCAFDoc_AssemblyGraph::NodeType_Occurrence:   return "O";
1424   case XCAFDoc_AssemblyGraph::NodeType_Part:         return "P";
1425   case XCAFDoc_AssemblyGraph::NodeType_Subshape:     return "S";
1426   default:                                           return "?";
1427   }
1428 }
1429
1430 //=======================================================================
1431 //function : XAssemblyGraphDump
1432 //purpose  : Prints assembly graph structure
1433 //=======================================================================
1434
1435 static Standard_Integer XDumpAssemblyGraph(Draw_Interpretor& di,
1436                                            Standard_Integer argc,
1437                                            const char ** argv)
1438 {
1439   if (argc < 2)
1440   {
1441     di << "Usage :\n " << argv[0] << " Doc [-root label] [-verbose] \n"
1442       << "   Doc         - is the document name. \n"
1443       << "   -root label - is the optional starting label. \n"
1444       << "   -names      - prints names instead of entries. \n";
1445
1446     return 1;
1447   }
1448
1449   // get specified document
1450   Handle(TDocStd_Document) aDoc;
1451   DDocStd::GetDocument(argv[1], aDoc);
1452   if (aDoc.IsNull())
1453   {
1454     di << argv[1] << " is not a document\n";
1455     return 1;
1456   }
1457
1458   Standard_Boolean aPrintNames = Standard_False;
1459   TDF_Label aLabel = XCAFDoc_DocumentTool::ShapesLabel(aDoc->Main());
1460   for (Standard_Integer iarg = 2; iarg < argc; ++iarg)
1461   {
1462     if (strcmp(argv[iarg], "-root") == 0)
1463     {
1464       Standard_ProgramError_Raise_if(iarg + 1 >= argc, "Root is expected!");
1465       TDF_Tool::Label(aDoc->GetData(), argv[++iarg], aLabel, Standard_False);
1466     }
1467     else if (strcmp(argv[iarg], "-names") == 0)
1468     {
1469       aPrintNames = Standard_True;
1470     }
1471   }
1472
1473   Handle(XCAFDoc_AssemblyGraph) aG = new XCAFDoc_AssemblyGraph(aLabel);
1474
1475   Standard_SStream aSS;
1476
1477   XCAFDoc_AssemblyTool::Traverse(aG, 
1478     [](const Handle(XCAFDoc_AssemblyGraph)& /*theGraph*/,
1479        const Standard_Integer               /*theNode*/) -> Standard_Boolean
1480     {
1481       return Standard_True;
1482     },
1483     [&](const Handle(XCAFDoc_AssemblyGraph)& theGraph,
1484         const Standard_Integer               theNode) -> Standard_Boolean
1485     {
1486       const TDF_Label& aLabel = theGraph->GetNode(theNode);
1487
1488       const XCAFDoc_AssemblyGraph::NodeType aNodeType = theGraph->GetNodeType(theNode);
1489
1490       TCollection_AsciiString aNodeEntry;
1491       if (aPrintNames)
1492       {
1493         Handle(TDataStd_Name) aNameAttr;
1494         if (aLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
1495         {
1496           aNodeEntry.AssignCat("'");
1497           aNodeEntry.AssignCat(aNameAttr->Get());
1498           aNodeEntry.AssignCat("'");
1499         }
1500       }
1501       if (aNodeEntry.IsEmpty())
1502       {
1503         TDF_Tool::Entry(aLabel, aNodeEntry);
1504       }
1505
1506       aSS << theNode << " " << graphNodeTypename(aNodeType) << " " << aNodeEntry;
1507       const XCAFDoc_AssemblyGraph::AdjacencyMap& anAdjacencyMap = theGraph->GetLinks();
1508       const TColStd_PackedMapOfInteger* aLinksPtr = anAdjacencyMap.Seek(theNode);
1509       if (aLinksPtr != NULL)
1510       {
1511         for (TColStd_MapIteratorOfPackedMapOfInteger anIt1(*aLinksPtr); anIt1.More(); anIt1.Next())
1512         {
1513           aSS << " " << anIt1.Key();
1514         }
1515       }
1516       aSS << std::endl;
1517
1518       return Standard_True;
1519     }
1520   );
1521
1522   di << aSS.str().c_str();
1523   return 0;
1524 }
1525
1526 //=======================================================================
1527 //function : XDumpNomenclature
1528 //purpose  : Prints number of assembly instances
1529 //=======================================================================
1530
1531 static Standard_Integer XDumpNomenclature(Draw_Interpretor& di,
1532                                           Standard_Integer argc,
1533                                           const char ** argv)
1534 {
1535   if (argc < 2)
1536   {
1537     di << "Usage :\n " << argv[0] << " Doc [-names] \n"
1538       << "   Doc    - is the document name. \n"
1539       << "   -names - prints names instead of entries. \n";
1540
1541     return 1;
1542   }
1543
1544   // get specified document
1545   Handle(TDocStd_Document) aDoc;
1546   DDocStd::GetDocument(argv[1], aDoc);
1547   if (aDoc.IsNull())
1548   {
1549     di << argv[1] << " is not a document\n";
1550     return 1;
1551   }
1552
1553   Standard_Boolean aPrintNames = Standard_False;
1554   for (Standard_Integer iarg = 2; iarg < argc; ++iarg)
1555   {
1556     if (strcmp(argv[iarg], "-names") == 0)
1557     {
1558       aPrintNames = Standard_True;
1559     }
1560   }
1561
1562   Handle(XCAFDoc_AssemblyGraph) aG = new XCAFDoc_AssemblyGraph(aDoc);
1563
1564   Standard_SStream aSS;
1565
1566   XCAFDoc_AssemblyTool::Traverse(aG, 
1567     [](const Handle(XCAFDoc_AssemblyGraph)& theGraph,
1568        const Standard_Integer               theNode) -> Standard_Boolean
1569     {
1570       const XCAFDoc_AssemblyGraph::NodeType aNodeType = theGraph->GetNodeType(theNode);
1571       return (aNodeType == XCAFDoc_AssemblyGraph::NodeType_AssemblyRoot) ||
1572              (aNodeType == XCAFDoc_AssemblyGraph::NodeType_Subassembly) ||
1573              (aNodeType == XCAFDoc_AssemblyGraph::NodeType_Part);
1574     },
1575     [&](const Handle(XCAFDoc_AssemblyGraph)& theGraph,
1576         const Standard_Integer               theNode) -> Standard_Boolean
1577     {
1578       const TDF_Label& aLabel = theGraph->GetNode(theNode);
1579
1580       const XCAFDoc_AssemblyGraph::NodeType aNodeType = theGraph->GetNodeType(theNode);
1581
1582       TCollection_AsciiString aNodeEntry;
1583       if (aPrintNames)
1584       {
1585         Handle(TDataStd_Name) aNameAttr;
1586         if (aLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
1587         {
1588           aNodeEntry.AssignCat("'");
1589           aNodeEntry.AssignCat(aNameAttr->Get());
1590           aNodeEntry.AssignCat("'");
1591         }
1592       }
1593       if (aNodeEntry.IsEmpty())
1594       {
1595         TDF_Tool::Entry(aLabel, aNodeEntry);
1596       }
1597
1598       aSS << theNode << " " << graphNodeTypename(aNodeType) << " " << aNodeEntry << " "
1599           << theGraph->NbOccurrences(theNode) << std::endl;
1600
1601       return Standard_True;
1602     }
1603   );
1604
1605   di << aSS.str().c_str();
1606
1607   return 0;
1608 }
1609
1610 //=======================================================================
1611 //function : XRescaleGeometry
1612 //purpose  : Applies geometrical scale to all assembly components
1613 //=======================================================================
1614
1615 static Standard_Integer XRescaleGeometry(Draw_Interpretor& di,
1616                                          Standard_Integer argc,
1617                                          const char ** argv)
1618 {
1619   if (argc < 3)
1620   {
1621     di << "Usage :\n " << argv[0] << " Doc factor [-root label] [-force]\n"
1622       << "   Doc         - is the document name. \n"
1623       << "   factor      - is the scale factor. \n"
1624       << "   -root label - is the starting label to apply rescaling. \n"
1625       << "   -force      - forces rescaling even if the starting label\n"
1626       << "                 is not a root. \n";
1627
1628     return 1;
1629   }
1630
1631   // get specified document
1632   Handle(TDocStd_Document) aDoc;
1633   DDocStd::GetDocument(argv[1], aDoc);
1634   if (aDoc.IsNull())
1635   {
1636     di << argv[1] << " is not a document\n";
1637     return 1;
1638   }
1639
1640   // get scale factor
1641   Standard_Real aScaleFactor = Draw::Atof(argv[2]);
1642   if (aScaleFactor <= 0)
1643   {
1644     di << "Scale factor must be positive\n";
1645     return 1;
1646   }
1647
1648   Standard_Boolean aForce = Standard_False;
1649   TDF_Label aLabel = XCAFDoc_DocumentTool::ShapesLabel(aDoc->Main());
1650   for (Standard_Integer iarg = 3; iarg < argc; ++iarg)
1651   {
1652     if (strcmp(argv[iarg], "-root") == 0)
1653     {
1654       Standard_ProgramError_Raise_if(iarg + 1 >= argc, "Root is expected!");
1655       TDF_Tool::Label(aDoc->GetData(), argv[++iarg], aLabel, Standard_False);
1656     }
1657     else if (strcmp(argv[iarg], "-force") == 0)
1658     {
1659       aForce = Standard_True;
1660     }
1661   }
1662
1663   if (!XCAFDoc_Editor::RescaleGeometry(aLabel, aScaleFactor, aForce))
1664   {
1665     di << "Geometry rescale failed\n";
1666     return 1;
1667   }
1668
1669   return 0;
1670 }
1671
1672 //=======================================================================
1673 //function : testDoc
1674 //purpose  : Method to test destruction of document
1675 //=======================================================================
1676 static Standard_Integer testDoc (Draw_Interpretor&,
1677                                  Standard_Integer argc,
1678                                  const char ** argv)
1679 {
1680   if( argc < 2 )
1681   {
1682     std::cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<std::endl;
1683     return 1;
1684   }
1685   TopoDS_Shape shape = DBRep::Get(argv[1]);
1686   if( shape.IsNull())
1687     return 1;
1688  
1689   Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1690  
1691   Handle(TDocStd_Document) aD1 = new TDocStd_Document("BinXCAF");
1692   aD1->Open(anApp);
1693   
1694   TCollection_AsciiString  aViewName ("Driver1/DummyDocument/View1");
1695   ViewerTest::ViewerInit (aViewName);
1696   TPrsStd_AISViewer::New (aD1->GetData()->Root(), ViewerTest::GetAISContext());
1697
1698   // get shape tool for shape verification
1699   Handle(XCAFDoc_ShapeTool) aShapes =
1700     XCAFDoc_DocumentTool::ShapeTool (aD1->Main());
1701   TDF_Label aLab = aShapes->AddShape(shape);
1702
1703   Handle(Geom_Axis2Placement) aPlacement = 
1704     new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX());
1705   Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement);
1706   
1707   Handle(TNaming_NamedShape) NS;
1708   Handle(TPrsStd_AISPresentation) prs;
1709   if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) {
1710     prs = TPrsStd_AISPresentation::Set( NS );
1711   }
1712    
1713   if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) ) 
1714     prs->Display();
1715
1716   TPrsStd_AISViewer::Update(aLab);
1717   ViewerTest::GetAISContext()->Display (aTriShape, Standard_True);
1718   aD1->BeforeClose();
1719   aD1->Close();
1720   ViewerTest::RemoveView (aViewName);
1721   return 0;
1722 }
1723
1724
1725 //=======================================================================
1726 //function : Init
1727 //purpose  :
1728 //=======================================================================
1729
1730 void XDEDRAW::Init(Draw_Interpretor& di)
1731 {
1732   static Standard_Boolean initactor = Standard_False;
1733   if (initactor)
1734   {
1735     return;
1736   }
1737   initactor = Standard_True;
1738
1739   // Load static variables for STEPCAF (ssv; 16.08.2012)
1740   STEPCAFControl_Controller::Init();
1741
1742   // Initialize XCAF formats
1743   Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1744   BinXCAFDrivers::DefineFormat(anApp);
1745   XmlXCAFDrivers::DefineFormat(anApp);
1746
1747   // Register driver in global table for displaying XDE documents 
1748   // in 3d viewer using OCAF mechanics
1749   TPrsStd_DriverTable::Get()->AddDriver (XCAFPrs_Driver::GetID(), new XCAFPrs_Driver);
1750
1751   //=====================================
1752   // General commands
1753   //=====================================
1754
1755   Standard_CString g = "XDE general commands";
1756
1757   di.Add ("XNewDoc","DocName \t: Create new DECAF document",
1758                    __FILE__, newDoc, g);
1759
1760   di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
1761                    __FILE__, saveDoc, g);
1762
1763   di.Add ("XOpen","Path Doc [-skipAttribute] [-readAttribute] [-readPath] [-append|-overwrite]\t: Open XDE Document with name Doc from Path"
1764           "\n\t\t The options are:"
1765           "\n\t\t   -skipAttribute : class name of the attribute to skip during open, for example -skipTDF_Reference"
1766           "\n\t\t   -readAttribute : class name of the attribute to read only during open, for example -readTDataStd_Name loads only such attributes"
1767           "\n\t\t   -append : to read file into already existing document once again, append new attributes and don't touch existing"
1768           "\n\t\t   -overwrite : to read file into already existing document once again, overwriting existing attributes",
1769     __FILE__, openDoc, g);
1770
1771   di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
1772                    __FILE__, dump, g);
1773
1774   di.Add ("XStat","Doc \t: Print statistics of document",
1775                    __FILE__, statdoc, g);
1776
1777   di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
1778                    __FILE__, setPrs, g);
1779
1780   di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
1781                    __FILE__, show, g);
1782
1783   di.Add ("XDisplay",
1784           "XDisplay Doc [label1 [label2 [...]]] [-explore {on|off}] [-docPrefix {on|off}] [-names {on|off}]"
1785           "\n\t\t:      [-noupdate] [-dispMode Mode] [-highMode Mode] [-autoTriangulation {0|1}]"
1786           "\n\t\t: Displays document (parts) in 3D Viewer."
1787           "\n\t\t:  -dispMode    Presentation display mode."
1788           "\n\t\t:  -highMode    Presentation highlight mode."
1789           "\n\t\t:  -docPrefix   Prepend document name to object names; TRUE by default."
1790           "\n\t\t:  -names       Use object names instead of label tag; TRUE by default."
1791           "\n\t\t:  -explore     Explode labels to leaves; FALSE by default."
1792           "\n\t\t:  -outDispList Set the TCL variable to the list of displayed object names."
1793           "\n\t\t:               (instead of printing them to draw interpreter)"
1794           "\n\t\t:  -autoTriang  Enable/disable auto-triangulation for displayed shapes.",
1795           __FILE__, XDEDRAW_XDisplayTool::XDisplay, g);
1796
1797   di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
1798                    __FILE__, xwd, g);
1799
1800   di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
1801                    __FILE__, XAttributeValue, g);
1802
1803   di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
1804                    __FILE__, setviewName, g);
1805
1806   di.Add ("XGetViewNameMode", "\t: Print if  mode of displaying names is turn on.",
1807                    __FILE__, getviewName, g);
1808
1809   di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
1810                    __FILE__, XSetTransparency, g);
1811
1812   di.Add("XSetLengthUnit",
1813     "Doc {unit_name|scale_factor}\t: Set value of length unit"
1814     "\n\t\t: Possible unit_name: m, mm, km, cm, micron, mille, in(inch), min(microinch), nin(nano inch), ft, stat.mile"
1815     "\n\t\t: Possible scale factor: any real value more then 0. Factor to meter.",
1816     __FILE__, setLengthUnit, g);
1817
1818   di.Add("XGetLengthUnit",
1819     "Doc [-scale]\t: Print name of length unit"
1820     "\n\t\t: -scale : print value of the scaling factor to meter of length unit",
1821     __FILE__, dumpLengthUnit, g);
1822
1823   di.Add ("XShowFaceBoundary",
1824           "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
1825           "- turns on/off drawing of face boundaries and defines boundary line style",
1826           __FILE__, XShowFaceBoundary, g);
1827    di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g);
1828
1829   di.Add("XDumpAssemblyTree",
1830          "Doc [-root label] [-level l] [-names]: Iterates through the assembly tree in depth up to the specified level, if any",
1831          __FILE__, XDumpAssemblyTree, g);
1832   di.Add("XDumpAssemblyGraph",
1833          "Doc [-root label] [-names]: Prints assembly graph structure",
1834          __FILE__, XDumpAssemblyGraph, g);
1835   di.Add("XDumpNomenclature",
1836          "Doc [-names]: Prints number of assembly instances",
1837          __FILE__, XDumpNomenclature, g);
1838   di.Add("XRescaleGeometry",
1839          "Doc factor [-root label] [-force]: Applies geometrical scale to assembly",
1840          __FILE__, XRescaleGeometry, g);
1841
1842   // Specialized commands
1843   XDEDRAW_Shapes::InitCommands ( di );
1844   XDEDRAW_Colors::InitCommands ( di );
1845   XDEDRAW_Layers::InitCommands ( di );
1846   XDEDRAW_Props::InitCommands ( di );
1847   XDEDRAW_GDTs::InitCommands ( di );
1848   XDEDRAW_Views::InitCommands(di);
1849   XDEDRAW_Notes::InitCommands(di);
1850   XDEDRAW_Common::InitCommands ( di );//moved from EXE
1851 }
1852
1853 //==============================================================================
1854 // XDEDRAW::Factory
1855 //==============================================================================
1856 void XDEDRAW::Factory(Draw_Interpretor& theDI)
1857 {
1858   XDEDRAW::Init(theDI);
1859
1860 #ifdef OCCT_DEBUG
1861       theDI << "Draw Plugin : All TKXDEDRAW commands are loaded\n";
1862 #endif
1863 }
1864
1865 // Declare entry point PLUGINFACTORY
1866 DPLUGIN(XDEDRAW)