20#include <unordered_set>
24#include <QGraphicsItem>
25#include <QGraphicsScene>
27#include <QPainterPath>
35#include <nlohmann/json.hpp>
39using namespace SILICON::core;
103 [[nodiscard]]
const std::unordered_set<GraphicalWireSegment*>&
getSegments()
const
154 [[nodiscard]] std::vector<QPointF>
getVertices()
const;
161 [[nodiscard]] QPainterPath
shape()
const;
197 std::unordered_set<GraphicalWireSegment*>
segments;
231 void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
232 QWidget* widget)
override;
235 [[nodiscard]] QPainterPath
shape()
const override;
265 void setShowPoints(
const std::vector<QPointF>& newShowPoints);
304 void setPoints(std::vector<QPointF> newPoints);
312 [[nodiscard]] std::optional<size_t>
pointIndexAt(QPointF localPos)
const;
318 [[nodiscard]] std::optional<size_t>
edgeIndexAt(QPointF localPos)
const;
368 [[nodiscard]] nlohmann::ordered_json
serialize()
const;
GraphicalItem(ItemCategory category=ItemCategory::GraphicalItem, QGraphicsItem *parent=nullptr)
The visible, selectable polyline wire on the diagram scene.
std::vector< QPointF > showPoints
Temporary points while drawing.
void setLastPointJunction(bool v)
Sets last endpoint junction status.
void setPoints(std::vector< QPointF > newPoints)
Replaces all points at once.
void updatePath()
Updates the internal path shapes.
QRectF getCollisionRect() const override
Gets the collision rectangle.
QPainterPath shape() const override
Gets the shape for hit testing.
QPainterPath showPath
The temporary path while drawing.
GraphicalWire * getGraphicalWire() const
Gets the logical wire.
QPainterPath centerlineShape() const
Narrow painted centerline used by component collision checks.
bool lastJunction
Junction flag for last endpoint.
bool isFirstPointJunction() const
Checks if first endpoint is a junction.
void setFirstPointJunction(bool v)
Sets first endpoint junction status.
const std::vector< QPointF > & getPoints() const
Gets all points of the segment.
int type() const override
Returns the item type identifier.
static constexpr int BOX_WIDTH
Width of bus size label box.
QPointF firstPoint() const
Gets the first point.
nlohmann::ordered_json serialize() const
Serializes the wire segment to JSON.
static constexpr int SLASH_ANGLE
Angle for slash decorations.
std::optional< size_t > edgeIndexAt(QPointF localPos) const
Finds the first edge within the grab radius of a local position.
static constexpr int INTERVAL
Interval for bus size decorations.
static constexpr int BOX_HEIGHT
Height of bus size label box.
bool empty() const
Checks if segment has only one point.
static constexpr double POINT_RADIUS
Radius of draggable points.
void setGraphicalWire(GraphicalWire *newWire)
Sets the logical wire, optionally propagating to touching siblings.
void updateTopology() override
GraphicalWireSegment(QPointF firstPoint, QGraphicsItem *parent=nullptr)
Constructs a segment starting at the given point.
std::vector< QPointF > points
The segment points.
std::vector< QPointF > getShowPoints()
Gets temporary points shown while drawing.
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
Handles hover for point highlighting.
void detachFromWire()
Detaches from the logical wire without side effects.
QPointF lastPoint() const
Gets the last point.
static constexpr int SLASH_LENGTH
Length of slash decorations.
GraphicalWire * graphicalWire
The logical wire this segment belongs to.
std::optional< size_t > hoveredPointIndex
Currently hovered point index.
std::vector< QPointF > getScenePoints() const
Gets all points mapped into scene coordinates.
std::optional< size_t > pointIndexAt(QPointF localPos) const
Gets the index of the point nearest to localPos.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse release.
void modeChanged(InteractionMode mode) override
Clears the drag cursor and resets hover highlighting outside normal mode.
void setShowPoints(const std::vector< QPointF > &newShowPoints)
Sets temporary points shown while drawing.
bool isLastPointJunction() const
Checks if last endpoint is a junction.
bool isPointOnPath(QPointF point) const
Checks if a point is on the wire path.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse press for point dragging.
void addPoints()
Confirms the show points as actual wire points.
QPointF lastShowPoint() const
Gets the last show point.
static constexpr double GRAB_RADIUS
Grab radius for point selection.
QRectF boundingRect() const override
Gets the bounding rectangle.
bool firstJunction
Junction flag for first endpoint.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Paints the wire segment.
~GraphicalWireSegment() override
bool isAlignedWith(const GraphicalWireSegment *other) const
Checks whether another segment is a straight continuation.
QPainterPath path
The main path.
bool hasShowPoints() const
Whether any temporary preview points are being shown.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse move for point dragging.
Logical wire entity that groups segments sharing the same bus.
void addSegment(GraphicalWireSegment *segment)
Adds a segment to this wire.
size_t getBusSize() const
Gets the bus size.
WireManager * manager
Wire manager for this wire.
QColor getColor() const
Gets the color for this wire based on bus size.
void removeSegment(GraphicalWireSegment *segment)
Removes a segment from this wire.
WireManager * getManager() const
Gets the wire manager.
GraphicalWire()
Creates a wire with a unique route identifier.
void restoreRouteId(uint64_t id)
Restores a saved identifier and advances the identifier allocator.
bool empty() const
Checks if this wire has no segments.
uint64_t getRouteId() const
Returns the persistent identifier of this logical wire group.
void setBus(Bus bus)
Sets the logical bus for this wire.
QPainterPath shape() const
Gets the combined shape of all segments.
const std::unordered_set< GraphicalWireSegment * > & getSegments() const
Gets all segments belonging to this wire.
void setBusSize(unsigned int size)
Sets the bus size.
std::optional< QString > connectionError
void setConnectionError(std::optional< QString > reason)
Updates the connection error and refreshes segment tooltips and painting.
void setManager(WireManager *manager)
Sets the wire manager.
std::optional< QString > getConnectionError() const
Returns the connection error, or no value when the net has no error.
void clearBusState()
Clears the state of all wires in the bus.
std::vector< QPointF > getVertices() const
Gets vertices at wire endpoints that are not junctions.
std::unordered_set< GraphicalWireSegment * > segments
Set of segments belonging to this wire.
Bus getBus() const
Gets the logical bus.
DiagramScene::InteractionMode InteractionMode
Alias for DiagramScene::InteractionMode.