SILICON
Loading...
Searching...
No Matches
GraphicalWireSegment Class Reference

The visible, selectable polyline wire on the diagram scene. More...

#include <graphicalWire.hpp>

Inheritance diagram for GraphicalWireSegment:
Collaboration diagram for GraphicalWireSegment:

Public Member Functions

 GraphicalWireSegment (QPointF firstPoint, QGraphicsItem *parent=nullptr)
 Constructs a segment starting at the given point.
int type () const override
 Returns the item type identifier.
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 Paints the wire segment.
QPainterPath shape () const override
 Gets the shape for hit testing.
QPainterPath centerlineShape () const
 Narrow painted centerline used by component collision checks.
QRectF boundingRect () const override
 Gets the bounding rectangle.
QRectF getCollisionRect () const override
 Gets the collision rectangle.
bool isPointOnPath (QPointF point) const
 Checks if a point is on the wire path.
void addPoints ()
 Confirms the show points as actual wire points.
void setShowPoints (const std::vector< QPointF > &newShowPoints)
 Sets temporary points shown while drawing.
std::vector< QPointF > getShowPoints ()
 Gets temporary points shown while drawing.
const std::vector< QPointF > & getPoints () const
 Gets all points of the segment.
std::vector< QPointF > getScenePoints () const
 Gets all points mapped into scene coordinates.
QPointF lastPoint () const
 Gets the last point.
QPointF firstPoint () const
 Gets the first point.
QPointF lastShowPoint () const
 Gets the last show point.
bool hasShowPoints () const
 Whether any temporary preview points are being shown.
bool empty () const
 Checks if segment has only one point.
void setPoints (std::vector< QPointF > newPoints)
 Replaces all points at once.
std::optional< size_t > pointIndexAt (QPointF localPos) const
 Gets the index of the point nearest to localPos.
std::optional< size_t > edgeIndexAt (QPointF localPos) const
 Finds the first edge within the grab radius of a local position.
bool isFirstPointJunction () const
 Checks if first endpoint is a junction.
bool isLastPointJunction () const
 Checks if last endpoint is a junction.
void setFirstPointJunction (bool v)
 Sets first endpoint junction status.
void setLastPointJunction (bool v)
 Sets last endpoint junction status.
GraphicalWire * getGraphicalWire () const
 Gets the logical wire.
void setGraphicalWire (GraphicalWire *newWire)
 Sets the logical wire, optionally propagating to touching siblings.
void detachFromWire ()
 Detaches from the logical wire without side effects.
void updateTopology () override
void modeChanged (InteractionMode mode) override
 Clears the drag cursor and resets hover highlighting outside normal mode.
 ~GraphicalWireSegment () override
bool isAlignedWith (const GraphicalWireSegment *other) const
 Checks whether another segment is a straight continuation.
nlohmann::ordered_json serialize () const
 Serializes the wire segment to JSON.
Public Member Functions inherited from GraphicalItem
 GraphicalItem (ItemCategory category=ItemCategory::GraphicalItem, QGraphicsItem *parent=nullptr)
 ~GraphicalItem () override
void setCollidingStatus (CollidingStatus newStatus)
 Sets the collision status.
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 Handles item change events.
int type () const override
 Returns the item type identifier.
bool isColliding () const
 Checks if the item is colliding.
QPointF getInitialPosition () const
 Gets the original position of the item before it started moving.
qreal getInitialRotation () const
uint64_t getUiId () const
void setInitialPosition ()
 Sets the initialPosition of the item to its current position (should be used when placed).
void setInitialRotation ()
void setUiId (uint64_t newUiId)
void setOwningScene (DiagramScene *scene)
void setGeometryPosition (QPointF position)

Private Member Functions

void updatePath ()
 Updates the internal path shapes.
void mousePressEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse press for point dragging.
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse move for point dragging.
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse release.
void hoverMoveEvent (QGraphicsSceneHoverEvent *event) override
 Handles hover for point highlighting.

Private Attributes

QPainterPath path
 The main path.
QPainterPath showPath
 The temporary path while drawing.
