2018-06-22 02:12:20 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Serge Bazanski <q3k@symbioticeda.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-06-06 03:03:06 +08:00
|
|
|
#ifndef MAPGLWIDGET_H
|
|
|
|
#define MAPGLWIDGET_H
|
|
|
|
|
2018-06-11 02:48:52 +08:00
|
|
|
#include <QMainWindow>
|
2018-07-18 02:16:26 +08:00
|
|
|
#include <QMutex>
|
2018-06-22 02:12:20 +08:00
|
|
|
#include <QOpenGLBuffer>
|
2018-06-06 03:03:06 +08:00
|
|
|
#include <QOpenGLFunctions>
|
2018-06-22 02:12:20 +08:00
|
|
|
#include <QOpenGLShaderProgram>
|
2018-06-23 03:16:49 +08:00
|
|
|
#include <QOpenGLVertexArrayObject>
|
2018-06-07 04:53:52 +08:00
|
|
|
#include <QOpenGLWidget>
|
2018-06-06 03:03:06 +08:00
|
|
|
#include <QPainter>
|
2018-07-18 02:16:26 +08:00
|
|
|
#include <QThread>
|
2018-07-20 20:19:45 +08:00
|
|
|
#include <QTimer>
|
2018-07-18 02:16:26 +08:00
|
|
|
#include <QWaitCondition>
|
2018-06-22 02:12:20 +08:00
|
|
|
|
2018-06-12 02:12:57 +08:00
|
|
|
#include "nextpnr.h"
|
2018-07-26 23:20:58 +08:00
|
|
|
#include "quadtree.h"
|
2018-07-27 00:37:24 +08:00
|
|
|
#include "lineshader.h"
|
2018-06-06 03:03:06 +08:00
|
|
|
|
2018-06-22 02:12:20 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2018-07-20 17:58:30 +08:00
|
|
|
class PeriodicRunner : public QThread
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-07-20 20:19:45 +08:00
|
|
|
private:
|
2018-07-20 17:58:30 +08:00
|
|
|
QMutex mutex_;
|
|
|
|
QWaitCondition condition_;
|
|
|
|
bool abort_;
|
|
|
|
std::function<void()> target_;
|
|
|
|
QTimer timer_;
|
2018-07-20 20:19:45 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PeriodicRunner(QObject *parent, std::function<void()> target)
|
|
|
|
: QThread(parent), abort_(false), target_(target), timer_(this)
|
2018-07-20 17:58:30 +08:00
|
|
|
{
|
|
|
|
connect(&timer_, &QTimer::timeout, this, &PeriodicRunner::poke);
|
|
|
|
}
|
|
|
|
|
|
|
|
void run(void) override
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
mutex_.lock();
|
|
|
|
condition_.wait(&mutex_);
|
|
|
|
|
|
|
|
if (abort_) {
|
|
|
|
mutex_.unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
target_();
|
|
|
|
|
|
|
|
mutex_.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-22 04:44:40 +08:00
|
|
|
void startTimer(int msecs) { timer_.start(msecs); }
|
2018-07-20 17:58:30 +08:00
|
|
|
|
|
|
|
~PeriodicRunner()
|
|
|
|
{
|
|
|
|
mutex_.lock();
|
|
|
|
abort_ = true;
|
|
|
|
condition_.wakeOne();
|
|
|
|
mutex_.unlock();
|
|
|
|
|
|
|
|
wait();
|
|
|
|
}
|
|
|
|
|
2018-07-20 20:19:45 +08:00
|
|
|
void poke(void) { condition_.wakeOne(); }
|
2018-07-20 17:58:30 +08:00
|
|
|
};
|
|
|
|
|
2018-06-06 03:03:06 +08:00
|
|
|
class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2018-06-07 04:53:52 +08:00
|
|
|
public:
|
2018-06-06 03:03:06 +08:00
|
|
|
FPGAViewWidget(QWidget *parent = 0);
|
|
|
|
~FPGAViewWidget();
|
|
|
|
|
2018-06-07 04:53:52 +08:00
|
|
|
protected:
|
2018-07-27 00:33:19 +08:00
|
|
|
// Qt callbacks.
|
2018-06-06 03:03:06 +08:00
|
|
|
void initializeGL() Q_DECL_OVERRIDE;
|
|
|
|
void paintGL() Q_DECL_OVERRIDE;
|
|
|
|
void resizeGL(int width, int height) Q_DECL_OVERRIDE;
|
|
|
|
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
|
|
|
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
|
2018-07-27 00:33:19 +08:00
|
|
|
QSize minimumSizeHint() const override;
|
|
|
|
QSize sizeHint() const override;
|
|
|
|
|
2018-07-26 23:26:05 +08:00
|
|
|
|
2018-06-26 21:47:22 +08:00
|
|
|
public Q_SLOTS:
|
|
|
|
void newContext(Context *ctx);
|
2018-07-15 01:44:37 +08:00
|
|
|
void onSelectedArchItem(std::vector<DecalXY> decals);
|
2018-07-15 23:50:58 +08:00
|
|
|
void onHighlightGroupChanged(std::vector<DecalXY> decals, int group);
|
2018-07-18 02:16:26 +08:00
|
|
|
void pokeRenderer(void);
|
2018-07-26 23:26:05 +08:00
|
|
|
void zoomIn();
|
|
|
|
void zoomOut();
|
|
|
|
void zoomSelected();
|
|
|
|
void zoomOutbound();
|
2018-07-26 23:14:56 +08:00
|
|
|
|
2018-07-26 23:20:58 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void clickedBel(BelId bel);
|
2018-07-15 18:39:19 +08:00
|
|
|
|
2018-06-07 04:53:52 +08:00
|
|
|
private:
|
2018-07-13 04:04:13 +08:00
|
|
|
const float zoomNear_ = 1.0f; // do not zoom closer than this
|
2018-07-13 03:22:53 +08:00
|
|
|
const float zoomFar_ = 10000.0f; // do not zoom further than this
|
|
|
|
const float zoomLvl1_ = 100.0f;
|
|
|
|
const float zoomLvl2_ = 50.0f;
|
2018-06-22 02:12:20 +08:00
|
|
|
|
2018-06-23 03:16:49 +08:00
|
|
|
Context *ctx_;
|
2018-07-20 17:58:30 +08:00
|
|
|
QTimer paintTimer_;
|
|
|
|
std::unique_ptr<PeriodicRunner> renderRunner_;
|
2018-07-18 02:16:26 +08:00
|
|
|
|
2018-07-26 23:20:58 +08:00
|
|
|
using QuadTreeBels = QuadTree<float, BelId>;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void commitToQuadtree(T *tree, const DecalXY &decal, BelId bel)
|
|
|
|
{
|
|
|
|
float offsetX = decal.x;
|
|
|
|
float offsetY = decal.y;
|
|
|
|
|
|
|
|
for (auto &el : ctx_->getDecalGraphics(decal.decal)) {
|
2018-07-27 00:46:27 +08:00
|
|
|
if (el.type == GraphicElement::TYPE_BOX) {
|
2018-07-26 23:20:58 +08:00
|
|
|
tree->insert(typename T::BoundingBox(offsetX + el.x1, offsetY + el.y1, offsetX + el.x2, offsetY + el.y2), bel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 00:33:19 +08:00
|
|
|
QPoint lastDragPos_;
|
|
|
|
LineShader lineShader_;
|
|
|
|
QMatrix4x4 viewMove_;
|
|
|
|
float zoom_;
|
|
|
|
|
2018-07-20 20:19:45 +08:00
|
|
|
struct
|
|
|
|
{
|
2018-07-18 02:16:26 +08:00
|
|
|
QColor background;
|
|
|
|
QColor grid;
|
|
|
|
QColor frame;
|
|
|
|
QColor hidden;
|
|
|
|
QColor inactive;
|
|
|
|
QColor active;
|
|
|
|
QColor selected;
|
|
|
|
QColor highlight[8];
|
|
|
|
} colors_;
|
|
|
|
|
2018-07-20 20:19:45 +08:00
|
|
|
struct RendererData
|
|
|
|
{
|
2018-07-27 00:26:26 +08:00
|
|
|
LineShaderData gfxByStyle[GraphicElement::STYLE_MAX];
|
|
|
|
LineShaderData gfxSelected;
|
|
|
|
LineShaderData gfxHighlighted[8];
|
2018-07-26 23:20:58 +08:00
|
|
|
std::unique_ptr<QuadTreeBels> qtBels;
|
2018-07-18 02:16:26 +08:00
|
|
|
};
|
2018-07-27 00:33:19 +08:00
|
|
|
std::unique_ptr<RendererData> rendererData_;
|
|
|
|
QMutex rendererDataLock_;
|
2018-07-20 20:19:45 +08:00
|
|
|
|
|
|
|
struct RendererArgs
|
|
|
|
{
|
2018-07-27 00:26:26 +08:00
|
|
|
std::vector<DecalXY> selectedDecals;
|
|
|
|
std::vector<DecalXY> highlightedDecals[8];
|
2018-07-18 02:16:26 +08:00
|
|
|
bool highlightedOrSelectedChanged;
|
|
|
|
};
|
|
|
|
std::unique_ptr<RendererArgs> rendererArgs_;
|
|
|
|
QMutex rendererArgsLock_;
|
2018-07-27 00:33:19 +08:00
|
|
|
|
|
|
|
void zoom(int level);
|
|
|
|
void renderLines(void);
|
|
|
|
void drawGraphicElement(LineShaderData &out, const GraphicElement &el, float x, float y);
|
|
|
|
void drawDecal(LineShaderData &out, const DecalXY &decal);
|
|
|
|
void drawArchDecal(LineShaderData out[GraphicElement::STYLE_MAX], const DecalXY &decal);
|
|
|
|
QVector4D mouseToWorldCoordinates(int x, int y);
|
2018-07-27 00:46:27 +08:00
|
|
|
QVector4D mouseToWorldDimensions(int x, int y);
|
2018-07-27 00:33:19 +08:00
|
|
|
QMatrix4x4 getProjection(void);
|
2018-06-06 03:03:06 +08:00
|
|
|
};
|
2018-06-12 20:24:59 +08:00
|
|
|
|
2018-06-22 02:12:20 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|
|
|
|
|
2018-06-06 03:03:06 +08:00
|
|
|
#endif
|