diagrams-fable-qt/tests/TestFixtures.h
Ilya Ashikhmin 26905a4ba0 feat(core): add network model with typed ports, relations and grouped properties
Data-driven node types (SVG + port config) loaded from JSON, relation-based
connection validation, and a property system supporting string, int, float,
enum, catalogue item(s), color and value-list types grouped by category.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 23:14:11 +02:00

136 lines
5.5 KiB
C++

#pragma once
// Shared in-code registry fixture: a minimal water + power schema mirroring
// the shape of the shipped JSON config, without resource dependencies.
#include "core/TypeRegistry.h"
namespace fixtures {
inline diag::PropertySpec floatSpec(const QString& id, const QString& name, const QString& group,
double def, const QString& unit = {})
{
diag::PropertySpec s;
s.id = id;
s.name = name;
s.group = group;
s.type = diag::PropertyType::Float;
s.defaultValue = def;
s.unit = unit;
return s;
}
inline diag::PortSpec port(const QString& id, const QString& relation, diag::PortDirection dir,
QPointF pos, diag::Side side, int maxConnections = 1)
{
diag::PortSpec p;
p.id = id;
p.relation = relation;
p.direction = dir;
p.pos = pos;
p.side = side;
p.maxConnections = maxConnections;
return p;
}
inline void fillRegistry(diag::TypeRegistry& reg)
{
using namespace diag;
reg.clear();
reg.addRelation({QStringLiteral("water"), QStringLiteral("Water"), QColor("#1c78c0"),
QColor("#4aa3e8")});
reg.addRelation({QStringLiteral("power"), QStringLiteral("Power"), QColor("#d99000"),
QColor("#f0b429")});
Catalogue pipes;
pipes.id = QStringLiteral("pipe_series");
pipes.name = QStringLiteral("Pipe series");
pipes.items = {{QStringLiteral("dn50"), QStringLiteral("DN50 Steel"),
{{QStringLiteral("diameter"), 50}}},
{QStringLiteral("dn100"), QStringLiteral("DN100 Steel"),
{{QStringLiteral("diameter"), 100}}}};
reg.addCatalogue(pipes);
QList<PropertySpec> waterEdge;
waterEdge << floatSpec(QStringLiteral("length"), QStringLiteral("Length"),
QStringLiteral("Physics"), 10.0, QStringLiteral("m"));
waterEdge << floatSpec(QStringLiteral("diameter"), QStringLiteral("Diameter"),
QStringLiteral("Physics"), 100.0, QStringLiteral("mm"));
PropertySpec flowType;
flowType.id = QStringLiteral("flowType");
flowType.name = QStringLiteral("Flow type");
flowType.group = QStringLiteral("Physics");
flowType.type = PropertyType::Enum;
flowType.enumValues = {QStringLiteral("Laminar"), QStringLiteral("Turbulent")};
flowType.defaultValue = QStringLiteral("Laminar");
waterEdge << flowType;
PropertySpec series;
series.id = QStringLiteral("series");
series.name = QStringLiteral("Pipe series");
series.group = QStringLiteral("Physics");
series.type = PropertyType::CatalogueItem;
series.catalogueId = QStringLiteral("pipe_series");
waterEdge << series;
reg.setEdgeProperties(QStringLiteral("water"), waterEdge);
NodeType source;
source.id = QStringLiteral("source");
source.name = QStringLiteral("Source");
source.group = QStringLiteral("Water");
source.size = {60, 60};
source.ports = {port(QStringLiteral("out"), QStringLiteral("water"), PortDirection::Out,
{1.0, 0.5}, Side::Right, 0)};
source.properties = {floatSpec(QStringLiteral("supply"), QStringLiteral("Supply"),
QStringLiteral("Physics"), 10.0, QStringLiteral("m³/h"))};
reg.addNodeType(source);
NodeType pump;
pump.id = QStringLiteral("pump");
pump.name = QStringLiteral("Pump");
pump.group = QStringLiteral("Water");
pump.size = {60, 60};
pump.ports = {port(QStringLiteral("in"), QStringLiteral("water"), PortDirection::In,
{0.0, 0.5}, Side::Left),
port(QStringLiteral("out"), QStringLiteral("water"), PortDirection::Out,
{1.0, 0.5}, Side::Right)};
reg.addNodeType(pump);
NodeType junction;
junction.id = QStringLiteral("junction");
junction.name = QStringLiteral("Junction");
junction.group = QStringLiteral("Water");
junction.size = {40, 40};
junction.ports = {port(QStringLiteral("w"), QStringLiteral("water"), PortDirection::InOut,
{0.0, 0.5}, Side::Left, 0),
port(QStringLiteral("e"), QStringLiteral("water"), PortDirection::InOut,
{1.0, 0.5}, Side::Right, 0),
port(QStringLiteral("n"), QStringLiteral("water"), PortDirection::InOut,
{0.5, 0.0}, Side::Top, 0),
port(QStringLiteral("s"), QStringLiteral("water"), PortDirection::InOut,
{0.5, 1.0}, Side::Bottom, 0)};
reg.addNodeType(junction);
NodeType consumer;
consumer.id = QStringLiteral("consumer");
consumer.name = QStringLiteral("Consumer");
consumer.group = QStringLiteral("Water");
consumer.size = {60, 60};
consumer.ports = {port(QStringLiteral("in"), QStringLiteral("water"), PortDirection::In,
{0.0, 0.5}, Side::Left)};
consumer.properties = {floatSpec(QStringLiteral("demand"), QStringLiteral("Demand"),
QStringLiteral("Physics"), 10.0, QStringLiteral("m³/h"))};
reg.addNodeType(consumer);
NodeType generator;
generator.id = QStringLiteral("generator");
generator.name = QStringLiteral("Generator");
generator.group = QStringLiteral("Power");
generator.size = {60, 60};
generator.ports = {port(QStringLiteral("out"), QStringLiteral("power"), PortDirection::Out,
{1.0, 0.5}, Side::Right, 0)};
reg.addNodeType(generator);
}
} // namespace fixtures