wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
BeWavedDolphin.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <functional>
11#include <memory>
12
13#include <QFileInfo>
14#include <QMainWindow>
15#include <QStandardItemModel>
16#include <QTableView>
17#include <QUndoStack>
18
22#include "App/Scene/Scene.h"
23
24class DolphinHost;
25class DolphinZoom;
26class ExerciseOverlay;
28
29namespace DolphinSerializer { struct WaveformData; }
30
42class BewavedDolphin : public QMainWindow
43{
44 Q_OBJECT
46
47public:
58 explicit BewavedDolphin(Scene *scene, const bool askConnection = true, DolphinHost *host = nullptr,
59 QWidget *parent = nullptr);
60 ~BewavedDolphin() override;
61
63 void createWaveform();
64
69 void createWaveform(const QString &fileName);
70
72 void print();
73
78 void saveToTxt(QTextStream &stream);
79
81 void show();
82
83 // --- MCP Interface ---
84
90 bool exportToPng(const QString &filename);
91
98 void setCellValue(const int row, const int col, const int value);
99
104 void prepare(const QString &fileName = {});
105
107 void run();
108
114 void setLength(const int simLength, const bool runSimulation = false);
115
117 struct Signal {
118 QString label;
119 QVector<int> values;
120 };
121
124 QList<Signal> inputs;
125 QList<Signal> outputs;
126 };
127
129 WaveformSnapshot snapshot(int duration) const;
130
132 int inputRow(const QString &label) const;
133
134 // --- Tour / Exercise overlay support ---
135
138 void setExerciseOverlay(ExerciseOverlay *overlay);
139
141 QTableView *signalTableView() const { return m_signalTableView; }
143 QToolBar *mainToolBar() const;
145 QAction *actionCombinational() const;
148
149protected:
150 // --- Qt event overrides ---
151
153 void closeEvent(QCloseEvent *event) override;
155 void resizeEvent(QResizeEvent *event) override;
157 bool eventFilter(QObject *watched, QEvent *event) override;
158
159private:
160 Q_DISABLE_COPY(BewavedDolphin)
161
162 // --- Internal accessors (test-only; TestBewavedDolphinGui is a friend) ---
163
164
165 const SignalModel* model() const { return m_model; }
167 const QVector<GraphicElement *>& outputElements() const { return m_outputs; }
169 const QVector<GraphicElementInput *>& inputElements() const { return m_inputs; }
171 int length() const { return m_length; }
172
173 // --- File I/O ---
174
176 bool checkSave();
178 void associateToWiRedPanda(const QString &fileName);
180 void load(const QString &fileName);
182 void applyWaveformData(const DolphinSerializer::WaveformData &fileData);
183
188 bool elementsStillLive() const;
189
190 // --- Signal Table Management ---
191
193 void loadFromTerminal();
196 void loadNewTable(const QStringList &inputLabels, const QStringList &outputLabels);
199 void applyToSelectedCells(const std::function<int(int)> &valueFn);
200
203 std::pair<QList<QPair<int, int>>, QList<int>> snapshotCells(const QModelIndexList &indexes) const;
204
207 QModelIndexList allCellIndexes(int rows, int cols) const;
209 void applyZoom();
211 void zoomChanged();
212
213 // --- Action Handlers (menu / toolbar callbacks) ---
214
215 void on_actionAboutQt_triggered();
216 void on_actionAbout_triggered();
217 void on_actionAutoCrop_triggered();
218 void on_actionClear_triggered();
219 void on_actionCombinational_triggered();
220 void on_actionCopy_triggered();
221 void on_actionCut_triggered();
222 void on_actionExit_triggered();
223 void on_actionExportToPdf_triggered();
224 void on_actionExportToPng_triggered();
225 void on_actionFitScreen_triggered();
226 void on_actionInvert_triggered();
227 void on_actionLoad_triggered();
228 void on_actionPaste_triggered();
229 void on_actionResetZoom_triggered();
230 void on_actionSaveAs_triggered();
231 void on_actionSave_triggered();
232 void on_actionSetClockWave_triggered();
233 void on_actionSetLength_triggered();
234 void on_actionSetTo0_triggered();
235 void on_actionSetTo1_triggered();
236 void on_actionShowNumbers_triggered();
237 void on_actionShowWaveforms_triggered();
238 void on_actionZoomIn_triggered();
239 void on_actionZoomOut_triggered();
240 void on_tableView_cellDoubleClicked();
241 void on_tableView_selectionChanged();
242
243 // --- Members ---
244
245 std::unique_ptr<BewavedDolphinUi> m_ui;
246 QUndoStack m_undoStack;
247 DolphinHost *m_host = nullptr;
248 QFileInfo m_currentFile;
249 SignalModel *m_model = nullptr;
250 QTableView *m_signalTableView = new QTableView();
251 SignalDelegate *m_delegate = nullptr;
252 QVector<GraphicElement *> m_outputs;
253 QVector<GraphicElementInput *> m_inputs;
254 QVector<Status> m_oldInputValues;
255 Scene *m_externalScene = nullptr;
256 Simulation *m_simulation = nullptr;
257 std::unique_ptr<WaveformSimulator> m_simDriver;
258 std::unique_ptr<DolphinZoom> m_zoom;
259 bool m_edited = false;
260 const bool m_askConnection;
261 int m_clockPeriod = 0;
262 int m_inputPorts = 0;
263 int m_length = 32;
264 ExerciseOverlay *m_exerciseOverlay = nullptr;
265};
BewavedDolphinUi: hand-written UI class for the BeWavedDolphin main window.
Main circuit editing scene with undo/redo and user interaction.
SignalDelegate: paints digital waveform graphics into table cells.
SignalModel for the beWavedDolphin waveform table.
Waveform editor main window for creating and analyzing digital signal sequences.
void print()
Prints the waveform table to the system printer.
int inputRow(const QString &label) const
Returns the input row index whose element label equals label, or -1 (MCP access).
void run()
Runs the simulation for all input combinations and fills output rows.
void createWaveform()
Initializes a blank waveform from the current scene's I/O elements.
~BewavedDolphin() override
QTableView * signalTableView() const
Returns the waveform table view (for tour target resolution).
void setExerciseOverlay(ExerciseOverlay *overlay)
void setCellValue(const int row, const int col, const int value)
Sets a single cell value in the waveform table.
QAction * actionCombinational() const
Returns the combinational action (for tour button spotlighting).
void prepare(const QString &fileName={})
Prepares the waveform from fileName (or blank if empty).
friend class TestBewavedDolphinGui
void saveToTxt(QTextStream &stream)
Exports the waveform data as plain text to stream.
WaveformSnapshot snapshot(int duration) const
Returns the input/output signals over the first duration columns (MCP access).
bool exportToPng(const QString &filename)
Exports the waveform scene to a PNG image file.
QToolBar * mainToolBar() const
Returns the main toolbar (for tour target resolution).
void show()
Shows the window and loads the initial waveform.
void resizeEvent(QResizeEvent *event) override
bool eventFilter(QObject *watched, QEvent *event) override
void triggerCombinational()
Triggers the combinational input-pattern generator (for tour automation).
void closeEvent(QCloseEvent *event) override
BewavedDolphin(Scene *scene, const bool askConnection=true, DolphinHost *host=nullptr, QWidget *parent=nullptr)
Constructs the waveform editor.
void setLength(const int simLength, const bool runSimulation=false)
Sets the number of time-step columns.
Interface the host application (MainWindow) provides to BewavedDolphin.
Definition DolphinHost.h:24
Owns the waveform table's zoom state and the math that maps it to view metrics.
Definition DolphinZoom.h:23
Semi-transparent overlay displayed at the bottom of the canvas during a circuit exercise.
Main circuit editing scene.
Definition Scene.h:56
QStandardItemModel subclass that makes all cells non-editable.
Definition SignalModel.h:21
Drives the circuit simulation across the waveform's time columns.
Pure I/O functions for the beWavedDolphin waveform file formats.
A labelled waveform signal: a row label and its per-column 0/1 values.
QVector< int > values
Per-column logic values.
QString label
The signal's display label.
A read-only snapshot of the computed waveform, for automation/export consumers.
QList< Signal > outputs
Output signals (one per output element).
QList< Signal > inputs
Input signals (one per input element).
Raw waveform data returned by the load functions.
Definition Serializer.h:33