From: nds Date: Mon, 28 Sep 2020 17:56:54 +0000 (+0300) Subject: 0029451: Information Message Alert to debug an algorithm or object functionality X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=ee77107582289774508442602b8b9ea8ac0fad09;p=occt-copy.git 0029451: Information Message Alert to debug an algorithm or object functionality --- diff --git a/src/Message/Message_PrinterToReport.cxx b/src/Message/Message_PrinterToReport.cxx index ca225ab0af..609e10c978 100644 --- a/src/Message/Message_PrinterToReport.cxx +++ b/src/Message/Message_PrinterToReport.cxx @@ -28,6 +28,18 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_PrinterToReport, Message_Printer) +//======================================================================= +//function : Destructor +//purpose : +//======================================================================= +Message_PrinterToReport::~Message_PrinterToReport() +{ + if (!myReport.IsNull()) + { + myReport->UpdateActiveInMessenger(); + } +} + //======================================================================= //function : Report //purpose : @@ -40,6 +52,16 @@ const Handle(Message_Report)& Message_PrinterToReport::Report() const return Message::DefaultReport (Standard_True); } +//======================================================================= +//function : Send +//purpose : +//======================================================================= +void Message_PrinterToReport::SetReport (const Handle(Message_Report)& theReport) +{ + myReport = theReport; + myReport->UpdateActiveInMessenger(); +} + //======================================================================= //function : Send //purpose : diff --git a/src/Message/Message_PrinterToReport.hxx b/src/Message/Message_PrinterToReport.hxx index f61a5be2b0..faa95acf1a 100644 --- a/src/Message/Message_PrinterToReport.hxx +++ b/src/Message/Message_PrinterToReport.hxx @@ -35,14 +35,15 @@ public: //! 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. diff --git a/src/Message/Message_Report.cxx b/src/Message/Message_Report.cxx index 2850240119..a6e15044fe 100644 --- a/src/Message/Message_Report.cxx +++ b/src/Message/Message_Report.cxx @@ -37,7 +37,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_Report,Standard_Transient) //======================================================================= Message_Report::Message_Report () -: myLimit (-1), myWriteFileOnEachAlert (Standard_False) +: myLimit (-1), myWriteFileOnEachAlert (Standard_False), + myIsActiveInMessenger (Standard_False) { } @@ -123,14 +124,7 @@ Standard_Boolean Message_Report::HasAlert (const Handle(Standard_Type)& theType, 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; } //======================================================================= @@ -139,11 +133,12 @@ Standard_Boolean Message_Report::IsActiveInMessenger (const Handle(Message_Messe //======================================================================= 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) { @@ -168,6 +163,24 @@ void Message_Report::ActivateInMessenger (const Standard_Boolean 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 : diff --git a/src/Message/Message_Report.hxx b/src/Message/Message_Report.hxx index 599b0fad7b..b96f5c5e62 100644 --- a/src/Message/Message_Report.hxx +++ b/src/Message/Message_Report.hxx @@ -82,8 +82,13 @@ public: //! 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); @@ -183,6 +188,7 @@ protected: 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