62 std::span<GraphicalLogicComponent* const> components,
67 const auto& circuitGraph = circuit.
getGraph();
68 const auto vertexCount = boost::num_vertices(circuitGraph);
70 std::vector<ogdf::node> vertexToNode(vertexCount,
nullptr);
71 std::vector<GraphicalLogicComponent*> vertexToGraphics(vertexCount,
nullptr);
72 std::unordered_map<const Component*, GraphicalLogicComponent*> componentToGraphics;
73 std::unordered_map<ogdf::node, GraphicalLogicComponent*> nodeToGraphics;
76 if (!component || !component->getComponent())
79 componentToGraphics.emplace(component->getComponent().get(), component);
82 std::vector<std::size_t> orderedVertices;
83 orderedVertices.reserve(vertexCount);
84 for (
const auto vertex : boost::make_iterator_range(boost::vertices(circuitGraph))) {
85 const auto& component = circuitGraph[vertex].component;
89 auto graphicsIt = componentToGraphics.find(component.get());
90 if (graphicsIt == componentToGraphics.end())
93 const auto index =
static_cast<std::size_t
>(vertex);
94 vertexToGraphics[index] = graphicsIt->second;
95 orderedVertices.push_back(index);
98 std::ranges::sort(orderedVertices, [&](
const std::size_t lhs,
const std::size_t rhs) {
99 const auto* lhsGraphics = vertexToGraphics[lhs];
100 const auto* rhsGraphics = vertexToGraphics[rhs];
101 return std::pair{lhsGraphics->getUiId(), lhs}
102 < std::pair{rhsGraphics->getUiId(), rhs};
104 for (
const std::size_t vertex : orderedVertices) {
105 ogdf::node node = graph.newNode();
106 vertexToNode[vertex] = node;
107 nodeToGraphics.emplace(node, vertexToGraphics[vertex]);
110 if (graph.numberOfNodes() == 0)
116 std::vector<std::uint64_t> busKey;
118 std::vector<OrderedEdge> orderedEdges;
119 orderedEdges.reserve(boost::num_edges(circuitGraph));
120 for (
const auto edge : boost::make_iterator_range(boost::edges(circuitGraph))) {
121 const auto sourceVertex = boost::source(edge, circuitGraph);
122 const auto targetVertex = boost::target(edge, circuitGraph);
123 if (sourceVertex == targetVertex)
126 const auto source =
static_cast<std::size_t
>(sourceVertex);
127 const auto target =
static_cast<std::size_t
>(targetVertex);
128 if (!vertexToNode[source] || !vertexToNode[target])
131 std::vector<std::uint64_t> busKey;
132 busKey.reserve(circuitGraph[edge].bus.size());
133 for (
const auto& wire : circuitGraph[edge].bus)
134 busKey.push_back(wire ? wire->getId() : 0);
135 orderedEdges.push_back(
136 {.source = source, .target = target, .busKey = std::move(busKey)});
139 std::ranges::sort(orderedEdges, [&](
const OrderedEdge& lhs,
const OrderedEdge& rhs) {
140 return std::tuple{vertexToGraphics[lhs.source]->getUiId(),
141 vertexToGraphics[lhs.target]->getUiId(), lhs.busKey}
142 < std::tuple{vertexToGraphics[rhs.source]->getUiId(),
143 vertexToGraphics[rhs.target]->getUiId(), rhs.busKey};
145 for (
const OrderedEdge& edge : orderedEdges)
146 graph.newEdge(vertexToNode[edge.source], vertexToNode[edge.target]);
148 ogdf::GraphAttributes attributes(graph, ogdf::GraphAttributes::nodeGraphics
149 | ogdf::GraphAttributes::edgeGraphics);
153 for (ogdf::node node : graph.nodes) {
154 const QRectF bounds = nodeToGraphics.at(node)->sceneBoundingRect();
155 attributes.width(node) =
158 horizontalLayers ? bounds.height() : bounds.width());
159 attributes.height(node) =
162 horizontalLayers ? bounds.width() : bounds.height());
166 ogdf::FMMMLayout layout;
167 layout.useHighLevelOptions(
true);
170 layout.qualityVersusSpeed(ogdf::FMMMOptions::QualityVsSpeed::GorgeousAndEfficient);
174 layout.newInitialPlacement(
false);
176 layout.call(attributes);
178 ogdf::SugiyamaLayout layout;
179 layout.arrangeCCs(
true);
183 layout.permuteFirst(
false);
186 auto* hierarchyLayout =
new ogdf::FastHierarchyLayout();
189 hierarchyLayout->fixedLayerDistance(
true);
190 layout.setLayout(hierarchyLayout);
191 layout.call(attributes);
194 double minSceneLeft = std::numeric_limits<double>::infinity();
195 double minSceneTop = std::numeric_limits<double>::infinity();
197 for (ogdf::node node : graph.nodes) {
198 const QPointF layoutPoint =
200 ? orientedLayerPoint(attributes.x(node), attributes.y(node),
202 : QPointF(attributes.x(node), attributes.y(node));
203 const double x = layoutPoint.x();
204 const double y = layoutPoint.y();
205 const double sceneWidth =
206 horizontalLayers ? attributes.height(node) : attributes.width(node);
207 const double sceneHeight =
208 horizontalLayers ? attributes.width(node) : attributes.height(node);
209 minSceneLeft = std::min(minSceneLeft, x - sceneWidth / 2.0);
210 minSceneTop = std::min(minSceneTop, y - sceneHeight / 2.0);
214 placements.reserve(
static_cast<std::size_t
>(graph.numberOfNodes()));
216 for (ogdf::node node : graph.nodes) {
218 const QRectF bounds = component->sceneBoundingRect();
219 const QPointF centerOffset =
220 bounds.isValid() ? bounds.center() - component->pos() : QPointF(0.0, 0.0);
222 const QPointF layoutPoint =
224 ? orientedLayerPoint(attributes.x(node), attributes.y(node),
226 : QPointF(attributes.x(node), attributes.y(node));
227 const double x = layoutPoint.x();
228 const double y = layoutPoint.y();
229 const QPointF arrangedCenter(options.
origin.x() + x - minSceneLeft,
230 options.
origin.y() + y - minSceneTop);
232 placements.emplace(component,