SILICON
Loading...
Searching...
No Matches
localWireEditor.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <cstdint>
21#include <optional>
22#include <span>
23#include <vector>
24
26
27namespace SILICON::ui {
28
31public:
39 LocalWireEditor(std::span<const RoutingComponent> components,
40 std::span<const RoutingSegment> segments, qreal gridSize);
41
47 [[nodiscard]] RoutePreview
48 moveComponents(std::span<const ComponentRouteMove> moves) const;
49
57 [[nodiscard]] RoutePreview
58 moveBend(uint64_t segmentId, std::size_t index, QPointF position) const;
59
67 [[nodiscard]] RoutePreview
68 moveEdge(uint64_t segmentId, std::size_t index, QPointF displacement) const;
69
76 [[nodiscard]] bool valid(std::span<const RoutedSegment> routes,
77 uint64_t editedSegment) const;
78
79private:
81 [[nodiscard]] QPointF snap(QPointF point) const;
83 [[nodiscard]] const RoutingSegment* find(uint64_t id) const;
91 [[nodiscard]] static std::optional<std::vector<QPointF>>
92 moveAttachedEndpoint(const RoutingSegment& segment, bool first,
93 QPointF destination);
100 [[nodiscard]] RoutePreview
101 finish(uint64_t editedId, std::vector<RoutedSegment> routes) const;
102
103 std::span<const RoutingComponent> components;
104 std::span<const RoutingSegment> segments;
105 qreal gridSize;
106};
107
108} // namespace SILICON::ui
const RoutingSegment * find(uint64_t id) const
Returns the borrowed segment with the given identifier, or nullptr.
std::span< const RoutingSegment > segments
QPointF snap(QPointF point) const
Snaps a scene point to the grid when the grid spacing is positive.
RoutePreview moveBend(uint64_t segmentId, std::size_t index, QPointF position) const
Moves an interior bend and adjusts electrically attached branches.
LocalWireEditor(std::span< const RoutingComponent > components, std::span< const RoutingSegment > segments, qreal gridSize)
Borrows the original geometry for local wire edits.
RoutePreview moveEdge(uint64_t segmentId, std::size_t index, QPointF displacement) const
Offsets an edge perpendicular to its direction, preserving endpoints.
std::span< const RoutingComponent > components
RoutePreview moveComponents(std::span< const ComponentRouteMove > moves) const
Adjusts wire endpoints attached to moved component ports.
RoutePreview finish(uint64_t editedId, std::vector< RoutedSegment > routes) const
Canonicalizes and validates edits, then fills in unchanged snapshot routes.
bool valid(std::span< const RoutedSegment > routes, uint64_t editedSegment) const
Checks route geometry, obstacles, and preservation of electrical contacts.
static std::optional< std::vector< QPointF > > moveAttachedEndpoint(const RoutingSegment &segment, bool first, QPointF destination)
Adjusts one endpoint while keeping its route orthogonal.
std::optional< std::vector< RoutedSegment > > RoutePreview