Skip to content

Commit

Permalink
bugfix: close gaps for 'trivial' junctions
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Nov 17, 2023
1 parent 0d1ff5f commit 1776c0d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ namespace hal {
void dumpToFile(const QPoint& pnt) const;

static QString gridPointName(const QPoint& p);

/**
* Returns whether a junction is trivial and can be omitted
* @return true if only one direction and inputs identical to outputs, false otherwise
*/
bool isTrivial() const;

/**
* Reset dump junction file, initialize file with timestamp
*/
static void resetFile();
};

/**
Expand Down
37 changes: 20 additions & 17 deletions plugins/gui/src/graph_widget/layouters/graph_layouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace hal
const static qreal sMinimumHChannelHeight = 20;

GraphLayouter::GraphLayouter(GraphContext* context, QObject* parent)
: QObject(parent), mScene(new GraphicsScene(this)), mParentContext(context), mDone(false), mRollbackStatus(0), mDumpJunctions(true)
: QObject(parent), mScene(new GraphicsScene(this)), mParentContext(context), mDone(false), mRollbackStatus(0), mDumpJunctions(false)
{
SelectionDetailsWidget* details = gContentManager->getSelectionDetailsWidget();
if (details)
Expand Down Expand Up @@ -213,6 +213,8 @@ namespace hal

void GraphLayouter::layout()
{
if (mDumpJunctions)
NetLayoutJunctionEntries::resetFile();
QElapsedTimer timer;
timer.start();
mParentContext->layoutProgress(0);
Expand Down Expand Up @@ -587,12 +589,15 @@ namespace hal
{
if (it != mJunctionEntries.constEnd() && mJunctionThreads.size() < QThread::idealThreadCount())
{
if (mDumpJunctions)
it.value().dumpToFile(it.key());
JunctionThread* jt = new JunctionThread(it.key(), it.value());
connect(jt,&QThread::finished,this,&GraphLayouter::handleJunctionThreadFinished);
mJunctionThreads.append(jt);
jt->start();
if (!it.value().isTrivial())
{
if (mDumpJunctions)
it.value().dumpToFile(it.key());
JunctionThread* jt = new JunctionThread(it.key(), it.value());
connect(jt,&QThread::finished,this,&GraphLayouter::handleJunctionThreadFinished);
mJunctionThreads.append(jt);
jt->start();
}
++it;
}
qApp->processEvents();
Expand Down Expand Up @@ -1342,8 +1347,8 @@ namespace hal

if (it.key().isHorizontal())
{
float x0 = j0 ? mLayouter->mCoordArrayX->lanePosition(ix0,j0->rect().right()) : mLayouter->mCoordX[ix0].junctionExit();
float x1 = j1 ? mLayouter->mCoordArrayX->lanePosition(ix1,j1->rect().left()) : mLayouter->mCoordX[ix1].junctionEntry();
float x0 = mLayouter->mCoordArrayX->lanePosition(ix0,j0? j0->rect().right() : 0);
float x1 = mLayouter->mCoordArrayX->lanePosition(ix1,j1? j1->rect().left() : 0);
float yy = mLayouter->mCoordArrayY->lanePosition(iy0,ilane);
mLines.appendHLine(x0, x1, yy);
}
Expand All @@ -1355,19 +1360,17 @@ namespace hal
{
// netjunction -> endpoint
auto itEpc = mLayouter->mEndpointHash.find(wToPoint);
y0 = j0 ? mLayouter->mCoordArrayY->lanePosition(iy0,j0->rect().bottom()) : mLayouter->mCoordY[iy0].junctionExit();
y1 = itEpc != mLayouter->mEndpointHash.constEnd() ? itEpc.value().lanePosition(j1->rect().top(), true) : mLayouter->mCoordY[iy1].junctionEntry();
// if (itEpc==mEndpointHash.constEnd())
// qDebug() << "xxx to endp" << wToPoint.x() << wToPoint.y() << y0 << y1;
y0 = mLayouter->mCoordArrayY->lanePosition(iy0, j0? j0->rect().bottom() : 0);
y1 = itEpc != mLayouter->mEndpointHash.constEnd() ? itEpc.value().lanePosition(j1->rect().top(), true)
: mLayouter->mCoordArrayY->lanePosition(iy1,0);
}
else
{
// endpoint -> netjunction
auto itEpc = mLayouter->mEndpointHash.find(wFromPoint);
y0 = itEpc != mLayouter->mEndpointHash.constEnd() ? itEpc.value().lanePosition(j0->rect().bottom(), true) : mLayouter->mCoordY[iy0].junctionExit();
y1 = j1 ? mLayouter->mCoordArrayY->lanePosition(iy1,j1->rect().top()) : mLayouter->mCoordY[iy1].junctionEntry();
// if (itEpc==mEndpointHash.constEnd())
// qDebug() << "xxx fr endp" << wFromPoint.x() << wFromPoint.y() << y0 << y1;
y0 = itEpc != mLayouter->mEndpointHash.constEnd() ? itEpc.value().lanePosition(j0->rect().bottom(), true)
: mLayouter->mCoordArrayY->lanePosition(iy0,0);
y1 = mLayouter->mCoordArrayY->lanePosition(iy1, j1? j1->rect().top() : 0);
}
if (y1 > y0)
mLines.appendVLine(xx, y0, y1);
Expand Down
17 changes: 17 additions & 0 deletions plugins/gui/src/graph_widget/layouters/net_layout_junction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QDebug>
#include <QPoint>
#include <QDir>
#include <QDateTime>
#include "hal_core/netlist/project_manager.h"

#ifdef JUNCTION_DEBUG
Expand Down Expand Up @@ -908,6 +909,15 @@ namespace hal {
return mRange.isEntry(0) || mRange.isEntry(1);
}

bool NetLayoutJunctionEntries::isTrivial() const
{
if (mEntries[NetLayoutDirection::Left].isEmpty() && mEntries[NetLayoutDirection::Right].isEmpty())
return mEntries[NetLayoutDirection::Up] == mEntries[NetLayoutDirection::Down];
if (mEntries[NetLayoutDirection::Up].isEmpty() && mEntries[NetLayoutDirection::Down].isEmpty())
return mEntries[NetLayoutDirection::Left] == mEntries[NetLayoutDirection::Right];
return false;
}

void NetLayoutJunctionEntries::dumpToFile(const QPoint &pnt) const
{
QFile ff(QString::fromStdString(ProjectManager::instance()->get_project_directory().get_filename("junction_data.txt").string()));
Expand All @@ -923,6 +933,13 @@ namespace hal {
xout.flush();
}

void NetLayoutJunctionEntries::resetFile()
{
QFile ff(QString::fromStdString(ProjectManager::instance()->get_project_directory().get_filename("junction_data.txt").string()));
if (!ff.open(QIODevice::WriteOnly)) return;
ff.write(QDateTime::currentDateTime().toLocalTime().toString("--- dd.MM.yyyy hh:mm:ss ---\n").toUtf8());
}

QString NetLayoutJunctionEntries::toString() const
{
QString retval;
Expand Down

0 comments on commit 1776c0d

Please sign in to comment.