std::vector< QPointF > points
 The segment points.
std::vector< QPointF > showPoints
 Temporary points while drawing.
GraphicalWire * graphicalWire = nullptr
 The logical wire this segment belongs to.
bool firstJunction = false
 Junction flag for first endpoint.
bool lastJunction = false
 Junction flag for last endpoint.
std::optional< size_t > hoveredPointIndex = std::nullopt
 Currently hovered point index.

Static Private Attributes

static constexpr int INTERVAL = 60
 Interval for bus size decorations.
static constexpr int SLASH_LENGTH = 20
 Length of slash decorations.
static constexpr int SLASH_ANGLE = 135
 Angle for slash decorations.
static constexpr int BOX_HEIGHT = 20
 Height of bus size label box.
static constexpr int BOX_WIDTH = INTERVAL * 0.6
 Width of bus size label box.
static constexpr double POINT_RADIUS = 4.0
 Radius of draggable points.
static constexpr double GRAB_RADIUS = 8.0
 Grab radius for point selection.

Additional Inherited Members

Static Public Member Functions inherited from GraphicalItem
static uint64_t generateUiId ()
Protected Member Functions inherited from GraphicalItem
virtual bool canRotate () const
 Whether the item can be rotated.
virtual void onPositionChanged (QPointF offset)
 Called when the item position changes.
CollidingStatus getCollidingStatus () const
 Gets the current collision status.
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
void mousePressEvent (QGraphicsSceneMouseEvent *event) override

Detailed Description

The visible, selectable polyline wire on the diagram scene.

GraphicalWireSegment is a QGraphicsItem representing a polyline wire drawn on the diagram. It stores and paints orthogonal route geometry and exposes hit-tested bend and edge handles to DiagramScene's interaction state.

Junctions occur where an endpoint meets at least three distinct wire arms. Individual bends can be highlighted while a scene edit previews the route.

See also
GraphicalWire

Definition at line 216 of file graphicalWire.hpp.

Constructor & Destructor Documentation

◆ GraphicalWireSegment()

GraphicalWireSegment ( QPointF firstPoint,
QGraphicsItem * parent = nullptr )
explicit

Constructs a segment starting at the given point.

Parameters
firstPointThe starting point in local coordinates
parentOptional parent graphics item

Definition at line 158 of file graphicalWire.cpp.

◆ ~GraphicalWireSegment()

~GraphicalWireSegment ( )
override

Definition at line 599 of file graphicalWire.cpp.

Member Function Documentation

◆ addPoints()

void addPoints ( )

Confirms the show points as actual wire points.

Called when the wire drawing is completed, converting the temporary showPoints into permanent points.

Definition at line 223 of file graphicalWire.cpp.

◆ boundingRect()

QRectF boundingRect ( ) const
nodiscardoverride

Gets the bounding rectangle.

Definition at line 371 of file graphicalWire.cpp.

◆ centerlineShape()

QPainterPath centerlineShape ( ) const
nodiscard

Narrow painted centerline used by component collision checks.

Definition at line 386 of file graphicalWire.cpp.

◆ detachFromWire()

void detachFromWire ( )
inline

Detaches from the logical wire without side effects.

Used during WireManager teardown to avoid creating new wires or accessing freed memory.

Definition at line 347 of file graphicalWire.hpp.

◆ edgeIndexAt()

std::optional< size_t > edgeIndexAt ( QPointF localPos) const
nodiscard

Finds the first edge within the grab radius of a local position.

Parameters
localPosPosition in segment coordinates.
Returns
Index of the edge's first point, or no value when no edge is hit.

Definition at line 428 of file graphicalWire.cpp.

◆ empty()

bool empty ( ) const
inlinenodiscard

Checks if segment has only one point.

Definition at line 295 of file graphicalWire.hpp.

◆ firstPoint()

QPointF firstPoint ( ) const
inlinenodiscard

Gets the first point.

Definition at line 283 of file graphicalWire.hpp.

◆ getCollisionRect()

QRectF getCollisionRect ( ) const
inlinenodiscardoverridevirtual

Gets the collision rectangle.

