1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0031362: Inspectors - MessageView plugin for message alerts

- append new MessageView plugin to display content of Message_Report;

- correct DumpJson of TDataStd array attributes to print Lower/Upper values;
- correct remove level of Message_Report to store stop time during removing all levels;
- append DumpJson for TFunction, TPrsStd attributes;
- correct DumpJson of XCAFDoc tools due to simplify performance of it;
- move AttributeInfo functionality from XDEDRAW into a static public method of XCAFDoc to call it outside;
- remove obsolete pane classes in DFBrowser plugin, now we may use DumpJSon panel to visualize this content of attributes;
- add new property panel in DFBrowser (synchronized with the same in other plugins);
- add button to switch ON DumpJson in DFBrowser(OFF by default, for better performance), also there is a context menu item in tree view;
- rename in DFBrowser "Property Panel" into "Property Panel (custom)";
- implement ViewControl_ColorSeletor and setting color in TreeModel_ItemProperties. Use only for light in VInspector now;
- implement setting false for all created AIS_Shape presentation to don't modify source TopoDS_Shape;
- remove not use VInspector_CallBack. It's possible using Message_Report/MessageView to track commands way;
- remove History panel in VInspector as not used, MessageView will be better solution for this;
- implement item and actions in VInspector for setting Lights in the view.
This commit is contained in:
nds
2021-04-26 18:01:38 +03:00
committed by bugmaster
parent 9a5bfc1c07
commit d16ecfe28e
239 changed files with 6001 additions and 8009 deletions

14
tools/MessageModel/FILES Normal file
View File

@@ -0,0 +1,14 @@
MessageModel.qrc
MessageModel_Actions.cxx
MessageModel_Actions.hxx
MessageModel_ActionType.hxx
MessageModel_ItemAlert.cxx
MessageModel_ItemAlert.hxx
MessageModel_ItemBase.cxx
MessageModel_ItemBase.hxx
MessageModel_ItemReport.cxx
MessageModel_ItemReport.hxx
MessageModel_ItemRoot.cxx
MessageModel_ItemRoot.hxx
MessageModel_TreeModel.cxx
MessageModel_TreeModel.hxx

View File

@@ -0,0 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/item_shape.png</file>
<file>icons/item_streamValues.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,31 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef MessageModel_ActionType_H
#define MessageModel_ActionType_H
//! Kind of action type for tree view context menu item
enum MessageModel_ActionType
{
MessageModel_ActionType_Activate, //!< set Message_Report active
MessageModel_ActionType_Deactivate, //!< set Message_Report not active
MessageModel_ActionType_Clear, //!< clear Message_Report alerts
MessageModel_ActionType_ExportToShapeView, //!< export TopoDS_Shape of selected item into TKShapeView plugin
MessageModel_ActionType_TestMetric, //!< test alerts
MessageModel_ActionType_TestMessenger, //!< test message view on messenger printer to report
MessageModel_ActionType_TestReportTree //!< test message view on hierarchical report
};
#endif

View File

