8#include <QCoreApplication>
24template <
typename Elements,
typename PortCount>
25void appendRows(QVector<Row> &rows,
const Elements &elements,
const RowKind kind,
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) {
38 const QString rowLabel = (ports > 1) ? label +
"[" + QString::number(port) +
"]" : label;
39 rows.append(
Row{elm, port, kind, rowLabel});
45QStringList labelsOf(
const QVector<Row> &rows,
const RowKind kind)
48 for (
const auto &row : rows) {
49 if (row.kind == kind) {
50 labels.append(row.label);
62 const auto elements = scene->
elements();
64 if (elements.isEmpty()) {
65 throw PANDACEPTION_WITH_CONTEXT(
"BewavedDolphin",
"The circuit is empty. Add input and output elements to generate a waveform.");
68 for (
auto *elm : elements) {
77 if (elm->elementGroup() == ElementGroup::Input) {
78 result.
inputs.append(qobject_cast<GraphicElementInput *>(elm));
81 if (elm->elementGroup() == ElementGroup::Output) {
88 std::stable_sort(result.
inputs.begin(), result.
inputs.end(), [](
const auto &elm1,
const auto &elm2) {
89 return QString::compare(elm1->label(), elm2->label(), Qt::CaseInsensitive) < 0;
92 std::stable_sort(result.
outputs.begin(), result.
outputs.end(), [](
const auto &elm1,
const auto &elm2) {
93 return QString::compare(elm1->label(), elm2->label(), Qt::CaseInsensitive) < 0;
97 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.");
100 if (result.
inputs.isEmpty()) {
101 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.");
104 if (result.
outputs.isEmpty()) {
105 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)
RowKind
Which side of the table a row belongs to.
One waveform table row: exactly one PORT of one element.
The input/output elements (label-sorted) and the row layout 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.
int inputPorts
Total input rows; derived from rows.