Aktueller technischer Ansatz (detaillierte Implementierung)
Meine Architektur besteht aus zwei Hauptkomponenten, die zusammenarbeiten, um Logikgatter aus JSON-Definitionen zu rendern:
0. Formdefinitionssystem
Jede Komponente wird in einer JSON-Datei definiert (
Code: Select all
canvas_elements.jsonCode: Select all
{
"id": "OR_Gate",
"name": "OR Gate",
"anchorPoint": [80, 60],
"shapes": [
{
"type": "BezierShape",
"p0": {"x": 43, "y": 20},
"p1": {"x": 85, "y": 24},
"p2": {"x": 110, "y": 60},
"color": "#333333"
},
{
"type": "BezierShape",
"p0": {"x": 43, "y": 100},
"p1": {"x": 85, "y": 96},
"p2": {"x": 110, "y": 60},
"color": "#333333"
},
{
"type": "BezierShape",
"p0": {"x": 43, "y": 20},
"p1": {"x": 60, "y": 60},
"p2": {"x": 43, "y": 100},
"color": "#333333"
}
]
}
1. CanvasModel: JSON-Analyse und Element Factory (
Code: Select all
CanvasModel.hCode: Select all
// CanvasModel.h - JSON deserialization entry point
#pragma once
#include
#include
#include
class CanvasElement;
// Global function: JSON -> CanvasElement list
std::vector LoadCanvasElements(const wxString& jsonPath);
2. CanvasElement: Formspeicher- und Bezier-Rendering-Engine (
Code: Select all
CanvasElement.hCode: Select all
// CanvasElement.h - Core shape storage and Bezier math
#pragma once
#include
#include
#include
#include
#include
struct Point { int x, y; };
// Quadratic Bezier curve definition (loaded directly from JSON)
struct BezierShape {
Point p0, p1, p2;
wxColour color;
BezierShape(Point p0 = Point(), Point p1 = Point(), Point p2 = Point(),
wxColour c = wxColour(0, 0, 0))
: p0(p0), p1(p1), p2(p2), color(c) {}
};
// Shape variant that stores all drawable primitives
using Shape = std::variant[*];
class CanvasElement {
private:
std::vector m_shapes; // All shapes for this element, including Bezier curves
// Core Bezier math: samples quadratic curve into polyline
std::vector CalculateBezier(const Point& p0, const Point& p1,
const Point& p2, int segments = 16) const {
std::vector points;
for (int i = 0; i
Mobile version