0024947: Redesign OCCT legacy type system
[occt.git] / src / IFSelect / IFSelect_CheckCounter.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <IFSelect_CheckCounter.ixx>
15 #include <Standard_Transient.hxx>
16 #include <Interface_Check.hxx>
17 #include <stdio.h>
18
19
20 //=======================================================================
21 //function : IFSelect_CheckCounter
22 //purpose  : 
23 //=======================================================================
24
25 IFSelect_CheckCounter::IFSelect_CheckCounter(const Standard_Boolean withlist)
26      : IFSelect_SignatureList (withlist)
27 {
28   SetName("Check");
29 }
30
31
32 //=======================================================================
33 //function : SetSignature
34 //purpose  : 
35 //=======================================================================
36
37 void IFSelect_CheckCounter::SetSignature(const Handle(MoniTool_SignText)& sign)
38 {
39   thesign = sign;
40 }
41
42
43 //=======================================================================
44 //function : Signature
45 //purpose  : 
46 //=======================================================================
47
48 Handle(MoniTool_SignText) IFSelect_CheckCounter::Signature () const
49 {
50  return thesign;
51 }
52
53
54 //=======================================================================
55 //function : Analyse
56 //purpose  : 
57 //=======================================================================
58
59 void  IFSelect_CheckCounter::Analyse(const Interface_CheckIterator& list,
60                                      const Handle(Interface_InterfaceModel)& model,
61                                      const Standard_Boolean original,
62                                      const Standard_Boolean failsonly)
63 {
64   Standard_Integer i,nb,num, nbe = (model.IsNull() ? 0 : model->NbEntities());
65   char mess[300];
66   sprintf (mess,"Check %s",list.Name());
67   SetName (mess);
68   for (list.Start(); list.More(); list.Next()) {
69     num = list.Number();
70     Handle(Standard_Transient) ent;
71     const Handle(Interface_Check) check = list.Value();
72     ent = check->Entity();
73     if (ent.IsNull() && num > 0 && num <= nbe) ent = model->Value(num);
74     nb = check->NbFails();
75     Standard_CString tystr = NULL;
76     if (!ent.IsNull()) {
77       if (!thesign.IsNull()) tystr = thesign->Text (ent,model).ToCString();
78       else if (!model.IsNull()) tystr = model->TypeName (ent);
79       else tystr =
80         Interface_InterfaceModel::ClassName(ent->DynamicType()->Name());
81     }
82     for (i = 1; i <= nb; i ++) {
83       if (ent.IsNull())  sprintf(mess,"F: %s",check->CFail(i,original));
84       else sprintf(mess,"F:%s: %s",tystr,check->CFail(i,original));
85       Add (ent,mess);
86     }
87     nb = 0;
88     if (!failsonly) nb = check->NbWarnings();
89     for (i = 1; i <= nb; i ++) {
90       if (ent.IsNull())  sprintf(mess,"W: %s",check->CWarning(i,original));
91       else sprintf(mess,"W:%s: %s",tystr,check->CWarning(i,original));
92       Add (ent,mess);
93     }
94   }
95 }