Skip to content

Commit

Permalink
Merge branch 'memory-designer-address-spaces'
Browse files Browse the repository at this point in the history
  • Loading branch information
teuhom committed Jan 20, 2025
2 parents 16813a2 + 466d238 commit 852a5bb
Show file tree
Hide file tree
Showing 30 changed files with 375 additions and 188 deletions.
Binary file added common/graphics/filterMemoryOverlap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added common/graphics/memOverlap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions common/graphicsItems/GraphicsColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ ColumnTypes::ColumnContentType GraphicsColumn::getContentType() const
//-----------------------------------------------------------------------------
void GraphicsColumn::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
if (static_cast<DesignDiagram*>(scene())->isProtected())
if (auto designDiagram = dynamic_cast<DesignDiagram*>(scene()); designDiagram && designDiagram->isProtected())
{
return;
}
Expand All @@ -438,7 +438,7 @@ void GraphicsColumn::mousePressEvent(QGraphicsSceneMouseEvent* event)
void GraphicsColumn::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
// Discard mouse move if the diagram is protected.
if (static_cast<DesignDiagram*>(scene())->isProtected())
if (auto designDiagram = dynamic_cast<DesignDiagram*>(scene()); designDiagram && designDiagram->isProtected())
{
return;
}
Expand Down Expand Up @@ -504,7 +504,9 @@ void GraphicsColumn::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
QGraphicsRectItem::hoverEnterEvent(event);

