Files

152 lines
4.1 KiB
C++

/*
* Copyright (c) 2025 Fraunhofer IESE. All rights reserved.
*
* Authors:
* Iron Prando da Silva
*/
#include "phasedependency.h"
#include "businessObjects/phases/phase.h"
#include <iostream>
PhaseDependency::PhaseDependency(DependencyType type,
QString timeDependency,
std::shared_ptr<Phase> dependency)
{
mType = type;
mTimeDependency = timeDependency;
mDependency = dependency;
}
PhaseDependency::PhaseDependency(DependencyType type, QString timeDependency)
{
mType = type;
mTimeDependency = timeDependency;
mDependency = nullptr;
mIsInvisible = true;
}
PhaseDependency::~PhaseDependency()
{
}
bool PhaseDependency::draw(QPoint& end,
const TraceDrawingProperties& drawingProperties,
QPainter* painter,
const QwtScaleMap& xMap,
const QwtScaleMap& yMap)
{
if (mIsInvisible)
return false;
// traceTime depBegin = mDependency->span.Begin();
traceTime depEnd = mDependency->span.End();
if (xMap.transform(depEnd) < 0)
return false;
bool drawn = false;
for (auto yVal : mDependency->getYVals(drawingProperties))
{
mDraw(end, yVal, drawingProperties, painter, xMap, yMap);
drawn = true;
}
return drawn;
}
void PhaseDependency::mDraw(QPoint& end,
double depY,
const TraceDrawingProperties& drawingProperties,
QPainter* painter,
const QwtScaleMap& xMap,
const QwtScaleMap& yMap)
{
traceTime depBegin = mDependency->span.Begin();
// traceTime depEnd = mDependency->span.End();
// traceTime depOffset =
// (depBegin == depEnd) ? static_cast<traceTime>(0.05 * mDependency->clk) : 0;
double depYVal = yMap.transform(depY);
// double depSymbolHeight = yMap.transform(0) - yMap.transform(mDependency->hexagonHeight);
QPoint depLineFrom(
static_cast<int>(xMap.transform(depBegin /* + (depEnd + depOffset - depBegin)/4*/)),
static_cast<int>(depYVal));
QLineF line(depLineFrom, end);
double angle = std::atan2(-line.dy(), line.dx());
qreal arrowSize = 10;
QPointF arrowP1 =
line.p2() - QPointF(sin(angle + M_PI / 3) * arrowSize, cos(angle + M_PI / 3) * arrowSize);
QPointF arrowP2 = line.p2() - QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
cos(angle + M_PI - M_PI / 3) * arrowSize);
QPolygonF arrowHead;
arrowHead << line.p2() << arrowP1 << arrowP2;
painter->setBrush(QPalette().base());
painter->setPen(QPalette().text().color());
painter->drawLine(line);
painter->drawPolygon(arrowHead);
if (drawingProperties.drawDependenciesOption.text == DependencyTextOption::Enabled)
{
QPoint textPosition(line.x1() + (line.x2() - line.x1()) / 2,
line.y1() + (line.y2() - line.y1()) / 2);
auto alignment = TextPositioning::topRight;
if (textPosition.y() == line.y1())
{
alignment = TextPositioning::topCenter;
}
else if (textPosition.x() == line.x1())
{
if (line.y1() > line.y2())
{
alignment = TextPositioning::bottomRight;
}
}
drawText(painter, mTimeDependency, textPosition, alignment, QPalette().text().color());
}
}
QString PhaseDependency::dependencyTypeName(DependencyType dtype)
{
switch (dtype)
{
case IntraBank:
return "IntraBank";
case IntraBankGroup:
return "IntraBankGroup";
case IntraBankInGroup:
return "IntraBankInGroup";
case IntraRank:
return "IntraRank";
case IntraLogicalRank:
return "IntraLogicalRank";
case IntraPhysicalRank:
return "IntraPhysicalRank";
case IntraDIMMRank:
return "IntraDIMMRank";
case InterRank:
return "InterRank";
case InterDIMMRank:
return "InterDIMMRank";
default:
// TODO - maybe throw?
return "";
}
}