ConstructCraft

Structural Profiles Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Make structural cross-sections first-class, named, parametric project objects (Project::profiles). Build them from standard shapes or a parametric sketch, import them from built-in steel, cold-formed, timber and tube catalogs, and use them in column and beam types through geometry, IFC, the engine and a Profile Manager in the app.

Architecture: A new cc_core::structural_profile module holds ProfileDef (standard ProfileShape or ParamSketch), outline resolution and section properties. Profiles are tracked project settings, like fill patterns.

Column and beam types gain profile: Option<ProfileId>. The legacy section fields stay in files as a bounding-box cache, which EditCtx::finish → sync_profiles keeps in step, so the code that only needs a size keeps working. Geometry, IFC and properties go through one resolver, Project::type_section.

On load, convert_sections_to_profiles turns every legacy section into a deduplicated profile (format 27). Catalogs are CSV assets compiled in with include_str!. Engine commands live in cc_engine::commands::profiles, and the app’s profiles_dialog.rs calls them.

Tech Stack: Rust 2024 workspace, serde/RON, schemars, glam DVec2, earcutr (via cc_geom::polygon), egui/eframe, egui_kittest, Fluent i18n.

Spec: docs/superpowers/specs/2026-11-10-structural-profiles-design.md

Global Constraints

File Structure

