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