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 <Interface_STAT.hxx> |
7fd59977 |
16 | #include <TCollection_AsciiString.hxx> |
42cf5bc1 |
17 | #include <TCollection_HAsciiString.hxx> |
7fd59977 |
18 | |
19 | static Interface_STAT statvoid(""); |
20 | static Interface_STAT statact (""); |
21 | static Standard_CString voidname = ""; |
22 | |
23 | Interface_STAT::Interface_STAT (const Standard_CString title) |
24 | { |
25 | thetitle = new TCollection_HAsciiString(title); |
26 | thetotal = 1.; |
27 | } |
28 | |
29 | Interface_STAT::Interface_STAT (const Interface_STAT& other) |
30 | { other.Internals (thetitle,thetotal, thephnam,thephw, thephdeb,thephfin, thestw); } |
31 | |
32 | void Interface_STAT::Internals |
33 | (Handle(TCollection_HAsciiString)& tit, Standard_Real& total, |
34 | Handle(TColStd_HSequenceOfAsciiString)& phn, |
35 | Handle(TColStd_HSequenceOfReal)& phw, |
36 | Handle(TColStd_HSequenceOfInteger)& phdeb, |
37 | Handle(TColStd_HSequenceOfInteger)& phfin, |
38 | Handle(TColStd_HSequenceOfReal)& stw) const |
39 | { |
40 | tit = thetitle; total = thetotal; phn = thephnam; phw = thephw; |
41 | phdeb = thephdeb; phfin = thephfin; stw = thestw; |
42 | } |
43 | |
44 | void Interface_STAT::AddPhase |
45 | (const Standard_Real weight, const Standard_CString name) |
46 | { |
47 | if (thephw.IsNull()) { |
48 | // 1re fois : vider les steps deja notees |
49 | thetotal = 0.; |
50 | thephnam = new TColStd_HSequenceOfAsciiString(); |
51 | thephw = new TColStd_HSequenceOfReal(); |
52 | thephdeb = new TColStd_HSequenceOfInteger(); |
53 | thephfin = new TColStd_HSequenceOfInteger(); |
54 | thestw = new TColStd_HSequenceOfReal(); |
55 | } |
56 | thetotal += weight; |
57 | thephnam->Append (TCollection_AsciiString (name)); |
58 | thephw->Append (weight); |
59 | thephdeb->Append (thestw->Length()+1); |
60 | thephfin->Append (0); |
61 | thestw->Append (0.); |
62 | } |
63 | |
64 | void Interface_STAT::AddStep (const Standard_Real weight) |
65 | { |
66 | if (thephdeb.IsNull()) { |
67 | // 1re fois : pour default phase, au moins creer receptacle des steps |
68 | thephdeb = new TColStd_HSequenceOfInteger(); |
69 | thephfin = new TColStd_HSequenceOfInteger(); |
70 | thestw = new TColStd_HSequenceOfReal(); |
71 | thephdeb->Append (thestw->Length()+1); |
72 | thephfin->Append (1); |
73 | thestw->Append (0.); |
74 | } |
75 | // A present, ajouter cette etape |
76 | Standard_Integer n0 = thephdeb->Value (thephdeb->Length()); |
77 | // Ceci donne dans thestw le numero du cumul des etapes |
78 | thestw->ChangeValue (n0) += weight; |
79 | thestw->Append (weight); // on ajoute cette etape |
80 | thephfin->ChangeValue (thephfin->Length()) ++; |
81 | } |
82 | |
83 | |
84 | void Interface_STAT::Description |
85 | (Standard_Integer& nbphases, |
86 | Standard_Real& total, Standard_CString& title) const |
87 | { |
88 | nbphases = (thephw.IsNull() ? 1 : thephw->Length()); |
89 | total = thetotal; |
90 | title = thetitle->ToCString(); |
91 | } |
92 | |
93 | void Interface_STAT::Phase |
94 | (const Standard_Integer num, |
95 | Standard_Integer& n0step, Standard_Integer& nbstep, |
96 | Standard_Real& weight, Standard_CString& name) const |
97 | { |
98 | if (thephdeb.IsNull()) { |
99 | // Pas de phase, pas d etape ... donc une seule ... |
100 | n0step = -1; nbstep = 1; weight = 1.; name = voidname; |
101 | } |
102 | if (thephw.IsNull()) { |
103 | // Pas de phase mais des etapes |
104 | weight = 1.; name = voidname; |
105 | } else if (num < 1 || num > thephdeb->Length()) return; |
106 | else { |
107 | // Phase |
108 | weight = thephw->Value(num); name = thephnam->Value(num).ToCString(); |
109 | n0step = thephdeb->Value(num); |
110 | nbstep = thephfin->Value(num); |
111 | } |
112 | |
113 | // Voyons pour cette phase |
114 | } |
115 | |
116 | Standard_Real Interface_STAT::Step (const Standard_Integer num) const |
117 | { |
118 | if (thestw.IsNull()) return 1.; |
119 | if (num < 1 || num > thestw->Length()) return 1.; |
120 | return thestw->Value(num); |
121 | } |
122 | |
123 | // ############### COMPTAGE ################ |
124 | |
125 | // Le comptage se fait sur la base suivante : |
126 | // TOTAL : total des poids des phases par rapport auquel calculer |
127 | // PHASES : poids des phases passees et poids de la phase en cours |
128 | // Ces poids sont a ramener au TOTAL |
129 | // PHASE COURANTE : nb d items et nb de cycles declares |
130 | // Nb d items deja passes (cycle complet) |
131 | // CYCLE COURANT : nb d items de ce cycle, total des poids des etapes |
132 | // Poids des etapes deja passees, de l etape en cours, n0 etape en cours |
133 | // ETAPE COURANTE : nb d items deja passes |
134 | |
135 | static struct zestat { |
136 | Standard_CString itle, name; |
137 | Standard_Real otal, // total des poids des phases |
138 | oldph, // poids des phases deja passes |
139 | phw, // poids de la phase en cours |
140 | otph, // poids des etapes de la phase en cours (cycle en cours) |
141 | oldst, // poids des etapes deja passees (cycle en cours) |
142 | stw; // poids etape en cours |
143 | Standard_Integer nbph, // total nb de phases |
144 | numph, // n0 phase en cours |
145 | n0, n1, // n0 et nb etapes dans phase en cours |
146 | nbitp, // nb items total phase |
147 | nbcyc, // nb cycles total phase |
148 | olditp, // nb items deja passes (cycles passes) / phase |
149 | numcyc, // n0 cycle en cours / phase |
150 | nbitc, // nb items cycle en cours |
151 | numst, // n0 etape en cours / cycle |
152 | numitem; // nb items deja passes / etape courante |
9bfa28a7 |
153 | } TheStat; |
7fd59977 |
154 | |
155 | |
156 | void Interface_STAT::Start |
157 | (const Standard_Integer items, const Standard_Integer cycles) const |
158 | { |
159 | statact = *this; |
9bfa28a7 |
160 | statact.Description (TheStat.nbph, TheStat.otal, TheStat.itle); |
161 | TheStat.oldph = TheStat.phw = 0.; TheStat.numph = 0; |
7fd59977 |
162 | NextPhase (items,cycles); |
163 | } |
164 | |
165 | void Interface_STAT::StartCount |
166 | (const Standard_Integer items, const Standard_CString name) |
167 | { |
168 | Interface_STAT statcount(name); |
169 | statcount.Start (items); |
170 | } |
171 | |
172 | void Interface_STAT::NextPhase |
173 | (const Standard_Integer items, const Standard_Integer cycles) |
174 | { |
175 | // On cumule la phase precedente au total, on efface les donnees "locales" |
9bfa28a7 |
176 | TheStat.numcyc = TheStat.numst = TheStat.olditp = 0; TheStat.oldst = TheStat.stw = 0.; |
177 | if (TheStat.numph >= TheStat.nbph) { End(); return; } |
7fd59977 |
178 | |
9bfa28a7 |
179 | TheStat.numph ++; TheStat.oldph += TheStat.phw; // cumule sur cette phase |
180 | TheStat.nbitp = items; TheStat.nbcyc = cycles; |
181 | statact.Phase(TheStat.numph, TheStat.n0, TheStat.n1, TheStat.phw, TheStat.name); |
182 | TheStat.otph = (TheStat.n1 > 1 ? statact.Step (TheStat.n0) : 1.); |
7fd59977 |
183 | // si un seul cycle, on le demarre; sinon, attendre NextCycle |
9bfa28a7 |
184 | TheStat.nbitc = 0; |
7fd59977 |
185 | if (cycles == 1) NextCycle (items); |
186 | } |
187 | |
188 | void Interface_STAT::SetPhase |
189 | (const Standard_Integer items, const Standard_Integer cycles) |
9bfa28a7 |
190 | { TheStat.nbitp = items; TheStat.nbcyc = cycles; } |
7fd59977 |
191 | |
192 | void Interface_STAT::NextCycle (const Standard_Integer items) |
193 | { |
194 | // cumul de ce cycle sur les cycles deja passes, raz etapes |
9bfa28a7 |
195 | TheStat.numcyc ++; TheStat.olditp += TheStat.nbitc; |
7fd59977 |
196 | // if (stat.olditem > stat.nbitp) return; |
9bfa28a7 |
197 | TheStat.numst = 1; |
198 | TheStat.oldst = 0.; |
199 | TheStat.stw = (TheStat.n1 > 1 ? statact.Step(TheStat.n0 + 1) : TheStat.otph); |
200 | TheStat.nbitc = items; TheStat.numitem = 0; |
7fd59977 |
201 | } |
202 | |
203 | void Interface_STAT::NextStep () |
204 | { |
9bfa28a7 |
205 | if (TheStat.numst >= TheStat.n1) return; |
206 | TheStat.numst ++; TheStat.oldst += TheStat.stw; |
207 | TheStat.numitem = 0; |
208 | TheStat.stw = statact.Step (TheStat.n0 + TheStat.numst); |
7fd59977 |
209 | } |
210 | |
211 | void Interface_STAT::NextItem (const Standard_Integer nbitems) |
9bfa28a7 |
212 | { TheStat.numitem += nbitems; } |
7fd59977 |
213 | |
214 | void Interface_STAT::End () |
9bfa28a7 |
215 | { TheStat.oldph = TheStat.otal; TheStat.phw = TheStat.stw = 0.; TheStat.itle = TheStat.name = voidname; } |
7fd59977 |
216 | |
217 | // ########### QUERY ############ |
218 | |
219 | Standard_CString Interface_STAT::Where (const Standard_Boolean phase) |
9bfa28a7 |
220 | { return (phase ? TheStat.name : TheStat.itle); } |
7fd59977 |
221 | |
222 | Standard_Integer Interface_STAT::Percent (const Standard_Boolean phase) |
223 | { |
9bfa28a7 |
224 | if (TheStat.numitem > TheStat.nbitc) TheStat.numitem = TheStat.nbitc; |
7fd59977 |
225 | // on compte les items deja passes |
226 | Standard_Real enphase = |
9bfa28a7 |
227 | TheStat.olditp * TheStat.otph + // cycles complets passes |
228 | TheStat.nbitc * TheStat.oldst + // cycle courant, etapes completes passees |
229 | TheStat.numitem * TheStat.stw; // etape courante |
7fd59977 |
230 | // proportion pour cette phase |
9bfa28a7 |
231 | Standard_Real prophase = enphase / (TheStat.nbitp * TheStat.otph); |
7fd59977 |
232 | Standard_Integer res = Standard_Integer (prophase*100.); |
233 | if (phase) return res; |
234 | |
235 | // voila pour cette phase |
236 | // comptage dans les phases |
9bfa28a7 |
237 | Standard_Real encours = (TheStat.oldph + TheStat.phw * prophase) / TheStat.otal; |
7fd59977 |
238 | res = Standard_Integer (encours * 100.); |
239 | return res; |
240 | } |