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 | |
7fd59977 |
14 | #include <IFSelect_SignatureList.ixx> |
15 | #include <Dico_IteratorOfDictionaryOfInteger.hxx> |
16 | #include <Dico_IteratorOfDictionaryOfTransient.hxx> |
17 | #include <TColStd_HSequenceOfTransient.hxx> |
18 | #include <Interface_MSG.hxx> |
19 | #include <Interface_Macros.hxx> |
20 | #include <Message_Messenger.hxx> |
21 | #include <Message.hxx> |
22 | |
b311480e |
23 | IFSelect_SignatureList::IFSelect_SignatureList |
7fd59977 |
24 | (const Standard_Boolean withlist) |
25 | { |
26 | thesignonly = Standard_False; |
27 | thelistat = withlist; |
28 | thenbnuls = 0; |
29 | thedicount = new Dico_DictionaryOfInteger; |
30 | thediclist = new Dico_DictionaryOfTransient; |
31 | SetName("..."); |
32 | } |
33 | |
34 | void IFSelect_SignatureList::SetList |
35 | (const Standard_Boolean withlist) |
36 | { thelistat = withlist; } |
37 | |
38 | Standard_Boolean& IFSelect_SignatureList::ModeSignOnly () |
39 | { return thesignonly; } |
40 | |
41 | void IFSelect_SignatureList::Clear () |
42 | { |
43 | thelastval.Clear(); |
44 | thenbnuls = 0; |
45 | thedicount = new Dico_DictionaryOfInteger; |
46 | thediclist = new Dico_DictionaryOfTransient; |
47 | } |
48 | |
49 | void IFSelect_SignatureList::Add |
50 | (const Handle(Standard_Transient)& ent, const Standard_CString sign) |
51 | { |
52 | if (thesignonly) { |
53 | thelastval.Clear(); |
54 | thelastval.AssignCat (sign); |
55 | return; |
56 | } |
57 | |
58 | if (sign[0] == '\0') { thenbnuls ++; return; } |
59 | |
60 | Standard_Boolean deja; |
61 | Standard_Integer& nb = thedicount->NewItem(sign,deja); |
62 | if (!deja) nb = 0; |
63 | nb ++; |
64 | |
65 | if (thelistat) { |
66 | Handle(Standard_Transient)& anitem = thediclist->NewItem(sign,deja); |
67 | DeclareAndCast(TColStd_HSequenceOfTransient,alist,anitem); |
68 | if (!deja) { alist = new TColStd_HSequenceOfTransient(); anitem = alist; } |
69 | alist->Append(ent); |
70 | } |
71 | } |
72 | |
73 | Standard_CString IFSelect_SignatureList::LastValue () const |
74 | { return thelastval.ToCString(); } |
75 | |
76 | void IFSelect_SignatureList::Init |
77 | (const Standard_CString name, |
75259fc5 |
78 | const Handle(Dico_DictionaryOfInteger)& theCount, |
7fd59977 |
79 | const Handle(Dico_DictionaryOfTransient)& list, |
80 | const Standard_Integer nbnuls) |
81 | { |
82 | thelastval.Clear(); |
83 | thename = new TCollection_HAsciiString (name); |
75259fc5 |
84 | thedicount = theCount; |
7fd59977 |
85 | thediclist = list; |
86 | thenbnuls = nbnuls; |
87 | if (thediclist.IsNull()) thelistat = Standard_False; |
88 | } |
89 | |
90 | |
91 | Handle(TColStd_HSequenceOfHAsciiString) IFSelect_SignatureList::List |
92 | (const Standard_CString root) const |
93 | { |
94 | Handle(TColStd_HSequenceOfHAsciiString) list = |
95 | new TColStd_HSequenceOfHAsciiString(); |
96 | Dico_IteratorOfDictionaryOfInteger iter(thedicount,root); |
97 | for (; iter.More(); iter.Next()) { |
98 | Handle(TCollection_HAsciiString) sign = |
99 | new TCollection_HAsciiString (iter.Name()); |
100 | list->Append(sign); |
101 | } |
102 | return list; |
103 | } |
104 | |
105 | |
106 | Standard_Boolean IFSelect_SignatureList::HasEntities () const |
107 | { return thelistat; } |
108 | |
109 | Standard_Integer IFSelect_SignatureList::NbNulls () const |
110 | { return thenbnuls; } |
111 | |
112 | Standard_Integer IFSelect_SignatureList::NbTimes |
113 | (const Standard_CString sign) const |
114 | { |
115 | Standard_Integer nb; |
116 | if (thedicount->GetItem(sign,nb)) return nb; |
117 | else return 0; |
118 | } |
119 | |
120 | Handle(TColStd_HSequenceOfTransient) IFSelect_SignatureList::Entities |
121 | (const Standard_CString sign) const |
122 | { |
123 | Handle(TColStd_HSequenceOfTransient) list; |
124 | if (!thelistat) return list; |
125 | if (thediclist->GetItem(sign,list)) return list; |
126 | list = new TColStd_HSequenceOfTransient(); |
127 | return list; |
128 | } |
129 | |
130 | |
131 | void IFSelect_SignatureList::SetName (const Standard_CString name) |
132 | { thename = new TCollection_HAsciiString (name); } |
133 | |
134 | Standard_CString IFSelect_SignatureList::Name () const |
135 | { return thename->ToCString(); } |
136 | |
137 | |
138 | void IFSelect_SignatureList::PrintCount (const Handle(Message_Messenger)& S) const |
139 | { |
140 | Standard_Integer nbtot = 0, nbsign = 0; |
141 | Dico_IteratorOfDictionaryOfInteger iter(thedicount,""); |
142 | S << " Count "<<thename->ToCString()<<"\n ----- -----------"<<endl; |
143 | for (; iter.More(); iter.Next()) { |
144 | Standard_Integer val = iter.Value(); |
145 | S << Interface_MSG::Blanks(val,6) << val <<" "<<iter.Name()<<endl; |
146 | nbtot += val; |
147 | nbsign ++; |
148 | } |
149 | if (thenbnuls > 0) S << thename->ToCString()<< " Nul : " << thenbnuls<<endl; |
150 | S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl; |
151 | } |
152 | |
153 | void IFSelect_SignatureList::PrintList |
154 | (const Handle(Message_Messenger)& S, const Handle(Interface_InterfaceModel)& model, |
155 | const IFSelect_PrintCount mod) const |
156 | { |
157 | if (mod == IFSelect_ItemsByEntity) return; |
158 | if (mod == IFSelect_CountByItem) { PrintCount (S); return; } |
159 | if (mod == IFSelect_CountSummary) { PrintSum (S); return; } |
160 | if (!HasEntities()) { |
161 | S <<" SignatureList "<<Name()<<" : PrintList, list not available"<<endl; |
162 | PrintCount(S); |
163 | return; |
164 | } |
165 | Standard_Integer nbtot = 0, nbsign = 0; |
166 | Dico_IteratorOfDictionaryOfTransient iter(thediclist,""); |
167 | for (; iter.More(); iter.Next()) { |
168 | DeclareAndCast(TColStd_HSequenceOfTransient,list,iter.Value()); |
169 | S<<Name()<<" : "<<iter.Name()<<endl; |
170 | if (list.IsNull()) { S<<" - (empty list)"<<endl; continue; } |
171 | Standard_Integer nb = list->Length(); |
172 | S<<" - Nb: "<<nb<<" : "; |
173 | Standard_Integer nc = nb; if (nb > 5 && mod == IFSelect_ShortByItem) nc = 5; |
174 | for (Standard_Integer i = 1; i <= nc; i ++) { |
175 | if (list->Value(i).IsNull()) { |
176 | S<<" 0"; if (mod == IFSelect_EntitiesByItem) S<<":(Global)"; |
177 | continue; |
178 | } |
179 | Standard_Integer num = model->Number(list->Value(i)); |
180 | if (num == IFSelect_ShortByItem) { S<<" ??"; continue; } |
181 | S<<" "<<num; |
182 | if (mod == IFSelect_EntitiesByItem) |
183 | { S<<":"; model->PrintLabel(list->Value(i),S); } |
184 | } |
185 | if (nc < nb) S<<" .. etc"; |
186 | S<<endl; |
187 | nbtot += nb; |
188 | nbsign ++; |
189 | } |
190 | S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl; |
191 | } |
192 | |
193 | |
194 | void IFSelect_SignatureList::PrintSum (const Handle(Message_Messenger)& S) const |
195 | { |
196 | Dico_IteratorOfDictionaryOfInteger iter(thedicount,""); |
197 | S << " Summary "<<thename->ToCString()<<"\n ----- -----------"<<endl; |
198 | Standard_Integer nbtot = 0, nbsign = 0, maxent = 0, nbval = 0, nbve = 0, minval = 0, maxval = 0, totval = 0; |
199 | for (; iter.More(); iter.Next()) { |
200 | Standard_Integer nbent = iter.Value(); |
201 | nbtot += nbent; |
202 | nbsign ++; |
203 | if (nbent > maxent) maxent = nbent; |
204 | TCollection_AsciiString name = iter.Name(); |
205 | // if (!name.IsIntegerValue()) continue; pas bien fiable |
206 | Standard_Integer ic, nc = name.Length(); |
207 | Standard_Boolean iaint = Standard_True; |
208 | for (ic = 1; ic <= nc; ic ++) { |
209 | char unc = name.Value(ic); |
210 | if (ic == 1 && (unc == ' ' || unc == '+' || unc == '-')) continue; |
211 | if (unc >= '0' && unc <= '9') continue; |
212 | iaint = Standard_False; break; |
213 | } |
214 | if (!iaint) continue; |
215 | Standard_Integer val = name.IntegerValue(); |
216 | if (nbval == 0) { minval = maxval = val; } |
217 | if (minval > val) minval = val; |
218 | if (maxval < val) maxval = val; |
219 | nbval ++; |
220 | nbve += nbent; |
221 | totval += (val*nbent); |
222 | } |
223 | S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl; |
224 | S << " Highest count of entities : "<<maxent<<" on one item"<<endl; |
225 | if (nbval > 0) { |
226 | S<<" Summary on Integer Values"<<endl; |
227 | S<<" Nb Integer Items : "<<nbval<<endl; |
228 | S<<" For Nb Entities : "<<nbve<<endl; |
229 | S<<" Cumulated Values : "<<totval<<endl; |
230 | S<<" Maximum Value : "<<maxval<<endl; |
231 | Standard_Integer avg1, avg2; |
232 | avg1 = totval/nbve; |
233 | avg2 = ((totval - (avg1*nbve)) * 10) / nbve; |
234 | S<<" Average Value : "<<avg1<<" "<<avg2<<"/10"<<endl; |
235 | S<<" Minimum Value : "<<minval<<endl; |
236 | } |
237 | } |