973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
15 | #include <Dico_DictionaryOfInteger.hxx> |
7fd59977 |
16 | #include <IFSelect_BasicDumper.hxx> |
42cf5bc1 |
17 | #include <IFSelect_Dispatch.hxx> |
18 | #include <IFSelect_GeneralModifier.hxx> |
7fd59977 |
19 | #include <IFSelect_IntParam.hxx> |
42cf5bc1 |
20 | #include <IFSelect_Modifier.hxx> |
7fd59977 |
21 | #include <IFSelect_SelectAnyList.hxx> |
42cf5bc1 |
22 | #include <IFSelect_SelectAnyType.hxx> |
23 | #include <IFSelect_SelectCombine.hxx> |
24 | #include <IFSelect_SelectControl.hxx> |
25 | #include <IFSelect_SelectDeduct.hxx> |
26 | #include <IFSelect_SelectExtract.hxx> |
27 | #include <IFSelect_Selection.hxx> |
28 | #include <IFSelect_SessionDumper.hxx> |
29 | #include <IFSelect_SessionFile.hxx> |
c04c30b3 |
30 | #include <IFSelect_ShareOut.hxx> |
7fd59977 |
31 | #include <IFSelect_Transformer.hxx> |
42cf5bc1 |
32 | #include <IFSelect_WorkSession.hxx> |
33 | #include <Interface_Macros.hxx> |
34 | #include <Message.hxx> |
35 | #include <Message_Messenger.hxx> |
36 | #include <OSD_OpenFile.hxx> |
37 | #include <Standard_Transient.hxx> |
38 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
39 | #include <TCollection_HAsciiString.hxx> |
40 | #include <TColStd_HSequenceOfInteger.hxx> |
41 | |
7fd59977 |
42 | #include <stdio.h> |
7fd59977 |
43 | static int deja = 0; |
44 | |
45 | |
46 | IFSelect_SessionFile::IFSelect_SessionFile |
47 | (const Handle(IFSelect_WorkSession)& WS) |
48 | { |
49 | ClearLines(); |
50 | themode = Standard_False; |
51 | if (!deja) { // au moins celui-la : |
52 | Handle(IFSelect_BasicDumper) basedumper = new IFSelect_BasicDumper; |
53 | deja = 1; |
54 | } |
55 | thedone = Standard_False; |
56 | thelastgen = 0; |
57 | thesess = WS; |
58 | } |
59 | |
60 | IFSelect_SessionFile::IFSelect_SessionFile |
61 | (const Handle(IFSelect_WorkSession)& WS, const Standard_CString filename) |
62 | { |
63 | ClearLines(); |
64 | themode = Standard_True; |
65 | if (!deja) { // au moins celui-la : |
66 | Handle(IFSelect_BasicDumper) basedumper = new IFSelect_BasicDumper; |
67 | deja = 1; |
68 | } |
69 | thedone = Standard_False; |
70 | theownflag = Standard_False; |
71 | thelastgen = 0; |
72 | thesess = WS; |
73 | thedone = (Write (filename) == 0); |
74 | // Close fait par Write (selon les cas) |
75 | } |
76 | |
77 | |
78 | void IFSelect_SessionFile::ClearLines () |
79 | { thelist.Clear(); thenl = 0; } |
80 | |
81 | Standard_Integer IFSelect_SessionFile::NbLines () const |
82 | { return thelist.Length(); } |
83 | |
84 | |
85 | const TCollection_AsciiString& IFSelect_SessionFile::Line |
86 | (const Standard_Integer num) const |
87 | { return thelist.Value(num); } |
88 | |
89 | |
90 | void IFSelect_SessionFile::AddLine (const Standard_CString line) |
91 | { thelist.Append (TCollection_AsciiString(line) ); } |
92 | |
93 | void IFSelect_SessionFile::RemoveLastLine () |
94 | { if (thelist.Length() > 1) thelist.Remove(thelist.Length()); } |
95 | |
96 | |
97 | Standard_Boolean IFSelect_SessionFile::WriteFile |
98 | (const Standard_CString filename) |
99 | { |
94708556 |
100 | FILE* lefic = OSD_OpenFile(filename,"w"); |
7fd59977 |
101 | Standard_Integer nbl = thelist.Length(); |
102 | for (Standard_Integer i = 1; i <= nbl; i ++) |
103 | fprintf (lefic,"%s\n",thelist.Value(i).ToCString()); |
104 | fclose ( lefic ); |
105 | ClearLines(); |
106 | return Standard_True; |
107 | } |
108 | |
109 | Standard_Boolean IFSelect_SessionFile::ReadFile |
110 | (const Standard_CString filename) |
111 | { |
112 | char ligne[201]; |
94708556 |
113 | FILE* lefic = OSD_OpenFile(filename,"r"); |
7fd59977 |
114 | if (!lefic) return Standard_False; |
115 | ClearLines(); |
116 | // read mode : lire les lignes |
117 | // On charge le fichier dans "thelist" |
118 | Standard_Boolean header = Standard_False; |
302f96fb |
119 | for(;;) { |
7fd59977 |
120 | ligne[0] = '\0'; |
98160038 |
121 | if (fgets(ligne,200,lefic) == NULL |
122 | || feof(lefic) != 0) |
123 | { |
124 | break; |
125 | } |
7fd59977 |
126 | if (ligne[0] == '\0') continue; |
127 | // D abord ligne initiale ? |
128 | if (!header) |
129 | { if (!RecognizeFile(ligne)) break; header = Standard_True; } |
130 | ligne[200] = '\0'; // fin forcee ... |
131 | TCollection_AsciiString onemore(ligne); |
132 | thelist.Append(onemore); |
133 | } |
134 | fclose ( lefic ); |
135 | return header; |
136 | } |
137 | |
138 | Standard_Boolean IFSelect_SessionFile::RecognizeFile |
139 | (const Standard_CString headerline) |
140 | { |
141 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
142 | |
143 | SplitLine (headerline); |
144 | if (theline.Length() != 4) { sout<<"File Form Incorrect"<<endl; return Standard_False; } |
145 | Handle(Standard_Type) sesstype = thesess->DynamicType(); |
146 | if (!theline.Value(1).IsEqual("!XSTEP") || |
147 | !theline.Value(2).IsEqual("SESSION") || |
148 | !theline.Value(4).IsEqual(sesstype->Name()) ) |
149 | { sout<<"Lineno."<<thenl<<" : File Header Description Incorrect"<<endl; return Standard_False; } |
150 | // Value(3) definit la VERSION du format de fichier |
151 | return Standard_True; |
152 | } |
153 | |
154 | |
155 | Standard_Integer IFSelect_SessionFile::Write |
156 | (const Standard_CString filename) |
157 | { |
158 | thenewnum = 0; |
159 | Standard_Integer stat = WriteSession(); |
160 | if (stat != 0) return stat; |
161 | stat = WriteEnd(); |
162 | if (stat != 0) return stat; |
163 | return (WriteFile(filename) ? 0 : -1); |
164 | } |
165 | |
166 | Standard_Integer IFSelect_SessionFile::Read |
167 | (const Standard_CString filename) |
168 | { |
169 | if (!ReadFile(filename)) return -1; |
170 | thenewnum = 0; |
171 | Standard_Integer stat = ReadSession(); |
172 | if (stat != 0) return stat; |
173 | stat = ReadEnd(); |
174 | return stat; |
175 | } |
176 | |
177 | |
178 | // ################################################################## |
179 | // ######## WriteSession : Ecriture du contenu ######## |
180 | |
181 | Standard_Integer IFSelect_SessionFile::WriteSession () |
182 | { |
183 | char laligne[200]; |
184 | thedone = Standard_True; |
185 | // ... Preparation Specifique |
186 | thenames.Nullify(); |
187 | Standard_Integer nbidents = thesess->MaxIdent(); |
188 | thenums = new TColStd_HArray1OfInteger (0,nbidents); thenums->Init(0); |
189 | Standard_Integer i; // svv Jan11 2000 : porting on DEC |
190 | for ( i = 1; i <= nbidents; i ++) { |
191 | Handle(Standard_Transient) item = thesess->Item(i); |
192 | if (!item.IsNull()) thenums->SetValue(i,-1); |
193 | } |
194 | |
195 | // ... ECRITURE |
196 | sprintf (laligne,"!XSTEP SESSION V1 %s",thesess->DynamicType()->Name()); |
197 | WriteLine(laligne,'\n'); |
198 | sprintf (laligne,"!GENERALS"); |
199 | WriteLine(laligne,'\n'); |
200 | sprintf (laligne,"ErrorHandle %d", (thesess->ErrorHandle() ? 1 : 0)); |
201 | WriteLine(laligne,'\n'); |
202 | Handle(TColStd_HSequenceOfInteger) idents; |
203 | Standard_Integer nb; |
204 | Handle(TCollection_HAsciiString) name; |
205 | |
206 | idents = thesess->ItemIdents(STANDARD_TYPE(IFSelect_IntParam)); |
207 | nb = idents->Length(); |
208 | if (nb > 0) WriteLine ("!INTEGERS",'\n'); |
209 | Standard_Integer j; // svv Jan11 2000 : porting on DEC |
210 | for (j = 1; j <= nb; j ++) { |
211 | i = idents->Value(j); |
212 | Handle(IFSelect_IntParam) P = thesess->IntParam(i); |
213 | name = thesess->Name(P); |
214 | if (name.IsNull()) { |
215 | thenewnum ++; idents->SetValue(i,thenewnum); |
216 | sprintf(laligne," #%d %d",thenewnum,P->Value()); |
217 | } |
218 | else sprintf(laligne," %s %d",name->ToCString(),P->Value()); |
219 | WriteLine(laligne,'\n'); |
220 | } |
221 | |
222 | idents = thesess->ItemIdents(STANDARD_TYPE(TCollection_HAsciiString)); |
223 | nb = idents->Length(); |
224 | if (nb > 0) WriteLine ("!TEXTS",'\n'); |
225 | for (j = 1; j <= nb; j ++) { |
226 | i = idents->Value(j); |
227 | Handle(TCollection_HAsciiString) P = thesess->TextParam(i); |
228 | name = thesess->Name(P); |
229 | if (name.IsNull()) { |
230 | thenewnum ++; thenums->SetValue(i,thenewnum); |
231 | sprintf(laligne," #%d %s",thenewnum,P->ToCString()); |
232 | } |
233 | else sprintf(laligne," %s %s",name->ToCString(),P->ToCString()); |
234 | WriteLine(laligne,'\n'); |
235 | } |
236 | |
237 | idents = thesess->ItemIdents(STANDARD_TYPE(IFSelect_Selection)); |
238 | nb = idents->Length(); |
239 | if (nb > 0) WriteLine ("!SELECTIONS",'\n'); |
240 | for (j = 1; j <= nb; j ++) { |
241 | i = idents->Value(j); |
242 | Handle(IFSelect_Selection) P = thesess->Selection(i); |
243 | NewItem (i,P); |
244 | // .. Ecritures particulieres |
245 | // -> Traiter les principaux sous-types : Extract,AnyList,AnyType |
246 | DeclareAndCast(IFSelect_SelectExtract,sxt,P); |
247 | if (!sxt.IsNull()) { |
248 | sprintf(laligne," %c", (sxt->IsDirect() ? 'D' : 'R')); |
249 | WriteLine(laligne); |
250 | } |
251 | DeclareAndCast(IFSelect_SelectAnyList,sli,P); |
252 | if (!sli.IsNull()) { |
253 | SetOwn(Standard_False); |
254 | WriteLine(" LIST"); |
255 | SendItem(sli->Lower()); |
256 | SendItem(sli->Upper()); |
257 | SetOwn(Standard_True); |
258 | } |
259 | // .. Ecritures specifiques selon dumpers |
260 | WriteOwn(P); |
261 | WriteLine("",'\n'); |
262 | } |
263 | |
264 | SetOwn(Standard_False); |
265 | if (nb > 0) WriteLine ("!SOURCES",'\n'); |
266 | for (j = 1; j <= nb; j ++) { |
267 | i = idents->Value(j); |
268 | Handle(IFSelect_Selection) P = thesess->Selection(i); |
269 | Standard_Integer nbs = thesess->NbSources(P); |
270 | if (nbs == 0) continue; |
271 | name = thesess->Name(P); |
272 | if (name.IsNull()) sprintf(laligne," #%d %d",thenums->Value(i),nbs); |
273 | else sprintf(laligne," %s %d",name->ToCString(),nbs); |
274 | WriteLine(laligne); |
275 | for (Standard_Integer k = 1; k <= nbs; k ++) |
276 | SendItem (thesess->Source(P,k)); |
277 | WriteLine("",'\n'); |
278 | } |
279 | |
280 | idents = thesess->ItemIdents(STANDARD_TYPE(IFSelect_GeneralModifier)); |
281 | nb = idents->Length(); |
282 | if (nb > 0) WriteLine ("!MODIFIERS",'\n'); |
283 | for (j = 1; j <= nb; j ++) { |
284 | // Description de base des Modifiers, donc sans Selection ni Dispatch-Rank |
285 | i = idents->Value(j); |
286 | Handle(IFSelect_GeneralModifier) P = thesess->GeneralModifier(i); |
287 | NewItem (i,P); |
288 | SetOwn(Standard_True); |
289 | // .. Ecritures specifiques selon dumpers |
290 | WriteOwn(P); |
291 | WriteLine("",'\n'); |
292 | } |
293 | |
294 | idents = thesess->ItemIdents(STANDARD_TYPE(IFSelect_Transformer)); |
295 | nb = idents->Length(); |
296 | if (nb > 0) WriteLine ("!TRANSFORMERS",'\n'); |
297 | for (j = 1; j <= nb; j ++) { |
298 | // Description des Transformers |
299 | i = idents->Value(j); |
300 | Handle(IFSelect_Transformer) P = thesess->Transformer(i); |
301 | NewItem (i,P); |
302 | SetOwn(Standard_True); |
303 | // .. Ecritures specifiques selon dumpers |
304 | WriteOwn(P); |
305 | WriteLine("",'\n'); |
306 | } |
307 | |
308 | SetOwn(Standard_False); |
309 | idents = thesess->ItemIdents(STANDARD_TYPE(IFSelect_Dispatch)); |
310 | nb = idents->Length(); |
311 | if (nb > 0) WriteLine ("!DISPATCHES",'\n'); |
312 | for (j = 1; j <= nb; j ++) { |
313 | i = idents->Value(j); |
314 | Handle(IFSelect_Dispatch) P = thesess->Dispatch(i); |
315 | NewItem (i,P); |
316 | // .. Final Selection |
317 | SetOwn(Standard_False); |
318 | SendItem(P->FinalSelection()); |
319 | SetOwn(Standard_True); |
320 | // .. Ecritures specifiques selon dumpers |
321 | WriteOwn(P); |
322 | WriteLine("",'\n'); |
323 | } |
324 | |
325 | WriteLine ("!FILENAMING"); |
326 | SetOwn(Standard_False); |
327 | Handle(TCollection_HAsciiString) namingpart = thesess->FilePrefix(); |
328 | if (namingpart->IsEmpty()) namingpart.Nullify(); |
329 | if (namingpart.IsNull()) SendVoid(); |
330 | else SendText(namingpart->ToCString()); |
331 | namingpart = thesess->DefaultFileRoot(); |
332 | if (namingpart->IsEmpty()) namingpart.Nullify(); |
333 | if (namingpart.IsNull()) SendVoid(); |
334 | else SendText(namingpart->ToCString()); |
335 | namingpart = thesess->FileExtension(); |
336 | if (namingpart->IsEmpty()) namingpart.Nullify(); |
337 | if (namingpart.IsNull()) SendVoid(); |
338 | else SendText(namingpart->ToCString()); |
339 | WriteLine("",'\n'); |
340 | |
341 | for (j = 1; j <= nb; j ++) { |
342 | i = idents->Value(j); |
343 | Handle(IFSelect_Dispatch) P = thesess->Dispatch(i); |
344 | if (!P->HasRootName()) continue; |
345 | namingpart = P->RootName(); |
346 | SetOwn(Standard_False); |
347 | SendItem(P); |
348 | sprintf(laligne," %s",namingpart->ToCString()); |
349 | WriteLine(laligne,' '); |
350 | WriteLine("",'\n'); |
351 | } |
352 | |
353 | // Pour les Modifiers, ATTENTION car il faut respecter l ORDRE effectif |
354 | // Or il y a deux listes : Model Modifiers; File Modifiers |
355 | // Les Modifiers eux-memes ont deja ete ecrits |
356 | // Ici, on ecrit simplement leur utilisation dans l envoi final |
357 | for (Standard_Integer formod = 1; formod >= 0; formod --) { |
358 | idents = thesess->FinalModifierIdents((formod > 0)); // donnes dans l ordre d application |
359 | nb = idents->Length(); |
360 | if (nb == 0) continue; |
361 | if (formod > 0) WriteLine ("!MODELMODIFIERS",'\n'); |
362 | else WriteLine ("!FILEMODIFIERS",'\n'); |
363 | for (j = 1; j <= nb; j ++) { |
364 | i = idents->Value(j); |
365 | Handle(IFSelect_GeneralModifier) P = thesess->GeneralModifier(i); |
366 | SetOwn(Standard_False); |
367 | SendItem(P); |
368 | // .. Parametres Generaux (les specifiques ont deja ete envoyes) |
369 | SendItem(P->Selection()); |
370 | SendItem(P->Dispatch()); |
371 | WriteLine("",'\n'); |
372 | } |
373 | } |
374 | |
375 | // ... Conclusion |
376 | theline.Clear(); |
377 | return 0; |
378 | } |
379 | |
380 | Standard_Integer IFSelect_SessionFile::WriteEnd () |
381 | { |
382 | WriteLine("!XSTEP END",'\n'); // sinon, cf sous-types de SessionFile ... |
383 | return 0; |
384 | } |
385 | |
386 | |
387 | void IFSelect_SessionFile::WriteLine |
388 | (const Standard_CString line, const Standard_Character follow) |
389 | { |
390 | if (line[0] != '\0') thebuff.AssignCat (line); |
391 | if (follow == '\0') return; |
392 | if (follow != '\n') thebuff.AssignCat(follow); |
393 | else { |
394 | thelist.Append(thebuff); |
395 | thebuff.Clear(); |
396 | thenl ++; |
397 | } |
398 | } |
399 | |
400 | Standard_Boolean IFSelect_SessionFile::WriteOwn |
401 | (const Handle(Standard_Transient)& item) |
402 | { |
403 | if (item.IsNull()) return Standard_False; |
404 | SetOwn(Standard_True); |
405 | Handle(IFSelect_SessionDumper) dumper = IFSelect_SessionDumper::First(); |
406 | while (!dumper.IsNull()) { |
407 | if (dumper->WriteOwn(*this,item)) break; |
408 | dumper = dumper->Next(); |
409 | } |
410 | SetOwn(Standard_False); |
411 | return (!dumper.IsNull()); // IsNull -> echec |
412 | } |
413 | |
414 | |
415 | |
416 | // ################################################################## |
417 | // ######## ReadSession : Lecture du contenu ######## |
418 | |
419 | Standard_Integer IFSelect_SessionFile::ReadSession () |
420 | { |
421 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
422 | |
423 | thedone = Standard_True; |
424 | // ... Preparation Specifique |
425 | thenums.Nullify(); |
426 | thenames = new Dico_DictionaryOfInteger; |
427 | // .. Donnees generales, controle |
428 | if (!ReadLine()) return 1; |
429 | if (theline.Length() != 4) { sout<<"File Form Incorrect"<<endl; return 1; } |
430 | Handle(Standard_Type) sesstype = thesess->DynamicType(); |
431 | if (!theline.Value(1).IsEqual("!XSTEP") || |
432 | !theline.Value(2).IsEqual("SESSION") || |
433 | !theline.Value(4).IsEqual(sesstype->Name()) ) |
434 | { sout<<"Lineno."<<thenl<<" : File Header Description Incorrect"<<endl; return 1; } |
435 | // Value(3) definit la VERSION du format de fichier |
436 | if (!ReadLine()) return 1; |
437 | |
438 | // .. Parametres Generaux |
439 | Standard_Integer rubr = |
440 | (theline.Length() == 1 && theline.Value(1).IsEqual("!GENERALS")); |
441 | while (rubr) { |
442 | if (!ReadLine()) return 1; |
443 | if (theline.Length() == 0) continue; |
444 | const TCollection_AsciiString& ungen = theline.Value(1); |
445 | if (ungen.Value(1) == '!') break; // fin des generaux |
446 | if (ungen.IsEqual("ErrorHandle")) { |
447 | if (theline.Length() != 2) |
448 | { sout<<"Lineno."<<thenl<<" : ErrorHandle Description Incorrect"<<endl; continue; } |
449 | if (theline.Value(2).IsEqual("0")) |
450 | thesess->SetErrorHandle(Standard_False); |
451 | else if (theline.Value(2).IsEqual("1")) |
452 | thesess->SetErrorHandle(Standard_True); |
453 | else { sout<<"Lineno."<<thenl<<" : ErrorHandle Incorrect : "<<theline.Value(2)<<endl; continue; } |
454 | continue; |
455 | } |
456 | else sout<<"Lineno."<<thenl<<" : Unknown General Parameter : "<<ungen<<" , ignored"<<endl; |
457 | } |
458 | |
459 | // .. IntParams |
460 | // deja fait if (!ReadLine()) return 1; |
461 | rubr = (theline.Length() == 1 && theline.Value(1).IsEqual("!INTEGERS")); |
462 | while (rubr) { |
463 | if (!ReadLine()) return 1; |
464 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
465 | if (theline.Length() != 2) |
466 | { sout<<"Lineno."<<thenl<<" : An Integer Parameter is badly defined"<<endl; continue; } |
467 | Handle(IFSelect_IntParam) par = new IFSelect_IntParam; |
468 | par->SetValue ( atoi(theline.Value(2).ToCString()) ); |
469 | AddItem (par); |
470 | } |
471 | |
472 | // .. TextParams (ligne de garde deja lue) |
473 | rubr = (theline.Length() == 1 && theline.Value(1).IsEqual("!TEXTS")); |
474 | while (rubr) { |
475 | if (!ReadLine()) return 1; |
476 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
477 | if (theline.Length() != 2) |
478 | { sout<<"Lineno."<<thenl<<" : A Text Parameter is badly defined"<<endl; continue; } |
479 | // Attention, un texte peut contenir des blancs ... repartir de line(thenl) |
480 | TCollection_AsciiString oneline = thelist.Value(thenl); |
481 | Standard_Integer iw = 0, inc = 0; |
482 | for (Standard_Integer ic = 1; ic <= oneline.Length(); ic ++) { |
483 | char unc = oneline.Value(1); |
484 | inc = ic; |
485 | if (unc == ' ') iw = 1; |
486 | else if (iw > 0) break; |
487 | } |
488 | oneline.Remove (1,inc); |
489 | AddItem ( new TCollection_HAsciiString (oneline.ToCString()) ); |
490 | } |
491 | |
492 | // .. Selections (ligne de garde deja lue) |
493 | rubr = (theline.Length() == 1 && theline.Value(1).IsEqual("!SELECTIONS")); |
494 | while (rubr) { |
495 | if (!ReadLine()) return 1; |
496 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
497 | if (theline.Length() < 2) |
498 | { sout<<"Lineno."<<thenl<<" : A Selection is badly defined"<<endl; continue; } |
499 | // .. Analyse de certains cas generaux |
500 | Handle(IFSelect_IntParam) low,up; |
501 | Standard_Integer firstown = 3; |
502 | Standard_Integer direct = 0; |
503 | Standard_Integer numlist = 0; |
504 | if (theline.Length() > 2) { |
505 | if (theline.Value(3).IsEqual("D")) direct = 1; |
506 | else if (theline.Value(3).IsEqual("R")) direct = -1; |
507 | if (direct != 0) firstown ++; |
508 | if (firstown+2 <= theline.Length()) { |
509 | if (theline.Value(firstown).IsEqual("LIST")) { |
510 | numlist = firstown; firstown += 3; |
511 | low = GetCasted(IFSelect_IntParam,ItemValue(numlist+1)); |
512 | up = GetCasted(IFSelect_IntParam,ItemValue(numlist+2)); |
513 | } |
514 | } |
515 | SetLastGeneral (firstown-1); |
516 | } |
517 | Handle(Standard_Transient) item; // a fournir ... |
518 | ReadOwn(item); |
519 | if (item.IsNull()) continue; |
520 | DeclareAndCast(IFSelect_SelectExtract,sxt,item); |
521 | if (!sxt.IsNull()) { |
522 | if (direct == 0) sout<<"Lineno."<<thenl<<" : A SelectExtract is badly defined"<<endl; |
523 | else sxt->SetDirect( (direct > 0) ); |
524 | } |
525 | DeclareAndCast(IFSelect_SelectAnyList,sli,item); |
526 | if (!sli.IsNull()) { |
527 | if (numlist == 0) sout<<"Lineno."<<thenl<<" : A SelectAnyList is badly defined"<<endl; |
528 | else sli->SetRange(low,up); |
529 | } |
530 | AddItem(item); |
531 | } |
532 | |
533 | // .. Sources |
534 | rubr = (theline.Length() == 1 && theline.Value(1).IsEqual("!SOURCES")); |
535 | while (rubr) { |
536 | if (!ReadLine()) return 1; |
537 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
538 | if (theline.Length() < 3) |
539 | { sout<<"Lineno."<<thenl<<" : A Selection Source List is badly defined"<<endl; continue; } |
540 | DeclareAndCast(IFSelect_Selection,sel,ItemValue(1)); |
541 | if (sel.IsNull()) |
542 | { sout<<"Lineno."<<thenl<<" : A Source List is not for a Selection"<<endl; continue; } |
543 | Standard_Integer nbs = atoi(theline.Value(2).ToCString()); |
544 | // .. Differents cas reconnus |
545 | DeclareAndCast(IFSelect_SelectExtract,sxt,sel); |
546 | if (!sxt.IsNull()) { |
547 | if (nbs > 1) |
548 | sout<<"Lineno."<<thenl<<" : SelectExtract, more than one source, followings ignored"<<endl; |
549 | DeclareAndCast(IFSelect_Selection,source,ItemValue(3)); |
550 | sxt->SetInput(source); |
551 | } |
552 | DeclareAndCast(IFSelect_SelectDeduct,sdt,sel); |
553 | if (!sdt.IsNull()) { |
554 | if (nbs > 1) |
555 | sout<<"Lineno."<<thenl<<" : SelectDeduct, more than one source, followings ignored"<<endl; |
556 | sdt->SetInput(GetCasted(IFSelect_Selection,ItemValue(3))); |
557 | } |
558 | DeclareAndCast(IFSelect_SelectControl,sct,sel); |
559 | if (!sct.IsNull()) { |
560 | if (nbs != 2) |
561 | sout<<"Lineno."<<thenl<<" : SelectControl, not two sources, followings ignored"<<endl; |
562 | sct->SetMainInput (GetCasted(IFSelect_Selection,ItemValue(3))); |
563 | sct->SetSecondInput (GetCasted(IFSelect_Selection,ItemValue(4))); |
564 | } |
565 | DeclareAndCast(IFSelect_SelectCombine,sco,sel); |
566 | if (!sco.IsNull()) { |
567 | for (Standard_Integer j = 1; j <= nbs; j ++) |
568 | sco->Add(GetCasted(IFSelect_Selection,ItemValue(j+2))); |
569 | } |
570 | } |
571 | |
572 | // ... Modifiers en tout genre |
573 | rubr = (theline.Length() == 1 && theline.Value(1).IsEqual("!MODIFIERS")); |
574 | while (rubr) { |
575 | if (!ReadLine()) return 1; |
576 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
577 | if (theline.Length() < 2) |
578 | { sout<<"Lineno."<<thenl<<" : A Modifier is badly defined"<<endl; continue; } |
579 | Handle(Standard_Transient) item; // a fournir ... |
580 | ReadOwn(item); |
581 | if (item.IsNull()) continue; |
582 | DeclareAndCast(IFSelect_GeneralModifier,modif,item); |
583 | if (modif.IsNull()) |
584 | { sout<<"Lineno."<<thenl<<" : A Modifier has not been Recognized"<<endl; continue; } |
585 | AddItem(modif,Standard_False); // active plus tard |
586 | } |
587 | |
588 | // ... Transformers |
589 | rubr = (theline.Length() == 1 && theline.Value(1).IsEqual("!TRANSFORMERS")); |
590 | while (rubr) { |
591 | if (!ReadLine()) return 1; |
592 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
593 | if (theline.Length() < 2) |
594 | { sout<<"Lineno."<<thenl<<" : A Transformer is badly defined"<<endl; continue; } |
595 | Handle(Standard_Transient) item; // a fournir ... |
596 | ReadOwn(item); |
597 | if (item.IsNull()) continue; |
598 | DeclareAndCast(IFSelect_Transformer,trf,item); |
599 | if (trf.IsNull()) |
600 | { sout<<"Lineno."<<thenl<<" : A Transformer has not been Recognized"<<endl; continue; } |
601 | AddItem(trf,Standard_False); // active plus tard |
602 | } |
603 | |
604 | // ... Dispatches (ligne de garde deja lue) |
605 | rubr = (theline.Length() == 1 && theline.Value(1).IsEqual("!DISPATCHES")); |
606 | while (rubr) { |
607 | if (!ReadLine()) return 1; |
608 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
609 | if (theline.Length() < 3) |
610 | { sout<<"Lineno."<<thenl<<" : A Dispatch is badly defined"<<endl; continue; } |
611 | DeclareAndCast(IFSelect_Selection,input,ItemValue(3)); |
612 | SetLastGeneral(3); |
613 | Handle(Standard_Transient) item; // a fournir ... |
614 | ReadOwn(item); |
615 | if (item.IsNull()) continue; |
616 | DeclareAndCast(IFSelect_Dispatch,disp,item); |
617 | if (disp.IsNull()) |
618 | { sout<<"Lineno."<<thenl<<" : A Dispatch has not been Recognized"<<endl; continue; } |
619 | AddItem(disp); |
620 | thesess->SetItemSelection(disp,input); |
621 | } |
622 | |
623 | // ... FileNaming (ligne de garde deja lue) |
624 | // .. Modifiers deja lus et charges |
625 | rubr = (theline.Length() == 4 && theline.Value(1).IsEqual("!FILENAMING")); |
626 | if (rubr) { |
627 | if (!IsVoid(2)) thesess->SetFilePrefix (TextValue(2).ToCString()); |
628 | if (!IsVoid(3)) thesess->SetDefaultFileRoot (TextValue(3).ToCString()); |
629 | if (!IsVoid(4)) thesess->SetFileExtension (TextValue(4).ToCString()); |
630 | } |
631 | while (rubr) { |
632 | if (!ReadLine()) return 1; |
633 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
634 | if (theline.Length() != 2) |
635 | { sout<<"Lineno."<<thenl<<" : A File Root is badly defined"<<endl; continue; } |
636 | DeclareAndCast(IFSelect_Dispatch,disp,ItemValue(1)); |
637 | thesess->SetFileRoot (disp,theline.Value(2).ToCString()); |
638 | } |
639 | |
640 | // ... Modifiers (ligne de garde deja lue) |
641 | // ... Attention, deux listes (MODELMODIFIERS et FILEMODIFIERS) |
642 | for (Standard_Integer formod = 1; formod >= 0; formod --) { |
643 | rubr = (theline.Length() == 1 && |
644 | ( (formod == 1 && theline.Value(1).IsEqual("!MODELMODIFIERS")) || |
645 | (formod == 0 && theline.Value(1).IsEqual("!FILEMODIFIERS")) ) ); |
646 | // if ( formod == 1 && ( theline.Length() != 1 || |
647 | // !theline.Value(1).IsEqual("!MODELMODIFIERS")) ) |
648 | // { sout<<"Lineno."<<thenl<<" : Model Modifier List Incorrect"<<endl; return 1; } |
649 | // if ( formod == 0 && ( theline.Length() != 1 || |
650 | // !theline.Value(1).IsEqual("!FILEMODIFIERS")) ) |
651 | // { sout<<"Lineno."<<thenl<<" : File Modifier List Incorrect"<<endl; return 1; } |
652 | while (rubr) { |
653 | if (!ReadLine()) return 1; |
654 | if (theline.Value(1).Value(1) == '!') break; // liste suivante |
655 | if (theline.Length() < 3) |
656 | { sout<<"Lineno."<<thenl<<" : A General Modifier is badly defined"<<endl; continue; } |
657 | DeclareAndCast(IFSelect_GeneralModifier,modif,ItemValue(1)); |
658 | DeclareAndCast(IFSelect_Selection,input,ItemValue(2)); |
659 | DeclareAndCast(IFSelect_Dispatch,disp,ItemValue(3)); |
660 | if (modif.IsNull()) |
661 | { sout<<"Lineno."<<thenl<<" : A General Modifier has not been Recognized"<<endl; continue; } |
662 | thesess->SetItemSelection (modif,input); |
663 | if (!disp.IsNull()) thesess->SetAppliedModifier (modif,disp); |
664 | else thesess->SetAppliedModifier (modif,thesess->ShareOut()); |
665 | } |
666 | } |
667 | |
668 | // ... Conclusion : voir ReadEnd (separe) |
669 | return 0; |
670 | } |
671 | |
672 | Standard_Integer IFSelect_SessionFile::ReadEnd () |
673 | { |
674 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
675 | if ( theline.Length() != 2 || |
676 | !theline.Value(1).IsEqual("!XSTEP") || |
677 | !theline.Value(2).IsEqual("END")) |
678 | { sout<<"End of File Incorrect, lineno"<<thenl<<endl; return 1; } |
679 | return 0; |
680 | } |
681 | |
682 | |
683 | Standard_Boolean IFSelect_SessionFile::ReadLine () |
684 | { |
685 | if (thenl >= thelist.Length()) return Standard_False; |
686 | thenl ++; |
687 | Standard_CString ligne = thelist.Value(thenl).ToCString(); |
688 | // Lignes vides ? |
689 | if (ligne[0] == '\0') return ReadLine(); |
690 | SplitLine (ligne); |
691 | return Standard_True; |
692 | } |
693 | |
694 | |
695 | void IFSelect_SessionFile::SplitLine (const Standard_CString line) |
696 | { |
697 | char mot[80]; |
698 | theline.Clear(); |
699 | Standard_Integer nbc = 0; |
700 | Standard_Boolean word = (line[0] > ' '); |
701 | for (Standard_Integer i = 0; line[i] != '\0'; i ++) { |
702 | if (line[i] > ' ') { |
703 | if (!word) { nbc = 0; word = Standard_True; } |
704 | mot[nbc] = line[i]; nbc ++; |
705 | } else { |
706 | if (word) { |
707 | word = Standard_False; |
708 | mot[nbc] = '\0'; |
709 | theline.Append (TCollection_AsciiString(mot)); |
710 | } |
711 | if (line[i] == '\0' || line[i] == '\n') break; |
712 | } |
713 | } |
714 | thelastgen = 0; |
715 | } |
716 | |
717 | Standard_Boolean IFSelect_SessionFile::ReadOwn |
718 | (Handle(Standard_Transient)& item) |
719 | { |
720 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
721 | |
722 | if (theline.Length() < 2) return Standard_False; |
723 | const TCollection_AsciiString& type = theline.Value(2); |
724 | if (thelastgen < 2) thelastgen = 2; // mini : ident+type d abord |
725 | // thelastgen = theline.Length(); |
726 | // for (Standard_Integer i = theline.Length(); i > 0; i --) { |
727 | // if (theline.Value(i).Value(1) == ':') thelastgen = i - 1; |
728 | // } |
729 | Handle(IFSelect_SessionDumper) dumper = IFSelect_SessionDumper::First(); |
730 | while (!dumper.IsNull()) { |
731 | if (dumper->ReadOwn(*this,type,item)) break; |
732 | dumper = dumper->Next(); |
733 | } |
734 | if (dumper.IsNull()) sout<<" -- Lineno."<<thenl<<" : an Item could not be read"<<endl; |
735 | return (!dumper.IsNull()); // IsNull -> echec |
736 | } |
737 | |
738 | |
739 | void IFSelect_SessionFile::AddItem |
740 | (const Handle(Standard_Transient)& item, const Standard_Boolean active) |
741 | { |
742 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
743 | |
744 | const TCollection_AsciiString& name = theline.Value(1); |
745 | Standard_Integer id = 0; |
746 | if (!item.IsNull()) { |
747 | if (name.Value(1) == '#') id = thesess->AddItem(item,active); |
748 | else if (!thesess->NamedItem(name.ToCString()).IsNull()) id = |
749 | thesess->AddItem(item,active); |
750 | else id = thesess->AddNamedItem(name.ToCString(),item,active); |
751 | } |
752 | else sout<<"Lineno."<<thenl<<" -- Name : "<<name |
753 | <<" : Item could not be defined" << endl; |
754 | thenames->SetItem(name.ToCString(),id); |
755 | } |
756 | |
757 | Standard_Boolean IFSelect_SessionFile::IsDone () const |
758 | { return thedone; } |
759 | |
760 | Handle(IFSelect_WorkSession) IFSelect_SessionFile::WorkSession () const |
761 | { return thesess; } |
762 | |
763 | // ######## Actions Unitaires d ECRITURE ######## |
764 | |
765 | void IFSelect_SessionFile::NewItem |
766 | (const Standard_Integer ident, const Handle(Standard_Transient)& par) |
767 | { |
768 | char laligne[100]; |
769 | if (!thesess->HasName(par)) { |
770 | thenewnum ++; thenums->SetValue(ident,thenewnum); |
771 | sprintf(laligne," #%d %s",thenewnum,par->DynamicType()->Name()); |
772 | } |
773 | else sprintf(laligne," %s %s",thesess->Name(par)->ToCString(), |
774 | par->DynamicType()->Name()); |
775 | WriteLine(laligne); |
776 | } |
777 | |
778 | void IFSelect_SessionFile::SetOwn (const Standard_Boolean mode) |
779 | { theownflag = mode; } |
780 | |
781 | void IFSelect_SessionFile::SendVoid () |
782 | { |
783 | //// if (theownflag) WriteLine(" :$"); |
784 | WriteLine(" $"); |
785 | } |
786 | |
787 | void IFSelect_SessionFile::SendItem (const Handle(Standard_Transient)& par) |
788 | { |
789 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
790 | |
791 | char laligne[100]; |
792 | Standard_Integer filenum = 0; |
793 | Standard_Integer id = thesess->ItemIdent(par); |
794 | if (id != 0) filenum = thenums->Value(id); |
795 | if (filenum == 0) { |
796 | if (!par.IsNull()) sout << "Lineno " << thenl << " -- Unknown Item : " |
797 | << " Type:" << par->DynamicType()->Name() << endl; //sout<<Handle par |
798 | SendVoid(); |
799 | thedone = Standard_False; |
800 | return; |
801 | } |
802 | //// if (theownflag) WriteLine(" :"); |
803 | //// else WriteLine(" "); |
804 | if (filenum < 0) sprintf(laligne," :%s",thesess->Name(par)->ToCString()); |
805 | else sprintf(laligne," #%d",filenum); |
806 | WriteLine(laligne); |
807 | } |
808 | |
809 | void IFSelect_SessionFile::SendText (const Standard_CString text) |
810 | { |
811 | char laligne[100]; |
812 | //// if (theownflag) sprintf(laligne," :%s",text); |
813 | sprintf(laligne," %s",text); |
814 | WriteLine(laligne); |
815 | } |
816 | |
817 | |
818 | // ######## Actions Unitaires de LECTURE ######## |
819 | |
820 | void IFSelect_SessionFile::SetLastGeneral (const Standard_Integer lastgen) |
821 | { thelastgen = lastgen; } |
822 | |
823 | Standard_Integer IFSelect_SessionFile::NbParams () const |
824 | { return theline.Length() - thelastgen; } |
825 | |
826 | |
827 | Standard_Boolean IFSelect_SessionFile::IsVoid |
828 | (const Standard_Integer num) const |
829 | { |
830 | Standard_Integer nm = num + thelastgen; |
831 | if (nm <= 0 || nm > theline.Length()) return Standard_True; |
832 | const TCollection_AsciiString& term = theline.Value(nm); |
833 | return (term.IsEqual ("$") || term.IsEqual (":$") ); |
834 | } |
835 | |
836 | Standard_Boolean IFSelect_SessionFile::IsText |
837 | (const Standard_Integer num) const |
838 | { |
839 | Standard_Integer nm = num + thelastgen; |
840 | if (nm <= 0 || nm > theline.Length()) return Standard_False; |
841 | const TCollection_AsciiString& term = theline.Value(nm); |
842 | if (term.Value(1) == ':') return Standard_False; |
843 | if (term.Value(1) == '#') return Standard_False; |
844 | if (term.IsEqual("$")) return Standard_False; |
845 | return Standard_True; |
846 | } |
847 | |
848 | const TCollection_AsciiString& IFSelect_SessionFile::ParamValue |
849 | (const Standard_Integer num) const |
850 | { return theline.Value(num+thelastgen); } |
851 | |
852 | |
853 | TCollection_AsciiString IFSelect_SessionFile::TextValue |
854 | (const Standard_Integer num) const |
855 | { |
856 | Standard_Integer nm = num + thelastgen; |
857 | TCollection_AsciiString res; |
858 | if (nm <= 0 || nm > theline.Length()) return res; |
859 | res = theline.Value(nm); |
860 | if (res.Value( res.Length() ) == '"') res.Remove(res.Length()); |
861 | if (res.Value(1) == ':') res.Remove(1); |
862 | if (res.Value(1) == '"') res.Remove(1); |
863 | return res; |
864 | } |
865 | |
866 | Handle(Standard_Transient) IFSelect_SessionFile::ItemValue |
867 | (const Standard_Integer num) const |
868 | { |
869 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
870 | |
871 | Handle(Standard_Transient) res; |
872 | Standard_Integer nm = num + thelastgen; |
873 | if (nm <= 0 || nm > theline.Length()) return res; |
874 | Standard_Integer id; |
875 | TCollection_AsciiString name = theline.Value(nm); |
876 | if (name.Value(1) == ':') name.Remove(1); |
877 | if (name.IsEqual("$")) return res; // item non-defini justement |
878 | if (!thenames->GetItem(name.ToCString(),id)) { |
879 | sout << " -- Item Unknown in File : " << name |
880 | << " lineno " << thenl << " param." << nm << endl; |
881 | id = 0; |
882 | } |
883 | return thesess->Item(id); |
884 | } |
885 | |
886 | |
887 | void IFSelect_SessionFile::Destroy () |
888 | { } // agit si File non ferme, sinon ne fait rien |