29#include <boost/graph/adjacency_list.hpp>
74 std::vector<PortReference>
ports;
88 std::vector<std::pair<uint64_t, QPointF>>
junctions;
109 [[nodiscard]]
const SegmentTopology&
topologyFor(uint64_t segmentId)
const;
183 std::shared_ptr<GraphicalWire>
createWire(
unsigned int busSize = 1);
185 [[nodiscard]]
const std::vector<std::shared_ptr<GraphicalWire>>&
wires()
const
205 std::span<
const std::pair<uint64_t, QPointF>> translations);
209 bool includeNeighborhood =
true)
const;
221 static std::vector<GraphicalWireSegment*>
225 [[nodiscard]]
const std::vector<GraphicalWireSegment*>&
getSegments()
const
234 void replaceSegments(QGraphicsScene& scene, std::span<const RoutedWire> routedSegments);
267 boost::undirectedS, uint64_t, uint64_t>;
The visible, selectable polyline wire on the diagram scene.
Logical wire entity that groups segments sharing the same bus.
Represents a connection point on a component.
~Batch() noexcept
Discards an unfinished batch's pending work without restoring geometry.
Batch & operator=(const Batch &)=delete
Disables copy assignment of the batch lifecycle guard.
void commit()
Finishes the batch, rebuilding topology and notifying at the outermost level.
Batch(const Batch &)=delete
Disables copying of the batch lifecycle guard.
Batch(WireManager &manager)
Begins a batch that defers topology rebuilds and change notifications.
void cancel()
Restores the original local route if the segment is still registered.
Edit & operator=(const Edit &)=delete
Disables copy assignment of a route edit.
std::vector< QPointF > originalPoints
Edit(WireManager &manager, GraphicalWireSegment *segment)
Captures a registered segment's original local route for a preview edit.
~Edit() noexcept
Cancels an uncommitted edit and suppresses exceptions during cleanup.
Edit(const Edit &)=delete
Disables copying of an edit that owns route restoration.
void commit()
Validates the preview route and queues its topology rebuild.
void addSegment(GraphicalWireSegment *segment, bool updateTopology=true)
void calculateJunctions() const
void replaceSegments(QGraphicsScene &scene, std::span< const RoutedWire > routedSegments)
Replaces all managed graphical wire segments with routed segments.
std::map< uint64_t, TopologyEdge > TopologyEdgeMap
static bool segmentsTouching(const GraphicalWireSegment *segment, const GraphicalWireSegment *other)
GraphicalWireSegment * segmentAtPoint(QPointF scenePoint, const GraphicalWireSegment *ignoredSegment=nullptr) const
std::vector< GraphicalWireSegment * > allSegments
const TopologyEdgeMap & topologyEdges() const
Borrows the topology edge map until the topology is modified.
void finishBatch()
Finishes one batch level and flushes pending edits and changes at the outermost level.
void notifyTopologyChanged() const
Force execute the callback natively mapped to topological splits, merges, or drags.
boost::graph_traits< TopologyGraph >::vertex_descriptor VertexDescriptor
void removeSegment(GraphicalWireSegment *segment)
WireManager(WireManager &&)=delete
WireManager & operator=(WireManager &&)=delete
const TopologyVertexMap & topologyVertices() const
Borrows the topology vertex map until the topology is modified.
const std::vector< std::shared_ptr< GraphicalWire > > & wires() const
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, uint64_t, uint64_t > TopologyGraph
void rebuildTopologyEdges()
Rebuilds graph edges by splitting each segment route at its electrical vertices.
std::vector< uint64_t > pendingEdits
TopologyGraph topologyGraph
std::vector< std::shared_ptr< GraphicalWire > > managedWires
const std::vector< GraphicalWireSegment * > & getSegments() const
static std::vector< GraphicalWireSegment * > segmentNeighbors(GraphicalWireSegment *segment)
void discardBatch() noexcept
Drops one batch level and clears pending work when no batch remains.
TopologyVertexMap vertices
std::map< uint64_t, SegmentTopology > segmentTopology
const SegmentTopology & topologyFor(uint64_t segmentId) const
Borrows segment topology until rebuilt; missing segments return an empty topology.
std::shared_ptr< GraphicalWire > createWire(unsigned int busSize=1)
GraphicalWireSegment * registeredSegment(uint64_t id) const
Returns the registered segment with the given identifier, or nullptr.
WireManager(const WireManager &)=delete
std::function< std::vector< PortAnchor >()> PortAnchorProvider
void calculateJunctionsFor(std::span< GraphicalWireSegment *const > segments) const
Updates endpoint junction flags for the supplied registered segments.
std::map< uint64_t, TopologyVertex > TopologyVertexMap
void refreshPortAnchors()
Refreshes port references after components enter or leave the scene.
void setChangedCallback(ChangeCallback cb)
Sets the callback for geometry, connectivity, and electrical changes.
std::map< uint64_t, VertexDescriptor > vertexDescriptors
void updateSegmentTopology(GraphicalWireSegment *segment)
void removeWire(GraphicalWire *wire)
void rebuildFromGeometry()
Derives electrical groups, junctions, and port vertices from segment geometry.
WireManager & operator=(const WireManager &)=delete
PortAnchorProvider portAnchors
void notify(Change change) const
Delivers change flags to the callback or accumulates them in an active batch.
uint64_t createVertex(QPointF position, VertexKind kind=VertexKind::FreeEndpoint)
Creates a topology vertex and attaches matching port anchors.
void clearSegments(QGraphicsScene &scene)
Deletes all managed graphical wire segments from scene.
void notifyElectricalChanged() const
Notifies listeners of an electrical change, deferring delivery within a batch.
std::function< void(Change)> ChangeCallback
bool commitSegmentTranslations(std::span< const std::pair< uint64_t, QPointF > > translations)
Rebuilds connectivity after segment positions have been translated.
ChangeCallback onChanged
Callback invoked when wire topology changes (splits, merges, drags).
void setPortAnchors(PortAnchorProvider anchors)
Sets the provider of current component port anchors in scene coordinates.
Scene-coordinate wire path produced by an automatic router.
std::vector< QPointF > points
auto operator<=>(const PortReference &) const =default
Compares references by component identifier, port index, and direction.
std::vector< uint64_t > edgeIds
std::vector< std::pair< uint64_t, QPointF > > junctions
std::vector< QPointF > points
std::vector< PortReference > ports