0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / MoniTool / MoniTool_Stat.cxx
CommitLineData
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
42cf5bc1 14
15#include <MoniTool_Stat.hxx>
7fd59977 16#include <TCollection_AsciiString.hxx>
42cf5bc1 17#include <TCollection_HAsciiString.hxx>
7fd59977 18
19//static MoniTool_Stat Statvoid("");
20//static MoniTool_Stat Statact ("");
7fd59977 21//not Used
22//static Standard_CString voidname = "";
b311480e 23MoniTool_Stat::MoniTool_Stat (const Standard_CString title)
7fd59977 24{
25 thetit = new TCollection_HAsciiString(title);
26 thelev = 0;
27 thetot = new TColStd_HArray1OfInteger (1,20); thetot->Init(0);
28 thedone = new TColStd_HArray1OfInteger (1,20); thetot->Init(0);
29 thecurr = new TColStd_HArray1OfInteger (1,20); thetot->Init(0);
30}
31
32 MoniTool_Stat::MoniTool_Stat (const MoniTool_Stat& )
33{ }
34
35 MoniTool_Stat& MoniTool_Stat::Current ()
36{
37 static MoniTool_Stat thecur;
38 return thecur;
39}
40
41 Standard_Integer MoniTool_Stat::Open (const Standard_Integer nb)
42{
43 thelev ++;
44 thetot->SetValue(thelev,nb);
45 thedone->SetValue(thelev,0);
46 thecurr->SetValue(thelev,0);
47 return thelev;
48}
49
50void MoniTool_Stat::OpenMore (const Standard_Integer id, const Standard_Integer nb)
51{
52 if (id <= 0 || id > thelev) return;
53 thetot->SetValue (id, thetot->Value(id)+nb);
54}
55
56void MoniTool_Stat::Add (const Standard_Integer nb)
57{
58 thedone->SetValue (thelev, thedone->Value(thelev) + nb);
59 thecurr->SetValue (thelev, 0);
60}
61
62void MoniTool_Stat::AddSub (const Standard_Integer nb)
63{
64 thecurr->SetValue (thelev, nb);
65}
66
67void MoniTool_Stat::AddEnd ()
68{
69 thedone->SetValue (thelev, thedone->Value(thelev) + thecurr->Value(thelev));
70 thecurr->SetValue (thelev, 0);
71}
72
73void MoniTool_Stat::Close (const Standard_Integer id)
74{
75 if (id < thelev) Close (id+1);
76 AddEnd();
77 thelev --;
78}
79
80Standard_Integer MoniTool_Stat::Level () const
81{ return thelev; }
82
83Standard_Real MoniTool_Stat::Percent (const Standard_Integer fromlev) const
84{
85 if (fromlev > thelev) return 0;
86 Standard_Real r1,r2,r3;
87 Standard_Integer tot = thetot->Value(fromlev);
88 Standard_Integer done = thedone->Value(fromlev);
89 if (done >= tot) return 100.;
90 if (fromlev == thelev) {
91 r1 = tot; r2 = done;
92 return (r2*100)/r1;
93 }
94 Standard_Integer cur = thecurr->Value(fromlev);
95 r1 = tot; r2 = done;
96 r3 = 0;
97 if (cur > 0) { r3 = cur; r3 = cur/tot; r3 = r3*Percent (fromlev+1); }
98 if (r1 == 0) return 1;
99 return (r2*100)/r1 + r3;
100}