File size: 9,361 Bytes
8604d66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fa1554
8604d66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { Cpu, FileText, Gauge, Ruler, Sparkles, Waypoints } from 'lucide-react'
import type { LibraryPart, ProjectSpec } from '../types/pcb'
import { EXAMPLE_SPEC } from '../lib/spec'
import { NumberField, Section } from './ui'

interface Props {
  name: string
  spec: ProjectSpec
  library: LibraryPart[]
  disabled: boolean
  imported?: boolean
  onName: (name: string) => void
  onChange: (spec: ProjectSpec) => void
}

export function ProjectInput({ name, spec, library, disabled, imported = false, onName, onChange }: Props) {
  const set = (patch: Partial<ProjectSpec>) => onChange({ ...spec, ...patch })
  const rules = (patch: Partial<ProjectSpec['rules']>) => set({ rules: { ...spec.rules, ...patch } })
  const opt = (patch: Partial<ProjectSpec['optimization']>) => set({ optimization: { ...spec.optimization, ...patch } })
  const board = (patch: Partial<ProjectSpec['board']>) => set({ board: { ...spec.board, ...patch } })
  const selectable = library.filter((p) => p.category !== 'passive')

  return (
    <div className="text-[13px]">

      <Section title="Project" icon={<FileText size={14} />}>

        <label className="block">

          <span className="label">Project name</span>

          <input className="field" value={name} maxLength={120} disabled={disabled} onChange={(e) => onName(e.target.value)} />

        </label>

      </Section>



      {!imported && (<>

      <Section title="Requirements" icon={<Sparkles size={14} />}

        right={

          <span role="button" tabIndex={0} className="text-[11px] text-accent hover:underline"

            onClick={(e) => { e.stopPropagation(); if (!disabled) set({ description: EXAMPLE_SPEC }) }}

            onKeyDown={(e) => { if (e.key === 'Enter' && !disabled) set({ description: EXAMPLE_SPEC }) }}>

            use example

          </span>

        }>

        <label className="block">

          <span className="label">Natural-language description</span>

          <textarea className="field min-h-[112px] resize-y leading-relaxed" value={spec.description} disabled={disabled}

            placeholder="e.g. Compact 2-layer ESP32 board with a temperature sensor, USB-C power, status LED and programming header"

            onChange={(e) => set({ description: e.target.value })} />

        </label>

        <label className="mt-2.5 block">

          <span className="label">Component requirements</span>

          <textarea className="field min-h-[56px] resize-y" value={spec.component_requirements} disabled={disabled}

            placeholder="Optional list, e.g. SHT31 humidity sensor, 2 green LEDs, reset button"

            onChange={(e) => set({ component_requirements: e.target.value })} />

        </label>

        <details className="mt-2 text-[11.5px] text-ink-400">

          <summary className="cursor-pointer select-none hover:text-ink-200">Supported parts ({selectable.length})</summary>

          <ul className="mt-1.5 grid grid-cols-1 gap-0.5">

            {selectable.map((p) => (

              <li key={p.key} className="truncate" title={p.description}>

                <span className="text-ink-200">{p.name}</span> <span className="text-ink-500">· {p.package}</span>

              </li>

            ))}

          </ul>

        </details>

      </Section>



      <Section title="Board" icon={<Ruler size={14} />}>

        <div className="grid grid-cols-2 gap-2">

          <NumberField label="Width" unit="mm" value={spec.board.width_mm} allowEmpty placeholder="auto" min={8} max={500}

            step={1} disabled={disabled} onChange={(v) => board({ width_mm: v })} />

          <NumberField label="Height" unit="mm" value={spec.board.height_mm} allowEmpty placeholder="auto" min={8} max={500}

            step={1} disabled={disabled} onChange={(v) => board({ height_mm: v })} />

        </div>

        <label className="mt-2 block">

          <span className="label">Copper layers</span>

          <select className="field" value={spec.board.layers ?? ''} disabled={disabled}

            onChange={(e) => board({ layers: e.target.value ? Number(e.target.value) : null })}>

            <option value="">From description (default 2)</option>

            <option value="1">1 layer (single-sided)</option>

            <option value="2">2 layers</option>

            <option value="4">4 layers</option>

            <option value="6">6 layers</option>

          </select>

        </label>

        <p className="mt-1.5 text-[11px] text-ink-400">Board size and layer count apply when you press Generate PCB.</p>

      </Section>

      </>)}

      {!imported && (
      <Section title="Design constraints" icon={<Cpu size={14} />} defaultOpen={false}>

        <label className="block">

          <span className="label">Constraints (free text, sent to the AI parser)</span>

          <textarea className="field min-h-[52px] resize-y" value={spec.design_constraints} disabled={disabled}

            placeholder="e.g. USB-C on the left edge, keep the antenna at the board edge"

            onChange={(e) => set({ design_constraints: e.target.value })} />

        </label>

        <div className="mt-2 grid grid-cols-2 gap-2">

          <NumberField label="Component spacing" unit="mm" value={spec.rules.component_spacing} min={0} max={5}

            disabled={disabled} onChange={(v) => rules({ component_spacing: v ?? 0.5 })} />

          <NumberField label="Edge clearance" unit="mm" value={spec.rules.edge_clearance} min={0} max={5}

            disabled={disabled} onChange={(v) => rules({ edge_clearance: v ?? 0.3 })} />

        </div>

      </Section>

      )}

      <Section title="Routing constraints" icon={<Waypoints size={14} />} defaultOpen={imported}>
        <div className="grid grid-cols-2 gap-2">

          <NumberField label="Signal trace" unit="mm" value={spec.rules.trace_width} min={0.075} max={2} disabled={disabled}

            onChange={(v) => rules({ trace_width: v ?? 0.2 })} />

          <NumberField label="Power trace" unit="mm" value={spec.rules.power_trace_width} min={0.075} max={3}

            disabled={disabled} onChange={(v) => rules({ power_trace_width: v ?? 0.4 })} />

          <NumberField label="Clearance" unit="mm" value={spec.rules.clearance} min={0.075} max={2} disabled={disabled}

            onChange={(v) => rules({ clearance: v ?? 0.15 })} />

          <NumberField label="Min trace" unit="mm" value={spec.rules.min_trace_width} min={0.075} max={1}

            disabled={disabled} onChange={(v) => rules({ min_trace_width: v ?? 0.127 })} />

          <NumberField label="Via diameter" unit="mm" value={spec.rules.via_diameter} min={0.2} max={3} disabled={disabled}

            onChange={(v) => rules({ via_diameter: v ?? 0.6 })} />

          <NumberField label="Via drill" unit="mm" value={spec.rules.via_drill} min={0.1} max={2} disabled={disabled}

            onChange={(v) => rules({ via_drill: v ?? 0.3 })} />

          <NumberField label="Routing grid" unit="mm" value={spec.rules.routing_grid} min={0.1} max={1} disabled={disabled}

            onChange={(v) => rules({ routing_grid: v ?? 0.25 })} />

          <NumberField label="Via cost" value={spec.rules.via_cost} min={0} max={50} step={0.5} disabled={disabled}

            hint="Routing penalty per via, in mm of equivalent trace length"

            onChange={(v) => rules({ via_cost: v ?? 8 })} />

        </div>
        <label className="mt-2 flex items-center gap-2 text-[12.5px] text-ink-200">

          <input type="checkbox" className="accent-teal-400" checked={spec.rules.allow_vias} disabled={disabled}

            onChange={(e) => rules({ allow_vias: e.target.checked })} />

          Allow vias (layer changes)

        </label>
        <p className="mt-1.5 text-[11px] text-ink-400">Routing rules apply to the next placement, route, optimise or fix.</p>
      </Section>

      <Section title="Optimization" icon={<Gauge size={14} />} defaultOpen={false}>

        <label className="block">

          <span className="label">Effort</span>

          <select className="field" value={spec.optimization.effort} disabled={disabled}

            onChange={(e) => opt({ effort: e.target.value as ProjectSpec['optimization']['effort'] })}>

            <option value="fast">Fast</option>

            <option value="balanced">Balanced</option>

            <option value="thorough">Thorough</option>

          </select>

        </label>

        <div className="mt-2 grid grid-cols-2 gap-2">

          <NumberField label="Seed" value={spec.optimization.seed} min={0} max={1e6} step={1} disabled={disabled}

            onChange={(v) => opt({ seed: Math.round(v ?? 1) })} />

          <NumberField label="Length weight" value={spec.optimization.wirelength_weight} min={0} max={10} step={0.1}

            disabled={disabled} onChange={(v) => opt({ wirelength_weight: v ?? 1 })} />

          <NumberField label="Bend weight" value={spec.optimization.bend_weight} min={0} max={10} step={0.1}

            disabled={disabled} onChange={(v) => opt({ bend_weight: v ?? 0.5 })} />

          <NumberField label="Via weight" value={spec.optimization.via_weight} min={0} max={20} step={0.5}

            disabled={disabled} onChange={(v) => opt({ via_weight: v ?? 2 })} />

        </div>

      </Section>
    </div>
  )
}