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 <Interface_Check.hxx>
16 #include <Interface_CheckIterator.hxx>
17 #include <Interface_InterfaceModel.hxx>
18 #include <Interface_IntVal.hxx>
19 #include <Message_Messenger.hxx>
20 #include <Standard_NoSuchObject.hxx>
21 #include <Standard_Transient.hxx>
22 #include <TCollection_HAsciiString.hxx>
24 static const Handle(Interface_Check)& nulcheck ()
26 static Handle(Interface_Check) nulch = new Interface_Check;
31 //=======================================================================
32 //function : Interface_CheckIterator
34 //=======================================================================
36 Interface_CheckIterator::Interface_CheckIterator ()
42 //=======================================================================
43 //function : Interface_CheckIterator
45 //=======================================================================
47 Interface_CheckIterator::Interface_CheckIterator(const Standard_CString name)
54 //=======================================================================
57 //=======================================================================
59 void Interface_CheckIterator::SetName (const Standard_CString name)
62 if (name[0] != '\0') thename.AssignCat(name);
66 //=======================================================================
69 //=======================================================================
71 Standard_CString Interface_CheckIterator::Name () const
73 return thename.ToCString();
77 //=======================================================================
80 //=======================================================================
82 void Interface_CheckIterator::SetModel(const Handle(Interface_InterfaceModel)& model)
88 //=======================================================================
91 //=======================================================================
93 Handle(Interface_InterfaceModel) Interface_CheckIterator::Model() const
99 //=======================================================================
102 //=======================================================================
104 void Interface_CheckIterator::Clear ()
106 thelist = new Interface_HSequenceOfCheck();
107 thenums = new TColStd_HSequenceOfInteger();
108 thecurr = new Interface_IntVal;
109 thecurr->CValue() = 1;
113 //=======================================================================
116 //=======================================================================
118 void Interface_CheckIterator::Merge (Interface_CheckIterator& other)
120 themod = other.Model();
121 for (other.Start(); other.More(); other.Next())
122 Add (other.Value(),other.Number());
126 //=======================================================================
129 //=======================================================================
131 void Interface_CheckIterator::Add(const Handle(Interface_Check)& ach,
132 const Standard_Integer num)
134 // Add <meme num que le dernier> -> cumul des Checks
135 if (ach->NbWarnings() + ach->NbFails() == 0) return;
136 Standard_Integer nm = num;
137 if (num <= 0 && ach->HasEntity()) {
138 if (!themod.IsNull()) {
139 nm = themod->Number (ach->Entity());
140 if (nm <= 0) nm = -1;
144 if (nm >= 0 && nm <= - (thecurr->Value()) ) {
145 Standard_Integer i , numpos = 0 , nb = thelist->Length();
146 for (i = nb; i > 0; i --)
147 if (thenums->Value(i) == nm) { numpos = i; break; }
148 if (numpos > 0 && nm >= 0) {
149 Handle(Interface_Check) lch = thelist->ChangeValue(numpos);
150 lch->GetMessages (ach);
152 // Cas normal : on ajoute en fin de liste
153 else { thelist->Append(ach); thenums->Append(nm); }
155 // Pas encore vu passe : inutile de chercher
156 else { thelist->Append(ach); thenums->Append(nm); thecurr->CValue() = -nm; }
160 //=======================================================================
163 //=======================================================================
165 const Handle(Interface_Check)& Interface_CheckIterator::Check
166 (const Standard_Integer num) const
168 Standard_Integer i, nb = thelist->Length();
169 for (i = 1; i <= nb; i ++) {
170 if (num == thenums->Value(i)) return thelist->Value(i);
176 //=======================================================================
179 //=======================================================================
181 const Handle(Interface_Check)& Interface_CheckIterator::Check
182 (const Handle(Standard_Transient)& ent) const
184 Standard_Integer num = -1;
185 if (!themod.IsNull()) num = themod->Number(ent);
186 if (num > 0) return Check(num);
188 Standard_Integer i, nb = thelist->Length();
189 for (i = 1; i <= nb; i ++) {
190 if (ent == thelist->Value(i)->Entity()) return thelist->Value(i);
196 //=======================================================================
199 //=======================================================================
201 Handle(Interface_Check)& Interface_CheckIterator::CCheck
202 (const Standard_Integer num)
204 Standard_Integer i, nb = thenums->Length();
205 for (i = 1; i <= nb; i ++) {
206 if (num == thenums->Value(i)) return thelist->ChangeValue(i);
208 Handle(Interface_Check) ach = new Interface_Check;
209 thelist->Append(ach); thenums->Append(num);
210 return thelist->ChangeValue (thelist->Length());
214 //=======================================================================
217 //=======================================================================
219 Handle(Interface_Check)& Interface_CheckIterator::CCheck
220 (const Handle(Standard_Transient)& ent)
222 Standard_Integer num = -1;
223 if (!themod.IsNull()) num = themod->Number(ent);
224 if (num > 0) return CCheck(num);
226 Standard_Integer i, nb = thelist->Length();
227 for (i = 1; i <= nb; i ++) {
228 if (ent == thelist->Value(i)->Entity()) return thelist->ChangeValue(i);
231 Handle(Interface_Check) ach = new Interface_Check;
232 thelist->Append(ach); thenums->Append(num);
233 return thelist->ChangeValue (thelist->Length());
237 //=======================================================================
240 //=======================================================================
242 Standard_Boolean Interface_CheckIterator::IsEmpty
243 (const Standard_Boolean failsonly) const
245 if (thelist->IsEmpty()) return Standard_True;
246 if (!failsonly) return Standard_False;
247 Standard_Integer i, nb = thelist->Length();
248 for (i = 1; i <= nb; i ++) {
249 if (thelist->Value(i)->HasFailed()) return Standard_False;
251 return Standard_True;
255 //=======================================================================
258 //=======================================================================
260 Interface_CheckStatus Interface_CheckIterator::Status () const
262 Interface_CheckStatus stat = Interface_CheckOK;
263 Standard_Integer i, nb = thelist->Length();
264 for (i = 1; i <= nb; i ++) {
265 const Handle(Interface_Check) ach = thelist->Value(i);
266 if (ach->HasFailed()) return Interface_CheckFail;
267 if (ach->NbWarnings() > 0) stat = Interface_CheckWarning;
273 //=======================================================================
274 //function : Complies
276 //=======================================================================
278 Standard_Boolean Interface_CheckIterator::Complies
279 (const Interface_CheckStatus stat) const
281 Standard_Boolean res = (stat == Interface_CheckNoFail);
282 Standard_Integer nb = thelist->Length();
283 for (Standard_Integer i = 1; i <= nb; ++i)
285 const Handle(Interface_Check) ach = thelist->Value(i);
286 Standard_Integer nbf = ach->NbFails(), nbw = ach->NbWarnings();
289 case Interface_CheckOK:
293 return Standard_False;
297 case Interface_CheckWarning:
301 return Standard_False;
309 case Interface_CheckFail:
313 return Standard_True;
317 case Interface_CheckAny:
319 return Standard_True;
321 case Interface_CheckMessage:
325 return Standard_True;
329 case Interface_CheckNoFail:
333 return Standard_False;
345 //=======================================================================
348 //=======================================================================
350 Interface_CheckIterator Interface_CheckIterator::Extract
351 (const Interface_CheckStatus stat) const
353 Interface_CheckIterator res;
354 res.SetModel (themod); res.SetName (thename.ToCString());
355 Standard_Integer i, nb = thelist->Length();
356 for (i = 1; i <= nb; i ++) {
357 const Handle(Interface_Check) ach = thelist->Value(i);
358 Standard_Integer nbf = ach->NbFails(), nbw = ach->NbWarnings();
359 Standard_Boolean prend = Standard_False;
361 case Interface_CheckOK : prend = (nbf + nbw == 0); break;
362 case Interface_CheckWarning : prend = (nbf == 0 && nbw > 0); break;
363 case Interface_CheckFail : prend = (nbf > 0); break;
364 case Interface_CheckAny : prend = Standard_True; break;
365 case Interface_CheckMessage : prend = (nbf + nbw > 0); break;
366 case Interface_CheckNoFail : prend = (nbf == 0); break;
369 if (prend) res.Add (ach,thenums->Value(i));
375 //=======================================================================
378 //=======================================================================
380 Interface_CheckIterator Interface_CheckIterator::Extract
381 (const Standard_CString mess,
382 const Standard_Integer incl, const Interface_CheckStatus stat) const
384 Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mess);
385 Interface_CheckIterator res;
386 res.SetModel (themod); res.SetName (thename.ToCString());
387 Standard_Integer i, nb = thelist->Length();
388 for (i = 1; i <= nb; i ++) {
389 const Handle(Interface_Check) ach = thelist->Value(i);
390 if (ach->Complies(str,incl,stat)) res.Add (ach,thenums->Value(i));
396 //=======================================================================
399 //=======================================================================
401 Standard_Boolean Interface_CheckIterator::Remove(const Standard_CString mess,
402 const Standard_Integer incl,
403 const Interface_CheckStatus stat)
405 Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mess);
406 Standard_Boolean res = Standard_False;
407 Standard_Integer i, nb = thelist->Length();
408 for (i = 1; i <= nb; i ++) {
409 Handle(Interface_Check) ach = thelist->ChangeValue(i);
410 if (ach->Remove (str,incl,stat)) res = Standard_True;
416 //=======================================================================
417 //function : Checkeds
419 //=======================================================================
421 Handle(TColStd_HSequenceOfTransient) Interface_CheckIterator::Checkeds
422 (const Standard_Boolean failsonly, const Standard_Boolean global) const
424 Handle(TColStd_HSequenceOfTransient) list;
425 if (themod.IsNull()) return list;
426 list = new TColStd_HSequenceOfTransient();
427 Standard_Integer num, i, nb = thelist->Length();
428 for (i = 1; i <= nb; i ++) {
429 const Handle(Interface_Check) chk = thelist->Value(i);
430 if (failsonly && !chk->HasFailed()) continue;
431 if (chk->NbWarnings() == 0) continue;
432 num = thenums->Value(i);
433 if (num == 0 && global) list->Append (themod);
434 else if (num > 0) list->Append (themod->Value(num));
440 //=======================================================================
443 //=======================================================================
445 void Interface_CheckIterator::Start () const
447 thecurr->CValue() = 1;
451 //=======================================================================
454 //=======================================================================
456 Standard_Boolean Interface_CheckIterator::More () const
458 if (thecurr->Value() < 0) thecurr->CValue() = 1;
459 return (thecurr->Value() <= thelist->Length());
463 //=======================================================================
466 //=======================================================================
468 void Interface_CheckIterator::Next () const
470 if (thecurr->Value() < 0) thecurr->CValue() = 1;
471 thecurr->CValue() ++;
475 //=======================================================================
478 //=======================================================================
480 const Handle(Interface_Check)& Interface_CheckIterator::Value () const
482 if (thecurr->Value() > thelist->Length()) throw Standard_NoSuchObject("Interface Check Iterator : Value");
483 return thelist->Value(thecurr->Value());
487 //=======================================================================
490 //=======================================================================
492 Standard_Integer Interface_CheckIterator::Number () const
494 if (thecurr->Value() > thenums->Length()) throw Standard_NoSuchObject("Interface Check Iterator : Value");
495 return thenums->Value(thecurr->Value());
499 //=======================================================================
502 //=======================================================================
504 void Interface_CheckIterator::Print(const Handle(Message_Messenger)& S,
505 const Standard_Boolean failsonly,
506 const Standard_Integer final) const
508 Print (S,themod,failsonly,final);
512 //=======================================================================
515 //=======================================================================
517 void Interface_CheckIterator::Print(const Handle(Message_Messenger)& S,
518 const Handle(Interface_InterfaceModel)& model,
519 const Standard_Boolean failsonly,
520 const Standard_Integer /*final*/) const
522 Standard_Boolean titre = Standard_False;
523 /*Standard_CString mesnum;
524 Standard_CString mesnum0 = ":";
525 Standard_CString mesnum1 = " (original):";
526 Standard_CString mesnum2 = " (computed):"; */
527 Standard_Integer i, nbch = 0, nb = thelist->Length();//,j; svv #2
528 Standard_Boolean yamod = !model.IsNull();
529 for (i = 1; i <= nb; i ++) {
530 const Handle(Interface_Check) ach = thelist->Value(i);
531 Standard_Integer nbw = 0, nbf = ach->NbFails();
532 if (!failsonly) nbw = ach->NbWarnings();
533 if (nbf + nbw == 0) continue;
534 Handle(Standard_Transient) ent = ach->Entity();
535 Standard_Integer nm0 = thenums->Value(i);
536 Standard_Boolean entnul = ent.IsNull();
537 Standard_Integer num = nm0;
538 if (nm0 <= 0 && !entnul && yamod) num = model->Number(ent);
539 if (nm0 <= 0 && entnul) num = -1; // Global
541 // if (yamod) mesnum = (nm0 > 0 ? mesnum1 : mesnum2);
543 if (!titre) S<<" ** " << Name() << " **"<<Message_EndLine;
544 titre = Standard_True;
545 S<<"Check:"; if(nb > 9 && i < 10) S<<" "; if (nb > 99 && i < 100) S<<" ";
547 if (num < 0) S<<" -- Global Check"<<Message_EndLine;
548 else if (num == 0) S<<" -- Entity n0 ??:";
550 if (yamod) { S<<" -- Entity (n0:id) "; model->Print (ent,S); }
551 else S<<" -- Entity n0 "<<num;
552 // S<<" -- Entity n0 "<<num<<mesnum;
553 // if (yamod) model->PrintLabel(ent,S);
555 if (num >= 0 && entnul) S<<" (unknown Type)"<<Message_EndLine;
556 else if (num >= 0 && !entnul) {
557 if (yamod) S<<" Type:"<<model->TypeName(ent)<<Message_EndLine;
558 else S<<" Type:"<<ent->DynamicType()->Name()<<Message_EndLine;
562 ach->Print (S, (failsonly ? 1 : 3));
564 // if (nbch > 0) S<<" ---- Checks : "<<nbch<<" ----"<<std::endl;
568 //=======================================================================
571 //=======================================================================
573 void Interface_CheckIterator::Destroy ()
576 } // redevient standard