]> OCCT Git - occt-copy.git/commitdiff
0029451: Information Message Alert to debug an algorithm or object functionality CR0_DMUReviewer_WEEK-7
authornds <nds@opencascade.com>
Sat, 22 Feb 2020 05:51:43 +0000 (08:51 +0300)
committernds <nds@opencascade.com>
Sat, 22 Feb 2020 05:52:18 +0000 (08:52 +0300)
review corrections

26 files changed:
src/DDocStd/DDocStd_ToolsCommands.cxx
src/Draw/Draw.cxx
src/Draw/Draw.hxx
src/Draw/Draw_BasicCommands.cxx
src/Draw/Draw_Commands.cxx
src/Draw/Draw_MessageCommands.cxx [new file with mode: 0644]
src/Draw/Draw_Printer.cxx
src/Draw/Draw_Printer.hxx
src/Draw/FILES
src/Message/Message_Messenger.cxx
src/Message/Message_Messenger.hxx
src/Message/Message_Printer.cxx
src/Message/Message_Printer.hxx
src/Message/Message_PrinterOStream.cxx
src/Message/Message_PrinterOStream.hxx
src/Message/Message_PrinterSystemLog.cxx
src/Message/Message_PrinterSystemLog.hxx
src/Message/Message_PrinterToReport.cxx
src/Message/Message_PrinterToReport.hxx
src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx
src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx
tests/basic/begin [new file with mode: 0644]
tests/basic/end [new file with mode: 0644]
tests/basic/grids.list [new file with mode: 0644]
tests/basic/message/messenger [new file with mode: 0644]
tests/basic/parse.rules [new file with mode: 0644]

index d31e9e0440a552e89d59c901393a94a320b3b086..27fd52563aa26697ed5c26d4d339f332ec9f9fcd 100644 (file)
@@ -149,25 +149,63 @@ static Standard_Integer DDocStd_DumpCommand (Draw_Interpretor& di,
     }
     return 0;
   } 
-  di << "TDocStd_DumpCommand : Error\n";
+  std::cerr << "TDocStd_DumpCommand : Error\n";
   return 1;
 }
 
 //=======================================================================
-//function : DDocStd_WriteReport 
+//function : DDocStd_ReadMessageReport
 //=======================================================================
