# DFM Analysis Implementation Plan

## Goal Description
Add a native **Design‑for‑Manufacturing (DFM)** analysis tool to the FikoCAD platform. The feature will automatically scan a model’s B‑Rep topology and report manufacturability issues for CNC milling and casting, provide visual heat‑maps, and generate an instant cost/quote estimate.

## User Review Required
> [!IMPORTANT]
> - **License impact:** The DFM engine introduces new command IDs (`analiz.dfm`, `analiz.casting`) and a per‑analysis quota (`kota=analiz.dfm:50/ay`). Confirm if you want these to be part of a separate commercial module or bundled with the core.
> - **UI placement:** Decide whether the DFM panel appears in the existing **Command Palette** (`Ctrl+Space`) or as a new **Dockable Tab** in the side‑bar.
> - **Performance budget:** The AI‑driven DFM uses GPU‑accelerated BVH traversal. Specify the maximum acceptable analysis time for models up to 2 M triangles (e.g., ≤ 2 s).

## Open Questions
- Should the DFM module support both **CNC milling** and **casting** in a single run (combined report) or separate commands?
- Do you want the **cost estimate** to be a simple linear model (material × volume × price) or integrate with an external ERP API?
- Which **visual style** do you prefer for the heat‑map (gradient red→green, glass‑morphism overlay, or hover tooltip only)?

## Proposed Changes
---
### Core Engine (motor/zeka)
#### [NEW] [dfm_engine.cpp](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/motor/dfm_engine.cpp)
- Implements `Zeka::DFMAnalyzer` with methods `runCncChecks`, `runCastingChecks`, and `estimateCost`.
- Uses existing BVH utilities (`motor/bvh.h`) for fast collision/clearance tests.
- Returns a JSON report (`DfMReport`) with issue list, severity, and optional heat‑map data.

#### [NEW] [dfm_engine.h](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/motor/dfm_engine.h)
- Public API declaration.

---
### Command Registration (engine/komut_kayit.cpp)
#### [MODIFY] [komut_kayit.cpp](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/engine/komut_kayit.cpp)
- Register new commands:
  - `analiz.dfm` – runs full DFM (CNC + casting) and opens DFM panel.
  - `analiz.dfm_cnc` – CNC‑only.
  - `analiz.dfm_casting` – casting‑only.
- Hook them to `Zeka::DFMAnalyzer`.

---
### UI Integration (ui/dfm_panel.cpp & UI resources)
#### [NEW] [dfm_panel.cpp](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/ui/dfm_panel.cpp)
- ImGui‑based dockable panel showing a tree view of detected issues, a heat‑map overlay on the 3D viewport, and a “Generate Quote” button.
- Uses existing `ui/immediate_mode.h` utilities for drawing overlay.

#### [NEW] [dfm_panel.h](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/ui/dfm_panel.h)
- Header for the panel.

#### [MODIFY] [ui/main_window.cpp](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/ui/main_window.cpp)
- Add a menu entry **Tools → DFM Analysis** that toggles the panel.
- Ensure the panel is loaded only if the license flag `analiz.dfm` is present.

---
### Licensing (licensing/dfm_licence.md & source)
#### [NEW] [dfm_licence.md](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/licensing/dfm_licence.md)
- Document new license keys, quota (`kota=analiz.dfm:50/ay`), and optional SaaS activation.

#### [MODIFY] [lisans_dosya.cpp](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/motor/cekirdek/src/lisans_dosya.cpp)
- Add parsing for `analiz.dfm` command IDs.

---
### Tests (test/dfm_test.cpp)
#### [NEW] [dfm_test.cpp](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/test/dfm_test.cpp)
- Unit tests for clearance checks, casting thin‑wall detection, and cost estimation accuracy.

---
### Documentation (docs/DFM_Kilavuz.md)
#### [NEW] [DFM_Kilavuz.md](file:///d:/__sistem__/Masaustu/FikoYT.Yeni.Cag/fikatia-local/docs/DFM_Kilavuz.md)
- User guide with screenshots of the heat‑map overlay and step‑by‑step quote generation.

## Verification Plan
### Automated Tests
- Run `ctest` suite; ensure `dfm_test` passes.
- Verify that `analiz.dfm` command appears in the command palette only when a valid license is loaded.

### Manual Verification
- Load a sample part with known CNC problems (tight fillet, under‑cut). Run **Tools → DFM Analysis** and confirm issues are highlighted.
- Generate a cost estimate and compare against a hand‑calculated baseline.
- Test casting‑only mode on a thick‑walled model and verify shrinkage‑risk detection.

---
**Next Steps**
- Await user approval on open questions and licensing scope.
- Once approved, the implementation will be carried out in incremental commits.
