summaryrefslogtreecommitdiff
path: root/src/MoniTool/MoniTool_CaseData.cxx
blob: c76360b1b830c8b73580c9c70b62dc3224d6d175 (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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#include <MoniTool_CaseData.ixx>
#include <Standard_Failure.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_HShape.hxx>
#include <Geom_CartesianPoint.hxx>
#include <Geom2d_CartesianPoint.hxx>

#include <TopAbs.hxx>
//#include <GeomTools.hxx>
#include <TCollection_HAsciiString.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Surface.hxx>
#include <OSD_Timer.hxx>

// definitions
#include <Dico_DictionaryOfInteger.hxx>
#include <Dico_DictionaryOfTransient.hxx>

static Handle(Dico_DictionaryOfInteger)& defchecks()
{
  static Handle(Dico_DictionaryOfInteger) defch;
  if (defch.IsNull()) defch = new Dico_DictionaryOfInteger();
  return defch;
}

static Handle(Dico_DictionaryOfTransient)& defmess()
{
  static Handle(Dico_DictionaryOfTransient) defms;
  if (defms.IsNull()) defms = new Dico_DictionaryOfTransient();
  return defms;
}


static Standard_Boolean stachr = Standard_False;

//static OSD_Timer chrono;
// because merdouille link dynamique & perf, ne creer le static qu au 1er usage
static OSD_Timer& chrono() {
  static OSD_Timer chr;
  return chr;
}


    MoniTool_CaseData::MoniTool_CaseData
  (const Standard_CString caseid, const Standard_CString name)
    : thesubst (0) , thecase (caseid) , thename (name)  
      {  thecheck = DefCheck(caseid);  }

    void  MoniTool_CaseData::SetCaseId (const Standard_CString caseid)
      {  thecase.Clear();  thecase.AssignCat (caseid);  thecheck = DefCheck(caseid);  thesubst = 0;  }

    void  MoniTool_CaseData::SetName   (const Standard_CString name)
      {  thename.Clear();  thename.AssignCat (name);  thesubst = 0;  }

    Standard_CString  MoniTool_CaseData::CaseId () const
      {  return thecase.ToCString();  }

    Standard_CString  MoniTool_CaseData::Name   () const
      {  return thename.ToCString();  }


    Standard_Boolean  MoniTool_CaseData::IsCheck   () const
      {  return  (thecheck > 0);  }

    Standard_Boolean  MoniTool_CaseData::IsWarning () const
      {  return (thecheck == 1);  }

    Standard_Boolean  MoniTool_CaseData::IsFail    () const
      {  return (thecheck == 2);  }

    void  MoniTool_CaseData::ResetCheck ()
      {  thecheck = 0;  }

    void  MoniTool_CaseData::SetWarning ()
      {  thecheck = 1;  }

    void  MoniTool_CaseData::SetFail    ()
      {  thecheck = 2;  }

//  ####    DATA    ####

    void  MoniTool_CaseData::SetChange  ()
      {  thesubst = -1;   }

    void  MoniTool_CaseData::SetReplace (const Standard_Integer num)
      {  thesubst = num;  }

    void  MoniTool_CaseData::AddData
  (const Handle(Standard_Transient)& val,
   const Standard_Integer kind, const Standard_CString name)
{
  TCollection_AsciiString aname(name);
  Standard_Integer subs = thesubst;

//  SetChange (calculer la position d apres Name)
  if (thesubst < 0) {
    if (name[0] != '\0') subs = NameNum (name);
  }
//  SetChange / SetReplace
  if (subs > 0 && subs <= thedata.Length()) {
    thedata.SetValue (subs,val);
    thekind.SetValue (subs,kind);
    if (aname.Length() > 0) thednam.SetValue (subs,aname);
//  Ajout Normal
  } else {
    thedata.Append (val);
    thekind.Append (kind);
    thednam.Append (aname);
  }
  thesubst = 0;
}

    void  MoniTool_CaseData::AddRaised (const Standard_CString name)
      {  AddData ( Standard_Failure::Caught(),1,name);  }

    void  MoniTool_CaseData::AddShape
  (const TopoDS_Shape& sh, const Standard_CString name)
      {  AddData ( new TopoDS_HShape(sh), 4,name);  }

    void  MoniTool_CaseData::AddXYZ
  (const gp_XYZ& aXYZ, const Standard_CString name)
      {  AddData ( new Geom_CartesianPoint (aXYZ), 5,name);  }

    void  MoniTool_CaseData::AddXY
  (const gp_XY&  aXY, const Standard_CString name)
      {  AddData ( new Geom2d_CartesianPoint (aXY), 6,name);  }

    void  MoniTool_CaseData::AddReal
  (const Standard_Real val, const Standard_CString name)
      {  AddData ( new Geom2d_CartesianPoint (val,0.), 8,name);  }

    void  MoniTool_CaseData::AddReals
 (const Standard_Real v1, const Standard_Real v2, const Standard_CString name)
      {  AddData ( new Geom2d_CartesianPoint (v1,v2), 7,name);  }

    void  MoniTool_CaseData::AddCPU
  (const Standard_Real lastCPU, const Standard_Real curCPU,
   const Standard_CString name)
{
  Standard_Real cpu = curCPU;
  if (cpu == 0.) {
    Standard_Real sec;  Standard_Integer i1,i2;
    chrono().Show (sec,i1,i2,cpu);
  }
  cpu = cpu - lastCPU;
  AddData ( new Geom2d_CartesianPoint (cpu,0.), 9,name);
}

    Standard_Real  MoniTool_CaseData::GetCPU () const
{
  if (!stachr) { chrono().Start(); stachr = Standard_True; }
  Standard_Real sec,cpu;  Standard_Integer i1,i2;
  chrono().Show (sec,i1,i2,cpu);
  return cpu;
}

    Standard_Boolean  MoniTool_CaseData::LargeCPU
  (const Standard_Real maxCPU,
   const Standard_Real lastCPU, const Standard_Real curCPU) const
{
  Standard_Real cpu = curCPU;
  if (cpu == 0.) {
    Standard_Real sec;  Standard_Integer i1,i2;
    chrono().Show (sec,i1,i2,cpu);
  }
  cpu = cpu - lastCPU;
  return (cpu >= maxCPU);
}

    void  MoniTool_CaseData::AddGeom
  (const Handle(Standard_Transient)& val, const Standard_CString name)
      {  AddData (val,3,name);  }

    void  MoniTool_CaseData::AddEntity
  (const Handle(Standard_Transient)& val, const Standard_CString name)
      {  AddData (val,2,name);  }

    void  MoniTool_CaseData::AddText
  (const Standard_CString text, const Standard_CString name)
      {  AddData (new TCollection_HAsciiString(text),10,name);  }

    void  MoniTool_CaseData::AddInteger
  (const Standard_Integer val, const Standard_CString name)
{
  Standard_Real rval = val;
  AddData ( new Geom2d_CartesianPoint (rval,0.), 11,name);
}

    void  MoniTool_CaseData::AddAny
  (const Handle(Standard_Transient)& val, const Standard_CString name)
      {  AddData (val,0,name);  }


    void  MoniTool_CaseData::RemoveData (const Standard_Integer num)
{
  if (num < 1 || num > thedata.Length()) return;
  thedata.Remove(num);  thekind.Remove(num);  thednam.Remove(num);
}

//    ####    INTERROGATIONS    ####

    Standard_Integer  MoniTool_CaseData::NbData () const
      {  return thedata.Length();  }

    Handle(Standard_Transient)  MoniTool_CaseData::Data
  (const Standard_Integer nd) const
{
  Handle(Standard_Transient) val;
  if (nd < 1 || nd > thedata.Length()) return val;
  return thedata (nd);
}

Standard_Boolean  MoniTool_CaseData::GetData
  (const Standard_Integer nd, const Handle(Standard_Type)& type,
   Handle(Standard_Transient)& val) const
{
  if (type.IsNull()) return Standard_False;
  if (nd < 1 || nd > thedata.Length()) return Standard_False;
  Handle(Standard_Transient) v = thedata (nd);
  if (v.IsNull()) return Standard_False;
  if (!v->IsKind(type)) return Standard_False;
  val = v;
  return Standard_True;
}

    Standard_Integer  MoniTool_CaseData::Kind
  (const Standard_Integer nd) const
{
  if (nd < 1 || nd > thekind.Length()) return 0;
  return thekind (nd);
}


static  const TCollection_AsciiString&  nulname ()
{
  static TCollection_AsciiString nuln;
  return nuln;
}

    const TCollection_AsciiString&  MoniTool_CaseData::Name
  (const Standard_Integer nd) const
{
  if (nd < 1 || nd > thednam.Length()) return nulname();
  return thednam(nd);
}

static Standard_Integer NameKind (const Standard_CString name)
{
  char n0 = name[0];
  if (n0 == 'A' && name[1] == 'N' && name[2] == 'Y' && name[3] == '\0') return 0;
  if (n0 == 'E') {
    if (name[1] == 'X' && name[2] == '\0') return 1;
    if (name[1] == 'N' && name[2] == '\0') return 2;
    return 0;
  }
  if (n0 == 'G' && name[1] == '\0') return 3;
  if (n0 == 'S' && name[1] == 'H' && name[2] == '\0') return 4;
  if (n0 == 'X' && name[1] == 'Y') {
    if (name[2] == 'Z' && name[3] == '\0') return 5;
    if (name[2] == '\0') return 6;
  }
  if (n0 == 'U' && name[1] == 'V' && name[2] == '\0') return 6;
  if (n0 == 'R') {
    if (name[1] == '\0') return 8;
    if (name[1] == 'R' && name[2] == '\0') return 7;
  }
  if (n0 == 'C' && name[1] == 'P' && name[2] == 'U' && name[3] == '\0') return 9;
  if (n0 == 'T' && name[1] == '\0') return 10;
  if (n0 == 'I' && name[1] == '\0') return 11;

  return 0;
}

static Standard_Integer NameRank (const Standard_CString name)
{
  for (Standard_Integer i = 0; name[i] != '\0'; i ++) {
    if (name[i] == ':' && name[i+1] != '\0') return atoi(&name[i+1]);
  }
  return 1;
}

    Standard_Integer  MoniTool_CaseData::NameNum
  (const Standard_CString name) const
{
  if (!name || name[0] == '\0') return 0;
  Standard_Integer nd, nn = 0, nb = NbData();
  for (nd = 1; nd <= nb; nd ++) {
    if (thednam(nd).IsEqual(name)) return nd;
  }

  Standard_Integer kind = NameKind (name);
  if (kind < 0) return 0;
  Standard_Integer num  = NameRank (name);

  for (nd = 1; nd <= nb; nd ++) {
    if (thekind(nd) == kind) {
      nn ++;
      if (nn == num) return nd;
    }
  }
  return 0;
}


//  ####    RETOUR DES VALEURS    ####

    TopoDS_Shape  MoniTool_CaseData::Shape
  (const Standard_Integer nd) const
{
  TopoDS_Shape sh;
  Handle(TopoDS_HShape) hs = Handle(TopoDS_HShape)::DownCast (Data(nd));
  if (!hs.IsNull()) sh = hs->Shape();
  return sh;
}

    Standard_Boolean  MoniTool_CaseData::XYZ
  (const Standard_Integer nd, gp_XYZ& val) const
{
  Handle(Geom_CartesianPoint) p = Handle(Geom_CartesianPoint)::DownCast(Data(nd));
  if (p.IsNull()) return Standard_False;
  val = p->Pnt().XYZ();
  return Standard_True;
}

    Standard_Boolean   MoniTool_CaseData::XY
  (const Standard_Integer nd, gp_XY& val) const
{
  Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
  if (p.IsNull()) return Standard_False;
  val = p->Pnt2d().XY();
  return Standard_True;
}

    Standard_Boolean   MoniTool_CaseData::Reals
  (const Standard_Integer nd,
   Standard_Real& v1, Standard_Real& v2) const
{
  Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
  if (p.IsNull()) return Standard_False;
  v1 = p->X();  v2 = p->Y();
  return Standard_True;
}


    Standard_Boolean   MoniTool_CaseData::Real
  (const Standard_Integer nd,
   Standard_Real& val) const
{
  Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
  if (p.IsNull()) return Standard_False;
  val = p->X();
  return Standard_True;
}

    Standard_Boolean   MoniTool_CaseData::Text
  (const Standard_Integer nd,
   Standard_CString& text) const
{
  Handle(TCollection_HAsciiString) t = Handle(TCollection_HAsciiString)::DownCast(Data(nd));
  if (t.IsNull()) return Standard_False;
  text = t->ToCString();
  return Standard_True;
}

    Standard_Boolean   MoniTool_CaseData::Integer
  (const Standard_Integer nd,
   Standard_Integer& val) const
{
  Handle(Geom2d_CartesianPoint) p = Handle(Geom2d_CartesianPoint)::DownCast(Data(nd));
//  if (p.IsNull()) return Standard_False;
  if (thekind(nd) != 11) return Standard_False;
  Standard_Real rval = p->X();
  val = (Standard_Integer)rval;
  return Standard_True;
}


//  ####    MESSAGES ET DEFINITIONS    ####

Message_Msg  MoniTool_CaseData::Msg () const
{
  Standard_CString defm = DefMsg (thecase.ToCString());

//  A REPRENDRE COMPLETEMENT !  Il faut analyser defm = mescode + variables
  Message_Msg mess;
  mess.Set (defm);

  return mess;
}


    void  MoniTool_CaseData::SetDefWarning (const Standard_CString acode)
      {  defchecks()->SetItem (acode,1);  }

    void  MoniTool_CaseData::SetDefFail (const Standard_CString acode)
      {  defchecks()->SetItem (acode,2);  }

    Standard_Integer  MoniTool_CaseData::DefCheck (const Standard_CString acode)
{
  Standard_Integer val;
  if (!defchecks()->GetItem (acode,val)) val = 0;
  return val;
}


    void  MoniTool_CaseData::SetDefMsg
  (const Standard_CString casecode, const Standard_CString mesdef)
{
  Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mesdef);
  defmess()->SetItem (casecode,str);
}

    Standard_CString MoniTool_CaseData::DefMsg (const Standard_CString casecode)
{
  //Standard_CString mesd;
  Handle(TCollection_HAsciiString) str;
  if (!defmess()->GetItem (casecode,str)) return "";
  if (str.IsNull()) return "";
  return str->ToCString();
}