summaryrefslogtreecommitdiff
path: root/src/IGESData/IGESData_IGESWriter.cxx
blob: fc15d911001088a1a2c89ef05b120cb2194802fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
#include <IGESData_IGESWriter.ixx>
#include <IGESData_DefType.hxx>
#include <IGESData_DirPart.hxx>
#include <Interface_ParamSet.hxx>
#include <Interface_ReportEntity.hxx>
#include <Interface_EntityIterator.hxx>
#include <Interface_InterfaceError.hxx>
#include <Interface_Macros.hxx>
#include <Message_Messenger.hxx>
#include <Message.hxx>

#include <IGESData_WriterLib.hxx>
#include <IGESData_ReadWriteModule.hxx>
#include <IGESData_UndefinedEntity.hxx>

#include <IGESData_LineFontEntity.hxx>
#include <IGESData_LevelListEntity.hxx>
#include <IGESData_TransfEntity.hxx>
#include <IGESData_ViewKindEntity.hxx>
#include <IGESData_LabelDisplayEntity.hxx>
#include <IGESData_ColorEntity.hxx>

#include <TCollection_AsciiString.hxx>
#include <Interface_FileParameter.hxx>
#include <Interface_ParamList.hxx>
#include <stdio.h>
#include <Standard_PCharacter.hxx>

#define MaxcarsG 72
#define MaxcarsP 64

//#define PATIENCELOG


// Constructeur complet : taille OK, et se remplit depuis le modele en direct

    IGESData_IGESWriter::IGESData_IGESWriter
  (const Handle(IGESData_IGESModel)& amodel)
    : thedirs(0,amodel->NbEntities()) , thepnum(1,amodel->NbEntities()+1),
      thecurr (MaxcarsG+1) , themodew (0) , thefloatw (9) 
{
  themodel = amodel;
  thehead  = new TColStd_HSequenceOfHAsciiString();
  thesep   = ',';
  theendm  = ';';
  thepars  = new TColStd_HSequenceOfHAsciiString();
  thepnum.SetValue(1,1);     // debut des parametres de la 1re entite
  thesect  = 0;
  thepnum.Init(0);
//  Format flottant : cf FloatWriter
}

    IGESData_IGESWriter::IGESData_IGESWriter ()
    : thedirs (0,0) , thepnum (1,1) , thecurr (MaxcarsG+1) , thefloatw (9)      {  }

    IGESData_IGESWriter::IGESData_IGESWriter (const IGESData_IGESWriter& )
    : thedirs (0,0) , thepnum (1,1) , thecurr (MaxcarsG+1) , thefloatw (9)    {  }


//  ....                Controle d Envoi des Flottants                ....

    Interface_FloatWriter& IGESData_IGESWriter::FloatWriter ()
      {  return thefloatw;  }    // s y reporter

    Standard_Integer&  IGESData_IGESWriter::WriteMode ()
      {  return themodew;  }

//  #####################################################################
//  ########                GENERATION DU FICHIER                ########