File Responsibility
crates/cc_core/src/structural_profile.rs (new) ProfileId usage, ProfileMaterial, ProfileShape, ParamSketch, ProfileDef, SectionOutline, outline(), limits, repair of one profile
crates/cc_core/src/section_props.rs (new) SectionProperties and polygon integration
crates/cc_core/src/profile_catalog.rs (new) CSV parsing, Series, CatalogRow, catalog(), row_to_def
crates/cc_core/assets/profiles/*.csv (new) Built-in catalog data
crates/cc_core/src/profiles_project.rs (new) impl Project: lookup, users, type_section, convert_sections_to_profiles, repair_profiles
crates/cc_core/src/{ids,lib,project,document,persist,repair,types}.rs Wiring: id, field, settings snapshot, profiles_mut, sync_profiles, format 27, repair call, type fields
crates/cc_geom/src/section.rs TypeSection-driven column parts and loops, detail levels
crates/cc_geom/src/beam.rs, build.rs Beams swept from general section polygons
crates/cc_views/src/annotate.rs, schedule.rs Tags show the profile name; mass per length
crates/cc_engine/src/commands/profiles.rs (new) Every profile command
crates/cc_engine/tests/profiles.rs (new) Engine tests
crates/cc_ifc/src/export.rs, import.rs, tests/round_trip.rs, tests/fixtures/profiles.ccad IFC
crates/cc_app/src/profiles_dialog.rs (new), commands.rs, ribbon.rs, type_dialog.rs, sketch_mode.rs, assets/icons/ui/profiles.svg, assets/i18n/*.ftl App
docs/automation.md, docs/automacao.md, docs/commands.md, AGENTS.md, .github/workflows/ci.yml Documentation and CI

Task 1: Standard profile shapes and their outlines

Files:

Interfaces:

#[cfg(test)]
mod tests {
    use super::*;

    fn area(o: &SectionOutline) -> f64 {
        let a = |p: &[DVec2]| 0.5 * (0..p.len()).map(|i| p[i].perp_dot(p[(i + 1) % p.len()])).sum::<f64>();
        a(&o.outer) + o.holes.iter().map(|h| a(h)).sum::<f64>()
    }

    #[test]
    fn rect_and_round_areas() {
        let r = ProfileShape::Rect { b: 0.2, h: 0.4, chamfer: 0.0 }.outline().unwrap();
        assert!((area(&r) - 0.08).abs() < 1e-12);
        let c = ProfileShape::Round { d: 0.3 }.outline().unwrap();
        let exact = std::f64::consts::PI * 0.15 * 0.15;
        assert!((area(&c) - exact).abs() / exact < 0.01);
    }

    #[test]
    fn i_without_root_radius_is_exact() {
        // IPE-like: d 200, bf 100, tw 5.6, tf 8.5, r 0
        let o = ProfileShape::I { d: 0.2, bf: 0.1, tw: 0.0056, tf: 0.0085, r: 0.0 }.outline().unwrap();
        let exact = 2.0 * 0.1 * 0.0085 + (0.2 - 2.0 * 0.0085) * 0.0056;
        assert!((area(&o) - exact).abs() < 1e-12);
        let (lo, hi) = o.bbox();
        assert!((hi - lo - DVec2::new(0.1, 0.2)).length() < 1e-12);
    }

    #[test]
    fn root_radius_adds_four_fillets() {
        let (d, bf, tw, tf, r) = (0.2, 0.1, 0.0056, 0.0085, 0.012);
        let o = ProfileShape::I { d, bf, tw, tf, r }.outline().unwrap();
        let plain = 2.0 * bf * tf + (d - 2.0 * tf) * tw;
        let fillets = 4.0 * (1.0 - std::f64::consts::FRAC_PI_4) * r * r;
        assert!((area(&o) - (plain + fillets)).abs() / (plain + fillets) < 0.002);
    }

    #[test]
    fn tubes_have_holes() {
        let o = ProfileShape::RectTube { h: 0.1, b: 0.05, t: 0.004, ro: 0.0 }.outline().unwrap();
        assert_eq!(o.holes.len(), 1);
        assert!((area(&o) - (0.1 * 0.05 - 0.092 * 0.042)).abs() < 1e-12);
        let c = ProfileShape::RoundTube { d: 0.1, t: 0.005 }.outline().unwrap();
        assert_eq!(c.holes.len(), 1);
    }

    #[test]
    fn lipped_channel_area_matches_centerline_formula() {
        // Ue 90x40x12x0.95 with ri 0: area = t * (d + 2 bf + 2 lip - 4 t) for square corners
        let (d, bf, lip, t) = (0.09, 0.04, 0.012, 0.00095);
        let o = ProfileShape::ColdLippedU { d, bf, lip, t, ri: 0.0 }.outline().unwrap();
        let exact = t * (d + 2.0 * bf + 2.0 * lip - 4.0 * t);
        assert!((area(&o) - exact).abs() / exact < 1e-9);
    }

    #[test]
    fn every_default_shape_resolves() {
        for code in ProfileShape::CODES {
            let s = ProfileShape::default_for(code).unwrap();
            assert!(s.outline().is_ok(), "{code}");
            assert_eq!(s.code(), *code);
        }
    }

    #[test]
    fn bad_values_are_errors_not_panics() {
        assert!(ProfileShape::I { d: 0.2, bf: 0.1, tw: 0.2, tf: 0.0085, r: 0.0 }.outline().is_err());
        assert!(ProfileShape::Rect { b: f64::NAN, h: 0.4, chamfer: 0.0 }.outline().is_err());
        assert!(ProfileShape::RoundTube { d: 0.1, t: 0.06 }.outline().is_err());
        assert!(ProfileShape::Rect { b: 50.0, h: 0.4, chamfer: 0.0 }.outline().is_err());
    }

    #[test]
    fn set_param_round_trips() {
        let mut s = ProfileShape::default_for("i").unwrap();
        assert!(s.set_param("tw", 0.007));
        assert!(!s.set_param("nope", 1.0));
        assert_eq!(s.params().iter().find(|(n, _)| *n == "tw").unwrap().1, 0.007);
    }
}

Run: cargo test -p cc_core structural_profile Expected: compile error (module missing).

//! Structural profiles: the cross-sections of columns, beams and framing
//! members as named project objects (`Project::profiles`). A profile is a
//! standard parametric shape (rolled, welded, cold-formed, timber or
//! concrete) or a parametric sketch ([`ParamSketch`], see Task 2). Lengths
//! are meters. Outlines are laid out as in steel tables: the depth along
//! +y, the web of an I or channel vertical, the flanges of a channel and
//! the legs of an angle pointing to +x; centered on the bounding box.

use crate::{ProfileId, Uid};
use glam::DVec2;
use serde::{Deserialize, Serialize};

pub const ARC_SEGMENTS: usize = 8;
pub const MAX_POINTS: usize = 4096;
pub const MAX_OPENINGS: usize = 64;
pub const MIN_THICKNESS: f64 = 0.0003;
pub const MAX_SIZE: f64 = 10.0;
pub const MAX_NAME: usize = 100;
pub const MAX_DESCRIPTION: usize = 200;
pub const MAX_PROFILES: usize = 5000;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize, schemars::JsonSchema)]
pub enum ProfileMaterial { #[default] Steel, ColdFormed, Timber, Concrete }

impl ProfileMaterial {
    pub const ALL: [ProfileMaterial; 4] = [Self::Steel, Self::ColdFormed, Self::Timber, Self::Concrete];
    pub fn code(self) -> &'static str { match self { Self::Steel => "steel", Self::ColdFormed => "cold_formed", Self::Timber => "timber", Self::Concrete => "concrete" } }
    pub fn from_code(c: &str) -> Option<Self> { Self::ALL.into_iter().find(|m| m.code().eq_ignore_ascii_case(c.trim())) }
    pub fn key(self) -> &'static str { match self { Self::Steel => "profile-material-steel", Self::ColdFormed => "profile-material-cold-formed", Self::Timber => "profile-material-timber", Self::Concrete => "profile-material-concrete" } }
    /// The `MaterialClass` a type made for this profile gets its material from.
    pub fn material_class(self) -> crate::MaterialClass { match self { Self::Steel | Self::ColdFormed => crate::MaterialClass::Metal, Self::Timber => crate::MaterialClass::Wood, Self::Concrete => crate::MaterialClass::Concrete } }
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ProfileShape {
    I { d: f64, bf: f64, tw: f64, tf: f64, r: f64 },
    IAsym { d: f64, bf_top: f64, tf_top: f64, bf_bot: f64, tf_bot: f64, tw: f64 },
    Channel { d: f64, bf: f64, tw: f64, tf: f64, r: f64 },
    T { d: f64, bf: f64, tw: f64, tf: f64, r: f64 },
    Angle { h: f64, b: f64, t: f64, r: f64 },
    ColdU { d: f64, bf: f64, t: f64, ri: f64 },
    ColdLippedU { d: f64, bf: f64, lip: f64, t: f64, ri: f64 },
    ColdZ { d: f64, bf: f64, lip: f64, t: f64, ri: f64, angle: f64 },
    ColdHat { d: f64, bf: f64, lip: f64, t: f64, ri: f64 },
    RectTube { h: f64, b: f64, t: f64, ro: f64 },
    RoundTube { d: f64, t: f64 },
    Rect { b: f64, h: f64, chamfer: f64 },
    Round { d: f64 },
    ConcreteT { h: f64, bf: f64, hf: f64, bw: f64 },
    ConcreteL { h: f64, bf: f64, hf: f64, bw: f64 },
    Sketch(ParamSketch),
}

/// Filled in by Task 2. In Task 1 it is an empty struct, and outline()
/// returns Err(ProfileError::Sketch("empty sketch".into())) for it.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct ParamSketch {}

#[derive(Debug, Clone, PartialEq, Default)]
pub struct SectionOutline { pub outer: Vec<DVec2>, pub holes: Vec<Vec<DVec2>> }

#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum ProfileError {
    #[error("{0} must be a number between {MIN_THICKNESS} and {MAX_SIZE} m")]
    Value(&'static str),
    #[error("{0}")]
    DoesNotFit(String),
    #[error("sketch: {0}")]
    Sketch(String),
    #[error("the outline has more than {MAX_POINTS} points")]
    TooBig,
}

Implementation rules:

  1. Checks before building. Every field must be finite, at most MAX_SIZE, and at least MIN_THICKNESS. The exceptions are radii, chamfer and angle, which may be 0, and ColdZ::angle, which must lie in 0..=90°. Then check fit: 2*tf < d, tw < bf, t < d/2, 2*t < min(h,b), 2*t < d, r <= (bf - tw)/2, lip > t. If a check fails, return DoesNotFit with a sentence naming the parameters.
  2. Fillets. Add a helper fn fillet(corner: DVec2, a: DVec2, b: DVec2, r: f64) -> Vec<DVec2>. It returns ARC_SEGMENTS + 1 points of the arc tangent to the two edges that leave corner along unit directions a and b. With r = 0 it returns vec![corner]. Re-entrant corners (root radius r, cold-formed inner ri) add material. Cold-formed outer corners use ri + t and the matching inner corners use ri.
  3. I and IAsym. Build the 12 vertices as in cc_geom::section::shape_loops (SectionShape::I), with web-to-flange fillets on the 4 inner corners. For IAsym, put the centroid-independent bounding box center at the origin.
  4. Cold-formed shapes are a polyline offset. For U, Ue, Z and Hat, build the centerline polyline with corners at the right distances. Then offset it ±t/2, using the bend radius at each corner as the arc center radius ri + t/2. This gives exactly t·(centerline length) when ri = 0 at square corners. The test above checks Ue.
  5. Circles use 4 * ARC_SEGMENTS points.
  6. Winding and bounds. outer is CCW and holes are CW; normalize with the signed area. Return TooBig past MAX_POINTS.
  7. Defaults. CODES: &[&str] = &["i","i_asym","channel","t","angle","cold_u","cold_lipped_u","cold_z","cold_hat","rect_tube","round_tube","rect","round","concrete_t","concrete_l","sketch"]. default_for gives sensible values (I = IPE 200, Ue = 90x40x12x0.95, Rect = 0.15x0.30, Sketch = a 0.1 m square with params b/h, see Task 2).
  8. Parameters. params()/set_param() list each variant’s fields by their spec names, in declaration order. Sketch returns its ParamSketch::params values.
  9. ProfileDef. Fields id: ProfileId, uid: Uid, name: String, material: ProfileMaterial, shape: ProfileShape, catalog: Option<CatalogRef>, description: String; derive Debug, Clone, PartialEq, Serialize, Deserialize. The fields #[serde(default)] uid: Uid, catalog: Option<CatalogRef> and description: String have serde defaults. outline() forwards to shape.outline().

Run: cargo test -p cc_core structural_profile Expected: all 8 pass.

cargo fmt --all && cargo clippy -p cc_core --all-targets -- -D warnings
git add crates/cc_core && git commit -s -m "Add parametric structural profile shapes"

Task 2: Parametric sketch profiles

Files:

Interfaces:

#[test]
fn sketch_reads_its_parameters() {
    let mut s = ParamSketch::square(0.1, 0.2);
    let o = ProfileShape::Sketch(s.clone()).outline().unwrap();
    let (lo, hi) = o.bbox();
    assert!((hi - lo - DVec2::new(0.1, 0.2)).length() < 1e-12);
    s.params.iter_mut().find(|p| p.name == "b").unwrap().value = 0.3;
    let (lo, hi) = ProfileShape::Sketch(s).outline().unwrap().bbox();
    assert!((hi.x - lo.x - 0.3).abs() < 1e-12);
}

#[test]
fn sketch_with_opening_is_a_hollow_section() {
    let mut s = ParamSketch::square(0.2, 0.2);
    s.params.push(crate::component::ComponentParam::number("t", 0.01, crate::component::ParamKind::Length));
    s.openings.push(vec![
        ProfilePoint::new("-b/2+t", "-h/2+t"), ProfilePoint::new("b/2-t", "-h/2+t"),
        ProfilePoint::new("b/2-t", "h/2-t"), ProfilePoint::new("-b/2+t", "h/2-t"),
    ]);
    let o = ProfileShape::Sketch(s).outline().unwrap();
    assert_eq!(o.holes.len(), 1);
}

#[test]
fn bad_sketch_is_an_error() {
    let mut s = ParamSketch::square(0.1, 0.1);
    s.outline[0].u = "nope + 1".into();
    assert!(matches!(ProfileShape::Sketch(s).outline(), Err(ProfileError::Sketch(_))));
    let mut s = ParamSketch::square(0.1, 0.1);
    s.outline.truncate(2);
    assert!(ProfileShape::Sketch(s).outline().is_err());
}

Task 3: Section properties

Files:

Interfaces:

#[cfg(test)]
mod tests {
    use crate::structural_profile::ProfileShape;

    #[test]
    fn rectangle_closed_forms() {
        let p = ProfileShape::Rect { b: 0.2, h: 0.4, chamfer: 0.0 }.outline().unwrap().properties(7850.0);
        assert!((p.area - 0.08).abs() < 1e-12);
        assert!((p.ix - 0.2 * 0.4f64.powi(3) / 12.0).abs() < 1e-12);
        assert!((p.iy - 0.4 * 0.2f64.powi(3) / 12.0).abs() < 1e-12);
        assert!((p.wx - 0.2 * 0.4 * 0.4 / 6.0).abs() < 1e-12);
        assert!((p.linear_mass - 0.08 * 7850.0).abs() < 1e-9);
        assert!(p.centroid[0].abs() < 1e-12 && p.centroid[1].abs() < 1e-12);
        assert!((p.perimeter - 1.2).abs() < 1e-12);
    }

    #[test]
    fn circle_and_tube() {
        let p = ProfileShape::Round { d: 0.3 }.outline().unwrap().properties(0.0);
        let exact = std::f64::consts::PI * 0.15f64.powi(4) / 4.0;
        assert!((p.ix - exact).abs() / exact < 0.02);
        let t = ProfileShape::RectTube { h: 0.1, b: 0.1, t: 0.005, ro: 0.0 }.outline().unwrap().properties(0.0);
        let exact = (0.1f64.powi(4) - 0.09f64.powi(4)) / 12.0;
        assert!((t.ix - exact).abs() / exact < 1e-9);
    }

    #[test]
    fn i_section_against_hand_calculation() {
        let (d, bf, tw, tf) = (0.2, 0.1, 0.0056, 0.0085);
        let p = ProfileShape::I { d, bf, tw, tf, r: 0.0 }.outline().unwrap().properties(0.0);
        let hw = d - 2.0 * tf;
        let ix = bf * d.powi(3) / 12.0 - (bf - tw) * hw.powi(3) / 12.0;
        assert!((p.ix - ix).abs() / ix < 1e-9);
    }

    #[test]
    fn angle_centroid_is_off_center() {
        let p = ProfileShape::Angle { h: 0.1, b: 0.1, t: 0.01, r: 0.0 }.outline().unwrap().properties(0.0);
        assert!(p.centroid[0] < 0.0 && p.centroid[1] < 0.0);
        assert!(p.ixy.abs() > 0.0);
    }
}

Task 4: Profiles in the project (settings, undo, repair)

Files:

Interfaces:

#[cfg(test)]
mod tests {
    use crate::structural_profile::*;
    use crate::{Document, Project, ProfileId};

    fn def(id: u64, name: &str) -> ProfileDef {
        ProfileDef { id: ProfileId(id), uid: crate::Uid::generate(), name: name.into(), material: ProfileMaterial::Steel,
            shape: ProfileShape::default_for("i").unwrap(), catalog: None, description: String::new() }
    }

    #[test]
    fn profiles_are_undone_as_settings() {
        let mut doc = Document::new(Project::from_template());
        doc.edit("add", |ctx| { let id = ProfileId(ctx.alloc_id()); ctx.profiles_mut().insert(id, def(id.0, "IPE 200")); });
        assert!(doc.project.profile_named("ipe 200").is_some());
        doc.undo();
        assert!(doc.project.profile_named("IPE 200").is_none());
    }

    #[test]
    fn repair_fixes_ids_names_and_bad_shapes() {
        let mut p = Project::from_template();
        let base = p.max_id() + 1;
        p.profiles.insert(ProfileId(base), def(999, "A"));
        p.profiles.insert(ProfileId(base + 1), def(base + 1, "a"));
        let mut bad = def(base + 2, "Bad");
        bad.shape = ProfileShape::Rect { b: f64::NAN, h: 1.0, chamfer: 0.0 };
        p.profiles.insert(ProfileId(base + 2), bad);
        assert!(p.repair_profiles() >= 3);
        assert_eq!(p.profiles.len(), 2);
        assert_eq!(p.profiles[&ProfileId(base)].id, ProfileId(base));
        assert_ne!(p.profiles[&ProfileId(base)].name.to_lowercase(), p.profiles[&ProfileId(base + 1)].name.to_lowercase());
        assert_eq!(p.repair_profiles(), 0);
    }

    #[test]
    fn free_names_count_up() {
        let mut p = Project::empty();
        p.profiles.insert(ProfileId(1), def(1, "W 150 x 13"));
        assert_eq!(p.free_profile_name("W 150 x 13"), "W 150 x 13 2");
        assert_eq!(p.free_profile_name("HEB 200"), "HEB 200");
    }
}

(Check the real names of Document::new/edit/undo in document.rs and adapt the calls; the behaviour asserted stays.)


Task 5: Types use profiles; legacy sections become profiles (format 27)

Files:

#[test]
fn template_types_point_to_profiles() {
    let p = Project::from_template();
    for t in p.types.values() {
        if let crate::TypeData::Column { profile, .. } | crate::TypeData::Beam { profile, .. } = &t.data {
            let id = profile.expect("template column/beam types get a profile");
            assert!(p.profile(id).is_some());
            assert!(p.type_section(&t.data).is_some());
        }
    }
    let n = p.profiles.len();
    let mut q = p.clone();
    assert_eq!(q.convert_sections_to_profiles(&|k| k.to_string()), 0, "idempotent");
    assert_eq!(q.profiles.len(), n);
}

#[test]
fn identical_sections_share_one_profile() {
    let mut p = Project::from_template();
    let column = p.types.values().find(|t| matches!(t.data, crate::TypeData::Column { .. })).unwrap().clone();
    let mut copy = column.clone();
    if let crate::TypeData::Column { profile, .. } = &mut copy.data { *profile = None; }
    copy.name = "Copy".into();
    let id = p.add_type(copy); // use the real add/insert helper
    let before = p.profiles.len();
    p.convert_sections_to_profiles(&|k| k.to_string());
    assert_eq!(p.profiles.len(), before);
    let same = |t: &crate::ElementType| match &t.data { crate::TypeData::Column { profile, .. } => *profile, _ => None };
    assert_eq!(same(&p.types[&id]), same(&column));
}

#[test]
fn editing_a_profile_resizes_its_types_in_one_undo_step() {
    let mut doc = Document::new(Project::from_template());
    let (tid, pid) = doc.project.types.values().find_map(|t| match &t.data {
        crate::TypeData::Beam { profile: Some(p), .. } => Some((t.id, *p)), _ => None }).unwrap();
    doc.edit("grow", |ctx| {
        let p = ctx.profiles_mut().get_mut(&pid).unwrap();
        p.shape = ProfileShape::Rect { b: 0.25, h: 0.6, chamfer: 0.0 };
    });
    let crate::TypeData::Beam { width, height, .. } = doc.project.types[&tid].data else { panic!() };
    assert!((width - 0.25).abs() < 1e-9 && (height - 0.6).abs() < 1e-9);
    doc.undo();
    let crate::TypeData::Beam { height, .. } = doc.project.types[&tid].data else { panic!() };
    assert!((height - 0.6).abs() > 1e-6);
}

In crates/cc_core/src/persist.rs tests:

#[test]
fn format_26_sections_load_as_profiles() {
    let mut p = Project::from_template();
    for t in p.types.values_mut() {
        if let crate::TypeData::Column { profile, .. } | crate::TypeData::Beam { profile, .. } = &mut t.data { *profile = None; }
    }
    p.profiles.clear();
    let text = to_ron(&p).unwrap().replacen("format_version: 27", "format_version: 26", 1);
    let back = from_ron(&text).unwrap();
    assert!(!back.profiles.is_empty());
    assert!(back.types.values().all(|t| !matches!(t.data, crate::TypeData::Column { profile: None, .. } | crate::TypeData::Beam { profile: None, .. })));
}

#[test]
fn dangling_profile_reference_is_repaired() {
    let mut p = Project::from_template();
    p.profiles.clear();
    let text = to_ron(&p).unwrap();
    let (back, repairs) = from_ron_with_repairs(&text).unwrap();
    assert!(repairs > 0);
    assert!(back.types.values().all(|t| back.type_section(&t.data).is_some() || !matches!(t.data, crate::TypeData::Column { .. } | crate::TypeData::Beam { .. })));
}

Task 6: Built-in catalogs

Files:

Interfaces:

CSV format (header row first; dimensions in millimeters; area_cm2 from the source table):

designation,d,bf,tw,tf,r,area_cm2
200,200,100,5.6,8.5,12,28.5
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn every_series_parses_and_has_rows() {
        let codes: Vec<&str> = catalog().iter().map(|s| s.code).collect();
        for c in ["W","HP","IPE","HEA","HEB","NBR6355-U","NBR6355-Ue","NBR6355-Z","NBR6355-Ze","NBR6355-L","NBR6355-Cartola","Timber-Sawn","Glulam","SHS","RHS","CHS"] {
            assert!(codes.contains(&c), "{c}");
            assert!(!series(c).unwrap().rows.is_empty(), "{c}");
        }
    }

    #[test]
    fn computed_areas_match_the_tables() {
        for s in catalog() {
            for row in &s.rows {
                let def = row_to_def(s, row).unwrap_or_else(|| panic!("{} {}", s.code, row.designation));
                let a = def.outline().unwrap().properties(0.0).area;
                let err = (a - row.area).abs() / row.area;
                assert!(err < 0.02, "{} {}: computed {a} table {}", s.code, row.designation, row.area);
            }
        }
    }

    #[test]
    fn reference_rows() {
        let ipe = series("IPE").unwrap();
        let r = ipe.rows.iter().find(|r| r.designation == "200").unwrap();
        let def = row_to_def(ipe, r).unwrap();
        assert_eq!(def.name, "IPE 200");
        assert_eq!(def.shape, ProfileShape::I { d: 0.2, bf: 0.1, tw: 0.0056, tf: 0.0085, r: 0.012 });
    }

    #[test]
    fn malformed_csv_rows_are_skipped() {
        let rows = parse_rows("designation,d,bf\nok,100,50\nbad,x,50\n,1\n", &["d", "bf"]);
        assert_eq!(rows.len(), 1);
    }
}

Task 7: Columns drawn from their profile

Files:

Interfaces:

#[test]
fn a_column_with_an_ipe_profile_has_its_area_times_height() {
    let mut s = Session::default();
    // Until Task 10 exists, build the type through the core API in the test:
    let (pid, tid) = s.edit_for_test(|ctx| { /* insert IPE 200 profile; duplicate the steel column type with profile: Some(pid) */ });
    let col = run(&mut s, "column_create", json!({"type": tid, "position": [0.0, 0.0]}))["id"].as_u64().unwrap();
    let props = run(&mut s, "element_get", json!({"element": col}));
    let height = props["derived"]["height"].as_f64().unwrap();
    let volume = props["derived"]["volume"].as_f64().unwrap();
    let area = 2.0 * 0.1 * 0.0085 + (0.2 - 0.017) * 0.0056 + 4.0 * (1.0 - std::f64::consts::FRAC_PI_4) * 0.012f64.powi(2);
    assert!((volume - area * height).abs() / (area * height) < 0.003, "{volume}");
}

