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