6#include <QGraphicsPixmapItem>
23 .type = ElementType::Node,
24 .group = ElementGroup::Gate,
29 .canChangeAppearance =
true,
32 static_assert(
validate(constraints));
37 meta.pixmapPath = []{
return QStringLiteral(
":/Components/Logic/node.svg"); };
38 meta.titleText = QT_TRANSLATE_NOOP(
"Node",
"NODE");
39 meta.translatedName = QT_TRANSLATE_NOOP(
"Node",
"Node");
40 meta.trContext =
"Node";
41 meta.defaultAppearances = QStringList({
":/Components/Logic/node.svg"});
80 updateWirelessColor(Status::Unknown);
85 updateWirelessColor(status);
92 const auto hex = color.name();
93 const auto svg = QStringLiteral(
94 "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">"
95 "<circle cx=\"1.5\" cy=\"14.5\" r=\"1.5\" fill=\"%1\"/>"
96 "<path d=\"M 1.5,11 A 3.5,3.5 0 0 1 5,14.5\" fill=\"none\" stroke=\"%1\" stroke-width=\"1.5\" stroke-linecap=\"round\"/>"
97 "<path d=\"M 1.5,7 A 7.5,7.5 0 0 1 9,14.5\" fill=\"none\" stroke=\"%1\" stroke-width=\"1.5\" stroke-linecap=\"round\"/>"
98 "<path d=\"M 1.5,3 A 11.5,11.5 0 0 1 13,14.5\" fill=\"none\" stroke=\"%1\" stroke-width=\"1.5\" stroke-linecap=\"round\"/>"
101 QSvgRenderer renderer(svg.toUtf8());
102 QPixmap pixmap(20, 20);
103 pixmap.fill(Qt::transparent);
104 QPainter painter(&pixmap);
105 renderer.render(&painter);
112 return m_wirelessMode;
122 if (m_wirelessMode == mode) {
125 m_wirelessMode = mode;
130 const bool inputRequired = (mode != WirelessMode::Rx);
131 if (
inputPort()->isRequired() != inputRequired) {
136 inputPort()->setVisible(mode != WirelessMode::Rx);
137 outputPort()->setVisible(mode != WirelessMode::Tx);
139 if (mode == WirelessMode::None) {
140 if (m_wirelessIndicator) {
141 m_wirelessIndicator->setVisible(
false);
143 m_wirelessColor = QColor();
150 if (!m_wirelessIndicator) {
153 m_wirelessIndicator->setZValue(1);
154 m_wirelessColor =
color;
157 m_wirelessIndicator->setVisible(
true);
159 if (mode == WirelessMode::Tx) {
163 m_wirelessIndicator->setPos(30, -6);
164 m_wirelessIndicator->setTransform(QTransform());
169 m_wirelessIndicator->setPos(2, -6);
170 m_wirelessIndicator->setTransform(QTransform().scale(-1, 1));
180 QMap<QString, QVariant> map;
185 map.insert(
"wirelessMode",
static_cast<int>(m_wirelessMode));
198 QMap<QString, QVariant> map;
202 const int raw = map.value(
"wirelessMode", 0).toInt();
206void Node::updateWirelessColor(
Status status)
208 if (m_wirelessMode == WirelessMode::None || !m_wirelessIndicator) {
215 case Status::Unknown:
color = theme.m_connectionUnknown;
break;
216 case Status::Inactive:
color = theme.m_connectionInactive;
break;
217 case Status::Active:
color = theme.m_connectionActive;
break;
218 case Status::Error:
color = theme.m_connectionError;
break;
221 if (
color == m_wirelessColor) {
224 m_wirelessColor =
color;
Common logging utilities, the Pandaception error type, and helper macros.
Connection: a wire that connects an output port to an input port in the circuit scene.
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
Enums::WirelessMode WirelessMode
static QPixmap renderWirelessPixmap(const QColor &color)
Graphic element for a wire junction node.
Port classes: Port (base), InputPort, and OutputPort.
Deserialization/serialization context structs passed through load()/save() call chains.
Circuit and waveform file serialization/deserialization utilities.
Theme management types and singleton ThemeManager.
Named version predicates for file-format compatibility checks.
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.
void setLabelAnchor(const QPointF &pos)
bool simUpdateInputsAllowUnknown()
Like simUpdateInputs(), but allows Unknown/Error values through.
void setOutputValue(const int index, const Status value)
Sets simulation output port index to value.
virtual void load(QDataStream &stream, SerializationContext &context)
Loads the graphic element through a binary data stream.
InputPort * inputPort(const int index=0) const
Returns the input port at index (default 0).
virtual QString color() const
Returns the name of the color currently applied to this element.
OutputPort * outputPort(const int index=0) const
Returns the output port at index (default 0).
virtual void save(QDataStream &stream, SerializationOptions options) const
Visible wire junction (T-junction) element with 1 input and 1 output.
Node(QGraphicsItem *parent=nullptr)
Constructs the element with optional parent.
WirelessMode wirelessMode() const override
Returns the current wireless routing mode (None / Tx / Rx).
void setWirelessMode(WirelessMode mode)
Sets the wireless routing mode and adjusts port requirements accordingly.
void updatePortsProperties() override
Recalculates port positions for the current port count.
bool hasWirelessMode() const override
Returns true — Node supports wireless mode configuration.
void save(QDataStream &stream, SerializationOptions options) const override
void load(QDataStream &stream, SerializationContext &context) override
Loads the graphic element through a binary data stream.
void updateLogic() override
Copies the single input value to the single output (pass-through).
void setRequired(const bool required)
Marks whether a wire to this port is mandatory.
static QMap< QString, QVariant > readBoundedMetadata(QDataStream &stream)
Reads the file-level metadata QMap<QString,QVariant> from stream without calling QList::reserve() wit...
QColor m_connectionUnknown
static const ThemeAttributes & attributes()
Returns the current ThemeAttributes color set.
bool hasWirelessMode(const QVersionNumber &v)
V4.4: Node wireless mode stored in file.
Compile-time-validatable subset of ElementMetadata.
static const bool registered
static ElementMetadata metadata()
static constexpr ElementConstraints constraints
Self-registering element information trait.
Bundles all per-deserialization state so that load() overrides receive it through one explicit parame...
QVersionNumber version
File-format version read from the stream header.
Options passed to GraphicElement::save() (and friends); the save-side counterpart of SerializationCon...
SerializationPurpose purpose
What this serialization is for; see SerializationPurpose. Mandatory, no default.