973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
15 | #include <Interface_Check.hxx> |
16 | #include <Interface_CheckIterator.hxx> |
17 | #include <Interface_InterfaceModel.hxx> |
18 | #include <Interface_IntVal.hxx> |
7fd59977 |
19 | #include <Standard_NoSuchObject.hxx> |
42cf5bc1 |
20 | #include <Standard_Transient.hxx> |
7fd59977 |
21 | #include <TCollection_HAsciiString.hxx> |
22 | |
7fd59977 |
23 | static const Handle(Interface_Check)& nulcheck () |
24 | { |
25 | static Handle(Interface_Check) nulch = new Interface_Check; |
26 | return nulch; |
27 | } |
28 | |
29 | |
30 | //======================================================================= |
31 | //function : Interface_CheckIterator |
32 | //purpose : |
33 | //======================================================================= |
34 | |
35 | Interface_CheckIterator::Interface_CheckIterator () |
36 | { |
37 | Clear(); |
38 | } |
39 | |
40 | |
41 | //======================================================================= |
42 | //function : Interface_CheckIterator |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | Interface_CheckIterator::Interface_CheckIterator(const Standard_CString name) |
47 | : thename (name) |
48 | { |
49 | Clear(); |
50 | } |
51 | |
52 | |
53 | //======================================================================= |
54 | //function : SetName |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | void Interface_CheckIterator::SetName (const Standard_CString name) |
59 | { |
60 | thename.Clear(); |
61 | if (name[0] != '\0') thename.AssignCat(name); |
62 | } |
63 | |
64 | |
65 | //======================================================================= |
66 | //function : Name |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | Standard_CString Interface_CheckIterator::Name () const |
71 | { |
72 | return thename.ToCString(); |
73 | } |
74 | |
75 | |
76 | //======================================================================= |
77 | //function : SetModel |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | void Interface_CheckIterator::SetModel(const Handle(Interface_InterfaceModel)& model) |
82 | { |
83 | themod = model; |
84 | } |
85 | |
86 | |
87 | //======================================================================= |
88 | //function : Model |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | Handle(Interface_InterfaceModel) Interface_CheckIterator::Model() const |
93 | { |
94 | return themod; |
95 | } |
96 | |
97 | |
98 | //======================================================================= |
99 | //function : Clear |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | void Interface_CheckIterator::Clear () |
104 | { |
105 | thelist = new Interface_HSequenceOfCheck(); |
106 | thenums = new TColStd_HSequenceOfInteger(); |
107 | thecurr = new Interface_IntVal; |
108 | thecurr->CValue() = 1; |
109 | } |
110 | |
111 | |
112 | //======================================================================= |
113 | //function : Merge |
114 | //purpose : |
115 | //======================================================================= |
116 | |
117 | void Interface_CheckIterator::Merge (Interface_CheckIterator& other) |
118 | { |
119 | themod = other.Model(); |
120 | for (other.Start(); other.More(); other.Next()) |
121 | Add (other.Value(),other.Number()); |
122 | } |
123 | |
124 | |
125 | //======================================================================= |
126 | //function : Add |
127 | //purpose : |
128 | //======================================================================= |
129 | |
130 | void Interface_CheckIterator::Add(const Handle(Interface_Check)& ach, |
131 | const Standard_Integer num) |
132 | { |
133 | // Add <meme num que le dernier> -> cumul des Checks |
134 | if (ach->NbWarnings() + ach->NbFails() == 0) return; |
135 | Standard_Integer nm = num; |
136 | if (num <= 0 && ach->HasEntity()) { |
137 | if (!themod.IsNull()) { |
138 | nm = themod->Number (ach->Entity()); |
139 | if (nm <= 0) nm = -1; |
140 | } |
141 | else nm = -1; |
142 | } |
143 | if (nm >= 0 && nm <= - (thecurr->Value()) ) { |
144 | Standard_Integer i , numpos = 0 , nb = thelist->Length(); |
145 | for (i = nb; i > 0; i --) |
146 | if (thenums->Value(i) == nm) { numpos = i; break; } |
147 | if (numpos > 0 && nm >= 0) { |
148 | Handle(Interface_Check) lch = thelist->ChangeValue(numpos); |
149 | lch->GetMessages (ach); |
150 | } |
151 | // Cas normal : on ajoute en fin de liste |
152 | else { thelist->Append(ach); thenums->Append(nm); } |
153 | } |
154 | // Pas encore vu passe : inutile de chercher |
155 | else { thelist->Append(ach); thenums->Append(nm); thecurr->CValue() = -nm; } |
156 | } |
157 | |
158 | |
159 | //======================================================================= |
160 | //function : Check |
161 | //purpose : |
162 | //======================================================================= |
163 | |
164 | const Handle(Interface_Check)& Interface_CheckIterator::Check |
165 | (const Standard_Integer num) const |
166 | { |
167 | Standard_Integer i, nb = thelist->Length(); |
168 | for (i = 1; i <= nb; i ++) { |
169 | if (num == thenums->Value(i)) return thelist->Value(i); |
170 | } |
171 | return nulcheck(); |
172 | } |
173 | |
174 | |
175 | //======================================================================= |
176 | //function : Check |
177 | //purpose : |
178 | //======================================================================= |
179 | |
180 | const Handle(Interface_Check)& Interface_CheckIterator::Check |
181 | (const Handle(Standard_Transient)& ent) const |
182 | { |
183 | Standard_Integer num = -1; |
184 | if (!themod.IsNull()) num = themod->Number(ent); |
185 | if (num > 0) return Check(num); |
186 | |
187 | Standard_Integer i, nb = thelist->Length(); |
188 | for (i = 1; i <= nb; i ++) { |
189 | if (ent == thelist->Value(i)->Entity()) return thelist->Value(i); |
190 | } |
191 | return nulcheck(); |
192 | } |
193 | |
194 | |
195 | //======================================================================= |
196 | //function : CCheck |
197 | //purpose : |
198 | //======================================================================= |
199 | |
200 | Handle(Interface_Check)& Interface_CheckIterator::CCheck |
201 | (const Standard_Integer num) |
202 | { |
203 | Standard_Integer i, nb = thenums->Length(); |
204 | for (i = 1; i <= nb; i ++) { |
205 | if (num == thenums->Value(i)) return thelist->ChangeValue(i); |
206 | } |
207 | Handle(Interface_Check) ach = new Interface_Check; |
208 | thelist->Append(ach); thenums->Append(num); |
209 | return thelist->ChangeValue (thelist->Length()); |
210 | } |
211 | |
212 | |
213 | //======================================================================= |
214 | //function : CCheck |
215 | //purpose : |
216 | //======================================================================= |
217 | |
218 | Handle(Interface_Check)& Interface_CheckIterator::CCheck |
219 | (const Handle(Standard_Transient)& ent) |
220 | { |
221 | Standard_Integer num = -1; |
222 | if (!themod.IsNull()) num = themod->Number(ent); |
223 | if (num > 0) return CCheck(num); |
224 | |
225 | Standard_Integer i, nb = thelist->Length(); |
226 | for (i = 1; i <= nb; i ++) { |
227 | if (ent == thelist->Value(i)->Entity()) return thelist->ChangeValue(i); |
228 | } |
229 | |
230 | Handle(Interface_Check) ach = new Interface_Check; |
231 | thelist->Append(ach); thenums->Append(num); |
232 | return thelist->ChangeValue (thelist->Length()); |
233 | } |
234 | |
235 | |
236 | //======================================================================= |
237 | //function : IsEmpty |
238 | //purpose : |
239 | //======================================================================= |
240 | |
241 | Standard_Boolean Interface_CheckIterator::IsEmpty |
242 | (const Standard_Boolean failsonly) const |
243 | { |
244 | if (thelist->IsEmpty()) return Standard_True; |
245 | if (!failsonly) return Standard_False; |
246 | Standard_Integer i, nb = thelist->Length(); |
247 | for (i = 1; i <= nb; i ++) { |
248 | if (thelist->Value(i)->HasFailed()) return Standard_False; |
249 | } |
250 | return Standard_True; |
251 | } |
252 | |
253 | |
254 | //======================================================================= |
255 | //function : Status |
256 | //purpose : |
257 | //======================================================================= |
258 | |
259 | Interface_CheckStatus Interface_CheckIterator::Status () const |
260 | { |
261 | Interface_CheckStatus stat = Interface_CheckOK; |
262 | Standard_Integer i, nb = thelist->Length(); |
263 | for (i = 1; i <= nb; i ++) { |
264 | const Handle(Interface_Check) ach = thelist->Value(i); |
265 | if (ach->HasFailed()) return Interface_CheckFail; |
266 | if (ach->NbWarnings() > 0) stat = Interface_CheckWarning; |
267 | } |
268 | return stat; |
269 | } |
270 | |
271 | |
272 | //======================================================================= |
273 | //function : Complies |
c48e2889 |
274 | //purpose : |
7fd59977 |
275 | //======================================================================= |
276 | |
277 | Standard_Boolean Interface_CheckIterator::Complies |
278 | (const Interface_CheckStatus stat) const |
279 | { |
c48e2889 |
280 | Standard_Boolean res = (stat == Interface_CheckNoFail); |
281 | Standard_Integer nb = thelist->Length(); |
282 | for (Standard_Integer i = 1; i <= nb; ++i) |
283 | { |
7fd59977 |
284 | const Handle(Interface_Check) ach = thelist->Value(i); |
285 | Standard_Integer nbf = ach->NbFails(), nbw = ach->NbWarnings(); |
c48e2889 |
286 | switch (stat) |
287 | { |
288 | case Interface_CheckOK: |
289 | { |
290 | if (nbf + nbw > 0) |
291 | { |
292 | return Standard_False; |
293 | } |
294 | break; |
295 | } |
296 | case Interface_CheckWarning: |
297 | { |
298 | if (nbf > 0) |
299 | { |
300 | return Standard_False; |
301 | } |
302 | if (nbw > 0) |
303 | { |
304 | res = Standard_True; |
305 | } |
306 | break; |
307 | } |
308 | case Interface_CheckFail: |
309 | { |
310 | if (nbf > 0) |
311 | { |
312 | return Standard_True; |
313 | } |
314 | break; |
315 | } |
316 | case Interface_CheckAny: |
317 | { |
318 | return Standard_True; |
319 | } |
320 | case Interface_CheckMessage: |
321 | { |
322 | if (nbf + nbw > 0) |
323 | { |
324 | return Standard_True; |
325 | } |
326 | break; |
327 | } |
328 | case Interface_CheckNoFail: |
329 | { |
330 | if (nbf > 0) |
331 | { |
332 | return Standard_False; |
333 | } |
334 | break; |
335 | } |
336 | default: |
337 | break; |
7fd59977 |
338 | } |
339 | } |
340 | return res; |
341 | } |
342 | |
343 | |
344 | //======================================================================= |
345 | //function : Extract |
346 | //purpose : |
347 | //======================================================================= |
348 | |
349 | Interface_CheckIterator Interface_CheckIterator::Extract |
350 | (const Interface_CheckStatus stat) const |
351 | { |
352 | Interface_CheckIterator res; |
353 | res.SetModel (themod); res.SetName (thename.ToCString()); |
354 | Standard_Integer i, nb = thelist->Length(); |
355 | for (i = 1; i <= nb; i ++) { |
356 | const Handle(Interface_Check) ach = thelist->Value(i); |
357 | Standard_Integer nbf = ach->NbFails(), nbw = ach->NbWarnings(); |
358 | Standard_Boolean prend = Standard_False; |
359 | switch (stat) { |
360 | case Interface_CheckOK : prend = (nbf + nbw == 0); break; |
361 | case Interface_CheckWarning : prend = (nbf == 0 && nbw > 0); break; |
362 | case Interface_CheckFail : prend = (nbf > 0); break; |
363 | case Interface_CheckAny : prend = Standard_True; break; |
364 | case Interface_CheckMessage : prend = (nbf + nbw > 0); break; |
365 | case Interface_CheckNoFail : prend = (nbf == 0); break; |
366 | default : break; |
367 | } |
368 | if (prend) res.Add (ach,thenums->Value(i)); |
369 | } |
370 | return res; |
371 | } |
372 | |
373 | |
374 | //======================================================================= |
375 | //function : Extract |
376 | //purpose : |
377 | //======================================================================= |
378 | |
379 | Interface_CheckIterator Interface_CheckIterator::Extract |
380 | (const Standard_CString mess, |
381 | const Standard_Integer incl, const Interface_CheckStatus stat) const |
382 | { |
383 | Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mess); |
384 | Interface_CheckIterator res; |
385 | res.SetModel (themod); res.SetName (thename.ToCString()); |
386 | Standard_Integer i, nb = thelist->Length(); |
387 | for (i = 1; i <= nb; i ++) { |
388 | const Handle(Interface_Check) ach = thelist->Value(i); |
389 | if (ach->Complies(str,incl,stat)) res.Add (ach,thenums->Value(i)); |
390 | } |
391 | return res; |
392 | } |
393 | |
394 | |
395 | //======================================================================= |
396 | //function : Remove |
397 | //purpose : |
398 | //======================================================================= |
399 | |
400 | Standard_Boolean Interface_CheckIterator::Remove(const Standard_CString mess, |
401 | const Standard_Integer incl, |
402 | const Interface_CheckStatus stat) |
403 | { |
404 | Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mess); |
405 | Standard_Boolean res = Standard_False; |
406 | Standard_Integer i, nb = thelist->Length(); |
407 | for (i = 1; i <= nb; i ++) { |
408 | Handle(Interface_Check) ach = thelist->ChangeValue(i); |
409 | if (ach->Remove (str,incl,stat)) res = Standard_True; |
410 | } |
411 | return res; |
412 | } |
413 | |
414 | |
415 | //======================================================================= |
416 | //function : Checkeds |
417 | //purpose : |
418 | //======================================================================= |
419 | |
420 | Handle(TColStd_HSequenceOfTransient) Interface_CheckIterator::Checkeds |
421 | (const Standard_Boolean failsonly, const Standard_Boolean global) const |
422 | { |
423 | Handle(TColStd_HSequenceOfTransient) list; |
424 | if (themod.IsNull()) return list; |
425 | list = new TColStd_HSequenceOfTransient(); |
426 | Standard_Integer num, i, nb = thelist->Length(); |
427 | for (i = 1; i <= nb; i ++) { |
428 | const Handle(Interface_Check) chk = thelist->Value(i); |
429 | if (failsonly && !chk->HasFailed()) continue; |
430 | if (chk->NbWarnings() == 0) continue; |
431 | num = thenums->Value(i); |
432 | if (num == 0 && global) list->Append (themod); |
433 | else if (num > 0) list->Append (themod->Value(num)); |
434 | } |
435 | return list; |
436 | } |
437 | |
438 | |
439 | //======================================================================= |
440 | //function : Start |
441 | //purpose : |
442 | //======================================================================= |
443 | |
444 | void Interface_CheckIterator::Start () const |
445 | { |
446 | thecurr->CValue() = 1; |
447 | } |
448 | |
449 | |
450 | //======================================================================= |
451 | //function : More |
452 | //purpose : |
453 | //======================================================================= |
454 | |
455 | Standard_Boolean Interface_CheckIterator::More () const |
456 | { |
457 | if (thecurr->Value() < 0) thecurr->CValue() = 1; |
458 | return (thecurr->Value() <= thelist->Length()); |
459 | } |
460 | |
461 | |
462 | //======================================================================= |
463 | //function : Next |
464 | //purpose : |
465 | //======================================================================= |
466 | |
467 | void Interface_CheckIterator::Next () const |
468 | { |
469 | if (thecurr->Value() < 0) thecurr->CValue() = 1; |
470 | thecurr->CValue() ++; |
471 | } |
472 | |
473 | |
474 | //======================================================================= |
475 | //function : Value |
476 | //purpose : |
477 | //======================================================================= |
478 | |
479 | const Handle(Interface_Check)& Interface_CheckIterator::Value () const |
480 | { |
9775fa61 |
481 | if (thecurr->Value() > thelist->Length()) throw Standard_NoSuchObject("Interface Check Iterator : Value"); |
7fd59977 |
482 | return thelist->Value(thecurr->Value()); |
483 | } |
484 | |
485 | |
486 | //======================================================================= |
487 | //function : Number |
488 | //purpose : |
489 | //======================================================================= |
490 | |
491 | Standard_Integer Interface_CheckIterator::Number () const |
492 | { |
9775fa61 |
493 | if (thecurr->Value() > thenums->Length()) throw Standard_NoSuchObject("Interface Check Iterator : Value"); |
7fd59977 |
494 | return thenums->Value(thecurr->Value()); |
495 | } |
496 | |
497 | |
498 | //======================================================================= |
499 | //function : Print |
500 | //purpose : |
501 | //======================================================================= |
502 | |
0ebe5b0a |
503 | void Interface_CheckIterator::Print(Standard_OStream& S, |
7fd59977 |
504 | const Standard_Boolean failsonly, |
505 | const Standard_Integer final) const |
506 | { |
507 | Print (S,themod,failsonly,final); |
508 | } |
509 | |
510 | |
511 | //======================================================================= |
512 | //function : Print |
513 | //purpose : |
514 | //======================================================================= |
515 | |
0ebe5b0a |
516 | void Interface_CheckIterator::Print(Standard_OStream& S, |
7fd59977 |
517 | const Handle(Interface_InterfaceModel)& model, |
518 | const Standard_Boolean failsonly, |
519 | const Standard_Integer /*final*/) const |
520 | { |
521 | Standard_Boolean titre = Standard_False; |
522 | /*Standard_CString mesnum; |
523 | Standard_CString mesnum0 = ":"; |
524 | Standard_CString mesnum1 = " (original):"; |
525 | Standard_CString mesnum2 = " (computed):"; */ |
526 | Standard_Integer i, nbch = 0, nb = thelist->Length();//,j; svv #2 |
527 | Standard_Boolean yamod = !model.IsNull(); |
528 | for (i = 1; i <= nb; i ++) { |
529 | const Handle(Interface_Check) ach = thelist->Value(i); |
530 | Standard_Integer nbw = 0, nbf = ach->NbFails(); |
531 | if (!failsonly) nbw = ach->NbWarnings(); |
532 | if (nbf + nbw == 0) continue; |
533 | Handle(Standard_Transient) ent = ach->Entity(); |
534 | Standard_Integer nm0 = thenums->Value(i); |
535 | Standard_Boolean entnul = ent.IsNull(); |
536 | Standard_Integer num = nm0; |
537 | if (nm0 <= 0 && !entnul && yamod) num = model->Number(ent); |
538 | if (nm0 <= 0 && entnul) num = -1; // Global |
539 | // mesnum = mesnum0; |
540 | // if (yamod) mesnum = (nm0 > 0 ? mesnum1 : mesnum2); |
541 | |
0ebe5b0a |
542 | if (!titre) S <<" ** " << Name() << " **"<<std::endl; |
7fd59977 |
543 | titre = Standard_True; |
0ebe5b0a |
544 | S <<"Check:"; if(nb > 9 && i < 10) S <<" "; if (nb > 99 && i < 100) S <<" "; |
545 | S <<i; |
546 | if (num < 0) S <<" -- Global Check"<<std::endl; |
547 | else if (num == 0) S <<" -- Entity n0 ??:"; |
7fd59977 |
548 | else { |
0ebe5b0a |
549 | if (yamod) { S <<" -- Entity (n0:id) "; model->Print (ent, S); } |
550 | else S <<" -- Entity n0 "<<num; |
7fd59977 |
551 | // S<<" -- Entity n0 "<<num<<mesnum; |
552 | // if (yamod) model->PrintLabel(ent,S); |
553 | } |
0ebe5b0a |
554 | if (num >= 0 && entnul) S <<" (unknown Type)"<<std::endl; |
7fd59977 |
555 | else if (num >= 0 && !entnul) { |
0ebe5b0a |
556 | if (yamod) S <<" Type:"<<model->TypeName(ent)<<std::endl; |
557 | else S <<" Type:"<<ent->DynamicType()->Name()<<std::endl; |
7fd59977 |
558 | } |
559 | |
560 | nbch ++; |
561 | ach->Print (S, (failsonly ? 1 : 3)); |
562 | } |
04232180 |
563 | // if (nbch > 0) S<<" ---- Checks : "<<nbch<<" ----"<<std::endl; |
7fd59977 |
564 | } |
565 | |
566 | |
567 | //======================================================================= |
568 | //function : Destroy |
569 | //purpose : |
570 | //======================================================================= |
571 | |
572 | void Interface_CheckIterator::Destroy () |
573 | { |
574 | thecurr.Nullify(); |
575 | } // redevient standard |