0023570: Command param in DRAW outputs non-readable symbols
[occt.git] / src / MoniTool / MoniTool_TypedValue.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <MoniTool_TypedValue.ixx>
19
20 #include <Dico_DictionaryOfInteger.hxx>
21 #include <Dico_IteratorOfDictionaryOfInteger.hxx>
22 #include <Dico_DictionaryOfTransient.hxx>
23 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
24 #include <MoniTool_Element.hxx>
25 #include <Message_Messenger.hxx>
26
27 #include <OSD_Path.hxx>
28 #include <stdio.h>
29
30
31
32 // Not Used :
33 //static  char defmess[30];
34
35 static Handle(Dico_DictionaryOfTransient) libtv()
36 {
37   static Handle(Dico_DictionaryOfTransient) thelibtv;
38   if (thelibtv.IsNull()) {
39     thelibtv = new Dico_DictionaryOfTransient;
40     Handle(MoniTool_TypedValue) tv;
41     tv = new MoniTool_TypedValue("Integer",MoniTool_ValueInteger);
42     thelibtv->SetItem ("Integer",tv);
43     tv = new MoniTool_TypedValue("Real",MoniTool_ValueReal);
44     thelibtv->SetItem ("Real",tv);
45     tv = new MoniTool_TypedValue("Text",MoniTool_ValueText);
46     thelibtv->SetItem ("Text",tv);
47     tv = new MoniTool_TypedValue("Transient",MoniTool_ValueIdent);
48     thelibtv->SetItem ("Transient",tv);
49     tv = new MoniTool_TypedValue("Boolean",MoniTool_ValueEnum);
50     tv->AddDef ("enum 0");    //    = 0 False  ,  > 0 True
51     tv->AddDef ("eval False");
52     tv->AddDef ("eval True");
53     thelibtv->SetItem ("Boolean",tv);
54     tv = new MoniTool_TypedValue("Logical",MoniTool_ValueEnum);
55     tv->AddDef ("enum -1");    //    < 0 False  ,  = 0 Unk  ,  > 0 True
56     tv->AddDef ("eval False");
57     tv->AddDef ("eval Unknown");
58     tv->AddDef ("eval True");
59     thelibtv->SetItem ("Logical",tv);
60   }
61   return thelibtv;
62 }
63
64
65 //  Fonctions Satisfies offertes en standard ...
66 /* Not Used
67
68 static Standard_Boolean StaticPath(const Handle(TCollection_HAsciiString)& val)
69 {
70   OSD_Path apath;
71   return apath.IsValid (TCollection_AsciiString(val->ToCString()));
72 }
73 */
74
75     MoniTool_TypedValue::MoniTool_TypedValue
76   (const Standard_CString name,
77    const MoniTool_ValueType type, const Standard_CString init)
78     : thename (name) , thetype (type) ,
79       thelims (0), themaxlen (0) , theintlow (0) , theintup (-1) ,
80       theinterp (NULL) , thesatisf (NULL) , 
81       theival (0),
82       thehval (new TCollection_HAsciiString(""))
83 {
84   if (type != MoniTool_ValueInteger && type != MoniTool_ValueReal &&
85       type != MoniTool_ValueEnum    && type != MoniTool_ValueText &&
86       type != MoniTool_ValueIdent)
87     Standard_ConstructionError::Raise("MoniTool_TypedValue : Type not supported");
88   if (init[0] != '\0')
89     if (Satisfies(new TCollection_HAsciiString(init))) SetCStringValue (init);
90
91 }
92
93
94     MoniTool_TypedValue::MoniTool_TypedValue
95   (const Handle(MoniTool_TypedValue)& other)
96     : thename  (other->Name()) , thedef (other->Definition()) ,
97       thelabel (other->Label()) , thetype (other->ValueType()) ,
98       theotyp  (other->ObjectType()) ,
99       thelims (0) , themaxlen (other->MaxLength()) ,
100       theintlow (0) , theintup (0) , therealow (0) , therealup (0) ,
101       theunidef (other->UnitDef()) ,
102       theival  (other->IntegerValue()) ,  thehval  (other->HStringValue()) ,
103       theoval  (other->ObjectValue())
104 {
105   Handle(Dico_DictionaryOfInteger) eadds;
106   Standard_CString satisname;
107   other->Internals (theinterp,thesatisf,satisname, eadds);
108   thesatisn.AssignCat (satisname);
109
110   if (other->IntegerLimit (Standard_False,theintlow)) thelims |= 1;
111   if (other->IntegerLimit (Standard_True ,theintup )) thelims |= 2;
112   if (other->RealLimit    (Standard_False,therealow)) thelims |= 1;
113   if (other->RealLimit    (Standard_True ,therealup)) thelims |= 2;
114
115   Standard_Integer startcase, endcase; Standard_Boolean match;
116   if (other->EnumDef (startcase,endcase,match)) {
117     theintlow = startcase;  theintup = endcase;
118     if (match) thelims |= 4;
119     if (theintup >= theintlow) theenums = new TColStd_HArray1OfAsciiString (theintlow,theintup);
120     for (startcase = theintlow; startcase <= theintup; startcase ++) {
121       theenums->SetValue (startcase,other->EnumVal (startcase));
122     }
123   }
124 //  dupliquer theeadds
125   if (!eadds.IsNull()) {
126     theeadds = new Dico_DictionaryOfInteger;
127     Dico_IteratorOfDictionaryOfInteger itad (eadds);
128     for (; itad.More(); itad.Next()) theeadds->SetItem (itad.Name(),itad.Value());
129   }
130
131 //  on duplique la string
132   if (!thehval.IsNull()) thehval = new TCollection_HAsciiString (other->CStringValue());
133 }
134
135
136     void  MoniTool_TypedValue::Internals
137   (MoniTool_ValueInterpret& interp, MoniTool_ValueSatisfies& satisf,
138    Standard_CString& satisname,
139    Handle(Dico_DictionaryOfInteger)& enums) const
140 {  interp = theinterp; satisf = thesatisf; satisname = thesatisn.ToCString();
141    enums = theeadds;  }
142
143     Standard_CString  MoniTool_TypedValue::Name   () const
144       {  return thename.ToCString();    }
145
146     MoniTool_ValueType  MoniTool_TypedValue::ValueType () const
147       {  return thetype;  }
148
149     TCollection_AsciiString  MoniTool_TypedValue::Definition () const
150 {
151   if (thedef.Length() > 0) return thedef;
152   TCollection_AsciiString def;
153   char mess[50];
154   switch (thetype) {
155     case MoniTool_ValueInteger : {
156       def.AssignCat("Integer");
157       Standard_Integer ilim;
158       if (IntegerLimit(Standard_False, ilim)) {
159         Sprintf(mess,"  >= %d",ilim);
160         def.AssignCat(mess);
161       }
162       if (IntegerLimit(Standard_True,  ilim)) {
163         Sprintf(mess,"  <= %d",ilim);
164         def.AssignCat(mess);
165       }
166     }
167       break;
168     case MoniTool_ValueReal    : {
169       def.AssignCat("Real");
170       Standard_Real rlim;
171       if (RealLimit(Standard_False, rlim)) {
172         Sprintf(mess,"  >= %f",rlim);
173         def.AssignCat(mess);
174       }
175       if (RealLimit(Standard_True,  rlim)) {
176         Sprintf(mess,"  <= %f",rlim);
177         def.AssignCat(mess);
178       }
179       if (theunidef.Length() > 0)
180         {  def.AssignCat("  Unit:");  def.AssignCat(UnitDef());  }
181     }
182       break;
183     case MoniTool_ValueEnum    : {
184       def.AssignCat("Enum");
185       Standard_Integer startcase, endcase; Standard_Boolean match;
186       EnumDef (startcase,endcase,match);
187       Sprintf(mess," [%s%d-%d]",(match ? "in " : ""),startcase,endcase);
188       def.AssignCat(mess);
189       for (Standard_Integer i = startcase; i <= endcase; i ++) {
190         Standard_CString enva = EnumVal(i);
191         if (enva[0] == '?' || enva[0] == '\0') continue;
192         Sprintf(mess," %d:%s",i,enva);
193         def.AssignCat (mess);
194       }
195       if (!theeadds.IsNull()) {
196         def.AssignCat(" , alpha: ");
197         Dico_IteratorOfDictionaryOfInteger listadd(theeadds);
198         for (listadd.Start(); listadd.More(); listadd.Next()) {
199           TCollection_AsciiString aName = listadd.Name();
200           Standard_CString enva = aName.ToCString();
201           if (enva[0] == '?') continue;
202           Sprintf(mess,":%d ",listadd.Value());
203           def.AssignCat (enva);
204           def.AssignCat (mess);
205         }
206       }
207     }
208       break;
209     case MoniTool_ValueIdent  : {
210       def.AssignCat("Object(Entity)");
211       if (!theotyp.IsNull()) {
212         def.AssignCat(":");
213         def.AssignCat(theotyp->Name());
214       }
215     }
216       break;
217     case MoniTool_ValueText    : {
218       def.AssignCat("Text");
219       if (themaxlen > 0) {
220         Sprintf (mess," <= %d C.",themaxlen);
221         def.AssignCat (mess);
222       }
223       break;
224     }
225     default :  def.AssignCat("(undefined)");  break;
226   }
227   return def;
228 }
229
230     void  MoniTool_TypedValue::SetDefinition (const Standard_CString deftext)
231       {  thedef.Clear();  thedef.AssignCat(deftext);  }
232
233 //  ##   Print   ##
234
235     void  MoniTool_TypedValue::Print (const Handle(Message_Messenger)& S) const
236 {
237   S<<"--- Typed Value : "<<Name();
238   if (thelabel.Length() > 0) S<<"  Label : "<<Label();
239   S<<endl<<"--- Type : "<<Definition()<<endl<<"--- Value : ";
240
241   PrintValue (S);
242   S<<endl;
243
244   if (thesatisf) S<<" -- Specific Function for Satisfies : "<<thesatisn.ToCString()<<endl;
245 }
246
247
248     void  MoniTool_TypedValue::PrintValue (const Handle(Message_Messenger)& S) const
249 {
250   if (IsSetValue()) {
251     if (thetype == MoniTool_ValueIdent)
252       S<<" (type) "<<theoval->DynamicType()->Name();
253     if (!thehval.IsNull())
254       S<<(thetype == MoniTool_ValueIdent ? " : " : "")<<thehval->ToCString();
255
256     if (HasInterpret()) {
257       S<<"  (";
258       Handle(TCollection_HAsciiString) str = Interpret (thehval,Standard_True);
259       if (!str.IsNull() && str != thehval) S<<"Native:"<<str->ToCString();
260       str = Interpret (thehval,Standard_False);
261       if (!str.IsNull() && str != thehval) S<<"  Coded:"<<str->ToCString();
262       S<<")";
263     }
264   }
265   else S<<"(not set)";
266 }
267
268
269 //  #########    COMPLEMENTS    ##########
270
271     Standard_Boolean  MoniTool_TypedValue::AddDef
272   (const Standard_CString init)
273 {
274 //    Editions : init donne un petit texte d edition, en 2 termes "cmd var" :
275   Standard_Integer i,iblc = 0;
276   for (i = 0; init[i] != '\0'; i ++) if (init[i] == ' ') iblc = i+1;
277   if (iblc == 0) return Standard_False;
278 //  Reconnaissance du sous-cas et aiguillage
279   if      (init[0] == 'i' && init[2] == 'i')            // imin ival
280     SetIntegerLimit (Standard_False,atoi(&init[iblc]));
281   else if (init[0] == 'i' && init[2] == 'a')            // imax ival
282     SetIntegerLimit (Standard_True ,atoi(&init[iblc]));
283   else if (init[0] == 'r' && init[2] == 'i')            // rmin rval
284     SetRealLimit (Standard_False,Atof(&init[iblc]));
285   else if (init[0] == 'r' && init[2] == 'a')            // rmax rval
286     SetRealLimit (Standard_True ,Atof(&init[iblc]));
287   else if (init[0] == 'u')                              // unit name
288     SetUnitDef (&init[iblc]);
289   else if (init[0] == 'e' && init[1] == 'm')            // ematch istart
290     StartEnum (atoi(&init[iblc]),Standard_True);
291   else if (init[0] == 'e' && init[1] == 'n')            // enum istart
292     StartEnum (atoi(&init[iblc]),Standard_False);
293   else if (init[0] == 'e' && init[1] == 'v')            // eval text
294     AddEnum (&init[iblc]);
295   else if (init[0] == 't' && init[1] == 'm')            // tmax length
296     SetMaxLength (atoi(&init[iblc]));
297
298   else return Standard_False;
299
300   return Standard_True;
301 }
302
303
304     void  MoniTool_TypedValue::SetLabel (const Standard_CString label)
305       {  thelabel.Clear();  thelabel.AssignCat (label);  }
306
307     Standard_CString  MoniTool_TypedValue::Label  () const
308       {  return thelabel.ToCString();    }
309
310
311
312     void  MoniTool_TypedValue::SetMaxLength
313   (const Standard_Integer max)
314       {  themaxlen = max;  if (max < 0) themaxlen = 0;  }
315
316     Standard_Integer  MoniTool_TypedValue::MaxLength () const
317       {  return themaxlen;  }
318
319     void  MoniTool_TypedValue::SetIntegerLimit
320   (const Standard_Boolean max, const Standard_Integer val)
321 {
322   if (thetype != MoniTool_ValueInteger) Standard_ConstructionError::Raise
323       ("MoniTool_TypedValue : SetIntegerLimit, not an Integer");
324
325   if (max)  {  thelims |= 2;  theintup  = val; }
326   else      {  thelims |= 1;  theintlow = val; }
327 }
328
329     Standard_Boolean  MoniTool_TypedValue::IntegerLimit
330   (const Standard_Boolean max, Standard_Integer& val) const
331 {
332   Standard_Boolean res = Standard_False;
333   if (max) { res = (thelims & 2) != 0; val = (res ? theintup  : IntegerLast()); }
334   else     { res = (thelims & 1) != 0; val = (res ? theintlow : IntegerFirst()); }
335   return res;
336 }
337
338
339     void  MoniTool_TypedValue::SetRealLimit
340   (const Standard_Boolean max, const Standard_Real val)
341 {
342   if (thetype != MoniTool_ValueReal) Standard_ConstructionError::Raise
343       ("MoniTool_TypedValue : SetRealLimit, not a Real");
344
345   if (max)  {  thelims |= 2;  therealup = val; }
346   else      {  thelims |= 1;  therealow = val; }
347 }
348
349     Standard_Boolean  MoniTool_TypedValue::RealLimit
350   (const Standard_Boolean max, Standard_Real& val) const
351 {
352   Standard_Boolean res = Standard_False;
353   if (max) { res = (thelims & 2) != 0; val = (res ? therealup : RealLast()); }
354   else     { res = (thelims & 1) != 0; val = (res ? therealow : RealFirst()); }
355   return res;
356 }
357
358     void   MoniTool_TypedValue::SetUnitDef (const Standard_CString def)
359       {  theunidef.Clear();  theunidef.AssignCat(def);  }
360
361     Standard_CString  MoniTool_TypedValue::UnitDef () const
362       {  return  theunidef.ToCString();  }
363
364 //  ******  les enums  ******
365
366     void  MoniTool_TypedValue::StartEnum
367   (const Standard_Integer start, const Standard_Boolean match)
368 {
369   if (thetype != MoniTool_ValueEnum) Standard_ConstructionError::Raise
370     ("MoniTool_TypedValue : StartEnum, Not an Enum");
371
372   thelims |= 4;  if (!match) thelims -= 4;
373   theintlow = start;  theintup = start -1;
374 }
375
376     void  MoniTool_TypedValue::AddEnum
377   (const Standard_CString v1, const Standard_CString v2,
378    const Standard_CString v3, const Standard_CString v4,
379    const Standard_CString v5, const Standard_CString v6,
380    const Standard_CString v7, const Standard_CString v8,
381    const Standard_CString v9, const Standard_CString v10)
382 {
383   if (thetype != MoniTool_ValueEnum) Standard_ConstructionError::Raise
384     ("MoniTool_TypedValue : AddEnum, Not an Enum");
385   if (theenums.IsNull()) theenums =
386     new TColStd_HArray1OfAsciiString(theintlow,theintlow+10);
387   else if (theenums->Upper() < theintup + 10) {
388     Handle(TColStd_HArray1OfAsciiString) enums =
389       new TColStd_HArray1OfAsciiString(theintlow,theintup+10);
390     for (Standard_Integer i = theintlow; i <= theintup; i ++)
391       enums->SetValue(i,theenums->Value(i));
392     theenums = enums;
393   }
394
395   if (theeadds.IsNull()) theeadds = new Dico_DictionaryOfInteger;
396   if (v1[0] != '\0') {
397     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v1));
398     theeadds->SetItem (v1,theintup);
399   }
400   if (v2[0] != '\0') {
401     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v2));
402     theeadds->SetItem (v2,theintup);
403   }
404   if (v3[0] != '\0') {
405     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v3));
406     theeadds->SetItem (v3,theintup);
407   }
408   if (v4[0] != '\0') {
409     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v4));
410     theeadds->SetItem (v4,theintup);
411   }
412   if (v5[0] != '\0') {
413     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v5));
414     theeadds->SetItem (v5,theintup);
415   }
416   if (v6[0] != '\0') {
417     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v6));
418     theeadds->SetItem (v6,theintup);
419   }
420   if (v7[0] != '\0') {
421     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v7));
422     theeadds->SetItem (v7,theintup);
423   }
424   if (v8[0] != '\0') {
425     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v8));
426     theeadds->SetItem (v8,theintup);
427   }
428   if (v9[0] != '\0') {
429     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v9));
430     theeadds->SetItem (v9,theintup);
431   }
432   if (v10[0] != '\0') {
433     theintup ++;  theenums->SetValue(theintup,TCollection_AsciiString(v10));
434     theeadds->SetItem (v10,theintup);
435   }
436 }
437
438     void  MoniTool_TypedValue::AddEnumValue
439   (const Standard_CString val, const Standard_Integer num)
440 {
441   if (thetype != MoniTool_ValueEnum) Standard_ConstructionError::Raise
442     ("MoniTool_TypedValue : AddEnum, Not an Enum");
443   if (num < theintlow) Standard_ConstructionError::Raise
444     ("MoniTool_TypedValue : AddEnum, out of range");
445   if (val[0] == '\0') return;
446   if (theenums.IsNull()) theenums =
447     new TColStd_HArray1OfAsciiString(theintlow,num+1);
448   else if (theenums->Upper() < num) {
449     Handle(TColStd_HArray1OfAsciiString) enums =
450       new TColStd_HArray1OfAsciiString(theintlow,num+1);
451     for (Standard_Integer i = theintlow; i <= theintup; i ++)
452       enums->SetValue(i,theenums->Value(i));
453     theenums = enums;
454   }
455
456   if (theintup < num) theintup = num;
457   if (theenums->Value(num).Length() == 0)
458     theenums->SetValue(num,TCollection_AsciiString(val));
459 //    On met AUSSI dans le dictionnaire
460 //  else {
461     if (theeadds.IsNull()) theeadds = new Dico_DictionaryOfInteger;
462     theeadds->SetItem (val,num);
463 //  }
464 }
465
466     Standard_Boolean  MoniTool_TypedValue::EnumDef
467   (Standard_Integer& startcase, Standard_Integer& endcase,
468    Standard_Boolean& match) const
469 {
470   if (thetype != MoniTool_ValueEnum) return Standard_False;
471   startcase = theintlow;  endcase = theintup;
472   match = ((thelims & 4) != 0);
473   return Standard_True;
474 }
475
476     Standard_CString  MoniTool_TypedValue::EnumVal
477   (const Standard_Integer num) const
478 {
479   if (thetype != MoniTool_ValueEnum) return "";
480   if (num < theintlow || num > theintup) return "";
481   return theenums->Value(num).ToCString();
482 }
483
484     Standard_Integer  MoniTool_TypedValue::EnumCase
485   (const Standard_CString val) const
486 {
487   if (thetype != MoniTool_ValueEnum) return (theintlow - 1);
488   Standard_Integer i; // svv Jan 10 2000 : porting on DEC
489   for (i = theintlow; i <= theintup; i ++)
490     if (theenums->Value(i).IsEqual(val)) return i;
491 //  cas additionnel ?
492   if (!theeadds.IsNull()) {
493     if (theeadds->GetItem (val,i,Standard_False)) return i;
494   }
495 //  entier possible
496   //gka S4054
497   for (i = 0; val[i] != '\0'; i ++)
498     if (val[i] != ' ' && val[i] != '-' && (val[i] < '0' || val[i] > '9' )) return (theintlow -1);
499   return atoi(val);
500 }
501
502 //  ******  object/entity  ******
503
504     void  MoniTool_TypedValue::SetObjectType
505   (const Handle(Standard_Type)& typ)
506 {
507   if (thetype != MoniTool_ValueIdent) Standard_ConstructionError::Raise
508     ("MoniTool_TypedValue : AddEnum, Not an Entity/Object");
509   theotyp = typ;
510 }
511
512     Handle(Standard_Type)  MoniTool_TypedValue::ObjectType () const
513 {
514   if (!theotyp.IsNull()) return theotyp;
515   return STANDARD_TYPE(Standard_Transient);
516 }
517
518 //  ******   Specific Interpret/Satisfy   ******
519
520     void  MoniTool_TypedValue::SetInterpret
521   (const MoniTool_ValueInterpret func)
522       {  theinterp = func;  }
523
524     Standard_Boolean  MoniTool_TypedValue::HasInterpret () const
525 {
526   if (theinterp) return Standard_True;
527   if (thetype == MoniTool_ValueEnum) return Standard_True;
528   return Standard_False;
529 }
530
531     void  MoniTool_TypedValue::SetSatisfies
532   (const MoniTool_ValueSatisfies func, const Standard_CString name)
533 {
534   thesatisn.Clear();
535   thesatisf = func;
536   if (thesatisf) thesatisn.AssignCat (name);
537 }
538
539     Standard_CString MoniTool_TypedValue::SatisfiesName () const
540       {  return thesatisn.ToCString();  }
541
542 //  ###########    VALEUR DU STATIC    ############
543
544     Standard_Boolean MoniTool_TypedValue::IsSetValue () const
545 {
546   if (thetype == MoniTool_ValueIdent) return (!theoval.IsNull());
547   if (thehval->Length() > 0) return Standard_True;
548   if (!theoval.IsNull()) return Standard_True;
549   return Standard_False;
550 }
551
552     Standard_CString MoniTool_TypedValue::CStringValue () const
553       {  if (thehval.IsNull()) return "";  return thehval->ToCString();  }
554
555     Handle(TCollection_HAsciiString) MoniTool_TypedValue::HStringValue () const
556       {  return thehval;  }
557
558     Handle(TCollection_HAsciiString)  MoniTool_TypedValue::Interpret
559   (const Handle(TCollection_HAsciiString)& hval,
560    const Standard_Boolean native) const
561 {
562   Handle(TCollection_HAsciiString) inter = hval;
563   if (hval.IsNull()) return hval;
564   if (theinterp) return theinterp (this,hval,native);
565   if (thetype == MoniTool_ValueEnum) {
566 //  On admet les deux formes : Enum de preference, sinon Integer
567     Standard_Integer startcase, endcase; Standard_Boolean match;
568     EnumDef (startcase,endcase,match);
569     Standard_Integer encas = EnumCase (hval->ToCString());
570     if (encas < startcase) return hval;    // loupe
571     if (native) inter = new TCollection_HAsciiString (EnumVal(encas));
572     else inter = new TCollection_HAsciiString (encas);
573   }
574   return inter;
575 }
576
577     Standard_Boolean  MoniTool_TypedValue::Satisfies
578   (const Handle(TCollection_HAsciiString)& val) const
579 {
580   if (val.IsNull()) return Standard_False;
581   if (thesatisf)
582     if (!thesatisf (val) ) return Standard_False;
583   if (val->Length() == 0) return Standard_True;
584   switch (thetype) {
585     case MoniTool_ValueInteger : {
586       if (!val->IsIntegerValue()) return Standard_False;
587       Standard_Integer ival, ilim;  ival = atoi(val->ToCString());
588       if (IntegerLimit(Standard_False, ilim))
589         if (ilim > ival) return Standard_False;
590       if (IntegerLimit(Standard_True,  ilim))
591         if (ilim < ival) return Standard_False;
592       return Standard_True;
593     }
594     case MoniTool_ValueReal    : {
595       if (!val->IsRealValue()) return Standard_False;
596       Standard_Real rval, rlim;  rval = val->RealValue();
597       if (RealLimit(Standard_False, rlim))
598         if (rlim > rval) return Standard_False;
599       if (RealLimit(Standard_True,  rlim))
600         if (rlim < rval) return Standard_False;
601       return Standard_True;
602     }
603     case MoniTool_ValueEnum    : {
604 //  On admet les deux formes : Enum de preference, sinon Integer
605       Standard_Integer startcase, endcase;// unused ival;
606       Standard_Boolean match;
607       EnumDef (startcase,endcase,match);
608       if (!match) return Standard_True;
609       if (EnumCase (val->ToCString()) >= startcase) return Standard_True;
610 //  Ici, on admet un entier dans la fourchette
611 ////      if (val->IsIntegerValue()) ival = atoi (val->ToCString());
612
613 // PTV 16.09.2000 The if is comment, cause this check is never been done (You can see the logic)
614 //      if (ival >= startcase && ival <= endcase) return Standard_True;
615       return Standard_False;
616     }
617     case MoniTool_ValueText    : {
618       if (themaxlen > 0 && val->Length() > themaxlen) return Standard_False;
619       break;
620     }
621     default : break;
622   }
623   return Standard_True;
624 }
625
626     void  MoniTool_TypedValue::ClearValue ()
627 {
628   thehval.Nullify();
629   theoval.Nullify();
630   theival = 0;
631 }
632
633     Standard_Boolean  MoniTool_TypedValue::SetCStringValue
634   (const Standard_CString val)
635 {
636   Handle(TCollection_HAsciiString) hval = new TCollection_HAsciiString(val);
637   if (hval->IsSameString (thehval)) return Standard_True;
638   if (!Satisfies(hval))  return Standard_False;
639   if      (thetype == MoniTool_ValueInteger) {
640     thehval->Clear();
641     theival = atoi(val);
642     thehval->AssignCat(val);
643   }
644   else if (thetype == MoniTool_ValueEnum) {
645     Standard_Integer ival = EnumCase(val);
646     Standard_CString cval = EnumVal(ival);
647     if (!cval || cval[0] == '\0') return Standard_False;
648     theival = ival;
649     thehval->Clear();
650     thehval->AssignCat(cval);
651   } else {
652     thehval->Clear();
653     thehval->AssignCat(val);
654     return Standard_True;
655   }
656   return Standard_True;
657 }
658
659     Standard_Boolean  MoniTool_TypedValue::SetHStringValue
660   (const Handle(TCollection_HAsciiString)& hval)
661 {
662   if (hval.IsNull())     return Standard_False;
663   if (!Satisfies(hval))  return Standard_False;
664   thehval = hval;
665   if      (thetype == MoniTool_ValueInteger) theival = atoi(hval->ToCString());
666   else if (thetype == MoniTool_ValueEnum)    theival = EnumCase(hval->ToCString());
667 //  else return Standard_True;
668   return Standard_True;
669 }
670
671     Standard_Integer  MoniTool_TypedValue::IntegerValue () const
672       {  return theival;  }
673
674     Standard_Boolean  MoniTool_TypedValue::SetIntegerValue
675   (const Standard_Integer ival)
676 {
677   Handle(TCollection_HAsciiString) hval = new TCollection_HAsciiString(ival);
678   if (hval->IsSameString (thehval)) return Standard_True;
679   if (!Satisfies(hval))  return Standard_False;
680   thehval->Clear();
681   if (thetype == MoniTool_ValueEnum) thehval->AssignCat (EnumVal(ival));
682   else thehval->AssignCat (hval->ToCString());
683   theival = ival;
684   return Standard_True;
685 }
686
687     Standard_Real     MoniTool_TypedValue::RealValue () const
688 {
689   if (thehval->Length() == 0)  return 0.0;
690   if (!thehval->IsRealValue()) return 0.0;
691   return thehval->RealValue();
692 }
693
694     Standard_Boolean  MoniTool_TypedValue::SetRealValue (const Standard_Real rval)
695 {
696   Handle(TCollection_HAsciiString) hval = new TCollection_HAsciiString(rval);
697   if (hval->IsSameString (thehval)) return Standard_True;
698   if (!Satisfies(hval))  return Standard_False;
699   thehval->Clear();  thehval->AssignCat (hval->ToCString());
700   return Standard_True;
701 }
702
703     Handle(Standard_Transient)  MoniTool_TypedValue::ObjectValue () const
704       {  return theoval;  }
705
706     void  MoniTool_TypedValue::GetObjectValue (Handle(Standard_Transient)& val) const
707       {  val = theoval;  }
708
709     Standard_Boolean  MoniTool_TypedValue::SetObjectValue
710   (const Handle(Standard_Transient)& obj)
711 {
712   if (thetype != MoniTool_ValueIdent) return Standard_False;
713   if (obj.IsNull()) { theoval.Nullify();  return Standard_True; }
714   if (!theotyp.IsNull())
715     if (!obj->IsKind(theotyp)) return Standard_False;
716   theoval = obj;
717   return Standard_True;
718 }
719
720
721     Standard_CString  MoniTool_TypedValue::ObjectTypeName () const
722 {
723   if (theoval.IsNull()) return "";
724   Handle(MoniTool_Element) elm = Handle(MoniTool_Element)::DownCast(theoval);
725   if (!elm.IsNull()) return elm->ValueTypeName();
726   return theoval->DynamicType()->Name();
727 }
728
729
730 //    ########        LIBRARY        ########
731
732     Standard_Boolean  MoniTool_TypedValue::AddLib
733   (const Handle(MoniTool_TypedValue)& tv, const Standard_CString defin)
734 {
735   if (tv.IsNull()) return Standard_False;
736   if (defin[0] != '\0') tv->SetDefinition(defin);
737 //  else if (tv->Definition() == '\0') return Standard_False;
738   libtv()->SetItem (tv->Name(),tv);
739   return Standard_True;
740 }
741
742     Handle(MoniTool_TypedValue)  MoniTool_TypedValue::Lib
743   (const Standard_CString defin)
744 {
745   Handle(MoniTool_TypedValue) val;
746   if (!libtv()->GetItem (defin,val,Standard_False)) val.Nullify();
747   return val;
748 }
749
750     Handle(MoniTool_TypedValue)  MoniTool_TypedValue::FromLib
751   (const Standard_CString defin)
752 {
753   Handle(MoniTool_TypedValue) val = MoniTool_TypedValue::Lib(defin);
754   if (!val.IsNull()) val = new MoniTool_TypedValue (val);
755   return val;
756 }
757
758     Handle(TColStd_HSequenceOfAsciiString)  MoniTool_TypedValue::LibList ()
759 {
760   Handle(TColStd_HSequenceOfAsciiString) list = new TColStd_HSequenceOfAsciiString();
761   if (libtv().IsNull()) return list;
762   for (Dico_IteratorOfDictionaryOfTransient it(libtv()); it.More();it.Next()) {
763     list->Append (it.Name());
764   }
765   return list;
766 }
767
768
769
770     Handle(Dico_DictionaryOfTransient)  MoniTool_TypedValue::Stats ()
771 {
772   static Handle(Dico_DictionaryOfTransient) astats;
773   if (astats.IsNull()) astats  = new Dico_DictionaryOfTransient;
774   return astats;
775 }
776
777     Handle(MoniTool_TypedValue)  MoniTool_TypedValue::StaticValue
778   (const Standard_CString name)
779 {
780   Handle(MoniTool_TypedValue) result;
781   if (!Stats()->GetItem(name,result)) result.Nullify();
782   return result;
783 }