0029296: Data Exchange - implement import of mesh data from files in OBJ format
[occt.git] / src / XDEDRAW / XDEDRAW_Common.cxx
CommitLineData
b311480e 1// Created on: 2003-08-15
2// Created by: Sergey ZARITCHNY
973c2be1 3// Copyright (c) 2003-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
42cf5bc1 17#include <DDocStd.hxx>
18#include <DDocStd_DrawDocument.hxx>
7fd59977 19#include <Draw.hxx>
20#include <Draw_Interpretor.hxx>
42cf5bc1 21#include <IFSelect_SessionPilot.hxx>
7fd59977 22#include <IGESCAFControl_Reader.hxx>
23#include <IGESCAFControl_Writer.hxx>
42cf5bc1 24#include <IGESControl_Controller.hxx>
25#include <Interface_Macros.hxx>
7fd59977 26#include <STEPCAFControl_ExternFile.hxx>
42cf5bc1 27#include <STEPCAFControl_Reader.hxx>
28#include <STEPCAFControl_Writer.hxx>
29#include <STEPControl_Controller.hxx>
30#include <TCollection_ExtendedString.hxx>
31#include <TDataStd_Name.hxx>
32#include <TDF_Data.hxx>
33#include <TDocStd_Application.hxx>
34#include <TDocStd_Document.hxx>
35#include <XDEDRAW.hxx>
36#include <XDEDRAW_Common.hxx>
37#include <XSControl_WorkSession.hxx>
38#include <XSDRAW.hxx>
7fd59977 39#include <XSDRAW_Vars.hxx>
42cf5bc1 40#include <XSDRAWIGES.hxx>
41#include <XSDRAWSTEP.hxx>
a3506de7 42#include <VrmlAPI_Writer.hxx>
f5e92b04 43#include <DDF.hxx>
7fd59977 44
5f07d05d 45#include <DBRep.hxx>
46#include <XCAFDoc_DocumentTool.hxx>
47#include <XCAFDoc_ShapeTool.hxx>
48#include <XCAFDoc_Editor.hxx>
49#include <TDF_Tool.hxx>
50#include <TopoDS_Shape.hxx>
0575de6d 51#include <Interface_Static.hxx>
a3506de7 52#include <UnitsMethods.hxx>
5f07d05d 53
42cf5bc1 54#include <stdio.h>
a3506de7 55
7fd59977 56//============================================================
57// Support for several models in DRAW
58//============================================================
997e128f 59static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> thedictws;
7fd59977 60
61static Standard_Boolean ClearDicWS()
62{
997e128f 63 thedictws.Clear();
7fd59977 64 return Standard_True;
65}
66
67static void AddWS(TCollection_AsciiString filename,
68 const Handle(XSControl_WorkSession)& WS)
69{
70 WS->SetVars ( new XSDRAW_Vars ); // support of DRAW variables
997e128f 71 thedictws.Bind( filename, WS );
7fd59977 72}
73
74
997e128f 75static Standard_Boolean FillDicWS(NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& dicFile)
7fd59977 76{
77 ClearDicWS();
997e128f 78 if ( dicFile.IsEmpty() ) {
7fd59977 79 return Standard_False;
80 }
81 Handle(STEPCAFControl_ExternFile) EF;
997e128f 82 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator DicEFIt(dicFile);
7fd59977 83 for (; DicEFIt.More(); DicEFIt.Next() ) {
997e128f 84 TCollection_AsciiString filename = DicEFIt.Key();
7fd59977 85 EF = DicEFIt.Value();
86 AddWS ( filename, EF->GetWS() );
87 }
88 return Standard_True;
89}
90
91static Standard_Boolean SetCurrentWS (TCollection_AsciiString filename)
92{
997e128f 93 if ( !thedictws.IsBound(filename) ) return Standard_False;
7fd59977 94 Handle(XSControl_WorkSession) CurrentWS =
997e128f 95 Handle(XSControl_WorkSession)::DownCast( thedictws.ChangeFind(filename) );
7fd59977 96 XSDRAW::Pilot()->SetSession( CurrentWS );
97
98 return Standard_True;
99}
100
101
102//=======================================================================
103//function : SetCurWS
104//purpose : Set current file if many files are read
105//=======================================================================
106
107static Standard_Integer SetCurWS (Draw_Interpretor& di , Standard_Integer argc, const char** argv)
108{
109 if (argc <2) {
586db386 110 di<<"Use: "<<argv[0]<<" filename \n";
7fd59977 111 return 1;
112 }
113 TCollection_AsciiString filename (argv[1]);
114 SetCurrentWS( filename );
115 return 0;
116}
117
118
119//=======================================================================
120//function : GetDicWSList
121//purpose : List all files recorded after translation
122//=======================================================================
123
124static Standard_Integer GetDicWSList (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
125{
997e128f 126 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> DictWS = thedictws;
127 if ( DictWS.IsEmpty() ) return 1;
128 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator DicIt(DictWS);
586db386 129 di << " The list of last translated files:\n";
7fd59977 130 Standard_Integer num = 0;
131 for (; DicIt.More() ; DicIt.Next(), num++ ) {
997e128f 132 TCollection_AsciiString strng ( DicIt.Key() );
7fd59977 133 if ( num ) di << "\n";
134 di << "\"" << strng.ToCString() << "\"";
135 }
136 return 0;
137}
138
139//=======================================================================
140//function : GetCurWS
141//purpose : Return name of file which is current
142//=======================================================================
143
144static Standard_Integer GetCurWS (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
145{
146 Handle(XSControl_WorkSession) WS = XSDRAW::Session();
147 di << "\"" << WS->LoadedFile() << "\"";
148 return 0;
149}
150
151//=======================================================================
152//function : FromShape
153//purpose : Apply fromshape command to all the loaded WSs
154//=======================================================================
155
156static Standard_Integer FromShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
157{
158 if ( argc <2 ) {
586db386 159 di << argv[0] << " shape: search for shape origin among all last tranalated files\n";
7fd59977 160 return 0;
161 }
162
163 char command[256];
91322f44 164 Sprintf ( command, "fromshape %.200s -1", argv[1] );
997e128f 165 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> DictWS = thedictws;
166 if ( DictWS.IsEmpty() ) return di.Eval ( command );
7fd59977 167
168 Handle(XSControl_WorkSession) WS = XSDRAW::Session();
169
997e128f 170 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator DicIt ( DictWS );
586db386 171// di << "Searching for shape among all the loaded files:\n";
7fd59977 172 Standard_Integer num = 0;
173 for (; DicIt.More() ; DicIt.Next(), num++ ) {
174 Handle(XSControl_WorkSession) CurrentWS =
175 Handle(XSControl_WorkSession)::DownCast( DicIt.Value() );
176 XSDRAW::Pilot()->SetSession( CurrentWS );
177 di.Eval ( command );
178 }
179
180 XSDRAW::Pilot()->SetSession( WS );
181 return 0;
182}
183
184//=======================================================================
185//function : ReadIges
186//purpose : Read IGES to DECAF document
187//=======================================================================
188
189static Standard_Integer ReadIges (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
190{
191 if ( argc <3 ) {
586db386 192 di << "Use: " << argv[0] << " Doc filename [mode]: read IGES file to a document\n";
7fd59977 193 return 0;
194 }
195
196 DeclareAndCast(IGESControl_Controller,ctl,XSDRAW::Controller());
197 if (ctl.IsNull()) XSDRAW::SetNorm("IGES");
0575de6d 198
63cdf48e 199 TCollection_AsciiString fnom, rnom;
200 Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "IGES", fnom, rnom);
201 if (modfic) di << " File IGES to read : " << fnom.ToCString() << "\n";
202 else di << " Model taken from the session : " << fnom.ToCString() << "\n";
203 // di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom<<"\n";
7fd59977 204
63cdf48e 205 IGESCAFControl_Reader reader ( XSDRAW::Session(),modfic);
0575de6d 206 Standard_Integer onlyvisible = Interface_Static::IVal("read.iges.onlyvisible");
207 reader.SetReadVisible(onlyvisible == 1);
7fd59977 208
209 if (argc == 4) {
210 Standard_Boolean mode = Standard_True;
211 for ( Standard_Integer i = 0; argv[3][i] ; i++ )
212 switch (argv[3][i]) {
213 case '-' : mode = Standard_False; break;
214 case '+' : mode = Standard_True; break;
215 case 'c' : reader.SetColorMode (mode); break;
216 case 'n' : reader.SetNameMode (mode); break;
217 case 'l' : reader.SetLayerMode (mode); break;
218 }
219 }
7fd59977 220 IFSelect_ReturnStatus readstat = IFSelect_RetVoid;
221 if (modfic) readstat = reader.ReadFile (fnom.ToCString());
222 else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone;
223 if (readstat != IFSelect_RetDone) {
586db386 224 if (modfic) di<<"Could not read file "<<fnom.ToCString()<<" , abandon\n";
225 else di<<"No model loaded\n";
7fd59977 226 return 1;
227 }
228
229 Handle(TDocStd_Document) doc;
230 if (!DDocStd::GetDocument(argv[1],doc,Standard_False)) {
6fe96f84 231 Handle(TDocStd_Application) A = DDocStd::GetApplication();
fff263bd 232 A->NewDocument("BinXCAF",doc);
7fd59977 233 TDataStd_Name::Set(doc->GetData()->Root(),argv[1]);
234 Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
235 Draw::Set(argv[1],DD);
236// di << "Document saved with name " << argv[1];
237 }
238 if ( ! reader.Transfer ( doc ) ) {
586db386 239 di << "Cannot read any relevant data from the IGES file\n";
7fd59977 240 return 1;
241 }
242
243// Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
244// Draw::Set(argv[1],DD);
245 di << "Document saved with name " << argv[1];
246
247 return 0;
248}
249
250//=======================================================================
251//function : WriteIges
252//purpose : Write DECAF document to IGES
253//=======================================================================
254
255static Standard_Integer WriteIges (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
256{
257 if ( argc <3 ) {
586db386 258 di << "Use: " << argv[0] << " Doc filename [mode]: write document to IGES file\n";
7fd59977 259 return 0;
260 }
261
262 Handle(TDocStd_Document) Doc;
263 DDocStd::GetDocument(argv[1], Doc);
264 if ( Doc.IsNull() ) {
586db386 265 di << argv[1] << " is not a document\n";
7fd59977 266 return 1;
267 }
268
269 XSDRAW::SetNorm ("IGES");
270
271// IGESControl_Writer ICW (Interface_Static::CVal("write.iges.unit"),
272// Interface_Static::IVal("write.iges.brep.mode"));
273
274 IGESCAFControl_Writer writer ( XSDRAW::Session(), Standard_True );
275 if (argc == 4) {
276 Standard_Boolean mode = Standard_True;
277 for ( Standard_Integer i = 0; argv[3][i] ; i++ )
278 switch (argv[3][i]) {
279 case '-' : mode = Standard_False; break;
280 case '+' : mode = Standard_True; break;
281 case 'c' : writer.SetColorMode (mode); break;
282 case 'n' : writer.SetNameMode (mode); break;
283 case 'l' : writer.SetLayerMode (mode); break;
284 }
285 }
286 writer.Transfer ( Doc );
287
63cdf48e 288 TCollection_AsciiString fnom, rnom;
289 Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "IGES", fnom, rnom);
290 if (modfic)
291 {
292 di << "Writig IGES model to file " << argv[2] << "\n";
293 if ( writer.Write ( argv[2] ) ) di<<" Write OK\n";
294 else di<<" Write failed\n";
295 }
296 else
297 {
298 di << "Document has been translated into the session";
299 }
7fd59977 300 return 0;
301}
302
303//=======================================================================
304//function : ReadStep
305//purpose : Read STEP file to DECAF document
306//=======================================================================
307
308static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
309{
7fd59977 310 DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller());
311 if (ctl.IsNull()) XSDRAW::SetNorm("STEP");
312
e3249d8e 313 Standard_CString aDocName = NULL;
314 TCollection_AsciiString aFilePath, aModeStr;
315 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
316 {
317 TCollection_AsciiString anArgCase (argv[anArgIter]);
318 anArgCase.LowerCase();
319 if (aDocName == NULL)
320 {
321 aDocName = argv[anArgIter];
322 }
323 else if (aFilePath.IsEmpty())
324 {
325 aFilePath = argv[anArgIter];
326 }
327 else if (aModeStr.IsEmpty())
328 {
329 aModeStr = argv[anArgIter];
330 }
331 else
332 {
333 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
334 return 1;
335 }
336 }
337
63cdf48e 338 TCollection_AsciiString fnom, rnom;
e3249d8e 339 Standard_Boolean modfic = XSDRAW::FileAndVar (aFilePath.ToCString(), aDocName, "STEP", fnom, rnom);
63cdf48e 340 if (modfic) di << " File STEP to read : " << fnom.ToCString() << "\n";
341 else di << " Model taken from the session : " << fnom.ToCString() << "\n";
342 // di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom<<"\n";
343
344 STEPCAFControl_Reader reader ( XSDRAW::Session(),modfic);
e3249d8e 345 if (!aModeStr.IsEmpty())
346 {
7fd59977 347 Standard_Boolean mode = Standard_True;
e3249d8e 348 for (Standard_Integer i = 1; aModeStr.Value (i); ++i)
349 {
350 switch (aModeStr.Value (i))
351 {
352 case '-' : mode = Standard_False; break;
353 case '+' : mode = Standard_True; break;
354 case 'c' : reader.SetColorMode (mode); break;
355 case 'n' : reader.SetNameMode (mode); break;
356 case 'l' : reader.SetLayerMode (mode); break;
357 case 'v' : reader.SetPropsMode (mode); break;
358 default:
359 {
360 std::cout << "Syntax error at '" << aModeStr << "'\n";
361 return 1;
362 }
7fd59977 363 }
e3249d8e 364 }
7fd59977 365 }
366
7fd59977 367 IFSelect_ReturnStatus readstat = IFSelect_RetVoid;
368 if (modfic) readstat = reader.ReadFile (fnom.ToCString());
369 else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone;
370 if (readstat != IFSelect_RetDone) {
586db386 371 if (modfic) di<<"Could not read file "<<fnom.ToCString()<<" , abandon\n";
372 else di<<"No model loaded\n";
7fd59977 373 return 1;
374 }
375
376 Handle(TDocStd_Document) doc;
e3249d8e 377 if (!DDocStd::GetDocument (aDocName, doc, Standard_False))
378 {
6fe96f84 379 Handle(TDocStd_Application) A = DDocStd::GetApplication();
e3249d8e 380 A->NewDocument("BinXCAF",doc);
381 TDataStd_Name::Set(doc->GetData()->Root(), aDocName);
382 Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
383 Draw::Set (aDocName, DD);
384// di << "Document saved with name " << aDocName;
7fd59977 385 }
386 if ( ! reader.Transfer ( doc ) ) {
586db386 387 di << "Cannot read any relevant data from the STEP file\n";
7fd59977 388 return 1;
389 }
390
e3249d8e 391 Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
392 Draw::Set (aDocName, DD);
393 di << "Document saved with name " << aDocName;
7fd59977 394
997e128f 395 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> DicFile = reader.ExternFiles();
7fd59977 396 FillDicWS( DicFile );
397 AddWS ( fnom , XSDRAW::Session() );
e3249d8e 398
7fd59977 399 return 0;
400}
401
402//=======================================================================
403//function : WriteStep
404//purpose : Write DECAF document to STEP
405//=======================================================================
406
407static Standard_Integer WriteStep (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
408{
409 if ( argc <3 ) {
586db386 410 di << "Use: " << argv[0] << " Doc filename [mode [multifile_prefix [label]]]: write document to the STEP file\n";
411 di << "mode can be: a or 0 : AsIs (default)\n";
f5e92b04 412 di << " f or 1 : FacettedBRep s or 2 : ShellBasedSurfaceModel\n";
413 di << " m or 3 : ManifoldSolidBrep w or 4 : GeometricCurveSet/WireFrame\n";
414 di << "multifile_prefix: triggers writing assembly components as separate files,\n";
415 di << " and defines common prefix for their names\n";
416 di << "label: tag of the sub-assembly label to save only that sub-assembly\n";
7fd59977 417 return 0;
418 }
419
420 Handle(TDocStd_Document) Doc;
421 DDocStd::GetDocument(argv[1], Doc);
422 if ( Doc.IsNull() ) {
586db386 423 di << argv[1] << " is not a document\n";
7fd59977 424 return 1;
425 }
f5e92b04 426 Standard_CString multifile = 0;
7fd59977 427
f5e92b04 428 Standard_Integer k = 3;
7fd59977 429 DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller());
430 if (ctl.IsNull()) XSDRAW::SetNorm("STEP");
431 STEPCAFControl_Writer writer ( XSDRAW::Session(), Standard_True );
f5e92b04 432
7fd59977 433 STEPControl_StepModelType mode = STEPControl_AsIs;
f5e92b04 434 if ( argc > k ) {
435 switch (argv[k][0]) {
7fd59977 436 case 'a' :
437 case '0' : mode = STEPControl_AsIs; break;
438 case 'f' :
439 case '1' : mode = STEPControl_FacetedBrep; break;
440 case 's' :
441 case '2' : mode = STEPControl_ShellBasedSurfaceModel; break;
442 case 'm' :
443 case '3' : mode = STEPControl_ManifoldSolidBrep; break;
444 case 'w' :
445 case '4' : mode = STEPControl_GeometricCurveSet; break;
586db386 446 default : di<<"3st arg = mode, incorrect [give fsmw]\n"; return 1;
7fd59977 447 }
448 Standard_Boolean wrmode = Standard_True;
f5e92b04 449 for ( Standard_Integer i = 0; argv[k][i] ; i++ )
7fd59977 450 switch (argv[3][i]) {
451 case '-' : wrmode = Standard_False; break;
452 case '+' : wrmode = Standard_True; break;
453 case 'c' : writer.SetColorMode (wrmode); break;
454 case 'n' : writer.SetNameMode (wrmode); break;
455 case 'l' : writer.SetLayerMode (wrmode); break;
456 case 'v' : writer.SetPropsMode (wrmode); break;
457 }
f5e92b04 458 k++;
459 }
460
461 TDF_Label label;
462 if( argc > k)
463 {
464 TCollection_AsciiString aStr(argv[k]);
465 if( aStr.Search(":") ==-1)
466 multifile = argv[k++];
7fd59977 467
468 }
f5e92b04 469 if( argc > k)
470 {
471
472 if( !DDF::FindLabel(Doc->Main().Data(), argv[k], label) || label.IsNull()) {
473 di << "No label for entry" << "\n";
474 return 1;
475
476 }
7fd59977 477 }
f5e92b04 478 if( !label.IsNull())
479 {
586db386 480 di << "Translating label "<< argv[k]<<" of document " << argv[1] << " to STEP\n";
f5e92b04 481 if(!writer.Transfer ( label, mode, multifile ))
482 {
586db386 483 di << "The label of document cannot be translated or gives no result\n";
f5e92b04 484 return 1;
485 }
486
487 }
488 else
489 {
586db386 490 di << "Translating document " << argv[1] << " to STEP\n";
f5e92b04 491 if ( ! writer.Transfer ( Doc, mode, multifile ) ) {
586db386 492 di << "The document cannot be translated or gives no result\n";
f5e92b04 493 }
494 }
495
63cdf48e 496 TCollection_AsciiString fnom, rnom;
497 Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "STEP", fnom, rnom);
498 if (modfic)
499 {
500 di << "Writing STEP file " << argv[2] << "\n";
501 IFSelect_ReturnStatus stat = writer.Write(argv[2]);
502 switch (stat) {
503 case IFSelect_RetVoid : di<<"No file written\n"; break;
504 case IFSelect_RetDone : {
505 di<<"File "<<argv[2]<<" written\n";
506
507 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> DicFile = writer.ExternFiles();
508 FillDicWS( DicFile );
509 AddWS( argv[2], XSDRAW::Session() );
510 break;
511 }
512 default : di<<"Error on writing file\n"; break;
7fd59977 513 }
63cdf48e 514 }
515 else
516 {
517 di << "Document has been translated into the session";
7fd59977 518 }
519 return 0;
520}
521
5f07d05d 522static Standard_Integer Expand (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
523{
524 if (argc < 3) {
586db386 525 di<<"Use: "<<argv[0]<<" Doc recurs(0/1) or Doc recurs(0/1) label1 label2 ... or Doc recurs(0/1 shape1 shape2 ...\n";
5f07d05d 526 return 1;
527 }
528 Handle(TDocStd_Document) Doc;
529 DDocStd::GetDocument(argv[1], Doc);
586db386 530 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
5f07d05d 531
532 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
533 Standard_Boolean recurs = Standard_False;
534 if(atoi(argv[2]) != 0)
535 recurs = Standard_True;
536
537 if (argc == 3)
538 {
539 if(!XCAFDoc_Editor::Expand(Doc->Main(), recurs)){
00dfcc76 540 di << "No suitable labels to expand\n";
5f07d05d 541 return 1;
542 }
543 }
544 else
545 {
546 for (Standard_Integer i = 3; i < argc; i++)
547 {
548 TDF_Label aLabel;
549 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
550 if(aLabel.IsNull()){
551 TopoDS_Shape aShape;
552 aShape = DBRep::Get(argv[i]);
553 aLabel = aShapeTool->FindShape(aShape);
554 }
555
556 if (!aLabel.IsNull()){
557 if(!XCAFDoc_Editor::Expand(Doc->Main(), aLabel, recurs)){
00dfcc76 558 di << "The shape is assembly or not compound\n";
5f07d05d 559 return 1;
560 }
561 }
562 else
586db386 563 { di << argv[i] << " is not a shape\n"; return 1; }
5f07d05d 564 }
565 }
566 return 0;
567}
568
a3506de7 569
570//=======================================================================
571//function : WriteVrml
572//purpose : Write DECAF document to Vrml
573//=======================================================================
574
575static Standard_Integer WriteVrml(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
576{
577 if (argc <3) {
578 di << "Use: " << argv[0] << " Doc filename: write document to Vrml file\n";
579 return 0;
580 }
581
582 Handle(TDocStd_Document) aDoc;
583 DDocStd::GetDocument(argv[1], aDoc);
584 if (aDoc.IsNull()) {
585 di << argv[1] << " is not a document\n";
586 return 1;
587 }
588
589 if (argc < 3 || argc > 5)
590 {
591 di << "wrong number of parameters\n";
592 return 0;
593 }
594
595 VrmlAPI_Writer writer;
596 writer.SetRepresentation(VrmlAPI_ShadedRepresentation);
597 Standard_Real anOCCLengthUnit =
598 UnitsMethods::GetLengthFactorValue(Interface_Static::IVal("xstep.cascade.unit"));
599 Standard_Real aScale = 0.001*anOCCLengthUnit;
600 writer.WriteDoc(aDoc, argv[2], aScale);
601
602 return 0;
603}
604
605
c48e2889 606void XDEDRAW_Common::InitCommands(Draw_Interpretor& di)
607{
7fd59977 608 static Standard_Boolean initactor = Standard_False;
c48e2889 609 if (initactor)
610 {
611 return;
612 }
613 initactor = Standard_True;
7fd59977 614
615 Standard_CString g = "XDE translation commands";
616
617 di.Add("ReadIges" , "Doc filename: Read IGES file to DECAF document" ,__FILE__, ReadIges, g);
618 di.Add("WriteIges" , "Doc filename: Write DECAF document to IGES file" ,__FILE__, WriteIges, g);
e3249d8e 619 di.Add("ReadStep" ,
620 "Doc filename [mode]"
621 "\n\t\t: Read STEP file to a document.",
622 __FILE__, ReadStep, g);
f5e92b04 623 di.Add("WriteStep" , "Doc filename [mode=a [multifile_prefix] [label]]: Write DECAF document to STEP file" ,__FILE__, WriteStep, g);
7fd59977 624
625 di.Add("XFileList","Print list of files that was transfered by the last transfer" ,__FILE__, GetDicWSList , g);
626 di.Add("XFileCur", ": returns name of file which is set as current",__FILE__, GetCurWS, g);
627 di.Add("XFileSet", "filename: Set the specified file to be the current one",__FILE__, SetCurWS, g);
628 di.Add("XFromShape", "shape: do fromshape command for all the files",__FILE__, FromShape, g);
629
00dfcc76 630 di.Add("XExpand", "XExpand Doc recursively(0/1) or XExpand Doc recursively(0/1) label1 label2 ..."
5f07d05d 631 "or XExpand Doc recursively(0/1) shape1 shape2 ...",__FILE__, Expand, g);
632
a3506de7 633 di.Add("WriteVrml", "Doc filename [version VRML#1.0/VRML#2.0 (1/2): 2 by default] [representation shaded/wireframe/both (0/1/2): 0 by default]", __FILE__, WriteVrml, g);
634
7fd59977 635}