0032429: Coding - Warnings during compilation on macosx arm64 with option BUILD_Inspe...
[occt.git] / tools / MessageModel / MessageModel_ItemReport.cxx
CommitLineData
d16ecfe2 1// Created on: 2021-04-27
2// Created by: Natalia ERMOLAEVA
3// Copyright (c) 2021 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <inspector/MessageModel_ItemReport.hxx>
17
18#include <inspector/MessageModel_ItemAlert.hxx>
19#include <inspector/MessageModel_ItemRoot.hxx>
20#include <inspector/MessageModel_TreeModel.hxx>
21
22#include <Message.hxx>
23#include <Message_Alert.hxx>
24#include <Message_AttributeMeter.hxx>
25#include <Message_Messenger.hxx>
26#include <Message_PrinterToReport.hxx>
27#include <OSD_Path.hxx>
28
29#include <Standard_WarningsDisable.hxx>
30#include <QColor>
31#include <Standard_WarningsRestore.hxx>
32
33// =======================================================================
34// function : initValue
35// purpose :
36// =======================================================================
37QVariant MessageModel_ItemReport::initValue (const int theRole) const
38{
39 QVariant aParentValue = MessageModel_ItemBase::initValue (theRole);
40 if (aParentValue.isValid())
41 return aParentValue;
42
43 const Handle(Message_Report)& aReport = getReport();
44 if (aReport.IsNull())
45 return QVariant();
46
47 if (theRole == Qt::ForegroundRole)
48 {
49 if (!aReport->IsActiveInMessenger())
50 return QColor(Qt::darkGray);
51
52 return QVariant();
53 }
54 if (theRole == Qt::ToolTipRole && !myDescription.IsEmpty() && Column() == 0) // display the exported file name in tool tip
55 {
56 OSD_Path aPath(myDescription);
57 return QString ("%1%2").arg (aPath.Name().ToCString()).arg (aPath.Extension().ToCString());
58 }
59
60 if (theRole != Qt::DisplayRole)
61 return QVariant();
62
63 if (Column() == 0)
64 return aReport->DynamicType()->Name();
65
66 Message_MetricType aMetricType;
67 int aPosition;
68 if (MessageModel_TreeModel::IsMetricColumn (Column(), aMetricType, aPosition) &&
69 (aMetricType == Message_MetricType_ProcessCPUUserTime || aMetricType == Message_MetricType_ProcessCPUSystemTime ||
70 aMetricType == Message_MetricType_WallClock))
71 {
72 if (aPosition == 0) return CumulativeMetric (aReport, aMetricType);
73 else if (aPosition == 1) return "100";
74 }
75 return QVariant();
76}
77
78// =======================================================================
79// function : initRowCount
80// purpose :
81// =======================================================================
82int MessageModel_ItemReport::initRowCount() const
83{
84 const Handle(Message_Report)& aReport = getReport();
85 if (aReport.IsNull())
86 return 0;
87
88 MessageModel_ItemReport* aCurrentItem = (MessageModel_ItemReport*)this;
89 for (int aGravityId = Message_Trace; aGravityId <= Message_Fail; aGravityId++)
90 {
91 const Message_ListOfAlert& anAlerts = aReport->GetAlerts ((Message_Gravity)aGravityId);
92 for (Message_ListOfAlert::Iterator anIt(anAlerts); anIt.More(); anIt.Next())
93 {
94 Message_ListOfAlert aCurAlerts;
95 aCurAlerts.Append (anIt.Value());
96 aCurrentItem->myChildAlerts.Bind(myChildAlerts.Size(), aCurAlerts);
97 }
98 }
99 return aCurrentItem->myChildAlerts.Size();
100}
101
102// =======================================================================
103// function : createChild
104// purpose :
105// =======================================================================
106TreeModel_ItemBasePtr MessageModel_ItemReport::createChild (int theRow, int theColumn)
107{
108 return MessageModel_ItemAlert::CreateItem (currentItem(), theRow, theColumn);
109}
110
111// =======================================================================
112// function : Init
113// purpose :
114// =======================================================================
115void MessageModel_ItemReport::Init()
116{
117 MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (Parent());
118 myReport = aRootItem ? aRootItem->GetReport (Row(), myDescription) : Handle(Message_Report)();
119
120 MessageModel_ItemBase::Init();
121}
122
123// =======================================================================
124// function : getReport
125// purpose :
126// =======================================================================
127const Handle(Message_Report)& MessageModel_ItemReport::getReport() const
128{
129 initItem();
130 return myReport;
131}
132
133// =======================================================================
134// function : Reset
135// purpose :
136// =======================================================================
137void MessageModel_ItemReport::Reset()
138{
139 MessageModel_ItemBase::Reset();
140 myReport = Handle(Message_Report)();
141 myChildAlerts.Clear();
142}
143
144// =======================================================================
145// function : initItem
146// purpose :
147// =======================================================================
148void MessageModel_ItemReport::initItem() const
149{
150 if (IsInitialized())
151 return;
152 const_cast<MessageModel_ItemReport*>(this)->Init();
153}
154
155// =======================================================================
156// function : FindReportItem
157// purpose :
158// =======================================================================
159MessageModel_ItemReportPtr MessageModel_ItemReport::FindReportItem (const TreeModel_ItemBasePtr& theItem)
160{
161 TreeModel_ItemBasePtr anItem = theItem;
162 while (anItem)
163 {
164 if (MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItem))
165 return aReportItem;
166
167 anItem = anItem->Parent();
168 }
169 return MessageModel_ItemReportPtr();
170}
171
172// =======================================================================
173// function : FindReport
174// purpose :
175// =======================================================================
176Handle(Message_Report) MessageModel_ItemReport::FindReport (const MessageModel_ItemBasePtr& theItem)
177{
178 Handle(Message_Report) aReport;
179
180 MessageModel_ItemBasePtr anItem = theItem;
181 while (anItem)
182 {
183 MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItem);
184
185 if (aReportItem)
186 return aReportItem->GetReport();
187
188 anItem = itemDynamicCast<MessageModel_ItemBase>(anItem->Parent());
189 }
190 return NULL;
191}
192
193// =======================================================================
194// function : CumulativeMetric
195// purpose :
196// =======================================================================
197Standard_Real MessageModel_ItemReport::CumulativeMetric (const Handle(Message_Report)& theReport, const Message_MetricType theMetricType)
198{
199 if (!theReport->ActiveMetrics().Contains (theMetricType))
200 return 0;
201
202 Standard_Real aMetric = 0;
203 for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
204 {
205 const Message_ListOfAlert& anAlerts = theReport->GetAlerts ((Message_Gravity)iGravity);
206 Handle(Message_AttributeMeter) aFirstAttribute/*, aLastAttribute*/;
207 for (Message_ListOfAlert::Iterator anAlertsIterator (anAlerts); anAlertsIterator.More(); anAlertsIterator.Next())
208 {
209 Handle(Message_AlertExtended) anAlert = Handle(Message_AlertExtended)::DownCast (anAlertsIterator.Value());
210 if (anAlert.IsNull())
211 continue;
212 Handle(Message_AttributeMeter) anAttribute = Handle(Message_AttributeMeter)::DownCast (anAlert->Attribute());
213 if (anAttribute.IsNull() || !anAttribute->HasMetric (theMetricType) || !anAttribute->IsMetricValid (theMetricType))
214 continue;
215
216 //if (aFirstAttribute.IsNull())
217 // aFirstAttribute = anAttribute;
218 //else
219 //{
220 //aLastAttribute = anAttribute;
221 //}
222 aMetric += anAttribute->StopValue (theMetricType) - anAttribute->StartValue (theMetricType);
223 }
224 //if (aFirstAttribute.IsNull())
225 // continue;
226 //if (aLastAttribute.IsNull())
227 // aLastAttribute = aFirstAttribute;
228
229 //aMetric += aLastAttribute->StopValue (theMetricType) - aFirstAttribute->StartValue (theMetricType);
230 }
231 return aMetric;
232}