0028367: Draw Harness - XSave should print an error on store failure
[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>
7fd59977 49#include <TDF_Data.hxx>
50#include <TDF_LabelSequence.hxx>
f767df4e 51#include <TDF_Reference.hxx>
42cf5bc1 52#include <TDF_Tool.hxx>
6fe96f84 53#include <TDocStd_Application.hxx>
7fd59977 54#include <TDocStd_Document.hxx>
42cf5bc1 55#include <TDocStd_Owner.hxx>
7fd59977 56#include <TNaming_NamedShape.hxx>
42cf5bc1 57#include <TopoDS_Shape.hxx>
7fd59977 58#include <TPrsStd_AISPresentation.hxx>
7fd59977 59#include <TPrsStd_AISViewer.hxx>
6fe96f84 60#include <TPrsStd_DriverTable.hxx>
42cf5bc1 61#include <TPrsStd_NamedShapeDriver.hxx>
62#include <V3d_View.hxx>
63#include <V3d_Viewer.hxx>
64#include <ViewerTest.hxx>
7fd59977 65#include <XCAFDoc.hxx>
7fd59977 66#include <XCAFDoc_Area.hxx>
67#include <XCAFDoc_Centroid.hxx>
42cf5bc1 68#include <XCAFDoc_Color.hxx>
7fd59977 69#include <XCAFDoc_ColorTool.hxx>
42cf5bc1 70#include <XCAFDoc_DimTol.hxx>
9ebaae37 71#include <XCAFDoc_Dimension.hxx>
72#include <XCAFDoc_Datum.hxx>
73#include <XCAFDoc_GeomTolerance.hxx>
7fd59977 74#include <XCAFDoc_DocumentTool.hxx>
75#include <XCAFDoc_GraphNode.hxx>
76#include <XCAFDoc_LayerTool.hxx>
7fd59977 77#include <XCAFDoc_Material.hxx>
42cf5bc1 78#include <XCAFDoc_ShapeTool.hxx>
79#include <XCAFDoc_Volume.hxx>
80#include <XCAFPrs.hxx>
7fd59977 81#include <XCAFPrs_Driver.hxx>
42cf5bc1 82#include <XDEDRAW.hxx>
7fd59977 83#include <XDEDRAW_Colors.hxx>
42cf5bc1 84#include <XDEDRAW_Common.hxx>
7fd59977 85#include <XDEDRAW_Layers.hxx>
86#include <XDEDRAW_Props.hxx>
42cf5bc1 87#include <XDEDRAW_Shapes.hxx>
9ebaae37 88#include <XDEDRAW_GDTs.hxx>
42cf5bc1 89#include <XSDRAW.hxx>
7fd59977 90#include <XSDRAWIGES.hxx>
91#include <XSDRAWSTEP.hxx>
a2d5ab2e 92
6fe96f84 93#include <BinXCAFDrivers.hxx>
94#include <XmlXCAFDrivers.hxx>
95
42cf5bc1 96#include <stdio.h>
7fd59977 97
98//=======================================================================
99// Section: General commands
100//=======================================================================
101
102//=======================================================================
103//function : newDoc
104//purpose :
105//=======================================================================
106static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
107{
586db386 108 if (argc < 2) {di<<"Give document name\n";return 1;}
7fd59977 109
110 Handle(TDocStd_Document) D;
111 Handle(DDocStd_DrawDocument) DD;
6fe96f84 112 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 113
114 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
fff263bd 115 A->NewDocument( "BinXCAF" ,D);
7fd59977 116 DD = new DDocStd_DrawDocument(D);
117 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
118 Draw::Set(argv[1],DD);
586db386 119 di << "document " << argv[1] << " created\n";
7fd59977 120 //DDocStd::ReturnLabel(di,D->Main());
121 }
586db386 122 else di << argv[1] << " is already a document\n";
7fd59977 123
124 return 0;
125}
126
127
128//=======================================================================
129//function : saveDoc
130//purpose :
131//=======================================================================
132static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
133{
134 Handle(TDocStd_Document) D;
6fe96f84 135 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 136
137 if (argc == 1) {
138 if (A->NbDocuments() < 1) return 1;
139 A->GetDocument(1, D);
140 }
141 else {
142 if (!DDocStd::GetDocument(argv[1],D)) return 1;
143 }
144
61887a4a 145 PCDM_StoreStatus aStatus = PCDM_SS_Doc_IsNull;
146 if (argc == 3)
147 {
7fd59977 148 TCollection_ExtendedString path (argv[2]);
61887a4a 149 aStatus = A->SaveAs (D, path);
7fd59977 150 }
61887a4a 151 else if (!D->IsSaved())
152 {
153 std::cout << "Storage error: this document has never been saved\n";
7fd59977 154 return 1;
155 }
61887a4a 156 else
157 {
158 aStatus = A->Save(D);
159 }
160
161 switch (aStatus)
162 {
163 case PCDM_SS_OK:
164 break;
165 case PCDM_SS_DriverFailure:
166 di << "Storage error: driver failure\n";
167 break;
168 case PCDM_SS_WriteFailure:
169 di << "Storage error: write failure\n";
170 break;
171 case PCDM_SS_Failure:
172 di << "Storage error: general failure\n";
173 break;
174 case PCDM_SS_Doc_IsNull:
175 di << "Storage error: document is NULL\n";
176 break;
177 case PCDM_SS_No_Obj:
178 di << "Storage error: no object\n";
179 break;
180 case PCDM_SS_Info_Section_Error:
181 di << "Storage error: section error\n";
182 break;
183 }
184
7fd59977 185 return 0;
186}
187
02a0b964 188//=======================================================================
189//function : openDoc
190//purpose :
191//=======================================================================
192static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
193{
194 Handle(TDocStd_Document) D;
195 Handle(DDocStd_DrawDocument) DD;
6fe96f84 196 Handle(TDocStd_Application) A = DDocStd::GetApplication();
02a0b964 197
198 if ( argc != 3 )
199 {
586db386 200 di << "invalid number of arguments. Usage:\t XOpen filename docname\n";
02a0b964 201 return 1;
202 }
203
204 Standard_CString Filename = argv[1];
205 Standard_CString DocName = argv[2];
206
207 if ( DDocStd::GetDocument(DocName, D, Standard_False) )
208 {
586db386 209 di << "document with name " << DocName << " already exists\n";
02a0b964 210 return 1;
211 }
212
213 if ( A->Open(Filename, D) != PCDM_RS_OK )
214 {
586db386 215 di << "cannot open XDE document\n";
02a0b964 216 return 1;
217 }
218
219 DD = new DDocStd_DrawDocument(D);
220 TDataStd_Name::Set(D->GetData()->Root(), DocName);
221 Draw::Set(DocName, DD);
222
586db386 223 di << "document " << DocName << " opened\n";
02a0b964 224
225 return 0;
226}
7fd59977 227
228//=======================================================================
229//function : dump
230//purpose :
231//=======================================================================
232static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
233{
234 if (argc<2) {
586db386 235 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]\n";
7fd59977 236 return 1;
237 }
238 Handle(TDocStd_Document) Doc;
239 DDocStd::GetDocument(argv[1], Doc);
586db386 240 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 241
242 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
243 Standard_Boolean deep = Standard_False;
91322f44 244 if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True;
0cc44c47 245 Standard_SStream aDumpLog;
246 myAssembly->Dump(aDumpLog, deep);
247 di<<aDumpLog;
7fd59977 248 return 0;
249}
250
251
252//=======================================================================
253//function : StatAssembly
254//purpose : recursive part of statistics
255//=======================================================================
256
257static void StatAssembly(const TDF_Label L,
258 const Standard_Integer level,
259 Handle(TColStd_HArray1OfInteger) &HAI,
260 Standard_Integer &NbCentroidProp,
261 Standard_Integer &NbVolumeProp,
262 Standard_Integer &NbAreaProp,
263 Standard_Integer &NbShapesWithName,
264 Standard_Integer &NbShapesWithColor,
265 Standard_Integer &NbShapesWithLayer,
266 Handle(TDocStd_Document) &aDoc,
267 Standard_Boolean &PrintStructMode,
268 Draw_Interpretor& di)
269{
270 if(PrintStructMode) {
271 for(Standard_Integer j=0; j<=level; j++)
272 di<<" ";
273 }
274 TCollection_AsciiString Entry;
275 TDF_Tool::Entry(L, Entry);
276 if(PrintStructMode) di<<Entry.ToCString();
277
278 Handle(TDataStd_Name) Name;
279 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
280 NbShapesWithName++;
281 if(PrintStructMode) {
282 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
283 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
284 }
285 }
286 else {
287 if(PrintStructMode) di<<" NoName has attributes: ";
288 }
289
290 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
291 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
292 if(PrintStructMode) di<<"Centroid ";
293 NbCentroidProp++;
294 }
295 Standard_Real tmp;
296 if(XCAFDoc_Volume::Get(L,tmp)) {
297 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
298 NbVolumeProp++;
299 }
300 if(XCAFDoc_Area::Get(L,tmp)) {
301 if(PrintStructMode) di<<"Area("<<tmp<<") ";
302 NbAreaProp++;
303 }
304 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
305 Quantity_Color col;
306 Standard_Boolean IsColor = Standard_False;
307 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
308 IsColor = Standard_True;
309 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
310 IsColor = Standard_True;
311 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
312 IsColor = Standard_True;
313 if(IsColor) {
314 TCollection_AsciiString Entry1;
315 Entry1 = col.StringName(col.Name());
316 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
317 NbShapesWithColor++;
318 }
319 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
320 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
321 LTool->GetLayers(L, aLayerS);
322 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
323 if(PrintStructMode) {
324 di<<"Layer(";
325 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
326 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
327 if(i==1)
328 di<<"\""<<Entry2.ToCString()<<"\"";
329 else
586db386 330 di<<" \""<<Entry2.ToCString()<<"\"";
7fd59977 331 }
332 di<<") ";
333 }
334 NbShapesWithLayer++;
335 }
336 if(PrintStructMode) di<<"\n";
337
338 HAI->SetValue(level, HAI->Value(level)+1 );
339 if(L.HasChild()) {
340 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
341 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
342 NbAreaProp, NbShapesWithName, NbShapesWithColor,
343 NbShapesWithLayer, aDoc, PrintStructMode, di);
344 }
345 }
346
347}
348
349
350//=======================================================================
351//function : statdoc
352//purpose :
353//=======================================================================
354static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
355{
356 if (argc<2) {
586db386 357 di<<"Use: "<<argv[0]<<" Doc \n";
7fd59977 358 return 1;
359 }
360 Handle(TDocStd_Document) Doc;
361 DDocStd::GetDocument(argv[1], Doc);
586db386 362 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 363
364 Standard_Boolean PrintStructMode = (argc==3);
365 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
366
367 TDF_LabelSequence SeqLabels;
368 aTool->GetShapes(SeqLabels);
369 if(SeqLabels.Length()<=0) return 0;
586db386 370 if(PrintStructMode) di<<"\nStructure of shapes in the document:\n";
7fd59977 371 Standard_Integer level=0;
372 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
373 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
374 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
375 Standard_Integer i=0;
376 for(i=0; i<=20; i++) HAI->SetValue(i,0);
377 for(i=1; i<=SeqLabels.Length(); i++) {
378 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
379 NbAreaProp, NbShapesWithName, NbShapesWithColor,
380 NbShapesWithLayer, Doc, PrintStructMode, di);
381 }
382 Standard_Integer NbLabelsShape = 0;
586db386 383 di<<"\nStatistis of shapes in the document:\n";
7fd59977 384 for(i=0; i<=20; i++) {
385 if(HAI->Value(i)==0) break;
386 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
387 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
388 NbLabelsShape = NbLabelsShape + HAI->Value(i);
389 }
390 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
391 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
392 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
393 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
394
586db386 395 di<<"\nStatistis of Props in the document:\n";
7fd59977 396 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
397 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
398 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
399
400 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
401 TDF_LabelSequence CLabels;
402 CTool->GetColors(CLabels);
586db386 403 di<<"\nNumber of colors = "<<CLabels.Length()<<"\n";
7fd59977 404 if(CLabels.Length()>0) {
405 for(i=1; i<=CLabels.Length(); i++) {
406 TDF_Label aLabel = CLabels.Value(i);
407 Quantity_Color col;
408 CTool->GetColor(aLabel, col);
409 di<<col.StringName(col.Name())<<" ";
410 }
411 di<<"\n";
412 }
413
414 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
415 TDF_LabelSequence LLabels;
416 LTool->GetLayerLabels(LLabels);
586db386 417 di<<"\nNumber of layers = "<<LLabels.Length()<<"\n";
7fd59977 418 if(LLabels.Length()>0) {
419 for(i=1; i<=LLabels.Length(); i++) {
420 TDF_Label aLabel = LLabels.Value(i);
421 TCollection_ExtendedString layerName;
422 LTool->GetLayer(aLabel, layerName);
423 TCollection_AsciiString Entry(layerName,'?');
424 di<<"\""<<Entry.ToCString() <<"\" ";
425 }
426 di<<"\n";
427 }
428
429 di<<"\n";
430 return 0;
431}
432
433
434//=======================================================================
435//function : setPrs
436//purpose :
437//=======================================================================
438static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
439{
440 if (argc <2) {
586db386 441 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
7fd59977 442 return 1;
443 }
444
445 Handle(TDocStd_Document) Doc;
446 DDocStd::GetDocument(argv[1], Doc);
586db386 447 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 448
449 // collect sequence of labels to set presentation
450 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
451 TDF_LabelSequence seq;
452 if ( argc >2 ) {
453 for ( Standard_Integer i=2; i < argc; i++ ) {
454 TDF_Label aLabel;
455 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
456 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
457 di << argv[i] << " is not a valid shape label!";
458 continue;
459 }
460 seq.Append ( aLabel );
461 }
462 }
463 else {
464 shapes->GetShapes ( seq );
465 }
466
467 // set presentations
468 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
469 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
470 Handle(TPrsStd_AISPresentation) prs;
471 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
472 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
473 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
474 }
475// Quantity_Color Col;
476// if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
477// prs->SetColor ( Col.Name() );
478// else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
479// prs->SetColor ( Col.Name() );
480 }
481 return 0;
482}
483
484
485//=======================================================================
486//function : show
487//purpose :
488//=======================================================================
489static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
490{
491 if (argc <2) {
586db386 492 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] \n";
7fd59977 493 return 1;
494 }
495
0e93d9e5 496 Handle(TDocStd_Document) aDoc;
497 DDocStd::GetDocument (argv[1], aDoc);
498 if (aDoc.IsNull())
499 {
500 std::cout << argv[1] << " is not a document\n";
501 return 1;
502 }
7fd59977 503
504 // init viewer
0e93d9e5 505 TDF_Label aRoot = aDoc->GetData()->Root();
506 Handle(TPrsStd_AISViewer) aDocViewer;
507 TCollection_AsciiString aViewName = TCollection_AsciiString ("Driver1/Document_") + argv[1] + "/View1";
508 if (!TPrsStd_AISViewer::Find (aRoot, aDocViewer))
509 {
510 ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), "");
511 aDocViewer = TPrsStd_AISViewer::New (aRoot, ViewerTest::GetAISContext());
512 }
7fd59977 513
7fd59977 514 // collect sequence of labels to display
0e93d9e5 515 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
7fd59977 516 TDF_LabelSequence seq;
517 if ( argc >2 ) {
518 for ( Standard_Integer i=2; i < argc; i++ ) {
519 TDF_Label aLabel;
0e93d9e5 520 TDF_Tool::Label (aDoc->GetData(), argv[i], aLabel);
7fd59977 521 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
522 di << argv[i] << " is not a valid shape label!";
523 continue;
524 }
525 seq.Append ( aLabel );
526 }
527 }
528 else {
529 shapes->GetFreeShapes ( seq );
530 }
531
532 // set presentations and show
533 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
534 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
535 Handle(TPrsStd_AISPresentation) prs;
536 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
537 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
538 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
539 }
540// Quantity_Color Col;
541// if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
542// prs->SetColor ( Col.Name() );
543// else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
544// prs->SetColor ( Col.Name() );
545 prs->Display(Standard_True);
546 }
0e93d9e5 547 TPrsStd_AISViewer::Update (aDoc->GetData()->Root());
7fd59977 548 return 0;
549}
550
551
552//=======================================================================
553//function : xwd
554//purpose :
555//=======================================================================
556static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
557{
558 if (argc <3) {
586db386 559 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}\n";
7fd59977 560 return 1;
561 }
562
563 Handle(TDocStd_Document) Doc;
564 DDocStd::GetDocument(argv[1], Doc);
586db386 565 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 566
567 Handle(AIS_InteractiveContext) IC;
568 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
569 di << "Cannot find viewer for document " << argv[1] << "\n";
570 return 1;
571 }
572
6a24c6de 573 Handle(V3d_Viewer) aViewer = IC->CurrentViewer();
574 V3d_ListOfViewIterator aViewIter = aViewer->ActiveViewIterator();
575 if (aViewIter.More())
576 {
577 aViewIter.Value()->Dump ( argv[2] );
7fd59977 578 }
579 else {
580 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
581 return 1;
582 }
583
584 return 0;
585}
586
587
588//=======================================================================
589//function : XAttributeValue
590//purpose :
591//=======================================================================
592static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
593{
586db386 594 if ( argc <4 ) { di << "ERROR: Too few args\n"; return 0; }
7fd59977 595 Handle(DDF_Browser) browser =
596 Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
597 if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
598
599 TDF_Label lab;
600 TDF_Tool::Label(browser->Data(),argv[2],lab);
601 if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
602
91322f44 603 Standard_Integer num = Draw::Atoi ( argv[3] );
7fd59977 604 TDF_AttributeIterator itr(lab,Standard_False);
605 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
606
586db386 607 if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found\n"; return 0; }
7fd59977 608
609 const Handle(TDF_Attribute)& att = itr.Value();
610 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
f767df4e 611 Standard_CString type = "";
7fd59977 612 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
613 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
614 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
615 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
616 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
617 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
618 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
7fd59977 619 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
620 TCollection_AsciiString ref;
621 if ( TN->HasFather() ) {
622 TDF_Tool::Entry ( TN->Father()->Label(), ref );
623 di << type << " ==> " << ref.ToCString();
624 }
625 else {
626 di << type << " <== (" << ref.ToCString();
627 Handle(TDataStd_TreeNode) child = TN->First();
628 while ( ! child.IsNull() ) {
f767df4e 629 TDF_Tool::Entry ( child->Label(), ref );
630 if ( child != TN->First() ) di << ", ";
631 di << ref.ToCString();
632 child = child->Next();
7fd59977 633 }
634 di << ")";
635 }
636 }
f767df4e 637 else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
638 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
639 TCollection_AsciiString ref;
640 TDF_Tool::Entry ( val->Get(), ref );
641 di << "==> " << ref.ToCString();
642 }
7fd59977 643 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
644 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
645 TCollection_AsciiString str ( val->Get() );
646 di << str.ToCString();
647 }
648 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
649 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
650 TCollection_AsciiString str ( val->Get() );
651 di << str.ToCString();
652 }
f767df4e 653 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
654 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
655 TCollection_AsciiString str ( val->Get(), '?' );
7fd59977 656 di << str.ToCString();
657 }
f767df4e 658 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
659 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
660 TCollection_AsciiString str ( val->Get(), '?' );
7fd59977 661 di << str.ToCString();
662 }
f767df4e 663 else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
664 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
7fd59977 665 TCollection_AsciiString str ( val->Get(), '?' );
666 di << str.ToCString();
667 }
f767df4e 668 else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
669 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
670 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
671 if ( j > val->Lower() ) di << ", ";
672 TCollection_AsciiString str ( val->Value(j) );
673 di << str.ToCString();
674 }
675 }
7fd59977 676 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
677 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
678 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
679 if ( j > val->Lower() ) di << ", ";
680 TCollection_AsciiString str ( val->Value(j) );
681 di << str.ToCString();
682 }
683 }
f767df4e 684 else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
685 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
686 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
687 if ( j > val->Lower() ) di << ", ";
688 TCollection_AsciiString str ( val->Value(j) );
689 di << str.ToCString();
690 }
691 }
7fd59977 692 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
693 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
694 TopoDS_Shape S = val->Get();
695 di << S.TShape()->DynamicType()->Name();
696 if ( ! S.Location().IsIdentity() ) di << "(located)";
697 }
f767df4e 698 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
699 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
700 TCollection_AsciiString str ( val->Get() );
701 di << str.ToCString();
702 }
703 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
704 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
705 TCollection_AsciiString str ( val->Get() );
706 di << str.ToCString();
707 }
708 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
709 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
710 gp_Pnt myCentroid = val->Get();
711 di << "(" ;
712 di << myCentroid.X();
713 di <<" , ";
714 di << myCentroid.Y();
715 di <<" , ";
716 di << myCentroid.Z();
717 di << ")";
718 }
7fd59977 719 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
720 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
721 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
722 }
723 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
724 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
725 Quantity_Color C = val->GetColor();
726 char string[260];
91322f44 727 Sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
7fd59977 728 C.Red(), C.Green(), C.Blue() );
729 di << string;
730 }
731 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
732 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
733 Standard_Integer kind = val->GetKind();
734 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
735 if(kind<20) { //dimension
736 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
737 }
738 else {
739 switch(kind) {
740 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
741 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
742 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
743 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
744 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
745 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
746 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
747 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
748 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
749 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
750 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
751 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
752 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
753 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
754 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
755 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
756 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
757 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
758 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
759 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
760 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
761 }
762 }
763 }
764 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
765 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
766 Standard_Real dens = val->GetDensity();
767 Standard_CString dimdens = "g/cu sm";
768 if(dens==0)
769 di<<val->GetName()->ToCString();
770 else
771 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
772 }
773 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
774 Standard_CString type;
775 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
776 type = "Layer Instance Link";
777 }
778 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
779 type = "SHUO Instance Link";
780 }
781 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
782 type = "DatumToler Link";
783 }
1c9d3225 784 else if ( att->ID() == XCAFDoc::DimensionRefFirstGUID() ) {
785 type = "Dimension Link First";
786 }
787 else if ( att->ID() == XCAFDoc::DimensionRefSecondGUID() ) {
788 type = "Dimension Link Second";
789 }
790 else if ( att->ID() == XCAFDoc::GeomToleranceRefGUID() ){
791 type = "GeomTolerance Link";
9ebaae37 792 }
400af1bc 793 else if ( att->ID() == XCAFDoc::DatumRefGUID() ){
794 type = "Datum Link";
795 }
7fd59977 796 else return 0;
797
798 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
799 TCollection_AsciiString ref;
800 Standard_Integer ii = 1;
801 if (DETGN->NbFathers()!=0) {
802
803 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
804 di << type<< " ==> (" << ref.ToCString();
805 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
806 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
807 di << ", " << ref.ToCString();
808 }
809 di << ") ";
810 }
811 ii = 1;
812 if (DETGN->NbChildren()!=0) {
813 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
814 di << type<< " <== (" << ref.ToCString();
815 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
816 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
817 di << ", " << ref.ToCString();
818 }
819 di << ")";
820 }
821 }
822 return 0;
823}
824
825
826//=======================================================================
827//function : setviewName
828//purpose :
829//=======================================================================
830static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
831{
832 if (argc <2) {
586db386 833 di<<"Use: "<<argv[0]<<" (1/0)\n";
7fd59977 834 return 1;
835 }
836 Standard_Boolean mode = Standard_False;
91322f44 837 if (Draw::Atoi(argv[1]) == 1) mode = Standard_True;
7fd59977 838 XCAFPrs::SetViewNameMode(mode);
839 return 0;
840}
841
842
843//=======================================================================
844//function : getviewName
845//purpose : auxilary
846//=======================================================================
847
848static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
849{
586db386 850 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON\n";
851 else di << "Display names OFF\n";
7fd59977 852 return 0;
853}
854
855
856//=======================================================================
5cbef0fe
S
857//function : XSetTransparency
858//purpose :
859//=======================================================================
860static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
861{
862 if (argc < 3) {
586db386 863 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] \n";
5cbef0fe
S
864 return 1;
865 }
866
867 Handle(TDocStd_Document) Doc;
868 DDocStd::GetDocument(argv[1], Doc);
586db386 869 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
5cbef0fe 870
91322f44 871 const Standard_Real aTransparency = Draw::Atof(argv[2]);
5cbef0fe
S
872
873 // collect sequence of labels
874 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
875 TDF_LabelSequence seq;
876 if ( argc > 3 ) {
877 for ( Standard_Integer i=3; i < argc; i++ ) {
878 TDF_Label aLabel;
879 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
880 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
881 di << argv[i] << " is not a valid shape label!";
882 continue;
883 }
884 seq.Append ( aLabel );
885 }
886 }
887 else {
888 shapes->GetFreeShapes ( seq );
889 }
890
891 // find presentations and set transparency
892 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
893 Handle(TPrsStd_AISPresentation) prs;
894 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
895 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
896 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
897 }
898 prs->SetTransparency( aTransparency );
899 }
900 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
901 return 0;
902}
903
a2d5ab2e 904//=======================================================================
905//function : XShowFaceBoundary
906//purpose : Set face boundaries on/off
907//=======================================================================
908static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
909 Standard_Integer argc,
910 const char ** argv)
911{
912 if (( argc != 4 && argc < 7 ) || argc > 9)
913 {
914 di << "Usage :\n " << argv[0]
915 << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
916 << " Doc - is the document name. \n"
917 << " Label - is the shape label. \n"
918 << " IsOn - flag indicating whether the boundaries\n"
919 << " should be turned on or off (can be set\n"
920 << " to 0 (off) or 1 (on)).\n"
921 << " R, G, B - red, green and blue components of boundary\n"
922 << " color in range (0 - 255).\n"
923 << " (default is (0, 0, 0)\n"
924 << " LineWidth - line width\n"
925 << " (default is 1)\n"
926 << " LineStyle - line fill style :\n"
927 << " 0 - solid \n"
928 << " 1 - dashed \n"
929 << " 2 - dot \n"
930 << " 3 - dashdot\n"
931 << " (default is solid)";
932
933 return 1;
934 }
935
936 // get specified document
937 Handle(TDocStd_Document) aDoc;
938 DDocStd::GetDocument (argv[1], aDoc);
939 if (aDoc.IsNull())
940 {
586db386 941 di << argv[1] << " is not a document\n";
a2d5ab2e 942 return 1;
943 }
944
945 Handle(AIS_InteractiveContext) aContext;
946 if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext))
947 {
948 di << "Cannot find viewer for document " << argv[1] << "\n";
949 return 1;
950 }
951
952 // get shape tool for shape verification
953 Handle(XCAFDoc_ShapeTool) aShapes =
954 XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
955
956 // get label and validate that it is a shape label
957 TDF_Label aLabel;
958 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
959 if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
960 {
961 di << argv[2] << " is not a valid shape label!";
962 return 1;
963 }
964
965 // get presentation from label
966 Handle(TPrsStd_AISPresentation) aPrs;
967 if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
968 {
969 aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
970 }
971
972 Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
973 if (anInteractive.IsNull ())
974 {
975 di << "Can't set drawer attributes.\n"
976 "Interactive object for shape label doesn't exists.";
977 return 1;
978 }
979
980 // get drawer
6262338c 981 const Handle(Prs3d_Drawer)& aDrawer = anInteractive->Attributes ();
a2d5ab2e 982
983 // default attributes
984 Quantity_Parameter aRed = 0.0;
985 Quantity_Parameter aGreen = 0.0;
986 Quantity_Parameter aBlue = 0.0;
987 Standard_Real aWidth = 1.0;
988 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
989
990 // turn boundaries on/off
91322f44 991 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1);
a2d5ab2e 992 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
993
994 // set boundary color
995 if (argc >= 7)
996 {
997 // Text color
91322f44 998 aRed = Draw::Atof (argv[4])/255.;
999 aGreen = Draw::Atof (argv[5])/255.;
1000 aBlue = Draw::Atof (argv[6])/255.;
a2d5ab2e 1001 }
1002
1003 // set line width
1004 if (argc >= 8)
1005 {
91322f44 1006 aWidth = (Standard_Real)Draw::Atof (argv[7]);
a2d5ab2e 1007 }
1008
1009 // select appropriate line type
1010 if (argc == 9)
1011 {
3a4a3962 1012 if (!ViewerTest::ParseLineType (argv[8], aLineType))
a2d5ab2e 1013 {
3a4a3962 1014 std::cout << "Syntax error: unknown line type '" << argv[8] << "'\n";
a2d5ab2e 1015 }
1016 }
1017
1018 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
1019
1020 Handle(Prs3d_LineAspect) aBoundaryAspect =
1021 new Prs3d_LineAspect (aColor, aLineType, aWidth);
1022
1023 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
1024
0577ae8c 1025 aContext->Redisplay (anInteractive, Standard_True);
a2d5ab2e 1026
1027 return 0;
1028}
5cbef0fe
S
1029
1030//=======================================================================
da0e82aa 1031//function : testDoc
1032//purpose : Method to test destruction of document
1033//=======================================================================
498ce76b 1034static Standard_Integer testDoc (Draw_Interpretor&,
da0e82aa 1035 Standard_Integer argc,
1036 const char ** argv)
1037{
1038 if( argc < 2 )
1039 {
1040 cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<endl;
1041 return 1;
1042 }
1043 TopoDS_Shape shape = DBRep::Get(argv[1]);
1044 if( shape.IsNull())
1045 return 1;
1046
6fe96f84 1047 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
da0e82aa 1048
fff263bd 1049 Handle(TDocStd_Document) aD1 = new TDocStd_Document("BinXCAF");
6fe96f84 1050 aD1->Open(anApp);
da0e82aa 1051
0e93d9e5 1052 TCollection_AsciiString aViewName ("Driver1/DummyDocument/View1");
1053 ViewerTest::ViewerInit (0, 0, 0, 0, aViewName.ToCString(), "");
1054 TPrsStd_AISViewer::New (aD1->GetData()->Root(), ViewerTest::GetAISContext());
1055
da0e82aa 1056 // get shape tool for shape verification
1057 Handle(XCAFDoc_ShapeTool) aShapes =
1058 XCAFDoc_DocumentTool::ShapeTool (aD1->Main());
1059 TDF_Label aLab = aShapes->AddShape(shape);
1060
1061 Handle(Geom_Axis2Placement) aPlacement =
1062 new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX());
1063 Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement);
1064
1065 Handle(TNaming_NamedShape) NS;
1066 Handle(TPrsStd_AISPresentation) prs;
1067 if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) {
1068 prs = TPrsStd_AISPresentation::Set( NS );
1069 }
1070
1071 if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) )
1072 prs->Display();
da0e82aa 1073
1074 TPrsStd_AISViewer::Update(aLab);
0e93d9e5 1075 ViewerTest::GetAISContext()->Display (aTriShape, Standard_True);
d01cc61d 1076 aD1->BeforeClose();
da0e82aa 1077 aD1->Close();
0e93d9e5 1078 ViewerTest::RemoveView (aViewName);
da0e82aa 1079 return 0;
1080}
1081
1082
1083//=======================================================================
7fd59977 1084//function : Init
1085//purpose :
1086//=======================================================================
1087
1088void XDEDRAW::Init(Draw_Interpretor& di)
1089{
1090
1091 static Standard_Boolean initactor = Standard_False;
1092 if (initactor) return; initactor = Standard_True;
1093
02a0b964 1094 // Load static variables for STEPCAF (ssv; 16.08.2012)
1095 STEPCAFControl_Controller::Init();
1096
6fe96f84 1097 // Initialize XCAF formats
1098 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1099 BinXCAFDrivers::DefineFormat(anApp);
1100 XmlXCAFDrivers::DefineFormat(anApp);
7fd59977 1101
6fe96f84 1102 // Register driver in global table for displaying XDE documents
1103 // in 3d viewer using OCAF mechanics
1104 TPrsStd_DriverTable::Get()->AddDriver (XCAFPrs_Driver::GetID(), new XCAFPrs_Driver);
7fd59977 1105
1106 //=====================================
1107 // General commands
1108 //=====================================
1109
1110 Standard_CString g = "XDE general commands";
1111
1112 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
1113 __FILE__, newDoc, g);
1114
1115 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
1116 __FILE__, saveDoc, g);
1117
02a0b964 1118 di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path",
1119 __FILE__, openDoc, g);
1120
7fd59977 1121 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
1122 __FILE__, dump, g);
1123
1124 di.Add ("XStat","Doc \t: Print statistics of document",
1125 __FILE__, statdoc, g);
1126
1127 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
1128 __FILE__, setPrs, g);
1129
1130 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
1131 __FILE__, show, g);
1132
1133 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
1134 __FILE__, xwd, g);
1135
1136 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
1137 __FILE__, XAttributeValue, g);
1138
1139 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
1140 __FILE__, setviewName, g);
1141
1142 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
1143 __FILE__, getviewName, g);
1144
5cbef0fe
S
1145 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
1146 __FILE__, XSetTransparency, g);
1147
a2d5ab2e 1148 di.Add ("XShowFaceBoundary",
1149 "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
1150 "- turns on/off drawing of face boundaries and defines boundary line style",
1151 __FILE__, XShowFaceBoundary, g);
da0e82aa 1152 di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g);
a2d5ab2e 1153
7fd59977 1154 // Specialized commands
1155 XDEDRAW_Shapes::InitCommands ( di );
1156 XDEDRAW_Colors::InitCommands ( di );
1157 XDEDRAW_Layers::InitCommands ( di );
1158 XDEDRAW_Props::InitCommands ( di );
9ebaae37 1159 XDEDRAW_GDTs::InitCommands ( di );
7fd59977 1160 XDEDRAW_Common::InitCommands ( di );//moved from EXE
1161
1162}
1163
1164
1165//==============================================================================
1166// XDEDRAW::Factory
1167//==============================================================================
1168void XDEDRAW::Factory(Draw_Interpretor& theDI)
1169{
1170 XSDRAWIGES::InitSelect();
1171 XSDRAWIGES::InitToBRep(theDI);
1172 XSDRAWIGES::InitFromBRep(theDI);
1173
1174 XSDRAWSTEP::InitCommands(theDI);
1175
7fd59977 1176 XSDRAW::LoadDraw(theDI);
1177
1178 XDEDRAW::Init(theDI);
1179
0797d9d3 1180#ifdef OCCT_DEBUG
586db386 1181 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded\n";
7fd59977 1182#endif
1183}
1184
1185// Declare entry point PLUGINFACTORY
1186DPLUGIN(XDEDRAW)