0030690: Draw Harness - provide XDisplay command for displaying XDE document
[occt.git] / src / XDEDRAW / XDEDRAW.cxx
CommitLineData
b311480e 1// Created on: 2000-08-04
2// Created by: Pavel TELKOV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
7fd59977 17#include <AIS_InteractiveContext.hxx>
42cf5bc1 18#include <AIS_InteractiveObject.hxx>
19#include <AIS_Trihedron.hxx>
20#include <Aspect_TypeOfLine.hxx>
21#include <DBRep.hxx>
7fd59977 22#include <DDF_Browser.hxx>
23#include <DDocStd.hxx>
24#include <DDocStd_DrawDocument.hxx>
42cf5bc1 25#include <Draw.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>
02a0b964 31#include <STEPCAFControl_Controller.hxx>
42cf5bc1 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>
ab1f4580 49#include <TDF_ChildIterator.hxx>
7fd59977 50#include <TDF_Data.hxx>
51#include <TDF_LabelSequence.hxx>
f767df4e 52#include <TDF_Reference.hxx>
42cf5bc1 53#include <TDF_Tool.hxx>
6fe96f84 54#include <TDocStd_Application.hxx>
7fd59977 55#include <TDocStd_Document.hxx>
42cf5bc1 56#include <TDocStd_Owner.hxx>
7fd59977 57#include <TNaming_NamedShape.hxx>
42cf5bc1 58#include <TopoDS_Shape.hxx>
7fd59977 59#include <TPrsStd_AISPresentation.hxx>
7fd59977 60#include <TPrsStd_AISViewer.hxx>
6fe96f84 61#include <TPrsStd_DriverTable.hxx>
42cf5bc1 62#include <TPrsStd_NamedShapeDriver.hxx>
63#include <V3d_View.hxx>
64#include <V3d_Viewer.hxx>
65#include <ViewerTest.hxx>
ab1f4580 66#include <ViewerTest_AutoUpdater.hxx>
7fd59977 67#include <XCAFDoc.hxx>
7fd59977 68#include <XCAFDoc_Area.hxx>
69#include <XCAFDoc_Centroid.hxx>
42cf5bc1 70#include <XCAFDoc_Color.hxx>
7fd59977 71#include <XCAFDoc_ColorTool.hxx>
42cf5bc1 72#include <XCAFDoc_DimTol.hxx>
9ebaae37 73#include <XCAFDoc_Dimension.hxx>
74#include <XCAFDoc_Datum.hxx>
75#include <XCAFDoc_GeomTolerance.hxx>
7fd59977 76#include <XCAFDoc_DocumentTool.hxx>
77#include <XCAFDoc_GraphNode.hxx>
78#include <XCAFDoc_LayerTool.hxx>
7fd59977 79#include <XCAFDoc_Material.hxx>
42cf5bc1 80#include <XCAFDoc_ShapeTool.hxx>
81#include <XCAFDoc_Volume.hxx>
82#include <XCAFPrs.hxx>
ab1f4580 83#include <XCAFPrs_AISObject.hxx>
7fd59977 84#include <XCAFPrs_Driver.hxx>
42cf5bc1 85#include <XDEDRAW.hxx>
7fd59977 86#include <XDEDRAW_Colors.hxx>
42cf5bc1 87#include <XDEDRAW_Common.hxx>
7fd59977 88#include <XDEDRAW_Layers.hxx>
89#include <XDEDRAW_Props.hxx>
42cf5bc1 90#include <XDEDRAW_Shapes.hxx>
9ebaae37 91#include <XDEDRAW_GDTs.hxx>
2df785d7 92#include <XDEDRAW_Views.hxx>
024d6f77 93#include <XDEDRAW_Notes.hxx>
42cf5bc1 94#include <XSDRAW.hxx>
7fd59977 95#include <XSDRAWIGES.hxx>
96#include <XSDRAWSTEP.hxx>
a2d5ab2e 97
6fe96f84 98#include <BinXCAFDrivers.hxx>
99#include <XmlXCAFDrivers.hxx>
100
42cf5bc1 101#include <stdio.h>
7fd59977 102
103//=======================================================================
104// Section: General commands
105//=======================================================================
106
107//=======================================================================
108//function : newDoc
109//purpose :
110//=======================================================================
111static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
112{
586db386 113 if (argc < 2) {di<<"Give document name\n";return 1;}
7fd59977 114
115 Handle(TDocStd_Document) D;
116 Handle(DDocStd_DrawDocument) DD;
6fe96f84 117 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 118
119 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
fff263bd 120 A->NewDocument( "BinXCAF" ,D);
7fd59977 121 DD = new DDocStd_DrawDocument(D);
122 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
123 Draw::Set(argv[1],DD);
586db386 124 di << "document " << argv[1] << " created\n";
7fd59977 125 //DDocStd::ReturnLabel(di,D->Main());
126 }
586db386 127 else di << argv[1] << " is already a document\n";
7fd59977 128
129 return 0;
130}
131
132
133//=======================================================================
134//function : saveDoc
135//purpose :
136//=======================================================================
137static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
138{
139 Handle(TDocStd_Document) D;
6fe96f84 140 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 141
142 if (argc == 1) {
143 if (A->NbDocuments() < 1) return 1;
144 A->GetDocument(1, D);
145 }
146 else {
147 if (!DDocStd::GetDocument(argv[1],D)) return 1;
148 }
149
61887a4a 150 PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull;
151 if (argc == 3)
152 {
7fd59977 153 TCollection_ExtendedString path (argv[2]);
61887a4a 154 aStatus = A->SaveAs (D, path);
7fd59977 155 }
61887a4a 156 else if (!D->IsSaved())
157 {
158 std::cout << "Storage error: this document has never been saved\n";
7fd59977 159 return 1;
160 }
61887a4a 161 else
162 {
163 aStatus = A->Save(D);
164 }
165
166 switch (aStatus)
167 {
168 case PCDM_SS_OK:
169 break;
170 case PCDM_SS_DriverFailure:
171 di << "Storage error: driver failure\n";
172 break;
173 case PCDM_SS_WriteFailure:
174 di << "Storage error: write failure\n";
175 break;
176 case PCDM_SS_Failure:
177 di << "Storage error: general failure\n";
178 break;
179 case PCDM_SS_Doc_IsNull:
180 di << "Storage error: document is NULL\n";
181 break;
182 case PCDM_SS_No_Obj:
183 di << "Storage error: no object\n";
184 break;
185 case PCDM_SS_Info_Section_Error:
186 di << "Storage error: section error\n";
187 break;
188 }
189
7fd59977 190 return 0;
191}
192
02a0b964 193//=======================================================================
194//function : openDoc
195//purpose :
196//=======================================================================
197static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
198{
199 Handle(TDocStd_Document) D;
200 Handle(DDocStd_DrawDocument) DD;
6fe96f84 201 Handle(TDocStd_Application) A = DDocStd::GetApplication();
02a0b964 202
203 if ( argc != 3 )
204 {
586db386 205 di << "invalid number of arguments. Usage:\t XOpen filename docname\n";
02a0b964 206 return 1;
207 }
208
209 Standard_CString Filename = argv[1];
210 Standard_CString DocName = argv[2];
211
212 if ( DDocStd::GetDocument(DocName, D, Standard_False) )
213 {
586db386 214 di << "document with name " << DocName << " already exists\n";
02a0b964 215 return 1;
216 }
217
218 if ( A->Open(Filename, D) != PCDM_RS_OK )
219 {
586db386 220 di << "cannot open XDE document\n";
02a0b964 221 return 1;
222 }
223
224 DD = new DDocStd_DrawDocument(D);
225 TDataStd_Name::Set(D->GetData()->Root(), DocName);
226 Draw::Set(DocName, DD);
227
586db386 228 di << "document " << DocName << " opened\n";
02a0b964 229
230 return 0;
231}
7fd59977 232
233//=======================================================================
234//function : dump
235//purpose :
236//=======================================================================
237static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
238{
239 if (argc<2) {
586db386 240 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]\n";
7fd59977 241 return 1;
242 }
243 Handle(TDocStd_Document) Doc;
244 DDocStd::GetDocument(argv[1], Doc);
586db386 245 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 246
247 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
248 Standard_Boolean deep = Standard_False;
91322f44 249 if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True;
0cc44c47 250 Standard_SStream aDumpLog;
251 myAssembly->Dump(aDumpLog, deep);
252 di<<aDumpLog;
7fd59977 253 return 0;
254}
255
256
257//=======================================================================
258//function : StatAssembly
259//purpose : recursive part of statistics
260//=======================================================================
261
262static void StatAssembly(const TDF_Label L,
263 const Standard_Integer level,
264 Handle(TColStd_HArray1OfInteger) &HAI,
265 Standard_Integer &NbCentroidProp,
266 Standard_Integer &NbVolumeProp,
267 Standard_Integer &NbAreaProp,
268 Standard_Integer &NbShapesWithName,
269 Standard_Integer &NbShapesWithColor,
270 Standard_Integer &NbShapesWithLayer,
271 Handle(TDocStd_Document) &aDoc,
272 Standard_Boolean &PrintStructMode,
273 Draw_Interpretor& di)
274{
275 if(PrintStructMode) {
276 for(Standard_Integer j=0; j<=level; j++)
277 di<<" ";
278 }
279 TCollection_AsciiString Entry;
280 TDF_Tool::Entry(L, Entry);
281 if(PrintStructMode) di<<Entry.ToCString();
282
283 Handle(TDataStd_Name) Name;
284 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
285 NbShapesWithName++;
286 if(PrintStructMode) {
287 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
288 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
289 }
290 }
291 else {
292 if(PrintStructMode) di<<" NoName has attributes: ";
293 }
294
295 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
296 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
297 if(PrintStructMode) di<<"Centroid ";
298 NbCentroidProp++;
299 }
300 Standard_Real tmp;
301 if(XCAFDoc_Volume::Get(L,tmp)) {
302 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
303 NbVolumeProp++;
304 }
305 if(XCAFDoc_Area::Get(L,tmp)) {
306 if(PrintStructMode) di<<"Area("<<tmp<<") ";
307 NbAreaProp++;
308 }
309 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
08b183fe 310 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
973d410e 311 Quantity_ColorRGBA col;
7fd59977 312 Standard_Boolean IsColor = Standard_False;
08b183fe 313 Standard_Boolean IsByLayer = Standard_False;
7fd59977 314 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
315 IsColor = Standard_True;
316 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
317 IsColor = Standard_True;
318 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
319 IsColor = Standard_True;
08b183fe 320 else if(CTool->IsColorByLayer(L))
321 IsByLayer = Standard_True;
322 if(IsColor || IsByLayer) {
323 if(IsByLayer)
324 {
325 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
326 LTool->GetLayers(L, aLayerS);
327 // Currently for DXF pnly, thus
328 // only 1 Layer should be.
329 if(aLayerS->Length() == 1)
330 {
331 TDF_Label aLayer = LTool->FindLayer (aLayerS->First());
332 Quantity_ColorRGBA aColor;
333 if (CTool->GetColor (aLayer, XCAFDoc_ColorGen, aColor))
334 {
335 TCollection_AsciiString aColorName = aColor.GetRGB().StringName(aColor.GetRGB().Name());
336 di<<"Color(" << aColorName.ToCString() << ") ";
337 }
338 else
339 {
340 di<<"Color(ByLayer) ";
341 }
342 }
343 NbShapesWithColor++;
344 }
345 else
346 {
347 TCollection_AsciiString Entry1;
348 Entry1 = col.GetRGB().StringName(col.GetRGB().Name());
349 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<" "<<col.Alpha()<<") ";
350 NbShapesWithColor++;
351 }
7fd59977 352 }
7fd59977 353 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
354 LTool->GetLayers(L, aLayerS);
355 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
356 if(PrintStructMode) {
357 di<<"Layer(";
358 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
359 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
360 if(i==1)
361 di<<"\""<<Entry2.ToCString()<<"\"";
362 else
586db386 363 di<<" \""<<Entry2.ToCString()<<"\"";
7fd59977 364 }
365 di<<") ";
366 }
367 NbShapesWithLayer++;
368 }
369 if(PrintStructMode) di<<"\n";
370
371 HAI->SetValue(level, HAI->Value(level)+1 );
372 if(L.HasChild()) {
373 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
374 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
375 NbAreaProp, NbShapesWithName, NbShapesWithColor,
376 NbShapesWithLayer, aDoc, PrintStructMode, di);
377 }
378 }
379
380}
381
382
383//=======================================================================
384//function : statdoc
385//purpose :
386//=======================================================================
387static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
388{
389 if (argc<2) {
586db386 390 di<<"Use: "<<argv[0]<<" Doc \n";
7fd59977 391 return 1;
392 }
393 Handle(TDocStd_Document) Doc;
394 DDocStd::GetDocument(argv[1], Doc);
586db386 395 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 396
397 Standard_Boolean PrintStructMode = (argc==3);
398 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
399
400 TDF_LabelSequence SeqLabels;
401 aTool->GetShapes(SeqLabels);
402 if(SeqLabels.Length()<=0) return 0;
586db386 403 if(PrintStructMode) di<<"\nStructure of shapes in the document:\n";
7fd59977 404 Standard_Integer level=0;
405 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
406 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
407 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
408 Standard_Integer i=0;
409 for(i=0; i<=20; i++) HAI->SetValue(i,0);
410 for(i=1; i<=SeqLabels.Length(); i++) {
411 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
412 NbAreaProp, NbShapesWithName, NbShapesWithColor,
413 NbShapesWithLayer, Doc, PrintStructMode, di);
414 }
415 Standard_Integer NbLabelsShape = 0;
586db386 416 di<<"\nStatistis of shapes in the document:\n";
7fd59977 417 for(i=0; i<=20; i++) {
418 if(HAI->Value(i)==0) break;
419 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
420 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
421 NbLabelsShape = NbLabelsShape + HAI->Value(i);
422 }
423 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
424 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
425 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
426 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
427
586db386 428 di<<"\nStatistis of Props in the document:\n";
7fd59977 429 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
430 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
431 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
432
433 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
434 TDF_LabelSequence CLabels;
435 CTool->GetColors(CLabels);
586db386 436 di<<"\nNumber of colors = "<<CLabels.Length()<<"\n";
7fd59977 437 if(CLabels.Length()>0) {
438 for(i=1; i<=CLabels.Length(); i++) {
439 TDF_Label aLabel = CLabels.Value(i);
440 Quantity_Color col;
441 CTool->GetColor(aLabel, col);
442 di<<col.StringName(col.Name())<<" ";
443 }
444 di<<"\n";
445 }
446
447 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
448 TDF_LabelSequence LLabels;
449 LTool->GetLayerLabels(LLabels);
586db386 450 di<<"\nNumber of layers = "<<LLabels.Length()<<"\n";
7fd59977 451 if(LLabels.Length()>0) {
452 for(i=1; i<=LLabels.Length(); i++) {
453 TDF_Label aLabel = LLabels.Value(i);
454 TCollection_ExtendedString layerName;
455 LTool->GetLayer(aLabel, layerName);
456 TCollection_AsciiString Entry(layerName,'?');
457 di<<"\""<<Entry.ToCString() <<"\" ";
458 }
459 di<<"\n";
460 }
461
462 di<<"\n";
463 return 0;
464}
465
466
467//=======================================================================
468//function : setPrs
469//purpose :
470//=======================================================================
471static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
472{
473 if (argc <2) {
586db386 474 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
7fd59977 475 return 1;
476 }
477
478 Handle(TDocStd_Document) Doc;
479 DDocStd::GetDocument(argv[1], Doc);
586db386 480 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 481
482 // collect sequence of labels to set presentation
483 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
484 TDF_LabelSequence seq;
485 if ( argc >2 ) {
486 for ( Standard_Integer i=2; i < argc; i++ ) {
487 TDF_Label aLabel;
488 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
489 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
490 di << argv[i] << " is not a valid shape label!";
491 continue;
492 }
493 seq.Append ( aLabel );
494 }
495 }
496 else {
497 shapes->GetShapes ( seq );
498 }
499
500 // set presentations
501 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
502 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
503 Handle(TPrsStd_AISPresentation) prs;
504 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
505 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
506 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
507 }
508// Quantity_Color Col;
509// if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
510// prs->SetColor ( Col.Name() );
511// else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
512// prs->SetColor ( Col.Name() );
513 }
514 return 0;
515}
516
517
518//=======================================================================
519//function : show
520//purpose :
521//=======================================================================
522static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
523{
524 if (argc <2) {
586db386 525 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
7fd59977 526 return 1;
527 }
528
0e93d9e5 529 Handle(TDocStd_Document) aDoc;
530 DDocStd::GetDocument (argv[1], aDoc);
531 if (aDoc.IsNull())
532 {
533 std::cout << argv[1] << " is not a document\n";
534 return 1;
535 }
7fd59977 536
537 // init viewer
0e93d9e5 538 TDF_Label aRoot = aDoc->GetData()->Root();
539 Handle(TPrsStd_AISViewer) aDocViewer;
540 TCollection_AsciiString aViewName = TCollection_AsciiString ("Driver1/Document_") + argv[1] + "/View1";
541 if (!TPrsStd_AISViewer::Find (aRoot, aDocViewer))
542 {
543 ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), "");
544 aDocViewer = TPrsStd_AISViewer::New (aRoot, ViewerTest::GetAISContext());
545 }
7fd59977 546
7fd59977 547 // collect sequence of labels to display
0e93d9e5 548 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
7fd59977 549 TDF_LabelSequence seq;
550 if ( argc >2 ) {
551 for ( Standard_Integer i=2; i < argc; i++ ) {
552 TDF_Label aLabel;
0e93d9e5 553 TDF_Tool::Label (aDoc->GetData(), argv[i], aLabel);
7fd59977 554 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
555 di << argv[i] << " is not a valid shape label!";
556 continue;
557 }
558 seq.Append ( aLabel );
559 }
560 }
561 else {
562 shapes->GetFreeShapes ( seq );
563 }
564
565 // set presentations and show
566 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
567 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
568 Handle(TPrsStd_AISPresentation) prs;
569 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
570 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
571 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
572 }
573// Quantity_Color Col;
574// if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
575// prs->SetColor ( Col.Name() );
576// else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
577// prs->SetColor ( Col.Name() );
578 prs->Display(Standard_True);
579 }
0e93d9e5 580 TPrsStd_AISViewer::Update (aDoc->GetData()->Root());
7fd59977 581 return 0;
582}
583
ab1f4580 584//! XDisplay command implementation.
585class XDEDRAW_XDisplayTool
586{
587public:
588 //! XDisplay command interface.
589 static Standard_Integer XDisplay (Draw_Interpretor& theDI,
590 Standard_Integer theNbArgs,
591 const char** theArgVec)
592 {
593 XDEDRAW_XDisplayTool aTool;
594 return aTool.xdisplay (theDI, theNbArgs, theArgVec);
595 }
596
597private:
598 //! Constructor.
599 XDEDRAW_XDisplayTool()
600 : myDispMode(-2),
601 myHiMode (-2),
602 myToPrefixDocName (Standard_True),
603 myToGetNames (Standard_True),
604 myToExplore (Standard_False) {}
605
606 //! Display single label.
607 Standard_Integer displayLabel (Draw_Interpretor& theDI,
608 const TDF_Label& theLabel,
609 const TCollection_AsciiString& theNamePrefix,
610 const TopLoc_Location& theLoc)
611 {
612 TCollection_AsciiString aName;
613 if (myToGetNames)
614 {
615 Handle(TDataStd_Name) aNodeName;
616 if (theLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
617 {
618 aName = aNodeName->Get();
619 }
620 if (aName.IsEmpty())
621 {
622 TDF_Label aRefLabel;
623 if (XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel)
624 && aRefLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
625 {
626 aName = aNodeName->Get();
627 }
628 }
629
630 if (aName.IsEmpty())
631 {
632 TDF_Tool::Entry (theLabel, aName);
633 }
634 for (Standard_Integer aNameIndex = 1;; ++aNameIndex)
635 {
636 if (myNameMap.Add (aName))
637 {
638 break;
639 }
640 aName = aNodeName->Get() + "_" + aNameIndex;
641 }
642 }
643 else
644 {
645 TDF_Tool::Entry (theLabel, aName);
646 }
647 aName = theNamePrefix + aName;
648
649 if (myToExplore)
650 {
651 TDF_Label aRefLabel = theLabel;
652 XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel);
653 if (XCAFDoc_ShapeTool::IsAssembly (aRefLabel))
654 {
655 aName += "/";
656 const TopLoc_Location aLoc = theLoc * XCAFDoc_ShapeTool::GetLocation (theLabel);
657 for (TDF_ChildIterator aChildIter (aRefLabel); aChildIter.More(); aChildIter.Next())
658 {
659 if (displayLabel (theDI, aChildIter.Value(), aName, aLoc) == 1)
660 {
661 return 1;
662 }
663 }
664 return 0;
665 }
666 }
667
668 Handle(XCAFPrs_AISObject) aPrs = new XCAFPrs_AISObject (theLabel);
669 if (!theLoc.IsIdentity())
670 {
671 aPrs->SetLocalTransformation (theLoc);
672 }
673 if (myDispMode != -2)
674 {
675 if (myDispMode == -1)
676 {
677 aPrs->UnsetDisplayMode();
678 }
679 if (!aPrs->AcceptDisplayMode (myDispMode))
680 {
681 std::cout << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myDispMode << " display mode\n";
682 return 1;
683 }
684 else
685 {
686 aPrs->SetDisplayMode (myDispMode);
687 }
688 }
689 if (myHiMode != -2)
690 {
691 if (myHiMode != -1
692 && !aPrs->AcceptDisplayMode (myHiMode))
693 {
694 std::cout << "Syntax error: " << aPrs->DynamicType()->Name() << " rejects " << myHiMode << " display mode\n";
695 return 1;
696 }
697 aPrs->SetHilightMode (myHiMode);
698 }
699
700 ViewerTest::Display (aName, aPrs, false);
701 theDI << aName << " ";
702 return 0;
703 }
704
705 //! XDisplay command implementation.
706 Standard_Integer xdisplay (Draw_Interpretor& theDI,
707 Standard_Integer theNbArgs,
708 const char** theArgVec)
709 {
710 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
711 if (aContext.IsNull())
712 {
713 std::cout << "Error: no active view!\n";
714 return 1;
715 }
716
717 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
718 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
719 {
720 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
721 anArgCase.LowerCase();
722 if (anAutoUpdater.parseRedrawMode (anArgCase))
723 {
724 continue;
725 }
726 else if (anArgIter + 1 < theNbArgs
727 && myDispMode == -2
728 && (anArgCase == "-dispmode"
729 || anArgCase == "-displaymode")
730 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
731 {
732 myDispMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue();
733 }
734 else if (anArgIter + 1 < theNbArgs
735 && myHiMode == -2
736 && (anArgCase == "-himode"
737 || anArgCase == "-highmode"
738 || anArgCase == "-highlightmode")
739 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
740 {
741 myHiMode = TCollection_AsciiString (theArgVec[++anArgIter]).IntegerValue();
742 }
743 else if (anArgCase == "-docprefix"
744 || anArgCase == "-nodocprefix")
745 {
746 myToPrefixDocName = Standard_True;
747 if (anArgIter + 1 < theNbArgs
748 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToPrefixDocName))
749 {
750 ++anArgIter;
751 }
752 if (anArgCase.StartsWith ("-no"))
753 {
754 myToPrefixDocName = !myToPrefixDocName;
755 }
756 }
757 else if (anArgCase == "-names"
758 || anArgCase == "-nonames")
759 {
760 myToGetNames = Standard_True;
761 if (anArgIter + 1 < theNbArgs
762 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToGetNames))
763 {
764 ++anArgIter;
765 }
766 if (anArgCase.StartsWith ("-no"))
767 {
768 myToGetNames = !myToGetNames;
769 }
770 }
771 else if (anArgCase == "-explore"
772 || anArgCase == "-noexplore")
773 {
774 myToExplore = Standard_True;
775 if (anArgIter + 1 < theNbArgs
776 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], myToExplore))
777 {
778 ++anArgIter;
779 }
780 if (anArgCase.StartsWith ("-no"))
781 {
782 myToExplore = !myToExplore;
783 }
784 }
785 else
786 {
787 if (myDoc.IsNull()
788 && DDocStd::GetDocument (theArgVec[anArgIter], myDoc, Standard_False))
789 {
790 myDocName = theArgVec[anArgIter];
791 continue;
792 }
793
794 TCollection_AsciiString aValue (theArgVec[anArgIter]);
795 const Standard_Integer aFirstSplit = aValue.Search (":");
796 if (!IsDigit (aValue.Value (1))
797 && aFirstSplit >= 2
798 && aFirstSplit < aValue.Length())
799 {
800 TCollection_AsciiString aDocName = aValue.SubString (1, aFirstSplit - 1);
801 Standard_CString aDocNameStr = aDocName.ToCString();
802 Handle(TDocStd_Document) aDoc;
803 if (DDocStd::GetDocument (aDocNameStr, aDoc, Standard_False))
804 {
805 aValue = aValue.SubString (aFirstSplit + 1, aValue.Length());
806 if (!myDoc.IsNull()
807 && myDoc != aDoc)
808 {
809 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
810 return 1;
811 }
812 myDoc = aDoc;
813 myDocName = aDocName;
814 }
815 }
816 if (myDoc.IsNull())
817 {
818 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
819 return 1;
820 }
821
822 TDF_Label aLabel;
823 TDF_Tool::Label (myDoc->GetData(), aValue.ToCString(), aLabel);
824 if (aLabel.IsNull()
825 || !XCAFDoc_ShapeTool::IsShape (aLabel))
826 {
827 std::cout << "Syntax error: " << aValue << " is not a valid shape label\n";
828 return 1;
829 }
830 myLabels.Append (aLabel);
831 }
832 }
833 if (myDoc.IsNull())
834 {
835 std::cout << "Syntax error: not enough arguments\n";
836 return 1;
837 }
838 if (myLabels.IsEmpty())
839 {
840 XCAFDoc_DocumentTool::ShapeTool (myDoc->Main())->GetFreeShapes (myLabels);
841 }
842
843 for (TDF_LabelSequence::Iterator aLabIter (myLabels); aLabIter.More(); aLabIter.Next())
844 {
845 const TDF_Label& aLabel = aLabIter.Value();
846 if (displayLabel (theDI, aLabel, myToPrefixDocName ? myDocName + ":" : "", TopLoc_Location()) == 1)
847 {
848 return 1;
849 }
850 }
851 return 0;
852 }
853
854private:
855 NCollection_Map<TCollection_AsciiString, TCollection_AsciiString>
856 myNameMap; //!< names map to handle collisions
857 Handle(TDocStd_Document) myDoc; //!< document
858 TCollection_AsciiString myDocName; //!< document name
859 TDF_LabelSequence myLabels; //!< labels to display
860 Standard_Integer myDispMode; //!< shape display mode
861 Standard_Integer myHiMode; //!< shape highlight mode
862 Standard_Boolean myToPrefixDocName; //!< flag to prefix objects with document name
863 Standard_Boolean myToGetNames; //!< flag to use label names or tags
864 Standard_Boolean myToExplore; //!< flag to explore assembles
865};
7fd59977 866
867//=======================================================================
868//function : xwd
869//purpose :
870//=======================================================================
871static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
872{
873 if (argc <3) {
586db386 874 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}\n";
7fd59977 875 return 1;
876 }
877
878 Handle(TDocStd_Document) Doc;
879 DDocStd::GetDocument(argv[1], Doc);
586db386 880 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 881
882 Handle(AIS_InteractiveContext) IC;
883 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
884 di << "Cannot find viewer for document " << argv[1] << "\n";
885 return 1;
886 }
887
6a24c6de 888 Handle(V3d_Viewer) aViewer = IC->CurrentViewer();
889 V3d_ListOfViewIterator aViewIter = aViewer->ActiveViewIterator();
890 if (aViewIter.More())
891 {
892 aViewIter.Value()->Dump ( argv[2] );
7fd59977 893 }
894 else {
895 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
896 return 1;
897 }
898
899 return 0;
900}
901
902
903//=======================================================================
904//function : XAttributeValue
905//purpose :
906//=======================================================================
907static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
908{
1c8fc6be 909 if ( argc < 4 ) { std::cout << "Syntax error: Too few args\n"; return 1; }
910 Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (argv[1]));
911 if ( browser.IsNull() ) { std::cout << "Syntax error: Not a browser: " << argv[1] << "\n"; return 1; }
7fd59977 912
913 TDF_Label lab;
914 TDF_Tool::Label(browser->Data(),argv[2],lab);
1c8fc6be 915 if ( lab.IsNull() ) { std::cout << "Syntax error: label is Null: " << argv[2] << "\n"; return 1; }
7fd59977 916
91322f44 917 Standard_Integer num = Draw::Atoi ( argv[3] );
7fd59977 918 TDF_AttributeIterator itr(lab,Standard_False);
919 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
920
1c8fc6be 921 if ( ! itr.More() ) { std::cout << "Syntax error: Attribute #" << num << " not found\n"; return 1; }
7fd59977 922
923 const Handle(TDF_Attribute)& att = itr.Value();
924 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
f767df4e 925 Standard_CString type = "";
7fd59977 926 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
927 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
928 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
929 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
930 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
931 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
932 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
7fd59977 933 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
934 TCollection_AsciiString ref;
935 if ( TN->HasFather() ) {
936 TDF_Tool::Entry ( TN->Father()->Label(), ref );
937 di << type << " ==> " << ref.ToCString();
938 }
939 else {
940 di << type << " <== (" << ref.ToCString();
941 Handle(TDataStd_TreeNode) child = TN->First();
942 while ( ! child.IsNull() ) {
f767df4e 943 TDF_Tool::Entry ( child->Label(), ref );
944 if ( child != TN->First() ) di << ", ";
945 di << ref.ToCString();
946 child = child->Next();
7fd59977 947 }
948 di << ")";
949 }
950 }
f767df4e 951 else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
952 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
953 TCollection_AsciiString ref;
954 TDF_Tool::Entry ( val->Get(), ref );
955 di << "==> " << ref.ToCString();
956 }
7fd59977 957 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
958 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
959 TCollection_AsciiString str ( val->Get() );
960 di << str.ToCString();
961 }
962 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
963 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
964 TCollection_AsciiString str ( val->Get() );
965 di << str.ToCString();
966 }
f767df4e 967 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
968 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
969 TCollection_AsciiString str ( val->Get(), '?' );
7fd59977 970 di << str.ToCString();
971 }
f767df4e 972 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
973 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
974 TCollection_AsciiString str ( val->Get(), '?' );
7fd59977 975 di << str.ToCString();
976 }
f767df4e 977 else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
978 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
7fd59977 979 TCollection_AsciiString str ( val->Get(), '?' );
980 di << str.ToCString();
981 }
f767df4e 982 else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
983 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
984 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
985 if ( j > val->Lower() ) di << ", ";
986 TCollection_AsciiString str ( val->Value(j) );
987 di << str.ToCString();
988 }
989 }
7fd59977 990 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
991 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
992 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
993 if ( j > val->Lower() ) di << ", ";
994 TCollection_AsciiString str ( val->Value(j) );
995 di << str.ToCString();
996 }
997 }
f767df4e 998 else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
999 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
1000 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
1001 if ( j > val->Lower() ) di << ", ";
1002 TCollection_AsciiString str ( val->Value(j) );
1003 di << str.ToCString();
1004 }
1005 }
7fd59977 1006 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
1007 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
1008 TopoDS_Shape S = val->Get();
1009 di << S.TShape()->DynamicType()->Name();
1010 if ( ! S.Location().IsIdentity() ) di << "(located)";
1011 }
f767df4e 1012 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
1013 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
1014 TCollection_AsciiString str ( val->Get() );
1015 di << str.ToCString();
1016 }
1017 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
1018 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
1019 TCollection_AsciiString str ( val->Get() );
1020 di << str.ToCString();
1021 }
1022 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
1023 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
1024 gp_Pnt myCentroid = val->Get();
1025 di << "(" ;
1026 di << myCentroid.X();
1027 di <<" , ";
1028 di << myCentroid.Y();
1029 di <<" , ";
1030 di << myCentroid.Z();
1031 di << ")";
1032 }
7fd59977 1033 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
1034 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
1035 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
1036 }
1037 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
1038 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
973d410e 1039 Quantity_ColorRGBA C = val->GetColorRGBA();
7fd59977 1040 char string[260];
973d410e 1041 Sprintf ( string, "%s (%g, %g, %g, %g)", C.GetRGB().StringName ( C.GetRGB().Name() ),
1042 C.GetRGB().Red(), C.GetRGB().Green(), C.GetRGB().Blue(), C.Alpha());
7fd59977 1043 di << string;
1044 }
1045 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
1046 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
1047 Standard_Integer kind = val->GetKind();
1048 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
1049 if(kind<20) { //dimension
1050 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
1051 }
1052 else {
1053 switch(kind) {
1054 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
1055 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
1056 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
1057 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
1058 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
1059 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
1060 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
1061 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
1062 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
1063 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
1064 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
1065 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
1066 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
1067 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
1068 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
1069 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
1070 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
1071 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
1072 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
1073 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
1074 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
1075 }
1076 }
1077 }
1078 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
1079 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
1080 Standard_Real dens = val->GetDensity();
1081 Standard_CString dimdens = "g/cu sm";
1082 if(dens==0)
1083 di<<val->GetName()->ToCString();
1084 else
1085 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
1086 }
1087 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
1088 Standard_CString type;
1089 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
1090 type = "Layer Instance Link";
1091 }
1092 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
1093 type = "SHUO Instance Link";
1094 }
1095 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
1096 type = "DatumToler Link";
1097 }
1c9d3225 1098 else if ( att->ID() == XCAFDoc::DimensionRefFirstGUID() ) {
1099 type = "Dimension Link First";
1100 }
1101 else if ( att->ID() == XCAFDoc::DimensionRefSecondGUID() ) {
1102 type = "Dimension Link Second";
1103 }
1104 else if ( att->ID() == XCAFDoc::GeomToleranceRefGUID() ){
1105 type = "GeomTolerance Link";
9ebaae37 1106 }
400af1bc 1107 else if ( att->ID() == XCAFDoc::DatumRefGUID() ){
1108 type = "Datum Link";
1109 }
2df785d7 1110 else if (att->ID() == XCAFDoc::ViewRefShapeGUID()){
1111 type = "View Shape Link";
1112 }
1113 else if (att->ID() == XCAFDoc::ViewRefGDTGUID()){
1114 type = "View GD&T Link";
1115 }
0c63f2f8 1116 else if (att->ID() == XCAFDoc::ViewRefPlaneGUID()) {
1117 type = "View Clipping Plane Link";
1118 }
7fd59977 1119 else return 0;
1120
1121 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
1122 TCollection_AsciiString ref;
1123 Standard_Integer ii = 1;
1124 if (DETGN->NbFathers()!=0) {
1125
1126 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
1127 di << type<< " ==> (" << ref.ToCString();
1128 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
1129 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
1130 di << ", " << ref.ToCString();
1131 }
1132 di << ") ";
1133 }
1134 ii = 1;
1135 if (DETGN->NbChildren()!=0) {
1136 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
1137 di << type<< " <== (" << ref.ToCString();
1138 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
1139 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
1140 di << ", " << ref.ToCString();
1141 }
1142 di << ")";
1143 }
1144 }
1145 return 0;
1146}
1147
1148
1149//=======================================================================
1150//function : setviewName
1151//purpose :
1152//=======================================================================
1153static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1154{
1155 if (argc <2) {
586db386 1156 di<<"Use: "<<argv[0]<<" (1/0)\n";
7fd59977 1157 return 1;
1158 }
1159 Standard_Boolean mode = Standard_False;
91322f44 1160 if (Draw::Atoi(argv[1]) == 1) mode = Standard_True;
7fd59977 1161 XCAFPrs::SetViewNameMode(mode);
1162 return 0;
1163}
1164
1165
1166//=======================================================================
1167//function : getviewName
1168//purpose : auxilary
1169//=======================================================================
1170
1171static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
1172{
586db386 1173 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON\n";
1174 else di << "Display names OFF\n";
7fd59977 1175 return 0;
1176}
1177
1178
5cbef0fe
S
1179//=======================================================================
1180//function : XSetTransparency
1181//purpose :
1182//=======================================================================
1183static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1184{
1185 if (argc < 3) {
586db386 1186 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] \n";
5cbef0fe
S
1187 return 1;
1188 }
1189
1190 Handle(TDocStd_Document) Doc;
1191 DDocStd::GetDocument(argv[1], Doc);
586db386 1192 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
5cbef0fe 1193
91322f44 1194 const Standard_Real aTransparency = Draw::Atof(argv[2]);
5cbef0fe
S
1195
1196 // collect sequence of labels
1197 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1198 TDF_LabelSequence seq;
1199 if ( argc > 3 ) {
1200 for ( Standard_Integer i=3; i < argc; i++ ) {
1201 TDF_Label aLabel;
1202 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
1203 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
1204 di << argv[i] << " is not a valid shape label!";
1205 continue;
1206 }
1207 seq.Append ( aLabel );
1208 }
1209 }
1210 else {
1211 shapes->GetFreeShapes ( seq );
1212 }
1213
1214 // find presentations and set transparency
1215 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
1216 Handle(TPrsStd_AISPresentation) prs;
1217 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
1218 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
1219 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
1220 }
1221 prs->SetTransparency( aTransparency );
1222 }
1223 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
1224 return 0;
1225}
1226
a2d5ab2e 1227//=======================================================================
1228//function : XShowFaceBoundary
1229//purpose : Set face boundaries on/off
1230//=======================================================================
1231static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
1232 Standard_Integer argc,
1233 const char ** argv)
1234{
1235 if (( argc != 4 && argc < 7 ) || argc > 9)
1236 {
1237 di << "Usage :\n " << argv[0]
1238 << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
1239 << " Doc - is the document name. \n"
1240 << " Label - is the shape label. \n"
1241 << " IsOn - flag indicating whether the boundaries\n"
1242 << " should be turned on or off (can be set\n"
1243 << " to 0 (off) or 1 (on)).\n"
1244 << " R, G, B - red, green and blue components of boundary\n"
1245 << " color in range (0 - 255).\n"
1246 << " (default is (0, 0, 0)\n"
1247 << " LineWidth - line width\n"
1248 << " (default is 1)\n"
1249 << " LineStyle - line fill style :\n"
1250 << " 0 - solid \n"
1251 << " 1 - dashed \n"
1252 << " 2 - dot \n"
1253 << " 3 - dashdot\n"
1254 << " (default is solid)";
1255
1256 return 1;
1257 }
1258
1259 // get specified document
1260 Handle(TDocStd_Document) aDoc;
1261 DDocStd::GetDocument (argv[1], aDoc);
1262 if (aDoc.IsNull())
1263 {
586db386 1264 di << argv[1] << " is not a document\n";
a2d5ab2e 1265 return 1;
1266 }
1267
1268 Handle(AIS_InteractiveContext) aContext;
1269 if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext))
1270 {
1271 di << "Cannot find viewer for document " << argv[1] << "\n";
1272 return 1;
1273 }
1274
1275 // get shape tool for shape verification
1276 Handle(XCAFDoc_ShapeTool) aShapes =
1277 XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
1278
1279 // get label and validate that it is a shape label
1280 TDF_Label aLabel;
1281 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
1282 if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
1283 {
1284 di << argv[2] << " is not a valid shape label!";
1285 return 1;
1286 }
1287
1288 // get presentation from label
1289 Handle(TPrsStd_AISPresentation) aPrs;
1290 if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
1291 {
1292 aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
1293 }
1294
1295 Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
1296 if (anInteractive.IsNull ())
1297 {
1298 di << "Can't set drawer attributes.\n"
1299 "Interactive object for shape label doesn't exists.";
1300 return 1;
1301 }
1302
1303 // get drawer
6262338c 1304 const Handle(Prs3d_Drawer)& aDrawer = anInteractive->Attributes ();
a2d5ab2e 1305
1306 // default attributes
ee2be2a8 1307 Standard_Real aRed = 0.0;
1308 Standard_Real aGreen = 0.0;
1309 Standard_Real aBlue = 0.0;
1310 Standard_Real aWidth = 1.0;
1311 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
a2d5ab2e 1312
1313 // turn boundaries on/off
91322f44 1314 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1);
a2d5ab2e 1315 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
1316
1317 // set boundary color
1318 if (argc >= 7)
1319 {
1320 // Text color
91322f44 1321 aRed = Draw::Atof (argv[4])/255.;
1322 aGreen = Draw::Atof (argv[5])/255.;
1323 aBlue = Draw::Atof (argv[6])/255.;
a2d5ab2e 1324 }
1325
1326 // set line width
1327 if (argc >= 8)
1328 {
91322f44 1329 aWidth = (Standard_Real)Draw::Atof (argv[7]);
a2d5ab2e 1330 }
1331
1332 // select appropriate line type
1333 if (argc == 9)
1334 {
3a4a3962 1335 if (!ViewerTest::ParseLineType (argv[8], aLineType))
a2d5ab2e 1336 {
3a4a3962 1337 std::cout << "Syntax error: unknown line type '" << argv[8] << "'\n";
a2d5ab2e 1338 }
1339 }
1340
1341 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
1342
1343 Handle(Prs3d_LineAspect) aBoundaryAspect =
1344 new Prs3d_LineAspect (aColor, aLineType, aWidth);
1345
1346 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
1347
0577ae8c 1348 aContext->Redisplay (anInteractive, Standard_True);
a2d5ab2e 1349
1350 return 0;
1351}
5cbef0fe 1352
da0e82aa 1353//=======================================================================
1354//function : testDoc
1355//purpose : Method to test destruction of document
1356//=======================================================================
498ce76b 1357static Standard_Integer testDoc (Draw_Interpretor&,
da0e82aa 1358 Standard_Integer argc,
1359 const char ** argv)
1360{
1361 if( argc < 2 )
1362 {
1363 cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<endl;
1364 return 1;
1365 }
1366 TopoDS_Shape shape = DBRep::Get(argv[1]);
1367 if( shape.IsNull())
1368 return 1;
1369
6fe96f84 1370 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
da0e82aa 1371
fff263bd 1372 Handle(TDocStd_Document) aD1 = new TDocStd_Document("BinXCAF");
6fe96f84 1373 aD1->Open(anApp);
da0e82aa 1374
0e93d9e5 1375 TCollection_AsciiString aViewName ("Driver1/DummyDocument/View1");
1376 ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), "");
1377 TPrsStd_AISViewer::New (aD1->GetData()->Root(), ViewerTest::GetAISContext());
1378
da0e82aa 1379 // get shape tool for shape verification
1380 Handle(XCAFDoc_ShapeTool) aShapes =
1381 XCAFDoc_DocumentTool::ShapeTool (aD1->Main());
1382 TDF_Label aLab = aShapes->AddShape(shape);
1383
1384 Handle(Geom_Axis2Placement) aPlacement =
1385 new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX());
1386 Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement);
1387
1388 Handle(TNaming_NamedShape) NS;
1389 Handle(TPrsStd_AISPresentation) prs;
1390 if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) {
1391 prs = TPrsStd_AISPresentation::Set( NS );
1392 }
1393
1394 if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) )
1395 prs->Display();
da0e82aa 1396
1397 TPrsStd_AISViewer::Update(aLab);
0e93d9e5 1398 ViewerTest::GetAISContext()->Display (aTriShape, Standard_True);
d01cc61d 1399 aD1->BeforeClose();
da0e82aa 1400 aD1->Close();
0e93d9e5 1401 ViewerTest::RemoveView (aViewName);
da0e82aa 1402 return 0;
1403}
1404
1405
7fd59977 1406//=======================================================================
1407//function : Init
1408//purpose :
1409//=======================================================================
1410
1411void XDEDRAW::Init(Draw_Interpretor& di)
1412{
7fd59977 1413 static Standard_Boolean initactor = Standard_False;
c48e2889 1414 if (initactor)
1415 {
1416 return;
1417 }
1418 initactor = Standard_True;
7fd59977 1419
02a0b964 1420 // Load static variables for STEPCAF (ssv; 16.08.2012)
1421 STEPCAFControl_Controller::Init();
1422
6fe96f84 1423 // Initialize XCAF formats
1424 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1425 BinXCAFDrivers::DefineFormat(anApp);
1426 XmlXCAFDrivers::DefineFormat(anApp);
7fd59977 1427
6fe96f84 1428 // Register driver in global table for displaying XDE documents
1429 // in 3d viewer using OCAF mechanics
1430 TPrsStd_DriverTable::Get()->AddDriver (XCAFPrs_Driver::GetID(), new XCAFPrs_Driver);
7fd59977 1431
1432 //=====================================
1433 // General commands
1434 //=====================================
1435
1436 Standard_CString g = "XDE general commands";
1437
1438 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
1439 __FILE__, newDoc, g);
1440
1441 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
1442 __FILE__, saveDoc, g);
1443
02a0b964 1444 di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path",
1445 __FILE__, openDoc, g);
1446
7fd59977 1447 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
1448 __FILE__, dump, g);
1449
1450 di.Add ("XStat","Doc \t: Print statistics of document",
1451 __FILE__, statdoc, g);
1452
1453 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
1454 __FILE__, setPrs, g);
1455
1456 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
1457 __FILE__, show, g);
1458
ab1f4580 1459 di.Add ("XDisplay",
1460 "XDisplay Doc [label1 [label2 [...]]] [-explore {on|off}] [-docPrefix {on|off}] [-names {on|off}]"
1461 "\n\t\t: [-noupdate] [-dispMode Mode] [-highMode Mode]"
1462 "\n\t\t: Displays document (parts) in 3D Viewer."
1463 "\n\t\t: -dispMode Presentation display mode."
1464 "\n\t\t: -highMode Presentation highlight mode."
1465 "\n\t\t: -docPrefix Prepend document name to object names; TRUE by default."
1466 "\n\t\t: -names Use object names instead of label tag; TRUE by default."
1467 "\n\t\t: -explore Explode labels to leaves; FALSE by default.",
1468 __FILE__, XDEDRAW_XDisplayTool::XDisplay, g);
1469
7fd59977 1470 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
1471 __FILE__, xwd, g);
1472
1473 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
1474 __FILE__, XAttributeValue, g);
1475
1476 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
1477 __FILE__, setviewName, g);
1478
1479 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
1480 __FILE__, getviewName, g);
1481
5cbef0fe
S
1482 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
1483 __FILE__, XSetTransparency, g);
1484
a2d5ab2e 1485 di.Add ("XShowFaceBoundary",
1486 "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
1487 "- turns on/off drawing of face boundaries and defines boundary line style",
1488 __FILE__, XShowFaceBoundary, g);
da0e82aa 1489 di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g);
a2d5ab2e 1490
7fd59977 1491 // Specialized commands
1492 XDEDRAW_Shapes::InitCommands ( di );
1493 XDEDRAW_Colors::InitCommands ( di );
1494 XDEDRAW_Layers::InitCommands ( di );
1495 XDEDRAW_Props::InitCommands ( di );
9ebaae37 1496 XDEDRAW_GDTs::InitCommands ( di );
2df785d7 1497 XDEDRAW_Views::InitCommands(di);
024d6f77 1498 XDEDRAW_Notes::InitCommands(di);
7fd59977 1499 XDEDRAW_Common::InitCommands ( di );//moved from EXE
1500
1501}
1502
1503
1504//==============================================================================
1505// XDEDRAW::Factory
1506//==============================================================================
1507void XDEDRAW::Factory(Draw_Interpretor& theDI)
1508{
1509 XSDRAWIGES::InitSelect();
1510 XSDRAWIGES::InitToBRep(theDI);
1511 XSDRAWIGES::InitFromBRep(theDI);
1512
1513 XSDRAWSTEP::InitCommands(theDI);
1514
7fd59977 1515 XSDRAW::LoadDraw(theDI);
1516
1517 XDEDRAW::Init(theDI);
1518
0797d9d3 1519#ifdef OCCT_DEBUG
586db386 1520 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded\n";
7fd59977 1521#endif
1522}
1523
1524// Declare entry point PLUGINFACTORY
1525DPLUGIN(XDEDRAW)