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.
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>
23 IFSelect_SignatureList::IFSelect_SignatureList
24 (const Standard_Boolean withlist)
26 thesignonly = Standard_False;
29 thedicount = new Dico_DictionaryOfInteger;
30 thediclist = new Dico_DictionaryOfTransient;
34 void IFSelect_SignatureList::SetList
35 (const Standard_Boolean withlist)
36 { thelistat = withlist; }
38 Standard_Boolean& IFSelect_SignatureList::ModeSignOnly ()
39 { return thesignonly; }
41 void IFSelect_SignatureList::Clear ()
45 thedicount = new Dico_DictionaryOfInteger;
46 thediclist = new Dico_DictionaryOfTransient;
49 void IFSelect_SignatureList::Add
50 (const Handle(Standard_Transient)& ent, const Standard_CString sign)
54 thelastval.AssignCat (sign);
58 if (sign[0] == '\0') { thenbnuls ++; return; }
60 Standard_Boolean deja;
61 Standard_Integer& nb = thedicount->NewItem(sign,deja);
66 Handle(Standard_Transient)& anitem = thediclist->NewItem(sign,deja);
67 DeclareAndCast(TColStd_HSequenceOfTransient,alist,anitem);
68 if (!deja) { alist = new TColStd_HSequenceOfTransient(); anitem = alist; }
73 Standard_CString IFSelect_SignatureList::LastValue () const
74 { return thelastval.ToCString(); }
76 void IFSelect_SignatureList::Init
77 (const Standard_CString name,
78 const Handle(Dico_DictionaryOfInteger)& theCount,
79 const Handle(Dico_DictionaryOfTransient)& list,
80 const Standard_Integer nbnuls)
83 thename = new TCollection_HAsciiString (name);
84 thedicount = theCount;
87 if (thediclist.IsNull()) thelistat = Standard_False;
91 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_SignatureList::List
92 (const Standard_CString root) const
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());
106 Standard_Boolean IFSelect_SignatureList::HasEntities () const
107 { return thelistat; }
109 Standard_Integer IFSelect_SignatureList::NbNulls () const
110 { return thenbnuls; }
112 Standard_Integer IFSelect_SignatureList::NbTimes
113 (const Standard_CString sign) const
116 if (thedicount->GetItem(sign,nb)) return nb;
120 Handle(TColStd_HSequenceOfTransient) IFSelect_SignatureList::Entities
121 (const Standard_CString sign) const
123 Handle(TColStd_HSequenceOfTransient) list;
124 if (!thelistat) return list;
125 if (thediclist->GetItem(sign,list)) return list;
126 list = new TColStd_HSequenceOfTransient();
131 void IFSelect_SignatureList::SetName (const Standard_CString name)
132 { thename = new TCollection_HAsciiString (name); }
134 Standard_CString IFSelect_SignatureList::Name () const
135 { return thename->ToCString(); }
138 void IFSelect_SignatureList::PrintCount (const Handle(Message_Messenger)& S) const
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;
149 if (thenbnuls > 0) S << thename->ToCString()<< " Nul : " << thenbnuls<<endl;
150 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
153 void IFSelect_SignatureList::PrintList
154 (const Handle(Message_Messenger)& S, const Handle(Interface_InterfaceModel)& model,
155 const IFSelect_PrintCount mod) const
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;
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)";
179 Standard_Integer num = model->Number(list->Value(i));
180 if (num == IFSelect_ShortByItem) { S<<" ??"; continue; }
182 if (mod == IFSelect_EntitiesByItem)
183 { S<<":"; model->PrintLabel(list->Value(i),S); }
185 if (nc < nb) S<<" .. etc";
190 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
194 void IFSelect_SignatureList::PrintSum (const Handle(Message_Messenger)& S) const
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();
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;
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;
221 totval += (val*nbent);
223 S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
224 S << " Highest count of entities : "<<maxent<<" on one item"<<endl;
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;
233 avg2 = ((totval - (avg1*nbve)) * 10) / nbve;
234 S<<" Average Value : "<<avg1<<" "<<avg2<<"/10"<<endl;
235 S<<" Minimum Value : "<<minval<<endl;