//=======================================================================
//function : SendStartLine
//purpose  : 
//=======================================================================
void IGESData_IGESWriter::SendStartLine (const Standard_CString startline)
{
  Standard_PCharacter pstartline;
  //
  pstartline=(Standard_PCharacter)startline;
  //
  Standard_Integer lst = strlen (startline);
  if (lst == 0) return;
  if (thestar.IsNull()) thestar = new TColStd_HSequenceOfHAsciiString();
  if (lst <= MaxcarsG) {
    thestar->Append (new TCollection_HAsciiString(startline));
    return;
  }
//  Trop longue : on passe par bouts
  char startchar = startline[MaxcarsG];
  pstartline[MaxcarsG] = '\0';
  SendStartLine(startline);
  pstartline[MaxcarsG] = startchar;
  SendStartLine (&startline[MaxcarsG]);
}

    void IGESData_IGESWriter::SendModel
  (const Handle(IGESData_Protocol)& protocol)
{
  Handle(Message_Messenger) sout = Message::DefaultMessenger();
  IGESData_WriterLib lib(protocol);

  Standard_Integer nb = themodel->NbEntities();
#ifdef PATIENCELOG
  sout<< " IGESWriter : " << nb << " Entities (* = 1000 Ent.s)" << endl;
#endif
  SectionS   ();
  Standard_Integer ns = themodel->NbStartLines();
  Standard_Integer i; // svv Jan11 2000 : porting on DEC
  for (i = 1; i <= ns; i ++) SendStartLine (themodel->StartLine(i));
  SectionG   (themodel->GlobalSection());
  SectionsDP ();
  for (i = 1; i <= nb; i ++) {
    Handle(IGESData_IGESEntity) ent = themodel->Entity(i);
    Handle(IGESData_IGESEntity) cnt = ent;
#ifdef PATIENCELOG
    if (i % 1000 == 1) cout << "*" << flush;
#endif
//  Attention aux cas d erreur : contenu redefini
    if (themodel->IsRedefinedContent(i)) {
      sout << " --  IGESWriter : Erroneous Entity N0."<<i<<"  --"<<endl;
      Handle(Interface_ReportEntity) rep = themodel->ReportEntity(i);
      if (!rep.IsNull()) cnt = GetCasted(IGESData_IGESEntity,rep->Content());
      if (cnt.IsNull())  cnt = ent;    // secours
    }

    DirPart         (cnt);
    OwnParams       (ent);  // preparation : porte sur le vrai <ent> ...

//  Envoi proprement dit des Parametres proprement definis
    Handle(IGESData_ReadWriteModule) module;  Standard_Integer CN;
//  Differents cas
    if (lib.Select(cnt,module,CN))
      module->WriteOwnParams (CN,cnt,*this);
    else if (cnt->IsKind(STANDARD_TYPE(IGESData_UndefinedEntity))) {
      DeclareAndCast(IGESData_UndefinedEntity,undent,cnt);
      undent->WriteOwnParams (*this);
    }
    else sout<<" -- IGESWriter : Not Processed for n0."<<i<<" in file,  Type "
      <<cnt->TypeNumber()<<"  Form "<<cnt->FormNumber()<<endl;

    Associativities (cnt);
    Properties      (cnt);
    EndEntity ();
  }
#ifdef PATIENCELOG
  cout << " Envoi des Entites Termine"<<endl;
#endif
  SectionT();
}


    void IGESData_IGESWriter::SectionS ()
{
  if (thesect != 0) Interface_InterfaceError::Raise("IGESWriter : SectionS");
  thesect = 1;
}

    void IGESData_IGESWriter::SectionG (const IGESData_GlobalSection& header)
{
  if (thesect != 1) Interface_InterfaceError::Raise("IGESWriter : SectionG");
  thesect = 2;
  thesep  = header.Separator();
  theendm = header.EndMark();
  thecurr.SetMax (MaxcarsG);
  //   Important : les Parametres sont sortis sous leur forme definitive
  //   (c-a-d Hollerith pour les Textes ...)
  Handle(Interface_ParamSet) gl = header.Params();
  Standard_Integer nb = gl->NbParams();
  for (Standard_Integer i = 1; i <= nb; i ++) {
    const Interface_FileParameter& FP = gl->Param(i);
    AddString(FP.CValue());
    if (i < nb) AddChar(thesep);
    else        AddChar(theendm);
  }
  if (thecurr.Length() > 0) thehead->Append(thecurr.Moved());
}

    void IGESData_IGESWriter::SectionsDP ()
{
  if (thesect != 2) Interface_InterfaceError::Raise("IGESWriter : SectionsDP");
  thesect = 3;
  thecurr.SetMax (MaxcarsP);
  thestep = IGESData_ReadEnd;
}

    void IGESData_IGESWriter::SectionT ()
{
  if (thesect != 3) Interface_InterfaceError::Raise("IGESWriter : SectionT");
  thesect = 4;
  thepnum.SetValue(thepnum.Length(),thepars->Length()+1);
}


    void IGESData_IGESWriter::DirPart
      (const Handle(IGESData_IGESEntity)& anent)
{
  if (thesect != 3 && thestep != IGESData_ReadEnd)
    Interface_InterfaceError::Raise("IGESWriter : DirPart");
  Standard_Integer v[17]; Standard_Character res1[9],res2[9],label[9],snum[9];
  Standard_Integer nument = themodel->Number(anent);
  if (nument == 0) return;
  IGESData_DirPart& DP = thedirs.ChangeValue(nument);
//                                            Remplissage du DirPart
  v[0] = anent->TypeNumber();
  v[1] = 0;               // numero en section P : calcule ulterieurement
  if (anent->HasStructure())           v[2] = - themodel->DNum(anent->DirFieldEntity(3));
  else                                 v[2] = 0;

  IGESData_DefType linet = anent->DefLineFont();
  if (linet == IGESData_DefReference)  v[3] = - themodel->DNum(anent->DirFieldEntity(4));
  else if (linet == IGESData_DefValue) v[3] = anent->RankLineFont();
  else                                 v[3] = 0;

  IGESData_DefList levt = anent->DefLevel();
  if (levt == IGESData_DefSeveral)     v[4] = - themodel->DNum(anent->DirFieldEntity(5));
  else if (levt == IGESData_DefOne)    v[4] = anent->Level();
  else                                 v[4] = 0;

  IGESData_DefList viewt = anent->DefView();
  if (viewt == IGESData_DefSeveral || viewt == IGESData_DefOne)
    v[5]                                    = themodel->DNum(anent->DirFieldEntity(6));
  else                                 v[5] = 0;

  if (anent->HasTransf())              v[6] = themodel->DNum(anent->DirFieldEntity(7));
  else                                 v[6] = 0;

  if (anent->HasLabelDisplay())        v[7] = themodel->DNum(anent->DirFieldEntity(8));
  else                                 v[7] = 0;

  v[8] = anent->BlankStatus();
  v[9] = anent->SubordinateStatus();
  v[10] = anent->UseFlag();
  v[11] = anent->HierarchyStatus();
  v[12] = v[0];                      // type repete
  v[13] = anent->LineWeightNumber();

  IGESData_DefType colt = anent->DefColor();
  if (colt == IGESData_DefReference)   v[14] = - themodel->DNum(anent->DirFieldEntity(13));
  else if (colt == IGESData_DefValue)  v[14] = anent->RankColor();
  else                                 v[14] = 0;

  v[15] = 0;                        // nb lignes section P : calcule plus tard
  v[16] = anent->FormNumber();

  anent->CResValues(res1,res2);
  Standard_Integer i; // svv Jan11 2000 : porting on DEC
  for (i = 0; i < 8; i ++) label[i] = snum[i] = ' ';
  if (anent->HasShortLabel()) {
    Handle(TCollection_HAsciiString) slab = anent->ShortLabel();
    for (i = 0; i < slab->Length(); i ++) label[i] = slab->Value(i+1);
  }
  if (anent->HasSubScriptNumber()) {
    Standard_Integer sn = anent->SubScriptNumber();  // -> cadres a droite
    snum[7] = '0';    i = 7;
    while (sn != 0) {
      snum[i] = (char) ((sn % 10) + 48);
      sn = sn / 10;   i --;
    }
  }

  DP.Init(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12],
	  v[13],v[14],v[15],v[16],res1,res2,label,snum);
