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 #include <AIS_InteractiveObject.hxx>
98 #include <AIS_Drawer.hxx>
99 #include <Aspect_TypeOfLine.hxx>
100 #include <Prs3d_LineAspect.hxx>
102 #define ZVIEW_SIZE 1000000.0
103 // avoid warnings on 'extern "C"' functions returning C++ classes
105 #pragma warning(4:4190)
108 //=======================================================================
109 // Section: General commands
110 //=======================================================================
112 //=======================================================================
115 //=======================================================================
116 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
118 if (argc < 2) {di<<"Give document name"<<"\n";return 1;}
120 Handle(TDocStd_Document) D;
121 Handle(DDocStd_DrawDocument) DD;
122 Handle(TDocStd_Application) A;
124 if (!DDocStd::Find(A)) return 1;
126 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
127 A->NewDocument( "MDTV-XCAF" ,D);
128 DD = new DDocStd_DrawDocument(D);
129 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
130 Draw::Set(argv[1],DD);
131 di << "document " << argv[1] << " created" << "\n";
132 //DDocStd::ReturnLabel(di,D->Main());
134 else di << argv[1] << " is already a document" << "\n";
140 //=======================================================================
143 //=======================================================================
144 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
146 Handle(TDocStd_Document) D;
147 Handle(TDocStd_Application) A;
148 if (!DDocStd::Find(A)) return 1;
151 if (A->NbDocuments() < 1) return 1;
152 A->GetDocument(1, D);
155 if (!DDocStd::GetDocument(argv[1],D)) return 1;
159 TCollection_ExtendedString path (argv[2]);
164 di << "this document has never been saved" << "\n";
171 //=======================================================================
174 //=======================================================================
175 static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
177 Handle(TDocStd_Document) D;
178 Handle(DDocStd_DrawDocument) DD;
179 Handle(TDocStd_Application) A;
181 if ( !DDocStd::Find(A) )
186 di << "invalid number of arguments. Usage:\t XOpen filename docname" << "\n";
190 Standard_CString Filename = argv[1];
191 Standard_CString DocName = argv[2];
193 if ( DDocStd::GetDocument(DocName, D, Standard_False) )
195 di << "document with name " << DocName << " already exists" << "\n";
199 if ( A->Open(Filename, D) != PCDM_RS_OK )
201 di << "cannot open XDE document" << "\n";
205 DD = new DDocStd_DrawDocument(D);
206 TDataStd_Name::Set(D->GetData()->Root(), DocName);
207 Draw::Set(DocName, DD);
209 di << "document " << DocName << " opened" << "\n";
214 //=======================================================================
217 //=======================================================================
218 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
221 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n";
224 Handle(TDocStd_Document) Doc;
225 DDocStd::GetDocument(argv[1], Doc);
226 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
228 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
229 Standard_Boolean deep = Standard_False;
230 if ( (argc==3) && (atoi(argv[2])==1) ) deep = Standard_True;
231 myAssembly->Dump(deep);
236 //=======================================================================
237 //function : StatAssembly
238 //purpose : recursive part of statistics
239 //=======================================================================
241 static void StatAssembly(const TDF_Label L,
242 const Standard_Integer level,
243 Handle(TColStd_HArray1OfInteger) &HAI,
244 Standard_Integer &NbCentroidProp,
245 Standard_Integer &NbVolumeProp,
246 Standard_Integer &NbAreaProp,
247 Standard_Integer &NbShapesWithName,
248 Standard_Integer &NbShapesWithColor,
249 Standard_Integer &NbShapesWithLayer,
250 Handle(TDocStd_Document) &aDoc,
251 Standard_Boolean &PrintStructMode,
252 Draw_Interpretor& di)
254 if(PrintStructMode) {
255 for(Standard_Integer j=0; j<=level; j++)
258 TCollection_AsciiString Entry;
259 TDF_Tool::Entry(L, Entry);
260 if(PrintStructMode) di<<Entry.ToCString();
262 Handle(TDataStd_Name) Name;
263 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
265 if(PrintStructMode) {
266 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
267 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
271 if(PrintStructMode) di<<" NoName has attributes: ";
274 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
275 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
276 if(PrintStructMode) di<<"Centroid ";
280 if(XCAFDoc_Volume::Get(L,tmp)) {
281 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
284 if(XCAFDoc_Area::Get(L,tmp)) {
285 if(PrintStructMode) di<<"Area("<<tmp<<") ";
288 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
290 Standard_Boolean IsColor = Standard_False;
291 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
292 IsColor = Standard_True;
293 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
294 IsColor = Standard_True;
295 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
296 IsColor = Standard_True;
298 TCollection_AsciiString Entry1;
299 Entry1 = col.StringName(col.Name());
300 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
303 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
304 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
305 LTool->GetLayers(L, aLayerS);
306 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
307 if(PrintStructMode) {
309 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
310 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
312 di<<"\""<<Entry2.ToCString()<<"\"";
314 di<<" "<<"\""<<Entry2.ToCString()<<"\"";
320 if(PrintStructMode) di<<"\n";
322 HAI->SetValue(level, HAI->Value(level)+1 );
324 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
325 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
326 NbAreaProp, NbShapesWithName, NbShapesWithColor,
327 NbShapesWithLayer, aDoc, PrintStructMode, di);
334 //=======================================================================
337 //=======================================================================
338 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
341 di<<"Use: "<<argv[0]<<" Doc "<<"\n";
344 Handle(TDocStd_Document) Doc;
345 DDocStd::GetDocument(argv[1], Doc);
346 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
348 Standard_Boolean PrintStructMode = (argc==3);
349 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
351 TDF_LabelSequence SeqLabels;
352 aTool->GetShapes(SeqLabels);
353 if(SeqLabels.Length()<=0) return 0;
354 if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n";
355 Standard_Integer level=0;
356 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
357 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
358 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
359 Standard_Integer i=0;
360 for(i=0; i<=20; i++) HAI->SetValue(i,0);
361 for(i=1; i<=SeqLabels.Length(); i++) {
362 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
363 NbAreaProp, NbShapesWithName, NbShapesWithColor,
364 NbShapesWithLayer, Doc, PrintStructMode, di);
366 Standard_Integer NbLabelsShape = 0;
367 di<<"\n"<<"Statistis of shapes in the document:"<<"\n";
368 for(i=0; i<=20; i++) {
369 if(HAI->Value(i)==0) break;
370 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
371 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
372 NbLabelsShape = NbLabelsShape + HAI->Value(i);
374 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
375 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
376 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
377 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
379 di<<"\n"<<"Statistis of Props in the document:"<<"\n";
380 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
381 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
382 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
384 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
385 TDF_LabelSequence CLabels;
386 CTool->GetColors(CLabels);
387 di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n";
388 if(CLabels.Length()>0) {
389 for(i=1; i<=CLabels.Length(); i++) {
390 TDF_Label aLabel = CLabels.Value(i);
392 CTool->GetColor(aLabel, col);
393 di<<col.StringName(col.Name())<<" ";
398 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
399 TDF_LabelSequence LLabels;
400 LTool->GetLayerLabels(LLabels);
401 di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n";
402 if(LLabels.Length()>0) {
403 for(i=1; i<=LLabels.Length(); i++) {
404 TDF_Label aLabel = LLabels.Value(i);
405 TCollection_ExtendedString layerName;
406 LTool->GetLayer(aLabel, layerName);
407 TCollection_AsciiString Entry(layerName,'?');
408 di<<"\""<<Entry.ToCString() <<"\" ";
418 //=======================================================================
421 //=======================================================================
422 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
425 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
429 Handle(TDocStd_Document) Doc;
430 DDocStd::GetDocument(argv[1], Doc);
431 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
433 // collect sequence of labels to set presentation
434 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
435 TDF_LabelSequence seq;
437 for ( Standard_Integer i=2; i < argc; i++ ) {
439 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
440 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
441 di << argv[i] << " is not a valid shape label!";
444 seq.Append ( aLabel );
448 shapes->GetShapes ( seq );
452 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
453 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
454 Handle(TPrsStd_AISPresentation) prs;
455 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
456 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
457 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
459 // Quantity_Color Col;
460 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
461 // prs->SetColor ( Col.Name() );
462 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
463 // prs->SetColor ( Col.Name() );
469 //=======================================================================
472 //=======================================================================
473 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
476 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
480 Handle(TDocStd_Document) Doc;
481 DDocStd::GetDocument(argv[1], Doc);
482 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
486 // sprintf ( string, "AISInitViewer %s", argv[1] );
487 // di.Eval ( string );
488 TDF_Label acces = Doc->GetData()->Root();
489 Handle(TPrsStd_AISViewer) viewer;
490 if (!TPrsStd_AISViewer::Find (acces,viewer)) {
491 TCollection_AsciiString title;
492 title.Prepend(argv[1]);
494 title.Prepend("Document");
495 Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString());
496 viewer = TPrsStd_AISViewer::New (acces,vw);
498 ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
500 //szv:CAX-TRJ7 c2-pe-214.stp was clipped
501 viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE);
502 //DDF::ReturnLabel(di,viewer->Label());
504 // collect sequence of labels to display
505 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
506 TDF_LabelSequence seq;
508 for ( Standard_Integer i=2; i < argc; i++ ) {
510 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
511 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
512 di << argv[i] << " is not a valid shape label!";
515 seq.Append ( aLabel );
519 shapes->GetFreeShapes ( seq );
522 // set presentations and show
523 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
524 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
525 Handle(TPrsStd_AISPresentation) prs;
526 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
527 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
528 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
530 // Quantity_Color Col;
531 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
532 // prs->SetColor ( Col.Name() );
533 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
534 // prs->SetColor ( Col.Name() );
535 prs->Display(Standard_True);
537 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
542 //=======================================================================
545 //=======================================================================
546 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
549 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n";
553 Handle(TDocStd_Document) Doc;
554 DDocStd::GetDocument(argv[1], Doc);
555 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
557 Handle(AIS_InteractiveContext) IC;
558 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
559 di << "Cannot find viewer for document " << argv[1] << "\n";
563 Handle(V3d_Viewer) viewer = IC->CurrentViewer();
564 viewer->InitActiveViews();
565 if ( viewer->MoreActiveViews() ) {
566 viewer->ActiveView()->Dump ( argv[2] );
569 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
577 //=======================================================================
578 //function : XAttributeValue
580 //=======================================================================
581 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
583 if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; }
584 Handle(DDF_Browser) browser =
585 Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
586 if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
589 TDF_Tool::Label(browser->Data(),argv[2],lab);
590 if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
592 Standard_Integer num = atoi ( argv[3] );
593 TDF_AttributeIterator itr(lab,Standard_False);
594 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
596 if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; }
598 const Handle(TDF_Attribute)& att = itr.Value();
599 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
600 Standard_CString type = "";
601 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
602 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
603 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
604 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
605 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
606 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
607 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
608 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
609 TCollection_AsciiString ref;
610 if ( TN->HasFather() ) {
611 TDF_Tool::Entry ( TN->Father()->Label(), ref );
612 di << type << " ==> " << ref.ToCString();
615 di << type << " <== (" << ref.ToCString();
616 Handle(TDataStd_TreeNode) child = TN->First();
617 while ( ! child.IsNull() ) {
618 TDF_Tool::Entry ( child->Label(), ref );
619 if ( child != TN->First() ) di << ", ";
620 di << ref.ToCString();
621 child = child->Next();
626 else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
627 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
628 TCollection_AsciiString ref;
629 TDF_Tool::Entry ( val->Get(), ref );
630 di << "==> " << ref.ToCString();
632 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
633 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
634 TCollection_AsciiString str ( val->Get() );
635 di << str.ToCString();
637 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
638 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
639 TCollection_AsciiString str ( val->Get() );
640 di << str.ToCString();
642 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
643 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
644 TCollection_AsciiString str ( val->Get(), '?' );
645 di << str.ToCString();
647 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
648 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
649 TCollection_AsciiString str ( val->Get(), '?' );
650 di << str.ToCString();
652 else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
653 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
654 TCollection_AsciiString str ( val->Get(), '?' );
655 di << str.ToCString();
657 else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
658 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
659 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
660 if ( j > val->Lower() ) di << ", ";
661 TCollection_AsciiString str ( val->Value(j) );
662 di << str.ToCString();
665 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
666 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
667 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
668 if ( j > val->Lower() ) di << ", ";
669 TCollection_AsciiString str ( val->Value(j) );
670 di << str.ToCString();
673 else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
674 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
675 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
676 if ( j > val->Lower() ) di << ", ";
677 TCollection_AsciiString str ( val->Value(j) );
678 di << str.ToCString();
681 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
682 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
683 TopoDS_Shape S = val->Get();
684 di << S.TShape()->DynamicType()->Name();
685 if ( ! S.Location().IsIdentity() ) di << "(located)";
687 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
688 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
689 TCollection_AsciiString str ( val->Get() );
690 di << str.ToCString();
692 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
693 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
694 TCollection_AsciiString str ( val->Get() );
695 di << str.ToCString();
697 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
698 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
699 gp_Pnt myCentroid = val->Get();
701 di << myCentroid.X();
703 di << myCentroid.Y();
705 di << myCentroid.Z();
708 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
709 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
710 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
712 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
713 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
714 Quantity_Color C = val->GetColor();
716 sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
717 C.Red(), C.Green(), C.Blue() );
720 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
721 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
722 Standard_Integer kind = val->GetKind();
723 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
724 if(kind<20) { //dimension
725 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
729 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
730 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
731 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
732 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
733 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
734 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
735 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
736 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
737 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
738 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
739 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
740 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
741 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
742 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
743 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
744 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
745 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
746 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
747 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
748 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
749 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
753 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
754 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
755 Standard_Real dens = val->GetDensity();
756 Standard_CString dimdens = "g/cu sm";
758 di<<val->GetName()->ToCString();
760 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
762 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
763 Standard_CString type;
764 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
765 type = "Layer Instance Link";
767 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
768 type = "SHUO Instance Link";
770 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
771 type = "DatumToler Link";
775 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
776 TCollection_AsciiString ref;
777 Standard_Integer ii = 1;
778 if (DETGN->NbFathers()!=0) {
780 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
781 di << type<< " ==> (" << ref.ToCString();
782 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
783 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
784 di << ", " << ref.ToCString();
789 if (DETGN->NbChildren()!=0) {
790 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
791 di << type<< " <== (" << ref.ToCString();
792 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
793 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
794 di << ", " << ref.ToCString();
803 //=======================================================================
804 //function : setviewName
806 //=======================================================================
807 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
810 di<<"Use: "<<argv[0]<<" (1/0)"<<"\n";
813 Standard_Boolean mode = Standard_False;
814 if (atoi(argv[1]) == 1) mode = Standard_True;
815 XCAFPrs::SetViewNameMode(mode);
820 //=======================================================================
821 //function : getviewName
823 //=======================================================================
825 static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
827 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n";
828 else di << "Display names OFF"<< "\n";
833 //=======================================================================
834 //function : XSetTransparency
836 //=======================================================================
837 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
840 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] "<<"\n";
844 Handle(TDocStd_Document) Doc;
845 DDocStd::GetDocument(argv[1], Doc);
846 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
848 const Standard_Real aTransparency = atof(argv[2]);
850 // collect sequence of labels
851 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
852 TDF_LabelSequence seq;
854 for ( Standard_Integer i=3; i < argc; i++ ) {
856 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
857 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
858 di << argv[i] << " is not a valid shape label!";
861 seq.Append ( aLabel );
865 shapes->GetFreeShapes ( seq );
868 // find presentations and set transparency
869 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
870 Handle(TPrsStd_AISPresentation) prs;
871 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
872 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
873 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
875 prs->SetTransparency( aTransparency );
877 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
881 //=======================================================================
882 //function : XShowFaceBoundary
883 //purpose : Set face boundaries on/off
884 //=======================================================================
885 static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
886 Standard_Integer argc,
889 if (( argc != 4 && argc < 7 ) || argc > 9)
891 di << "Usage :\n " << argv[0]
892 << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
893 << " Doc - is the document name. \n"
894 << " Label - is the shape label. \n"
895 << " IsOn - flag indicating whether the boundaries\n"
896 << " should be turned on or off (can be set\n"
897 << " to 0 (off) or 1 (on)).\n"
898 << " R, G, B - red, green and blue components of boundary\n"
899 << " color in range (0 - 255).\n"
900 << " (default is (0, 0, 0)\n"
901 << " LineWidth - line width\n"
902 << " (default is 1)\n"
903 << " LineStyle - line fill style :\n"
908 << " (default is solid)";
913 // get specified document
914 Handle(TDocStd_Document) aDoc;
915 DDocStd::GetDocument (argv[1], aDoc);
918 di << argv[1] << " is not a document" << "\n";
922 Handle(AIS_InteractiveContext) aContext;
923 if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext))
925 di << "Cannot find viewer for document " << argv[1] << "\n";
929 // get shape tool for shape verification
930 Handle(XCAFDoc_ShapeTool) aShapes =
931 XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
933 // get label and validate that it is a shape label
935 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
936 if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
938 di << argv[2] << " is not a valid shape label!";
942 // get presentation from label
943 Handle(TPrsStd_AISPresentation) aPrs;
944 if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
946 aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
949 Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
950 if (anInteractive.IsNull ())
952 di << "Can't set drawer attributes.\n"
953 "Interactive object for shape label doesn't exists.";
958 const Handle(AIS_Drawer)& aDrawer = anInteractive->Attributes ();
960 // default attributes
961 Quantity_Parameter aRed = 0.0;
962 Quantity_Parameter aGreen = 0.0;
963 Quantity_Parameter aBlue = 0.0;
964 Standard_Real aWidth = 1.0;
965 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
967 // turn boundaries on/off
968 Standard_Boolean isBoundaryDraw = (atoi (argv[3]) == 1);
969 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
971 // set boundary color
975 aRed = atof (argv[4])/255.;
976 aGreen = atof (argv[5])/255.;
977 aBlue = atof (argv[6])/255.;
983 aWidth = (Standard_Real)atof (argv[7]);
986 // select appropriate line type
989 switch (atoi (argv[8]))
991 case 1: aLineType = Aspect_TOL_DASH; break;
992 case 2: aLineType = Aspect_TOL_DOT; break;
993 case 3: aLineType = Aspect_TOL_DOTDASH; break;
995 aLineType = Aspect_TOL_SOLID;
999 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
1001 Handle(Prs3d_LineAspect) aBoundaryAspect =
1002 new Prs3d_LineAspect (aColor, aLineType, aWidth);
1004 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
1006 aContext->Redisplay (anInteractive);
1011 //=======================================================================
1014 //=======================================================================
1016 void XDEDRAW::Init(Draw_Interpretor& di)
1019 static Standard_Boolean initactor = Standard_False;
1020 if (initactor) return; initactor = Standard_True;
1022 // Load static variables for STEPCAF (ssv; 16.08.2012)
1023 STEPCAFControl_Controller::Init();
1025 // OCAF *** szy: use <pload> command
1027 // DDF::AllCommands(di);
1028 // DNaming::AllCommands(di);
1029 // DDataStd::AllCommands(di);
1030 // DPrsStd::AllCommands(di);
1031 //DFunction::AllCommands(di);
1032 // DDocStd::AllCommands(di);
1034 // ViewerTest::Commands (di); *** szy: use <pload> command
1036 // init XCAF application (if not yet done)
1037 XCAFApp_Application::GetApplication();
1039 //=====================================
1041 //=====================================
1043 Standard_CString g = "XDE general commands";
1045 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
1046 __FILE__, newDoc, g);
1048 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
1049 __FILE__, saveDoc, g);
1051 di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path",
1052 __FILE__, openDoc, g);
1054 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
1057 di.Add ("XStat","Doc \t: Print statistics of document",
1058 __FILE__, statdoc, g);
1060 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
1061 __FILE__, setPrs, g);
1063 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
1066 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
1069 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
1070 __FILE__, XAttributeValue, g);
1072 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
1073 __FILE__, setviewName, g);
1075 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
1076 __FILE__, getviewName, g);
1078 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
1079 __FILE__, XSetTransparency, g);
1081 di.Add ("XShowFaceBoundary",
1082 "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
1083 "- turns on/off drawing of face boundaries and defines boundary line style",
1084 __FILE__, XShowFaceBoundary, g);
1086 // Specialized commands
1087 XDEDRAW_Shapes::InitCommands ( di );
1088 XDEDRAW_Colors::InitCommands ( di );
1089 XDEDRAW_Layers::InitCommands ( di );
1090 XDEDRAW_Props::InitCommands ( di );
1091 XDEDRAW_Common::InitCommands ( di );//moved from EXE
1096 //==============================================================================
1098 //==============================================================================
1099 void XDEDRAW::Factory(Draw_Interpretor& theDI)
1101 XSDRAWIGES::InitSelect();
1102 XSDRAWIGES::InitToBRep(theDI);
1103 XSDRAWIGES::InitFromBRep(theDI);
1105 XSDRAWSTEP::InitCommands(theDI);
1107 SWDRAW::Init(theDI);
1108 XSDRAW::LoadDraw(theDI);
1110 XDEDRAW::Init(theDI);
1113 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n";
1117 // Declare entry point PLUGINFACTORY