+static Standard_Integer DDocStd_ReadMessageReport (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
+{
+  if (theArgNb < 2)
+  {
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  TCollection_ExtendedString aFileName (theArgVec[1]);
+  Handle(Message_Report) aReport = Message::DefaultReport (Standard_False);
+  if (aReport.IsNull())
+  {
+    std::cerr << "Error: Message_Report is not created.\n";
+    return 0;
+  }
+
+  if (!XmlDrivers_MessageReportStorage::ExportReport (aReport, aFileName))
+  {
+    std::cerr << "Error: Message_Report can not be exported in " << aFileName << ".\n";
+    return 0;
+  }
+  return 0;
+}
 
-static Standard_Integer DDocStd_WriteReport(Draw_Interpretor& di,Standard_Integer n, const char** a)
+//=======================================================================
+//function : DDocStd_WriteMessageReport
+//=======================================================================
+static Standard_Integer DDocStd_WriteMessageReport (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
 {
-  if (n < 2)
+  if (theArgNb < 2)
   {
-    di << "DDocStd_WriteReport : Error not enough argument\n";
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
     return 1;
   }
 
-  TCollection_ExtendedString aPath (a[1]); 
-  MESSAGE_STORE_XML_REPORT (aPath);
+  TCollection_ExtendedString aFileName (theArgVec[1]);
+  Handle(Message_Report) aReport = Message::DefaultReport (Standard_False);
+  if (aReport.IsNull())
+  {
+    std::cerr << "Error: Message_Report is not created.\n";
+    return 0;
+  }
 
+  if (!XmlDrivers_MessageReportStorage::ExportReport (aReport, aFileName))
+  {
+    std::cerr << "Error: Message_Report can not be exported in " << aFileName << ".\n";
+    return 0;
+  }
   return 0;
 }
 
@@ -192,9 +230,15 @@ void DDocStd::ToolsCommands(Draw_Interpretor& theCommands)
                    "DumpCommand (DOC)",
                   __FILE__, DDocStd_DumpCommand, g);   
 
-  theCommands.Add ("WriteReport", 
-                   "WriteReport path",
-                  __FILE__, DDocStd_WriteReport, g);   
-
+  theCommands.Add ("ReadMessageReport",
+                   "ReadMessageReport FileName"
+    "\nRestores content of the default Message_Report from the file. This file is an XML document."
+    "\nIt might be restored into report using ReadMessageReport."
+                   __FILE__, DDocStd_ReadMessageReport, g);
+
+  theCommands.Add ("WriteMessageReport",
+                   "WriteMessageReport FileName"
+    "\nStores the default Message_Report into a file. This is an XML document."
+    "\nIt might be restored into report using ReadMessageReport."
+                   __FILE__, DDocStd_WriteMessageReport, g);
 }
-
index 0f833476387e4014f0f4da1c07594d67f226101f..937ae34d6e4e2aa60f8bf7e78d023862a632a411 100644 (file)
@@ -425,6 +425,7 @@ void Draw_Appli(int argc, char** argv, const FDraw_InitAppli Draw_InitAppli)
   // standard commands
   // *****************************************************************
   Draw::BasicCommands(theCommands);
+  Draw::MessageCommands(theCommands);
   Draw::VariableCommands(theCommands);
   Draw::UnitCommands(theCommands);
   if (!Draw_Batch) Draw::GraphicCommands(theCommands);
index e7183164611db450e657c023cf32c9c3c94433fa..3f0f1457e41d69cfd6dc795eb85be0d999b5e384 100644 (file)
@@ -132,6 +132,9 @@ public:
   //! Defines Draw basic commands
   Standard_EXPORT static void BasicCommands (Draw_Interpretor& I);
   
+  //! Defines Draw message commands
+  Standard_EXPORT static void MessageCommands (Draw_Interpretor& I);
+
   //! Defines Draw variables handling commands.
   Standard_EXPORT static void VariableCommands (Draw_Interpretor& I);
   
index 8ccfa0093425dd899bad65f03f58131747367700..7943efc645367bc0e45ea23f9b201443be463a6c 100644 (file)
@@ -23,7 +23,6 @@
 #include <Draw_ProgressIndicator.hxx>
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
-#include <Message_Report.hxx>
 #include <OSD.hxx>
 #include <OSD_Chronometer.hxx>
 #include <OSD_Environment.hxx>
@@ -1006,115 +1005,6 @@ static int dsetsignal (Draw_Interpretor& theDI, Standard_Integer theArgNb, const
   return 0;
 }
 
-//==============================================================================
-//function : dsetreportprinter
-//purpose  :
-//==============================================================================
-static Message_SequenceOfPrinters MyDeactivatedPrinters;
-
-static Standard_Integer dsetreportprinter(Draw_Interpretor&, Standard_Integer n, const char** a)
-{
-  if (n != 2)
-  {
-    std::cout << "Enable or disable report printer: " << a[0] << " {on|off}" << std::endl;
-    return 1;
-  }
-
-  const Handle(Message_Report)& aReport = Message::DefaultReport (Standard_True);
-  const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger();
-  if (! strcmp (a[1], "on") && n == 2)
-  {
-    if (aReport->IsActiveInMessenger (aMessenger))
-    {
-      std::cout << "Error: report printer has been already activated." << std::endl;
-      return 1;
-    }
-    // store current printers in cache to restore them by deactivation current printer
-    MyDeactivatedPrinters = aMessenger->Printers();
-    aMessenger->ChangePrinters().Clear();
-
-    aReport->ActivateInMessenger (Standard_True);
-  }
-  else if (! strcmp (a[1], "off") && n == 2)
-  {
-    if (!aReport->IsActiveInMessenger())
-    {
-      std::cout << "Report printer was not activated." << std::endl;
-      return 1;
-    }
-    aReport->ActivateInMessenger (Standard_False);
-
-    aMessenger->ChangePrinters().Assign (MyDeactivatedPrinters);
-  }
-  else
-  {
-    std::cout << "Unrecognized option(s): " << a[1] << std::endl;
-    return 1;
-  }
-  return 0;
-}
-
-//==============================================================================
-//function : dsetreportmetric
-//purpose  :
-//==============================================================================
-static Standard_Integer dsetreportmetric(Draw_Interpretor&, Standard_Integer n, const char** a)
-{
-  if (n < 1)
-  {
-    std::cout << "Report metric activation: " << a[0] << " [metric_1 metric_2 ...]" << std::endl;
-    return 1;
-  }
-
-  const Handle(Message_Report)& aReport = Message::DefaultReport (Standard_True);
-  if (aReport.IsNull())
-    return 1;
-
-  aReport->ClearMetrics();
-  for (int i = 1; i < n; i++)
-  {
-    Standard_Integer aMetricId = Draw::Atoi (a [i]);
-    if (aMetricId < Message_MetricType_UserTimeCPU || aMetricId > Message_MetricType_MemHeapUsage)
-    {
-      std::cout << "Unrecognized message metric: " << aMetricId << std::endl;
-      return 1;
-    }
-    aReport->SetActiveMetric ((Message_MetricType)aMetricId, Standard_True);
-  }
-
-  return 0;
-}
-
-//==============================================================================
-//function : dprintreport
-//purpose  :
-//==============================================================================
-static Standard_Integer dprintreport(Draw_Interpretor& di, Standard_Integer n, const char** a)
-{
-  if (n < 1)
-  {
-    std::cout << "Report metric activation: " << a[0] << " [messenger]" << std::endl;
-    return 1;
-  }
-
-  const Handle(Message_Report)& aReport = Message::DefaultReport (Standard_True);
-  if (aReport.IsNull())
-    return 1;
-
-  if (n > 1) // default messenger
-  {
-    aReport->SendMessages (Message::DefaultMessenger());
-  }
-  else // stream
-  {
-    Standard_SStream aSStream;
-    aReport->Dump (aSStream);
-    di << aSStream;
-  }
-
-  return 0;
-}
-
 //==============================================================================
 //function : dtracelevel
 //purpose  :
@@ -1243,12 +1133,6 @@ void Draw::BasicCommands(Draw_Interpretor& theCommands)
                  __FILE__,dperf,g);
   theCommands.Add("dsetsignal","dsetsignal [{asis|set|unhandled|unset}=set] [{0|1|default=$CSF_FPE}]\n -- set OSD signal handler, with FPE option if argument is given",
                  __FILE__,dsetsignal,g);
