0024644: Draw_Printer - provide the way to control messages gravity filter
[occt.git] / src / Draw / Draw_Commands.cxx
index 5ef912c..d979d0a 100644 (file)
 
 #include <Draw.ixx>
 
-void Draw::Commands(Draw_Interpretor& theCommands)
+#include <Draw_Printer.hxx>
+#include <Message.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_PrinterOStream.hxx>
+
+void Draw::Commands (Draw_Interpretor& theCommands)
 {
+  static Standard_Boolean isFirstTime = Standard_True;
+  if (isFirstTime)
+  {
+    // override default std::cout printer by draw interpretor printer
+    const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger();
+    if (!aMsgMgr.IsNull())
+    {
+      aMsgMgr->RemovePrinters (STANDARD_TYPE (Message_PrinterOStream));
+      aMsgMgr->RemovePrinters (STANDARD_TYPE (Draw_Printer));
+      aMsgMgr->AddPrinter (new Draw_Printer (theCommands));
+    }
+    isFirstTime = Standard_False;
+  }
+
   Draw::BasicCommands(theCommands);
   Draw::VariableCommands(theCommands);
   Draw::GraphicCommands(theCommands);