From 16b1544fff7e9ca11deb3ae1b891c79eac7ec50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 21 Jan 2018 11:36:34 +0100 Subject: Implement little bit more of scheme and fix connection angle This commit adds few more bits to scheme but mainly it chnages how connectors specify angles. Originally it was in radians but we was mapping that trough mathematical operations directly to sizes. But that was problematic because of floating point inacuracy and we sometimes founded intersection where there should be one. So this commit gets rid of this at all and instead allows just some fixes axes to be used instead of arbitrary angles. --- qtmips_gui/coreview/connection.h | 54 +++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'qtmips_gui/coreview/connection.h') diff --git a/qtmips_gui/coreview/connection.h b/qtmips_gui/coreview/connection.h index 0ee981e..88ad1da 100644 --- a/qtmips_gui/coreview/connection.h +++ b/qtmips_gui/coreview/connection.h @@ -10,21 +10,30 @@ namespace coreview { class Connector : public QObject { Q_OBJECT public: - Connector(qreal angle); + enum Axis { + AX_X, // X axis + AX_Y, // Y axis + AX_XY, // X=Y axis (45°) + AX_MXY // X=-Y axis (-45°) + }; + + Connector(enum Axis axis = AX_X); void setPos(qreal x, qreal y); + + enum Axis axis() const; qreal x() const; qreal y() const; + QPointF point() const; QLineF vector() const; - qreal angle() const; - signals: - void updated(QPointF); + void updated(QPointF point); + void updated(QLineF vector); private: - qreal ang; + enum Axis ax; qreal qx, qy; }; @@ -42,22 +51,43 @@ public: void setAxes(QVector); private slots: - void moved_start(QPointF); - void moved_end(QPointF); + void moved_start(QLineF); + void moved_end(QLineF); -private: +protected: QGraphicsSimpleTextItem *value; QVector points; - QPointF p_start, p_end; - qreal ang_start, ang_end; + QLineF ax_start, ax_end; QVector break_axes; QString text; int pen_width; + QColor color; - // TODO line width and possibly bus width void recalc_line(); - void recalc_line_add_point(const QLineF &l1, const QLineF &l2); + bool recalc_line_add_point(const QLineF &l1, const QLineF &l2); +}; + +class Bus : public Connection { +public: + Bus(const Connector *start, const Connector *end, unsigned width = 4); + + // This creates connector snapped to closes point to x,y that is on bus + const Connector *new_connector(qreal x, qreal y, enum Connector::Axis = Connector::AX_X); + const Connector *new_connector(const QPointF&, enum Connector::Axis = Connector::AX_X); + +protected: + struct con_pos { + Connector *c; + QPointF p; + }; + QVector conns; + // TODO because of this we have to overload setAxis function and update that in there +}; + +class Signal : public Connection { +public: + Signal(const Connector *start, const Connector *end); }; #define CON_AXIS_X(Y) QLineF(QPointF(0, Y), QPointF(1, Y)) -- cgit v1.2.3