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