If Session has no test edit helper, write this test at the cc_geom level instead: build a Project::from_template(), insert the profile and type, add a column element, run ModelGeometry::build, and sum the volume of the column’s solid with the existing volume helper. Check cc_geom/src/build.rs tests for how other tests do it. Once Task 10 exists, move the test to the engine using profile_import + profile_type_create.

Add a plan test: generate a floor plan cutting the column at DetailLevel::Coarse and Fine, and assert that the cut outline has 4 vertices at Coarse and more than 12 at Fine.


Task 8: Beams swept from general sections

Files:

Interfaces:

New add_to:

#[test]
fn general_section_volume_is_area_times_length() {
    let i = cc_core::ProfileShape::I { d: 0.3, bf: 0.15, tw: 0.0071, tf: 0.0107, r: 0.0 }.outline().unwrap();
    let area = i.properties(0.0).area;
    let g = beam_with_section(i, DVec2::ZERO, DVec2::new(5.0, 0.0)); // helper: square ends, level
    assert!((g.volume() - area * 5.0).abs() < 1e-9);
    let mut s = crate::Solid::default();
    g.add_to(&mut s);
    assert!((s.volume() - area * 5.0).abs() / (area * 5.0) < 1e-6);
}

#[test]
fn round_tube_beam_is_watertight() {
    let t = cc_core::ProfileShape::RoundTube { d: 0.1, t: 0.005 }.outline().unwrap();
    let g = beam_with_section(t, DVec2::ZERO, DVec2::new(3.0, 4.0));
    let mut s = crate::Solid::default();
    g.add_to(&mut s);
    assert!(s.is_closed(), "every edge shared by two faces"); // use the existing closure check in solid.rs tests, or add one
}

