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