1 // Created on: 2000-08-04
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <AIS_InteractiveContext.hxx>
18 #include <AIS_InteractiveObject.hxx>
19 #include <AIS_Trihedron.hxx>
20 #include <Aspect_TypeOfLine.hxx>
22 #include <DDF_Browser.hxx>
23 #include <DDocStd.hxx>
24 #include <DDocStd_DrawDocument.hxx>
26 #include <Draw_PluginMacro.hxx>
27 #include <Geom_Axis2Placement.hxx>
28 #include <Prs3d_Drawer.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Quantity_Color.hxx>
31 #include <STEPCAFControl_Controller.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <TCollection_ExtendedString.hxx>
34 #include <TCollection_HAsciiString.hxx>
35 #include <TColStd_HArray1OfInteger.hxx>
36 #include <TColStd_HArray1OfReal.hxx>
37 #include <TColStd_HSequenceOfExtendedString.hxx>
38 #include <TDataStd_AsciiString.hxx>
39 #include <TDataStd_ByteArray.hxx>
40 #include <TDataStd_Comment.hxx>
41 #include <TDataStd_Integer.hxx>
42 #include <TDataStd_IntegerArray.hxx>
43 #include <TDataStd_Name.hxx>
44 #include <TDataStd_Real.hxx>
45 #include <TDataStd_RealArray.hxx>
46 #include <TDataStd_TreeNode.hxx>
47 #include <TDataStd_UAttribute.hxx>
48 #include <TDF_AttributeIterator.hxx>
49 #include <TDF_Data.hxx>
50 #include <TDF_LabelSequence.hxx>
51 #include <TDF_Reference.hxx>
52 #include <TDF_Tool.hxx>
53 #include <TDocStd_Application.hxx>
54 #include <TDocStd_Document.hxx>
55 #include <TDocStd_Owner.hxx>
56 #include <TNaming_NamedShape.hxx>
57 #include <TopoDS_Shape.hxx>
58 #include <TPrsStd_AISPresentation.hxx>
59 #include <TPrsStd_AISViewer.hxx>
60 #include <TPrsStd_DriverTable.hxx>
61 #include <TPrsStd_NamedShapeDriver.hxx>
62 #include <V3d_View.hxx>
63 #include <V3d_Viewer.hxx>
64 #include <ViewerTest.hxx>
65 #include <XCAFDoc.hxx>
66 #include <XCAFDoc_Area.hxx>
67 #include <XCAFDoc_Centroid.hxx>
68 #include <XCAFDoc_Color.hxx>
69 #include <XCAFDoc_ColorTool.hxx>
70 #include <XCAFDoc_DimTol.hxx>
71 #include <XCAFDoc_Dimension.hxx>
72 #include <XCAFDoc_Datum.hxx>
73 #include <XCAFDoc_GeomTolerance.hxx>
74 #include <XCAFDoc_DocumentTool.hxx>
75 #include <XCAFDoc_GraphNode.hxx>
76 #include <XCAFDoc_LayerTool.hxx>
77 #include <XCAFDoc_Material.hxx>
78 #include <XCAFDoc_ShapeTool.hxx>
79 #include <XCAFDoc_Volume.hxx>
80 #include <XCAFPrs.hxx>
81 #include <XCAFPrs_Driver.hxx>
82 #include <XDEDRAW.hxx>
83 #include <XDEDRAW_Colors.hxx>
84 #include <XDEDRAW_Common.hxx>
85 #include <XDEDRAW_Layers.hxx>
86 #include <XDEDRAW_Props.hxx>
87 #include <XDEDRAW_Shapes.hxx>
88 #include <XDEDRAW_GDTs.hxx>
90 #include <XSDRAWIGES.hxx>
91 #include <XSDRAWSTEP.hxx>
93 #include <BinXCAFDrivers.hxx>
94 #include <XmlXCAFDrivers.hxx>
98 //=======================================================================
99 // Section: General commands
100 //=======================================================================
102 //=======================================================================
105 //=======================================================================
106 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
108 if (argc < 2) {di<<"Give document name\n";return 1;}
110 Handle(TDocStd_Document) D;
111 Handle(DDocStd_DrawDocument) DD;
112 Handle(TDocStd_Application) A = DDocStd::GetApplication();
114 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
115 A->NewDocument( "BinXCAF" ,D);
116 DD = new DDocStd_DrawDocument(D);
117 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
118 Draw::Set(argv[1],DD);
119 di << "document " << argv[1] << " created\n";
120 //DDocStd::ReturnLabel(di,D->Main());
122 else di << argv[1] << " is already a document\n";
128 //=======================================================================
131 //=======================================================================
132 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
134 Handle(TDocStd_Document) D;
135 Handle(TDocStd_Application) A = DDocStd::GetApplication();
138 if (A->NbDocuments() < 1) return 1;
139 A->GetDocument(1, D);
142 if (!DDocStd::GetDocument(argv[1],D)) return 1;
146 TCollection_ExtendedString path (argv[2]);
151 di << "this document has never been saved\n";
158 //=======================================================================
161 //=======================================================================
162 static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
164 Handle(TDocStd_Document) D;
165 Handle(DDocStd_DrawDocument) DD;
166 Handle(TDocStd_Application) A = DDocStd::GetApplication();
170 di << "invalid number of arguments. Usage:\t XOpen filename docname\n";
174 Standard_CString Filename = argv[1];
175 Standard_CString DocName = argv[2];
177 if ( DDocStd::GetDocument(DocName, D, Standard_False) )
179 di << "document with name " << DocName << " already exists\n";
183 if ( A->Open(Filename, D) != PCDM_RS_OK )
185 di << "cannot open XDE document\n";
189 DD = new DDocStd_DrawDocument(D);
190 TDataStd_Name::Set(D->GetData()->Root(), DocName);
191 Draw::Set(DocName, DD);
193 di << "document " << DocName << " opened\n";
198 //=======================================================================
201 //=======================================================================
202 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
205 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]\n";
208 Handle(TDocStd_Document) Doc;
209 DDocStd::GetDocument(argv[1], Doc);
210 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
212 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
213 Standard_Boolean deep = Standard_False;
214 if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True;
215 Standard_SStream aDumpLog;
216 myAssembly->Dump(aDumpLog, deep);
222 //=======================================================================
223 //function : StatAssembly
224 //purpose : recursive part of statistics
225 //=======================================================================
227 static void StatAssembly(const TDF_Label L,
228 const Standard_Integer level,
229 Handle(TColStd_HArray1OfInteger) &HAI,
230 Standard_Integer &NbCentroidProp,
231 Standard_Integer &NbVolumeProp,
232 Standard_Integer &NbAreaProp,
233 Standard_Integer &NbShapesWithName,
234 Standard_Integer &NbShapesWithColor,
235 Standard_Integer &NbShapesWithLayer,
236 Handle(TDocStd_Document) &aDoc,
237 Standard_Boolean &PrintStructMode,
238 Draw_Interpretor& di)
240 if(PrintStructMode) {
241 for(Standard_Integer j=0; j<=level; j++)
244 TCollection_AsciiString Entry;
245 TDF_Tool::Entry(L, Entry);
246 if(PrintStructMode) di<<Entry.ToCString();
248 Handle(TDataStd_Name) Name;
249 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
251 if(PrintStructMode) {
252 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
253 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
257 if(PrintStructMode) di<<" NoName has attributes: ";
260 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
261 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
262 if(PrintStructMode) di<<"Centroid ";
266 if(XCAFDoc_Volume::Get(L,tmp)) {
267 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
270 if(XCAFDoc_Area::Get(L,tmp)) {
271 if(PrintStructMode) di<<"Area("<<tmp<<") ";
274 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
276 Standard_Boolean IsColor = Standard_False;
277 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
278 IsColor = Standard_True;
279 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
280 IsColor = Standard_True;
281 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
282 IsColor = Standard_True;
284 TCollection_AsciiString Entry1;
285 Entry1 = col.StringName(col.Name());
286 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
289 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
290 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
291 LTool->GetLayers(L, aLayerS);
292 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
293 if(PrintStructMode) {
295 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
296 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
298 di<<"\""<<Entry2.ToCString()<<"\"";
300 di<<" \""<<Entry2.ToCString()<<"\"";
306 if(PrintStructMode) di<<"\n";
308 HAI->SetValue(level, HAI->Value(level)+1 );
310 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
311 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
312 NbAreaProp, NbShapesWithName, NbShapesWithColor,
313 NbShapesWithLayer, aDoc, PrintStructMode, di);
320 //=======================================================================
323 //=======================================================================
324 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
327 di<<"Use: "<<argv[0]<<" Doc \n";
330 Handle(TDocStd_Document) Doc;
331 DDocStd::GetDocument(argv[1], Doc);
332 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
334 Standard_Boolean PrintStructMode = (argc==3);
335 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
337 TDF_LabelSequence SeqLabels;
338 aTool->GetShapes(SeqLabels);
339 if(SeqLabels.Length()<=0) return 0;
340 if(PrintStructMode) di<<"\nStructure of shapes in the document:\n";
341 Standard_Integer level=0;
342 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
343 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
344 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
345 Standard_Integer i=0;
346 for(i=0; i<=20; i++) HAI->SetValue(i,0);
347 for(i=1; i<=SeqLabels.Length(); i++) {
348 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
349 NbAreaProp, NbShapesWithName, NbShapesWithColor,
350 NbShapesWithLayer, Doc, PrintStructMode, di);
352 Standard_Integer NbLabelsShape = 0;
353 di<<"\nStatistis of shapes in the document:\n";
354 for(i=0; i<=20; i++) {
355 if(HAI->Value(i)==0) break;
356 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
357 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
358 NbLabelsShape = NbLabelsShape + HAI->Value(i);
360 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
361 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
362 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
363 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
365 di<<"\nStatistis of Props in the document:\n";
366 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
367 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
368 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
370 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
371 TDF_LabelSequence CLabels;
372 CTool->GetColors(CLabels);
373 di<<"\nNumber of colors = "<<CLabels.Length()<<"\n";
374 if(CLabels.Length()>0) {
375 for(i=1; i<=CLabels.Length(); i++) {
376 TDF_Label aLabel = CLabels.Value(i);
378 CTool->GetColor(aLabel, col);
379 di<<col.StringName(col.Name())<<" ";
384 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
385 TDF_LabelSequence LLabels;
386 LTool->GetLayerLabels(LLabels);
387 di<<"\nNumber of layers = "<<LLabels.Length()<<"\n";
388 if(LLabels.Length()>0) {
389 for(i=1; i<=LLabels.Length(); i++) {
390 TDF_Label aLabel = LLabels.Value(i);
391 TCollection_ExtendedString layerName;
392 LTool->GetLayer(aLabel, layerName);
393 TCollection_AsciiString Entry(layerName,'?');
394 di<<"\""<<Entry.ToCString() <<"\" ";
404 //=======================================================================
407 //=======================================================================
408 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
411 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
415 Handle(TDocStd_Document) Doc;
416 DDocStd::GetDocument(argv[1], Doc);
417 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
419 // collect sequence of labels to set presentation
420 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
421 TDF_LabelSequence seq;
423 for ( Standard_Integer i=2; i < argc; i++ ) {
425 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
426 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
427 di << argv[i] << " is not a valid shape label!";
430 seq.Append ( aLabel );
434 shapes->GetShapes ( seq );
438 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
439 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
440 Handle(TPrsStd_AISPresentation) prs;
441 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
442 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
443 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
445 // Quantity_Color Col;
446 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
447 // prs->SetColor ( Col.Name() );
448 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
449 // prs->SetColor ( Col.Name() );
455 //=======================================================================
458 //=======================================================================
459 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
462 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
466 Handle(TDocStd_Document) aDoc;
467 DDocStd::GetDocument (argv[1], aDoc);
470 std::cout << argv[1] << " is not a document\n";
475 TDF_Label aRoot = aDoc->GetData()->Root();
476 Handle(TPrsStd_AISViewer) aDocViewer;
477 TCollection_AsciiString aViewName = TCollection_AsciiString ("Driver1/Document_") + argv[1] + "/View1";
478 if (!TPrsStd_AISViewer::Find (aRoot, aDocViewer))
480 ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), "");
481 aDocViewer = TPrsStd_AISViewer::New (aRoot, ViewerTest::GetAISContext());
484 // collect sequence of labels to display
485 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
486 TDF_LabelSequence seq;
488 for ( Standard_Integer i=2; i < argc; i++ ) {
490 TDF_Tool::Label (aDoc->GetData(), argv[i], aLabel);
491 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
492 di << argv[i] << " is not a valid shape label!";
495 seq.Append ( aLabel );
499 shapes->GetFreeShapes ( seq );
502 // set presentations and show
503 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
504 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
505 Handle(TPrsStd_AISPresentation) prs;
506 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
507 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
508 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
510 // Quantity_Color Col;
511 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
512 // prs->SetColor ( Col.Name() );
513 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
514 // prs->SetColor ( Col.Name() );
515 prs->Display(Standard_True);
517 TPrsStd_AISViewer::Update (aDoc->GetData()->Root());
522 //=======================================================================
525 //=======================================================================
526 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
529 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}\n";
533 Handle(TDocStd_Document) Doc;
534 DDocStd::GetDocument(argv[1], Doc);
535 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
537 Handle(AIS_InteractiveContext) IC;
538 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
539 di << "Cannot find viewer for document " << argv[1] << "\n";
543 Handle(V3d_Viewer) aViewer = IC->CurrentViewer();
544 V3d_ListOfViewIterator aViewIter = aViewer->ActiveViewIterator();
545 if (aViewIter.More())
547 aViewIter.Value()->Dump ( argv[2] );
550 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
558 //=======================================================================
559 //function : XAttributeValue
561 //=======================================================================
562 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
564 if ( argc <4 ) { di << "ERROR: Too few args\n"; return 0; }
565 Handle(DDF_Browser) browser =
566 Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
567 if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
570 TDF_Tool::Label(browser->Data(),argv[2],lab);
571 if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
573 Standard_Integer num = Draw::Atoi ( argv[3] );
574 TDF_AttributeIterator itr(lab,Standard_False);
575 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
577 if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found\n"; return 0; }
579 const Handle(TDF_Attribute)& att = itr.Value();
580 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
581 Standard_CString type = "";
582 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
583 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
584 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
585 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
586 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
587 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
588 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
589 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
590 TCollection_AsciiString ref;
591 if ( TN->HasFather() ) {
592 TDF_Tool::Entry ( TN->Father()->Label(), ref );
593 di << type << " ==> " << ref.ToCString();
596 di << type << " <== (" << ref.ToCString();
597 Handle(TDataStd_TreeNode) child = TN->First();
598 while ( ! child.IsNull() ) {
599 TDF_Tool::Entry ( child->Label(), ref );
600 if ( child != TN->First() ) di << ", ";
601 di << ref.ToCString();
602 child = child->Next();
607 else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
608 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
609 TCollection_AsciiString ref;
610 TDF_Tool::Entry ( val->Get(), ref );
611 di << "==> " << ref.ToCString();
613 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
614 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
615 TCollection_AsciiString str ( val->Get() );
616 di << str.ToCString();
618 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
619 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
620 TCollection_AsciiString str ( val->Get() );
621 di << str.ToCString();
623 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
624 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
625 TCollection_AsciiString str ( val->Get(), '?' );
626 di << str.ToCString();
628 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
629 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
630 TCollection_AsciiString str ( val->Get(), '?' );
631 di << str.ToCString();
633 else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
634 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
635 TCollection_AsciiString str ( val->Get(), '?' );
636 di << str.ToCString();
638 else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
639 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
640 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
641 if ( j > val->Lower() ) di << ", ";
642 TCollection_AsciiString str ( val->Value(j) );
643 di << str.ToCString();
646 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
647 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
648 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
649 if ( j > val->Lower() ) di << ", ";
650 TCollection_AsciiString str ( val->Value(j) );
651 di << str.ToCString();
654 else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
655 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
656 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
657 if ( j > val->Lower() ) di << ", ";
658 TCollection_AsciiString str ( val->Value(j) );
659 di << str.ToCString();
662 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
663 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
664 TopoDS_Shape S = val->Get();
665 di << S.TShape()->DynamicType()->Name();
666 if ( ! S.Location().IsIdentity() ) di << "(located)";
668 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
669 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
670 TCollection_AsciiString str ( val->Get() );
671 di << str.ToCString();
673 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
674 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
675 TCollection_AsciiString str ( val->Get() );
676 di << str.ToCString();
678 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
679 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
680 gp_Pnt myCentroid = val->Get();
682 di << myCentroid.X();
684 di << myCentroid.Y();
686 di << myCentroid.Z();
689 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
690 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
691 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
693 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
694 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
695 Quantity_Color C = val->GetColor();
697 Sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
698 C.Red(), C.Green(), C.Blue() );
701 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
702 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
703 Standard_Integer kind = val->GetKind();
704 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
705 if(kind<20) { //dimension
706 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
710 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
711 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
712 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
713 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
714 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
715 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
716 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
717 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
718 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
719 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
720 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
721 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
722 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
723 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
724 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
725 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
726 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
727 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
728 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
729 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
730 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
734 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
735 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
736 Standard_Real dens = val->GetDensity();
737 Standard_CString dimdens = "g/cu sm";
739 di<<val->GetName()->ToCString();
741 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
743 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
744 Standard_CString type;
745 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
746 type = "Layer Instance Link";
748 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
749 type = "SHUO Instance Link";
751 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
752 type = "DatumToler Link";
754 else if ( att->ID() == XCAFDoc::DimensionRefFirstGUID() ) {
755 type = "Dimension Link First";
757 else if ( att->ID() == XCAFDoc::DimensionRefSecondGUID() ) {
758 type = "Dimension Link Second";
760 else if ( att->ID() == XCAFDoc::GeomToleranceRefGUID() ){
761 type = "GeomTolerance Link";
765 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
766 TCollection_AsciiString ref;
767 Standard_Integer ii = 1;
768 if (DETGN->NbFathers()!=0) {
770 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
771 di << type<< " ==> (" << ref.ToCString();
772 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
773 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
774 di << ", " << ref.ToCString();
779 if (DETGN->NbChildren()!=0) {
780 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
781 di << type<< " <== (" << ref.ToCString();
782 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
783 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
784 di << ", " << ref.ToCString();
793 //=======================================================================
794 //function : setviewName
796 //=======================================================================
797 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
800 di<<"Use: "<<argv[0]<<" (1/0)\n";
803 Standard_Boolean mode = Standard_False;
804 if (Draw::Atoi(argv[1]) == 1) mode = Standard_True;
805 XCAFPrs::SetViewNameMode(mode);
810 //=======================================================================
811 //function : getviewName
813 //=======================================================================
815 static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
817 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON\n";
818 else di << "Display names OFF\n";
823 //=======================================================================
824 //function : XSetTransparency
826 //=======================================================================
827 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
830 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] \n";
834 Handle(TDocStd_Document) Doc;
835 DDocStd::GetDocument(argv[1], Doc);
836 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
838 const Standard_Real aTransparency = Draw::Atof(argv[2]);
840 // collect sequence of labels
841 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
842 TDF_LabelSequence seq;
844 for ( Standard_Integer i=3; i < argc; i++ ) {
846 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
847 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
848 di << argv[i] << " is not a valid shape label!";
851 seq.Append ( aLabel );
855 shapes->GetFreeShapes ( seq );
858 // find presentations and set transparency
859 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
860 Handle(TPrsStd_AISPresentation) prs;
861 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
862 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
863 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
865 prs->SetTransparency( aTransparency );
867 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
871 //=======================================================================
872 //function : XShowFaceBoundary
873 //purpose : Set face boundaries on/off
874 //=======================================================================
875 static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
876 Standard_Integer argc,
879 if (( argc != 4 && argc < 7 ) || argc > 9)
881 di << "Usage :\n " << argv[0]
882 << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
883 << " Doc - is the document name. \n"
884 << " Label - is the shape label. \n"
885 << " IsOn - flag indicating whether the boundaries\n"
886 << " should be turned on or off (can be set\n"
887 << " to 0 (off) or 1 (on)).\n"
888 << " R, G, B - red, green and blue components of boundary\n"
889 << " color in range (0 - 255).\n"
890 << " (default is (0, 0, 0)\n"
891 << " LineWidth - line width\n"
892 << " (default is 1)\n"
893 << " LineStyle - line fill style :\n"
898 << " (default is solid)";
903 // get specified document
904 Handle(TDocStd_Document) aDoc;
905 DDocStd::GetDocument (argv[1], aDoc);
908 di << argv[1] << " is not a document\n";
912 Handle(AIS_InteractiveContext) aContext;
913 if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext))
915 di << "Cannot find viewer for document " << argv[1] << "\n";
919 // get shape tool for shape verification
920 Handle(XCAFDoc_ShapeTool) aShapes =
921 XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
923 // get label and validate that it is a shape label
925 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
926 if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
928 di << argv[2] << " is not a valid shape label!";
932 // get presentation from label
933 Handle(TPrsStd_AISPresentation) aPrs;
934 if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
936 aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
939 Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
940 if (anInteractive.IsNull ())
942 di << "Can't set drawer attributes.\n"
943 "Interactive object for shape label doesn't exists.";
948 const Handle(Prs3d_Drawer)& aDrawer = anInteractive->Attributes ();
950 // default attributes
951 Quantity_Parameter aRed = 0.0;
952 Quantity_Parameter aGreen = 0.0;
953 Quantity_Parameter aBlue = 0.0;
954 Standard_Real aWidth = 1.0;
955 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
957 // turn boundaries on/off
958 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1);
959 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
961 // set boundary color
965 aRed = Draw::Atof (argv[4])/255.;
966 aGreen = Draw::Atof (argv[5])/255.;
967 aBlue = Draw::Atof (argv[6])/255.;
973 aWidth = (Standard_Real)Draw::Atof (argv[7]);
976 // select appropriate line type
979 switch (Draw::Atoi (argv[8]))
981 case 1: aLineType = Aspect_TOL_DASH; break;
982 case 2: aLineType = Aspect_TOL_DOT; break;
983 case 3: aLineType = Aspect_TOL_DOTDASH; break;
985 aLineType = Aspect_TOL_SOLID;
989 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
991 Handle(Prs3d_LineAspect) aBoundaryAspect =
992 new Prs3d_LineAspect (aColor, aLineType, aWidth);
994 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
996 aContext->Redisplay (anInteractive);
1001 //=======================================================================
1002 //function : testDoc
1003 //purpose : Method to test destruction of document
1004 //=======================================================================
1005 static Standard_Integer testDoc (Draw_Interpretor&,
1006 Standard_Integer argc,
1011 cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<endl;
1014 TopoDS_Shape shape = DBRep::Get(argv[1]);
1018 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1020 Handle(TDocStd_Document) aD1 = new TDocStd_Document("BinXCAF");
1023 TCollection_AsciiString aViewName ("Driver1/DummyDocument/View1");
1024 ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), "");
1025 TPrsStd_AISViewer::New (aD1->GetData()->Root(), ViewerTest::GetAISContext());
1027 // get shape tool for shape verification
1028 Handle(XCAFDoc_ShapeTool) aShapes =
1029 XCAFDoc_DocumentTool::ShapeTool (aD1->Main());
1030 TDF_Label aLab = aShapes->AddShape(shape);
1032 Handle(Geom_Axis2Placement) aPlacement =
1033 new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX());
1034 Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement);
1036 Handle(TNaming_NamedShape) NS;
1037 Handle(TPrsStd_AISPresentation) prs;
1038 if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) {
1039 prs = TPrsStd_AISPresentation::Set( NS );
1042 if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) )
1045 TPrsStd_AISViewer::Update(aLab);
1046 ViewerTest::GetAISContext()->Display (aTriShape, Standard_True);
1049 ViewerTest::RemoveView (aViewName);
1054 //=======================================================================
1057 //=======================================================================
1059 void XDEDRAW::Init(Draw_Interpretor& di)
1062 static Standard_Boolean initactor = Standard_False;
1063 if (initactor) return; initactor = Standard_True;
1065 // Load static variables for STEPCAF (ssv; 16.08.2012)
1066 STEPCAFControl_Controller::Init();
1068 // Initialize XCAF formats
1069 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1070 BinXCAFDrivers::DefineFormat(anApp);
1071 XmlXCAFDrivers::DefineFormat(anApp);
1073 // Register driver in global table for displaying XDE documents
1074 // in 3d viewer using OCAF mechanics
1075 TPrsStd_DriverTable::Get()->AddDriver (XCAFPrs_Driver::GetID(), new XCAFPrs_Driver);
1077 //=====================================
1079 //=====================================
1081 Standard_CString g = "XDE general commands";
1083 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
1084 __FILE__, newDoc, g);
1086 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
1087 __FILE__, saveDoc, g);
1089 di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path",
1090 __FILE__, openDoc, g);
1092 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
1095 di.Add ("XStat","Doc \t: Print statistics of document",
1096 __FILE__, statdoc, g);
1098 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
1099 __FILE__, setPrs, g);
1101 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
1104 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
1107 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
1108 __FILE__, XAttributeValue, g);
1110 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
1111 __FILE__, setviewName, g);
1113 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
1114 __FILE__, getviewName, g);
1116 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
1117 __FILE__, XSetTransparency, g);
1119 di.Add ("XShowFaceBoundary",
1120 "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
1121 "- turns on/off drawing of face boundaries and defines boundary line style",
1122 __FILE__, XShowFaceBoundary, g);
1123 di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g);
1125 // Specialized commands
1126 XDEDRAW_Shapes::InitCommands ( di );
1127 XDEDRAW_Colors::InitCommands ( di );
1128 XDEDRAW_Layers::InitCommands ( di );
1129 XDEDRAW_Props::InitCommands ( di );
1130 XDEDRAW_GDTs::InitCommands ( di );
1131 XDEDRAW_Common::InitCommands ( di );//moved from EXE
1136 //==============================================================================
1138 //==============================================================================
1139 void XDEDRAW::Factory(Draw_Interpretor& theDI)
1141 XSDRAWIGES::InitSelect();
1142 XSDRAWIGES::InitToBRep(theDI);
1143 XSDRAWIGES::InitFromBRep(theDI);
1145 XSDRAWSTEP::InitCommands(theDI);
1147 XSDRAW::LoadDraw(theDI);
1149 XDEDRAW::Init(theDI);
1152 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded\n";
1156 // Declare entry point PLUGINFACTORY