@@ -0,0 +1,263 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/MessageModel_Actions.hxx>
#include <inspector/MessageModel_ItemReport.hxx>
#include <inspector/MessageModel_ItemRoot.hxx>
#include <inspector/MessageModel_ItemAlert.hxx>
#include <inspector/MessageModel_TreeModel.hxx>
#include <inspector/TInspectorAPI_PluginParameters.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Message.hxx>
#include <Message_AlertExtended.hxx>
#include <Message_Messenger.hxx>
#include <Message_PrinterToReport.hxx>
#include <OSD_Chronometer.hxx>
#include <Quantity_Color.hxx>
#include <Quantity_ColorRGBA.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_AlertAttribute.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAction>
#include <QFileDialog>
#include <QItemSelectionModel>
#include <QMenu>
#include <QMessageBox>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
MessageModel_Actions::MessageModel_Actions (QWidget* theParent,
MessageModel_TreeModel* theTreeModel,
QItemSelectionModel* theModel)
: QObject (theParent), myTreeModel (theTreeModel), mySelectionModel (theModel)
{
myActions.insert (MessageModel_ActionType_Activate,
ViewControl_Tools::CreateAction (tr ("Activate"), SLOT (OnActivateReport()), parent(), this));
myActions.insert (MessageModel_ActionType_Deactivate,
ViewControl_Tools::CreateAction (tr ("Deactivate"), SLOT (OnDeactivateReport()), parent(), this));
myActions.insert (MessageModel_ActionType_Clear,
ViewControl_Tools::CreateAction (tr ("Clear"), SLOT (OnClearReport()), parent(), this));
myActions.insert (MessageModel_ActionType_ExportToShapeView,
ViewControl_Tools::CreateAction (tr ("Export to ShapeView"), SLOT (OnExportToShapeView()), parent(), this));
}
// =======================================================================
// function : GetAction
// purpose :
// =======================================================================
QAction* MessageModel_Actions::GetAction (const MessageModel_ActionType& theType)
{
return myActions.contains (theType) ? myActions[theType] : 0;
}
// =======================================================================
// function : AddMenuActions
// purpose :
// =======================================================================
void MessageModel_Actions::AddMenuActions (const QModelIndexList& theSelectedIndices, QMenu* theMenu)
{
MessageModel_ItemRootPtr aRootItem;
MessageModel_ItemReportPtr aReportItem;
MessageModel_ItemAlertPtr anAlertItem;
for (QModelIndexList::const_iterator aSelIt = theSelectedIndices.begin(); aSelIt != theSelectedIndices.end(); aSelIt++)
{
QModelIndex anIndex = *aSelIt;
if (anIndex.column() != 0)
continue;
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
if (!anItemBase)
continue;
aRootItem = itemDynamicCast<MessageModel_ItemRoot> (anItemBase);
if (aRootItem)
break;
aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
if (aReportItem)
break;
anAlertItem = itemDynamicCast<MessageModel_ItemAlert> (anItemBase);
if (anAlertItem)
break;
}
if (aReportItem && !aReportItem->GetReport().IsNull())
{
theMenu->addAction (myActions[MessageModel_ActionType_Deactivate]);
theMenu->addAction (myActions[MessageModel_ActionType_Activate]);
theMenu->addAction (myActions[MessageModel_ActionType_Clear]);
}
else if (anAlertItem)
{
theMenu->addAction (myActions[MessageModel_ActionType_ExportToShapeView]);
}
theMenu->addSeparator();
}
// =======================================================================
// function : getSelectedReport
// purpose :
// =======================================================================
Handle(Message_Report) MessageModel_Actions::getSelectedReport (QModelIndex& theReportIndex) const
{
MessageModel_ItemReportPtr aReportItem;
QModelIndexList aSelectedIndices = mySelectionModel->selectedIndexes();
for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
{
QModelIndex anIndex = *aSelIt;
if (anIndex.column() != 0)
continue;
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
if (!anItemBase)
continue;
aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
theReportIndex = anIndex;
if (aReportItem)
break;
}
if (!aReportItem)
return NULL;
return aReportItem->GetReport();
}
// =======================================================================
// function : OnActivateReport
// purpose :
// =======================================================================
static Handle(Message_PrinterToReport) MyPrinterToReport;
static Message_SequenceOfPrinters MyDeactivatedPrinters;
void MessageModel_Actions::OnActivateReport()
{
if (MyPrinterToReport.IsNull())
MyPrinterToReport = new Message_PrinterToReport();
if (MyPrinterToReport->Report()->IsActiveInMessenger())
return;
MyDeactivatedPrinters = Message::DefaultMessenger()->Printers();
Message::DefaultMessenger()->ChangePrinters().Clear();
Message::DefaultMessenger()->AddPrinter (MyPrinterToReport);
Message::DefaultReport()->UpdateActiveInMessenger();
myTreeModel->UpdateTreeModel();
}
// =======================================================================
// function : OnDeactivateReport
// purpose :
// =======================================================================
void MessageModel_Actions::OnDeactivateReport()
{
if (MyPrinterToReport.IsNull() || !MyPrinterToReport->Report()->IsActiveInMessenger())
return;
Message::DefaultMessenger()->RemovePrinter (MyPrinterToReport);
Message::DefaultMessenger()->ChangePrinters().Assign (MyDeactivatedPrinters);
myTreeModel->UpdateTreeModel();
}
// =======================================================================
// function : OnClearReport
// purpose :
// =======================================================================
void MessageModel_Actions::OnClearReport()
{
QModelIndex aReportIndex;
Handle(Message_Report) aReport = getSelectedReport (aReportIndex);
if (aReport.IsNull())
return;
aReport->Clear();
myTreeModel->UpdateTreeModel();
}
// =======================================================================
// function : OnExportToShapeView
// purpose :
// =======================================================================
void MessageModel_Actions::OnExportToShapeView()
{
TCollection_AsciiString aPluginName ("TKShapeView");
NCollection_List<Handle(Standard_Transient)> aPluginParameters;
if (myParameters->FindParameters (aPluginName))
aPluginParameters = myParameters->Parameters (aPluginName);
NCollection_List<TCollection_AsciiString> anItemNames;
if (myParameters->FindSelectedNames (aPluginName))
anItemNames = myParameters->GetSelectedNames (aPluginName);
QModelIndexList aSelectedIndices = mySelectionModel->selectedIndexes();
QStringList anExportedPointers;
for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
{
QModelIndex anIndex = *aSelIt;
if (anIndex.column() != 0)
continue;
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
if (!anItemBase)
continue;
MessageModel_ItemAlertPtr anAlertItem = itemDynamicCast<MessageModel_ItemAlert> (anItemBase);
if (!anAlertItem)
continue;
Handle(Message_Alert) anAlert = anAlertItem->GetAlert();
if (anAlert.IsNull())
continue;
Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast (anAlert);
if (anExtAlert.IsNull())
continue;
Handle(Message_Attribute) anAttribute = anExtAlert->Attribute();
if (anAttribute.IsNull())
continue;
if (!anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute)))
continue;
const TopoDS_Shape aShape = Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape();
if (aShape.IsNull())
continue;
aPluginParameters.Append (aShape.TShape());
anItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
anExportedPointers.append (Standard_Dump::GetPointerInfo (aShape.TShape(), true).ToCString());
}
if (anExportedPointers.empty())
return;
myParameters->SetSelectedNames (aPluginName, anItemNames);
myParameters->SetParameters (aPluginName, aPluginParameters);
QMessageBox::information (0, "Information", QString ("TShapes '%1' are sent to %2 tool.")
.arg (anExportedPointers.join (", ")).arg (QString (aPluginName.ToCString())));
}

View File

@@ -0,0 +1,98 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef MessageModel_Actions_H
#define MessageModel_Actions_H
#include <Standard.hxx>
#include <Standard_Transient.hxx>
#include <inspector/MessageModel_ActionType.hxx>
#include <inspector/TInspectorAPI_PluginParameters.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QObject>
#include <QMap>
#include <QModelIndexList>
#include <QPoint>
#include <QString>
#include <Standard_WarningsRestore.hxx>
class Message_Report;
class MessageModel_TreeModel;
class QAction;
class QItemSelectionModel;
class QMenu;
class QWidget;
//! \class MessageModel_Actions
//! \brief This is a listener of popup context menu items and selection change in message model
class MessageModel_Actions : public QObject
{
Q_OBJECT
public:
//! Constructor
Standard_EXPORT MessageModel_Actions (QWidget* theParent,
MessageModel_TreeModel* theTreeModel,
QItemSelectionModel* theModel);
//! Destructor
virtual ~MessageModel_Actions() Standard_OVERRIDE {}
//! Returns action by the type
//! \param theType an action type
//! \return an action instance if it exists
Standard_EXPORT QAction* GetAction (const MessageModel_ActionType& theType);
//! Fills popup menu with actions depending on the current selection
//! \param theSelectedIndices tree model selected indices
//! \param theMenu menu to be filled
Standard_EXPORT void AddMenuActions (const QModelIndexList& theSelectedIndices, QMenu* theMenu);
//! Sets parameters container, it should be used when the plugin is initialized or in update content
//! \param theParameters a parameters container
void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters)
{ myParameters = theParameters; }
public slots:
//! Set selected report active
void OnActivateReport();
//! Set selected report not active
void OnDeactivateReport();
//! Clears container of alerts of selected report
void OnClearReport();
//! Exports the first selected shape into ShapeViewer plugin.
void OnExportToShapeView();
protected:
//! Returns report of selected tree view item if a report item is selected
//! \param theReportIndex tree model index of the found report
//! \return report instance or NULL
Handle(Message_Report) getSelectedReport (QModelIndex& theReportIndex) const;
protected:
MessageModel_TreeModel* myTreeModel; //< tree model
QItemSelectionModel* mySelectionModel; //< selection model
Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
QMap<MessageModel_ActionType, QAction*> myActions; //!< container of all actions
};
#endif

