summaryrefslogtreecommitdiff
path: root/src/MoniTool/MoniTool_Profile.cxx
blob: 23340b081fcbf6ac553207dac6615462be31cea0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#include <MoniTool_Profile.ixx>
#include <TCollection_HAsciiString.hxx>
#include <Dico_IteratorOfDictionaryOfTransient.hxx>
#include <MoniTool_TypedValue.hxx>


static Standard_Boolean IsCurrent (const Standard_CString name)
{  return (name[0] == '.' && name[1] == '\0');  }

    MoniTool_Profile::MoniTool_Profile ()
{
  theopts  = new Dico_DictionaryOfTransient;
  theconfs = new Dico_DictionaryOfTransient;
//    Current
  Handle(Dico_DictionaryOfTransient) conf = new Dico_DictionaryOfTransient;
  theconfs->SetItem (".",conf);
  thecurname.AssignCat(".");
  thecurconf = conf;
}

    void  MoniTool_Profile::AddOption
  (const Handle(MoniTool_Option)& option,
   const Standard_CString name)
{
  if (option.IsNull()) return;
  if (name[0] == '\0') theopts->SetItem (option->Name().ToCString(),option);
  else theopts->SetItem (name,option);
}

    Handle(MoniTool_Option)  MoniTool_Profile::Option
  (const Standard_CString name) const
{
  Handle(MoniTool_Option) opt;
  if (!theopts->GetItem (name,opt,Standard_True)) opt.Nullify();
  return opt;
}

    Handle(TColStd_HSequenceOfAsciiString)  MoniTool_Profile::OptionList () const
{
  Handle(TColStd_HSequenceOfAsciiString) list = new TColStd_HSequenceOfAsciiString();
  Dico_IteratorOfDictionaryOfTransient iter(theopts);
  for (; iter.More(); iter.Next())  list->Append (iter.Name());
  return list;
}

    Handle(TColStd_HSequenceOfAsciiString)  MoniTool_Profile::TypedValueList () const
{
  Handle(TColStd_HSequenceOfAsciiString) list = new TColStd_HSequenceOfAsciiString();
  Dico_IteratorOfDictionaryOfTransient iter(theopts);
  for (; iter.More(); iter.Next()) {
    Handle(MoniTool_Option) opt = Handle(MoniTool_Option)::DownCast(iter.Value());
    if (!opt->TypedValue().IsNull())  list->Append (iter.Name());
  }
  return list;
}

    void  MoniTool_Profile::NewConf (const Standard_CString name)
{
  if (IsCurrent (name)) return;
  Handle(Dico_DictionaryOfTransient) conf = new Dico_DictionaryOfTransient;
  theconfs->SetItem (name,conf);
//  thecurname.Clear();  thecurname.AssignCat (name);
//  thecurconf = conf;
}

    void  MoniTool_Profile::AddConf (const Standard_CString name)
{
  if (IsCurrent (name)) return;
  Handle(Dico_DictionaryOfTransient) conf;
  if (theconfs->GetItem (name,conf,Standard_False)) return;
  conf = new Dico_DictionaryOfTransient;
  theconfs->SetItem (name,conf);
//  thecurname.Clear();  thecurname.AssignCat (name);
//  thecurconf = conf;
}

    Standard_Boolean  MoniTool_Profile::HasConf (const Standard_CString name) const
      {  return theconfs->HasItem (name,Standard_False);  }

    Handle(TColStd_HSequenceOfAsciiString)  MoniTool_Profile::ConfList () const
{ 
  Handle(TColStd_HSequenceOfAsciiString) list = new TColStd_HSequenceOfAsciiString();
  Dico_IteratorOfDictionaryOfTransient iter(theconfs);
  for (; iter.More(); iter.Next())  list->Append (iter.Name());
  return list;
}

    Handle(Dico_DictionaryOfTransient)  MoniTool_Profile::Conf
  (const Standard_CString name) const
{
  Handle(Dico_DictionaryOfTransient) conf;
  if (!theconfs->GetItem (name,conf,Standard_False)) conf.Nullify();
  return conf;
}


    Standard_Boolean  MoniTool_Profile::ClearConf
  (const Standard_CString confname)
{
  Handle(Dico_DictionaryOfTransient) conf;
  if (!theconfs->GetItem (confname,conf,Standard_False)) return Standard_False;
  conf->Clear();
  return Standard_True;
}

    Standard_Boolean  MoniTool_Profile::AddFromOtherConf
  (const Standard_CString confname, const Standard_CString otherconf)
{
  Handle(Dico_DictionaryOfTransient) conf, other;
  if (!theconfs->GetItem (confname,conf,Standard_False)) return Standard_False;
  if (!theconfs->GetItem (otherconf,other,Standard_False)) return Standard_False;
  if (conf == other) return Standard_True;
  Dico_IteratorOfDictionaryOfTransient iter(other);
  for (; iter.More(); iter.Next())    conf->SetItem (iter.Name(),iter.Value());
  return Standard_True;
}

    Standard_Boolean  MoniTool_Profile::SetFromCurrent
  (const Standard_CString confname)
{
  Handle(Dico_DictionaryOfTransient) conf;
  if (!theconfs->GetItem (confname,conf,Standard_False)) return Standard_False;
  Dico_IteratorOfDictionaryOfTransient iter(theopts);
  for (; iter.More(); iter.Next()) {
    TCollection_AsciiString name = iter.Name();
    TCollection_AsciiString cn   = CaseName (name.ToCString());
    AddSwitch (name.ToCString(), cn.ToCString() );
  }
  return Standard_True;
}


    Standard_Boolean  MoniTool_Profile::AddSwitch
  (const Standard_CString confname,
   const Standard_CString optname,
   const Standard_CString casename)
{
  Handle(Dico_DictionaryOfTransient) conf = Conf (confname);
  Handle(MoniTool_Option) opt = Option (optname);
  if (conf.IsNull() || opt.IsNull()) return Standard_False;
  Handle(TCollection_HAsciiString) sw = new TCollection_HAsciiString(casename);
  if (casename[0] == '\0') sw = new TCollection_HAsciiString (opt->CaseName());
  Handle(Standard_Transient) val;
  if (!opt->Item (sw->ToCString(),val)) return Standard_False;
  conf->SetItem (optname,sw);
  return Standard_True;
}

    Standard_Boolean  MoniTool_Profile::RemoveSwitch
  (const Standard_CString confname,
   const Standard_CString optname)
{
  Handle(Dico_DictionaryOfTransient) conf = Conf (confname);
  Handle(MoniTool_Option) opt = Option (optname);
  if (conf.IsNull() || opt.IsNull()) return Standard_False;
  conf->RemoveItem (optname,Standard_False,Standard_False);
  return Standard_True;
}


    void  MoniTool_Profile::SwitchList
  (const Standard_CString confname,
   Handle(TColStd_HSequenceOfAsciiString)& optlist,
   Handle(TColStd_HSequenceOfAsciiString)& caselist) const
{
  optlist  = new TColStd_HSequenceOfAsciiString();
  caselist = new TColStd_HSequenceOfAsciiString();
  Handle(Dico_DictionaryOfTransient) conf = Conf (confname);
  if (conf.IsNull()) return;
  Dico_IteratorOfDictionaryOfTransient iter (conf);
  for (; iter.More(); iter.Next()) {
    TCollection_AsciiString optname = iter.Name();
    Handle(TCollection_HAsciiString) cn =
      Handle(TCollection_HAsciiString)::DownCast(iter.Value());
    TCollection_AsciiString casename(cn->ToCString());
    optlist->Append(optname);
    caselist->Append(casename);
  }
}


    Standard_Boolean  MoniTool_Profile::SetCurrent
  (const Standard_CString confname)
{
  if (!AddFromOtherConf (".",confname)) return Standard_False;
  thecurname.Clear();  thecurname.AssignCat (confname);
  return Standard_True;
}

    void  MoniTool_Profile::RecordCurrent ()
{
  Dico_IteratorOfDictionaryOfTransient iter(theconfs);
  for (; iter.More(); iter.Next()) {
    Handle(MoniTool_Option) opt = Option (iter.Name().ToCString());
    Handle(TCollection_HAsciiString) val =
      Handle(TCollection_HAsciiString)::DownCast (iter.Value());
    if (!val.IsNull())  opt->Switch (val->ToCString());
  }
}

    const TCollection_AsciiString&  MoniTool_Profile::Current () const
      {  return thecurname;  }

    TCollection_AsciiString  MoniTool_Profile::CaseName
  (const Standard_CString optname, const Standard_Boolean proper) const
{
  TCollection_AsciiString cn;
  Handle(TCollection_HAsciiString) sw;
  if (thecurconf->GetItem (optname,sw,Standard_True)) {
    cn.AssignCat (sw->ToCString());
    return cn;
  }
  if (proper) return cn;
  Handle(MoniTool_Option) opt = Option (optname);
  if (opt.IsNull()) return cn;
  return opt->CaseName();
}

    Handle(Standard_Transient)  MoniTool_Profile::CaseValue
  (const Standard_CString optname) const
{
  Handle(Standard_Transient) val;
  Handle(MoniTool_Option) opt = Option (optname);
  if (opt.IsNull()) return val;

  Handle(TCollection_HAsciiString) sw;
  if (!thecurconf->GetItem (optname,sw,Standard_True)) sw.Nullify();

  if (sw.IsNull()) return opt->CaseValue();
  if (!opt->Item (sw->ToCString(),val)) val.Nullify();
  return val;
}


    Standard_Boolean  MoniTool_Profile::Value
  (const Standard_CString optname,
   Handle(Standard_Transient)& val) const
{
  Handle(MoniTool_Option) opt = Option (optname);
  if (opt.IsNull()) return Standard_False;

  Handle(TCollection_HAsciiString) sw;
  if (!thecurconf->GetItem (optname,sw,Standard_True)) sw.Nullify();

  if (sw.IsNull()) {  opt->Value(val);  return Standard_True;  }
  return opt->Item (sw->ToCString(),val);
}


    void  MoniTool_Profile::SetTypedValues
  (const Standard_Boolean proper, const Standard_CString name) const
{
  Dico_IteratorOfDictionaryOfTransient iter(theopts,name);
  for (; iter.More(); iter.Next()) {
    Handle(MoniTool_Option) opt = Handle(MoniTool_Option)::DownCast(iter.Value());
    Handle(MoniTool_TypedValue) tv = opt->TypedValue();
    if (tv.IsNull())  continue;

//    On recherche la valeur: en conf courante, sinon dans l option (cf proper)

    Handle(TCollection_HAsciiString) sw, val;
    if (!thecurconf->GetItem (name,sw,Standard_True)) sw.Nullify();
    if (!sw.IsNull()) {
      if (!opt->Item (sw->ToCString(),val)) val.Nullify();
    }
    if (val.IsNull() && !proper) opt->Value(val);

//    On applique
    if (!val.IsNull()) tv->SetHStringValue (val);

  }
}

    void  MoniTool_Profile::SetFast (const Standard_CString confname)
{
  Standard_Boolean cur = (confname[0] == '\0');
  thefastval = new Dico_DictionaryOfTransient;
  Dico_IteratorOfDictionaryOfTransient iter(theopts);
  for (; iter.More(); iter.Next()) {
    Handle(MoniTool_Option) opt = Handle(MoniTool_Option)::DownCast(iter.Value());
    if (opt.IsNull()) continue;
    Standard_Boolean iaopt = Standard_True;
    TCollection_AsciiString optnam = iter.Name();
    Standard_CString optname = optnam.ToCString();
    Handle(Standard_Transient) val;

    if (cur) {
      Handle(TCollection_HAsciiString) sw;
      if (!thecurconf->GetItem (optname,sw,Standard_True)) sw.Nullify();

      if (sw.IsNull()) opt->Value(val);
      else iaopt = opt->Item (sw->ToCString(),val);
    }
    else iaopt = opt->Item (confname,val);

//   Now, recording
    if (iaopt) thefastval->SetItem (optname,val);
  }
}


    void  MoniTool_Profile::ClearFast ()
      {  thefastval.Nullify(); }


    Standard_Boolean  MoniTool_Profile::FastValue
  (const Standard_CString optname,
   Handle(Standard_Transient)& val) const
{
  if (!thefastval.IsNull()) {
    if (thefastval->GetItem (optname,val,Standard_True)) return Standard_True;
  }
  return Value (optname,val);
}