1 #include <Interface_CheckIterator.ixx>
2 #include <Standard_NoSuchObject.hxx>
3 #include <TCollection_HAsciiString.hxx>
6 static const Handle(Interface_Check)& nulcheck ()
8 static Handle(Interface_Check) nulch = new Interface_Check;
13 //=======================================================================
14 //function : Interface_CheckIterator
16 //=======================================================================
18 Interface_CheckIterator::Interface_CheckIterator ()
24 //=======================================================================
25 //function : Interface_CheckIterator
27 //=======================================================================
29 Interface_CheckIterator::Interface_CheckIterator(const Standard_CString name)
36 //=======================================================================
39 //=======================================================================
41 void Interface_CheckIterator::SetName (const Standard_CString name)
44 if (name[0] != '\0') thename.AssignCat(name);
48 //=======================================================================
51 //=======================================================================
53 Standard_CString Interface_CheckIterator::Name () const
55 return thename.ToCString();
59 //=======================================================================
62 //=======================================================================
64 void Interface_CheckIterator::SetModel(const Handle(Interface_InterfaceModel)& model)
70 //=======================================================================
73 //=======================================================================
75 Handle(Interface_InterfaceModel) Interface_CheckIterator::Model() const
81 //=======================================================================
84 //=======================================================================
86 void Interface_CheckIterator::Clear ()
88 thelist = new Interface_HSequenceOfCheck();
89 thenums = new TColStd_HSequenceOfInteger();
90 thecurr = new Interface_IntVal;
91 thecurr->CValue() = 1;
95 //=======================================================================
98 //=======================================================================
100 void Interface_CheckIterator::Merge (Interface_CheckIterator& other)
102 themod = other.Model();
103 for (other.Start(); other.More(); other.Next())
104 Add (other.Value(),other.Number());
108 //=======================================================================
111 //=======================================================================
113 void Interface_CheckIterator::Add(const Handle(Interface_Check)& ach,
114 const Standard_Integer num)
116 // Add <meme num que le dernier> -> cumul des Checks
117 if (ach->NbWarnings() + ach->NbFails() == 0) return;
118 Standard_Integer nm = num;
119 if (num <= 0 && ach->HasEntity()) {
120 if (!themod.IsNull()) {
121 nm = themod->Number (ach->Entity());
122 if (nm <= 0) nm = -1;
126 if (nm >= 0 && nm <= - (thecurr->Value()) ) {
127 Standard_Integer i , numpos = 0 , nb = thelist->Length();
128 for (i = nb; i > 0; i --)
129 if (thenums->Value(i) == nm) { numpos = i; break; }
130 if (numpos > 0 && nm >= 0) {
131 Handle(Interface_Check) lch = thelist->ChangeValue(numpos);
132 lch->GetMessages (ach);
134 // Cas normal : on ajoute en fin de liste
135 else { thelist->Append(ach); thenums->Append(nm); }
137 // Pas encore vu passe : inutile de chercher
138 else { thelist->Append(ach); thenums->Append(nm); thecurr->CValue() = -nm; }
142 //=======================================================================
145 //=======================================================================
147 const Handle(Interface_Check)& Interface_CheckIterator::Check
148 (const Standard_Integer num) const
150 Standard_Integer i, nb = thelist->Length();
151 for (i = 1; i <= nb; i ++) {
152 if (num == thenums->Value(i)) return thelist->Value(i);
158 //=======================================================================
161 //=======================================================================
163 const Handle(Interface_Check)& Interface_CheckIterator::Check
164 (const Handle(Standard_Transient)& ent) const
166 Standard_Integer num = -1;
167 if (!themod.IsNull()) num = themod->Number(ent);
168 if (num > 0) return Check(num);
170 Standard_Integer i, nb = thelist->Length();
171 for (i = 1; i <= nb; i ++) {
172 if (ent == thelist->Value(i)->Entity()) return thelist->Value(i);
178 //=======================================================================
181 //=======================================================================
183 Handle(Interface_Check)& Interface_CheckIterator::CCheck
184 (const Standard_Integer num)
186 Standard_Integer i, nb = thenums->Length();
187 for (i = 1; i <= nb; i ++) {
188 if (num == thenums->Value(i)) return thelist->ChangeValue(i);
190 Handle(Interface_Check) ach = new Interface_Check;
191 thelist->Append(ach); thenums->Append(num);
192 return thelist->ChangeValue (thelist->Length());
196 //=======================================================================
199 //=======================================================================
201 Handle(Interface_Check)& Interface_CheckIterator::CCheck
202 (const Handle(Standard_Transient)& ent)
204 Standard_Integer num = -1;
205 if (!themod.IsNull()) num = themod->Number(ent);
206 if (num > 0) return CCheck(num);
208 Standard_Integer i, nb = thelist->Length();
209 for (i = 1; i <= nb; i ++) {
210 if (ent == thelist->Value(i)->Entity()) return thelist->ChangeValue(i);
213 Handle(Interface_Check) ach = new Interface_Check;
214 thelist->Append(ach); thenums->Append(num);
215 return thelist->ChangeValue (thelist->Length());
219 //=======================================================================
222 //=======================================================================
224 Standard_Boolean Interface_CheckIterator::IsEmpty
225 (const Standard_Boolean failsonly) const
227 if (thelist->IsEmpty()) return Standard_True;
228 if (!failsonly) return Standard_False;
229 Standard_Integer i, nb = thelist->Length();
230 for (i = 1; i <= nb; i ++) {
231 if (thelist->Value(i)->HasFailed()) return Standard_False;
233 return Standard_True;
237 //=======================================================================
240 //=======================================================================
242 Interface_CheckStatus Interface_CheckIterator::Status () const
244 Interface_CheckStatus stat = Interface_CheckOK;
245 Standard_Integer i, nb = thelist->Length();
246 for (i = 1; i <= nb; i ++) {
247 const Handle(Interface_Check) ach = thelist->Value(i);
248 if (ach->HasFailed()) return Interface_CheckFail;
249 if (ach->NbWarnings() > 0) stat = Interface_CheckWarning;
255 //=======================================================================
256 //function : Complies
258 //=======================================================================
260 Standard_Boolean Interface_CheckIterator::Complies
261 (const Interface_CheckStatus stat) const
263 Standard_Boolean res = Standard_False;
264 if (stat == Interface_CheckNoFail) res = Standard_True;
265 Standard_Integer i, nb = thelist->Length();
266 for (i = 1; i <= nb; i ++) {
267 const Handle(Interface_Check) ach = thelist->Value(i);
268 Standard_Integer nbf = ach->NbFails(), nbw = ach->NbWarnings();
270 case Interface_CheckOK : if (nbf + nbw > 0) return Standard_False; break;
271 case Interface_CheckWarning : if (nbf > 0) return Standard_False;
272 if (nbw > 0) res = Standard_True; break;
273 case Interface_CheckFail : if (nbf > 0) return Standard_True; break;
274 case Interface_CheckAny : return Standard_True;
275 case Interface_CheckMessage : if (nbf + nbw > 0) return Standard_True; break;
276 case Interface_CheckNoFail : if (nbf > 0) return Standard_False; break;
284 //=======================================================================
287 //=======================================================================
289 Interface_CheckIterator Interface_CheckIterator::Extract
290 (const Interface_CheckStatus stat) const
292 Interface_CheckIterator res;
293 res.SetModel (themod); res.SetName (thename.ToCString());
294 Standard_Integer i, nb = thelist->Length();
295 for (i = 1; i <= nb; i ++) {
296 const Handle(Interface_Check) ach = thelist->Value(i);
297 Standard_Integer nbf = ach->NbFails(), nbw = ach->NbWarnings();
298 Standard_Boolean prend = Standard_False;
300 case Interface_CheckOK : prend = (nbf + nbw == 0); break;
301 case Interface_CheckWarning : prend = (nbf == 0 && nbw > 0); break;
302 case Interface_CheckFail : prend = (nbf > 0); break;
303 case Interface_CheckAny : prend = Standard_True; break;
304 case Interface_CheckMessage : prend = (nbf + nbw > 0); break;
305 case Interface_CheckNoFail : prend = (nbf == 0); break;
308 if (prend) res.Add (ach,thenums->Value(i));
314 //=======================================================================
317 //=======================================================================
319 Interface_CheckIterator Interface_CheckIterator::Extract
320 (const Standard_CString mess,
321 const Standard_Integer incl, const Interface_CheckStatus stat) const
323 Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mess);
324 Interface_CheckIterator res;
325 res.SetModel (themod); res.SetName (thename.ToCString());
326 Standard_Integer i, nb = thelist->Length();
327 for (i = 1; i <= nb; i ++) {
328 const Handle(Interface_Check) ach = thelist->Value(i);
329 if (ach->Complies(str,incl,stat)) res.Add (ach,thenums->Value(i));
335 //=======================================================================
338 //=======================================================================
340 Standard_Boolean Interface_CheckIterator::Remove(const Standard_CString mess,
341 const Standard_Integer incl,
342 const Interface_CheckStatus stat)
344 Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mess);
345 Standard_Boolean res = Standard_False;
346 Standard_Integer i, nb = thelist->Length();
347 for (i = 1; i <= nb; i ++) {
348 Handle(Interface_Check) ach = thelist->ChangeValue(i);
349 if (ach->Remove (str,incl,stat)) res = Standard_True;
355 //=======================================================================
356 //function : Checkeds
358 //=======================================================================
360 Handle(TColStd_HSequenceOfTransient) Interface_CheckIterator::Checkeds
361 (const Standard_Boolean failsonly, const Standard_Boolean global) const
363 Handle(TColStd_HSequenceOfTransient) list;
364 if (themod.IsNull()) return list;
365 list = new TColStd_HSequenceOfTransient();
366 Standard_Integer num, i, nb = thelist->Length();
367 for (i = 1; i <= nb; i ++) {
368 const Handle(Interface_Check) chk = thelist->Value(i);
369 if (failsonly && !chk->HasFailed()) continue;
370 if (chk->NbWarnings() == 0) continue;
371 num = thenums->Value(i);
372 if (num == 0 && global) list->Append (themod);
373 else if (num > 0) list->Append (themod->Value(num));
379 //=======================================================================
382 //=======================================================================
384 void Interface_CheckIterator::Start () const
386 thecurr->CValue() = 1;
390 //=======================================================================
393 //=======================================================================
395 Standard_Boolean Interface_CheckIterator::More () const
397 if (thecurr->Value() < 0) thecurr->CValue() = 1;
398 return (thecurr->Value() <= thelist->Length());
402 //=======================================================================
405 //=======================================================================
407 void Interface_CheckIterator::Next () const
409 if (thecurr->Value() < 0) thecurr->CValue() = 1;
410 thecurr->CValue() ++;
414 //=======================================================================
417 //=======================================================================
419 const Handle(Interface_Check)& Interface_CheckIterator::Value () const
421 if (thecurr->Value() > thelist->Length()) Standard_NoSuchObject::Raise
422 ("Interface Check Iterator : Value");
423 return thelist->Value(thecurr->Value());
427 //=======================================================================
430 //=======================================================================
432 Standard_Integer Interface_CheckIterator::Number () const
434 if (thecurr->Value() > thenums->Length()) Standard_NoSuchObject::Raise
435 ("Interface Check Iterator : Value");
436 return thenums->Value(thecurr->Value());
440 //=======================================================================
443 //=======================================================================
445 void Interface_CheckIterator::Print(const Handle(Message_Messenger)& S,
446 const Standard_Boolean failsonly,
447 const Standard_Integer final) const
449 Print (S,themod,failsonly,final);
453 //=======================================================================
456 //=======================================================================
458 void Interface_CheckIterator::Print(const Handle(Message_Messenger)& S,
459 const Handle(Interface_InterfaceModel)& model,
460 const Standard_Boolean failsonly,
461 const Standard_Integer /*final*/) const
463 Standard_Boolean titre = Standard_False;
464 /*Standard_CString mesnum;
465 Standard_CString mesnum0 = ":";
466 Standard_CString mesnum1 = " (original):";
467 Standard_CString mesnum2 = " (computed):"; */
468 Standard_Integer i, nbch = 0, nb = thelist->Length();//,j; svv #2
469 Standard_Boolean yamod = !model.IsNull();
470 for (i = 1; i <= nb; i ++) {
471 const Handle(Interface_Check) ach = thelist->Value(i);
472 Standard_Integer nbw = 0, nbf = ach->NbFails();
473 if (!failsonly) nbw = ach->NbWarnings();
474 if (nbf + nbw == 0) continue;
475 Handle(Standard_Transient) ent = ach->Entity();
476 Standard_Integer nm0 = thenums->Value(i);
477 Standard_Boolean entnul = ent.IsNull();
478 Standard_Integer num = nm0;
479 if (nm0 <= 0 && !entnul && yamod) num = model->Number(ent);
480 if (nm0 <= 0 && entnul) num = -1; // Global
482 // if (yamod) mesnum = (nm0 > 0 ? mesnum1 : mesnum2);
484 if (!titre) S<<" ** " << Name() << " **"<<endl;
485 titre = Standard_True;
486 S<<"Check:"; if(nb > 9 && i < 10) S<<" "; if (nb > 99 && i < 100) S<<" ";
488 if (num < 0) S<<" -- Global Check"<<endl;
489 else if (num == 0) S<<" -- Entity n0 ??:";
491 if (yamod) { S<<" -- Entity (n0:id) "; model->Print (ent,S); }
492 else S<<" -- Entity n0 "<<num;
493 // S<<" -- Entity n0 "<<num<<mesnum;
494 // if (yamod) model->PrintLabel(ent,S);
496 if (num >= 0 && entnul) S<<" (unknown Type)"<<endl;
497 else if (num >= 0 && !entnul) {
498 if (yamod) S<<" Type:"<<model->TypeName(ent)<<endl;
499 else S<<" Type:"<<ent->DynamicType()->Name()<<endl;
503 ach->Print (S, (failsonly ? 1 : 3));
505 // if (nbch > 0) S<<" ---- Checks : "<<nbch<<" ----"<<endl;
509 //=======================================================================
512 //=======================================================================
514 void Interface_CheckIterator::Destroy ()
517 } // redevient standard