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