1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Dico_DictionaryOfInteger.hxx>
16 #include <Dico_DictionaryOfTransient.hxx>
17 #include <Dico_IteratorOfDictionaryOfInteger.hxx>
18 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
19 #include <IFSelect_SignatureList.hxx>
20 #include <Interface_InterfaceModel.hxx>
21 #include <Interface_Macros.hxx>
22 #include <Interface_MSG.hxx>
23 #include <Message.hxx>
24 #include <Message_Messenger.hxx>
25 #include <Standard_Transient.hxx>
26 #include <Standard_Type.hxx>
27 #include <TCollection_HAsciiString.hxx>
28 #include <TColStd_HSequenceOfTransient.hxx>
30 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SignatureList,MMgt_TShared)
32 IFSelect_SignatureList::IFSelect_SignatureList
33 (const Standard_Boolean withlist)
35 thesignonly = Standard_False;
38 thedicount = new Dico_DictionaryOfInteger;
39 thediclist = new Dico_DictionaryOfTransient;
43 void IFSelect_SignatureList::SetList
44 (const Standard_Boolean withlist)
45 { thelistat = withlist; }
47 Standard_Boolean& IFSelect_SignatureList::ModeSignOnly ()
48 { return thesignonly; }
50 void IFSelect_SignatureList::Clear ()
54 thedicount = new Dico_DictionaryOfInteger;
55 thediclist = new Dico_DictionaryOfTransient;
58 void IFSelect_SignatureList::Add
59 (const Handle(Standard_Transient)& ent, const Standard_CString sign)
63 thelastval.AssignCat (sign);
67 if (sign[0] == '\0') { thenbnuls ++; return; }
69 Standard_Boolean deja;
70 Standard_Integer& nb = thedicount->NewItem(sign,deja);
75 Handle(Standard_Transient)& anitem = thediclist->NewItem(sign,deja);
76 DeclareAndCast(TColStd_HSequenceOfTransient,alist,anitem);
77 if (!deja) { alist = new TColStd_HSequenceOfTransient(); anitem = alist; }
82 Standard_CString IFSelect_SignatureList::LastValue () const
83 { return thelastval.ToCString(); }
85 void IFSelect_SignatureList::Init
86 (const Standard_CString name,
87 const Handle(Dico_DictionaryOfInteger)& theCount,
88 const Handle(Dico_DictionaryOfTransient)& list,
89 const Standard_Integer nbnuls)
92 thename = new TCollection_HAsciiString (name);
93 thedicount = theCount;
96 if (thediclist.IsNull()) thelistat = Standard_False;
100 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_SignatureList::List
101 (const Standard_CString root) const
103 Handle(TColStd_HSequenceOfHAsciiString) list =
104 new TColStd_HSequenceOfHAsciiString();
105 Dico_IteratorOfDictionaryOfInteger iter(thedicount,root);
106 for (; iter.More(); iter.Next()) {
107 Handle(TCollection_HAsciiString) sign =
108 new TCollection_HAsciiString (iter.Name());
115 Standard_Boolean IFSelect_SignatureList::HasEntities () const
116 { return thelistat; }
118 Standard_Integer IFSelect_SignatureList::NbNulls () const
119 { return thenbnuls; }
121 Standard_Integer IFSelect_SignatureList::NbTimes
122 (const Standard_CString sign) const
125 if (thedicount->GetItem(sign,nb)) return nb;
129 Handle(TColStd_HSequenceOfTransient) IFSelect_SignatureList::Entities
130 (const Standard_CString sign) const
132 Handle(TColStd_HSequenceOfTransient) list;
133 if (!thelistat) return list;
134 if (thediclist->GetItem(sign,list)) return list;
135 list = new TColStd_HSequenceOfTransient();
140 void IFSelect_SignatureList::SetName (const Standard_CString name)
141 { thename = new TCollection_HAsciiString (name); }
143 Standard_CString IFSelect_SignatureList::Name () const
144 { return thename->ToCString(); }
147 void IFSelect_SignatureList::PrintCount (const Handle(Message_Messenger)& S) const
149 Standard_Integer nbtot = 0, nbsign = 0;
150 Dico_IteratorOfDictionaryOfInteger iter(thedicount,"");
151 S << " Count "<<thename->ToCString()<<"\n ----- -----------"<<endl;
152 for (; iter.More(); iter.Next()) {
153 Standard_Integer val = iter.Value();
154 S << Interface_MSG::Blanks(val,6) << val <<" "<<iter.Name()<<endl;
158 if (thenbnuls > 0) S << thename->ToCString()<< " Nul : " << thenbnuls<<endl;
159 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
162 void IFSelect_SignatureList::PrintList
163 (const Handle(Message_Messenger)& S, const Handle(Interface_InterfaceModel)& model,
164 const IFSelect_PrintCount mod) const
166 if (mod == IFSelect_ItemsByEntity) return;
167 if (mod == IFSelect_CountByItem) { PrintCount (S); return; }
168 if (mod == IFSelect_CountSummary) { PrintSum (S); return; }
169 if (!HasEntities()) {
170 S <<" SignatureList "<<Name()<<" : PrintList, list not available"<<endl;
174 Standard_Integer nbtot = 0, nbsign = 0;
175 Dico_IteratorOfDictionaryOfTransient iter(thediclist,"");
176 for (; iter.More(); iter.Next()) {
177 DeclareAndCast(TColStd_HSequenceOfTransient,list,iter.Value());
178 S<<Name()<<" : "<<iter.Name()<<endl;
179 if (list.IsNull()) { S<<" - (empty list)"<<endl; continue; }
180 Standard_Integer nb = list->Length();
181 S<<" - Nb: "<<nb<<" : ";
182 Standard_Integer nc = nb; if (nb > 5 && mod == IFSelect_ShortByItem) nc = 5;
183 for (Standard_Integer i = 1; i <= nc; i ++) {
184 if (list->Value(i).IsNull()) {
185 S<<" 0"; if (mod == IFSelect_EntitiesByItem) S<<":(Global)";
188 Standard_Integer num = model->Number(list->Value(i));
189 if (num == IFSelect_ShortByItem) { S<<" ??"; continue; }
191 if (mod == IFSelect_EntitiesByItem)
192 { S<<":"; model->PrintLabel(list->Value(i),S); }
194 if (nc < nb) S<<" .. etc";
199 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
203 void IFSelect_SignatureList::PrintSum (const Handle(Message_Messenger)& S) const
205 Dico_IteratorOfDictionaryOfInteger iter(thedicount,"");
206 S << " Summary "<<thename->ToCString()<<"\n ----- -----------"<<endl;
207 Standard_Integer nbtot = 0, nbsign = 0, maxent = 0, nbval = 0, nbve = 0, minval = 0, maxval = 0, totval = 0;
208 for (; iter.More(); iter.Next()) {
209 Standard_Integer nbent = iter.Value();
212 if (nbent > maxent) maxent = nbent;
213 TCollection_AsciiString name = iter.Name();
214 // if (!name.IsIntegerValue()) continue; pas bien fiable
215 Standard_Integer ic, nc = name.Length();
216 Standard_Boolean iaint = Standard_True;
217 for (ic = 1; ic <= nc; ic ++) {
218 char unc = name.Value(ic);
219 if (ic == 1 && (unc == ' ' || unc == '+' || unc == '-')) continue;
220 if (unc >= '0' && unc <= '9') continue;
221 iaint = Standard_False; break;
223 if (!iaint) continue;
224 Standard_Integer val = name.IntegerValue();
225 if (nbval == 0) { minval = maxval = val; }
226 if (minval > val) minval = val;
227 if (maxval < val) maxval = val;
230 totval += (val*nbent);
232 S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
233 S << " Highest count of entities : "<<maxent<<" on one item"<<endl;
235 S<<" Summary on Integer Values"<<endl;
236 S<<" Nb Integer Items : "<<nbval<<endl;
237 S<<" For Nb Entities : "<<nbve<<endl;
238 S<<" Cumulated Values : "<<totval<<endl;
239 S<<" Maximum Value : "<<maxval<<endl;
240 Standard_Integer avg1, avg2;
242 avg2 = ((totval - (avg1*nbve)) * 10) / nbve;
243 S<<" Average Value : "<<avg1<<" "<<avg2<<"/10"<<endl;
244 S<<" Minimum Value : "<<minval<<endl;