Plus an engine test in profiles.rs: two beams meeting in an L with W profiles. Assert both volumes are positive and that their sum is below 2 × area × length (the mitre removed material).


Task 9: Tags and schedules know the profile

Files:


Task 10: Engine commands — list, get, create, set, duplicate, delete

Files:

Interfaces:

Every edit goes through super::edit(session, "<undo name>", |ctx| ...), the same helper fill_patterns.rs uses. Names are checked: not empty, at most MAX_NAME, unique ignoring case.

#[test]
fn create_get_set_delete() {
    let mut s = Session::default();
    let out = run(&mut s, "profile_create", json!({"material": "steel", "shape": "i",
        "name": "PS 300", "params": {"d": 0.3, "bf": 0.15, "tw": 0.008, "tf": 0.0125, "r": 0.0}}));
    let id = out["id"].as_u64().unwrap();
    let got = run(&mut s, "profile_get", json!({"profile": "ps 300"}));
    assert_eq!(got["id"].as_u64(), Some(id));
    let area = got["properties"]["area"].as_f64().unwrap();
    assert!((area - (2.0 * 0.15 * 0.0125 + 0.275 * 0.008)).abs() < 1e-9);

    let err = run_err(&mut s, "profile_set", json!({"profile": id, "params": {"tw": 0.5}}));
    assert_eq!(err.code, "invalid");
    run(&mut s, "profile_set", json!({"profile": id, "params": {"tw": 0.01}}));
    assert_eq!(run(&mut s, "profile_get", json!({"profile": id}))["params"]["tw"], 0.01);

    run(&mut s, "undo", json!({}));
    assert_eq!(run(&mut s, "profile_get", json!({"profile": id}))["params"]["tw"], 0.008);
    run(&mut s, "profile_delete", json!({"profile": id}));
    assert!(run(&mut s, "profiles_list", json!({})).as_array().unwrap().iter().all(|p| p["id"].as_u64() != Some(id)));
}