View File

@@ -0,0 +1,327 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/MessageModel_ItemAlert.hxx>
#include <inspector/MessageModel_ItemRoot.hxx>
#include <inspector/MessageModel_ItemReport.hxx>
#include <inspector/MessageModel_TreeModel.hxx>
#include <inspector/Convert_TransientShape.hxx>
#include <inspector/TreeModel_ItemProperties.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <Message_AlertExtended.hxx>
#include <Message_AttributeMeter.hxx>
#include <Message_AttributeStream.hxx>
#include <Message_CompositeAlerts.hxx>
#include <Precision.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_AlertAttribute.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QColor>
#include <QIcon>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : initValue
// purpose :
// =======================================================================
QVariant MessageModel_ItemAlert::initValue (const int theRole) const
{
QVariant aParentValue = MessageModel_ItemBase::initValue (theRole);
if (aParentValue.isValid())
return aParentValue;
MessageModel_ItemReportPtr aReportItem = MessageModel_ItemReport::FindReportItem (Parent());
if (!aReportItem)
return QVariant();
Handle(Message_Report) aReport = aReportItem->GetReport();
if (aReport.IsNull())
return QVariant();
if (theRole == Qt::ForegroundRole)
{
if (!aReport->IsActiveInMessenger())
return QColor(Qt::darkGray);
return QVariant();
}
Handle(Message_Alert) anAlert = getAlert();
Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(anAlert);
// if the alert is composite, process the real alert
if (theRole == Qt::DecorationRole && Column() == 0)
{
if (anExtendedAlert.IsNull())
return QVariant();
Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute();
if (anAttribute.IsNull())
return QVariant();
if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute)))
return QIcon (":/icons/item_shape.png");
else if (!Handle(Message_AttributeStream)::DownCast (anAttribute).IsNull())
return QIcon (":/icons/item_streamValues.png");
else
return QVariant();
}
if (theRole != Qt::DisplayRole && theRole != Qt::ToolTipRole)
return QVariant();
if (anAlert.IsNull())
return QVariant();
if (Column() == 0)
{
if (theRole == Qt::DisplayRole)
{
TCollection_AsciiString aMessageKey = anAlert->GetMessageKey();
if (aMessageKey.IsEmpty() && !Properties().IsNull())
aMessageKey = Properties()->Key();
return aMessageKey.ToCString();
}
else
return anAlert->DynamicType()->Name();
}
Message_MetricType aMetricType;
int aPosition;
if (MessageModel_TreeModel::IsMetricColumn (Column(), aMetricType, aPosition))
{
if (anExtendedAlert.IsNull())
return QVariant();
Handle(Message_AttributeMeter) anAttribute = Handle(Message_AttributeMeter)::DownCast (anExtendedAlert->Attribute());
if (anAttribute.IsNull() || !anAttribute->HasMetric (aMetricType))
return QVariant();
if (!anAttribute->IsMetricValid (aMetricType))
return QVariant ("in process");
if (aMetricType == Message_MetricType_ProcessCPUUserTime ||
aMetricType == Message_MetricType_ProcessCPUSystemTime ||
aMetricType == Message_MetricType_WallClock)
{
Standard_Real aCumulativeMetric = anAttribute->StopValue (aMetricType) - anAttribute->StartValue (aMetricType);
if (fabs (aCumulativeMetric) < Precision::Confusion())
return QVariant();
if (aPosition == 0) return aCumulativeMetric;
else if (aPosition == 1)
{
Standard_Real aReportCumulativeMetric = MessageModel_ItemReport::CumulativeMetric (aReport, aMetricType);
if (fabs (aReportCumulativeMetric) > Precision::Confusion())
return 100. * aCumulativeMetric / aReportCumulativeMetric;
else
return QVariant();
}
}
else
{
if (aPosition == 0) return anAttribute->StopValue (aMetricType);
else if (aPosition == 1)
{
Standard_Real aCumulativeMetric = anAttribute->StopValue (aMetricType) - anAttribute->StartValue (aMetricType);
if (fabs (aCumulativeMetric) < Precision::Confusion())
return QVariant();
else
return aCumulativeMetric;
}
}
}
return QVariant();
}
// =======================================================================
// function : initRowCount
// purpose :
// =======================================================================
int MessageModel_ItemAlert::initRowCount() const
{
const Handle(Message_Alert)& anAlert = getAlert();
if (anAlert.IsNull())
return 0;
Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(anAlert);
if (anExtendedAlert.IsNull())
return 0;
Handle(Message_CompositeAlerts) aCompositeAlert = anExtendedAlert->CompositeAlerts();
if (aCompositeAlert.IsNull())
return 0;
MessageModel_ItemAlert* aCurrentItem = (MessageModel_ItemAlert*)this;
for (int aGravityId = Message_Trace; aGravityId <= Message_Fail; aGravityId++)
{
const Message_ListOfAlert& anAlerts = aCompositeAlert->Alerts ((Message_Gravity)aGravityId);
{
for (Message_ListOfAlert::Iterator anIt(anAlerts); anIt.More(); anIt.Next())
{
Message_ListOfAlert aCurAlerts;
aCurAlerts.Append (anIt.Value());
aCurrentItem->myChildAlerts.Bind(myChildAlerts.Size(), aCurAlerts);
}
}
}
return aCurrentItem->myChildAlerts.Size();
}
// =======================================================================
// function : initStream
// purpose :
// =======================================================================
void MessageModel_ItemAlert::initStream (Standard_OStream& theOStream) const
{
Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (getAlert());
if (anExtendedAlert.IsNull() || anExtendedAlert->Attribute().IsNull())
return;
Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute();
if (anAttribute.IsNull())
return;
if (Handle(Message_AttributeStream)::DownCast(anAttribute).IsNull())
return;
Handle(Message_AttributeStream) anAttributeStream = Handle(Message_AttributeStream)::DownCast (anExtendedAlert->Attribute());
theOStream << anAttributeStream->Stream().str();
}
// =======================================================================
// function : SetStream
// purpose :
// =======================================================================
bool MessageModel_ItemAlert::SetStream (const Standard_SStream& theSStream, Standard_Integer& theStartPos,
Standard_Integer& theLastPos) const
{
Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (getAlert());
if (anExtendedAlert.IsNull() || anExtendedAlert->Attribute().IsNull())
return false;
Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute();
if (anAttribute.IsNull())
return false;
if (Handle(Message_AttributeStream)::DownCast(anAttribute).IsNull())
return false;
Handle(Message_AttributeStream) anAttributeStream = Handle(Message_AttributeStream)::DownCast (anExtendedAlert->Attribute());
TCollection_AsciiString aStreamValue = Standard_Dump::Text (anAttributeStream->Stream());
TCollection_AsciiString aNewValue = Standard_Dump::Text (theSStream);
Standard_SStream aStream;
aStream << aStreamValue.SubString (1, theStartPos - 1);
aStream << aNewValue;
if (theLastPos + 1 <= aStreamValue.Length())
aStream << aStreamValue.SubString (theLastPos + 1, aStreamValue.Length());
anAttributeStream->SetStream (aStream);
return true;
}
// =======================================================================
// function : createChild
// purpose :
// =======================================================================
TreeModel_ItemBasePtr MessageModel_ItemAlert::createChild (int theRow, int theColumn)
{
return MessageModel_ItemAlert::CreateItem (currentItem(), theRow, theColumn);
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void MessageModel_ItemAlert::Init()
{
MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport> (Parent());
MessageModel_ItemAlertPtr anAlertItem;
Handle(Message_Alert) anAlert;
if (aReportItem)
{
Message_ListOfAlert anAlerts;
if (aReportItem->GetChildAlerts (Row(), anAlerts))
{
myAlert = anAlerts.First();
}
}
else
{
anAlertItem = itemDynamicCast<MessageModel_ItemAlert> (Parent());
if (anAlertItem)
{
Message_ListOfAlert anAlerts;
if (anAlertItem->GetChildAlerts (Row(), anAlerts))
{
myAlert = anAlerts.First();
}
}
}
Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast(myAlert);
if (!anExtendedAlert.IsNull() && !anExtendedAlert->Attribute().IsNull())
{
Handle(Message_Attribute) anAttribute = anExtendedAlert->Attribute();
if (!anAttribute.IsNull())
{
if (anAttribute->IsKind (STANDARD_TYPE (TopoDS_AlertAttribute)))
myPresentation = new Convert_TransientShape (Handle(TopoDS_AlertAttribute)::DownCast (anAttribute)->GetShape());
}
}
MessageModel_ItemBase::Init();
}
// =======================================================================
// function : Reset
// purpose :
// =======================================================================
void MessageModel_ItemAlert::Reset()
{
MessageModel_ItemBase::Reset();
myAlert = Handle(Message_Alert)();
myChildAlerts.Clear();
myPresentation = NULL;
}
// =======================================================================
// function : initItem
// purpose :
// =======================================================================
void MessageModel_ItemAlert::initItem() const
{
if (IsInitialized())
return;
const_cast<MessageModel_ItemAlert*>(this)->Init();
}
// =======================================================================
// function : getAlert
// purpose :
// =======================================================================
const Handle(Message_Alert)& MessageModel_ItemAlert::getAlert() const
{
initItem();
return myAlert;
}

View File

@@ -0,0 +1,117 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef MessageModel_ItemAlert_H
#define MessageModel_ItemAlert_H
#include <inspector/MessageModel_ItemBase.hxx>
#include <Message_Alert.hxx>
#include <Message_ListOfAlert.hxx>
#include <Message_Report.hxx>
#include <NCollection_DataMap.hxx>
#include <NCollection_List.hxx>
#include <NCollection_Vector.hxx>
#include <Standard.hxx>
#include <TopoDS_Shape.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QMap>
#include <QVariant>
#include <Standard_WarningsRestore.hxx>
class QAbstractTableModel;
class MessageModel_ItemAlert;
typedef QExplicitlySharedDataPointer<MessageModel_ItemAlert> MessageModel_ItemAlertPtr;
//! \class MessageModel_ItemAlert
//! This item is connected to Message_Alert.
//! Parent is either MessageModel_ItemRoot or MessageModel_ItemAlert, children are MessageModel_ItemAlert or no children
class MessageModel_ItemAlert : public MessageModel_ItemBase
{
public:
//! Creates an item wrapped by a shared pointer
//! \param theRow the item row positition in the parent item
//! \param theColumn the item column positition in the parent item
//! \return the pointer to the created item
static MessageModel_ItemAlertPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
{ return MessageModel_ItemAlertPtr (new MessageModel_ItemAlert (theParent, theRow, theColumn)); }
//! Destructor
virtual ~MessageModel_ItemAlert() Standard_OVERRIDE {};
//! Returns the current shape
const Handle(Message_Alert)& GetAlert() const { return myAlert; }
//! Returns alert of the report for the parameter row
Standard_Boolean GetChildAlerts (const int theRow, Message_ListOfAlert& theAlerts) const { return myChildAlerts.Find(theRow, theAlerts); }
//! Inits the item, fills internal containers
Standard_EXPORT virtual void Init() Standard_OVERRIDE;
//! Resets cached values
Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
//! Return data value for the role.
//! \param theRole a value role
//! \return the value
Standard_EXPORT virtual QVariant initValue (const int theRole) const Standard_OVERRIDE;
//! \return number of children.
Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE;
//! Returns stream value of the item to fulfill property panel.
//! \return stream value or dummy
Standard_EXPORT virtual bool SetStream (const Standard_SStream& theSStream, Standard_Integer& theStartPos,
Standard_Integer& theLastPos) const Standard_OVERRIDE;
//! Returns presentation of the attribute to be visualized in the view
//! \thePresentations [out] container of presentation handles to be visualized
virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations) Standard_OVERRIDE
{ TreeModel_ItemBase::Presentations (thePresentations); thePresentations.Append (myPresentation); }
protected:
//! Initialize the current item.
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
//! \return the created item
virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
//! Returns current alert, initialized item if it has not been initialized yet
//! \return alert value
const Handle(Message_Alert)& getAlert() const;
private:
//! Constructor
MessageModel_ItemAlert (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
: MessageModel_ItemBase (theParent, theRow, theColumn) {}
private:
Handle(Message_Alert) myAlert; //!< current alert item
NCollection_DataMap<Standard_Integer, Message_ListOfAlert> myChildAlerts; //!< container of child alerts
Handle(Standard_Transient) myPresentation; //!< item presentation
};
#endif

View File

@@ -0,0 +1,35 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/MessageModel_ItemBase.hxx>
#include <inspector/MessageModel_ItemRoot.hxx>
// =======================================================================
// function : GetRootItem
// purpose :
// =======================================================================
TreeModel_ItemBasePtr MessageModel_ItemBase::GetRootItem() const
{
TreeModel_ItemBasePtr anItem = Parent();
while (anItem)
{
if (MessageModel_ItemRootPtr aThisRootItem = itemDynamicCast<MessageModel_ItemRoot> (anItem))
{
return aThisRootItem;
}
anItem = anItem->Parent();
}
return TreeModel_ItemBasePtr();
}

View File

@@ -0,0 +1,52 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef MessageModel_ItemBase_H
#define MessageModel_ItemBase_H
#include <Standard.hxx>
#include <TopoDS_Shape.hxx>
#include <inspector/TreeModel_ItemBase.hxx>
class MessageModel_ItemBase;
typedef QExplicitlySharedDataPointer<MessageModel_ItemBase> MessageModel_ItemBasePtr;
//! \class MessageModel_ItemBase
// \brief Declaration of the tree model base item.
class MessageModel_ItemBase : public TreeModel_ItemBase
{
public:
//! Resets cached values
virtual void Reset() Standard_OVERRIDE { TreeModel_ItemBase::Reset(); }
protected:
//! Initialize the current item. It creates a backup of the specific item information
virtual void initItem() const {};
//! Constructor
//! param theParent a parent item
//! \param theRow the item row positition in the parent item
//! \param theColumn the item column positition in the parent item
MessageModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
: TreeModel_ItemBase (theParent, theRow, theColumn) {}
//! Return root item
//! \return an item instance
TreeModel_ItemBasePtr GetRootItem() const;
};
#endif

View File

@@ -0,0 +1,232 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/MessageModel_ItemReport.hxx>
#include <inspector/MessageModel_ItemAlert.hxx>
#include <inspector/MessageModel_ItemRoot.hxx>
#include <inspector/MessageModel_TreeModel.hxx>
#include <Message.hxx>
#include <Message_Alert.hxx>
#include <Message_AttributeMeter.hxx>
#include <Message_Messenger.hxx>
#include <Message_PrinterToReport.hxx>
#include <OSD_Path.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QColor>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : initValue
// purpose :
// =======================================================================
QVariant MessageModel_ItemReport::initValue (const int theRole) const
{
QVariant aParentValue = MessageModel_ItemBase::initValue (theRole);
if (aParentValue.isValid())
return aParentValue;
const Handle(Message_Report)& aReport = getReport();
if (aReport.IsNull())
return QVariant();
if (theRole == Qt::ForegroundRole)
{
if (!aReport->IsActiveInMessenger())
return QColor(Qt::darkGray);
return QVariant();
}
if (theRole == Qt::ToolTipRole && !myDescription.IsEmpty() && Column() == 0) // display the exported file name in tool tip
{
OSD_Path aPath(myDescription);
return QString ("%1%2").arg (aPath.Name().ToCString()).arg (aPath.Extension().ToCString());
}
if (theRole != Qt::DisplayRole)
return QVariant();
if (Column() == 0)
return aReport->DynamicType()->Name();
Message_MetricType aMetricType;
int aPosition;
if (MessageModel_TreeModel::IsMetricColumn (Column(), aMetricType, aPosition) &&
(aMetricType == Message_MetricType_ProcessCPUUserTime || aMetricType == Message_MetricType_ProcessCPUSystemTime ||
aMetricType == Message_MetricType_WallClock))
{
if (aPosition == 0) return CumulativeMetric (aReport, aMetricType);
else if (aPosition == 1) return "100";
}
return QVariant();
}
// =======================================================================
// function : initRowCount
// purpose :
// =======================================================================
int MessageModel_ItemReport::initRowCount() const
{
const Handle(Message_Report)& aReport = getReport();
if (aReport.IsNull())
return 0;
MessageModel_ItemReport* aCurrentItem = (MessageModel_ItemReport*)this;
for (int aGravityId = Message_Trace; aGravityId <= Message_Fail; aGravityId++)
{
const Message_ListOfAlert& anAlerts = aReport->GetAlerts ((Message_Gravity)aGravityId);
for (Message_ListOfAlert::Iterator anIt(anAlerts); anIt.More(); anIt.Next())
{
Message_ListOfAlert aCurAlerts;
aCurAlerts.Append (anIt.Value());
aCurrentItem->myChildAlerts.Bind(myChildAlerts.Size(), aCurAlerts);
}
}
return aCurrentItem->myChildAlerts.Size();
}
// =======================================================================
// function : createChild
// purpose :
// =======================================================================
TreeModel_ItemBasePtr MessageModel_ItemReport::createChild (int theRow, int theColumn)
{
return MessageModel_ItemAlert::CreateItem (currentItem(), theRow, theColumn);
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void MessageModel_ItemReport::Init()
{
MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (Parent());
myReport = aRootItem ? aRootItem->GetReport (Row(), myDescription) : Handle(Message_Report)();
MessageModel_ItemBase::Init();
}
// =======================================================================
// function : getReport
// purpose :
// =======================================================================
const Handle(Message_Report)& MessageModel_ItemReport::getReport() const
{
initItem();
return myReport;
}
// =======================================================================
// function : Reset
// purpose :
// =======================================================================
void MessageModel_ItemReport::Reset()
{
MessageModel_ItemBase::Reset();
myReport = Handle(Message_Report)();
myChildAlerts.Clear();
}
// =======================================================================
// function : initItem
// purpose :
// =======================================================================
void MessageModel_ItemReport::initItem() const
{
if (IsInitialized())
return;
const_cast<MessageModel_ItemReport*>(this)->Init();
}
// =======================================================================
// function : FindReportItem
// purpose :
// =======================================================================
MessageModel_ItemReportPtr MessageModel_ItemReport::FindReportItem (const TreeModel_ItemBasePtr& theItem)
{
TreeModel_ItemBasePtr anItem = theItem;
while (anItem)
{
if (MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItem))
return aReportItem;
anItem = anItem->Parent();
}
return MessageModel_ItemReportPtr();
}
// =======================================================================
// function : FindReport
// purpose :
// =======================================================================
Handle(Message_Report) MessageModel_ItemReport::FindReport (const MessageModel_ItemBasePtr& theItem)
{
Handle(Message_Report) aReport;
MessageModel_ItemBasePtr anItem = theItem;
while (anItem)
{
MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItem);
if (aReportItem)
return aReportItem->GetReport();
anItem = itemDynamicCast<MessageModel_ItemBase>(anItem->Parent());
}
return NULL;
}
// =======================================================================
// function : CumulativeMetric
// purpose :
// =======================================================================
Standard_Real MessageModel_ItemReport::CumulativeMetric (const Handle(Message_Report)& theReport, const Message_MetricType theMetricType)
{
if (!theReport->ActiveMetrics().Contains (theMetricType))
return 0;
Standard_Real aMetric = 0;
for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
{
const Message_ListOfAlert& anAlerts = theReport->GetAlerts ((Message_Gravity)iGravity);
Handle(Message_AttributeMeter) aFirstAttribute/*, aLastAttribute*/;
for (Message_ListOfAlert::Iterator anAlertsIterator (anAlerts); anAlertsIterator.More(); anAlertsIterator.Next())
{
Handle(Message_AlertExtended) anAlert = Handle(Message_AlertExtended)::DownCast (anAlertsIterator.Value());
if (anAlert.IsNull())
continue;
Handle(Message_AttributeMeter) anAttribute = Handle(Message_AttributeMeter)::DownCast (anAlert->Attribute());
if (anAttribute.IsNull() || !anAttribute->HasMetric (theMetricType) || !anAttribute->IsMetricValid (theMetricType))
continue;
//if (aFirstAttribute.IsNull())
// aFirstAttribute = anAttribute;
//else
//{
//aLastAttribute = anAttribute;
//}
aMetric += anAttribute->StopValue (theMetricType) - anAttribute->StartValue (theMetricType);
}
//if (aFirstAttribute.IsNull())
// continue;
//if (aLastAttribute.IsNull())
// aLastAttribute = aFirstAttribute;
//aMetric += aLastAttribute->StopValue (theMetricType) - aFirstAttribute->StartValue (theMetricType);
}
return aMetric;
}

