1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 #include <Interface_Static.ixx>
20 #include <Dico_DictionaryOfInteger.hxx>
21 #include <Dico_DictionaryOfTransient.hxx>
22 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
23 #include <Dico_IteratorOfDictionaryOfInteger.hxx>
25 #include <OSD_Path.hxx>
29 static char defmess[30];
31 // Fonctions Satisfies offertes en standard ...
34 //static Standard_Boolean StaticPath(const Handle(TCollection_HAsciiString)& val)
37 // return apath.IsValid (TCollection_AsciiString(val->ToCString()));
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) ,
46 theupdate (Standard_True) { }
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(), "") ,
53 theupdate (Standard_True)
56 case Interface_ParamInteger : {
58 if (other->IntegerLimit (Standard_True ,lim)) SetIntegerLimit (Standard_True ,lim);
59 if (other->IntegerLimit (Standard_False,lim)) SetIntegerLimit (Standard_False,lim);
62 case Interface_ParamReal : {
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());
69 case Interface_ParamEnum : {
70 Standard_Boolean match; Standard_Integer e0,e1,i;
71 other->EnumDef (e0,e1,match);
73 // if (e1 >= e0) theenums = new TColStd_HArray1OfAsciiString(e0,e1);
74 for (i = e0; i <= e1; i ++)
75 AddEnum (other->EnumVal(i));
78 case Interface_ParamIdent :
79 SetObjectType (other->ObjectType());
84 if (other->IsSetValue()) SetCStringValue (other->CStringValue());
90 void Interface_Static::PrintStatic (const Handle(Message_Messenger)& S) const
92 S<<"--- Static Value : "<<Name()<<" Family:"<<Family();
94 if (!thewild.IsNull())
95 S<<" -- Attached to wild-card : "<<thewild->Name()<<endl;
96 S<<"--- Actual status : "<<(theupdate ? "" : "original")<<" Value : ";
98 if (thesatisf) S<<" -- Specific Function for Satisfies : "<<thesatisn.ToCString()<<endl;
102 // ######### COMPLEMENTS ##########
104 Standard_CString Interface_Static::Family () const
106 return thefamily.ToCString();
110 Handle(Interface_Static) Interface_Static::Wild () const
116 void Interface_Static::SetWild (const Handle(Interface_Static)& wild)
122 // ######### UPDATE ##########
124 void Interface_Static::SetUptodate ()
126 theupdate = Standard_True;
130 Standard_Boolean Interface_Static::UpdatedStatus () const
137 // #######################################################################
138 // ######### DICTIONNAIRE DES STATICS (static sur Static) ##########
140 Standard_Boolean Interface_Static::Init
141 (const Standard_CString family, const Standard_CString name,
142 const Interface_ParamType type, const Standard_CString init)
144 if (name[0] == '\0') return Standard_False;
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);
153 else item = new Interface_Static (family,name,type,init);
155 MoniTool_TypedValue::Stats()->SetItem (name,item);
156 return Standard_True;
160 Standard_Boolean Interface_Static::Init
161 (const Standard_CString family, const Standard_CString name,
162 const Standard_Character type, const Standard_CString init)
164 Interface_ParamType epyt;
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;
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;
201 default : return Standard_False;
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;
212 Handle(Interface_Static) Interface_Static::Static
213 (const Standard_CString name)
215 Handle(Interface_Static) result;
216 MoniTool_TypedValue::Stats()->GetItem (name,result);
221 Standard_Boolean Interface_Static::IsPresent (const Standard_CString name)
223 return MoniTool_TypedValue::Stats()->HasItem (name);
227 Standard_CString Interface_Static::CDef
228 (const Standard_CString name, const Standard_CString part)
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";
244 if (part[0] == 'e') {
245 Standard_Integer nume = 0;
246 sscanf (part,"%s %d",defmess,&nume);
247 return stat->EnumVal(nume);
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;
254 if (part[0] == 'r') {
256 if (!stat->RealLimit((part[2] == 'a'),rlim)) return "";
257 Sprintf(defmess,"%f",rlim); return defmess;
259 if (part[0] == 'u') return stat->UnitDef();
264 Standard_Integer Interface_Static::IDef
265 (const Standard_CString name, const Standard_CString part)
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;
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') {
283 sscanf (part,"%s %s",defmess,vale);
284 return stat->EnumCase (vale);
291 // ########## VALEUR COURANTE ###########
293 Standard_Boolean Interface_Static::IsSet
294 (const Standard_CString name, const Standard_Boolean proper)
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;
301 return item->IsSetValue();
305 Standard_CString Interface_Static::CVal (const Standard_CString name)
307 Handle(Interface_Static) item = Interface_Static::Static(name);
310 cout << "Warning: Interface_Static::CVal: incorrect parameter " << name << endl;
314 return item->CStringValue();
318 Standard_Integer Interface_Static::IVal (const Standard_CString name)
320 Handle(Interface_Static) item = Interface_Static::Static(name);
323 cout << "Warning: Interface_Static::IVal: incorrect parameter " << name << endl;
327 return item->IntegerValue();
331 Standard_Real Interface_Static::RVal (const Standard_CString name)
333 Handle(Interface_Static) item = Interface_Static::Static(name);
336 cout << "Warning: Interface_Static::RVal: incorrect parameter " << name << endl;
340 return item->RealValue();
344 Standard_Boolean Interface_Static::SetCVal
345 (const Standard_CString name, const Standard_CString val)
347 Handle(Interface_Static) item = Interface_Static::Static(name);
348 if (item.IsNull()) return Standard_False;
349 return item->SetCStringValue(val);
353 Standard_Boolean Interface_Static::SetIVal
354 (const Standard_CString name, const Standard_Integer val)
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;
363 Standard_Boolean Interface_Static::SetRVal
364 (const Standard_CString name, const Standard_Real val)
366 Handle(Interface_Static) item = Interface_Static::Static(name);
367 if (item.IsNull()) return Standard_False;
368 return item->SetRealValue(val);
373 Standard_Boolean Interface_Static::Update (const Standard_CString name)
375 Handle(Interface_Static) item = Interface_Static::Static(name);
376 if (item.IsNull()) return Standard_False;
378 return Standard_True;
381 Standard_Boolean Interface_Static::IsUpdated (const Standard_CString name)
383 Handle(Interface_Static) item = Interface_Static::Static(name);
384 if (item.IsNull()) return Standard_False;
385 return item->UpdatedStatus();
388 Handle(TColStd_HSequenceOfHAsciiString) Interface_Static::Items
389 (const Standard_Integer mode, const Standard_CString criter)
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;
405 } else { // tous ... sauf famille a $
406 if (item->Family()[0] == '$') continue;
408 if (ok && (modup == 1)) ok = !item->UpdatedStatus();
409 if (ok && (modup == 2)) ok = item->UpdatedStatus();
411 if (ok) list->Append (new TCollection_HAsciiString (iter.Name()) );