-  theCommands.Add("dsetreportprinter", "manage logging of messenger into default report",
-                 __FILE__,dsetreportprinter,g);
-  theCommands.Add("dsetreportmetric", "dsetreportmetric [metric...] \n Activate report metrics, deactivate all if there are no parameters.\n",
-                 __FILE__,dsetreportmetric,g);
-  theCommands.Add("dprintreport", "dprintreport [messenger] \n Send report content to default messenger or stream (if parameter is absent).\n",
-                 __FILE__,dprintreport,g);
 
   theCommands.Add("dparallel",
     "dparallel [-occt {0|1}] [-nbThreads Count] [-nbDefThreads Count]"
index c375f9eeda033c838cf12c59ae40602f6214d18a..cf291fb0806f64576571ad2faa32c4ffb3b6aa0f 100644 (file)
@@ -23,6 +23,7 @@
 void Draw::Commands (Draw_Interpretor& theCommands)
 {
   Draw::BasicCommands(theCommands);
+  Draw::MessageCommands(theCommands);
   Draw::VariableCommands(theCommands);
   Draw::GraphicCommands(theCommands);
   Draw::PloadCommands(theCommands);
diff --git a/src/Draw/Draw_MessageCommands.cxx b/src/Draw/Draw_MessageCommands.cxx
new file mode 100644 (file)
index 0000000..d2dc6dc
--- /dev/null
@@ -0,0 +1,266 @@
+// Copyright (c) 2020 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <Draw.hxx>
+#include <Draw_Printer.hxx>
+
+#include <Message.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_PrinterOStream.hxx>
+#include <Message_PrinterSystemLog.hxx>
+#include <Message_PrinterToReport.hxx>
+#include <Message_Report.hxx>
+#include <Standard_Dump.hxx>
+
+//==============================================================================
+//function : printerType
+//purpose  :
+//==============================================================================
+Standard_Boolean printerType (const TCollection_AsciiString& theTypeName,
+                              Handle(Standard_Type)& theType)
+{
+  if (theTypeName == "ostream")
+  {
+    theType = STANDARD_TYPE(Message_PrinterOStream);
+  }
+  else if (theTypeName == "systemlog")
+  {
+    theType = STANDARD_TYPE(Message_PrinterSystemLog);
+  }
+  else if (theTypeName == "report")
+  {
+    theType = STANDARD_TYPE(Message_PrinterToReport);
+  }
+  else if (theTypeName == "draw")
+  {
+    theType = STANDARD_TYPE(Draw_Printer);
+  }
+  else
+    return Standard_False;
+
+  return Standard_True;
+}
+
+//==============================================================================
+//function : createPrinter
+//purpose  :
+//==============================================================================
+Handle(Message_Printer) createPrinter (const Handle(Standard_Type)& theType, Draw_Interpretor& theDI)
+{
+  const Standard_CString aTypeName = theType->Name();
+  if (aTypeName == STANDARD_TYPE(Message_PrinterOStream)->Name())
+  {
+    return new Message_PrinterOStream();
+  }
+  else if (aTypeName == STANDARD_TYPE(Message_PrinterSystemLog)->Name())
+  {
+    return new Message_PrinterSystemLog ("draw_messages");
+  }
+  else if (aTypeName == STANDARD_TYPE(Message_PrinterToReport)->Name())
+  {
+    Handle(Message_PrinterToReport) aMessagePrinter = new Message_PrinterToReport();
+    const Handle(Message_Report)& aReport = Message::DefaultReport (Standard_True);
+    aMessagePrinter->SetReport (aReport);
+    return aMessagePrinter;
+  }
+  else if (aTypeName == STANDARD_TYPE(Draw_Printer)->Name())
+  {
+    return new Draw_Printer (theDI);
+  }
+  return Handle(Message_Printer)();
+}
+
+//==============================================================================
+//function : SendMessage
+//purpose  :
+//==============================================================================
+static Standard_Integer SendMessage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
+{
+  if (theArgNb < 2)
+  {
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger();
+  Handle(Standard_Type) aPrinterType;
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    anArg.LowerCase();
+
+    aMessenger->Send (anArg);
+  }
+
+  return 0;
+}
+
+//==============================================================================
+//function : DumpMessenger
+//purpose  :
+//==============================================================================
+static Standard_Integer DumpMessenger (Draw_Interpretor& theDI, Standard_Integer, const char**)
+{
+  Standard_SStream aStream;
+  const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger();
+  aMessenger->DumpJson (aStream);
+
+  theDI << "Message_Messenger\n";
+  theDI << Standard_Dump::FormatJson (aStream);
+
+  return 0;
+}
+
+//==============================================================================
+//function : SetMessagePrinter
+//purpose  :
+//==============================================================================
+static Standard_Integer SetMessagePrinter (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
+{
+  if (theArgNb < 2)
+  {
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger();
+  Handle(Standard_Type) aPrinterType;
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    anArg.LowerCase();
+    if (anArg == "-clear")
+    {
+      aMessenger->ChangePrinters().Clear();
+    }
+    else if (anArg == "-type"
+          && anArgIter + 1 < theArgNb)
+    {
+      TCollection_AsciiString aVal (theArgVec[++anArgIter]);
+      if (!printerType (aVal, aPrinterType))
+      {
+        std::cout << "Syntax error: unknown printer type '" << aVal << "'\n";
+        return 1;
+      }
+      if (aMessenger->HasPrinter (aPrinterType))
+        continue;
+
+      aMessenger->AddPrinter (createPrinter (aPrinterType, theDI));
+    }
+    else
+    {
+      std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n";
+      return 1;
+    }
+  }
+  return 0;
+}
+
+//==============================================================================
+//function : SetReportMetric
+//purpose  :
+//==============================================================================
+static Standard_Integer SetReportMetric(Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
+{
+  if (theArgNb < 1)
+  {
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  const Handle(Message_Report)& aReport = Message::DefaultReport (Standard_True);
+  if (aReport.IsNull())
+    return 1;
+
+  aReport->ClearMetrics();
+  for (int i = 1; i < theArgNb; i++)
+  {
+    Standard_Integer aMetricId = Draw::Atoi (theArgVec[i]);
+    if (aMetricId < Message_MetricType_UserTimeCPU || aMetricId > Message_MetricType_MemHeapUsage)
+    {
+      std::cout << "Unrecognized message metric: " << aMetricId << std::endl;
+      return 1;
+    }
+    aReport->SetActiveMetric ((Message_MetricType)aMetricId, Standard_True);
+  }
+  return 0;
+}
+
+//==============================================================================
+//function : PrintReport
+//purpose  :
+//==============================================================================
+static Standard_Integer PrintReport(Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
+{
+  if (theArgNb < 1)
+  {
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  const Handle(Message_Report)& aReport = Message::DefaultReport (Standard_True);
+  if (aReport.IsNull())
+    return 1;
+
+  if (theArgNb > 1) // default messenger
+  {
+    aReport->SendMessages (Message::DefaultMessenger());
+  }
+  else // stream
+  {
+    Standard_SStream aSStream;
+    aReport->Dump (aSStream);
+    theDI << aSStream;
+  }
+
+  return 0;
+}
+
+void Draw::MessageCommands(Draw_Interpretor& theCommands)
+{
+  static Standard_Boolean Done = Standard_False;
+  if (Done) return;
+  Done = Standard_True;
+
+  std::ios::sync_with_stdio();
+
+  const char* group = "DRAW Message Commands";
+
+  theCommands.Add("SetMessagePrinter",
+    "SetMessagePrinter [-type ostream|systemlog|report|draw] [-clear]"
+    "\n\t\t: Sets printer into messenger or remove all printers."
+    "\n    : Option -type set type of printer. Printers are applyed with And combination."
+    "\n    : Option -clear remove all printers in messenger",
+    __FILE__, SetMessagePrinter, group);
+
+  theCommands.Add("DumpMessenger",
+    "DumpMessenger"
+    "\n Prints DumpJson information about Messenger.\n",
+    __FILE__, DumpMessenger, group);
+
+  theCommands.Add("SendMessage",
+    "SendMessage text [text ...]"
+    "\n Sends the text into the messenger.\n",
+    __FILE__, SendMessage, group);
+
+  theCommands.Add("SetReportMetric", "SetReportMetric [metric...] \n Activate report metrics, deactivate all if there are no parameters.\n",
+    __FILE__, SetReportMetric, group);
+
+  theCommands.Add("PrintReport", "PrintReport [messenger] \n Send report content to default messenger or stream (if parameter is absent).\n",
+    __FILE__, PrintReport, group);
+}
index 09e29e1e14b2fe5a93c3a424d55b17ce1d699d76..60fa08a3d9659668f757f79853463bf42610ce3a 100644 (file)
@@ -15,6 +15,7 @@
 
 
 #include <Draw_Printer.hxx>
+#include <Standard_Dump.hxx>
 #include <Standard_Type.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
@@ -95,3 +96,12 @@ void Draw_Printer::Send (const TCollection_AsciiString& theString,
     (*(Draw_Interpretor*)myTcl) << "\n";
   }
 }
+
+//=======================================================================
+//function : DumpJson
+//purpose  :
+//=======================================================================
+void Draw_Printer::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+  OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
index 2cd649bc2b18ac7c80457f69d0530f73d038d927..600c8b84364a67ded58304896903f104cf7a660f 100644 (file)
@@ -61,6 +61,8 @@ public:
   //! Default implementation calls first method Send().
   Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl) const Standard_OVERRIDE;
 
+  //! Dumps the content of me into the stream
+  Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
 
 
 
index c43b33613f43e599cdfcdedc133bb35de457df48..479b683ce97decccb9801c4d52044ce50138599a 100755 (executable)
@@ -43,6 +43,7 @@ Draw_Marker2D.hxx
 Draw_Marker3D.cxx
 Draw_Marker3D.hxx
 Draw_MarkerShape.hxx
+Draw_MessageCommands.cxx
 Draw_Number.cxx
 Draw_Number.hxx
 Draw_PInterp.hxx
index c2e2c71799d579279fda8b135968e49a8b2fd4dc..0fc4904be85377f01928fa156125ac016ca19ae1 100644 (file)
@@ -18,6 +18,8 @@
 #include <Message_Printer.hxx>
 #include <Message_PrinterOStream.hxx>
 
+#include <Standard_Dump.hxx>
+
 IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
 
 //=======================================================================
@@ -62,6 +64,23 @@ Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& t
   return Standard_True;
 }
 
+//=======================================================================
+//function : HasPrinters
+//purpose  : 
+//=======================================================================
+Standard_Boolean Message_Messenger::HasPrinter (const Handle(Standard_Type)& theType)
+{
+  for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More();)
+  {
+    const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+    if (!aPrinter.IsNull() && aPrinter->IsKind (theType))
+    {
+      return Standard_True;
+    }
+  }
+  return Standard_False;
+}
+
 //=======================================================================
 //function : RemovePrinter
 //purpose  : 
@@ -201,3 +220,22 @@ void Message_Messenger::Send (const Handle(Standard_Transient)& theObject,
     }
   }
 }
+
+//=======================================================================
+//function : DumpJson
+//purpose  :
+//=======================================================================
+void Message_Messenger::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
+{
+  OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+
+  for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
+  {
+    const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+    if (aPrinter.IsNull())
+      continue;
+    OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aPrinter.get())
+  }
+
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOutputGravity)
+}
index 398c92792f51173d115a3ae992d999d6064878f7..a48ca1a01b67834700b847f4a797ecd25a958f33 100644 (file)
@@ -67,6 +67,9 @@ public:
   //! Returns True if printer has been added.
   Standard_EXPORT Standard_Boolean AddPrinter (const Handle(Message_Printer)& thePrinter);
   
