1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <IFSelect_SignatureList.ixx>
19 #include <Dico_IteratorOfDictionaryOfInteger.hxx>
20 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
21 #include <TColStd_HSequenceOfTransient.hxx>
22 #include <Interface_MSG.hxx>
23 #include <Interface_Macros.hxx>
24 #include <Message_Messenger.hxx>
25 #include <Message.hxx>
27 IFSelect_SignatureList::IFSelect_SignatureList
28 (const Standard_Boolean withlist)
30 thesignonly = Standard_False;
33 thedicount = new Dico_DictionaryOfInteger;
34 thediclist = new Dico_DictionaryOfTransient;
38 void IFSelect_SignatureList::SetList
39 (const Standard_Boolean withlist)
40 { thelistat = withlist; }
42 Standard_Boolean& IFSelect_SignatureList::ModeSignOnly ()
43 { return thesignonly; }
45 void IFSelect_SignatureList::Clear ()
49 thedicount = new Dico_DictionaryOfInteger;
50 thediclist = new Dico_DictionaryOfTransient;
53 void IFSelect_SignatureList::Add
54 (const Handle(Standard_Transient)& ent, const Standard_CString sign)
58 thelastval.AssignCat (sign);
62 if (sign[0] == '\0') { thenbnuls ++; return; }
64 Standard_Boolean deja;
65 Standard_Integer& nb = thedicount->NewItem(sign,deja);
70 Handle(Standard_Transient)& anitem = thediclist->NewItem(sign,deja);
71 DeclareAndCast(TColStd_HSequenceOfTransient,alist,anitem);
72 if (!deja) { alist = new TColStd_HSequenceOfTransient(); anitem = alist; }
77 Standard_CString IFSelect_SignatureList::LastValue () const
78 { return thelastval.ToCString(); }
80 void IFSelect_SignatureList::Init
81 (const Standard_CString name,
82 const Handle(Dico_DictionaryOfInteger)& count,
83 const Handle(Dico_DictionaryOfTransient)& list,
84 const Standard_Integer nbnuls)
87 thename = new TCollection_HAsciiString (name);
91 if (thediclist.IsNull()) thelistat = Standard_False;
95 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_SignatureList::List
96 (const Standard_CString root) const
98 Handle(TColStd_HSequenceOfHAsciiString) list =
99 new TColStd_HSequenceOfHAsciiString();
100 Dico_IteratorOfDictionaryOfInteger iter(thedicount,root);
101 for (; iter.More(); iter.Next()) {
102 Handle(TCollection_HAsciiString) sign =
103 new TCollection_HAsciiString (iter.Name());
110 Standard_Boolean IFSelect_SignatureList::HasEntities () const
111 { return thelistat; }
113 Standard_Integer IFSelect_SignatureList::NbNulls () const
114 { return thenbnuls; }
116 Standard_Integer IFSelect_SignatureList::NbTimes
117 (const Standard_CString sign) const
120 if (thedicount->GetItem(sign,nb)) return nb;
124 Handle(TColStd_HSequenceOfTransient) IFSelect_SignatureList::Entities
125 (const Standard_CString sign) const
127 Handle(TColStd_HSequenceOfTransient) list;
128 if (!thelistat) return list;
129 if (thediclist->GetItem(sign,list)) return list;
130 list = new TColStd_HSequenceOfTransient();
135 void IFSelect_SignatureList::SetName (const Standard_CString name)
136 { thename = new TCollection_HAsciiString (name); }
138 Standard_CString IFSelect_SignatureList::Name () const
139 { return thename->ToCString(); }
142 void IFSelect_SignatureList::PrintCount (const Handle(Message_Messenger)& S) const
144 Standard_Integer nbtot = 0, nbsign = 0;
145 Dico_IteratorOfDictionaryOfInteger iter(thedicount,"");
146 S << " Count "<<thename->ToCString()<<"\n ----- -----------"<<endl;
147 for (; iter.More(); iter.Next()) {
148 Standard_Integer val = iter.Value();
149 S << Interface_MSG::Blanks(val,6) << val <<" "<<iter.Name()<<endl;
153 if (thenbnuls > 0) S << thename->ToCString()<< " Nul : " << thenbnuls<<endl;
154 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
157 void IFSelect_SignatureList::PrintList
158 (const Handle(Message_Messenger)& S, const Handle(Interface_InterfaceModel)& model,
159 const IFSelect_PrintCount mod) const
161 if (mod == IFSelect_ItemsByEntity) return;
162 if (mod == IFSelect_CountByItem) { PrintCount (S); return; }
163 if (mod == IFSelect_CountSummary) { PrintSum (S); return; }
164 if (!HasEntities()) {
165 S <<" SignatureList "<<Name()<<" : PrintList, list not available"<<endl;
169 Standard_Integer nbtot = 0, nbsign = 0;
170 Dico_IteratorOfDictionaryOfTransient iter(thediclist,"");
171 for (; iter.More(); iter.Next()) {
172 DeclareAndCast(TColStd_HSequenceOfTransient,list,iter.Value());
173 S<<Name()<<" : "<<iter.Name()<<endl;
174 if (list.IsNull()) { S<<" - (empty list)"<<endl; continue; }
175 Standard_Integer nb = list->Length();
176 S<<" - Nb: "<<nb<<" : ";
177 Standard_Integer nc = nb; if (nb > 5 && mod == IFSelect_ShortByItem) nc = 5;
178 for (Standard_Integer i = 1; i <= nc; i ++) {
179 if (list->Value(i).IsNull()) {
180 S<<" 0"; if (mod == IFSelect_EntitiesByItem) S<<":(Global)";
183 Standard_Integer num = model->Number(list->Value(i));
184 if (num == IFSelect_ShortByItem) { S<<" ??"; continue; }
186 if (mod == IFSelect_EntitiesByItem)
187 { S<<":"; model->PrintLabel(list->Value(i),S); }
189 if (nc < nb) S<<" .. etc";
194 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
198 void IFSelect_SignatureList::PrintSum (const Handle(Message_Messenger)& S) const
200 Dico_IteratorOfDictionaryOfInteger iter(thedicount,"");
201 S << " Summary "<<thename->ToCString()<<"\n ----- -----------"<<endl;
202 Standard_Integer nbtot = 0, nbsign = 0, maxent = 0, nbval = 0, nbve = 0, minval = 0, maxval = 0, totval = 0;
203 for (; iter.More(); iter.Next()) {
204 Standard_Integer nbent = iter.Value();
207 if (nbent > maxent) maxent = nbent;
208 TCollection_AsciiString name = iter.Name();
209 // if (!name.IsIntegerValue()) continue; pas bien fiable
210 Standard_Integer ic, nc = name.Length();
211 Standard_Boolean iaint = Standard_True;
212 for (ic = 1; ic <= nc; ic ++) {
213 char unc = name.Value(ic);
214 if (ic == 1 && (unc == ' ' || unc == '+' || unc == '-')) continue;
215 if (unc >= '0' && unc <= '9') continue;
216 iaint = Standard_False; break;
218 if (!iaint) continue;
219 Standard_Integer val = name.IntegerValue();
220 if (nbval == 0) { minval = maxval = val; }
221 if (minval > val) minval = val;
222 if (maxval < val) maxval = val;
225 totval += (val*nbent);
227 S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
228 S << " Highest count of entities : "<<maxent<<" on one item"<<endl;
230 S<<" Summary on Integer Values"<<endl;
231 S<<" Nb Integer Items : "<<nbval<<endl;
232 S<<" For Nb Entities : "<<nbve<<endl;
233 S<<" Cumulated Values : "<<totval<<endl;
234 S<<" Maximum Value : "<<maxval<<endl;
235 Standard_Integer avg1, avg2;
237 avg2 = ((totval - (avg1*nbve)) * 10) / nbve;
238 S<<" Average Value : "<<avg1<<" "<<avg2<<"/10"<<endl;
239 S<<" Minimum Value : "<<minval<<endl;