-TModelingData TKShapeView
+TModelingData TKShapeView TKMessageModel TKMessageView
TVisualization TKView TKVInspector
TApplicationFramework TKTreeModel TKTInspectorAPI TKDFBrowser
TTool TKTInspector TKToolsDraw TInspectorEXE
\ No newline at end of file
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
+#include <Message.hxx>
#include <TDocStd_Document.hxx>
#include <TDF_Label.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_ListIteratorOfAttributeDeltaList.hxx>
#include <Standard_DomainError.hxx>
+#include <XmlDrivers_MessageReportStorage.hxx>
//=======================================================================
}
return 0;
}
- di << "TDocStd_DumpCommand : Error\n";
+ std::cerr << "TDocStd_DumpCommand : Error\n";
return 1;
}
+//=======================================================================
+//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;
+ }
+
+ Handle(Message_ReportWriter) aWriter = aReport->MessageWriter();
+ if (aWriter.IsNull())
+ {
+ aWriter = new XmlDrivers_MessageReportStorage();
+ aWriter->SetFileName (aFileName);
+ aReport->SetMessageWriter (aWriter);
+ }
+
+ if (!aWriter->ImportReport (aReport))
+ {
+ std::cerr << "Error: Message_Report can not be exported in " << aFileName << ".\n";
+ return 0;
+ }
+ return 0;
+}
+
+//=======================================================================
+//function : DDocStd_WriteMessageReport
+//=======================================================================
+static Standard_Integer DDocStd_WriteMessageReport (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;
+ }
+
+ Handle(Message_ReportWriter) aWriter = aReport->MessageWriter();
+ if (aWriter.IsNull())
+ {
+ aWriter = new XmlDrivers_MessageReportStorage();
+ aWriter->SetFileName (aFileName);
+ aReport->SetMessageWriter (aWriter);
+ }
+
+ if (!aWriter->ExportReport (aReport))
+ {
+ std::cerr << "Error: Message_Report can not be exported in " << aFileName << ".\n";
+ return 0;
+ }
+ return 0;
+}
//=======================================================================
//function : ModificationCommands
"DumpCommand (DOC)",
__FILE__, DDocStd_DumpCommand, 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);
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 <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
*myTcl << theString << "\n";
}
+
+//=======================================================================
+//function : DumpJson
+//purpose :
+//=======================================================================
+void Draw_Printer::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+ OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
//! Creates a printer connected to the interpretor.
Standard_EXPORT Draw_Printer (Draw_Interpretor& theTcl);
+ //! 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 a string message with specified trace level.
Draw_Marker3D.cxx
Draw_Marker3D.hxx
Draw_MarkerShape.hxx
+Draw_MessageCommands.cxx
Draw_Number.cxx
Draw_Number.hxx
Draw_PInterp.hxx
Message.cxx
Message.hxx
+Message_Alert.cxx
+Message_Alert.hxx
+Message_AlertExtended.cxx
+Message_AlertExtended.hxx
Message_Algorithm.cxx
Message_Algorithm.hxx
Message_Algorithm.lxx
Message_ConsoleColor.hxx
+Message_Attribute.cxx
+Message_Attribute.hxx
+Message_AttributeMeter.cxx
+Message_AttributeMeter.hxx
+Message_AttributeObject.hxx
+Message_AttributeStream.cxx
+Message_AttributeStream.hxx
+Message_CompositeAlerts.cxx
+Message_CompositeAlerts.hxx
Message_ExecStatus.hxx
Message_Gravity.hxx
Message_HArrayOfMsg.hxx
+Message_Level.cxx
+Message_Level.hxx
Message_ListIteratorOfListOfMsg.hxx
Message_ListOfMsg.hxx
Message_Messenger.cxx
Message_Messenger.hxx
+Message_MetricType.hxx
Message_Msg.cxx
Message_Msg.hxx
Message_Msg.lxx
Message_PrinterOStream.hxx
Message_PrinterSystemLog.cxx
Message_PrinterSystemLog.hxx
+Message_PrinterToReport.cxx
+Message_PrinterToReport.hxx
Message_ProgressIndicator.cxx
Message_ProgressIndicator.hxx
Message_ProgressIndicator.lxx
Message_SequenceOfProgressScale.hxx
Message_Status.hxx
Message_StatusType.hxx
-Message_Alert.cxx
-Message_Alert.hxx
Message_ListOfAlert.hxx
Message_Report.cxx
Message_Report.hxx
+Message_ReportWriter.hxx
#include <Message.hxx>
#include <Message_Messenger.hxx>
+#include <Message_Report.hxx>
#include <TCollection_AsciiString.hxx>
#include <stdio.h>
#include <string.h>
+
+static Handle(Message_Messenger) MyMessenger;
+
+namespace
+{
+ static Standard_CString Message_Table_PrintMetricTypeEnum[10] =
+ {
+ "NONE", "UserTimeCPU", "SystemTimeInfo", "MemPrivate", "MemVirtual",
+ "MemWorkingSet", "MemWorkingSetPeak", "MemSwapUsage", "MemSwapUsagePeak", "MemHeapUsage"
+ };
+}
+
//=======================================================================
//function : DefaultMessenger
//purpose :
//=======================================================================
const Handle(Message_Messenger)& Message::DefaultMessenger ()
{
- static Handle(Message_Messenger) aMessenger = new Message_Messenger;
- return aMessenger;
+ if (MyMessenger.IsNull())
+ MyMessenger = new Message_Messenger;
+ return MyMessenger;
+}
+
+//=======================================================================
+//function : SetDefaultMessenger
+//purpose :
+//=======================================================================
+void Message::SetDefaultMessenger (const Handle(Message_Messenger)& theMessenger)
+{
+ MyMessenger = theMessenger;
+}
+
+//=======================================================================
+//function : DefaultReport
+//purpose :
+//=======================================================================
+const Handle(Message_Report)& Message::DefaultReport(const Standard_Boolean theToCreate)
+{
+ static Handle(Message_Report) MyReport;
+
+ if (MyReport.IsNull() && theToCreate)
+ MyReport = new Message_Report();
+
+ return MyReport;
+}
+
+//=======================================================================
+//function : MetricToString
+//purpose :
+//=======================================================================
+Standard_CString Message::MetricToString (const Message_MetricType theType)
+{
+ return Message_Table_PrintMetricTypeEnum[theType];
+}
+
+//=======================================================================
+//function : MetricFromString
+//purpose :
+//=======================================================================
+Standard_Boolean Message::MetricFromString (const Standard_CString theString,
+ Message_MetricType& theGravity)
+{
+ TCollection_AsciiString aName (theString);
+ for (Standard_Integer aMetricIter = 0; aMetricIter <= Message_MetricType_MemHeapUsage; ++aMetricIter)
+ {
+ Standard_CString aMetricName = Message_Table_PrintMetricTypeEnum[aMetricIter];
+ if (aName == aMetricName)
+ {
+ theGravity = Message_MetricType (aMetricIter);
+ return Standard_True;
+ }
+ }
+ return Standard_False;
+}
+
+// =======================================================================
+// function : ToOSDMetric
+// purpose :
+// =======================================================================
+Standard_Boolean Message::ToOSDMetric (const Message_MetricType theMetric, OSD_MemInfo::Counter& theMemInfo)
+{
+ switch (theMetric)
+ {
+ case Message_MetricType_MemPrivate: theMemInfo = OSD_MemInfo::MemPrivate; return Standard_True;
+ case Message_MetricType_MemVirtual: theMemInfo = OSD_MemInfo::MemVirtual; return Standard_True;
+ case Message_MetricType_MemWorkingSet: theMemInfo = OSD_MemInfo::MemWorkingSet; return Standard_True;
+ case Message_MetricType_MemWorkingSetPeak: theMemInfo = OSD_MemInfo::MemWorkingSetPeak; return Standard_True;
+ case Message_MetricType_MemSwapUsage: theMemInfo = OSD_MemInfo::MemSwapUsage; return Standard_True;
+ case Message_MetricType_MemSwapUsagePeak: theMemInfo = OSD_MemInfo::MemSwapUsagePeak; return Standard_True;
+ case Message_MetricType_MemHeapUsage: theMemInfo = OSD_MemInfo::MemHeapUsage; return Standard_True;
+ }
+ return Standard_False;
+}
+
+// =======================================================================
+// function : ToMessageMetric
+// purpose :
+// =======================================================================
+Standard_Boolean Message::ToMessageMetric (const OSD_MemInfo::Counter theMemInfo, Message_MetricType& theMetric)
+{
+ switch (theMemInfo)
+ {
+ case OSD_MemInfo::MemPrivate: theMetric = Message_MetricType_MemPrivate; break;
+ case OSD_MemInfo::MemVirtual: theMetric = Message_MetricType_MemVirtual; break;
+ case OSD_MemInfo::MemWorkingSet: theMetric = Message_MetricType_MemWorkingSet; break;
+ case OSD_MemInfo::MemWorkingSetPeak: theMetric = Message_MetricType_MemWorkingSetPeak; break;
+ case OSD_MemInfo::MemSwapUsage: theMetric = Message_MetricType_MemSwapUsage; break;
+ case OSD_MemInfo::MemSwapUsagePeak: theMetric = Message_MetricType_MemSwapUsagePeak; break;
+ case OSD_MemInfo::MemHeapUsage: theMetric = Message_MetricType_MemHeapUsage; break;
+ default: return Standard_False;
+ }
+ return Standard_True;
}
//=======================================================================
#define _Message_HeaderFile
#include <Message_Messenger.hxx>
+#include <Message_Gravity.hxx>
+#include <Message_MetricType.hxx>
+#include <NCollection_Vector.hxx>
+#include <OSD_MemInfo.hxx>
+
+#include <TCollection_AsciiString.hxx>
+
+class Message_Report;
//! Defines
//! - tools to work with messages
//! @endcode
Standard_EXPORT static const Handle(Message_Messenger)& DefaultMessenger();
+ //! Sets default messenger.
+ Standard_EXPORT static void SetDefaultMessenger (const Handle(Message_Messenger)& theMessenger);
+
public:
+ //! returns the only one instance of Report
+ //! When theToCreate is true - automatically creates message report when not exist.
+ //! that has been created.
+ Standard_EXPORT static const Handle(Message_Report)& DefaultReport (const Standard_Boolean theToCreate = Standard_False);
+
+ //! Determines the metric from the given string identifier.
+ //! @param theString string identifier
+ //! @param theType detected type of metric
+ //! @return TRUE if string identifier is known
+ Standard_EXPORT static Standard_Boolean MetricFromString (const Standard_CString theString,
+ Message_MetricType& theType);
+ //! Returns the string name for a given metric type.
+ //! @param theType metric type
+ //! @return string identifier from the list of Message_MetricType
+ Standard_EXPORT static Standard_CString MetricToString (const Message_MetricType theType);
+ //! Returns the metric type from the given string identifier.
+ //! @param theString string identifier
+ //! @return metric type or Message_MetricType_None if string identifier is invalid
+ static Message_MetricType MetricFromString (const Standard_CString theString)
+ {
+ Message_MetricType aMetric = Message_MetricType_None;
+ MetricFromString (theString, aMetric);
+ return aMetric;
+ }
+ //! Converts message metric to OSD memory info type.
+ //! @param theMetric [in] message metric
+ //! @param theMemInfo [out] filled memory info type
+ //! @return true if converted
+ static Standard_EXPORT Standard_Boolean ToOSDMetric (const Message_MetricType theMetric, OSD_MemInfo::Counter& theMemInfo);
+
+ //! Converts OSD memory info type to message metric.
+ //! @param theMemInfo [int] memory info type
+ //! @param theMetric [out] filled message metric
+ //! @return true if converted
+ static Standard_EXPORT Standard_Boolean ToMessageMetric (const OSD_MemInfo::Counter theMemInfo, Message_MetricType& theMetric);
+
//!@name Short-cuts to DefaultMessenger
static Message_Messenger::StreamBuffer Send(Message_Gravity theGravity)
};
+// AsciiString
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const Handle(Standard_Transient)& theObject)
+{
+ theMessenger->Send (theObject, Message_Info);
+}
+
+//! @def OCCT_SEND_DUMPJSON
+//! Append into messenger result of DumpJson for the field
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for fields of the dumped class which has own DumpJson implementation.
+#define OCCT_SEND_DUMPJSON(theField, theMessage) \
+{ \
+ if ((void*)(theField) != NULL) \
+ { \
+ Message::SendInfo() << theMessage; \
+ (theField)->DumpJson (Message::SendInfo()); \
+ } \
+}
+
+//! @def OCCT_SEND_MESSAGE
+//! Append into messenger result of DumpJson for the field
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for fields of the dumped class which has own DumpJson implementation.
+#define OCCT_SEND_MESSAGE(theMessage) \
+{ \
+ Message::SendInfo() << theMessage; \
+}
+
+//! @def OCCT_SEND_DUMPJSON
+//! Append into messenger result of DumpJson for the field
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for fields of the dumped class which has own DumpJson implementation.
+#define OCCT_SEND_STREAM(theStream, theMessage) \
+{ \
+ Message::SendInfo() << theMessage; \
+ Message::SendInfo() << theStream.str().c_str(); \
+}
+
#endif // _Message_HeaderFile
//! Base implementation always returns true.
virtual Standard_EXPORT Standard_Boolean Merge (const Handle(Message_Alert)& theTarget);
- // OCCT RTTI
DEFINE_STANDARD_RTTIEXT(Message_Alert,Standard_Transient)
};
--- /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 <Message_AlertExtended.hxx>
+#include <Message_Attribute.hxx>
+#include <Message_CompositeAlerts.hxx>
+#include <Message_Report.hxx>
+
+#include <Precision.hxx>
+#include <Standard_Assert.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Message_AlertExtended,Message_Alert)
+
+//=======================================================================
+//function : GetMessageKey
+//purpose :
+//=======================================================================
+
+Standard_CString Message_AlertExtended::GetMessageKey () const
+{
+ if (myAttribute.IsNull())
+ return Message_Alert::GetMessageKey();
+
+ return myAttribute->GetMessageKey();
+}
+
+//=======================================================================
+//function : CompositeAlerts
+//purpose :
+//=======================================================================
+Handle(Message_CompositeAlerts) Message_AlertExtended::CompositeAlerts (const Standard_Boolean theToCreate)
+{
+ if (myCompositAlerts.IsNull() && theToCreate)
+ myCompositAlerts = new Message_CompositeAlerts();
+
+ return myCompositAlerts;
+}
+
+//=======================================================================
+//function : SupportsMerge
+//purpose :
+//=======================================================================
+Standard_Boolean Message_AlertExtended::SupportsMerge () const
+{
+ if (myCompositAlerts.IsNull())
+ return Standard_True;
+
+ // hierarchical alerts can not be merged
+ for (int aGravIter = Message_Trace; aGravIter <= Message_Fail; ++aGravIter)
+ {
+ if (!myCompositAlerts->Alerts ((Message_Gravity)aGravIter).IsEmpty())
+ return Standard_False;
+ }
+
+ return Standard_True;
+}
+
+//=======================================================================
+//function : Merge
+//purpose :
+//=======================================================================
+Standard_Boolean Message_AlertExtended::Merge (const Handle(Message_Alert)& /*theTarget*/)
+{
+ // by default, merge trivially
+ return Standard_False;
+}
+
+//=======================================================================
+//function : AddAlert
+//purpose :
+//=======================================================================
+Handle(Message_Alert) Message_AlertExtended::AddAlert (const Handle(Message_Report)& theReport,
+ const Handle(Message_Attribute)& theAttribute,
+ const Message_Gravity theGravity)
+{
+ Handle(Message_AlertExtended) anAlert = new Message_AlertExtended();
+ anAlert->SetAttribute (theAttribute);
+ theReport->AddAlert (theGravity, anAlert);
+
+ return anAlert;
+}
--- /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.
+
+#ifndef _Message_AlertExtended_HeaderFile
+#define _Message_AlertExtended_HeaderFile
+
+#include <Message_Alert.hxx>
+#include <Message_Gravity.hxx>
+#include <TCollection_AsciiString.hxx>
+
+class Message_Attribute;
+class Message_Report;
+
+DEFINE_STANDARD_HANDLE(Message_AlertExtended, Message_Alert)
+
+class Message_CompositeAlerts;
+
+//! Inherited class of Message_Alert with some additional information.
+//!
+//! It has Message_Attributes to provide the alert name, and other custom information
+//!
+//! It has a container of composite alerts, if the alert might provide
+//! sub-alerts collecting.
+//!
+class Message_AlertExtended : public Message_Alert
+{
+public:
+ //! Empty constructor
+ Standard_EXPORT Message_AlertExtended() : Message_Alert() {}
+
+ //! Return a C string to be used as a key for generating text user
+ //! messages describing this alert.
+ //! The messages are generated with help of Message_Msg class, in
+ //! Message_Report::Dump().
+ //! Base implementation returns dynamic type name of the instance.
+ Standard_EXPORT virtual Standard_CString GetMessageKey () const Standard_OVERRIDE;
+
+ //! Sets container of the alert attributes
+ //! @param theAttributes an attribute values
+ void SetAttribute (const Handle(Message_Attribute)& theAttribute) { myAttribute = theAttribute; }
+
+ //! Returns container of the alert attributes
+ //! @param theAttributes an attribute values
+ const Handle(Message_Attribute)& Attribute() const { return myAttribute; }
+
+ //! Returns class provided hierarchy of alerts if created or create if the parameter is true
+ //! @param isCreate if composite alert has not been created for this alert, it should be created
+ //! @return instance or NULL
+ Standard_EXPORT Handle(Message_CompositeAlerts) CompositeAlerts (const Standard_Boolean theToCreate = Standard_False);
+
+ //! Return true if this type of alert can be merged with other
+ //! of the same type to avoid duplication.
+ //! Hierarchical alerts can not be merged
+ //! Basis implementation returns true.
+ virtual Standard_EXPORT Standard_Boolean SupportsMerge() const Standard_OVERRIDE;
+
+ //! If possible, merge data contained in this alert to theTarget.
+ //! @return True if merged.
+ //! Base implementation always returns false.
+ virtual Standard_EXPORT Standard_Boolean Merge (const Handle(Message_Alert)& theTarget) Standard_OVERRIDE;
+
+ //! Creates new instance of the alert and put it into report with Message_Info gravity.
+ //! It does nothing if such kind of gravity is not active in the report
+ //! @param theReport the message report where new alert is placed
+ //! @param theAttribute container of additional values of the alert
+ //! @return created alert or NULL if Message_Info is not active in report
+ static Standard_EXPORT Handle(Message_Alert) AddAlert (const Handle(Message_Report)& theReport,
+ const Handle(Message_Attribute)& theAttribute,
+ const Message_Gravity theGravity);
+
+ DEFINE_STANDARD_RTTIEXT(Message_AlertExtended, Message_Alert)
+
+protected:
+
+ Handle(Message_CompositeAlerts) myCompositAlerts; //!< class provided hierarchical structure of alerts
+ Handle(Message_Attribute) myAttribute; //!< container of the alert attributes
+};
+
+#endif // _Message_Alert_HeaderFile
--- /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 <Message_Attribute.hxx>
+
+#include <Standard_Assert.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Message_Attribute, Standard_Transient)
+
+//=======================================================================
+//function : GetMessageKey
+//purpose :
+//=======================================================================
+
+Standard_CString Message_Attribute::GetMessageKey () const
+{
+ return !myName.IsEmpty() ? myName.ToCString() : "";
+}
--- /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.
+
+#ifndef _Message_Attribute_HeaderFile
+#define _Message_Attribute_HeaderFile
+
+#include <Standard_Transient.hxx>
+#include <TCollection_AsciiString.hxx>
+
+DEFINE_STANDARD_HANDLE(Message_Attribute, Standard_Transient)
+
+//! Additional information of extended alert attribute
+//! To provide other custom attribute container, it might be redefined.
+class Message_Attribute : public Standard_Transient
+{
+public:
+ //! Empty constructor
+ Standard_EXPORT Message_Attribute (const TCollection_AsciiString& theName = TCollection_AsciiString())
+ : myName (theName) {}
+
+ //! Return a C string to be used as a key for generating text user
+ //! messages describing this alert.
+ //! The messages are generated with help of Message_Msg class, in
+ //! Message_Report::Dump().
+ //! Base implementation returns dynamic type name of the instance.
+ virtual Standard_EXPORT Standard_CString GetMessageKey () const;
+
+ //! Returns custom name of alert if it is set
+ //! @return alert name
+ const TCollection_AsciiString& GetName() const { return myName; }
+
+ //! Sets the custom name of alert
+ //! @param theName a name for the alert
+ void SetName (const TCollection_AsciiString& theName) { myName = theName; }
+
+ DEFINE_STANDARD_RTTIEXT(Message_Attribute, Standard_Transient)
+
+private:
+ TCollection_AsciiString myName; //!< alert name, if defined is used in GetMessageKey
+
+};
+
+#endif // _Message_Attribute_HeaderFile
--- /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 <Message_AttributeMeter.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message.hxx>
+#include <Message_Report.hxx>
+#include <OSD_Chronometer.hxx>
+
+#include <Precision.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeMeter, Message_Attribute)
+
+//=======================================================================
+//function : SetValues
+//purpose :
+//=======================================================================
+Message_AttributeMeter::Message_AttributeMeter (const TCollection_AsciiString& theName)
+: Message_Attribute(theName)
+{
+}
+
+//=======================================================================
+//function : HasMetric
+//purpose :
+//=======================================================================
+Standard_Boolean Message_AttributeMeter::HasMetric (const Message_MetricType& theMetric) const
+{
+ return myMetrics.IsBound (theMetric);
+}
+
+//=======================================================================
+//function : IsMetricValid
+//purpose :
+//=======================================================================
+Standard_Boolean Message_AttributeMeter::IsMetricValid (const Message_MetricType& theMetric) const
+{
+ return Abs (StartValue (theMetric) - UndefinedMetricValue()) > Precision::Confusion() &&
+ Abs (StopValue (theMetric) - UndefinedMetricValue()) > Precision::Confusion();
+}
+
+//=======================================================================
+//function : StartValue
+//purpose :
+//=======================================================================
+Standard_Real Message_AttributeMeter::StartValue (const Message_MetricType& theMetric) const
+{
+ if (!HasMetric (theMetric))
+ return UndefinedMetricValue();
+
+ return myMetrics.Seek (theMetric)->first;
+}
+
+//=======================================================================
+//function : SetStartValue
+//purpose :
+//=======================================================================
+void Message_AttributeMeter::SetStartValue (const Message_MetricType& theMetric, const Standard_Real theValue)
+{
+ //std::cout << GetName() << ": " << theValue << " (start)" << std::endl;
+
+ if (!HasMetric (theMetric))
+ {
+ myMetrics.Bind (theMetric, std::make_pair (theValue, UndefinedMetricValue()));
+ }
+ myMetrics.ChangeFind (theMetric).first = theValue;
+}
+
+//=======================================================================
+//function : StopValue
+//purpose :
+//=======================================================================
+Standard_Real Message_AttributeMeter::StopValue (const Message_MetricType& theMetric) const
+{
+ if (!HasMetric (theMetric))
+ return UndefinedMetricValue();
+
+ return myMetrics.Find (theMetric).second;
+}
+
+//=======================================================================
+//function : SetStopValue
+//purpose :
+//=======================================================================
+void Message_AttributeMeter::SetStopValue (const Message_MetricType& theMetric, const Standard_Real theValue)
+{
+ //std::cout << GetName() << ": " << theValue << " (stop)" << std::endl;
+ if (!HasMetric (theMetric))
+ {
+ // start value should be already set
+ return;
+ }
+ myMetrics.ChangeFind (theMetric).second = theValue;
+}
+
+//=======================================================================
+//function : SetAlertMetrics
+//purpose :
+//=======================================================================
+void Message_AttributeMeter::SetAlertMetrics (const Handle(Message_AlertExtended)& theAlert,
+ const Standard_Boolean theStartValue)
+{
+ if (theAlert.IsNull())
+ return;
+
+ Handle(Message_AttributeMeter) aMeterAttribute = Handle(Message_AttributeMeter)::DownCast (theAlert->Attribute());
+ if (aMeterAttribute.IsNull())
+ return;
+
+ Handle(Message_Report) aReport = Message::DefaultReport (Standard_True);
+ const NCollection_Map<Message_MetricType>& anActiveMetrics = aReport->ActiveMetrics();
+
+ // time metrics
+ if (anActiveMetrics.Contains (Message_MetricType_UserTimeCPU) ||
+ anActiveMetrics.Contains (Message_MetricType_SystemTimeInfo))
+ {
+ Standard_Real aUserSeconds, aSystemSeconds;
+ OSD_Chronometer::GetProcessCPU (aUserSeconds, aSystemSeconds);
+
+ if (anActiveMetrics.Contains (Message_MetricType_UserTimeCPU))
+ {
+ if (theStartValue)
+ aMeterAttribute->SetStartValue (Message_MetricType_UserTimeCPU, aUserSeconds);
+ else
+ aMeterAttribute->SetStopValue (Message_MetricType_UserTimeCPU, aUserSeconds);
+ }
+ if (anActiveMetrics.Contains (Message_MetricType_SystemTimeInfo))
+ {
+ if (theStartValue)
+ aMeterAttribute->SetStartValue (Message_MetricType_SystemTimeInfo, aSystemSeconds);
+ else
+ aMeterAttribute->SetStopValue (Message_MetricType_SystemTimeInfo, aSystemSeconds);
+ }
+ }
+ // memory metrics
+ OSD_MemInfo aMemInfo (Standard_False);
+ aMemInfo.SetActive (Standard_False);
+ NCollection_Map<OSD_MemInfo::Counter> aCounters;
+ Standard_Boolean isCounterFound = Standard_False;
+ for (NCollection_Map<Message_MetricType>::Iterator anIterator (anActiveMetrics); anIterator.More(); anIterator.Next())
+ {
+ OSD_MemInfo::Counter anInfoCounter;
+ if (!Message::ToOSDMetric (anIterator.Value(), anInfoCounter))
+ continue;
+
+ aCounters.Add (anInfoCounter);
+ aMemInfo.SetActive (anInfoCounter, Standard_True);
+ isCounterFound = Standard_True;
+ }
+ if (aCounters.IsEmpty())
+ return;
+
+ aMemInfo.Update();
+ Message_MetricType aMetricType;
+ for (NCollection_Map<OSD_MemInfo::Counter>::Iterator anIterator (aCounters); anIterator.More(); anIterator.Next())
+ {
+ if (!Message::ToMessageMetric (anIterator.Value(), aMetricType))
+ continue;
+
+ if (theStartValue)
+ aMeterAttribute->SetStartValue (aMetricType, (Standard_Real)aMemInfo.ValuePreciseMiB (anIterator.Value()));
+ else
+ aMeterAttribute->SetStopValue (aMetricType, (Standard_Real)aMemInfo.ValuePreciseMiB (anIterator.Value()));
+ }
+}
--- /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.
+
+#ifndef _Message_AttributeMeter_HeaderFile
+#define _Message_AttributeMeter_HeaderFile
+
+#include <Message_Attribute.hxx>
+#include <Message_MetricType.hxx>
+
+#include <NCollection_DataMap.hxx>
+
+class Message_Alert;
+class Message_AlertExtended;
+
+//! Alert object storing alert metrics values.
+//! Start and stop values for each metric.
+class Message_AttributeMeter : public Message_Attribute
+{
+public:
+
+ //! Returns default value of the metric when it is not defined
+ //! @return undefined value
+ static Standard_Real UndefinedMetricValue() { return -1.0; }
+
+public:
+
+ //! Constructor with string argument
+ Standard_EXPORT Message_AttributeMeter (const TCollection_AsciiString& theName = TCollection_AsciiString());
+
+ //! Checks whether the attribute has values for the metric
+ //! @param theMetric [in] metric type
+ //! @return true if the metric values exist in the attribute
+ Standard_EXPORT Standard_Boolean HasMetric (const Message_MetricType& theMetric) const;
+
+ //! Returns true when both values of the metric are set.
+ //! @param theMetric [in] metric type
+ //! @return true if metric values are valid
+ Standard_EXPORT Standard_Boolean IsMetricValid (const Message_MetricType& theMetric) const;
+
+ //! Returns start value for the metric
+ //! @param theMetric [in] metric type
+ //! @return real value
+ Standard_EXPORT Standard_Real StartValue (const Message_MetricType& theMetric) const;
+
+ //! Sets start values for the metric
+ //! @param theMetric [in] metric type
+ Standard_EXPORT void SetStartValue (const Message_MetricType& theMetric, const Standard_Real theValue);
+
+ //! Returns stop value for the metric
+ //! @param theMetric [in] metric type
+ //! @return real value
+ Standard_EXPORT Standard_Real StopValue (const Message_MetricType& theMetric) const;
+
+ //! Sets stop values for the metric
+ //! @param theMetric [in] metric type
+ Standard_EXPORT void SetStopValue (const Message_MetricType& theMetric, const Standard_Real theValue);
+
+ //! Sets start values of default report metrics into the alert
+ //! @param theAlert an alert
+ static void StartAlert (const Handle(Message_AlertExtended)& theAlert) { SetAlertMetrics (theAlert, Standard_True); }
+
+ //! Sets stop values of default report metrics into the alert
+ //! @param theAlert an alert
+ static void StopAlert (const Handle(Message_AlertExtended)& theAlert) { SetAlertMetrics (theAlert, Standard_False); }
+
+ //! Sets current values of default report metrics into the alert.
+ //! Processed oly alert with Message_AttributeMeter attribute
+ //! @param theAlert an alert
+ //! @param theStartValue flag, if true, the start value is collected otherwise stop
+ static Standard_EXPORT void SetAlertMetrics (const Handle(Message_AlertExtended)& theAlert,
+ const Standard_Boolean theStartValue);
+
+ DEFINE_STANDARD_RTTIEXT(Message_AttributeMeter, Message_Attribute)
+
+private:
+
+ typedef std::pair<Standard_Real, Standard_Real> StartToStopValue;
+ NCollection_DataMap<Message_MetricType, StartToStopValue> myMetrics; //!< computed metrics
+};
+
+#endif // _Message_AttributeMeter_HeaderFile
--- /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.
+
+#ifndef _Message_AttributeObject_HeaderFile
+#define _Message_AttributeObject_HeaderFile
+
+#include <Message_Attribute.hxx>
+
+class Standard_Transient;
+
+//! Alert object storing a transient object
+class Message_AttributeObject : public Message_Attribute
+{
+public:
+ //! Constructor with string argument
+ Message_AttributeObject (const Handle(Standard_Transient)& theObject,
+ const TCollection_AsciiString& theName = TCollection_AsciiString())
+ : Message_Attribute (theName) { myObject = theObject; }
+
+ //! Returns object
+ //! @return the object instance
+ const Handle(Standard_Transient)& Object() { return myObject; }
+
+ //! Sets the object
+ //! @param theObject an instance
+ void SetObject (const Handle(Standard_Transient)& theObject) { myObject = theObject; }
+
+ DEFINE_STANDARD_RTTI_INLINE(Message_AttributeObject, Message_Attribute)
+
+private:
+ Handle(Standard_Transient) myObject; //!< alert object
+};
+
+#endif // _Message_AttributeObject_HeaderFile
--- /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 <Message_AttributeStream.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeStream, Message_Attribute)
+
+//=======================================================================
+//function : SetValues
+//purpose :
+//=======================================================================
+Message_AttributeStream::Message_AttributeStream (const Standard_SStream& theStream,
+ const TCollection_AsciiString& theName)
+: Message_Attribute(theName)
+{
+ SetStream (theStream);
+}
+
+//=======================================================================
+//function : SetStream
+//purpose :
+//=======================================================================
+
+void Message_AttributeStream::SetStream (const Standard_SStream& theStream)
+{
+ myStream.str ("");
+
+ TCollection_AsciiString aStreamStr (theStream.str().c_str());
+ myStream << aStreamStr;
+}
+
--- /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.
+
+#ifndef _Message_AttributeStream_HeaderFile
+#define _Message_AttributeStream_HeaderFile
+
+#include <Message_Attribute.hxx>
+
+#include <NCollection_Vector.hxx>
+#include <Standard_SStream.hxx>
+
+//! Alert object storing stream values
+class Message_AttributeStream : public Message_Attribute
+{
+public:
+
+ //! Constructor with string argument
+ Standard_EXPORT Message_AttributeStream (const Standard_SStream& theStream,
+ const TCollection_AsciiString& theName = TCollection_AsciiString());
+
+ //! Returns stream value
+ const Standard_SStream& Stream() const { return myStream; }
+
+ //! Sets stream value
+ Standard_EXPORT void SetStream (const Standard_SStream& theStream);
+
+ DEFINE_STANDARD_RTTIEXT(Message_AttributeStream, Message_Attribute)
+
+private:
+ Standard_SStream myStream; //!< container of values
+};
+
+#endif // _Message_AttributeStream_HeaderFile
--- /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 <Message_CompositeAlerts.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Standard_Assert.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Message_CompositeAlerts, Standard_Transient)
+
+//=======================================================================
+//function : Alerts
+//purpose :
+//=======================================================================
+const Message_ListOfAlert& Message_CompositeAlerts::Alerts (const Message_Gravity theGravity) const
+{
+ static const Message_ListOfAlert anEmptyList;
+ Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
+ "Requesting alerts for gravity not in valid range", anEmptyList);
+
+ return myAlerts[theGravity];
+}
+
+//=======================================================================
+//function : AddAlert
+//purpose :
+//=======================================================================
+Standard_Boolean Message_CompositeAlerts::AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert)
+{
+ Standard_ASSERT_RETURN (! theAlert.IsNull(), "Attempt to add null alert", Standard_False);
+ Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
+ "Adding alert with gravity not in valid range", Standard_False);
+
+ Message_ListOfAlert& aList = myAlerts[theGravity];
+ if (theAlert->SupportsMerge() && ! aList.IsEmpty())
+ {
+ // merge is performed only for alerts of exactly same type
+ const Handle(Standard_Type)& aType = theAlert->DynamicType();
+ for (Message_ListOfAlert::Iterator anIt(aList); anIt.More(); anIt.Next())
+ {
+ // if merged successfully, just return
+ if (aType == anIt.Value()->DynamicType() && theAlert->Merge (anIt.Value()))
+ return Standard_False;
+ }
+ }
+
+ // if not merged, just add to the list
+ aList.Append (theAlert);
+ return Standard_True;
+}
+
+//=======================================================================
+//function : RemoveAlert
+//purpose :
+//=======================================================================
+Standard_Boolean Message_CompositeAlerts::RemoveAlert (Message_Gravity theGravity,
+ const Handle(Message_Alert)& theAlert)
+{
+ Standard_ASSERT_RETURN (! theAlert.IsNull(), "Attempt to add null alert", Standard_False);
+ Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
+ "Adding alert with gravity not in valid range", Standard_False);
+
+ Message_ListOfAlert& anAlerts = myAlerts[theGravity];
+ if (!anAlerts.Contains (theAlert))
+ return Standard_False;
+
+ return anAlerts.Remove (theAlert);
+}
+
+//=======================================================================
+//function : HasAlerts
+//purpose :
+//=======================================================================
+
+Standard_Boolean Message_CompositeAlerts::HasAlert (const Handle(Message_Alert)& theAlert)
+{
+ for (int aGravIter = Message_Trace; aGravIter <= Message_Fail; ++aGravIter)
+ {
+ const Message_ListOfAlert& anAlerts = Alerts ((Message_Gravity)aGravIter);
+ if (anAlerts.Contains (theAlert))
+ return Standard_True;
+ }
+ return Standard_False;
+}
+
+//=======================================================================
+//function : HasAlerts
+//purpose :
+//=======================================================================
+Standard_Boolean Message_CompositeAlerts::HasAlert (const Handle(Standard_Type)& theType, Message_Gravity theGravity)
+{
+ Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
+ "Requesting alerts for gravity not in valid range", Standard_False);
+
+ for (Message_ListOfAlert::Iterator anIt (myAlerts[theGravity]); anIt.More(); anIt.Next())
+ {
+ if (anIt.Value()->IsInstance(theType))
+ return Standard_True;
+ }
+ return Standard_False;
+}
+
+//=======================================================================
+//function : Clear
+//purpose :
+//=======================================================================
+void Message_CompositeAlerts::Clear ()
+{
+ for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i)
+ {
+ myAlerts[i].Clear();
+ }
+}
+
+//=======================================================================
+//function : Clear
+//purpose :
+//=======================================================================
+void Message_CompositeAlerts::Clear (Message_Gravity theGravity)
+{
+ Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
+ "Requesting alerts for gravity not in valid range", );
+ myAlerts[theGravity].Clear();
+}
+
+//=======================================================================
+//function : Clear
+//purpose :
+//=======================================================================
+void Message_CompositeAlerts::Clear (const Handle(Standard_Type)& theType)
+{
+ for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i)
+ {
+ for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); )
+ {
+ if (anIt.Value().IsNull() || anIt.Value()->IsInstance (theType))
+ {
+ myAlerts[i].Remove (anIt);
+ }
+ else
+ {
+ anIt.More();
+ }
+ }
+ }
+}
--- /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.
+
+#ifndef _Message_CompositeAlerts_HeaderFile
+#define _Message_CompositeAlerts_HeaderFile
+
+#include <Message_Alert.hxx>
+#include <Message_Gravity.hxx>
+#include <Message_ListOfAlert.hxx>
+#include <Standard_Transient.hxx>
+
+class Message_CompositeAlerts;
+DEFINE_STANDARD_HANDLE(Message_CompositeAlerts, Standard_Transient)
+
+//! Class providing container of alerts
+class Message_CompositeAlerts : public Standard_Transient
+{
+public:
+ //! Empty constructor
+ Standard_EXPORT Message_CompositeAlerts() {}
+
+ //! Returns list of collected alerts with specified gravity
+ Standard_EXPORT const Message_ListOfAlert& Alerts (const Message_Gravity theGravity) const;
+
+ //! Add alert with specified gravity. If the alert supports merge it will be merged.
+ //! @param theGravity an alert gravity
+ //! @param theAlert an alert to be added as a child alert
+ //! @return true if the alert is added or merged
+ Standard_EXPORT Standard_Boolean AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert);
+
+ //! Removes alert with specified gravity.
+ //! @param theGravity an alert gravity
+ //! @param theAlert an alert to be removed from the children
+ //! @return true if the alert is removed
+ Standard_EXPORT Standard_Boolean RemoveAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert);
+
+ //! Returns true if the alert belong the list of the child alerts.
+ //! @param theAlert an alert to be checked as a child alert
+ //! @return true if the alert is found in a container of children
+ Standard_EXPORT Standard_Boolean HasAlert (const Handle(Message_Alert)& theAlert);
+
+ //! Returns true if specific type of alert is recorded with specified gravity
+ //! @param theType an alert type
+ //! @param theGravity an alert gravity
+ //! @return true if the alert is found in a container of children
+ Standard_EXPORT Standard_Boolean HasAlert (const Handle(Standard_Type)& theType, Message_Gravity theGravity);
+
+ //! Clears all collected alerts
+ Standard_EXPORT void Clear ();
+
+ //! Clears collected alerts with specified gravity
+ //! @param theGravity an alert gravity
+ Standard_EXPORT void Clear (Message_Gravity theGravity);
+
+ //! Clears collected alerts with specified type
+ //! @param theType an alert type
+ Standard_EXPORT void Clear (const Handle(Standard_Type)& theType);
+
+ DEFINE_STANDARD_RTTIEXT(Message_CompositeAlerts,Standard_Transient)
+
+protected:
+ // store messages in a lists sorted by gravity;
+ // here we rely on knowledge that Message_Fail is the last element of the enum
+ Message_ListOfAlert myAlerts[Message_Fail + 1]; //!< container of child alert for each type of gravity
+};
+
+#endif // _Message_CompositeAlerts_HeaderFile
#include <Message_StatusType.hxx>
#include <Message_Status.hxx>
+#include <Standard_Dump.hxx>
+
/**
* Tiny class for extended handling of error / execution
* status of algorithm in universal way.
const Message_ExecStatus& operator &= ( const Message_ExecStatus& theOther )
{ And ( theOther ); return *this; }
+ //! Dumps the content of me into the stream
+ virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const
+ {
+ (void)theDepth;
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDone)
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myWarn)
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAlarm)
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myFail)
+ }
+
//@}
public:
--- /dev/null
+// Copyright (c) 2019 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 <Message_Level.hxx>
+
+#include <Message.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_CompositeAlerts.hxx>
+#include <Message_AttributeMeter.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_Report.hxx>
+
+#include <OSD_Chronometer.hxx>
+#include <OSD_MemInfo.hxx>
+
+//=======================================================================
+//function : Message_Level
+//purpose :
+//=======================================================================
+Message_Level::Message_Level (const TCollection_AsciiString& theName)
+{
+ const Handle(Message_Report)& aDefaultReport = Message::DefaultReport();
+ if (!aDefaultReport.IsNull() && aDefaultReport->IsActiveInMessenger())
+ aDefaultReport->AddLevel (this, theName);
+}
+
+//=======================================================================
+//function : Destructor
+//purpose :
+//=======================================================================
+Message_Level::~Message_Level()
+{
+ remove();
+}
+
+//=======================================================================
+//function : SetRootAlert
+//purpose :
+//=======================================================================
+void Message_Level::SetRootAlert (const Handle(Message_AlertExtended)& theAlert,
+ const Standard_Boolean isRequiredToStart)
+{
+ myRootAlert = theAlert;
+ if (isRequiredToStart)
+ Message_AttributeMeter::StartAlert (myRootAlert);
+}
+
+//=======================================================================
+//function : AddAlert
+//purpose :
+//=======================================================================
+Standard_Boolean Message_Level::AddAlert (const Message_Gravity theGravity,
+ const Handle(Message_Alert)& theAlert)
+{
+ Handle(Message_AlertExtended) anAlertExtended = Handle(Message_AlertExtended)::DownCast (theAlert);
+ if (anAlertExtended.IsNull())
+ return Standard_False;
+
+ // looking for the parent of the parameter alert to release the previous alert
+ Handle(Message_AlertExtended) aRootAlert = myRootAlert;
+ Handle(Message_CompositeAlerts) aCompositeAlert = aRootAlert->CompositeAlerts (Standard_True);
+
+ // update metrics of the previous alert
+ Message_AttributeMeter::StopAlert (myLastAlert);
+
+ myLastAlert = anAlertExtended;
+ // set start metrics of the new alert
+ Message_AttributeMeter::StartAlert (myLastAlert);
+
+ // add child alert
+ aCompositeAlert->AddAlert (theGravity, theAlert);
+
+ return Standard_True;
+}
+
+//=======================================================================
+//function : remove()
+//purpose :
+//=======================================================================
+void Message_Level::remove()
+{
+ const Handle(Message_Report)& aDefaultReport = Message::DefaultReport();
+ if (aDefaultReport.IsNull() || !aDefaultReport->IsActiveInMessenger())
+ return;
+
+ Message_AttributeMeter::StopAlert (myLastAlert);
+
+ if (!Message::DefaultReport().IsNull())
+ Message::DefaultReport()->RemoveLevel (this);
+}
--- /dev/null
+// Copyright (c) 2019 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.
+
+#ifndef _Message_Level_HeaderFile
+#define _Message_Level_HeaderFile
+
+#include <Message.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_Gravity.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_MetricType.hxx>
+
+#include <NCollection_DataMap.hxx>
+#include <Standard.hxx>
+
+//! This class is an instance of Sentry to create a level in a message report
+//! Constructor of the class add new (active) level in the report, destructor removes it
+//! While the level is active in the report, new alerts are added below the level root alert.
+//!
+//! The first added alert is a root alert, other are added below the root alert
+//!
+//! If alert has Message_AttributeMeter attribute, active metrics of the default report are stored in
+//! the attriute: start value of metric on adding alert, stop on adding another alert or closing (delete) the level
+//! in the report.
+//!
+//! Processing of this class is implemented in Message_Report, it is used only insided it.
+//! Levels using should be only through using OCCT_ADD_MESSAGE_LEVEL_SENTRY only. No other code is required outside.
+class Message_Level
+{
+
+public:
+ //! Constructor. Append
+ //! One string key is used for all alert meters. The perf meter is not started automatically, it will be done in
+ //! AddAlert method
+ Standard_EXPORT Message_Level (const TCollection_AsciiString& theName = TCollection_AsciiString());
+
+ //! Assures stopping upon destruction
+ Standard_EXPORT ~Message_Level();
+
+ //! Returns root alert of the level
+ //! @return alert instance or NULL
+ const Handle(Message_AlertExtended)& RootAlert() const { return myRootAlert; }
+
+ //! Sets the root alert. Starts collects alert metrics if active.
+ //! @param theAlert an alert
+ Standard_EXPORT void SetRootAlert (const Handle(Message_AlertExtended)& theAlert,
+ const Standard_Boolean isRequiredToStart);
+
+ //! Adds new alert on the level. Stops the last alert metric, appends the alert and starts the alert metrics collecting.
+ //! Sets root alert beforehead this method using, if the root is NULL, it does nothing.
+ //! @param theGravity an alert gravity
+ //! @param theAlert an alert
+ //! @return true if alert is added
+ Standard_EXPORT Standard_Boolean AddAlert (const Message_Gravity theGravity,
+ const Handle(Message_Alert)& theAlert);
+
+protected:
+ //! Remove the current level from the report. It stops metric collecting for the last and the root alerts.
+ Standard_EXPORT void remove();
+
+protected:
+ Handle(Message_AlertExtended) myRootAlert; //!< root alert
+ Handle(Message_AlertExtended) myLastAlert; //!< last added alert on the root alert
+};
+
+//! @def MESSAGE_NEW_LEVEL
+//! Creates a new level instance of Sentry. This row should be inserted before messages using in the method.
+#define OCCT_ADD_MESSAGE_LEVEL_SENTRY(theMessage) \
+ Message_Level aLevel(theMessage);
+
+#endif // _Message_Level_HeaderFile
#include <Message_Printer.hxx>
#include <Message_PrinterOStream.hxx>
+#include <Standard_Dump.hxx>
+
IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
//=======================================================================
//purpose :
//=======================================================================
Message_Messenger::Message_Messenger ()
+: myTraceLevel (-1)
{
AddPrinter ( new Message_PrinterOStream );
}
//=======================================================================
Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
+: myTraceLevel (-1)
{
AddPrinter (thePrinter);
}
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 :
void Message_Messenger::Send (const Standard_CString theString,
const Message_Gravity theGravity) const
{
+ if (TraceLevel() == 0)
+ return;
+
for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
}
}
+//=======================================================================
+//function : Send
+//purpose :
+//=======================================================================
+
+void Message_Messenger::Send (const Standard_SStream& theStream,
+ const Message_Gravity theGravity) const
+{
+ if (TraceLevel() == 0)
+ return;
+
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
+ {
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (!aPrinter.IsNull())
+ {
+ aPrinter->Send (theStream, theGravity);
+ }
+ }
+}
+
+
//=======================================================================
//function : Send
//purpose :
void Message_Messenger::Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) const
{
+ if (TraceLevel() == 0)
+ return;
for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
void Message_Messenger::Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity) const
{
+ if (TraceLevel() == 0)
+ return;
for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
}
}
}
+
+//=======================================================================
+//function : Send
+//purpose :
+//=======================================================================
+void Message_Messenger::Send (const Handle(Standard_Transient)& theObject,
+ const Message_Gravity theGravity) const
+{
+ if (TraceLevel() == 0)
+ return;
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
+ {
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (!aPrinter.IsNull())
+ {
+ aPrinter->Send (theObject, theGravity);
+ }
+ }
+}
+
+//=======================================================================
+//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, myTraceLevel)
+}
#ifndef _Message_Messenger_HeaderFile
#define _Message_Messenger_HeaderFile
+//#include <Message.hxx>
#include <Message_Gravity.hxx>
#include <Message_SequenceOfPrinters.hxx>
{
if (myMessenger)
{
- myMessenger->Send(myStream.str().c_str(), myGravity);
+ myMessenger->Send(myStream, myGravity);
}
myStream.str(std::string()); // empty the buffer for possible reuse
}
//! 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.
//! The sequence can be modified.
Message_SequenceOfPrinters& ChangePrinters() { return myPrinters; }
+ //! Sets trace level used for outputting messages
+ //! - 0: no trace at all
+ //! - 1/2/3: messages of the first level are processed
+ //! - -1: all messages are processed
+ //! Default is 0 : no messages are processed
+ void SetTraceLevel (const Standard_Integer theTraceLevel) { myTraceLevel = theTraceLevel; }
+
+ //! Returns trace level used for outputting messages.
+ Standard_Integer TraceLevel() const { return myTraceLevel; }
+
//! Dispatch a message to all the printers in the list.
//! Three versions of string representations are accepted for
//! convenience, by default all are converted to ExtendedString.
Standard_EXPORT void Send (const Standard_CString theString,
const Message_Gravity theGravity = Message_Warning) const;
+ //! See above
+ Standard_EXPORT void Send (const Standard_SStream& theStream,
+ const Message_Gravity theGravity = Message_Warning) const;
+
//! See above
Standard_EXPORT void Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity = Message_Warning) const;
//! Create string buffer for message of specified type
StreamBuffer Send (Message_Gravity theGravity) { return StreamBuffer (this, theGravity); }
+ //! See above
+ Standard_EXPORT void Send (const Handle(Standard_Transient)& theObject, const Message_Gravity theGravity = Message_Warning) const;
+
+ //! Dumps the content of me into the stream
+ Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
+
+
//! Create string buffer for sending Fail message
StreamBuffer SendFail () { return Send (Message_Fail); }
private:
Message_SequenceOfPrinters myPrinters;
-
+ Standard_Integer myTraceLevel; //!< leel of processed messages
};
#endif // _Message_Messenger_HeaderFile
--- /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.
+
+#ifndef _Message_MetricType_HeaderFile
+#define _Message_MetricType_HeaderFile
+
+//! Specifies kind of report information to collect
+enum Message_MetricType
+{
+ Message_MetricType_None, //!< no computation
+ Message_MetricType_UserTimeCPU, //!< the current CPU user time in seconds
+ Message_MetricType_SystemTimeInfo, //!< the current CPU system time in seconds
+ Message_MetricType_MemPrivate, //!< OSD_MemInfo::MemPrivate
+ Message_MetricType_MemVirtual, //!< OSD_MemInfo::MemVirtual
+ Message_MetricType_MemWorkingSet, //!< OSD_MemInfo::MemWorkingSet
+ Message_MetricType_MemWorkingSetPeak, //!< OSD_MemInfo::MemWorkingSetPeak
+ Message_MetricType_MemSwapUsage, //!< OSD_MemInfo::MemSwapUsage
+ Message_MetricType_MemSwapUsagePeak, //!< OSD_MemInfo::MemSwapUsagePeak
+ Message_MetricType_MemHeapUsage //!< OSD_MemInfo::MemHeapUsage
+};
+
+#endif // _Message_MetricType_HeaderFile
#include <Message_Printer.hxx>
+#include <Standard_Dump.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
send (theString, theGravity);
}
}
+
+//=======================================================================
+//function : Send
+//purpose :
+//=======================================================================
+void Message_Printer::Send (const Standard_SStream& theStream,
+ const Message_Gravity theGravity) const
+{
+ if (theGravity >= myTraceLevel)
+ {
+ Send (theStream.str().c_str(), theGravity);
+ }
+}
+
+//=======================================================================
+//function : Send
+//purpose :
+//=======================================================================
+void Message_Printer::Send (const Handle(Standard_Transient)& theObject,
+ const Message_Gravity theGravity) const
+{
+ if (theObject.IsNull())
+ return;
+
+ if (theGravity >= myTraceLevel)
+ {
+ TCollection_ExtendedString aString = TCollection_ExtendedString (theObject->DynamicType()->Name())
+ + ": " + Standard_Dump::GetPointerInfo (theObject);
+ Send (aString, theGravity);
+ }
+}
+
+//=======================================================================
+//function : DumpJson
+//purpose :
+//=======================================================================
+void Message_Printer::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+ OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
#include <Standard_Transient.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_CString.hxx>
+#include <Standard_SStream.hxx>
+
class TCollection_ExtendedString;
class TCollection_AsciiString;
Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) const;
+ //! Send a string message with specified trace level.
+ //! Stream is converted to string value.
+ //! Default implementation calls first method Send().
+ Standard_EXPORT virtual void Send (const Standard_SStream& theStream, const Message_Gravity theGravity) const;
+
+ //! Send a string message with specified trace level.
+ //! The object is converted to string in format: <object kind> : <object pointer>.
+ //! Default implementation calls first method Send().
+ Standard_EXPORT virtual void Send (const Handle(Standard_Transient)& theObject, const Message_Gravity theGravity) 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)
+}
//! to the trace level set by SetTraceLevel()
Standard_EXPORT virtual void send (const TCollection_AsciiString& theString, const Message_Gravity theGravity) 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)
syslog (getSysLogPriority (theGravity), "%s", theString.ToCString());
#endif
}
+
+//=======================================================================
+//function : DumpJson
+//purpose :
+//=======================================================================
+void Message_PrinterSystemLog::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+ OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream);
+}
\ No newline at end of file
Standard_EXPORT virtual void send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) 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;
--- /dev/null
+// Created on: 2001-01-06
+// Created by: OCC Team
+// Copyright (c) 2001-2014 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 <Message_PrinterToReport.hxx>
+
+#include <Message.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_Attribute.hxx>
+#include <Message_AttributeMeter.hxx>
+#include <Message_AttributeObject.hxx>
+#include <Message_AttributeStream.hxx>
+#include <Message_Report.hxx>
+
+#include <Standard_Dump.hxx>
+#include <TCollection_ExtendedString.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Message_PrinterToReport, Message_Printer)
+
+//=======================================================================
+//function : Report
+//purpose :
+//=======================================================================
+const Handle(Message_Report)& Message_PrinterToReport::Report() const
+{
+ if (!myReport.IsNull())
+ return myReport;
+
+ return Message::DefaultReport (Standard_True);
+}
+
+//=======================================================================
+//function : Send
+//purpose :
+//=======================================================================
+void Message_PrinterToReport::Send (const Standard_SStream& theStream,
+ const Message_Gravity theGravity) const
+{
+ const Handle(Message_Report)& aReport = Report();
+ if (!aReport->ActiveMetrics().IsEmpty())
+ {
+ sendMetricAlert (theStream.str().c_str(), theGravity);
+ return;
+ }
+ if (Standard_Dump::HasChildKey(Standard_Dump::Text (theStream)))
+ {
+ Message_AlertExtended::AddAlert (aReport, new Message_AttributeStream (theStream, myName), theGravity);
+ myName.Clear();
+ }
+ else
+ {
+ if (!myName.IsEmpty())
+ {
+ TCollection_AsciiString aName = myName;
+ myName.Clear();
+ send (aName, theGravity);
+ }
+ myName = Standard_Dump::Text (theStream);
+ }
+}
+
+//=======================================================================
+//function : Send
+//purpose :
+//=======================================================================
+void Message_PrinterToReport::Send (const Handle(Standard_Transient)& /*theObject*/,
+ const Message_Gravity /*theGravity*/) const
+{
+ //const Handle(Message_Report)& aReport = Report();
+ //if (!aReport->ActiveMetrics().IsEmpty())
+ //{
+ // sendMetricAlert (myValue, theGravity);
+ // return;
+ //}
+
+ //Message_AlertExtended::AddAlert (aReport, new Message_AttributeObject (theObject, myValue), theGravity);
+}
+
+//=======================================================================
+//function : send
+//purpose :
+//=======================================================================
+void Message_PrinterToReport::send (const TCollection_AsciiString& theString,
+ const Message_Gravity theGravity) const
+{
+ if (!myName.IsEmpty())
+ {
+ send (myName, theGravity);
+ myName.Clear();
+ }
+
+ const Handle(Message_Report)& aReport = Report();
+ if (!aReport->ActiveMetrics().IsEmpty())
+ {
+ sendMetricAlert (theString, theGravity);
+ return;
+ }
+ Message_AlertExtended::AddAlert (aReport, new Message_Attribute (theString), theGravity);
+}
+
+//=======================================================================
+//function : sendMetricAlert
+//purpose :
+//=======================================================================
+void Message_PrinterToReport::sendMetricAlert (const TCollection_AsciiString theValue,
+ const Message_Gravity theGravity) const
+{
+ Message_AlertExtended::AddAlert (Report(), new Message_AttributeMeter (theValue), theGravity);
+}
+
+//=======================================================================
+//function : DumpJson
+//purpose :
+//=======================================================================
+void Message_PrinterToReport::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+{
+ OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+}
--- /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.
+
+#ifndef _Message_PrinterToReport_HeaderFile
+#define _Message_PrinterToReport_HeaderFile
+
+#include <Message_Printer.hxx>
+#include <Standard_Address.hxx>
+#include <Standard_OStream.hxx>
+#include <TCollection_AsciiString.hxx>
+
+class Message_Report;
+
+class Message_PrinterToReport;
+DEFINE_STANDARD_HANDLE(Message_PrinterToReport, Message_Printer)
+
+//! Implementation of a message printer associated with Message_Report
+//! Send will create a new alert of the report. If string is sent, an alert is created by Eol only.
+//! The alerts are sent into set report or default report of Message.
+class Message_PrinterToReport : public Message_Printer
+{
+ DEFINE_STANDARD_RTTIEXT(Message_PrinterToReport, Message_Printer)
+
+public:
+ //! Create printer for redirecting messages into report.
+ Message_PrinterToReport() {}
+
+ ~Message_PrinterToReport() {}
+
+ //! Returns the current or default report
+ Standard_EXPORT const Handle(Message_Report)& Report() const;
+
+ //! Sets the printer report
+ //! @param theReport report for messages processing, if NULL, the default report is used
+ Standard_EXPORT void SetReport (const Handle(Message_Report)& theReport) { myReport = theReport; }
+
+ //! Send a string message with specified trace level.
+ //! Stream is converted to string value.
+ //! Default implementation calls first method Send().
+ Standard_EXPORT virtual void Send (const Standard_SStream& theStream, const Message_Gravity theGravity) const;
+
+ //! Send a string message with specified trace level.
+ //! The object is converted to string in format: <object kind> : <object pointer>.
+ //! The parameter theToPutEol specified whether end-of-line should be added to the end of the message.
+ //! Default implementation calls first method Send().
+ Standard_EXPORT virtual void Send (const Handle(Standard_Transient)& theObject,
+ const Message_Gravity theGravity) 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 a string message with specified trace level.
+ //! This method must be redefined in descentant.
+ Standard_EXPORT virtual void send (const TCollection_AsciiString& theString,
+ const Message_Gravity theGravity) const;
+
+ //! Send an alert with metrics active in the current report
+ Standard_EXPORT void sendMetricAlert (const TCollection_AsciiString theValue,
+ const Message_Gravity theGravity) const;
+
+private:
+ mutable TCollection_AsciiString myName;
+ Handle(Message_Report) myReport; //!< the report for sending alerts
+};
+
+#endif // _Message_PrinterToReport_HeaderFile
// commercial license or contractual agreement.
#include <Message_Report.hxx>
+
+#include <Message.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_AttributeMeter.hxx>
+#include <Message_Attribute.hxx>
+#include <Message_CompositeAlerts.hxx>
#include <Message_Msg.hxx>
#include <Message_Messenger.hxx>
+#include <Message_PrinterToReport.hxx>
+#include <Message_ReportWriter.hxx>
+
#include <NCollection_Map.hxx>
+#include <Precision.hxx>
+#include <Standard_Dump.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Message_Report,Standard_Transient)
//=======================================================================
Message_Report::Message_Report ()
+: myLimit (-1), myWriteFileOnEachAlert (Standard_False)
{
}
void Message_Report::AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert)
{
- Standard_ASSERT_RETURN (! theAlert.IsNull(), "Attempt to add null alert",);
- Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- "Adding alert with gravity not in valid range",);
-
Standard_Mutex::Sentry aSentry (myMutex);
- // iterate by already recorded alerts and try to merge new one with one of those
- Message_ListOfAlert &aList = myAlerts[theGravity];
- if (theAlert->SupportsMerge() && ! aList.IsEmpty())
+ // alerts of the top level
+ if (myAlertLevels.IsEmpty())
{
- // merge is performed only for alerts of exactly same type
- const Handle(Standard_Type)& aType = theAlert->DynamicType();
- for (Message_ListOfAlert::Iterator anIt(aList); anIt.More(); anIt.Next())
+ Handle (Message_CompositeAlerts) aCompositeAlert = compositeAlerts (Standard_True);
+ if (aCompositeAlert->AddAlert (theGravity, theAlert))
+ {
+ writeReport();
+ return;
+ }
+ // remove alerts under the report only
+ const Message_ListOfAlert& anAlerts = aCompositeAlert->Alerts (theGravity);
+ if (anAlerts.Extent() > myLimit)
{
- // if merged successfully, just return
- if (aType == anIt.Value()->DynamicType() && theAlert->Merge (anIt.Value()))
- return;
+ aCompositeAlert->RemoveAlert (theGravity, anAlerts.First());
}
+ return;
}
- // if not merged, just add to the list
- aList.Append (theAlert);
+ // if there are some levels of alerts, the new alert will be placed below the root
+ myAlertLevels.Last()->AddAlert (theGravity, theAlert);
+
+ writeReport();
}
//=======================================================================
const Message_ListOfAlert& Message_Report::GetAlerts (Message_Gravity theGravity) const
{
static const Message_ListOfAlert anEmptyList;
- Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- "Requesting alerts for gravity not in valid range", anEmptyList);
- return myAlerts[theGravity];
+ if (myCompositAlerts.IsNull())
+ return anEmptyList;
+
+ return myCompositAlerts->Alerts (theGravity);
}
//=======================================================================
Standard_Boolean Message_Report::HasAlert (const Handle(Standard_Type)& theType)
{
- for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
+ for (int aGravIter = Message_Trace; aGravIter <= Message_Fail; ++aGravIter)
{
- if (HasAlert (theType, (Message_Gravity)iGravity))
+ if (HasAlert (theType, (Message_Gravity)aGravIter))
return Standard_True;
}
return Standard_False;
Standard_Boolean Message_Report::HasAlert (const Handle(Standard_Type)& theType, Message_Gravity theGravity)
{
- Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- "Requesting alerts for gravity not in valid range", Standard_False);
- for (Message_ListOfAlert::Iterator anIt (myAlerts[theGravity]); anIt.More(); anIt.Next())
+ if (compositeAlerts().IsNull())
+ return Standard_False;
+
+ return compositeAlerts()->HasAlert (theType, theGravity);
+}
+
+//=======================================================================
+//function : IsActiveInMessenger
+//purpose :
+//=======================================================================
+
+Standard_Boolean Message_Report::IsActiveInMessenger (const Handle(Message_Messenger)& theMessenger) const
+{
+ Handle(Message_Messenger) aMessenger = theMessenger.IsNull() ? Message::DefaultMessenger() : theMessenger;
+ for (Message_SequenceOfPrinters::Iterator anIterator (aMessenger->Printers()); anIterator.More(); anIterator.Next())
{
- if (anIt.Value()->IsInstance(theType))
+ if (anIterator.Value()->IsKind(STANDARD_TYPE (Message_PrinterToReport)) &&
+ Handle(Message_PrinterToReport)::DownCast (anIterator.Value())->Report() == this)
return Standard_True;
}
return Standard_False;
}
//=======================================================================
-//function : Clear
+//function : ActivateInMessenger
+//purpose :
+//=======================================================================
+
+void Message_Report::ActivateInMessenger (const Standard_Boolean toActivate,
+ const Handle(Message_Messenger)& theMessenger) const
+{
+ if (toActivate == IsActiveInMessenger())
+ return;
+
+ Handle(Message_Messenger) aMessenger = theMessenger.IsNull() ? Message::DefaultMessenger() : theMessenger;
+ if (toActivate)
+ {
+ Handle (Message_PrinterToReport) aPrinterToReport = new Message_PrinterToReport();
+ aPrinterToReport->SetReport (this);
+ aMessenger->AddPrinter (aPrinterToReport);
+ }
+ else // deactivate
+ {
+ Message_SequenceOfPrinters aPrintersToRemove;
+ for (Message_SequenceOfPrinters::Iterator anIterator (aMessenger->Printers()); anIterator.More(); anIterator.Next())
+ {
+ const Handle(Message_Printer) aPrinter = anIterator.Value();
+ if (aPrinter->IsKind(STANDARD_TYPE (Message_PrinterToReport)) &&
+ Handle(Message_PrinterToReport)::DownCast (aPrinter)->Report() == this)
+ aPrintersToRemove.Append (aPrinter);
+ }
+ for (Message_SequenceOfPrinters::Iterator anIterator (aPrintersToRemove); anIterator.More(); anIterator.Next())
+ {
+ aMessenger->RemovePrinter (anIterator.Value());
+ }
+ }
+}
+
+//=======================================================================
+//function : AddLevel
+//purpose :
+//=======================================================================
+void Message_Report::AddLevel (Message_Level* theLevel, const TCollection_AsciiString& theName)
+{
+ myAlertLevels.Append (theLevel);
+
+ Handle(Message_AlertExtended) aLevelRootAlert = new Message_AlertExtended();
+
+ Handle(Message_Attribute) anAttribute;
+ if (!ActiveMetrics().IsEmpty())
+ {
+ anAttribute = new Message_AttributeMeter (theName);
+ }
+ else
+ anAttribute = new Message_Attribute (theName);
+ aLevelRootAlert->SetAttribute (anAttribute);
+ theLevel->SetRootAlert (aLevelRootAlert, myAlertLevels.Size() == 1);
+
+ if (myAlertLevels.Size() == 1) // this is the first level, so root alert should be pushed in the report composite of alerts
+ {
+ compositeAlerts (Standard_True)->AddAlert (Message_Info, theLevel->RootAlert());
+ }
+ if (myAlertLevels.Size() > 1) // this is the first level, so root alert should be pushed in the report composite of alerts
+ {
+ // root alert of next levels should be pushed under the previous level
+ Message_Level* aPrevLevel = myAlertLevels.Value (myAlertLevels.Size() - 1); // previous level
+ aPrevLevel->AddAlert (Message_Info, aLevelRootAlert);
+ }
+}
+
+//=======================================================================
+//function : RemoveLevel
//purpose :
//=======================================================================
-void Message_Report::Clear ()
+void Message_Report::RemoveLevel (Message_Level* theLevel)
{
- for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i)
+ for (int aLevelIndex = myAlertLevels.Size(); aLevelIndex >= 1; aLevelIndex--)
{
- myAlerts[i].Clear();
+ Message_Level* aLevel = myAlertLevels.Value (aLevelIndex);
+ if (myAlertLevels.Size() == 1) // the last level, the root item should be stopped
+ {
+ Message_AttributeMeter::StopAlert (aLevel->RootAlert());
+ }
+ myAlertLevels.Remove (aLevelIndex);
+
+ if (aLevel == theLevel)
+ return;
}
}
//purpose :
//=======================================================================
+void Message_Report::Clear()
+{
+ if (compositeAlerts().IsNull())
+ return;
+
+ compositeAlerts()->Clear();
+ myAlertLevels.Clear();
+}
+
+//=======================================================================
+//function : Clear
+//purpose :
+//=======================================================================
+
void Message_Report::Clear (Message_Gravity theGravity)
{
- Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- "Requesting alerts for gravity not in valid range", );
- myAlerts[theGravity].Clear();
+ if (compositeAlerts().IsNull())
+ return;
+
+ compositeAlerts()->Clear (theGravity);
+ myAlertLevels.Clear();
}
//=======================================================================
void Message_Report::Clear (const Handle(Standard_Type)& theType)
{
- for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i)
- {
- for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); )
- {
- if (anIt.Value().IsNull() || anIt.Value()->IsInstance (theType))
- {
- myAlerts[i].Remove (anIt);
- }
- else
- {
- anIt.More();
- }
- }
- }
+ if (compositeAlerts().IsNull())
+ return;
+
+ compositeAlerts()->Clear (theType);
+ myAlertLevels.Clear();
+}
+
+//=======================================================================
+//function : SetActiveMetric
+//purpose :
+//=======================================================================
+
+void Message_Report::SetActiveMetric (const Message_MetricType theMetricType,
+ const Standard_Boolean theActivate)
+{
+ if (theActivate == myActiveMetrics.Contains (theMetricType))
+ return;
+
+ if (theActivate)
+ myActiveMetrics.Add (theMetricType);
+ else
+ myActiveMetrics.Remove (theMetricType);
}
//=======================================================================
void Message_Report::Dump (Standard_OStream& theOS)
{
- for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
+ for (int aGravIter = Message_Trace; aGravIter <= Message_Fail; ++aGravIter)
{
- Dump (theOS, (Message_Gravity)iGravity);
+ Dump (theOS, (Message_Gravity)aGravIter);
}
}
void Message_Report::Dump (Standard_OStream& theOS, Message_Gravity theGravity)
{
- Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- "Requesting alerts for gravity not in valid range", );
+ if (compositeAlerts().IsNull())
+ return;
- // report each type of warning only once
- NCollection_Map<Handle(Standard_Type)> aPassedAlerts;
- for (Message_ListOfAlert::Iterator anIt (myAlerts[theGravity]); anIt.More(); anIt.Next())
- {
- if (aPassedAlerts.Add (anIt.Value()->DynamicType()))
- {
- Message_Msg aMsg (anIt.Value()->GetMessageKey());
- theOS << aMsg.Original() << std::endl;
- }
- }
+ if (compositeAlerts().IsNull())
+ return;
+
+ dumpMessages (theOS, theGravity, compositeAlerts());
}
//=======================================================================
void Message_Report::SendMessages (const Handle(Message_Messenger)& theMessenger)
{
- for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
+ for (int aGravIter = Message_Trace; aGravIter <= Message_Fail; ++aGravIter)
{
- SendMessages (theMessenger, (Message_Gravity)iGravity);
+ SendMessages (theMessenger, (Message_Gravity)aGravIter);
}
}
void Message_Report::SendMessages (const Handle(Message_Messenger)& theMessenger, Message_Gravity theGravity)
{
- Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- "Requesting alerts for gravity not in valid range", );
+ if (compositeAlerts().IsNull())
+ return;
- // report each type of warning only once
- NCollection_Map<Handle(Standard_Type)> aPassedAlerts;
- for (Message_ListOfAlert::Iterator anIt (myAlerts[theGravity]); anIt.More(); anIt.Next())
- {
- if (aPassedAlerts.Add (anIt.Value()->DynamicType()))
- {
- Message_Msg aMsg (anIt.Value()->GetMessageKey());
- theMessenger->Send (aMsg, theGravity);
- }
- }
+ sendMessages (theMessenger, theGravity, compositeAlerts());
}
//=======================================================================
void Message_Report::Merge (const Handle(Message_Report)& theOther)
{
- for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
+ for (int aGravIter = Message_Trace; aGravIter <= Message_Fail; ++aGravIter)
{
- Merge (theOther, (Message_Gravity)iGravity);
+ Merge (theOther, (Message_Gravity)aGravIter);
}
}
AddAlert (theGravity, anIt.Value());
}
}
+
+//=======================================================================
+//function : CompositeAlerts
+//purpose :
+//=======================================================================
+const Handle(Message_CompositeAlerts)& Message_Report::compositeAlerts (const Standard_Boolean isCreate)
+{
+ if (myCompositAlerts.IsNull() && isCreate)
+ myCompositAlerts = new Message_CompositeAlerts();
+
+ return myCompositAlerts;
+}
+
+//=======================================================================
+//function : sendMessages
+//purpose :
+//=======================================================================
+
+void Message_Report::sendMessages (const Handle(Message_Messenger)& theMessenger, Message_Gravity theGravity,
+ const Handle(Message_CompositeAlerts)& theCompositeAlert)
+{
+ if (theCompositeAlert.IsNull())
+ return;
+
+ const Message_ListOfAlert& anAlerts = theCompositeAlert->Alerts (theGravity);
+ // report each type of warning only once
+ //NCollection_Map<Handle(Standard_Type)> aPassedAlerts;
+ for (Message_ListOfAlert::Iterator anIt (anAlerts); anIt.More(); anIt.Next())
+ {
+ //if (aPassedAlerts.Add (anIt.Value()->DynamicType()))
+ {
+ //Message_Msg aMsg (anIt.Value()->GetMessageKey());
+ //theMessenger->Send (aMsg, theGravity);
+ theMessenger->Send (anIt.Value()->GetMessageKey(), theGravity);
+ }
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (anIt.Value());
+ if (anExtendedAlert.IsNull())
+ continue;
+
+ Handle(Message_CompositeAlerts) aCompositeAlerts = anExtendedAlert->CompositeAlerts();
+ if (aCompositeAlerts.IsNull())
+ continue;
+
+ sendMessages (theMessenger, theGravity, aCompositeAlerts);
+ }
+}
+
+//=======================================================================
+//function : dumpMessages
+//purpose :
+//=======================================================================
+void Message_Report::dumpMessages (Standard_OStream& theOS, Message_Gravity theGravity,
+ const Handle(Message_CompositeAlerts)& theCompositeAlert)
+{
+ if (theCompositeAlert.IsNull())
+ return;
+
+ const Message_ListOfAlert& anAlerts = theCompositeAlert->Alerts (theGravity);
+ // report each type of war++ning only once
+ //NCollection_Map<Handle(Standard_Type)> aPassedAlerts;
+ for (Message_ListOfAlert::Iterator anIt (anAlerts); anIt.More(); anIt.Next())
+ {
+ //if (aPassedAlerts.Add (anIt.Value()->DynamicType()))
+ {
+ //Message_Msg aMsg (anIt.Value()->GetMessageKey());
+ //theOS << aMsg.Original() << std::endl;
+ theOS << anIt.Value()->GetMessageKey() << std::endl;
+ }
+
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (anIt.Value());
+ if (anExtendedAlert.IsNull())
+ continue;
+ dumpMessages (theOS, theGravity, anExtendedAlert->CompositeAlerts());
+ }
+}
+
+//=======================================================================
+//function : writeReport
+//purpose :
+//=======================================================================
+void Message_Report::writeReport()
+{
+ if (myReportWriter.IsNull() || !myWriteFileOnEachAlert)
+ return;
+
+ myReportWriter->ExportReport (this);
+}
#define _Message_Report_HeaderFile
#include <Message_Gravity.hxx>
+#include <Message_Level.hxx>
#include <Message_ListOfAlert.hxx>
+#include <Message_MetricType.hxx>
+#include <NCollection_Map.hxx>
+#include <NCollection_Sequence.hxx>
#include <Standard_Mutex.hxx>
+class Message_CompositeAlerts;
class Message_Messenger;
-
class Message_Report;
-DEFINE_STANDARD_HANDLE(Message_Report, MMgt_TShared)
+class Message_ReportWriter;
+
+DEFINE_STANDARD_HANDLE(Message_Report, Standard_Transient)
//! Container for alert messages, sorted according to their gravity.
//!
//! Dump() or in more advanced way, by iterating over lists returned by GetAlerts()
//!
//! - Report can be cleared by methods Clear() (usually after reporting)
+//!
+//! Message_PrinterToReport is a printer in Messenger to convert data sent to messenger into report
class Message_Report : public Standard_Transient
{
//! Returns true if specific type of alert is recorded with specified gravity
Standard_EXPORT Standard_Boolean HasAlert (const Handle(Standard_Type)& theType, Message_Gravity theGravity);
+ //! Returns true if a report printer for the current report is registered in the messenger
+ // @param theMessenger the messenger. If it's NULL, the default messenger is used
+ Standard_EXPORT Standard_Boolean IsActiveInMessenger (const Handle(Message_Messenger)& theMessenger = NULL) const;
+
+ //! Creates an instance of Message_PrinterToReport with the current report and register it in messenger
+ //! @param toActivate if true, activated else deactivated
+ // @param theMessenger the messenger. If it's NULL, the default messenger is used
+ Standard_EXPORT void ActivateInMessenger (const Standard_Boolean toActivate, const Handle(Message_Messenger)& theMessenger = NULL) const;
+
+ //! Add new level of alerts
+ //! @param theLevel a level
+ Standard_EXPORT void AddLevel (Message_Level* theLevel, const TCollection_AsciiString& theName);
+
+ //! Remove level of alerts
+ Standard_EXPORT void RemoveLevel (Message_Level* theLevel);
+
//! Clears all collected alerts
Standard_EXPORT void Clear ();
//! Clears collected alerts with specified type
Standard_EXPORT void Clear (const Handle(Standard_Type)& theType);
+ //! Returns computed metrics when alerts are performed
+ const NCollection_Map<Message_MetricType>& ActiveMetrics() const { return myActiveMetrics; }
+
+ //! Sets metrics to compute when alerts are performed
+ //! @param theMetrics container of metrics
+ Standard_EXPORT void SetActiveMetric (const Message_MetricType theMetricType, const Standard_Boolean theActivate);
+
+ //! Removes all activated metrics
+ void ClearMetrics() { myActiveMetrics.Clear(); }
+
+ //! Returns maximum number of collecting alerts. If the limit is achieved,
+ //! first alert is removed, the new alert is added in the container.
+ //! @return the limit value
+ Standard_Integer Limit() const { return myLimit; }
+
+ //! Sets maximum number of collecting alerts.
+ //! @param theLimit limit value
+ void SetLimit(const Standard_Integer theLimit) { myLimit = theLimit; }
+
+ //! Returns the message report writer
+ //! @return theWriter a writer
+ const Handle(Message_ReportWriter)& MessageWriter() const { return myReportWriter; }
+
+ //! Sets the message report writer
+ //! @param theWriter a writer
+ void SetMessageWriter (const Handle(Message_ReportWriter)& theWriter) { myReportWriter = theWriter; }
+
+ //! Returns true if the report is written into an output file by a new alert adding
+ //! @return the boolean flag
+ Standard_Boolean WriteFileOnEachAlert() const { return myWriteFileOnEachAlert; }
+
+ //! Sets state if the report should be written into an output file by a new alert adding
+ //! @param theToWrite boolean flag
+ void SetWriteFileOnEachAlert (const Standard_Boolean theToWrite) { myWriteFileOnEachAlert = theToWrite; }
+
//! Dumps all collected alerts to stream
Standard_EXPORT void Dump (Standard_OStream& theOS);
//! Merges alerts with specified gravity from theOther report into this
Standard_EXPORT void Merge (const Handle(Message_Report)& theOther, Message_Gravity theGravity);
- // OCCT RTTI
DEFINE_STANDARD_RTTIEXT(Message_Report,Standard_Transient)
+protected:
+ //! Returns class provided hierarchy of alerts if created or create if the parameter is true
+ //! @param isCreate if composite alert has not been created for this alert, it should be created
+ //! @return instance or NULL
+ Standard_EXPORT const Handle(Message_CompositeAlerts)& compositeAlerts (const Standard_Boolean isCreate = Standard_False);
+
+ //! Sends alerts to messenger
+ Standard_EXPORT void sendMessages (const Handle(Message_Messenger)& theMessenger, Message_Gravity theGravity,
+ const Handle(Message_CompositeAlerts)& theCompositeAlert);
+
+ //! Dumps collected alerts with specified gravity to stream
+ Standard_EXPORT void dumpMessages (Standard_OStream& theOS, Message_Gravity theGravity,
+ const Handle(Message_CompositeAlerts)& theCompositeAlert);
+
+ //! Write message report if writer is not null and WriteFileOnEachAlert is true
+ void writeReport();
+
protected:
Standard_Mutex myMutex;
- // store messages in a lists sorted by gravity;
- // here we rely on knowledge that Message_Fail is the last element of the enum
- Message_ListOfAlert myAlerts[Message_Fail + 1];
+ Handle(Message_CompositeAlerts) myCompositAlerts; //! container of alerts
+ Handle(Message_ReportWriter) myReportWriter; //! store/restore report
+
+ NCollection_Sequence<Message_Level*> myAlertLevels; //! container of active levels, new alerts are added below the latest level
+ NCollection_Map<Message_MetricType> myActiveMetrics; //! metrics to compute on alerts
+
+ Standard_Integer myLimit; //! Maximum number of collected alerts on the top level
+ Standard_Boolean myWriteFileOnEachAlert; //! State if output file should be written on each alert adding
};
#endif // _Message_Report_HeaderFile
--- /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.
+
+#ifndef _Message_ReportWriter_HeaderFile
+#define _Message_ReportWriter_HeaderFile
+
+#include <Standard_Handle.hxx>
+#include <Message_Gravity.hxx>
+#include <TCollection_AsciiString.hxx>
+
+class Message_Report;
+class Message_ReportWriter;
+DEFINE_STANDARD_HANDLE(Message_ReportWriter, Standard_Transient)
+
+//! Base class to store/restore Message_Report content in XML document
+class Message_ReportWriter : public Standard_Transient
+{
+public:
+ //! Constructor
+ Message_ReportWriter() {}
+
+ //! Returns the name of the output file
+ TCollection_AsciiString FileName() const { return myFileName; }
+
+ //! Sets the name of the file for output report
+ //! \param theFileName the name
+ void SetFileName (const TCollection_AsciiString& theFileName) { myFileName = theFileName; }
+
+ //! Returns the gravity of the output messages
+ Message_Gravity Gravity() const { return myGravity; }
+
+ //! Sets the gravity of the output messages
+ void SetGravity (const Message_Gravity theGravity) { myGravity = theGravity; }
+
+ //! Stores the report into a file. The file format is an XML document.
+ //! \param theReport the source report
+ //! \param theFileName a file name
+ //! \return true if success
+ virtual Standard_Boolean ExportReport (const Handle(Message_Report)& theReport) = 0;
+
+ //! 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 true if success
+ virtual Standard_Boolean ImportReport (const Handle(Message_Report)& theReport) = 0;
+
+ DEFINE_STANDARD_RTTI_INLINE(Message_ReportWriter, Standard_Transient)
+
+protected:
+ TCollection_AsciiString myFileName; //! file name
+ Message_Gravity myGravity; //! gravity level of messages
+};
+
+#endif // _Message_ReportWriter_HeaderFile
TopoDS.hxx
TopoDS.lxx
+TopoDS_AlertAttribute.hxx
+TopoDS_AlertAttribute.cxx
TopoDS_Builder.cxx
TopoDS_Builder.hxx
TopoDS_Builder.lxx
--- /dev/null
+// Created on: 2018-06-10
+// Created by: Natalia Ermolaeva
+// Copyright (c) 2017 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 <TopoDS_AlertAttribute.hxx>
+
+#include <Message_PrinterToReport.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(TopoDS_AlertAttribute, Message_Attribute)
+
+//=======================================================================
+//function : TopoDS_AlertAttribute
+//purpose :
+//=======================================================================
+TopoDS_AlertAttribute::TopoDS_AlertAttribute (const TopoDS_Shape& theShape,
+ const TCollection_AsciiString& theName)
+: Message_AttributeStream (Standard_SStream(), theName), myShape (theShape)
+{
+ Standard_SStream aStream;
+ theShape.DumpJson (aStream);
+
+ SetStream (aStream);
+}
+
+//=======================================================================
+//function : Send
+//purpose :
+//=======================================================================
+void TopoDS_AlertAttribute::Send (const Handle(Message_Messenger)& theMessenger,
+ const TopoDS_Shape& theShape)
+{
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (theMessenger->Printers()); aPrinterIter.More(); aPrinterIter.Next())
+ {
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (!aPrinter->IsKind (STANDARD_TYPE (Message_PrinterToReport)))
+ continue;
+
+ Handle (Message_PrinterToReport) aPrinterToReport = Handle(Message_PrinterToReport)::DownCast (aPrinter);
+ const Handle(Message_Report)& aReport = aPrinterToReport->Report();
+
+ //Message_AlertExtended::AddAlert (aReport, new TopoDS_AlertAttribute (theShape, aPrinterToReport->Value()),
+ // Message_Info);
+ }
+}
--- /dev/null
+// Created on: 2018-06-10
+// Created by: Natalia Ermolaeva
+// Copyright (c) 2017 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.
+
+#ifndef _TopoDS_AlertAttribute_HeaderFile
+#define _TopoDS_AlertAttribute_HeaderFile
+
+#include <Message_AttributeStream.hxx>
+#include <Message.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_Report.hxx>
+
+#include <TopoDS_Shape.hxx>
+
+class Message_Messenger;
+
+//! Alert attributre object storing TopoDS shape in its field
+class TopoDS_AlertAttribute : public Message_AttributeStream
+{
+public:
+ //! Constructor with shape argument
+ Standard_EXPORT TopoDS_AlertAttribute (const TopoDS_Shape& theShape,
+ const TCollection_AsciiString& theName = TCollection_AsciiString());
+
+ //! Returns contained shape
+ const TopoDS_Shape& GetShape() const { return myShape; }
+
+ //! Push shape information into messenger
+ Standard_EXPORT static void Send (const Handle(Message_Messenger)& theMessenger,
+ const TopoDS_Shape& theShape);
+
+ // OCCT RTTI
+ DEFINE_STANDARD_RTTIEXT(TopoDS_AlertAttribute, Message_AttributeStream)
+
+private:
+ TopoDS_Shape myShape;
+};
+
+#define MESSAGE_INFO_SHAPE(Shape, Name) \
+ { \
+ if (!Message::DefaultReport().IsNull()) \
+ { \
+ Message_AlertExtended::AddAlert (Message::DefaultReport(), \
+ new TopoDS_AlertAttribute (Shape, Name), Message_Info); \
+ } \
+ }
+
+// HAsciiString
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const TopoDS_Shape& theShape)
+{
+ TopoDS_AlertAttribute::Send (theMessenger, theShape);
+ return theMessenger;
+}
+
+//! @def OCCT_SEND_MESSAGE
+//! Append into messenger result of DumpJson for the field
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for fields of the dumped class which has own DumpJson implementation.
+#define OCCT_SEND_SHAPE(theShape) \
+{ \
+ Message::DefaultMessenger() << theShape; \
+}
+
+#endif // _TopoDS_AlertAttribute_HeaderFile
XmlDrivers_DocumentRetrievalDriver.hxx
XmlDrivers_DocumentStorageDriver.cxx
XmlDrivers_DocumentStorageDriver.hxx
+XmlDrivers_MessageReportStorage.cxx
+XmlDrivers_MessageReportStorage.hxx
--- /dev/null
+// Created on: 2018-06-10
+// Created by: Natalia Ermolaeva
+// Copyright (c) 2001-2014 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 <XmlDrivers_MessageReportStorage.hxx>
+
+#include <Message.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_AttributeMeter.hxx>
+#include <Message_AttributeObject.hxx>
+#include <Message_AttributeStream.hxx>
+#include <Message_CompositeAlerts.hxx>
+#include <Message_Level.hxx>
+#include <Message_Report.hxx>
+
+#include <BinTools.hxx>
+#include <Standard_Dump.hxx>
+
+#include <TCollection.hxx>
+#include <TDataStd_AsciiString.hxx>
+#include <TDataStd_Comment.hxx>
+#include <TDataStd_Real.hxx>
+#include <TDataStd_Name.hxx>
+#include <TDataStd_ExtStringArray.hxx>
+#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_RealArray.hxx>
+#include <TDF_ChildIterator.hxx>
+#include <TDocStd_Application.hxx>
+#include <TDocStd_Document.hxx>
+
+#include <TopoDS_AlertAttribute.hxx>
+
+#include <XmlDrivers.hxx>
+
+// =======================================================================
+// function : GetApplication
+// purpose :
+// =======================================================================
+const Handle(TDocStd_Application)& GetApplication()
+{
+ static Handle(TDocStd_Application) anApp;
+ if (anApp.IsNull())
+ {
+ anApp = new TDocStd_Application;
+ XmlDrivers::DefineFormat (anApp);
+ }
+ return anApp;
+}
+
+// =======================================================================
+// function : ExportReport
+// purpose :
+// =======================================================================
+Standard_Boolean XmlDrivers_MessageReportStorage::ExportReport (const Handle(Message_Report)& theReport)
+{
+
+ if (theReport.IsNull())
+ return Standard_False;
+
+ Handle(TDocStd_Document) aDocument;
+ GetApplication()->NewDocument (TCollection_ExtendedString ("XmlOcaf"), aDocument);
+
+ TDF_Label aMainLabel = aDocument->Main();
+
+ for (int aGravityId = Message_Trace; aGravityId <= Message_Fail; aGravityId++)
+ {
+ Message_Gravity aGravity = (Message_Gravity)aGravityId;
+
+ if (theReport->GetAlerts (aGravity).Size() == 0)
+ continue;
+ // Gravity Label
+ TDF_Label aGravityLabel = aMainLabel.NewChild();
+ // set gravity kind string
+ TCollection_ExtendedString aName (aGravity);
+ if (!aName.IsEmpty())
+ TDataStd_Name::Set (aGravityLabel, aName);
+
+ /// reserved label to store gravity information
+ //TDF_Label aFirstAlertLabel = aGravityLabel.NewChild();
+
+ // Alert Labels: labels are started from the second index
+ const Message_ListOfAlert& anAlerts = theReport->GetAlerts (aGravity);
+ for (Message_ListOfAlert::Iterator anAlertsIt (anAlerts); anAlertsIt.More(); anAlertsIt.Next())
+ {
+ exportAlert (anAlertsIt.Value(), aGravityLabel);
+ }
+ }
+ if (GetApplication()->SaveAs (aDocument, FileName()) != PCDM_SS_OK)
+ return Standard_False;
+
+ GetApplication()->Close (aDocument);
+ return Standard_True;
+}
+
+// =======================================================================
+// function : ImportReport
+// purpose :
+// =======================================================================
+Standard_Boolean XmlDrivers_MessageReportStorage::ImportReport (const Handle(Message_Report)& theReport)
+{
+ theReport->SetLimit(1000);
+
+ Handle(TDocStd_Application) anApplication = GetApplication();
+ Standard_Integer aDocumentId = anApplication->IsInSession (FileName());
+ if (aDocumentId > 0)
+ {
+ Handle(TDocStd_Document) aDocument;
+ anApplication->GetDocument (aDocumentId, aDocument);
+ anApplication->Close (aDocument);
+ }
+
+ Handle(TDocStd_Document) aDocument;
+ GetApplication()->Open (FileName(), aDocument);
+ if (aDocument.IsNull())
+ return Standard_False;
+
+ TDF_Label aMainLabel = aDocument->Main();
+ if (aMainLabel.IsNull())
+ return Standard_False;
+
+ TDF_Label aLabel;
+ for (TDF_ChildIterator aLabelsIt(aMainLabel); aLabelsIt.More(); aLabelsIt.Next())
+ {
+ TDF_Label aGravityLabel = aLabelsIt.Value();
+ if (aGravityLabel.IsNull())
+ continue;
+ Handle(TDF_Attribute) anAttribute;
+ if (!aGravityLabel.FindAttribute (TDataStd_Name::GetID(), anAttribute))
+ continue;
+ Handle(TDataStd_Name) aNameAttribute = Handle(TDataStd_Name)::DownCast (anAttribute);
+ if (aNameAttribute.IsNull())
+ continue;
+
+ // get gravity type
+ const TCollection_ExtendedString& aGravityName = aNameAttribute->Get();
+ Message_Gravity aGravity = (Message_Gravity) (TCollection_AsciiString (aGravityName).IntegerValue());
+
+ /// reserved label to store gravity information
+ //TDF_Label aFirstAlertLabel = aGravityLabel.FindChild (1, Standard_False);
+
+ // find alerts information, add corresponded alerts to the report
+ for (TDF_ChildIterator anAlertLabelsIt (aGravityLabel); anAlertLabelsIt.More(); anAlertLabelsIt.Next())
+ {
+ TDF_Label anAlertLabel = anAlertLabelsIt.Value();
+ if (anAlertLabel.IsNull())
+ continue;
+
+ importAlert (anAlertLabel, aGravity, theReport, Handle(Message_Alert)());
+ }
+ }
+ return Standard_True;
+}
+
+// =======================================================================
+// function : exportAlert
+// purpose :
+// =======================================================================
+void XmlDrivers_MessageReportStorage::exportAlert (const Handle(Message_Alert)& theAlert, const TDF_Label& theParentLabel)
+{
+ TDF_Label anAlertLabel = theParentLabel.NewChild();
+ TDataStd_Name::Set (anAlertLabel, theAlert->DynamicType()->Name());
+
+ /// reserved label to store parameters of the current label
+ TDF_Label anAlertParmetersLabel = anAlertLabel.NewChild();
+ exportAlertParameters (theAlert, anAlertParmetersLabel);
+
+ for (int aGravityId = Message_Trace; aGravityId <= Message_Fail; aGravityId++)
+ {
+ // Gravity Label
+ TDF_Label aGravityLabel = anAlertLabel.NewChild();
+ // set gravity kind string
+ TDataStd_Name::Set (aGravityLabel, aGravityId);
+
+ Handle(Message_AlertExtended) anAlertExtended = Handle(Message_AlertExtended)::DownCast (theAlert);
+ if (anAlertExtended.IsNull())
+ continue;
+ Handle(Message_CompositeAlerts) aComposite = anAlertExtended->CompositeAlerts();
+ if (aComposite.IsNull())
+ continue;
+
+ const Message_ListOfAlert& anAlerts = aComposite->Alerts ((Message_Gravity)aGravityId);
+ for (Message_ListOfAlert::Iterator anAlertsIt (anAlerts); anAlertsIt.More(); anAlertsIt.Next())
+ exportAlert (anAlertsIt.Value(), aGravityLabel);
+ }
+}
+
+// =======================================================================
+// function : importAlert
+// purpose :
+// =======================================================================
+void XmlDrivers_MessageReportStorage::importAlert (const TDF_Label& theAlertLabel,
+ const Message_Gravity theGravity,
+ const Handle(Message_Report)& theReport,
+ const Handle(Message_Alert)& theParentAlert)
+{
+ TDF_Label aParametersLabel = theAlertLabel.FindChild (1, Standard_False);
+ Handle(Message_Alert) anAlert = importAlertParameters (aParametersLabel);
+ if (anAlert.IsNull())
+ return;
+
+ TDF_Label aLabel;
+ TDF_ChildIterator aSubAlertsLabelsIt (theAlertLabel);
+ aSubAlertsLabelsIt.Next(); // do not processing the first (parameters) label
+ for (; aSubAlertsLabelsIt.More(); aSubAlertsLabelsIt.Next())
+ {
+ TDF_Label aGravityLabel = aSubAlertsLabelsIt.Value();
+ if (aGravityLabel.IsNull())
+ continue;
+ Handle(TDF_Attribute) anAttribute;
+ if (!aGravityLabel.FindAttribute (TDataStd_Name::GetID(), anAttribute))
+ continue;
+ Handle(TDataStd_Name) aNameAttribute = Handle(TDataStd_Name)::DownCast (anAttribute);
+ if (aNameAttribute.IsNull())
+ continue;
+
+ // get gravity type
+ Message_Gravity aGravity = (Message_Gravity) (TCollection_AsciiString (aNameAttribute->Get()).IntegerValue());
+ // find alerts information, add corresponded alerts to the report
+ for (TDF_ChildIterator anAlertLabelsIt (aGravityLabel); anAlertLabelsIt.More(); anAlertLabelsIt.Next())
+ {
+ TDF_Label anAlertLabel = anAlertLabelsIt.Value();
+ if (anAlertLabel.IsNull())
+ continue;
+
+ importAlert (anAlertLabel, aGravity, theReport, anAlert);
+ }
+ }
+ if (theParentAlert.IsNull())
+ theReport->AddAlert (theGravity, anAlert);
+ else
+ {
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (theParentAlert);
+ if (anExtendedAlert.IsNull())
+ {
+ theReport->AddAlert (theGravity, anAlert);
+ }
+ else
+ {
+ anExtendedAlert->CompositeAlerts (Standard_True)->AddAlert (theGravity, anAlert);
+ }
+ }
+}
+
+// =======================================================================
+// function : exportAlertParameters
+// purpose :
+// =======================================================================
+void XmlDrivers_MessageReportStorage::exportAlertParameters (const Handle(Message_Alert)& theAlert, const TDF_Label& theAlertLabel)
+{
+ Handle(Message_AlertExtended) anAlertExtended = Handle(Message_AlertExtended)::DownCast (theAlert);
+ if (anAlertExtended.IsNull()) // name attribute is empty
+ return;
+
+ // store attribute time
+ Handle(Message_Attribute) anAttribute = anAlertExtended->Attribute();
+
+ Standard_CString aDynamicTypeName = anAttribute->DynamicType()->Name();
+ TDataStd_Name::Set (theAlertLabel, aDynamicTypeName);
+ //TDataStd_Real::Set (theAlertLabel, anAlertExtended->CumulativeMetric());
+
+ TDataStd_AsciiString::Set (theAlertLabel, anAttribute->GetName());
+
+ TCollection_AsciiString aStreamText;
+ if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeStream)->Name())
+ {
+ Handle(Message_AttributeStream) aValuesArrayAlert = Handle(Message_AttributeStream)::DownCast (anAttribute);
+ aStreamText = Standard_Dump::Text (aValuesArrayAlert->Stream());
+ }
+ else if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeMeter)->Name())
+ {
+ Handle(Message_AttributeMeter) aMeterAttribute = Handle(Message_AttributeMeter)::DownCast (anAttribute);
+
+ Standard_Integer aMetricsCount = 0;
+ for (Standard_Integer aMetricId = (Standard_Integer)Message_MetricType_None; aMetricId <= (Standard_Integer)Message_MetricType_MemHeapUsage; aMetricId++)
+ {
+ if (aMeterAttribute->HasMetric ((Message_MetricType)aMetricId))
+ aMetricsCount++;
+ }
+ if (aMetricsCount > 0)
+ {
+ Handle(TDataStd_IntegerArray) anActiveMetrics = TDataStd_IntegerArray::Set (theAlertLabel, 0, aMetricsCount - 1);
+ Handle(TDataStd_RealArray) aMetricValues = TDataStd_RealArray::Set (theAlertLabel, 0, aMetricsCount * 2 - 1);
+
+ Standard_Integer aCurIndex = 0;
+ for (Standard_Integer aMetricId = (Standard_Integer)Message_MetricType_None; aMetricId <= (Standard_Integer)Message_MetricType_MemHeapUsage; aMetricId++)
+ {
+ Message_MetricType aMetricType = (Message_MetricType)aMetricId;
+ if (!aMeterAttribute->HasMetric (aMetricType))
+ continue;
+
+ anActiveMetrics->SetValue (aCurIndex, aMetricId);
+ aMetricValues->SetValue (2 * aCurIndex, aMeterAttribute->StartValue (aMetricType));
+ aMetricValues->SetValue (2 * aCurIndex + 1, aMeterAttribute->StopValue (aMetricType));
+ aCurIndex++;
+ }
+ }
+ }
+ else if (aDynamicTypeName == STANDARD_TYPE (TopoDS_AlertAttribute)->Name())
+ {
+ Handle(TopoDS_AlertAttribute) aShapeAttribute = Handle(TopoDS_AlertAttribute)::DownCast (anAttribute);
+ Standard_SStream aStream;
+ BinTools::Write (aShapeAttribute->GetShape(), aStream);
+ aStreamText = Standard_Dump::Text (aStream);
+ }
+ if (!aStreamText.IsEmpty())
+ {
+ Handle(TDataStd_ExtStringArray) aListAttribute = TDataStd_ExtStringArray::Set (theAlertLabel, 0, 0);
+ aListAttribute->SetValue (0, aStreamText);
+ }
+}
+
+// =======================================================================
+// function : importAlertParameters
+// purpose :
+// =======================================================================
+Handle(Message_Alert) XmlDrivers_MessageReportStorage::importAlertParameters (const TDF_Label& aParametersLabel)
+{
+ Handle(TDF_Attribute) anAttribute;
+ if (!aParametersLabel.FindAttribute (TDataStd_Name::GetID(), anAttribute))
+ return Handle(Message_Alert)();
+
+ Handle(TDataStd_Name) aDynamicTypeAttribute = Handle(TDataStd_Name)::DownCast (anAttribute);
+ if (aDynamicTypeAttribute.IsNull())
+ return Handle(Message_Alert)();
+ const TCollection_ExtendedString& aDynamicTypeName = aDynamicTypeAttribute->Get();
+
+ Handle(Message_AlertExtended) anAlert = new Message_AlertExtended();
+ Handle(Message_Attribute) aMessageAttribute;
+ if (aDynamicTypeName == STANDARD_TYPE (Message_Attribute)->Name())
+ aMessageAttribute = new Message_Attribute();
+ else if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeStream)->Name() ||
+ aDynamicTypeName == STANDARD_TYPE (TopoDS_AlertAttribute)->Name())
+ {
+ // values
+ if (!aParametersLabel.FindAttribute (TDataStd_ExtStringArray::GetID(), anAttribute))
+ return Handle(Message_Alert)();
+
+ Handle(TDataStd_ExtStringArray) aValuesAttribute = Handle(TDataStd_ExtStringArray)::DownCast (anAttribute);
+ if (aValuesAttribute.IsNull())
+ return Handle(Message_Alert)();
+
+ Standard_SStream aStream;
+ for (int aValueId = aValuesAttribute->Lower(); aValueId <= aValuesAttribute->Upper(); aValueId++)
+ {
+ aStream << aValuesAttribute->Value (aValueId);
+ }
+
+ if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeStream)->Name())
+ {
+ aMessageAttribute = new Message_AttributeStream (aStream);
+ }
+ else if (aDynamicTypeName == STANDARD_TYPE (TopoDS_AlertAttribute)->Name())
+ {
+ TopoDS_Shape aShape;
+ BinTools::Read (aShape, aStream);
+ aMessageAttribute = new TopoDS_AlertAttribute (aShape);
+ }
+ }
+ else if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeMeter)->Name())
+ {
+ Handle (Message_AttributeMeter) aMetricAttribute = new Message_AttributeMeter();
+ // values
+ Handle(TDataStd_IntegerArray) anActiveMetrics;
+ Handle(TDataStd_RealArray) aMetricValues;
+ if (aParametersLabel.FindAttribute (TDataStd_IntegerArray::GetID(), anActiveMetrics) &&
+ aParametersLabel.FindAttribute (TDataStd_RealArray::GetID(), aMetricValues))
+ {
+ for (int aValueId = anActiveMetrics->Lower(); aValueId <= anActiveMetrics->Upper(); aValueId++)
+ {
+ Message_MetricType aMetricType = (Message_MetricType)anActiveMetrics->Value (aValueId);
+
+ Standard_Real aStartValue = aMetricValues->Value (2 * aValueId);
+ Standard_Real aStopValue = aMetricValues->Value (2 * aValueId + 1);
+
+ aMetricAttribute->SetStartValue (aMetricType, aStartValue);
+ aMetricAttribute->SetStopValue (aMetricType, aStopValue);
+ }
+ }
+ aMessageAttribute = aMetricAttribute;
+ }
+
+
+ if (!aMessageAttribute.IsNull())
+ {
+ // name
+ if (!aParametersLabel.FindAttribute (TDataStd_AsciiString::GetID(), anAttribute))
+ return Handle(Message_Alert)();
+ Handle(TDataStd_AsciiString) aNameAttribute = Handle(TDataStd_AsciiString)::DownCast (anAttribute);
+ if (aNameAttribute.IsNull())
+ return Handle(Message_Alert)();
+
+ aMessageAttribute->SetName (aNameAttribute->Get());
+ anAlert->SetAttribute (aMessageAttribute);
+ }
+ return anAlert;
+}
--- /dev/null
+// Created on: 2018-06-10
+// Created by: Natalia Ermolaeva
+// Copyright (c) 2001-2014 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.
+
+#ifndef _XmlDrivers_MessageReportStorage
+#define _XmlDrivers_MessageReportStorage
+
+#include <Standard_Handle.hxx>
+
+#include <Message_ReportWriter.hxx>
+#include <Message_Report.hxx>
+#include <Message_Alert.hxx>
+#include <TDF_Label.hxx>
+
+//! Base class to store/restore Message_Report content in XML document
+class XmlDrivers_MessageReportStorage : public Message_ReportWriter
+{
+public:
+ //! Stores the report into a file. The file format is an XML document.
+ //! \param theReport the source report
+ //! \param theFileName a file name
+ //! \return true if success
+ Standard_EXPORT virtual Standard_Boolean ExportReport (const Handle(Message_Report)& theReport) Standard_OVERRIDE;
+
+ //! 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 true if success
+ Standard_EXPORT virtual Standard_Boolean ImportReport (const Handle(Message_Report)& theReport) Standard_OVERRIDE;
+
+private:
+ //! Create labels/attributes for the alert and place it under the parent label.
+ //! It is recursive as alerts may contains other alerts
+ //! \param theAlert a source alert
+ //! \parm theParentLabel a label where alert label is placed
+ void exportAlert (const Handle(Message_Alert)& theAlert, const TDF_Label& theParentLabel);
+
+ //! Creates a new alert by the label parameters
+ //! \param theAlertLabel a source document label
+ //! \param theGravity an alert gravity
+ //! \param theReport a container of alerts
+ //! \param theParentAlert a parent alert, if null, the parent is report
+ void importAlert (const TDF_Label& theAlertLabel,
+ const Message_Gravity theGravity,
+ 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
+ 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
+ //! \return new alert or NULL
+ static Handle(Message_Alert) importAlertParameters (const TDF_Label& aParametersLabel);
+};
+
+#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
-// Created on: 2020-01-25
+// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
-// Copyright (c) 2020 OPEN CASCADE SAS
+// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
#include <inspector/Convert_Tools.hxx>
#include <inspector/Convert_TransientShape.hxx>
-#include <BRep_Builder.hxx>
+#include <AIS_Plane.hxx>
+#include <AIS_Shape.hxx>
+#include <gp_XY.hxx>
+#include <Geom_Plane.hxx>
+#include <Prs3d_PlaneAspect.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <Standard_Dump.hxx>
#include <BRepTools.hxx>
+#include <BRep_Builder.hxx>
+#include <TopoDS_Compound.hxx>
+#include <BRepPrimAPI_MakeBox.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
// =======================================================================
// function : ReadShape
}
//=======================================================================
-//function : ConvertStreamToPresentations
+//function : CreateShape
//purpose :
//=======================================================================
-void Convert_Tools::ConvertStreamToPresentations (const Standard_SStream&,
- const Standard_Integer,
- const Standard_Integer,
- NCollection_List<Handle(Standard_Transient)>&)
+void Convert_Tools::ConvertStreamToPresentations (const Standard_SStream& theSStream,
+ const Standard_Integer theStartPos,
+ const Standard_Integer /*theLastPos*/,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations)
{
+ int aStartPos = theStartPos;
+
+ gp_XYZ aPoint;
+ if (aPoint.InitFromJson (theSStream, aStartPos))
+ {
+ thePresentations.Append (new Convert_TransientShape (BRepBuilderAPI_MakeVertex (aPoint)));
+ return;
+ }
+
+ gp_Pnt aPnt;
+ if (aPnt.InitFromJson (theSStream, aStartPos))
+ {
+ thePresentations.Append (new Convert_TransientShape (BRepBuilderAPI_MakeVertex (aPnt)));
+ return;
+ }
+
+ gp_Dir aDir;
+ if (aDir.InitFromJson (theSStream, aStartPos))
+ {
+ thePresentations.Append (new Convert_TransientShape (BRepBuilderAPI_MakeEdge (gp::Origin(), aDir.XYZ())));
+ return;
+ }
+
+ gp_Ax2 anAx2;
+ if (anAx2.InitFromJson (theSStream, aStartPos))
+ {
+ Handle(Geom_Plane) aGeomPlane = new Geom_Plane (gp_Ax3 (anAx2));
+ CreatePresentation (aGeomPlane, thePresentations);
+ return;
+ }
+
+ gp_Ax3 anAx3; // should be after gp_Ax2
+ if (anAx3.InitFromJson (theSStream, aStartPos))
+ {
+ Handle(Geom_Plane) aGeomPlane = new Geom_Plane (anAx3);
+ CreatePresentation (aGeomPlane, thePresentations);
+ return;
+ }
+
+ // should be after gp_Ax3
+ gp_Ax1 anAxis;
+ if (anAxis.InitFromJson (theSStream, aStartPos))
+ {
+ thePresentations.Append (new Convert_TransientShape (BRepBuilderAPI_MakeEdge (anAxis.Location(), anAxis.Location().Coord() + anAxis.Direction().XYZ())));
+ return;
+ }
+
+ gp_Trsf aTrsf;
+ if (aTrsf.InitFromJson (theSStream, aStartPos))
+ {
+ CreatePresentation (aTrsf, thePresentations);
+ return;
+ }
+
+ Bnd_Box aBox;
+ if (aBox.InitFromJson (theSStream, aStartPos))
+ {
+ TopoDS_Shape aShape;
+ if (Convert_Tools::CreateShape (aBox, aShape))
+ thePresentations.Append (new Convert_TransientShape (aShape));
+ return;
+ }
Select3D_BndBox3d aSelectBndBox;
if (aSelectBndBox.InitFromJson (theSStream, aStartPos))
//function : ConvertStreamToColor
//purpose :
//=======================================================================
-Standard_Boolean Convert_Tools::ConvertStreamToColor (const Standard_SStream&,
- Quantity_Color&)
+Standard_Boolean Convert_Tools::ConvertStreamToColor (const Standard_SStream& theSStream,
+ Quantity_Color& theColor)
{
+ Standard_Integer aStartPos = 1;
+ Quantity_ColorRGBA aColorRGBA;
+ if (aColorRGBA.InitFromJson (theSStream, aStartPos))
+ {
+ theColor = aColorRGBA.GetRGB();
+ return Standard_True;
+ }
+
+ Quantity_Color aColor;
+ if (aColor.InitFromJson (theSStream, aStartPos))
+ {
+ theColor = aColor;
+ return Standard_True;
+ }
+
return Standard_False;
}
+
+//=======================================================================
+//function : CreateShape
+//purpose :
+//=======================================================================
+Standard_Boolean Convert_Tools::CreateShape (const Bnd_Box& theBoundingBox, TopoDS_Shape& theShape)
+{
+ if (theBoundingBox.IsVoid() || theBoundingBox.IsWhole())
+ return Standard_False;
+
+ Standard_Real aXmin, anYmin, aZmin, aXmax, anYmax, aZmax;
+ theBoundingBox.Get (aXmin, anYmin, aZmin, aXmax, anYmax, aZmax);
+
+ gp_Pnt aPntMin = gp_Pnt (aXmin, anYmin, aZmin);
+ gp_Pnt aPntMax = gp_Pnt (aXmax, anYmax, aZmax);
+
+ return CreateBoxShape (aPntMin, aPntMax, theShape);
+}
+
+//=======================================================================
+//function : CreateShape
+//purpose :
+//=======================================================================
+Standard_Boolean Convert_Tools::CreateShape (const Bnd_OBB& theBoundingBox, TopoDS_Shape& theShape)
+{
+ if (theBoundingBox.IsVoid())
+ return Standard_False;
+
+ TColgp_Array1OfPnt anArrPnts(0, 8);
+ theBoundingBox.GetVertex(&anArrPnts(0));
+
+ BRep_Builder aBuilder;
+ TopoDS_Compound aCompound;
+ aBuilder.MakeCompound (aCompound);
+
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt (anArrPnts.Value(0)), gp_Pnt (anArrPnts.Value(1))));
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt (anArrPnts.Value(0)), gp_Pnt (anArrPnts.Value(2))));
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt (anArrPnts.Value(1)), gp_Pnt (anArrPnts.Value(3))));
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (gp_Pnt (anArrPnts.Value(2)), gp_Pnt (anArrPnts.Value(3))));
+
+ theShape = aCompound;
+ return Standard_True;
+}
+
+//=======================================================================
+//function : CreateBoxShape
+//purpose :
+//=======================================================================
+Standard_Boolean Convert_Tools::CreateBoxShape (const gp_Pnt& thePntMin, const gp_Pnt& thePntMax, TopoDS_Shape& theShape)
+{
+ Standard_Boolean aThinOnX = fabs (thePntMin.X() - thePntMax.X()) < Precision::Confusion();
+ Standard_Boolean aThinOnY = fabs (thePntMin.Y() - thePntMax.Y()) < Precision::Confusion();
+ Standard_Boolean aThinOnZ = fabs (thePntMin.Z() - thePntMax.Z()) < Precision::Confusion();
+
+ if (((int)aThinOnX + (int)aThinOnY + (int)aThinOnZ) > 1) // thin box in several directions is a point
+ {
+ BRep_Builder aBuilder;
+ TopoDS_Compound aCompound;
+ aBuilder.MakeCompound (aCompound);
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeVertex (thePntMin));
+ theShape = aCompound;
+ return Standard_True;
+ }
+
+ if (aThinOnX || aThinOnY || aThinOnZ)
+ {
+ gp_Pnt aPnt1, aPnt2, aPnt3, aPnt4 ;
+ if (aThinOnX)
+ {
+ aPnt1 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMin.Z());
+ aPnt2 = gp_Pnt(thePntMin.X(), thePntMax.Y(), thePntMin.Z());
+ aPnt3 = gp_Pnt(thePntMin.X(), thePntMax.Y(), thePntMax.Z());
+ aPnt4 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMax.Z());
+ }
+ else if (aThinOnY)
+ {
+ aPnt1 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMin.Z());
+ aPnt2 = gp_Pnt(thePntMax.X(), thePntMin.Y(), thePntMin.Z());
+ aPnt3 = gp_Pnt(thePntMax.X(), thePntMin.Y(), thePntMax.Z());
+ aPnt4 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMax.Z());
+ }
+ else if (aThinOnZ)
+ {
+ aPnt1 = gp_Pnt(thePntMin.X(), thePntMin.Y(), thePntMin.Z());
+ aPnt2 = gp_Pnt(thePntMax.X(), thePntMin.Y(), thePntMin.Z());
+ aPnt3 = gp_Pnt(thePntMax.X(), thePntMax.Y(), thePntMin.Z());
+ aPnt4 = gp_Pnt(thePntMin.X(), thePntMax.Y(), thePntMin.Z());
+ }
+ BRep_Builder aBuilder;
+ TopoDS_Compound aCompound;
+ aBuilder.MakeCompound (aCompound);
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (aPnt1, aPnt2));
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (aPnt2, aPnt3));
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (aPnt3, aPnt4));
+ aBuilder.Add (aCompound, BRepBuilderAPI_MakeEdge (aPnt4, aPnt1));
+
+ theShape = aCompound;
+ return Standard_True;
+ }
+ else
+ {
+ BRepPrimAPI_MakeBox aBoxBuilder (thePntMin, thePntMax);
+ theShape = aBoxBuilder.Shape();
+ return Standard_True;
+ }
+}
+
+//=======================================================================
+//function : CreatePresentation
+//purpose :
+//=======================================================================
+void Convert_Tools::CreatePresentation (const Handle(Geom_Plane)& thePlane,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations)
+{
+ Handle(AIS_Plane) aPlanePrs = new AIS_Plane (thePlane);
+
+ // TODO - default fields to be defined in another place
+ aPlanePrs->Attributes()->SetPlaneAspect (new Prs3d_PlaneAspect());
+ Handle (Prs3d_PlaneAspect) aPlaneAspect = aPlanePrs->Attributes()->PlaneAspect();
+ aPlaneAspect->SetPlaneLength (100, 100);
+ aPlaneAspect->SetDisplayCenterArrow (Standard_True);
+ aPlaneAspect->SetDisplayEdgesArrows (Standard_True);
+ aPlaneAspect->SetArrowsSize (100);
+ aPlaneAspect->SetArrowsLength (100);
+ aPlaneAspect->SetDisplayCenterArrow (Standard_True);
+ aPlaneAspect->SetDisplayEdges (Standard_True);
+
+ aPlanePrs->SetColor (Quantity_NOC_WHITE);
+ aPlanePrs->SetTransparency (0);
+
+ thePresentations.Append (aPlanePrs);
+}
+
+//=======================================================================
+//function : CreatePresentation
+//purpose :
+//=======================================================================
+void Convert_Tools::CreatePresentation (const gp_Trsf& theTrsf,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations)
+{
+ Bnd_Box aBox (gp_Pnt(), gp_Pnt(10., 10., 10));
+
+ TopoDS_Shape aBoxShape;
+ if (!Convert_Tools::CreateShape (aBox, aBoxShape))
+ return;
+
+ Handle(AIS_Shape) aSourcePrs = new AIS_Shape (aBoxShape);
+ // TODO - default fields to be defined in another place
+ aSourcePrs->SetColor (Quantity_NOC_WHITE);
+ aSourcePrs->SetTransparency (0.5);
+ thePresentations.Append (aSourcePrs);
+
+ Handle(AIS_Shape) aTransformedPrs = new AIS_Shape (aBoxShape);
+ // TODO - default fields to be defined in another place
+ aTransformedPrs->SetColor (Quantity_NOC_TOMATO);
+ aTransformedPrs->SetTransparency (0.5);
+ aTransformedPrs->SetLocalTransformation (theTrsf);
+ thePresentations.Append (aTransformedPrs);
+}
-// Created on: 2020-01-25
+// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
-// Copyright (c) 2020 OPEN CASCADE SAS
+// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
#ifndef Convert_Tools_H
#define Convert_Tools_H
+#include <gp_Dir.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Trsf.hxx>
+#include <gp_XYZ.hxx>
+#include <Bnd_Box.hxx>
+#include <Bnd_OBB.hxx>
#include <NCollection_List.hxx>
#include <Quantity_Color.hxx>
#include <Standard.hxx>
#include <Standard_Macro.hxx>
-#include <Standard_SStream.hxx>
+#include <TColgp_HArray1OfPnt.hxx>
+#include <Standard_Dump.hxx>
#include <TCollection_AsciiString.hxx>
+#include <TopLoc_Location.hxx>
#include <TopoDS_Shape.hxx>
+#include <Standard_SStream.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QString>
+#include <QVariant>
+#include <Standard_WarningsRestore.hxx>
+
+class Geom_Plane;
+class Geom_Transformation;
//! \class Convert_Tools
-//! \brief The tool that gives auxiliary methods converting.
+//! \brief The tool that gives auxiliary methods for qt elements manipulation
class Convert_Tools
{
public:
//! \returns true if done
Standard_EXPORT static Standard_Boolean ConvertStreamToColor (const Standard_SStream& theSStream,
Quantity_Color& theColor);
+
+ //! Creates box shape
+ //! \param theBoundingBox box shape parameters
+ //! \return created shape
+ Standard_EXPORT static Standard_Boolean CreateShape (const Bnd_Box& theBoundingBox, TopoDS_Shape& theShape);
+
+ //! Creates box shape
+ //! \param theBoundingBox box shape parameters
+ //! \return created shape
+ Standard_EXPORT static Standard_Boolean CreateShape (const Bnd_OBB& theBoundingBox, TopoDS_Shape& theShape);
+
+ //! Creates box shape
+ //! \param thePntMin minimum point on the bounding box
+ //! \param thePntMax maximum point on the bounding box
+ //! \return created shape
+ Standard_EXPORT static Standard_Boolean CreateBoxShape (const gp_Pnt& thePntMin, const gp_Pnt& thePntMax, TopoDS_Shape& theShape);
+
+ //! Creates presentation AIS_Plane
+ //! \param thePlane source plane
+ //! \param thePresentations container to collect new presentation/s
+ Standard_EXPORT static void CreatePresentation (const Handle(Geom_Plane)& thePlane,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations);
+
+ //! Creates two presentations base on gp_Trsf: box in initial place and transformed box
+ //! \param thePlane source plane
+ //! \param thePresentations container to collect new presentation/s
+ Standard_EXPORT static void CreatePresentation (const gp_Trsf& theTrsf,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations);
+
};
#endif
--- /dev/null
+MessageModel.qrc
+MessageModel_Actions.cxx
+MessageModel_Actions.hxx
+MessageModel_ActionType.hxx
+MessageModel_ItemAlert.cxx
+MessageModel_ItemAlert.hxx
+MessageModel_ItemBase.cxx
+MessageModel_ItemBase.hxx
+MessageModel_ItemReport.cxx
+MessageModel_ItemReport.hxx
+MessageModel_ItemRoot.cxx
+MessageModel_ItemRoot.hxx
+MessageModel_Tools.cxx
+MessageModel_Tools.hxx
+MessageModel_TreeModel.cxx
+MessageModel_TreeModel.hxx
--- /dev/null
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>icons/item_shape.png</file>
+ <file>icons/item_streamValues.png</file>
+ </qresource>
+</RCC>
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageModel_ActionType_H
+#define MessageModel_ActionType_H
+
+//! Kind of action type for tree view context menu item
+enum MessageModel_ActionType
+{
+ MessageModel_ActionType_Activate, //!< set Message_Report active
+ MessageModel_ActionType_Deactivate, //!< set Message_Report not active
+ MessageModel_ActionType_Clear, //!< clear Message_Report alerts
+ MessageModel_ActionType_ExportToShapeView, //!< export TopoDS_Shape of selected item into TKShapeView plugin
+ MessageModel_ActionType_TestMetric, //!< test alerts
+ MessageModel_ActionType_TestProperties, //!< test alerts
+ MessageModel_ActionType_TestMessenger, //!< test message view on messenger printer to report
+ MessageModel_ActionType_TestReportTree, //!< test message view on hierarchical report
+ MessageModel_ActionType_TestReportTree2 //!< test message view on hierarchical report
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageModel_Actions.hxx>
+
+#include <inspector/MessageModel_ItemReport.hxx>
+#include <inspector/MessageModel_ItemRoot.hxx>
+#include <inspector/MessageModel_ItemAlert.hxx>
+#include <inspector/MessageModel_Tools.hxx>
+#include <inspector/MessageModel_TreeModel.hxx>
+#include <inspector/TInspectorAPI_PluginParameters.hxx>
+#include <inspector/ViewControl_Tools.hxx>
+
+#include <Message.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_PrinterToReport.hxx>
+
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <OSD_Chronometer.hxx>
+#include <Quantity_Color.hxx>
+#include <Quantity_ColorRGBA.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TopoDS_AlertAttribute.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QAction>
+#include <QFileDialog>
+#include <QItemSelectionModel>
+#include <QMenu>
+#include <QMessageBox>
+#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
+
+// =======================================================================
+// function : Constructor
+// purpose :
+// =======================================================================
+MessageModel_Actions::MessageModel_Actions (QWidget* theParent,
+ MessageModel_TreeModel* theTreeModel, QItemSelectionModel* theModel)
+: QObject (theParent), myTreeModel (theTreeModel), mySelectionModel (theModel)
+{
+ myActions.insert (MessageModel_ActionType_Activate,
+ ViewControl_Tools::CreateAction ("Activate", SLOT (OnActivateReport()), parent(), this));
+ myActions.insert (MessageModel_ActionType_Deactivate,
+ ViewControl_Tools::CreateAction ("Deactivate", SLOT (OnDeactivateReport()), parent(), this));
+ myActions.insert (MessageModel_ActionType_Clear,
+ ViewControl_Tools::CreateAction ("Clear", SLOT (OnClearReport()), parent(), this));
+ myActions.insert (MessageModel_ActionType_ExportToShapeView,
+ ViewControl_Tools::CreateAction (tr ("Export to ShapeView"), SLOT (OnExportToShapeView()), parent(), this));
+}
+
+// =======================================================================
+// function : GetAction
+// purpose :
+// =======================================================================
+QAction* MessageModel_Actions::GetAction (const MessageModel_ActionType& theType)
+{
+ if (myActions.contains (theType))
+ return myActions[theType];
+
+ return 0;
+}
+
+// =======================================================================
+// function : AddMenuActions
+// purpose :
+// =======================================================================
+void MessageModel_Actions::AddMenuActions (const QModelIndexList& theSelectedIndices, QMenu* theMenu)
+{
+ MessageModel_ItemRootPtr aRootItem;
+ MessageModel_ItemReportPtr aReportItem;
+ MessageModel_ItemAlertPtr anAlertItem;
+ for (QModelIndexList::const_iterator aSelIt = theSelectedIndices.begin(); aSelIt != theSelectedIndices.end(); aSelIt++)
+ {
+ QModelIndex anIndex = *aSelIt;
+ if (anIndex.column() != 0)
+ continue;
+
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ continue;
+
+ aRootItem = itemDynamicCast<MessageModel_ItemRoot> (anItemBase);
+ if (aRootItem)
+ break;
+
+ aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
+ if (aReportItem)
+ break;
+
+ anAlertItem = itemDynamicCast<MessageModel_ItemAlert> (anItemBase);
+ if (anAlertItem)
+ break;
+ }
+
+ if (aReportItem && !aReportItem->GetReport().IsNull())
+ {
+ theMenu->addAction (myActions[MessageModel_ActionType_Deactivate]);
+ theMenu->addAction (myActions[MessageModel_ActionType_Activate]);
+ theMenu->addAction (myActions[MessageModel_ActionType_Clear]);
+ }
+ else if (anAlertItem)
+ {
+ theMenu->addAction (myActions[MessageModel_ActionType_ExportToShapeView]);
+ }
+
+ theMenu->addSeparator();
+}
+
+// =======================================================================
+// function : getSelectedReport
+// purpose :
+// =======================================================================
+Handle(Message_Report) MessageModel_Actions::getSelectedReport (QModelIndex& theReportIndex) const
+{
+ MessageModel_ItemReportPtr aReportItem;
+ QModelIndexList aSelectedIndices = mySelectionModel->selectedIndexes();
+ for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
+ {
+ QModelIndex anIndex = *aSelIt;
+ if (anIndex.column() != 0)
+ continue;
+
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ continue;
+
+ aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
+ theReportIndex = anIndex;
+ if (aReportItem)
+ break;
+ }
+ if (!aReportItem)
+ return NULL;
+
+ return aReportItem->GetReport();
+}
+
+// =======================================================================
+// function : OnActivateReport
+// purpose :
+// =======================================================================
+static Handle(Message_PrinterToReport) MyPrinterToReport;
+static Message_SequenceOfPrinters MyDeactivatedPrinters;
+
+void MessageModel_Actions::OnActivateReport()
+{
+ if (MyPrinterToReport.IsNull())
+ MyPrinterToReport = new Message_PrinterToReport();
+
+ if (MyPrinterToReport->Report()->IsActiveInMessenger())
+ return;
+
+ MyDeactivatedPrinters = Message::DefaultMessenger()->Printers();
+ Message::DefaultMessenger()->ChangePrinters().Clear();
+
+ Message::DefaultMessenger()->AddPrinter (MyPrinterToReport);
+ Message::DefaultMessenger()->SetTraceLevel (1);
+
+ myTreeModel->UpdateTreeModel();
+}
+
+// =======================================================================
+// function : OnDeactivateReport
+// purpose :
+// =======================================================================
+void MessageModel_Actions::OnDeactivateReport()
+{
+ if (MyPrinterToReport.IsNull() || !MyPrinterToReport->Report()->IsActiveInMessenger())
+ return;
+
+ Message::DefaultMessenger()->RemovePrinter (MyPrinterToReport);
+ Message::DefaultMessenger()->ChangePrinters().Assign (MyDeactivatedPrinters);
+
+ myTreeModel->UpdateTreeModel();
+}
+
+// =======================================================================
+// function : OnClearReport
+// purpose :
+// =======================================================================
+void MessageModel_Actions::OnClearReport()
+{
+ QModelIndex aReportIndex;
+ Handle(Message_Report) aReport = getSelectedReport (aReportIndex);
+ if (aReport.IsNull())
+ return;
+
+ aReport->Clear();
+ myTreeModel->UpdateTreeModel();
+}
+
+// =======================================================================
+// function : OnExportToShapeView
+// purpose :
+// =======================================================================
+void MessageModel_Actions::OnExportToShapeView()
+{
+ TCollection_AsciiString aPluginName ("TKShapeView");
+
+ NCollection_List<Handle(Standard_Transient)> aPluginParameters;
+ if (myParameters->FindParameters (aPluginName))
+ aPluginParameters = myParameters->Parameters (aPluginName);
+ NCollection_List<TCollection_AsciiString> anItemNames;
+ if (myParameters->FindSelectedNames (aPluginName))
+ anItemNames = myParameters->GetSelectedNames (aPluginName);
+
+ QModelIndexList aSelectedIndices = mySelectionModel->selectedIndexes();
+ QStringList anExportedPointers;
+ for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
+ {
+ QModelIndex anIndex = *aSelIt;
+ if (anIndex.column() != 0)
+ continue;
+
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ continue;
+
+ MessageModel_ItemAlertPtr anAlertItem = itemDynamicCast<MessageModel_ItemAlert> (anItemBase);
+ if (!anAlertItem)
+ continue;
+
+ Handle(Message_Alert) anAlert = anAlertItem->GetAlert();
+ if (anAlert.IsNull())
+ continue;
+
+ Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (anAlert);
+ if (anExtAlert.IsNull())
+ continue;
+
+ Handle(Message_Attribute) anAttribute = anExtAlert->Attribute();
+ if (anAttribute.IsNull())
+ continue;
+
+ if (!anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute)))
+ continue;
+
+ const TopoDS_Shape aShape = Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape();
+ if (aShape.IsNull())
+ continue;
+ aPluginParameters.Append (aShape.TShape());
+ anItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
+
+ anExportedPointers.append (MessageModel_Tools::GetPointerInfo (aShape.TShape(), true).ToCString());
+ }
+
+ if (anExportedPointers.empty())
+ return;
+ myParameters->SetSelectedNames (aPluginName, anItemNames);
+ myParameters->SetParameters (aPluginName, aPluginParameters);
+ QMessageBox::information (0, "Information", QString ("TShapes '%1' are sent to %2 tool.")
+ .arg (anExportedPointers.join (", ")).arg (QString (aPluginName.ToCString())));
+}
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageModel_Actions_H
+#define MessageModel_Actions_H
+
+#include <Standard.hxx>
+#include <Standard_Transient.hxx>
+
+#include <inspector/MessageModel_ActionType.hxx>
+#include <inspector/TInspectorAPI_PluginParameters.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QObject>
+#include <QMap>
+#include <QModelIndexList>
+#include <QPoint>
+#include <QString>
+#include <Standard_WarningsRestore.hxx>
+
+class Message_Report;
+class MessageModel_TreeModel;
+
+class QAction;
+class QItemSelectionModel;
+class QMenu;
+class QWidget;
+
+//! \class MessageModel_Actions
+//! \brief This is a listener of popup context menu items and selection change in message model
+class MessageModel_Actions : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ //! Constructor
+ Standard_EXPORT MessageModel_Actions (QWidget* theParent,
+ MessageModel_TreeModel* theTreeModel,
+ QItemSelectionModel* theModel);
+
+ //! Destructor
+ virtual ~MessageModel_Actions() Standard_OVERRIDE {}
+
+ //! Returns action by the type
+ //! \param theType an action type
+ //! \return an action instance if it exists
+ Standard_EXPORT QAction* GetAction (const MessageModel_ActionType& theType);
+
+ //! Fills popup menu with actions depending on the current selection
+ //! \param theSelectedIndices tree model selected indices
+ //! \param theMenu menu to be filled
+ Standard_EXPORT void AddMenuActions (const QModelIndexList& theSelectedIndices, QMenu* theMenu);
+
+ //! Sets parameters container, it should be used when the plugin is initialized or in update content
+ //! \param theParameters a parameters container
+ void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters)
+ { myParameters = theParameters; }
+
+public slots:
+ //! Set selected report active
+ void OnActivateReport();
+
+ //! Set selected report not active
+ void OnDeactivateReport();
+
+ //! Clears container of alerts of selected report
+ void OnClearReport();
+
+ //! Exports the first selected shape into ShapeViewer plugin.
+ void OnExportToShapeView();
+
+protected:
+ //! Returns report of selected tree view item if a report item is selected
+ //! \param theReportIndex tree model index of the found report
+ //! \return report instance or NULL
+ Handle(Message_Report) getSelectedReport (QModelIndex& theReportIndex) const;
+
+protected:
+ MessageModel_TreeModel* myTreeModel; //< tree model
+ QItemSelectionModel* mySelectionModel; //< selection model
+ Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
+ QMap<MessageModel_ActionType, QAction*> myActions; //!< container of all actions
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageModel_ItemAlert.hxx>
+
+#include <inspector/MessageModel_ItemRoot.hxx>
+#include <inspector/MessageModel_ItemReport.hxx>
+#include <inspector/MessageModel_Tools.hxx>
+#include <inspector/MessageModel_TreeModel.hxx>
+
+#include <inspector/ViewControl_Tools.hxx>
+#include <inspector/Convert_TransientShape.hxx>
+#include <inspector/TreeModel_ItemProperties.hxx>
+#include <inspector/TreeModel_Tools.hxx>
+
+#include <Message_AlertExtended.hxx>
+#include <Message_AttributeObject.hxx>
+#include <Message_AttributeMeter.hxx>
+#include <Message_AttributeStream.hxx>
+#include <Message_CompositeAlerts.hxx>
+
+#include <Bnd_Box.hxx>
+#include <Precision.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TopoDS_AlertAttribute.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QColor>
+#include <QIcon>
+#include <Standard_WarningsRestore.hxx>
+
+
+// =======================================================================
+// function : initValue
+// purpose :
+// =======================================================================
+QVariant MessageModel_ItemAlert::initValue (const int theRole) const
+{
+ QVariant aParentValue = MessageModel_ItemBase::initValue (theRole);
+ if (aParentValue.isValid())
+ return aParentValue;
+
+ MessageModel_ItemReportPtr aReportItem = MessageModel_ItemReport::FindReportItem (Parent());
+ if (!aReportItem)
+ return QVariant();
+
+ Handle(Message_Report) aReport = aReportItem->GetReport();
+ if (aReport.IsNull())
+ return QVariant();
+
+ if (theRole == Qt::ForegroundRole)
+ {
+ if (!aReport->IsActiveInMessenger())
+ return QColor(Qt::darkGray);
+
+ return QVariant();
+ }
+
+ Handle(Message_Alert) anAlert = getAlert();
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(anAlert);
+
+ // if the alert is composite, process the real alert
+ if (theRole == Qt::DecorationRole && Column() == 0)
+ {
+ if (anExtendedAlert.IsNull())
+ return QVariant();
+
+ Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute();
+ if (anAttribute.IsNull())
+ return QVariant();
+
+ if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute)))
+ return QIcon (":/icons/item_shape.png");
+ else if (!Handle(Message_AttributeStream)::DownCast (anAttribute).IsNull())
+ return QIcon (":/icons/item_streamValues.png");
+ else
+ return QVariant();
+ }
+
+ if (theRole != Qt::DisplayRole && theRole != Qt::ToolTipRole)
+ return QVariant();
+
+ if (anAlert.IsNull())
+ return QVariant();
+
+ if (Column() == 0)
+ {
+ if (theRole == Qt::DisplayRole)
+ {
+ TCollection_AsciiString aMessageKey = anAlert->GetMessageKey();
+ if (aMessageKey.IsEmpty() && !Properties().IsNull())
+ aMessageKey = Properties()->Key();
+ return aMessageKey.ToCString();
+ }
+ else
+ return anAlert->DynamicType()->Name();
+ }
+
+ Message_MetricType aMetricType;
+ int aPosition;
+ if (MessageModel_TreeModel::IsMetricColumn (Column(), aMetricType, aPosition))
+ {
+ if (anExtendedAlert.IsNull())
+ return QVariant();
+
+ Handle(Message_AttributeMeter) anAttribute = Handle(Message_AttributeMeter)::DownCast (anExtendedAlert->Attribute());
+ if (anAttribute.IsNull() || !anAttribute->HasMetric (aMetricType))
+ return QVariant();
+
+ if (aMetricType == Message_MetricType_UserTimeCPU ||
+ aMetricType == Message_MetricType_SystemTimeInfo)
+ {
+ Standard_Real aCumulativeMetric = anAttribute->StopValue (aMetricType) - anAttribute->StartValue (aMetricType);
+ if (fabs (aCumulativeMetric) < Precision::Confusion())
+ return QVariant();
+
+ if (aPosition == 0) return aCumulativeMetric;
+ else if (aPosition == 1)
+ {
+ Standard_Real aReportCumulativeMetric = MessageModel_ItemReport::CumulativeMetric (aReport, aMetricType);
+ if (fabs (aReportCumulativeMetric) > Precision::Confusion())
+ return 100. * aCumulativeMetric / aReportCumulativeMetric;
+ else
+ return QVariant();
+ }
+ }
+ else
+ {
+ if (aPosition == 0) return anAttribute->StopValue (aMetricType);
+ else if (aPosition == 1)
+ {
+ Standard_Real aCumulativeMetric = anAttribute->StopValue (aMetricType) - anAttribute->StartValue (aMetricType);
+ if (fabs (aCumulativeMetric) < Precision::Confusion())
+ return QVariant();
+ else
+ return aCumulativeMetric;
+ }
+
+ }
+ }
+ return QVariant();
+}
+
+// =======================================================================
+// function : initRowCount
+// purpose :
+// =======================================================================
+int MessageModel_ItemAlert::initRowCount() const
+{
+ const Handle(Message_Alert)& anAlert = getAlert();
+ if (anAlert.IsNull())
+ return 0;
+
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(anAlert);
+ if (anExtendedAlert.IsNull())
+ return 0;
+
+ Handle(Message_CompositeAlerts) aCompositeAlert = anExtendedAlert->CompositeAlerts();
+ if (aCompositeAlert.IsNull())
+ return 0;
+
+ MessageModel_ItemAlert* aCurrentItem = (MessageModel_ItemAlert*)this;
+ for (int aGravityId = Message_Trace; aGravityId <= Message_Fail; aGravityId++)
+ {
+ const Message_ListOfAlert& anAlerts = aCompositeAlert->Alerts ((Message_Gravity)aGravityId);
+ {
+ for (Message_ListOfAlert::Iterator anIt(anAlerts); anIt.More(); anIt.Next())
+ {
+ Message_ListOfAlert aCurAlerts;
+ aCurAlerts.Append (anIt.Value());
+ aCurrentItem->myChildAlerts.Bind(myChildAlerts.Size(), aCurAlerts);
+ }
+ }
+ }
+
+ return aCurrentItem->myChildAlerts.Size();
+}
+
+// =======================================================================
+// function : initStream
+// purpose :
+// =======================================================================
+void MessageModel_ItemAlert::initStream (Standard_OStream& OS) const
+{
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (getAlert());
+ if (anExtendedAlert.IsNull() || anExtendedAlert->Attribute().IsNull())
+ return;
+
+ Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute();
+ if (anAttribute.IsNull())
+ return;
+
+ if (Handle(Message_AttributeStream)::DownCast(anAttribute).IsNull())
+ return;
+
+ Handle(Message_AttributeStream) anAttributeStream = Handle(Message_AttributeStream)::DownCast (anExtendedAlert->Attribute());
+ OS << anAttributeStream->Stream().str();
+}
+
+// =======================================================================
+// function : SetStream
+// purpose :
+// =======================================================================
+bool MessageModel_ItemAlert::SetStream (const Standard_SStream& theSStream, Standard_Integer& theStartPos,
+ Standard_Integer& theLastPos) const
+{
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (getAlert());
+ if (anExtendedAlert.IsNull() || anExtendedAlert->Attribute().IsNull())
+ return false;
+
+ Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute();
+ if (anAttribute.IsNull())
+ return false;
+
+ if (Handle(Message_AttributeStream)::DownCast(anAttribute).IsNull())
+ return false;
+
+ Handle(Message_AttributeStream) anAttributeStream = Handle(Message_AttributeStream)::DownCast (anExtendedAlert->Attribute());
+ TCollection_AsciiString aStreamValue = Standard_Dump::Text (anAttributeStream->Stream());
+
+ TCollection_AsciiString aNewValue = Standard_Dump::Text (theSStream);
+
+ Standard_SStream aStream;
+ aStream << aStreamValue.SubString (1, theStartPos - 1);
+ aStream << aNewValue;
+ if (theLastPos + 1 <= aStreamValue.Length())
+ aStream << aStreamValue.SubString (theLastPos + 1, aStreamValue.Length());
+
+ //TCollection_AsciiString aStreamValue_debug = Standard_Dump::Text (aStream);
+
+ anAttributeStream->SetStream (aStream);
+
+ return true;
+}
+
+// =======================================================================
+// function : createChild
+// purpose :
+// =======================================================================
+TreeModel_ItemBasePtr MessageModel_ItemAlert::createChild (int theRow, int theColumn)
+{
+ return MessageModel_ItemAlert::CreateItem (currentItem(), theRow, theColumn);
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+void MessageModel_ItemAlert::Init()
+{
+ MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport> (Parent());
+ MessageModel_ItemAlertPtr anAlertItem;
+ Handle(Message_Alert) anAlert;
+ if (aReportItem)
+ {
+ Message_ListOfAlert anAlerts;
+ if (aReportItem->GetChildAlerts (Row(), anAlerts))
+ {
+ myAlert = anAlerts.First();
+ }
+ }
+ else
+ {
+ anAlertItem = itemDynamicCast<MessageModel_ItemAlert> (Parent());
+ if (anAlertItem)
+ {
+ Message_ListOfAlert anAlerts;
+ if (anAlertItem->GetChildAlerts (Row(), anAlerts))
+ {
+ myAlert = anAlerts.First();
+ }
+ }
+ }
+
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(myAlert);
+ if (!anExtendedAlert.IsNull() && !anExtendedAlert->Attribute().IsNull())
+ {
+ Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute();
+ if (!anAttribute.IsNull())
+ {
+ //if (!Handle(Message_AttributeStream)::DownCast(anAttribute).IsNull())
+ //{
+ // if (GetProperties().IsNull())
+ // {
+ // TreeModel_ItemBasePtr anItem = Parent()->Child (Row(), Column(), false);
+ // SetProperties (new MessageModel_ItemPropertiesAttributeStream (anItem));
+ // }
+ // Handle(Message_AttributeStream) anAttributeStream = Handle(Message_AttributeStream)::DownCast (anExtendedAlert->Attribute());
+ // Handle(MessageModel_ItemPropertiesAttributeStream) aProperties = Handle(MessageModel_ItemPropertiesAttributeStream)::DownCast (GetProperties());
+ // aProperties->Init (anAttributeStream->GetStream());
+ //}
+ ////if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeObject)))
+ //// myPresentation = Handle(Message_AttributeObject)::DownCast (anAttribute)->GetObject();
+ if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute)))
+ myPresentation = new Convert_TransientShape (Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape());
+ }
+ //TCollection_AsciiString aDescription = anExtendedAlert->Attribute()->GetDescription();
+ //Bnd_Box aBox;
+ //if (aBox.Init (Standard_SStream (aDescription.ToCString())))
+ // myPresentation =new Convert_TransientShape (Convert_Tools::CreateShape (aBox));
+ }
+ MessageModel_ItemBase::Init();
+}
+
+// =======================================================================
+// function : Reset
+// purpose :
+// =======================================================================
+void MessageModel_ItemAlert::Reset()
+{
+ MessageModel_ItemBase::Reset();
+ myAlert = Handle(Message_Alert)();
+ myChildAlerts.Clear();
+ myPresentation = NULL;
+}
+
+// =======================================================================
+// function : initItem
+// purpose :
+// =======================================================================
+void MessageModel_ItemAlert::initItem() const
+{
+ if (IsInitialized())
+ return;
+ const_cast<MessageModel_ItemAlert*>(this)->Init();
+}
+
+// =======================================================================
+// function : getAlert
+// purpose :
+// =======================================================================
+const Handle(Message_Alert)& MessageModel_ItemAlert::getAlert() const
+{
+ initItem();
+ return myAlert;
+}
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageModel_ItemAlert_H
+#define MessageModel_ItemAlert_H
+
+#include <inspector/MessageModel_ItemBase.hxx>
+#include <Message_Alert.hxx>
+#include <Message_ListOfAlert.hxx>
+#include <Message_Report.hxx>
+#include <NCollection_DataMap.hxx>
+#include <Standard.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QMap>
+#include <QVariant>
+#include <Standard_WarningsRestore.hxx>
+
+#include <NCollection_List.hxx>
+#include <NCollection_Vector.hxx>
+
+class QAbstractTableModel;
+
+class MessageModel_ItemAlert;
+typedef QExplicitlySharedDataPointer<MessageModel_ItemAlert> MessageModel_ItemAlertPtr;
+
+//! \class MessageModel_ItemAlert
+//! This item is connected to Message_Alert.
+//! Parent is either MessageModel_ItemRoot or MessageModel_ItemAlert, children are MessageModel_ItemAlert or no children
+class MessageModel_ItemAlert : public MessageModel_ItemBase
+{
+public:
+
+ //! Creates an item wrapped by a shared pointer
+ //! \param theRow the item row positition in the parent item
+ //! \param theColumn the item column positition in the parent item
+ //! \return the pointer to the created item
+ static MessageModel_ItemAlertPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ { return MessageModel_ItemAlertPtr (new MessageModel_ItemAlert (theParent, theRow, theColumn)); }
+
+ //! Destructor
+ virtual ~MessageModel_ItemAlert() Standard_OVERRIDE {};
+
+ //! Returns the current shape
+ const Handle(Message_Alert)& GetAlert() const { return myAlert; }
+
+ //! Returns alert of the report for the parameter row
+ Standard_Boolean GetChildAlerts (const int theRow, Message_ListOfAlert& theAlerts) const { return myChildAlerts.Find(theRow, theAlerts); }
+
+ //! Inits the item, fills internal containers
+ Standard_EXPORT virtual void Init() Standard_OVERRIDE;
+
+ //! Resets cached values
+ Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
+
+ //! Return data value for the role.
+ //! \param theRole a value role
+ //! \return the value
+ Standard_EXPORT virtual QVariant initValue (const int theRole) const Standard_OVERRIDE;
+
+ //! \return number of children.
+ Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE;
+
+ //! Returns stream value of the item to fulfill property panel.
+ //! \return stream value or dummy
+ Standard_EXPORT virtual bool SetStream (const Standard_SStream& theSStream, Standard_Integer& theStartPos,
+ Standard_Integer& theLastPos) const Standard_OVERRIDE;
+
+ //! Sets some shape to present the item
+ //! \param theShape shape instance
+ void SetCustomShape (const TopoDS_Shape& theShape) { myCustomShape = theShape; }
+
+ //! Returns custom shape to present the item
+ //! \return instance of the shape
+ const TopoDS_Shape& GetCustomShape() const { return myCustomShape; }
+
+ //! Returns presentation of the attribute to be visualized in the view
+ //! \param theRow a model index row
+ //! \param theColumn a model index column
+ //! \thePresentations [out] container of presentation handles to be visualized
+ virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations) Standard_OVERRIDE
+ { TreeModel_ItemBase::Presentations (thePresentations); thePresentations.Append (myPresentation); }
+
+
+ ////! Returns summ of children alert elapsed times. The method is recusive.
+ ////! \param theAlert a message alert
+ ////! \return double value
+ //Standard_EXPORT static double CumulativeMetric (const Handle(Message_Alert)& theAlert);
+
+protected:
+
+ //! Initialize the current item. It is empty because Reset() is also empty.
+ virtual void initItem() const Standard_OVERRIDE;
+
+ //! Returns stream value of the item to fulfill property panel.
+ //! \return stream value or dummy
+ Standard_EXPORT virtual void initStream (Standard_OStream& OS) const Standard_OVERRIDE;
+
+ //! Creates a child item in the given position.
+ //! \param theRow the child row position
+ //! \param theColumn the child column position
+ //! \return the created item
+ virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
+
+ //! Returns current alert, initialized item if it has not been initialized yet
+ //! \return alert value
+ const Handle(Message_Alert)& getAlert() const;
+
+private:
+
+ //! Constructor
+ MessageModel_ItemAlert (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ : MessageModel_ItemBase (theParent, theRow, theColumn) {}
+
+private:
+ Handle(Message_Alert) myAlert;
+
+ NCollection_DataMap<Standard_Integer, Message_ListOfAlert> myChildAlerts; //!< container of child alerts
+
+ TopoDS_Shape myCustomShape;
+ Handle(Standard_Transient) myPresentation;
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageModel_ItemBase.hxx>
+#include <inspector/MessageModel_ItemRoot.hxx>
+
+// =======================================================================
+// function : isReversed
+// purpose :
+// =======================================================================
+Standard_Boolean MessageModel_ItemBase::isReversed() const
+{
+ TreeModel_ItemBasePtr aParentItem = GetRootItem();
+ MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (aParentItem);
+ return aRootItem ? aRootItem->IsReversed() : Standard_False;
+}
+
+// =======================================================================
+// function : GetRootItem
+// purpose :
+// =======================================================================
+TreeModel_ItemBasePtr MessageModel_ItemBase::GetRootItem() const
+{
+ TreeModel_ItemBasePtr anItem = Parent();
+ while (anItem)
+ {
+ if (MessageModel_ItemRootPtr aThisRootItem = itemDynamicCast<MessageModel_ItemRoot> (anItem))
+ {
+ return aThisRootItem;
+ }
+ anItem = anItem->Parent();
+ }
+ return TreeModel_ItemBasePtr();
+}
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageModel_ItemBase_H
+#define MessageModel_ItemBase_H
+
+#include <Standard.hxx>
+#include <TopoDS_Shape.hxx>
+#include <inspector/TreeModel_ItemBase.hxx>
+
+class MessageModel_ItemBase;
+typedef QExplicitlySharedDataPointer<MessageModel_ItemBase> MessageModel_ItemBasePtr;
+
+//! \class MessageModel_ItemBase
+// \brief Declaration of the tree model base item.
+class MessageModel_ItemBase : public TreeModel_ItemBase
+{
+public:
+
+ //! Resets cached values
+ virtual void Reset() Standard_OVERRIDE { TreeModel_ItemBase::Reset(); }
+
+protected:
+
+ //! Initialize the current item. It creates a backup of the specific item information
+ virtual void initItem() const {};
+
+ //! Constructor
+ //! param theParent a parent item
+ //! \param theRow the item row positition in the parent item
+ //! \param theColumn the item column positition in the parent item
+ MessageModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ : TreeModel_ItemBase (theParent, theRow, theColumn) {}
+
+ //! Return whether the view is reversed or not
+ //! \return boolean value
+ Standard_Boolean isReversed() const;
+
+ //! Return root item
+ //! \return an item instance
+ TreeModel_ItemBasePtr GetRootItem() const;
+};
+
+#endif
\ No newline at end of file
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageModel_ItemReport.hxx>
+
+#include <inspector/MessageModel_ItemAlert.hxx>
+#include <inspector/MessageModel_ItemRoot.hxx>
+#include <inspector/MessageModel_Tools.hxx>
+#include <inspector/MessageModel_TreeModel.hxx>
+
+#include <Message.hxx>
+#include <Message_Alert.hxx>
+#include <Message_AttributeMeter.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_PrinterToReport.hxx>
+#include <OSD_Path.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QColor>
+#include <Standard_WarningsRestore.hxx>
+
+// =======================================================================
+// function : initValue
+// purpose :
+// =======================================================================
+QVariant MessageModel_ItemReport::initValue (const int theRole) const
+{
+ QVariant aParentValue = MessageModel_ItemBase::initValue (theRole);
+ if (aParentValue.isValid())
+ return aParentValue;
+
+ const Handle(Message_Report)& aReport = getReport();
+ if (aReport.IsNull())
+ return QVariant();
+
+ if (theRole == Qt::ForegroundRole)
+ {
+ if (!aReport->IsActiveInMessenger())
+ return QColor(Qt::darkGray);
+
+ return QVariant();
+ }
+ if (theRole == Qt::ToolTipRole && !myDescription.IsEmpty() && Column() == 0) // display the exported file name in tool tip
+ {
+ OSD_Path aPath(myDescription);
+ return QString ("%1%2").arg (aPath.Name().ToCString()).arg (aPath.Extension().ToCString());
+ }
+
+ if (theRole != Qt::DisplayRole)
+ return QVariant();
+
+ if (Column() == 0)
+ return aReport->DynamicType()->Name();
+
+ Message_MetricType aMetricType;
+ int aPosition;
+ if (MessageModel_TreeModel::IsMetricColumn (Column(), aMetricType, aPosition) &&
+ (aMetricType == Message_MetricType_UserTimeCPU || aMetricType == Message_MetricType_SystemTimeInfo))
+ {
+ if (aPosition == 0) return CumulativeMetric (aReport, aMetricType);
+ else if (aPosition == 1) return "100";
+ }
+ return QVariant();
+}
+
+// =======================================================================
+// function : initRowCount
+// purpose :
+// =======================================================================
+int MessageModel_ItemReport::initRowCount() const
+{
+ const Handle(Message_Report)& aReport = getReport();
+ if (aReport.IsNull())
+ return 0;
+
+ MessageModel_ItemReport* aCurrentItem = (MessageModel_ItemReport*)this;
+ for (int aGravityId = Message_Trace; aGravityId <= Message_Fail; aGravityId++)
+ {
+ const Message_ListOfAlert& anAlerts = aReport->GetAlerts ((Message_Gravity)aGravityId);
+ for (Message_ListOfAlert::Iterator anIt(anAlerts); anIt.More(); anIt.Next())
+ {
+ Message_ListOfAlert aCurAlerts;
+ aCurAlerts.Append (anIt.Value());
+ aCurrentItem->myChildAlerts.Bind(myChildAlerts.Size(), aCurAlerts);
+ }
+ }
+ return aCurrentItem->myChildAlerts.Size();
+}
+
+// =======================================================================
+// function : createChild
+// purpose :
+// =======================================================================
+TreeModel_ItemBasePtr MessageModel_ItemReport::createChild (int theRow, int theColumn)
+{
+ return MessageModel_ItemAlert::CreateItem (currentItem(), theRow, theColumn);
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+void MessageModel_ItemReport::Init()
+{
+ MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (Parent());
+ myReport = aRootItem ? aRootItem->GetReport (Row(), myDescription) : Handle(Message_Report)();
+
+ MessageModel_ItemBase::Init();
+}
+
+// =======================================================================
+// function : getReport
+// purpose :
+// =======================================================================
+const Handle(Message_Report)& MessageModel_ItemReport::getReport() const
+{
+ initItem();
+ return myReport;
+}
+
+// =======================================================================
+// function : Reset
+// purpose :
+// =======================================================================
+void MessageModel_ItemReport::Reset()
+{
+ MessageModel_ItemBase::Reset();
+ myReport = Handle(Message_Report)();
+ myChildAlerts.Clear();
+}
+
+// =======================================================================
+// function : initItem
+// purpose :
+// =======================================================================
+void MessageModel_ItemReport::initItem() const
+{
+ if (IsInitialized())
+ return;
+ const_cast<MessageModel_ItemReport*>(this)->Init();
+}
+
+// =======================================================================
+// function : FindReportItem
+// purpose :
+// =======================================================================
+MessageModel_ItemReportPtr MessageModel_ItemReport::FindReportItem (const TreeModel_ItemBasePtr& theItem)
+{
+ TreeModel_ItemBasePtr anItem = theItem;
+ while (anItem)
+ {
+ if (MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItem))
+ return aReportItem;
+
+ anItem = anItem->Parent();
+ }
+ return MessageModel_ItemReportPtr();
+}
+
+// =======================================================================
+// function : FindReport
+// purpose :
+// =======================================================================
+Handle(Message_Report) MessageModel_ItemReport::FindReport (const MessageModel_ItemBasePtr& theItem)
+{
+ Handle(Message_Report) aReport;
+
+ MessageModel_ItemBasePtr anItem = theItem;
+ while (anItem)
+ {
+ MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItem);
+
+ if (aReportItem)
+ return aReportItem->GetReport();
+
+ anItem = itemDynamicCast<MessageModel_ItemBase>(anItem->Parent());
+ }
+ return NULL;
+}
+
+// =======================================================================
+// function : CumulativeMetric
+// purpose :
+// =======================================================================
+Standard_Real MessageModel_ItemReport::CumulativeMetric (const Handle(Message_Report)& theReport, const Message_MetricType theMetricType)
+{
+ if (!theReport->ActiveMetrics().Contains (theMetricType))
+ return 0;
+
+ Standard_Real aMetric = 0;
+ for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
+ {
+ const Message_ListOfAlert& anAlerts = theReport->GetAlerts ((Message_Gravity)iGravity);
+ Handle(Message_AttributeMeter) aFirstAttribute/*, aLastAttribute*/;
+ for (Message_ListOfAlert::Iterator anAlertsIterator (anAlerts); anAlertsIterator.More(); anAlertsIterator.Next())
+ {
+ Handle(Message_AlertExtended) anAlert = Handle(Message_AlertExtended)::DownCast (anAlertsIterator.Value());
+ if (anAlert.IsNull())
+ continue;
+ Handle(Message_AttributeMeter) anAttribute = Handle(Message_AttributeMeter)::DownCast (anAlert->Attribute());
+ if (anAttribute.IsNull() || !anAttribute->HasMetric(theMetricType))
+ continue;
+ //if (aFirstAttribute.IsNull())
+ // aFirstAttribute = anAttribute;
+ //else
+ //{
+ //aLastAttribute = anAttribute;
+ //}
+ aMetric += anAttribute->StopValue (theMetricType) - anAttribute->StartValue (theMetricType);
+ }
+ //if (aFirstAttribute.IsNull())
+ // continue;
+ //if (aLastAttribute.IsNull())
+ // aLastAttribute = aFirstAttribute;
+
+ //aMetric += aLastAttribute->StopValue (theMetricType) - aFirstAttribute->StartValue (theMetricType);
+ }
+ return aMetric;
+}
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageModel_ItemReport_H
+#define MessageModel_ItemReport_H
+
+#include <inspector/MessageModel_ItemBase.hxx>
+#include <Standard.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <Message_Alert.hxx>
+#include <Message_Report.hxx>
+#include <NCollection_DataMap.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QMap>
+#include <QVariant>
+#include <Standard_WarningsRestore.hxx>
+
+class MessageModel_ItemReport;
+typedef QExplicitlySharedDataPointer<MessageModel_ItemReport> MessageModel_ItemReportPtr;
+
+//! \class MessageModel_ItemReport
+//! This item is connected to Message_Alert.
+//! Parent is MessageModel_ItemRoot, children are MessageModel_ItemAlert or no children
+class MessageModel_ItemReport : public MessageModel_ItemBase
+{
+public:
+
+ //! Creates an item wrapped by a shared pointer
+ //! \param theRow the item row positition in the parent item
+ //! \param theColumn the item column positition in the parent item
+ //! \return the pointer to the created item
+ static MessageModel_ItemReportPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ { return MessageModel_ItemReportPtr (new MessageModel_ItemReport (theParent, theRow, theColumn)); }
+
+ //! Destructor
+ virtual ~MessageModel_ItemReport() Standard_OVERRIDE {};
+
+ //! Returns the current shape
+ const Handle(Message_Report)& GetReport() const { return myReport; }
+
+ //! Returns alert of the report for the parameter row
+ Standard_Boolean GetChildAlerts (const int theRow, Message_ListOfAlert& theAlerts) const { return myChildAlerts.Find(theRow, theAlerts); }
+
+ //! Returns the report description or NULL
+ const TCollection_AsciiString& GetDescription() const { return myDescription; }
+
+ //! Inits the item, fills internal containers
+ Standard_EXPORT virtual void Init() Standard_OVERRIDE;
+
+ //! Resets cached values
+ Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
+
+ //! Return data value for the role.
+ //! \param theRole a value role
+ //! \return the value
+ Standard_EXPORT virtual QVariant initValue (const int theRole) const Standard_OVERRIDE;
+
+ //! \return number of children.
+ Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE;
+
+ //! Returns report of the tree model item. Iterates up by parents intil the report item is found.
+ //! \return an item or NULL
+ Standard_EXPORT static MessageModel_ItemReportPtr FindReportItem (const TreeModel_ItemBasePtr& theItem);
+
+ //! Returns report of the item
+ static Handle(Message_Report) FindReport (const MessageModel_ItemBasePtr& thetItem);
+
+ //! Returns report cumulative metric as stop time of the last alert minus start time of the first alert
+ Standard_EXPORT static Standard_Real CumulativeMetric (const Handle(Message_Report)& theReport, const Message_MetricType theMetricType);
+
+protected:
+
+ //! Initialize the current item. It is empty because Reset() is also empty.
+ virtual void initItem() const Standard_OVERRIDE;
+
+ //! Creates a child item in the given position.
+ //! \param theRow the child row position
+ //! \param theColumn the child column position
+ //! \return the created item
+ virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
+
+ //! Returns number of child shapes. Init item if it is not initialized
+ //! \return integer value
+ int getRowCount() const;
+
+ //! Returns current shape, initialized item if it has not been initialized yet
+ //! \return shape value
+ const Handle(Message_Report)& getReport() const;
+
+private:
+
+ //! Constructor
+ MessageModel_ItemReport (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ : MessageModel_ItemBase (theParent, theRow, theColumn) {}
+
+private:
+
+ NCollection_DataMap<Standard_Integer, Message_ListOfAlert> myChildAlerts; //!< container of child alerts
+
+ Handle(Message_Report) myReport; //!< current report
+ TCollection_AsciiString myDescription; //!< description
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageModel_ItemRoot.hxx>
+#include <inspector/MessageModel_ItemReport.hxx>
+
+// =======================================================================
+// function : SetReport
+// purpose :
+// =======================================================================
+void MessageModel_ItemRoot::SetReport (const int theRowId, const Handle(Message_Report)& theReport,
+ const TCollection_AsciiString& theReportDescription)
+{
+ NCollection_List<MessageModel_ReportInformation>::Iterator aReportsIt (myReports);
+ for (int aRowId = 0; aReportsIt.More(); aReportsIt.Next(), aRowId++)
+ {
+ if (aRowId == theRowId)
+ break;
+ }
+ aReportsIt.Value().myReport = theReport;
+ aReportsIt.Value().myDescription = theReportDescription;
+}
+
+// =======================================================================
+// function : GetReport
+// purpose :
+// =======================================================================
+const Handle(Message_Report)& MessageModel_ItemRoot::GetReport (const int theRowId,
+ TCollection_AsciiString& theReportDescription)
+{
+ NCollection_List<MessageModel_ReportInformation>::Iterator aReportsIt (myReports);
+ for (int aRowId = 0; aReportsIt.More(); aReportsIt.Next(), aRowId++)
+ {
+ if (aRowId == theRowId)
+ break;
+ }
+ theReportDescription = aReportsIt.Value().myDescription;
+ return aReportsIt.Value().myReport;
+}
+
+// =======================================================================
+// function : HasReport
+// purpose :
+// =======================================================================
+Standard_Boolean MessageModel_ItemRoot::HasReport (const Handle(Message_Report)& theReport)
+{
+ NCollection_List<MessageModel_ReportInformation>::Iterator aReportsIt (myReports);
+ for (int aRowId = 0; aReportsIt.More(); aReportsIt.Next(), aRowId++)
+ {
+ if (aReportsIt.Value().myReport == theReport)
+ return Standard_True;
+ }
+ return Standard_False;
+}
+
+// =======================================================================
+// function : initValue
+// purpose :
+// =======================================================================
+QVariant MessageModel_ItemRoot::initValue (const int theRole) const
+{
+ QVariant aParentValue = MessageModel_ItemBase::initValue (theRole);
+ if (aParentValue.isValid())
+ return aParentValue;
+
+ if (Column() != 0)
+ return QVariant();
+
+ if (theRole == Qt::DisplayRole)
+ return myName.IsEmpty() ? "Message_Reports" : myName.ToCString();
+
+ return QVariant();
+}
+
+// =======================================================================
+// function : createChild
+// purpose :
+// =======================================================================
+TreeModel_ItemBasePtr MessageModel_ItemRoot::createChild (int theRow, int theColumn)
+{
+ return MessageModel_ItemReport::CreateItem (currentItem(), theRow, theColumn);
+}
+
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageModel_ItemRoot_H
+#define MessageModel_ItemRoot_H
+
+#include <Message_Alert.hxx>
+#include <Message_Report.hxx>
+#include <NCollection_List.hxx>
+#include <Standard.hxx>
+#include <TCollection_AsciiString.hxx>
+
+#include <inspector/MessageModel_ItemBase.hxx>
+
+class MessageModel_ItemRoot;
+typedef QExplicitlySharedDataPointer<MessageModel_ItemRoot> MessageModel_ItemRootPtr;
+
+//! \struct to extend report by description
+struct MessageModel_ReportInformation
+{
+ //! Constructor
+ MessageModel_ReportInformation (Handle(Message_Report) theReport, const TCollection_AsciiString& theDescription)
+ : myReport (theReport), myDescription (theDescription) {}
+
+ Handle(Message_Report) myReport; //! report
+ TCollection_AsciiString myDescription; //! report description
+};
+
+//! \class MessageModel_ItemRoot
+//! Collects message reports that should be visualized in tree view. Reports are cached and if reports are not needed,
+//! cache should be cleared using RemoveAllReports
+//! Parent is NULL, children are MessageModel_ItemReport items.
+class MessageModel_ItemRoot : public MessageModel_ItemBase
+{
+public:
+
+ //! Creates an item wrapped by a shared pointer
+ static MessageModel_ItemRootPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ { return MessageModel_ItemRootPtr (new MessageModel_ItemRoot (theParent, theRow, theColumn)); }
+
+ //! Destructor
+ virtual ~MessageModel_ItemRoot() Standard_OVERRIDE {};
+
+ //! Appends new report
+ //! \param theReport a report instance
+ //! \param theReportDescription an additional report information
+ void AddReport (const Handle(Message_Report)& theReport, const TCollection_AsciiString& theReportDescription)
+ { myReports.Append (MessageModel_ReportInformation (theReport, theReportDescription)); }
+
+ //! Set report, se it into the given row index
+ //! \param theRowId a report child row
+ //! \param theReport a report instance
+ //! \param theReportDescription an additional report information
+ Standard_EXPORT void SetReport (const int theRowId, const Handle(Message_Report)& theReport,
+ const TCollection_AsciiString& theReportDescription = "");
+
+ //! Returns true if report exists is in the list of the current reports
+ //! \param theReport a report instance
+ //! \return boolen value
+ Standard_EXPORT Standard_Boolean HasReport (const Handle(Message_Report)& theReport);
+
+ //!< Returns processed reports
+ const NCollection_List<MessageModel_ReportInformation>& Reports() const { return myReports; }
+
+ //! Clears internal container of added reports
+ void RemoveAllReports() { myReports.Clear(); }
+
+ //! Returns report by the number
+ //! \param theRowId an index of the report in the internal container.
+ Standard_EXPORT const Handle(Message_Report)& GetReport (const int theRowId, TCollection_AsciiString& theReportDescription);
+
+ //! Set the view reversed. If reversed, the last report alert is upper item in the tree view
+ //! \param theReversed boolean flag
+ void SetReversed (const Standard_Boolean& theReversed) { myIsReversed = theReversed; }
+
+ //! Return whether the view is reversed or not
+ //! \return boolean value
+ Standard_Boolean IsReversed() const { return myIsReversed; };
+
+ //! Set the view reversed. If reversed, the last report alert is upper item in the tree view
+ //! \param theReversed boolean flag
+ void SetName (const TCollection_AsciiString& theName) { myName = theName; }
+
+protected:
+
+ //! Return data value for the role.
+ //! \param theRole a value role
+ //! \return the value
+ virtual QVariant initValue (const int theRole) const Standard_OVERRIDE;
+
+ //! \return number of children.
+ virtual int initRowCount() const Standard_OVERRIDE { return myReports.Size(); }
+
+ //! Creates a child item in the given position.
+ //! \param theRow the child row position
+ //! \param theColumn the child column position
+ //! \return the created item
+ virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
+
+private:
+
+ //! Constructor
+ //! param theParent a parent item
+ MessageModel_ItemRoot (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ : MessageModel_ItemBase (theParent, theRow, theColumn), myIsReversed (Standard_False) {}
+
+private:
+
+ NCollection_List<MessageModel_ReportInformation> myReports; //!< reports sent by algorithms
+ Standard_Boolean myIsReversed; //!< state if the model is reversed
+ TCollection_AsciiString myName; //!< DisplayRole data, if defined
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageModel_Tools.hxx>
+#include <inspector/MessageModel_ItemAlert.hxx>
+
+#include <inspector/ViewControl_Table.hxx>
+#include <inspector/ViewControl_TableModelValues.hxx>
+
+#include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepTools.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_AttributeObject.hxx>
+#include <Message_AttributeStream.hxx>
+
+#include <Precision.hxx>
+#include <TopoDS_AlertAttribute.hxx>
+#include <TopoDS_Edge.hxx>
+
+// =======================================================================
+// function : GetPointerInfo
+// purpose :
+// =======================================================================
+TCollection_AsciiString MessageModel_Tools::GetPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo)
+{
+ if (thePointer.IsNull())
+ return TCollection_AsciiString();
+
+ std::ostringstream aPtrStr;
+ aPtrStr << thePointer.operator->();
+ if (!isShortInfo)
+ return aPtrStr.str().c_str();
+
+ TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str());
+ for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++)
+ {
+ if (anInfoPtr.Value(aSymbolId) != '0')
+ {
+ anInfoPtr = anInfoPtr.SubString (aSymbolId, anInfoPtr.Length());
+ anInfoPtr.Prepend("0x");
+ return anInfoPtr;
+ }
+ }
+ return aPtrStr.str().c_str();
+}
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageModel_Tools_H
+#define MessageModel_Tools_H
+
+#include <Standard.hxx>
+
+#include <TCollection_AsciiString.hxx>
+#include <Message_ListOfAlert.hxx>
+#include <NCollection_DataMap.hxx>
+#include <NCollection_Vector.hxx>
+#include <Standard_Transient.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <inspector/TreeModel_ItemBase.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QList>
+#include <Standard_WarningsRestore.hxx>
+
+class Message_Alert;
+class ViewControl_TableModelValues;
+
+class ViewControl_Table;
+
+//! \class MessageModel_Tools
+//! It gives auxiliary methods for Message classes manipulation
+class MessageModel_Tools
+{
+public:
+
+ //! Convert pointer to string value
+ //! \param thePointer a pointer
+ //! \param isShortInfo if true, all '0' symbols in the beginning of the pointer are skipped
+ //! \return the string value
+ Standard_EXPORT static TCollection_AsciiString GetPointerInfo (const Handle(Standard_Transient)& thePointer,
+ const bool isShortInfo = true);
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageModel_TreeModel.hxx>
+
+#include <inspector/MessageModel_ItemAlert.hxx>
+#include <inspector/MessageModel_ItemRoot.hxx>
+#include <inspector/MessageModel_ItemReport.hxx>
+#include <inspector/TreeModel_ColumnType.hxx>
+
+#include <Message.hxx>
+
+const int COLUMN_NAME_WIDTH = 460;
+const int COLUMN_SIZE_WIDTH = 30;
+
+const int COLUMN_REAL_VALUE_WIDTH = 115;
+const int COLUMN_PERCENT_VALUE_WIDTH = 50;
+
+// =======================================================================
+// function : Constructor
+// purpose :
+// =======================================================================
+MessageModel_TreeModel::MessageModel_TreeModel (QObject* theParent)
+: TreeModel_ModelBase (theParent), myIsReversed (Standard_False)
+{
+}
+
+// =======================================================================
+// function : InitColumns
+// purpose :
+// =======================================================================
+void MessageModel_TreeModel::InitColumns()
+{
+ // 0 - Name, 1 - visibility, 2 - Row
+ SetHeaderItem (TreeModel_ColumnType_Name, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
+ SetHeaderItem (TreeModel_ColumnType_Visibility, TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
+ SetHeaderItem (TreeModel_ColumnType_Row, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH, Standard_True /*hidden*/));
+
+ int aNextIndex = 3;
+ for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
+ {
+ Message_MetricType aMetricType = (Message_MetricType)aMetricId;
+ OSD_MemInfo::Counter aMemInfo;
+ bool isMemInfo = Message::ToOSDMetric (aMetricType, aMemInfo);
+
+ SetHeaderItem (aNextIndex++,
+ TreeModel_HeaderSection (QString("%1 [%2]").arg (Message::MetricToString (aMetricType)).arg(isMemInfo ? "Mb" : "s"),
+ COLUMN_REAL_VALUE_WIDTH));
+ SetHeaderItem (aNextIndex++, TreeModel_HeaderSection (isMemInfo ? "Delta" : "%", COLUMN_PERCENT_VALUE_WIDTH));
+ }
+}
+
+// =======================================================================
+// function : GetMetricColumns
+// purpose :
+// =======================================================================
+void MessageModel_TreeModel::GetMetricColumns (const Message_MetricType theMetricType, QList<int>& theMetricColumns)
+{
+ theMetricColumns.clear();
+ int aNextIndex = 3; // after default parent columns, see InitColumns
+ for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
+ {
+ if (theMetricType != (Message_MetricType)aMetricId)
+ {
+ aNextIndex += 2;
+ continue;
+ }
+ theMetricColumns.append (aNextIndex++);
+ theMetricColumns.append (aNextIndex++);
+ }
+}
+
+// =======================================================================
+// function : IsMetricColumn
+// purpose :
+// =======================================================================
+bool MessageModel_TreeModel::IsMetricColumn (const int theColumnId, Message_MetricType& theMetricType, int& thePosition)
+{
+ int aNextIndex = 3; // after default parent columns, see InitColumns
+ for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
+ {
+ if (theColumnId == aNextIndex || theColumnId == aNextIndex + 1)
+ {
+ theMetricType = (Message_MetricType)aMetricId;
+ thePosition = theColumnId - aNextIndex;
+ return true;
+ }
+ aNextIndex += 2;
+ }
+ return false;
+}
+
+// =======================================================================
+// function : createRootItem
+// purpose :
+// =======================================================================
+TreeModel_ItemBasePtr MessageModel_TreeModel::createRootItem (const int theColumnId)
+{
+ return MessageModel_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId);
+}
+
+// =======================================================================
+// function : HasShape
+// purpose :
+// =======================================================================
+Standard_Boolean MessageModel_TreeModel::HasReport (const Handle(Message_Report)& theReport)
+{
+ if (columnCount() == 0)
+ return Standard_False;
+
+ MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
+ return aRootItem && aRootItem->HasReport (theReport);
+}
+
+// =======================================================================
+// function : AddShape
+// purpose :
+// =======================================================================
+void MessageModel_TreeModel::AddReport (const Handle(Message_Report)& theReport,
+ const TCollection_AsciiString& theReportDescription)
+{
+ for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
+ {
+ MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (aColId));
+ if (!aRootItem)
+ continue;
+ aRootItem->AddReport (theReport, theReportDescription);
+ aRootItem->SetReversed (myIsReversed);
+ }
+
+ Reset();
+ EmitLayoutChanged();
+}
+
+// =======================================================================
+// function : SetReport
+// purpose :
+// =======================================================================
+void MessageModel_TreeModel::SetReport (const int theRowId, const Handle(Message_Report)& theReport,
+ const TCollection_AsciiString& theReportDescription)
+{
+ for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
+ {
+ MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (aColId));
+ if (!aRootItem)
+ continue;
+ aRootItem->SetReport (theRowId, theReport, theReportDescription);
+ }
+ Reset();
+ EmitLayoutChanged();
+}
+
+// =======================================================================
+// function : Reports
+// purpose :
+// =======================================================================
+const NCollection_List<MessageModel_ReportInformation>& MessageModel_TreeModel::Reports() const
+{
+ MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
+ return aRootItem->Reports();
+}
+
+// =======================================================================
+// function : SetReversed
+// purpose :
+// =======================================================================
+void MessageModel_TreeModel::SetReversed (const Standard_Boolean& theReversed)
+{
+ myIsReversed = theReversed;
+
+ for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
+ {
+ MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (aColId));
+ if (aRootItem)
+ aRootItem->SetReversed (myIsReversed);
+ }
+
+ Reset();
+ EmitLayoutChanged();
+}
+
+// =======================================================================
+// function : UpdateTreeModel
+// purpose :
+// =======================================================================
+void MessageModel_TreeModel::SetRootItemName (const TCollection_AsciiString& theName)
+{
+ MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
+ if (aRootItem)
+ aRootItem->SetName (theName);
+}
+
+// =======================================================================
+// function : UpdateTreeModel
+// purpose :
+// =======================================================================
+void MessageModel_TreeModel::UpdateTreeModel()
+{
+ Reset();
+ EmitLayoutChanged();
+}
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageModel_TreeModel_H
+#define MessageModel_TreeModel_H
+
+#include <inspector/MessageModel_ItemBase.hxx>
+#include <inspector/MessageModel_ItemRoot.hxx>
+#include <Standard.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <Message_Report.hxx>
+#include <inspector/TreeModel_ModelBase.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QMap>
+#include <QObject>
+#include <Standard_WarningsRestore.hxx>
+
+class MessageModel_TreeModel;
+
+//! \class MessageModel_TreeModel
+//! View model to visualize MessageReport/s content
+class MessageModel_TreeModel : public TreeModel_ModelBase
+{
+public:
+
+ //! Constructor
+ Standard_EXPORT MessageModel_TreeModel (QObject* theParent);
+
+ //! Destructor
+ virtual ~MessageModel_TreeModel() Standard_OVERRIDE {};
+
+ //! Creates model columns and root items.
+ Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE;
+
+ //!< Returns columns of the model for the metric
+ //!< \param theMetricType metric
+ //!< \param theMetricColumns [out] container of metric columns
+ static Standard_EXPORT void GetMetricColumns (const Message_MetricType theMetricType, QList<int>& theMetricColumns);
+
+ //!< Returns metric type for the column
+ //!< \param theColumnId [in] index of the tree column
+ //!< \param theMetricType [out] metric type if found
+ //!< \param thePosition [out] index of the metric column, 0 - is metric, 1 - is delta
+ //!< \return true if the column has metric parameters
+ static Standard_EXPORT bool IsMetricColumn (const int theColumnId, Message_MetricType& theMetricType, int& thePosition);
+
+ //! Returns true if parameter report was added into the model
+ //! \param theReport a report instance
+ //! \return boolen value
+ Standard_EXPORT Standard_Boolean HasReport (const Handle(Message_Report)& theReport);
+
+ //! Add shape, append it to the model root item
+ //! \param theReport a report instance
+ //! \param theReportDescription an additional report information
+ Standard_EXPORT void AddReport (const Handle(Message_Report)& theReport,
+ const TCollection_AsciiString& theReportDescription = "");
+
+ //! Set report, se it into the given row index
+ //! \param theRowId a report child row
+ //! \param theReport a report instance
+ //! \param theReportDescription an additional report information
+ Standard_EXPORT void SetReport (const int theRowId, const Handle(Message_Report)& theReport,
+ const TCollection_AsciiString& theReportDescription = "");
+
+ //!< Returns processed reports
+ Standard_EXPORT const NCollection_List<MessageModel_ReportInformation>& Reports() const;
+
+ //! Set the view reversed. If reversed, the last report alert is upper item in the tree view
+ //! \param theReversed boolean flag
+ Standard_EXPORT void SetReversed (const Standard_Boolean& theReversed);
+
+ //! Return whether the view is reversed or not
+ //! \return boolean value
+ Standard_Boolean IsReversed() const { return myIsReversed; };
+
+ //! Sets the text value of the Root item, only "Name" column accepts the parameter value
+ //! \theName visulized text of root item
+ Standard_EXPORT void SetRootItemName (const TCollection_AsciiString& theName);
+
+ //! Updates tree model
+ Standard_EXPORT void UpdateTreeModel();
+
+protected:
+ //! Creates root item
+ //! \param theColumnId index of a column
+ virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE;
+
+private:
+ Standard_Boolean myIsReversed; //!< state if the model is reversed
+};
+
+#endif
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="20"
+ height="20"
+ viewBox="0 0 5.2916664 5.2916666"
+ version="1.1"
+ id="svg8"
+ inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
+ sodipodi:docname="item_shape.svg"
+ inkscape:export-filename="D:\OCCT\master_CR29451_1\tools\MessageModel\icons\item_shape.png"
+ inkscape:export-xdpi="96"
+ inkscape:export-ydpi="96">
+ <defs
+ id="defs2">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="-2.6544163 : -0.28690906 : 1"
+ inkscape:vp_y="0 : 1028.295 : 0"
+ inkscape:vp_z="9.504499 : -1.1228559 : 1"
+ inkscape:persp3d-origin="2.7661607 : -1.3768436 : 1"
+ id="perspective3711" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="15.839192"
+ inkscape:cx="4.9829441"
+ inkscape:cy="7.75434"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="false"
+ fit-margin-top="0"
+ fit-margin-left="0"
+ fit-margin-right="0"
+ fit-margin-bottom="0"
+ inkscape:window-width="1446"
+ inkscape:window-height="676"
+ inkscape:window-x="1766"
+ inkscape:window-y="124"
+ inkscape:window-maximized="0"
+ units="px" />
+ <metadata
+ id="metadata5">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(71.966667,-93.642022)">
+ <g
+ sodipodi:type="inkscape:box3d"
+ id="g3741"
+ inkscape:perspectiveID="#perspective3711"
+ inkscape:corner0="0.78884625 : 0.0054590483 : 0 : 1"
+ inkscape:corner7="-0.14713316 : 0.0022509206 : 0.25 : 1">
+ <path
+ sodipodi:type="inkscape:box3dside"
+ id="path3743"
+ style="fill:#353564;fill-rule:evenodd;stroke:none;stroke-width:1.45609081;stroke-linejoin:round"
+ inkscape:box3dsidetype="6"
+ d="m -71.590875,96.691829 v 1.844151 l 1.119347,0.186449 v -1.618024 z"
+ points="-71.590875,98.53598 -70.471528,98.722429 -70.471528,97.104405 -71.590875,96.691829 " />
+ <path
+ sodipodi:type="inkscape:box3dside"
+ id="path3753"
+ style="fill:#e9e9ff;fill-rule:evenodd;stroke:none;stroke-width:1.45609081;stroke-linejoin:round"
+ inkscape:box3dsidetype="11"
+ d="m -70.471528,97.104405 3.521639,-1.795967 v 2.991206 l -3.521639,0.422785 z"
+ points="-66.949889,95.308438 -66.949889,98.299644 -70.471528,98.722429 -70.471528,97.104405 " />
+ <path
+ sodipodi:type="inkscape:box3dside"
+ id="path3745"
+ style="fill:#4d4d9f;fill-rule:evenodd;stroke:none;stroke-width:1.45609081;stroke-linejoin:round"
+ inkscape:box3dsidetype="5"
+ d="m -71.590875,96.691829 3.325505,-2.775198 1.315481,1.391807 -3.521639,1.795967 z"
+ points="-68.26537,93.916631 -66.949889,95.308438 -70.471528,97.104405 -71.590875,96.691829 " />
+ <path
+ sodipodi:type="inkscape:box3dside"
+ id="path3751"
+ style="fill:#afafde;fill-rule:evenodd;stroke:none;stroke-width:1.45609081;stroke-linejoin:round"
+ inkscape:box3dsidetype="13"
+ d="m -71.590875,98.53598 3.325505,-0.751334 1.315481,0.514998 -3.521639,0.422785 z"
+ points="-68.26537,97.784646 -66.949889,98.299644 -70.471528,98.722429 -71.590875,98.53598 " />
+ <path
+ sodipodi:type="inkscape:box3dside"
+ id="path3749"
+ style="fill:#d7d7ff;fill-rule:evenodd;stroke:none;stroke-width:1.45609081;stroke-linejoin:round"
+ inkscape:box3dsidetype="14"
+ d="m -68.26537,93.916631 v 3.868015 l 1.315481,0.514998 v -2.991206 z"
+ points="-68.26537,97.784646 -66.949889,98.299644 -66.949889,95.308438 -68.26537,93.916631 " />
+ <path
+ sodipodi:type="inkscape:box3dside"
+ id="path3747"
+ style="fill:#8686bf;fill-rule:evenodd;stroke:none;stroke-width:1.45609081;stroke-linejoin:round"
+ inkscape:box3dsidetype="3"
+ d="m -71.590875,96.691829 3.325505,-2.775198 v 3.868015 l -3.325505,0.751334 z"
+ points="-68.26537,93.916631 -68.26537,97.784646 -71.590875,98.53598 -71.590875,96.691829 " />
+ </g>
+ </g>
+</svg>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="20"
+ height="20"
+ viewBox="0 0 5.2916664 5.2916666"
+ version="1.1"
+ id="svg8"
+ inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
+ sodipodi:docname="item_vectorOfReal.svg"
+ inkscape:export-filename="D:\OCCT\master_CR29451_1\tools\MessageModel\icons\item_vectorOfRealVec3.png"
+ inkscape:export-xdpi="96"
+ inkscape:export-ydpi="96">
+ <defs
+ id="defs2">
+ <linearGradient
+ id="linearGradient4578"
+ osb:paint="solid">
+ <stop
+ style="stop-color:#000000;stop-opacity:1;"
+ offset="0"
+ id="stop4576" />
+ </linearGradient>
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="-2.6544163 : -0.28690906 : 1"
+ inkscape:vp_y="0 : 1028.295 : 0"
+ inkscape:vp_z="9.504499 : -1.1228559 : 1"
+ inkscape:persp3d-origin="2.7661607 : -1.3768436 : 1"
+ id="perspective3711" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="15.839192"
+ inkscape:cx="-10.548151"
+ inkscape:cy="10.279721"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="false"
+ fit-margin-top="0"
+ fit-margin-left="0"
+ fit-margin-right="0"
+ fit-margin-bottom="0"
+ inkscape:window-width="1446"
+ inkscape:window-height="838"
+ inkscape:window-x="1733"
+ inkscape:window-y="67"
+ inkscape:window-maximized="0"
+ units="px" />
+ <metadata
+ id="metadata5">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(71.966667,-93.642022)">
+ <rect
+ id="rect3769"
+ width="4.660512"
+ height="4.443356"
+ x="-71.632576"
+ y="94.056023"
+ style="opacity:1;fill:none;fill-opacity:1;stroke:#8c8c8c;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ id="rect3769-3"
+ width="4.7041783"
+ height="2.2966287"
+ x="-71.676239"
+ y="96.202751"
+ style="opacity:1;fill:none;fill-opacity:1;stroke:#8c8c8c;stroke-width:0.19110738;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ id="rect3769-9"
+ width="2.3560426"
+ height="4.4502382"
+ x="-71.617508"
+ y="94.071091"
+ style="opacity:1;fill:none;fill-opacity:1;stroke:#8c8c8c;stroke-width:0.18826659;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+</svg>
--- /dev/null
+MessageView_ActionsTest.cxx
+MessageView_ActionsTest.hxx
+MessageView_Communicator.cxx
+MessageView_Communicator.hxx
+MessageView_VisibilityState.cxx
+MessageView_VisibilityState.hxx
+MessageView_Window.cxx
+MessageView_Window.hxx
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageView_ActionsTest.hxx>
+
+#include <inspector/MessageModel_ItemReport.hxx>
+#include <inspector/MessageModel_ItemRoot.hxx>
+#include <inspector/MessageModel_ItemAlert.hxx>
+#include <inspector/MessageModel_Tools.hxx>
+#include <inspector/MessageModel_TreeModel.hxx>
+#include <inspector/TInspectorAPI_PluginParameters.hxx>
+#include <inspector/ViewControl_Tools.hxx>
+
+#include <Message.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_PrinterToReport.hxx>
+
+#include <gp_Ax1.hxx>
+#include <gp_Ax2.hxx>
+#include <gp_Ax3.hxx>
+#include <Bnd_Box.hxx>
+#include <Bnd_OBB.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <OSD_Chronometer.hxx>
+#include <Quantity_Color.hxx>
+#include <Quantity_ColorRGBA.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TopoDS_AlertAttribute.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QAction>
+#include <QFileDialog>
+#include <QItemSelectionModel>
+#include <QMenu>
+#include <QMessageBox>
+#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
+
+#define DEBUG_ALERTS
+
+#ifdef DEBUG_ALERTS
+#include <Message_Level.hxx>
+#endif
+
+#include <ctime>
+
+
+// =======================================================================
+// function : Constructor
+// purpose :
+// =======================================================================
+MessageView_ActionsTest::MessageView_ActionsTest (QWidget* theParent,
+ MessageModel_TreeModel* theTreeModel, QItemSelectionModel* theModel)
+: QObject (theParent), myTreeModel (theTreeModel), mySelectionModel (theModel)
+{
+ myActions.insert (MessageModel_ActionType_TestMetric,
+ ViewControl_Tools::CreateAction ("Test <metric>", SLOT (OnTestMetric()), parent(), this));
+ myActions.insert (MessageModel_ActionType_TestProperties,
+ ViewControl_Tools::CreateAction ("Test <PropertyPanel>", SLOT (OnTestPropertyPanel()), parent(), this));
+ myActions.insert (MessageModel_ActionType_TestMessenger,
+ ViewControl_Tools::CreateAction ("Test <Message_Messenger>", SLOT (OnTestMessenger()), parent(), this));
+ myActions.insert (MessageModel_ActionType_TestReportTree,
+ ViewControl_Tools::CreateAction ("Test <Tree of messages>", SLOT (OnTestReportTree()), parent(), this));
+ myActions.insert (MessageModel_ActionType_TestReportTree2,
+ ViewControl_Tools::CreateAction ("Test <Tree of messages> 2", SLOT (OnTestReportTree2()), parent(), this));
+}
+
+// =======================================================================
+// function : AddMenuActions
+// purpose :
+// =======================================================================
+void MessageView_ActionsTest::AddMenuActions (const QModelIndexList& theSelectedIndices, QMenu* theMenu)
+{
+ MessageModel_ItemRootPtr aRootItem;
+ MessageModel_ItemReportPtr aReportItem;
+ MessageModel_ItemAlertPtr anAlertItem;
+ for (QModelIndexList::const_iterator aSelIt = theSelectedIndices.begin(); aSelIt != theSelectedIndices.end(); aSelIt++)
+ {
+ QModelIndex anIndex = *aSelIt;
+ if (anIndex.column() != 0)
+ continue;
+
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ continue;
+
+ aRootItem = itemDynamicCast<MessageModel_ItemRoot> (anItemBase);
+ if (aRootItem)
+ break;
+
+ aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
+ if (aReportItem)
+ break;
+
+ anAlertItem = itemDynamicCast<MessageModel_ItemAlert> (anItemBase);
+ if (anAlertItem)
+ break;
+ }
+
+ if (aReportItem && !aReportItem->GetReport().IsNull())
+ {
+ theMenu->addAction (myActions[MessageModel_ActionType_TestMetric]);
+ theMenu->addAction (myActions[MessageModel_ActionType_TestProperties]);
+ theMenu->addAction (myActions[MessageModel_ActionType_TestMessenger]);
+ theMenu->addAction (myActions[MessageModel_ActionType_TestReportTree]);
+ theMenu->addAction (myActions[MessageModel_ActionType_TestReportTree2]);
+
+ bool isReportEnabled = aReportItem->GetReport()->IsActiveInMessenger();
+
+ myActions[MessageModel_ActionType_TestMetric]->setEnabled (isReportEnabled);
+ myActions[MessageModel_ActionType_TestProperties]->setEnabled (isReportEnabled);
+ myActions[MessageModel_ActionType_TestMessenger]->setEnabled (isReportEnabled);
+ myActions[MessageModel_ActionType_TestReportTree]->setEnabled (isReportEnabled);
+ myActions[MessageModel_ActionType_TestReportTree2]->setEnabled (isReportEnabled);
+ }
+ theMenu->addSeparator();
+}
+
+// =======================================================================
+// function : getSelectedReport
+// purpose :
+// =======================================================================
+Handle(Message_Report) MessageView_ActionsTest::getSelectedReport (QModelIndex& theReportIndex) const
+{
+ MessageModel_ItemReportPtr aReportItem;
+ QModelIndexList aSelectedIndices = mySelectionModel->selectedIndexes();
+ for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
+ {
+ QModelIndex anIndex = *aSelIt;
+ if (anIndex.column() != 0)
+ continue;
+
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ continue;
+
+ aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
+ theReportIndex = anIndex;
+ if (aReportItem)
+ break;
+ }
+ if (!aReportItem)
+ return NULL;
+
+ return aReportItem->GetReport();
+}
+
+// =======================================================================
+// function : OnTestMetric
+// purpose :
+// =======================================================================
+void MessageView_ActionsTest::OnTestMetric()
+{
+#ifdef DEBUG_ALERTS
+ QModelIndex aReportIndex;
+ Handle(Message_Report) aReport = getSelectedReport (aReportIndex);
+ if (aReport.IsNull())
+ return;
+
+ OCCT_ADD_MESSAGE_LEVEL_SENTRY ("MessageModel_Actions::OnTestMetric()");
+ unsigned int start_time = clock();
+ //Standard_Real aSystemSeconds, aCurrentSeconds;
+ //OSD_Chronometer::GetThreadCPU (aCurrentSeconds, aSystemSeconds);
+
+ Standard_Integer aCounter = 1500;//0;
+ Standard_Real aValue = 0., aValue2 = 0.1;
+
+ double* aMemValue;
+ for (int aTopIt = 0; aTopIt < 4; aTopIt++)
+ {
+ Message::SendInfo() << "Calculate";
+ for (int j = 0; j < aCounter; j++)
+ {
+ for (int i = 0; i < aCounter; i++)
+ {
+ aValue = (aValue * 2. + 3.) * 0.5 - 0.3 * 0.5;
+
+ Standard_Real aValue3 = aValue + aValue2 * 0.2;
+ (void)aValue3;
+
+ aMemValue = new double;
+ }
+ }
+ }
+
+ //((MessageModel_TreeModel*)mySelectionModel->model())->EmitLayoutChanged();
+
+ myTreeModel->UpdateTreeModel();
+
+ //Standard_Real aSystemSeconds1, aCurrentSeconds1;
+ //OSD_Chronometer::GetThreadCPU (aCurrentSeconds1, aSystemSeconds1);
+
+ //std::cout << aValue << std::endl;
+ //std::cout << "user time = " << aCurrentSeconds1 - aCurrentSeconds
+ // << ", system time = " << aSystemSeconds1 - aSystemSeconds << std::endl;
+
+ unsigned int end_time = clock();
+ std::cout << "clock() = " << end_time - start_time << std::endl;
+#endif
+}
+
+// =======================================================================
+// function : OnTestPropertyPanel
+// purpose :
+// =======================================================================
+void MessageView_ActionsTest::OnTestPropertyPanel()
+{
+#ifdef DEBUG_ALERTS
+ QModelIndex aReportIndex;
+ Handle(Message_Report) aReport = getSelectedReport (aReportIndex);
+ if (aReport.IsNull())
+ return;
+
+ OCCT_ADD_MESSAGE_LEVEL_SENTRY ("MessageModel_Actions::OnTestPropertyPanel()");
+
+ OCCT_SEND_MESSAGE ("Values")
+ OCCT_SEND_MESSAGE ("Values2")
+ // gp_XYZ
+ {
+ gp_XYZ aCoords (1.3, 2.3, 3.4);
+ OCCT_SEND_DUMPJSON (&aCoords, "gp_XYZ")
+ }
+ // gp_Dir
+ {
+ gp_Dir aDir (0.3, 0.3, 0.4);
+ OCCT_SEND_DUMPJSON (&aDir, "gp_Dir")
+ }
+ // gp_Ax1
+ {
+ gp_Ax1 aCoords (gp_Pnt (1.3, 2.3, 3.4), gp_Dir (0.3, 0.3, 0.4));
+ OCCT_SEND_DUMPJSON (&aCoords, "gp_Ax1")
+ }
+ // gp_Ax2
+ {
+ gp_Ax2 aCoords (gp_Pnt (10.3, 20.3, 30.4), gp_Dir (0.3, 0.3, 0.4));
+ OCCT_SEND_DUMPJSON (&aCoords, "gp_Ax2")
+ }
+ // gp_Ax3
+ {
+ gp_Ax3 aPln (gp_Pnt (10., 20., 15.), gp_Dir (0., 0., 1.), gp_Dir (1., 0., 0.));
+ OCCT_SEND_DUMPJSON (&aPln, "gp_Ax3")
+ }
+ // gp_Trsf
+ {
+ gp_Trsf aTrsf;
+ aTrsf.SetRotation (gp::OZ(), 0.3);
+ aTrsf.SetTranslationPart (gp_Vec (15., 15., 15.));
+ aTrsf.SetScaleFactor (3.);
+
+ OCCT_SEND_DUMPJSON (&aTrsf, "gp_Trsf")
+ }
+ // Bnd_Box
+ {
+ Bnd_Box aBox (gp_Pnt (20., 15., 10.), gp_Pnt (25., 20., 15.));
+ OCCT_SEND_DUMPJSON (&aBox, "Bnd_Box")
+ }
+ // Bnd_OBB
+ {
+ Bnd_OBB anOBB (gp_Pnt (-10., -15., -10.), gp_Dir (1., 0., 0.), gp_Dir (0., 1., 0.), gp_Dir (0., 0., 1.),
+ 5., 10., 5.);
+ OCCT_SEND_DUMPJSON (&anOBB, "Bnd_OBB");
+ }
+ // Quantity_ColorRGBA
+ {
+ Quantity_ColorRGBA aColor (0.2f, 0.8f, 0.8f, 0.2f);
+ OCCT_SEND_DUMPJSON (&aColor, "Quantity_ColorRGBA");
+ }
+ // Quantity_Color
+ {
+ Quantity_Color aColor (0.8, 0.8, 0.8, Quantity_TOC_RGB);
+ OCCT_SEND_DUMPJSON (&aColor, "Quantity_Color");
+ }
+
+ // stream of some table values
+ {
+ Standard_SStream aStream;
+ OCCT_DUMP_FIELD_VALUES_NUMERICAL (aStream, "value_1", 1, 100);
+ OCCT_DUMP_FIELD_VALUES_STRING (aStream, "value_2", 2, "value_1", "value_2");
+ OCCT_SEND_STREAM (aStream, "Table: Name to value");
+ }
+
+ // SHAPE messages
+ {
+ BRepBuilderAPI_MakeEdge aBuilder (gp_Pnt (0., 0., 0.), gp_Pnt (20., 10., 20.));
+ TopoDS_Shape aShape = aBuilder.Shape();
+
+ MESSAGE_INFO_SHAPE (aShape, "Shape message edge");
+ }
+
+ myTreeModel->UpdateTreeModel();
+#endif
+}
+
+// =======================================================================
+// function : createShapeOnLevel
+// purpose :
+// =======================================================================
+void createShapeOnLevel()
+{
+ OCCT_ADD_MESSAGE_LEVEL_SENTRY ("createShapeOnLevel")
+
+ Message_Messenger::StreamBuffer sout = Message::SendInfo();
+
+ BRepBuilderAPI_MakeEdge aBuilder (gp_Pnt (0., 0., 0.), gp_Pnt (20., 10., 20.));
+ TopoDS_Shape aShape = aBuilder.Shape();
+
+ MESSAGE_INFO_SHAPE (aShape, "Shape message edge ON LEVEL");
+ //sout << "Shape message edge" << aShape;
+}
+
+// =======================================================================
+// function : createShape
+// purpose :
+// =======================================================================
+void createShape()
+{
+ Message_Messenger::StreamBuffer sout = Message::SendInfo();
+
+ BRepBuilderAPI_MakeEdge aBuilder (gp_Pnt (0., 0., 0.), gp_Pnt (20., 10., 20.));
+ TopoDS_Shape aShape = aBuilder.Shape();
+
+ MESSAGE_INFO_SHAPE (aShape, "Shape message edge");
+ //sout << "Shape message edge" << aShape;
+
+ createShapeOnLevel();
+}
+
+// =======================================================================
+// function : OnTestMessenger
+// purpose :
+// =======================================================================
+void MessageView_ActionsTest::OnTestMessenger()
+{
+ // string messages
+ Message_Messenger::StreamBuffer sout = Message::SendInfo();
+ Standard_Integer aTraceLevel_prev = Message::DefaultMessenger()->TraceLevel();
+ Message::DefaultMessenger()->SetTraceLevel (1);
+
+ OCCT_ADD_MESSAGE_LEVEL_SENTRY ("MessageModel_Actions::OnTestMessenger()")
+
+ sout << "IGESBasic_Hierarchy" << std::endl;
+ sout << "Number of property valueaMessenger : " << 15 << std::endl;
+ sout << "Line Font : " << 1 << std::endl << "View Number : " << 3 << std::endl;
+ sout << "Entity level : " << 1 << std::endl;
+ sout << "Blank statuaMessenger : " << 0 << std::endl;
+ sout << "Line weight : " << 14 << std::endl;
+ sout << "Color number : " << 5 << std::endl;
+
+ // stream messages
+ // gp_XYZ
+ {
+ gp_XYZ aCoords (1.3, 2.3, 3.4);
+ Standard_SStream aStream;
+ //aCoords.DumpJson (aStream);
+ //sout << "gp_XYZ" << aStream << std::endl;
+ aCoords.DumpJson (sout);
+ }
+ // Bnd_Box
+ {
+ Bnd_Box aBox (gp_Pnt (20., 15., 10.), gp_Pnt (25., 20., 15.));
+ Standard_SStream aStream;
+ //aBox.DumpJson (aStream);
+ //sout << "Bnd_Box" << aStream;
+ aBox.DumpJson (sout);
+ }
+
+ // object messages
+ Handle(Standard_Transient) anObject = new Message_AlertExtended();
+ //sout << "Message_AlertExtended" << anObject;
+
+ // shape messages
+ {
+ BRepBuilderAPI_MakeEdge aBuilder (gp_Pnt (0., 0., 0.), gp_Pnt (20., 10., 20.));
+ TopoDS_Shape aShape = aBuilder.Shape();
+
+ MESSAGE_INFO_SHAPE (aShape, "Shape message edge");
+ //sout << "Shape message edge" << aShape;
+
+ createShape();
+ }
+ myTreeModel->UpdateTreeModel();
+ Message::DefaultMessenger()->SetTraceLevel (aTraceLevel_prev);
+}
+
+// =======================================================================
+// function : levelAlerts
+// purpose :
+// =======================================================================
+void levelAlerts (const int theCurrentLevel, const int theTopLevel)
+{
+ if (theTopLevel - theCurrentLevel <= 0)
+ return;
+
+ OCCT_ADD_MESSAGE_LEVEL_SENTRY (TCollection_AsciiString ("Level: " ) + theCurrentLevel)
+
+ Message_Messenger::StreamBuffer sout = Message::SendInfo();
+ sout << "Alert(" << theCurrentLevel << "): " << 1 << ", " << 2 << std::endl;
+ sout << "Alert(" << theCurrentLevel << "): " << 3 << ", " << 4 << std::endl;
+
+ //for (int i = 0; i < 2; i++)
+ levelAlerts (theCurrentLevel + 1, theTopLevel);
+
+ sout << "Alert(" << theCurrentLevel << "): " << 4 << ", " << 5 << std::endl;
+}
+
+// =======================================================================
+// function : levelAlert
+// purpose :
+// =======================================================================
+void levelAlert (const int theCurrentLevel, const int theTopLevel)
+{
+ if (theTopLevel - theCurrentLevel <= 0)
+ return;
+
+ OCCT_ADD_MESSAGE_LEVEL_SENTRY ("levelAlert")
+
+ Message_Messenger::StreamBuffer sout = Message::SendInfo();
+ sout << "Level: " << theCurrentLevel << "(Single, no alerts on the level)" << std::endl;
+
+ //for (int i = 0; i < 2; i++)
+ levelAlerts (theCurrentLevel + 1, theTopLevel);
+}
+
+// =======================================================================
+// function : OnTestReportTree
+// purpose :
+// =======================================================================
+void MessageView_ActionsTest::OnTestReportTree()
+{
+ OCCT_ADD_MESSAGE_LEVEL_SENTRY ("MessageModel_Actions::OnTestReportTree()")
+ Message_Messenger::StreamBuffer sout = Message::SendInfo();
+
+ // string messages
+ //sout << "Alert: " << 1 << std::endl;
+ //sout << "Alert: " << 2 << std::endl;
+
+ int aTopLevel = 3;
+ levelAlerts (1, aTopLevel);
+
+ //sout << "Alert: " << 3 << std::endl;
+ //levelAlerts (1, aTopLevel);
+
+ sout << "Alert: " << 4 << std::endl;
+ levelAlert (1, aTopLevel);
+
+ myTreeModel->UpdateTreeModel();
+}
+
+// =======================================================================
+// function : OnTestReportTree2
+// purpose :
+// =======================================================================
+void MessageView_ActionsTest::OnTestReportTree2()
+{
+ OCCT_ADD_MESSAGE_LEVEL_SENTRY ("MessageModel_Actions::OnTestReportTree()")
+ Message_Messenger::StreamBuffer sout = Message::SendInfo();
+
+ // string messages
+ //sout << "Alert: " << 1 << std::endl;
+ //sout << "Alert: " << 2 << std::endl;
+
+ int aTopLevel = 3;
+ levelAlerts (1, aTopLevel);
+
+ //sout << "Alert: " << 3 << std::endl;
+ //levelAlerts (1, aTopLevel);
+
+ //sout << "Alert: " << 4 << std::endl;
+ //levelAlert (1, aTopLevel);
+
+ myTreeModel->UpdateTreeModel();
+}
--- /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.
+
+#ifndef MessageView_ActionsTest_H
+#define MessageView_ActionsTest_H
+
+#include <Standard.hxx>
+#include <Standard_Handle.hxx>
+#include <Standard_Transient.hxx>
+
+#include <inspector/MessageModel_ActionType.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QObject>
+#include <QMap>
+#include <QModelIndexList>
+#include <QPoint>
+#include <QString>
+#include <Standard_WarningsRestore.hxx>
+
+class Message_Report;
+class MessageModel_TreeModel;
+class QItemSelectionModel;
+
+class QAction;
+class QWidget;
+class QMenu;
+
+//! \class MessageView_ActionsTest
+//! Window that unites all MessageView controls.
+class MessageView_ActionsTest : public QObject
+{
+ Q_OBJECT
+public:
+
+ //! Constructor
+ MessageView_ActionsTest (QWidget* theParent, MessageModel_TreeModel* theTreeModel, QItemSelectionModel* theModel);
+
+ //! Destructor
+ virtual ~MessageView_ActionsTest() {}
+
+ //! Fills popup menu with actions depending on the current selection
+ //! \param theSelectedIndices tree model selected indices
+ //! \param theMenu menu to be filled
+ Standard_EXPORT void AddMenuActions (const QModelIndexList& theSelectedIndices, QMenu* theMenu);
+
+public slots:
+ //! Sending several alerts to check metric of message-alert-tool mechanizm
+ void OnTestMetric();
+
+ //! Sending several alerts to check property panel/presentations of message-alert-tool mechanizm
+ void OnTestPropertyPanel();
+
+ //! Sending several alerts to check property panel/presentations of messenger-alert-tool mechanizm
+ void OnTestMessenger();
+
+ //! Check tree of alerts
+ void OnTestReportTree();
+
+ //! Check tree of alerts
+ void OnTestReportTree2();
+
+protected:
+ //! Returns report of selected tree view item if a report item is selected
+ //! \param theReportIndex tree model index of the found report
+ //! \return report instance or NULL
+ Handle(Message_Report) getSelectedReport (QModelIndex& theReportIndex) const;
+
+protected:
+ MessageModel_TreeModel* myTreeModel; //< tree model
+ QItemSelectionModel* mySelectionModel; //< selection model
+ QMap<MessageModel_ActionType, QAction*> myActions; //!< container of all actions
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageView_Communicator.hxx>
+
+
+// =======================================================================
+// function : CreateCommunicator
+// purpose : Creates a communicator by the library loading
+// =======================================================================
+Standard_EXPORTEXTERNC TInspectorAPI_Communicator* CreateCommunicator()
+{
+ return new MessageView_Communicator();
+}
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageView_Communicator_H
+#define MessageView_Communicator_H
+
+#include <inspector/MessageView_Window.hxx>
+#include <inspector/TInspectorAPI_Communicator.hxx>
+
+//! \class MessageView_Communicator.
+//! \brief This is a connector from TInspector application to MessageView window
+class MessageView_Communicator : public TInspectorAPI_Communicator
+{
+public:
+
+ //! Constructor
+ MessageView_Communicator() : TInspectorAPI_Communicator(), myWindow (new MessageView_Window (0)) {}
+
+ //! Destructor
+ virtual ~MessageView_Communicator() Standard_OVERRIDE {}
+
+ //! Provides the container with a parent where this container should be inserted.
+ //! If Qt implementation, it should be QWidget with QLayout set inside
+ //! \param theParent a parent class
+ virtual void SetParent (void* theParent) Standard_OVERRIDE { myWindow->SetParent (theParent); }
+
+ //! Sets parameters container, it should be used when the plugin is initialized or in update content
+ //! \param theParameters a parameters container
+ virtual void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) Standard_OVERRIDE
+ { myWindow->SetParameters (theParameters); }
+
+ //! Provide container for actions available in inspector on general level
+ //! \param theMenu if Qt implementation, it is QMenu object
+ virtual void FillActionsMenu(void* theMenu) Standard_OVERRIDE { myWindow->FillActionsMenu (theMenu); }
+
+ //! Returns plugin preferences, empty implementation by default
+ //! \param theItem container of preference elements
+ virtual void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
+ { myWindow->GetPreferences (theItem); }
+
+ //! Stores plugin preferences, empty implementation by default
+ //! \param theItem container of preference elements
+ virtual void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
+ { myWindow->SetPreferences (theItem); }
+
+ //! Calls update of the plugin's content
+ virtual void UpdateContent() Standard_OVERRIDE { myWindow->UpdateContent(); }
+
+private:
+
+ MessageView_Window* myWindow; //!< current window
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageView_VisibilityState.hxx>
+#include <inspector/MessageModel_ItemAlert.hxx>
+
+#include <Message_AlertExtended.hxx>
+#include <Message_AttributeStream.hxx>
+
+#include <TopoDS_AlertAttribute.hxx>
+
+// =======================================================================
+// function : CanBeVisible
+// purpose :
+// =======================================================================
+bool MessageView_VisibilityState::CanBeVisible (const QModelIndex& theIndex) const
+{
+ MessageModel_ItemAlertPtr anAlertItem = getAlertItem (theIndex);
+ if (anAlertItem)
+ {
+ NCollection_List<Handle(Standard_Transient)> aPresentations;
+ anAlertItem->Presentations (aPresentations);
+ if (!aPresentations.IsEmpty())
+ return true;
+ }
+
+ return !Shape (theIndex).IsNull();// || hasTableValues (theIndex);
+}
+
+// =======================================================================
+// function : SetVisible
+// purpose :
+// =======================================================================
+bool MessageView_VisibilityState::SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged)
+{
+ TopoDS_Shape aShape = Shape (theIndex);
+ if (aShape.IsNull())
+ return false;
+
+ myDisplayer->SetVisible (aShape, theState, myPresentationType);
+
+ if (!theState) {
+ MessageModel_ItemAlertPtr anAlertItem = getAlertItem (theIndex);
+ if (anAlertItem && !anAlertItem->GetCustomShape().IsNull())
+ anAlertItem->SetCustomShape (TopoDS_Shape());
+ }
+
+ if (toEmitDataChanged)
+ {
+ QModelIndex anIndex = theIndex;
+ if (theIndex.column() != TreeModel_ColumnType_Visibility)
+ anIndex = theIndex.model()->index(theIndex.row(), TreeModel_ColumnType_Visibility, theIndex.parent());
+
+ getModel()->EmitDataChanged (anIndex, anIndex);
+ }
+ return true;
+}
+
+// =======================================================================
+// function : IsVisible
+// purpose :
+// =======================================================================
+bool MessageView_VisibilityState::IsVisible (const QModelIndex& theIndex) const
+{
+ return myDisplayer->IsVisible (Shape (theIndex), myPresentationType);
+}
+
+// =======================================================================
+// function : OnClicked
+// purpose :
+// =======================================================================
+void MessageView_VisibilityState::OnClicked (const QModelIndex& theIndex)
+{
+ processClicked (theIndex);
+ emit itemClicked (theIndex);
+}
+
+// =======================================================================
+// function : getAlertItem
+// purpose :
+// =======================================================================
+MessageModel_ItemAlertPtr MessageView_VisibilityState::getAlertItem (const QModelIndex& theIndex) const
+{
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theIndex);
+ if (!anItemBase)
+ return MessageModel_ItemAlertPtr();
+
+ MessageModel_ItemAlertPtr anAlertItem = itemDynamicCast<MessageModel_ItemAlert>(anItemBase);
+ return anAlertItem;
+}
+
+// =======================================================================
+// function : Shape
+// purpose :
+// =======================================================================
+TopoDS_Shape MessageView_VisibilityState::Shape (const QModelIndex& theIndex) const
+{
+ MessageModel_ItemAlertPtr anAlertItem = getAlertItem (theIndex);
+ if (!anAlertItem)
+ return TopoDS_Shape();
+
+ /*if (!anAlertItem->GetCustomShape().IsNull())
+ return anAlertItem->GetCustomShape();
+
+ Handle(Message_Alert) anAlert = anAlertItem->GetAlert();
+ if (anAlert.IsNull())
+ return TopoDS_Shape();
+
+ Handle(Message_AlertExtended) anAlertExtended = Handle(Message_AlertExtended)::DownCast(anAlert);
+ if (anAlertExtended.IsNull())
+ return TopoDS_Shape();
+
+ Handle(TopoDS_AlertAttribute) aShapeAttribute = Handle(TopoDS_AlertAttribute)::DownCast (anAlertExtended->Attribute());
+ if (!aShapeAttribute.IsNull())
+ return aShapeAttribute->GetShape();
+ */
+ return TopoDS_Shape();
+}
+
+// =======================================================================
+// function : hasTableValues
+// purpose :
+// =======================================================================
+bool MessageView_VisibilityState::hasTableValues (const QModelIndex& theIndex) const
+{
+ MessageModel_ItemAlertPtr anAlertItem = getAlertItem (theIndex);
+ if (!anAlertItem)
+ return false;
+
+ Handle(Message_Alert) anAlert = anAlertItem->GetAlert();
+ if (anAlert.IsNull())
+ return false;
+
+ if (anAlert->IsKind (STANDARD_TYPE (Message_AttributeStream)))
+ return true;
+
+ return false;
+}
\ No newline at end of file
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageView_VisibilityState_H
+#define MessageView_VisibilityState_H
+
+#include <inspector/TreeModel_VisibilityState.hxx>
+
+#include <inspector/MessageModel_ItemAlert.hxx>
+
+#include <inspector/View_Displayer.hxx>
+
+#include <Standard.hxx>
+#include <Standard_Macro.hxx>
+#include <TopoDS_Shape.hxx>
+
+class TreeModel_ModelBase;
+
+//! \class MessageView_VisibilityState
+//! \brief Class provides connection between model and visualization control
+class MessageView_VisibilityState : public QObject, public TreeModel_VisibilityState
+{
+ Q_OBJECT
+public:
+ //! Constructor
+ MessageView_VisibilityState (TreeModel_ModelBase* theModel)
+ : TreeModel_VisibilityState (theModel), myPresentationType (View_PresentationType_Main) {}
+
+ //! Destructor
+ ~MessageView_VisibilityState() {}
+
+ //! Sets current displayer
+ //! \theDisplayer class that provides connection to visualized objects
+ void SetDisplayer (View_Displayer* theDisplayer) { myDisplayer = theDisplayer; }
+
+ //! Sets presentation type for displayer
+ //! \param theType type value
+ void SetPresentationType (const View_PresentationType theType) { myPresentationType = theType; }
+
+ //! Returns true if visibility of the item can be changed
+ //! \param theIndex tree model index
+ //! \return boolean value
+ Standard_EXPORT virtual bool CanBeVisible (const QModelIndex& theIndex) const Standard_OVERRIDE;
+
+ //! Sets visibility state
+ //! \theIndex tree model index
+ //! \param theState visibility state
+ //! \param toEmitDataChanged boolean flag whether emit of the model should be done immediatelly
+ //! \return true if state is changed
+ Standard_EXPORT virtual bool SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged) Standard_OVERRIDE;
+
+ //! Returns visibility state value
+ Standard_EXPORT virtual bool IsVisible (const QModelIndex& theIndex) const Standard_OVERRIDE;
+
+public slots:
+ //! Processes the mouse clicked on the index.
+ //! It changes the item visibility if model allows to change it.
+ //! \theIndex tree model index
+ void OnClicked (const QModelIndex& theIndex);
+
+signals:
+ //! Signal after OnClicked is performed
+ //! \theIndex tree model index
+ void itemClicked (const QModelIndex& theIndex);
+
+protected:
+ //! Gets the alert item
+ //! \theIndex tree model index
+ //! \return item or NULL
+ MessageModel_ItemAlertPtr getAlertItem (const QModelIndex& theIndex) const;
+
+ //! Gets shape of the view model by the parameter index if it has a shape
+ //! \param theIndex tree model index
+ //! \return shape instance
+ TopoDS_Shape Shape (const QModelIndex& theIndex) const;
+
+ //! Returns true if alert of the item has table values
+ //! \param theIndex tree model index
+ //! \return boolean result
+ bool hasTableValues (const QModelIndex& theIndex) const;
+
+private:
+ View_Displayer* myDisplayer; //! view displayer
+ View_PresentationType myPresentationType; //! presentation type
+};
+
+#endif
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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 <inspector/MessageView_Window.hxx>
+#include <inspector/MessageView_VisibilityState.hxx>
+#include <inspector/MessageView_ActionsTest.hxx>
+
+#include <inspector/MessageModel_Actions.hxx>
+#include <inspector/MessageModel_ItemAlert.hxx>
+#include <inspector/MessageModel_ItemReport.hxx>
+#include <inspector/MessageModel_ItemRoot.hxx>
+#include <inspector/MessageModel_Tools.hxx>
+#include <inspector/MessageModel_TreeModel.hxx>
+
+#include <inspector/TreeModel_ContextMenu.hxx>
+#include <inspector/TreeModel_Tools.hxx>
+
+#include <inspector/ViewControl_PropertyView.hxx>
+#include <inspector/ViewControl_TableModelValues.hxx>
+#include <inspector/ViewControl_TreeView.hxx>
+#include <inspector/Convert_Tools.hxx>
+
+#include <inspector/View_Viewer.hxx>
+#include <inspector/View_Widget.hxx>
+
+#include <AIS_Shape.hxx>
+#include <Graphic3d_Camera.hxx>
+#include <OSD_Environment.hxx>
+#include <OSD_Directory.hxx>
+#include <OSD_Protection.hxx>
+#include <Message.hxx>
+#include <TCollection_AsciiString.hxx>
+
+#define DEBUG_ALERTS
+
+#include <XmlDrivers_MessageReportStorage.hxx>
+
+#include <inspector/ViewControl_Tools.hxx>
+#include <inspector/View_Displayer.hxx>
+#include <inspector/View_ToolBar.hxx>
+#include <inspector/View_Widget.hxx>
+#include <inspector/View_Window.hxx>
+#include <inspector/View_Viewer.hxx>
+
+#include <BRep_Builder.hxx>
+#include <BRepTools.hxx>
+#include <OSD_File.hxx>
+#include <OSD_Path.hxx>
+
+#include <QApplication>
+#include <QAction>
+#include <QComboBox>
+#include <QDockWidget>
+#include <QDir>
+#include <QFile>
+#include <QFileDialog>
+#include <QHeaderView>
+#include <QMainWindow>
+#include <QMenu>
+#include <QMessageBox>
+#include <QPlainTextEdit>
+#include <QPushButton>
+#include <QTextEdit>
+#include <QTextStream>
+#include <QToolBar>
+#include <QToolButton>
+#include <QTreeView>
+#include <QWidget>
+#include <QVBoxLayout>
+
+const int DEFAULT_TEXT_VIEW_WIDTH = 400;// 800;
+const int DEFAULT_TEXT_VIEW_HEIGHT = 700;
+const int DEFAULT_TEXT_VIEW_POSITION_X = 430;
+const int DEFAULT_TEXT_VIEW_POSITION_Y = 30;
+const int DEFAULT_TEXT_VIEW_DELTA = 100;
+
+const int DEFAULT_SHAPE_VIEW_WIDTH = 400;// 900;
+const int DEFAULT_SHAPE_VIEW_HEIGHT = 450;
+const int DEFAULT_SHAPE_VIEW_POSITION_X = 60;
+const int DEFAULT_SHAPE_VIEW_POSITION_Y = 60;
+
+const int DEFAULT_DETACH_POSITION_X = 5;
+const int DEFAULT_DETACH_POSITION_Y = 450;
+
+const int MESSAGEVIEW_DEFAULT_TREE_VIEW_WIDTH = 950; //600
+const int MESSAGEVIEW_DEFAULT_TREE_VIEW_HEIGHT = 500;
+
+const int MESSAGEVIEW_DEFAULT_VIEW_WIDTH = 200;// 400;
+const int MESSAGEVIEW_DEFAULT_VIEW_HEIGHT = 300;// 1000;
+
+#include <Prs3d_PointAspect.hxx>
+#include <Prs3d_ShadingAspect.hxx>
+Handle(Prs3d_Drawer) GetPreviewAttributes (const Handle(AIS_InteractiveContext)& theContext)
+{
+ Handle(Prs3d_Drawer) myDrawer = new Prs3d_Drawer();
+ myDrawer->Link (theContext->DefaultDrawer());
+
+ Quantity_Color aColor(Quantity_NOC_TOMATO);//Quantity_NOC_GREENYELLOW));//Quantity_NOC_BLUE1));
+ Standard_ShortReal aTransparency = 0.8;
+
+ // point parameters
+ myDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_O_PLUS, aColor, 3.0));
+
+ // shading parameters
+ Graphic3d_MaterialAspect aShadingMaterial;
+ aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
+ aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT);
+
+ myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
+ myDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID);
+ myDrawer->ShadingAspect()->SetColor (aColor);
+ myDrawer->ShadingAspect()->SetMaterial (aShadingMaterial);
+
+ myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (aTransparency);
+ myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (aTransparency);
+ myDrawer->SetTransparency (aTransparency);
+
+ // common parameters
+ myDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
+
+ return myDrawer;
+}
+
+// =======================================================================
+// function : Constructor
+// purpose :
+// =======================================================================
+MessageView_Window::MessageView_Window (QWidget* theParent)
+: QObject (theParent)
+{
+ myMainWindow = new QMainWindow (theParent);
+
+ myTreeView = new ViewControl_TreeView (myMainWindow);
+ ((ViewControl_TreeView*)myTreeView)->SetPredefinedSize (QSize (MESSAGEVIEW_DEFAULT_TREE_VIEW_WIDTH,
+ MESSAGEVIEW_DEFAULT_TREE_VIEW_HEIGHT));
+ MessageModel_TreeModel* aModel = new MessageModel_TreeModel (myTreeView);
+ aModel->InitColumns();
+ //aModel->SetReversed (Standard_True);
+
+ myTreeView->setModel (aModel);
+ MessageView_VisibilityState* aVisibilityState = new MessageView_VisibilityState (aModel);
+ aModel->SetVisibilityState (aVisibilityState);
+ connect (aVisibilityState, SIGNAL (itemClicked (const QModelIndex&)), this, SLOT(onTreeViewVisibilityClicked(const QModelIndex&)));
+
+ TreeModel_Tools::UseVisibilityColumn (myTreeView);
+ TreeModel_Tools::SetDefaultHeaderSections (myTreeView);
+
+ QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aModel);
+ myTreeView->setSelectionMode (QAbstractItemView::ExtendedSelection);
+ myTreeView->setSelectionModel (aSelectionModel);
+ connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
+ this, SLOT (onTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
+
+ myTreeViewActions = new MessageModel_Actions (myMainWindow, aModel, aSelectionModel);
+ myTestViewActions = new MessageView_ActionsTest (myMainWindow, aModel, aSelectionModel);
+
+ myTreeView->setContextMenuPolicy (Qt::CustomContextMenu);
+ connect (myTreeView, SIGNAL (customContextMenuRequested (const QPoint&)),
+ this, SLOT (onTreeViewContextMenuRequested (const QPoint&)));
+ //new TreeModel_ContextMenu (myTreeView);
+
+ QModelIndex aParentIndex = myTreeView->model()->index (0, 0);
+ myTreeView->setExpanded (aParentIndex, true);
+
+ myMainWindow->setCentralWidget (myTreeView);
+
+ // property view
+ myPropertyView = new ViewControl_PropertyView (myMainWindow);
+ myPropertyPanelWidget = new QDockWidget (tr ("PropertyPanel"), myMainWindow);
+ myPropertyPanelWidget->setObjectName (myPropertyPanelWidget->windowTitle());
+ myPropertyPanelWidget->setTitleBarWidget (new QWidget(myMainWindow));
+ myPropertyPanelWidget->setWidget (myPropertyView->GetControl());
+ myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myPropertyPanelWidget);
+ connect (myPropertyPanelWidget->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT (onPropertyPanelShown (bool)));
+ connect (myPropertyView, SIGNAL (propertyViewDataChanged()), this, SLOT (onPropertyViewDataChanged()));
+
+
+ // view
+ myViewWindow = new View_Window (myMainWindow, false);
+ connect (myViewWindow, SIGNAL(eraseAllPerformed()), this, SLOT(onEraseAllPerformed()));
+ aVisibilityState->SetDisplayer (myViewWindow->Displayer());
+ aVisibilityState->SetPresentationType (View_PresentationType_Main);
+ myViewWindow->ViewWidget()->SetPredefinedSize (MESSAGEVIEW_DEFAULT_VIEW_WIDTH, MESSAGEVIEW_DEFAULT_VIEW_HEIGHT);
+
+ myViewDockWidget = new QDockWidget (tr ("View"), myMainWindow);
+ myViewDockWidget->setObjectName (myViewDockWidget->windowTitle());
+ myViewDockWidget->setWidget (myViewWindow);
+ myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myViewDockWidget);
+
+ myMainWindow->resize (DEFAULT_SHAPE_VIEW_WIDTH, DEFAULT_SHAPE_VIEW_HEIGHT);
+ myMainWindow->move (DEFAULT_SHAPE_VIEW_POSITION_X, DEFAULT_SHAPE_VIEW_POSITION_Y);
+
+ updateVisibleColumns();
+}
+
+// =======================================================================
+// function : SetParent
+// purpose :
+// =======================================================================
+void MessageView_Window::SetParent (void* theParent)
+{
+ QWidget* aParent = (QWidget*)theParent;
+ if (aParent)
+ {
+ QLayout* aLayout = aParent->layout();
+ if (aLayout)
+ aLayout->addWidget (GetMainWindow());
+ }
+ else
+ {
+ GetMainWindow()->setParent (0);
+ GetMainWindow()->setVisible (true);
+ }
+}
+
+// =======================================================================
+// function : FillActionsMenu
+// purpose :
+// =======================================================================
+void MessageView_Window::FillActionsMenu (void* theMenu)
+{
+ QMenu* aMenu = (QMenu*)theMenu;
+ QList<QDockWidget*> aDockwidgets = myMainWindow->findChildren<QDockWidget*>();
+ for (QList<QDockWidget*>::iterator it = aDockwidgets.begin(); it != aDockwidgets.end(); ++it)
+ {
+ QDockWidget* aDockWidget = *it;
+ if (aDockWidget->parentWidget() == myMainWindow)
+ aMenu->addAction (aDockWidget->toggleViewAction());
+ }
+}
+
+// =======================================================================
+// function : GetPreferences
+// purpose :
+// =======================================================================
+void MessageView_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
+{
+ theItem.Clear();
+ theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str());
+
+ QMap<QString, QString> anItems;
+ //TreeModel_Tools::SaveState (myTreeView, anItems);
+
+ anItems.clear();
+ View_Window::SaveState(myViewWindow, anItems);
+ for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++)
+ theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
+
+ for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++)
+ theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
+}
+
+// =======================================================================
+// function : SetPreferences
+// purpose :
+// =======================================================================
+void MessageView_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem)
+{
+ for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (theItem); anItemIt.More(); anItemIt.Next())
+ {
+ if (anItemIt.Key().IsEqual ("geometry"))
+ myMainWindow->restoreState (TreeModel_Tools::ToByteArray (anItemIt.Value().ToCString()));
+ //else if (TreeModel_Tools::RestoreState (myTreeView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
+ // continue;
+ else if (myViewWindow && View_Window::RestoreState(myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
+ continue;
+ }
+}
+
+// =======================================================================
+// function : UpdateContent
+// purpose :
+// =======================================================================
+void MessageView_Window::UpdateContent()
+{
+ bool isUpdated = false;
+ TCollection_AsciiString aName = "TKMessageView";
+ if (myParameters->FindParameters (aName))
+ {
+ NCollection_List<Handle(Standard_Transient)> aParameters = myParameters->Parameters (aName);
+ // Init will remove from parameters those, that are processed only one time (TShape)
+ Init (aParameters);
+ myParameters->SetParameters (aName, aParameters);
+ isUpdated = true;
+ }
+ if (myParameters->FindFileNames (aName))
+ {
+ for (NCollection_List<TCollection_AsciiString>::Iterator aFilesIt (myParameters->FileNames (aName));
+ aFilesIt.More(); aFilesIt.Next())
+ openFile (aFilesIt.Value());
+
+ NCollection_List<TCollection_AsciiString> aNames;
+ myParameters->SetFileNames (aName, aNames);
+ isUpdated = true;
+ }
+ Handle(Message_Report) aDefaultReport = Message::DefaultReport (Standard_False);
+ MessageModel_TreeModel* aViewModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ if (!aDefaultReport.IsNull() && !aViewModel->HasReport (aDefaultReport))
+ {
+ addReport (aDefaultReport);
+ }
+ // reload report of selected item
+ //onReloadReport();
+
+ updateTreeModel();
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+void MessageView_Window::Init (NCollection_List<Handle(Standard_Transient)>& theParameters)
+{
+ Handle(AIS_InteractiveContext) aContext;
+ NCollection_List<Handle(Standard_Transient)> aParameters;
+
+ Handle(Graphic3d_Camera) aViewCamera;
+
+ for (NCollection_List<Handle(Standard_Transient)>::Iterator aParamsIt (theParameters);
+ aParamsIt.More(); aParamsIt.Next())
+ {
+ Handle(Standard_Transient) anObject = aParamsIt.Value();
+ Handle(Message_Report) aMessageReport = Handle(Message_Report)::DownCast (anObject);
+ if (!aMessageReport.IsNull())
+ {
+ addReport (aMessageReport);
+ }
+ else if (!Handle(AIS_InteractiveContext)::DownCast (anObject).IsNull())
+ {
+ aParameters.Append (anObject);
+ if (aContext.IsNull())
+ aContext = Handle(AIS_InteractiveContext)::DownCast (anObject);
+ }
+ else if (!Handle(Graphic3d_Camera)::DownCast (anObject).IsNull())
+ {
+ aViewCamera = Handle(Graphic3d_Camera)::DownCast (anObject);
+ }
+ }
+ MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ if (!aTreeModel)
+ return;
+
+ aTreeModel->EmitLayoutChanged();
+
+ if (!aContext.IsNull())
+ {
+ myViewWindow->SetContext (View_ContextType_External, aContext);
+ //myViewWindow->GetViewToolBar()->SetCurrentContextType (View_ContextType_External);
+ }
+
+ //if (!aViewCamera.IsNull())
+ // myViewWindow->View()->Viewer()->View()->Camera()->Copy (aViewCamera);
+
+ theParameters = aParameters;
+}
+
+// =======================================================================
+// function : openFile
+// purpose :
+// =======================================================================
+void MessageView_Window::openFile(const TCollection_AsciiString& theFileName)
+{
+ const Handle(Message_Report)& aReport = Message::DefaultReport();
+
+ //Handle(Message_Report) aReport = new Message_Report();
+ if (aReport->MessageWriter().IsNull())
+ aReport->SetMessageWriter (new XmlDrivers_MessageReportStorage());
+
+ aReport->MessageWriter()->SetFileName (TCollection_AsciiString (theFileName));
+ aReport->MessageWriter()->ImportReport (aReport);
+
+ addReport (aReport, theFileName);
+}
+
+// =======================================================================
+// function : updateTreeModel
+// purpose :
+// =======================================================================
+void MessageView_Window::updateTreeModel()
+{
+ MessageModel_TreeModel* aViewModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ if (!aViewModel)
+ return;
+
+ aViewModel->UpdateTreeModel();
+}
+
+// =======================================================================
+// function : addReport
+// purpose :
+// =======================================================================
+void MessageView_Window::addReport (const Handle(Message_Report)& theReport,
+ const TCollection_AsciiString& theReportDescription)
+{
+ MessageModel_TreeModel* aModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ aModel->AddReport (theReport, theReportDescription);
+
+ updateVisibleColumns();
+}
+
+// =======================================================================
+// function : onTreeViewVisibilityClicked
+// purpose :
+// =======================================================================
+void MessageView_Window::onTreeViewVisibilityClicked(const QModelIndex& theIndex)
+{
+ MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ TreeModel_VisibilityState* aVisibilityState = aTreeModel->GetVisibilityState();
+ if (!aVisibilityState->IsVisible (theIndex))
+ myPropertyView->ClearActiveTablesSelection();
+}
+
+// =======================================================================
+// function : onTreeViewSelectionChanged
+// purpose :
+// =======================================================================
+void MessageView_Window::onTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&)
+{
+ if (!myPropertyPanelWidget->toggleViewAction()->isChecked())
+ return;
+
+ updatePropertyPanelBySelection();
+ updatePreviewPresentation();
+}
+
+// =======================================================================
+// function : onTreeViewContextMenuRequested
+// purpose :
+// =======================================================================
+void MessageView_Window::onTreeViewContextMenuRequested (const QPoint& thePosition)
+{
+ QMenu* aMenu = new QMenu (GetMainWindow());
+
+ MessageModel_ItemRootPtr aRootItem;
+ MessageModel_ItemReportPtr aReportItem;
+ QModelIndexList aSelectedIndices = myTreeView->selectionModel()->selectedIndexes();
+
+ for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
+ {
+ QModelIndex anIndex = *aSelIt;
+ if (anIndex.column() != 0)
+ continue;
+
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ continue;
+
+ aRootItem = itemDynamicCast<MessageModel_ItemRoot> (anItemBase);
+ if (aRootItem)
+ break;
+ aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
+ if (aReportItem)
+ break;
+ }
+ if (aRootItem)
+ {
+ aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Import Report"), SLOT (onImportReport()), myMainWindow, this));
+ // unite
+ //MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ //aMenu->addAction (ViewControl_Tools::CreateAction (aTreeModel->IsUniteAlerts() ? tr ("SetUniteAlerts - OFF") : tr ("SetUniteAlerts - ON"),
+ // SLOT (onUniteAlerts()), myMainWindow, this));
+ // reversed
+ //aMenu->addAction (ViewControl_Tools::CreateAction (aTreeModel->IsReversed() ? tr ("SetReversed - OFF") : tr ("SetReversed - ON"),
+ // SLOT (onSetReversedAlerts()), myMainWindow, this));
+ }
+ else if (aReportItem)
+ {
+ aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Export Report"), SLOT (onExportReport()), myMainWindow, this));
+ const TCollection_AsciiString& aDescription = aReportItem->GetDescription();
+ if (!aDescription.IsEmpty())
+ {
+ OSD_Path aPath(aDescription);
+ OSD_File aDescriptionFile (aPath);
+ if (aDescriptionFile.IsReadable())
+ aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Reload"), SLOT (onReloadReport()), myMainWindow, this));
+ }
+ Handle(Message_Report) aReport = aReportItem->GetReport();
+ QAction* anAction = ViewControl_Tools::CreateAction (tr ("Export by alert"), SLOT (onAutoExportActivate()), myMainWindow, this);
+ anAction->setCheckable (true);
+ anAction->setChecked (aReport->WriteFileOnEachAlert());
+ aMenu->addAction (anAction);
+
+ anAction = ViewControl_Tools::CreateAction (tr ("Export trace only"), SLOT (onExportTraceOnly()), myMainWindow, this);
+ anAction->setCheckable (true);
+ bool isTraceOnly = aReport->MessageWriter().IsNull() ? false : aReport->MessageWriter()->Gravity() == Message_Trace;
+ anAction->setChecked (isTraceOnly);
+ aMenu->addAction (anAction);
+ }
+ aMenu->addSeparator();
+
+ aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Preview children presentations"), SLOT (onPreviewChildren()), myMainWindow, this));
+ aMenu->addSeparator();
+
+ myTreeViewActions->AddMenuActions (aSelectedIndices, aMenu);
+ addActivateMetricActions (aMenu);
+
+#ifdef DEBUG_ALERTS
+ aMenu->addSeparator();
+ myTestViewActions->AddMenuActions (aSelectedIndices, aMenu);
+#endif
+
+ QPoint aPoint = myTreeView->mapToGlobal (thePosition);
+ aMenu->exec (aPoint);
+}
+
+// =======================================================================
+// function : onPropertyPanelShown
+// purpose :
+// =======================================================================
+void MessageView_Window::onPropertyPanelShown (bool isToggled)
+{
+ if (!isToggled)
+ return;
+
+ updatePropertyPanelBySelection();
+}
+
+// =======================================================================
+// function : onPropertyViewDataChanged
+// purpose :
+// =======================================================================
+void MessageView_Window::onPropertyViewDataChanged()
+{
+ QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ return;
+
+ updatePropertyPanelBySelection();
+ updatePreviewPresentation();
+}
+
+// =======================================================================
+// function : onEraseAllPerformed
+// purpose :
+// =======================================================================
+void MessageView_Window::onEraseAllPerformed()
+{
+ MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+
+ // TODO: provide update for only visibility state for better performance TopoDS_Shape myCustomShape;
+
+ aTreeModel->Reset();
+ aTreeModel->EmitLayoutChanged();
+}
+
+// =======================================================================
+// function : onExportReport
+// purpose :
+// =======================================================================
+void MessageView_Window::onExportReport()
+{
+ QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ return;
+ MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItemBase);
+ if (!aReportItem)
+ return;
+
+ QString aFilter (tr ("Document file (*.xml *)"));
+ QString aSelectedFilter;
+ QString aFileName = QFileDialog::getSaveFileName (0, tr ("Export report to file"), QString(), aFilter, &aSelectedFilter);
+
+ Handle(Message_Report) aReport = aReportItem->GetReport();
+ if (aReport->MessageWriter().IsNull())
+ aReport->SetMessageWriter (new XmlDrivers_MessageReportStorage());
+
+ aReport->MessageWriter()->SetFileName (TCollection_AsciiString (aFileName.toStdString().c_str()));
+ aReport->MessageWriter()->ExportReport (aReport);
+}
+
+// =======================================================================
+// function : onImportReport
+// purpose :
+// =======================================================================
+void MessageView_Window::onImportReport()
+{
+ QString aFilter (tr ("Document file (*.cbf *)"));
+ QString aSelectedFilter;
+
+ QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
+ aSelectionModel->clear();
+
+ QString aFileName = QFileDialog::getOpenFileName (0, tr("Import report"), QString(), aSelectedFilter);
+ openFile (TCollection_AsciiString (aFileName.toStdString().c_str()));
+}
+
+// =======================================================================
+// function : onImportReport
+// purpose :
+// =======================================================================
+//void MessageView_Window::onUniteAlerts()
+//{
+ //MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ //Standard_Boolean isUniteAlerts = aTreeModel->IsUniteAlerts();
+
+ //aTreeModel->SetUniteAlerts (!isUniteAlerts);
+//}
+
+// =======================================================================
+// function : onSetReversedAlerts
+// purpose :
+// =======================================================================
+void MessageView_Window::onSetReversedAlerts()
+{
+ MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ Standard_Boolean isReversed = aTreeModel->IsReversed();
+
+ aTreeModel->SetReversed (!isReversed);
+}
+
+// =======================================================================
+// function : onReloadReport
+// purpose :
+// =======================================================================
+void MessageView_Window::onReloadReport()
+{
+ QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ return;
+ MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItemBase);
+ if (!aReportItem)
+ aReportItem = MessageModel_ItemReport::FindReportItem (anItemBase);
+
+ if (!aReportItem)
+ return;
+
+ const TCollection_AsciiString aDescription = aReportItem->GetDescription();
+ if (aDescription.IsEmpty())
+ return;
+
+ Handle(Message_Report) aReport = aReportItem->GetReport();
+ aReport->Clear();
+ if (aReport->MessageWriter().IsNull())
+ aReport->SetMessageWriter (new XmlDrivers_MessageReportStorage());
+
+ aReport->MessageWriter()->SetFileName (TCollection_AsciiString (aDescription));
+ if (!aReport->MessageWriter()->ImportReport (aReport))
+ return;
+
+ MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+ aModel->clearSelection();
+ aTreeModel->SetReport (aReportItem->Row(), aReport, aDescription);
+}
+
+// =======================================================================
+// function : onAutoExportActivate
+// purpose :
+// =======================================================================
+void MessageView_Window::onAutoExportActivate()
+{
+ QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ return;
+ MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItemBase);
+ if (!aReportItem)
+ aReportItem = MessageModel_ItemReport::FindReportItem (anItemBase);
+
+ if (!aReportItem)
+ return;
+
+ Handle(Message_Report) aReport = aReportItem->GetReport();
+ QAction* anAction = (QAction*)(sender());
+ aReport->SetWriteFileOnEachAlert (anAction->isChecked());
+}
+
+// =======================================================================
+// function : onExportTraceOnly
+// purpose :
+// =======================================================================
+void MessageView_Window::onExportTraceOnly()
+{
+ QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ return;
+ MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItemBase);
+ if (!aReportItem)
+ aReportItem = MessageModel_ItemReport::FindReportItem (anItemBase);
+
+ if (!aReportItem)
+ return;
+
+ Handle(Message_Report) aReport = aReportItem->GetReport();
+ if (aReport->MessageWriter().IsNull())
+ return;
+
+ QAction* anAction = (QAction*)(sender());
+ aReport->MessageWriter()->SetGravity (anAction->isChecked() ? Message_Trace : Message_Info);
+}
+
+// =======================================================================
+// function : onPreviewChildren
+// purpose :
+// =======================================================================
+void MessageView_Window::onPreviewChildren()
+{
+ QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+
+ QModelIndexList aSelectedIndices = myTreeView->selectionModel()->selectedIndexes();
+ NCollection_List<Handle(Standard_Transient)> aPresentations;
+ TreeModel_ModelBase::SubItemsPresentations (aSelectedIndices, aPresentations);
+
+ displayer()->UpdatePreview (View_DisplayActionType_DisplayId, aPresentations);
+}
+
+// =======================================================================
+// function : addActivateMetricActions
+// purpose :
+// =======================================================================
+void MessageView_Window::addActivateMetricActions (QMenu* theMenu)
+{
+ QMenu* aSubMenu = new QMenu ("Activate metric");
+
+ Handle(Message_Report) aReport = Message::DefaultReport (Standard_True);
+
+ for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
+ {
+ Message_MetricType aMetricType = (Message_MetricType)aMetricId;
+ QAction* anAction = ViewControl_Tools::CreateAction (Message::MetricToString (aMetricType),
+ SLOT (OnActivateMetric()), parent(), this);
+ anAction->setCheckable (true);
+ anAction->setChecked (aReport->ActiveMetrics().Contains (aMetricType));
+ aSubMenu->addAction (anAction);
+ }
+ aSubMenu->addSeparator();
+ aSubMenu->addAction (ViewControl_Tools::CreateAction ("Deactivate all", SLOT (OnDeactivateAllMetrics()), parent(), this));
+
+ theMenu->addMenu (aSubMenu);
+}
+
+// =======================================================================
+// function : OnActivateMetric
+// purpose :
+// =======================================================================
+void MessageView_Window::OnActivateMetric()
+{
+ QAction* anAction = (QAction*)(sender());
+
+ Message_MetricType aMetricType;
+ if (!Message::MetricFromString (anAction->text().toStdString().c_str(), aMetricType))
+ return;
+
+ Handle(Message_Report) aReport = Message::DefaultReport (Standard_True);
+ const NCollection_Map<Message_MetricType>& anActiveMetrics = aReport->ActiveMetrics();
+
+ aReport->SetActiveMetric (aMetricType, !anActiveMetrics.Contains (aMetricType));
+
+ updateVisibleColumns();
+}
+
+// =======================================================================
+// function : OnDeactivateAllMetrics
+// purpose :
+// =======================================================================
+void MessageView_Window::OnDeactivateAllMetrics()
+{
+ Handle(Message_Report) aReport = Message::DefaultReport();
+ if (aReport.IsNull())
+ return;
+ aReport->ClearMetrics();
+
+ updateVisibleColumns();
+}
+
+// =======================================================================
+// function : displayer
+// purpose :
+// =======================================================================
+View_Displayer* MessageView_Window::displayer()
+{
+ return myViewWindow->Displayer();
+}
+
+// =======================================================================
+// function : updatePropertyPanelBySelection
+// purpose :
+// =======================================================================
+void MessageView_Window::updatePropertyPanelBySelection()
+{
+ /*QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ return;
+
+ QList<ViewControl_TableModelValues*> aTableValues;
+ MessageModel_Tools::GetPropertyTableValues (anItemBase, aTableValues);
+
+ myPropertyView->Init (aTableValues);*/
+ ViewControl_TableModelValues* aTableValues = 0;
+
+ QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (anItemBase)
+ {
+ Handle(TreeModel_ItemProperties) anItemProperties = anItemBase->Properties ();
+ if (!anItemProperties.IsNull())
+ {
+ aTableValues = new ViewControl_TableModelValues();
+ aTableValues->SetProperties (anItemProperties);
+ }
+ }
+ myPropertyView->Init (aTableValues);
+}
+
+// =======================================================================
+// function : updatePreviewPresentation
+// purpose :
+// =======================================================================
+void MessageView_Window::updatePreviewPresentation()
+{
+ Handle(AIS_InteractiveContext) aContext = myViewWindow->ViewToolBar()->CurrentContext();
+ if (aContext.IsNull())
+ return;
+
+ NCollection_List<Handle(Standard_Transient)> aPresentations;
+ QModelIndexList aSelectedIndices = myTreeView->selectionModel()->selectedIndexes();
+ for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
+ {
+ QModelIndex anIndex = *aSelIt;
+ if (anIndex.column() != 0)
+ continue;
+
+ TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
+ if (!anItemBase)
+ continue;
+
+ anItemBase->Presentations (aPresentations);
+ }
+
+ displayer()->UpdatePreview (View_DisplayActionType_DisplayId, aPresentations);
+}
+
+// =======================================================================
+// function : updateVisibleColumns
+// purpose :
+// =======================================================================
+void MessageView_Window::updateVisibleColumns()
+{
+ MessageModel_TreeModel* aViewModel = dynamic_cast<MessageModel_TreeModel*> (myTreeView->model());
+
+ NCollection_Map<Message_MetricType> anActiveMetrics;
+ for (NCollection_List<MessageModel_ReportInformation>::Iterator anIterator (aViewModel->Reports()); anIterator.More(); anIterator.Next())
+ {
+ Handle(Message_Report) aReport = anIterator.Value().myReport;
+ for (NCollection_Map<Message_MetricType>::Iterator aMetricsIterator (aReport->ActiveMetrics()); aMetricsIterator.More(); aMetricsIterator.Next())
+ {
+ if (anActiveMetrics.Contains (aMetricsIterator.Value()))
+ continue;
+ anActiveMetrics.Add (aMetricsIterator.Value());
+ }
+ }
+
+ for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
+ {
+ Message_MetricType aMetricType = (Message_MetricType)aMetricId;
+ QList<int> aMetricColumns;
+ aViewModel->GetMetricColumns (aMetricType, aMetricColumns);
+ bool isColumnHidden = !anActiveMetrics.Contains (aMetricType);
+ for (int i = 0; i < aMetricColumns.size(); i++)
+ {
+ int aColumnId = aMetricColumns[i];
+ myTreeView->setColumnHidden (aColumnId, isColumnHidden);
+ TreeModel_HeaderSection aSection = aViewModel->GetHeaderItem (aColumnId);
+ aSection.SetIsHidden (isColumnHidden);
+ aViewModel->SetHeaderItem (aColumnId, aSection);
+ }
+ }
+}
--- /dev/null
+// Created on: 2017-06-16
+// Created by: Natalia ERMOLAEVA
+// Copyright (c) 2017 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.
+
+#ifndef MessageView_Window_H
+#define MessageView_Window_H
+
+#include <Message_Report.hxx>
+#include <Standard.hxx>
+#include <TCollection_AsciiString.hxx>
+
+#include <inspector/MessageModel_Actions.hxx>
+#include <inspector/TInspectorAPI_PluginParameters.hxx>
+
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_InteractiveObject.hxx>
+#include <TopoDS_Shape.hxx>
+
+#ifdef _MSC_VER
+#pragma warning(disable : 4127) // conditional expression is constant
+#endif
+#include <QItemSelection>
+#include <QList>
+#include <QModelIndexList>
+#include <QObject>
+#include <QPoint>
+#include <QString>
+#include <QTreeView>
+
+class View_Displayer;
+class View_Window;
+
+class ViewControl_PropertyView;
+
+class MessageView_ActionsTest;
+
+class QDockWidget;
+class QMainWindow;
+class QMenu;
+class QWidget;
+
+//! \class MessageView_Window
+//! Window that unites all MessageView controls.
+class MessageView_Window : public QObject
+{
+ Q_OBJECT
+public:
+
+ //! Constructor
+ Standard_EXPORT MessageView_Window (QWidget* theParent);
+
+ //! Destructor
+ virtual ~MessageView_Window() {}
+
+ //! Provides the container with a parent where this container should be inserted.
+ //! If Qt implementation, it should be QWidget with QLayout set inside
+ //! \param theParent a parent class
+ Standard_EXPORT void SetParent (void* theParent);
+
+ //! Sets parameters container, it should be used when the plugin is initialized or in update content
+ //! \param theParameters a parameters container
+ void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters)
+ { myParameters = theParameters; myTreeViewActions->SetParameters (theParameters); }
+
+ //! Provide container for actions available in inspector on general level
+ //! \param theMenu if Qt implementation, it is QMenu object
+ Standard_EXPORT virtual void FillActionsMenu (void* theMenu);
+
+ //! Returns plugin preferences: dock widgets state, tree view columns.
+ //! \param theItem container of preference elements
+ Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
+
+ //! Applies plugin preferences
+ //! \param theItem container of preference elements
+ Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
+
+ //! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
+ Standard_EXPORT void UpdateContent();
+
+ //! Returns main control
+ QMainWindow* GetMainWindow() const { return myMainWindow; }
+
+ //! Returns current tree view
+ QTreeView* GetTreeView() const { return myTreeView; }
+
+protected:
+ //! Appends shape into tree view model
+ //! \param theShape a shape instance
+ //! \param theReportDescription an additional report information
+ void addReport (const Handle(Message_Report)& theReport,
+ const TCollection_AsciiString& theReportDescription = "");
+
+private:
+
+ //! Fills controls of the plugin by parameters:
+ //! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
+ //! \param theParameters a parameters container
+ void Init (NCollection_List<Handle(Standard_Transient)>& theParameters);
+
+ //! Read Shape from the file name, add Shape into tree view
+ //! \param theFileName BREP file name
+ void openFile (const TCollection_AsciiString& theFileName);
+
+ //! Updates tree model
+ void updateTreeModel();
+
+protected slots:
+ //! Updates property view selection in table if the item is hidden
+ //! \param theIndex tree view model index
+ void onTreeViewVisibilityClicked(const QModelIndex& theIndex);
+
+ //! Udpates all controls by changed selection in OCAF tree view
+ //! \param theSelected list of selected tree view items
+ //! \param theDeselected list of deselected tree view items
+ void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
+
+ //! Shows context menu for tree view selected item. It contains expand/collapse actions.
+ //! \param thePosition a clicked point
+ void onTreeViewContextMenuRequested (const QPoint& thePosition);
+
+ //! Display content of selected tree view item if isToggled is true
+ //! \param isToggled true if the property dock widget is shown
+ void onPropertyPanelShown (bool isToggled);
+
+ //! Update tree view item, preview presentation by item value change
+ void onPropertyViewDataChanged();
+
+ //! Updates visibility states by erase all in context
+ void onEraseAllPerformed();
+
+ //! Export report into document
+ void onExportReport();
+
+ //! Import report into document
+ void onImportReport();
+
+ //! Unite alerts in view model
+ //void onUniteAlerts();
+
+ //! Sets report reversed
+ void onSetReversedAlerts();
+
+ //! Reads if possible report of a selected item and updates this report in tree view
+ void onReloadReport();
+
+ //! Sets report state to write it by each message alert
+ void onAutoExportActivate();
+
+ //! Sets report writer state to write only trace information of alerts
+ void onExportTraceOnly();
+
+ //! Iterates by children items of selected items and display its presentations if found
+ void onPreviewChildren();
+
+ //! Switch active state in report for clicked type of metric
+ void OnActivateMetric();
+
+ //! Deactivate all types of metrics for the current report
+ void OnDeactivateAllMetrics();
+
+protected:
+ //! Appends items to activate report metrics
+ void addActivateMetricActions (QMenu* theMenu);
+
+ //! Returns displayer where the presentations/preview should be shown/erased
+ //! If default view is created, it returns displayer of this view
+ Standard_EXPORT View_Displayer* displayer();
+
+ //! Updates property panel content by item selected in tree view.
+ void updatePropertyPanelBySelection();
+
+ //!< Updates presentation of preview for parameter shapes. Creates a compound of the shapes
+ void updatePreviewPresentation();
+
+ //!< Sets reports metric columns visible if used
+ void updateVisibleColumns();
+
+private:
+ QMainWindow* myMainWindow; //!< main control, parent for all MessageView controls
+ QDockWidget* myViewDockWidget; //!< view dock widget to hide/show
+
+ QDockWidget* myPropertyPanelWidget; //!< property pane dockable widget
+ ViewControl_PropertyView* myPropertyView; //!< property control to display model item values if exist
+
+ View_Window* myViewWindow; //!< OCC 3d view to visualize presentations
+ QTreeView* myTreeView; //!< tree view visualized shapes
+ MessageModel_Actions* myTreeViewActions; //!< processing history view actions
+ MessageView_ActionsTest* myTestViewActions; //!< check view actions
+
+ Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
+
+ Handle(AIS_InteractiveObject) myPreviewPresentation; //!< presentation of preview for a selected object
+};
+
+#endif
#include <inspector/ShapeView_ItemShape.hxx>
#include <inspector/ShapeView_TreeModel.hxx>
#include <inspector/ShapeView_VisibilityState.hxx>
+#include <inspector/ViewControl_PropertiesDialog.hxx>
#include <inspector/Convert_Tools.hxx>
#include <inspector/ShapeView_OpenFileDialog.hxx>
#include <inspector/ShapeView_Tools.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
+#include <IMeshTools_Parameters.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
+#include <Message_Report.hxx>
+#include <StdPrs_ShadedShape.hxx>
+#include <TopoDS.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
aVisibilityState, SLOT (OnClicked(const QModelIndex&)));
QItemSelectionModel* aSelModel = new QItemSelectionModel (myTreeView->model(), myTreeView);
+ myTreeView->setSelectionMode (QAbstractItemView::ExtendedSelection);
myTreeView->setSelectionModel (aSelModel);
connect (aSelModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
this, SLOT (onTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
- if (!anItemBase)
- return;
-
QMenu* aMenu = new QMenu(myMainWindow);
+
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot> (anItemBase);
if (aRootItem) {
aMenu->addAction (ViewControl_Tools::CreateAction ("Load BREP file", SLOT (onLoadFile()), myMainWindow, this));
aMenu->addAction (ViewControl_Tools::CreateAction ("Remove all shape items", SLOT (onClearView()), myMainWindow, this));
}
- else {
+ else if (anItemBase) { // single selection
aMenu->addAction (ViewControl_Tools::CreateAction ("Export to BREP", SLOT (onExportToBREP()), myMainWindow, this));
+
ShapeView_ItemShapePtr aShapeItem = itemDynamicCast<ShapeView_ItemShape>(anItemBase);
- const TopoDS_Shape& aShape = aShapeItem->GetItemShape();
- TopAbs_ShapeEnum anExplodeType = aShapeItem->ExplodeType();
- NCollection_List<TopAbs_ShapeEnum> anExplodeTypes;
- ShapeView_Tools::IsPossibleToExplode (aShape, anExplodeTypes);
- if (anExplodeTypes.Size() > 0)
+ if (aShapeItem)
{
- QMenu* anExplodeMenu = aMenu->addMenu ("Explode");
- for (NCollection_List<TopAbs_ShapeEnum>::Iterator anExpIterator (anExplodeTypes); anExpIterator.More();
- anExpIterator.Next())
+ const TopoDS_Shape& aShape = aShapeItem->GetItemShape();
+ TopAbs_ShapeEnum anExplodeType = aShapeItem->ExplodeType();
+ NCollection_List<TopAbs_ShapeEnum> anExplodeTypes;
+ ShapeView_Tools::IsPossibleToExplode (aShape, anExplodeTypes);
+ if (anExplodeTypes.Size() > 0)
{
- TopAbs_ShapeEnum aType = anExpIterator.Value();
- QAction* anAction = ViewControl_Tools::CreateAction (TopAbs::ShapeTypeToString (aType), SLOT (onExplode()), myMainWindow, this);
- anExplodeMenu->addAction (anAction);
- if (anExplodeType == aType)
+ QMenu* anExplodeMenu = aMenu->addMenu ("Explode");
+ for (NCollection_List<TopAbs_ShapeEnum>::Iterator anExpIterator (anExplodeTypes); anExpIterator.More();
+ anExpIterator.Next())
{
- anAction->setCheckable (true);
- anAction->setChecked (true);
+ TopAbs_ShapeEnum aType = anExpIterator.Value();
+ QAction* anAction = ViewControl_Tools::CreateAction (TopAbs::ShapeTypeToString (aType), SLOT (onExplode()), myMainWindow, this);
+ anExplodeMenu->addAction (anAction);
+ if (anExplodeType == aType)
+ {
+ anAction->setCheckable (true);
+ anAction->setChecked (true);
+ }
}
+ QAction* anAction = ViewControl_Tools::CreateAction ("NONE", SLOT (onExplode()), myMainWindow, this);
+ anExplodeMenu->addSeparator();
+ anExplodeMenu->addAction (anAction);
}
- QAction* anAction = ViewControl_Tools::CreateAction ("NONE", SLOT (onExplode()), myMainWindow, this);
- anExplodeMenu->addSeparator();
- anExplodeMenu->addAction (anAction);
}
}
+ aMenu->addAction (ViewControl_Tools::CreateAction ("Create Face", SLOT (onCreateFace()), myMainWindow, this));
+ aMenu->addAction (ViewControl_Tools::CreateAction ("Create Compound", SLOT (onCreateCompound()), myMainWindow, this));
+ aMenu->addAction (ViewControl_Tools::CreateAction ("Algo: Incremental Mesh", SLOT (onIncrementalMesh()), myMainWindow, this));
QPoint aPoint = myTreeView->mapToGlobal (thePosition);
aMenu->exec (aPoint);
anItem->SetFileName (aFileNameIndiced.ToCString());
aFileName = aFileNameIndiced.ToCString();
}
+
+// =======================================================================
+// function : onCreateFace
+// purpose :
+// =======================================================================
+void ShapeView_Window::onCreateFace()
+{
+ /*QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+ QList<TreeModel_ItemBasePtr> anItems = TreeModel_ModelBase::SelectedItems (aModel->selectedIndexes());
+
+ QList<size_t> aSelectedIds; // Remember of selected address in order to avoid duplicates
+ NCollection_List<Handle(Standard_Transient)> anItemPresentations;
+
+ BRepBuilderAPI_MakeWire aWireBuilder;
+ for (QList<TreeModel_ItemBasePtr>::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); ++anItemIt)
+ {
+ ShapeView_ItemShapePtr anItem = itemDynamicCast<ShapeView_ItemShape>(*anItemIt);
+ if (!anItem)
+ continue;
+
+ const TopoDS_Shape& aShape = anItem->GetItemShape();
+ if (aShape.ShapeType() != TopAbs_EDGE)
+ continue;
+
+ const TopoDS_Edge& aSourceEdge = TopoDS::Edge (aShape);
+ const TopoDS_Edge& anEdgeCopied = TopoDS::Edge (aSourceEdge.EmptyCopied());
+
+ aWireBuilder.Add (anEdgeCopied);//aSourceEdge);
+ }
+ if (!aWireBuilder.IsDone())
+ return;
+
+ BRepBuilderAPI_MakeFace aFaceBuilder;
+
+ const TopoDS_Wire& aWire = aWireBuilder.Wire();
+ const TopoDS_Wire& aWireCopied = TopoDS::Wire (aWire.EmptyCopied());
+
+ aFaceBuilder.Add (aWireCopied);
+
+ addShape (aFaceBuilder.Face());
+ */
+}
+
+// =======================================================================
+// function : onCreateCompound
+// purpose :
+// =======================================================================
+void ShapeView_Window::onCreateCompound()
+{
+ QItemSelectionModel* aModel = myTreeView->selectionModel();
+ if (!aModel)
+ return;
+ QList<TreeModel_ItemBasePtr> anItems = TreeModel_ModelBase::SelectedItems (aModel->selectedIndexes());
+
+ QList<size_t> aSelectedIds; // Remember of selected address in order to avoid duplicates
+ NCollection_List<Handle(Standard_Transient)> anItemPresentations;
+
+ BRep_Builder aBB;
+ TopoDS_Compound aC;
+ aBB.MakeCompound(aC);
+
+ for (QList<TreeModel_ItemBasePtr>::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); ++anItemIt)
+ {
+ ShapeView_ItemShapePtr anItem = itemDynamicCast<ShapeView_ItemShape>(*anItemIt);
+ if (!anItem)
+ return;
+
+ aBB.Add(aC, anItem->GetItemShape());
+ }
+ addShape (aC);
+}
+
+// =======================================================================
+// function : onIncrementalMesh
+// purpose :
+// =======================================================================
+void ShapeView_Window::onIncrementalMesh()
+{
+}
//! Views BREP files of selected items if exist
void onExportToBREP();
+ //! Create a wire of selected edges
+ void onCreateFace();
+
+ //! Create a compound of selected shapes
+ void onCreateCompound();
+
+ //! Perform BRepMesh_IncrementalMesh on the selected shape
+ void onIncrementalMesh();
+
//! Convers file name to Ascii String and perform opeging file
//! \param theFileName a file name to be opened
void onOpenFile(const QString& theFileName) { OpenFile (TCollection_AsciiString (theFileName.toUtf8().data())); }
#include <inspector/TInspector_Communicator.hxx>
+#include <Message.hxx>
+#include <Message_Report.hxx>
#include <OSD_Environment.hxx>
#include <Standard_WarningsDisable.hxx>
if (!strcmp (argv[anArgId], "vinspector"))
aPlugins.insert ("TKVInspector");
+
+ if (!strcmp (argv[anArgId], "messageview"))
+ aPlugins.insert ("TKMessageView");
}
NCollection_List<Handle(Standard_Transient)> aParameters;
aPlugins.insert("TKShapeView");
aPlugins.insert("TKVInspector");
- anActivatedPluginName = "TKDFBrowser";
+ Handle(Message_Report) aReport = Message::DefaultReport (Standard_True);
+ aReport->SetLimit (100);//30);
+ aPlugins.insert("TKMessageView");
+
+ //anActivatedPluginName = "TKVInspector";
+ //anActivatedPluginName = "TKMessageView";
+ //anActivatedPluginName = "TKDFBrowser";
+ anActivatedPluginName = "TKShapeView";
}
else
anActivatedPluginName = *aPlugins.rbegin();
--- /dev/null
+project(TKMessageModel)
+
+OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool)
+OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)
+OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool)
--- /dev/null
+TKMath
+TKBin
+TKBRep
+TKGeomBase
+TKG3d
+TKTInspectorAPI
+TKService
+TKTopAlgo
+TKTreeModel
+CSF_QT
--- /dev/null
+EXTERNLIB
+PACKAGES
--- /dev/null
+MessageModel
--- /dev/null
+project(TKMessageView)
+
+OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool)
+OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)
+OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool)
--- /dev/null
+TKTInspectorAPI
+TKMath
+TKMessageModel
+TKBin
+TKBRep
+TKGeomBase
+TKG3d
+TKService
+TKTopAlgo
+TKTreeModel
+TKView
+TKXml
+CSF_QT
--- /dev/null
+EXTERNLIB
+PACKAGES
--- /dev/null
+MessageView
if (anArgument == "dfbrowser") { thePluginName = "TKDFBrowser"; return Standard_True; }
else if (anArgument == "shapeview") { thePluginName = "TKShapeView"; return Standard_True; }
else if (anArgument == "vinspector") { thePluginName = "TKVInspector"; return Standard_True; }
+ else if (anArgument == "messageview") { thePluginName = "TKMessageView"; return Standard_True; }
return Standard_False;
}
aPlugins.Append ("TKDFBrowser");
aPlugins.Append ("TKShapeView");
aPlugins.Append ("TKVInspector");
+ aPlugins.Append ("TKMessageView");
}
aPluginNameToActivate = !aPluginNameToActivate.IsEmpty() ? aPluginNameToActivate : aPlugins.First();
}
"\n\t\t: Starts tool of inspection."
"\n\t\t: Options:"
"\n\t\t: -plugins enters plugins that should be added in the inspector."
- "\n\t\t: Available names are: dfbrowser, vinspector and shapeview."
+ "\n\t\t: Available names are: dfbrowser, vinspector, shapeview and messageview."
"\n\t\t: Plugins order will be the same as defined in arguments."
"\n\t\t: 'all' adds all available plugins in the order:"
- "\n\t\t: DFBrowser, VInspector and ShapeView."
+ "\n\t\t: DFBrowser, VInspector, ShapeView and MessageView."
"\n\t\t: If at the first call this option is not used, 'all' option is applied;"
"\n\t\t: -activate activates the plugin in the tool view."
"\n\t\t: If at the first call this option is not used, the first plugin is activated;"
enum TreeModel_ColumnType
{
TreeModel_ColumnType_Name = 0, //! name column
- TreeModel_ColumnType_Visibility //! visibility state column
+ TreeModel_ColumnType_Visibility, //! visibility state column
+ TreeModel_ColumnType_Row //! row of the item column
};
#endif
#include <Standard_Handle.hxx>
#include <Standard_OStream.hxx>
#include <Standard_SStream.hxx>
+#include <NCollection_List.hxx>
#include <inspector/TreeModel_ItemRole.hxx>
//! Returns the item properties
const Handle(TreeModel_ItemProperties)& Properties() const { return myProperties; }
+ //! Returns presentation of the attribute to be visualized in the view
+ //! \thePresentations [out] container of presentation handles to be visualized
Standard_EXPORT virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations);
+
protected:
//! \param theParent the parent item
const Standard_SStream& aStream = Item()->Stream();
+ InitByStream (aStream);
+}
+
+// =======================================================================
+// function : InitByStream
+// purpose :
+// =======================================================================
+void TreeModel_ItemProperties::InitByStream (const Standard_SStream& aStream)
+{
NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue> aValues;
TCollection_AsciiString aStreamText = Standard_Dump::Text (aStream);
Standard_Dump::SplitJson (aStreamText, aValues);
Standard_DumpValue aKeyValue;
if (!aStreamParent)
{
- const Handle(Standard_Transient)& anItemObject = Item()->Object();
- aKey = anItemObject.IsNull() ? "Dump" : anItemObject->DynamicType()->Name();
+ if (!Item() || Item()->Object().IsNull())
+ {
+ aKey = "Dump";
+ }
+ else
+ {
+ const Handle(Standard_Transient)& anItemObject = Item()->Object();
+ aKey = anItemObject.IsNull() ? "Dump" : anItemObject->DynamicType()->Name();
+ }
aKeyValue = Standard_DumpValue (aStreamText, 1);
myKey = aKey;
(int)(aGreen * aDelta), (int)(aBlue * aDelta)));
}
}
+ // in case if the stream alert has empty key avalue, use as the key the first row value
+ if ((myKey.IsEmpty() || myKey.IsEqual ("Dump")) && myRowValues.Size() > 0)
+ {
+ myKey = myRowValues.FindFromIndex (1).Value.toString().toStdString().c_str();
+ }
}
// =======================================================================
// function : SetData
// purpose :
// =======================================================================
-bool TreeModel_ItemProperties::SetData (const int /*theRow*/, const int theColumn, const QVariant& /*theValue*/, int)
+bool TreeModel_ItemProperties::SetData (const int theRow, const int theColumn, const QVariant& theValue, int theRole)
{
if (theColumn == 0)
return false;
+
+ if (theRole == Qt::DisplayRole || theRole == Qt::EditRole)
+ {
+ myRowValues.ChangeFromIndex (theRow + 1).Value = theValue;
+ }
+
return false;
}
// =======================================================================
void TreeModel_ItemProperties::Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations)
{
+ if (!Item())
+ return;
const Standard_SStream& aStream = Item()->Stream();
Convert_Tools::ConvertStreamToPresentations (aStream, 1, -1, thePresentations);
}
//! Sets the current item
void SetItem (const TreeModel_ItemBasePtr& theItem) { myItem = theItem; }
+ //! Fills properties with the stream value
+ Standard_EXPORT void InitByStream (const Standard_SStream& theStream);
+
//! Returns the current item
TreeModel_ItemBasePtr Item() const { return myItem; }
Standard_EXPORT void Init();
//! If the item has internal values, there should be reseted here.
- Standard_EXPORT virtual void Reset();
+ Standard_EXPORT void Reset();
//! Returns number of table rows
//! \return an integer value
//! \param theColumn a model index column
//! \param theRole a view role
//! \return true if the value is changed
- Standard_EXPORT virtual bool SetData (const int theRow, const int theColumn, const QVariant& theValue,
- int theRole = Qt::DisplayRole);
+ Standard_EXPORT bool SetData (const int theRow, const int theColumn, const QVariant& theValue,
+ int theRole = Qt::DisplayRole);
//! Returns presentation of the attribute to be visualized in the view
//! \thePresentations [out] container of presentation handles to be visualized
- Standard_EXPORT virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations);
+ Standard_EXPORT void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations);
//! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable.
//! Additional flag for the column 1 is Qt::ItemIsEditable.
//! \param theIndex a model index
//! \return flags
- Standard_EXPORT virtual Qt::ItemFlags TableFlags (const int theRow, const int theColumn) const;
+ Standard_EXPORT Qt::ItemFlags TableFlags (const int theRow, const int theColumn) const;
//! Returns stream value of the item to fulfill property panel.
//! \return stream value or dummy
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_ItemBase.hxx>
+#include <inspector/TreeModel_ItemProperties.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/TreeModel_VisibilityState.hxx>
// =======================================================================
void TreeModel_ModelBase::InitColumns()
{
- SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
- SetHeaderItem (1, TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
- SetHeaderItem (2, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH));
+ SetHeaderItem (TreeModel_ColumnType_Name, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
+ SetHeaderItem (TreeModel_ColumnType_Visibility, TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
+ SetHeaderItem (TreeModel_ColumnType_Row, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH));
}
// =======================================================================
return anItems;
}
+// =======================================================================
+// function : SubItemsPresentations
+// purpose :
+// =======================================================================
+void TreeModel_ModelBase::SubItemsPresentations (const QModelIndexList& theIndices,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations)
+{
+ QList<TreeModel_ItemBasePtr> anItems;
+
+ for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++)
+ {
+ TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex (*anIndicesIt);
+ if (!anItem || anItems.contains (anItem))
+ continue;
+ subItemsPresentations (anItem, thePresentations);
+ }
+}
+
+// =======================================================================
+// function : subItemPresentations
+// purpose :
+// =======================================================================
+void TreeModel_ModelBase::subItemsPresentations (const TreeModel_ItemBasePtr& theItem,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations)
+{
+ theItem->Presentations (thePresentations);
+
+ QList<TreeModel_ItemBasePtr> anItems;
+ for (int aRowId = 0; aRowId < theItem->rowCount(); aRowId++)
+ {
+ subItemsPresentations (theItem->Child (aRowId, theItem->Column()), thePresentations);
+ }
+}
+
// =======================================================================
// function : createRoot
// purpose :
//! \return model items from the list
Standard_EXPORT static QList<TreeModel_ItemBasePtr> SelectedItems (const QModelIndexList& theIndices);
+ //! Returns presentations of sub items
+ //! \param theIndices a container of selected indices
+ //! \thePresentations [out] container of presentation handles to be visualized
+ Standard_EXPORT static void SubItemsPresentations (const QModelIndexList& theIndices,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations);
+
protected:
//! Creates root item
//! \param theColumnId index of a column
//! \return an item pointer
Standard_EXPORT static void* getIndexValue (const TreeModel_ItemBasePtr& theItem);
+ //! Returns presentations of sub items
+ //! \param theIndices a container of selected indices
+ //! \thePresentations [out] container of presentation handles to be visualized
+ static void subItemsPresentations (const TreeModel_ItemBasePtr& theItem,
+ NCollection_List<Handle(Standard_Transient)>& thePresentations);
+
private:
//! Creates root item
//! \param theColumnId index of a column
//! \return the value
Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE;
- //! Returns presentation of the attribute to be visualized in the view
- //! \thePresentations [out] container of presentation handles to be visualized
- virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations)
- { (void)thePresentations; }
-
//! Returns transform persistent of the item or NULL
Handle(Graphic3d_TransformPers) TransformPersistence() const { return myTransformPersistence; }
//! Returns presentation of the attribute to be visualized in the view
//! \thePresentations [out] container of presentation handles to be visualized
- Standard_EXPORT virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations);
+ Standard_EXPORT virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations) Standard_OVERRIDE;
protected:
TCollection_AsciiString aPluginName ("TKShapeView");
NCollection_List<Handle(Standard_Transient)> aParameters;
- if (myParameters->FindParameters (aPluginName))
- aParameters = myParameters->Parameters (aPluginName);
+ //if (myParameters->FindParameters (aPluginName))
+ // aParameters = myParameters->Parameters (aPluginName);
NCollection_List<TCollection_AsciiString> anItemNames;
- if (myParameters->FindSelectedNames (aPluginName))
- anItemNames = myParameters->GetSelectedNames (aPluginName);
+ //if (myParameters->FindSelectedNames (aPluginName))
+ // anItemNames = myParameters->GetSelectedNames (aPluginName);
QStringList anExportedPointers;
if (aSelectedShapes.Extent() > 0)
}
}
- // search for objects to be exported
- QList<TreeModel_ItemBasePtr> anItems = TreeModel_ModelBase::SelectedItems (myTreeView->selectionModel()->selectedIndexes());
- for (QList<TreeModel_ItemBasePtr>::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); ++anItemIt)
- {
- TreeModel_ItemBasePtr anItem = *anItemIt;
- VInspector_ItemBasePtr aVItem = itemDynamicCast<VInspector_ItemBase>(anItem);
- if (!aVItem)
- continue;
-
- const Handle(Standard_Transient)& anObject = aVItem->Object();
- if (anObject.IsNull())
- continue;
-
- aParameters.Append (anObject);
- anItemNames.Append (anObject->DynamicType()->Name());
- anExportedPointers.append (Standard_Dump::GetPointerInfo (anObject, true).ToCString());
- }
+ //// search for objects to be exported
+ //QList<TreeModel_ItemBasePtr> anItems = TreeModel_ModelBase::SelectedItems (myTreeView->selectionModel()->selectedIndexes());
+ //for (QList<TreeModel_ItemBasePtr>::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); ++anItemIt)
+ //{
+ // TreeModel_ItemBasePtr anItem = *anItemIt;
+ // VInspector_ItemBasePtr aVItem = itemDynamicCast<VInspector_ItemBase>(anItem);
+ // if (!aVItem)
+ // continue;
+
+ // const Handle(Standard_Transient)& anObject = aVItem->Object();
+ // if (anObject.IsNull())
+ // continue;
+
+ // aParameters.Append (anObject);
+ // anItemNames.Append (anObject->DynamicType()->Name());
+ // anExportedPointers.append (Standard_Dump::GetPointerInfo (anObject, true).ToCString());
+ //}
if (anExportedPointers.isEmpty())
return;
ViewControl_MessageDialog.hxx
ViewControl_PropertyView.cxx
ViewControl_PropertyView.hxx
+ViewControl_PropertiesDialog.cxx
+ViewControl_PropertiesDialog.hxx
ViewControl_Table.cxx
ViewControl_Table.hxx
ViewControl_TableModel.cxx
--- /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 <inspector/ViewControl_PropertiesDialog.hxx>
+
+#include <inspector/ViewControl_TableModel.hxx>
+#include <inspector/TreeModel_ItemProperties.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QGridLayout>
+#include <QPushButton>
+#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
+
+// =======================================================================
+// function : Constructor
+// purpose :
+// =======================================================================
+ViewControl_PropertiesDialog::ViewControl_PropertiesDialog (QWidget* theParent)
+: QDialog (theParent)
+{
+ setWindowTitle ("Properties");
+
+ QGridLayout* aLayout = new QGridLayout (this);
+ myTable = new ViewControl_Table (this);
+ ViewControl_TableModel* aModel = new ViewControl_TableModel (myTable->TableView());
+ myTable->SetModel (aModel);
+
+ aLayout->addWidget(myTable->TableView(), 0, 0, 1, 3);
+
+ myOkButton = new QPushButton ("Ok", this);
+ myCancelButton = new QPushButton ("Cancel", this);
+ connect (myOkButton, SIGNAL (clicked()), this, SLOT (accept()));
+ connect (myCancelButton, SIGNAL (clicked()), this, SLOT (reject()));
+ aLayout->addWidget (myOkButton, 1, 1);
+ aLayout->addWidget (myCancelButton, 1, 2);
+
+ aLayout->setColumnStretch (0, 1);
+
+ myCancelButton->setDefault (true);
+
+ setMinimumSize (200, 600);
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+void ViewControl_PropertiesDialog::Init (const Handle(TreeModel_ItemProperties)& theProperties)
+{
+ ViewControl_TableModelValues* aTableValues = new ViewControl_TableModelValues();
+ aTableValues->SetProperties (theProperties);
+
+ myTable->Init (aTableValues);
+}
--- /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.
+
+#ifndef ViewControl_PropertiesDialog_H
+#define ViewControl_PropertiesDialog_H
+
+#include <Standard.hxx>
+#include <Standard_Macro.hxx>
+
+#include <inspector/ViewControl_Table.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QDialog>
+#include <Standard_WarningsRestore.hxx>
+
+class TreeModel_ItemProperties;
+
+class QWidget;
+class QPushButton;
+
+//! \class ViewControl_PropertiesDialog
+//! Dialog providing table of stream values
+class ViewControl_PropertiesDialog : public QDialog
+{
+ Q_OBJECT
+public:
+
+ //! Constructor
+ Standard_EXPORT ViewControl_PropertiesDialog (QWidget* theParent);
+
+ //! Destructor
+ virtual ~ViewControl_PropertiesDialog() {}
+
+ Standard_EXPORT void Init (const Handle(TreeModel_ItemProperties)& theProperties);
+
+private:
+ ViewControl_Table* myTable; //!< table view
+
+ QPushButton* myOkButton; //!< accept button
+ QPushButton* myCancelButton; //!< reject button
+};
+
+
+#endif