Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions crates/konnect-core/src/tools/footprint_graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use konnect_sexp::writer::{
use serde::{Deserialize, Serialize};
use serde_json::json;

fn point_schema() -> serde_json::Value {
pub(super) fn point_schema() -> serde_json::Value {
json!({
"type": "object",
"properties": {
Expand All @@ -22,7 +22,12 @@ fn point_schema() -> serde_json::Value {
})
}

fn common_shape_properties() -> serde_json::Map<String, serde_json::Value> {
/// Shared shape properties, with the fill vocabulary of the calling domain.
/// Footprints fill or they do not; a symbol also has KiCad's pale `background`
/// body fill, so the geometry is shared and only this list differs.
pub(super) fn common_shape_properties_with_fill(
fill_values: &[&str],
) -> serde_json::Map<String, serde_json::Value> {
serde_json::Map::from_iter([
(
"stroke_width_mm".to_string(),
Expand All @@ -36,13 +41,13 @@ fn common_shape_properties() -> serde_json::Map<String, serde_json::Value> {
"fill".to_string(),
json!({
"type": "string",
"enum": ["none", "solid"]
"enum": fill_values
}),
),
])
}

fn primitive_schema(
pub(super) fn primitive_schema(
primitive_type: &str,
mut properties: serde_json::Map<String, serde_json::Value>,
required: &[&str],
Expand All @@ -57,22 +62,28 @@ fn primitive_schema(
}

fn graphics_schema() -> serde_json::Value {
graphics_schema_with_fill(&["none", "solid"])
}

/// The primitive vocabulary, shared with `create_symbol` so the two domains
/// cannot drift apart. Only the fill values differ.
pub(super) fn graphics_schema_with_fill(fill_values: &[&str]) -> serde_json::Value {
let mut line = serde_json::Map::new();
line.insert("start".to_string(), point_schema());
line.insert("end".to_string(), point_schema());
line.insert(
"stroke_width_mm".to_string(),
common_shape_properties()["stroke_width_mm"].clone(),
common_shape_properties_with_fill(fill_values)["stroke_width_mm"].clone(),
);

let mut arc = line.clone();
arc.insert("mid".to_string(), point_schema());

let mut rect = common_shape_properties();
let mut rect = common_shape_properties_with_fill(fill_values);
rect.insert("start".to_string(), point_schema());
rect.insert("end".to_string(), point_schema());

let mut circle = common_shape_properties();
let mut circle = common_shape_properties_with_fill(fill_values);
circle.insert("center".to_string(), point_schema());
circle.insert(
"radius_mm".to_string(),
Expand All @@ -83,7 +94,7 @@ fn graphics_schema() -> serde_json::Value {
}),
);

let mut poly = common_shape_properties();
let mut poly = common_shape_properties_with_fill(fill_values);
poly.insert(
"points".to_string(),
json!({
Expand Down
Loading
Loading