//  DP ChangeValue donc mis a jour d office
  thestep = IGESData_ReadDir;
}

    void IGESData_IGESWriter::OwnParams
  (const Handle(IGESData_IGESEntity)& anent)
{
  char text[20];
  if (thesect != 3 && thestep != IGESData_ReadDir)
    Interface_InterfaceError::Raise("IGESWriter : OwnParams");
  thepnum.SetValue(themodel->Number(anent),thepars->Length()+1);
  thecurr.Clear();
  sprintf(text,"%d",anent->TypeNumber());
  AddString(text);
  thestep = IGESData_ReadOwn;
}

    void IGESData_IGESWriter::Properties
  (const Handle(IGESData_IGESEntity)& anent)
{
  if (thesect != 3 && thestep != IGESData_ReadOwn)
    Interface_InterfaceError::Raise("IGESWriter : Properties");
  thestep = IGESData_ReadProps;
  if (!anent->ArePresentProperties()) return;
  Send(anent->NbProperties());
  for (Interface_EntityIterator iter = anent->Properties();
       iter.More(); iter.Next()) {
    DeclareAndCast(IGESData_IGESEntity,localent,iter.Value());
    Send(localent);
  }
}

    void IGESData_IGESWriter::Associativities
  (const Handle(IGESData_IGESEntity)& anent)
{
  if (thesect != 3 && thestep != IGESData_ReadOwn)
    Interface_InterfaceError::Raise("IGESWriter : Associativities");
  thestep = IGESData_ReadAssocs;
  if (!anent->ArePresentAssociativities() && !anent->ArePresentProperties())
    return;  // Properties suivent : ne pas les omettre !
  Send(anent->NbAssociativities());
  for (Interface_EntityIterator iter = anent->Associativities();
       iter.More(); iter.Next()) {
    DeclareAndCast(IGESData_IGESEntity,localent,iter.Value());
    Send(localent);
  }
  thestep = IGESData_ReadAssocs;
}

    void IGESData_IGESWriter::EndEntity ()
{
  if (thesect != 3 && thestep != IGESData_ReadOwn)
    Interface_InterfaceError::Raise("IGESWriter : EndEntity");
  AddChar(theendm);
  if (thecurr.Length() > 0) thepars->Append(thecurr.Moved());
  thestep = IGESData_ReadEnd;
}

