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