+  //! Returns true if messenger printers contain a printer of specified type (including derived classes) 
+  Standard_EXPORT Standard_Boolean HasPrinter (const Handle(Standard_Type)& theType);
+
   //! Removes specified printer from the messenger.
   //! Returns True if this printer has been found in the list
   //! and removed.
@@ -76,7 +79,7 @@ public:
   //! from the messenger.
   //! Returns number of removed printers.
   Standard_EXPORT Standard_Integer RemovePrinters (const Handle(Standard_Type)& theType);
-  
+
   //! Returns current sequence of printers
   const Message_SequenceOfPrinters& Printers() const { return myPrinters; }
 
@@ -110,6 +113,9 @@ public:
   //! See above
   Standard_EXPORT void Send (const Handle(Standard_Transient)& theObject, const Message_Gravity theGravity = Message_Warning, const Standard_Boolean putEndl = Standard_True) const;
 
+  //! Dumps the content of me into the stream
+  Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
+
 private:
 
   Message_SequenceOfPrinters myPrinters;
index cc1c09878d8beb2b94f0270446f4daad9be5de0a..85c18291b88b0e506824737f9bab685f19dec84c 100644 (file)
@@ -93,3 +93,12 @@ void Message_Printer::Send (const Handle(Standard_Transient)& theObject,
     Send (aString, theGravity, theToOutEol);
   }
 }
