use crate::feature_pipeline::SelectionProbe;
pub(crate) mod angle;
pub(crate) mod center;
pub(crate) mod coincident;
pub(crate) mod concentric;
pub(crate) mod distance;
pub(crate) mod fixed;
pub(crate) mod parallel;
pub(crate) mod perpendicular;
pub(crate) mod tangent;
pub(crate) mod touch_align;
pub struct ConstraintTypeDef {
pub type_id: &'static str,
pub short_name: &'static str,
pub icon: &'static str,
pub long_name: &'static str,
pub label: &'static str,
pub min_elements: usize,
pub max_elements: usize,
pub duplicate_family: bool,
pub applicable: fn(&SelectionProbe) -> bool,
}
pub const CONSTRAINT_TYPES: [ConstraintTypeDef; 10] = [
fixed::DEF,
coincident::DEF,
touch_align::DEF,
parallel::DEF,
distance::DEF,
angle::DEF,
concentric::DEF,
perpendicular::DEF,
tangent::DEF,
center::DEF,
];
pub fn constraint_type(type_id: &str) -> Option<&'static ConstraintTypeDef> {
CONSTRAINT_TYPES.iter().find(|def| def.type_id == type_id)
}
pub fn constraint_schema_catalogue() -> serde_json::Value {
serde_json::Value::Array(vec![
fixed::schema(),
coincident::schema(),
touch_align::schema(),
parallel::schema(),
distance::schema(),
angle::schema(),
concentric::schema(),
perpendicular::schema(),
tangent::schema(),
center::schema(),
])
}
pub(super) fn pair_applicable(probe: &SelectionProbe, seedable: usize) -> bool {
probe.all_component && probe.components == 2 && seedable == 2
}
pub(super) fn id_field() -> serde_json::Value {
serde_json::json!({
"type": "string",
"default_value": null,
"hint": "Unique identifier for the constraint"
})
}
pub(super) fn elements_field(
filter: &[&str],
min: usize,
max: usize,
hint: &str,
) -> serde_json::Value {
serde_json::json!({
"type": "reference_selection",
"selectionFilter": filter,
"multiple": max > 1,
"minSelections": min,
"maxSelections": max,
"default_value": null,
"hint": hint
})
}
pub(super) fn schema_entry(
def: &ConstraintTypeDef,
params: serde_json::Value,
) -> serde_json::Value {
serde_json::json!({
"type": def.type_id,
"shortName": def.short_name,
"longName": def.long_name,
"label": def.label,
"icon": def.icon,
"inputParamsSchema": params,
})
}