0022627: Change OCCT memory management defaults
[occt.git] / src / XDEDRAW / XDEDRAW.cxx
CommitLineData
7fd59977 1// File: XDEDRAW.cxx
2// Created: Fri Aug 4 14:38:55 2000
3// Author: Pavel TELKOV
7fd59977 4
5#include <XDEDRAW.ixx>
6#include <stdio.h>
7
8#include <TCollection_ExtendedString.hxx>
9#include <TCollection_AsciiString.hxx>
10#include <TColStd_HSequenceOfExtendedString.hxx>
11#include <TCollection_HAsciiString.hxx>
12#include <Quantity_Color.hxx>
13
14#include <TopoDS_Shape.hxx>
15
16#include <Draw.hxx>
17#include <DBRep.hxx>
18#include <V3d_Viewer.hxx>
19#include <V3d_View.hxx>
20#include <AIS_InteractiveContext.hxx>
21#include <ViewerTest_Tool.hxx>
22
23#include <DDF_Browser.hxx>
24#include <DDocStd.hxx>
25#include <DDocStd_DrawDocument.hxx>
26
27#include <TDF_Tool.hxx>
28#include <TDF_Data.hxx>
29#include <TDF_LabelSequence.hxx>
30#include <TDF_AttributeIterator.hxx>
f767df4e 31#include <TDF_Reference.hxx>
7fd59977 32#include <TDocStd_Document.hxx>
33#include <TDataStd_UAttribute.hxx>
34#include <TDataStd_TreeNode.hxx>
35#include <TDataStd_Integer.hxx>
36#include <TDataStd_Real.hxx>
37#include <TDataStd_Name.hxx>
f767df4e 38#include <TDataStd_Comment.hxx>
39#include <TDataStd_AsciiString.hxx>
7fd59977 40#include <TNaming_NamedShape.hxx>
f767df4e 41#include <TDataStd_IntegerArray.hxx>
7fd59977 42#include <TDataStd_RealArray.hxx>
f767df4e 43#include <TDataStd_ByteArray.hxx>
7fd59977 44#include <TPrsStd_AISPresentation.hxx>
45#include <TPrsStd_NamedShapeDriver.hxx>
46#include <TPrsStd_AISViewer.hxx>
47
48#include <XCAFDoc.hxx>
49#include <XCAFDoc_Color.hxx>
50#include <XCAFDoc_Volume.hxx>
51#include <XCAFDoc_Area.hxx>
52#include <XCAFDoc_Centroid.hxx>
53#include <XCAFDoc_ShapeTool.hxx>
54#include <XCAFDoc_ColorTool.hxx>
55#include <XCAFDoc_DocumentTool.hxx>
56#include <XCAFDoc_GraphNode.hxx>
57#include <XCAFDoc_LayerTool.hxx>
58#include <XCAFDoc_DimTol.hxx>
59#include <XCAFDoc_Material.hxx>
60#include <XCAFPrs_Driver.hxx>
61#include <XCAFApp_Application.hxx>
62
63#include <XDEDRAW_Shapes.hxx>
64#include <XDEDRAW_Colors.hxx>
65#include <XDEDRAW_Layers.hxx>
66#include <XDEDRAW_Props.hxx>
67#include <XDEDRAW_Common.hxx>
68#include <XSDRAWIGES.hxx>
69#include <XSDRAWSTEP.hxx>
70#include <SWDRAW.hxx>
71#include <XSDRAW.hxx>
72#include <XCAFPrs.hxx>
73#include <ViewerTest.hxx>
74#include <Draw_PluginMacro.hxx>
75
76#include <TColStd_HArray1OfInteger.hxx>
77#include <TColStd_HArray1OfReal.hxx>
78
79#define ZVIEW_SIZE 1000000.0
80// avoid warnings on 'extern "C"' functions returning C++ classes
81#ifdef WNT
82#pragma warning(4:4190)
83#endif
84
85//=======================================================================
86// Section: General commands
87//=======================================================================
88
89//=======================================================================
90//function : newDoc
91//purpose :
92//=======================================================================
93static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
94{
95 if (argc < 2) {di<<"Give document name"<<"\n";return 1;}
96
97 Handle(TDocStd_Document) D;
98 Handle(DDocStd_DrawDocument) DD;
99 Handle(TDocStd_Application) A;
100
101 if (!DDocStd::Find(A)) return 1;
102
103 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
104 A->NewDocument( "MDTV-XCAF" ,D);
105 DD = new DDocStd_DrawDocument(D);
106 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
107 Draw::Set(argv[1],DD);
108 di << "document " << argv[1] << " created" << "\n";
109 //DDocStd::ReturnLabel(di,D->Main());
110 }
111 else di << argv[1] << " is already a document" << "\n";
112
113 return 0;
114}
115
116
117//=======================================================================
118//function : saveDoc
119//purpose :
120//=======================================================================
121static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
122{
123 Handle(TDocStd_Document) D;
124 Handle(TDocStd_Application) A;
125 if (!DDocStd::Find(A)) return 1;
126
127 if (argc == 1) {
128 if (A->NbDocuments() < 1) return 1;
129 A->GetDocument(1, D);
130 }
131 else {
132 if (!DDocStd::GetDocument(argv[1],D)) return 1;
133 }
134
135 if (argc == 3 ) {
136 TCollection_ExtendedString path (argv[2]);
137 A->SaveAs(D,path);
138 return 0;
139 }
140 if (!D->IsSaved()) {
141 di << "this document has never been saved" << "\n";
142 return 1;
143 }
144 A->Save(D);
145 return 0;
146}
147
148
149//=======================================================================
150//function : dump
151//purpose :
152//=======================================================================
153static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
154{
155 if (argc<2) {
156 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n";
157 return 1;
158 }
159 Handle(TDocStd_Document) Doc;
160 DDocStd::GetDocument(argv[1], Doc);
161 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
162
163 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
164 Standard_Boolean deep = Standard_False;
165 if ( (argc==3) && (atoi(argv[2])==1) ) deep = Standard_True;
166 myAssembly->Dump(deep);
167 return 0;
168}
169
170
171//=======================================================================
172//function : StatAssembly
173//purpose : recursive part of statistics
174//=======================================================================
175
176static void StatAssembly(const TDF_Label L,
177 const Standard_Integer level,
178 Handle(TColStd_HArray1OfInteger) &HAI,
179 Standard_Integer &NbCentroidProp,
180 Standard_Integer &NbVolumeProp,
181 Standard_Integer &NbAreaProp,
182 Standard_Integer &NbShapesWithName,
183 Standard_Integer &NbShapesWithColor,
184 Standard_Integer &NbShapesWithLayer,
185 Handle(TDocStd_Document) &aDoc,
186 Standard_Boolean &PrintStructMode,
187 Draw_Interpretor& di)
188{
189 if(PrintStructMode) {
190 for(Standard_Integer j=0; j<=level; j++)
191 di<<" ";
192 }
193 TCollection_AsciiString Entry;
194 TDF_Tool::Entry(L, Entry);
195 if(PrintStructMode) di<<Entry.ToCString();
196
197 Handle(TDataStd_Name) Name;
198 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
199 NbShapesWithName++;
200 if(PrintStructMode) {
201 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
202 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
203 }
204 }
205 else {
206 if(PrintStructMode) di<<" NoName has attributes: ";
207 }
208
209 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
210 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
211 if(PrintStructMode) di<<"Centroid ";
212 NbCentroidProp++;
213 }
214 Standard_Real tmp;
215 if(XCAFDoc_Volume::Get(L,tmp)) {
216 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
217 NbVolumeProp++;
218 }
219 if(XCAFDoc_Area::Get(L,tmp)) {
220 if(PrintStructMode) di<<"Area("<<tmp<<") ";
221 NbAreaProp++;
222 }
223 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
224 Quantity_Color col;
225 Standard_Boolean IsColor = Standard_False;
226 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
227 IsColor = Standard_True;
228 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
229 IsColor = Standard_True;
230 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
231 IsColor = Standard_True;
232 if(IsColor) {
233 TCollection_AsciiString Entry1;
234 Entry1 = col.StringName(col.Name());
235 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
236 NbShapesWithColor++;
237 }
238 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
239 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
240 LTool->GetLayers(L, aLayerS);
241 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
242 if(PrintStructMode) {
243 di<<"Layer(";
244 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
245 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
246 if(i==1)
247 di<<"\""<<Entry2.ToCString()<<"\"";
248 else
249 di<<" "<<"\""<<Entry2.ToCString()<<"\"";
250 }
251 di<<") ";
252 }
253 NbShapesWithLayer++;
254 }
255 if(PrintStructMode) di<<"\n";
256
257 HAI->SetValue(level, HAI->Value(level)+1 );
258 if(L.HasChild()) {
259 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
260 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
261 NbAreaProp, NbShapesWithName, NbShapesWithColor,
262 NbShapesWithLayer, aDoc, PrintStructMode, di);
263 }
264 }
265
266}
267
268
269//=======================================================================
270//function : statdoc
271//purpose :
272//=======================================================================
273static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
274{
275 if (argc<2) {
276 di<<"Use: "<<argv[0]<<" Doc "<<"\n";
277 return 1;
278 }
279 Handle(TDocStd_Document) Doc;
280 DDocStd::GetDocument(argv[1], Doc);
281 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
282
283 Standard_Boolean PrintStructMode = (argc==3);
284 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
285
286 TDF_LabelSequence SeqLabels;
287 aTool->GetShapes(SeqLabels);
288 if(SeqLabels.Length()<=0) return 0;
289 if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n";
290 Standard_Integer level=0;
291 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
292 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
293 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
294 Standard_Integer i=0;
295 for(i=0; i<=20; i++) HAI->SetValue(i,0);
296 for(i=1; i<=SeqLabels.Length(); i++) {
297 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
298 NbAreaProp, NbShapesWithName, NbShapesWithColor,
299 NbShapesWithLayer, Doc, PrintStructMode, di);
300 }
301 Standard_Integer NbLabelsShape = 0;
302 di<<"\n"<<"Statistis of shapes in the document:"<<"\n";
303 for(i=0; i<=20; i++) {
304 if(HAI->Value(i)==0) break;
305 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
306 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
307 NbLabelsShape = NbLabelsShape + HAI->Value(i);
308 }
309 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
310 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
311 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
312 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
313
314 di<<"\n"<<"Statistis of Props in the document:"<<"\n";
315 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
316 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
317 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
318
319 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
320 TDF_LabelSequence CLabels;
321 CTool->GetColors(CLabels);
322 di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n";
323 if(CLabels.Length()>0) {
324 for(i=1; i<=CLabels.Length(); i++) {
325 TDF_Label aLabel = CLabels.Value(i);
326 Quantity_Color col;
327 CTool->GetColor(aLabel, col);
328 di<<col.StringName(col.Name())<<" ";
329 }
330 di<<"\n";
331 }
332
333 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
334 TDF_LabelSequence LLabels;
335 LTool->GetLayerLabels(LLabels);
336 di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n";
337 if(LLabels.Length()>0) {
338 for(i=1; i<=LLabels.Length(); i++) {
339 TDF_Label aLabel = LLabels.Value(i);
340 TCollection_ExtendedString layerName;
341 LTool->GetLayer(aLabel, layerName);
342 TCollection_AsciiString Entry(layerName,'?');
343 di<<"\""<<Entry.ToCString() <<"\" ";
344 }
345 di<<"\n";
346 }
347
348 di<<"\n";
349 return 0;
350}
351
352
353//=======================================================================
354//function : setPrs
355//purpose :
356//=======================================================================
357static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
358{
359 if (argc <2) {
360 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
361 return 1;
362 }
363
364 Handle(TDocStd_Document) Doc;
365 DDocStd::GetDocument(argv[1], Doc);
366 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
367
368 // collect sequence of labels to set presentation
369 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
370 TDF_LabelSequence seq;
371 if ( argc >2 ) {
372 for ( Standard_Integer i=2; i < argc; i++ ) {
373 TDF_Label aLabel;
374 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
375 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
376 di << argv[i] << " is not a valid shape label!";
377 continue;
378 }
379 seq.Append ( aLabel );
380 }
381 }
382 else {
383 shapes->GetShapes ( seq );
384 }
385
386 // set presentations
387 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
388 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
389 Handle(TPrsStd_AISPresentation) prs;
390 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
391 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
392 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
393 }
394// Quantity_Color Col;
395// if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
396// prs->SetColor ( Col.Name() );
397// else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
398// prs->SetColor ( Col.Name() );
399 }
400 return 0;
401}
402
403
404//=======================================================================
405//function : show
406//purpose :
407//=======================================================================
408static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
409{
410 if (argc <2) {
411 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
412 return 1;
413 }
414
415 Handle(TDocStd_Document) Doc;
416 DDocStd::GetDocument(argv[1], Doc);
417 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
418
419 // init viewer
420// char string[260];
421// sprintf ( string, "AISInitViewer %s", argv[1] );
422// di.Eval ( string );
423 TDF_Label acces = Doc->GetData()->Root();
424 Handle(TPrsStd_AISViewer) viewer;
425 if (!TPrsStd_AISViewer::Find (acces,viewer)) {
426 TCollection_AsciiString title;
427 title.Prepend(argv[1]);
428 title.Prepend("_");
429 title.Prepend("Document");
430 Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString());
431 viewer = TPrsStd_AISViewer::New (acces,vw);
432 }
433 ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
434
435 //szv:CAX-TRJ7 c2-pe-214.stp was clipped
436 viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE);
437 //DDF::ReturnLabel(di,viewer->Label());
438
439 // collect sequence of labels to display
440 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
441 TDF_LabelSequence seq;
442 if ( argc >2 ) {
443 for ( Standard_Integer i=2; i < argc; i++ ) {
444 TDF_Label aLabel;
445 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
446 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
447 di << argv[i] << " is not a valid shape label!";
448 continue;
449 }
450 seq.Append ( aLabel );
451 }
452 }
453 else {
454 shapes->GetFreeShapes ( seq );
455 }
456
457 // set presentations and show
458 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
459 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
460 Handle(TPrsStd_AISPresentation) prs;
461 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
462 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
463 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
464 }
465// Quantity_Color Col;
466// if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
467// prs->SetColor ( Col.Name() );
468// else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
469// prs->SetColor ( Col.Name() );
470 prs->Display(Standard_True);
471 }
472 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
473 return 0;
474}
475
476
477//=======================================================================
478//function : xwd
479//purpose :
480//=======================================================================
481static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
482{
483 if (argc <3) {
484 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n";
485 return 1;
486 }
487
488 Handle(TDocStd_Document) Doc;
489 DDocStd::GetDocument(argv[1], Doc);
490 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
491
492 Handle(AIS_InteractiveContext) IC;
493 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
494 di << "Cannot find viewer for document " << argv[1] << "\n";
495 return 1;
496 }
497
498 Handle(V3d_Viewer) viewer = IC->CurrentViewer();
499 viewer->InitActiveViews();
500 if ( viewer->MoreActiveViews() ) {
501 viewer->ActiveView()->Dump ( argv[2] );
502 }
503 else {
504 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
505 return 1;
506 }
507
508 return 0;
509}
510
511
512//=======================================================================
513//function : XAttributeValue
514//purpose :
515//=======================================================================
516static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
517{
518 if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; }
519 Handle(DDF_Browser) browser =
520 Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
521 if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
522
523 TDF_Label lab;
524 TDF_Tool::Label(browser->Data(),argv[2],lab);
525 if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
526
527 Standard_Integer num = atoi ( argv[3] );
528 TDF_AttributeIterator itr(lab,Standard_False);
529 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
530
531 if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; }
532
533 const Handle(TDF_Attribute)& att = itr.Value();
534 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
f767df4e 535 Standard_CString type = "";
7fd59977 536 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
537 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
538 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
539 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
540 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
541 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
542 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
7fd59977 543 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
544 TCollection_AsciiString ref;
545 if ( TN->HasFather() ) {
546 TDF_Tool::Entry ( TN->Father()->Label(), ref );
547 di << type << " ==> " << ref.ToCString();
548 }
549 else {
550 di << type << " <== (" << ref.ToCString();
551 Handle(TDataStd_TreeNode) child = TN->First();
552 while ( ! child.IsNull() ) {
f767df4e 553 TDF_Tool::Entry ( child->Label(), ref );
554 if ( child != TN->First() ) di << ", ";
555 di << ref.ToCString();
556 child = child->Next();
7fd59977 557 }
558 di << ")";
559 }
560 }
f767df4e 561 else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
562 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
563 TCollection_AsciiString ref;
564 TDF_Tool::Entry ( val->Get(), ref );
565 di << "==> " << ref.ToCString();
566 }
7fd59977 567 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
568 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
569 TCollection_AsciiString str ( val->Get() );
570 di << str.ToCString();
571 }
572 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
573 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
574 TCollection_AsciiString str ( val->Get() );
575 di << str.ToCString();
576 }
f767df4e 577 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
578 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
579 TCollection_AsciiString str ( val->Get(), '?' );
7fd59977 580 di << str.ToCString();
581 }
f767df4e 582 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
583 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
584 TCollection_AsciiString str ( val->Get(), '?' );
7fd59977 585 di << str.ToCString();
586 }
f767df4e 587 else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
588 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
7fd59977 589 TCollection_AsciiString str ( val->Get(), '?' );
590 di << str.ToCString();
591 }
f767df4e 592 else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
593 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
594 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
595 if ( j > val->Lower() ) di << ", ";
596 TCollection_AsciiString str ( val->Value(j) );
597 di << str.ToCString();
598 }
599 }
7fd59977 600 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
601 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
602 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
603 if ( j > val->Lower() ) di << ", ";
604 TCollection_AsciiString str ( val->Value(j) );
605 di << str.ToCString();
606 }
607 }
f767df4e 608 else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
609 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
610 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
611 if ( j > val->Lower() ) di << ", ";
612 TCollection_AsciiString str ( val->Value(j) );
613 di << str.ToCString();
614 }
615 }
7fd59977 616 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
617 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
618 TopoDS_Shape S = val->Get();
619 di << S.TShape()->DynamicType()->Name();
620 if ( ! S.Location().IsIdentity() ) di << "(located)";
621 }
f767df4e 622 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
623 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
624 TCollection_AsciiString str ( val->Get() );
625 di << str.ToCString();
626 }
627 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
628 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
629 TCollection_AsciiString str ( val->Get() );
630 di << str.ToCString();
631 }
632 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
633 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
634 gp_Pnt myCentroid = val->Get();
635 di << "(" ;
636 di << myCentroid.X();
637 di <<" , ";
638 di << myCentroid.Y();
639 di <<" , ";
640 di << myCentroid.Z();
641 di << ")";
642 }
7fd59977 643 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
644 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
645 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
646 }
647 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
648 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
649 Quantity_Color C = val->GetColor();
650 char string[260];
651 sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
652 C.Red(), C.Green(), C.Blue() );
653 di << string;
654 }
655 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
656 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
657 Standard_Integer kind = val->GetKind();
658 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
659 if(kind<20) { //dimension
660 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
661 }
662 else {
663 switch(kind) {
664 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
665 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
666 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
667 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
668 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
669 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
670 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
671 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
672 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
673 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
674 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
675 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
676 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
677 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
678 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
679 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
680 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
681 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
682 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
683 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
684 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
685 }
686 }
687 }
688 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
689 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
690 Standard_Real dens = val->GetDensity();
691 Standard_CString dimdens = "g/cu sm";
692 if(dens==0)
693 di<<val->GetName()->ToCString();
694 else
695 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
696 }
697 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
698 Standard_CString type;
699 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
700 type = "Layer Instance Link";
701 }
702 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
703 type = "SHUO Instance Link";
704 }
705 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
706 type = "DatumToler Link";
707 }
708 else return 0;
709
710 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
711 TCollection_AsciiString ref;
712 Standard_Integer ii = 1;
713 if (DETGN->NbFathers()!=0) {
714
715 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
716 di << type<< " ==> (" << ref.ToCString();
717 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
718 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
719 di << ", " << ref.ToCString();
720 }
721 di << ") ";
722 }
723 ii = 1;
724 if (DETGN->NbChildren()!=0) {
725 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
726 di << type<< " <== (" << ref.ToCString();
727 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
728 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
729 di << ", " << ref.ToCString();
730 }
731 di << ")";
732 }
733 }
734 return 0;
735}
736
737
738//=======================================================================
739//function : setviewName
740//purpose :
741//=======================================================================
742static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
743{
744 if (argc <2) {
745 di<<"Use: "<<argv[0]<<" (1/0)"<<"\n";
746 return 1;
747 }
748 Standard_Boolean mode = Standard_False;
749 if (atoi(argv[1]) == 1) mode = Standard_True;
750 XCAFPrs::SetViewNameMode(mode);
751 return 0;
752}
753
754
755//=======================================================================
756//function : getviewName
757//purpose : auxilary
758//=======================================================================
759
760static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
761{
762 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n";
763 else di << "Display names OFF"<< "\n";
764 return 0;
765}
766
767
768//=======================================================================
5cbef0fe
S
769//function : XSetTransparency
770//purpose :
771//=======================================================================
772static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
773{
774 if (argc < 3) {
775 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] "<<"\n";
776 return 1;
777 }
778
779 Handle(TDocStd_Document) Doc;
780 DDocStd::GetDocument(argv[1], Doc);
781 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
782
783 const Standard_Real aTransparency = atof(argv[2]);
784
785 // collect sequence of labels
786 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
787 TDF_LabelSequence seq;
788 if ( argc > 3 ) {
789 for ( Standard_Integer i=3; i < argc; i++ ) {
790 TDF_Label aLabel;
791 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
792 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
793 di << argv[i] << " is not a valid shape label!";
794 continue;
795 }
796 seq.Append ( aLabel );
797 }
798 }
799 else {
800 shapes->GetFreeShapes ( seq );
801 }
802
803 // find presentations and set transparency
804 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
805 Handle(TPrsStd_AISPresentation) prs;
806 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
807 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
808 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
809 }
810 prs->SetTransparency( aTransparency );
811 }
812 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
813 return 0;
814}
815
816
817//=======================================================================
7fd59977 818//function : Init
819//purpose :
820//=======================================================================
821
822void XDEDRAW::Init(Draw_Interpretor& di)
823{
824
825 static Standard_Boolean initactor = Standard_False;
826 if (initactor) return; initactor = Standard_True;
827
828 // OCAF *** szy: use <pload> command
829
830// DDF::AllCommands(di);
831// DNaming::AllCommands(di);
832// DDataStd::AllCommands(di);
833// DPrsStd::AllCommands(di);
834 //DFunction::AllCommands(di);
835// DDocStd::AllCommands(di);
836
837// ViewerTest::Commands (di); *** szy: use <pload> command
838
839 // init XCAF application (if not yet done)
840 XCAFApp_Application::GetApplication();
841
842 //=====================================
843 // General commands
844 //=====================================
845
846 Standard_CString g = "XDE general commands";
847
848 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
849 __FILE__, newDoc, g);
850
851 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
852 __FILE__, saveDoc, g);
853
854 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
855 __FILE__, dump, g);
856
857 di.Add ("XStat","Doc \t: Print statistics of document",
858 __FILE__, statdoc, g);
859
860 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
861 __FILE__, setPrs, g);
862
863 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
864 __FILE__, show, g);
865
866 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
867 __FILE__, xwd, g);
868
869 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
870 __FILE__, XAttributeValue, g);
871
872 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
873 __FILE__, setviewName, g);
874
875 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
876 __FILE__, getviewName, g);
877
5cbef0fe
S
878 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
879 __FILE__, XSetTransparency, g);
880
7fd59977 881 // Specialized commands
882 XDEDRAW_Shapes::InitCommands ( di );
883 XDEDRAW_Colors::InitCommands ( di );
884 XDEDRAW_Layers::InitCommands ( di );
885 XDEDRAW_Props::InitCommands ( di );
886 XDEDRAW_Common::InitCommands ( di );//moved from EXE
887
888}
889
890
891//==============================================================================
892// XDEDRAW::Factory
893//==============================================================================
894void XDEDRAW::Factory(Draw_Interpretor& theDI)
895{
896 XSDRAWIGES::InitSelect();
897 XSDRAWIGES::InitToBRep(theDI);
898 XSDRAWIGES::InitFromBRep(theDI);
899
900 XSDRAWSTEP::InitCommands(theDI);
901
902 SWDRAW::Init(theDI);
903 XSDRAW::LoadDraw(theDI);
904
905 XDEDRAW::Init(theDI);
906
907#ifdef DEB
908 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n";
909#endif
910}
911
912// Declare entry point PLUGINFACTORY
913DPLUGIN(XDEDRAW)