]> OCCT Git - occt-copy.git/commitdiff
0031362: Inspectors - MessageView plugin for message alerts
authornds <nds@opencascade.com>
Thu, 8 Oct 2020 09:27:06 +0000 (12:27 +0300)
committernds <nds@opencascade.com>
Mon, 12 Oct 2020 08:49:23 +0000 (11:49 +0300)
DumpJson correction

src/Message/Message_AttributeMeter.cxx
src/Message/Message_AttributeStream.cxx
src/Message/Message_CompositeAlerts.cxx
src/Standard/Standard_Dump.cxx
src/Standard/Standard_Dump.hxx

index 27c386f8bdd791bf97abac5e90cf20b9e36e8d5b..52608d7085efc944a985b5d90ad13ede1fde071b 100644 (file)
@@ -188,13 +188,7 @@ void Message_AttributeMeter::DumpJson (Standard_OStream& theOStream,
   for (NCollection_DataMap<Message_MetricType, StartToStopValue>::Iterator anIterator (myMetrics);
        anIterator.More(); anIterator.Next())
   {
-    Message_MetricType aMetricType = anIterator.Key();
-    OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aMetricType)
-
-    Standard_Real aStartValue = anIterator.Value().first;
-    OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aStartValue)
-
-    Standard_Real aStopValue = anIterator.Value().second;
-    OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aStopValue)
+    OCCT_DUMP_VECTOR_CLASS (theOStream, Message::MetricToString (anIterator.Key()),
+                            2, anIterator.Value().first, anIterator.Value().second)
   }
 }
index 0236296b9c3ba49709dcb4a7a30c0767b1690b43..72abd8689074d5cca308b0baaceffd81e8534830 100644 (file)
@@ -50,6 +50,5 @@ void Message_AttributeStream::DumpJson (Standard_OStream& theOStream,
   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Message_Attribute)
 
-  TCollection_AsciiString aStream = Standard_Dump::Text (myStream);
-  OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aStream)
+  OCCT_DUMP_STREAM_VALUE_DUMPED (theOStream, myStream)
 }
index 9c25f226cf5ca537d4a8594c61f74ed19c7f434b..5d315f3e8cf9beed6403c62a4ca9cf6a07a6cf6a 100644 (file)
@@ -166,13 +166,17 @@ void Message_CompositeAlerts::DumpJson (Standard_OStream& theOStream,
 
   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)
 
-    for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); anIt.Next())
+    Standard_Integer anInc = 1;
+    for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); anIt.Next(), anInc++)
     {
       const Handle(Message_Alert)& anAlert = anIt.Value();
-      OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anAlert.get())
+      OCCT_DUMP_FIELD_VALUES_DUMPED_INC (theOStream, theDepth, anAlert.get(), anInc)
     }
   }
 }
index 4f030678dc18ae99fa4bd5cf5d138888dc4cca5f..a56292f912f93f754d99d7a9d26f16b7d269d07d 100644 (file)
@@ -24,7 +24,7 @@ void Standard_Dump::AddValuesSeparator (Standard_OStream& theOStream)
   Standard_SStream aStream;
   aStream << theOStream.rdbuf();
   TCollection_AsciiString aStreamStr = Standard_Dump::Text (aStream);
-  if (!aStreamStr.IsEmpty() && !aStreamStr.EndsWith ("{"))
+  if (!aStreamStr.IsEmpty() && !aStreamStr.EndsWith ("{") && !aStreamStr.EndsWith (", "))
     theOStream << ", ";
 }
 
@@ -306,9 +306,15 @@ TCollection_AsciiString Standard_Dump::FormatJson (const Standard_SStream& theSt
 
   Standard_Integer anIndentCount = 0;
   Standard_Boolean isMassiveValues = Standard_False;
-  for (Standard_Integer anIndex = 1; anIndex < aStreamStr.Length(); anIndex++)
+  for (Standard_Integer anIndex = 1; anIndex <= aStreamStr.Length(); anIndex++)
   {
     Standard_Character aSymbol = aStreamStr.Value (anIndex);
+    if (anIndex == 1 && aText.IsEmpty() && aSymbol != '{')
+    {
+      // append opening brace for json start
+      aSymbol = '{';
+      anIndex--;
+    }
     if (aSymbol == '{')
     {
       anIndentCount++;
@@ -354,6 +360,18 @@ TCollection_AsciiString Standard_Dump::FormatJson (const Standard_SStream& theSt
     }
     else
       aText += aSymbol;
+  
+    if (anIndex == aStreamStr.Length() && aSymbol != '}')
+    {
+      // append closing brace for json end
+      aSymbol = '}';
+
+      anIndentCount--;
+      aText += '\n';
+      for (int anIndent = 0; anIndent < anIndentCount; anIndent++)
+        aText += anIndentStr;
+      aText += aSymbol;
+    }
   }
   return aText;
 }
index 846c9cb001ac2c752e41345f85fc92aac98ca479..e0333c03e457c76a47dc2d7de5e1af4d74bdecbf 100644 (file)
   } \
 }
 
+//! @def OCCT_DUMP_FIELD_VALUES_DUMPED
+//! Append into output value: "Name": { field dumped values }
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for fields of the dumped class which has own Dump implementation.
+//! The macros is recursive. Recursion is stopped when the depth value becomes equal to zero.
+//! Depth = -1 is the default value, dump here is unlimited.
+#define OCCT_DUMP_FIELD_VALUES_DUMPED_INC(theOStream, theDepth, theField, theIncName) \
+{ \
+  if (theDepth != 0 && (void*)(theField) != NULL) \
+  { \
+    Standard_SStream aFieldStream; \
+    (theField)->DumpJson (aFieldStream, theDepth - 1); \
+    TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (#theField) + theIncName; \
+    Standard_Dump::DumpKeyToClass (theOStream, aName, Standard_Dump::Text (aFieldStream)); \
+  } \
+}
+
+//! @def OCCT_DUMP_FIELD_VALUES_DUMPED
+//! Append into output value: "Name": { field dumped values }
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for fields of the dumped class which has own Dump implementation.
+//! The macros is recursive. Recursion is stopped when the depth value becomes equal to zero.
+//! Depth = -1 is the default value, dump here is unlimited.
+#define OCCT_DUMP_STREAM_VALUE_DUMPED(theOStream, theField) \
+{ \
+  TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (#theField); \
+  Standard_Dump::DumpKeyToClass (theOStream, aName, Standard_Dump::Text (theField)); \
+}
+
 //! @def OCCT_INIT_FIELD_VALUES_DUMPED
 //! Append into output value: "Name": { field dumped values }
 //! It computes Dump of the fields. The expected field is a pointer.
@@ -267,6 +296,7 @@ public:
   //! - for '{' append after '\n' and indent to the next value, increment current indent value
   //! - for '}' append '\n' and current indent before it, decrement indent value
   //! - for ',' append after '\n' and indent to the next value. If the current symbol is in massive container [], do nothing
+  //! Covers result with opened and closed brackets on the top level, if it has no symbols there.
   //! @param theStream source value
   //! @param theIndent count of ' ' symbols to apply hierarchical indent of the text values
   //! @return text presentation