// SAME Analog Modular Ecosystem
//
// / SPDX-FileCopyrightText: 2026 Denis Chevalier <perso@denischevalier.fr>
// / SPDX-License-Identifier: CC-BY-SA-4.0
// / SPDX-License-Identifier: CERN-OHL-S-2.0+
// / SPDX-License-Identifier: GPL-3.0-or-later
//
// The prose, explanatory text, rendered figures, tables, and mathematical
// content of this specification are licensed under CC BY-SA 4.0. If a later
// version of CC BY-SA is published, the author grants permission to distribute
// this work under that later version as well.
//
// Hardware designs contained herein (schematics, PCB layouts, mechanical
// drawings, and CAD models) are licensed under CERN-OHL-S-2.0+.
//
// All executable code, helper libraries (`lib/*`), metrology assertions, and
// embedded verification scripts throughout the source documents are licensed
// under the GNU General Public License v3.0 or later (GPL-3.0-or-later).

#import "../lib/unify.typ": qty
#import "@preview/cetz:0.5.2"

#figure(
  cetz.canvas({
    import cetz.draw: *

    // Scale factor: 1 mm = 0.06 drawing units
    let s = 0.06

    let h-panel = 177.8 * s // 6.223
    let h-body = 165.1 * s // 5.7785
    let h-lip = 6.35 * s // 0.22225
    let w-panel = 38.0 * s // 1.33
    let d-body = 152.4 * s // 5.334
    let t-panel = 3.0 * s // 0.105 (exaggerated slightly for visual clarity)

    let y-center = 0
    let y-top-panel = h-panel / 2
    let y-bot-panel = -h-panel / 2
    let y-top-body = h-body / 2
    let y-bot-body = -h-body / 2

    // --- FRONT ELEVATION ---
    let x-front-left = 0
    let x-front-right = w-panel
    let x-front-mid = w-panel / 2

    // View Title
    content((x-front-mid, y-top-panel + 0.8), text(
      size: 9pt,
      weight: "bold",
    )[FRONT ELEVATION])

    // Front Panel Outline
    rect(
      (x-front-left, y-bot-panel),
      (x-front-right, y-top-panel),
      fill: luma(250),
      stroke: 1.2pt + black,
    )

    // Hidden Body Transition Lines (Dashed)
    line(
      (x-front-left, y-top-body),
      (x-front-right, y-top-body),
      stroke: (paint: luma(130), thickness: 0.7pt, dash: "dashed"),
    )
    line(
      (x-front-left, y-bot-body),
      (x-front-right, y-bot-body),
      stroke: (paint: luma(130), thickness: 0.7pt, dash: "dashed"),
    )

    // Panel Mounting Screw Holes (Top and Bottom Lips)
    circle(
      (x-front-mid, y-top-panel - h-lip / 2),
      radius: 0.08,
      fill: white,
      stroke: 0.8pt + black,
    )
    circle(
      (x-front-mid, y-bot-panel + h-lip / 2),
      radius: 0.08,
      fill: white,
      stroke: 0.8pt + black,
    )

    // Dimension: Panel Width (38.0 mm)
    line(
      (x-front-left, y-bot-panel),
      (x-front-left, y-bot-panel - 0.6),
      stroke: 0.5pt + luma(120),
    )
    line(
      (x-front-right, y-bot-panel),
      (x-front-right, y-bot-panel - 0.6),
      stroke: 0.5pt + luma(120),
    )
    line(
      (x-front-left, y-bot-panel - 0.6),
      (x-front-right, y-bot-panel - 0.6),
      mark: (start: "stealth", end: "stealth"),
      mark-size: 0.12,
      stroke: 0.7pt + black,
    )
    content((x-front-mid, y-bot-panel - 0.9), text(
      size: 7.5pt,
    )[$qty(38.0, "mm")$])

    // Dimension: Panel Height (177.8 mm / 4U)
    line(
      (x-front-left, y-top-panel),
      (x-front-left - 0.6, y-top-panel),
      stroke: 0.5pt + luma(120),
    )
    line(
      (x-front-left, y-bot-panel),
      (x-front-left - 0.6, y-bot-panel),
      stroke: 0.5pt + luma(120),
    )
    line(
      (x-front-left - 0.6, y-bot-panel),
      (x-front-left - 0.6, y-top-panel),
      mark: (start: "stealth", end: "stealth"),
      mark-size: 0.12,
      stroke: 0.7pt + black,
    )
    content(
      (x-front-left - 0.95, y-center),
      text(size: 7.5pt)[$qty(177.8, "mm")$ ($qty(4, "U")$)],
      angle: 90deg,
    )

    // --- SIDE ELEVATION ---
    let x-side-start = 2.8
    let x-panel-back = x-side-start + t-panel
    let x-body-rear = x-panel-back + d-body
    let x-side-mid = (x-side-start + x-body-rear) / 2

    // View Title
    content((x-side-mid, y-top-panel + 0.8), text(
      size: 9pt,
      weight: "bold",
    )[SIDE ELEVATION])

    // Cassette Steel Body
    rect(
      (x-panel-back, y-bot-body),
      (x-body-rear, y-top-body),
      fill: luma(235),
      stroke: 1.2pt + black,
    )

    // Front Panel Plate Attached to Body
    rect(
      (x-side-start, y-bot-panel),
      (x-panel-back, y-top-panel),
      fill: luma(210),
      stroke: 1.2pt + black,
    )

    // Rear DB-25 Connector Standoff / Bezel Projection
    rect(
      (x-body-rear, y-center - 0.6),
      (x-body-rear + 0.25, y-center + 0.6),
      fill: luma(240),
      stroke: 0.8pt + black,
    )

    // Dimension: Depth (152.4 mm)
    line(
      (x-panel-back, y-top-panel),
      (x-panel-back, y-top-panel + 0.2),
      stroke: 0.5pt + luma(120),
    )
    line(
      (x-body-rear, y-top-panel - 0.4),
      (x-body-rear, y-top-panel + 0.2),
      stroke: 0.5pt + luma(120),
    )
    line(
      (x-panel-back, y-top-panel + 0.2),
      (x-body-rear, y-top-panel + 0.2),
      mark: (start: "stealth", end: "stealth"),
      mark-size: 0.12,
      stroke: 0.7pt + black,
    )
    content(((x-panel-back + x-body-rear) / 2, y-top-panel + 0.4), text(
      size: 7.5pt,
    )[$qty(152.4, "mm")$])

    // Dimension: Body Height (165.1 mm)
    line(
      (x-body-rear, y-top-body),
      (x-body-rear + 0.6, y-top-body),
      stroke: 0.5pt + luma(120),
    )
    line(
      (x-body-rear, y-bot-body),
      (x-body-rear + 0.6, y-bot-body),
      stroke: 0.5pt + luma(120),
    )
    line(
      (x-body-rear + 0.6, y-bot-body),
      (x-body-rear + 0.6, y-top-body),
      mark: (start: "stealth", end: "stealth"),
      mark-size: 0.12,
      stroke: 0.7pt + black,
    )
    content(
      (x-body-rear + 0.9, y-center),
      text(size: 7.5pt)[$qty(165.1, "mm")$],
      angle: -90deg,
    )

    // Dimension: Top Lip Height (6.35 mm)
    line(
      (x-panel-back, y-top-panel),
      (x-body-rear + 1.8, y-top-panel),
      stroke: 0.4pt + luma(160),
    )
    line(
      (x-panel-back, y-top-body),
      (x-body-rear + 1.8, y-top-body),
      stroke: 0.4pt + luma(160),
    )
    line(
      (x-body-rear + 1.65, y-top-body),
      (x-body-rear + 1.65, y-top-panel),
      mark: (start: "stealth", end: "stealth"),
      mark-size: 0.10,
      stroke: 0.7pt + black,
    )
    content(
      (x-body-rear + 2.2, (y-top-panel + y-top-body) / 2),
      text(size: 7.0pt)[$qty(6.35, "mm")$],
    )
  }),
  caption: [Cassette enclosure orthographic projections (front and side elevation) detailing external physical dimensions and lip offsets],
) <figure-cassette-external-dimensions-diagram>