View File

@@ -0,0 +1,117 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef MessageModel_ItemReport_H
#define MessageModel_ItemReport_H
#include <inspector/MessageModel_ItemBase.hxx>
#include <Standard.hxx>
#include <TCollection_AsciiString.hxx>
#include <Message_Alert.hxx>
#include <Message_Report.hxx>
#include <NCollection_DataMap.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QMap>
#include <QVariant>
#include <Standard_WarningsRestore.hxx>
class MessageModel_ItemReport;
typedef QExplicitlySharedDataPointer<MessageModel_ItemReport> MessageModel_ItemReportPtr;
//! \class MessageModel_ItemReport
//! This item is connected to Message_Alert.
//! Parent is MessageModel_ItemRoot, children are MessageModel_ItemAlert or no children
class MessageModel_ItemReport : public MessageModel_ItemBase
{
public:
//! Creates an item wrapped by a shared pointer
//! \param theRow the item row positition in the parent item
//! \param theColumn the item column positition in the parent item
//! \return the pointer to the created item
static MessageModel_ItemReportPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
{ return MessageModel_ItemReportPtr (new MessageModel_ItemReport (theParent, theRow, theColumn)); }
//! Destructor
virtual ~MessageModel_ItemReport() Standard_OVERRIDE {};
//! Returns the current shape
const Handle(Message_Report)& GetReport() const { return myReport; }
//! Returns alert of the report for the parameter row
Standard_Boolean GetChildAlerts (const int theRow, Message_ListOfAlert& theAlerts) const { return myChildAlerts.Find(theRow, theAlerts); }
//! Returns the report description or NULL
const TCollection_AsciiString& GetDescription() const { return myDescription; }
//! Inits the item, fills internal containers
Standard_EXPORT virtual void Init() Standard_OVERRIDE;
//! Resets cached values
Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
//! Return data value for the role.
//! \param theRole a value role
//! \return the value
Standard_EXPORT virtual QVariant initValue (const int theRole) const Standard_OVERRIDE;
//! \return number of children.
Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE;
//! Returns report of the tree model item. Iterates up by parents intil the report item is found.
//! \return an item or NULL
Standard_EXPORT static MessageModel_ItemReportPtr FindReportItem (const TreeModel_ItemBasePtr& theItem);
//! Returns report of the item
static Handle(Message_Report) FindReport (const MessageModel_ItemBasePtr& thetItem);
//! Returns report cumulative metric as stop time of the last alert minus start time of the first alert
Standard_EXPORT static Standard_Real CumulativeMetric (const Handle(Message_Report)& theReport, const Message_MetricType theMetricType);
protected:
//! Initialize the current item.
virtual void initItem() const Standard_OVERRIDE;
//! Creates a child item in the given position.
//! \param theRow the child row position
//! \param theColumn the child column position
//! \return the created item
virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
//! Returns number of child shapes. Init item if it is not initialized
//! \return integer value
int getRowCount() const;
//! Returns current shape, initialized item if it has not been initialized yet
//! \return shape value
const Handle(Message_Report)& getReport() const;
private:
//! Constructor
MessageModel_ItemReport (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
: MessageModel_ItemBase (theParent, theRow, theColumn) {}
private:
NCollection_DataMap<Standard_Integer, Message_ListOfAlert> myChildAlerts; //!< container of child alerts
Handle(Message_Report) myReport; //!< current report
TCollection_AsciiString myDescription; //!< description
};
#endif

View File

@@ -0,0 +1,95 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/MessageModel_ItemRoot.hxx>
#include <inspector/MessageModel_ItemReport.hxx>
// =======================================================================
// function : SetReport
// purpose :
// =======================================================================
void MessageModel_ItemRoot::SetReport (const int theRowId, const Handle(Message_Report)& theReport,
const TCollection_AsciiString& theReportDescription)
{
NCollection_List<MessageModel_ReportInformation>::Iterator aReportsIt (myReports);
for (int aRowId = 0; aReportsIt.More(); aReportsIt.Next(), aRowId++)
{
if (aRowId == theRowId)
break;
}
aReportsIt.Value().myReport = theReport;
aReportsIt.Value().myDescription = theReportDescription;
}
// =======================================================================
// function : GetReport
// purpose :
// =======================================================================
const Handle(Message_Report)& MessageModel_ItemRoot::GetReport (const int theRowId,
TCollection_AsciiString& theReportDescription)
{
NCollection_List<MessageModel_ReportInformation>::Iterator aReportsIt (myReports);
for (int aRowId = 0; aReportsIt.More(); aReportsIt.Next(), aRowId++)
{
if (aRowId == theRowId)
break;
}
theReportDescription = aReportsIt.Value().myDescription;
return aReportsIt.Value().myReport;
}
// =======================================================================
// function : HasReport
// purpose :
// =======================================================================
Standard_Boolean MessageModel_ItemRoot::HasReport (const Handle(Message_Report)& theReport)
{
NCollection_List<MessageModel_ReportInformation>::Iterator aReportsIt (myReports);
for (int aRowId = 0; aReportsIt.More(); aReportsIt.Next(), aRowId++)
{
if (aReportsIt.Value().myReport == theReport)
return Standard_True;
}
return Standard_False;
}
// =======================================================================
// function : initValue
// purpose :
// =======================================================================
QVariant MessageModel_ItemRoot::initValue (const int theRole) const
{
QVariant aParentValue = MessageModel_ItemBase::initValue (theRole);
if (aParentValue.isValid())
return aParentValue;
if (Column() != 0)
return QVariant();
if (theRole == Qt::DisplayRole)
return myName.IsEmpty() ? "Message_Reports" : myName.ToCString();
return QVariant();
}
// =======================================================================
// function : createChild
// purpose :
// =======================================================================
TreeModel_ItemBasePtr MessageModel_ItemRoot::createChild (int theRow, int theColumn)
{
return MessageModel_ItemReport::CreateItem (currentItem(), theRow, theColumn);
}

View File

@@ -0,0 +1,117 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef MessageModel_ItemRoot_H
#define MessageModel_ItemRoot_H
#include <Message_Alert.hxx>
#include <Message_Report.hxx>
#include <NCollection_List.hxx>
#include <Standard.hxx>
#include <TCollection_AsciiString.hxx>
#include <inspector/MessageModel_ItemBase.hxx>
class MessageModel_ItemRoot;
typedef QExplicitlySharedDataPointer<MessageModel_ItemRoot> MessageModel_ItemRootPtr;
//! \struct to extend report by description
struct MessageModel_ReportInformation
{
//! Constructor
MessageModel_ReportInformation (Handle(Message_Report) theReport, const TCollection_AsciiString& theDescription)
: myReport (theReport), myDescription (theDescription) {}
Handle(Message_Report) myReport; //! report
TCollection_AsciiString myDescription; //! report description
};
//! \class MessageModel_ItemRoot
//! Collects message reports that should be visualized in tree view. Reports are cached and if reports are not needed,
//! cache should be cleared using RemoveAllReports
//! Parent is NULL, children are MessageModel_ItemReport items.
class MessageModel_ItemRoot : public MessageModel_ItemBase
{
public:
//! Creates an item wrapped by a shared pointer
static MessageModel_ItemRootPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
{ return MessageModel_ItemRootPtr (new MessageModel_ItemRoot (theParent, theRow, theColumn)); }
//! Destructor
virtual ~MessageModel_ItemRoot() Standard_OVERRIDE {};
//! Appends new report
//! \param theReport a report instance
//! \param theReportDescription an additional report information
void AddReport (const Handle(Message_Report)& theReport, const TCollection_AsciiString& theReportDescription)
{ myReports.Append (MessageModel_ReportInformation (theReport, theReportDescription)); }
//! Set report, se it into the given row index
//! \param theRowId a report child row
//! \param theReport a report instance
//! \param theReportDescription an additional report information
Standard_EXPORT void SetReport (const int theRowId, const Handle(Message_Report)& theReport,
const TCollection_AsciiString& theReportDescription = "");
//! Returns true if report exists is in the list of the current reports
//! \param theReport a report instance
//! \return boolen value
Standard_EXPORT Standard_Boolean HasReport (const Handle(Message_Report)& theReport);
//!< Returns processed reports
const NCollection_List<MessageModel_ReportInformation>& Reports() const { return myReports; }
//! Clears internal container of added reports
void RemoveAllReports() { myReports.Clear(); }
//! Returns report by the number
//! \param theRowId an index of the report in the internal container.
Standard_EXPORT const Handle(Message_Report)& GetReport (const int theRowId, TCollection_AsciiString& theReportDescription);
//! Set the item name
//! \param theName text value
void SetName (const TCollection_AsciiString& theName) { myName = theName; }
protected:
//! Return data value for the role.
//! \param theRole a value role
//! \return the value
virtual QVariant initValue (const int theRole) const Standard_OVERRIDE;
//! \return number of children.
virtual int initRowCount() const Standard_OVERRIDE { return myReports.Size(); }
//! Creates a child item in the given position.
//! \param theRow the child row position
//! \param theColumn the child column position
//! \return the created item
virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
private:
//! Constructor
//! param theParent a parent item
MessageModel_ItemRoot (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
: MessageModel_ItemBase (theParent, theRow, theColumn) {}
private:
NCollection_List<MessageModel_ReportInformation> myReports; //!< reports sent by algorithms
TCollection_AsciiString myName; //!< DisplayRole data, if defined
};
#endif

View File

@@ -0,0 +1,193 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/MessageModel_TreeModel.hxx>
#include <inspector/MessageModel_ItemAlert.hxx>
#include <inspector/MessageModel_ItemRoot.hxx>
#include <inspector/MessageModel_ItemReport.hxx>
#include <inspector/TreeModel_ColumnType.hxx>
#include <Message.hxx>
const int COLUMN_NAME_WIDTH = 230;
const int COLUMN_SIZE_WIDTH = 30;
const int COLUMN_REAL_VALUE_WIDTH = 115;
const int COLUMN_PERCENT_VALUE_WIDTH = 50;
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
MessageModel_TreeModel::MessageModel_TreeModel (QObject* theParent)
: TreeModel_ModelBase (theParent)
{
}
// =======================================================================
// function : InitColumns
// purpose :
// =======================================================================
void MessageModel_TreeModel::InitColumns()
{
// 0 - Name, 1 - visibility, 2 - Row
setHeaderItem (TreeModel_ColumnType_Name, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
setHeaderItem (TreeModel_ColumnType_Visibility, TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
setHeaderItem (TreeModel_ColumnType_Row, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH, Standard_True /*hidden*/));
int aNextIndex = 3;
for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
{
Message_MetricType aMetricType = (Message_MetricType)aMetricId;
OSD_MemInfo::Counter aMemInfo;
bool isMemInfo = Message::ToOSDMetric (aMetricType, aMemInfo);
setHeaderItem (aNextIndex++,
TreeModel_HeaderSection (QString("%1 [%2]").arg (Message::MetricToString (aMetricType)).arg(isMemInfo ? "Mb" : "s"),
COLUMN_REAL_VALUE_WIDTH));
setHeaderItem (aNextIndex++, TreeModel_HeaderSection (isMemInfo ? "Delta" : "%", COLUMN_PERCENT_VALUE_WIDTH));
}
}
// =======================================================================
// function : GetMetricColumns
// purpose :
// =======================================================================
void MessageModel_TreeModel::GetMetricColumns (const Message_MetricType theMetricType, QList<int>& theMetricColumns)
{
theMetricColumns.clear();
int aNextIndex = 3; // after default parent columns, see InitColumns
for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
{
if (theMetricType != (Message_MetricType)aMetricId)
{
aNextIndex += 2;
continue;
}
theMetricColumns.append (aNextIndex++);
theMetricColumns.append (aNextIndex++);
}
}
// =======================================================================
// function : IsMetricColumn
// purpose :
// =======================================================================
bool MessageModel_TreeModel::IsMetricColumn (const int theColumnId, Message_MetricType& theMetricType, int& thePosition)
{
int aNextIndex = 3; // after default parent columns, see InitColumns
for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
{
if (theColumnId == aNextIndex || theColumnId == aNextIndex + 1)
{
theMetricType = (Message_MetricType)aMetricId;
thePosition = theColumnId - aNextIndex;
return true;
}
aNextIndex += 2;
}
return false;
}
// =======================================================================
// function : createRootItem
// purpose :
// =======================================================================
TreeModel_ItemBasePtr MessageModel_TreeModel::createRootItem (const int theColumnId)
{
return MessageModel_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId);
}
// =======================================================================
// function : HasReport
// purpose :
// =======================================================================
Standard_Boolean MessageModel_TreeModel::HasReport (const Handle(Message_Report)& theReport)
{
if (columnCount() == 0)
return Standard_False;
MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
return aRootItem && aRootItem->HasReport (theReport);
}
// =======================================================================
// function : AddReport
// purpose :
// =======================================================================
void MessageModel_TreeModel::AddReport (const Handle(Message_Report)& theReport,
const TCollection_AsciiString& theReportDescription)
{
for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
{
MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (aColId));
if (!aRootItem)
continue;
aRootItem->AddReport (theReport, theReportDescription);
}
Reset();
EmitLayoutChanged();
}
// =======================================================================
// function : SetReport
// purpose :
// =======================================================================
void MessageModel_TreeModel::SetReport (const int theRowId, const Handle(Message_Report)& theReport,
const TCollection_AsciiString& theReportDescription)
{
for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
{
MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (aColId));
if (!aRootItem)
continue;
aRootItem->SetReport (theRowId, theReport, theReportDescription);
}
Reset();
EmitLayoutChanged();
}
// =======================================================================
// function : Reports
// purpose :
// =======================================================================
const NCollection_List<MessageModel_ReportInformation>& MessageModel_TreeModel::Reports() const
{
MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
return aRootItem->Reports();
}
// =======================================================================
// function : UpdateTreeModel
// purpose :
// =======================================================================
void MessageModel_TreeModel::SetRootItemName (const TCollection_AsciiString& theName)
{
MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
if (aRootItem)
aRootItem->SetName (theName);
}
// =======================================================================
// function : UpdateTreeModel
// purpose :
// =======================================================================
void MessageModel_TreeModel::UpdateTreeModel()
{
Reset();
EmitLayoutChanged();
}

