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 <Standard_Transient.hxx>
20 #include <Standard_Type.hxx>
21 #include <TCollection_HAsciiString.hxx>
22 #include <TColStd_HSequenceOfTransient.hxx>
24 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SignatureList,Standard_Transient)
26 IFSelect_SignatureList::IFSelect_SignatureList
27 (const Standard_Boolean withlist)
29 thesignonly = Standard_False;
35 void IFSelect_SignatureList::SetList
36 (const Standard_Boolean withlist)
37 { thelistat = withlist; }
39 Standard_Boolean& IFSelect_SignatureList::ModeSignOnly ()
40 { return thesignonly; }
42 void IFSelect_SignatureList::Clear ()
50 void IFSelect_SignatureList::Add
51 (const Handle(Standard_Transient)& ent, const Standard_CString sign)
55 thelastval.AssignCat (sign);
59 if (sign[0] == '\0') { thenbnuls ++; return; }
61 if (thedicount.Contains(sign))
62 thedicount.ChangeFromKey(sign)++;
64 thedicount.Add(sign, 1);
67 Handle(TColStd_HSequenceOfTransient) alist;
68 if (thediclist.Contains(sign))
69 alist = Handle(TColStd_HSequenceOfTransient)::DownCast(thediclist.FindFromKey(sign));
71 alist = new TColStd_HSequenceOfTransient();
72 thediclist.Add(sign, alist);
78 Standard_CString IFSelect_SignatureList::LastValue () const
79 { return thelastval.ToCString(); }
81 void IFSelect_SignatureList::Init
82 (const Standard_CString name,
83 const NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer>& theCount,
84 const NCollection_IndexedDataMap<TCollection_AsciiString, Handle(Standard_Transient)>& list,
85 const Standard_Integer nbnuls)
88 thename = new TCollection_HAsciiString (name);
89 thedicount = theCount;
92 if (thediclist.IsEmpty()) thelistat = Standard_False;
96 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_SignatureList::List
97 (const Standard_CString root) const
99 Handle(TColStd_HSequenceOfHAsciiString) list =
100 new TColStd_HSequenceOfHAsciiString();
101 NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer>::Iterator iter(thedicount);
102 for (; iter.More(); iter.Next()) {
103 if (!iter.Key().StartsWith(root)) continue;
105 Handle(TCollection_HAsciiString) sign =
106 new TCollection_HAsciiString (iter.Key());
113 Standard_Boolean IFSelect_SignatureList::HasEntities () const
114 { return thelistat; }
116 Standard_Integer IFSelect_SignatureList::NbNulls () const
117 { return thenbnuls; }
119 Standard_Integer IFSelect_SignatureList::NbTimes
120 (const Standard_CString sign) const
122 Standard_Integer nb = 0;
123 thedicount.FindFromKey(sign, nb);
127 Handle(TColStd_HSequenceOfTransient) IFSelect_SignatureList::Entities
128 (const Standard_CString sign) const
130 Handle(TColStd_HSequenceOfTransient) list;
131 Handle(Standard_Transient) aTList;
132 if (!thelistat) return list;
133 if (thediclist.FindFromKey(sign, aTList))
134 list = Handle(TColStd_HSequenceOfTransient)::DownCast(aTList);
136 list = new TColStd_HSequenceOfTransient();
141 void IFSelect_SignatureList::SetName (const Standard_CString name)
142 { thename = new TCollection_HAsciiString (name); }
144 Standard_CString IFSelect_SignatureList::Name () const
145 { return thename->ToCString(); }
148 void IFSelect_SignatureList::PrintCount (Standard_OStream& S) const
150 Standard_Integer nbtot = 0, nbsign = 0;
151 NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer>::Iterator iter(thedicount);
152 S << " Count "<<thename->ToCString()<<"\n ----- -----------"<<std::endl;
153 for (; iter.More(); iter.Next()) {
154 Standard_Integer val = iter.Value();
155 S << Interface_MSG::Blanks(val,6) << val <<" "<<iter.Key()<<std::endl;
159 if (thenbnuls > 0) S << thename->ToCString()<< " Nul : " << thenbnuls <<std::endl;
160 S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<std::endl;
163 void IFSelect_SignatureList::PrintList
164 (Standard_OStream& S, const Handle(Interface_InterfaceModel)& model,
165 const IFSelect_PrintCount mod) const
167 if (mod == IFSelect_ItemsByEntity) return;
168 if (mod == IFSelect_CountByItem) { PrintCount (S); return; }
169 if (mod == IFSelect_CountSummary) { PrintSum (S); return; }
170 if (!HasEntities()) {
171 S <<" SignatureList "<<Name()<<" : PrintList, list not available"<<std::endl;
175 Standard_Integer nbtot = 0, nbsign = 0;
176 NCollection_IndexedDataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator iter(thediclist);
177 for (; iter.More(); iter.Next()) {
178 DeclareAndCast(TColStd_HSequenceOfTransient,list,iter.Value());
179 S<<Name()<<" : "<<iter.Key()<<std::endl;
180 if (list.IsNull()) { S<<" - (empty list)"<<std::endl; continue; }
181 Standard_Integer nb = list->Length();
182 S<<" - Nb: "<<nb<<" : ";
183 Standard_Integer nc = nb; if (nb > 5 && mod == IFSelect_ShortByItem) nc = 5;
184 for (Standard_Integer i = 1; i <= nc; i ++) {
185 if (list->Value(i).IsNull()) {
187 if (mod == IFSelect_EntitiesByItem) S<<":(Global)";
190 Standard_Integer num = model->Number(list->Value(i));
191 if (num == IFSelect_ShortByItem) { S<<" ??"; continue; }
193 if (mod == IFSelect_EntitiesByItem)
194 { S<<":"; model->PrintLabel(list->Value(i), S); }
196 if (nc < nb) S<<" .. etc";
201 S <<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<std::endl;
205 void IFSelect_SignatureList::PrintSum (Standard_OStream& S) const
207 NCollection_IndexedDataMap<TCollection_AsciiString, Standard_Integer>::Iterator iter(thedicount);
208 S << " Summary "<<thename->ToCString()<<"\n ----- -----------"<<std::endl;
209 Standard_Integer nbtot = 0, nbsign = 0, maxent = 0, nbval = 0, nbve = 0, minval = 0, maxval = 0, totval = 0;
210 for (; iter.More(); iter.Next()) {
211 Standard_Integer nbent = iter.Value();
214 if (nbent > maxent) maxent = nbent;
215 TCollection_AsciiString name = iter.Key();
216 // if (!name.IsIntegerValue()) continue; pas bien fiable
217 Standard_Integer ic, nc = name.Length();
218 Standard_Boolean iaint = Standard_True;
219 for (ic = 1; ic <= nc; ic ++) {
220 char unc = name.Value(ic);
221 if (ic == 1 && (unc == ' ' || unc == '+' || unc == '-')) continue;
222 if (unc >= '0' && unc <= '9') continue;
223 iaint = Standard_False; break;
225 if (!iaint) continue;
226 Standard_Integer val = name.IntegerValue();
227 if (nbval == 0) { minval = maxval = val; }
228 if (minval > val) minval = val;
229 if (maxval < val) maxval = val;
232 totval += (val*nbent);
234 S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<std::endl;
235 S << " Highest count of entities : "<<maxent<<" on one item"<<std::endl;
237 S<<" Summary on Integer Values"<<std::endl;
238 S<<" Nb Integer Items : "<<nbval<<std::endl;
239 S<<" For Nb Entities : "<<nbve<<std::endl;
240 S<<" Cumulated Values : "<<totval<<std::endl;
241 S <<" Maximum Value : "<<maxval<<std::endl;
242 Standard_Integer avg1, avg2;
244 avg2 = ((totval - (avg1*nbve)) * 10) / nbve;
245 S <<" Average Value : "<<avg1<<" "<<avg2<<"/10"<<std::endl;
246 S <<" Minimum Value : "<<minval<<std::endl;