2 // Created: Fri Aug 4 14:38:55 2000
3 // Author: Pavel TELKOV
8 #include <TCollection_ExtendedString.hxx>
9 #include <TCollection_AsciiString.hxx>
10 #include <TColStd_HSequenceOfExtendedString.hxx>
11 #include <TCollection_HAsciiString.hxx>
12 #include <Quantity_Color.hxx>
14 #include <TopoDS_Shape.hxx>
18 #include <V3d_Viewer.hxx>
19 #include <V3d_View.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <ViewerTest_Tool.hxx>
23 #include <DDF_Browser.hxx>
24 #include <DDocStd.hxx>
25 #include <DDocStd_DrawDocument.hxx>
27 #include <TDF_Tool.hxx>
28 #include <TDF_Data.hxx>
29 #include <TDF_LabelSequence.hxx>
30 #include <TDF_AttributeIterator.hxx>
31 #include <TDocStd_Document.hxx>
32 #include <TDataStd_UAttribute.hxx>
33 #include <TDataStd_TreeNode.hxx>
34 #include <TDataStd_Integer.hxx>
35 #include <TDataStd_Real.hxx>
36 #include <TDataStd_Name.hxx>
37 #include <TNaming_NamedShape.hxx>
38 #include <TDataStd_RealArray.hxx>
39 #include <TPrsStd_AISPresentation.hxx>
40 #include <TPrsStd_NamedShapeDriver.hxx>
41 #include <TPrsStd_AISViewer.hxx>
43 #include <XCAFDoc.hxx>
44 #include <XCAFDoc_Color.hxx>
45 #include <XCAFDoc_Volume.hxx>
46 #include <XCAFDoc_Area.hxx>
47 #include <XCAFDoc_Centroid.hxx>
48 #include <XCAFDoc_ShapeTool.hxx>
49 #include <XCAFDoc_ColorTool.hxx>
50 #include <XCAFDoc_DocumentTool.hxx>
51 #include <XCAFDoc_GraphNode.hxx>
52 #include <XCAFDoc_LayerTool.hxx>
53 #include <XCAFDoc_DimTol.hxx>
54 #include <XCAFDoc_Material.hxx>
55 #include <XCAFPrs_Driver.hxx>
56 #include <XCAFApp_Application.hxx>
58 #include <XDEDRAW_Shapes.hxx>
59 #include <XDEDRAW_Colors.hxx>
60 #include <XDEDRAW_Layers.hxx>
61 #include <XDEDRAW_Props.hxx>
62 #include <XDEDRAW_Common.hxx>
63 #include <XSDRAWIGES.hxx>
64 #include <XSDRAWSTEP.hxx>
67 #include <XCAFPrs.hxx>
68 #include <ViewerTest.hxx>
69 #include <Draw_PluginMacro.hxx>
71 #include <TColStd_HArray1OfInteger.hxx>
72 #include <TColStd_HArray1OfReal.hxx>
74 #define ZVIEW_SIZE 1000000.0
75 // avoid warnings on 'extern "C"' functions returning C++ classes
77 #pragma warning(4:4190)
80 //=======================================================================
81 // Section: General commands
82 //=======================================================================
84 //=======================================================================
87 //=======================================================================
88 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
90 if (argc < 2) {di<<"Give document name"<<"\n";return 1;}
92 Handle(TDocStd_Document) D;
93 Handle(DDocStd_DrawDocument) DD;
94 Handle(TDocStd_Application) A;
96 if (!DDocStd::Find(A)) return 1;
98 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
99 A->NewDocument( "MDTV-XCAF" ,D);
100 DD = new DDocStd_DrawDocument(D);
101 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
102 Draw::Set(argv[1],DD);
103 di << "document " << argv[1] << " created" << "\n";
104 //DDocStd::ReturnLabel(di,D->Main());
106 else di << argv[1] << " is already a document" << "\n";
112 //=======================================================================
115 //=======================================================================
116 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
118 Handle(TDocStd_Document) D;
119 Handle(TDocStd_Application) A;
120 if (!DDocStd::Find(A)) return 1;
123 if (A->NbDocuments() < 1) return 1;
124 A->GetDocument(1, D);
127 if (!DDocStd::GetDocument(argv[1],D)) return 1;
131 TCollection_ExtendedString path (argv[2]);
136 di << "this document has never been saved" << "\n";
144 //=======================================================================
147 //=======================================================================
148 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
151 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n";
154 Handle(TDocStd_Document) Doc;
155 DDocStd::GetDocument(argv[1], Doc);
156 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
158 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
159 Standard_Boolean deep = Standard_False;
160 if ( (argc==3) && (atoi(argv[2])==1) ) deep = Standard_True;
161 myAssembly->Dump(deep);
166 //=======================================================================
167 //function : StatAssembly
168 //purpose : recursive part of statistics
169 //=======================================================================
171 static void StatAssembly(const TDF_Label L,
172 const Standard_Integer level,
173 Handle(TColStd_HArray1OfInteger) &HAI,
174 Standard_Integer &NbCentroidProp,
175 Standard_Integer &NbVolumeProp,
176 Standard_Integer &NbAreaProp,
177 Standard_Integer &NbShapesWithName,
178 Standard_Integer &NbShapesWithColor,
179 Standard_Integer &NbShapesWithLayer,
180 Handle(TDocStd_Document) &aDoc,
181 Standard_Boolean &PrintStructMode,
182 Draw_Interpretor& di)
184 if(PrintStructMode) {
185 for(Standard_Integer j=0; j<=level; j++)
188 TCollection_AsciiString Entry;
189 TDF_Tool::Entry(L, Entry);
190 if(PrintStructMode) di<<Entry.ToCString();
192 Handle(TDataStd_Name) Name;
193 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
195 if(PrintStructMode) {
196 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
197 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
201 if(PrintStructMode) di<<" NoName has attributes: ";
204 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
205 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
206 if(PrintStructMode) di<<"Centroid ";
210 if(XCAFDoc_Volume::Get(L,tmp)) {
211 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
214 if(XCAFDoc_Area::Get(L,tmp)) {
215 if(PrintStructMode) di<<"Area("<<tmp<<") ";
218 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
220 Standard_Boolean IsColor = Standard_False;
221 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
222 IsColor = Standard_True;
223 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
224 IsColor = Standard_True;
225 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
226 IsColor = Standard_True;
228 TCollection_AsciiString Entry1;
229 Entry1 = col.StringName(col.Name());
230 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
233 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
234 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
235 LTool->GetLayers(L, aLayerS);
236 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
237 if(PrintStructMode) {
239 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
240 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
242 di<<"\""<<Entry2.ToCString()<<"\"";
244 di<<" "<<"\""<<Entry2.ToCString()<<"\"";
250 if(PrintStructMode) di<<"\n";
252 HAI->SetValue(level, HAI->Value(level)+1 );
254 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
255 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
256 NbAreaProp, NbShapesWithName, NbShapesWithColor,
257 NbShapesWithLayer, aDoc, PrintStructMode, di);
264 //=======================================================================
267 //=======================================================================
268 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
271 di<<"Use: "<<argv[0]<<" Doc "<<"\n";
274 Handle(TDocStd_Document) Doc;
275 DDocStd::GetDocument(argv[1], Doc);
276 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
278 Standard_Boolean PrintStructMode = (argc==3);
279 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
281 TDF_LabelSequence SeqLabels;
282 aTool->GetShapes(SeqLabels);
283 if(SeqLabels.Length()<=0) return 0;
284 if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n";
285 Standard_Integer level=0;
286 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
287 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
288 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
289 Standard_Integer i=0;
290 for(i=0; i<=20; i++) HAI->SetValue(i,0);
291 for(i=1; i<=SeqLabels.Length(); i++) {
292 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
293 NbAreaProp, NbShapesWithName, NbShapesWithColor,
294 NbShapesWithLayer, Doc, PrintStructMode, di);
296 Standard_Integer NbLabelsShape = 0;
297 di<<"\n"<<"Statistis of shapes in the document:"<<"\n";
298 for(i=0; i<=20; i++) {
299 if(HAI->Value(i)==0) break;
300 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
301 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
302 NbLabelsShape = NbLabelsShape + HAI->Value(i);
304 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
305 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
306 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
307 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
309 di<<"\n"<<"Statistis of Props in the document:"<<"\n";
310 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
311 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
312 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
314 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
315 TDF_LabelSequence CLabels;
316 CTool->GetColors(CLabels);
317 di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n";
318 if(CLabels.Length()>0) {
319 for(i=1; i<=CLabels.Length(); i++) {
320 TDF_Label aLabel = CLabels.Value(i);
322 CTool->GetColor(aLabel, col);
323 di<<col.StringName(col.Name())<<" ";
328 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
329 TDF_LabelSequence LLabels;
330 LTool->GetLayerLabels(LLabels);
331 di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n";
332 if(LLabels.Length()>0) {
333 for(i=1; i<=LLabels.Length(); i++) {
334 TDF_Label aLabel = LLabels.Value(i);
335 TCollection_ExtendedString layerName;
336 LTool->GetLayer(aLabel, layerName);
337 TCollection_AsciiString Entry(layerName,'?');
338 di<<"\""<<Entry.ToCString() <<"\" ";
348 //=======================================================================
351 //=======================================================================
352 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
355 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
359 Handle(TDocStd_Document) Doc;
360 DDocStd::GetDocument(argv[1], Doc);
361 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
363 // collect sequence of labels to set presentation
364 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
365 TDF_LabelSequence seq;
367 for ( Standard_Integer i=2; i < argc; i++ ) {
369 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
370 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
371 di << argv[i] << " is not a valid shape label!";
374 seq.Append ( aLabel );
378 shapes->GetShapes ( seq );
382 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
383 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
384 Handle(TPrsStd_AISPresentation) prs;
385 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
386 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
387 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
389 // Quantity_Color Col;
390 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
391 // prs->SetColor ( Col.Name() );
392 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
393 // prs->SetColor ( Col.Name() );
399 //=======================================================================
402 //=======================================================================
403 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
406 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
410 Handle(TDocStd_Document) Doc;
411 DDocStd::GetDocument(argv[1], Doc);
412 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
416 // sprintf ( string, "AISInitViewer %s", argv[1] );
417 // di.Eval ( string );
418 TDF_Label acces = Doc->GetData()->Root();
419 Handle(TPrsStd_AISViewer) viewer;
420 if (!TPrsStd_AISViewer::Find (acces,viewer)) {
421 TCollection_AsciiString title;
422 title.Prepend(argv[1]);
424 title.Prepend("Document");
425 Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString());
426 viewer = TPrsStd_AISViewer::New (acces,vw);
428 ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
430 //szv:CAX-TRJ7 c2-pe-214.stp was clipped
431 viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE);
432 //DDF::ReturnLabel(di,viewer->Label());
434 // collect sequence of labels to display
435 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
436 TDF_LabelSequence seq;
438 for ( Standard_Integer i=2; i < argc; i++ ) {
440 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
441 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
442 di << argv[i] << " is not a valid shape label!";
445 seq.Append ( aLabel );
449 shapes->GetFreeShapes ( seq );
452 // set presentations and show
453 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
454 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
455 Handle(TPrsStd_AISPresentation) prs;
456 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
457 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
458 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
460 // Quantity_Color Col;
461 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
462 // prs->SetColor ( Col.Name() );
463 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
464 // prs->SetColor ( Col.Name() );
465 prs->Display(Standard_True);
467 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
472 //=======================================================================
475 //=======================================================================
476 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
479 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n";
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; }
487 Handle(AIS_InteractiveContext) IC;
488 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
489 di << "Cannot find viewer for document " << argv[1] << "\n";
493 Handle(V3d_Viewer) viewer = IC->CurrentViewer();
494 viewer->InitActiveViews();
495 if ( viewer->MoreActiveViews() ) {
496 viewer->ActiveView()->Dump ( argv[2] );
499 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
507 //=======================================================================
508 //function : XAttributeValue
510 //=======================================================================
511 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
513 if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; }
514 Handle(DDF_Browser) browser =
515 Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
516 if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
519 TDF_Tool::Label(browser->Data(),argv[2],lab);
520 if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
522 Standard_Integer num = atoi ( argv[3] );
523 TDF_AttributeIterator itr(lab,Standard_False);
524 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
526 if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; }
528 const Handle(TDF_Attribute)& att = itr.Value();
529 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
530 Standard_CString type;
531 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
532 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
533 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
534 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
535 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
536 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
537 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
539 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
540 TCollection_AsciiString ref;
541 if ( TN->HasFather() ) {
542 TDF_Tool::Entry ( TN->Father()->Label(), ref );
543 di << type << " ==> " << ref.ToCString();
546 di << type << " <== (" << ref.ToCString();
547 Handle(TDataStd_TreeNode) child = TN->First();
548 while ( ! child.IsNull() ) {
549 TDF_Tool::Entry ( child->Label(), ref );
550 if ( child != TN->First() ) di << ", ";
551 di << ref.ToCString();
552 child = child->Next();
557 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
558 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
559 TCollection_AsciiString str ( val->Get() );
560 di << str.ToCString();
562 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
563 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
564 TCollection_AsciiString str ( val->Get() );
565 di << str.ToCString();
567 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
568 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
569 TCollection_AsciiString str ( val->Get() );
570 di << str.ToCString();
572 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
573 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
574 TCollection_AsciiString str ( val->Get() );
575 di << str.ToCString();
577 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
578 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
579 gp_Pnt myCentroid = val->Get();
581 di << myCentroid.X();
583 di << myCentroid.Y();
585 di << myCentroid.Z();
588 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
589 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
590 TCollection_AsciiString str ( val->Get(), '?' );
591 di << str.ToCString();
593 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
594 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
595 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
596 if ( j > val->Lower() ) di << ", ";
597 TCollection_AsciiString str ( val->Value(j) );
598 di << str.ToCString();
601 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
602 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
603 TopoDS_Shape S = val->Get();
604 di << S.TShape()->DynamicType()->Name();
605 if ( ! S.Location().IsIdentity() ) di << "(located)";
607 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
608 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
609 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
611 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
612 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
613 Quantity_Color C = val->GetColor();
615 sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
616 C.Red(), C.Green(), C.Blue() );
619 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
620 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
621 Standard_Integer kind = val->GetKind();
622 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
623 if(kind<20) { //dimension
624 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
628 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
629 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
630 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
631 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
632 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
633 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
634 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
635 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
636 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
637 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
638 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
639 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
640 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
641 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
642 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
643 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
644 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
645 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
646 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
647 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
648 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
652 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
653 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
654 Standard_Real dens = val->GetDensity();
655 Standard_CString dimdens = "g/cu sm";
657 di<<val->GetName()->ToCString();
659 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
661 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
662 Standard_CString type;
663 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
664 type = "Layer Instance Link";
666 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
667 type = "SHUO Instance Link";
669 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
670 type = "DatumToler Link";
674 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
675 TCollection_AsciiString ref;
676 Standard_Integer ii = 1;
677 if (DETGN->NbFathers()!=0) {
679 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
680 di << type<< " ==> (" << ref.ToCString();
681 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
682 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
683 di << ", " << ref.ToCString();
688 if (DETGN->NbChildren()!=0) {
689 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
690 di << type<< " <== (" << ref.ToCString();
691 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
692 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
693 di << ", " << ref.ToCString();
702 //=======================================================================
703 //function : setviewName
705 //=======================================================================
706 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
709 di<<"Use: "<<argv[0]<<" (1/0)"<<"\n";
712 Standard_Boolean mode = Standard_False;
713 if (atoi(argv[1]) == 1) mode = Standard_True;
714 XCAFPrs::SetViewNameMode(mode);
719 //=======================================================================
720 //function : getviewName
722 //=======================================================================
724 static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
726 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n";
727 else di << "Display names OFF"<< "\n";
732 //=======================================================================
733 //function : XSetTransparency
735 //=======================================================================
736 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
739 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] "<<"\n";
743 Handle(TDocStd_Document) Doc;
744 DDocStd::GetDocument(argv[1], Doc);
745 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
747 const Standard_Real aTransparency = atof(argv[2]);
749 // collect sequence of labels
750 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
751 TDF_LabelSequence seq;
753 for ( Standard_Integer i=3; i < argc; i++ ) {
755 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
756 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
757 di << argv[i] << " is not a valid shape label!";
760 seq.Append ( aLabel );
764 shapes->GetFreeShapes ( seq );
767 // find presentations and set transparency
768 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
769 Handle(TPrsStd_AISPresentation) prs;
770 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
771 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
772 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
774 prs->SetTransparency( aTransparency );
776 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
781 //=======================================================================
784 //=======================================================================
786 void XDEDRAW::Init(Draw_Interpretor& di)
789 static Standard_Boolean initactor = Standard_False;
790 if (initactor) return; initactor = Standard_True;
792 // OCAF *** szy: use <pload> command
794 // DDF::AllCommands(di);
795 // DNaming::AllCommands(di);
796 // DDataStd::AllCommands(di);
797 // DPrsStd::AllCommands(di);
798 //DFunction::AllCommands(di);
799 // DDocStd::AllCommands(di);
801 // ViewerTest::Commands (di); *** szy: use <pload> command
803 // init XCAF application (if not yet done)
804 XCAFApp_Application::GetApplication();
806 //=====================================
808 //=====================================
810 Standard_CString g = "XDE general commands";
812 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
813 __FILE__, newDoc, g);
815 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
816 __FILE__, saveDoc, g);
818 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
821 di.Add ("XStat","Doc \t: Print statistics of document",
822 __FILE__, statdoc, g);
824 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
825 __FILE__, setPrs, g);
827 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
830 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
833 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
834 __FILE__, XAttributeValue, g);
836 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
837 __FILE__, setviewName, g);
839 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
840 __FILE__, getviewName, g);
842 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
843 __FILE__, XSetTransparency, g);
845 // Specialized commands
846 XDEDRAW_Shapes::InitCommands ( di );
847 XDEDRAW_Colors::InitCommands ( di );
848 XDEDRAW_Layers::InitCommands ( di );
849 XDEDRAW_Props::InitCommands ( di );
850 XDEDRAW_Common::InitCommands ( di );//moved from EXE
855 //==============================================================================
857 //==============================================================================
858 void XDEDRAW::Factory(Draw_Interpretor& theDI)
860 XSDRAWIGES::InitSelect();
861 XSDRAWIGES::InitToBRep(theDI);
862 XSDRAWIGES::InitFromBRep(theDI);
864 XSDRAWSTEP::InitCommands(theDI);
867 XSDRAW::LoadDraw(theDI);
869 XDEDRAW::Init(theDI);
872 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n";
876 // Declare entry point PLUGINFACTORY