From: nds Date: Sat, 22 Feb 2020 05:51:43 +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=53635357bcf4b326fc9e05332fc6c2578237417d;p=occt-copy.git 0029451: Information Message Alert to debug an algorithm or object functionality review corrections --- diff --git a/src/DDocStd/DDocStd_ToolsCommands.cxx b/src/DDocStd/DDocStd_ToolsCommands.cxx index d31e9e0440..27fd52563a 100644 --- a/src/DDocStd/DDocStd_ToolsCommands.cxx +++ b/src/DDocStd/DDocStd_ToolsCommands.cxx @@ -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); } - diff --git a/src/Draw/Draw.cxx b/src/Draw/Draw.cxx index 0f83347638..937ae34d6e 100644 --- a/src/Draw/Draw.cxx +++ b/src/Draw/Draw.cxx @@ -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); diff --git a/src/Draw/Draw.hxx b/src/Draw/Draw.hxx index e718316461..3f0f1457e4 100644 --- a/src/Draw/Draw.hxx +++ b/src/Draw/Draw.hxx @@ -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); diff --git a/src/Draw/Draw_BasicCommands.cxx b/src/Draw/Draw_BasicCommands.cxx index 8ccfa00934..7943efc645 100644 --- a/src/Draw/Draw_BasicCommands.cxx +++ b/src/Draw/Draw_BasicCommands.cxx @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -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]" diff --git a/src/Draw/Draw_Commands.cxx b/src/Draw/Draw_Commands.cxx index c375f9eeda..cf291fb080 100644 --- a/src/Draw/Draw_Commands.cxx +++ b/src/Draw/Draw_Commands.cxx @@ -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 index 0000000000..d2dc6dc1e3 --- /dev/null +++ b/src/Draw/Draw_MessageCommands.cxx @@ -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 +#include + +#include +#include +#include +#include +#include +#include +#include + +//============================================================================== +//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); +} diff --git a/src/Draw/Draw_Printer.cxx b/src/Draw/Draw_Printer.cxx index 09e29e1e14..60fa08a3d9 100644 --- a/src/Draw/Draw_Printer.cxx +++ b/src/Draw/Draw_Printer.cxx @@ -15,6 +15,7 @@ #include +#include #include #include #include @@ -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) +} diff --git a/src/Draw/Draw_Printer.hxx b/src/Draw/Draw_Printer.hxx index 2cd649bc2b..600c8b8436 100644 --- a/src/Draw/Draw_Printer.hxx +++ b/src/Draw/Draw_Printer.hxx @@ -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; diff --git a/src/Draw/FILES b/src/Draw/FILES index c43b33613f..479b683ce9 100755 --- a/src/Draw/FILES +++ b/src/Draw/FILES @@ -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 diff --git a/src/Message/Message_Messenger.cxx b/src/Message/Message_Messenger.cxx index c2e2c71799..0fc4904be8 100644 --- a/src/Message/Message_Messenger.cxx +++ b/src/Message/Message_Messenger.cxx @@ -18,6 +18,8 @@ #include #include +#include + 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) +} diff --git a/src/Message/Message_Messenger.hxx b/src/Message/Message_Messenger.hxx index 398c92792f..a48ca1a01b 100644 --- a/src/Message/Message_Messenger.hxx +++ b/src/Message/Message_Messenger.hxx @@ -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; diff --git a/src/Message/Message_Printer.cxx b/src/Message/Message_Printer.cxx index cc1c09878d..85c18291b8 100644 --- a/src/Message/Message_Printer.cxx +++ b/src/Message/Message_Printer.cxx @@ -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) +} diff --git a/src/Message/Message_Printer.hxx b/src/Message/Message_Printer.hxx index ae877c7081..965454998d 100644 --- a/src/Message/Message_Printer.hxx +++ b/src/Message/Message_Printer.hxx @@ -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 diff --git a/src/Message/Message_PrinterOStream.cxx b/src/Message/Message_PrinterOStream.cxx index e28b23909b..4220826e07 100644 --- a/src/Message/Message_PrinterOStream.cxx +++ b/src/Message/Message_PrinterOStream.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -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) +} diff --git a/src/Message/Message_PrinterOStream.hxx b/src/Message/Message_PrinterOStream.hxx index 163a2ac0ce..fe2b2055bb 100644 --- a/src/Message/Message_PrinterOStream.hxx +++ b/src/Message/Message_PrinterOStream.hxx @@ -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; diff --git a/src/Message/Message_PrinterSystemLog.cxx b/src/Message/Message_PrinterSystemLog.cxx index 8d2be63398..2900c2b9a7 100644 --- a/src/Message/Message_PrinterSystemLog.cxx +++ b/src/Message/Message_PrinterSystemLog.cxx @@ -17,6 +17,7 @@ #include +#include #include #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) +} diff --git a/src/Message/Message_PrinterSystemLog.hxx b/src/Message/Message_PrinterSystemLog.hxx index 309a48a250..68a0b32ea9 100644 --- a/src/Message/Message_PrinterSystemLog.hxx +++ b/src/Message/Message_PrinterSystemLog.hxx @@ -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; diff --git a/src/Message/Message_PrinterToReport.cxx b/src/Message/Message_PrinterToReport.cxx index a36885f07a..bdd35f2686 100644 --- a/src/Message/Message_PrinterToReport.cxx +++ b/src/Message/Message_PrinterToReport.cxx @@ -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) +} diff --git a/src/Message/Message_PrinterToReport.hxx b/src/Message/Message_PrinterToReport.hxx index 8de68321e5..27d45ae1f4 100644 --- a/src/Message/Message_PrinterToReport.hxx +++ b/src/Message/Message_PrinterToReport.hxx @@ -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 diff --git a/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx b/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx index 2abde38808..cf51ba0b1f 100644 --- a/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx +++ b/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx @@ -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); diff --git a/src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx b/src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx index 81e1db8f9c..048a51ed9a 100644 --- a/src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx +++ b/src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx @@ -26,15 +26,19 @@ 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 index 0000000000..a9dadf81c4 --- /dev/null +++ b/tests/basic/begin @@ -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 index 0000000000..504ad5983c --- /dev/null +++ b/tests/basic/end @@ -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 index 0000000000..fea9d466f3 --- /dev/null +++ b/tests/basic/grids.list @@ -0,0 +1 @@ +001 message diff --git a/tests/basic/message/messenger b/tests/basic/message/messenger new file mode 100644 index 0000000000..94a7e4717d --- /dev/null +++ b/tests/basic/message/messenger @@ -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 index 0000000000..bca616b06f --- /dev/null +++ b/tests/basic/parse.rules @@ -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