0024047: Exception in TPrsStd_AISPresentation during destruction of TDocStd_Document
[occt.git] / src / XDEDRAW / XDEDRAW.cxx
1 // Created on: 2000-08-04
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <XDEDRAW.ixx>
22 #include <stdio.h>
23
24 #include <TCollection_ExtendedString.hxx>
25 #include <TCollection_AsciiString.hxx>
26 #include <TColStd_HSequenceOfExtendedString.hxx>
27 #include <TCollection_HAsciiString.hxx>
28 #include <Quantity_Color.hxx>
29
30 #include <TopoDS_Shape.hxx>
31
32 #include <Draw.hxx>
33 #include <DBRep.hxx>
34 #include <V3d_Viewer.hxx>
35 #include <V3d_View.hxx>
36 #include <AIS_InteractiveContext.hxx>
37 #include <ViewerTest_Tool.hxx>
38
39 #include <DDF_Browser.hxx>
40 #include <DDocStd.hxx>
41 #include <DDocStd_DrawDocument.hxx>
42
43 #include <STEPCAFControl_Controller.hxx>
44
45 #include <TDF_Tool.hxx>
46 #include <TDF_Data.hxx>
47 #include <TDF_LabelSequence.hxx>
48 #include <TDF_AttributeIterator.hxx>
49 #include <TDF_Reference.hxx>
50 #include <TDocStd_Document.hxx>
51 #include <TDataStd_UAttribute.hxx>
52 #include <TDataStd_TreeNode.hxx>
53 #include <TDataStd_Integer.hxx>
54 #include <TDataStd_Real.hxx>
55 #include <TDataStd_Name.hxx>
56 #include <TDataStd_Comment.hxx>
57 #include <TDataStd_AsciiString.hxx>
58 #include <TNaming_NamedShape.hxx>
59 #include <TDataStd_IntegerArray.hxx>
60 #include <TDataStd_RealArray.hxx>
61 #include <TDataStd_ByteArray.hxx>
62 #include <TPrsStd_AISPresentation.hxx>
63 #include <TPrsStd_NamedShapeDriver.hxx>
64 #include <TPrsStd_AISViewer.hxx>
65
66 #include <XCAFDoc.hxx>
67 #include <XCAFDoc_Color.hxx>
68 #include <XCAFDoc_Volume.hxx>
69 #include <XCAFDoc_Area.hxx>
70 #include <XCAFDoc_Centroid.hxx>
71 #include <XCAFDoc_ShapeTool.hxx>
72 #include <XCAFDoc_ColorTool.hxx>
73 #include <XCAFDoc_DocumentTool.hxx>
74 #include <XCAFDoc_GraphNode.hxx>
75 #include <XCAFDoc_LayerTool.hxx>
76 #include <XCAFDoc_DimTol.hxx>
77 #include <XCAFDoc_Material.hxx>
78 #include <XCAFPrs_Driver.hxx>
79 #include <XCAFApp_Application.hxx>
80
81 #include <XDEDRAW_Shapes.hxx>
82 #include <XDEDRAW_Colors.hxx>
83 #include <XDEDRAW_Layers.hxx>
84 #include <XDEDRAW_Props.hxx>
85 #include <XDEDRAW_Common.hxx>
86 #include <XSDRAWIGES.hxx>
87 #include <XSDRAWSTEP.hxx>
88 #include <SWDRAW.hxx>
89 #include <XSDRAW.hxx>
90 #include <XCAFPrs.hxx>
91 #include <ViewerTest.hxx>
92 #include <Draw_PluginMacro.hxx>
93
94 #include <TColStd_HArray1OfInteger.hxx>
95 #include <TColStd_HArray1OfReal.hxx>
96
97 #include <AIS_InteractiveObject.hxx>
98 #include <AIS_Drawer.hxx>
99 #include <Aspect_TypeOfLine.hxx>
100 #include <Prs3d_LineAspect.hxx>
101 #include <TDocStd_Owner.hxx>
102 #include <Geom_Axis2Placement.hxx>
103 #include <AIS_Trihedron.hxx>
104
105 #define ZVIEW_SIZE 1000000.0
106 // avoid warnings on 'extern "C"' functions returning C++ classes
107 #ifdef WNT
108 #pragma warning(4:4190)
109 #endif
110
111 //=======================================================================
112 // Section: General commands
113 //=======================================================================
114
115 //=======================================================================
116 //function : newDoc
117 //purpose  :
118 //=======================================================================
119 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
120 {
121   if (argc < 2) {di<<"Give document name"<<"\n";return 1;}
122
123   Handle(TDocStd_Document) D;
124   Handle(DDocStd_DrawDocument) DD;
125   Handle(TDocStd_Application) A;
126
127   if (!DDocStd::Find(A)) return 1;
128
129   if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
130     A->NewDocument(  "MDTV-XCAF"  ,D);
131     DD = new DDocStd_DrawDocument(D);
132     TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
133     Draw::Set(argv[1],DD);
134     di << "document " << argv[1] << " created" << "\n";
135     //DDocStd::ReturnLabel(di,D->Main());
136   }
137   else di << argv[1] << " is already a document" << "\n";
138
139   return 0;
140 }
141
142
143 //=======================================================================
144 //function : saveDoc
145 //purpose  :
146 //=======================================================================
147 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
148 {
149   Handle(TDocStd_Document) D;
150   Handle(TDocStd_Application) A;
151   if (!DDocStd::Find(A)) return 1;
152
153   if (argc == 1) {
154     if (A->NbDocuments() < 1) return 1;
155     A->GetDocument(1, D);
156   }
157   else {
158     if (!DDocStd::GetDocument(argv[1],D)) return 1;
159   }
160
161   if (argc == 3 ) {
162     TCollection_ExtendedString path (argv[2]);
163     A->SaveAs(D,path);
164     return 0;
165   }
166   if (!D->IsSaved()) {
167     di << "this document has never been saved" << "\n";
168     return 1;
169   }
170   A->Save(D);
171   return 0;
172 }
173
174 //=======================================================================
175 //function : openDoc
176 //purpose  :
177 //=======================================================================
178 static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
179 {
180   Handle(TDocStd_Document) D;
181   Handle(DDocStd_DrawDocument) DD;
182   Handle(TDocStd_Application) A;
183
184   if ( !DDocStd::Find(A) )
185     return 1;
186
187   if ( argc != 3 )
188   {
189     di << "invalid number of arguments. Usage:\t XOpen filename docname" << "\n";
190     return 1;
191   }
192
193   Standard_CString Filename = argv[1];
194   Standard_CString DocName = argv[2];
195
196   if ( DDocStd::GetDocument(DocName, D, Standard_False) )
197   {
198     di << "document with name " << DocName << " already exists" << "\n";
199     return 1;
200   }
201
202   if ( A->Open(Filename, D) != PCDM_RS_OK )
203   {
204     di << "cannot open XDE document" << "\n";
205     return 1;
206   }
207
208   DD = new DDocStd_DrawDocument(D);
209   TDataStd_Name::Set(D->GetData()->Root(), DocName);
210   Draw::Set(DocName, DD);
211
212   di << "document " << DocName << " opened" << "\n";
213
214   return 0;
215 }
216
217 //=======================================================================
218 //function : dump
219 //purpose  :
220 //=======================================================================
221 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
222 {
223   if (argc<2) {
224     di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n";
225     return 1;
226   }
227   Handle(TDocStd_Document) Doc;
228   DDocStd::GetDocument(argv[1], Doc);
229   if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
230
231   Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
232   Standard_Boolean deep = Standard_False;
233   if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True;
234   myAssembly->Dump(deep);
235   return 0;
236 }
237
238
239 //=======================================================================
240 //function : StatAssembly
241 //purpose  : recursive part of statistics
242 //=======================================================================
243
244 static void StatAssembly(const TDF_Label L,
245                          const Standard_Integer level,
246                          Handle(TColStd_HArray1OfInteger) &HAI,
247                          Standard_Integer &NbCentroidProp,
248                          Standard_Integer &NbVolumeProp,
249                          Standard_Integer &NbAreaProp,
250                          Standard_Integer &NbShapesWithName,
251                          Standard_Integer &NbShapesWithColor,
252                          Standard_Integer &NbShapesWithLayer,
253                          Handle(TDocStd_Document) &aDoc,
254                          Standard_Boolean &PrintStructMode,
255                          Draw_Interpretor& di)
256 {
257   if(PrintStructMode) {
258     for(Standard_Integer j=0; j<=level; j++)
259       di<<"  ";
260   }
261   TCollection_AsciiString Entry;
262   TDF_Tool::Entry(L, Entry);
263   if(PrintStructMode) di<<Entry.ToCString();
264
265   Handle(TDataStd_Name) Name;
266   if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
267     NbShapesWithName++;
268     if(PrintStructMode) {
269       TCollection_AsciiString AsciiStringName(Name->Get(),'?');
270       di<<" "<<AsciiStringName.ToCString()<<"  has attributes: ";
271     }
272   }
273   else {
274     if(PrintStructMode) di<<" NoName  has attributes: ";
275   }
276
277   Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
278   if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
279     if(PrintStructMode) di<<"Centroid ";
280     NbCentroidProp++;
281   }
282   Standard_Real tmp;
283   if(XCAFDoc_Volume::Get(L,tmp)) {
284     if(PrintStructMode) di<<"Volume("<<tmp<<") ";
285     NbVolumeProp++;
286   }
287   if(XCAFDoc_Area::Get(L,tmp)) {
288     if(PrintStructMode) di<<"Area("<<tmp<<") ";
289     NbAreaProp++;
290   }
291   Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
292   Quantity_Color col;
293   Standard_Boolean IsColor = Standard_False;
294   if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
295     IsColor = Standard_True;
296   else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
297     IsColor = Standard_True;
298   else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
299     IsColor = Standard_True;
300   if(IsColor) {
301     TCollection_AsciiString Entry1;
302     Entry1 = col.StringName(col.Name());
303     if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
304     NbShapesWithColor++;
305   }
306   Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
307   Handle(TColStd_HSequenceOfExtendedString) aLayerS;
308   LTool->GetLayers(L, aLayerS);
309   if(!aLayerS.IsNull() && aLayerS->Length()>0) {
310     if(PrintStructMode) {
311       di<<"Layer(";
312       for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
313         TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
314         if(i==1)
315           di<<"\""<<Entry2.ToCString()<<"\"";
316         else
317           di<<" "<<"\""<<Entry2.ToCString()<<"\"";
318       }
319       di<<") ";
320     }
321     NbShapesWithLayer++;
322   }
323   if(PrintStructMode) di<<"\n";
324   
325   HAI->SetValue(level, HAI->Value(level)+1 );
326   if(L.HasChild()) {
327     for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
328       StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
329                    NbAreaProp, NbShapesWithName, NbShapesWithColor,
330                    NbShapesWithLayer, aDoc, PrintStructMode, di);
331     }
332   }
333
334 }
335
336
337 //=======================================================================
338 //function : statdoc
339 //purpose  : 
340 //=======================================================================
341 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
342 {
343   if (argc<2) {
344     di<<"Use: "<<argv[0]<<" Doc "<<"\n";
345     return 1;
346   }
347   Handle(TDocStd_Document) Doc;   
348   DDocStd::GetDocument(argv[1], Doc);
349   if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
350
351   Standard_Boolean PrintStructMode = (argc==3);
352   Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
353
354   TDF_LabelSequence SeqLabels;
355   aTool->GetShapes(SeqLabels);
356   if(SeqLabels.Length()<=0) return 0;
357   if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n";
358   Standard_Integer level=0;
359   Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
360   Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
361   Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
362   Standard_Integer i=0;
363   for(i=0; i<=20; i++) HAI->SetValue(i,0);
364   for(i=1; i<=SeqLabels.Length(); i++) {
365     StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
366                  NbAreaProp, NbShapesWithName, NbShapesWithColor,
367                  NbShapesWithLayer, Doc, PrintStructMode, di);
368   }
369   Standard_Integer NbLabelsShape = 0;
370   di<<"\n"<<"Statistis of shapes in the document:"<<"\n";
371   for(i=0; i<=20; i++) {
372     if(HAI->Value(i)==0) break;
373     //di<<"level N "<<i<<" :  number of labels with shape = "<<HAI->Value(i)<<"\n";
374     di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
375     NbLabelsShape = NbLabelsShape + HAI->Value(i);
376   }
377   di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
378   di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
379   di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
380   di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
381
382   di<<"\n"<<"Statistis of Props in the document:"<<"\n";
383   di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
384   di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
385   di<<"Number of Area Props = "<<NbAreaProp<<"\n";
386
387   Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
388   TDF_LabelSequence CLabels;
389   CTool->GetColors(CLabels);
390   di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n";
391   if(CLabels.Length()>0) {
392     for(i=1; i<=CLabels.Length(); i++) {
393       TDF_Label aLabel = CLabels.Value(i);
394       Quantity_Color col;
395       CTool->GetColor(aLabel, col);
396       di<<col.StringName(col.Name())<<" ";
397     }
398     di<<"\n";
399   }
400
401   Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
402   TDF_LabelSequence LLabels;
403   LTool->GetLayerLabels(LLabels);
404   di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n";
405   if(LLabels.Length()>0) {
406     for(i=1; i<=LLabels.Length(); i++) {
407       TDF_Label aLabel = LLabels.Value(i);
408       TCollection_ExtendedString layerName;
409       LTool->GetLayer(aLabel, layerName);
410       TCollection_AsciiString Entry(layerName,'?');
411       di<<"\""<<Entry.ToCString() <<"\" ";
412     }
413     di<<"\n";
414   }
415
416   di<<"\n";
417   return 0;
418 }
419
420
421 //=======================================================================
422 //function : setPrs
423 //purpose  :
424 //=======================================================================
425 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
426 {
427   if (argc <2) {
428     di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
429     return 1;
430   }
431
432   Handle(TDocStd_Document) Doc;
433   DDocStd::GetDocument(argv[1], Doc);
434   if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
435
436   // collect sequence of labels to set presentation
437   Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
438   TDF_LabelSequence seq;
439   if ( argc >2 ) {
440     for ( Standard_Integer i=2; i < argc; i++ ) {
441       TDF_Label aLabel;
442       TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
443       if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
444         di << argv[i] << " is not a valid shape label!";
445         continue;
446       }
447       seq.Append ( aLabel );
448     }
449   }
450   else {
451     shapes->GetShapes ( seq );
452   }
453
454   // set presentations
455   Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
456   for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
457     Handle(TPrsStd_AISPresentation) prs;
458     if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
459       prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
460       prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
461     }
462 //    Quantity_Color Col;
463 //    if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
464 //      prs->SetColor ( Col.Name() );
465 //    else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
466 //      prs->SetColor ( Col.Name() );
467   }
468   return 0;
469 }
470
471
472 //=======================================================================
473 //function : show
474 //purpose  :
475 //=======================================================================
476 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
477 {
478   if (argc <2) {
479     di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
480     return 1;
481   }
482
483   Handle(TDocStd_Document) Doc;
484   DDocStd::GetDocument(argv[1], Doc);
485   if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
486
487   // init viewer
488 //  char string[260];
489 //  Sprintf ( string, "AISInitViewer %s", argv[1] );
490 //  di.Eval ( string );
491   TDF_Label acces = Doc->GetData()->Root();
492   Handle(TPrsStd_AISViewer) viewer;
493   if (!TPrsStd_AISViewer::Find (acces,viewer)) {
494     TCollection_AsciiString title;
495     title.Prepend(argv[1]);
496     title.Prepend("_");
497     title.Prepend("Document");
498     Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString());
499     viewer = TPrsStd_AISViewer::New (acces,vw);
500   }
501   ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
502
503   //szv:CAX-TRJ7 c2-pe-214.stp was clipped
504   viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE);
505   //DDF::ReturnLabel(di,viewer->Label());
506
507   // collect sequence of labels to display
508   Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
509   TDF_LabelSequence seq;
510   if ( argc >2 ) {
511     for ( Standard_Integer i=2; i < argc; i++ ) {
512       TDF_Label aLabel;
513       TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
514       if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
515         di << argv[i] << " is not a valid shape label!";
516         continue;
517       }
518       seq.Append ( aLabel );
519     }
520   }
521   else {
522     shapes->GetFreeShapes ( seq );
523   }
524
525   // set presentations and show
526   //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
527   for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
528     Handle(TPrsStd_AISPresentation) prs;
529     if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
530       prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
531       prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
532     }
533 //    Quantity_Color Col;
534 //    if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
535 //      prs->SetColor ( Col.Name() );
536 //    else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
537 //      prs->SetColor ( Col.Name() );
538     prs->Display(Standard_True);
539   }
540   TPrsStd_AISViewer::Update(Doc->GetData()->Root());
541   return 0;
542 }
543
544
545 //=======================================================================
546 //function : xwd
547 //purpose  :
548 //=======================================================================
549 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
550 {
551   if (argc <3) {
552     di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n";
553     return 1;
554   }
555
556   Handle(TDocStd_Document) Doc;
557   DDocStd::GetDocument(argv[1], Doc);
558   if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
559
560   Handle(AIS_InteractiveContext) IC;
561   if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
562     di << "Cannot find viewer for document " << argv[1] << "\n";
563     return 1;
564   }
565
566   Handle(V3d_Viewer) viewer = IC->CurrentViewer();
567   viewer->InitActiveViews();
568   if ( viewer->MoreActiveViews() ) {
569     viewer->ActiveView()->Dump ( argv[2] );
570   }
571   else {
572     di << "Cannot find an active view in a viewer " << argv[1] << "\n";
573     return 1;
574   }
575
576   return 0;
577 }
578
579
580 //=======================================================================
581 //function : XAttributeValue
582 //purpose  :
583 //=======================================================================
584 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
585 {
586   if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; }
587   Handle(DDF_Browser) browser =
588     Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
589   if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
590
591   TDF_Label lab;
592   TDF_Tool::Label(browser->Data(),argv[2],lab);
593   if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
594
595   Standard_Integer num = Draw::Atoi ( argv[3] );
596   TDF_AttributeIterator itr(lab,Standard_False);
597   for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
598
599   if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; }
600
601   const Handle(TDF_Attribute)& att = itr.Value();
602   if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
603     Standard_CString type = "";
604     if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
605     else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
606     else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
607     else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
608     else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
609     else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
610     else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
611     Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
612     TCollection_AsciiString ref;
613     if ( TN->HasFather() ) {
614       TDF_Tool::Entry ( TN->Father()->Label(), ref );
615       di << type << " ==> " << ref.ToCString();
616     }
617     else {
618       di << type << " <== (" << ref.ToCString();
619       Handle(TDataStd_TreeNode) child = TN->First();
620       while ( ! child.IsNull() ) {
621         TDF_Tool::Entry ( child->Label(), ref );
622         if ( child != TN->First() ) di << ", ";
623         di << ref.ToCString();
624         child = child->Next();
625       }
626       di << ")";
627     }
628   }
629   else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
630     Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
631     TCollection_AsciiString ref;
632     TDF_Tool::Entry ( val->Get(), ref );
633     di << "==> " << ref.ToCString();
634   }
635   else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
636     Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
637     TCollection_AsciiString str ( val->Get() );
638     di << str.ToCString();
639   }
640   else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
641     Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
642     TCollection_AsciiString str ( val->Get() );
643     di << str.ToCString();
644   }
645   else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
646     Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
647     TCollection_AsciiString str ( val->Get(), '?' );
648     di << str.ToCString();
649   }
650   else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
651     Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
652     TCollection_AsciiString str ( val->Get(), '?' );
653     di << str.ToCString();
654   }
655   else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
656     Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
657     TCollection_AsciiString str ( val->Get(), '?' );
658     di << str.ToCString();
659   }
660   else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
661     Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
662     for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
663       if ( j > val->Lower() ) di << ", ";
664       TCollection_AsciiString str ( val->Value(j) );
665       di << str.ToCString();
666     }
667   }
668   else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
669     Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
670     for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
671       if ( j > val->Lower() ) di << ", ";
672       TCollection_AsciiString str ( val->Value(j) );
673       di << str.ToCString();
674     }
675   }
676   else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
677     Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
678     for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
679       if ( j > val->Lower() ) di << ", ";
680       TCollection_AsciiString str ( val->Value(j) );
681       di << str.ToCString();
682     }
683   }
684   else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
685     Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
686     TopoDS_Shape S = val->Get();
687     di << S.TShape()->DynamicType()->Name();
688     if ( ! S.Location().IsIdentity() ) di << "(located)";
689   }
690   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
691     Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
692     TCollection_AsciiString str ( val->Get() );
693     di << str.ToCString();
694   }
695   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
696     Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
697     TCollection_AsciiString str ( val->Get() );
698     di << str.ToCString();
699   }
700   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
701     Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
702     gp_Pnt myCentroid = val->Get();
703     di << "(" ;
704     di << myCentroid.X();
705     di <<" , ";
706     di << myCentroid.Y();
707     di <<" , ";
708     di << myCentroid.Z();
709     di << ")";
710   }
711   else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
712     if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
713     if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
714   }
715   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
716     Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
717     Quantity_Color C = val->GetColor();
718     char string[260];
719     Sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
720               C.Red(), C.Green(), C.Blue() );
721     di << string;
722   }
723   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
724     Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
725     Standard_Integer kind = val->GetKind();
726     Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
727     if(kind<20) { //dimension
728       di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
729     }
730     else {
731       switch(kind) {
732       case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
733       case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
734       case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
735       case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
736       case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
737       case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
738       case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
739       case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
740       case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
741       case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
742       case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
743       case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
744       case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
745       case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
746       case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
747       case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
748       case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
749       case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
750       case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
751       case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
752       case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
753       }
754     }
755   }
756   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
757     Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
758     Standard_Real dens = val->GetDensity();
759     Standard_CString dimdens = "g/cu sm";
760     if(dens==0) 
761       di<<val->GetName()->ToCString();
762     else
763       di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
764   }
765   else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
766     Standard_CString type;
767     if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
768       type = "Layer Instance Link";
769     }
770     else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
771       type = "SHUO Instance Link";
772     }
773     else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
774       type = "DatumToler Link";
775     }
776     else return 0;
777
778     Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
779     TCollection_AsciiString ref;
780     Standard_Integer ii = 1;
781     if (DETGN->NbFathers()!=0) {
782
783       TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
784       di << type<< " ==> (" << ref.ToCString();
785       for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
786         TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
787           di << ", " << ref.ToCString();
788         }
789       di << ") ";
790     }
791     ii = 1;
792     if (DETGN->NbChildren()!=0) {
793       TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
794       di << type<< " <== (" << ref.ToCString();
795       for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
796         TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
797           di << ", " << ref.ToCString();
798         }
799       di << ")";
800     }
801   }
802   return 0;
803 }
804
805
806 //=======================================================================
807 //function : setviewName
808 //purpose  :
809 //=======================================================================
810 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
811 {
812   if (argc <2) {
813     di<<"Use: "<<argv[0]<<" (1/0)"<<"\n";
814     return 1;
815   }
816   Standard_Boolean mode = Standard_False;
817   if (Draw::Atoi(argv[1]) == 1) mode = Standard_True;
818   XCAFPrs::SetViewNameMode(mode);
819   return 0;
820 }
821
822
823 //=======================================================================
824 //function : getviewName
825 //purpose  : auxilary
826 //=======================================================================
827
828 static Standard_Integer getviewName (Draw_Interpretor&  di, Standard_Integer /*argc*/, const char** /*argv*/)
829 {
830   if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n";
831   else di << "Display names OFF"<< "\n";
832   return 0;
833 }
834
835
836 //=======================================================================
837 //function : XSetTransparency
838 //purpose  :
839 //=======================================================================
840 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
841 {
842   if (argc < 3) {
843     di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] "<<"\n";
844     return 1;
845   }
846
847   Handle(TDocStd_Document) Doc;
848   DDocStd::GetDocument(argv[1], Doc);
849   if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
850
851   const Standard_Real aTransparency = Draw::Atof(argv[2]);
852
853   // collect sequence of labels
854   Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
855   TDF_LabelSequence seq;
856   if ( argc > 3 ) {
857     for ( Standard_Integer i=3; i < argc; i++ ) {
858       TDF_Label aLabel;
859       TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
860       if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
861         di << argv[i] << " is not a valid shape label!";
862         continue;
863       }
864       seq.Append ( aLabel );
865     }
866   }
867   else {
868     shapes->GetFreeShapes ( seq );
869   }
870
871   // find presentations and set transparency
872   for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
873     Handle(TPrsStd_AISPresentation) prs;
874     if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
875       prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
876       prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
877     }
878     prs->SetTransparency( aTransparency );
879   }
880   TPrsStd_AISViewer::Update(Doc->GetData()->Root());
881   return 0;
882 }
883
884 //=======================================================================
885 //function : XShowFaceBoundary
886 //purpose  : Set face boundaries on/off
887 //=======================================================================
888 static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
889                                            Standard_Integer argc,
890                                            const char ** argv)
891 {
892   if (( argc != 4 && argc < 7 ) || argc > 9)
893   {
894     di << "Usage :\n " << argv[0]
895        << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
896        << "   Doc       - is the document name. \n"
897        << "   Label     - is the shape label. \n"
898        << "   IsOn      - flag indicating whether the boundaries\n"
899        << "                should be turned on or off (can be set\n"
900        << "                to 0 (off) or 1 (on)).\n"
901        << "   R, G, B   - red, green and blue components of boundary\n"
902        << "                color in range (0 - 255).\n"
903        << "                (default is (0, 0, 0)\n"
904        << "   LineWidth - line width\n"
905        << "                (default is 1)\n"
906        << "   LineStyle - line fill style :\n"
907        << "                 0 - solid  \n"
908        << "                 1 - dashed \n"
909        << "                 2 - dot    \n"
910        << "                 3 - dashdot\n"
911        << "                (default is solid)";
912
913     return 1;
914   }
915
916   // get specified document
917   Handle(TDocStd_Document) aDoc;
918   DDocStd::GetDocument (argv[1], aDoc);
919   if (aDoc.IsNull())
920   {
921     di << argv[1] << " is not a document" << "\n"; 
922     return 1;
923   }
924
925   Handle(AIS_InteractiveContext) aContext;
926   if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext)) 
927   {
928     di << "Cannot find viewer for document " << argv[1] << "\n";
929     return 1;
930   }
931
932   // get shape tool for shape verification
933   Handle(XCAFDoc_ShapeTool) aShapes =
934     XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
935
936   // get label and validate that it is a shape label
937   TDF_Label aLabel;
938   TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
939   if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
940   {
941     di << argv[2] << " is not a valid shape label!";
942     return 1;
943   }
944
945   // get presentation from label
946   Handle(TPrsStd_AISPresentation) aPrs;
947   if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
948   {
949     aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
950   }
951
952   Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
953   if (anInteractive.IsNull ())
954   {
955     di << "Can't set drawer attributes.\n"
956           "Interactive object for shape label doesn't exists.";
957     return 1;
958   }
959
960   // get drawer
961   const Handle(AIS_Drawer)& aDrawer = anInteractive->Attributes ();
962
963   // default attributes
964   Quantity_Parameter aRed      = 0.0;
965   Quantity_Parameter aGreen    = 0.0;
966   Quantity_Parameter aBlue     = 0.0;
967   Standard_Real      aWidth    = 1.0;
968   Aspect_TypeOfLine  aLineType = Aspect_TOL_SOLID;
969   
970   // turn boundaries on/off
971   Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1);
972   aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
973   
974   // set boundary color
975   if (argc >= 7)
976   {
977     // Text color
978     aRed   = Draw::Atof (argv[4])/255.;
979     aGreen = Draw::Atof (argv[5])/255.;
980     aBlue  = Draw::Atof (argv[6])/255.;
981   }
982
983   // set line width
984   if (argc >= 8)
985   {
986     aWidth = (Standard_Real)Draw::Atof (argv[7]);
987   }
988
989   // select appropriate line type
990   if (argc == 9)
991   {
992     switch (Draw::Atoi (argv[8]))
993     {
994       case 1: aLineType = Aspect_TOL_DASH;    break;
995       case 2: aLineType = Aspect_TOL_DOT;     break;
996       case 3: aLineType = Aspect_TOL_DOTDASH; break;
997       default:
998         aLineType = Aspect_TOL_SOLID;
999     }
1000   }
1001
1002   Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
1003
1004   Handle(Prs3d_LineAspect) aBoundaryAspect = 
1005     new Prs3d_LineAspect (aColor, aLineType, aWidth);
1006
1007   aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
1008
1009   aContext->Redisplay (anInteractive);
1010   
1011   return 0;
1012 }
1013
1014 //=======================================================================
1015 //function : testDoc
1016 //purpose  : Method to test destruction of document
1017 //=======================================================================
1018 static Standard_Integer testDoc (Draw_Interpretor& di,
1019                                  Standard_Integer argc,
1020                                  const char ** argv)
1021 {
1022   if( argc < 2 )
1023   {
1024     cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<endl;
1025     return 1;
1026   }
1027   TopoDS_Shape shape = DBRep::Get(argv[1]);
1028   if( shape.IsNull())
1029     return 1;
1030  
1031   Handle(XCAFApp_Application) A = XCAFApp_Application::GetApplication();
1032  
1033   Handle(TDocStd_Document) aD1 = new TDocStd_Document("MDTV-XCAF");
1034   aD1->Open(A);
1035   
1036   Handle(V3d_Viewer) vw = ViewerTest_Tool::MakeViewer ("Test viwer"); 
1037   Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(vw);
1038   TPrsStd_AISViewer::New (aD1->Main(),aContext);
1039   // get shape tool for shape verification
1040   Handle(XCAFDoc_ShapeTool) aShapes =
1041     XCAFDoc_DocumentTool::ShapeTool (aD1->Main());
1042   TDF_Label aLab = aShapes->AddShape(shape);
1043
1044   Handle(Geom_Axis2Placement) aPlacement = 
1045     new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX());
1046   Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement);
1047   
1048   Handle(TNaming_NamedShape) NS;
1049   Handle(TPrsStd_AISPresentation) prs;
1050   if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) {
1051     prs = TPrsStd_AISPresentation::Set( NS );
1052   }
1053    
1054   if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) ) 
1055     prs->Display();
1056   
1057
1058   TPrsStd_AISViewer::Update(aLab);
1059   aContext->Display(aTriShape, Standard_True);
1060   Handle(TDocStd_Owner) owner;
1061   if (aD1->Main().Root().FindAttribute(TDocStd_Owner::GetID(), owner))
1062   {
1063     Handle_TDocStd_Document empty;
1064     owner->SetDocument(empty);
1065   }
1066   aContext.Nullify();
1067   aD1->Close();
1068   aD1.Nullify();
1069   return 0;
1070 }
1071
1072
1073 //=======================================================================
1074 //function : Init
1075 //purpose  :
1076 //=======================================================================
1077
1078 void XDEDRAW::Init(Draw_Interpretor& di)
1079 {
1080
1081   static Standard_Boolean initactor = Standard_False;
1082   if (initactor) return;  initactor = Standard_True;
1083
1084   // Load static variables for STEPCAF (ssv; 16.08.2012)
1085   STEPCAFControl_Controller::Init();
1086
1087   // OCAF *** szy: use <pload> command
1088
1089 //  DDF::AllCommands(di);
1090 //  DNaming::AllCommands(di);
1091 //  DDataStd::AllCommands(di);
1092 //  DPrsStd::AllCommands(di);
1093   //DFunction::AllCommands(di);
1094 //  DDocStd::AllCommands(di);
1095
1096 //  ViewerTest::Commands (di); *** szy: use <pload> command
1097
1098   // init XCAF application (if not yet done)
1099   XCAFApp_Application::GetApplication();
1100
1101   //=====================================
1102   // General commands
1103   //=====================================
1104
1105   Standard_CString g = "XDE general commands";
1106
1107   di.Add ("XNewDoc","DocName \t: Create new DECAF document",
1108                    __FILE__, newDoc, g);
1109
1110   di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
1111                    __FILE__, saveDoc, g);
1112
1113   di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path",
1114           __FILE__, openDoc, g);
1115
1116   di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
1117                    __FILE__, dump, g);
1118
1119   di.Add ("XStat","Doc \t: Print statistics of document",
1120                    __FILE__, statdoc, g);
1121
1122   di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
1123                    __FILE__, setPrs, g);
1124
1125   di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
1126                    __FILE__, show, g);
1127
1128   di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
1129                    __FILE__, xwd, g);
1130
1131   di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
1132                    __FILE__, XAttributeValue, g);
1133
1134   di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
1135                    __FILE__, setviewName, g);
1136
1137   di.Add ("XGetViewNameMode", "\t: Print if  mode of displaying names is turn on.",
1138                    __FILE__, getviewName, g);
1139
1140   di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
1141                    __FILE__, XSetTransparency, g);
1142
1143   di.Add ("XShowFaceBoundary", 
1144           "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
1145           "- turns on/off drawing of face boundaries and defines boundary line style",
1146           __FILE__, XShowFaceBoundary, g);
1147    di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g);
1148
1149   // Specialized commands
1150   XDEDRAW_Shapes::InitCommands ( di );
1151   XDEDRAW_Colors::InitCommands ( di );
1152   XDEDRAW_Layers::InitCommands ( di );
1153   XDEDRAW_Props::InitCommands ( di );
1154   XDEDRAW_Common::InitCommands ( di );//moved from EXE
1155
1156 }
1157
1158
1159 //==============================================================================
1160 // XDEDRAW::Factory
1161 //==============================================================================
1162 void XDEDRAW::Factory(Draw_Interpretor& theDI)
1163 {
1164   XSDRAWIGES::InitSelect();
1165   XSDRAWIGES::InitToBRep(theDI);
1166   XSDRAWIGES::InitFromBRep(theDI);
1167
1168   XSDRAWSTEP::InitCommands(theDI);
1169
1170   SWDRAW::Init(theDI);
1171   XSDRAW::LoadDraw(theDI);
1172
1173   XDEDRAW::Init(theDI);
1174
1175 #ifdef DEB
1176       theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n";
1177 #endif
1178 }
1179
1180 // Declare entry point PLUGINFACTORY
1181 DPLUGIN(XDEDRAW)