if (!static_cast<DesignDiagram*>(scene())->isProtected() &&
if (auto designDiagram = dynamic_cast<DesignDiagram*>(scene());
designDiagram &&
designDiagram->isProtected() &&
qAbs(event->pos().x() - boundingRect().right()) <= 10 &&
!mouseNearResizeArea_)
{
Expand All @@ -520,7 +522,8 @@ void GraphicsColumn::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
{
QGraphicsRectItem::hoverMoveEvent(event);

if (static_cast<DesignDiagram*>(scene())->isProtected())
if (auto designDiagram = dynamic_cast<DesignDiagram*>(scene());
designDiagram && designDiagram->isProtected())
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions editors/MemoryDesigner/AddressSpaceGraphicsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cpuIcon_(new QGraphicsPixmapItem(QPixmap(":icons/common/graphics/settings-code_e
setBrush(addressSpaceBrush);

quint64 spaceRangeInt = memoryItem->getRange().toULongLong();
int spaceWidth = 250;
int spaceWidth = MemoryDesignerConstants::ITEMWIDTH;

setGraphicsRectangle(spaceWidth + 1, spaceRangeInt);

Expand All @@ -53,7 +53,7 @@ cpuIcon_(new QGraphicsPixmapItem(QPixmap(":icons/common/graphics/settings-code_e
cpuIcon_->setPos(spaceWidth / 2 - cpuIcon_->pixmap().width() - GridSize, GridSize * 3);
cpuIcon_->setVisible(false);

qreal segmentPositionX = - boundingRect().width() / 4;
qreal segmentPositionX = - MemoryDesignerConstants::MAPSUBITEMPOSITIONX - 1;
setupSubItems(segmentPositionX, getSubItemType(), memoryItem);

setLabelPositions();
Expand Down
46 changes: 22 additions & 24 deletions editors/MemoryDesigner/MainMemoryGraphicsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,34 +240,32 @@ bool MainMemoryGraphicsItem::labelCollidesWithRangeLabels(QGraphicsTextItem* lab
//-----------------------------------------------------------------------------
void MainMemoryGraphicsItem::createOverlappingConnectionMarkers()
{
if (getMemoryConnections().size() > 1)
auto memConnections = getMemoryConnections();

if (memConnections.size() < 2)
return;

for (auto const& selectedItem : memConnections)
{
QMultiMapIterator<quint64, MemoryConnectionItem*> connectionIterator(getMemoryConnections());
while (connectionIterator.hasNext())
for (auto const& comparisonItem : memConnections)
{
connectionIterator.next();

QMultiMapIterator<quint64, MemoryConnectionItem*> comparisonIterator(connectionIterator);
while (comparisonIterator.hasNext())
if (!selectedItem || !comparisonItem || selectedItem == comparisonItem)
{
comparisonIterator.next();

MemoryConnectionItem* selectedItem = connectionIterator.value();
MemoryConnectionItem* comparisonItem = comparisonIterator.value();
continue;
}

QRectF connectionRect = selectedItem->sceneBoundingRect();
QRectF comparisonRect = comparisonItem->sceneBoundingRect();
QRectF connectionRect = selectedItem->sceneBoundingRect();
QRectF comparisonRect = comparisonItem->sceneBoundingRect();

if (selectedItem && comparisonItem && selectedItem != comparisonItem &&
selectedItem->getConnectionStartItem() == this &&
comparisonItem->getConnectionStartItem() == this &&
MemoryDesignerConstants::itemOverlapsAnotherItem(connectionRect,
selectedItem->pen().width(), comparisonRect, comparisonItem->pen().width()))
{
MemoryCollisionItem* newCollisionItem =
new MemoryCollisionItem(selectedItem, comparisonItem, scene());
memoryCollisions_.append(newCollisionItem);
}
if (selectedItem->getConnectionStartItem() == this &&
comparisonItem->getConnectionStartItem() == this &&
MemoryDesignerConstants::itemOverlapsAnotherItem(connectionRect,
selectedItem->pen().width(), comparisonRect, comparisonItem->pen().width()) &&
connectionRect.width() < comparisonRect.width())
{
MemoryCollisionItem* newCollisionItem =
new MemoryCollisionItem(selectedItem, comparisonItem, scene());
memoryCollisions_.append(newCollisionItem);
}
}
}
Expand Down Expand Up @@ -575,7 +573,7 @@ void MainMemoryGraphicsItem::extendMemoryItem()
{
qreal positionX = itemTopLeft.x() + lineWidth;
qreal extensionWidth = itemLowRight.x() - itemTopLeft.x() - lineWidth;
qreal positionY = extensionTop;
qreal positionY = extensionTop - lineWidth;
qreal extensionHeight = extensionLow - extensionTop;

auto extensionItem = new MemoryExtensionGraphicsItem(positionX, positionY, extensionWidth, extensionHeight, getContainingInstance(), this);
Expand Down
40 changes: 3 additions & 37 deletions editors/MemoryDesigner/MemoryCollisionItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,43 +58,9 @@ MemoryCollisionItem::~MemoryCollisionItem()
//-----------------------------------------------------------------------------
void MemoryCollisionItem::setCollisionBrush()
{
qreal mainCollisionOpacity = 0.4;

QVector<MemoryCollisionItem*> collidingCollisionItems;
foreach (QGraphicsItem* collidingItem, collidingItems())
{
MemoryCollisionItem* memoryCollisionItem = dynamic_cast<MemoryCollisionItem*>(collidingItem);
if (memoryCollisionItem && memoryCollisionItem != this)
{
collidingCollisionItems.append(memoryCollisionItem);
}
}

if (!collidingCollisionItems.isEmpty())
{
collidingCollisionItems.removeFirst();

mainCollisionOpacity = 0.3;
qreal collisionOpacity = mainCollisionOpacity;

int collisionMarker = collidingCollisionItems.size();
for (int collisionIndex = collidingCollisionItems.size() - 1; collisionIndex >= 0; --collisionIndex)
{
MemoryCollisionItem* collidingItem = collidingCollisionItems.at(collisionIndex);

if (collidingItem->boundingRect().top() == boundingRect().top() &&
collidingItem->boundingRect().bottom() == boundingRect().bottom())
{
collisionMarker = collisionMarker - 1;
collisionOpacity = collisionOpacity / (collidingCollisionItems.size() - collisionMarker);
collidingItem->setOpacity(collisionOpacity);
}
}
}

QBrush collisionBrush(KactusColors::MISSING_COMPONENT);
setBrush(collisionBrush);
setOpacity(mainCollisionOpacity);
setOpacity(0.2);
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -151,7 +117,7 @@ void MemoryCollisionItem::setLabels()

QVector<MemoryColumn*> collidingColumns;

foreach (QGraphicsItem* collidingItem, collidingItems())
for (QGraphicsItem* collidingItem : collidingItems())
{
MemoryMapGraphicsItem* mapGraphicsItem = dynamic_cast<MemoryMapGraphicsItem*>(collidingItem);
QGraphicsRectItem* extensionItem = dynamic_cast<QGraphicsRectItem*>(collidingItem);
Expand Down Expand Up @@ -227,6 +193,6 @@ void MemoryCollisionItem::setRectangle()
qreal itemHeight = endY - startY;

QPointF spaceItemStartPoint (startX, startY);

setRect(spaceItemStartPoint.x(), spaceItemStartPoint.y(), itemWidth, itemHeight - 1);
}
4 changes: 2 additions & 2 deletions editors/MemoryDesigner/MemoryColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ QMultiMap<qreal, MainMemoryGraphicsItem*> MemoryColumn::getGraphicsItemInOrder()
{
QMultiMap<qreal, MainMemoryGraphicsItem*> orderedGraphicsItems;

foreach (QGraphicsItem* graphicsItem, getItems())
for (QGraphicsItem* graphicsItem : getItems())
{
auto memoryItem = dynamic_cast<MainMemoryGraphicsItem*>(graphicsItem);
if (memoryItem)
Expand Down Expand Up @@ -254,7 +254,7 @@ bool MemoryColumn::itemOverlapsAnotherPlacedColumnItem(MainMemoryGraphicsItem co
int lineWidth,
QSharedPointer<QVector<MainMemoryGraphicsItem*> > placedItems) const
{
foreach(MainMemoryGraphicsItem * comparisonItem, getGraphicsItemInOrder())
for (MainMemoryGraphicsItem * comparisonItem : getGraphicsItemInOrder())
{
if (placedItems->contains(comparisonItem) && comparisonItem != memoryItem)
{
Expand Down
13 changes: 9 additions & 4 deletions editors/MemoryDesigner/MemoryColumnHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,16 @@ MemoryColumn* MemoryColumnHandler::createAddressSpaceColumn()
{
QString spaceName = MemoryDesignerConstants::ADDRESSSPACECOLUMN_NAME;

QPointF columnPosition (0,0);

int spaceCounter = 0;
foreach (GraphicsColumn* column, layout_->getColumns())
int lastSpaceColumnIndex = 0;
for (int i = 0; i < layout_->getColumns().size(); ++i)
{
auto column = layout_->getColumns().at(i);

if (column->name().contains(spaceName, Qt::CaseInsensitive))
{
spaceCounter += 1;
lastSpaceColumnIndex = i;
}
}
if (spaceCounter != 0)
Expand All @@ -169,7 +171,10 @@ MemoryColumn* MemoryColumnHandler::createAddressSpaceColumn()
MemoryColumn* spaceColumn(new MemoryColumn(addressSpaceColumnDescription, layout_.data(), 0));
layout_->addColumn(spaceColumn);

spaceColumn->setPos(columnPosition);
auto lastColumnPos = layout_->getColumns().at(lastSpaceColumnIndex)->pos();
auto lastColumnRightSideX = layout_->getColumns().at(lastSpaceColumnIndex)->rect().width() + lastColumnPos.x();

spaceColumn->setPos(QPointF(lastColumnRightSideX + 1, 0));

layout_->onMoveColumn(spaceColumn);
layout_->onReleaseColumn(spaceColumn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MemoryConnectionAddressCalculator::ConnectionPathVariables MemoryConnectionAddre

newPathVariables.spaceChain_.append(newChainedSpace);

foreach(QSharedPointer<ConnectivityInterface const> pathInterface, connectionPath)
for (QSharedPointer<ConnectivityInterface const> pathInterface : connectionPath)
{
if (pathInterface != startInterface && pathInterface != endInterface)
{
Expand Down
4 changes: 2 additions & 2 deletions editors/MemoryDesigner/MemoryConnectionAddressCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ namespace MemoryConnectionAddressCalculator
//! Last address of the connected memory map interface.
quint64 endAddressNumber_;

//! The remapped base address.
//! The remapped base address. (where the mapped memory map starts in the initiator address space)
quint64 remappedAddress_;

//! The remapped end address.
//! The remapped end address. (where the mapped memory map ends in the initiator address space)
quint64 remappedEndAddress_;
};

Expand Down
Loading

0 comments on commit 852a5bb

Please sign in to comment.