From: nds Date: Wed, 22 Jan 2020 17:15:04 +0000 (+0300) Subject: 0030268: Inspectors - improvements in VInspector plugin X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=98f8ae5f24dc5ab32bc2603a237e396a44b29387;p=occt-copy.git 0030268: Inspectors - improvements in VInspector plugin # Messages are simplified, redirecting Message_Messenger into Message_Report # STEP reading trace level setting to get Message_Report # tools: TreeModel: moving container of parents on the base levelAlert # tools: MessageView is extended to select list of report metrics to collect --- diff --git a/src/DDocStd/DDocStd_ToolsCommands.cxx b/src/DDocStd/DDocStd_ToolsCommands.cxx index 9d925859c9..9507d731e8 100644 --- a/src/DDocStd/DDocStd_ToolsCommands.cxx +++ b/src/DDocStd/DDocStd_ToolsCommands.cxx @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include +#include //======================================================================= @@ -151,7 +153,23 @@ static Standard_Integer DDocStd_DumpCommand (Draw_Interpretor& di, return 1; } +//======================================================================= +//function : DDocStd_WriteReport +//======================================================================= + +static Standard_Integer DDocStd_WriteReport(Draw_Interpretor& di,Standard_Integer n, const char** a) +{ + if (n < 2) + { + di << "DDocStd_WriteReport : Error not enough argument\n"; + return 1; + } + TCollection_ExtendedString path (a[1]); + MESSAGE_STORE_XML_REPORT (path); + + return 0; +} //======================================================================= //function : ModificationCommands @@ -174,5 +192,9 @@ void DDocStd::ToolsCommands(Draw_Interpretor& theCommands) "DumpCommand (DOC)", __FILE__, DDocStd_DumpCommand, g); + theCommands.Add ("WriteReport", + "WriteReport path", + __FILE__, DDocStd_WriteReport, g); + } diff --git a/src/Draw/Draw_BasicCommands.cxx b/src/Draw/Draw_BasicCommands.cxx index 8c57448a03..5fa9608390 100644 --- a/src/Draw/Draw_BasicCommands.cxx +++ b/src/Draw/Draw_BasicCommands.cxx @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -931,6 +933,91 @@ static int dsetsignal (Draw_Interpretor& theDI, Standard_Integer theArgNb, const return 0; } +//============================================================================== +//function : dsetreportprinter +//purpose : +//============================================================================== +static Handle(Message_PrinterToReport) MyPrinterToReport; +static Message_SequenceOfPrinters MyDeactivatedPrinters; + +static Standard_Integer dsetreportprinter(Draw_Interpretor&, Standard_Integer n, const char** a) +{ + if (n != 2) + { + std::cout << "Enable or disable report printer: " << a[0] << " {on|off}" << std::endl; + return 1; + } + + const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger(); + if (aMsgMgr.IsNull()) + return 1; + + if (! strcmp (a[1], "on") && n == 2) + { + if (MyPrinterToReport.IsNull()) + MyPrinterToReport = new Message_PrinterToReport; + + if (MyPrinterToReport->Report()->IsActiveInMessenger()) + { + std::cout << "Report printer has been already activated." << std::endl; + return 1; + } + + MyDeactivatedPrinters = Message::DefaultMessenger()->Printers(); + Message::DefaultMessenger()->ChangePrinters().Clear(); + aMsgMgr->AddPrinter (MyPrinterToReport); + + } + else if (! strcmp (a[1], "off") && n == 2) + { + if (MyPrinterToReport.IsNull() || !MyPrinterToReport->Report()->IsActiveInMessenger()) + { + std::cout << "Report printer was not activated." << std::endl; + return 1; + } + + Message::DefaultMessenger()->ChangePrinters().Assign (MyDeactivatedPrinters); + } + else { + std::cout << "Unrecognized option(s): " << a[1] << std::endl; + return 1; + } + return 0; +} + +//============================================================================== +//function : dsetreportmetric +//purpose : +//============================================================================== +static Standard_Integer dsetreportmetric(Draw_Interpretor&, Standard_Integer n, const char** a) +{ + if (n < 1) + { + std::cout << "Report metric activation: " << a[0] << " [metric_1 metric_2 ...]" << std::endl; + return 1; + } + + const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger(); + const Handle(Message_Report)& aDefReport = Message::DefaultReport(); + + if (aMsgMgr.IsNull() || aDefReport.IsNull()) + return 1; + + aDefReport->ClearMetrics(); + for (int i = 1; i < n; i++) + { + Standard_Integer aMetricId = atoi (a [i]); + if (aMetricId < Message_MetricType_UserTimeCPU || aMetricId > Message_MetricType_MemHeapUsage) + { + std::cout << "Unrecognized message metric: " << aMetricId << std::endl; + return 1; + } + aDefReport->SetActiveMetric ((Message_MetricType)aMetricId, Standard_True); + } + + return 0; +} + //============================================================================== //function : dtracelevel //purpose : @@ -1059,6 +1146,10 @@ void Draw::BasicCommands(Draw_Interpretor& theCommands) __FILE__,dperf,g); theCommands.Add("dsetsignal","dsetsignal [fpe=0] -- set OSD signal handler, with FPE option if argument is given", __FILE__,dsetsignal,g); + theCommands.Add("dsetreportprinter", "manage logging of messenger into current report", + __FILE__,dsetreportprinter,g); + theCommands.Add("dsetreportmetric", "manage logging of messenger into current report", + __FILE__,dsetreportmetric,g); theCommands.Add("dparallel", "dparallel [-occt {0|1}] [-nbThreads Count] [-nbDefThreads Count]" diff --git a/src/Message/FILES b/src/Message/FILES index 9a4bf4a982..e332c94b46 100755 --- a/src/Message/FILES +++ b/src/Message/FILES @@ -10,6 +10,8 @@ Message_Algorithm.hxx Message_Algorithm.lxx Message_Attribute.cxx Message_Attribute.hxx +Message_AttributeMeter.cxx +Message_AttributeMeter.hxx Message_AttributeObject.cxx Message_AttributeObject.hxx Message_AttributeStream.cxx @@ -19,22 +21,24 @@ 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_MsgFile.cxx Message_MsgFile.hxx -Message_PerfMeter.cxx -Message_PerfMeter.hxx -Message_PerfMeterMode.hxx Message_Printer.cxx Message_Printer.hxx Message_PrinterOStream.cxx Message_PrinterOStream.hxx +Message_PrinterToReport.cxx +Message_PrinterToReport.hxx Message_ProgressIndicator.cxx Message_ProgressIndicator.hxx Message_ProgressIndicator.lxx @@ -51,5 +55,3 @@ Message_StatusType.hxx Message_ListOfAlert.hxx Message_Report.cxx Message_Report.hxx -Message_ReportCallBack.cxx -Message_ReportCallBack.hxx diff --git a/src/Message/Message.cxx b/src/Message/Message.cxx index 3aea6317a4..4c412893cf 100644 --- a/src/Message/Message.cxx +++ b/src/Message/Message.cxx @@ -17,10 +17,12 @@ #include #include +#include #include #include #include + //======================================================================= //function : DefaultMessenger //purpose : @@ -31,6 +33,21 @@ const Handle(Message_Messenger)& Message::DefaultMessenger () return aMessenger; } +//======================================================================= +//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 : FillTime //purpose : @@ -52,76 +69,38 @@ TCollection_AsciiString Message::FillTime (const Standard_Integer hour, namespace { - static Standard_CString Message_Table_PrintGravityEnum[5] = + static Standard_CString Message_Table_PrintMetricTypeEnum[10] = { - "TRACE", "INFO", "WARNING", "ALARM", "FAIL" + "NONE", "UserTimeCPU", "SystemTimeInfo", "MemPrivate", "MemVirtual", + "MemWorkingSet", "MemWorkingSetPeak", "MemSwapUsage", "MemSwapUsagePeak", "MemHeapUsage" }; - - static Standard_CString Message_Table_PrintPerfMeterModeEnum[10] = - { - "NONE", "USER_TIME_CPU", "SYSTEM_TIME_CPU", "MEM_PRIVATE", "MEM_VIRTUAL", - "MEM_WORKING_SET", "MEM_WORKING_SET_PEAK", "MEM_SWAP_USAGE", "MEM_SWAP_USAGE_PEAK", "MEM_HEAP_USAGE" - }; -} - -//======================================================================= -//function : GravityToString -//purpose : -//======================================================================= - -Standard_CString Message::GravityToString (const Message_Gravity theGravity) -{ - return Message_Table_PrintGravityEnum[theGravity]; -} - -//======================================================================= -//function : GravityFromString -//purpose : -//======================================================================= - -Standard_Boolean Message::GravityFromString (const Standard_CString theGravityString, - Message_Gravity& theGravity) -{ - TCollection_AsciiString aName (theGravityString); - aName.UpperCase(); - for (Standard_Integer aGravityIter = 0; aGravityIter <= Message_Fail; ++aGravityIter) - { - Standard_CString aGravityName = Message_Table_PrintGravityEnum[aGravityIter]; - if (aName == aGravityName) - { - theGravity = Message_Gravity (aGravityIter); - return Standard_True; - } - } - return Standard_False; } //======================================================================= -//function : PerfMeterModeToString +//function : MetricToString //purpose : //======================================================================= -Standard_CString Message::PerfMeterModeToString (const Message_PerfMeterMode theValue) +Standard_CString Message::MetricToString (const Message_MetricType theType) { - return Message_Table_PrintPerfMeterModeEnum[theValue]; + return Message_Table_PrintMetricTypeEnum[theType]; } //======================================================================= -//function : PerfMeterModeFromString +//function : MetricFromString //purpose : //======================================================================= -Standard_Boolean Message::PerfMeterModeFromString (const Standard_CString theString, - Message_PerfMeterMode& theValue) +Standard_Boolean Message::MetricFromString (const Standard_CString theString, + Message_MetricType& theGravity) { TCollection_AsciiString aName (theString); - aName.UpperCase(); - for (Standard_Integer aModeIter = 0; aModeIter <= Message_PerfMeterMode_MemHeapUsage; ++aModeIter) + for (Standard_Integer aMetricIter = 0; aMetricIter <= Message_MetricType_MemHeapUsage; ++aMetricIter) { - Standard_CString aModeName = Message_Table_PrintPerfMeterModeEnum[aModeIter]; - if (aName == aModeName) + Standard_CString aMetricName = Message_Table_PrintMetricTypeEnum[aMetricIter]; + if (aName == aMetricName) { - theValue = Message_PerfMeterMode (aModeIter); + theGravity = Message_MetricType (aMetricIter); return Standard_True; } } @@ -129,262 +108,41 @@ Standard_Boolean Message::PerfMeterModeFromString (const Standard_CString theStr } // ======================================================================= -// function : GetPointerInfo -// purpose : -// ======================================================================= -TCollection_AsciiString Message::TransientToString (const Handle(Standard_Transient)& thePointer, const bool isShortInfo) -{ - if (thePointer.IsNull()) - return TCollection_AsciiString(); - - return PointerToString(thePointer.operator->(), isShortInfo); -} - -// ======================================================================= -// function : GetPointerInfo -// purpose : -// ======================================================================= -TCollection_AsciiString Message::PointerToString (const void* thePointer, const bool isShortInfo) -{ - std::ostringstream aPtrStr; - aPtrStr << thePointer; - 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(); -} - -// ======================================================================= -// function : StrVectorToString +// function : ToOSDMetric // purpose : // ======================================================================= -TCollection_AsciiString Message::StrVectorToString - (const NCollection_Vector& theValues) +Standard_Boolean Message::ToOSDMetric (const Message_MetricType theMetric, OSD_MemInfo::Counter& theMemInfo) { - TCollection_AsciiString aValue; - for (NCollection_Vector::Iterator aValuesIt (theValues); aValuesIt.More(); aValuesIt.Next()) - { - aValue += aValuesIt.Value(); - if (aValuesIt.More()) - aValue += VectorSeparator(); - } - return aValue; -} - -// ======================================================================= -// function : StrVectorFromString -// purpose : -// ======================================================================= -Standard_Boolean Message::StrVectorFromString - (const TCollection_AsciiString& theValue, - NCollection_Vector& theValues) -{ - TCollection_AsciiString aCurrentString = theValue, aValueString; - - while (!aCurrentString.IsEmpty()) + switch (theMetric) { - Standard_Integer aPosition = aCurrentString.Search (", "); - aValueString = aCurrentString; - if (aPosition > 0) - aCurrentString = aValueString.Split (aPosition - 1); - theValues.Append (aValueString.RealValue()); - if (aPosition > 0) - aCurrentString = aCurrentString.Split (2); + case Message_MetricType_MemPrivate: theMemInfo = OSD_MemInfo::MemPrivate; break; + case Message_MetricType_MemVirtual: theMemInfo = OSD_MemInfo::MemVirtual; break; + case Message_MetricType_MemWorkingSet: theMemInfo = OSD_MemInfo::MemWorkingSet; break; + case Message_MetricType_MemWorkingSetPeak: theMemInfo = OSD_MemInfo::MemWorkingSetPeak; break; + case Message_MetricType_MemSwapUsage: theMemInfo = OSD_MemInfo::MemSwapUsage; break; + case Message_MetricType_MemSwapUsagePeak: theMemInfo = OSD_MemInfo::MemSwapUsagePeak; break; + case Message_MetricType_MemHeapUsage: theMemInfo = OSD_MemInfo::MemHeapUsage; break; + default: return Standard_False; } return Standard_True; } // ======================================================================= -// function : RealVectorToString +// function : ToMessageMetric // purpose : // ======================================================================= -TCollection_AsciiString Message::RealVectorToString - (const NCollection_Vector& theValues) +Standard_Boolean Message::ToMessageMetric (const OSD_MemInfo::Counter theMemInfo, Message_MetricType& theMetric) { - TCollection_AsciiString aValue = ("("); - - for (NCollection_Vector::Iterator aValuesIt (theValues); aValuesIt.More(); aValuesIt.Next()) + switch (theMemInfo) { - aValue += aValuesIt.Value(); - if (aValuesIt.More()) - aValue += VectorSeparator(); - } - aValue += ")"; - - return aValue; -} - -// ======================================================================= -// function : RealVectorFromString -// purpose : -// ======================================================================= -Standard_Boolean Message::RealVectorFromString - (const TCollection_AsciiString& theValue, - NCollection_Vector& theValues) -{ - TCollection_AsciiString aCurrentString = theValue, aValueString; - - Standard_Integer aPosition = aCurrentString.Search ("("); - if (aPosition != 1) - return Standard_False; - aCurrentString = aCurrentString.Split (aPosition); - - aPosition = aCurrentString.Search (")"); - if (aPosition != 1) - return Standard_False; - aValueString = aCurrentString.Split (aPosition); - - - while (!aCurrentString.IsEmpty()) - { - // x value - aPosition = aCurrentString.Search (", "); - aValueString = aCurrentString; - if (aPosition > 0) - aCurrentString = aValueString.Split (aPosition - 1); - theValues.Append (aValueString.RealValue()); - if (aPosition > 0) - aCurrentString = aCurrentString.Split (2); + 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; } - -// ======================================================================= -// function : CoordVectorToString -// purpose : -// ======================================================================= -TCollection_AsciiString Message::CoordVectorToString - (const NCollection_Vector& theValues) -{ - TCollection_AsciiString aValue = ("("); - aValue += RealVectorToString (theValues); - aValue += ")"; - - return aValue; -} - -// ======================================================================= -// function : CoordVectorFromString -// purpose : -// ======================================================================= -Standard_Boolean Message::CoordVectorFromString - (const TCollection_AsciiString& theValue, - NCollection_Vector& theValues) -{ - TCollection_AsciiString aCurrentString = theValue, aValueString; - - Standard_Integer aPosition = aCurrentString.Search ("("); - if (aPosition != 1) - return Standard_False; - aCurrentString = aCurrentString.Split (aPosition); - - aPosition = aCurrentString.Search (")"); - if (aPosition != 1) - return Standard_False; - aValueString = aCurrentString.Split (aPosition); - - return RealVectorFromString (aCurrentString, theValues); -} - -// ======================================================================= -// function : ColorVectorToString -// purpose : -// ======================================================================= -TCollection_AsciiString Message::ColorVectorToString - (const NCollection_Vector& theValues) -{ - TCollection_AsciiString aValue = ("["); - aValue += RealVectorToString (theValues); - aValue += "]"; - - return aValue; -} - -// ======================================================================= -// function : ColorVectorFromString -// purpose : -// ======================================================================= -Standard_Boolean Message::ColorVectorFromString - (const TCollection_AsciiString& theValue, - NCollection_Vector& theValues) -{ - TCollection_AsciiString aCurrentString = theValue, aValueString; - - Standard_Integer aPosition = aCurrentString.Search ("["); - if (aPosition != 1) - return Standard_False; - aCurrentString = aCurrentString.Split (aPosition); - - aPosition = aCurrentString.Search ("]"); - if (aPosition != 1) - return Standard_False; - aValueString = aCurrentString.Split (aPosition); - - return RealVectorFromString (aCurrentString, theValues); -} - -// ======================================================================= -// function : ConvertStream -// purpose : -// ======================================================================= -void Message::ConvertStream (const Standard_SStream& theStream, - Standard_Integer& theColumnCount, - NCollection_Vector& theValues) -{ - TCollection_AsciiString aStream (theStream.str().c_str()); - Standard_Character aSeparator = Message::DumpSeparator(); - Standard_Integer aColumnCount = 0; - - TCollection_AsciiString aCurrentString = aStream; - Standard_Integer aPosition = aCurrentString.Search (aSeparator); - if (aPosition >= 1) - { - TCollection_AsciiString aTailString = aCurrentString.Split (aPosition); - Standard_Boolean aClassNameFound = Standard_False; - while (!aCurrentString.IsEmpty()) - { - TCollection_AsciiString aValueString = aCurrentString; - aPosition = aValueString.Search (aSeparator); - if (aPosition < 0 ) - break; - aCurrentString = aValueString.Split (aPosition - 1); - - if (!aColumnCount) - { - if (!aClassNameFound) - aClassNameFound = Standard_True; - else - { - if (!aValueString.IsIntegerValue()) - break; // not correct Dump, in correct the first value is number of property columns - aColumnCount = aValueString.IntegerValue(); - } - } - else - theValues.Append (aValueString); - - if (aTailString.IsEmpty()) - break; - aCurrentString = aTailString; - aPosition = aCurrentString.Search (aSeparator); - if (aPosition < 0 ) - { - aCurrentString = aTailString; - aTailString = TCollection_AsciiString(); - } - else - aTailString = aCurrentString.Split (aPosition); - } - } - theColumnCount = aColumnCount; -} diff --git a/src/Message/Message.hxx b/src/Message/Message.hxx index 6c440bad81..2df8154bce 100644 --- a/src/Message/Message.hxx +++ b/src/Message/Message.hxx @@ -18,8 +18,9 @@ #define _Message_HeaderFile #include -#include +#include #include +#include #include #include @@ -39,6 +40,7 @@ class Message_PrinterOStream; class Message_ProgressIndicator; class Message_ProgressScale; class Message_ProgressSentry; +class Message_Report; //! Defines @@ -56,7 +58,12 @@ public: //! By default, it contains single printer directed to std::cout. //! It can be customized according to the application needs. Standard_EXPORT static const Handle(Message_Messenger)& DefaultMessenger(); - + + //! 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); + //! Returns the string filled with values of hours, minutes and seconds. //! Example: //! 1. (5, 12, 26.3345) returns "05h:12m:26.33s", @@ -64,132 +71,41 @@ public: //! 3. (0, 0, 4.5 ) returns "4.50s" Standard_EXPORT static TCollection_AsciiString FillTime (const Standard_Integer Hour, const Standard_Integer Minute, const Standard_Real Second); - //! Returns the string name for a given gravity. - //! @param Gravity gravity type - //! @return string identifier from the list Message_Trace, Message_Info, Message_Warning, Message_Alarm and Message_Fail - Standard_EXPORT static Standard_CString GravityToString (const Message_Gravity theGravity); - - //! Returns the gravity type from the given string identifier (using case-insensitive comparison). - //! @param theGravityString string identifier - //! @return gravity or Message_Trace if string identifier is invalid - static Message_Gravity GravityFromString (const Standard_CString theGravityString) - { - Message_Gravity aGravity = Message_Trace; - GravityFromString (theGravityString, aGravity); - return aGravity; - } - - //! Determines the gravity from the given string identifier (using case-insensitive comparison). - //! @param theGravityString string identifier - //! @param theGravity detected shape type + //! 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 GravityFromString (const Standard_CString theGravityString, - Message_Gravity& theGravity); + Standard_EXPORT static Standard_Boolean MetricFromString (const Standard_CString theString, + Message_MetricType& theType); - //! Returns the string name for a perf meter mode. - //! @param theValue mode - //! @return string identifier - Standard_EXPORT static Standard_CString PerfMeterModeToString (const Message_PerfMeterMode theValue); + //! 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 enum value from the given string identifier (using case-insensitive comparison). + //! Returns the metric type from the given string identifier. //! @param theString string identifier - //! @return enum or Message_PerfMeterMode_None if string identifier is invalid - static Message_PerfMeterMode PerfMeterModeFromString (const Standard_CString theString) + //! @return metric type or Message_MetricType_None if string identifier is invalid + static Message_MetricType MetricFromString (const Standard_CString theString) { - Message_PerfMeterMode aValue = Message_PerfMeterMode_None; - PerfMeterModeFromString (theString, aValue); - return aValue; + Message_MetricType aMetric = Message_MetricType_None; + MetricFromString (theString, aMetric); + return aMetric; } - //! Returns the enum value from the given string identifier (using case-insensitive comparison). - //! @param theString string identifier - //! @return enum or Message_PerfMeterMode_None if string identifier is invalid - //! @return TRUE if string identifier is known - Standard_EXPORT static Standard_Boolean PerfMeterModeFromString (const Standard_CString theString, - Message_PerfMeterMode& theValue); - - - //! Returns separator symbol of Dump information - static Standard_Character DumpSeparator() { return '\\'; } - - //! Returns separator symbol of values vector union - static TCollection_AsciiString VectorSeparator() { return " ,"; } - - //! Convert handle 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 TransientToString (const Handle(Standard_Transient)& thePointer, - const bool isShortInfo = true); - - //! 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 PointerToString (const void* thePointer, - const bool isShortInfo = true); - //! Convert vector of real values to string, separator is vector separator - //! \param thePointer a container of real values - //! \return the string value - Standard_EXPORT static TCollection_AsciiString StrVectorToString - (const NCollection_Vector& theValues); - - //! Convert string to vector of real values, separator is vector separator - //! \param thePointer a container of real values - //! \return the string value - Standard_EXPORT static Standard_Boolean StrVectorFromString - (const TCollection_AsciiString& theValue, - NCollection_Vector& theValues); - - //! Convert vector of real values to string, separator is vector separator - //! \param thePointer a container of real values - //! \return the string value - Standard_EXPORT static TCollection_AsciiString RealVectorToString - (const NCollection_Vector& theValues); - - //! Convert string to vector of real values, separator is vector separator - //! \param thePointer a container of real values - //! \return the string value - Standard_EXPORT static Standard_Boolean RealVectorFromString - (const TCollection_AsciiString& theValue, - NCollection_Vector& theValues); - - //! Convert vector of real values to string, separator is vector separator - //! \param thePointer a container of real values - //! \return the string value - Standard_EXPORT static TCollection_AsciiString CoordVectorToString - (const NCollection_Vector& theValues); - - //! Convert string to vector of real values, separator is vector separator - //! \param thePointer a container of real values - //! \return the string value - Standard_EXPORT static Standard_Boolean CoordVectorFromString - (const TCollection_AsciiString& theValue, - NCollection_Vector& theValues); - - //! Convert vector of real values to string, separator is vector separator - //! \param thePointer a container of real values - //! \return the string value - Standard_EXPORT static TCollection_AsciiString ColorVectorToString - (const NCollection_Vector& theValues); - - //! Convert string to vector of real values, separator is vector separator - //! \param thePointer a container of real values - //! \return the string value - Standard_EXPORT static Standard_Boolean ColorVectorFromString - (const TCollection_AsciiString& theValue, - NCollection_Vector& theValues); - - //! Converts stream to vector of values and column count - //! \param theStream stream value - //! \param theColumnCount [out] number of columns - //! \param theValues [out] container of split values - static Standard_EXPORT void ConvertStream (const Standard_SStream& theStream, - Standard_Integer& theColumnCount, - NCollection_Vector& theValues); + //! 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); -protected: + //! 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); +protected: diff --git a/src/Message/Message_AlertExtended.cxx b/src/Message/Message_AlertExtended.cxx index 44555fccf2..2e7815feae 100644 --- a/src/Message/Message_AlertExtended.cxx +++ b/src/Message/Message_AlertExtended.cxx @@ -40,7 +40,6 @@ Standard_CString Message_AlertExtended::GetMessageKey () const //function : GetCompositeAlerts //purpose : //======================================================================= - Handle (Message_CompositeAlerts) Message_AlertExtended::GetCompositeAlerts (const Standard_Boolean isCreate) { if (myCompositAlerts.IsNull() && isCreate) @@ -50,32 +49,45 @@ Handle (Message_CompositeAlerts) Message_AlertExtended::GetCompositeAlerts (cons } //======================================================================= -//function : IsMetricValid +//function : SupportsMerge //purpose : //======================================================================= +Standard_Boolean Message_AlertExtended::SupportsMerge () const +{ + if (myCompositAlerts.IsNull()) + return Standard_True; + + // hierarchical alerts can not be merged + for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity) + { + if (!myCompositAlerts->GetAlerts ((Message_Gravity)iGravity).IsEmpty()) + return Standard_False; + } + + return Standard_True; +} -Standard_Boolean Message_AlertExtended::IsMetricValid() const +//======================================================================= +//function : Merge +//purpose : +//======================================================================= +Standard_Boolean Message_AlertExtended::Merge (const Handle(Message_Alert)& /*theTarget*/) { - return fabs (myMetricStart - GetUndefinedMetric()) > Precision::Confusion() && - fabs (myMetricStop - GetUndefinedMetric()) > Precision::Confusion(); + // 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, - Message_PerfMeter* thePerfMeter, - const Handle(Message_Alert)& theParentAlert) + const Message_Gravity theGravity) { - if (!theReport->IsActive (Message_Info)) - return Handle(Message_Alert)(); - Handle(Message_AlertExtended) anAlert = new Message_AlertExtended(); anAlert->SetAttribute (theAttribute); - theReport->AddAlert (Message_Info, anAlert, thePerfMeter, theParentAlert); + theReport->AddAlert (theGravity, anAlert); return anAlert; } diff --git a/src/Message/Message_AlertExtended.hxx b/src/Message/Message_AlertExtended.hxx index bac7047cd9..c5d81355e5 100644 --- a/src/Message/Message_AlertExtended.hxx +++ b/src/Message/Message_AlertExtended.hxx @@ -17,10 +17,10 @@ #define _Message_AlertExtended_HeaderFile #include +#include #include class Message_Attribute; -class Message_PerfMeter; class Message_Report; DEFINE_STANDARD_HANDLE(Message_AlertExtended, Message_Alert) @@ -29,8 +29,7 @@ class Message_CompositeAlerts; //! Inherited class of Message_Alert with some additional information. //! -//! It has Message_Attributes to provide the alert name, description and -//! other custom information +//! It has Message_Attributes to provide the alert name, and other custom information //! //! It is possible to set performance meter into alert to store time/memory metric information //! spent between the next alert adding. Also time of child alerts are collected @@ -43,8 +42,7 @@ class Message_AlertExtended : public Message_Alert { public: //! Empty constructor - Standard_EXPORT Message_AlertExtended() - : Message_Alert(), myMetricStart (GetUndefinedMetric()), myMetricStop (GetUndefinedMetric()) {} + Standard_EXPORT Message_AlertExtended() : Message_Alert() {} //! Return a C string to be used as a key for generating text user //! messages describing this alert. @@ -59,75 +57,41 @@ public: //! Returns container of the alert attributes //! \param theAttributes an attribute values - const Handle(Message_Attribute)& Attribute () const { return myAttribute; } + 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) GetCompositeAlerts (const Standard_Boolean isCreate = Standard_False); - //! Returns performance meter - //! \return instance or NULL - Message_PerfMeter* GetPerfMeter() { return myPerfMeter; } - - //! Returns true if metric is computed - //! @return value - Standard_EXPORT Standard_Boolean IsMetricValid() const; - - //! Returns the alert cumulative metric. It includes time/mem of sub alerts - //! @return value - Standard_Real MetricStart() const { return myMetricStart; } - - //! Returns the alert cumulative metric. It includes time/mem of sub alerts - //! @return value - Standard_Real MetricStop() const { return myMetricStop; } - - //! Sets cumulative time/mem of alert - //! \param theCumulativeMetric time/mem of the alert - void SetMetricValues (const Standard_Real theStartValue, const Standard_Real theStopValue) - { myMetricStart = theStartValue; myMetricStop = theStopValue; } - //! 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 { return Standard_False; } + virtual Standard_EXPORT Standard_Boolean SupportsMerge() const; - //! Returns default value of the time/mem when it is not defined - //! \return integer value - static Standard_Real GetUndefinedMetric() { return -1.0; } + //! 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); //! 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 - //! @param thePerfMeter performance meter calculates the alert spent time and participate in searching the last alert if needed - //! @param theParentAlert parent for the new alert, or alert is placed under the report //! @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, - Message_PerfMeter* thePerfMeter, - const Handle(Message_Alert)& theParentAlert = Handle(Message_Alert)()); + const Message_Gravity theGravity); // OCCT RTTI DEFINE_STANDARD_RTTIEXT(Message_AlertExtended, Message_Alert) -protected: - //! Sets performance meter - //! \param theMeter instance pointer or NULL - void SetPerfMeter (Message_PerfMeter* theMeter) { myPerfMeter = theMeter; } - protected: Handle(Message_CompositeAlerts) myCompositAlerts; //!< class provided hierarchical structure of alerts //!< It should be created by an attempt of a child alert creation - Handle(Message_Attribute) myAttribute; //!< container of the alert attributes - - Message_PerfMeter* myPerfMeter; //!< performance meter - Standard_Real myMetricStart; //!< value on start metric computation - Standard_Real myMetricStop; //!< value on stop metric computation - - friend Message_PerfMeter; }; #endif // _Message_Alert_HeaderFile diff --git a/src/Message/Message_Alerts.hxx b/src/Message/Message_Alerts.hxx index 9f73a1f56c..3aed324b89 100644 --- a/src/Message/Message_Alerts.hxx +++ b/src/Message/Message_Alerts.hxx @@ -21,82 +21,46 @@ #include #include #include +#include #include #include #include -static Handle(Message_Alert) OCCT_Message_Alert; - -#define MESSAGE_INFO(Name, Description, PerfMeter, ParentAlert) \ +#define MESSAGE_INFO(Name) \ { \ - if (!Message_Report::CurrentReport().IsNull() && \ - Message_Report::CurrentReport()->IsActive (Message_Info)) \ + if (!Message::DefaultReport().IsNull()) \ { \ - OCCT_Message_Alert = Message_AlertExtended::AddAlert (Message_Report::CurrentReport(), \ - new Message_Attribute (Name, Description), PerfMeter, ParentAlert); \ + if (Message::DefaultReport()->IsActiveInMessenger())\ + { Message::DefaultMessenger() << Name << Message_EndLine; } \ + else \ + Message_AlertExtended::AddAlert (Message::DefaultReport(), \ + new Message_Attribute (Name), Message_Info); \ } \ } -#define MESSAGE_INFO_OBJECT(Object, StreamValues, Name, Description, PerfMeter, ParentAlert) \ +#define MESSAGE_INFO_OBJECT(Object, Name) \ { \ - if (!Message_Report::CurrentReport().IsNull() && \ - Message_Report::CurrentReport()->IsActive (Message_Info)) \ + if (!Message::DefaultReport().IsNull()) \ { \ - OCCT_Message_Alert = Message_AlertExtended::AddAlert (Message_Report::CurrentReport(), \ - new Message_AttributeObject (Object, StreamValues, Name, Description), PerfMeter, ParentAlert ); \ + if (Message::DefaultReport()->IsActiveInMessenger())\ + { Message::DefaultMessenger() << Name << Object << Message_EndLine; } \ + else \ + Message_AlertExtended::AddAlert (Message::DefaultReport(), \ + new Message_AttributeObject (Object, Name), Message_Info); \ } \ } -#define MESSAGE_INFO_STREAM(StreamValues, Name, Description, PerfMeter, ParentAlert) \ +#define MESSAGE_INFO_STREAM(StreamValues, Name) \ { \ - if (!Message_Report::CurrentReport().IsNull() && \ - Message_Report::CurrentReport()->IsActive (Message_Info)) \ + if (!Message::DefaultReport().IsNull()) \ { \ - OCCT_Message_Alert = Message_AlertExtended::AddAlert (Message_Report::CurrentReport(), \ - new Message_AttributeStream (StreamValues, Name, Description), PerfMeter, ParentAlert ); \ + if (Message::DefaultReport()->IsActiveInMessenger())\ + { Message::DefaultMessenger() << Name << StreamValues << Message_EndLine; } \ + else \ + Message_AlertExtended::AddAlert (Message::DefaultReport(), \ + new Message_AttributeStream (StreamValues, Name), Message_Info); \ } \ } -//#define DUMP_VALUE(OS, Value) \ -// { \ -// OS << Value << Message::DumpSeparator(); \ -// } -// -//#define DUMP_VALUES_COLUMNS(OS, ObjectName, ColumnCount) \ -// { \ -// OS << ObjectName << Message::DumpSeparator() << ColumnCount << Message::DumpSeparator(); \ -// } -// -//#define DUMP_VALUES(OS, Value1, Value2) \ -// { \ -// OS << Value1 << Message::DumpSeparator() << Value2 << Message::DumpSeparator(); \ -// } -// -//#define DUMP_VEC_COLOR(Values, Value) \ -// { \ -// Value = Message::ColorVectorToString (aValues); \ -// } -// -//#define DUMP_VEC_COLOR_SPLIT(Value, Values) \ -// { \ -// Message::ColorVectorFromString (Value, Values); \ -// } -// -//#define DUMP_VEC_COORD(Values, Value) \ -// { \ -// Value = Message::CoordVectorToString (aValues); \ -// } -// -//#define DUMP_VEC_COORD_SPLIT(Value, Values) \ -// { \ -// Message::CoordVectorFromString (Value, Values); \ -// } -// -// -//#define DUMP_VALUES_SPLIT(OS, ColumnCount, Values) \ -// { \ -// Message::ConvertStream (OS, aColumnCount, aValues); \ -// } - #endif // _Message_Alerts_HeaderFile diff --git a/src/Message/Message_Attribute.hxx b/src/Message/Message_Attribute.hxx index f27b332266..61198d28d0 100644 --- a/src/Message/Message_Attribute.hxx +++ b/src/Message/Message_Attribute.hxx @@ -27,9 +27,8 @@ class Message_Attribute : public Standard_Transient { public: //! Empty constructor - Standard_EXPORT Message_Attribute (const TCollection_AsciiString& theName = TCollection_AsciiString(), - const TCollection_AsciiString& theDescription = TCollection_AsciiString()) - : myName (theName), myDescription (theDescription) {} + 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. @@ -46,21 +45,12 @@ public: //! @param theName a name for the alert void SetName (const TCollection_AsciiString& theName) { myName = theName; } - //! Sets desription of alert - //! @param theName a name for the alert - void SetDescription (const TCollection_AsciiString& theDescription) { myDescription = theDescription; } - - //! Returns description of alert if it is set - //! @return alert description - virtual const TCollection_AsciiString& GetDescription() const { return myDescription; } - // OCCT RTTI DEFINE_STANDARD_RTTIEXT(Message_Attribute, Standard_Transient) private: TCollection_AsciiString myName; //!< alert name, if defined is used in GetMessageKey - TCollection_AsciiString myDescription; //!< alert description if defined }; diff --git a/src/Message/Message_AttributeMeter.cxx b/src/Message/Message_AttributeMeter.cxx new file mode 100644 index 0000000000..3ffc22cb7b --- /dev/null +++ b/src/Message/Message_AttributeMeter.cxx @@ -0,0 +1,98 @@ +// Copyright (c) 2020 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include + +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 fabs (StartValue (theMetric) - GetUndefinedMetric()) > Precision::Confusion() && + fabs (StopValue (theMetric) - GetUndefinedMetric()) > Precision::Confusion(); +} + +//======================================================================= +//function : StartValue +//purpose : +//======================================================================= +Standard_Real Message_AttributeMeter::StartValue (const Message_MetricType& theMetric) const +{ + if (!HasMetric (theMetric)) + return GetUndefinedMetric(); + + return myMetrics.Find (theMetric).first; +} + +//======================================================================= +//function : SetStartValue +//purpose : +//======================================================================= +void Message_AttributeMeter::SetStartValue (const Message_MetricType& theMetric, const Standard_Real theValue) +{ + if (!HasMetric (theMetric)) + { + myMetrics.Bind (theMetric, std::make_pair (theValue, GetUndefinedMetric())); + } + myMetrics.ChangeFind (theMetric).first = theValue; +} + +//======================================================================= +//function : StopValue +//purpose : +//======================================================================= +Standard_Real Message_AttributeMeter::StopValue (const Message_MetricType& theMetric) const +{ + if (!HasMetric (theMetric)) + return GetUndefinedMetric(); + + return myMetrics.Find (theMetric).second; +} + +//======================================================================= +//function : SetStopValue +//purpose : +//======================================================================= +void Message_AttributeMeter::SetStopValue (const Message_MetricType& theMetric, const Standard_Real theValue) +{ + if (!HasMetric (theMetric)) + { + // start value should be already set + return; + } + myMetrics.ChangeFind (theMetric).second = theValue; +} diff --git a/src/Message/Message_AttributeMeter.hxx b/src/Message/Message_AttributeMeter.hxx new file mode 100644 index 0000000000..a9f98d42ba --- /dev/null +++ b/src/Message/Message_AttributeMeter.hxx @@ -0,0 +1,72 @@ +// 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 +#include + +#include + +#include + +class Message_Alert; + +//! Alert object storing container metrics values +class Message_AttributeMeter : public Message_Attribute +{ +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 + Standard_EXPORT Standard_Boolean HasMetric (const Message_MetricType& theMetric) const; + + //! Returns true if metric is computed + //! @return value + Standard_EXPORT Standard_Boolean IsMetricValid (const Message_MetricType& theMetric) const; + + //! Returns start value for the metric + //! \param theMetric [in] metric type + 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 + 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); + + //! Returns default value of the time/mem when it is not defined + //! \return integer value + static Standard_Real GetUndefinedMetric() { return -1.0; } + + // OCCT RTTI + DEFINE_STANDARD_RTTIEXT(Message_AttributeMeter, Message_Attribute) + +private: + + typedef std::pair MinToMaxValue; + NCollection_DataMap myMetrics; //!< computed metrics +}; + +#endif // _Message_AttributeMeter_HeaderFile diff --git a/src/Message/Message_AttributeObject.cxx b/src/Message/Message_AttributeObject.cxx index b31ad97cd0..67ac1f6aff 100644 --- a/src/Message/Message_AttributeObject.cxx +++ b/src/Message/Message_AttributeObject.cxx @@ -15,7 +15,7 @@ #include -IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeObject, Message_AttributeStream) +IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeObject, Message_Attribute) //======================================================================= //function : Message_AttributeObject @@ -23,10 +23,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeObject, Message_AttributeStream) //======================================================================= Message_AttributeObject::Message_AttributeObject (const Handle(Standard_Transient)& theObject, - const Standard_SStream& theStream, - const TCollection_AsciiString& theName, - const TCollection_AsciiString& theDescription) -: Message_AttributeStream (theStream, theName, theDescription) + const TCollection_AsciiString& theName) +: Message_Attribute (theName) { myObject = theObject; } diff --git a/src/Message/Message_AttributeObject.hxx b/src/Message/Message_AttributeObject.hxx index 29e45e98ca..75321a1008 100644 --- a/src/Message/Message_AttributeObject.hxx +++ b/src/Message/Message_AttributeObject.hxx @@ -16,18 +16,16 @@ #ifndef _Message_AttributeObject_HeaderFile #define _Message_AttributeObject_HeaderFile -#include +#include #include //! Alert object storing Transient object in its field -class Message_AttributeObject : public Message_AttributeStream +class Message_AttributeObject : public Message_Attribute { public: //! Constructor with string argument Standard_EXPORT Message_AttributeObject (const Handle(Standard_Transient)& theObject, - const Standard_SStream& theStream, - const TCollection_AsciiString& theName = TCollection_AsciiString(), - const TCollection_AsciiString& theDescription = TCollection_AsciiString()); + const TCollection_AsciiString& theName = TCollection_AsciiString()); //! Sets the object //! @param theObject an instance @@ -37,7 +35,7 @@ public: Handle(Standard_Transient) GetObject() const { return myObject; } // OCCT RTTI - DEFINE_STANDARD_RTTIEXT(Message_AttributeObject, Message_AttributeStream) + DEFINE_STANDARD_RTTIEXT(Message_AttributeObject, Message_Attribute) private: Handle(Standard_Transient) myObject; diff --git a/src/Message/Message_AttributeStream.cxx b/src/Message/Message_AttributeStream.cxx index 20c38b79b1..19c5c8323a 100644 --- a/src/Message/Message_AttributeStream.cxx +++ b/src/Message/Message_AttributeStream.cxx @@ -17,7 +17,6 @@ #include #include -#include #include IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeStream, Message_Attribute) @@ -27,9 +26,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeStream, Message_Attribute) //purpose : //======================================================================= Message_AttributeStream::Message_AttributeStream (const Standard_SStream& theStream, - const TCollection_AsciiString& theName, - const TCollection_AsciiString& theDescription) -: Message_Attribute(theName, theDescription) + const TCollection_AsciiString& theName) +: Message_Attribute(theName) { SetStream (theStream); } diff --git a/src/Message/Message_AttributeStream.hxx b/src/Message/Message_AttributeStream.hxx index c0a3218726..2520670cfc 100644 --- a/src/Message/Message_AttributeStream.hxx +++ b/src/Message/Message_AttributeStream.hxx @@ -21,7 +21,6 @@ #include -class Message_PerfMeter; class Message_Report; //! Alert object storing container of Standard_Real values in its field @@ -31,8 +30,7 @@ public: //! Constructor with string argument Standard_EXPORT Message_AttributeStream (const Standard_SStream& theStream, - const TCollection_AsciiString& theName = TCollection_AsciiString(), - const TCollection_AsciiString& theDescription = TCollection_AsciiString()); + const TCollection_AsciiString& theName = TCollection_AsciiString()); //! Sets stream value Standard_EXPORT void SetStream (const Standard_SStream& theStream); diff --git a/src/Message/Message_CompositeAlerts.cxx b/src/Message/Message_CompositeAlerts.cxx index bf390d424a..79ed72e80d 100644 --- a/src/Message/Message_CompositeAlerts.cxx +++ b/src/Message/Message_CompositeAlerts.cxx @@ -20,25 +20,50 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_CompositeAlerts, Standard_Transient) //======================================================================= -//function : Merge -//purpose : +//function : AddAlert +//purpose : //======================================================================= -Standard_Boolean Message_CompositeAlerts::Merge (const Handle(Message_Alert)& theTarget) +Standard_Boolean Message_CompositeAlerts::AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert) { - Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (theTarget); - if (!anExtAlert.IsNull() && !anExtAlert->GetCompositeAlerts().IsNull()) + 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()) { - Handle(Message_CompositeAlerts) anExtCompositeAlert = anExtAlert->GetCompositeAlerts(); - // hierarchical alerts can not be merged - for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity) + // 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 (!GetAlerts ((Message_Gravity)iGravity).IsEmpty() || - !anExtCompositeAlert->GetAlerts ((Message_Gravity)iGravity).IsEmpty()) + // if merged successfully, just return + if (aType == anIt.Value()->DynamicType() && theAlert->Merge (anIt.Value())) return Standard_False; } } - // by default, merge trivially + + // if not merged, just add to the list + aList.Append (theAlert); + return Standard_True; +} + +//======================================================================= +//function : Merge +//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; + + anAlerts.Remove (theAlert); return Standard_True; } @@ -47,9 +72,13 @@ Standard_Boolean Message_CompositeAlerts::Merge (const Handle(Message_Alert)& th //purpose : //======================================================================= -Message_ListOfAlert& Message_CompositeAlerts::GetAlerts (const Message_Gravity theGravity) +const Message_ListOfAlert& Message_CompositeAlerts::GetAlerts (const Message_Gravity theGravity) const { - return myChildAlerts[theGravity]; + 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]; } //======================================================================= @@ -61,9 +90,75 @@ Standard_Boolean Message_CompositeAlerts::HasAlert (const Handle(Message_Alert)& { for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity) { - Message_ListOfAlert& anAlerts = GetAlerts ((Message_Gravity)iGravity); + const Message_ListOfAlert& anAlerts = GetAlerts ((Message_Gravity)iGravity); 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(); + } + } + } +} diff --git a/src/Message/Message_CompositeAlerts.hxx b/src/Message/Message_CompositeAlerts.hxx index f069d45836..aeb53d972f 100644 --- a/src/Message/Message_CompositeAlerts.hxx +++ b/src/Message/Message_CompositeAlerts.hxx @@ -42,26 +42,39 @@ public: //! Empty constructor Standard_EXPORT Message_CompositeAlerts () {} - //! If possible, merge data contained in this alert to theTarget. - //! @return True if merged. - //! Base implementation always returns true. - virtual Standard_EXPORT Standard_Boolean Merge (const Handle(Message_Alert)& theTarget); - + //! Add alert with specified gravity. + Standard_EXPORT Standard_Boolean AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert); + + //! Removes alert with specified gravity. + Standard_EXPORT Standard_Boolean RemoveAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert); + //! Returns list of collected alerts with specified gravity - Standard_EXPORT Message_ListOfAlert& GetAlerts (const Message_Gravity theGravity); + Standard_EXPORT const Message_ListOfAlert& GetAlerts (const Message_Gravity theGravity) const; //! 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 + 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 + Standard_EXPORT void Clear (Message_Gravity theGravity); + + //! Clears collected alerts with specified type + Standard_EXPORT void Clear (const Handle(Standard_Type)& theType); + // OCCT RTTI 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 myChildAlerts[Message_Fail + 1]; + Message_ListOfAlert myAlerts[Message_Fail + 1]; }; #endif // _Message_CompositeAlerts_HeaderFile diff --git a/src/Message/Message_Level.cxx b/src/Message/Message_Level.cxx new file mode 100644 index 0000000000..2542a6df8a --- /dev/null +++ b/src/Message/Message_Level.cxx @@ -0,0 +1,211 @@ +// 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 + +#include +#include +#include +#include +#include + +#include +#include + +//======================================================================= +//function : Destructor +//purpose : +//======================================================================= +Message_Level::Message_Level() +{ + const Handle(Message_Report)& aDefaultReport = Message::DefaultReport(); + if (!aDefaultReport.IsNull() && aDefaultReport->IsActiveInMessenger()) + aDefaultReport->AddLevel (this); +} + +//======================================================================= +//function : Destructor +//purpose : +//======================================================================= + +Message_Level::~Message_Level() +{ + Remove(); +} + +//======================================================================= +//function : SetRootAlert +//purpose : +//======================================================================= + +void Message_Level::SetRootAlert (const Handle(Message_AlertExtended)& theAlert) +{ + myRootAlert = theAlert; + 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; + + if (myRootAlert.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->GetCompositeAlerts (Standard_True); + + // update metrics of the previous alert + stopAlert (myLastAlert); + + // set start metrics of the new alert + myLastAlert = anAlertExtended; + startAlert (myLastAlert); + + // add child alert + aCompositeAlert->AddAlert (theGravity, theAlert); + + return Standard_True; +} + +//======================================================================= +//function : AddAlert +//purpose : +//======================================================================= + +Standard_Boolean Message_Level::AddLevelAlert (const Message_Gravity theGravity, + const Handle(Message_Alert)& theAlert) +{ + Handle(Message_AlertExtended) aRootAlert = !myLastAlert.IsNull() ? myLastAlert : myRootAlert; + + Handle(Message_CompositeAlerts) aCompositeAlert = aRootAlert->GetCompositeAlerts (Standard_True); + // 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; + + stopAlert (myLastAlert); + stopAlert (myRootAlert); + + if (!Message::DefaultReport().IsNull()) + Message::DefaultReport()->RemoveLevel (this); +} + +//======================================================================= +//function : startAlert +//purpose : +//======================================================================= + +Standard_Boolean Message_Level::startAlert (const Handle(Message_AlertExtended)& theAlert) +{ + return setAlertMetrics (theAlert, Standard_True); +} + +//======================================================================= +//function : stopAlert +//purpose : +//======================================================================= + +Standard_Boolean Message_Level::stopAlert (const Handle(Message_AlertExtended)& theAlert) +{ + return setAlertMetrics (theAlert, Standard_False); +} + +//======================================================================= +//function : setAlertMetrics +//purpose : +//======================================================================= + +Standard_Boolean Message_Level::setAlertMetrics (const Handle(Message_AlertExtended)& theAlert, + const Standard_Boolean theStartValue) +{ + if (theAlert.IsNull()) + return Standard_False; + + Handle(Message_AttributeMeter) aMeterAttribute = Handle(Message_AttributeMeter)::DownCast (theAlert->Attribute()); + if (aMeterAttribute.IsNull()) + return Standard_False; + + Handle(Message_Report) aReport = Message::DefaultReport (Standard_True); + const NCollection_Map& anActiveMetrics = aReport->ActiveMetrics(); + + // time metrics + if (anActiveMetrics.Contains (Message_MetricType_UserTimeCPU) || + anActiveMetrics.Contains (Message_MetricType_SystemTimeInfo)) + { + Standard_Real aUserSeconds, aSystemSeconds; + OSD_Chronometer::GetThreadCPU (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 + NCollection_Map aCounters; + for (NCollection_Map::Iterator anIterator (anActiveMetrics); anIterator.More(); anIterator.Next()) + { + OSD_MemInfo::Counter aMemInfo; + if (!Message::ToOSDMetric (anIterator.Value(), aMemInfo)) + continue; + + aCounters.Add (aMemInfo); + } + if (aCounters.IsEmpty()) + return Standard_True; + + OSD_MemInfo aMemInfo (Standard_False); + aMemInfo.Update (aCounters); + Message_MetricType aMetricType; + for (NCollection_Map::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())); + } + return Standard_True; +} diff --git a/src/Message/Message_Level.hxx b/src/Message/Message_Level.hxx new file mode 100644 index 0000000000..35de389bab --- /dev/null +++ b/src/Message/Message_Level.hxx @@ -0,0 +1,93 @@ +// 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 +#include +#include + +#include +#include + +//! This class defines level of alerts in the current report. +//! The first added alert is the root alert, next alerts are children of the root alert. +class Message_Level +{ + +public: + //! Constructs and starts (if autoStart is true) the named meter + //! 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(); + + //! Assures stopping upon destruction + Standard_EXPORT ~Message_Level(); + + //! Returns message alert on the level, by default the upper alert is returned + //! \param theLevelId a level of child position inside the upper alert of performance meter + //! \return alert instance or NULL + Handle(Message_AlertExtended) RootAlert() const { return myRootAlert; } + + //! Returns message alert on the level, by default the upper alert is returned + //! \param theLevelId a level of child position inside the upper alert of performance meter + //! \return alert instance or NULL + Standard_EXPORT void SetRootAlert (const Handle(Message_AlertExtended)& theAlert); + + //! Processes the parameter alert. There are some variants: + //! - current alert is NULL, the alert becomes the current one and perf meter is started + //! - last alert of the current alert is stopped (perf meter becomes NULL, time is calculated), + //! the parameter alert is started (perf meter becomes the current one) + Standard_EXPORT Standard_Boolean AddAlert (const Message_Gravity theGravity, + const Handle(Message_Alert)& theAlert); + + //! Add level alert, that is placed under the previous last alert if exists or under the root alert + Standard_EXPORT Standard_Boolean AddLevelAlert (const Message_Gravity theGravity, + const Handle(Message_Alert)& theAlert); + + //! Remove the current level from the report + Standard_EXPORT void Remove(); + +protected: + //! Sets stop time into the alert + //! \param theAlert a level of child position inside the upper alert of performance meter + Standard_Boolean startAlert (const Handle(Message_AlertExtended)& theAlert); + + //! Sets start time into the alert + //! \param theAlert a level of child position inside the upper alert of performance meter + Standard_Boolean stopAlert (const Handle(Message_AlertExtended)& theAlert); + + //! Fills the alert with metric values + //! \param theAlert a level of child position inside the upper alert of performance meter + //! \param theStartValue flag whether the computed value is the start value, if false, stop value is filled + //! \return true if the alert is filled + Standard_Boolean setAlertMetrics (const Handle(Message_AlertExtended)& theAlert, + const Standard_Boolean theStartValue); + +protected: + Handle(Message_AlertExtended) myRootAlert; //!< root alerts + Handle(Message_AlertExtended) myLastAlert; //!< last added alert +}; + +//! @def MESSAGE_NEW_LEVEL +//! Creates a new level instance of Sentry. This row should be inserted before messages using in the method. +#define MESSAGE_ADD_LEVEL_SENTRY Message_Level aLevel; + +//! @def MESSAGE_NEW_LEVEL +//! Removed the current level from report. It is not necessary to call it as the level will be removed at the method end. +//! This macro might be useful for creation several levels in one method to remove previous and add new one. +#define MESSAGE_REMOVE_LEVEL_SENTRY() aLevel.Remove(); + + +#endif // _Message_Level_HeaderFile diff --git a/src/Message/Message_Messenger.cxx b/src/Message/Message_Messenger.cxx index 1e44c8b220..c2e2c71799 100644 --- a/src/Message/Message_Messenger.cxx +++ b/src/Message/Message_Messenger.cxx @@ -25,6 +25,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient) //purpose : //======================================================================= Message_Messenger::Message_Messenger () +: myOutputGravity (Message_Info) { AddPrinter ( new Message_PrinterOStream ); } @@ -35,6 +36,7 @@ Message_Messenger::Message_Messenger () //======================================================================= Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter) +: myOutputGravity (Message_Info) { AddPrinter (thePrinter); } @@ -161,3 +163,41 @@ void Message_Messenger::Send (const TCollection_ExtendedString& theString, } } } + +//======================================================================= +//function : Send +//purpose : +//======================================================================= + +void Message_Messenger::Send (const Standard_SStream& theStream, + const Message_Gravity theGravity, + const Standard_Boolean putEndl) const +{ + for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next()) + { + const Handle(Message_Printer)& aPrinter = aPrinterIter.Value(); + if (!aPrinter.IsNull()) + { + aPrinter->Send (theStream, theGravity, putEndl); + } + } +} + +//======================================================================= +//function : Send +//purpose : +//======================================================================= + +void Message_Messenger::Send (const Handle(Standard_Transient)& theObject, + const Message_Gravity theGravity, + const Standard_Boolean putEndl) const +{ + for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next()) + { + const Handle(Message_Printer)& aPrinter = aPrinterIter.Value(); + if (!aPrinter.IsNull()) + { + aPrinter->Send (theObject, theGravity, putEndl); + } + } +} diff --git a/src/Message/Message_Messenger.hxx b/src/Message/Message_Messenger.hxx index 675fba3436..951eac85f4 100644 --- a/src/Message/Message_Messenger.hxx +++ b/src/Message/Message_Messenger.hxx @@ -84,6 +84,12 @@ public: //! The sequence can be modified. Message_SequenceOfPrinters& ChangePrinters() { return myPrinters; } + //! Returns the output gavity used in operator << + Message_Gravity OuputGravity() const { return myOutputGravity; } + + //! Sets the output gavity used in operator << + void SetOuputGravity (const Message_Gravity theValue) { myOutputGravity = theValue; } + //! 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. @@ -98,17 +104,23 @@ public: //! See above Standard_EXPORT void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity = Message_Warning, const Standard_Boolean putEndl = Standard_True) const; + //! See above + Standard_EXPORT void Send (const Standard_SStream& theStream, const Message_Gravity theGravity = Message_Warning, const Standard_Boolean putEndl = Standard_True) const; + + //! See above + Standard_EXPORT void Send (const Handle(Standard_Transient)& theObject, const Message_Gravity theGravity = Message_Warning, const Standard_Boolean putEndl = Standard_True) const; + private: Message_SequenceOfPrinters myPrinters; - + Message_Gravity myOutputGravity; //!< gavity used in operator << }; // CString inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger, const Standard_CString theStr) { - theMessenger->Send (theStr, Message_Info, Standard_False); + theMessenger->Send (theStr, theMessenger->OuputGravity(), Standard_False); return theMessenger; } @@ -116,7 +128,7 @@ inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messeng inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger, const TCollection_AsciiString& theStr) { - theMessenger->Send (theStr, Message_Info, Standard_False); + theMessenger->Send (theStr, theMessenger->OuputGravity(), Standard_False); return theMessenger; } @@ -124,7 +136,7 @@ inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messeng inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger, const Handle(TCollection_HAsciiString)& theStr) { - theMessenger->Send (theStr->String(), Message_Info, Standard_False); + theMessenger->Send (theStr->String(), theMessenger->OuputGravity(), Standard_False); return theMessenger; } @@ -132,7 +144,7 @@ inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messeng inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger, const TCollection_ExtendedString& theStr) { - theMessenger->Send (theStr, Message_Info, Standard_False); + theMessenger->Send (theStr, theMessenger->OuputGravity(), Standard_False); return theMessenger; } @@ -140,7 +152,7 @@ inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messeng inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger, const Handle(TCollection_HExtendedString)& theStr) { - theMessenger->Send (theStr->String(), Message_Info, Standard_False); + theMessenger->Send (theStr->String(), theMessenger->OuputGravity(), Standard_False); return theMessenger; } @@ -149,7 +161,7 @@ inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messeng const Standard_Integer theVal) { TCollection_AsciiString aStr (theVal); - theMessenger->Send (aStr, Message_Info, Standard_False); + theMessenger->Send (aStr, theMessenger->OuputGravity(), Standard_False); return theMessenger; } @@ -158,7 +170,7 @@ inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messeng const Standard_Real theVal) { TCollection_AsciiString aStr (theVal); - theMessenger->Send (aStr, Message_Info, Standard_False); + theMessenger->Send (aStr, theMessenger->OuputGravity(), Standard_False); return theMessenger; } @@ -166,7 +178,15 @@ inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messeng inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger, const Standard_SStream& theStream) { - theMessenger->Send (theStream.str().c_str(), Message_Info, Standard_False); + theMessenger->Send (theStream, theMessenger->OuputGravity(), Standard_False); + return theMessenger; +} + +// AsciiString +inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger, + const Handle(Standard_Transient)& theObject) +{ + theMessenger->Send (theObject, theMessenger->OuputGravity(), Standard_False); return theMessenger; } @@ -181,7 +201,7 @@ inline const Handle(Message_Messenger)& // Message_EndLine inline const Handle(Message_Messenger)& Message_EndLine (const Handle(Message_Messenger)& theMessenger) { - theMessenger->Send ("", Message_Info, Standard_True); + theMessenger->Send ("", theMessenger->OuputGravity(), Standard_True); return theMessenger; } diff --git a/src/Message/Message_MetricType.hxx b/src/Message/Message_MetricType.hxx new file mode 100644 index 0000000000..1529306864 --- /dev/null +++ b/src/Message/Message_MetricType.hxx @@ -0,0 +1,34 @@ +// Created on: 2019-08-13 +// Created by: Natalia ERMOLAEVA +// 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_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 diff --git a/src/Message/Message_PerfMeter.cxx b/src/Message/Message_PerfMeter.cxx deleted file mode 100644 index d602574afa..0000000000 --- a/src/Message/Message_PerfMeter.cxx +++ /dev/null @@ -1,192 +0,0 @@ -// 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 - -#include -#include - -#include -#include - -//======================================================================= -//function : Destructor -//purpose : -//======================================================================= - -Message_PerfMeter::~Message_PerfMeter() -{ - releaseAlert (0); -} - -//======================================================================= -//function : GetAlert -//purpose : -//======================================================================= - -Handle(Message_AlertExtended) Message_PerfMeter::GetAlert (const Standard_Integer theLevelId) const -{ - if (!myActiveAlerts.IsBound (theLevelId)) - return Handle(Message_AlertExtended)(); - - return myActiveAlerts.Find (theLevelId).myAlert; -} - -//======================================================================= -//function : AddAlert -//purpose : -//======================================================================= - -void Message_PerfMeter::AddAlert (const Handle(Message_Alert)& theAlert, - const Message_PerfMeterMode theMode) -{ - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (theAlert); - if (anExtendedAlert.IsNull()) - return; - - if (myActiveAlerts.IsEmpty()) - { - setAlert (0, theAlert, theMode); - return; - } - - Standard_Integer aSize = myActiveAlerts.Size(); - // looking for the parent of the parameter alert to release the previous alert - for (Standard_Integer aLevelId = 0; aLevelId < aSize; aLevelId++) - { - Handle(Message_AlertExtended) anAlert = GetAlert (aLevelId); - Handle(Message_CompositeAlerts) aCompositeAlert = anAlert->GetCompositeAlerts(); - Standard_ASSERT_RETURN (! aCompositeAlert.IsNull(), "Any alert of the performance meter has composite and children",); - if (!aCompositeAlert->HasAlert (theAlert)) - continue; - // parent alert is found - if (myActiveAlerts.IsBound (aLevelId + 1)) - releaseAlert (aLevelId + 1); - - setAlert (aLevelId + 1, theAlert, theMode); - return; - } - Standard_Boolean isDone = Standard_True; - Standard_ASSERT_RETURN (!isDone, "Alert should be processed above",); -} - -//======================================================================= -//function : setAlert -//purpose : -//======================================================================= - -Standard_Boolean Message_PerfMeter::setAlert (const Standard_Integer theLevelId, - const Handle(Message_Alert)& theAlert, - const Message_PerfMeterMode theMode) -{ - if (!GetAlert (theLevelId).IsNull()) - return Standard_False; - - Handle(Message_AlertExtended) anAlertExtended = Handle(Message_AlertExtended)::DownCast (theAlert); - if (anAlertExtended.IsNull()) - return Standard_False; - - myActiveAlerts.Bind (theLevelId, AlertInfo (anAlertExtended, getCurrentInfo (theMode))); - anAlertExtended->SetPerfMeter (this); - myMode = theMode; - return Standard_True; -} - -//======================================================================= -//function : releaseAlert -//purpose : -//======================================================================= - -Standard_Boolean Message_PerfMeter::releaseAlert (const Standard_Integer theLevelId) -{ - // release alerts from the tail till the given alert - for (Standard_Integer aLevelId = myActiveAlerts.Extent() - 1; aLevelId >= theLevelId; aLevelId--) - { - if (!myActiveAlerts.IsBound (aLevelId)) - continue; - stopAlert (aLevelId); - } - - return Standard_True; -} - -//======================================================================= -//function : stopAlert -//purpose : -//======================================================================= - -Standard_Boolean Message_PerfMeter::stopAlert (const Standard_Integer theLevelId) -{ - if (!myActiveAlerts.IsBound (theLevelId)) - return Standard_False; - - AlertInfo anAlertInfo = myActiveAlerts.Find (theLevelId); - Handle(Message_AlertExtended) anExtendedAlert = anAlertInfo.myAlert; - - anExtendedAlert->SetMetricValues (anAlertInfo.myStartValue, getCurrentInfo(myMode)); - anExtendedAlert->SetPerfMeter (0); - myActiveAlerts.UnBind (theLevelId); - - return Standard_True; -} - -//======================================================================= -//function : getLevel -//purpose : -//======================================================================= - -Standard_Integer Message_PerfMeter::getLevel (const Handle(Message_Alert)& theAlert) -{ - for (NCollection_DataMap::Iterator anIterator (myActiveAlerts); - anIterator.More(); anIterator.Next()) - { - if (anIterator.Value().myAlert == theAlert) - return anIterator.Key(); - } - return -1; -} - -//======================================================================= -//function : getCurrentInfo -//purpose : -//======================================================================= - -Standard_Real Message_PerfMeter::getCurrentInfo (const Message_PerfMeterMode theMode) -{ - if (theMode == Message_PerfMeterMode_UserTimeCPU || - theMode == Message_PerfMeterMode_SystemTimeInfo) - { - Standard_Real aUserSeconds, aSystemSeconds; - OSD_Chronometer::GetThreadCPU (aUserSeconds, aSystemSeconds); - return theMode == Message_PerfMeterMode_UserTimeCPU ? aUserSeconds : aSystemSeconds; - } - - OSD_MemInfo::Counter aType; - switch (theMode) - { - case Message_PerfMeterMode_MemPrivate: aType = OSD_MemInfo::MemPrivate; break; - case Message_PerfMeterMode_MemVirtual: aType = OSD_MemInfo::MemVirtual; break; - case Message_PerfMeterMode_MemWorkingSet: aType = OSD_MemInfo::MemWorkingSet; break; - case Message_PerfMeterMode_MemWorkingSetPeak: aType = OSD_MemInfo::MemWorkingSetPeak; break; - case Message_PerfMeterMode_MemSwapUsage: aType = OSD_MemInfo::MemSwapUsage; break; - case Message_PerfMeterMode_MemSwapUsagePeak: aType = OSD_MemInfo::MemSwapUsagePeak; break; - case Message_PerfMeterMode_MemHeapUsage: aType = OSD_MemInfo::MemHeapUsage; break; - default: return Message_AlertExtended::GetUndefinedMetric(); break; - } - - OSD_MemInfo aMemInfo (Standard_False); - aMemInfo.Update (aType); - return (Standard_Real)aMemInfo.ValuePreciseMiB (aType); -} diff --git a/src/Message/Message_PerfMeter.hxx b/src/Message/Message_PerfMeter.hxx deleted file mode 100644 index d9f85bd522..0000000000 --- a/src/Message/Message_PerfMeter.hxx +++ /dev/null @@ -1,97 +0,0 @@ -// 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 _Message_PerfMeter_HeaderFile -#define _Message_PerfMeter_HeaderFile - -#include -#include -#include - -#include -#include - -//! This class is performance meter for message alerts. The usage is create the simple instance of it (not a pointer) -//! in a method. Finalizing of the method will call destructor of the meter and store time into alert. -class Message_PerfMeter -{ - -public: - //! Constructs and starts (if autoStart is true) the named meter - //! One string key is used for all alert meters. The perf meter is not started automatically, it will be done in - //! AddAlert method - Message_PerfMeter() : myGravity (Message_Info), myMode (Message_PerfMeterMode_None) {} - - //! Assures stopping upon destruction - Standard_EXPORT ~Message_PerfMeter(); - - //! Returns message alert on the level, by default the upper alert is returned - //! \param theLevelId a level of child position inside the upper alert of performance meter - //! \return alert instance or NULL - Handle(Message_AlertExtended) GetAlert (const Standard_Integer theLevelId = 0) const; - - //! Processes the parameter alert. There are some variants: - //! - current alert is NULL, the alert becomes the current one and perf meter is started - //! - last alert of the current alert is stopped (perf meter becomes NULL, time is calculated), - //! the parameter alert is started (perf meter becomes the current one) - Standard_EXPORT void AddAlert (const Handle(Message_Alert)& theAlert, - const Message_PerfMeterMode theMode); - -protected: - - //! Sets message alert on the level - //! \param theLevelId a level of child position inside the upper alert of performance meter - //! \param theAlert an alert to be stored - //! \return true if succeeded, false if there is stored alert on the given level - Standard_Boolean setAlert (const Standard_Integer theLevelId, - const Handle(Message_Alert)& theAlert, - const Message_PerfMeterMode theMode); - - //! Stop alert, store time into the alert and last child alert - //! \param theLevelId a level of child position inside the upper alert of performance meter - Standard_Boolean releaseAlert (const Standard_Integer theLevelId); - - //! Sets NULL perf meter and parameter time into the alert - //! \param theLevelId a level of child position inside the upper alert of performance meter - Standard_Boolean stopAlert (const Standard_Integer theLevelId); - - //! Returns level of given alert if it participates in the performance meter - //! \param theAlert modified alert - //! \return level value or -1 - Standard_Integer getLevel (const Handle(Message_Alert)& theAlert); - - //! Returns cumulative info of the performance meter - //! \param theMeterId a performance meter index - //! \return time value - static Standard_Real getCurrentInfo (const Message_PerfMeterMode theMode); - -protected: - //! Struct to store start time for the alert - struct AlertInfo - { - AlertInfo (const Handle(Message_AlertExtended)& theAlert, Standard_Real theStartValue) - : myAlert (theAlert), myStartValue (theStartValue) {} - - Handle(Message_AlertExtended) myAlert; //!< an alert - Standard_Real myStartValue; //!< start alert information - }; - - NCollection_DataMap myActiveAlerts; //!< container of current alerts - Message_Gravity myGravity; //!< perf meter alert gravity - Message_PerfMeterMode myMode; //!< mode to define which information to collect -}; - - -#endif // _Message_PerfMeter_HeaderFile diff --git a/src/Message/Message_PerfMeterMode.hxx b/src/Message/Message_PerfMeterMode.hxx deleted file mode 100644 index d03d5d43f9..0000000000 --- a/src/Message/Message_PerfMeterMode.hxx +++ /dev/null @@ -1,34 +0,0 @@ -// Created on: 2019-08-13 -// Created by: Natalia ERMOLAEVA -// 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_PerfMeterMode_HeaderFile -#define _Message_PerfMeterMode_HeaderFile - -//! Specifies kind of report information to collect -enum Message_PerfMeterMode -{ - Message_PerfMeterMode_None, //!< no computation - Message_PerfMeterMode_UserTimeCPU, //!< the current CPU user time in seconds - Message_PerfMeterMode_SystemTimeInfo, //!< the current CPU system time in seconds - Message_PerfMeterMode_MemPrivate, //!< OSD_MemInfo::MemPrivate - Message_PerfMeterMode_MemVirtual, //!< OSD_MemInfo::MemVirtual - Message_PerfMeterMode_MemWorkingSet, //!< OSD_MemInfo::MemWorkingSet - Message_PerfMeterMode_MemWorkingSetPeak, //!< OSD_MemInfo::MemWorkingSetPeak - Message_PerfMeterMode_MemSwapUsage, //!< OSD_MemInfo::MemSwapUsage - Message_PerfMeterMode_MemSwapUsagePeak, //!< OSD_MemInfo::MemSwapUsagePeak - Message_PerfMeterMode_MemHeapUsage //!< OSD_MemInfo::MemHeapUsage -}; - -#endif // _Message_PerfMeterKind_HeaderFile diff --git a/src/Message/Message_Printer.cxx b/src/Message/Message_Printer.cxx index 8ed2b87e6a..cc1c09878d 100644 --- a/src/Message/Message_Printer.cxx +++ b/src/Message/Message_Printer.cxx @@ -15,6 +15,7 @@ #include +#include #include #include @@ -58,3 +59,37 @@ void Message_Printer::Send (const TCollection_AsciiString& theString, Send (TCollection_ExtendedString (theString), theGravity, theToOutEol); } } + +//======================================================================= +//function : Send +//purpose : +//======================================================================= + +void Message_Printer::Send (const Standard_SStream& theStream, + const Message_Gravity theGravity, + const Standard_Boolean theToOutEol) const +{ + if (theGravity >= myTraceLevel) + { + Send (TCollection_ExtendedString (theStream.str().c_str()), theGravity, theToOutEol); + } +} + +//======================================================================= +//function : Send +//purpose : +//======================================================================= +void Message_Printer::Send (const Handle(Standard_Transient)& theObject, + const Message_Gravity theGravity, + const Standard_Boolean theToOutEol) const +{ + if (theObject.IsNull()) + return; + + if (theGravity >= myTraceLevel) + { + TCollection_ExtendedString aString = TCollection_ExtendedString (theObject->DynamicType()->Name()) + + ": " + Standard_Dump::GetPointerInfo (theObject); + Send (aString, theGravity, theToOutEol); + } +} diff --git a/src/Message/Message_Printer.hxx b/src/Message/Message_Printer.hxx index e7e70ddfbd..ae877c7081 100644 --- a/src/Message/Message_Printer.hxx +++ b/src/Message/Message_Printer.hxx @@ -23,6 +23,8 @@ #include #include #include +#include + class TCollection_ExtendedString; class TCollection_AsciiString; @@ -62,6 +64,18 @@ public: //! Default implementation calls first method Send(). Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const; + //! Send a string message with specified trace level. + //! Stream is converted to string value. + //! 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 Standard_SStream& theStream, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const; + + //! Send a string message with specified trace level. + //! The object is converted to string in format: : . + //! 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_Boolean theToPutEol) const; + protected: //! Empty constructor with Message_Info trace level diff --git a/src/Message/Message_PrinterToReport.cxx b/src/Message/Message_PrinterToReport.cxx new file mode 100644 index 0000000000..99ce957882 --- /dev/null +++ b/src/Message/Message_PrinterToReport.cxx @@ -0,0 +1,137 @@ +// 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 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +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 : Clear +//purpose : +//======================================================================= +void Message_PrinterToReport::Clear() +{ + myKey.Clear(); +} + +//======================================================================= +//function : Send +//purpose : +//======================================================================= + +void Message_PrinterToReport::Send (const TCollection_ExtendedString& theString, + const Message_Gravity theGravity, + const Standard_Boolean putEndl) const +{ + TCollection_AsciiString aString (theString/*, myUseUtf8 ? Standard_Character(0) : '?'*/); + + Message_PrinterToReport* aThis = (Message_PrinterToReport*)this; // TODO! + if (putEndl) + { + if (myKey.IsEmpty()) + return; + + const Handle(Message_Report)& aReport = Report(); + if (!aReport->ActiveMetrics().IsEmpty()) + { + sendMetricAlert (aString, theGravity); + return; + } + Message_AlertExtended::AddAlert (aReport, new Message_Attribute (myKey), theGravity); + aThis->Clear(); + return; + } + aThis->myKey += aString; +} + +//======================================================================= +//function : Send +//purpose : +//======================================================================= + +void Message_PrinterToReport::Send (const Standard_SStream& theStream, + const Message_Gravity theGravity, + const Standard_Boolean /*putEndl*/) const +{ + const Handle(Message_Report)& aReport = Report(); + if (!aReport->ActiveMetrics().IsEmpty()) + { + sendMetricAlert (myKey, theGravity); + return; + } + Message_AlertExtended::AddAlert (aReport, new Message_AttributeStream (theStream, myKey), theGravity); + Message_PrinterToReport* aThis = (Message_PrinterToReport*)this; // TODO! + aThis->Clear(); + + return; +} + +//======================================================================= +//function : Send +//purpose : +//======================================================================= + +void Message_PrinterToReport::Send (const Handle(Standard_Transient)& theObject, + const Message_Gravity theGravity, + const Standard_Boolean /*putEndl*/) const +{ + const Handle(Message_Report)& aReport = Report(); + if (!aReport->ActiveMetrics().IsEmpty()) + { + sendMetricAlert (myKey, theGravity); + return; + } + + Message_AlertExtended::AddAlert (aReport, new Message_AttributeObject (theObject, myKey), theGravity); + Message_PrinterToReport* aThis = (Message_PrinterToReport*)this; // TODO! + aThis->Clear(); +} + +//======================================================================= +//function : sendMetricAlert +//purpose : +//======================================================================= + +void Message_PrinterToReport::sendMetricAlert (const TCollection_AsciiString theValue, + const Message_Gravity theGravity) const +{ + Message_AlertExtended::AddAlert (Report(), new Message_AttributeMeter (myKey), theGravity); + Message_PrinterToReport* aThis = (Message_PrinterToReport*)this; // TODO! + aThis->Clear(); +} diff --git a/src/Message/Message_PrinterToReport.hxx b/src/Message/Message_PrinterToReport.hxx new file mode 100644 index 0000000000..37d61ca04a --- /dev/null +++ b/src/Message/Message_PrinterToReport.hxx @@ -0,0 +1,84 @@ +// 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 +#include +#include +#include + +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. +//! 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. + Standard_EXPORT Message_PrinterToReport () {} + + ~Message_PrinterToReport() {} + + //! Returns the current or default report + Standard_EXPORT const Handle(Message_Report)& Report() const; + + //!< Returns the first sent value + TCollection_AsciiString Key() const { return myKey; } + + //! Clears current values + Standard_EXPORT void Clear(); + + //! Sets the printer report + //! @param theReport report for messages processing, if NULL, the default report is used + void SetReport (const Handle(Message_Report)& theReport); + + //! Appends a new alert into message report + Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, + const Message_Gravity theGravity, + const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE; + + //! Send a string message with specified trace level. + //! Stream is converted to string value. + //! 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 Standard_SStream& theStream, + const Message_Gravity theGravity, + const Standard_Boolean theToPutEol) const Standard_OVERRIDE; + + //! Send a string message with specified trace level. + //! The object is converted to string in format: : . + //! 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_Boolean theToPutEol) const Standard_OVERRIDE; +protected: + + //! Send an alert with metrics active in the current report + Standard_EXPORT void sendMetricAlert (const TCollection_AsciiString theValue, + const Message_Gravity theGravity) const; + +private: + Handle(Message_Report) myReport; //!< the report for sending alerts + TCollection_AsciiString myKey; //!< the sent string value +}; + +#endif // _Message_PrinterToReport_HeaderFile diff --git a/src/Message/Message_Report.cxx b/src/Message/Message_Report.cxx index fc57f328e3..f225f004e0 100644 --- a/src/Message/Message_Report.cxx +++ b/src/Message/Message_Report.cxx @@ -15,12 +15,12 @@ #include +#include #include #include #include #include -#include -#include +#include #include #include @@ -28,66 +28,55 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_Report,Standard_Transient) -static Handle(Message_Report) MyReport; - //======================================================================= //function : Message_Report //purpose : //======================================================================= Message_Report::Message_Report () -: myPerfMeterMode (Message_PerfMeterMode_None), myLimit (-1) +: myLimit (-1) { - SetActive (Standard_True); } //======================================================================= -//function : CurrentReport +//function : IsActiveInMessenger //purpose : //======================================================================= -Handle(Message_Report) Message_Report::CurrentReport(const Standard_Boolean theToCreate) +Standard_Boolean Message_Report::IsActiveInMessenger() const { - if (MyReport.IsNull() && theToCreate) - MyReport = new Message_Report(); - - return MyReport; + const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger(); + for (Message_SequenceOfPrinters::Iterator anIterator (aMessenger->Printers()); anIterator.More(); anIterator.Next()) + { + if (anIterator.Value()->IsKind(STANDARD_TYPE (Message_PrinterToReport)) && + Handle(Message_PrinterToReport)::DownCast (anIterator.Value())->Report() == this) + return Standard_True; + } + return Standard_False; } //======================================================================= -//function : AddAlert +//function : AddLevel //purpose : //======================================================================= - -void Message_Report::AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert) +void Message_Report::AddLevel (Message_Level* theLevel) { - if (!IsActive (theGravity)) - return; - - 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); + myAlertLevels.Append (theLevel); +} - // 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()) +//======================================================================= +//function : RemoveLevel +//purpose : +//======================================================================= +void Message_Report::RemoveLevel (Message_Level* theLevel) +{ + for (int aLevelIndex = myAlertLevels.Size(); aLevelIndex >= 1; aLevelIndex--) { - // 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; - } - } + Message_Level* aLevel = myAlertLevels.Value (aLevelIndex); + myAlertLevels.Remove (aLevelIndex); - // if not merged, just add to the list - aList.Append (theAlert); - - if (!myCallBack.IsNull()) - myCallBack->Update (theAlert); + if (aLevel == theLevel) + return; + } } //======================================================================= @@ -95,216 +84,84 @@ void Message_Report::AddAlert (Message_Gravity theGravity, const Handle(Message_ //purpose : //======================================================================= -void Message_Report::AddAlert (const Message_Gravity theGravity, const Handle(Message_Alert)& theAlert, - Message_PerfMeter* thePerfMeter, const Handle(Message_Alert)& theParentAlert) +void Message_Report::AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert) { - if (!IsActive (theGravity)) - return; - - 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 - Handle(Message_Alert) aParentAlert = theParentAlert; - if (aParentAlert.IsNull() && thePerfMeter) - aParentAlert = thePerfMeter->GetAlert(); - if (aParentAlert.IsNull()) - aParentAlert = getLastAlertInPerfMeter(theGravity); - - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(aParentAlert); - Handle(Message_CompositeAlerts) aCompositeAlert = !anExtendedAlert.IsNull() ? anExtendedAlert->GetCompositeAlerts (Standard_True) - : Handle(Message_CompositeAlerts)(); - Message_ListOfAlert& aList = !aCompositeAlert.IsNull() ? aCompositeAlert->GetAlerts (theGravity) : 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 and same name - 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)) + return; + + // remove alerts under the report only + const Message_ListOfAlert& anAlerts = aCompositeAlert->GetAlerts (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); - // remove alerts under the report only - if (theParentAlert.IsNull() && aParentAlert.IsNull() && myLimit > 0 && aList.Extent() > myLimit) - aList.RemoveFirst(); - - if (thePerfMeter) - thePerfMeter->AddAlert (theAlert, PerfMeterMode()); - - if (!myCallBack.IsNull()) - myCallBack->Update(theAlert); -} - -//======================================================================= -//function : GetAlerts -//purpose : -//======================================================================= + // if there are some levels of alerts + // iterate by already recorded alerts and try to merge new one with one of those + Message_Level* aLevel = myAlertLevels.Last(); + if (!aLevel) + return; -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]; -} + // alert is placed below the level + if (!aLevel->RootAlert().IsNull()) + { + aLevel->AddAlert (theGravity, theAlert); + return; + } -//======================================================================= -//function : CumulativeMetric -//purpose : -//======================================================================= + Handle(Message_AlertExtended) anAlert = Handle(Message_AlertExtended)::DownCast (theAlert); + if (anAlert.IsNull()) + return; + // place new alert as a root of the level, after place the level alert below the report or + // below the previous level + aLevel->SetRootAlert (anAlert); -Standard_Real Message_Report::CumulativeMetric (const Message_Gravity theGravity) const -{ - switch (myPerfMeterMode) + if (myAlertLevels.Size() == 1) + compositeAlerts (Standard_True)->AddAlert (theGravity, theAlert); + else { - case Message_PerfMeterMode_None: return 0.0; - case Message_PerfMeterMode_UserTimeCPU: - case Message_PerfMeterMode_SystemTimeInfo: - { - Standard_Real aStartTime = Message_AlertExtended::GetUndefinedMetric(); - Standard_Boolean isFound = Standard_False; - for (Message_ListOfAlert::Iterator anAlertsIt (GetAlerts (theGravity)); anAlertsIt.More(); anAlertsIt.Next()) - { - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(anAlertsIt.Value()); - if (anExtendedAlert.IsNull() && anExtendedAlert->IsMetricValid()) - { - aStartTime = anExtendedAlert->MetricStart(); - isFound = Standard_True; - break; - } - } - if (!isFound) - return 0.0; - - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(getLastAlert (theGravity)); - if (anExtendedAlert.IsNull() || !anExtendedAlert->IsMetricValid()) - return 0.0; - - return anExtendedAlert->MetricStop() - aStartTime; - } - case Message_PerfMeterMode_MemPrivate: - case Message_PerfMeterMode_MemVirtual: - case Message_PerfMeterMode_MemWorkingSet: - { - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(getLastAlert (theGravity)); - if (!anExtendedAlert.IsNull()) - return anExtendedAlert->MetricStop(); - } + Message_Level* aPrevLevel = myAlertLevels.Value (myAlertLevels.Size() - 1); // previous level + aPrevLevel->AddLevelAlert (theGravity, theAlert); } - return 0.0; } //======================================================================= -//function : getLastAlert +//function : GetAlerts //purpose : //======================================================================= -Handle(Message_Alert) Message_Report::getLastAlert (const Message_Gravity theGravity) const +const Message_ListOfAlert& Message_Report::GetAlerts (Message_Gravity theGravity) const { - if (!IsActive (theGravity)) - return Handle(Message_Alert)(); - - const Message_ListOfAlert& anAlerts = GetAlerts (theGravity); - if (anAlerts.IsEmpty()) - return Handle(Message_Alert)(); - - Handle(Message_Alert) aLastAlert = anAlerts.Last(); - - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (aLastAlert); - if (anExtendedAlert.IsNull()) - return aLastAlert; - Handle(Message_CompositeAlerts) aCompositeAlert = anExtendedAlert->GetCompositeAlerts (Standard_True); - if (aCompositeAlert.IsNull()) - return aLastAlert; - - while (!aCompositeAlert.IsNull() && !aCompositeAlert->GetAlerts (theGravity).IsEmpty()) - { - Handle(Message_Alert) anAlert = aCompositeAlert->GetAlerts (theGravity).Last(); - - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (anAlert); - if (anExtendedAlert.IsNull()) - { - aLastAlert = anAlert; - break; - } - - aLastAlert = anExtendedAlert; - aCompositeAlert = anExtendedAlert->GetCompositeAlerts(); - } - - // if alert has perf meter, use as the last alert, an alert of the perf meter - anExtendedAlert = Handle(Message_AlertExtended)::DownCast (aLastAlert); - if (anExtendedAlert.IsNull()) - return aLastAlert; + static const Message_ListOfAlert anEmptyList; + if (myCompositAlerts.IsNull()) + return anEmptyList; - return aLastAlert; + return myCompositAlerts->GetAlerts (theGravity); } //======================================================================= -//function : getLastAlertInPerfMeter +//function : SetActiveMetric //purpose : //======================================================================= -Handle(Message_Alert) Message_Report::getLastAlertInPerfMeter (const Message_Gravity theGravity) const +void Message_Report::SetActiveMetric (const Message_MetricType theMetricType, + const Standard_Boolean theActivate) { - if (!IsActive (theGravity)) - return Handle(Message_Alert)(); - - const Message_ListOfAlert& anAlerts = GetAlerts (theGravity); - if (anAlerts.IsEmpty()) - return Handle(Message_Alert)(); - - Handle(Message_Alert) aLastAlert = anAlerts.Last(); - - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (aLastAlert); - if (anExtendedAlert.IsNull()) - return aLastAlert; - Handle(Message_CompositeAlerts) aCompositeAlert = anExtendedAlert->GetCompositeAlerts (Standard_True); - if (aCompositeAlert.IsNull()) - return aLastAlert; - - Standard_Boolean aHasPerfMeter = anExtendedAlert->GetPerfMeter() != NULL; - if (!aHasPerfMeter) // the alert has finished and is not the last alert anymore - return Handle(Message_Alert)(); - - while (!aCompositeAlert.IsNull() && !aCompositeAlert->GetAlerts (theGravity).IsEmpty()) - { - Handle(Message_Alert) anAlert = aCompositeAlert->GetAlerts (theGravity).Last(); - - Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (anAlert); - if (anExtendedAlert.IsNull()) - { - if (!aHasPerfMeter) // if there is a perf meter, use alert of it - aLastAlert = anAlert; - break; - } - - if (!aHasPerfMeter) - aHasPerfMeter = anExtendedAlert->GetPerfMeter() != NULL; - else if (!anExtendedAlert->GetPerfMeter()) - break; // last alert is the previous alert where perf meter is not NULL - - aLastAlert = anExtendedAlert; - aCompositeAlert = anExtendedAlert->GetCompositeAlerts(); - } - - // if alert has perf meter, use as the last alert, an alert of the perf meter - anExtendedAlert = Handle(Message_AlertExtended)::DownCast (aLastAlert); - if (anExtendedAlert.IsNull()) - return aLastAlert; - //if (anExtendedAlert->GetPerfMeter()) - // aLastAlert = anExtendedAlert->GetPerfMeter()->GetAlert(); + if (theActivate == myActiveMetrics.Contains (theMetricType)) + return; - return aLastAlert; + if (theActivate) + myActiveMetrics.Add (theMetricType); + else + myActiveMetrics.Remove (theMetricType); } //======================================================================= @@ -329,14 +186,17 @@ Standard_Boolean Message_Report::HasAlert (const Handle(Standard_Type)& theType) 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 (anIt.Value()->IsInstance(theType)) - return Standard_True; - } - return Standard_False; + //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; + //} + if (compositeAlerts().IsNull()) + return Standard_False; + + return compositeAlerts()->HasAlert (theType, theGravity); } //======================================================================= @@ -344,12 +204,13 @@ Standard_Boolean Message_Report::HasAlert (const Handle(Standard_Type)& theType, //purpose : //======================================================================= -void Message_Report::Clear () +void Message_Report::Clear() { - for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i) - { - myAlerts[i].Clear(); - } + if (compositeAlerts().IsNull()) + return; + + compositeAlerts()->Clear(); + myAlertLevels.Clear(); } //======================================================================= @@ -359,9 +220,11 @@ void Message_Report::Clear () 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(); } //======================================================================= @@ -371,20 +234,26 @@ void Message_Report::Clear (Message_Gravity theGravity) 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(); + + //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(); + // } + // } + //} } //======================================================================= @@ -407,12 +276,13 @@ void Message_Report::Dump (Standard_OStream& theOS) 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; + const Message_ListOfAlert& anAlerts = compositeAlerts()->GetAlerts (theGravity); // report each type of warning only once NCollection_Map aPassedAlerts; - for (Message_ListOfAlert::Iterator anIt (myAlerts[theGravity]); anIt.More(); anIt.Next()) + for (Message_ListOfAlert::Iterator anIt (anAlerts); anIt.More(); anIt.Next()) { if (aPassedAlerts.Add (anIt.Value()->DynamicType())) { @@ -442,12 +312,15 @@ void Message_Report::SendMessages (const Handle(Message_Messenger)& theMessenger 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; + const Message_ListOfAlert& anAlerts = compositeAlerts()->GetAlerts (theGravity); + //Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]), + // "Requesting alerts for gravity not in valid range", ); // report each type of warning only once NCollection_Map aPassedAlerts; - for (Message_ListOfAlert::Iterator anIt (myAlerts[theGravity]); anIt.More(); anIt.Next()) + for (Message_ListOfAlert::Iterator anIt (anAlerts); anIt.More(); anIt.Next()) { if (aPassedAlerts.Add (anIt.Value()->DynamicType())) { @@ -484,48 +357,13 @@ void Message_Report::Merge (const Handle(Message_Report)& theOther, Message_Grav } //======================================================================= -//function : SetActive -//purpose : -//======================================================================= - -void Message_Report::SetActive (const Standard_Boolean theActive, const Standard_Integer theGravity) -{ - if (theGravity < 0) - { - for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity) - SetActive (theActive, iGravity); - return; - } - - Standard_ASSERT_RETURN (theGravity >= 0 && size_t (theGravity) < sizeof (myAlerts) / sizeof (myAlerts[0]), - "Set active report with gravity not in valid range", ); - myIsActive[theGravity] = theActive; -} - -//======================================================================= -//function : DumpJson +//function : ñompositeAlerts //purpose : //======================================================================= -void Message_Report::DumpJson (Standard_OStream& theOStream, const Standard_Integer) const +Handle (Message_CompositeAlerts) Message_Report::compositeAlerts (const Standard_Boolean isCreate) { - OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPerfMeterMode); - OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myLimit); -} - -//======================================================================= -//function : InitJson -//purpose : -//======================================================================= -Standard_Boolean Message_Report::InitJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos) -{ - Standard_Integer aPos = theStreamPos; - - Standard_Real PerfMeterMode; - OCCT_INIT_FIELD_VALUE_INTEGER (theSStream, aPos, PerfMeterMode); - myPerfMeterMode = (Message_PerfMeterMode)((Standard_Integer)PerfMeterMode); - - OCCT_INIT_FIELD_VALUE_INTEGER (theSStream, aPos, myLimit); + if (myCompositAlerts.IsNull() && isCreate) + myCompositAlerts = new Message_CompositeAlerts(); - theStreamPos = aPos; - return Standard_True; + return myCompositAlerts; } diff --git a/src/Message/Message_Report.hxx b/src/Message/Message_Report.hxx index 9fc0708cf3..81d20febc5 100644 --- a/src/Message/Message_Report.hxx +++ b/src/Message/Message_Report.hxx @@ -17,14 +17,16 @@ #define _Message_Report_HeaderFile #include +#include #include -#include +#include +#include +#include #include +class Message_CompositeAlerts; class Message_Messenger; -class Message_PerfMeter; class Message_Report; -class Message_ReportCallBack; DEFINE_STANDARD_HANDLE(Message_Report, Standard_Transient) @@ -57,24 +59,19 @@ public: //! Empty constructor Standard_EXPORT Message_Report (); - //! 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 Handle(Message_Report) CurrentReport (const Standard_Boolean theToCreate = Standard_False); + //! Returns true if report printer is registered in the messenger + Standard_EXPORT Standard_Boolean IsActiveInMessenger() const; + + //! Add new level of alerts + Standard_EXPORT void AddLevel (Message_Level* theLevel); + + //! Remove level of alerts + Standard_EXPORT void RemoveLevel (Message_Level* theLevel); //! Add alert with specified gravity. //! This method is thread-safe, i.e. alerts can be added from parallel threads safely. Standard_EXPORT void AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert); - //! Add alert with specified gravity. The alert is a sub-alert of report or another alert - //! The parent alert is the parameter alert or the last alert if found else report. - //! \param theGravity a message gravity - //! \param theAlert a new alert to be added - //! \param thePerfMeter performance meter calculates the alert spent time and participate in searching the last alert if needed - //! \param theParentAlert if not NULL specifies parent alert where the alert should be placed, if the parent is an extednded alert - Standard_EXPORT void AddAlert (const Message_Gravity theGravity, const Handle(Message_Alert)& theAlert, - Message_PerfMeter* thePerfMeter, const Handle(Message_Alert)& theParentAlert = Handle(Message_Alert)()); - //! Returns list of collected alerts with specified gravity Standard_EXPORT const Message_ListOfAlert& GetAlerts (Message_Gravity theGravity) const; @@ -111,24 +108,15 @@ public: //! Merges alerts with specified gravity from theOther report into this Standard_EXPORT void Merge (const Handle(Message_Report)& theOther, Message_Gravity theGravity); - //! Returns a state whether the report is active - //! \return the state - Standard_Boolean IsActive (const Message_Gravity theGravity) const { return myIsActive[theGravity]; } + //! 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); - //! Starts a timer to compute time between messages. If a timer has already been started, it will be stopped - //! \param theActive new state of report active - //! \param theGravity gravity type, if '-1', apply value for all gravity kinds - Standard_EXPORT void SetActive (const Standard_Boolean theActive, const Standard_Integer theGravity = -1); + //! Returns computed metrics when alerts are performed + const NCollection_Map& ActiveMetrics() const { return myActiveMetrics; } - //! Sets a perf meter mode - //! \param theMode new mode - Standard_EXPORT void SetPerfMeterMode (const Message_PerfMeterMode theMode) - { myPerfMeterMode = theMode; } - - //! Returns mode of perf meter - //! \return the state - Standard_EXPORT Message_PerfMeterMode PerfMeterMode() const - { return myPerfMeterMode; } + //! Removes all activated metrics + void ClearMetrics() { myActiveMetrics.Clear(); } //! Returns maximum number of collecting alerts. If the limit is achieved, //! adding of a new alert after removing the first cached alert. @@ -139,48 +127,29 @@ public: //! \return theLimit limit value Standard_EXPORT void SetLimit(const Standard_Integer theLimit) { myLimit = theLimit; } - //! Returns the report cumulative metric. It includes time/mem of sub alerts depending on PerfMeter mode - //! @return value - Standard_EXPORT Standard_Real CumulativeMetric (const Message_Gravity theGravity) const; - - //! Sets a listener for the report events - void SetCallBack(const Handle(Message_ReportCallBack)& theCallBack) { myCallBack = theCallBack; } - - //! Returns listener of the reports events - const Handle(Message_ReportCallBack)& GetCallBack() const { return myCallBack; } - //! Dumps the content of me into the stream Standard_EXPORT void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const; - //! Inits the content of me into the stream - Standard_EXPORT Standard_Boolean InitJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); - // OCCT RTTI DEFINE_STANDARD_RTTIEXT(Message_Report,Standard_Transient) protected: - //! Returns last alert in list of report alerts or last alert in hierarchical tree of alerts provided by - //! the last alert - //! \parm theGravity a message gravity - Standard_EXPORT Handle(Message_Alert) getLastAlert (const Message_Gravity theGravity) const; - - //! Returns last alert in list of report alerts or last alert in hierarchical tree of alerts provided by - //! the last alert - //! \parm theGravity a message gravity - Standard_EXPORT Handle(Message_Alert) getLastAlertInPerfMeter (const Message_Gravity theGravity) const; + //! 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 isCreate = Standard_False); 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; - Standard_Boolean myIsActive[Message_Fail + 1]; - Message_PerfMeterMode myPerfMeterMode; //! If true, each alert will store the mode information Standard_Integer myLimit; //! Maximum number of collected alerts - Handle(Message_ReportCallBack) myCallBack; //! signal about performed modifications + NCollection_Sequence myAlertLevels; //! container of alerts, new alerts are added below the latest level + NCollection_Map myActiveMetrics; //! metrics to compute on alerts }; #endif // _Message_Report_HeaderFile diff --git a/src/Message/Message_ReportCallBack.cxx b/src/Message/Message_ReportCallBack.cxx deleted file mode 100644 index 5f0ce64327..0000000000 --- a/src/Message/Message_ReportCallBack.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// Created on: 2017-12-01 -// 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 "Message_ReportCallBack.hxx" - -IMPLEMENT_STANDARD_RTTIEXT(Message_ReportCallBack, Standard_Transient) - -Message_ReportCallBack::Message_ReportCallBack () -{ -} diff --git a/src/Message/Message_ReportCallBack.hxx b/src/Message/Message_ReportCallBack.hxx deleted file mode 100644 index 884b64dcaf..0000000000 --- a/src/Message/Message_ReportCallBack.hxx +++ /dev/null @@ -1,44 +0,0 @@ -// Created on: 2017-12-01 -// 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 _Message_ReportCallBack_HeaderFile -#define _Message_ReportCallBack_HeaderFile - -#include -#include -#include - -class Message_Alert; -class Message_ReportCallBack; -DEFINE_STANDARD_HANDLE(Message_ReportCallBack, Standard_Transient) - -//! Interface to have possibility of processing message report events. -class Message_ReportCallBack : public Standard_Transient -{ -public: - - //! Empty constructor - Standard_EXPORT Message_ReportCallBack (); - ~Message_ReportCallBack () {} - - //! Interface to be implemented in the child to process the message report event - //! \param theAlert created or modified message alert - virtual void Update(const Handle(Message_Alert)& theAlert) = 0; - - //! OCCT RTTI - DEFINE_STANDARD_RTTIEXT(Message_ReportCallBack, Standard_Transient) -}; - -#endif // _Message_ReportCallBack_HeaderFile diff --git a/src/OSD/OSD_MemInfo.cxx b/src/OSD/OSD_MemInfo.cxx index 6651c8f2b1..8723021376 100644 --- a/src/OSD/OSD_MemInfo.cxx +++ b/src/OSD/OSD_MemInfo.cxx @@ -190,12 +190,12 @@ void OSD_MemInfo::Update() // function : Update // purpose : // ======================================================================= -void OSD_MemInfo::Update (const OSD_MemInfo::Counter theCounter) +void OSD_MemInfo::Update (const NCollection_Map theCounters) { #ifndef OCCT_UWP #if defined(_WIN32) - if (theCounter == MemVirtual) + if (theCounters.Contains (MemVirtual)) { #if (_WIN32_WINNT >= 0x0500) MEMORYSTATUSEX aStatEx; @@ -212,11 +212,11 @@ void OSD_MemInfo::Update (const OSD_MemInfo::Counter theCounter) return; } - if (theCounter == MemPrivate || - theCounter == MemWorkingSet || - theCounter == MemWorkingSetPeak || - theCounter == MemSwapUsage || - theCounter == MemSwapUsagePeak) + if (theCounters.Contains (MemPrivate) || + theCounters.Contains (MemWorkingSet) || + theCounters.Contains (MemWorkingSetPeak) || + theCounters.Contains (MemSwapUsage) || + theCounters.Contains (MemSwapUsagePeak)) { // use Psapi library HANDLE aProcess = GetCurrentProcess(); @@ -238,7 +238,7 @@ void OSD_MemInfo::Update (const OSD_MemInfo::Counter theCounter) return; } - if (theCounter == MemHeapUsage) + if (theCounters.Contains (MemHeapUsage)) { _HEAPINFO hinfo; int heapstatus; diff --git a/src/OSD/OSD_MemInfo.hxx b/src/OSD/OSD_MemInfo.hxx index 71c0c9a1ea..84d4fda7ec 100644 --- a/src/OSD/OSD_MemInfo.hxx +++ b/src/OSD/OSD_MemInfo.hxx @@ -16,6 +16,7 @@ #ifndef _OSD_MemInfo_H__ #define _OSD_MemInfo_H__ +#include #include //! This class provide information about memory utilized by current process. @@ -75,7 +76,7 @@ public: Standard_EXPORT void Update(); //! Update counter of specified counter - Standard_EXPORT void Update (const OSD_MemInfo::Counter theCounter); + Standard_EXPORT void Update (const NCollection_Map theCounters); //! Return the string representation for all available counter. Standard_EXPORT TCollection_AsciiString ToString() const; diff --git a/src/OpenGl/OpenGl_CappingAlgo.cxx b/src/OpenGl/OpenGl_CappingAlgo.cxx index 377f870235..a57be8b7d1 100755 --- a/src/OpenGl/OpenGl_CappingAlgo.cxx +++ b/src/OpenGl/OpenGl_CappingAlgo.cxx @@ -25,6 +25,12 @@ #include #include +//#define DEBUG_INFO +#ifdef DEBUG_INFO +#include +#include +#endif // DEBUG_INFO + namespace { static const OpenGl_CappingPlaneResource* THE_DEFAULT_ASPECT = new OpenGl_CappingPlaneResource (new Graphic3d_AspectFillCapping); @@ -341,13 +347,13 @@ namespace // function : RenderCapping // purpose : // ======================================================================= -#include -#include void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorkspace, const OpenGl_Structure& theStructure) { - Message_PerfMeter aPerfMeter; - MESSAGE_INFO ("RenderCapping", "", &aPerfMeter, NULL); +#ifdef DEBUG_INFO + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO ("RenderCapping"); +#endif const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); if (!aContext->Clipping().IsCappingOn()) @@ -394,8 +400,9 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks Standard_SStream aStream; aClipChain->DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "ClipChain", "", &aPerfMeter, NULL); - +#ifdef DEBUG_INFO + MESSAGE_INFO_STREAM(aStream, "ClipChain"); +#endif Standard_Integer aSubPlaneIndex = 1; for (const Graphic3d_ClipPlane* aSubPlaneIter = aClipChain.get(); aSubPlaneIter != NULL; aSubPlaneIter = aSubPlaneIter->ChainNextPlane().get(), ++aSubPlaneIndex) { diff --git a/src/OpenGl/OpenGl_Group.cxx b/src/OpenGl/OpenGl_Group.cxx index 8c6f0ff4d0..882eb66980 100644 --- a/src/OpenGl/OpenGl_Group.cxx +++ b/src/OpenGl/OpenGl_Group.cxx @@ -31,7 +31,7 @@ //#define DEBUG_INFO #ifdef DEBUG_INFO #include -#include +#include #endif // DEBUG_INFO IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Group,Graphic3d_Group) @@ -306,16 +306,16 @@ void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const { #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO_OBJECT(this, "OpenGl_Group::Render") + Standard_SStream aGroupStream; DumpJson (aGroupStream); - MESSAGE_INFO_OBJECT(this, aGroupStream, "OpenGl_Group::Render", "", &aPerfMeter, NULL) - Handle(Message_Alert) aParentAlert = OCCT_Message_Alert; + MESSAGE_INFO_STREAM(aGroupStream, "group") Standard_SStream aContextStream; theWorkspace->GetGlContext()->DumpJson (aContextStream); - MESSAGE_INFO_OBJECT(this, aContextStream, "Context", "", &aPerfMeter, aParentAlert) + MESSAGE_INFO_STREAM(aContextStream, "context") #endif // Setup aspects diff --git a/src/OpenGl/OpenGl_LayerList.cxx b/src/OpenGl/OpenGl_LayerList.cxx index 3b8d2c3021..ca1084f891 100644 --- a/src/OpenGl/OpenGl_LayerList.cxx +++ b/src/OpenGl/OpenGl_LayerList.cxx @@ -29,7 +29,7 @@ //#define DEBUG_INFO #ifdef DEBUG_INFO #include -#include +#include #endif namespace @@ -587,8 +587,8 @@ void OpenGl_LayerList::renderLayer (const Handle(OpenGl_Workspace)& theWorkspace const Graphic3d_Layer& theLayer) const { #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_LayerList::renderLayer", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_LayerList::renderLayer") #endif const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); @@ -900,8 +900,8 @@ void OpenGl_LayerList::renderTransparent (const Handle(OpenGl_Workspace)& theW } #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_LayerList::renderTransparent", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_LayerList::renderTransparent") #endif const Handle(OpenGl_Context) aCtx = theWorkspace->GetGlContext(); diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index b71dd848f3..e4941d9bd7 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -32,7 +32,7 @@ //#define DEBUG_INFO #ifdef DEBUG_INFO #include -#include +#include #endif // DEBUG_INFO namespace @@ -776,10 +776,12 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace } #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; + MESSAGE_ADD_LEVEL_SENTRY + + MESSAGE_INFO_OBJECT(this, "OpenGl_PrimitiveArray::Render") Standard_SStream aGroupStream; DumpJson (aGroupStream); - MESSAGE_INFO_STREAM(aGroupStream, "OpenGl_PrimitiveArray::Render", Standard_Dump::GetPointerInfo(this), &aPerfMeter, NULL) + MESSAGE_INFO_STREAM(aGroupStream, "parameters") #endif const OpenGl_Aspects* anAspectFace = theWorkspace->ApplyAspects(); diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index a552a33ff2..1fa6d8d861 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -28,7 +28,7 @@ //#define DEBUG_INFO #ifdef DEBUG_INFO #include -#include +#include #endif IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure) @@ -390,8 +390,8 @@ void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorksp bool& theHasClosed) const { #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_Structure::renderGeometry", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_Structure::renderGeometry") #endif if (myInstancedStructure != NULL) diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 2fe1563ea0..06b57bcffb 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -33,7 +33,7 @@ //#define DEBUG_INFO #ifdef DEBUG_INFO #include -#include +#include #endif namespace @@ -286,23 +286,22 @@ void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx, void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const { #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; + MESSAGE_ADD_LEVEL_SENTRY Standard_SStream aGroupStream; DumpJson (aGroupStream); - MESSAGE_INFO_STREAM (aGroupStream, "OpenGl_Text::Render", "", &aPerfMeter, NULL) - Handle(Message_Alert) aParentAlert = OCCT_Message_Alert; + MESSAGE_INFO_STREAM (aGroupStream, "OpenGl_Text::Render") #endif const OpenGl_Aspects* aTextAspect = theWorkspace->ApplyAspects(); #ifdef DEBUG_INFO aGroupStream.str(""); aTextAspect->DumpJson (aGroupStream); - MESSAGE_INFO_STREAM (aGroupStream, "aTextAspect", "", &aPerfMeter, aParentAlert) + MESSAGE_INFO_STREAM (aGroupStream, "aTextAspect") aGroupStream.str(""); OpenGl_Context::DumpJsonOpenGl (aGroupStream); - MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters1", "", &aPerfMeter, aParentAlert) + MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters1") #endif const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); @@ -344,7 +343,7 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const #ifdef DEBUG_INFO aGroupStream.str(""); OpenGl_Context::DumpJsonOpenGl (aGroupStream); - MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters2", "", &aPerfMeter, aParentAlert) + MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters2") #endif } @@ -645,11 +644,11 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, } #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; + MESSAGE_ADD_LEVEL_SENTRY Standard_SStream aGroupStream; OpenGl_Context::DumpJsonOpenGl (aGroupStream); - MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters3", "", &aPerfMeter, NULL) + MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters3") #endif // Note that using difference resolution in different Views in same Viewer @@ -823,7 +822,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, #ifdef DEBUG_INFO aGroupStream.str(""); OpenGl_Context::DumpJsonOpenGl (aGroupStream); - MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters4", "", &aPerfMeter, NULL) + MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters4") #endif // main draw call @@ -840,7 +839,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, #ifdef DEBUG_INFO aGroupStream.str(""); OpenGl_Context::DumpJsonOpenGl (aGroupStream); - MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters5", "", &aPerfMeter, NULL) + MESSAGE_INFO_STREAM (aGroupStream, "openGl_parameters5") #endif #if !defined(GL_ES_VERSION_2_0) diff --git a/src/OpenGl/OpenGl_View_Redraw.cxx b/src/OpenGl/OpenGl_View_Redraw.cxx index 1fd9aab95a..0d5444e215 100644 --- a/src/OpenGl/OpenGl_View_Redraw.cxx +++ b/src/OpenGl/OpenGl_View_Redraw.cxx @@ -42,7 +42,7 @@ //#define DEBUG_INFO #ifdef DEBUG_INFO #include -#include +#include #endif namespace @@ -182,8 +182,8 @@ void OpenGl_View::Redraw() } #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_View::Redraw", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_View::Redraw") #endif myWindow->SetSwapInterval(); @@ -626,8 +626,8 @@ void OpenGl_View::RedrawImmediate() } #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_View::RedrawImmediate", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_View::RedrawImmediate") #endif const Graphic3d_StereoMode aStereoMode = myRenderParams.StereoMode; @@ -789,8 +789,8 @@ void OpenGl_View::redraw (const Graphic3d_Camera::Projection theProjection, { #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_View::redraw", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_View::redraw") #endif Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); @@ -840,8 +840,8 @@ bool OpenGl_View::redrawImmediate (const Graphic3d_Camera::Projection theProject const Standard_Boolean theIsPartialUpdate) { #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_View::redrawImmediate", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_View::redrawImmediate") #endif Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); @@ -921,8 +921,8 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection, // ================================== #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_View::render", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_View::render") #endif const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext(); @@ -1136,8 +1136,8 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection, return; #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_View::renderStructs", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_View::renderStructs") #endif Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); @@ -1265,8 +1265,8 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection, { #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; - MESSAGE_INFO("OpenGl_View::renderScene", "", &aPerfMeter, NULL) + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO("OpenGl_View::renderScene") #endif const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext(); diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index a9032de1f2..6758ce3b4c 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -36,7 +36,7 @@ //#define DEBUG_INFO #ifdef DEBUG_INFO #include -#include +#include #endif // DEBUG_INFO IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient) @@ -408,11 +408,12 @@ Standard_Boolean OpenGl_Workspace::BufferDump (const Handle(OpenGl_FrameBuffer)& bool OpenGl_Workspace::ShouldRender (const OpenGl_Element* theElement) { #ifdef DEBUG_INFO - Message_PerfMeter aPerfMeter; + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO_OBJECT(this, "Workspace") Standard_SStream aWorkspaceStream; DumpJson (aWorkspaceStream); - MESSAGE_INFO_OBJECT(this, aWorkspaceStream, "Workspace", "", &aPerfMeter, NULL) + MESSAGE_INFO_STREAM(aWorkspaceStream, "parameters") #endif // render only non-raytracable elements when RayTracing is enabled diff --git a/src/PrsMgr/PrsMgr_PresentableObject.cxx b/src/PrsMgr/PrsMgr_PresentableObject.cxx index 95eb535d8a..e2bef68142 100644 --- a/src/PrsMgr/PrsMgr_PresentableObject.cxx +++ b/src/PrsMgr/PrsMgr_PresentableObject.cxx @@ -340,6 +340,9 @@ void PrsMgr_PresentableObject::recomputeComputed() const //======================================================================= void PrsMgr_PresentableObject::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { + if (myTransformPersistence == theTrsfPers) + return; + myTransformPersistence = theTrsfPers; for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) { diff --git a/src/STEPControl/STEPControl_ActorRead.cxx b/src/STEPControl/STEPControl_ActorRead.cxx index 37463e7e1d..2ef79f9fba 100644 --- a/src/STEPControl/STEPControl_ActorRead.cxx +++ b/src/STEPControl/STEPControl_ActorRead.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -96,6 +97,7 @@ #include #include #include +#include #include #include #include @@ -467,6 +469,10 @@ static void getSDR(const Handle(StepRepr_ProductDefinitionShape)& PDS, { Handle(Message_Messenger) sout = TP->Messenger(); +#ifdef TRANSLOG + //if (TP->TraceLevel() > 1) + MESSAGE_ADD_LEVEL_SENTRY +#endif Handle(TransferBRep_ShapeBinder) shbinder; TopoDS_Compound Cund; @@ -550,6 +556,8 @@ static void getSDR(const Handle(StepRepr_ProductDefinitionShape)& PDS, TopoDS_Shape theResult = TransferBRep::ShapeResult (binder); if (!theResult.IsNull()) { + if (TP->TraceLevel() > 3) + sout<<"TransferBRep::ShapeResult"< -#include +#include IMPLEMENT_STANDARD_RTTIEXT(TopoDS_AlertAttribute, Message_Attribute) @@ -23,15 +23,34 @@ IMPLEMENT_STANDARD_RTTIEXT(TopoDS_AlertAttribute, Message_Attribute) //function : TopoDS_AlertAttribute //purpose : //======================================================================= - - TopoDS_AlertAttribute::TopoDS_AlertAttribute (const TopoDS_Shape& theShape, - const TCollection_AsciiString& theName, - const TCollection_AsciiString& theDescription) -: Message_AttributeStream (Standard_SStream(), theName, theDescription), myShape (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->Key()), + theMessenger->OuputGravity()); + aPrinterToReport->Clear(); + } +} diff --git a/src/TopoDS/TopoDS_AlertAttribute.hxx b/src/TopoDS/TopoDS_AlertAttribute.hxx index ea347944e7..49f1313816 100644 --- a/src/TopoDS/TopoDS_AlertAttribute.hxx +++ b/src/TopoDS/TopoDS_AlertAttribute.hxx @@ -17,20 +17,30 @@ #define _TopoDS_AlertAttribute_HeaderFile #include +#include +#include +#include +#include + #include +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(), - const TCollection_AsciiString& theDescription = TCollection_AsciiString()); + 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) @@ -38,14 +48,21 @@ private: TopoDS_Shape myShape; }; -#define MESSAGE_INFO_SHAPE(Shape, Name, Description, PerfMeter, ParentAlert) \ +#define MESSAGE_INFO_SHAPE(Shape, Name) \ { \ - if (!Message_Report::CurrentReport().IsNull() && \ - Message_Report::CurrentReport()->IsActive (Message_Info)) \ + if (!Message::DefaultReport().IsNull()) \ { \ - OCCT_Message_Alert = Message_AlertExtended::AddAlert (Message_Report::CurrentReport(), \ - new TopoDS_AlertAttribute (Shape, Name, Description), PerfMeter, ParentAlert); \ + 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; +} + #endif // _TopoDS_AlertAttribute_HeaderFile diff --git a/src/Transfer/Transfer_TransferProcess.gxx b/src/Transfer/Transfer_TransferProcess.gxx index b42e1c4aa4..d979699e1c 100644 --- a/src/Transfer/Transfer_TransferProcess.gxx +++ b/src/Transfer/Transfer_TransferProcess.gxx @@ -1086,6 +1086,8 @@ Handle(Transfer_Binder) Transfer_TransferProcess::Transferring(const TheStart& s thelevel = oldlev; } catch (Standard_Failure const& anException) { + Message_Gravity aPrevGravity = themessenger->OuputGravity(); + themessenger->SetOuputGravity (Message_Fail); if (binder.IsNull()) { themessenger << " *** Exception Raised with no Result" << Message_EndLine; binder = new Transfer_VoidBinder; @@ -1097,6 +1099,7 @@ Handle(Transfer_Binder) Transfer_TransferProcess::Transferring(const TheStart& s StartTrace (binder, start, thelevel-1,4); } thelevel = oldlev; + themessenger->SetOuputGravity (aPrevGravity); } } diff --git a/src/XDEDRAW/XDEDRAW_Common.cxx b/src/XDEDRAW/XDEDRAW_Common.cxx index 98eaa4dc1b..7b08848208 100644 --- a/src/XDEDRAW/XDEDRAW_Common.cxx +++ b/src/XDEDRAW/XDEDRAW_Common.cxx @@ -28,12 +28,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -312,11 +314,17 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c Standard_CString aDocName = NULL; TCollection_AsciiString aFilePath, aModeStr; + Standard_Integer aTraceLevel = 0; for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter) { TCollection_AsciiString anArgCase (argv[anArgIter]); anArgCase.LowerCase(); - if (aDocName == NULL) + if (anArgCase == "-tracelevel" && anArgIter < argc) + { + anArgIter++; + aTraceLevel = atoi (argv[anArgIter]); + } + else if (aDocName == NULL) { aDocName = argv[anArgIter]; } @@ -383,6 +391,12 @@ static Standard_Integer ReadStep (Draw_Interpretor& di, Standard_Integer argc, c Draw::Set (aDocName, DD); // di << "Document saved with name " << aDocName; } + + if (aTraceLevel > 0) + { + const Handle(XSControl_TransferReader) &TR1 = reader.Reader().WS()->TransferReader(); + TR1->TransientProcess()->SetTraceLevel (aTraceLevel); + } if ( ! reader.Transfer ( doc ) ) { di << "Cannot read any relevant data from the STEP file\n"; return 1; @@ -617,7 +631,7 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di) di.Add("ReadIges" , "Doc filename: Read IGES file to DECAF document" ,__FILE__, ReadIges, g); di.Add("WriteIges" , "Doc filename: Write DECAF document to IGES file" ,__FILE__, WriteIges, g); di.Add("ReadStep" , - "Doc filename [mode]" + "Doc filename [mode] [-traceLevel level]" "\n\t\t: Read STEP file to a document.", __FILE__, ReadStep, g); di.Add("WriteStep" , "Doc filename [mode=a [multifile_prefix] [label]]: Write DECAF document to STEP file" ,__FILE__, WriteStep, g); diff --git a/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx b/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx index b6a5696f63..8546a7e8c7 100644 --- a/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx +++ b/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx @@ -17,10 +17,14 @@ #include #include +#include #include #include +#include #include +#include + #include #include #include @@ -30,6 +34,8 @@ #include #include #include +#include + #include // ======================================================================= @@ -73,7 +79,7 @@ void XmlDrivers_MessageReportStorage::ExportReport (const Handle(Message_Report) // Gravity Label TDF_Label aGravityLabel = aMainLabel.NewChild(); // set gravity kind string - TCollection_ExtendedString aName (Message::GravityToString ((Message_Gravity)aGravity)); + TCollection_ExtendedString aName (aGravity); if (!aName.IsEmpty()) TDataStd_Name::Set (aGravityLabel, aName); @@ -88,6 +94,7 @@ void XmlDrivers_MessageReportStorage::ExportReport (const Handle(Message_Report) } } GetApplication()->SaveAs (aDocument, theFileName); + GetApplication()->Close (aDocument); } // ======================================================================= @@ -131,7 +138,7 @@ Handle(Message_Report) XmlDrivers_MessageReportStorage::ImportReport (const TCol // get gravity type const TCollection_ExtendedString& aGravityName = aNameAttribute->Get(); - Message_Gravity aGravity = Message::GravityFromString (TCollection_AsciiString (aGravityName).ToCString()); + Message_Gravity aGravity = (Message_Gravity) (TCollection_AsciiString (aGravityName).IntegerValue()); /// reserved label to store gravity information //TDF_Label aFirstAlertLabel = aGravityLabel.FindChild (1, Standard_False); @@ -168,7 +175,7 @@ void XmlDrivers_MessageReportStorage::exportAlert (const Handle(Message_Alert)& // Gravity Label TDF_Label aGravityLabel = anAlertLabel.NewChild(); // set gravity kind string - TDataStd_Name::Set (aGravityLabel, Message::GravityToString ((Message_Gravity)aGravityId)); + TDataStd_Name::Set (aGravityLabel, aGravityId); Handle(Message_AlertExtended) anAlertExtended = Handle(Message_AlertExtended)::DownCast (theAlert); if (anAlertExtended.IsNull()) @@ -214,7 +221,7 @@ void XmlDrivers_MessageReportStorage::importAlert (const TDF_Label& theAlertLabe continue; // get gravity type - Message_Gravity aGravity = Message::GravityFromString (TCollection_AsciiString (aNameAttribute->Get()).ToCString()); + 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()) { @@ -225,7 +232,13 @@ void XmlDrivers_MessageReportStorage::importAlert (const TDF_Label& theAlertLabe importAlert (anAlertLabel, aGravity, theReport, anAlert); } } - theReport->AddAlert (theGravity, anAlert, 0, theParentAlert); + if (theParentAlert.IsNull()) + theReport->AddAlert (theGravity, anAlert); + else + { + MESSAGE_ADD_LEVEL_SENTRY + theReport->AddAlert (theGravity, anAlert); + } } // ======================================================================= @@ -234,40 +247,30 @@ void XmlDrivers_MessageReportStorage::importAlert (const TDF_Label& theAlertLabe // ======================================================================= 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(); - - //TDataStd_Name::Set (theAlertLabel, anAttribute->DynamicType()->Name()); - ////TDataStd_Real::Set (theAlertLabel, anAlertExtended->CumulativeMetric()); - - //TDataStd_AsciiString::Set (theAlertLabel, anAttribute->GetName()); - //TCollection_AsciiString aDescription = anAttribute->GetDescription(); - //if (!aDescription.IsEmpty()) - // TDataStd_Comment::Set (theAlertLabel, anAttribute->GetDescription()); - - //Standard_CString aDynamicTypeName = anAttribute->DynamicType()->Name(); - //if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeStream)->Name()) - //{ - // Handle(Message_AttributeStream) aValuesArrayAlert = Handle(Message_AttributeStream)::DownCast (anAttribute); - // // store values - // NCollection_IndexedDataMap aValues; - // TCollection_AsciiString aKey; - // TCollection::Split (aValuesArrayAlert->GetStream(), aValues, aKey); - // if (aValues.IsEmpty()) - // return; - // int anArraySize = 2 * aValues.Size(); - // Handle(TDataStd_ExtStringArray) aListAttribute = TDataStd_ExtStringArray::Set (theAlertLabel, 0, anArraySize - 1); - // for (int aValueId = 0; aValueId < anArraySize; aValueId++) - // { - // TCollection_AsciiString aKey = aValues.FindKey (aValueId); - // aListAttribute->SetValue (aValueId * 2, aKey); - // aListAttribute->SetValue (aValueId * 2 + 1, aValues.FindFromKey (aKey)); - // } - //} + 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(); + + TDataStd_Name::Set (theAlertLabel, anAttribute->DynamicType()->Name()); + //TDataStd_Real::Set (theAlertLabel, anAlertExtended->CumulativeMetric()); + + TDataStd_AsciiString::Set (theAlertLabel, anAttribute->GetName()); + + Standard_CString aDynamicTypeName = anAttribute->DynamicType()->Name(); + if (aDynamicTypeName == STANDARD_TYPE (Message_AttributeStream)->Name() || + aDynamicTypeName == STANDARD_TYPE (TopoDS_AlertAttribute)->Name()) + { + Handle(Message_AttributeStream) aValuesArrayAlert = Handle(Message_AttributeStream)::DownCast (anAttribute); + // store values + TCollection_AsciiString aStreamText = Standard_Dump::Text (aValuesArrayAlert->GetStream()); + if (aStreamText.IsEmpty()) + return; + Handle(TDataStd_ExtStringArray) aListAttribute = TDataStd_ExtStringArray::Set (theAlertLabel, 0, 0); + aListAttribute->SetValue (0, aStreamText); + } } // ======================================================================= @@ -276,72 +279,59 @@ void XmlDrivers_MessageReportStorage::exportAlertParameters (const Handle(Messag // ======================================================================= 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(); - - //TCollection_ExtendedString aDescription; - //if (aParametersLabel.FindAttribute (TDataStd_Comment::GetID(), anAttribute)) - //{ - // Handle(TDataStd_Comment) aDescriptionAttribute = Handle(TDataStd_Comment)::DownCast (anAttribute); - // if (!aDescriptionAttribute.IsNull()) - // aDescription = aDescriptionAttribute->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()) - //{ - // // values - // NCollection_Vector anArrayValues; - // 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++) - // { - // TCollection_AsciiString aKey = aValuesAttribute->Value (aValueId++); - // if (aValueId > aValuesAttribute->Upper()) - // break; - // DUMP_VALUES (aStream, aKey, aValuesAttribute->Value (aValueId)); - // } - // Handle(Message_AttributeStream) anAlert = new Message_AttributeStream (aStream); - // aMessageAttribute = anAlert; - //} - - //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()); - // aMessageAttribute->SetDescription (aDescription); - - // anAlert->SetAttribute (aMessageAttribute); - //} - - //// time + 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 + NCollection_Vector anArrayValues; + 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); + } + Handle(Message_AttributeStream) anAlert = new Message_AttributeStream (aStream); + aMessageAttribute = anAlert; + } + + 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); + } + + // time //Standard_Real aTime = -1; //Handle(TDataStd_Real) aTimeAttribute; //if (aParametersLabel.FindAttribute (TDataStd_Real::GetID(), aTimeAttribute)) // aTime = aTimeAttribute->Get(); - ////anAlert->SetCumulativeMetric (aTime); - //return anAlert; - return NULL; + //anAlert->SetCumulativeMetric (aTime); + return anAlert; } diff --git a/src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx b/src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx index cd97441c1e..81e1db8f9c 100644 --- a/src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx +++ b/src/XmlDrivers/XmlDrivers_MessageReportStorage.hxx @@ -65,4 +65,10 @@ private: static Handle(Message_Alert) importAlertParameters (const TDF_Label& aParametersLabel); }; +#define MESSAGE_STORE_XML_REPORT(FileName) \ +{ \ + Handle(Message_Report) aReport = Message::DefaultReport (Standard_False); \ + if (!aReport.IsNull()) XmlDrivers_MessageReportStorage::ExportReport (aReport, FileName); \ +} + #endif // _XmlDrivers_MessageReportStorage diff --git a/tests/de/step_5/B8 b/tests/de/step_5/B8 new file mode 100644 index 0000000000..cae0e88df6 --- /dev/null +++ b/tests/de/step_5/B8 @@ -0,0 +1,23 @@ +pload ALL + +dsetreportprinter on + +dsetreportmetric 1 + +ReadStep d d:/dmu/step1.stp -tracelevel 4 +#ReadStep d [locate_data_file bug21802_as1-oc-214.stp] +dsetreportprinter off +dsetreportmetric + +set aFile d:/dmu/B8_report.xml +#set aFile ${imagedir}/B8_report.xml + +file delete ${aFile} +WriteReport ${aFile} +if { ![file exists ${aFile}] } { + puts "There is not ${aFile} file; WriteReport command: Error" + return +} + +pload INSPECTOR +tinspector -plugins MessageView diff --git a/tools/DFBrowser/DFBrowser_Module.cxx b/tools/DFBrowser/DFBrowser_Module.cxx index 2aff65e7f1..edd1a88239 100644 --- a/tools/DFBrowser/DFBrowser_Module.cxx +++ b/tools/DFBrowser/DFBrowser_Module.cxx @@ -53,7 +53,9 @@ DFBrowser_Module::DFBrowser_Module() // ======================================================================= void DFBrowser_Module::CreateViewModel (void* theParent) { - myOCAFViewModel = new DFBrowser_TreeModel ((QWidget*)theParent, this); + myOCAFViewModel = new DFBrowser_TreeModel ((QWidget*)theParent); + myOCAFViewModel->InitColumns(); + myOCAFViewModel->SetModule (this); } // ======================================================================= diff --git a/tools/DFBrowser/DFBrowser_TreeModel.cxx b/tools/DFBrowser/DFBrowser_TreeModel.cxx index 16fe10485e..23ab2c2aa8 100644 --- a/tools/DFBrowser/DFBrowser_TreeModel.cxx +++ b/tools/DFBrowser/DFBrowser_TreeModel.cxx @@ -38,12 +38,27 @@ const int COLUMN_NAME_WIDTH = 300; // function : Constructor // purpose : // ======================================================================= -DFBrowser_TreeModel::DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* theModule) +DFBrowser_TreeModel::DFBrowser_TreeModel (QObject* theParent) : TreeModel_ModelBase (theParent) { - SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); +} - DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (m_pRootItem); +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void DFBrowser_TreeModel::InitColumns() +{ + SetHeaderItem (0, TreeModel_HeaderSection ("Name")); +} + +// ======================================================================= +// function : SetModule +// purpose : +// ======================================================================= +void DFBrowser_TreeModel::SetModule (DFBrowser_Module* theModule) +{ + DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (RootItem (0)); aRootItem->SetModule (theModule); } @@ -51,9 +66,9 @@ DFBrowser_TreeModel::DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* // function : createRootItem // purpose : // ======================================================================= -void DFBrowser_TreeModel::createRootItem (const int) +TreeModel_ItemBasePtr DFBrowser_TreeModel::createRootItem (const int) { - m_pRootItem = DFBrowser_ItemApplication::CreateItem (TreeModel_ItemBasePtr()); + return DFBrowser_ItemApplication::CreateItem (TreeModel_ItemBasePtr()); } // ======================================================================= @@ -62,7 +77,7 @@ void DFBrowser_TreeModel::createRootItem (const int) // ======================================================================= void DFBrowser_TreeModel::Init (const Handle(TDocStd_Application)& theApplication) { - DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (m_pRootItem); + DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (RootItem (0)); Reset(); aRootItem->SetApplication (theApplication); EmitLayoutChanged(); @@ -74,7 +89,7 @@ void DFBrowser_TreeModel::Init (const Handle(TDocStd_Application)& theApplicatio // ======================================================================= Handle(TDocStd_Application) DFBrowser_TreeModel::GetTDocStdApplication() const { - DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (m_pRootItem); + DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (RootItem (0)); return aRootItem->GetApplication(); } @@ -179,7 +194,7 @@ QModelIndex DFBrowser_TreeModel::FindIndexByPath (const QStringList& theLabelEnt if (aPathId == aPathCount && anItem->HasAttribute()) { // processing attribute in theValue - DFBrowser_ItemApplicationPtr aRootAppItem = itemDynamicCast(m_pRootItem); + DFBrowser_ItemApplicationPtr aRootAppItem = itemDynamicCast(RootItem (0)); QString anAttributeInfo = DFBrowser_Module::GetAttributeInfo (anItem->GetAttribute(), aRootAppItem->GetModule(), Qt::DisplayRole, 0).toString(); if (anAttributeInfo == anEntry) diff --git a/tools/DFBrowser/DFBrowser_TreeModel.hxx b/tools/DFBrowser/DFBrowser_TreeModel.hxx index 6182c25b56..dbe038ffc1 100644 --- a/tools/DFBrowser/DFBrowser_TreeModel.hxx +++ b/tools/DFBrowser/DFBrowser_TreeModel.hxx @@ -45,14 +45,20 @@ class DFBrowser_TreeModel : public TreeModel_ModelBase public: //! Constructor - Standard_EXPORT DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* theModule); + Standard_EXPORT DFBrowser_TreeModel (QObject* theParent); //! Destructor virtual ~DFBrowser_TreeModel() Standard_OVERRIDE {}; + //! Creates model columns and root items. + Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; + //! Fills the root item by the application Standard_EXPORT void Init (const Handle(TDocStd_Application)& theApplication); + //! Fill root item by the module + void SetModule (DFBrowser_Module* theModule); + //! Returns an OCAF application or NULL //! \return an application instance Standard_EXPORT Handle(TDocStd_Application) GetTDocStdApplication() const; @@ -98,7 +104,7 @@ public: protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId); + virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; private: diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.cxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.cxx index 0e79829114..a903cf3f25 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.cxx @@ -41,6 +41,7 @@ DFBrowserPane_TDataStdTreeNode::DFBrowserPane_TDataStdTreeNode() : DFBrowserPane_AttributePane(), myTreeNodeView (0) { myModel = new DFBrowserPane_TDataStdTreeNodeModel (0); + myModel->InitColumns(); mySelectionModels.clear(); // do not use selection model of parent pane mySelectionModels.push_back (new QItemSelectionModel (myModel)); } @@ -99,15 +100,14 @@ void DFBrowserPane_TDataStdTreeNode::Init (const Handle(TDF_Attribute)& theAttri } - DFBrowserPane_TDataStdTreeNodeModel* aModel = dynamic_cast (myModel); - aModel->Reset(); + myModel->Reset(); if (!aTreeNode.IsNull()) { Handle(TDataStd_TreeNode) aRootItem = aTreeNode->Root(); - aModel->SetAttribute (aRootItem); + myModel->SetAttribute (aRootItem); - QModelIndex anIndex = aModel->FindIndex (theAttribute, QModelIndex()); + QModelIndex anIndex = myModel->FindIndex (theAttribute, QModelIndex()); if (myTreeNodeView && anIndex.isValid()) { myTreeNodeView->setExpanded (anIndex.parent(), true); @@ -119,7 +119,7 @@ void DFBrowserPane_TDataStdTreeNode::Init (const Handle(TDF_Attribute)& theAttri anAttributeNodeItem->setCurrentAttribute (true); } } - aModel->EmitLayoutChanged(); + myModel->EmitLayoutChanged(); } // ======================================================================= diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.hxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.hxx index 9057060869..50d676a419 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.hxx @@ -20,7 +20,7 @@ #include -class QAbstractItemModel; +class DFBrowserPane_TDataStdTreeNodeModel; class QTreeView; //! \class DFBrowserPane_TDataStdTreeNode @@ -66,7 +66,7 @@ public: private: - QAbstractItemModel* myModel; + DFBrowserPane_TDataStdTreeNodeModel* myModel; QTreeView* myTreeNodeView; }; diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.cxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.cxx index aaa62b23b5..4f8a4847f0 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.cxx @@ -29,16 +29,24 @@ DFBrowserPane_TDataStdTreeNodeModel::DFBrowserPane_TDataStdTreeNodeModel (QObject* theParent) : TreeModel_ModelBase (theParent) { - createRootItem(0); +} + +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void DFBrowserPane_TDataStdTreeNodeModel::InitColumns() +{ + SetHeaderItem (0, TreeModel_HeaderSection ("Name")); } // ======================================================================= // function : createRootItem // purpose : // ======================================================================= -void DFBrowserPane_TDataStdTreeNodeModel::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr DFBrowserPane_TDataStdTreeNodeModel::createRootItem (const int theColumnId) { - m_pRootItem = DFBrowserPane_TDataStdTreeNodeItem::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); + return DFBrowserPane_TDataStdTreeNodeItem::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= @@ -47,7 +55,7 @@ void DFBrowserPane_TDataStdTreeNodeModel::createRootItem (const int theColumnId) // ======================================================================= void DFBrowserPane_TDataStdTreeNodeModel::SetAttribute (const Handle(TDF_Attribute)& theAttribute) { - DFBrowserPane_TDataStdTreeNodeItemPtr aRootItem = itemDynamicCast(m_pRootItem); + DFBrowserPane_TDataStdTreeNodeItemPtr aRootItem = itemDynamicCast(RootItem (0)); Reset(); aRootItem->SetAttribute (theAttribute); EmitLayoutChanged(); diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.hxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.hxx index 9223cfa19b..62e016ce86 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.hxx @@ -40,6 +40,9 @@ public: //! Destructor virtual ~DFBrowserPane_TDataStdTreeNodeModel() Standard_OVERRIDE {}; + //! Creates model columns and root items. + Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; + //! Initializes the tree model by the attribute //! \param theAttribute a current attribute Standard_EXPORT void SetAttribute (const Handle(TDF_Attribute)& theAttribute); @@ -59,7 +62,7 @@ public: protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) Standard_OVERRIDE; + virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; private: diff --git a/tools/MessageModel/FILES b/tools/MessageModel/FILES index 953018ceee..5fbdcbc86b 100644 --- a/tools/MessageModel/FILES +++ b/tools/MessageModel/FILES @@ -10,8 +10,6 @@ MessageModel_ItemReport.cxx MessageModel_ItemReport.hxx MessageModel_ItemRoot.cxx MessageModel_ItemRoot.hxx -MessageModel_ReportCallBack.cxx -MessageModel_ReportCallBack.hxx MessageModel_Tools.cxx MessageModel_Tools.hxx MessageModel_TreeModel.cxx diff --git a/tools/MessageModel/MessageModel.qrc b/tools/MessageModel/MessageModel.qrc index 6862cafe7d..8b794a8599 100644 --- a/tools/MessageModel/MessageModel.qrc +++ b/tools/MessageModel/MessageModel.qrc @@ -1,6 +1,6 @@ icons/item_shape.png - icons/item_vectorOfValues.png + icons/item_streamValues.png diff --git a/tools/MessageModel/MessageModel_ActionType.hxx b/tools/MessageModel/MessageModel_ActionType.hxx index 8cd073c1c8..7df28caaba 100644 --- a/tools/MessageModel/MessageModel_ActionType.hxx +++ b/tools/MessageModel/MessageModel_ActionType.hxx @@ -24,7 +24,9 @@ enum MessageModel_ActionType 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_TestProperties, //!< test alerts + MessageModel_ActionType_TestMessenger, //!< test message view on messenger printer to report + MessageModel_ActionType_TestReportTree //!< test message view on hierarchical report }; #endif diff --git a/tools/MessageModel/MessageModel_Actions.cxx b/tools/MessageModel/MessageModel_Actions.cxx index 82f9268da8..b5e4785262 100644 --- a/tools/MessageModel/MessageModel_Actions.cxx +++ b/tools/MessageModel/MessageModel_Actions.cxx @@ -24,9 +24,13 @@ #include #include +#include #include +#include +#include #include +#include #include #include #include @@ -41,13 +45,6 @@ #include #include -#define DEBUG_ALERTS - -#ifdef DEBUG_ALERTS -#include -#include -#endif - // ======================================================================= // function : Constructor // purpose : @@ -56,20 +53,14 @@ MessageModel_Actions::MessageModel_Actions (QWidget* theParent, MessageModel_TreeModel* theTreeModel, QItemSelectionModel* theModel) : QObject (theParent), myTreeModel (theTreeModel), mySelectionModel (theModel) { - myActions.insert (MessageModel_ActionType_Deactivate, - ViewControl_Tools::CreateAction ("Deactivate", SLOT (OnDeactivateReport()), parent(), this)); 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)); -#ifdef DEBUG_ALERTS - myActions.insert (MessageModel_ActionType_TestMetric, - ViewControl_Tools::CreateAction ("Test ", SLOT (OnTestMetric()), parent(), this)); - myActions.insert (MessageModel_ActionType_TestProperties, - ViewControl_Tools::CreateAction ("Test ", SLOT (OnTestPropertyPanel()), parent(), this)); -#endif } // ======================================================================= @@ -121,10 +112,6 @@ void MessageModel_Actions::AddMenuActions (const QModelIndexList& theSelectedInd theMenu->addAction (myActions[MessageModel_ActionType_Deactivate]); theMenu->addAction (myActions[MessageModel_ActionType_Activate]); theMenu->addAction (myActions[MessageModel_ActionType_Clear]); -#ifdef DEBUG_ALERTS - theMenu->addAction (myActions[MessageModel_ActionType_TestMetric]); - theMenu->addAction (myActions[MessageModel_ActionType_TestProperties]); -#endif } else if (anAlertItem) { @@ -135,7 +122,7 @@ void MessageModel_Actions::AddMenuActions (const QModelIndexList& theSelectedInd } // ======================================================================= -// function : onImportReport +// function : getSelectedReport // purpose : // ======================================================================= Handle(Message_Report) MessageModel_Actions::getSelectedReport (QModelIndex& theReportIndex) const @@ -164,33 +151,40 @@ Handle(Message_Report) MessageModel_Actions::getSelectedReport (QModelIndex& the } // ======================================================================= -// function : OnDeactivateReport +// function : OnActivateReport // purpose : // ======================================================================= -void MessageModel_Actions::OnDeactivateReport() +static Handle(Message_PrinterToReport) MyPrinterToReport; +static Message_SequenceOfPrinters MyDeactivatedPrinters; + +void MessageModel_Actions::OnActivateReport() { - QModelIndex aReportIndex; - Handle(Message_Report) aReport = getSelectedReport (aReportIndex); - if (aReport.IsNull()) + if (MyPrinterToReport.IsNull()) + MyPrinterToReport = new Message_PrinterToReport(); + + if (MyPrinterToReport->Report()->IsActiveInMessenger()) return; - aReport->SetActive (Standard_False); - ((MessageModel_TreeModel*)mySelectionModel->model())->EmitDataChanged (aReportIndex, aReportIndex); + MyDeactivatedPrinters = Message::DefaultMessenger()->Printers(); + Message::DefaultMessenger()->ChangePrinters().Clear(); + + Message::DefaultMessenger()->AddPrinter (MyPrinterToReport); + myTreeModel->UpdateTreeModel(); } // ======================================================================= -// function : OnActivateReport +// function : OnDeactivateReport // purpose : // ======================================================================= -void MessageModel_Actions::OnActivateReport() +void MessageModel_Actions::OnDeactivateReport() { - QModelIndex aReportIndex; - Handle(Message_Report) aReport = getSelectedReport (aReportIndex); - if (aReport.IsNull()) + if (MyPrinterToReport.IsNull() || !MyPrinterToReport->Report()->IsActiveInMessenger()) return; - aReport->SetActive (Standard_True); - ((MessageModel_TreeModel*)mySelectionModel->model())->EmitDataChanged (aReportIndex, aReportIndex); + Message::DefaultMessenger()->RemovePrinter (MyPrinterToReport); + Message::DefaultMessenger()->ChangePrinters().Assign (MyDeactivatedPrinters); + + myTreeModel->UpdateTreeModel(); } // ======================================================================= @@ -205,7 +199,7 @@ void MessageModel_Actions::OnClearReport() return; aReport->Clear(); - ((MessageModel_TreeModel*)mySelectionModel->model())->EmitDataChanged (aReportIndex, aReportIndex); + myTreeModel->UpdateTreeModel(); } // ======================================================================= @@ -270,172 +264,3 @@ void MessageModel_Actions::OnExportToShapeView() QMessageBox::information (0, "Information", QString ("TShapes '%1' are sent to %2 tool.") .arg (anExportedPointers.join (", ")).arg (QString (aPluginName.ToCString()))); } - -// ======================================================================= -// function : OnTestMetric -// purpose : -// ======================================================================= -#include -#include -void MessageModel_Actions::OnTestMetric() -{ -#ifdef DEBUG_ALERTS - QModelIndex aReportIndex; - Handle(Message_Report) aReport = getSelectedReport (aReportIndex); - if (aReport.IsNull()) - return; - - Message_PerfMeter aPerfMeter; - MESSAGE_INFO ("MessageModel_Actions::OnTestAlerts()", "", &aPerfMeter, NULL); - unsigned int start_time = clock(); - //Standard_Real aSystemSeconds, aCurrentSeconds; - //OSD_Chronometer::GetThreadCPU (aCurrentSeconds, aSystemSeconds); - - Standard_Integer aCounter = 5000;//0; - Standard_Real aValue = 0., aValue2 = 0.1; - - double* aMemValue; - for (int aTopIt = 0; aTopIt < 4; aTopIt++) - { - 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; - } - } - MESSAGE_INFO ("Calculate", "", &aPerfMeter, NULL); - } - - //((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 MessageModel_Actions::OnTestPropertyPanel() -{ -#ifdef DEBUG_ALERTS - QModelIndex aReportIndex; - Handle(Message_Report) aReport = getSelectedReport (aReportIndex); - if (aReport.IsNull()) - return; - - Message_PerfMeter aPerfMeter; - MESSAGE_INFO ("MessageModel_Actions::OnTestAlerts()", "", &aPerfMeter, NULL); - - // gp_XYZ - { - gp_XYZ aCoords (1.3, 2.3, 3.4); - Standard_SStream aStream; - aCoords.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "gp_XYZ", "", &aPerfMeter, NULL); - } - // gp_Dir - { - gp_Dir aDir (0.3, 0.3, 0.4); - Standard_SStream aStream; - aDir.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "gp_Dir", "", &aPerfMeter, NULL); - } - // gp_Ax1 - { - gp_Ax1 aCoords (gp_Pnt (1.3, 2.3, 3.4), gp_Dir (0.3, 0.3, 0.4)); - Standard_SStream aStream; - aCoords.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "gp_Ax1", "", &aPerfMeter, NULL); - } - // gp_Ax2 - { - gp_Ax2 aCoords (gp_Pnt (10.3, 20.3, 30.4), gp_Dir (0.3, 0.3, 0.4)); - Standard_SStream aStream; - aCoords.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "gp_Ax2", "", &aPerfMeter, NULL); - } - // gp_Ax3 - { - gp_Ax3 aPln (gp_Pnt (10., 20., 15.), gp_Dir (0., 0., 1.), gp_Dir (1., 0., 0.)); - Standard_SStream aStream; - aPln.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "gp_Ax3", "", &aPerfMeter, NULL); - } - // gp_Trsf - { - gp_Trsf aTrsf; - aTrsf.SetRotation (gp::OZ(), 0.3); - aTrsf.SetTranslationPart (gp_Vec (15., 15., 15.)); - aTrsf.SetScaleFactor (3.); - - Standard_SStream aStream; - aTrsf.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "gp_Trsf", "", &aPerfMeter, NULL); - } - // Bnd_Box - { - Bnd_Box aBox (gp_Pnt (20., 15., 10.), gp_Pnt (25., 20., 15.)); - Standard_SStream aStream; - aBox.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "Bnd_Box", "", &aPerfMeter, NULL); - } - // 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.); - Standard_SStream aStream; - anOBB.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "Bnd_OBB", "", &aPerfMeter, NULL); - } - // Quantity_ColorRGBA - { - Quantity_ColorRGBA aColor (0.2f, 0.8f, 0.8f, 0.2f); - Standard_SStream aStream; - aColor.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "Quantity_ColorRGBA", "", &aPerfMeter, NULL); - } - // Quantity_Color - { - Quantity_Color aColor (0.8, 0.8, 0.8, Quantity_TOC_RGB); - Standard_SStream aStream; - aColor.DumpJson (aStream); - MESSAGE_INFO_STREAM(aStream, "Quantity_Color", "", &aPerfMeter, NULL); - } - - // 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"); - - MESSAGE_INFO_STREAM(aStream, "Table: Name to value", "", &aPerfMeter, NULL); - } - - // 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", "", &aPerfMeter, NULL); - } - - myTreeModel->UpdateTreeModel(); -#endif -} diff --git a/tools/MessageModel/MessageModel_Actions.hxx b/tools/MessageModel/MessageModel_Actions.hxx index c030c97fdf..39eab429e2 100644 --- a/tools/MessageModel/MessageModel_Actions.hxx +++ b/tools/MessageModel/MessageModel_Actions.hxx @@ -70,24 +70,18 @@ public: { myParameters = theParameters; } public slots: - //! Set selected report not active - void OnDeactivateReport(); - //! 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(); - //! 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(); - protected: //! Returns report of selected tree view item if a report item is selected //! \param theReportIndex tree model index of the found report diff --git a/tools/MessageModel/MessageModel_ItemAlert.cxx b/tools/MessageModel/MessageModel_ItemAlert.cxx index bcec35a4cd..7b076871fe 100644 --- a/tools/MessageModel/MessageModel_ItemAlert.cxx +++ b/tools/MessageModel/MessageModel_ItemAlert.cxx @@ -18,12 +18,15 @@ #include #include #include +#include + #include #include #include #include #include +#include #include #include @@ -55,22 +58,15 @@ QVariant MessageModel_ItemAlert::initValue (const int theRole) const if (aReport.IsNull()) return QVariant(); - Standard_Boolean isTimeReport = aReport->PerfMeterMode() == Message_PerfMeterMode_UserTimeCPU || - aReport->PerfMeterMode() == Message_PerfMeterMode_SystemTimeInfo; - - if (aReport->PerfMeterMode() == Message_PerfMeterMode_UserTimeCPU || - aReport->PerfMeterMode() == Message_PerfMeterMode_SystemTimeInfo) - if (theRole == Qt::ForegroundRole) { - if (!aReport->GetAlerts (Message_Fail).IsEmpty()) + if (!aReport->GetAlerts (Message_Fail).IsEmpty() || + !aReport->GetAlerts (Message_Alarm).IsEmpty()) return QColor(Qt::darkRed); - for (int aGravityId = (int)Message_Trace; aGravityId <= (int)Message_Fail; aGravityId++) - { - if (!aReport->IsActive ((Message_Gravity)aGravityId)) - return QColor(Qt::darkGray); - } + if (!aReport->IsActiveInMessenger()) + return QColor(Qt::darkGray); + return QVariant(); } @@ -84,11 +80,13 @@ QVariant MessageModel_ItemAlert::initValue (const int theRole) const 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_vectorOfValues.png"); + return QIcon (":/icons/item_streamValues.png"); else return QVariant(); } @@ -99,69 +97,33 @@ QVariant MessageModel_ItemAlert::initValue (const int theRole) const if (anAlert.IsNull()) return QVariant(); - switch (Column()) + if (Column() == 0) + return theRole == Qt::DisplayRole ? anAlert->GetMessageKey() : anAlert->DynamicType()->Name(); + + Message_MetricType aMetricType; + int aPosition; + if (MessageModel_TreeModel::IsMetricColumn (Column(), aMetricType, aPosition)) { - case 0: - return theRole == Qt::DisplayRole ? anAlert->GetMessageKey() : anAlert->DynamicType()->Name(); - //case 1: return QVariant(); // visibility state - //case 2: return rowCount() > 0 ? QVariant (rowCount()) : QVariant(); - //case 3: return anAlert->ElapsedTime() < 0 ? QVariant() : anAlert->ElapsedTime(); - case 4: - { - if (!anExtendedAlert->IsMetricValid()) - return QVariant(); + if (anExtendedAlert.IsNull()) + return QVariant(); - if (isTimeReport) - return anExtendedAlert->MetricStop() - anExtendedAlert->MetricStart(); - else - return anExtendedAlert->MetricStart(); - } - case 5: - { - if (!anExtendedAlert->IsMetricValid()) - return QVariant(); + Handle(Message_AttributeMeter) anAttribute = Handle(Message_AttributeMeter)::DownCast (anExtendedAlert->Attribute()); + if (anAttribute.IsNull()) + return QVariant(); - if (isTimeReport) - { - TreeModel_ItemBasePtr aParentItem = Parent(); - MessageModel_ItemReportPtr aReportItem = itemDynamicCast (aParentItem); - while (!aReportItem) - { - aParentItem = aParentItem->Parent(); - aReportItem = itemDynamicCast (aParentItem); - } - double aDivideTo = aReport->CumulativeMetric (Message_Info); - double anAlertTime = anExtendedAlert->MetricStop() - anExtendedAlert->MetricStart(); - - return aDivideTo == 0 ? QVariant() : 100. * anAlertTime / aDivideTo; - } - else - { - TreeModel_ItemBasePtr aParentItem = Parent(); - //MessageModel_ItemAlertPtr aParentAlertItem = itemDynamicCast (aParentItem); - //if (aParentAlertItem) - //{ - //double aDeltaToParent = CumulativeMetric (anAlert) - CumulativeMetric (aParentAlertItem->GetAlert()); - - //return fabs (aDeltaToParent) > Precision::Confusion() ? QVariant (aDeltaToParent) : QVariant(); - //} - double anAlertMem = anExtendedAlert->MetricStop() - anExtendedAlert->MetricStart(); - return anAlertMem; - } - } - case 6: return MessageModel_Tools::GetPointerAlertInfo (anAlert).ToCString(); - case 7: return MessageModel_Tools::GetShapeTypeAlertInfo (anAlert).ToCString(); - case 8: return MessageModel_Tools::GetStandardTypeAlertInfo (anAlert).ToCString(); - case 9: + 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) { - if (!anExtendedAlert.IsNull() && !anExtendedAlert->Attribute().IsNull()) - { - TCollection_AsciiString aDescription = anExtendedAlert->Attribute()->GetDescription(); - return theRole == Qt::DisplayRole ? TreeModel_Tools::CutString (aDescription.ToCString()) - : aDescription.ToCString(); - } + Standard_Real aReportCumulativeMetric = MessageModel_ItemReport::CumulativeMetric (aReport, aMetricType); + if (fabs (aReportCumulativeMetric) > Precision::Confusion()) + return 100. * aCumulativeMetric / aReportCumulativeMetric; + else + return QVariant(); } - default: break; } return QVariant(); } diff --git a/tools/MessageModel/MessageModel_ItemReport.cxx b/tools/MessageModel/MessageModel_ItemReport.cxx index c68a286759..40a7d0b627 100644 --- a/tools/MessageModel/MessageModel_ItemReport.cxx +++ b/tools/MessageModel/MessageModel_ItemReport.cxx @@ -18,7 +18,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include @@ -41,45 +47,33 @@ QVariant MessageModel_ItemReport::initValue (const int theRole) const if (theRole == Qt::ForegroundRole) { - if (!aReport->GetAlerts (Message_Fail).IsEmpty()) + if (!aReport->GetAlerts (Message_Fail).IsEmpty() || + !aReport->GetAlerts (Message_Alarm).IsEmpty()) return QColor(Qt::darkRed); - for (int aGravityId = (int)Message_Trace; aGravityId <= (int)Message_Fail; aGravityId++) - { - if (!aReport->IsActive ((Message_Gravity)aGravityId)) - return QColor(Qt::darkGray); - } + if (!aReport->IsActiveInMessenger()) + return QColor(Qt::darkGray); + return QVariant(); } - if (theRole == Qt::ToolTipRole && !myDescription.IsEmpty() && Column() == 8) - return myDescription.ToCString(); + 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(); - switch (Column()) - { - case 0: return aReport->DynamicType()->Name(); - //case 1: return QVariant(); // visibility state - //case 2: return rowCount() > 0 ? QVariant (rowCount()) : QVariant(); - case 4: return aReport->CumulativeMetric (Message_Info); - case 5: - { - if (aReport->PerfMeterMode() == Message_PerfMeterMode_UserTimeCPU || - aReport->PerfMeterMode() == Message_PerfMeterMode_SystemTimeInfo) - return "100"; - else - return QVariant(); - } - case 9: - { - if (myDescription.IsEmpty()) - return QVariant(); + if (Column() == 0) + return aReport->DynamicType()->Name(); - OSD_Path aPath(myDescription); - return QString ("%1%2").arg (aPath.Name().ToCString()).arg (aPath.Extension().ToCString()); - } - default: break; + Message_MetricType aMetricType; + int aPosition; + if (MessageModel_TreeModel::IsMetricColumn (Column(), aMetricType, aPosition)) + { + if (aPosition == 0) return CumulativeMetric (aReport, aMetricType); + else if (aPosition == 1) return "100"; } return QVariant(); } @@ -200,29 +194,38 @@ Handle(Message_Report) MessageModel_ItemReport::FindReport (const MessageModel_I } // ======================================================================= -// function : initStream +// function : CumulativeMetric // purpose : // ======================================================================= -void MessageModel_ItemReport::initStream (Standard_OStream& theOStream) const +Standard_Real MessageModel_ItemReport::CumulativeMetric (const Handle(Message_Report)& theReport, const Message_MetricType theMetricType) { - Handle(Message_Report) aReport = GetReport(); - if (aReport.IsNull()) - return; - - aReport->DumpJson (theOStream); -} + if (!theReport->ActiveMetrics().Contains (theMetricType)) + return 0; -// ======================================================================= -// function : SetStream -// purpose : -// ======================================================================= -bool MessageModel_ItemReport::SetStream (const Standard_SStream& theSStream, Standard_Integer& theStartPos, - Standard_Integer& theLastPos) const -{ - Handle(Message_Report) aReport = GetReport(); - if (aReport.IsNull()) - return false; + 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()) + continue; + if (aFirstAttribute.IsNull()) + aFirstAttribute = anAttribute; + else + aLastAttribute = anAttribute; + } + if (aFirstAttribute.IsNull()) + continue; + if (aLastAttribute.IsNull()) + aLastAttribute = aFirstAttribute; - Standard_Integer aStartPos = 1; - return aReport->InitJson (theSStream, aStartPos); + aMetric += aLastAttribute->StopValue (theMetricType) - aFirstAttribute->StartValue (theMetricType); + } + return aMetric; } diff --git a/tools/MessageModel/MessageModel_ItemReport.hxx b/tools/MessageModel/MessageModel_ItemReport.hxx index b0f67c7686..f03d98e58d 100644 --- a/tools/MessageModel/MessageModel_ItemReport.hxx +++ b/tools/MessageModel/MessageModel_ItemReport.hxx @@ -78,20 +78,14 @@ public: //! Returns report of the item static Handle(Message_Report) FindReport (const MessageModel_ItemBasePtr& thetItem); - //! 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; + //! 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; - //! Returns stream value of the item to fulfill property panel. - //! \return stream value or dummy - Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE; - //! Creates a child item in the given position. //! \param theRow the child row position //! \param theColumn the child column position diff --git a/tools/MessageModel/MessageModel_ItemRoot.hxx b/tools/MessageModel/MessageModel_ItemRoot.hxx index b7465675c3..197bd1eb9a 100644 --- a/tools/MessageModel/MessageModel_ItemRoot.hxx +++ b/tools/MessageModel/MessageModel_ItemRoot.hxx @@ -27,23 +27,23 @@ class MessageModel_ItemRoot; typedef QExplicitlySharedDataPointer 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 { -private: - //! \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 - }; public: //! Creates an item wrapped by a shared pointer @@ -71,6 +71,9 @@ public: //! \return boolen value Standard_EXPORT Standard_Boolean HasReport (const Handle(Message_Report)& theReport); + //!< Returns processed reports + const NCollection_List& Reports() const { return myReports; } + //! Clears internal container of added reports void RemoveAllReports() { myReports.Clear(); } diff --git a/tools/MessageModel/MessageModel_ReportCallBack.cxx b/tools/MessageModel/MessageModel_ReportCallBack.cxx deleted file mode 100644 index 695722f0a4..0000000000 --- a/tools/MessageModel/MessageModel_ReportCallBack.cxx +++ /dev/null @@ -1,18 +0,0 @@ -// Created on: 2018-06-20 -// 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 "MessageModel_ReportCallBack.hxx" - -IMPLEMENT_STANDARD_RTTIEXT(MessageModel_ReportCallBack, Message_ReportCallBack) diff --git a/tools/MessageModel/MessageModel_ReportCallBack.hxx b/tools/MessageModel/MessageModel_ReportCallBack.hxx deleted file mode 100644 index be5d7c98f3..0000000000 --- a/tools/MessageModel/MessageModel_ReportCallBack.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 2018-06-20 -// 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_ReportCallBack_HeaderFile -#define _MessageModel_ReportCallBack_HeaderFile - -#include - -#include "inspector/TInspectorAPI_Communicator.hxx" - -class TInspectorAPI_Communicator; -DEFINE_STANDARD_HANDLE(MessageModel_ReportCallBack, Message_ReportCallBack) - -//! Class to update tree view model by message report events. -class MessageModel_ReportCallBack : public Message_ReportCallBack -{ -public: - - //! Constructor - MessageModel_ReportCallBack (TInspectorAPI_Communicator* theWindow) : Message_ReportCallBack(), myCommunicator (theWindow) {} - - //! Destructor - ~MessageModel_ReportCallBack() {} - - // Interface to be implemented in the child to process the message report event - // \theAlert updated alert - virtual void Update(const Handle(Message_Alert)& theAlert) { (void)theAlert; /*myCommunicator->UpdateContent();*/ } - - // OCCT RTTI - DEFINE_STANDARD_RTTIEXT(MessageModel_ReportCallBack, Message_ReportCallBack) - -private: - TInspectorAPI_Communicator* myCommunicator; //< communicator -}; - -#endif // _MessageModel_ReportCallBack_HeaderFile diff --git a/tools/MessageModel/MessageModel_Tools.cxx b/tools/MessageModel/MessageModel_Tools.cxx index 189ecb573d..dfa5ee6704 100644 --- a/tools/MessageModel/MessageModel_Tools.cxx +++ b/tools/MessageModel/MessageModel_Tools.cxx @@ -58,138 +58,3 @@ TCollection_AsciiString MessageModel_Tools::GetPointerInfo (const Handle(Standar } return aPtrStr.str().c_str(); } - -// ======================================================================= -// function : GetPointerAlertInfo -// purpose : -// ======================================================================= -TCollection_AsciiString MessageModel_Tools::GetPointerAlertInfo (const Handle(Message_Alert)& theAlert) -{ - Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (theAlert); - if (anExtAlert.IsNull()) - return TCollection_AsciiString(); - - Handle(Message_Attribute) anAttribute = anExtAlert->Attribute(); - if (anAttribute.IsNull()) - return TCollection_AsciiString(); - - if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) - return GetPointerInfo (Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape().TShape()); - else if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeObject))) - return GetPointerInfo (Handle(Message_AttributeObject)::DownCast (anAttribute)->GetObject()); - return TCollection_AsciiString(); -} - -// ======================================================================= -// function : GetShapeTypeAlertInfo -// purpose : -// ======================================================================= -TCollection_AsciiString MessageModel_Tools::GetShapeTypeAlertInfo (const Handle(Message_Alert)& theAlert) -{ - Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (theAlert); - if (anExtAlert.IsNull()) - return TCollection_AsciiString(); - - Handle(Message_Attribute) anAttribute = anExtAlert->Attribute(); - if (anAttribute.IsNull()) - return TCollection_AsciiString(); - - TopoDS_Shape aShape; - if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) - aShape = Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape(); - - if (aShape.IsNull()) - return TCollection_AsciiString(); - - TopAbs_ShapeEnum aShapeType = aShape.ShapeType(); - Standard_SStream aSStream; - TopAbs::Print ((TopAbs_ShapeEnum)aShapeType, aSStream); - return aSStream.str().c_str(); -} - -// ======================================================================= -// function : GetStandardTypeAlertInfo -// purpose : -// ======================================================================= -TCollection_AsciiString MessageModel_Tools::GetStandardTypeAlertInfo (const Handle(Message_Alert)& theAlert) -{ - Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (theAlert); - if (anExtAlert.IsNull()) - return TCollection_AsciiString(); - - Handle(Message_Attribute) anAttribute = anExtAlert->Attribute(); - if (anAttribute.IsNull()) - return TCollection_AsciiString(); - - Handle(Standard_Transient) aPointer; - if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute))) - aPointer = Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape().TShape(); - else if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeObject))) - aPointer = Handle(Message_AttributeObject)::DownCast (anAttribute)->GetObject(); - - if (aPointer.IsNull()) - return TCollection_AsciiString(); - - return aPointer->DynamicType()->Name(); -} - -// ======================================================================= -// function : GetPropertyTableValues -// purpose : -// ======================================================================= -void MessageModel_Tools::GetPropertyTableValues (const TreeModel_ItemBasePtr& theItem, - QList& theTableValues) -{ - //Handle(TreeModel_ItemProperties) anItemProperties = theItem->GetProperties(); - //if (!anItemProperties.IsNull()) - //{ - // ViewControl_TableModelValues* aTableValues = new ViewControl_TableModelValues(); - // aTableValues->SetProperties (anItemProperties); - // theTableValues.append (aTableValues); - // return; - //} - - //MessageModel_ItemAlertPtr anAlertItem = itemDynamicCast(theItem); - //if (!anAlertItem) - // return; - - //const Handle(Message_Alert)& anAlert = anAlertItem->GetAlert(); - //Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(anAlert); - //if (anExtendedAlert.IsNull()) - // return; - - //Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute(); - //if (anAttribute.IsNull()) - // return; - - ////if (anAttribute->IsKind (STANDARD_TYPE (Message_AttributeStream))) - ////{ - // //int aSectionSize = 200; - // //ViewControl_TableModelValues* aTableValues = new MessageModel_TableModelValues (anAttribute, aSectionSize); - // //theTableValues.append (aTableValues); - ////} - ////else - ////{ - //if (!anAttribute->GetDescription().IsEmpty()) - //{ - // ViewControl_TableModelValuesDefault* aTableValues = new ViewControl_TableModelValuesDefault(); - // QList aHeaderValues; - // QVector aValues; - // aHeaderValues << TreeModel_HeaderSection ("Description", -2); - // aValues << anAttribute->GetDescription().ToCString(); - // aTableValues->SetHeaderValues (aHeaderValues, Qt::Horizontal); - - // QString aValueStr = anAttribute->GetDescription().ToCString(); - // QStringList aValueStrList = aValueStr.split ("\n"); - // int aNbRows = aValueStrList.size(); - - // QFontMetrics aFontMetrics (qApp->font()); - // int aHeight = aFontMetrics.boundingRect(aValueStr).height(); - // aHeight = (aHeight + TreeModel_Tools::HeaderSectionMargin()) * aNbRows; - // aTableValues->SetValues (aValues); - // aTableValues->SetDefaultSectionSize(Qt::Vertical, aHeight); - - // theTableValues.append (aTableValues); - //} - ////} -} diff --git a/tools/MessageModel/MessageModel_Tools.hxx b/tools/MessageModel/MessageModel_Tools.hxx index 15ff578375..c83922aed6 100644 --- a/tools/MessageModel/MessageModel_Tools.hxx +++ b/tools/MessageModel/MessageModel_Tools.hxx @@ -48,27 +48,6 @@ public: //! \return the string value Standard_EXPORT static TCollection_AsciiString GetPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo = true); - - //! Returns pointer alert information depening on type of alert (Transient_Object or TopoDS_TShape) - //! \param theAlert a message alert - //! \return text presentation - Standard_EXPORT static TCollection_AsciiString GetPointerAlertInfo (const Handle(Message_Alert)& theAlert); - - //! Returns TopoDS_Shape type alert information or empty string - //! \param theAlert a message alert - //! \return text presentation - Standard_EXPORT static TCollection_AsciiString GetShapeTypeAlertInfo (const Handle(Message_Alert)& theAlert); - - //! Returns dynamic type of an alert object/shape - //! \param theAlert a message alert - //! \return text presentation - Standard_EXPORT static TCollection_AsciiString GetStandardTypeAlertInfo (const Handle(Message_Alert)& theAlert); - - //! Fills container of table values - //! \param theAlert a message alert - //! \param theTableValue container of values - Standard_EXPORT static void GetPropertyTableValues (const TreeModel_ItemBasePtr& theItem, - QList& theTableValues); }; #endif diff --git a/tools/MessageModel/MessageModel_TreeModel.cxx b/tools/MessageModel/MessageModel_TreeModel.cxx index a994a4ed99..85b539817b 100644 --- a/tools/MessageModel/MessageModel_TreeModel.cxx +++ b/tools/MessageModel/MessageModel_TreeModel.cxx @@ -19,11 +19,10 @@ #include #include -const int COLUMN_NAME_WIDTH = 310; -const int COLUMN_SIZE_WIDTH = 30; -const int COLUMN_POINTER_WIDTH = 70; -const int COLUMN_SHAPE_TYPE_WIDTH = 75; -const int COLUMN_STANDARD_TYPE_WIDTH = 120; +#include + +const int COLUMN_REAL_VALUE_WIDTH = 115; +const int COLUMN_PERCENT_VALUE_WIDTH = 40; // ======================================================================= // function : Constructor @@ -32,33 +31,78 @@ const int COLUMN_STANDARD_TYPE_WIDTH = 120; MessageModel_TreeModel::MessageModel_TreeModel (QObject* theParent) : TreeModel_ModelBase (theParent), myIsReversed (Standard_False) { - SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); - SetHeaderItem (1, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH)); - SetHeaderItem (2, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); - SetHeaderItem (3, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH)); - - //SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); - // column 1 is reserved for visiblity state - //SetHeaderItem (2, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH)); - - SetHeaderItem (4, TreeModel_HeaderSection ("Metric", -1)); - SetHeaderItem (5, TreeModel_HeaderSection ("Difference", -1)); - - SetHeaderItem (6, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); - SetHeaderItem (7, TreeModel_HeaderSection ("Shape Type", COLUMN_SHAPE_TYPE_WIDTH)); - SetHeaderItem (8, TreeModel_HeaderSection ("Standard Type", COLUMN_STANDARD_TYPE_WIDTH)); - SetHeaderItem (9, TreeModel_HeaderSection ("Description", -1)); +} + +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void MessageModel_TreeModel::InitColumns() +{ + TreeModel_ModelBase::InitColumns(); + // 0 - Name, 1 - visibility, 2 - Row + + 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 ("%", COLUMN_PERCENT_VALUE_WIDTH)); + } +} + +// ======================================================================= +// function : GetMetricColumns +// purpose : +// ======================================================================= +void MessageModel_TreeModel::GetMetricColumns (const Message_MetricType theMetricType, QList& 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 : // ======================================================================= -void MessageModel_TreeModel::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr MessageModel_TreeModel::createRootItem (const int theColumnId) { - myRootItems.insert (theColumnId, MessageModel_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId)); - if (theColumnId == 0) - m_pRootItem = myRootItems[0]; + return MessageModel_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= @@ -112,6 +156,16 @@ void MessageModel_TreeModel::SetReport (const int theRowId, const Handle(Message EmitLayoutChanged(); } +// ======================================================================= +// function : Reports +// purpose : +// ======================================================================= +const NCollection_List& MessageModel_TreeModel::Reports() const +{ + MessageModel_ItemRootPtr aRootItem = itemDynamicCast (RootItem (0)); + return aRootItem->Reports(); +} + // ======================================================================= // function : SetReversed // purpose : diff --git a/tools/MessageModel/MessageModel_TreeModel.hxx b/tools/MessageModel/MessageModel_TreeModel.hxx index c4403a0c7f..01eeba4144 100644 --- a/tools/MessageModel/MessageModel_TreeModel.hxx +++ b/tools/MessageModel/MessageModel_TreeModel.hxx @@ -17,6 +17,7 @@ #define MessageModel_TreeModel_H #include +#include #include #include #include @@ -41,6 +42,21 @@ public: //! 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& 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 @@ -59,6 +75,9 @@ public: Standard_EXPORT void SetReport (const int theRowId, const Handle(Message_Report)& theReport, const TCollection_AsciiString& theReportDescription = ""); + //!< Returns processed reports + Standard_EXPORT const NCollection_List& 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); @@ -71,22 +90,15 @@ public: //! \theName visulized text of root item Standard_EXPORT void SetRootItemName (const TCollection_AsciiString& theName); - //! Returns root item by column - //! \param theColumn an index of the column - //! \return root item instance - virtual TreeModel_ItemBasePtr RootItem (const int theColumn) const Standard_OVERRIDE - { return myRootItems.contains (theColumn) ? myRootItems[theColumn] : TreeModel_ItemBasePtr(); } - //! Updates tree model Standard_EXPORT void UpdateTreeModel(); protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) Standard_OVERRIDE; + virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; private: - QMap myRootItems; //!< container of root items, for each column own root item Standard_Boolean myIsReversed; //!< state if the model is reversed }; diff --git a/tools/MessageModel/icons/item_streamValues.png b/tools/MessageModel/icons/item_streamValues.png new file mode 100644 index 0000000000..7181f9460e Binary files /dev/null and b/tools/MessageModel/icons/item_streamValues.png differ diff --git a/tools/MessageModel/icons/item_streamValues.svg b/tools/MessageModel/icons/item_streamValues.svg new file mode 100644 index 0000000000..38b1032701 --- /dev/null +++ b/tools/MessageModel/icons/item_streamValues.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/tools/MessageModel/icons/item_vectorOfReal.png b/tools/MessageModel/icons/item_vectorOfReal.png deleted file mode 100644 index 7181f9460e..0000000000 Binary files a/tools/MessageModel/icons/item_vectorOfReal.png and /dev/null differ diff --git a/tools/MessageModel/icons/item_vectorOfReal.svg b/tools/MessageModel/icons/item_vectorOfReal.svg deleted file mode 100644 index 38b1032701..0000000000 --- a/tools/MessageModel/icons/item_vectorOfReal.svg +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - diff --git a/tools/MessageModel/icons/item_vectorOfRealVec3.png b/tools/MessageModel/icons/item_vectorOfRealVec3.png deleted file mode 100644 index 4d0ebf93d9..0000000000 Binary files a/tools/MessageModel/icons/item_vectorOfRealVec3.png and /dev/null differ diff --git a/tools/MessageModel/icons/item_vectorOfRealVec3.svg b/tools/MessageModel/icons/item_vectorOfRealVec3.svg deleted file mode 100644 index 4d2d42b17f..0000000000 --- a/tools/MessageModel/icons/item_vectorOfRealVec3.svg +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - diff --git a/tools/MessageModel/icons/item_vectorOfValues.png b/tools/MessageModel/icons/item_vectorOfValues.png deleted file mode 100644 index 7181f9460e..0000000000 Binary files a/tools/MessageModel/icons/item_vectorOfValues.png and /dev/null differ diff --git a/tools/MessageModel/icons/item_vectorOfValues.svg b/tools/MessageModel/icons/item_vectorOfValues.svg deleted file mode 100644 index 38b1032701..0000000000 --- a/tools/MessageModel/icons/item_vectorOfValues.svg +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - diff --git a/tools/MessageView/FILES b/tools/MessageView/FILES index 529ec64718..5fe2f52661 100644 --- a/tools/MessageView/FILES +++ b/tools/MessageView/FILES @@ -1,3 +1,5 @@ +MessageView_ActionsTest.cxx +MessageView_ActionsTest.hxx MessageView_Communicator.cxx MessageView_Communicator.hxx MessageView_VisibilityState.cxx diff --git a/tools/MessageView/MessageView_ActionsTest.cxx b/tools/MessageView/MessageView_ActionsTest.cxx new file mode 100644 index 0000000000..76472fdf53 --- /dev/null +++ b/tools/MessageView/MessageView_ActionsTest.cxx @@ -0,0 +1,438 @@ +// 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 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_ALERTS + +#ifdef DEBUG_ALERTS +#include +#include +#endif + +#include + + +// ======================================================================= +// 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 ", SLOT (OnTestMetric()), parent(), this)); + myActions.insert (MessageModel_ActionType_TestProperties, + ViewControl_Tools::CreateAction ("Test ", SLOT (OnTestPropertyPanel()), parent(), this)); + myActions.insert (MessageModel_ActionType_TestMessenger, + ViewControl_Tools::CreateAction ("Test ", SLOT (OnTestMessenger()), parent(), this)); + myActions.insert (MessageModel_ActionType_TestReportTree, + ViewControl_Tools::CreateAction ("Test ", SLOT (OnTestReportTree()), 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 (anItemBase); + if (aRootItem) + break; + + aReportItem = itemDynamicCast (anItemBase); + if (aReportItem) + break; + + anAlertItem = itemDynamicCast (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]); + + 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); + } + 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 (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; + + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO ("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_INFO ("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; + + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO ("MessageModel_Actions::OnTestPropertyPanel()"); + + // gp_XYZ + { + gp_XYZ aCoords (1.3, 2.3, 3.4); + Standard_SStream aStream; + aCoords.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "gp_XYZ"); + } + // gp_Dir + { + gp_Dir aDir (0.3, 0.3, 0.4); + Standard_SStream aStream; + aDir.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "gp_Dir"); + } + // gp_Ax1 + { + gp_Ax1 aCoords (gp_Pnt (1.3, 2.3, 3.4), gp_Dir (0.3, 0.3, 0.4)); + Standard_SStream aStream; + aCoords.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "gp_Ax1"); + } + // gp_Ax2 + { + gp_Ax2 aCoords (gp_Pnt (10.3, 20.3, 30.4), gp_Dir (0.3, 0.3, 0.4)); + Standard_SStream aStream; + aCoords.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "gp_Ax2"); + } + // gp_Ax3 + { + gp_Ax3 aPln (gp_Pnt (10., 20., 15.), gp_Dir (0., 0., 1.), gp_Dir (1., 0., 0.)); + Standard_SStream aStream; + aPln.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "gp_Ax3"); + } + // gp_Trsf + { + gp_Trsf aTrsf; + aTrsf.SetRotation (gp::OZ(), 0.3); + aTrsf.SetTranslationPart (gp_Vec (15., 15., 15.)); + aTrsf.SetScaleFactor (3.); + + Standard_SStream aStream; + aTrsf.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "gp_Trsf"); + } + // Bnd_Box + { + Bnd_Box aBox (gp_Pnt (20., 15., 10.), gp_Pnt (25., 20., 15.)); + Standard_SStream aStream; + aBox.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "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.); + Standard_SStream aStream; + anOBB.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "Bnd_OBB"); + } + // Quantity_ColorRGBA + { + Quantity_ColorRGBA aColor (0.2f, 0.8f, 0.8f, 0.2f); + Standard_SStream aStream; + aColor.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "Quantity_ColorRGBA"); + } + // Quantity_Color + { + Quantity_Color aColor (0.8, 0.8, 0.8, Quantity_TOC_RGB); + Standard_SStream aStream; + aColor.DumpJson (aStream); + MESSAGE_INFO_STREAM(aStream, "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"); + + MESSAGE_INFO_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 : OnTestMessenger +// purpose : +// ======================================================================= +void MessageView_ActionsTest::OnTestMessenger() +{ + // string messages + const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger(); + + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO ("MessageModel_Actions::OnTestMessenger()"); + + aMessenger << "IGESBasic_Hierarchy" << Message_EndLine; + aMessenger << "Number of property valueaMessenger : " << 15 << Message_EndLine; + aMessenger << "Line Font : " << 1 << Message_EndLine << "View Number : " << 3 << Message_EndLine; + aMessenger << "Entity level : " << 1 << Message_EndLine; + aMessenger << "Blank statuaMessenger : " << 0 << Message_EndLine; + aMessenger << "Line weight : " << 14 << Message_EndLine; + aMessenger << "Color number : " << 5 << Message_EndLine; + + // stream messages + // gp_XYZ + { + gp_XYZ aCoords (1.3, 2.3, 3.4); + Standard_SStream aStream; + aCoords.DumpJson (aStream); + aMessenger << "gp_XYZ" << aStream << Message_EndLine; + } + // Bnd_Box + { + Bnd_Box aBox (gp_Pnt (20., 15., 10.), gp_Pnt (25., 20., 15.)); + Standard_SStream aStream; + aBox.DumpJson (aStream); + aMessenger << "Bnd_Box" << aStream; + } + + // object messages + Handle(Standard_Transient) anObject = new Message_AlertExtended(); + aMessenger << "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"); + + aMessenger << "Shape message edge" << aShape; + } + myTreeModel->UpdateTreeModel(); +} + +// ======================================================================= +// function : levelAlerts +// purpose : +// ======================================================================= +void levelAlerts (const int theCurrentLevel, const int theTopLevel) +{ + if (theTopLevel - theCurrentLevel <= 0) + return; + + MESSAGE_ADD_LEVEL_SENTRY + + const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger(); + aMessenger << "Level: " << theCurrentLevel << Message_EndLine; + aMessenger << "Alert: " << 1 << ", " << 2 << Message_EndLine; + aMessenger << "Alert: " << 3 << ", " << 4 << Message_EndLine; + + for (int i = 0; i < 2; i++) + levelAlerts (theCurrentLevel + 1, theTopLevel); + + aMessenger << "Alert: " << 4 << ", " << 5 << Message_EndLine; +} + +// ======================================================================= +// function : levelAlert +// purpose : +// ======================================================================= +void levelAlert (const int theCurrentLevel, const int theTopLevel) +{ + if (theTopLevel - theCurrentLevel <= 0) + return; + + MESSAGE_ADD_LEVEL_SENTRY + + const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger(); + aMessenger << "Level: " << theCurrentLevel << "(Single, no alerts on the level)" << Message_EndLine; + + for (int i = 0; i < 2; i++) + levelAlerts (theCurrentLevel + 1, theTopLevel); +} + +// ======================================================================= +// function : OnTestMessenger +// purpose : +// ======================================================================= +void MessageView_ActionsTest::OnTestReportTree() +{ + MESSAGE_ADD_LEVEL_SENTRY + MESSAGE_INFO ("MessageModel_Actions::OnTestReportTree()"); + + const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger(); + + // string messages + //aMessenger << "Alert: " << 1 << Message_EndLine; + //aMessenger << "Alert: " << 2 << Message_EndLine; + + int aTopLevel = 3; + levelAlerts (1, aTopLevel); + + //aMessenger << "Alert: " << 3 << Message_EndLine; + //levelAlerts (1, aTopLevel); + + aMessenger << "Alert: " << 4 << Message_EndLine; + levelAlert (1, aTopLevel); + + myTreeModel->UpdateTreeModel(); +} + diff --git a/tools/MessageView/MessageView_ActionsTest.hxx b/tools/MessageView/MessageView_ActionsTest.hxx new file mode 100644 index 0000000000..54943819e6 --- /dev/null +++ b/tools/MessageView/MessageView_ActionsTest.hxx @@ -0,0 +1,82 @@ +// 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 +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +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(); + +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 myActions; //!< container of all actions +}; + +#endif diff --git a/tools/MessageView/MessageView_Communicator.hxx b/tools/MessageView/MessageView_Communicator.hxx index 2164e2257b..7d93c21b55 100644 --- a/tools/MessageView/MessageView_Communicator.hxx +++ b/tools/MessageView/MessageView_Communicator.hxx @@ -16,7 +16,6 @@ #ifndef MessageView_Communicator_H #define MessageView_Communicator_H -#include #include #include @@ -27,8 +26,7 @@ class MessageView_Communicator : public TInspectorAPI_Communicator public: //! Constructor - MessageView_Communicator() : TInspectorAPI_Communicator(), myWindow (new MessageView_Window (0)) - { myWindow->SetCallBack (new MessageModel_ReportCallBack (this)); } + MessageView_Communicator() : TInspectorAPI_Communicator(), myWindow (new MessageView_Window (0)) {} //! Destructor virtual ~MessageView_Communicator() Standard_OVERRIDE {} diff --git a/tools/MessageView/MessageView_Window.cxx b/tools/MessageView/MessageView_Window.cxx index 14c000b7d6..fdc1cc8ece 100644 --- a/tools/MessageView/MessageView_Window.cxx +++ b/tools/MessageView/MessageView_Window.cxx @@ -15,12 +15,12 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -40,12 +40,12 @@ #include #include #include - #include #include - +#include #include -//#include + +#define DEBUG_ALERTS #include @@ -150,13 +150,8 @@ MessageView_Window::MessageView_Window (QWidget* theParent) ((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); - for (int i = 6; i <= 8; i++) // hide shape parameters columns - { - TreeModel_HeaderSection anItem = aModel->GetHeaderItem (i); - anItem.SetIsHidden (true); - aModel->SetHeaderItem (i, anItem); - } myTreeView->setModel (aModel); MessageView_VisibilityState* aVisibilityState = new MessageView_VisibilityState (aModel); @@ -172,10 +167,12 @@ MessageView_Window::MessageView_Window (QWidget* theParent) 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); + //new TreeModel_ContextMenu (myTreeView); QModelIndex aParentIndex = myTreeView->model()->index (0, 0); myTreeView->setExpanded (aParentIndex, true); @@ -209,6 +206,8 @@ MessageView_Window::MessageView_Window (QWidget* theParent) myMainWindow->resize (DEFAULT_SHAPE_VIEW_WIDTH, DEFAULT_SHAPE_VIEW_HEIGHT); myMainWindow->move (DEFAULT_SHAPE_VIEW_POSITION_X, DEFAULT_SHAPE_VIEW_POSITION_Y); + + updateVisibleColumns(); } // ======================================================================= @@ -257,7 +256,7 @@ void MessageView_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theIt theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str()); QMap anItems; - TreeModel_Tools::SaveState (myTreeView, anItems); + //TreeModel_Tools::SaveState (myTreeView, anItems); View_Tools::SaveState (myViewWindow, anItems); for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) @@ -280,8 +279,8 @@ void MessageView_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& { 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 (TreeModel_Tools::RestoreState (myTreeView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString())) + // continue; else if (View_Tools::RestoreState (myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString())) continue; } @@ -313,11 +312,10 @@ void MessageView_Window::UpdateContent() myParameters->SetFileNames (aName, aNames); isUpdated = true; } - Handle(Message_Report) aDefaultReport = Message_Report::CurrentReport( Standard_False); + Handle(Message_Report) aDefaultReport = Message::DefaultReport (Standard_False); MessageModel_TreeModel* aViewModel = dynamic_cast (myTreeView->model()); if (!aDefaultReport.IsNull() && !aViewModel->HasReport (aDefaultReport)) { - aDefaultReport->SetCallBack (myCallBack); addReport (aDefaultReport); } // reload report of selected item @@ -335,7 +333,6 @@ void MessageView_Window::Init (NCollection_List& the Handle(AIS_InteractiveContext) aContext; NCollection_List aParameters; - Handle(Message_ReportCallBack) aReportCallBack; Handle(Graphic3d_Camera) aViewCamera; for (NCollection_List::Iterator aParamsIt (theParameters); @@ -345,7 +342,6 @@ void MessageView_Window::Init (NCollection_List& the Handle(Message_Report) aMessageReport = Handle(Message_Report)::DownCast (anObject); if (!aMessageReport.IsNull()) { - aMessageReport->SetCallBack (myCallBack); addReport (aMessageReport); } else if (!Handle(AIS_InteractiveContext)::DownCast (anObject).IsNull()) @@ -368,7 +364,7 @@ void MessageView_Window::Init (NCollection_List& the if (!aContext.IsNull()) { myViewWindow->SetContext (View_ContextType_External, aContext); - myViewWindow->GetViewToolBar()->SetCurrentContextType (View_ContextType_External); + //myViewWindow->GetViewToolBar()->SetCurrentContextType (View_ContextType_External); } if (!aViewCamera.IsNull()) @@ -412,6 +408,8 @@ void MessageView_Window::addReport (const Handle(Message_Report)& theReport, { MessageModel_TreeModel* aModel = dynamic_cast (myTreeView->model()); aModel->AddReport (theReport, theReportDescription); + + updateVisibleColumns(); } // ======================================================================= @@ -492,7 +490,14 @@ void MessageView_Window::onTreeViewContextMenuRequested (const QPoint& thePositi } } 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); @@ -635,6 +640,9 @@ 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())); } @@ -663,7 +671,6 @@ void MessageView_Window::onSetReversedAlerts() aTreeModel->SetReversed (!isReversed); } - // ======================================================================= // function : onReloadReport // purpose : @@ -694,6 +701,65 @@ void MessageView_Window::onReloadReport() aTreeModel->SetReport (aReportItem->Row(), aReport, aDescription); } +// ======================================================================= +// 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& 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 : onContextSelected // purpose : @@ -784,3 +850,41 @@ void MessageView_Window::updatePreviewPresentation() myDisplayPreview->SetContext (aContext); myDisplayPreview->UpdatePreview (View_DisplayActionType_DisplayId, aPresentations); } + +// ======================================================================= +// function : updateVisibleColumns +// purpose : +// ======================================================================= +void MessageView_Window::updateVisibleColumns() +{ + MessageModel_TreeModel* aViewModel = dynamic_cast (myTreeView->model()); + const NCollection_List& aReports = aViewModel->Reports(); + + NCollection_Map anActiveMetrics; + for (NCollection_List::Iterator anIterator (aViewModel->Reports()); anIterator.More(); anIterator.Next()) + { + Handle(Message_Report) aReport = anIterator.Value().myReport; + for (NCollection_Map::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 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); + } + } +} diff --git a/tools/MessageView/MessageView_Window.hxx b/tools/MessageView/MessageView_Window.hxx index a602fe7e47..dbf98b78ed 100644 --- a/tools/MessageView/MessageView_Window.hxx +++ b/tools/MessageView/MessageView_Window.hxx @@ -42,10 +42,12 @@ class View_Window; class View_DisplayPreview; class ViewControl_PropertyView; -class MessageModel_ReportCallBack; + +class MessageView_ActionsTest; class QDockWidget; class QMainWindow; +class QMenu; class QWidget; //! \class MessageView_Window @@ -71,10 +73,6 @@ public: void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; myTreeViewActions->SetParameters (theParameters); } - //! Sets message callback to update the current content of the view - //! \param theCallBack - void SetCallBack (const Handle(Message_ReportCallBack)& theCallBack) { myCallBack = theCallBack; } - //! 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); @@ -161,16 +159,28 @@ protected slots: //! Reads if possible report of a selected item and updates this report in tree view void onReloadReport(); + //! Switch active state in report for clicked type of metric + void OnActivateMetric(); + + //! Deactivate all types of metrics for the current report + void OnDeactivateAllMetrics(); + //! Updates context in preview display void onContextSelected(); protected: + //! Appends items to activate report metrics + void addActivateMetricActions (QMenu* theMenu); + //! 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 @@ -183,9 +193,9 @@ private: 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(Message_ReportCallBack) myCallBack; //! < message call back to update content of the view Handle(AIS_InteractiveObject) myPreviewPresentation; //!< presentation of preview for a selected object }; diff --git a/tools/ShapeView/ShapeView_ItemBase.cxx b/tools/ShapeView/ShapeView_ItemBase.cxx index c660eab22b..81f3b1d351 100644 --- a/tools/ShapeView/ShapeView_ItemBase.cxx +++ b/tools/ShapeView/ShapeView_ItemBase.cxx @@ -14,22 +14,3 @@ // commercial license or contractual agreement. #include - -// ======================================================================= -// function : initValue -// purpose : -// ======================================================================= -QVariant ShapeView_ItemBase::initValue (const int theItemRole) const -{ - if (theItemRole != Qt::DisplayRole && theItemRole != Qt::ToolTipRole) - return QVariant(); - - switch (Column()) - { - case 2: { return rowCount(); } - //case 3: return ViewControl_Tools::GetPointerInfo (GetObject(), true).ToCString(); - case 4: { return Row(); } - } - - return QVariant(); -} diff --git a/tools/ShapeView/ShapeView_ItemBase.hxx b/tools/ShapeView/ShapeView_ItemBase.hxx index 27b09eb925..3e0559c501 100644 --- a/tools/ShapeView/ShapeView_ItemBase.hxx +++ b/tools/ShapeView/ShapeView_ItemBase.hxx @@ -32,11 +32,6 @@ public: //! Resets cached values virtual void Reset() Standard_OVERRIDE { TreeModel_ItemBase::Reset(); } - //! Return data value for the role. - //! \param theRole a value role - //! \return the value - Standard_EXPORT virtual QVariant initValue(const int theRole) const; - protected: //! Initialize the current item. It creates a backup of the specific item information diff --git a/tools/ShapeView/ShapeView_ItemShape.cxx b/tools/ShapeView/ShapeView_ItemShape.cxx index 1783cb5115..4dec90d239 100644 --- a/tools/ShapeView/ShapeView_ItemShape.cxx +++ b/tools/ShapeView/ShapeView_ItemShape.cxx @@ -81,10 +81,6 @@ QVariant ShapeView_ItemShape::initValue(const int theRole) const switch (Column()) { case 0: return TopAbs::ShapeTypeToString (aShape.ShapeType()); - //case 2: return rowCount() > 0 ? QVariant (rowCount()) : QVariant(); - case 3: return TShapePointer().ToCString(); - case 5: return TopAbs::ShapeOrientationToString (aShape.Orientation()); - case 6: return ViewControl_Tools::ToString (aShape.Location()).ToCString(); default: break; } return QVariant(); @@ -115,6 +111,19 @@ int ShapeView_ItemShape::initRowCount() const return aRowsCount; } +// ======================================================================= +// function : initStream +// purpose : +// ======================================================================= +void ShapeView_ItemShape::initStream (Standard_OStream& theOStream) const +{ + TopoDS_Shape aShape = getShape(); + if (aShape.IsNull()) + return; + + aShape.DumpJson (theOStream); +} + // ======================================================================= // function : createChild // purpose : @@ -135,6 +144,7 @@ void ShapeView_ItemShape::Init() myShape = aRootItem ? aRootItem->GetShape (Row()) : aShapeItem->GetShape (Row()); //SetProperties (createItemProperties()); + TreeModel_ItemBase::Init(); } // ======================================================================= diff --git a/tools/ShapeView/ShapeView_ItemShape.hxx b/tools/ShapeView/ShapeView_ItemShape.hxx index 24cbb8bd89..ce7871de94 100644 --- a/tools/ShapeView/ShapeView_ItemShape.hxx +++ b/tools/ShapeView/ShapeView_ItemShape.hxx @@ -91,6 +91,10 @@ public: //! \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 void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE; + protected: //! Initialize the current item. It is empty because Reset() is also empty. diff --git a/tools/ShapeView/ShapeView_TreeModel.cxx b/tools/ShapeView/ShapeView_TreeModel.cxx index 8b39f592cd..288b20c6a0 100644 --- a/tools/ShapeView/ShapeView_TreeModel.cxx +++ b/tools/ShapeView/ShapeView_TreeModel.cxx @@ -19,14 +19,6 @@ #include #include -const int COLUMN_NAME_WIDTH = 190; -const int COLUMN_SIZE_WIDTH = 30; -const int COLUMN_POINTER_WIDTH = 70; -const int COLUMN_SHAPE_TYPE_WIDTH = 75; - -const int COLUMN_ORIENTATION_WIDTH = 70; -const int COLUMN_LOCATION_WIDTH = 120; - // ======================================================================= // function : Constructor // purpose : @@ -34,24 +26,15 @@ const int COLUMN_LOCATION_WIDTH = 120; ShapeView_TreeModel::ShapeView_TreeModel (QObject* theParent) : TreeModel_ModelBase (theParent) { - SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); - // column 1 is reserved for visiblity state - SetHeaderItem (2, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH)); - SetHeaderItem (3, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); - SetHeaderItem (4, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH)); - SetHeaderItem (5, TreeModel_HeaderSection ("Orientation", COLUMN_ORIENTATION_WIDTH)); - SetHeaderItem (6, TreeModel_HeaderSection ("Location", COLUMN_LOCATION_WIDTH)); } // ======================================================================= // function : createRootItem // purpose : // ======================================================================= -void ShapeView_TreeModel::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr ShapeView_TreeModel::createRootItem (const int theColumnId) { - myRootItems.insert (theColumnId, ShapeView_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId)); - if (theColumnId == 0) - m_pRootItem = myRootItems[0]; + return ShapeView_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= diff --git a/tools/ShapeView/ShapeView_TreeModel.hxx b/tools/ShapeView/ShapeView_TreeModel.hxx index 7778ad535d..13954d5ea7 100644 --- a/tools/ShapeView/ShapeView_TreeModel.hxx +++ b/tools/ShapeView/ShapeView_TreeModel.hxx @@ -47,12 +47,6 @@ public: //! Remove all shapes in the model root item Standard_EXPORT void RemoveAllShapes(); - //! Returns root item by column - //! \param theColumn an index of the column - //! \return root item instance - virtual TreeModel_ItemBasePtr RootItem(const int theColumn) const Standard_OVERRIDE - { return myRootItems[theColumn]; } - //! Returns model index of the shape. //! \param theShape a shape object //! \return the model index @@ -61,10 +55,8 @@ public: protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) Standard_OVERRIDE; + virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; -private: - QMap myRootItems; //!< container of root items, for each column own root item }; #endif diff --git a/tools/ShapeView/ShapeView_Window.cxx b/tools/ShapeView/ShapeView_Window.cxx index 9d4ec97dfd..1e19a0e494 100644 --- a/tools/ShapeView/ShapeView_Window.cxx +++ b/tools/ShapeView/ShapeView_Window.cxx @@ -63,6 +63,9 @@ #include #include +#include +#include + const int DEFAULT_TEXT_VIEW_WIDTH = 800; const int DEFAULT_TEXT_VIEW_HEIGHT = 700; const int DEFAULT_TEXT_VIEW_POSITION_X = 430; @@ -85,7 +88,7 @@ const int SHAPEVIEW_DEFAULT_VIEW_HEIGHT = 1000; // purpose : // ======================================================================= ShapeView_Window::ShapeView_Window (QWidget* theParent) -: QObject (theParent), myNextPosition (0) +: QObject (theParent) { myMainWindow = new QMainWindow (theParent); @@ -97,13 +100,7 @@ ShapeView_Window::ShapeView_Window (QWidget* theParent) this, SLOT (onTreeViewContextMenuRequested (const QPoint&))); new TreeModel_ContextMenu (myTreeView); ShapeView_TreeModel* aModel = new ShapeView_TreeModel (myTreeView); - for (int i = 5; i <= 6; i++) // hide shape parameters columns - { - TreeModel_HeaderSection anItem = aModel->GetHeaderItem (i); - anItem.SetIsHidden (true); - aModel->SetHeaderItem (i, anItem); - } - + aModel->InitColumns(); myTreeView->setModel (aModel); ShapeView_VisibilityState* aVisibilityState = new ShapeView_VisibilityState (aModel); @@ -153,7 +150,6 @@ ShapeView_Window::ShapeView_Window (QWidget* theParent) // ======================================================================= ShapeView_Window::~ShapeView_Window() { - onCloseAllBREPViews(); } // ======================================================================= @@ -341,8 +337,6 @@ void ShapeView_Window::RemoveAllShapes() { ShapeView_TreeModel* aModel = dynamic_cast (myTreeView->model()); aModel->RemoveAllShapes(); - - onCloseAllBREPViews(); } // ======================================================================= @@ -377,10 +371,7 @@ void ShapeView_Window::onTreeViewContextMenuRequested (const QPoint& thePosition aMenu->addAction (ViewControl_Tools::CreateAction ("Remove all shape items", SLOT (onClearView()), myMainWindow, this)); } else { - if (!GetTemporaryDirectory().IsEmpty()) - aMenu->addAction (ViewControl_Tools::CreateAction ("BREP view", SLOT (onBREPView()), myMainWindow, this)); - aMenu->addAction (ViewControl_Tools::CreateAction ("Close All BREP views", SLOT (onCloseAllBREPViews()), myMainWindow, this)); - aMenu->addAction (ViewControl_Tools::CreateAction ("BREP directory", SLOT (onBREPDirectory()), myMainWindow, this)); + aMenu->addAction (ViewControl_Tools::CreateAction ("Export to BREP", SLOT (onExportToBREP()), myMainWindow, this)); aMenu->addAction (ViewControl_Tools::CreateAction ("ShapeFix_Shape", SLOT (onShapeFixShape()), myMainWindow, this)); ShapeView_ItemShapePtr aShapeItem = itemDynamicCast(anItemBase); @@ -443,20 +434,6 @@ void ShapeView_Window::onEraseAllPerformed() aTreeModel->EmitLayoutChanged(); } -// ======================================================================= -// function : onBREPDirectory -// purpose : -// ======================================================================= -void ShapeView_Window::onBREPDirectory() -{ - QString aFilter (tr ("BREP file (*.brep*)")); - QString aSelectedFilter; - QString aFileName = QFileDialog::getOpenFileName (0, tr ("Export shape to BREP file"), - GetTemporaryDirectory().ToCString(), aSelectedFilter); - if (!aFileName.isEmpty()) - viewFile (aFileName); -} - // ======================================================================= // function : onExplode // purpose : @@ -483,6 +460,7 @@ void ShapeView_Window::onShapeFixShape() Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape (aShape); Fixer->SetPrecision (LinTol); Fixer->SetMaxTolerance (LinTol); + Fixer->Perform(); TopoDS_Shape aFixedShape = Fixer->Shape(); @@ -548,13 +526,14 @@ void ShapeView_Window::onLoadFile() } // ======================================================================= -// function : onBREPView +// function : onExportToBREP // purpose : // ======================================================================= -void ShapeView_Window::onBREPView() +void ShapeView_Window::onExportToBREP() { - if (GetTemporaryDirectory().IsEmpty()) - return; + QString aFilter (tr ("Boundary representation file (*.brep *)")); + QString aSelectedFilter; + QString aFileName = QFileDialog::getSaveFileName (0, tr ("Export shape to file"), QString(), aFilter, &aSelectedFilter); QItemSelectionModel* aModel = myTreeView->selectionModel(); if (!aModel) @@ -573,90 +552,36 @@ void ShapeView_Window::onBREPView() if (!anItem) return; - QString aFileName = anItem->GetFileName(); - QDir aDir; - if (aFileName.isEmpty() || !aDir.exists (aFileName)) - { - TCollection_AsciiString aFileNameIndiced = GetTemporaryDirectory() + TCollection_AsciiString ("\\") + - getNextTmpName (anItem->TShapePointer()); - const TopoDS_Shape& aShape = anItem->GetItemShape(); - BRepTools::Write (aShape, aFileNameIndiced.ToCString()); - anItem->SetFileName (aFileNameIndiced.ToCString()); - aFileName = aFileNameIndiced.ToCString(); - } - viewFile (aFileName); -} - -// ======================================================================= -// function : onCloseAllBREPViews -// purpose : -// ======================================================================= -void ShapeView_Window::onCloseAllBREPViews() -{ - removeBREPFiles(); - - for (int aViewId = myBREPViews.size()-1; aViewId >= 0; aViewId--) - delete myBREPViews[aViewId]; - - myBREPViews.clear(); + TCollection_AsciiString aFileNameIndiced = aFileName.toStdString().c_str(); + const TopoDS_Shape& aShape = anItem->GetItemShape(); + BRepTools::Write (aShape, aFileNameIndiced.ToCString()); + anItem->SetFileName (aFileNameIndiced.ToCString()); + aFileName = aFileNameIndiced.ToCString(); } // ======================================================================= -// function : onEditorDestroyed +// function : updatePropertyPanelBySelection // purpose : // ======================================================================= -void ShapeView_Window::onEditorDestroyed(QObject* theObject) +void ShapeView_Window::updatePropertyPanelBySelection() { - QWidget* aWidget = dynamic_cast (theObject); + QItemSelectionModel* aModel = myTreeView->selectionModel(); + if (!aModel) + return; - for (int aViewId = myBREPViews.size()-1; aViewId >= 0; aViewId--) - { - if (myBREPViews[aViewId] == aWidget) - myBREPViews.removeAll(aWidget); - } -} + QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0); + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); + if (!anItemBase) + return; -// ======================================================================= -// function : viewFile -// purpose : -// ======================================================================= -void ShapeView_Window::viewFile (const QString& theFileName) -{ - QApplication::setOverrideCursor (Qt::WaitCursor); - QString aFileText; - QFile aFile (theFileName); - if (aFile.open (QIODevice::ReadOnly | QIODevice::Text)) + Handle(TreeModel_ItemProperties) anItemProperties = anItemBase->Properties (); + ViewControl_TableModelValues* aTableValues = 0; + if (!anItemProperties.IsNull()) { - QTextStream aStream(&aFile); - QString aLine = aStream.readLine(); - while (!aLine.isNull()) - { - aLine = aStream.readLine(); - aFileText.append (aLine + QString ("\n")); - } - if (!aFileText.isEmpty()) - { - QPlainTextEdit* anEditor = new QPlainTextEdit (0); - anEditor->setAttribute (Qt::WA_DeleteOnClose, true); - connect (anEditor, SIGNAL (destroyed(QObject*)), this, SLOT (onEditorDestroyed(QObject*))); - anEditor->setPlainText (aFileText); - anEditor->resize (DEFAULT_TEXT_VIEW_WIDTH, DEFAULT_TEXT_VIEW_HEIGHT); - anEditor->move (DEFAULT_TEXT_VIEW_POSITION_X + myNextPosition, DEFAULT_TEXT_VIEW_POSITION_Y); - myNextPosition += DEFAULT_TEXT_VIEW_DELTA; - anEditor->show(); - myBREPViews.append (anEditor); - } + aTableValues = new ViewControl_TableModelValues(); + aTableValues->SetProperties (anItemProperties); } - QApplication::restoreOverrideCursor(); -} - - -// ======================================================================= -// function : updatePropertyPanelBySelection -// purpose : -// ======================================================================= -void ShapeView_Window::updatePropertyPanelBySelection() -{ + myPropertyView->Init (aTableValues); /*QItemSelectionModel* aModel = myTreeView->selectionModel(); if (!aModel) return; @@ -671,31 +596,3 @@ void ShapeView_Window::updatePropertyPanelBySelection() } myPropertyView->Init (aTableValues);*/ } - -// ======================================================================= -// function : removeBREPFiles -// purpose : -// ======================================================================= -void ShapeView_Window::removeBREPFiles() -{ - QDir aDir (GetTemporaryDirectory().ToCString()); - - QStringList anEntries = aDir.entryList(); - QString aPrefix(viewBREPPrefix().ToCString()); - for (int anEntryId = 0, aSize = anEntries.size(); anEntryId < aSize; anEntryId++) - { - if (anEntries[anEntryId].contains (aPrefix)) - aDir.remove (anEntries[anEntryId]); - } -} - -// ======================================================================= -// function : getNextTmpName -// purpose : -// ======================================================================= -TCollection_AsciiString ShapeView_Window::getNextTmpName (const TCollection_AsciiString& thePointerInfo) -{ - TCollection_AsciiString aTmpName(viewBREPPrefix()); - aTmpName += thePointerInfo; - return aTmpName; -} diff --git a/tools/ShapeView/ShapeView_Window.hxx b/tools/ShapeView/ShapeView_Window.hxx index 4ff8cd245f..d022a98a23 100644 --- a/tools/ShapeView/ShapeView_Window.hxx +++ b/tools/ShapeView/ShapeView_Window.hxx @@ -83,9 +83,6 @@ public: //! Returns current tree view QTreeView* GetTreeView() const { return myTreeView; } - //! Returns path to temporary directory - TCollection_AsciiString GetTemporaryDirectory() const { return myParameters->GetTemporaryDirectory(); } - //! Removes all shapes in tree view model, remove all stored BREP files Standard_EXPORT void RemoveAllShapes(); @@ -120,9 +117,6 @@ protected slots: //! Updates visibility states by erase all in context void onEraseAllPerformed(); - //! Exports shape to BREP file and view result file - void onBREPDirectory(); - //! Perform shape fix for the selected shape. Result is a new shape in the tree. void onShapeFixShape(); @@ -136,13 +130,7 @@ protected slots: void onLoadFile(); //! View BREP files of selected items if exist - void onBREPView(); - - //! Remove BREP views, close views - void onCloseAllBREPViews(); - - //! Remove all BREP Viewse excepting active - void onEditorDestroyed (QObject* theObject); + void onExportToBREP(); //! Convers file name to Ascii String and perform opeging file //! \param theFileName a file name to be opened @@ -153,27 +141,11 @@ protected: //! Updates property panel content by item selected in tree view. void updatePropertyPanelBySelection(); - //! Views file name content in a text editor. It creates new Qt free control with content. - //! \param theFileName a file name - void viewFile (const QString& theFileName); - - //! Removes all BREP files in tmp directory - void removeBREPFiles(); - //! Creates new action and connect it to the given slot //! \param theText an action text //! \param theSlot a listener method QAction* createAction (const QString& theText, const char* theSlot); - //! Key that uses to generate BREP file name - //! \return string value - static TCollection_AsciiString viewBREPPrefix() { return "ShapeView_Window"; } - - //! Returns newxt temporary name using BREPPrefix and pointer information - //! \param thePointerInfo a pointer value - //! \return string value - TCollection_AsciiString getNextTmpName (const TCollection_AsciiString& thePointerInfo); - private: QMainWindow* myMainWindow; //!< main control, parent for all ShapeView controls @@ -184,9 +156,6 @@ private: View_Window* myViewWindow; //!< OCC 3d view to visualize presentations QTreeView* myTreeView; //!< tree view visualized shapes - int myNextPosition; //!< delta of moving control of view BREP file - - QList myBREPViews; //!< list of view BREP file controls Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container }; diff --git a/tools/TInspectorEXE/TInspectorEXE.cxx b/tools/TInspectorEXE/TInspectorEXE.cxx index 1c42a38530..14050121ae 100644 --- a/tools/TInspectorEXE/TInspectorEXE.cxx +++ b/tools/TInspectorEXE/TInspectorEXE.cxx @@ -18,6 +18,7 @@ #include +#include #include #include @@ -126,9 +127,8 @@ int main (int argc, char** argv) aPlugins.insert("TKShapeView"); aPlugins.insert("TKVInspector"); - Handle(Message_Report) aReport = Message_Report::CurrentReport (Standard_True); + Handle(Message_Report) aReport = Message::DefaultReport (Standard_True); aReport->SetLimit (100);//30); - aReport->SetActive (Standard_True);//Standard_False); aPlugins.insert("TKMessageView"); anActivatedPluginName = "TKVInspector"; diff --git a/tools/TreeModel/TreeModel_ItemBase.cxx b/tools/TreeModel/TreeModel_ItemBase.cxx index 31b62c871e..58ca97a084 100644 --- a/tools/TreeModel/TreeModel_ItemBase.cxx +++ b/tools/TreeModel/TreeModel_ItemBase.cxx @@ -192,9 +192,7 @@ QVariant TreeModel_ItemBase::initValue (const int theItemRole) const switch (Column()) { - case 1: { return rowCount(); } - //case 2: return ViewControl_Tools::GetPointerInfo (GetObject(), true).ToCString(); - case 3: { return Row(); } + case 1: { return Row(); } } return QVariant(); diff --git a/tools/TreeModel/TreeModel_ModelBase.cxx b/tools/TreeModel/TreeModel_ModelBase.cxx index 9a2d40fd6b..5046417492 100644 --- a/tools/TreeModel/TreeModel_ModelBase.cxx +++ b/tools/TreeModel/TreeModel_ModelBase.cxx @@ -25,18 +25,32 @@ #include #include +const int COLUMN_NAME_WIDTH = 260; +const int COLUMN_SIZE_WIDTH = 30; + // ======================================================================= // function : Constructor // purpose : // ======================================================================= TreeModel_ModelBase::TreeModel_ModelBase (QObject* theParent) -: QAbstractItemModel (theParent), m_pRootItem (0), m_pUseVisibilityColumn (false), +: QAbstractItemModel (theParent), m_pUseVisibilityColumn (false), myVisibilityState (0) { myVisibleIcon = QIcon (":/icons/item_visible.png"); myInvisibleIcon = QIcon (":/icons/item_invisible.png"); } +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +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)); +} + // ======================================================================= // function : GetItemByIndex // purpose : @@ -217,6 +231,23 @@ void TreeModel_ModelBase::EmitDataChanged (const QModelIndex& theTopLeft, const #endif } +// ======================================================================= +// function : GetSelected +// purpose : +// ======================================================================= +void TreeModel_ModelBase::SetHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection) +{ + if (theSection.IsEmpty()) + { + // remove section + myHeaderValues.remove (theColumnId); + myRootItems.remove (theColumnId); + } + + myHeaderValues[theColumnId] = theSection; + createRoot (theColumnId); +} + // ======================================================================= // function : GetSelected // purpose : @@ -264,6 +295,15 @@ QList TreeModel_ModelBase::GetSelectedItems (const QModel return anItems; } +// ======================================================================= +// function : createRoot +// purpose : +// ======================================================================= +void TreeModel_ModelBase::createRoot (const int theColumnId) +{ + myRootItems.insert (theColumnId, createRootItem (theColumnId)); +} + // ======================================================================= // function : getIndexValue // purpose : diff --git a/tools/TreeModel/TreeModel_ModelBase.hxx b/tools/TreeModel/TreeModel_ModelBase.hxx index f38b266f5c..8042fc7c6e 100644 --- a/tools/TreeModel/TreeModel_ModelBase.hxx +++ b/tools/TreeModel/TreeModel_ModelBase.hxx @@ -50,6 +50,10 @@ public: //! Destructor virtual ~TreeModel_ModelBase() {} + //! Creates model columns and root items. + //! Default columns are: [0] - Name, [1] - Visibility, [2] - Row + Standard_EXPORT virtual void InitColumns(); + //! Returns the item shared pointer by the model index //! if it is in the index internal pointer //! @param theIndex a model index @@ -61,7 +65,7 @@ public: //! Returns the model root item. //! It is realized for OCAFBrowser - virtual TreeModel_ItemBasePtr RootItem (const int theColumn) const { (void)theColumn; return m_pRootItem; } + TreeModel_ItemBasePtr RootItem (const int theColumn) const { return myRootItems[theColumn]; } //! Emits the layoutChanged signal from outside of this class Standard_EXPORT void EmitLayoutChanged(); @@ -142,8 +146,7 @@ public: //! Set header properties item. //! \param theColumnId a column index //! \param theSection a section value - void SetHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection) - { myHeaderValues[theColumnId] = theSection; createRootItem (theColumnId); } + Standard_EXPORT void SetHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection); //! Returns count of columns in the model //! \param theParent an index of the parent item @@ -181,16 +184,21 @@ public: protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) = 0; + virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) = 0; //! Converts the item shared pointer to void* type //! \param theItem //! \return an item pointer Standard_EXPORT static void* getIndexValue (const TreeModel_ItemBasePtr& theItem); +private: + //! Creates root item + //! \param theColumnId index of a column + Standard_EXPORT void createRoot (const int theColumnId); + protected: - TreeModel_ItemBasePtr m_pRootItem; //!< the model root item. It should be created in the + QMap myRootItems; //!< container of root items, for each column own root item QMap myHeaderValues; //!< header values //!< model subclass. The model is fulfilled by this item content diff --git a/tools/VInspector/VInspector_ItemBase.cxx b/tools/VInspector/VInspector_ItemBase.cxx index 56158a4018..f3aed4ba2e 100644 --- a/tools/VInspector/VInspector_ItemBase.cxx +++ b/tools/VInspector/VInspector_ItemBase.cxx @@ -40,9 +40,7 @@ QVariant VInspector_ItemBase::initValue (const int theItemRole) const switch (Column()) { - case 1: { return rowCount(); } - case 2: return ViewControl_Tools::GetPointerInfo (GetObject(), true).ToCString(); - case 3: { return Row(); } + case 3: return ViewControl_Tools::GetPointerInfo (GetObject(), true).ToCString(); } return QVariant(); diff --git a/tools/VInspector/VInspector_ItemContext.cxx b/tools/VInspector/VInspector_ItemContext.cxx index 57445893a3..36d4817978 100644 --- a/tools/VInspector/VInspector_ItemContext.cxx +++ b/tools/VInspector/VInspector_ItemContext.cxx @@ -26,8 +26,6 @@ #include #include -//#define DEBUG_FREE_OWNERS - // ======================================================================= // function : initRowCount // purpose : @@ -39,7 +37,6 @@ int VInspector_ItemContext::initRowCount() const int aNbProperties = 1; // item to visualize Filters/Drawer information of context - int aNbPresentations = 0; Handle(AIS_InteractiveContext) aContext = Handle(AIS_InteractiveContext)::DownCast (GetObject()); if (aContext.IsNull()) return 0; @@ -47,37 +44,14 @@ int VInspector_ItemContext::initRowCount() const AIS_ListOfInteractive aListOfIO; aContext->DisplayedObjects (aListOfIO); aContext->ErasedObjects(aListOfIO); - aNbPresentations = aListOfIO.Extent(); - - // owners without Presentation -#ifdef DEBUG_FREE_OWNERS - int aRows = 0; - // only local context is processed: TODO for global context - NCollection_List anActiveOwners; - aContext->MainSelector()->ActiveOwners(anActiveOwners); - - Handle(SelectMgr_EntityOwner) anOwner; - for (NCollection_List::Iterator anOwnersIt(anActiveOwners); - anOwnersIt.More(); anOwnersIt.Next()) + int aNbPresentations = 0; + for (AIS_ListIteratorOfListOfInteractive aListOfIOIt (aListOfIO); aListOfIOIt.More(); aListOfIOIt.Next()) { - anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value()); - if (anOwner.IsNull()) - continue; - Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable()); - if (anAISObj.IsNull()) - aRows++; + if (aListOfIOIt.Value()->Parent()) + continue; // child presentation + aNbPresentations++; } - // owners in Global Context - NCollection_List anActiveOwners; - aContext->MainSelector()->ActiveOwners(anActiveOwners); - if (aRows > 0) - aNbPresentations += aRows; - NCollection_List anEmptySelectableOwners; - NCollection_List anOwners = - VInspector_Tools::ActiveOwners (aContext, anEmptySelectableOwners); - if (anEmptySelectableOwners.Size() > 0) - aNbPresentations += 1; -#endif + return aNbProperties + aNbPresentations; } diff --git a/tools/VInspector/VInspector_ViewModel.cxx b/tools/VInspector/VInspector_ViewModel.cxx index 3bc538d87c..dfdc713b6d 100644 --- a/tools/VInspector/VInspector_ViewModel.cxx +++ b/tools/VInspector/VInspector_ViewModel.cxx @@ -30,10 +30,7 @@ #include #include -const int COLUMN_NAME_WIDTH = 260; -const int COLUMN_SIZE_WIDTH = 30; const int COLUMN_POINTER_WIDTH = 70; -const int COLUMN_SHAPE_TYPE_WIDTH = 75; // ======================================================================= // function : Constructor @@ -42,44 +39,27 @@ const int COLUMN_SHAPE_TYPE_WIDTH = 75; VInspector_ViewModel::VInspector_ViewModel (QObject* theParent) : TreeModel_ModelBase (theParent) { - SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); - SetHeaderItem (1, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH)); - SetHeaderItem (2, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); - SetHeaderItem (3, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH)); - SetHeaderItem (4, TreeModel_HeaderSection ("SelectedOwners", -1)); // ItemContext, ItemPresentableObject, ItemSelection - //SetHeaderItem (5, TreeModel_HeaderSection ("ActivatedModes", -1)); // ItemPresentableObject - //SetHeaderItem (6, TreeModel_HeaderSection ("DeviationCoefficient", -1, true)); // ItemContext, ItemPresentableObject - //SetHeaderItem (7, TreeModel_HeaderSection ("Deflection", -1, true)); // ItemPresentableObject - //SetHeaderItem (8, TreeModel_HeaderSection ("IsAutoTriangulation", -1, true)); // ItemPresentableObject - - //SetHeaderItem (9, TreeModel_HeaderSection ("SelectionState", -1)); // ItemSelection - //SetHeaderItem (10, TreeModel_HeaderSection ("Sensitivity", -1, true)); // ItemSelection - //SetHeaderItem (11, TreeModel_HeaderSection ("UpdateStatus", -1, true)); // ItemSelection - //SetHeaderItem (12, TreeModel_HeaderSection ("BVHUpdateStatus", -1, true)); // ItemSelection - - //SetHeaderItem (13, TreeModel_HeaderSection ("IsActiveForSelection", -1, true)); // ItemSensitiveEntity - //SetHeaderItem (14, TreeModel_HeaderSection ("SensitivityFactor", -1, true)); // ItemSensitiveEntity - //SetHeaderItem (15, TreeModel_HeaderSection ("NbSubElements", -1, true)); // ItemSensitiveEntity - //SetHeaderItem (16, TreeModel_HeaderSection ("Priority", -1, true)); // ItemSensitiveEntity - - //SetHeaderItem (17, TreeModel_HeaderSection ("TShape", COLUMN_POINTER_WIDTH, true)); // ItemEntityOwner - //SetHeaderItem (18, TreeModel_HeaderSection ("Orientation", -1, true)); // ItemEntityOwner - //SetHeaderItem (19, TreeModel_HeaderSection ("Location", -1, true)); // ItemEntityOwner - - //SetHeaderItem (20, TreeModel_HeaderSection ("Color", -1)); // ItemPresentableObject - - //SetHeaderItem (21, TreeModel_HeaderSection ("Owner Location", -1, true)); // ItemEntityOwner +} + +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void VInspector_ViewModel::InitColumns() +{ + TreeModel_ModelBase::InitColumns(); + + SetHeaderItem (3, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); + SetHeaderItem (4, TreeModel_HeaderSection ("SelectedOwners", -1)); } // ======================================================================= // function : createRootItem // purpose : // ======================================================================= -void VInspector_ViewModel::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr VInspector_ViewModel::createRootItem (const int theColumnId) { - myRootItems.insert (theColumnId, VInspector_ItemContext::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId)); - if (theColumnId == 0) - m_pRootItem = myRootItems[0]; + return VInspector_ItemContext::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= diff --git a/tools/VInspector/VInspector_ViewModel.hxx b/tools/VInspector/VInspector_ViewModel.hxx index 55bbecf996..13873bda01 100644 --- a/tools/VInspector/VInspector_ViewModel.hxx +++ b/tools/VInspector/VInspector_ViewModel.hxx @@ -49,6 +49,9 @@ public: //! Destructor virtual ~VInspector_ViewModel() Standard_OVERRIDE {}; + //! Creates model columns and root items. + Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; + //! Initialize the model by the given context //! \param theContext viewer context Standard_EXPORT Handle(AIS_InteractiveContext) GetContext() const; @@ -70,12 +73,6 @@ public: //! \return model index if the value is found or Null model index Standard_EXPORT QModelIndex FindIndex (const Handle(AIS_InteractiveObject)& thePresentation) const; - //! Returns root item by column - //! \param theColumn an index of the column - //! \return root item instance - virtual TreeModel_ItemBasePtr RootItem (const int theColumn) const Standard_OVERRIDE - { return myRootItems[theColumn]; } - //! Returns select owners for tree view selected items //! \param theSelectionModel a selection model //! \param theOwners an output list of owners @@ -86,14 +83,10 @@ public: Standard_EXPORT void UpdateTreeModel(); protected: - //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) Standard_OVERRIDE; - -private: + virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; - QMap myRootItems; //!< container of root items, for each column own root item }; #endif diff --git a/tools/VInspector/VInspector_ViewModelHistory.cxx b/tools/VInspector/VInspector_ViewModelHistory.cxx index a8f584ef15..980dc1e865 100644 --- a/tools/VInspector/VInspector_ViewModelHistory.cxx +++ b/tools/VInspector/VInspector_ViewModelHistory.cxx @@ -42,8 +42,18 @@ const int HISTORY_AIS_NAME_COLUMN_WIDTH = 140; // purpose : // ======================================================================= VInspector_ViewModelHistory::VInspector_ViewModelHistory (QObject* theParent, const int theHistoryTypesMaxAmount) -: TreeModel_ModelBase (theParent) +: TreeModel_ModelBase (theParent), myHistoryTypesMaxAmount (theHistoryTypesMaxAmount) { +} + +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void VInspector_ViewModelHistory::InitColumns() +{ + TreeModel_ModelBase::InitColumns(); + SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); SetHeaderItem (1, TreeModel_HeaderSection ("Visibility", COLUMN_SIZE_WIDTH)); // visualization item SetHeaderItem (2, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH)); @@ -55,20 +65,17 @@ VInspector_ViewModelHistory::VInspector_ViewModelHistory (QObject* theParent, co for (int aColumnId = 0, aNbColumns = columnCount(); aColumnId < aNbColumns; aColumnId++) { VInspector_ItemHistoryRootPtr aRootItem = itemDynamicCast (myRootItems[aColumnId]); - aRootItem->SetHistoryTypesMaxAmount (theHistoryTypesMaxAmount); + aRootItem->SetHistoryTypesMaxAmount (myHistoryTypesMaxAmount); } } - // ======================================================================= // function : createRootItem // purpose : // ======================================================================= -void VInspector_ViewModelHistory::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr VInspector_ViewModelHistory::createRootItem (const int theColumnId) { - myRootItems.insert (theColumnId, VInspector_ItemHistoryRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId)); - if (theColumnId == 0) - m_pRootItem = myRootItems[0]; + return VInspector_ItemHistoryRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= diff --git a/tools/VInspector/VInspector_ViewModelHistory.hxx b/tools/VInspector/VInspector_ViewModelHistory.hxx index d4215c3475..2560246f70 100644 --- a/tools/VInspector/VInspector_ViewModelHistory.hxx +++ b/tools/VInspector/VInspector_ViewModelHistory.hxx @@ -43,6 +43,9 @@ public: //! Destructor virtual ~VInspector_ViewModelHistory() Standard_OVERRIDE {}; + //! Creates model columns and root items. + Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; + //! Append new element under the root item Standard_EXPORT void AddElement (const VInspector_CallBackMode& theMode, const QList& theInfo); @@ -51,20 +54,14 @@ public: //! \param container of strings Standard_EXPORT QStringList GetSelectedPointers (const QModelIndex& theIndex); - //! Returns root item by column - //! \param theColumn an index of the column - //! \return root item instance - virtual TreeModel_ItemBasePtr RootItem(const int theColumn) const Standard_OVERRIDE { return myRootItems[theColumn]; } - protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) Standard_OVERRIDE; + virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; private: - - QMap myRootItems; //!< container of root items, for each column own root item + int myHistoryTypesMaxAmount; //!< maximum types in history }; #endif diff --git a/tools/VInspector/VInspector_Window.cxx b/tools/VInspector/VInspector_Window.cxx index 4d813c729f..3eb75f1601 100644 --- a/tools/VInspector/VInspector_Window.cxx +++ b/tools/VInspector/VInspector_Window.cxx @@ -19,7 +19,7 @@ #include #include //#include -//#include +#include //#include //#include #include @@ -77,6 +77,8 @@ #include #include +#define DEBUG_ALERTS + const int VINSPECTOR_DEFAULT_PROPERTY_VIEW_WIDTH = 300;//600; const int VINSPECTOR_DEFAULT_PROPERTY_VIEW_HEIGHT = 1000; @@ -125,6 +127,7 @@ VInspector_Window::VInspector_Window() //((ViewControl_TreeView*)myTreeView)->SetPredefinedSize (QSize (VINSPECTOR_DEFAULT_TREE_VIEW_WIDTH, // VINSPECTOR_DEFAULT_TREE_VIEW_HEIGHT)); VInspector_ViewModel* aTreeModel = new VInspector_ViewModel (myTreeView); + aTreeModel->InitColumns(); //aTreeModel->AddPropertiesCreator(new VInspector_PropertiesCreator()); myTreeView->setModel (aTreeModel); // hide Visibility column @@ -166,6 +169,7 @@ VInspector_Window::VInspector_Window() myHistoryView->setSelectionMode (QAbstractItemView::ExtendedSelection); VInspector_ViewModelHistory* aHistoryModel = new VInspector_ViewModelHistory (myHistoryView); + aHistoryModel->InitColumns(); myHistoryView->setModel (aHistoryModel); QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aHistoryModel); @@ -700,6 +704,11 @@ void VInspector_Window::onTreeViewContextMenuRequested(const QPoint& thePosition aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Expand All"), SLOT (onExpandAll()), GetMainWindow(), this)); aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Collapse All"), SLOT (onCollapseAll()), GetMainWindow(), this)); +#ifdef DEBUG_ALERTS + aMenu->addSeparator(); + aMenu->addAction (ViewControl_Tools::CreateAction ("Test AddChild", SLOT (OnTestAddChild()), GetMainWindow(), this)); +#endif + QPoint aPoint = myTreeView->mapToGlobal (thePosition); aMenu->exec(aPoint); } @@ -1054,6 +1063,24 @@ void VInspector_Window::onCollapseAll() } } +// ======================================================================= +// function : UpdateTreeModel +// purpose : +// ======================================================================= +void VInspector_Window::OnTestAddChild() +{ + Handle(AIS_Shape) aPresentation = new AIS_Shape (BRepBuilderAPI_MakeVertex (gp_Pnt())); + + aPresentation->AddChild (new AIS_Shape (BRepBuilderAPI_MakeVertex (gp_Pnt (10., 10., 10.)))); + aPresentation->AddChild (new AIS_Shape (BRepBuilderAPI_MakeVertex (gp_Pnt(20., 10., 10.)))); + aPresentation->AddChild (new AIS_Shape (BRepBuilderAPI_MakeVertex (gp_Pnt(30., 10., 10.)))); + + View_Displayer* aDisplayer = myViewWindow->GetDisplayer(); + aDisplayer->DisplayPresentation (aPresentation); + + UpdateTreeModel(); +} + // ======================================================================= // function : UpdateTreeModel // purpose : diff --git a/tools/VInspector/VInspector_Window.hxx b/tools/VInspector/VInspector_Window.hxx index 677b9a77a8..ac87285269 100644 --- a/tools/VInspector/VInspector_Window.hxx +++ b/tools/VInspector/VInspector_Window.hxx @@ -173,6 +173,9 @@ private slots: //! Collapse all levels for all selected items void onCollapseAll(); + //! Creates a tree of inherited presentable objects + void OnTestAddChild(); + private: //! Inits the window content by the given context