1 // Created on: 2000-08-04
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <XDEDRAW.ixx>
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>
30 #include <TopoDS_Shape.hxx>
34 #include <V3d_Viewer.hxx>
35 #include <V3d_View.hxx>
36 #include <AIS_InteractiveContext.hxx>
37 #include <ViewerTest_Tool.hxx>
39 #include <DDF_Browser.hxx>
40 #include <DDocStd.hxx>
41 #include <DDocStd_DrawDocument.hxx>
43 #include <STEPCAFControl_Controller.hxx>
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>
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>
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>
90 #include <XCAFPrs.hxx>
91 #include <ViewerTest.hxx>
92 #include <Draw_PluginMacro.hxx>
94 #include <TColStd_HArray1OfInteger.hxx>
95 #include <TColStd_HArray1OfReal.hxx>
97 #define ZVIEW_SIZE 1000000.0
98 // avoid warnings on 'extern "C"' functions returning C++ classes
100 #pragma warning(4:4190)
103 //=======================================================================
104 // Section: General commands
105 //=======================================================================
107 //=======================================================================
110 //=======================================================================
111 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
113 if (argc < 2) {di<<"Give document name"<<"\n";return 1;}
115 Handle(TDocStd_Document) D;
116 Handle(DDocStd_DrawDocument) DD;
117 Handle(TDocStd_Application) A;
119 if (!DDocStd::Find(A)) return 1;
121 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
122 A->NewDocument( "MDTV-XCAF" ,D);
123 DD = new DDocStd_DrawDocument(D);
124 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
125 Draw::Set(argv[1],DD);
126 di << "document " << argv[1] << " created" << "\n";
127 //DDocStd::ReturnLabel(di,D->Main());
129 else di << argv[1] << " is already a document" << "\n";
135 //=======================================================================
138 //=======================================================================
139 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
141 Handle(TDocStd_Document) D;
142 Handle(TDocStd_Application) A;
143 if (!DDocStd::Find(A)) return 1;
146 if (A->NbDocuments() < 1) return 1;
147 A->GetDocument(1, D);
150 if (!DDocStd::GetDocument(argv[1],D)) return 1;
154 TCollection_ExtendedString path (argv[2]);
159 di << "this document has never been saved" << "\n";
166 //=======================================================================
169 //=======================================================================
170 static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
172 Handle(TDocStd_Document) D;
173 Handle(DDocStd_DrawDocument) DD;
174 Handle(TDocStd_Application) A;
176 if ( !DDocStd::Find(A) )
181 di << "invalid number of arguments. Usage:\t XOpen filename docname" << "\n";
185 Standard_CString Filename = argv[1];
186 Standard_CString DocName = argv[2];
188 if ( DDocStd::GetDocument(DocName, D, Standard_False) )
190 di << "document with name " << DocName << " already exists" << "\n";
194 if ( A->Open(Filename, D) != PCDM_RS_OK )
196 di << "cannot open XDE document" << "\n";
200 DD = new DDocStd_DrawDocument(D);
201 TDataStd_Name::Set(D->GetData()->Root(), DocName);
202 Draw::Set(DocName, DD);
204 di << "document " << DocName << " opened" << "\n";
209 //=======================================================================
212 //=======================================================================
213 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
216 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n";
219 Handle(TDocStd_Document) Doc;
220 DDocStd::GetDocument(argv[1], Doc);
221 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
223 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
224 Standard_Boolean deep = Standard_False;
225 if ( (argc==3) && (atoi(argv[2])==1) ) deep = Standard_True;
226 myAssembly->Dump(deep);
231 //=======================================================================
232 //function : StatAssembly
233 //purpose : recursive part of statistics
234 //=======================================================================
236 static void StatAssembly(const TDF_Label L,
237 const Standard_Integer level,
238 Handle(TColStd_HArray1OfInteger) &HAI,
239 Standard_Integer &NbCentroidProp,
240 Standard_Integer &NbVolumeProp,
241 Standard_Integer &NbAreaProp,
242 Standard_Integer &NbShapesWithName,
243 Standard_Integer &NbShapesWithColor,
244 Standard_Integer &NbShapesWithLayer,
245 Handle(TDocStd_Document) &aDoc,
246 Standard_Boolean &PrintStructMode,
247 Draw_Interpretor& di)
249 if(PrintStructMode) {
250 for(Standard_Integer j=0; j<=level; j++)
253 TCollection_AsciiString Entry;
254 TDF_Tool::Entry(L, Entry);
255 if(PrintStructMode) di<<Entry.ToCString();
257 Handle(TDataStd_Name) Name;
258 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
260 if(PrintStructMode) {
261 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
262 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
266 if(PrintStructMode) di<<" NoName has attributes: ";
269 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
270 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
271 if(PrintStructMode) di<<"Centroid ";
275 if(XCAFDoc_Volume::Get(L,tmp)) {
276 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
279 if(XCAFDoc_Area::Get(L,tmp)) {
280 if(PrintStructMode) di<<"Area("<<tmp<<") ";
283 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
285 Standard_Boolean IsColor = Standard_False;
286 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
287 IsColor = Standard_True;
288 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
289 IsColor = Standard_True;
290 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
291 IsColor = Standard_True;
293 TCollection_AsciiString Entry1;
294 Entry1 = col.StringName(col.Name());
295 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
298 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
299 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
300 LTool->GetLayers(L, aLayerS);
301 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
302 if(PrintStructMode) {
304 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
305 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
307 di<<"\""<<Entry2.ToCString()<<"\"";
309 di<<" "<<"\""<<Entry2.ToCString()<<"\"";
315 if(PrintStructMode) di<<"\n";
317 HAI->SetValue(level, HAI->Value(level)+1 );
319 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
320 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
321 NbAreaProp, NbShapesWithName, NbShapesWithColor,
322 NbShapesWithLayer, aDoc, PrintStructMode, di);
329 //=======================================================================
332 //=======================================================================
333 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
336 di<<"Use: "<<argv[0]<<" Doc "<<"\n";
339 Handle(TDocStd_Document) Doc;
340 DDocStd::GetDocument(argv[1], Doc);
341 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
343 Standard_Boolean PrintStructMode = (argc==3);
344 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
346 TDF_LabelSequence SeqLabels;
347 aTool->GetShapes(SeqLabels);
348 if(SeqLabels.Length()<=0) return 0;
349 if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n";
350 Standard_Integer level=0;
351 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
352 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
353 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
354 Standard_Integer i=0;
355 for(i=0; i<=20; i++) HAI->SetValue(i,0);
356 for(i=1; i<=SeqLabels.Length(); i++) {
357 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
358 NbAreaProp, NbShapesWithName, NbShapesWithColor,
359 NbShapesWithLayer, Doc, PrintStructMode, di);
361 Standard_Integer NbLabelsShape = 0;
362 di<<"\n"<<"Statistis of shapes in the document:"<<"\n";
363 for(i=0; i<=20; i++) {
364 if(HAI->Value(i)==0) break;
365 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
366 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
367 NbLabelsShape = NbLabelsShape + HAI->Value(i);
369 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
370 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
371 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
372 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
374 di<<"\n"<<"Statistis of Props in the document:"<<"\n";
375 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
376 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
377 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
379 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
380 TDF_LabelSequence CLabels;
381 CTool->GetColors(CLabels);
382 di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n";
383 if(CLabels.Length()>0) {
384 for(i=1; i<=CLabels.Length(); i++) {
385 TDF_Label aLabel = CLabels.Value(i);
387 CTool->GetColor(aLabel, col);
388 di<<col.StringName(col.Name())<<" ";
393 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
394 TDF_LabelSequence LLabels;
395 LTool->GetLayerLabels(LLabels);
396 di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n";
397 if(LLabels.Length()>0) {
398 for(i=1; i<=LLabels.Length(); i++) {
399 TDF_Label aLabel = LLabels.Value(i);
400 TCollection_ExtendedString layerName;
401 LTool->GetLayer(aLabel, layerName);
402 TCollection_AsciiString Entry(layerName,'?');
403 di<<"\""<<Entry.ToCString() <<"\" ";
413 //=======================================================================
416 //=======================================================================
417 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
420 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
424 Handle(TDocStd_Document) Doc;
425 DDocStd::GetDocument(argv[1], Doc);
426 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
428 // collect sequence of labels to set presentation
429 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
430 TDF_LabelSequence seq;
432 for ( Standard_Integer i=2; i < argc; i++ ) {
434 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
435 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
436 di << argv[i] << " is not a valid shape label!";
439 seq.Append ( aLabel );
443 shapes->GetShapes ( seq );
447 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
448 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
449 Handle(TPrsStd_AISPresentation) prs;
450 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
451 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
452 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
454 // Quantity_Color Col;
455 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
456 // prs->SetColor ( Col.Name() );
457 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
458 // prs->SetColor ( Col.Name() );
464 //=======================================================================
467 //=======================================================================
468 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
471 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
475 Handle(TDocStd_Document) Doc;
476 DDocStd::GetDocument(argv[1], Doc);
477 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
481 // sprintf ( string, "AISInitViewer %s", argv[1] );
482 // di.Eval ( string );
483 TDF_Label acces = Doc->GetData()->Root();
484 Handle(TPrsStd_AISViewer) viewer;
485 if (!TPrsStd_AISViewer::Find (acces,viewer)) {
486 TCollection_AsciiString title;
487 title.Prepend(argv[1]);
489 title.Prepend("Document");
490 Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString());
491 viewer = TPrsStd_AISViewer::New (acces,vw);
493 ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
495 //szv:CAX-TRJ7 c2-pe-214.stp was clipped
496 viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE);
497 //DDF::ReturnLabel(di,viewer->Label());
499 // collect sequence of labels to display
500 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
501 TDF_LabelSequence seq;
503 for ( Standard_Integer i=2; i < argc; i++ ) {
505 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
506 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
507 di << argv[i] << " is not a valid shape label!";
510 seq.Append ( aLabel );
514 shapes->GetFreeShapes ( seq );
517 // set presentations and show
518 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
519 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
520 Handle(TPrsStd_AISPresentation) prs;
521 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
522 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
523 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
525 // Quantity_Color Col;
526 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
527 // prs->SetColor ( Col.Name() );
528 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
529 // prs->SetColor ( Col.Name() );
530 prs->Display(Standard_True);
532 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
537 //=======================================================================
540 //=======================================================================
541 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
544 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n";
548 Handle(TDocStd_Document) Doc;
549 DDocStd::GetDocument(argv[1], Doc);
550 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
552 Handle(AIS_InteractiveContext) IC;
553 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
554 di << "Cannot find viewer for document " << argv[1] << "\n";
558 Handle(V3d_Viewer) viewer = IC->CurrentViewer();
559 viewer->InitActiveViews();
560 if ( viewer->MoreActiveViews() ) {
561 viewer->ActiveView()->Dump ( argv[2] );
564 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
572 //=======================================================================
573 //function : XAttributeValue
575 //=======================================================================
576 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
578 if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; }
579 Handle(DDF_Browser) browser =
580 Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
581 if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
584 TDF_Tool::Label(browser->Data(),argv[2],lab);
585 if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
587 Standard_Integer num = atoi ( argv[3] );
588 TDF_AttributeIterator itr(lab,Standard_False);
589 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
591 if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; }
593 const Handle(TDF_Attribute)& att = itr.Value();
594 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
595 Standard_CString type = "";
596 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
597 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
598 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
599 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
600 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
601 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
602 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
603 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
604 TCollection_AsciiString ref;
605 if ( TN->HasFather() ) {
606 TDF_Tool::Entry ( TN->Father()->Label(), ref );
607 di << type << " ==> " << ref.ToCString();
610 di << type << " <== (" << ref.ToCString();
611 Handle(TDataStd_TreeNode) child = TN->First();
612 while ( ! child.IsNull() ) {
613 TDF_Tool::Entry ( child->Label(), ref );
614 if ( child != TN->First() ) di << ", ";
615 di << ref.ToCString();
616 child = child->Next();
621 else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
622 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
623 TCollection_AsciiString ref;
624 TDF_Tool::Entry ( val->Get(), ref );
625 di << "==> " << ref.ToCString();
627 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
628 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
629 TCollection_AsciiString str ( val->Get() );
630 di << str.ToCString();
632 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
633 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
634 TCollection_AsciiString str ( val->Get() );
635 di << str.ToCString();
637 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
638 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
639 TCollection_AsciiString str ( val->Get(), '?' );
640 di << str.ToCString();
642 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
643 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
644 TCollection_AsciiString str ( val->Get(), '?' );
645 di << str.ToCString();
647 else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
648 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
649 TCollection_AsciiString str ( val->Get(), '?' );
650 di << str.ToCString();
652 else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
653 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
654 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
655 if ( j > val->Lower() ) di << ", ";
656 TCollection_AsciiString str ( val->Value(j) );
657 di << str.ToCString();
660 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
661 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::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();
668 else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
669 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::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();
676 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
677 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
678 TopoDS_Shape S = val->Get();
679 di << S.TShape()->DynamicType()->Name();
680 if ( ! S.Location().IsIdentity() ) di << "(located)";
682 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
683 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
684 TCollection_AsciiString str ( val->Get() );
685 di << str.ToCString();
687 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
688 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
689 TCollection_AsciiString str ( val->Get() );
690 di << str.ToCString();
692 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
693 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
694 gp_Pnt myCentroid = val->Get();
696 di << myCentroid.X();
698 di << myCentroid.Y();
700 di << myCentroid.Z();
703 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
704 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
705 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
707 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
708 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
709 Quantity_Color C = val->GetColor();
711 sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
712 C.Red(), C.Green(), C.Blue() );
715 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
716 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
717 Standard_Integer kind = val->GetKind();
718 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
719 if(kind<20) { //dimension
720 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
724 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
725 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
726 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
727 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
728 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
729 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
730 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
731 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
732 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
733 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
734 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
735 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
736 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
737 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
738 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
739 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
740 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
741 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
742 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
743 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
744 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
748 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
749 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
750 Standard_Real dens = val->GetDensity();
751 Standard_CString dimdens = "g/cu sm";
753 di<<val->GetName()->ToCString();
755 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
757 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
758 Standard_CString type;
759 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
760 type = "Layer Instance Link";
762 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
763 type = "SHUO Instance Link";
765 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
766 type = "DatumToler Link";
770 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
771 TCollection_AsciiString ref;
772 Standard_Integer ii = 1;
773 if (DETGN->NbFathers()!=0) {
775 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
776 di << type<< " ==> (" << ref.ToCString();
777 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
778 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
779 di << ", " << ref.ToCString();
784 if (DETGN->NbChildren()!=0) {
785 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
786 di << type<< " <== (" << ref.ToCString();
787 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
788 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
789 di << ", " << ref.ToCString();
798 //=======================================================================
799 //function : setviewName
801 //=======================================================================
802 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
805 di<<"Use: "<<argv[0]<<" (1/0)"<<"\n";
808 Standard_Boolean mode = Standard_False;
809 if (atoi(argv[1]) == 1) mode = Standard_True;
810 XCAFPrs::SetViewNameMode(mode);
815 //=======================================================================
816 //function : getviewName
818 //=======================================================================
820 static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
822 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n";
823 else di << "Display names OFF"<< "\n";
828 //=======================================================================
829 //function : XSetTransparency
831 //=======================================================================
832 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
835 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] "<<"\n";
839 Handle(TDocStd_Document) Doc;
840 DDocStd::GetDocument(argv[1], Doc);
841 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
843 const Standard_Real aTransparency = atof(argv[2]);
845 // collect sequence of labels
846 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
847 TDF_LabelSequence seq;
849 for ( Standard_Integer i=3; i < argc; i++ ) {
851 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
852 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
853 di << argv[i] << " is not a valid shape label!";
856 seq.Append ( aLabel );
860 shapes->GetFreeShapes ( seq );
863 // find presentations and set transparency
864 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
865 Handle(TPrsStd_AISPresentation) prs;
866 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
867 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
868 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
870 prs->SetTransparency( aTransparency );
872 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
877 //=======================================================================
880 //=======================================================================
882 void XDEDRAW::Init(Draw_Interpretor& di)
885 static Standard_Boolean initactor = Standard_False;
886 if (initactor) return; initactor = Standard_True;
888 // Load static variables for STEPCAF (ssv; 16.08.2012)
889 STEPCAFControl_Controller::Init();
891 // OCAF *** szy: use <pload> command
893 // DDF::AllCommands(di);
894 // DNaming::AllCommands(di);
895 // DDataStd::AllCommands(di);
896 // DPrsStd::AllCommands(di);
897 //DFunction::AllCommands(di);
898 // DDocStd::AllCommands(di);
900 // ViewerTest::Commands (di); *** szy: use <pload> command
902 // init XCAF application (if not yet done)
903 XCAFApp_Application::GetApplication();
905 //=====================================
907 //=====================================
909 Standard_CString g = "XDE general commands";
911 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
912 __FILE__, newDoc, g);
914 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
915 __FILE__, saveDoc, g);
917 di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path",
918 __FILE__, openDoc, g);
920 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
923 di.Add ("XStat","Doc \t: Print statistics of document",
924 __FILE__, statdoc, g);
926 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
927 __FILE__, setPrs, g);
929 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
932 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
935 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
936 __FILE__, XAttributeValue, g);
938 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
939 __FILE__, setviewName, g);
941 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
942 __FILE__, getviewName, g);
944 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
945 __FILE__, XSetTransparency, g);
947 // Specialized commands
948 XDEDRAW_Shapes::InitCommands ( di );
949 XDEDRAW_Colors::InitCommands ( di );
950 XDEDRAW_Layers::InitCommands ( di );
951 XDEDRAW_Props::InitCommands ( di );
952 XDEDRAW_Common::InitCommands ( di );//moved from EXE
957 //==============================================================================
959 //==============================================================================
960 void XDEDRAW::Factory(Draw_Interpretor& theDI)
962 XSDRAWIGES::InitSelect();
963 XSDRAWIGES::InitToBRep(theDI);
964 XSDRAWIGES::InitFromBRep(theDI);
966 XSDRAWSTEP::InitCommands(theDI);
969 XSDRAW::LoadDraw(theDI);
971 XDEDRAW::Init(theDI);
974 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n";
978 // Declare entry point PLUGINFACTORY