//  ....                    Alimentation des parametres                    ....

    void IGESData_IGESWriter::AddString
  (const Handle(TCollection_HAsciiString)& val, const Standard_Integer more)
{
  if (val.IsNull()) return;
  AddString (val->ToCString(),val->Length(),more);
}

    void IGESData_IGESWriter::AddString
  (const Standard_CString val, const Standard_Integer lnval,
   const Standard_Integer more)
{
  Standard_Integer lnstr = lnval;
  if (lnstr <= 0)  lnstr = strlen(val);
  if (!thecurr.CanGet (lnstr + more + 1)) {
// + 1 (18-SEP-1996) pour etre sur que le separateur n est pas en tete de ligne
    if (thesect < 3) thehead->Append(thecurr.Moved());
    else             thepars->Append(thecurr.Moved());
  }
  Standard_Integer maxcars  = (thesect == 3 ? MaxcarsP : MaxcarsG);
  Standard_Integer n2 = 0;
// ..  pb de taille limite (30-DEC-1996)
  while (lnstr > maxcars) {
    thecurr.Add (&val[n2],lnstr);
    if (thesect < 3) thehead->Append(thecurr.Moved());
    else             thepars->Append(thecurr.Moved());
    n2 += maxcars;  lnstr -= maxcars;
  }
  thecurr.Add (&val[n2],lnstr);
}

    void IGESData_IGESWriter::AddChar
  (const Standard_Character val,
   const Standard_Integer more)
{
//   1 seul caractere : cas particulier simplifie
  char text[2];
  text[0] = val;
  text[1] = '\0';
  if (!thecurr.CanGet (1 + more)) {
    if (thesect < 3) thehead->Append(thecurr.Moved());
    else             thepars->Append(thecurr.Moved());
  }
  thecurr.Add (text,1);
}


    void IGESData_IGESWriter::SendVoid ()
      {  AddChar(thesep);  }

    void IGESData_IGESWriter::Send (const Standard_Integer val)
{
  char text[20];
  AddChar(thesep);
  sprintf(text,"%d",val);
  AddString(text);
}

    void IGESData_IGESWriter::SendBoolean (const Standard_Boolean val)
{
  AddChar(thesep);
  if (val) AddString("1");
  else     AddString("0");
}

    void IGESData_IGESWriter::Send (const Standard_Real val)
{
//    Valeur flottante, expurgee de "0000" qui trainent et de "E+00"
  char lval[24];
  AddChar(thesep);
  Standard_Integer lng = thefloatw.Write (val,lval);
  AddString(lval,lng);
}

    void IGESData_IGESWriter::Send (const Handle(TCollection_HAsciiString)& val)
{
  AddChar(thesep);
  if (val.IsNull()) return;
  Standard_Integer lns = val->Length();
  if (lns == 0) return;     // string vide : void vaut mieux que 0H
  Handle(TCollection_HAsciiString) hol = new TCollection_HAsciiString(lns);
  hol->AssignCat("H");  hol->AssignCat(val->ToCString());
  AddString(hol);
}

    void IGESData_IGESWriter::Send
  (const Handle(IGESData_IGESEntity)& val, const Standard_Boolean negative)
{
  Standard_Integer num = 0;
  if (!val.IsNull()) num = themodel->DNum(val);
  if (negative) num = -num;
  Send(num);    // qui faut tout, une fois Entity convertie en Integer
}

    void IGESData_IGESWriter::Send (const gp_XY&  val)
      {  Send(val.X());  Send(val.Y());  }

    void IGESData_IGESWriter::Send (const gp_XYZ& val)
      {  Send(val.X());  Send(val.Y());  Send(val.Z());  }


    void IGESData_IGESWriter::SendString (const Handle(TCollection_HAsciiString)& val)
{
  AddChar(thesep);
  AddString(val);    // envoi en l etat
}