+
+//=======================================================================
+//function : DumpJson
+//purpose  :
+//=======================================================================
+void Message_Printer::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+  OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
index ae877c7081efcf803b460640225c2e8ac6321626..965454998d6da603a765ff62d5cff7f6cb0b56ac 100644 (file)
@@ -76,6 +76,9 @@ public:
   //! Default implementation calls first method Send().
   Standard_EXPORT virtual void Send (const Handle(Standard_Transient)& theObject, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const;
 
+  //! Dumps the content of me into the stream
+  Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
+
 protected:
 
   //! Empty constructor with Message_Info trace level
index e28b23909b603fc0a05dd310edee0942bc543b67..4220826e073b106f8b90afe340e01a9c1078f7c7 100644 (file)
@@ -20,6 +20,7 @@
 #include <Message_PrinterOStream.hxx>
 
 #include <OSD_OpenFile.hxx>
+#include <Standard_Dump.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
 
@@ -283,3 +284,12 @@ void Message_PrinterOStream::SetConsoleTextColor (Standard_OStream* theOStream,
   *theOStream << aCode;
 #endif
 }
+
+//=======================================================================
+//function : DumpJson
+//purpose  :
+//=======================================================================
+void Message_PrinterOStream::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+  OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
index 163a2ac0ced277c0ef21e3c41e4c3846293bdbe0..fe2b2055bb1b33ecb95989450c6c43fa5b471181 100644 (file)
@@ -97,6 +97,9 @@ public:
   //! option is set, else replaced by symbols '?'
   Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
 
+  //! Dumps the content of me into the stream
+  Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
+
 private:
 
   Standard_Address myStream;
index 8d2be63398f1c3967854e7c35597724a32e54036..2900c2b9a79ab5dcde03aa406e413099879ea554 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <Message_PrinterSystemLog.hxx>
 
+#include <Standard_Dump.hxx>
 #include <TCollection_ExtendedString.hxx>
 
 #if defined(OCCT_UWP)
@@ -188,3 +189,12 @@ void Message_PrinterSystemLog::Send (const TCollection_ExtendedString& theString
   Send (TCollection_AsciiString (theString), theGravity, true);
 #endif
 }
+
+//=======================================================================
+//function : DumpJson
+//purpose  :
+//=======================================================================
+void Message_PrinterSystemLog::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+  OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
index 309a48a250041ae2d082a791f147326986b0e786..68a0b32ea939f608a58e3ceaaef56256281b91bd 100644 (file)
@@ -51,6 +51,9 @@ public:
                                      const Message_Gravity theGravity,
                                      const Standard_Boolean theToPutEndl) const Standard_OVERRIDE;
 
