12#include <QElapsedTimer>
13#include <QGraphicsScene>
19#include <QUndoCommand>
20#include <QVersionNumber>
61 void addItem(QGraphicsItem *item);
128 [[nodiscard]]
bool contains(
int id)
const;
157 explicit Scene(QObject *parent =
nullptr);
178 QList<QGraphicsItem *>
items(Qt::SortOrder order = Qt::AscendingOrder)
const;
180 QList<QGraphicsItem *>
items(QPointF pos, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::AscendingOrder,
const QTransform &deviceTransform = QTransform())
const;
182 QList<QGraphicsItem *>
items(
const QRectF &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::AscendingOrder,
const QTransform &deviceTransform = QTransform())
const;
186 const QVector<GraphicElement *>
elements()
const;
188 const QVector<GraphicElement *>
elements(
const QRectF &rect)
const;
235 QGraphicsItem *
itemAt(QPointF pos)
const;
240 [[nodiscard]]
Port *
portAt(QPointF pos)
const;
243 [[nodiscard]] QPointF
mousePos()
const {
return m_interaction.lastMousePos(); }
253 void addItem(QMimeData *mimeData, std::optional<QPointF> scenePos = std::nullopt);
384 bool eventFilter(QObject *watched, QEvent *event)
override;
406 void icOpenRequested(
int elementId,
const QString &blobName,
const QString &filePath);
430 void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
override;
432 void dropEvent(QGraphicsSceneDragDropEvent *event)
override;
446 void helpEvent(QGraphicsSceneHelpEvent *event)
override;
453 bool nudgeSelection(QKeyEvent *event);
454 QList<QGraphicsItem *> itemsAt(
const QPointF pos)
const;
455 const QVector<Connection *> connections()
const;
456 void checkUpdateRequest();
457 void updateUndoText(
const QString &text);
458 void updateRedoText(
const QString &text);
459 void drawBackground(QPainter *painter,
const QRectF &rect)
override;
460 void rotate(
const int angle);
461 void setDots(
const QPen &dots);
474 QUndoStack m_undoStack;
475 QAction *m_redoAction;
476 QAction *m_undoAction;
490 bool m_handlingMouseMove =
false;
493 QString m_contextDir;
499 bool m_autosaveRequired =
false;
516 bool m_visibilityDirty =
false;
521 mutable QRectF m_cachedItemsBoundingRect;
522 mutable bool m_itemsBoundingRectDirty =
true;
529 bool m_wireAntialiasing =
true;
530 int m_wireAaSlowPasses = 0;
531 int m_wireAaHeadroomPasses = 0;
532 QTimer m_wireAaIdleTimer;
533 QElapsedTimer m_wireFlipTimer;
534 QElapsedTimer m_wirePassTimer;
537 void checkWireIdleRestore();
ClipboardManager: handles copy, cut, paste and clone-drag operations.
ConnectionManager: manages wire creation, deletion, validation and hover feedback.
Interface for resolving a scene's associated .panda file directory.
IC definition registry with file watching and embedded blob storage.
InlineLabelEditor: on-canvas inline editing of an element's label.
Port classes: Port (base), InputPort, and OutputPort.
PropertyShortcutHandler: dispatches keyboard shortcuts that cycle element properties.
SceneDropHandler: decodes drag-and-drop payloads into scene elements.
SceneInteraction: owns the scene's mouse-driven editing state and gestures.
SceneItemRegistry: maps stable integer IDs to the scene's identifiable items.
SerializationPurpose
What a serialization operation is for – shared by both load() and save(), so the same distinction is ...
Interface exposing the narrow slice of Scene that Simulation depends on.
Synchronous cycle-based simulation engine with event-driven clock support.
VisibilityManager: controls gate and wire visibility in the scene.
Manages clipboard operations (copy/cut/paste) and clone-drag for the circuit scene.
Manages interactive wire creation, deletion, validation and hover feedback.
A bezier-curve wire connecting an output port to an input port in the scene.
Narrow interface exposing a scene's context directory.
Abstract base class for all graphical circuit elements in wiRedPanda.
Extended QGraphicsView with enhanced navigation capabilities.
Manages IC definitions, file watching, and embedded blob storage.
Graphic element representing an Integrated Circuit (sub-circuit) box.
Hosts a temporary QLineEdit directly on the canvas to rename an element's label in place,...
Base class providing a unique integer identifier for circuit items.
A port that drives a signal (the source end of a wire).
Abstract base class for circuit element ports (connection endpoints).
Dispatches keyboard shortcuts that cycle element properties and types.
Decodes wiRedPanda drag-and-drop payloads (new element from the palette, and clone-drag of an existin...
Owns the interactive editing state of a Scene — element dragging, the rubber-band selection rectangle...
Owns the id↔item bookkeeping for a Scene: the id-to-item map and the monotonically increasing last-as...
void flipHorizontally()
Flips selected elements horizontally.
void truthTableElementChanged(GraphicElement *element)
Emitted after a TruthTable element's output bit is toggled (redo or undo).
const QVector< GraphicElement * > elements() const
Returns all graphic elements in the scene.
void alignBottom()
Aligns selected elements' bottom edges to the bottommost selected edge. No-op below 2 elements.
void icPreviewRequested(IC *ic, const QPoint &screenPos)
void restoreWireAntialiasing()
void setLastId(int newLastId)
Advances the scene's ID counter to at least newLastId.
void dropEvent(QGraphicsSceneDragDropEvent *event) override
void recordWirePaintPass(qint64 elapsedNs)
void pasteAction()
Pastes items from the internal clipboard into the scene.
void fileDropRequested(const QString &filePath)
Emitted when a .panda file is dropped onto the canvas from the file manager.
QRectF cachedItemsBoundingRect() const
void resizeScene()
Tightens the scene rect to item bounds while preserving the viewport position.
bool wireAntialiasingEnabled() const
true while wires should stroke with antialiasing; Connection::paint() consults this.
void keyPressEvent(QKeyEvent *event) override
VisibilityManager * visibilityManager()
Returns the visibility manager for this scene.
void nextSecndPropShortcut()
Advances the secondary property of selected elements to the next value.
void showStatusMessageRequested(const QString &message)
GraphicsView * view() const
Returns the GraphicsView currently displaying this scene.
void contextMenuPos(QPoint screenPos, QGraphicsItem *itemAtMouse)
Emitted when a context menu should appear.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
bool eventFilter(QObject *watched, QEvent *event) override
void alignRight()
Aligns selected elements' right edges to the rightmost selected edge. No-op below 2 elements.
void setCircuitUpdateRequired()
Marks the simulation mapping as stale so it is rebuilt on the next tick.
Port * portAt(QPointF pos) const
PropertyShortcutHandler * propertyShortcutHandler()
Returns the handler for keyboard shortcuts that cycle element properties.
void prevElm()
Cycles selection backward to the previous element.
void forgetItemId(int id)
void removeItem(QGraphicsItem *item)
Removes item from the scene and unregisters it from the per-scene ID registry.
void copyAction()
Copies the selected items to the internal clipboard.
QAction * redoAction() const
Returns the redo QAction bound to the undo stack.
void icOpenRequested(int elementId, const QString &blobName, const QString &filePath)
Emitted when an IC element is double-clicked to request opening its sub-circuit.
void showStatusMessage(const QString &message)
void icPreviewMoved(IC *ic, const QPoint &screenPos)
static QHash< QString, InputPort * > wirelessTxInputPorts(const QVector< GraphicElement * > &elements)
Returns a map from wireless channel label to the Tx node's input port.
void rotateLeft()
Rotates selected elements 90 degrees counter-clockwise.
void receiveCommand(QUndoCommand *cmd)
Pushes cmd onto the undo stack (immediately executes its redo()).
int lastId() const
Returns the current highest ID in use by this scene.
QList< QGraphicsItem * > simulationItems() const override
void contextMenu(const QPoint screenPos)
Opens the element/selection context menu at screenPos (driven by SceneInteraction on right-click).
const QList< GraphicElement * > selectedElements() const
Returns the list of currently selected graphic elements.
static bool isConnectionAllowed(OutputPort *startPort, InputPort *endPort)
Returns true if a wire from startPort to endPort is permitted.
void distributeVertically()
void duplicateAction()
Duplicates the selection in place (leaves the system clipboard untouched).
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
QString contextDir() const override
Returns the directory of the .panda file associated with this scene.
void icPreviewCancelRequested(IC *ic)
void prevMainPropShortcut()
Retreats the main property of selected elements to the previous value.
void prevSecndPropShortcut()
Retreats the secondary property of selected elements to the previous value.
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override
void setAutosaveRequired()
Schedules an autosave of the current circuit state.
bool contains(int id) const
Returns true if an item with id is registered in this scene.
void selectAll()
Selects all items in the scene.
QGraphicsItem * itemAt(QPointF pos) const
Returns the topmost item at pos, prioritising ports over elements.
ItemWithId * itemById(int id) const
Returns the item registered under id, or nullptr if not found.
void rotateRight()
Rotates selected elements 90 degrees clockwise.
void alignVerticalCenter()
static QVector< GraphicElement * > sortByTopology(QVector< GraphicElement * > elements)
Returns elements sorted in topological dependency order (inputs first).
void setPropertyUpdateRequired()
void retranslateUi()
Updates undo/redo action text to reflect the current UI language.
ConnectionManager * connectionManager()
Returns the connection manager that handles wire creation, deletion, and hover feedback.
void flipVertically()
Flips selected elements vertically.
void addItem(QGraphicsItem *item)
Adds item to the scene and registers it in the per-scene ID registry.
ClipboardManager * clipboardManager()
Returns the clipboard manager that handles copy, cut, paste and clone-drag.
void mute(const bool mute=true)
Mutes or unmutes selected elements according to mute.
void keyReleaseEvent(QKeyEvent *event) override
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
void showWires(bool checked)
Shows or hides connection wires. Delegates to VisibilityManager.
void nextMainPropShortcut()
Advances the main property of selected elements to the next value.
void nextElm()
Cycles selection forward to the next element.
void icPreviewHideRequested()
ICRegistry * icRegistry()
Returns the IC definition registry for this scene.
void deleteAction()
Deletes the currently selected items.
void helpEvent(QGraphicsSceneHelpEvent *event) override
int nextId()
Returns the next available scene-local ID (does not assign it).
Scene(QObject *parent=nullptr)
Constructs a Scene and initialises the undo stack and simulation.
void alignTop()
Aligns selected elements' top edges to the topmost selected edge. No-op below 2 elements.
QList< QGraphicsItem * > items(Qt::SortOrder order=Qt::AscendingOrder) const
void alignLeft()
Aligns selected elements' left edges to the leftmost selected edge. No-op below 2 elements.
void updateItemId(ItemWithId *item, int newId)
Reassigns the ID of item to newId without adding it to the scene.
void circuitHasChanged()
Emitted whenever the circuit changes (element added/removed/moved).
static QString droppedPandaFile(const QMimeData *mimeData)
void distributeHorizontally()
void openTruthTableRequested()
Emitted when a TruthTable element is double-clicked to request opening its editor.
void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override
void showGates(bool checked)
Shows or hides gate elements. Delegates to VisibilityManager.
void alignHorizontalCenter()
const QVector< GraphicElement * > visibleElements() const
Returns all visible (non-hidden) graphic elements in the scene.
void updateTheme()
Propagates the current theme to all elements and connections.
SerializationContext deserializationContext(QHash< quint64, Port * > &portMap, const QVersionNumber &version, SerializationPurpose purpose)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
QPointF mousePos() const
Returns the last known mouse position in scene coordinates.
void setMuted(const bool muted) override
void cutAction()
Cuts the selected items to the internal clipboard.
const QVector< GraphicElement * > unsortedElements() const
void setContextDir(const QString &dir)
Sets the directory of the .panda file associated with this scene.
void setView(GraphicsView *view)
Sets the GraphicsView that displays this scene to view.
QAction * undoAction() const
Returns the undo QAction bound to the undo stack.
Simulation * simulation()
Returns the simulation engine associated with this scene.
QUndoStack * undoStack()
Returns the scene's undo stack.
Narrow interface letting Simulation reach its host scene without naming the concrete Scene class.
Manages the digital circuit simulation loop.
Controls the visibility of gates, wires, and port handles in the circuit scene.
Bundles all per-deserialization state so that load() overrides receive it through one explicit parame...