0024157: Parallelization of assembly part of BO
[occt.git] / src / IFSelect / IFSelect_SignatureList.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
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.
7//
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.
10//
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.
17
7fd59977 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>
26
b311480e 27IFSelect_SignatureList::IFSelect_SignatureList
7fd59977 28 (const Standard_Boolean withlist)
29{
30 thesignonly = Standard_False;
31 thelistat = withlist;
32 thenbnuls = 0;
33 thedicount = new Dico_DictionaryOfInteger;
34 thediclist = new Dico_DictionaryOfTransient;
35 SetName("...");
36}
37
38 void IFSelect_SignatureList::SetList
39 (const Standard_Boolean withlist)
40 { thelistat = withlist; }
41
42 Standard_Boolean& IFSelect_SignatureList::ModeSignOnly ()
43 { return thesignonly; }
44
45 void IFSelect_SignatureList::Clear ()
46{
47 thelastval.Clear();
48 thenbnuls = 0;
49 thedicount = new Dico_DictionaryOfInteger;
50 thediclist = new Dico_DictionaryOfTransient;
51}
52
53 void IFSelect_SignatureList::Add
54 (const Handle(Standard_Transient)& ent, const Standard_CString sign)
55{
56 if (thesignonly) {
57 thelastval.Clear();
58 thelastval.AssignCat (sign);
59 return;
60 }
61
62 if (sign[0] == '\0') { thenbnuls ++; return; }
63
64 Standard_Boolean deja;
65 Standard_Integer& nb = thedicount->NewItem(sign,deja);
66 if (!deja) nb = 0;
67 nb ++;
68
69 if (thelistat) {
70 Handle(Standard_Transient)& anitem = thediclist->NewItem(sign,deja);
71 DeclareAndCast(TColStd_HSequenceOfTransient,alist,anitem);
72 if (!deja) { alist = new TColStd_HSequenceOfTransient(); anitem = alist; }
73 alist->Append(ent);
74 }
75}
76
77 Standard_CString IFSelect_SignatureList::LastValue () const
78 { return thelastval.ToCString(); }
79
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)
85{
86 thelastval.Clear();
87 thename = new TCollection_HAsciiString (name);
88 thedicount = count;
89 thediclist = list;
90 thenbnuls = nbnuls;
91 if (thediclist.IsNull()) thelistat = Standard_False;
92}
93
94
95 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_SignatureList::List
96 (const Standard_CString root) const
97{
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());
104 list->Append(sign);
105 }
106 return list;
107}
108
109
110 Standard_Boolean IFSelect_SignatureList::HasEntities () const
111 { return thelistat; }
112
113 Standard_Integer IFSelect_SignatureList::NbNulls () const
114 { return thenbnuls; }
115
116 Standard_Integer IFSelect_SignatureList::NbTimes
117 (const Standard_CString sign) const
118{
119 Standard_Integer nb;
120 if (thedicount->GetItem(sign,nb)) return nb;
121 else return 0;
122}
123
124 Handle(TColStd_HSequenceOfTransient) IFSelect_SignatureList::Entities
125 (const Standard_CString sign) const
126{
127 Handle(TColStd_HSequenceOfTransient) list;
128 if (!thelistat) return list;
129 if (thediclist->GetItem(sign,list)) return list;
130 list = new TColStd_HSequenceOfTransient();
131 return list;
132}
133
134
135 void IFSelect_SignatureList::SetName (const Standard_CString name)
136 { thename = new TCollection_HAsciiString (name); }
137
138 Standard_CString IFSelect_SignatureList::Name () const
139 { return thename->ToCString(); }
140
141
142 void IFSelect_SignatureList::PrintCount (const Handle(Message_Messenger)& S) const
143{
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;
150 nbtot += val;
151 nbsign ++;
152 }
153 if (thenbnuls > 0) S << thename->ToCString()<< " Nul : " << thenbnuls<<endl;
154 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
155}
156
157 void IFSelect_SignatureList::PrintList
158 (const Handle(Message_Messenger)& S, const Handle(Interface_InterfaceModel)& model,
159 const IFSelect_PrintCount mod) const
160{
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;
166 PrintCount(S);
167 return;
168 }
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)";
181 continue;
182 }
183 Standard_Integer num = model->Number(list->Value(i));
184 if (num == IFSelect_ShortByItem) { S<<" ??"; continue; }
185 S<<" "<<num;
186 if (mod == IFSelect_EntitiesByItem)
187 { S<<":"; model->PrintLabel(list->Value(i),S); }
188 }
189 if (nc < nb) S<<" .. etc";
190 S<<endl;
191 nbtot += nb;
192 nbsign ++;
193 }
194 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
195}
196
197
198 void IFSelect_SignatureList::PrintSum (const Handle(Message_Messenger)& S) const
199{
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();
205 nbtot += nbent;
206 nbsign ++;
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;
217 }
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;
223 nbval ++;
224 nbve += nbent;
225 totval += (val*nbent);
226 }
227 S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
228 S << " Highest count of entities : "<<maxent<<" on one item"<<endl;
229 if (nbval > 0) {
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;
236 avg1 = totval/nbve;
237 avg2 = ((totval - (avg1*nbve)) * 10) / nbve;
238 S<<" Average Value : "<<avg1<<" "<<avg2<<"/10"<<endl;
239 S<<" Minimum Value : "<<minval<<endl;
240 }
241}