View File

@@ -0,0 +1,94 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef MessageModel_TreeModel_H
#define MessageModel_TreeModel_H
#include <inspector/MessageModel_ItemBase.hxx>
#include <inspector/MessageModel_ItemRoot.hxx>
#include <Standard.hxx>
#include <TCollection_AsciiString.hxx>
#include <Message_Report.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QMap>
#include <QObject>
#include <Standard_WarningsRestore.hxx>
class MessageModel_TreeModel;
//! \class MessageModel_TreeModel
//! View model to visualize MessageReport/s content
class MessageModel_TreeModel : public TreeModel_ModelBase
{
public:
//! Constructor
Standard_EXPORT MessageModel_TreeModel (QObject* theParent);
//! Destructor
virtual ~MessageModel_TreeModel() Standard_OVERRIDE {};
//! Creates model columns and root items.
Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE;
//!< Returns columns of the model for the metric
//!< \param theMetricType metric
//!< \param theMetricColumns [out] container of metric columns
static Standard_EXPORT void GetMetricColumns (const Message_MetricType theMetricType, QList<int>& theMetricColumns);
//!< Returns metric type for the column
//!< \param theColumnId [in] index of the tree column
//!< \param theMetricType [out] metric type if found
//!< \param thePosition [out] index of the metric column, 0 - is metric, 1 - is delta
//!< \return true if the column has metric parameters
static Standard_EXPORT bool IsMetricColumn (const int theColumnId, Message_MetricType& theMetricType, int& thePosition);
//! Returns true if parameter report was added into the model
//! \param theReport a report instance
//! \return boolen value
Standard_EXPORT Standard_Boolean HasReport (const Handle(Message_Report)& theReport);
//! Add shape, append it to the model root item
//! \param theReport a report instance
//! \param theReportDescription an additional report information
Standard_EXPORT void AddReport (const Handle(Message_Report)& theReport,
const TCollection_AsciiString& theReportDescription = "");
//! Set report, se it into the given row index
//! \param theRowId a report child row
//! \param theReport a report instance
//! \param theReportDescription an additional report information
Standard_EXPORT void SetReport (const int theRowId, const Handle(Message_Report)& theReport,
const TCollection_AsciiString& theReportDescription = "");
//!< Returns processed reports
Standard_EXPORT const NCollection_List<MessageModel_ReportInformation>& Reports() const;
//! Sets the text value of the Root item, only "Name" column accepts the parameter value
//! \theName visulized text of root item
Standard_EXPORT void SetRootItemName (const TCollection_AsciiString& theName);
//! Updates tree model
Standard_EXPORT void UpdateTreeModel();
protected:
//! Creates root item
//! \param theColumnId index of a column
virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE;
};
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B