wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
InputVCC.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::InputVcc,
14 .group = ElementGroup::StaticInput,
15 .minOutputSize = 1,
16 .maxOutputSize = 1,
17 .canChangeAppearance = true,
18 // Static inputs are not rotatable as a whole (see InputGND.cpp for explanation).
19 .rotatesGraphic = false,
20 };
21 static_assert(validate(constraints));
22
24 {
26 meta.pixmapPath = []{ return QStringLiteral(":/Components/Input/1.svg"); };
27 meta.titleText = QT_TRANSLATE_NOOP("InputVcc", "VCC");
28 meta.translatedName = QT_TRANSLATE_NOOP("InputVcc", "VCC");
29 meta.trContext = "InputVcc";
30 // Seed appearance lists from the constructor-supplied pixmap path (see And.cpp for details).
31 meta.defaultAppearances = QStringList({":/Components/Input/1.svg"});
32 return meta;
33 }
34
35 static inline const bool registered = []() {
37 ElementFactory::registerCreator(constraints.type, [] { return new InputVcc(); });
38 return true;
39 }();
40};
41
42InputVcc::InputVcc(QGraphicsItem *parent)
44{
45 // VCC always outputs logic HIGH; set the port default so both the visual
46 // wire colour and the simulation output vector are correct from the start.
47 outputs().constFirst()->setDefaultStatus(Status::Active);
48}
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 VCC (logic-1 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 VCC element that always drives logic-1 on its output.
Definition InputVCC.h:17
InputVcc(QGraphicsItem *parent=nullptr)
Constructs an InputVcc element.
Definition InputVCC.cpp:42
Compile-time-validatable subset of ElementMetadata.
Definition ElementInfo.h:21
static const bool registered
Definition InputVCC.cpp:35
static constexpr ElementConstraints constraints
Definition InputVCC.cpp:12
static ElementMetadata metadata()
Definition InputVCC.cpp:23
Self-registering element information trait.
Compile-time-registered properties for one element type.