Implements GraphicalItem.

Definition at line 244 of file graphicalWire.hpp.

◆ getGraphicalWire()

GraphicalWire * getGraphicalWire ( ) const
inline

Gets the logical wire.

Definition at line 333 of file graphicalWire.hpp.

◆ getPoints()

const std::vector< QPointF > & getPoints ( ) const
inlinenodiscard

Gets all points of the segment.

Definition at line 274 of file graphicalWire.hpp.

◆ getScenePoints()

std::vector< QPointF > getScenePoints ( ) const
nodiscard

Gets all points mapped into scene coordinates.

Definition at line 402 of file graphicalWire.cpp.

◆ getShowPoints()

std::vector< QPointF > getShowPoints ( )
inline

Gets temporary points shown while drawing.

Returns
Vector of show points

Definition at line 271 of file graphicalWire.hpp.

◆ hasShowPoints()

bool hasShowPoints ( ) const
inlinenodiscard

Whether any temporary preview points are being shown.

Definition at line 292 of file graphicalWire.hpp.

◆ hoverMoveEvent()

void hoverMoveEvent ( QGraphicsSceneHoverEvent * event)
overrideprivate

Handles hover for point highlighting.

Definition at line 563 of file graphicalWire.cpp.

◆ isAlignedWith()

bool isAlignedWith ( const GraphicalWireSegment * other) const
nodiscard

Checks whether another segment is a straight continuation.

Parameters
otherThe segment to check
Returns
True if the segments share an endpoint and their incident arms are collinear and point in opposite directions.

Definition at line 472 of file graphicalWire.cpp.

◆ isFirstPointJunction()

bool isFirstPointJunction ( ) const
inlinenodiscard

Checks if first endpoint is a junction.

Definition at line 321 of file graphicalWire.hpp.

◆ isLastPointJunction()

bool isLastPointJunction ( ) const
inlinenodiscard

Checks if last endpoint is a junction.

Definition at line 324 of file graphicalWire.hpp.

◆ isPointOnPath()

bool isPointOnPath ( QPointF point) const

Checks if a point is on the wire path.

Parameters
pointThe point to check
Returns
True if on path

Definition at line 391 of file graphicalWire.cpp.

◆ lastPoint()

QPointF lastPoint ( ) const
inlinenodiscard

Gets the last point.

Definition at line 280 of file graphicalWire.hpp.

◆ lastShowPoint()

QPointF lastShowPoint ( ) const
inlinenodiscard

Gets the last show point.

Definition at line 286 of file graphicalWire.hpp.

◆ modeChanged()

void modeChanged ( InteractionMode mode)
overridevirtual

Clears the drag cursor and resets hover highlighting outside normal mode.

Reimplemented from GraphicalItem.

Definition at line 589 of file graphicalWire.cpp.

◆ mouseMoveEvent()

void mouseMoveEvent ( QGraphicsSceneMouseEvent * event)
overrideprivate

Handles mouse move for point dragging.

Definition at line 539 of file graphicalWire.cpp.

◆ mousePressEvent()

void mousePressEvent ( QGraphicsSceneMouseEvent * event)
overrideprivate

Handles mouse press for point dragging.

Definition at line 522 of file graphicalWire.cpp.

◆ mouseReleaseEvent()

void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event)
overrideprivate

Handles mouse release.

Definition at line 550 of file graphicalWire.cpp.

◆ paint()

void paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget )
override

Paints the wire segment.

Definition at line 272 of file graphicalWire.cpp.

◆ pointIndexAt()

std::optional< size_t > pointIndexAt ( QPointF localPos) const
nodiscard

Gets the index of the point nearest to localPos.

Parameters
localPosThe position to check
Returns
Index of nearest point, or no value outside the grab radius

Definition at line 418 of file graphicalWire.cpp.

◆ serialize()

nlohmann::ordered_json serialize ( ) const
nodiscard

Serializes the wire segment to JSON.

Returns
JSON object with points and wire ID

Definition at line 616 of file graphicalWire.cpp.

◆ setFirstPointJunction()

void setFirstPointJunction ( bool v)

