// Phasen-Ring — Bibliothek + Vorschau
// SLC-Workshop Tabletop · Einheiten: mm
//
// 5 Segmente (Donut) als SLC-Uebersicht, die auseinandergenommen die Phasen-KOEPFE
// der linearen Puck-Bahn bilden (Design-Segment = Start vor dem ersten Puck).
// KEINE Magnete: Segmente werden lose aneinandergelegt.
//
// Gravur je Segment: ICON (oben) + Phasenname (darunter). Icons als gefuellte
// Silhouetten (lesen sich graviert besser als Linien), alle etwa gleich gross.
//
// Druckfertige Einzelteile: phasen-ring-design/-transition/-operation/-support/
// -review.scad (rufen nur phase_segment(idx) auf). Direkt geoeffnet = ganzer Ring.

// --- Phasendaten ------------------------------------------------------------
function ph_name(i) = ["DESIGN","TRANSITION","OPERATION","SUPPORT","REVIEW"][i];
function ph_col(i)  = [[0.16,0.44,0.69],[0.88,0.54,0.12],[0.23,0.62,0.29],
                       [0.12,0.62,0.62],[0.49,0.31,0.64]][i];

// --- Geometrie-Helfer -------------------------------------------------------
module ring_sector(a, r_out, r_in, seg_h) {
    a0 = 90 - a/2; a1 = 90 + a/2; big = r_out + 10;
    intersection() {
        difference() {
            cylinder(r = r_out, h = seg_h);
            translate([0,0,-0.5]) cylinder(r = r_in, h = seg_h + 1);
        }
        linear_extrude(seg_h)
            polygon([[0,0],[big*cos(a0), big*sin(a0)],
                     [big*cos(90), big*1.2],[big*cos(a1), big*sin(a1)]]);
    }
}

// ============================ ICONS (2D, gefuellt) =========================
// jeweils zentriert um (0,0), ~ +/- 8.5 mm Bauraum.

module ic_design() {            // Dokument/Plan + quer liegender Bleistift
    difference() {
        offset(0.9) offset(-0.9) translate([-4.5,-8]) square([9,16]); // abger. Hochformat
        for (yy = [4.3, 1.8, -0.7, -3.2, -5.7])                       // Linien (Stege)
            translate([-3, yy]) square([6, 1.0]);
    }
    // Bleistift diagonal, ragt unten-links + oben-rechts heraus -> klar erkennbar
    rotate(38) translate([3.5, 0]) union() {
        translate([-1, -9]) square([2, 16]);                 // Schaft
        translate([0, 7])  polygon([[-1,0],[1,0],[0,2.6]]);  // Spitze
        translate([-1,-9]) square([2, 1.6]);                 // Radierer-Ende
    }
}

module ic_rocket() {           // Rakete + Schub
    difference() {
        union() {
            hull() { translate([0,5]) circle(r=2.8,$fn=28);
                     translate([0,-2.5]) circle(r=2.8,$fn=28); }
            polygon([[-2.8,5],[2.8,5],[0,9]]);              // Nase
            polygon([[-2.8,-0.5],[-5.6,-4.5],[-2.8,-3.5]]); // Finne links
            polygon([[ 2.8,-0.5],[ 5.6,-4.5],[ 2.8,-3.5]]); // Finne rechts
            polygon([[-1.8,-2.8],[1.8,-2.8],[0,-7.5]]);     // Flamme
        }
        translate([0,3.6]) circle(r=1.3,$fn=20);            // Fenster
    }
}

module gear(R, teeth, hole) {
    difference() {
        union() {
            circle(r = R, $fn = 44);
            for (i = [0:teeth-1])
                rotate(360/teeth*i) translate([R,0])
                    square([R*0.5, R*0.55], center = true);
        }
        circle(r = hole, $fn = 28);
    }
}
module ic_gears() {            // zwei Zahnraeder
    translate([-2, 1.5])  gear(5.2, 8, 2.0);
    translate([4.5,-4])   gear(3.0, 7, 1.2);
}

module ic_headset() {         // Headset
    union() {
        difference() {                                   // Buegel (oberer Halbring)
            circle(r=7.2,$fn=44); circle(r=5.4,$fn=44);
            translate([-9,-9]) square([18,9]);
        }
        translate([-6.3,-1.5]) square([3.4,5.5], center=true); // Ohr links
        translate([ 6.3,-1.5]) square([3.4,5.5], center=true); // Ohr rechts
        hull() { translate([6.3,-4]) circle(r=0.8,$fn=16);     // Mikro-Arm
                 translate([1.8,-6.5]) circle(r=0.8,$fn=16); }
        translate([1.8,-6.5]) circle(r=1.4,$fn=20);            // Mikrofon
    }
}

module ic_review() {          // Lupe mit Haken
    union() {
        difference() { circle(r=5.6,$fn=44); circle(r=3.9,$fn=44); } // Glas-Ring
        rotate(-45) translate([4.8,-1.1]) square([5.5,2.2]);         // Griff
        // Haken im Glas
        hull(){ translate([-2,0.2]) circle(r=0.7,$fn=16);
                translate([-0.6,-1.3]) circle(r=0.7,$fn=16); }
        hull(){ translate([-0.6,-1.3]) circle(r=0.7,$fn=16);
                translate([2.2,2]) circle(r=0.7,$fn=16); }
    }
}

// per-Icon-Skalierung -> alle optisch etwa gleich gross
module icon(i) {
    if      (i==0) scale(0.92) ic_design();
    else if (i==1) scale(1.15) ic_rocket();
    else if (i==2) scale(1.12) ic_gears();
    else if (i==3) scale(1.08) ic_headset();
    else           scale(1.08) ic_review();
}

// --- ein Segment ------------------------------------------------------------
module phase_segment(idx,
                     r_out = 90, r_in = 42, seg_h = 6, seg_ang = 72, gap_deg = 1.2,
                     eng_depth = 1.0, name_size = 8, icon_size = 1.0,
                     icon_y = 75, name_y = 54) {
    $fn = 96;
    color(ph_col(idx))
    difference() {
        ring_sector(seg_ang - gap_deg, r_out, r_in, seg_h);
        translate([0,0,seg_h - eng_depth]) linear_extrude(eng_depth + 0.1) {
            translate([0, icon_y]) scale(icon_size) icon(idx);
            translate([0, name_y]) text(ph_name(idx), size=name_size,
                                        halign="center", valign="center");
        }
    }
}

// --- VORSCHAU (nur direkt geoeffnet; bei `use` ignoriert) -------------------
for (i = [0:4]) rotate([0,0, -i*72]) phase_segment(i);
