wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
InputGND.cpp
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
5
8#include "App/Wiring/Port.h"
9
10template<>
13 .type = ElementType::InputGnd,
14 .group = ElementGroup::StaticInput,
15 .minOutputSize = 1,
16 .maxOutputSize = 1,
17 .canChangeAppearance = true,
18 // Static inputs are not rotatable as a whole; instead their output port rotates
19 // around the element centre so the wire attachment point tracks the correct position.
20 .rotatesGraphic = false,
21 };
22 static_assert(validate(constraints));
23
25 {
27 meta.pixmapPath = []{ return QStringLiteral(":/Components/Input/0.svg"); };
28 meta.titleText = QT_TRANSLATE_NOOP("InputGnd", "GROUND");
29 meta.translatedName = QT_TRANSLATE_NOOP("InputGnd", "GND");
30 meta.trContext = "InputGnd";
31 // Seed appearance lists from the constructor-supplied pixmap path (see And.cpp for details).
32 meta.defaultAppearances = QStringList({":/Components/Input/0.svg"});
33 return meta;
34 }
35
36 static inline const bool registered = []() {
38 ElementFactory::registerCreator(constraints.type, [] { return new InputGnd(); });
39 return true;
40 }();
41};
42
43InputGnd::InputGnd(QGraphicsItem *parent)
45{
46 // GND always outputs logic LOW; set the port default so both the visual
47 // wire colour and the simulation output vector are correct from the start.
48 outputs().constFirst()->setDefaultStatus(Status::Inactive);
49}
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.
Definition ElementInfo.h:80
constexpr bool validate(const ElementConstraints &c)
Validates element constraints at compile time.
Definition ElementInfo.h:48
Enums::ElementType ElementType
Definition Enums.h:107
Graphic element for the GND (logic-0 constant) input.
Port classes: Port (base), InputPort, and OutputPort.
static void registerCreator(ElementType type, std::function< GraphicElement *()> creator)
Registers a creator lambda for type, used by buildElement().
static void registerMetadata(const ElementMetadata &meta)
Registers meta in the global map (called once per element type at startup).
GraphicElement(ElementType type, QGraphicsItem *parent=nullptr)
Constructs a graphic element of the given type, fetching all properties from the metadata registry.
const QVector< OutputPort * > & outputs() const
Returns a const reference to the vector of all output ports.
Static GND element that always drives logic-0 on its output.
Definition InputGND.h:17
InputGnd(QGraphicsItem *parent=nullptr)
Constructs an InputGnd element.
Definition InputGND.cpp:43
Compile-time-validatable subset of ElementMetadata.
Definition ElementInfo.h:21
static constexpr ElementConstraints constraints
Definition InputGND.cpp:12
static ElementMetadata metadata()
Definition InputGND.cpp:24
static const bool registered
Definition InputGND.cpp:36
Self-registering element information trait.
Compile-time-registered properties for one element type.