+  //! Dumps the content of me into the stream
+  Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
+
 private:
 
   TCollection_AsciiString myEventSourceName;
index a36885f07a7f83b2b6058c1949de0de69181a2f3..bdd35f2686c6441c725f49f93ab44eb4165fc662 100644 (file)
@@ -117,3 +117,12 @@ void Message_PrinterToReport::sendMetricAlert (const TCollection_AsciiString the
   Message_AlertExtended::AddAlert (Report(), new Message_AttributeMeter (theValue), theGravity);
   ((Message_PrinterToReport*)this)->Clear();
 }
+
+//=======================================================================
+//function : DumpJson
+//purpose  :
+//=======================================================================
+void Message_PrinterToReport::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+  OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
index 8de68321e5e7d1b299fa2915915025168f95c23b..27d45ae1f40674320c431a7b32efd44b3f78bd82 100644 (file)
@@ -71,6 +71,9 @@ public:
   Standard_EXPORT virtual void Send (const Handle(Standard_Transient)& theObject,
                                      const Message_Gravity theGravity,
                                      const Standard_Boolean theToPutEol) const Standard_OVERRIDE;
+  //! Dumps the content of me into the stream
+  Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
+
 protected:
 
   //! Send an alert with metrics active in the current report
index 2abde3880880be88f1de371a87b653e53ade3e5b..cf51ba0b1f4dd2b072d0f4b58caf89e88008d68d 100644 (file)
@@ -44,7 +44,6 @@
 // function : GetApplication
 // purpose :
 // =======================================================================
