gui: clang-format
This commit is contained in:
parent
0eb40da749
commit
5a7fe84a04
@ -31,11 +31,9 @@
|
||||
|
||||
NEXTPNR_NAMESPACE_BEGIN
|
||||
|
||||
FPGAViewWidget::FPGAViewWidget(QWidget *parent) :
|
||||
QOpenGLWidget(parent), ctx_(nullptr), paintTimer_(this),
|
||||
lineShader_(this), zoom_(10.0f),
|
||||
rendererArgs_(new FPGAViewWidget::RendererArgs),
|
||||
rendererData_(new FPGAViewWidget::RendererData)
|
||||
FPGAViewWidget::FPGAViewWidget(QWidget *parent)
|
||||
: QOpenGLWidget(parent), ctx_(nullptr), paintTimer_(this), lineShader_(this), zoom_(10.0f),
|
||||
rendererArgs_(new FPGAViewWidget::RendererArgs), rendererData_(new FPGAViewWidget::RendererData)
|
||||
{
|
||||
colors_.background = QColor("#000000");
|
||||
colors_.grid = QColor("#333");
|
||||
@ -126,10 +124,10 @@ float FPGAViewWidget::PickedElement::distance(Context *ctx, float wx, float wy)
|
||||
|
||||
// Go over its' GraphicElements, and calculate the distance to them.
|
||||
std::vector<float> distances;
|
||||
std::transform(graphics.begin(), graphics.end(), std::back_inserter(distances), [&](const GraphicElement &ge) -> float {
|
||||
std::transform(graphics.begin(), graphics.end(), std::back_inserter(distances),
|
||||
[&](const GraphicElement &ge) -> float {
|
||||
switch (ge.type) {
|
||||
case GraphicElement::TYPE_BOX:
|
||||
{
|
||||
case GraphicElement::TYPE_BOX: {
|
||||
// If outside the box, return unit distance to closest border.
|
||||
float outside_x = -1, outside_y = -1;
|
||||
if (dx < ge.x1 || dx > ge.x2) {
|
||||
@ -145,8 +143,7 @@ float FPGAViewWidget::PickedElement::distance(Context *ctx, float wx, float wy)
|
||||
return 0;
|
||||
}
|
||||
case GraphicElement::TYPE_LINE:
|
||||
case GraphicElement::TYPE_ARROW:
|
||||
{
|
||||
case GraphicElement::TYPE_ARROW: {
|
||||
// Return somewhat primitively calculated distance to segment.
|
||||
// TODO(q3k): consider coming up with a better algorithm
|
||||
QVector2D w(wx, wy);
|
||||
@ -165,13 +162,16 @@ float FPGAViewWidget::PickedElement::distance(Context *ctx, float wx, float wy)
|
||||
// Find smallest non -1 distance.
|
||||
// Find closest element.
|
||||
return *std::min_element(distances.begin(), distances.end(), [&](float a, float b) {
|
||||
if (a == -1) return false;
|
||||
if (b == -1) return true;
|
||||
if (a == -1)
|
||||
return false;
|
||||
if (b == -1)
|
||||
return true;
|
||||
return a < b;
|
||||
});
|
||||
}
|
||||
|
||||
void FPGAViewWidget::renderGraphicElement(RendererData *data, LineShaderData &out, const GraphicElement &el, float x, float y)
|
||||
void FPGAViewWidget::renderGraphicElement(RendererData *data, LineShaderData &out, const GraphicElement &el, float x,
|
||||
float y)
|
||||
{
|
||||
if (el.type == GraphicElement::TYPE_BOX) {
|
||||
auto line = PolyLine(true);
|
||||
@ -301,7 +301,8 @@ void FPGAViewWidget::paintGL()
|
||||
// Render Arch graphics.
|
||||
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_FRAME], colors_.frame, thick11Px, matrix);
|
||||
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_HIDDEN], colors_.hidden, thick11Px, matrix);
|
||||
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_INACTIVE], colors_.inactive, thick11Px, matrix);
|
||||
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_INACTIVE], colors_.inactive, thick11Px,
|
||||
matrix);
|
||||
lineShader_.draw(rendererData_->gfxByStyle[GraphicElement::STYLE_ACTIVE], colors_.active, thick11Px, matrix);
|
||||
|
||||
// Draw highlighted items.
|
||||
@ -410,7 +411,6 @@ void FPGAViewWidget::renderLines(void)
|
||||
flags = rendererArgs_->flags;
|
||||
}
|
||||
|
||||
|
||||
// Render decals if necessary.
|
||||
if (decalsChanged) {
|
||||
auto data = std::unique_ptr<FPGAViewWidget::RendererData>(new FPGAViewWidget::RendererData);
|
||||
@ -549,15 +549,16 @@ boost::optional<FPGAViewWidget::PickedElement> FPGAViewWidget::pickElement(float
|
||||
// Calculate distances to all elements picked.
|
||||
using ElemDist = std::pair<const PickedElement *, float>;
|
||||
std::vector<ElemDist> distances;
|
||||
std::transform(elems.begin(), elems.end(), std::back_inserter(distances),
|
||||
[&](const PickedElement &e) -> ElemDist {
|
||||
std::transform(elems.begin(), elems.end(), std::back_inserter(distances), [&](const PickedElement &e) -> ElemDist {
|
||||
return std::make_pair(&e, e.distance(ctx_, worldx, worldy));
|
||||
});
|
||||
|
||||
// Find closest non -1 element.
|
||||
auto closest = std::min_element(distances.begin(), distances.end(), [&](const ElemDist &a, const ElemDist &b) {
|
||||
if (a.second == -1) return false;
|
||||
if (b.second == -1) return true;
|
||||
if (a.second == -1)
|
||||
return false;
|
||||
if (b.second == -1)
|
||||
return true;
|
||||
return a.second < b.second;
|
||||
});
|
||||
|
||||
@ -619,7 +620,6 @@ void FPGAViewWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
// Invert the projection matrix to calculate screen/mouse to world/grid
|
||||
// coordinates.
|
||||
QVector4D FPGAViewWidget::mouseToWorldCoordinates(int x, int y)
|
||||
@ -677,7 +677,6 @@ void FPGAViewWidget::zoom(int level)
|
||||
zoom_ -= level / 100.0;
|
||||
} else {
|
||||
zoom_ -= level / 10.0;
|
||||
|
||||
}
|
||||
|
||||
if (zoom_ < zoomNear_)
|
||||
|
@ -20,7 +20,6 @@
|
||||
#ifndef MAPGLWIDGET_H
|
||||
#define MAPGLWIDGET_H
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <QMainWindow>
|
||||
#include <QMutex>
|
||||
#include <QOpenGLBuffer>
|
||||
@ -32,11 +31,12 @@
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QWaitCondition>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "designwidget.h"
|
||||
#include "lineshader.h"
|
||||
#include "nextpnr.h"
|
||||
#include "quadtree.h"
|
||||
#include "lineshader.h"
|
||||
#include "designwidget.h"
|
||||
|
||||
NEXTPNR_NAMESPACE_BEGIN
|
||||
|
||||
@ -108,7 +108,6 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
QSize minimumSizeHint() const override;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void newContext(Context *ctx);
|
||||
void onSelectedArchItem(std::vector<DecalXY> decals);
|
||||
@ -129,9 +128,11 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
const float zoomLvl1_ = 1.0f;
|
||||
const float zoomLvl2_ = 5.0f;
|
||||
|
||||
struct PickedElement {
|
||||
struct PickedElement
|
||||
{
|
||||
ElementType type;
|
||||
union Inner {
|
||||
union Inner
|
||||
{
|
||||
BelId bel;
|
||||
WireId wire;
|
||||
PipId pip;
|
||||
@ -202,17 +203,14 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
{
|
||||
bool zoomOutbound;
|
||||
|
||||
PassthroughFlags() :
|
||||
zoomOutbound(false) {}
|
||||
PassthroughFlags &operator=(const PassthroughFlags &other) noexcept {
|
||||
PassthroughFlags() : zoomOutbound(false) {}
|
||||
PassthroughFlags &operator=(const PassthroughFlags &other) noexcept
|
||||
{
|
||||
zoomOutbound = other.zoomOutbound;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
zoomOutbound = false;
|
||||
}
|
||||
void clear() { zoomOutbound = false; }
|
||||
};
|
||||
|
||||
struct RendererArgs
|
||||
|
@ -17,8 +17,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include "lineshader.h"
|
||||
#include "log.h"
|
||||
|
||||
NEXTPNR_NAMESPACE_BEGIN
|
||||
|
||||
|
@ -26,14 +26,16 @@
|
||||
NEXTPNR_NAMESPACE_BEGIN
|
||||
|
||||
// A node of a QuadTree. Internal.
|
||||
template <typename CoordinateT, typename ElementT>
|
||||
class QuadTreeNode
|
||||
template <typename CoordinateT, typename ElementT> class QuadTreeNode
|
||||
{
|
||||
public:
|
||||
class BoundingBox {
|
||||
class BoundingBox
|
||||
{
|
||||
friend class QuadTreeNode;
|
||||
|
||||
private:
|
||||
CoordinateT x0_, x1_, y0_, y1_;
|
||||
|
||||
public:
|
||||
// Standard constructor for a given (x0,y0), (x1,y1) bounding box
|
||||
//
|
||||
@ -41,11 +43,11 @@ class QuadTreeNode
|
||||
// @param y0 y coordinate of top-left corner of box
|
||||
// @param x1 x coordinate of bottom-right corner of box
|
||||
// @param y1 y coordinate of bottom-right corner of box
|
||||
BoundingBox(CoordinateT x0, CoordinateT y0, CoordinateT x1, CoordinateT y1) :
|
||||
x0_(x0), x1_(x1), y0_(y0), y1_(y1) {}
|
||||
BoundingBox(CoordinateT x0, CoordinateT y0, CoordinateT x1, CoordinateT y1) : x0_(x0), x1_(x1), y0_(y0), y1_(y1)
|
||||
{
|
||||
}
|
||||
|
||||
BoundingBox(const BoundingBox &other) :
|
||||
x0_(other.x0_), x1_(other.x1_), y0_(other.y0_), y1_(other.y1_) {}
|
||||
BoundingBox(const BoundingBox &other) : x0_(other.x0_), x1_(other.x1_), y0_(other.y0_), y1_(other.y1_) {}
|
||||
|
||||
// Whether a bounding box contains a given points.
|
||||
// A point is defined to be in a bounding box when it's not lesser than
|
||||
@ -74,14 +76,16 @@ class QuadTreeNode
|
||||
|
||||
private:
|
||||
// A pair of Element and BoundingBox that contains it.
|
||||
class BoundElement {
|
||||
class BoundElement
|
||||
{
|
||||
friend class QuadTreeNode;
|
||||
|
||||
private:
|
||||
BoundingBox bb_;
|
||||
ElementT elem_;
|
||||
|
||||
public:
|
||||
BoundElement(BoundingBox bb, ElementT elem) :
|
||||
bb_(bb), elem_(elem) {}
|
||||
BoundElement(BoundingBox bb, ElementT elem) : bb_(bb), elem_(elem) {}
|
||||
};
|
||||
|
||||
// The bounding box that this node describes.
|
||||
@ -124,7 +128,8 @@ class QuadTreeNode
|
||||
// Used to describe one of 5 possible places an element can exist:
|
||||
// - the node itself (THIS)
|
||||
// - any of the 4 children nodes.
|
||||
enum Quadrant {
|
||||
enum Quadrant
|
||||
{
|
||||
THIS = -1,
|
||||
NW = 0,
|
||||
NE = 1,
|
||||
@ -175,22 +180,18 @@ class QuadTreeNode
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
// Standard constructor for node.
|
||||
// @param b BoundingBox this node covers.
|
||||
// @param depth depth at which this node is in the tree
|
||||
// @max_elems how many elements should this node contain before it splits
|
||||
QuadTreeNode(BoundingBox b, int depth, size_t max_elems = 4) :
|
||||
bound_(b), max_elems_(max_elems), depth_(depth)
|
||||
{
|
||||
}
|
||||
QuadTreeNode(BoundingBox b, int depth, size_t max_elems = 4) : bound_(b), max_elems_(max_elems), depth_(depth) {}
|
||||
// Disallow copies.
|
||||
QuadTreeNode(const QuadTreeNode &other) = delete;
|
||||
QuadTreeNode &operator=(const QuadTreeNode &other) = delete;
|
||||
// Allow moves.
|
||||
QuadTreeNode(QuadTreeNode &&other) :
|
||||
bound_(other.bound_), max_elems_(other.max_elems_), children_(std::move(other.children_)),
|
||||
QuadTreeNode(QuadTreeNode &&other)
|
||||
: bound_(other.bound_), max_elems_(other.max_elems_), children_(std::move(other.children_)),
|
||||
splitx_(other.splitx_), splity_(other.splity_), elems_(std::move(other.elems_)), depth_(other.depth_)
|
||||
{
|
||||
other.children_ = nullptr;
|
||||
@ -242,10 +243,17 @@ class QuadTreeNode
|
||||
children_ = decltype(children_)(new QuadTreeNode<CoordinateT, ElementT>[4] {
|
||||
// Note: not using [NW] = QuadTreeNode because that seems to
|
||||
// crash g++ 7.3.0.
|
||||
/* NW */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(bound_.x0_, bound_.y0_, splitx_, splity_), depth_+1, max_elems_),
|
||||
/* NE */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(splitx_, bound_.y0_, bound_.x1_, splity_), depth_+1, max_elems_),
|
||||
/* SW */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(bound_.x0_, splity_, splitx_, bound_.y1_), depth_+1, max_elems_),
|
||||
/* SE */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(splitx_, splity_, bound_.x1_, bound_.y1_), depth_+1, max_elems_),
|
||||
/* NW */ QuadTreeNode<CoordinateT, ElementT>(BoundingBox(bound_.x0_, bound_.y0_, splitx_, splity_),
|
||||
depth_ + 1, max_elems_),
|
||||
/* NE */
|
||||
QuadTreeNode<CoordinateT, ElementT>(BoundingBox(splitx_, bound_.y0_, bound_.x1_, splity_),
|
||||
depth_ + 1, max_elems_),
|
||||
/* SW */
|
||||
QuadTreeNode<CoordinateT, ElementT>(BoundingBox(bound_.x0_, splity_, splitx_, bound_.y1_),
|
||||
depth_ + 1, max_elems_),
|
||||
/* SE */
|
||||
QuadTreeNode<CoordinateT, ElementT>(BoundingBox(splitx_, splity_, bound_.x1_, bound_.y1_),
|
||||
depth_ + 1, max_elems_),
|
||||
});
|
||||
// Move all elements to where they belong.
|
||||
auto it = elems_.begin();
|
||||
@ -271,15 +279,18 @@ class QuadTreeNode
|
||||
// Dump a human-readable representation of the tree to stdout.
|
||||
void dump(int level) const
|
||||
{
|
||||
for (int i = 0; i < level; i++) printf(" ");
|
||||
for (int i = 0; i < level; i++)
|
||||
printf(" ");
|
||||
printf("loc: % 3d % 3d % 3d % 3d\n", bound_.x0_, bound_.y0_, bound_.x1_, bound_.y1_);
|
||||
if (elems_.size() != 0) {
|
||||
for (int i = 0; i < level; i++) printf(" ");
|
||||
for (int i = 0; i < level; i++)
|
||||
printf(" ");
|
||||
printf("elems: %zu\n", elems_.size());
|
||||
}
|
||||
|
||||
if (children_ != nullptr) {
|
||||
for (int i = 0; i < level; i++) printf(" ");
|
||||
for (int i = 0; i < level; i++)
|
||||
printf(" ");
|
||||
printf("children:\n");
|
||||
children_[NW].dump(level + 1);
|
||||
children_[NE].dump(level + 1);
|
||||
@ -331,8 +342,7 @@ class QuadTreeNode
|
||||
//
|
||||
// @param CoodinateT scalar type of the coordinate system - int, float, ...
|
||||
// @param ElementT type of the contained element. Must be movable or copiable.
|
||||
template <typename CoordinateT, typename ElementT>
|
||||
class QuadTree
|
||||
template <typename CoordinateT, typename ElementT> class QuadTree
|
||||
{
|
||||
private:
|
||||
// Root of the tree.
|
||||
@ -348,10 +358,7 @@ class QuadTree
|
||||
//
|
||||
// @param b Bounding box of the entire tree - all comitted elements must
|
||||
// fit within in.
|
||||
QuadTree(BoundingBox b) :
|
||||
root_(b, 0)
|
||||
{
|
||||
}
|
||||
QuadTree(BoundingBox b) : root_(b, 0) {}
|
||||
|
||||
// Inserts a new value at a given bounding box.e
|
||||
// BoundingBoxes are not deduplicated - if two are pushed with the same
|
||||
@ -367,17 +374,11 @@ class QuadTree
|
||||
}
|
||||
|
||||
// Dump a human-readable representation of the tree to stdout.
|
||||
void dump() const
|
||||
{
|
||||
root_.dump(0);
|
||||
}
|
||||
void dump() const { root_.dump(0); }
|
||||
|
||||
// Return count of BoundingBoxes/Elements contained.
|
||||
// @returns count of elements contained.
|
||||
size_t size() const
|
||||
{
|
||||
return root_.size();
|
||||
}
|
||||
size_t size() const { return root_.size(); }
|
||||
|
||||
// Retrieve elements whose bounding boxes cover the given coordinates.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user