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 <IFSelect_SignatureList.hxx>
16 #include <Interface_InterfaceModel.hxx>
17 #include <Interface_Macros.hxx>
18 #include <Interface_MSG.hxx>
19 #include <Message.hxx>
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>
26 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SignatureList,Standard_Transient)
28 IFSelect_SignatureList::IFSelect_SignatureList
29 (const Standard_Boolean withlist)
31 thesignonly = Standard_False;
37 void IFSelect_SignatureList::SetList
38 (const Standard_Boolean withlist)
39 { thelistat = withlist; }
41 Standard_Boolean& IFSelect_SignatureList::ModeSignOnly ()
42 { return thesignonly; }
44 void IFSelect_SignatureList::Clear ()
52 void IFSelect_SignatureList::Add
53 (const Handle(Standard_Transient)& ent, const Standard_CString sign)
57 thelastval.AssignCat (sign);
61 if (sign[0] == '\0') { thenbnuls ++; return; }
63 if (thedicount.Contains(sign))
64 thedicount.ChangeFromKey(sign)++;
66 thedicount.Add(sign, 1);
69 Handle(TColStd_HSequenceOfTransient) alist;
70 if (thediclist.Contains(sign))
71 alist = Handle(TColStd_HSequenceOfTransient)::DownCast(thediclist.FindFromKey(sign));
73 alist = new TColStd_HSequenceOfTransient();
74 thediclist.Add(sign, alist);
80 Standard_CString IFSelect_SignatureList::LastValue () const
81 { return thelastval.ToCString(); }
83 void IFSelect_SignatureList::Init
84 (const Standard_CString name,
85 const NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer>& theCount,
86 const NCollection_IndexedDataMap<TCollection_AsciiString, Handle(Standard_Transient)>& list,
87 const Standard_Integer nbnuls)
90 thename = new TCollection_HAsciiString (name);
91 thedicount = theCount;
94 if (thediclist.IsEmpty()) thelistat = Standard_False;
98 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_SignatureList::List
99 (const Standard_CString root) const
101 Handle(TColStd_HSequenceOfHAsciiString) list =
102 new TColStd_HSequenceOfHAsciiString();
103 NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer>::Iterator iter(thedicount);
104 for (; iter.More(); iter.Next()) {
105 if (!iter.Key().StartsWith(root)) continue;
107 Handle(TCollection_HAsciiString) sign =
108 new TCollection_HAsciiString (iter.Key());
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
124 Standard_Integer nb = 0;
125 thedicount.FindFromKey(sign, nb);
129 Handle(TColStd_HSequenceOfTransient) IFSelect_SignatureList::Entities
130 (const Standard_CString sign) const
132 Handle(TColStd_HSequenceOfTransient) list;
133 Handle(Standard_Transient) aTList;
134 if (!thelistat) return list;
135 if (thediclist.FindFromKey(sign, aTList))
136 list = Handle(TColStd_HSequenceOfTransient)::DownCast(aTList);
138 list = new TColStd_HSequenceOfTransient();
143 void IFSelect_SignatureList::SetName (const Standard_CString name)
144 { thename = new TCollection_HAsciiString (name); }
146 Standard_CString IFSelect_SignatureList::Name () const
147 { return thename->ToCString(); }
150 void IFSelect_SignatureList::PrintCount (const Handle(Message_Messenger)& S) const
152 Standard_Integer nbtot = 0, nbsign = 0;
153 NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer>::Iterator iter(thedicount);
154 S << " Count "<<thename->ToCString()<<"\n ----- -----------"<<endl;
155 for (; iter.More(); iter.Next()) {
156 Standard_Integer val = iter.Value();
157 S << Interface_MSG::Blanks(val,6) << val <<" "<<iter.Key()<<endl;
161 if (thenbnuls > 0) S << thename->ToCString()<< " Nul : " << thenbnuls<<endl;
162 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
165 void IFSelect_SignatureList::PrintList
166 (const Handle(Message_Messenger)& S, const Handle(Interface_InterfaceModel)& model,
167 const IFSelect_PrintCount mod) const
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;
177 Standard_Integer nbtot = 0, nbsign = 0;
178 NCollection_IndexedDataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator iter(thediclist);
179 for (; iter.More(); iter.Next()) {
180 DeclareAndCast(TColStd_HSequenceOfTransient,list,iter.Value());
181 S<<Name()<<" : "<<iter.Key()<<endl;
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)";
191 Standard_Integer num = model->Number(list->Value(i));
192 if (num == IFSelect_ShortByItem) { S<<" ??"; continue; }
194 if (mod == IFSelect_EntitiesByItem)
195 { S<<":"; model->PrintLabel(list->Value(i),S); }
197 if (nc < nb) S<<" .. etc";
202 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
206 void IFSelect_SignatureList::PrintSum (const Handle(Message_Messenger)& S) const
208 NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer>::Iterator iter(thedicount);
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();
215 if (nbent > maxent) maxent = nbent;
216 TCollection_AsciiString name = iter.Key();
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;
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;
233 totval += (val*nbent);
235 S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
236 S << " Highest count of entities : "<<maxent<<" on one item"<<endl;
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;
245 avg2 = ((totval - (avg1*nbve)) * 10) / nbve;
246 S<<" Average Value : "<<avg1<<" "<<avg2<<"/10"<<endl;
247 S<<" Minimum Value : "<<minval<<endl;