0022898: IGES import fails in german environment
[occt.git] / src / Interface / Interface_Static.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 <Interface_Static.ixx>
19
20 #include <Dico_DictionaryOfInteger.hxx>
21 #include <Dico_DictionaryOfTransient.hxx>
22 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
23 #include <Dico_IteratorOfDictionaryOfInteger.hxx>
24
25 #include <OSD_Path.hxx>
26 #include <stdio.h>
27
28
29 static  char defmess[30];
30
31 //  Fonctions Satisfies offertes en standard ...
32
33 //svv #2
34 //static Standard_Boolean StaticPath(const Handle(TCollection_HAsciiString)& val)
35 //{
36 //  OSD_Path apath;
37 //  return apath.IsValid (TCollection_AsciiString(val->ToCString()));
38 //}
39
40
41     Interface_Static::Interface_Static
42   (const Standard_CString family,  const Standard_CString name,
43    const Interface_ParamType type, const Standard_CString init)
44     : Interface_TypedValue (name,type,init) ,
45       thefamily (family) ,
46       theupdate (Standard_True)    {  }
47
48     Interface_Static::Interface_Static
49   (const Standard_CString family,  const Standard_CString name,
50    const Handle(Interface_Static)& other)
51     : Interface_TypedValue (name, other->Type(), "") ,
52       thefamily (family) ,
53       theupdate (Standard_True)
54 {
55   switch (Type()) {
56     case Interface_ParamInteger : {
57       Standard_Integer lim;
58       if (other->IntegerLimit (Standard_True ,lim)) SetIntegerLimit (Standard_True ,lim);
59       if (other->IntegerLimit (Standard_False,lim)) SetIntegerLimit (Standard_False,lim);
60     }
61       break;
62     case Interface_ParamReal : {
63       Standard_Real lim;
64       if (other->RealLimit (Standard_True ,lim)) SetRealLimit (Standard_True ,lim);
65       if (other->RealLimit (Standard_False,lim)) SetRealLimit (Standard_False,lim);
66       SetUnitDef (other->UnitDef());
67     }
68       break;
69     case Interface_ParamEnum : {
70       Standard_Boolean match;  Standard_Integer e0,e1,i;
71       other->EnumDef (e0,e1,match);
72       StartEnum (e0,match);
73 //      if (e1 >= e0) theenums = new TColStd_HArray1OfAsciiString(e0,e1);
74       for (i = e0; i <= e1; i ++)
75         AddEnum (other->EnumVal(i));
76     }
77       break;
78     case Interface_ParamIdent :
79       SetObjectType (other->ObjectType());
80       break;
81     default :  break;
82   }
83
84   if (other->IsSetValue()) SetCStringValue (other->CStringValue());
85 }
86
87
88 //  ##   Print   ##
89
90 void  Interface_Static::PrintStatic (const Handle(Message_Messenger)& S) const
91 {
92   S<<"--- Static Value : "<<Name()<<"  Family:"<<Family();
93   Print (S);
94   if (!thewild.IsNull())
95     S<<" -- Attached to wild-card : "<<thewild->Name()<<endl;
96   S<<"--- Actual status : "<<(theupdate ? "" : "original")<<"  Value : ";
97
98   if (thesatisf) S<<" -- Specific Function for Satisfies : "<<thesatisn.ToCString()<<endl;
99 }
100
101
102 //  #########    COMPLEMENTS    ##########
103
104 Standard_CString  Interface_Static::Family () const
105 {
106   return thefamily.ToCString();
107 }
108
109
110 Handle(Interface_Static)  Interface_Static::Wild () const
111 {
112   return thewild;
113 }
114
115
116 void  Interface_Static::SetWild (const Handle(Interface_Static)& wild)
117 {
118   thewild = wild;
119 }
120
121
122 //  #########   UPDATE    ##########
123
124 void  Interface_Static::SetUptodate ()
125 {
126   theupdate = Standard_True;
127 }
128
129
130 Standard_Boolean  Interface_Static::UpdatedStatus () const
131 {
132   return theupdate;
133 }
134
135
136
137 //  #######################################################################
138 //  #########    DICTIONNAIRE DES STATICS (static sur Static)    ##########
139
140 Standard_Boolean  Interface_Static::Init
141   (const Standard_CString family,  const Standard_CString name,
142    const Interface_ParamType type, const Standard_CString init)
143 {
144   if (name[0] == '\0') return Standard_False;
145
146   if (MoniTool_TypedValue::Stats()->HasItem(name)) return Standard_False;
147   Handle(Interface_Static) item;
148   if (type == Interface_ParamMisc) {
149     Handle(Interface_Static) other = Interface_Static::Static(init);
150     if (other.IsNull()) return Standard_False;
151     item = new Interface_Static (family,name,other);
152   }
153   else item = new Interface_Static (family,name,type,init);
154
155   MoniTool_TypedValue::Stats()->SetItem (name,item);
156   return Standard_True;
157 }
158
159
160 Standard_Boolean  Interface_Static::Init
161   (const Standard_CString family,  const Standard_CString name,
162    const Standard_Character type, const Standard_CString init)
163 {
164   Interface_ParamType epyt;
165   switch (type) {
166     case 'e' : epyt = Interface_ParamEnum;     break;
167     case 'i' : epyt = Interface_ParamInteger;  break;
168     case 'o' : epyt = Interface_ParamIdent;    break;
169     case 'p' : epyt = Interface_ParamText;     break;
170     case 'r' : epyt = Interface_ParamReal;     break;
171     case 't' : epyt = Interface_ParamText;     break;
172     case '=' : epyt = Interface_ParamMisc;     break;
173     case '&' : {
174       Handle(Interface_Static) unstat = Interface_Static::Static(name);
175       if (unstat.IsNull()) return Standard_False;
176 //    Editions : init donne un petit texte d edition, en 2 termes "cmd var" :
177 //  imin <ival>  imax <ival>  rmin <rval>  rmax <rval>  unit <def>
178 //  enum <from>  ematch <from>  eval <cval>
179       Standard_Integer i,iblc = 0;
180       for (i = 0; init[i] != '\0'; i ++) if (init[i] == ' ') iblc = i+1;
181 //  Reconnaissance du sous-cas et aiguillage
182       if      (init[0] == 'i' && init[2] == 'i')
183         unstat->SetIntegerLimit (Standard_False,atoi(&init[iblc]));
184       else if (init[0] == 'i' && init[2] == 'a')
185         unstat->SetIntegerLimit (Standard_True ,atoi(&init[iblc]));
186       else if (init[0] == 'r' && init[2] == 'i')
187         unstat->SetRealLimit (Standard_False,Atof(&init[iblc]));
188       else if (init[0] == 'r' && init[2] == 'a')
189         unstat->SetRealLimit (Standard_True ,Atof(&init[iblc]));
190       else if (init[0] == 'u')
191         unstat->SetUnitDef (&init[iblc]);
192       else if (init[0] == 'e' && init[1] == 'm')
193         unstat->StartEnum (atoi(&init[iblc]),Standard_True);
194       else if (init[0] == 'e' && init[1] == 'n')
195         unstat->StartEnum (atoi(&init[iblc]),Standard_False);
196       else if (init[0] == 'e' && init[1] == 'v')
197         unstat->AddEnum (&init[iblc]);
198       else return Standard_False;
199       return Standard_True;
200     }
201     default  : return Standard_False;
202   }
203   if (!Interface_Static::Init (family,name,epyt,init)) return Standard_False;
204   if (type != 'p') return Standard_True;
205   Handle(Interface_Static) stat = Interface_Static::Static(name);
206 //NT  stat->SetSatisfies (StaticPath,"Path");
207   if (!stat->Satisfies(stat->HStringValue())) stat->SetCStringValue("");
208   return Standard_True;
209 }
210
211
212 Handle(Interface_Static)  Interface_Static::Static
213   (const Standard_CString name)
214 {
215   Handle(Interface_Static) result;
216   MoniTool_TypedValue::Stats()->GetItem (name,result);
217   return result;
218 }
219
220
221 Standard_Boolean  Interface_Static::IsPresent (const Standard_CString name)
222 {
223   return MoniTool_TypedValue::Stats()->HasItem (name);
224 }
225
226
227 Standard_CString  Interface_Static::CDef
228   (const Standard_CString name, const Standard_CString part)
229 {
230   if (!part || part[0] == '\0') return "";
231   Handle(Interface_Static) stat = Interface_Static::Static(name);
232   if (stat.IsNull()) return "";
233   if (part[0] == 'f' && part[1] == 'a') return stat->Family();
234   if (part[0] == 'l' && part[1] == 'a') return stat->Label();
235   if (part[0] == 's' && part[1] == 'a') return stat->SatisfiesName();
236   if (part[0] == 't' && part[1] == 'y') {
237     Interface_ParamType typ = stat->Type();
238     if (typ == Interface_ParamInteger)  return "integer";
239     if (typ == Interface_ParamReal)     return "real";
240     if (typ == Interface_ParamText)     return "text";
241     if (typ == Interface_ParamEnum)     return "enum";
242     return "?type?";
243   }
244   if (part[0] == 'e') {
245     Standard_Integer nume = 0;
246     sscanf (part,"%s %d",defmess,&nume);
247     return stat->EnumVal(nume);
248   }
249   if (part[0] == 'i') {
250     Standard_Integer ilim;
251     if (!stat->IntegerLimit((part[2] == 'a'),ilim)) return "";
252     Sprintf(defmess,"%d",ilim);   return defmess;
253   }
254   if (part[0] == 'r') {
255     Standard_Real rlim;
256     if (!stat->RealLimit((part[2] == 'a'),rlim)) return "";
257     Sprintf(defmess,"%f",rlim);   return defmess;
258   }
259   if (part[0] == 'u') return stat->UnitDef();
260   return "";
261 }
262
263
264 Standard_Integer  Interface_Static::IDef
265   (const Standard_CString name, const Standard_CString part)
266 {
267   if (!part || part[0] == '\0') return 0;
268   Handle(Interface_Static) stat = Interface_Static::Static(name);
269   if (stat.IsNull()) return 0;
270   if (part[0] == 'i') {
271     Standard_Integer ilim;
272     if (!stat->IntegerLimit((part[2] == 'a'),ilim)) return 0;
273     return ilim;
274   }
275   if (part[0] == 'e') {
276     Standard_Integer startcase,endcase;  Standard_Boolean match;
277     stat->EnumDef (startcase,endcase,match);
278     if (part[1] == 's') return startcase;
279     if (part[1] == 'c') return (endcase - startcase + 1);
280     if (part[1] == 'm') return (match ? 1 : 0);
281     if (part[1] == 'v') {
282       char vale[50];
283       sscanf (part,"%s %s",defmess,vale);
284       return stat->EnumCase (vale);
285     }
286   }
287   return 0;
288 }
289
290
291 //  ##########  VALEUR COURANTE  ###########
292
293 Standard_Boolean  Interface_Static::IsSet
294   (const Standard_CString name, const Standard_Boolean proper)
295 {
296   Handle(Interface_Static) item = Interface_Static::Static(name);
297   if (item.IsNull()) return Standard_False;
298   if (item->IsSetValue()) return Standard_True;
299   if (proper) return Standard_False;
300   item = item->Wild();
301   return item->IsSetValue();
302 }
303
304
305 Standard_CString  Interface_Static::CVal  (const Standard_CString name)
306 {
307   Handle(Interface_Static) item = Interface_Static::Static(name);
308   if (item.IsNull()) {
309 #ifdef DEB
310     cout << "Warning: Interface_Static::CVal: incorrect parameter " << name << endl;
311 #endif
312     return "";
313   }
314   return item->CStringValue();
315 }
316
317
318 Standard_Integer  Interface_Static::IVal  (const Standard_CString name)
319 {
320   Handle(Interface_Static) item = Interface_Static::Static(name);
321   if (item.IsNull()) {
322 #ifdef DEB
323     cout << "Warning: Interface_Static::IVal: incorrect parameter " << name << endl;
324 #endif
325     return 0;
326   }
327   return item->IntegerValue();
328 }
329
330
331 Standard_Real Interface_Static::RVal (const Standard_CString name)
332 {
333   Handle(Interface_Static) item = Interface_Static::Static(name);
334   if (item.IsNull()) {
335 #ifdef DEB
336     cout << "Warning: Interface_Static::RVal: incorrect parameter " << name << endl;
337 #endif
338     return 0.0;
339   }
340   return item->RealValue();
341 }
342
343
344 Standard_Boolean  Interface_Static::SetCVal
345   (const Standard_CString name, const Standard_CString val)
346 {
347   Handle(Interface_Static) item = Interface_Static::Static(name);
348   if (item.IsNull()) return Standard_False;
349   return item->SetCStringValue(val);
350 }
351
352
353 Standard_Boolean  Interface_Static::SetIVal
354   (const Standard_CString name, const Standard_Integer val)
355 {
356   Handle(Interface_Static) item = Interface_Static::Static(name);
357   if (item.IsNull()) return Standard_False;
358   if (!item->SetIntegerValue(val)) return Standard_False;
359   return Standard_True;
360 }
361
362
363 Standard_Boolean  Interface_Static::SetRVal
364   (const Standard_CString name, const Standard_Real val)
365 {
366   Handle(Interface_Static) item = Interface_Static::Static(name);
367   if (item.IsNull()) return Standard_False;
368   return item->SetRealValue(val);
369 }
370
371 //    UPDATE
372
373 Standard_Boolean  Interface_Static::Update (const Standard_CString name)
374 {
375   Handle(Interface_Static) item = Interface_Static::Static(name);
376   if (item.IsNull()) return Standard_False;
377   item->SetUptodate();
378   return Standard_True;
379 }
380
381 Standard_Boolean  Interface_Static::IsUpdated (const Standard_CString name)
382 {
383   Handle(Interface_Static) item = Interface_Static::Static(name);
384   if (item.IsNull()) return Standard_False;
385   return item->UpdatedStatus();
386 }
387
388 Handle(TColStd_HSequenceOfHAsciiString)  Interface_Static::Items
389   (const Standard_Integer mode, const Standard_CString criter)
390 {
391   Standard_Integer modup = (mode / 100);  // 0 any, 1 non-update, 2 update
392   Handle(TColStd_HSequenceOfHAsciiString) list =
393     new TColStd_HSequenceOfHAsciiString();
394   Dico_IteratorOfDictionaryOfTransient iter(MoniTool_TypedValue::Stats());
395   for (iter.Start(); iter.More(); iter.Next()) {
396     Handle(Interface_Static) item =
397       Handle(Interface_Static)::DownCast(iter.Value());
398     if (item.IsNull()) continue;
399     Standard_Boolean ok = Standard_True;
400     if (criter[0] == '$' && criter[1] == '\0') {
401       if ( (item->Family())[0] != '$') ok = Standard_False;
402     } else if (criter[0] != '\0') {
403       if (strcmp(criter, item->Family())) continue;
404       ok = Standard_True;
405     } else {     // tous ... sauf famille a $
406       if (item->Family()[0] == '$') continue;
407     }
408     if (ok && (modup == 1)) ok = !item->UpdatedStatus();
409     if (ok && (modup == 2)) ok =  item->UpdatedStatus();
410
411     if (ok) list->Append (new TCollection_HAsciiString (iter.Name()) );
412   }
413   return list;
414 }