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