1 #include <Interface_STAT.ixx>
2 #include <TCollection_AsciiString.hxx>
4 static Interface_STAT statvoid("");
5 static Interface_STAT statact ("");
6 static Standard_CString voidname = "";
8 Interface_STAT::Interface_STAT (const Standard_CString title)
10 thetitle = new TCollection_HAsciiString(title);
14 Interface_STAT::Interface_STAT (const Interface_STAT& other)
15 { other.Internals (thetitle,thetotal, thephnam,thephw, thephdeb,thephfin, thestw); }
17 void Interface_STAT::Internals
18 (Handle(TCollection_HAsciiString)& tit, Standard_Real& total,
19 Handle(TColStd_HSequenceOfAsciiString)& phn,
20 Handle(TColStd_HSequenceOfReal)& phw,
21 Handle(TColStd_HSequenceOfInteger)& phdeb,
22 Handle(TColStd_HSequenceOfInteger)& phfin,
23 Handle(TColStd_HSequenceOfReal)& stw) const
25 tit = thetitle; total = thetotal; phn = thephnam; phw = thephw;
26 phdeb = thephdeb; phfin = thephfin; stw = thestw;
29 void Interface_STAT::AddPhase
30 (const Standard_Real weight, const Standard_CString name)
32 if (thephw.IsNull()) {
33 // 1re fois : vider les steps deja notees
35 thephnam = new TColStd_HSequenceOfAsciiString();
36 thephw = new TColStd_HSequenceOfReal();
37 thephdeb = new TColStd_HSequenceOfInteger();
38 thephfin = new TColStd_HSequenceOfInteger();
39 thestw = new TColStd_HSequenceOfReal();
42 thephnam->Append (TCollection_AsciiString (name));
43 thephw->Append (weight);
44 thephdeb->Append (thestw->Length()+1);
49 void Interface_STAT::AddStep (const Standard_Real weight)
51 if (thephdeb.IsNull()) {
52 // 1re fois : pour default phase, au moins creer receptacle des steps
53 thephdeb = new TColStd_HSequenceOfInteger();
54 thephfin = new TColStd_HSequenceOfInteger();
55 thestw = new TColStd_HSequenceOfReal();
56 thephdeb->Append (thestw->Length()+1);
60 // A present, ajouter cette etape
61 Standard_Integer n0 = thephdeb->Value (thephdeb->Length());
62 // Ceci donne dans thestw le numero du cumul des etapes
63 thestw->ChangeValue (n0) += weight;
64 thestw->Append (weight); // on ajoute cette etape
65 thephfin->ChangeValue (thephfin->Length()) ++;
69 void Interface_STAT::Description
70 (Standard_Integer& nbphases,
71 Standard_Real& total, Standard_CString& title) const
73 nbphases = (thephw.IsNull() ? 1 : thephw->Length());
75 title = thetitle->ToCString();
78 void Interface_STAT::Phase
79 (const Standard_Integer num,
80 Standard_Integer& n0step, Standard_Integer& nbstep,
81 Standard_Real& weight, Standard_CString& name) const
83 if (thephdeb.IsNull()) {
84 // Pas de phase, pas d etape ... donc une seule ...
85 n0step = -1; nbstep = 1; weight = 1.; name = voidname;
87 if (thephw.IsNull()) {
88 // Pas de phase mais des etapes
89 weight = 1.; name = voidname;
90 } else if (num < 1 || num > thephdeb->Length()) return;
93 weight = thephw->Value(num); name = thephnam->Value(num).ToCString();
94 n0step = thephdeb->Value(num);
95 nbstep = thephfin->Value(num);
98 // Voyons pour cette phase
101 Standard_Real Interface_STAT::Step (const Standard_Integer num) const
103 if (thestw.IsNull()) return 1.;
104 if (num < 1 || num > thestw->Length()) return 1.;
105 return thestw->Value(num);
108 // ############### COMPTAGE ################
110 // Le comptage se fait sur la base suivante :
111 // TOTAL : total des poids des phases par rapport auquel calculer
112 // PHASES : poids des phases passees et poids de la phase en cours
113 // Ces poids sont a ramener au TOTAL
114 // PHASE COURANTE : nb d items et nb de cycles declares
115 // Nb d items deja passes (cycle complet)
116 // CYCLE COURANT : nb d items de ce cycle, total des poids des etapes
117 // Poids des etapes deja passees, de l etape en cours, n0 etape en cours
118 // ETAPE COURANTE : nb d items deja passes
120 static struct zestat {
121 Standard_CString itle, name;
122 Standard_Real otal, // total des poids des phases
123 oldph, // poids des phases deja passes
124 phw, // poids de la phase en cours
125 otph, // poids des etapes de la phase en cours (cycle en cours)
126 oldst, // poids des etapes deja passees (cycle en cours)
127 stw; // poids etape en cours
128 Standard_Integer nbph, // total nb de phases
129 numph, // n0 phase en cours
130 n0, n1, // n0 et nb etapes dans phase en cours
131 nbitp, // nb items total phase
132 nbcyc, // nb cycles total phase
133 olditp, // nb items deja passes (cycles passes) / phase
134 numcyc, // n0 cycle en cours / phase
135 nbitc, // nb items cycle en cours
136 numst, // n0 etape en cours / cycle
137 numitem; // nb items deja passes / etape courante
141 void Interface_STAT::Start
142 (const Standard_Integer items, const Standard_Integer cycles) const
145 statact.Description (stat.nbph,stat.otal,stat.itle);
146 stat.oldph = stat.phw = 0.; stat.numph = 0;
147 NextPhase (items,cycles);
150 void Interface_STAT::StartCount
151 (const Standard_Integer items, const Standard_CString name)
153 Interface_STAT statcount(name);
154 statcount.Start (items);
157 void Interface_STAT::NextPhase
158 (const Standard_Integer items, const Standard_Integer cycles)
160 // On cumule la phase precedente au total, on efface les donnees "locales"
161 stat.numcyc = stat.numst = stat.olditp = 0; stat.oldst = stat.stw = 0.;
162 if (stat.numph >= stat.nbph) { End(); return; }
164 stat.numph ++; stat.oldph += stat.phw; // cumule sur cette phase
165 stat.nbitp = items; stat.nbcyc = cycles;
166 statact.Phase(stat.numph, stat.n0,stat.n1,stat.phw,stat.name);
167 stat.otph = (stat.n1 > 1 ? statact.Step (stat.n0) : 1.);
168 // si un seul cycle, on le demarre; sinon, attendre NextCycle
170 if (cycles == 1) NextCycle (items);
173 void Interface_STAT::SetPhase
174 (const Standard_Integer items, const Standard_Integer cycles)
175 { stat.nbitp = items; stat.nbcyc = cycles; }
177 void Interface_STAT::NextCycle (const Standard_Integer items)
179 // cumul de ce cycle sur les cycles deja passes, raz etapes
180 stat.numcyc ++; stat.olditp += stat.nbitc;
181 // if (stat.olditem > stat.nbitp) return;
184 stat.stw = (stat.n1 > 1 ? statact.Step(stat.n0 + 1) : stat.otph);
185 stat.nbitc = items; stat.numitem = 0;
188 void Interface_STAT::NextStep ()
190 if (stat.numst >= stat.n1) return;
191 stat.numst ++; stat.oldst += stat.stw;
193 stat.stw = statact.Step (stat.n0 + stat.numst);
196 void Interface_STAT::NextItem (const Standard_Integer nbitems)
197 { stat.numitem += nbitems; }
199 void Interface_STAT::End ()
200 { stat.oldph = stat.otal; stat.phw = stat.stw = 0.; stat.itle = stat.name = voidname; }
202 // ########### QUERY ############
204 Standard_CString Interface_STAT::Where (const Standard_Boolean phase)
205 { return (phase ? stat.name : stat.itle); }
207 Standard_Integer Interface_STAT::Percent (const Standard_Boolean phase)
209 if (stat.numitem > stat.nbitc) stat.numitem = stat.nbitc;
210 // on compte les items deja passes
211 Standard_Real enphase =
212 stat.olditp * stat.otph + // cycles complets passes
213 stat.nbitc * stat.oldst + // cycle courant, etapes completes passees
214 stat.numitem * stat.stw; // etape courante
215 // proportion pour cette phase
216 Standard_Real prophase = enphase / (stat.nbitp * stat.otph);
217 Standard_Integer res = Standard_Integer (prophase*100.);
218 if (phase) return res;
220 // voila pour cette phase
221 // comptage dans les phases
222 Standard_Real encours = (stat.oldph + stat.phw * prophase) / stat.otal;
223 res = Standard_Integer (encours * 100.);