summaryrefslogtreecommitdiff
path: root/src/MoniTool/MoniTool_Stat.cxx
blob: 8779aa17404cc6349b4c9349d637bbf2c4ec4954 (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
#include <MoniTool_Stat.ixx>
#include <TCollection_AsciiString.hxx>

//static MoniTool_Stat Statvoid("");
//static MoniTool_Stat Statact ("");

//not Used
//static Standard_CString voidname = "";


    MoniTool_Stat::MoniTool_Stat (const Standard_CString title)
{
  thetit  = new TCollection_HAsciiString(title);
  thelev  = 0;
  thetot  = new TColStd_HArray1OfInteger (1,20);  thetot->Init(0);
  thedone = new TColStd_HArray1OfInteger (1,20);  thetot->Init(0);
  thecurr = new TColStd_HArray1OfInteger (1,20);  thetot->Init(0);
}

    MoniTool_Stat::MoniTool_Stat (const MoniTool_Stat& )
{  }

    MoniTool_Stat&  MoniTool_Stat::Current ()
{
  static MoniTool_Stat thecur;
  return thecur;
}

    Standard_Integer  MoniTool_Stat::Open (const Standard_Integer nb)
{
  thelev ++;
  thetot->SetValue(thelev,nb);
  thedone->SetValue(thelev,0);
  thecurr->SetValue(thelev,0);
  return thelev;
}

void  MoniTool_Stat::OpenMore (const Standard_Integer id, const Standard_Integer nb)
{
  if (id <= 0 || id > thelev) return;
  thetot->SetValue (id, thetot->Value(id)+nb);
}

void  MoniTool_Stat::Add (const Standard_Integer nb)
{
  thedone->SetValue (thelev, thedone->Value(thelev) + nb);
  thecurr->SetValue (thelev, 0);
}

void  MoniTool_Stat::AddSub (const Standard_Integer nb)
{
  thecurr->SetValue (thelev, nb);
}

void  MoniTool_Stat::AddEnd ()
{
  thedone->SetValue (thelev, thedone->Value(thelev) + thecurr->Value(thelev));
  thecurr->SetValue (thelev, 0);
}

void MoniTool_Stat::Close (const Standard_Integer id)
{
  if (id < thelev) Close (id+1);
  AddEnd();
  thelev --;
}

Standard_Integer  MoniTool_Stat::Level () const
{  return thelev;  }

Standard_Real  MoniTool_Stat::Percent (const Standard_Integer fromlev) const
{
  if (fromlev > thelev) return 0;
  Standard_Real r1,r2,r3;
  Standard_Integer tot  = thetot->Value(fromlev);
  Standard_Integer done = thedone->Value(fromlev);
  if (done >= tot) return 100.;
  if (fromlev == thelev) {
    r1 = tot;  r2 = done;
    return (r2*100)/r1;
  }
  Standard_Integer cur = thecurr->Value(fromlev);
  r1 = tot;  r2 = done;
  r3 = 0;
  if (cur > 0) { r3 = cur; r3 = cur/tot; r3 = r3*Percent (fromlev+1); }
  if (r1 == 0) return 1;
  return (r2*100)/r1 + r3;
}