Sets first endpoint junction status.

Definition at line 454 of file graphicalWire.cpp.

◆ setGraphicalWire()

void setGraphicalWire ( GraphicalWire * newWire)

Sets the logical wire, optionally propagating to touching siblings.

Parameters
newWireThe wire to set

Definition at line 180 of file graphicalWire.cpp.

◆ setLastPointJunction()

void setLastPointJunction ( bool v)

Sets last endpoint junction status.

Definition at line 463 of file graphicalWire.cpp.

◆ setPoints()

void setPoints ( std::vector< QPointF > newPoints)

Replaces all points at once.

Used for route previews, undo/redo, and aligned merge operations.

Parameters
newPointsThe new points vector

Definition at line 409 of file graphicalWire.cpp.

◆ setShowPoints()

void setShowPoints ( const std::vector< QPointF > & newShowPoints)

Sets temporary points shown while drawing.

Parameters
newShowPointsThe points to show

Definition at line 212 of file graphicalWire.cpp.

◆ shape()

QPainterPath shape ( ) const
nodiscardoverride

Gets the shape for hit testing.

Definition at line 379 of file graphicalWire.cpp.

◆ type()

int type ( ) const
inlineoverride

Returns the item type identifier.

Definition at line 226 of file graphicalWire.hpp.

◆ updatePath()

void updatePath ( )
private

Updates the internal path shapes.

Definition at line 246 of file graphicalWire.cpp.

◆ updateTopology()

void updateTopology ( )
overridevirtual

Reimplemented from GraphicalItem.

Definition at line 173 of file graphicalWire.cpp.

Member Data Documentation

◆ BOX_HEIGHT

int BOX_HEIGHT = 20
staticconstexprprivate

Height of bus size label box.

Definition at line 420 of file graphicalWire.hpp.

◆ BOX_WIDTH

int BOX_WIDTH = INTERVAL * 0.6
staticconstexprprivate

Width of bus size label box.

Definition at line 423 of file graphicalWire.hpp.

◆ firstJunction

bool firstJunction = false
private

Junction flag for first endpoint.

Definition at line 387 of file graphicalWire.hpp.

◆ GRAB_RADIUS

double GRAB_RADIUS = 8.0
staticconstexprprivate

Grab radius for point selection.

Definition at line 429 of file graphicalWire.hpp.

◆ graphicalWire

GraphicalWire* graphicalWire = nullptr
private

The logical wire this segment belongs to.

Definition at line 384 of file graphicalWire.hpp.

◆ hoveredPointIndex

std::optional<size_t> hoveredPointIndex = std::nullopt
private

Currently hovered point index.

Definition at line 393 of file graphicalWire.hpp.

◆ INTERVAL

int INTERVAL = 60
staticconstexprprivate

Interval for bus size decorations.

Definition at line 411 of file graphicalWire.hpp.

◆ lastJunction

bool lastJunction = false
private

Junction flag for last endpoint.

Definition at line 390 of file graphicalWire.hpp.

◆ path

QPainterPath path
private

The main path.

Definition at line 372 of file graphicalWire.hpp.

◆ POINT_RADIUS

double POINT_RADIUS = 4.0
staticconstexprprivate

Radius of draggable points.

Definition at line 426 of file graphicalWire.hpp.

◆ points

std::vector<QPointF> points
private

The segment points.

Definition at line 378 of file graphicalWire.hpp.

◆ showPath

QPainterPath showPath
private

The temporary path while drawing.

Definition at line 375 of file graphicalWire.hpp.

◆ showPoints

std::vector<QPointF> showPoints
private

Temporary points while drawing.

Definition at line 381 of file graphicalWire.hpp.

◆ SLASH_ANGLE

int SLASH_ANGLE = 135
staticconstexprprivate

Angle for slash decorations.

Definition at line 417 of file graphicalWire.hpp.

◆ SLASH_LENGTH

int SLASH_LENGTH = 20
staticconstexprprivate

Length of slash decorations.

Definition at line 414 of file graphicalWire.hpp.


The documentation for this class was generated from the following files: