]> OCCT Git - occt-copy.git/commitdiff
0031959: Inspectors - Statistics by name CR0_DMUReviewer_IR-2020-05-15_CR31959
authorsshutina <sshutina@opencascade.com>
Wed, 25 Nov 2020 12:51:28 +0000 (15:51 +0300)
committersshutina <sshutina@opencascade.com>
Wed, 25 Nov 2020 12:52:12 +0000 (15:52 +0300)
tools/MessageView/FILES
tools/MessageView/MessageView_UnitByNameModel.cxx [new file with mode: 0644]
tools/MessageView/MessageView_UnitByNameModel.hxx [new file with mode: 0644]
tools/MessageView/MessageView_Window.cxx
tools/MessageView/MessageView_Window.hxx

index 5fe2f5266101f0dd505d8ab44cda0717b82ed8c8..86a3a722dc17f785e633e72676d1b76231cfd35a 100644 (file)
@@ -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 (file)
index 0000000..a0e8add
--- /dev/null
@@ -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 <inspector/MessageView_UnitByNameModel.hxx>
+#include <inspector/MessageModel_ItemAlert.hxx>
+#include <inspector/MessageModel_ItemReport.hxx>
+#include <Message_AlertExtended.hxx>
+#include <Message_Attribute.hxx>
+#include <Message_AttributeMeter.hxx>
+#include <Message_CompositeAlerts.hxx>
+#include <Message_Report.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QApplication>
+#include <QMap>
+#include <QPair>
+#include <Standard_WarningsRestore.hxx>
+
+const int ICON_SIZE = 40;
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+void MessageView_UnitByNameModel::Init (const TreeModel_ItemBasePtr theItemBase)
+{
+  MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport> (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<MessageModel_ItemAlert> (theItemBase);
+    if (anAlertItem)
+    {
+      initByAlert (anAlertItem->GetAlert());
+    }
+  }
+  std::map<double, std::list<QString>> theTmpMap;
+  std::list<double> theTimes;
+  for (QMap<QString, QPair<int, double> >::Iterator i = myValues.begin(); i != myValues.end(); ++i)
+  {
+    std::map<double, std::list<QString>>::iterator iter = theTmpMap.find(i.value().second);
+    if (iter != theTmpMap.end())
+    {
+      theTmpMap.at (i.value().second).push_back (i.key());
+    }
+    else
+    {
+      std::list<QString> list;
+      list.push_back (i.key());
+      theTmpMap.insert (std::pair<double, std::list<QString> >(i.value().second, list));
+      theTimes.push_back (i.value().second);
+    }
+  }
+
+  theTimes.sort();
+  theTimes.reverse();
+
+  for (std::list<double>::iterator iter = theTimes.begin(); iter != theTimes.end(); iter++)
+  {
+    double aTime = *iter;
+    std::list<QString> names = theTmpMap.at (aTime);
+    for (std::list<QString>::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<int, RowValues>::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 (file)
index 0000000..26531b2
--- /dev/null
@@ -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 <Standard_Macro.hxx>
+
+#include <inspector/TreeModel_ItemBase.hxx>
+#include <Message_Alert.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QAbstractTableModel>
+#include <QStringList>
+#include <QItemDelegate>
+#include <Standard_WarningsRestore.hxx>
+
+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<QString, QPair<int, double> > myValues;
+  QMap<int, RowValues> myValues2;
+};
+
+#endif
index a2270827d1cc2302f9bcf11006fcbd882fff879a..91dd3a2872d7c6dbc8320ceec00f0cfa92bcc5e0 100644 (file)
@@ -23,6 +23,7 @@
 #include <inspector/MessageModel_ItemRoot.hxx>
 #include <inspector/MessageModel_Tools.hxx>
 #include <inspector/MessageModel_TreeModel.hxx>
+#include <inspector/MessageView_UnitByNameModel.hxx>
 
 #include <inspector/TreeModel_ContextMenu.hxx>
 #include <inspector/TreeModel_Tools.hxx>
@@ -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 :
index bae2ad6fa812efb3056cdc014896a9b8f9136fb4..fdd27c3226c95475203ba929e0f6d305ed8f6536 100644 (file)
@@ -36,6 +36,7 @@
 #include <QObject>
 #include <QPoint>
 #include <QString>
+#include <QTableView>
 #include <QTreeView>
 
 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