#[test]
fn sketch_profile_from_curves() {
    let mut s = Session::default();
    let out = run(&mut s, "profile_create", json!({"material": "steel", "name": "Box",
        "curves": [{"rectangle": [[-0.1, -0.15], [0.1, 0.15]]}],
        "openings": [[{"rectangle": [[-0.09, -0.14], [0.09, 0.14]]}]]}));
    let got = run(&mut s, "profile_get", json!({"profile": out["id"]}));
    assert_eq!(got["shape"], "sketch");
    assert_eq!(got["outline"]["holes"].as_array().unwrap().len(), 1);
}

#[test]
fn deleting_a_used_profile_needs_a_replacement() {
    let mut s = Session::default();
    let used = run(&mut s, "profiles_list", json!({})).as_array().unwrap().iter()
        .find(|p| p["users"].as_u64().unwrap() > 0).unwrap().clone();
    let other = run(&mut s, "profile_create", json!({"material": "concrete", "shape": "rect", "name": "R"}))["id"].clone();
    let err = run_err(&mut s, "profile_delete", json!({"profile": used["id"]}));
    assert!(err.message.contains("replace_with"), "{}", err.message);
    run(&mut s, "profile_delete", json!({"profile": used["id"], "replace_with": other}));
    let r = run(&mut s, "profile_get", json!({"profile": "R"}));
    assert!(r["used_by"].as_array().unwrap().len() >= 1);
}

