0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / XSControl / XSControl_SignTransferStatus.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
15 #include <Interface_Check.hxx>
16 #include <Interface_InterfaceModel.hxx>
17 #include <Standard_Transient.hxx>
18 #include <Standard_Type.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <Transfer_Binder.hxx>
21 #include <Transfer_TransientProcess.hxx>
22 #include <XSControl_SignTransferStatus.hxx>
23 #include <XSControl_TransferReader.hxx>
24
25 IMPLEMENT_STANDARD_RTTIEXT(XSControl_SignTransferStatus,IFSelect_Signature)
26
27 //#include <stdio.h>
28 static TCollection_AsciiString& themes()
29 {
30   static TCollection_AsciiString tm;
31   return tm;
32 }
33 // si resultat avec type: a exploiter tout de suite !
34
35 XSControl_SignTransferStatus::XSControl_SignTransferStatus ()
36 : IFSelect_Signature("Transfer Status")    {  }
37
38 XSControl_SignTransferStatus::XSControl_SignTransferStatus
39   (const Handle(XSControl_TransferReader)& TR)
40 : IFSelect_Signature("Transfer Status") ,
41   theTR (TR)    {  }
42
43 void  XSControl_SignTransferStatus::SetReader
44   (const Handle(XSControl_TransferReader)& TR)
45       {  theTR = TR;  }
46
47 void  XSControl_SignTransferStatus::SetMap
48   (const Handle(Transfer_TransientProcess)& TP)
49       {  theTP = TP;  }
50
51 Handle(Transfer_TransientProcess)  XSControl_SignTransferStatus::Map () const
52       {  return theTP;  }
53
54 Handle(XSControl_TransferReader)  XSControl_SignTransferStatus::Reader () const
55       {  return theTR;  }
56
57
58
59 // BinderStatus retourne une valeur :
60 // 0 Binder Null.   1 void  2 Warning seul  3 Fail seul
61 // 11 Resultat OK. 12 Resultat+Warning. 13 Resultat+Fail
62 // 20 Abnormal (Interrupted)
63
64 static Standard_Integer BinderStatus (const Handle(Transfer_Binder)& binder)
65 {
66   Standard_Integer stat = 0;
67   if (binder.IsNull())  return 0;
68   Interface_CheckStatus cst = binder->Check()->Status();
69   Transfer_StatusExec est = binder->StatusExec ();
70   Standard_Boolean res = binder->HasResult();
71   if (est == Transfer_StatusRun || est == Transfer_StatusLoop) return 20;
72   if      (cst == Interface_CheckOK)      stat = (res ? 11 : 1);
73   else if (cst == Interface_CheckWarning) stat = (res ? 12 : 2);
74   else if (cst == Interface_CheckFail)    stat = (res ? 13 : 3);
75
76   return stat;
77 }
78
79
80 Standard_CString  XSControl_SignTransferStatus::Value
81   (const Handle(Standard_Transient)& ent,
82    const Handle(Interface_InterfaceModel)& /*model*/) const
83 {
84   if (ent.IsNull()) return "";
85   Handle(Transfer_TransientProcess)  TP = theTP;
86   if (TP.IsNull() && !theTR.IsNull()) TP = theTR->TransientProcess();
87   if (TP.IsNull()) return "";
88
89   Handle(Transfer_Binder) binder = TP->Find(ent);
90
91   Standard_Integer stat = BinderStatus (binder);
92
93   if (stat <= 1) return "";
94   if (stat == 2) return "Warning";
95   if (stat == 3) return "Fail";
96   if (stat == 20) return "Fail on run";
97
98   themes().Clear();
99   if (stat > 10) {
100 //  Y a un resultat : donner son type
101     Handle(Transfer_Binder) bnd = binder;
102     Standard_Integer hasres = Standard_False;
103     while (!bnd.IsNull()) {
104       if (bnd->Status() != Transfer_StatusVoid) {
105         if (!hasres) themes().AssignCat("Result:");
106         else themes().AssignCat(",");
107         themes().AssignCat(bnd->ResultTypeName());
108         hasres = Standard_True;
109       }
110       bnd = bnd->NextResult();
111     }
112 //    if (stat == 11) sprintf(themes,"Result:%s",binder->ResultTypeName());
113     if (stat == 12) themes().AssignCat("/Warning");
114     if (stat == 13) themes().AssignCat("/Fail");
115   }
116   return themes().ToCString();
117 }