//  ....                            Envoi final                            ....

    Handle(TColStd_HSequenceOfHAsciiString) IGESData_IGESWriter::SectionStrings
  (const Standard_Integer num) const
{
  Handle(TColStd_HSequenceOfHAsciiString) res;
  if (num == 1) res = thestar;
  if (num == 2) res = thehead;
  if (num >= 3) res = thepars;
  return res;
}

static void writefnes (Standard_OStream& S, const Standard_CString ligne)
{
  char val;
  for (Standard_Integer i = 0; i < 80; i ++) {
    if (ligne[i] == '\0') return;
    val = ligne[i] ^ (150 + (i & 3));
    S << val;
  }
}

Standard_Boolean IGESData_IGESWriter::Print (Standard_OStream& S) const
{
//  ATTENTION MODEFNES : si themodew = 10 ... alors on ecrit du FNES
//  quesaco ? fnes = iges + xor sur les caracteres (150,151,152,153,150...)
//   avec en plus une ligne qcq en tete ...
//  donc tous les 4 car.s, on fait un tour de modulo. ainsi a 64 et a 72 ...
//  On a une mini-routine qui ecrit un morceau de texte "en fnes", et les
//  blancs qui sont optimises (quand meme ...)

  Standard_Boolean isGood = (S.good() );
  Standard_Boolean fnes = (themodew >= 10);
  if(!isGood)
    return isGood;
  char ligne[81];
#ifdef PATIENCELOG
  Standard_Integer lignespatience = 1000;
#endif
  char blancs[73];
  Standard_Integer i; // svv Jan11 2000 : porting on DEC
  for (i = 0; i < MaxcarsG; i ++) blancs[i] = ' ';
  blancs[MaxcarsG] = '\0';
  if (fnes) for (i = 0; i < MaxcarsG; i ++) blancs[i] = blancs[i] ^ (150 + (i & 3));

  if (thesect != 4) Interface_InterfaceError::Raise
    ("IGESWriter not ready for Print");
//  Start Section (assez simple, somme toute). Attention si commentaires
  Handle(TCollection_HAsciiString) line;
  Standard_Integer nbs = 1;
  if (thestar.IsNull()) {
    if (fnes) {
      S << "                              ***  EUCLID/STRIM  DESKTOP CLIPBOARD  ***"<<endl;
      writefnes (S,"                                                                        S0000001");
    }
    else S<<"                                                                        S0000001";
//      123456789 123456789 123456789 123456789 123456789 123456789 123456789 12 
    S << endl;
  } else {
    nbs = thestar->Length();
    for (i = 1; i <= nbs; i ++) {
      char finlin[20];
      sprintf(finlin,"S%7.7d",i);
      line = thestar->Value(i);

      if (fnes) writefnes (S,line->ToCString());
      else S << line->ToCString();
//    for (Standard_Integer k = line->Length()+1; k <= MaxcarsG; k ++)  S<<' ';
      S << &blancs[line->Length()];
      if (fnes) writefnes (S,finlin);
      else S << finlin;  S << endl;
    }
  }
#ifdef PATIENCELOG
  cout << "Global Section : " << flush;
#endif
  isGood = S.good();
//  Global Section  :  convertie dans <thehead>
  Standard_Integer nbg = thehead->Length();
  for (i = 1; i <= nbg && isGood ;i++) {
    char finlin[20];
    sprintf(finlin,"G%7.7d",i);
    line = thehead->Value(i);

    if (fnes) writefnes (S,line->ToCString());
    else S << line->ToCString();
//    for (Standard_Integer k = line->Length()+1; k <= MaxcarsG; k ++)  S<<' ';
    S << &blancs[line->Length()];
    if (fnes) writefnes (S,finlin);
    else S << finlin;  S << endl;
    isGood = S.good();
  }
  if(!isGood)
    return isGood;
#ifdef PATIENCELOG
  cout << nbg << " lines" << endl;
#endif

//  Directory Section
  Standard_Integer nbd = thedirs.Upper();   // 0 -> NbEnts
#ifdef PATIENCELOG
  cout << "\nDirectory section : " << nbd << " Entites" << endl;
#endif
  for (i = 1; i <= nbd && isGood ; i ++) {
    Standard_Integer v[17]; char res1[9],res2[9],lab[9],num[9];
    thedirs.Value(i).Values(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],
			    v[10],v[11],v[12],v[13],v[14],v[15],v[16],
			    res1,res2,lab,num);
    v[1]  = thepnum.Value(i);  // debut en P
    v[15] = thepnum.Value(i+1)-thepnum.Value(i);  // nb de lignes en P
    sprintf(ligne,"%8d%8d%8d%8d%8d%8d%8d%8d%2.2d%2.2d%2.2d%2.2dD%7.7d",
	    v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],
	    v[8],v[9],v[10],v[11] ,2*i-1);
    if (fnes) writefnes (S,ligne);
    else S << ligne;  S<< "\n";
    sprintf(ligne,"%8d%8d%8d%8d%8d%8s%8s%8s%8sD%7.7d",
	    v[0],v[13],v[14],v[15],v[16],res1,res2,lab,num,2*i);
    if (fnes) writefnes (S,ligne);
    else S << ligne;  S<< "\n";
