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 <TDF_Tool.hxx>
44 #include <TDF_Data.hxx>
45 #include <TDF_LabelSequence.hxx>
46 #include <TDF_AttributeIterator.hxx>
47 #include <TDF_Reference.hxx>
48 #include <TDocStd_Document.hxx>
49 #include <TDataStd_UAttribute.hxx>
50 #include <TDataStd_TreeNode.hxx>
51 #include <TDataStd_Integer.hxx>
52 #include <TDataStd_Real.hxx>
53 #include <TDataStd_Name.hxx>
54 #include <TDataStd_Comment.hxx>
55 #include <TDataStd_AsciiString.hxx>
56 #include <TNaming_NamedShape.hxx>
57 #include <TDataStd_IntegerArray.hxx>
58 #include <TDataStd_RealArray.hxx>
59 #include <TDataStd_ByteArray.hxx>
60 #include <TPrsStd_AISPresentation.hxx>
61 #include <TPrsStd_NamedShapeDriver.hxx>
62 #include <TPrsStd_AISViewer.hxx>
64 #include <XCAFDoc.hxx>
65 #include <XCAFDoc_Color.hxx>
66 #include <XCAFDoc_Volume.hxx>
67 #include <XCAFDoc_Area.hxx>
68 #include <XCAFDoc_Centroid.hxx>
69 #include <XCAFDoc_ShapeTool.hxx>
70 #include <XCAFDoc_ColorTool.hxx>
71 #include <XCAFDoc_DocumentTool.hxx>
72 #include <XCAFDoc_GraphNode.hxx>
73 #include <XCAFDoc_LayerTool.hxx>
74 #include <XCAFDoc_DimTol.hxx>
75 #include <XCAFDoc_Material.hxx>
76 #include <XCAFPrs_Driver.hxx>
77 #include <XCAFApp_Application.hxx>
79 #include <XDEDRAW_Shapes.hxx>
80 #include <XDEDRAW_Colors.hxx>
81 #include <XDEDRAW_Layers.hxx>
82 #include <XDEDRAW_Props.hxx>
83 #include <XDEDRAW_Common.hxx>
84 #include <XSDRAWIGES.hxx>
85 #include <XSDRAWSTEP.hxx>
88 #include <XCAFPrs.hxx>
89 #include <ViewerTest.hxx>
90 #include <Draw_PluginMacro.hxx>
92 #include <TColStd_HArray1OfInteger.hxx>
93 #include <TColStd_HArray1OfReal.hxx>
95 #define ZVIEW_SIZE 1000000.0
96 // avoid warnings on 'extern "C"' functions returning C++ classes
98 #pragma warning(4:4190)
101 //=======================================================================
102 // Section: General commands
103 //=======================================================================
105 //=======================================================================
108 //=======================================================================
109 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
111 if (argc < 2) {di<<"Give document name"<<"\n";return 1;}
113 Handle(TDocStd_Document) D;
114 Handle(DDocStd_DrawDocument) DD;
115 Handle(TDocStd_Application) A;
117 if (!DDocStd::Find(A)) return 1;
119 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
120 A->NewDocument( "MDTV-XCAF" ,D);
121 DD = new DDocStd_DrawDocument(D);
122 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
123 Draw::Set(argv[1],DD);
124 di << "document " << argv[1] << " created" << "\n";
125 //DDocStd::ReturnLabel(di,D->Main());
127 else di << argv[1] << " is already a document" << "\n";
133 //=======================================================================
136 //=======================================================================
137 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
139 Handle(TDocStd_Document) D;
140 Handle(TDocStd_Application) A;
141 if (!DDocStd::Find(A)) return 1;
144 if (A->NbDocuments() < 1) return 1;
145 A->GetDocument(1, D);
148 if (!DDocStd::GetDocument(argv[1],D)) return 1;
152 TCollection_ExtendedString path (argv[2]);
157 di << "this document has never been saved" << "\n";
165 //=======================================================================
168 //=======================================================================
169 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
172 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n";
175 Handle(TDocStd_Document) Doc;
176 DDocStd::GetDocument(argv[1], Doc);
177 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
179 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
180 Standard_Boolean deep = Standard_False;
181 if ( (argc==3) && (atoi(argv[2])==1) ) deep = Standard_True;
182 myAssembly->Dump(deep);
187 //=======================================================================
188 //function : StatAssembly
189 //purpose : recursive part of statistics
190 //=======================================================================
192 static void StatAssembly(const TDF_Label L,
193 const Standard_Integer level,
194 Handle(TColStd_HArray1OfInteger) &HAI,
195 Standard_Integer &NbCentroidProp,
196 Standard_Integer &NbVolumeProp,
197 Standard_Integer &NbAreaProp,
198 Standard_Integer &NbShapesWithName,
199 Standard_Integer &NbShapesWithColor,
200 Standard_Integer &NbShapesWithLayer,
201 Handle(TDocStd_Document) &aDoc,
202 Standard_Boolean &PrintStructMode,
203 Draw_Interpretor& di)
205 if(PrintStructMode) {
206 for(Standard_Integer j=0; j<=level; j++)
209 TCollection_AsciiString Entry;
210 TDF_Tool::Entry(L, Entry);
211 if(PrintStructMode) di<<Entry.ToCString();
213 Handle(TDataStd_Name) Name;
214 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
216 if(PrintStructMode) {
217 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
218 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
222 if(PrintStructMode) di<<" NoName has attributes: ";
225 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
226 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
227 if(PrintStructMode) di<<"Centroid ";
231 if(XCAFDoc_Volume::Get(L,tmp)) {
232 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
235 if(XCAFDoc_Area::Get(L,tmp)) {
236 if(PrintStructMode) di<<"Area("<<tmp<<") ";
239 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
241 Standard_Boolean IsColor = Standard_False;
242 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
243 IsColor = Standard_True;
244 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
245 IsColor = Standard_True;
246 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
247 IsColor = Standard_True;
249 TCollection_AsciiString Entry1;
250 Entry1 = col.StringName(col.Name());
251 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
254 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
255 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
256 LTool->GetLayers(L, aLayerS);
257 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
258 if(PrintStructMode) {
260 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
261 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
263 di<<"\""<<Entry2.ToCString()<<"\"";
265 di<<" "<<"\""<<Entry2.ToCString()<<"\"";
271 if(PrintStructMode) di<<"\n";
273 HAI->SetValue(level, HAI->Value(level)+1 );
275 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
276 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
277 NbAreaProp, NbShapesWithName, NbShapesWithColor,
278 NbShapesWithLayer, aDoc, PrintStructMode, di);
285 //=======================================================================
288 //=======================================================================
289 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
292 di<<"Use: "<<argv[0]<<" Doc "<<"\n";
295 Handle(TDocStd_Document) Doc;
296 DDocStd::GetDocument(argv[1], Doc);
297 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
299 Standard_Boolean PrintStructMode = (argc==3);
300 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
302 TDF_LabelSequence SeqLabels;
303 aTool->GetShapes(SeqLabels);
304 if(SeqLabels.Length()<=0) return 0;
305 if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n";
306 Standard_Integer level=0;
307 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
308 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
309 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
310 Standard_Integer i=0;
311 for(i=0; i<=20; i++) HAI->SetValue(i,0);
312 for(i=1; i<=SeqLabels.Length(); i++) {
313 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
314 NbAreaProp, NbShapesWithName, NbShapesWithColor,
315 NbShapesWithLayer, Doc, PrintStructMode, di);
317 Standard_Integer NbLabelsShape = 0;
318 di<<"\n"<<"Statistis of shapes in the document:"<<"\n";
319 for(i=0; i<=20; i++) {
320 if(HAI->Value(i)==0) break;
321 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
322 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
323 NbLabelsShape = NbLabelsShape + HAI->Value(i);
325 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
326 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
327 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
328 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
330 di<<"\n"<<"Statistis of Props in the document:"<<"\n";
331 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
332 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
333 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
335 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
336 TDF_LabelSequence CLabels;
337 CTool->GetColors(CLabels);
338 di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n";
339 if(CLabels.Length()>0) {
340 for(i=1; i<=CLabels.Length(); i++) {
341 TDF_Label aLabel = CLabels.Value(i);
343 CTool->GetColor(aLabel, col);
344 di<<col.StringName(col.Name())<<" ";
349 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
350 TDF_LabelSequence LLabels;
351 LTool->GetLayerLabels(LLabels);
352 di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n";
353 if(LLabels.Length()>0) {
354 for(i=1; i<=LLabels.Length(); i++) {
355 TDF_Label aLabel = LLabels.Value(i);
356 TCollection_ExtendedString layerName;
357 LTool->GetLayer(aLabel, layerName);
358 TCollection_AsciiString Entry(layerName,'?');
359 di<<"\""<<Entry.ToCString() <<"\" ";
369 //=======================================================================
372 //=======================================================================
373 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
376 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
380 Handle(TDocStd_Document) Doc;
381 DDocStd::GetDocument(argv[1], Doc);
382 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
384 // collect sequence of labels to set presentation
385 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
386 TDF_LabelSequence seq;
388 for ( Standard_Integer i=2; i < argc; i++ ) {
390 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
391 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
392 di << argv[i] << " is not a valid shape label!";
395 seq.Append ( aLabel );
399 shapes->GetShapes ( seq );
403 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
404 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
405 Handle(TPrsStd_AISPresentation) prs;
406 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
407 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
408 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
410 // Quantity_Color Col;
411 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
412 // prs->SetColor ( Col.Name() );
413 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
414 // prs->SetColor ( Col.Name() );
420 //=======================================================================
423 //=======================================================================
424 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
427 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
431 Handle(TDocStd_Document) Doc;
432 DDocStd::GetDocument(argv[1], Doc);
433 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
437 // sprintf ( string, "AISInitViewer %s", argv[1] );
438 // di.Eval ( string );
439 TDF_Label acces = Doc->GetData()->Root();
440 Handle(TPrsStd_AISViewer) viewer;
441 if (!TPrsStd_AISViewer::Find (acces,viewer)) {
442 TCollection_AsciiString title;
443 title.Prepend(argv[1]);
445 title.Prepend("Document");
446 Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString());
447 viewer = TPrsStd_AISViewer::New (acces,vw);
449 ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
451 //szv:CAX-TRJ7 c2-pe-214.stp was clipped
452 viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE);
453 //DDF::ReturnLabel(di,viewer->Label());
455 // collect sequence of labels to display
456 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
457 TDF_LabelSequence seq;
459 for ( Standard_Integer i=2; i < argc; i++ ) {
461 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
462 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
463 di << argv[i] << " is not a valid shape label!";
466 seq.Append ( aLabel );
470 shapes->GetFreeShapes ( seq );
473 // set presentations and show
474 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
475 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
476 Handle(TPrsStd_AISPresentation) prs;
477 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
478 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
479 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
481 // Quantity_Color Col;
482 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
483 // prs->SetColor ( Col.Name() );
484 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
485 // prs->SetColor ( Col.Name() );
486 prs->Display(Standard_True);
488 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
493 //=======================================================================
496 //=======================================================================
497 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
500 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n";
504 Handle(TDocStd_Document) Doc;
505 DDocStd::GetDocument(argv[1], Doc);
506 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
508 Handle(AIS_InteractiveContext) IC;
509 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
510 di << "Cannot find viewer for document " << argv[1] << "\n";
514 Handle(V3d_Viewer) viewer = IC->CurrentViewer();
515 viewer->InitActiveViews();
516 if ( viewer->MoreActiveViews() ) {
517 viewer->ActiveView()->Dump ( argv[2] );
520 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
528 //=======================================================================
529 //function : XAttributeValue
531 //=======================================================================
532 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
534 if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; }
535 Handle(DDF_Browser) browser =
536 Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
537 if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
540 TDF_Tool::Label(browser->Data(),argv[2],lab);
541 if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
543 Standard_Integer num = atoi ( argv[3] );
544 TDF_AttributeIterator itr(lab,Standard_False);
545 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
547 if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; }
549 const Handle(TDF_Attribute)& att = itr.Value();
550 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
551 Standard_CString type = "";
552 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
553 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
554 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
555 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
556 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
557 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
558 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
559 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
560 TCollection_AsciiString ref;
561 if ( TN->HasFather() ) {
562 TDF_Tool::Entry ( TN->Father()->Label(), ref );
563 di << type << " ==> " << ref.ToCString();
566 di << type << " <== (" << ref.ToCString();
567 Handle(TDataStd_TreeNode) child = TN->First();
568 while ( ! child.IsNull() ) {
569 TDF_Tool::Entry ( child->Label(), ref );
570 if ( child != TN->First() ) di << ", ";
571 di << ref.ToCString();
572 child = child->Next();
577 else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
578 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
579 TCollection_AsciiString ref;
580 TDF_Tool::Entry ( val->Get(), ref );
581 di << "==> " << ref.ToCString();
583 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
584 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
585 TCollection_AsciiString str ( val->Get() );
586 di << str.ToCString();
588 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
589 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
590 TCollection_AsciiString str ( val->Get() );
591 di << str.ToCString();
593 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
594 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
595 TCollection_AsciiString str ( val->Get(), '?' );
596 di << str.ToCString();
598 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
599 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
600 TCollection_AsciiString str ( val->Get(), '?' );
601 di << str.ToCString();
603 else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
604 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
605 TCollection_AsciiString str ( val->Get(), '?' );
606 di << str.ToCString();
608 else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
609 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
610 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
611 if ( j > val->Lower() ) di << ", ";
612 TCollection_AsciiString str ( val->Value(j) );
613 di << str.ToCString();
616 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
617 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
618 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
619 if ( j > val->Lower() ) di << ", ";
620 TCollection_AsciiString str ( val->Value(j) );
621 di << str.ToCString();
624 else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
625 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
626 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
627 if ( j > val->Lower() ) di << ", ";
628 TCollection_AsciiString str ( val->Value(j) );
629 di << str.ToCString();
632 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
633 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
634 TopoDS_Shape S = val->Get();
635 di << S.TShape()->DynamicType()->Name();
636 if ( ! S.Location().IsIdentity() ) di << "(located)";
638 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
639 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
640 TCollection_AsciiString str ( val->Get() );
641 di << str.ToCString();
643 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
644 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
645 TCollection_AsciiString str ( val->Get() );
646 di << str.ToCString();
648 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
649 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
650 gp_Pnt myCentroid = val->Get();
652 di << myCentroid.X();
654 di << myCentroid.Y();
656 di << myCentroid.Z();
659 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
660 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
661 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
663 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
664 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
665 Quantity_Color C = val->GetColor();
667 sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
668 C.Red(), C.Green(), C.Blue() );
671 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
672 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
673 Standard_Integer kind = val->GetKind();
674 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
675 if(kind<20) { //dimension
676 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
680 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
681 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
682 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
683 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
684 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
685 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
686 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
687 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
688 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
689 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
690 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
691 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
692 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
693 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
694 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
695 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
696 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
697 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
698 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
699 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
700 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
704 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
705 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
706 Standard_Real dens = val->GetDensity();
707 Standard_CString dimdens = "g/cu sm";
709 di<<val->GetName()->ToCString();
711 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
713 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
714 Standard_CString type;
715 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
716 type = "Layer Instance Link";
718 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
719 type = "SHUO Instance Link";
721 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
722 type = "DatumToler Link";
726 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
727 TCollection_AsciiString ref;
728 Standard_Integer ii = 1;
729 if (DETGN->NbFathers()!=0) {
731 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
732 di << type<< " ==> (" << ref.ToCString();
733 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
734 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
735 di << ", " << ref.ToCString();
740 if (DETGN->NbChildren()!=0) {
741 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
742 di << type<< " <== (" << ref.ToCString();
743 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
744 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
745 di << ", " << ref.ToCString();
754 //=======================================================================
755 //function : setviewName
757 //=======================================================================
758 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
761 di<<"Use: "<<argv[0]<<" (1/0)"<<"\n";
764 Standard_Boolean mode = Standard_False;
765 if (atoi(argv[1]) == 1) mode = Standard_True;
766 XCAFPrs::SetViewNameMode(mode);
771 //=======================================================================
772 //function : getviewName
774 //=======================================================================
776 static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
778 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n";
779 else di << "Display names OFF"<< "\n";
784 //=======================================================================
785 //function : XSetTransparency
787 //=======================================================================
788 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
791 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] "<<"\n";
795 Handle(TDocStd_Document) Doc;
796 DDocStd::GetDocument(argv[1], Doc);
797 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
799 const Standard_Real aTransparency = atof(argv[2]);
801 // collect sequence of labels
802 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
803 TDF_LabelSequence seq;
805 for ( Standard_Integer i=3; i < argc; i++ ) {
807 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
808 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
809 di << argv[i] << " is not a valid shape label!";
812 seq.Append ( aLabel );
816 shapes->GetFreeShapes ( seq );
819 // find presentations and set transparency
820 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
821 Handle(TPrsStd_AISPresentation) prs;
822 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
823 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
824 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
826 prs->SetTransparency( aTransparency );
828 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
833 //=======================================================================
836 //=======================================================================
838 void XDEDRAW::Init(Draw_Interpretor& di)
841 static Standard_Boolean initactor = Standard_False;
842 if (initactor) return; initactor = Standard_True;
844 // OCAF *** szy: use <pload> command
846 // DDF::AllCommands(di);
847 // DNaming::AllCommands(di);
848 // DDataStd::AllCommands(di);
849 // DPrsStd::AllCommands(di);
850 //DFunction::AllCommands(di);
851 // DDocStd::AllCommands(di);
853 // ViewerTest::Commands (di); *** szy: use <pload> command
855 // init XCAF application (if not yet done)
856 XCAFApp_Application::GetApplication();
858 //=====================================
860 //=====================================
862 Standard_CString g = "XDE general commands";
864 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
865 __FILE__, newDoc, g);
867 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
868 __FILE__, saveDoc, g);
870 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
873 di.Add ("XStat","Doc \t: Print statistics of document",
874 __FILE__, statdoc, g);
876 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
877 __FILE__, setPrs, g);
879 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
882 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
885 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
886 __FILE__, XAttributeValue, g);
888 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
889 __FILE__, setviewName, g);
891 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
892 __FILE__, getviewName, g);
894 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
895 __FILE__, XSetTransparency, g);
897 // Specialized commands
898 XDEDRAW_Shapes::InitCommands ( di );
899 XDEDRAW_Colors::InitCommands ( di );
900 XDEDRAW_Layers::InitCommands ( di );
901 XDEDRAW_Props::InitCommands ( di );
902 XDEDRAW_Common::InitCommands ( di );//moved from EXE
907 //==============================================================================
909 //==============================================================================
910 void XDEDRAW::Factory(Draw_Interpretor& theDI)
912 XSDRAWIGES::InitSelect();
913 XSDRAWIGES::InitToBRep(theDI);
914 XSDRAWIGES::InitFromBRep(theDI);
916 XSDRAWSTEP::InitCommands(theDI);
919 XSDRAW::LoadDraw(theDI);
921 XDEDRAW::Init(theDI);
924 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n";
928 // Declare entry point PLUGINFACTORY