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.
18 #include <AIS_InteractiveContext.hxx>
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_Trihedron.hxx>
21 #include <Aspect_TypeOfLine.hxx>
22 #include <BRepBuilderAPI_Transform.hxx>
24 #include <DDF_Browser.hxx>
25 #include <DDocStd.hxx>
26 #include <DDocStd_DrawDocument.hxx>
27 #include <DE_Wrapper.hxx>
28 #include <DEBRepCascade_ConfigurationNode.hxx>
29 #include <DEXCAFCascade_ConfigurationNode.hxx>
31 #include <Draw_PluginMacro.hxx>
32 #include <Draw_ProgressIndicator.hxx>
33 #include <Geom_Axis2Placement.hxx>
34 #include <IGESCAFControl_ConfigurationNode.hxx>
35 #include <Prs3d_Drawer.hxx>
36 #include <Prs3d_LineAspect.hxx>
37 #include <Quantity_Color.hxx>
38 #include <RWStl_ConfigurationNode.hxx>
39 #include <RWGltf_ConfigurationNode.hxx>
40 #include <RWObj_ConfigurationNode.hxx>
41 #include <RWPly_ConfigurationNode.hxx>
42 #include <STEPCAFControl_Controller.hxx>
43 #include <STEPCAFControl_ConfigurationNode.hxx>
44 #include <TCollection_AsciiString.hxx>
45 #include <TCollection_ExtendedString.hxx>
46 #include <TCollection_HAsciiString.hxx>
47 #include <TColStd_HArray1OfInteger.hxx>
48 #include <TColStd_HArray1OfReal.hxx>
49 #include <TColStd_HSequenceOfExtendedString.hxx>
50 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
51 #include <TDataStd_AsciiString.hxx>
52 #include <TDataStd_ByteArray.hxx>
53 #include <TDataStd_Comment.hxx>
54 #include <TDataStd_Integer.hxx>
55 #include <TDataStd_IntegerArray.hxx>
56 #include <XCAFDoc_LengthUnit.hxx>
57 #include <TDataStd_Name.hxx>
58 #include <TDataStd_Real.hxx>
59 #include <TDataStd_RealArray.hxx>
60 #include <TDataStd_TreeNode.hxx>
61 #include <TDataStd_UAttribute.hxx>
62 #include <TDF_AttributeIterator.hxx>
63 #include <TDF_ChildIterator.hxx>
64 #include <TDF_Data.hxx>
65 #include <TDF_LabelSequence.hxx>
66 #include <TDF_Reference.hxx>
67 #include <TDF_Tool.hxx>
68 #include <TDocStd_Application.hxx>
69 #include <TDocStd_Document.hxx>
70 #include <TDocStd_Owner.hxx>
71 #include <PCDM_ReaderFilter.hxx>
72 #include <TNaming_NamedShape.hxx>
73 #include <TopoDS_Shape.hxx>
74 #include <TPrsStd_AISPresentation.hxx>
75 #include <TPrsStd_AISViewer.hxx>
76 #include <TPrsStd_DriverTable.hxx>
77 #include <TPrsStd_NamedShapeDriver.hxx>
78 #include <V3d_View.hxx>
79 #include <V3d_Viewer.hxx>
80 #include <ViewerTest.hxx>
81 #include <ViewerTest_AutoUpdater.hxx>
82 #include <Vrml_ConfigurationNode.hxx>
83 #include <XCAFDoc.hxx>
84 #include <XCAFDoc_AssemblyIterator.hxx>
85 #include <XCAFDoc_AssemblyGraph.hxx>
86 #include <XCAFDoc_AssemblyTool.hxx>
87 #include <XCAFDoc_Area.hxx>
88 #include <XCAFDoc_Centroid.hxx>
89 #include <XCAFDoc_Color.hxx>
90 #include <XCAFDoc_ColorTool.hxx>
91 #include <XCAFDoc_DimTol.hxx>
92 #include <XCAFDoc_Dimension.hxx>
93 #include <XCAFDoc_Datum.hxx>
94 #include <XCAFDoc_Editor.hxx>
95 #include <XCAFDoc_GeomTolerance.hxx>
96 #include <XCAFDoc_DocumentTool.hxx>
97 #include <XCAFDoc_GraphNode.hxx>
98 #include <XCAFDoc_LayerTool.hxx>
99 #include <XCAFDoc_Material.hxx>
100 #include <XCAFDoc_ShapeTool.hxx>
101 #include <XCAFDoc_Volume.hxx>
102 #include <XCAFPrs.hxx>
103 #include <XCAFPrs_AISObject.hxx>
104 #include <XCAFPrs_Driver.hxx>
105 #include <XDEDRAW.hxx>
106 #include <XDEDRAW_Colors.hxx>
107 #include <XDEDRAW_Common.hxx>
108 #include <XDEDRAW_Layers.hxx>
109 #include <XDEDRAW_Props.hxx>
110 #include <XDEDRAW_Shapes.hxx>
111 #include <XDEDRAW_GDTs.hxx>
112 #include <XDEDRAW_Views.hxx>
113 #include <XDEDRAW_Notes.hxx>
114 #include <XSDRAWIGES.hxx>
115 #include <XSDRAWSTEP.hxx>
116 #include <UnitsMethods.hxx>
118 #include <BinXCAFDrivers.hxx>
119 #include <XmlXCAFDrivers.hxx>
123 //=======================================================================
124 // Section: General commands
125 //=======================================================================
127 //=======================================================================
130 //=======================================================================
131 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
133 if (argc < 2) {di<<"Give document name\n";return 1;}
135 Handle(TDocStd_Document) D;
136 Handle(DDocStd_DrawDocument) DD;
137 Handle(TDocStd_Application) A = DDocStd::GetApplication();
139 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
140 A->NewDocument( "BinXCAF" ,D);
141 DD = new DDocStd_DrawDocument(D);
142 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
143 Draw::Set(argv[1],DD);
144 di << "document " << argv[1] << " created\n";
145 //DDocStd::ReturnLabel(di,D->Main());
147 else di << argv[1] << " is already a document\n";
153 //=======================================================================
156 //=======================================================================
157 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
159 Handle(TDocStd_Document) D;
160 Handle(TDocStd_Application) A = DDocStd::GetApplication();
163 if (A->NbDocuments() < 1) return 1;
164 A->GetDocument(1, D);
167 if (!DDocStd::GetDocument(argv[1],D)) return 1;
170 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
172 PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull;
175 TCollection_ExtendedString path (argv[2]);
176 aStatus = A->SaveAs (D, path, aProgress->Start());
178 else if (!D->IsSaved())
180 std::cout << "Storage error: this document has never been saved\n";
185 aStatus = A->Save (D, aProgress->Start());
192 case PCDM_SS_DriverFailure:
193 di << "Storage error: driver failure\n";
195 case PCDM_SS_WriteFailure:
196 di << "Storage error: write failure\n";
198 case PCDM_SS_Failure:
199 di << "Storage error: general failure\n";
201 case PCDM_SS_Doc_IsNull:
202 di << "Storage error: document is NULL\n";
205 di << "Storage error: no object\n";
207 case PCDM_SS_Info_Section_Error:
208 di << "Storage error: section error\n";
210 case PCDM_SS_UserBreak:
211 di << "Storage error: user break\n";
213 case PCDM_SS_UnrecognizedFormat:
214 di << "Storage error: unrecognized document storage format " << D->StorageFormat() << "\n";
221 //=======================================================================
224 //=======================================================================
225 static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
227 Handle(TDocStd_Document) D;
228 Handle(DDocStd_DrawDocument) DD;
229 Handle(TDocStd_Application) A = DDocStd::GetApplication();
233 di << "invalid number of arguments. Usage:\t XOpen filename docname [-skipAttribute] [-readAttribute] [-readPath] [-append|-overwrite]\n";
237 TCollection_AsciiString Filename = argv[1];
238 Standard_CString DocName = argv[2];
240 Handle(PCDM_ReaderFilter) aFilter = new PCDM_ReaderFilter;
241 for (Standard_Integer i = 3; i < argc; i++)
243 TCollection_AsciiString anArg(argv[i]);
244 if (anArg == "-append")
246 aFilter->Mode() = PCDM_ReaderFilter::AppendMode_Protect;
248 else if (anArg == "-overwrite")
250 aFilter->Mode() = PCDM_ReaderFilter::AppendMode_Overwrite;
252 else if (anArg.StartsWith("-skip"))
254 TCollection_AsciiString anAttrType = anArg.SubString(6, anArg.Length());
255 aFilter->AddSkipped(anAttrType);
257 else if (anArg.StartsWith("-read"))
259 TCollection_AsciiString aValue = anArg.SubString(6, anArg.Length());
260 if (aValue.Value(1) == '0') // path
262 aFilter->AddPath(aValue);
264 else // attribute to read
266 aFilter->AddRead(aValue);
271 if (aFilter->IsAppendMode() && !DDocStd::GetDocument (DocName, D, Standard_False))
273 di << "for append mode document " << DocName << " must be already created\n";
277 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di);
278 if ( A->Open (Filename, D, aFilter, aProgress->Start()) != PCDM_RS_OK )
280 di << "cannot open XDE document\n";
284 if (!aFilter->IsAppendMode())
286 DD = new DDocStd_DrawDocument (D);
287 TDataStd_Name::Set (D->GetData()->Root(), DocName);
288 Draw::Set (DocName, DD);
291 di << "document " << DocName << " opened\n";
296 //=======================================================================
299 //=======================================================================
300 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
303 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]\n";
306 Handle(TDocStd_Document) Doc;
307 DDocStd::GetDocument(argv[1], Doc);
308 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
310 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
311 Standard_Boolean deep = Standard_False;
312 if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True;
313 Standard_SStream aDumpLog;
314 myAssembly->Dump(aDumpLog, deep);
320 //=======================================================================
321 //function : StatAssembly
322 //purpose : recursive part of statistics
323 //=======================================================================
325 static void StatAssembly(const TDF_Label L,
326 const Standard_Integer level,
327 Handle(TColStd_HArray1OfInteger) &HAI,
328 Standard_Integer &NbCentroidProp,
329 Standard_Integer &NbVolumeProp,
330 Standard_Integer &NbAreaProp,
331 Standard_Integer &NbShapesWithName,
332 Standard_Integer &NbShapesWithColor,
333 Standard_Integer &NbShapesWithLayer,
334 Handle(TDocStd_Document) &aDoc,
335 Standard_Boolean &PrintStructMode,
336 Draw_Interpretor& di)
338 if(PrintStructMode) {
339 for(Standard_Integer j=0; j<=level; j++)
342 TCollection_AsciiString Entry;
343 TDF_Tool::Entry(L, Entry);
344 if(PrintStructMode) di<<Entry.ToCString();
346 Handle(TDataStd_Name) Name;
347 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
349 if(PrintStructMode) {
350 di << " " << Name->Get() << " has attributes: ";
354 if(PrintStructMode) di<<" NoName has attributes: ";
357 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
358 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
359 if(PrintStructMode) di<<"Centroid ";
363 if(XCAFDoc_Volume::Get(L,tmp)) {
364 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
367 if(XCAFDoc_Area::Get(L,tmp)) {
368 if(PrintStructMode) di<<"Area("<<tmp<<") ";
371 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
372 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
373 Quantity_ColorRGBA col;
374 Standard_Boolean IsColor = Standard_False;
375 Standard_Boolean IsByLayer = Standard_False;
376 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
377 IsColor = Standard_True;
378 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
379 IsColor = Standard_True;
380 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
381 IsColor = Standard_True;
382 else if(CTool->IsColorByLayer(L))
383 IsByLayer = Standard_True;
384 if(IsColor || IsByLayer) {
387 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
388 LTool->GetLayers(L, aLayerS);
389 // Currently for DXF pnly, thus
390 // only 1 Layer should be.
391 if(aLayerS->Length() == 1)
393 TDF_Label aLayer = LTool->FindLayer (aLayerS->First());
394 Quantity_ColorRGBA aColor;
395 if (CTool->GetColor (aLayer, XCAFDoc_ColorGen, aColor))
397 TCollection_AsciiString aColorName = aColor.GetRGB().StringName(aColor.GetRGB().Name());
398 di<<"Color(" << aColorName.ToCString() << ") ";
402 di<<"Color(ByLayer) ";
409 TCollection_AsciiString Entry1;
410 Entry1 = col.GetRGB().StringName(col.GetRGB().Name());
411 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<" "<<col.Alpha()<<") ";
415 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
416 LTool->GetLayers(L, aLayerS);
417 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
418 if(PrintStructMode) {
420 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
421 TCollection_AsciiString Entry2(aLayerS->Value(i));
423 di<<"\""<<Entry2.ToCString()<<"\"";
425 di<<" \""<<Entry2.ToCString()<<"\"";
431 if(PrintStructMode) di<<"\n";
433 HAI->SetValue(level, HAI->Value(level)+1 );
435 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
436 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
437 NbAreaProp, NbShapesWithName, NbShapesWithColor,
438 NbShapesWithLayer, aDoc, PrintStructMode, di);
445 //=======================================================================
448 //=======================================================================
449 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
452 di<<"Use: "<<argv[0]<<" Doc \n";
455 Handle(TDocStd_Document) Doc;
456 DDocStd::GetDocument(argv[1], Doc);
457 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
459 Standard_Boolean PrintStructMode = (argc==3);
460 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
462 TDF_LabelSequence SeqLabels;
463 aTool->GetShapes(SeqLabels);
464 if(SeqLabels.Length()<=0) return 0;
465 if(PrintStructMode) di<<"\nStructure of shapes in the document:\n";
466 Standard_Integer level=0;
467 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
468 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
469 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
470 Standard_Integer i=0;
471 for(i=0; i<=20; i++) HAI->SetValue(i,0);
472 for(i=1; i<=SeqLabels.Length(); i++) {
473 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
474 NbAreaProp, NbShapesWithName, NbShapesWithColor,
475 NbShapesWithLayer, Doc, PrintStructMode, di);
477 Standard_Integer NbLabelsShape = 0;
478 di<<"\nStatistis of shapes in the document:\n";
479 for(i=0; i<=20; i++) {
480 if(HAI->Value(i)==0) break;
481 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
482 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
483 NbLabelsShape = NbLabelsShape + HAI->Value(i);
485 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
486 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
487 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
488 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
490 di<<"\nStatistis of Props in the document:\n";
491 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
492 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
493 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
495 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
496 TDF_LabelSequence CLabels;
497 CTool->GetColors(CLabels);
498 di<<"\nNumber of colors = "<<CLabels.Length()<<"\n";
499 if(CLabels.Length()>0) {
500 for(i=1; i<=CLabels.Length(); i++) {
501 TDF_Label aLabel = CLabels.Value(i);
503 CTool->GetColor(aLabel, col);
504 di<<col.StringName(col.Name())<<" ";
509 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
510 TDF_LabelSequence LLabels;
511 LTool->GetLayerLabels(LLabels);
512 di<<"\nNumber of layers = "<<LLabels.Length()<<"\n";
513 if(LLabels.Length()>0) {
514 for(i=1; i<=LLabels.Length(); i++) {
515 TDF_Label aLabel = LLabels.Value(i);
516 TCollection_ExtendedString layerName;
517 LTool->GetLayer(aLabel, layerName);
518 di << "\"" << layerName << "\" ";
528 //=======================================================================
531 //=======================================================================
532 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
535 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
539 Handle(TDocStd_Document) Doc;
540 DDocStd::GetDocument(argv[1], Doc);
541 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
543 // collect sequence of labels to set presentation
544 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
545 TDF_LabelSequence seq;
547 for ( Standard_Integer i=2; i < argc; i++ ) {
549 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
550 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
551 di << argv[i] << " is not a valid shape label!";
554 seq.Append ( aLabel );
558 shapes->GetShapes ( seq );
562 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
563 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
564 Handle(TPrsStd_AISPresentation) prs;
565 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
566 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
567 prs->SetMaterial (Graphic3d_NameOfMaterial_Plastified);
569 // Quantity_Color Col;
570 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
571 // prs->SetColor ( Col.Name() );
572 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
573 // prs->SetColor ( Col.Name() );
579 //=======================================================================
582 //=======================================================================
583 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
586 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
590 Handle(TDocStd_Document) aDoc;
591 DDocStd::GetDocument (argv[1], aDoc);
594 std::cout << argv[1] << " is not a document\n";
599 TDF_Label aRoot = aDoc->GetData()->Root();
600 Handle(TPrsStd_AISViewer) aDocViewer;
601 TCollection_AsciiString aViewName = TCollection_AsciiString ("Driver1/Document_") + argv[1] + "/View1";
602 if (!TPrsStd_AISViewer::Find (aRoot, aDocViewer))
604 ViewerTest::ViewerInit (aViewName);
605 aDocViewer = TPrsStd_AISViewer::New (aRoot, ViewerTest::GetAISContext());
608 // collect sequence of labels to display
609 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
610 TDF_LabelSequence seq;
612 for ( Standard_Integer i=2; i < argc; i++ ) {
614 TDF_Tool::Label (aDoc->GetData(), argv[i], aLabel);
615 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
616 di << argv[i] << " is not a valid shape label!";
619 seq.Append ( aLabel );
623 shapes->GetFreeShapes ( seq );
626 // set presentations and show
627 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
628 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
629 Handle(TPrsStd_AISPresentation) prs;
630 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
631 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
632 prs->SetMaterial (Graphic3d_NameOfMaterial_Plastified);
634 // Quantity_Color Col;
635 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
636 // prs->SetColor ( Col.Name() );
637 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
638 // prs->SetColor ( Col.Name() );
639 prs->Display(Standard_True);
641 TPrsStd_AISViewer::Update (aDoc->GetData()->Root());
645 //! XDisplay command implementation.
646 class XDEDRAW_XDisplayTool
649 //! XDisplay command interface.
650 static Standard_Integer XDisplay (Draw_Interpretor& theDI,
651 Standard_Integer theNbArgs,
652 const char** theArgVec)
654 XDEDRAW_XDisplayTool aTool;
655 return aTool.xdisplay (theDI, theNbArgs, theArgVec);
660 XDEDRAW_XDisplayTool()
664 myToPrefixDocName (Standard_True),
665 myToGetNames (Standard_True),
666 myToExplore (Standard_False) {}
668 //! Display single label.
669 Standard_Integer displayLabel (Draw_Interpretor& theDI,
670 const TDF_Label& theLabel,
671 const TCollection_AsciiString& theNamePrefix,
672 const TopLoc_Location& theLoc,
673 TCollection_AsciiString& theOutDispList)
675 TCollection_AsciiString aName;
678 Handle(TDataStd_Name) aNodeName;
679 if (theLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
681 aName = aNodeName->Get();
686 if (XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel)
687 && aRefLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
689 aName = aNodeName->Get();
695 TDF_Tool::Entry (theLabel, aName);
697 for (Standard_Integer aNameIndex = 1;; ++aNameIndex)
699 if (myNameMap.Add (aName))
703 aName = aNodeName->Get() + "_" + aNameIndex;
708 TDF_Tool::Entry (theLabel, aName);
710 aName = theNamePrefix + aName;
714 TDF_Label aRefLabel = theLabel;
715 XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel);
716 if (XCAFDoc_ShapeTool::IsAssembly (aRefLabel))
719 const TopLoc_Location aLoc = theLoc * XCAFDoc_ShapeTool::GetLocation (theLabel);
720 for (TDF_ChildIterator aChildIter (aRefLabel); aChildIter.More(); aChildIter.Next())
722 if (displayLabel (theDI, aChildIter.Value(), aName, aLoc, theOutDispList) == 1)
731 Handle(XCAFPrs_AISObject) aPrs = new XCAFPrs_AISObject (theLabel);
732 if (!theLoc.IsIdentity())
734 aPrs->SetLocalTransformation (theLoc);
736 if (myDispMode != -2)
738 if (myDispMode == -1)
740 aPrs->UnsetDisplayMode();
742 if (!aPrs->AcceptDisplayMode (myDispMode))
744 theDI << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myDispMode << " display mode";
749 aPrs->SetDisplayMode (myDispMode);
755 && !aPrs->AcceptDisplayMode (myHiMode))
757 theDI << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myHiMode << " display mode";
760 aPrs->SetHilightMode (myHiMode);
762 if (myIsAutoTriang != -1)
764 aPrs->Attributes()->SetAutoTriangulation (myIsAutoTriang == 1);
767 ViewerTest::Display (aName, aPrs, false);
768 theOutDispList += aName + " ";
772 //! XDisplay command implementation.
773 Standard_Integer xdisplay (Draw_Interpretor& theDI,
774 Standard_Integer theNbArgs,
775 const char** theArgVec)
777 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
778 if (aContext.IsNull())
780 theDI << "Error: no active viewer";
784 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
785 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
787 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
788 anArgCase.LowerCase();
789 if (anAutoUpdater.parseRedrawMode (anArgCase))
793 else if (anArgIter + 1 < theNbArgs
795 && (anArgCase == "-dispmode"
796 || anArgCase == "-displaymode")
797 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
799 myDispMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue();
801 else if (anArgIter + 1 < theNbArgs
803 && (anArgCase == "-himode"
804 || anArgCase == "-highmode"
805 || anArgCase == "-highlightmode")
806 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
808 myHiMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue();
810 else if (anArgCase == "-autotr"
811 || anArgCase == "-autotrian"
812 || anArgCase == "-autotriang"
813 || anArgCase == "-autotriangulation"
814 || anArgCase == "-noautotr"
815 || anArgCase == "-noautotrian"
816 || anArgCase == "-noautotriang"
817 || anArgCase == "-noautotriangulation")
819 myIsAutoTriang = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter) ? 1 : 0;
821 else if (anArgCase == "-docprefix"
822 || anArgCase == "-nodocprefix")
824 myToPrefixDocName = Standard_True;
825 if (anArgIter + 1 < theNbArgs
826 && Draw::ParseOnOff (theArgVec[anArgIter + 1], myToPrefixDocName))
830 if (anArgCase.StartsWith ("-no"))
832 myToPrefixDocName = !myToPrefixDocName;
835 else if (anArgCase == "-names"
836 || anArgCase == "-nonames")
838 myToGetNames = Standard_True;
839 if (anArgIter + 1 < theNbArgs
840 && Draw::ParseOnOff (theArgVec[anArgIter + 1], myToGetNames))
844 if (anArgCase.StartsWith ("-no"))
846 myToGetNames = !myToGetNames;
849 else if (anArgCase == "-explore"
850 || anArgCase == "-noexplore")
852 myToExplore = Standard_True;
853 if (anArgIter + 1 < theNbArgs
854 && Draw::ParseOnOff (theArgVec[anArgIter + 1], myToExplore))
858 if (anArgCase.StartsWith ("-no"))
860 myToExplore = !myToExplore;
863 else if (anArgCase == "-outdisplist"
864 && anArgIter + 1 < theNbArgs)
866 myOutDispListVar = theArgVec[++anArgIter];
867 myOutDispList.Clear();
872 && DDocStd::GetDocument (theArgVec[anArgIter], myDoc, Standard_False))
874 myDocName = theArgVec[anArgIter];
878 TCollection_AsciiString aValue (theArgVec[anArgIter]);
879 const Standard_Integer aFirstSplit = aValue.Search (":");
880 if (!IsDigit (aValue.Value (1))
882 && aFirstSplit < aValue.Length())
884 TCollection_AsciiString aDocName = aValue.SubString (1, aFirstSplit - 1);
885 Standard_CString aDocNameStr = aDocName.ToCString();
886 Handle(TDocStd_Document) aDoc;
887 if (DDocStd::GetDocument (aDocNameStr, aDoc, Standard_False))
889 aValue = aValue.SubString (aFirstSplit + 1, aValue.Length());
893 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
897 myDocName = aDocName;
902 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
907 TDF_Tool::Label (myDoc->GetData(), aValue.ToCString(), aLabel);
909 || !XCAFDoc_ShapeTool::IsShape (aLabel))
911 theDI << "Syntax error: " << aValue << " is not a valid shape label";
914 myLabels.Append (aLabel);
919 theDI << "Syntax error: not enough arguments";
922 if (myLabels.IsEmpty())
924 XCAFDoc_DocumentTool::ShapeTool (myDoc->Main())->GetFreeShapes (myLabels);
927 for (TDF_LabelSequence::Iterator aLabIter (myLabels); aLabIter.More(); aLabIter.Next())
929 const TDF_Label& aLabel = aLabIter.Value();
930 if (displayLabel (theDI, aLabel, myToPrefixDocName ? myDocName + ":" : "", TopLoc_Location(), myOutDispList) == 1)
935 if (myOutDispListVar.IsEmpty())
937 theDI << myOutDispList;
941 Draw::Set (myOutDispListVar.ToCString(), myOutDispList.ToCString());
947 NCollection_Map<TCollection_AsciiString>
948 myNameMap; //!< names map to handle collisions
949 Handle(TDocStd_Document) myDoc; //!< document
950 TCollection_AsciiString myDocName; //!< document name
951 TCollection_AsciiString myOutDispListVar; //!< tcl variable to print the result objects
952 TCollection_AsciiString myOutDispList; //!< string with list of all displayed object names
953 TDF_LabelSequence myLabels; //!< labels to display
954 Standard_Integer myDispMode; //!< shape display mode
955 Standard_Integer myHiMode; //!< shape highlight mode
956 Standard_Integer myIsAutoTriang; //!< auto-triangulation mode
957 Standard_Boolean myToPrefixDocName; //!< flag to prefix objects with document name
958 Standard_Boolean myToGetNames; //!< flag to use label names or tags
959 Standard_Boolean myToExplore; //!< flag to explore assembles
962 //=======================================================================
965 //=======================================================================
966 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
969 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}\n";
973 Handle(TDocStd_Document) Doc;
974 DDocStd::GetDocument(argv[1], Doc);
975 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
977 Handle(AIS_InteractiveContext) IC;
978 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
979 di << "Cannot find viewer for document " << argv[1] << "\n";
983 Handle(V3d_Viewer) aViewer = IC->CurrentViewer();
984 V3d_ListOfViewIterator aViewIter = aViewer->ActiveViewIterator();
985 if (aViewIter.More())
987 aViewIter.Value()->Dump ( argv[2] );
990 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
998 //=======================================================================
999 //function : XAttributeValue
1001 //=======================================================================
1002 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1004 if ( argc < 4 ) { std::cout << "Syntax error: Too few args\n"; return 1; }
1005 Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1]));
1006 if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; }
1009 TDF_Tool::Label(browser->Data(),argv[2],lab);
1010 if ( lab.IsNull() ) { std::cout << "Syntax error: label is Null: " << argv[2] << "\n"; return 1; }
1012 Standard_Integer num = Draw::Atoi ( argv[3] );
1013 TDF_AttributeIterator itr(lab,Standard_False);
1014 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
1016 if ( ! itr.More() ) { std::cout << "Syntax error: Attribute #" << num << " not found\n"; return 1; }
1018 TCollection_AsciiString anInfo = XCAFDoc::AttributeInfo ( itr.Value() );
1019 if (!anInfo.IsEmpty())
1021 di << anInfo.ToCString();
1027 //=======================================================================
1028 //function : setviewName
1030 //=======================================================================
1031 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1034 di<<"Use: "<<argv[0]<<" (1/0)\n";
1037 Standard_Boolean mode = Standard_False;
1038 if (Draw::Atoi(argv[1]) == 1) mode = Standard_True;
1039 XCAFPrs::SetViewNameMode(mode);
1044 //=======================================================================
1045 //function : getviewName
1046 //purpose : auxiliary
1047 //=======================================================================
1049 static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
1051 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON\n";
1052 else di << "Display names OFF\n";
1057 //=======================================================================
1058 //function : XSetTransparency
1060 //=======================================================================
1061 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1064 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] \n";
1068 Handle(TDocStd_Document) Doc;
1069 DDocStd::GetDocument(argv[1], Doc);
1070 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
1072 const Standard_Real aTransparency = Draw::Atof(argv[2]);
1074 // collect sequence of labels
1075 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1076 TDF_LabelSequence seq;
1078 for ( Standard_Integer i=3; i < argc; i++ ) {
1080 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
1081 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
1082 di << argv[i] << " is not a valid shape label!";
1085 seq.Append ( aLabel );
1089 shapes->GetFreeShapes ( seq );
1092 // find presentations and set transparency
1093 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
1094 Handle(TPrsStd_AISPresentation) prs;
1095 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
1096 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
1097 prs->SetMaterial (Graphic3d_NameOfMaterial_Plastified);
1099 prs->SetTransparency( aTransparency );
1101 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
1105 //=======================================================================
1106 //function : setLengthUnit
1108 //=======================================================================
1109 static Standard_Integer setLengthUnit(Draw_Interpretor& di,
1110 Standard_Integer argc,
1115 di << "Use: " << argv[0] << " Doc {unitName|scaleFactor} \n";
1119 Handle(TDocStd_Document) aDoc;
1120 DDocStd::GetDocument(argv[1], aDoc);
1123 di << "Error: " << argv[1] << " is not a document\n"; return 1;
1126 TCollection_AsciiString anUnit(argv[2]);
1127 Standard_Real anUnitValue = 1.;
1128 TCollection_AsciiString anUnitName;
1129 if (!anUnit.IsRealValue(true))
1131 UnitsMethods_LengthUnit aTypeUnit = UnitsMethods::LengthUnitFromString(anUnit.ToCString(), Standard_False);
1132 if (aTypeUnit == UnitsMethods_LengthUnit_Undefined)
1134 di << "Error: " << anUnit
1135 << " is incorrect unit, use m, mm, km, cm, micron, mille, in, min, nin, ft, stat.mile\n";
1138 anUnitName = anUnit;
1139 anUnitValue = UnitsMethods::GetLengthFactorValue(aTypeUnit) * 0.001;
1143 anUnitValue = anUnit.RealValue();
1144 anUnitName = UnitsMethods::DumpLengthUnit(anUnitValue, UnitsMethods_LengthUnit_Meter);
1146 XCAFDoc_LengthUnit::Set(aDoc->Main().Root(), anUnitName, anUnitValue);
1150 //=======================================================================
1151 //function : dumpLengthUnit
1153 //=======================================================================
1154 static Standard_Integer dumpLengthUnit(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1156 if (argc != 2 && argc != 3) {
1157 di << "Use: " << argv[0] << " Doc [-scale]\n";
1161 Handle(TDocStd_Document) aDoc;
1162 DDocStd::GetDocument(argv[1], aDoc);
1165 di << "Error: " << argv[1] << " is not a document\n"; return 1;
1167 Handle(XCAFDoc_LengthUnit) aUnits;
1168 if (!aDoc->Main().Root().FindAttribute(XCAFDoc_LengthUnit::GetID(), aUnits))
1170 di << "Error: Document doesn't contain a Length Unit\n";
1175 TCollection_AsciiString anOption(argv[2]);
1176 anOption.LowerCase();
1177 if (anOption.IsEqual("-scale"))
1179 di << aUnits->GetUnitValue();
1184 di << "Error: Incorrect option, use -scale\n";
1188 di << aUnits->GetUnitName();
1192 //=======================================================================
1193 //function : XShowFaceBoundary
1194 //purpose : Set face boundaries on/off
1195 //=======================================================================
1196 static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
1197 Standard_Integer argc,
1200 if (( argc != 4 && argc < 7 ) || argc > 9)
1202 di << "Usage :\n " << argv[0]
1203 << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
1204 << " Doc - is the document name. \n"
1205 << " Label - is the shape label. \n"
1206 << " IsOn - flag indicating whether the boundaries\n"
1207 << " should be turned on or off (can be set\n"
1208 << " to 0 (off) or 1 (on)).\n"
1209 << " R, G, B - red, green and blue components of boundary\n"
1210 << " color in range (0 - 255).\n"
1211 << " (default is (0, 0, 0)\n"
1212 << " LineWidth - line width\n"
1213 << " (default is 1)\n"
1214 << " LineStyle - line fill style :\n"
1219 << " (default is solid)";
1224 // get specified document
1225 Handle(TDocStd_Document) aDoc;
1226 DDocStd::GetDocument (argv[1], aDoc);
1229 di << argv[1] << " is not a document\n";
1233 Handle(AIS_InteractiveContext) aContext;
1234 if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext))
1236 di << "Cannot find viewer for document " << argv[1] << "\n";
1240 // get shape tool for shape verification
1241 Handle(XCAFDoc_ShapeTool) aShapes =
1242 XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
1244 // get label and validate that it is a shape label
1246 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
1247 if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
1249 di << argv[2] << " is not a valid shape label!";
1253 // get presentation from label
1254 Handle(TPrsStd_AISPresentation) aPrs;
1255 if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
1257 aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
1260 Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
1261 if (anInteractive.IsNull ())
1263 di << "Can't set drawer attributes.\n"
1264 "Interactive object for shape label doesn't exists.";
1269 const Handle(Prs3d_Drawer)& aDrawer = anInteractive->Attributes ();
1271 // default attributes
1272 Standard_Real aRed = 0.0;
1273 Standard_Real aGreen = 0.0;
1274 Standard_Real aBlue = 0.0;
1275 Standard_Real aWidth = 1.0;
1276 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
1278 // turn boundaries on/off
1279 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1);
1280 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
1282 // set boundary color
1286 aRed = Draw::Atof (argv[4])/255.;
1287 aGreen = Draw::Atof (argv[5])/255.;
1288 aBlue = Draw::Atof (argv[6])/255.;
1294 aWidth = (Standard_Real)Draw::Atof (argv[7]);
1297 // select appropriate line type
1300 if (!ViewerTest::ParseLineType (argv[8], aLineType))
1302 std::cout << "Syntax error: unknown line type '" << argv[8] << "'\n";
1306 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
1308 Handle(Prs3d_LineAspect) aBoundaryAspect =
1309 new Prs3d_LineAspect (aColor, aLineType, aWidth);
1311 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
1313 aContext->Redisplay (anInteractive, Standard_True);
1318 //=======================================================================
1319 //function : XAssemblyTreeDump
1320 //purpose : Prints assembly tree structure up to the specified level
1321 //=======================================================================
1323 static Standard_Integer XDumpAssemblyTree(Draw_Interpretor& di,
1324 Standard_Integer argc,
1329 di << "Usage :\n " << argv[0] << " Doc [-root label] [-level l] [-names]\n"
1330 << " Doc - document name. \n"
1331 << " -root label - starting root label. \n"
1332 << " -level l - depth level (infinite by default). \n"
1333 << " -names - prints names instead of entries. \n";
1338 // get specified document
1339 Handle(TDocStd_Document) aDoc;
1340 DDocStd::GetDocument(argv[1], aDoc);
1343 di << argv[1] << " is not a document\n";
1347 XCAFDoc_AssemblyItemId aRoot;
1348 Standard_Integer aLevel = INT_MAX;
1349 Standard_Boolean aPrintNames = Standard_False;
1350 for (Standard_Integer iarg = 2; iarg < argc; ++iarg)
1352 if (strcmp(argv[iarg], "-root") == 0)
1354 Standard_ProgramError_Raise_if(iarg + 1 >= argc, "Root is expected!");
1355 aRoot.Init(argv[++iarg]);
1357 else if (strcmp(argv[iarg], "-level") == 0)
1359 Standard_ProgramError_Raise_if(iarg + 1 >= argc, "Level is expected!");
1360 TCollection_AsciiString anArg = argv[++iarg];
1361 Standard_ProgramError_Raise_if(!anArg.IsIntegerValue(), "Integer value is expected!");
1362 aLevel = anArg.IntegerValue();
1364 else if (strcmp(argv[iarg], "-names") == 0)
1366 aPrintNames = Standard_True;
1370 Standard_SStream aSS;
1372 XCAFDoc_AssemblyIterator anIt = aRoot.IsNull() ? XCAFDoc_AssemblyIterator(aDoc, aLevel)
1373 : XCAFDoc_AssemblyIterator(aDoc, aRoot, aLevel);
1374 XCAFDoc_AssemblyTool::Traverse(anIt, [&](const XCAFDoc_AssemblyItemId& theItem) -> Standard_Boolean
1378 Standard_Boolean aFirst = Standard_True;
1379 for (TColStd_ListOfAsciiString::Iterator anIt(theItem.GetPath()); anIt.More();
1380 anIt.Next(), aFirst = Standard_False)
1382 if (!aFirst) aSS << "/";
1384 TDF_Tool::Label(aDoc->GetData(), anIt.Value(), aL, Standard_False);
1387 TCollection_ExtendedString aName;
1388 Handle(TDataStd_Name) aNameAttr;
1389 if (aL.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
1391 aName = aNameAttr->Get();
1396 aSS << anIt.Value();
1402 aSS << theItem.ToString() << std::endl;
1404 return Standard_True;
1407 di << aSS.str().c_str();
1411 //=======================================================================
1412 //function : graphNodeTypename
1413 //purpose : Returns node type name
1414 //=======================================================================
1417 const char* graphNodeTypename(const XCAFDoc_AssemblyGraph::NodeType theNodeType)
1419 switch (theNodeType)
1421 case XCAFDoc_AssemblyGraph::NodeType_AssemblyRoot: return "R";
1422 case XCAFDoc_AssemblyGraph::NodeType_Subassembly: return "A";
1423 case XCAFDoc_AssemblyGraph::NodeType_Occurrence: return "O";
1424 case XCAFDoc_AssemblyGraph::NodeType_Part: return "P";
1425 case XCAFDoc_AssemblyGraph::NodeType_Subshape: return "S";
1426 default: return "?";
1430 //=======================================================================
1431 //function : XAssemblyGraphDump
1432 //purpose : Prints assembly graph structure
1433 //=======================================================================
1435 static Standard_Integer XDumpAssemblyGraph(Draw_Interpretor& di,
1436 Standard_Integer argc,
1441 di << "Usage :\n " << argv[0] << " Doc [-root label] [-verbose] \n"
1442 << " Doc - is the document name. \n"
1443 << " -root label - is the optional starting label. \n"
1444 << " -names - prints names instead of entries. \n";
1449 // get specified document
1450 Handle(TDocStd_Document) aDoc;
1451 DDocStd::GetDocument(argv[1], aDoc);
1454 di << argv[1] << " is not a document\n";
1458 Standard_Boolean aPrintNames = Standard_False;
1459 TDF_Label aLabel = XCAFDoc_DocumentTool::ShapesLabel(aDoc->Main());
1460 for (Standard_Integer iarg = 2; iarg < argc; ++iarg)
1462 if (strcmp(argv[iarg], "-root") == 0)
1464 Standard_ProgramError_Raise_if(iarg + 1 >= argc, "Root is expected!");
1465 TDF_Tool::Label(aDoc->GetData(), argv[++iarg], aLabel, Standard_False);
1467 else if (strcmp(argv[iarg], "-names") == 0)
1469 aPrintNames = Standard_True;
1473 Handle(XCAFDoc_AssemblyGraph) aG = new XCAFDoc_AssemblyGraph(aLabel);
1475 Standard_SStream aSS;
1477 XCAFDoc_AssemblyTool::Traverse(aG,
1478 [](const Handle(XCAFDoc_AssemblyGraph)& /*theGraph*/,
1479 const Standard_Integer /*theNode*/) -> Standard_Boolean
1481 return Standard_True;
1483 [&](const Handle(XCAFDoc_AssemblyGraph)& theGraph,
1484 const Standard_Integer theNode) -> Standard_Boolean
1486 const TDF_Label& aLabel = theGraph->GetNode(theNode);
1488 const XCAFDoc_AssemblyGraph::NodeType aNodeType = theGraph->GetNodeType(theNode);
1490 TCollection_AsciiString aNodeEntry;
1493 Handle(TDataStd_Name) aNameAttr;
1494 if (aLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
1496 aNodeEntry.AssignCat("'");
1497 aNodeEntry.AssignCat(aNameAttr->Get());
1498 aNodeEntry.AssignCat("'");
1501 if (aNodeEntry.IsEmpty())
1503 TDF_Tool::Entry(aLabel, aNodeEntry);
1506 aSS << theNode << " " << graphNodeTypename(aNodeType) << " " << aNodeEntry;
1507 const XCAFDoc_AssemblyGraph::AdjacencyMap& anAdjacencyMap = theGraph->GetLinks();
1508 const TColStd_PackedMapOfInteger* aLinksPtr = anAdjacencyMap.Seek(theNode);
1509 if (aLinksPtr != NULL)
1511 for (TColStd_MapIteratorOfPackedMapOfInteger anIt1(*aLinksPtr); anIt1.More(); anIt1.Next())
1513 aSS << " " << anIt1.Key();
1518 return Standard_True;
1522 di << aSS.str().c_str();
1526 //=======================================================================
1527 //function : XDumpNomenclature
1528 //purpose : Prints number of assembly instances
1529 //=======================================================================
1531 static Standard_Integer XDumpNomenclature(Draw_Interpretor& di,
1532 Standard_Integer argc,
1537 di << "Usage :\n " << argv[0] << " Doc [-names] \n"
1538 << " Doc - is the document name. \n"
1539 << " -names - prints names instead of entries. \n";
1544 // get specified document
1545 Handle(TDocStd_Document) aDoc;
1546 DDocStd::GetDocument(argv[1], aDoc);
1549 di << argv[1] << " is not a document\n";
1553 Standard_Boolean aPrintNames = Standard_False;
1554 for (Standard_Integer iarg = 2; iarg < argc; ++iarg)
1556 if (strcmp(argv[iarg], "-names") == 0)
1558 aPrintNames = Standard_True;
1562 Handle(XCAFDoc_AssemblyGraph) aG = new XCAFDoc_AssemblyGraph(aDoc);
1564 Standard_SStream aSS;
1566 XCAFDoc_AssemblyTool::Traverse(aG,
1567 [](const Handle(XCAFDoc_AssemblyGraph)& theGraph,
1568 const Standard_Integer theNode) -> Standard_Boolean
1570 const XCAFDoc_AssemblyGraph::NodeType aNodeType = theGraph->GetNodeType(theNode);
1571 return (aNodeType == XCAFDoc_AssemblyGraph::NodeType_AssemblyRoot) ||
1572 (aNodeType == XCAFDoc_AssemblyGraph::NodeType_Subassembly) ||
1573 (aNodeType == XCAFDoc_AssemblyGraph::NodeType_Part);
1575 [&](const Handle(XCAFDoc_AssemblyGraph)& theGraph,
1576 const Standard_Integer theNode) -> Standard_Boolean
1578 const TDF_Label& aLabel = theGraph->GetNode(theNode);
1580 const XCAFDoc_AssemblyGraph::NodeType aNodeType = theGraph->GetNodeType(theNode);
1582 TCollection_AsciiString aNodeEntry;
1585 Handle(TDataStd_Name) aNameAttr;
1586 if (aLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
1588 aNodeEntry.AssignCat("'");
1589 aNodeEntry.AssignCat(aNameAttr->Get());
1590 aNodeEntry.AssignCat("'");
1593 if (aNodeEntry.IsEmpty())
1595 TDF_Tool::Entry(aLabel, aNodeEntry);
1598 aSS << theNode << " " << graphNodeTypename(aNodeType) << " " << aNodeEntry << " "
1599 << theGraph->NbOccurrences(theNode) << std::endl;
1601 return Standard_True;
1605 di << aSS.str().c_str();
1610 //=======================================================================
1611 //function : XRescaleGeometry
1612 //purpose : Applies geometrical scale to all assembly components
1613 //=======================================================================
1615 static Standard_Integer XRescaleGeometry(Draw_Interpretor& di,
1616 Standard_Integer argc,
1621 di << "Usage :\n " << argv[0] << " Doc factor [-root label] [-force]\n"
1622 << " Doc - is the document name. \n"
1623 << " factor - is the scale factor. \n"
1624 << " -root label - is the starting label to apply rescaling. \n"
1625 << " -force - forces rescaling even if the starting label\n"
1626 << " is not a root. \n";
1631 // get specified document
1632 Handle(TDocStd_Document) aDoc;
1633 DDocStd::GetDocument(argv[1], aDoc);
1636 di << argv[1] << " is not a document\n";
1641 Standard_Real aScaleFactor = Draw::Atof(argv[2]);
1642 if (aScaleFactor <= 0)
1644 di << "Scale factor must be positive\n";
1648 Standard_Boolean aForce = Standard_False;
1649 TDF_Label aLabel = XCAFDoc_DocumentTool::ShapesLabel(aDoc->Main());
1650 for (Standard_Integer iarg = 3; iarg < argc; ++iarg)
1652 if (strcmp(argv[iarg], "-root") == 0)
1654 Standard_ProgramError_Raise_if(iarg + 1 >= argc, "Root is expected!");
1655 TDF_Tool::Label(aDoc->GetData(), argv[++iarg], aLabel, Standard_False);
1657 else if (strcmp(argv[iarg], "-force") == 0)
1659 aForce = Standard_True;
1663 if (!XCAFDoc_Editor::RescaleGeometry(aLabel, aScaleFactor, aForce))
1665 di << "Geometry rescale failed\n";
1672 //=======================================================================
1673 //function : testDoc
1674 //purpose : Method to test destruction of document
1675 //=======================================================================
1676 static Standard_Integer testDoc (Draw_Interpretor&,
1677 Standard_Integer argc,
1682 std::cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<std::endl;
1685 TopoDS_Shape shape = DBRep::Get(argv[1]);
1689 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1691 Handle(TDocStd_Document) aD1 = new TDocStd_Document("BinXCAF");
1694 TCollection_AsciiString aViewName ("Driver1/DummyDocument/View1");
1695 ViewerTest::ViewerInit (aViewName);
1696 TPrsStd_AISViewer::New (aD1->GetData()->Root(), ViewerTest::GetAISContext());
1698 // get shape tool for shape verification
1699 Handle(XCAFDoc_ShapeTool) aShapes =
1700 XCAFDoc_DocumentTool::ShapeTool (aD1->Main());
1701 TDF_Label aLab = aShapes->AddShape(shape);
1703 Handle(Geom_Axis2Placement) aPlacement =
1704 new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX());
1705 Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement);
1707 Handle(TNaming_NamedShape) NS;
1708 Handle(TPrsStd_AISPresentation) prs;
1709 if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) {
1710 prs = TPrsStd_AISPresentation::Set( NS );
1713 if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) )
1716 TPrsStd_AISViewer::Update(aLab);
1717 ViewerTest::GetAISContext()->Display (aTriShape, Standard_True);
1720 ViewerTest::RemoveView (aViewName);
1725 //=======================================================================
1728 //=======================================================================
1730 void XDEDRAW::Init(Draw_Interpretor& di)
1732 static Standard_Boolean initactor = Standard_False;
1737 initactor = Standard_True;
1739 // Load static variables for STEPCAF (ssv; 16.08.2012)
1740 STEPCAFControl_Controller::Init();
1742 // Initialize XCAF formats
1743 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1744 BinXCAFDrivers::DefineFormat(anApp);
1745 XmlXCAFDrivers::DefineFormat(anApp);
1747 // Register driver in global table for displaying XDE documents
1748 // in 3d viewer using OCAF mechanics
1749 TPrsStd_DriverTable::Get()->AddDriver (XCAFPrs_Driver::GetID(), new XCAFPrs_Driver);
1751 //=====================================
1753 //=====================================
1755 Standard_CString g = "XDE general commands";
1757 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
1758 __FILE__, newDoc, g);
1760 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
1761 __FILE__, saveDoc, g);
1763 di.Add ("XOpen","Path Doc [-skipAttribute] [-readAttribute] [-readPath] [-append|-overwrite]\t: Open XDE Document with name Doc from Path"
1764 "\n\t\t The options are:"
1765 "\n\t\t -skipAttribute : class name of the attribute to skip during open, for example -skipTDF_Reference"
1766 "\n\t\t -readAttribute : class name of the attribute to read only during open, for example -readTDataStd_Name loads only such attributes"
1767 "\n\t\t -append : to read file into already existing document once again, append new attributes and don't touch existing"
1768 "\n\t\t -overwrite : to read file into already existing document once again, overwriting existing attributes",
1769 __FILE__, openDoc, g);
1771 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
1774 di.Add ("XStat","Doc \t: Print statistics of document",
1775 __FILE__, statdoc, g);
1777 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
1778 __FILE__, setPrs, g);
1780 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
1784 "XDisplay Doc [label1 [label2 [...]]] [-explore {on|off}] [-docPrefix {on|off}] [-names {on|off}]"
1785 "\n\t\t: [-noupdate] [-dispMode Mode] [-highMode Mode] [-autoTriangulation {0|1}]"
1786 "\n\t\t: Displays document (parts) in 3D Viewer."
1787 "\n\t\t: -dispMode Presentation display mode."
1788 "\n\t\t: -highMode Presentation highlight mode."
1789 "\n\t\t: -docPrefix Prepend document name to object names; TRUE by default."
1790 "\n\t\t: -names Use object names instead of label tag; TRUE by default."
1791 "\n\t\t: -explore Explode labels to leaves; FALSE by default."
1792 "\n\t\t: -outDispList Set the TCL variable to the list of displayed object names."
1793 "\n\t\t: (instead of printing them to draw interpreter)"
1794 "\n\t\t: -autoTriang Enable/disable auto-triangulation for displayed shapes.",
1795 __FILE__, XDEDRAW_XDisplayTool::XDisplay, g);
1797 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
1800 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
1801 __FILE__, XAttributeValue, g);
1803 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
1804 __FILE__, setviewName, g);
1806 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
1807 __FILE__, getviewName, g);
1809 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
1810 __FILE__, XSetTransparency, g);
1812 di.Add("XSetLengthUnit",
1813 "Doc {unit_name|scale_factor}\t: Set value of length unit"
1814 "\n\t\t: Possible unit_name: m, mm, km, cm, micron, mille, in(inch), min(microinch), nin(nano inch), ft, stat.mile"
1815 "\n\t\t: Possible scale factor: any real value more then 0. Factor to meter.",
1816 __FILE__, setLengthUnit, g);
1818 di.Add("XGetLengthUnit",
1819 "Doc [-scale]\t: Print name of length unit"
1820 "\n\t\t: -scale : print value of the scaling factor to meter of length unit",
1821 __FILE__, dumpLengthUnit, g);
1823 di.Add ("XShowFaceBoundary",
1824 "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
1825 "- turns on/off drawing of face boundaries and defines boundary line style",
1826 __FILE__, XShowFaceBoundary, g);
1827 di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g);
1829 di.Add("XDumpAssemblyTree",
1830 "Doc [-root label] [-level l] [-names]: Iterates through the assembly tree in depth up to the specified level, if any",
1831 __FILE__, XDumpAssemblyTree, g);
1832 di.Add("XDumpAssemblyGraph",
1833 "Doc [-root label] [-names]: Prints assembly graph structure",
1834 __FILE__, XDumpAssemblyGraph, g);
1835 di.Add("XDumpNomenclature",
1836 "Doc [-names]: Prints number of assembly instances",
1837 __FILE__, XDumpNomenclature, g);
1838 di.Add("XRescaleGeometry",
1839 "Doc factor [-root label] [-force]: Applies geometrical scale to assembly",
1840 __FILE__, XRescaleGeometry, g);
1842 // Specialized commands
1843 XDEDRAW_Shapes::InitCommands ( di );
1844 XDEDRAW_Colors::InitCommands ( di );
1845 XDEDRAW_Layers::InitCommands ( di );
1846 XDEDRAW_Props::InitCommands ( di );
1847 XDEDRAW_GDTs::InitCommands ( di );
1848 XDEDRAW_Views::InitCommands(di);
1849 XDEDRAW_Notes::InitCommands(di);
1850 XDEDRAW_Common::InitCommands ( di );//moved from EXE
1853 //==============================================================================
1855 //==============================================================================
1856 void XDEDRAW::Factory(Draw_Interpretor& theDI)
1858 XDEDRAW::Init(theDI);
1861 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded\n";
1865 // Declare entry point PLUGINFACTORY