}
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;
}
"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);
}
-
// standard commands
// *****************************************************************
Draw::BasicCommands(theCommands);
+ Draw::MessageCommands(theCommands);
Draw::VariableCommands(theCommands);
Draw::UnitCommands(theCommands);
if (!Draw_Batch) Draw::GraphicCommands(theCommands);
//! 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);
#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>
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 :
__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]"
void Draw::Commands (Draw_Interpretor& theCommands)
{
Draw::BasicCommands(theCommands);
+ Draw::MessageCommands(theCommands);
Draw::VariableCommands(theCommands);
Draw::GraphicCommands(theCommands);
Draw::PloadCommands(theCommands);
--- /dev/null
+// 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);
+}
#include <Draw_Printer.hxx>
+#include <Standard_Dump.hxx>
#include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
(*(Draw_Interpretor*)myTcl) << "\n";
}
}
+
+//=======================================================================
+//function : DumpJson
+//purpose :
+//=======================================================================
+void Draw_Printer::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+ OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
//! 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;
Draw_Marker3D.cxx
Draw_Marker3D.hxx
Draw_MarkerShape.hxx
+Draw_MessageCommands.cxx
Draw_Number.cxx
Draw_Number.hxx
Draw_PInterp.hxx
#include <Message_Printer.hxx>
#include <Message_PrinterOStream.hxx>
+#include <Standard_Dump.hxx>
+
IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
//=======================================================================
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 :
}
}
}
+
+//=======================================================================
+//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)
+}
//! 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.
//! 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; }
//! 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;
Send (aString, theGravity, theToOutEol);
}
}
+
+//=======================================================================
+//function : DumpJson
+//purpose :
+//=======================================================================
+void Message_Printer::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+ OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
//! 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
#include <Message_PrinterOStream.hxx>
#include <OSD_OpenFile.hxx>
+#include <Standard_Dump.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
*theOStream << aCode;
#endif
}
+
+//=======================================================================
+//function : DumpJson
+//purpose :
+//=======================================================================
+void Message_PrinterOStream::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+ OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
//! 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;
#include <Message_PrinterSystemLog.hxx>
+#include <Standard_Dump.hxx>
#include <TCollection_ExtendedString.hxx>
#if defined(OCCT_UWP)
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)
+}
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;
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)
+}
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
// function : GetApplication
// purpose :
// =======================================================================
-
const Handle(TDocStd_Application)& GetApplication()
{
static Handle(TDocStd_Application) anApp;
// 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);
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);
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();
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();
// 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);
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.
//! \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
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
--- /dev/null
+if { [info exists imagedir] == 0 } {
+ set imagedir .
+}
+if { [info exists test_image ] == 0 } {
+ set test_image photo
+}
--- /dev/null
+# File : end
+puts "TEST COMPLETED"
--- /dev/null
+001 message
--- /dev/null
+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
--- /dev/null
+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