13 .type = ElementType::DFlipFlop,
14 .group = ElementGroup::Memory,
19 .canChangeAppearance =
true,
21 static_assert(
validate(constraints));
27 meta.titleText = QT_TRANSLATE_NOOP(
"DFlipFlop",
"D-FLIP-FLOP");
28 meta.translatedName = QT_TRANSLATE_NOOP(
"DFlipFlop",
"D-Flip-Flop");
29 meta.trContext =
"DFlipFlop";
86 m_simLastClk = Status::Unknown;
96 if (clk == Status::Active && m_simLastClk == Status::Inactive) {
98 q1 = (m_simLastValue == Status::Active) ? Status::Inactive : Status::Active;
101 if (prst == Status::Inactive || clr == Status::Inactive) {
102 q0 = (prst == Status::Inactive) ? Status::Active : Status::Inactive;
103 q1 = (clr == Status::Inactive) ? Status::Active : Status::Inactive;
117 m_simLastClk = Status::Inactive;
118 m_simLastValue = Status::Active;
Graphic element for the D flip-flop.
Singleton factory for all circuit element types.
Self-registering element trait template and compile-time constraint validation.
ElementMetadata metadataFromConstraints(const ElementConstraints &c)
Converts ElementConstraints to an ElementMetadata with all constraint-derived fields set.
constexpr bool validate(const ElementConstraints &c)
Validates element constraints at compile time.
Enums::ElementType ElementType
Port classes: Port (base), InputPort, and OutputPort.
Graphical representation of an edge-triggered D flip-flop.
DFlipFlop(QGraphicsItem *parent=nullptr)
Constructs the element with optional parent.
void updateLogic() override
Updates output state on each rising clock edge.
void updatePortsProperties() override
Updates port names for this flip-flop.
void updateTheme() override
Refreshes the pixmap when the application theme changes.
void resetSimState() override
Resets Q/~Q outputs and edge-detection state to power-on defaults.
static QString pixmapPath()
static void registerCreator(ElementType type, std::function< GraphicElement *()> creator)
Registers a creator lambda for type, used by buildElement().
GraphicElement(ElementType type, QGraphicsItem *parent=nullptr)
Constructs a graphic element of the given type, fetching all properties from the metadata registry.
const QVector< Status > & simInputs() const
Read-only view of the cached simulation input values.
virtual void updateTheme()
Updates the element's visual theme according to the current dark/light palette.
void setOutputValue(const int index, const Status value)
Sets simulation output port index to value.
InputPort * inputPort(const int index=0) const
Returns the input port at index (default 0).
OutputPort * outputPort(const int index=0) const
Returns the output port at index (default 0).
bool simUpdateInputs()
Snapshots each predecessor's output into the simulation input cache.
const QVector< Status > & simOutputs() const
Read-only view of the current simulation output values.
void setPixmap(const QString &pixmapPath)
Loads and applies the pixmap located at pixmapPath.
virtual void resetSimState()
Resets all simulation-visible state to power-on defaults.
void setRequired(const bool required)
Marks whether a wire to this port is mandatory.
void setDefaultStatus(const Status defaultStatus)
Sets the status applied when the port has no connection.
void setName(const QString &name)
Sets the label text shown next to the port.
Compile-time-validatable subset of ElementMetadata.
static const bool registered
static ElementMetadata metadata()
static constexpr ElementConstraints constraints
Self-registering element information trait.