From d8d38cd1078a40e2660c4dd4ff91966ac3f031bb Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 10 Jun 2018 19:56:17 +0200 Subject: [PATCH] Draw fpga model --- dummy/chip.cc | 24 +++++++++++++++++++ gui/fpgaviewwidget.cc | 55 +++++++++++++++++++++++++++++++++---------- gui/fpgaviewwidget.h | 1 + 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/dummy/chip.cc b/dummy/chip.cc index 603be7e5..4184bc67 100644 --- a/dummy/chip.cc +++ b/dummy/chip.cc @@ -123,3 +123,27 @@ const vector &Chip::getWireAliases(WireId wire) const static vector ret; return ret; } + +vector Chip::getBelGraphics(BelId bel) const +{ + static vector ret; + return ret; +} + +vector Chip::getWireGraphics(WireId wire) const +{ + static vector ret; + return ret; +} + +vector Chip::getPipGraphics(PipId pip) const +{ + static vector ret; + return ret; +} + +vector Chip::getFrameGraphics() const +{ + static vector ret; + return ret; +} diff --git a/gui/fpgaviewwidget.cc b/gui/fpgaviewwidget.cc index 0e125449..db4179e4 100644 --- a/gui/fpgaviewwidget.cc +++ b/gui/fpgaviewwidget.cc @@ -7,7 +7,7 @@ FPGAViewWidget::FPGAViewWidget(QWidget *parent) : QOpenGLWidget(parent), m_xMove(0), m_yMove(0), m_zDistance(1.0) { - design = static_cast(parent)->getDesign(); + design = qobject_cast(parentWidget()->parentWidget()->parentWidget()->parentWidget())->getDesign(); } FPGAViewWidget::~FPGAViewWidget() {} @@ -51,6 +51,34 @@ void FPGAViewWidget::initializeGL() glClearColor(1.0, 1.0, 1.0, 0.0); } +void FPGAViewWidget::drawElement(const GraphicElement &el) +{ + float scale = 1.0, offset = 0.0; + if (el.type == GraphicElement::G_BOX) { + glBegin(GL_LINES); + glVertex3f((offset + scale * el.x1), (offset + scale * el.y1), 0.0f); + glVertex3f((offset + scale * el.x2), (offset + scale * el.y1), 0.0f); + + glVertex3f((offset + scale * el.x2), (offset + scale * el.y1), 0.0f); + glVertex3f((offset + scale * el.x2), (offset + scale * el.y2), 0.0f); + + glVertex3f((offset + scale * el.x2), (offset + scale * el.y2), 0.0f); + glVertex3f((offset + scale * el.x1), (offset + scale * el.y2), 0.0f); + + glVertex3f((offset + scale * el.x1), (offset + scale * el.y2), 0.0f); + glVertex3f((offset + scale * el.x1), (offset + scale * el.y1), 0.0f); + glEnd(); + + } + + if (el.type == GraphicElement::G_LINE) { + glBegin(GL_LINES); + glVertex3f((offset + scale * el.x1), (offset + scale * el.y1), 0.0f); + glVertex3f((offset + scale * el.x2), (offset + scale * el.y2), 0.0f); + glEnd(); + } +} + void FPGAViewWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -59,8 +87,8 @@ void FPGAViewWidget::paintGL() glTranslatef(m_xMove, m_yMove, -10.0); glScalef(m_zDistance, m_zDistance, 0.0f); - // Example grid - glColor3f(0.8, 0.8, 0.8); + // Grid + glColor3f(0.9, 0.9, 0.9); glBegin(GL_LINES); for (float i = -100; i <= 100; i += 0.1) { glVertex3f((float)i, -100.0f, 0.0f); @@ -68,7 +96,7 @@ void FPGAViewWidget::paintGL() glVertex3f(-100.0f, (float)i, 0.0f); glVertex3f(100.0f, (float)i, 0.0f); } - glColor3f(0.5, 0.5, 0.5); + glColor3f(0.7, 0.7, 0.7); for (int i = -100; i <= 100; i += 1) { glVertex3f((float)i, -100.0f, 0.0f); glVertex3f((float)i, 100.0f, 0.0f); @@ -77,15 +105,16 @@ void FPGAViewWidget::paintGL() } glEnd(); - // Example triangle - glBegin(GL_TRIANGLES); - glColor3f(1.0, 0.0, 0.0); - glVertex3f(-0.5, -0.5, 0); - glColor3f(0.0, 1.0, 0.0); - glVertex3f(0.5, -0.5, 0); - glColor3f(0.0, 0.0, 1.0); - glVertex3f(0, 0.5, 0); - glEnd(); + glColor3f(0.1, 0.1, 0.1); + glLineWidth(0.1); + // Draw Bels + for (auto bel : design->chip.getBels()) { + for (auto &el : design->chip.getBelGraphics(bel)) + drawElement(el); + } + // Draw Frame Graphics + for (auto &el : design->chip.getFrameGraphics()) + drawElement(el); } void FPGAViewWidget::resizeGL(int width, int height) diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index 070dd2f3..1eb98065 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -32,6 +32,7 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + void drawElement(const GraphicElement &el); private: int m_windowWidth;