IMPLEMENT_STANDARD_RTTIEXT(Message_PrinterToReport, Message_Printer)
+//=======================================================================
+//function : Destructor
+//purpose :
+//=======================================================================
+Message_PrinterToReport::~Message_PrinterToReport()
+{
+ if (!myReport.IsNull())
+ {
+ myReport->UpdateActiveInMessenger();
+ }
+}
+
//=======================================================================
//function : Report
//purpose :
return Message::DefaultReport (Standard_True);
}
+//=======================================================================
+//function : Send
+//purpose :
+//=======================================================================
+void Message_PrinterToReport::SetReport (const Handle(Message_Report)& theReport)
+{
+ myReport = theReport;
+ myReport->UpdateActiveInMessenger();
+}
+
//=======================================================================
//function : Send
//purpose :
//! Create printer for redirecting messages into report.
Message_PrinterToReport() {}
- ~Message_PrinterToReport() {}
+ //! Destructor
+ Standard_EXPORT ~Message_PrinterToReport();
//! Returns the current or default report
Standard_EXPORT const Handle(Message_Report)& Report() const;
//! Sets the printer report
//! @param theReport report for messages processing, if NULL, the default report is used
- Standard_EXPORT void SetReport (const Handle(Message_Report)& theReport) { myReport = theReport; }
+ Standard_EXPORT void SetReport (const Handle(Message_Report)& theReport);
//! Send a string message with specified trace level.
//! Stream is converted to string value.
//=======================================================================
Message_Report::Message_Report ()
-: myLimit (-1), myWriteFileOnEachAlert (Standard_False)
+: myLimit (-1), myWriteFileOnEachAlert (Standard_False),
+ myIsActiveInMessenger (Standard_False)
{
}
Standard_Boolean Message_Report::IsActiveInMessenger (const Handle(Message_Messenger)& theMessenger) const
{
- Handle(Message_Messenger) aMessenger = theMessenger.IsNull() ? Message::DefaultMessenger() : theMessenger;
- for (Message_SequenceOfPrinters::Iterator anIterator (aMessenger->Printers()); anIterator.More(); anIterator.Next())
- {
- if (anIterator.Value()->IsKind(STANDARD_TYPE (Message_PrinterToReport)) &&
- Handle(Message_PrinterToReport)::DownCast (anIterator.Value())->Report() == this)
- return Standard_True;
- }
- return Standard_False;
+ return myIsActiveInMessenger;
}
//=======================================================================
//=======================================================================
void Message_Report::ActivateInMessenger (const Standard_Boolean toActivate,
- const Handle(Message_Messenger)& theMessenger) const
+ const Handle(Message_Messenger)& theMessenger)
{
if (toActivate == IsActiveInMessenger())
return;
+ myIsActiveInMessenger = toActivate;
Handle(Message_Messenger) aMessenger = theMessenger.IsNull() ? Message::DefaultMessenger() : theMessenger;
if (toActivate)
{
}
}
+//=======================================================================
+//function : UpdateActiveInMessenger
+//purpose :
+//=======================================================================
+void Message_Report::UpdateActiveInMessenger (const Handle(Message_Messenger)& theMessenger)
+{
+ Handle(Message_Messenger) aMessenger = theMessenger.IsNull() ? Message::DefaultMessenger() : theMessenger;
+ for (Message_SequenceOfPrinters::Iterator anIterator (aMessenger->Printers()); anIterator.More(); anIterator.Next())
+ {
+ if (anIterator.Value()->IsKind(STANDARD_TYPE (Message_PrinterToReport)) &&
+ Handle(Message_PrinterToReport)::DownCast (anIterator.Value())->Report() == this)
+ {
+ myIsActiveInMessenger = Standard_True;
+ }
+ }
+ myIsActiveInMessenger = Standard_False;
+}
+
//=======================================================================
//function : AddLevel
//purpose :
//! Creates an instance of Message_PrinterToReport with the current report and register it in messenger
//! @param toActivate if true, activated else deactivated
// @param theMessenger the messenger. If it's NULL, the default messenger is used
- Standard_EXPORT void ActivateInMessenger (const Standard_Boolean toActivate, const Handle(Message_Messenger)& theMessenger = NULL) const;
+ Standard_EXPORT void ActivateInMessenger (const Standard_Boolean toActivate, const Handle(Message_Messenger)& theMessenger = NULL);
+ //! Updates internal flag IsActiveInMessenger.
+ //! It becomes true if messenger contains at least one instance of Message_PrinterToReport.
+ //! @param theMessenger the messenger. If it's NULL, the default messenger is used
+ Standard_EXPORT void UpdateActiveInMessenger (const Handle(Message_Messenger)& theMessenger = NULL);
+
//! Add new level of alerts
//! @param theLevel a level
Standard_EXPORT void AddLevel (Message_Level* theLevel, const TCollection_AsciiString& theName);
Standard_Integer myLimit; //! Maximum number of collected alerts on the top level
Standard_Boolean myWriteFileOnEachAlert; //! State if output file should be written on each alert adding
+ Standard_Boolean myIsActiveInMessenger; //! state whether the report is activated in messenger
};
#endif // _Message_Report_HeaderFile