From: sshutina Date: Wed, 25 Nov 2020 12:51:28 +0000 (+0300) Subject: 0031959: Inspectors - Statistics by name X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=fe1165d44e86e5d400342cb95e55e15443ffa0eb;p=occt-copy.git 0031959: Inspectors - Statistics by name --- diff --git a/tools/MessageView/FILES b/tools/MessageView/FILES index 5fe2f52661..86a3a722dc 100644 --- a/tools/MessageView/FILES +++ b/tools/MessageView/FILES @@ -2,6 +2,8 @@ MessageView_ActionsTest.cxx MessageView_ActionsTest.hxx MessageView_Communicator.cxx MessageView_Communicator.hxx +MessageView_UnitByNameModel.cxx +MessageView_UnitByNameModel.hxx MessageView_VisibilityState.cxx MessageView_VisibilityState.hxx MessageView_Window.cxx diff --git a/tools/MessageView/MessageView_UnitByNameModel.cxx b/tools/MessageView/MessageView_UnitByNameModel.cxx new file mode 100644 index 0000000000..a0e8add379 --- /dev/null +++ b/tools/MessageView/MessageView_UnitByNameModel.cxx @@ -0,0 +1,185 @@ +// 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 + +const int ICON_SIZE = 40; + + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void MessageView_UnitByNameModel::Init (const TreeModel_ItemBasePtr theItemBase) +{ + MessageModel_ItemReportPtr aReportItem = itemDynamicCast (theItemBase); + if (aReportItem) + { + Handle(Message_Report) aReport = aReportItem->GetReport(); + const Message_ListOfAlert& anAlerts = aReport->GetAlerts (Message_Info); + for (Message_ListOfAlert::Iterator anIt(anAlerts); anIt.More(); anIt.Next()) + { + initByAlert (anIt.Value()); + } + } + else + { + MessageModel_ItemAlertPtr anAlertItem = itemDynamicCast (theItemBase); + if (anAlertItem) + { + initByAlert (anAlertItem->GetAlert()); + } + } + std::map> theTmpMap; + std::list theTimes; + for (QMap >::Iterator i = myValues.begin(); i != myValues.end(); ++i) + { + std::map>::iterator iter = theTmpMap.find(i.value().second); + if (iter != theTmpMap.end()) + { + theTmpMap.at (i.value().second).push_back (i.key()); + } + else + { + std::list list; + list.push_back (i.key()); + theTmpMap.insert (std::pair >(i.value().second, list)); + theTimes.push_back (i.value().second); + } + } + + theTimes.sort(); + theTimes.reverse(); + + for (std::list::iterator iter = theTimes.begin(); iter != theTimes.end(); iter++) + { + double aTime = *iter; + std::list names = theTmpMap.at (aTime); + for (std::list::iterator name = names.begin(); name != names.end(); name++) + { + int nb = myValues.find(*name).value().first; + RowValues value = {*name, nb, aTime}; + setValueByIndex (-1, value); + } + } +} + +// ======================================================================= +// function : initByAlert +// purpose : +// ======================================================================= +void MessageView_UnitByNameModel::initByAlert(const Handle(Message_Alert)& theAlert) +{ + Handle(Message_AlertExtended) anExtAlert = Handle(Message_AlertExtended)::DownCast(theAlert); + if (anExtAlert.IsNull()) + return; + Handle(Message_Attribute) anAttr = anExtAlert->Attribute(); + Handle(Message_AttributeMeter) anAttrMeter = Handle(Message_AttributeMeter)::DownCast (anAttr); + if(anAttrMeter.IsNull()) + { + return; + } + + if (myValues.contains (anAttr->GetName().ToCString())) + { + int aCount = myValues.value(anAttr->GetName().ToCString()).first; + aCount++; + double aTime = myValues.value(anAttr->GetName().ToCString()).second; + aTime += anAttrMeter->StopValue(Message_MetricType_WallClock) - anAttrMeter->StartValue(Message_MetricType_WallClock); + myValues[anAttr->GetName().ToCString()] = qMakePair(aCount, aTime); + } + else + { + int aCount = 1; + double aTime = anAttrMeter->StopValue(Message_MetricType_WallClock) - anAttrMeter->StartValue(Message_MetricType_WallClock); + myValues.insert (anAttr->GetName().ToCString(), qMakePair(aCount, aTime)); + } + + if (!anExtAlert->CompositeAlerts().IsNull()) + { + const Message_ListOfAlert& anAlerts = anExtAlert->CompositeAlerts()->Alerts(Message_Info); + for (Message_ListOfAlert::Iterator anIt(anAlerts); anIt.More(); anIt.Next()) + { + initByAlert (anIt.Value()); + } + } +} + +// ======================================================================= +// function : data +// purpose : +// ======================================================================= +QVariant MessageView_UnitByNameModel::data (const QModelIndex& theIndex, int theRole) const +{ + switch (theRole) + { + case Qt::DisplayRole: + { + switch (theIndex.column()) + { + case 0: return myValues2[theIndex.row()].myName; + case 1: return myValues2[theIndex.row()].myCounter; + case 2: return myValues2[theIndex.row()].myTime; + } + break; + } + default: break; + } + return QVariant(); +} + +// ======================================================================= +// function : getValueIndex +// purpose : +// ======================================================================= +int MessageView_UnitByNameModel::getValueIndex(const QString name) +{ + for (QMap::iterator iter = myValues2.begin(); iter != myValues2.end(); iter++) + { + if (iter.value().myName == name) + { + return iter.key(); + } + } +} + +// ======================================================================= +// function : setValueByIndex +// purpose : +// ======================================================================= +void MessageView_UnitByNameModel::setValueByIndex(const int index, const RowValues value) +{ + if (index == -1) + { + myValues2.insert (myValues2.size(), value); + } + else + { + myValues2.insert (index, value); + } +} diff --git a/tools/MessageView/MessageView_UnitByNameModel.hxx b/tools/MessageView/MessageView_UnitByNameModel.hxx new file mode 100644 index 0000000000..26531b275f --- /dev/null +++ b/tools/MessageView/MessageView_UnitByNameModel.hxx @@ -0,0 +1,90 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef TInspectorEXE_OpenFileViewModel_H +#define TInspectorEXE_OpenFileViewModel_H + +#include + +#include +#include + +#include +#include +#include +#include +#include + +class QObject; +class QPainter; + +//! \class TInspector_OpenFileViewModel +//! Table model that visualizes container of string values (file names) +//! Table orientation is horizontal, it has 1 row, number of columns equals to number of values +class MessageView_UnitByNameModel : public QAbstractTableModel +{ +public: + + struct RowValues + { + QString myName; + int myCounter; + double myTime; + }; + + //! Constructor + MessageView_UnitByNameModel (QObject* theParent = 0) : QAbstractTableModel (theParent) {} + + //! Destructor + virtual ~MessageView_UnitByNameModel() {} + + //! Store values + //! \param theValues a container of values to fill model + void Init (const TreeModel_ItemBasePtr theItemBase); + + //! Returns content of the model index for the given role, it is obtained from internal container of values + //! It returns value only for DisplayRole. + //! \param theIndex a model index + //! \param theRole a view role + //! \return value intepreted depending on the given role + virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; + + //! Returns number of rows + //! \param theParent an index of the parent item + //! \return an integer value + virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { + (void)theParent; + return myValues.size(); } + + //! Returns number of columns + //! \param theParent an index of the parent item + //! \return an integer value + virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return 3; } + +private: + void initByAlert(const Handle(Message_Alert)& theAlert); + int getValueIndex(const QString name); + void setValueByIndex(const int, const RowValues); + +private: + + //QStringList myValues; //!< file names + QMap > myValues; + QMap myValues2; +}; + +#endif diff --git a/tools/MessageView/MessageView_Window.cxx b/tools/MessageView/MessageView_Window.cxx index a2270827d1..91dd3a2872 100644 --- a/tools/MessageView/MessageView_Window.cxx +++ b/tools/MessageView/MessageView_Window.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -192,6 +193,12 @@ MessageView_Window::MessageView_Window (QWidget* theParent) connect (myPropertyPanelWidget->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT (onPropertyPanelShown (bool))); connect (myPropertyView, SIGNAL (propertyViewDataChanged()), this, SLOT (onPropertyViewDataChanged())); + myCustomView = new QTableView (myMainWindow); + myCustomPanelWidget = new QDockWidget (tr ("Unit By Name"), myMainWindow); + myCustomPanelWidget->setObjectName (myCustomPanelWidget->windowTitle()); + myCustomPanelWidget->setTitleBarWidget (new QWidget(myMainWindow)); + myCustomPanelWidget->setWidget (myCustomView); + myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myCustomPanelWidget); // view myViewWindow = new View_Window (myMainWindow, false); @@ -205,6 +212,8 @@ MessageView_Window::MessageView_Window (QWidget* theParent) myViewDockWidget->setWidget (myViewWindow); myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myViewDockWidget); + myMainWindow->tabifyDockWidget (myPropertyPanelWidget, myCustomPanelWidget); + myMainWindow->resize (DEFAULT_SHAPE_VIEW_WIDTH, DEFAULT_SHAPE_VIEW_HEIGHT); myMainWindow->move (DEFAULT_SHAPE_VIEW_POSITION_X, DEFAULT_SHAPE_VIEW_POSITION_Y); @@ -511,6 +520,11 @@ void MessageView_Window::onTreeViewContextMenuRequested (const QPoint& thePositi bool isTraceOnly = aReport->MessageWriter().IsNull() ? false : aReport->MessageWriter()->Gravity() == Message_Trace; anAction->setChecked (isTraceOnly); aMenu->addAction (anAction); + + anAction = ViewControl_Tools::CreateAction (tr ("Unit by name"), SLOT (onUnitByName()), myMainWindow, this); + anAction->setCheckable (true); + //anAction->setChecked (isTraceOnly); + aMenu->addAction (anAction); } aMenu->addSeparator(); @@ -766,6 +780,41 @@ void MessageView_Window::onPreviewChildren() displayer()->UpdatePreview (View_DisplayActionType_DisplayId, aPresentations); } +// ======================================================================= +// function : onUnitByName +// purpose : +// ======================================================================= +void MessageView_Window::onUnitByName() +{ + QItemSelectionModel* aModel = myTreeView->selectionModel(); + if (!aModel) + return; + + QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0); + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); + if (!anItemBase) + return; + + /*QItemSelectionModel* aModel = myCustomView->selectionModel(); + if (!aModel) + { + return; + } + QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (myCustomView->selectionModel()->selectedIndexes(), 0); + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); + if (!anItemBase) + { + return; + }*/ + MessageView_UnitByNameModel* aUnitByNameModel = new MessageView_UnitByNameModel(myCustomView); + if (aUnitByNameModel) + { + aUnitByNameModel->Init(anItemBase); + } + + myCustomView->setModel (aUnitByNameModel); +} + // ======================================================================= // function : addActivateMetricActions // purpose : diff --git a/tools/MessageView/MessageView_Window.hxx b/tools/MessageView/MessageView_Window.hxx index bae2ad6fa8..fdd27c3226 100644 --- a/tools/MessageView/MessageView_Window.hxx +++ b/tools/MessageView/MessageView_Window.hxx @@ -36,6 +36,7 @@ #include #include #include +#include #include class View_Displayer; @@ -166,6 +167,8 @@ protected slots: //! Iterates by children items of selected items and display its presentations if found void onPreviewChildren(); + void onUnitByName(); + //! Switch active state in report for clicked type of metric void OnActivateMetric(); @@ -201,6 +204,9 @@ private: MessageModel_Actions* myTreeViewActions; //!< processing history view actions MessageView_ActionsTest* myTestViewActions; //!< check view actions + QTableView* myCustomView; + QDockWidget* myCustomPanelWidget; //!< property pane dockable widget + Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container Handle(AIS_InteractiveObject) myPreviewPresentation; //!< presentation of preview for a selected object