-
 const Handle(TDocStd_Application)& GetApplication()
 {
   static Handle(TDocStd_Application) anApp;
@@ -60,12 +59,11 @@ const Handle(TDocStd_Application)& GetApplication()
 // function : ExportReport
 // purpose :
 // =======================================================================
-
-void XmlDrivers_MessageReportStorage::ExportReport (const Handle(Message_Report)& theReport,
-                                                    const TCollection_AsciiString& theFileName)
+Standard_Boolean XmlDrivers_MessageReportStorage::ExportReport (const Handle(Message_Report)& theReport,
+                                                                const TCollection_AsciiString& theFileName)
 {
   if (theReport.IsNull())
-    return;
+    return Standard_False;
 
   Handle(TDocStd_Document) aDocument;
   GetApplication()->NewDocument (TCollection_ExtendedString ("XmlOcaf"), aDocument);
@@ -95,16 +93,19 @@ void XmlDrivers_MessageReportStorage::ExportReport (const Handle(Message_Report)
       exportAlert (anAlertsIt.Value(), aGravityLabel);
     }
   }
-  GetApplication()->SaveAs (aDocument, theFileName);
+  if (GetApplication()->SaveAs (aDocument, theFileName) != PCDM_SS_OK)
+    return Standard_False;
+
   GetApplication()->Close (aDocument);
+  return Standard_True;
 }
 
 // =======================================================================
 // function : ImportReport
 // purpose :
 // =======================================================================
