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