//    cout << "Ent.no "<<i<<" No en P "<<thepnum.Value(i)<<
//      " Lignes P:"<<thepnum.Value(i+1)-thepnum.Value(i)<<endl;
//    for (j = 0; j < 17; j ++) S<<v[j]<<" ";
//    S<<res1<<res2<<" label:"<<lab<<" subnum:"<<num<<endl;
    isGood = S.good();
  }
  if(!isGood)
    return isGood;
//  Parameter Section
#ifdef PATIENCELOG
  cout<<" Parameter Section : "<<thepnum.Value(nbd)-1
      <<" lines (* = 1000 lines) "<<flush;
#endif
  
  blancs[MaxcarsP] = '\0';
  for (i = 1; i <= nbd && isGood; i ++) {
    for (Standard_Integer j = thepnum.Value(i); j < thepnum.Value(i+1); j ++) {
      char finlin[20];
      sprintf(finlin," %7.7dP%7.7d",2*i-1,j);
      line = thepars->Value(j);
//      line->LeftJustify(MaxcarsP,' ');  remplace par plus economique ! :

      if (fnes) writefnes (S,line->ToCString());
      else S << line->ToCString();
//      for (Standard_Integer k = line->Length()+1; k <= MaxcarsP; k ++)S<<' ';
      S << &blancs[line->Length()];
      if (fnes) writefnes (S,finlin);
      else S << finlin;  S << endl;
      isGood = S.good();
#ifdef PATIENCELOG
      lignespatience --;
      if (lignespatience <= 0) {  cout<<"*"<<flush;  lignespatience = 1000;  }
#endif
    }
  }
  if(!isGood)
    return isGood;
//  Terminal Section (pas trop compliquee, ma foi)
  sprintf (ligne,
    "S%7dG%7dD%7dP%7d                                        T0000001",
	   nbs,nbg,nbd*2,thepnum.Value(thepnum.Length())-1);
//   12345678- 16- 24- 32  56789 123456789 123456789 123456789 12
  if (fnes) writefnes (S,ligne);
  else S << ligne;  S<< "\n";
  S.flush();
  isGood = S.good();
#ifdef PATIENCELOG
  cout <<"\n Section T (lines counts) : G "<<nbg<<"   D "<<nbd
       <<"   P "<<thepnum.Value(thepnum.Length())-1<<"   T 1"<<endl;
#endif
  return isGood;
}