(run_err is the error variant of run; copy it from another test file, e.g. grep -rn "fn run_err" crates/cc_engine/tests. Use whatever undo command name the catalog has: cargo run -p cc_cli -- commands | grep -i undo.)


Task 11: Catalog import, profile types, type_set, element_get, analytical export

Files:

Interfaces:

#[test]
fn import_from_catalog_and_make_types() {
    let mut s = Session::default();
    let series = run(&mut s, "profile_catalog", json!({}));
    assert!(series.as_array().unwrap().iter().any(|x| x["code"] == "IPE"));
    let rows = run(&mut s, "profile_catalog", json!({"series": "IPE", "search": "20"}));
    assert!(rows["rows"].as_array().unwrap().iter().any(|r| r["designation"] == "200"));

    let out = run(&mut s, "profile_import", json!({"series": "IPE", "designations": ["200", "270", "999"]}));
    assert_eq!(out["imported"].as_array().unwrap().len(), 2);
    assert_eq!(out["unknown"][0], "999");
    let again = run(&mut s, "profile_import", json!({"series": "IPE", "designations": ["200"]}));
    assert_eq!(again["kept"][0], "IPE 200");

    let t = run(&mut s, "profile_type_create", json!({"profile": "IPE 200", "category": "beam"}));
    let ty = run(&mut s, "type_get", json!({"type": t["id"]}));
    assert_eq!(ty["params"]["profile"], "IPE 200");
    assert!((ty["params"]["height"].as_f64().unwrap() - 0.2).abs() < 1e-9, "bbox cached");

    let beam = run(&mut s, "beam_create", json!({"type": t["id"], "start": [0.0, 0.0], "end": [6.0, 0.0]}))["id"].clone();
    let e = run(&mut s, "element_get", json!({"element": beam}));
    assert!((e["derived"]["section"]["area"].as_f64().unwrap() - 0.00285).abs() / 0.00285 < 0.02);

    run(&mut s, "profile_import", json!({"series": "HEB", "designations": ["200"]}));
    run(&mut s, "type_set", json!({"type": t["id"], "params": {"profile": "HEB 200"}}));
    let ty = run(&mut s, "type_get", json!({"type": t["id"]}));
    assert!((ty["params"]["width"].as_f64().unwrap() - 0.2).abs() < 1e-9);

    let a = run(&mut s, "analytical_export", json!({}));
    let text = a.to_string();
    assert!(text.contains("HEB 200"), "members carry their section");
}

