wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
GraphicElementInput.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
11
24{
25 Q_OBJECT
26
27public:
28 // --- Lifecycle ---
29
30 explicit GraphicElementInput(ElementType type, QGraphicsItem *parent = nullptr)
31 : GraphicElement(type, parent) {}
32 ~GraphicElementInput() override = default;
33
34 // --- State Queries ---
35
37 bool isLocked() const { return m_locked; }
38
43 virtual bool isOn(const int port = 0) const = 0;
44
46 virtual int outputSize() const { return 1; }
47
49 virtual int outputValue() const { return static_cast<int>(isOn()); }
50
52 virtual void setOff() = 0;
53
55 virtual void setOn() = 0;
56
68 virtual void setOn(const bool value, const int port = 0);
69
81 virtual void setWaveformValue(const bool value, const int port = 0);
82
88 void setAppearance(const bool defaultAppearance, const QString &fileName) override;
89
94 void setLocked(const bool locked) { m_locked = locked; }
95
96 // --- Updates ---
97
99 void updateOutputs();
100
101protected:
102 // --- Members ---
103
104 bool m_isOn = false;
105 bool m_locked = false;
106};
107
109{
110 for (int portIndex = 0; portIndex < outputSize(); ++portIndex) {
111 if (portIndex < simOutputSize()) {
112 setOutputValue(portIndex, isOn(portIndex));
113 }
114 }
115}
Enums::ElementType ElementType
Definition Enums.h:107
Abstract base class for all graphical circuit elements.
void setAppearance(const bool defaultAppearance, const QString &fileName) override
void setLocked(const bool locked)
Locks or unlocks user interaction on this element.
~GraphicElementInput() override=default
void updateOutputs()
Propagates the current on/off state of each output to the backing logic element.
virtual int outputSize() const
Returns the number of output ports (default 1 for most input elements).
virtual void setOff()=0
Sets all outputs to inactive (logic-0).
virtual void setOn()=0
Sets all outputs to active (logic-1).
GraphicElementInput(ElementType type, QGraphicsItem *parent=nullptr)
bool isLocked() const
Returns true if the element is locked against user interaction.
virtual bool isOn(const int port=0) const =0
Returns true if the output on port is currently active (logic-1).
virtual void setWaveformValue(const bool value, const int port=0)
Applies a waveform-sweep cell value to output port.
virtual int outputValue() const
Returns the integer encoding of the current output value.
GraphicElement(ElementType type, QGraphicsItem *parent=nullptr)
Constructs a graphic element of the given type, fetching all properties from the metadata registry.
qsizetype simOutputSize() const
Returns the number of simulation output slots.
void setOutputValue(const int index, const Status value)
Sets simulation output port index to value.
int type() const override
Returns the custom type identifier for this item.