wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ElementInfo.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
10#include "App/Core/Enums.h"
12
22 ElementType type = ElementType::Unknown;
23 ElementGroup group = ElementGroup::Unknown;
24
25 quint64 minInputSize = 0;
26 quint64 maxInputSize = 0;
27 quint64 minOutputSize = 0;
28 quint64 maxOutputSize = 0;
29
30 bool canChangeAppearance = false;
31 bool hasColors = false;
32 bool hasAudio = false;
33 bool hasAudioBox = false;
34 bool hasTrigger = false;
35 bool hasFrequency = false;
36 bool hasDelay = false;
37 bool hasLabel = false;
38 bool hasTruthTable = false;
39 bool hasVolume = false;
40 bool rotatesGraphic = true;
41};
42
48constexpr bool validate(const ElementConstraints &c)
49{
50 // Unknown elements not allowed
51 if (c.type == ElementType::Unknown) {
52 return false;
53 }
54
55 // Group must be set
56 if (c.group == ElementGroup::Unknown) {
57 return false;
58 }
59
60 // Input/output sizes must be consistent
61 if (c.minInputSize > c.maxInputSize) {
62 return false;
63 }
64 if (c.minOutputSize > c.maxOutputSize) {
65 return false;
66 }
67
68 return true;
69}
70
81{
82 ElementMetadata meta;
83 meta.type = c.type;
84 meta.group = c.group;
90 meta.hasColors = c.hasColors;
91 meta.hasAudio = c.hasAudio;
92 meta.hasAudioBox = c.hasAudioBox;
93 meta.hasTrigger = c.hasTrigger;
95 meta.hasDelay = c.hasDelay;
96 meta.hasLabel = c.hasLabel;
98 meta.hasVolume = c.hasVolume;
100 return meta;
101}
102
144template<typename T>
145struct ElementInfo; // Undefined — must be specialized in each element .cpp
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
Element metadata struct and global registry for compile-time element registration.
Central enumeration types for element types, groups, and signal status.
Enums::ElementType ElementType
Definition Enums.h:107
Enums::ElementGroup ElementGroup
Definition Enums.h:108
Compile-time-validatable subset of ElementMetadata.
Definition ElementInfo.h:21
ElementGroup group
Definition ElementInfo.h:23
ElementType type
Definition ElementInfo.h:22
Self-registering element information trait.
Compile-time-registered properties for one element type.
quint64 maxInputSize
Maximum number of input ports.
bool rotatesGraphic
True if rotating/flipping re-orients the graphic itself; false keeps the icon fixed and only repositi...
bool hasLabel
True if the element supports a user-editable label.
ElementGroup group
UI palette group this element belongs to.
bool hasAudioBox
True if the element shows an audio selection box.
quint64 maxOutputSize
Maximum number of output ports.
bool hasFrequency
True if the element exposes a configurable clock frequency.
bool hasAudio
True if the element supports audio output.
bool hasColors
True if the element supports color selection.
bool hasDelay
True if the element exposes a configurable clock phase delay.
bool hasVolume
True if the element supports volume control.
quint64 minInputSize
Minimum number of input ports.
ElementType type
Unique element type identifier.
quint64 minOutputSize
Minimum number of output ports.
bool canChangeAppearance
True if the user can choose a custom appearance.
bool hasTrigger
True if the element supports a keyboard trigger shortcut.
bool hasTruthTable
True if the element has an editable truth table.