(Check analytical_export’s real parameters and output shape; if it writes to a path, use its in-memory form or a temporary file in the test, as other tests do.)


Task 12: IFC export and import of profiles

Files:


Task 13: Profile Manager dialog

Files:

Behaviour:

Tests:

#[test]
fn profile_manager_imports_and_cancels() {
    let mut harness = app_harness(); // existing helper
    harness.get_by_label("Profiles").click(); // pt-BR? use the label the harness language uses; see other tests
    harness.run();
    harness.get_by_label("Import from catalog").click();
    harness.run();
    // choose series IPE, tick "200", click Add
    // ...use the existing helpers for combo boxes and checkboxes in ui_tests.rs
    harness.get_by_label("OK").click();
    harness.run();
    assert!(harness.state().session.project().profile_named("IPE 200").is_some());
    // reopen, delete it with a replacement, Cancel: still there
}

Fill the elided steps with the exact helper calls the file already uses for combo boxes and checkboxes. If the harness cannot drive a combo box, set the dialog state’s series field directly through harness.state_mut(), as other tests do.


Task 14: Profile picker in Type Properties and sketch editing

Files:


Task 15: Documentation and final checks

Files:

cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
cargo run -p cc_cli -- reference > docs/commands.md && git diff --exit-code docs/commands.md
cargo run -p cc_core --example casa_simples && git diff --stat examples/

Expected: everything is clean. If casa_simples.ccad changed (format 27 and template profiles), commit it.