8#include <QCoreApplication>
22template <
typename Elements,
typename PortCount>
23QStringList buildLabels(
const Elements &elements,
const PortCount &portCount)
27 for (
auto *elm : elements) {
28 QString label = elm->label();
31 if (label.isEmpty()) {
35 const int ports = portCount(elm);
36 for (
int port = 0; port < ports; ++port) {
39 labels.append(label +
"[" + QString::number(port) +
"]");
55 const auto elements = scene->
elements();
57 if (elements.isEmpty()) {
58 throw PANDACEPTION_WITH_CONTEXT(
"BewavedDolphin",
"The circuit is empty. Add input and output elements to generate a waveform.");
61 for (
auto *elm : elements) {
66 if (elm->elementGroup() == ElementGroup::Input) {
67 result.
inputs.append(qobject_cast<GraphicElementInput *>(elm));
72 if (elm->elementGroup() == ElementGroup::Output) {
79 std::stable_sort(result.
inputs.begin(), result.
inputs.end(), [](
const auto &elm1,
const auto &elm2) {
80 return QString::compare(elm1->label(), elm2->label(), Qt::CaseInsensitive) < 0;
83 std::stable_sort(result.
outputs.begin(), result.
outputs.end(), [](
const auto &elm1,
const auto &elm2) {
84 return QString::compare(elm1->label(), elm2->label(), Qt::CaseInsensitive) < 0;
88 throw PANDACEPTION_WITH_CONTEXT(
"BewavedDolphin",
"The circuit has no input or output elements. Add at least one input (e.g. Switch) and one output (e.g. LED) to generate a waveform.");
91 if (result.
inputs.isEmpty()) {
92 throw PANDACEPTION_WITH_CONTEXT(
"BewavedDolphin",
"The circuit has no input elements. Add at least one input (e.g. Switch, Button, or Clock) to generate a waveform.");
96 throw PANDACEPTION_WITH_CONTEXT(
"BewavedDolphin",
"The circuit has no output elements. Add at least one output (e.g. LED or Display) to generate a waveform.");
Common logging utilities, the Pandaception error type, and helper macros.
#define PANDACEPTION_WITH_CONTEXT(context, msg,...)
DolphinModelBuilder: maps a circuit scene's I/O elements to waveform signal rows.
Singleton factory for all circuit element types.
Abstract base class for all graphical circuit elements.
Main circuit editing scene with undo/redo and user interaction.
static QString translatedName(const ElementType type)
Returns the translated human-readable name for type.
Abstract base class for all graphical circuit elements in wiRedPanda.
Main circuit editing scene.
const QVector< GraphicElement * > elements() const
Returns all graphic elements in the scene.
Collects and orders the input/output elements of a circuit scene and derives the waveform table's row...
Signals collect(Scene *scene)
The input/output elements (label-sorted) and the row labels for a waveform table.
QVector< GraphicElement * > outputs
Output elements, sorted by label.
QStringList inputLabels
Row label per input port (indexed for multi-port).
QVector< GraphicElementInput * > inputs
Input elements, sorted by label.
QStringList outputLabels
Row label per output port (indexed for multi-port).
int inputPorts
Total input rows (sum of input output-port counts).