]> OCCT Git - occt-copy.git/commitdiff
0029451: Information Message Alert to debug an algorithm or object functionality
authornds <nds@opencascade.com>
Mon, 28 Sep 2020 17:56:54 +0000 (20:56 +0300)
committernds <nds@opencascade.com>
Mon, 5 Oct 2020 11:24:49 +0000 (14:24 +0300)
src/Message/Message_PrinterToReport.cxx
src/Message/Message_PrinterToReport.hxx
src/Message/Message_Report.cxx
src/Message/Message_Report.hxx

index ca225ab0af9fa7a78a0b873fa43c04e826317778..609e10c9789b3152f3b418f90cf25e6e90f30e77 100644 (file)
 
 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  :
index f61a5be2b0493c199da67bfb74e0df46cf19d195..faa95acf1ae5b972bdc7d72d0d60451ebabb9ceb 100644 (file)
@@ -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.
index 28502401190d17417e38f34147ecdd91b8b7fafe..a6e15044fe28e2535646fba43b78bd9258b1e62b 100644 (file)
@@ -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  :
index 599b0fad7bcef6de241027244cb9325d8182fcc0..b96f5c5e62e17a952a040ca8ccce50658482ff00 100644 (file)
@@ -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