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