-
-Handle(Message_Report) XmlDrivers_MessageReportStorage::ImportReport (const TCollection_AsciiString& theFileName)
+Standard_Boolean XmlDrivers_MessageReportStorage::ImportReport (const Handle(Message_Report)& theReport,
+                                                                const TCollection_AsciiString& theFileName)
 {
   Handle(TDocStd_Application) anApplication = GetApplication();
   Standard_Integer aDocumentId = anApplication->IsInSession (theFileName);
@@ -118,14 +119,13 @@ Handle(Message_Report) XmlDrivers_MessageReportStorage::ImportReport (const TCol
   Handle(TDocStd_Document) aDocument;
   GetApplication()->Open (theFileName, aDocument);
   if (aDocument.IsNull())
-    return Handle(Message_Report)();
+    return Standard_False;
 
   TDF_Label aMainLabel = aDocument->Main();
   if (aMainLabel.IsNull())
-    return Handle(Message_Report)();
+    return Standard_False;
 
   TDF_Label aLabel;
-  Handle(Message_Report) aReport = new Message_Report();
   for (TDF_ChildIterator aLabelsIt(aMainLabel); aLabelsIt.More(); aLabelsIt.Next())
   {
     TDF_Label aGravityLabel = aLabelsIt.Value();
@@ -152,17 +152,16 @@ Handle(Message_Report) XmlDrivers_MessageReportStorage::ImportReport (const TCol
       if (anAlertLabel.IsNull())
         continue;
 
-      importAlert (anAlertLabel, aGravity, aReport, Handle(Message_Alert)());
+      importAlert (anAlertLabel, aGravity, theReport, Handle(Message_Alert)());
     }
   }
-  return aReport;
+  return Standard_True;
 }
 
 // =======================================================================
 // function : exportAlert
 // purpose :
 // =======================================================================
 void XmlDrivers_MessageReportStorage::exportAlert (const Handle(Message_Alert)& theAlert, const TDF_Label& theParentLabel)
 {
    TDF_Label anAlertLabel = theParentLabel.NewChild();
@@ -196,10 +195,9 @@ void XmlDrivers_MessageReportStorage::exportAlert (const Handle(Message_Alert)&
 // function : importAlert
 // purpose :
 // =======================================================================
-
 void XmlDrivers_MessageReportStorage::importAlert (const TDF_Label& theAlertLabel,
                                                    const Message_Gravity theGravity,
-                                                   Handle(Message_Report)& theReport,
+                                                   const Handle(Message_Report)& theReport,
                                                    const Handle(Message_Alert)& theParentAlert)
 {
   TDF_Label aParametersLabel = theAlertLabel.FindChild (1, Standard_False);
index 81e1db8f9cdf860bdf0c0c2b9616aefc1631881c..048a51ed9ac0318b54b7545676415c1d5d781725 100644 (file)
 class XmlDrivers_MessageReportStorage
 {
 public:
-  //! Create document for the report
+  //! Stores the report into a file. The file format is an XML document.
   //! \param theReport the source report
   //! \param theFileName a file name
-  Standard_EXPORT static void ExportReport (const Handle(Message_Report)& theReport, const TCollection_AsciiString& theFileName);
+  //! \return true if success
+  Standard_EXPORT static Standard_Boolean ExportReport (const Handle(Message_Report)& theReport,
+                                                        const TCollection_AsciiString& theFileName);
 
-  //! Restores document file content into report instance
+  //! Restores the report from the file. The file format should be an XML document.
+  //! \return theReport the report to get the file content
   //! \param theFileName a file name
-  //! \return new report or NULL
-  Standard_EXPORT static Handle(Message_Report) ImportReport (const TCollection_AsciiString& theFileName);
+  //! \return true if success
+  Standard_EXPORT static Standard_Boolean ImportReport (const Handle(Message_Report)& theReport,
+                                                        const TCollection_AsciiString& theFileName);
 
 private:
   //! Create labels/attributes for the alert and place it under the parent label.
@@ -50,14 +54,13 @@ private:
   //! \param theParentAlert a parent alert, if null, the parent is report
   static void importAlert (const TDF_Label& theAlertLabel,
                            const Message_Gravity theGravity,
-                           Handle(Message_Report)& theReport,
+                           const Handle(Message_Report)& theReport,
                            const Handle(Message_Alert)& theParentAlert);
 
   //! Convert alert to a custom type and store parameters in child labels and attributes
   //! \param theAlert a source alert
   //! \parm theAlertLabel an alert label
-  static void exportAlertParameters (const Handle(Message_Alert)& theAlert,
-                                     const TDF_Label& theAlertLabel);
+  static void exportAlertParameters (const Handle(Message_Alert)& theAlert, const TDF_Label& theAlertLabel);
 
   //! Creates alert by label type filled by the label content
   //! \param theParametersLabel a label
@@ -65,10 +68,16 @@ private:
   static Handle(Message_Alert) importAlertParameters (const TDF_Label& aParametersLabel);
 };
 
-#define MESSAGE_STORE_XML_REPORT(FileName) \
+#define MESSAGE_REPORT_EXPORT(FileName) \
 { \
   Handle(Message_Report) aReport = Message::DefaultReport (Standard_False); \
   if (!aReport.IsNull()) XmlDrivers_MessageReportStorage::ExportReport (aReport, FileName); \
 }
 
+#define MESSAGE_REPORT_IMPORT(FileName) \
+{ \
+  Handle(Message_Report) aReport = Message::DefaultReport (Standard_True); \
+  if (!aReport.IsNull()) XmlDrivers_MessageReportStorage::ImportReport (aReport, FileName); \
+}
+
 #endif // _XmlDrivers_MessageReportStorage
diff --git a/tests/basic/begin b/tests/basic/begin
new file mode 100644 (file)
index 0000000..a9dadf8
--- /dev/null
@@ -0,0 +1,6 @@
+if { [info exists imagedir] == 0 } {
+   set imagedir .
+}
+if { [info exists test_image ] == 0 } {
+   set test_image photo
+}
diff --git a/tests/basic/end b/tests/basic/end
new file mode 100644 (file)
index 0000000..504ad59
--- /dev/null
@@ -0,0 +1,2 @@
+# File : end
+puts "TEST COMPLETED"
diff --git a/tests/basic/grids.list b/tests/basic/grids.list
new file mode 100644 (file)
index 0000000..fea9d46
--- /dev/null
@@ -0,0 +1 @@
+001 message
diff --git a/tests/basic/message/messenger b/tests/basic/message/messenger
new file mode 100644 (file)
index 0000000..94a7e47
--- /dev/null
@@ -0,0 +1,16 @@
+puts "=================================="
+puts ""
+puts "=================================="
+
+#ostream printer
+SetMessagePrinter -type ostream
+DumpMessenger
+SendMessage "processing a text message in ostream" "information message" "error message" "warning message"
+
+#report printer
+SetMessagePrinter -clear
+SetMessagePrinter -type report
+DumpMessenger
+SendMessage "processing a text message in report" "information message" "error message" "warning message"
+
+#WriteMessageReport d:/tmp.xml
diff --git a/tests/basic/parse.rules b/tests/basic/parse.rules
new file mode 100644 (file)
index 0000000..bca616b
--- /dev/null
@@ -0,0 +1,3 @@
+FAILED /\bFaulty\b/ bad shape
+IGNORE /^Tcl Exception: tolerance ang : [\d.-]+/ blend failure - test will be failed as incomplete
+OK /Relative error of mass computation/ message from vprops
\ No newline at end of file