0031362: Inspectors - MessageView plugin for message alerts
[occt.git] / src / Message / Message_PrinterToReport.cxx
1 // Copyright (c) 2020 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 <Message_PrinterToReport.hxx>
15
16 #include <Message.hxx>
17 #include <Message_AlertExtended.hxx>
18 #include <Message_Attribute.hxx>
19 #include <Message_AttributeMeter.hxx>
20 #include <Message_AttributeObject.hxx>
21 #include <Message_AttributeStream.hxx>
22 #include <Message_Report.hxx>
23
24 #include <Standard_Dump.hxx>
25 #include <TCollection_ExtendedString.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(Message_PrinterToReport, Message_Printer)
28
29 //=======================================================================
30 //function : Report
31 //purpose  :
32 //=======================================================================
33 const Handle(Message_Report)& Message_PrinterToReport::Report() const
34 {
35   if (!myReport.IsNull())
36   {
37     return myReport;
38   }
39
40   return Message::DefaultReport (Standard_True);
41 }
42
43 //=======================================================================
44 //function : SendStringStream
45 //purpose  :
46 //=======================================================================
47 void Message_PrinterToReport::SendStringStream (const Standard_SStream& theStream,
48                                                 const Message_Gravity   theGravity) const
49 {
50   const Handle(Message_Report)& aReport = Report();
51   if (!aReport->ActiveMetrics().IsEmpty())
52   {
53     sendMetricAlert (theStream.str().c_str(), theGravity);
54     return;
55   }
56   if (Standard_Dump::HasChildKey(Standard_Dump::Text (theStream)))
57   {
58     Message_AlertExtended::AddAlert (aReport, new Message_AttributeStream (theStream, myName), theGravity);
59     myName.Clear();
60   }
61   else
62   {
63     if (!myName.IsEmpty())
64     {
65       TCollection_AsciiString aName = myName;
66       myName.Clear();
67       send (aName, theGravity);
68     }
69     myName = Standard_Dump::Text (theStream);
70   }
71 }
72
73 //=======================================================================
74 //function : SendObject
75 //purpose  :
76 //=======================================================================
77 void Message_PrinterToReport::SendObject (const Handle(Standard_Transient)& theObject,
78                                           const Message_Gravity theGravity) const
79 {
80   const Handle(Message_Report)& aReport = Report();
81   if (!aReport->ActiveMetrics().IsEmpty())
82   {
83     sendMetricAlert (myName, theGravity);
84     return;
85   }
86
87   Message_AlertExtended::AddAlert (aReport, new Message_AttributeObject (theObject, myName), theGravity);
88 }
89
90 //=======================================================================
91 //function : send
92 //purpose  :
93 //=======================================================================
94 void Message_PrinterToReport::send (const TCollection_AsciiString& theString,
95                                     const Message_Gravity theGravity) const
96 {
97   if (!myName.IsEmpty())
98   {
99     TCollection_AsciiString aName = myName;
100     myName.Clear();
101     send (aName, theGravity);
102   }
103
104   const Handle(Message_Report)& aReport = Report();
105   if (!aReport->ActiveMetrics().IsEmpty())
106   {
107     sendMetricAlert (theString, theGravity);
108     return;
109   }
110   Message_AlertExtended::AddAlert (aReport, new Message_Attribute (theString), theGravity);
111 }
112
113 //=======================================================================
114 //function : sendMetricAlert
115 //purpose  :
116 //=======================================================================
117 void Message_PrinterToReport::sendMetricAlert (const TCollection_AsciiString theValue,
118                                                const Message_Gravity theGravity) const
119 {
120   Message_AlertExtended::AddAlert (Report(), new Message_AttributeMeter (theValue), theGravity);
121 }