nc_program_manager/.paul/phases/05-nc-validator/PLAN.md

69 lines
2.3 KiB
Markdown

# Phase 05 — NC Program Validator
**Status:** PLAN
## Goal
Per-manufacturer NC program validator runs inside `WriteProgramAsync` before upload.
Catches format errors before bytes hit the controller.
## Acceptance Criteria
- `NcProgramValidator` validates content for all 4 manufacturers
- All universal rules checked: block length ≤ 80, no lowercase, no tabs, no nested parens, comment ≤ 32 chars
- Per-manufacturer name format and forbidden chars checked
- Fanuc `#` char is Warning not Error
- All 4 machine classes call validator in `WriteProgramAsync` before upload
- Unit tests cover all rules + all manufacturers
- Old-style csproj Compile entries added for all new files
## File List
| # | File | Action |
|---|------|--------|
| 1 | `Cnc/Models/ValidationSeverity.cs` | Create |
| 2 | `Cnc/Models/ValidationError.cs` | Create |
| 3 | `Cnc/Models/ValidationResult.cs` | Create |
| 4 | `Cnc/INcProgramValidator.cs` | Create |
| 5 | `Cnc/NcProgramValidator.cs` | Create |
| 6 | `Cnc/Fanuc/FanucMachine.cs` | Edit — inject validator |
| 7 | `Cnc/Heidenhain/HeidenhainMachine.cs` | Edit — inject validator |
| 8 | `Cnc/Siemens/SiemensMachine.cs` | Edit — inject validator |
| 9 | `Cnc/Mitsubishi/MitsubishiMachine.cs` | Edit — inject validator |
| 10 | `FanucProgramManager.Tests/Unit/NcProgramValidatorTests.cs` | Create |
| 11 | `FanucProgramManager.csproj` | Edit — add 5 Compile entries |
| 12 | `FanucProgramManager.Tests/FanucProgramManager.Tests.csproj` | Edit — add test Compile entry |
## Validation Rules
### Universal
- Block length ≤ 80 chars per line
- No lowercase letters
- No tab characters
- No nested parentheses (depth > 1)
- Comment content inside `()` ≤ 32 chars
### Fanuc
- Name must match `O\d{4}`
- First line of content must be `O####`
- Forbidden chars: `;`, `[`, `]`
- `#` → Warning (macro variable indicator)
### Mitsubishi
- Same as Fanuc (O#### naming, same forbidden chars)
### Siemens
- Name must end with `.MPF` (uppercase)
- Forbidden chars: `;`
### Heidenhain
- Name must end with `.H`
- No O#### header required
- Forbidden chars: `%`, `;`
## Constraints
- .NET 4.7.2: no `Array.Empty<T>()`, no C# 8+ features
- No LINQ unless already imported
- Namespace: `FanucProgramManager.Cnc` (validator), `FanucProgramManager.Cnc.Models` (result types)
- English code + comments only