From 0ae2551ead0539735864d9ad52758844ca4541b4 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 6 Nov 2020 18:40:22 +0300 Subject: [PATCH] 0031362: Inspectors - MessageView plugin for message alerts - avoid '\n' in json report, Unique name of composite alerts (cherry picked from commit c2c6db031c23578c4ca5403fd4ecc1ece8758886) --- src/Message/Message_CompositeAlerts.cxx | 5 +---- src/Message/Message_Report.cxx | 3 ++- src/Standard/Standard_Dump.cxx | 4 ++++ src/Standard/Standard_Dump.hxx | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Message/Message_CompositeAlerts.cxx b/src/Message/Message_CompositeAlerts.cxx index e0a9cafca9..5c1a267ea3 100644 --- a/src/Message/Message_CompositeAlerts.cxx +++ b/src/Message/Message_CompositeAlerts.cxx @@ -169,15 +169,12 @@ void Message_CompositeAlerts::DumpJson (Standard_OStream& theOStream, { OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) + Standard_Integer anInc = 1; for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i) { if (myAlerts[i].IsEmpty()) continue; - Message_Gravity aGravity = (Message_Gravity)i; - OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aGravity) - - Standard_Integer anInc = 1; for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); anIt.Next(), anInc++) { const Handle(Message_Alert)& anAlert = anIt.Value(); diff --git a/src/Message/Message_Report.cxx b/src/Message/Message_Report.cxx index 3a88c7bdd5..4c09657ffb 100644 --- a/src/Message/Message_Report.cxx +++ b/src/Message/Message_Report.cxx @@ -479,10 +479,11 @@ void Message_Report::DumpJson (Standard_OStream& theOStream, Standard_Integer th Standard_Integer anAlertLevels = myAlertLevels.Size(); OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, anAlertLevels) + Standard_Integer anInc = 1; for (NCollection_IndexedMap::Iterator anIterator (myActiveMetrics); anIterator.More(); anIterator.Next()) { Message_MetricType anActiveMetric = anIterator.Value(); - OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, anActiveMetric) + OCCT_DUMP_FIELD_VALUE_NUMERICAL_INC (theOStream, anActiveMetric, anInc++) } OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myLimit) diff --git a/src/Standard/Standard_Dump.cxx b/src/Standard/Standard_Dump.cxx index c065dab3dd..3bdc2f55d5 100644 --- a/src/Standard/Standard_Dump.cxx +++ b/src/Standard/Standard_Dump.cxx @@ -384,6 +384,10 @@ TCollection_AsciiString Standard_Dump::FormatJson (const Standard_SStream& theSt else aText += aSymbol; } + else if (aSymbol == '\n') + { + aText += ""; // json does not support multi-lined values, skip this symbol + } else aText += aSymbol; diff --git a/src/Standard/Standard_Dump.hxx b/src/Standard/Standard_Dump.hxx index fffedf4ffd..a84ec5a532 100644 --- a/src/Standard/Standard_Dump.hxx +++ b/src/Standard/Standard_Dump.hxx @@ -74,6 +74,15 @@ class Standard_DumpSentry; theOStream << "\"" << aName << "\": " << theField; \ } +//! @def OCCT_DUMP_FIELD_VALUE_NUMERICAL +//! Append into output value: "Name": Field +#define OCCT_DUMP_FIELD_VALUE_NUMERICAL_INC(theOStream, theField, theIncName) \ +{ \ + TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (#theField) + theIncName; \ + Standard_Dump::AddValuesSeparator (theOStream); \ + theOStream << "\"" << aName << "\": " << theField; \ +} + //! @def OCCT_INIT_FIELD_VALUE_NUMERICAL //! Append vector values into output value: "Name": [value_1, value_2, ...] //! This macro is intended to have only one row for dumped object in Json. -- 2.39.5