# FreeCAD Entegrasyon Referans

## API Server

### Baslat
```bash
cd Python
python freecad_api_server.py
# Port: 8090
```

### Health Check
```bash
curl http://localhost:8090/health
```

## Endpoints

### STEP Analizi
```http
POST /uyar/api/freecad/analyze
Content-Type: application/json

{
  "file_id": "abc123",
  "options": {
    "include_topology": true,
    "calculate_volumes": true
  }
}
```

**Response:**
```json
{
  "objects": [...],
  "volumes": [...],
  "areas": [...],
  "cache_expires_in": 3600
}
```

### Cached Render
```http
POST /uyar/api-raw/freecad/render-cached
Content-Type: application/json

{
  "file_id": "abc123",
  "render_params": {
    "format": "gltf",
    "quality": "high"
  }
}
```

## Cache Sistemi

### TTL
- Default: 1 saat (3600 saniye)
- Analiz sonuclari cached
- Render output cached

### Temizle
```http
POST /uyar/api/freecad/cache/clear
{ "file_id": "abc123" }
```

## Headless Rendering

### GPU (CUDA)
```json
{
  "gpu_enabled": true,
  "cuda_device": 0,
  "samples": 64
}
```

### CPU Fallback
```json
{
  "gpu_enabled": false,
  "threads": 4
}
```

## Animasyon Scriptleri

### Spiral
```bash
python freesim-spiral.py --input model.step --output anim.gif
```

### Yatay-Dikey
```bash
python freesim-yatay-dikey.py --input model.step --frames 60
```

## Dosya Konumlari

```
Python/
├── freecad_api_server.py    - Flask API
├── free.py                  - Otomasyon motoru
├── freesim-spiral.py        - Spiral animasyon
├── freesim-yatay-dikey.py   - Hareket simulasyonu
├── headless_render.py       - Batch render
└── render-config.json       - Render ayarlari
```

## Dokumantasyon

```
.docs/
├── 04-freecad-entegrasyonu.md  - Mimari
├── 04-freecad-backend.md       - Backend detay
├── 04-freecad-cache.md         - Cache sistemi
├── 04-freecad-render.md        - Render pipeline
├── 04-freecad-gpu.md           - GPU rendering
└── 04-freecad-step-parser.md   - STEP parser v3.0
```

## Docker

```bash
docker-compose up -d freecad-api
docker logs freecad-api --tail 50
docker-compose restart freecad-api
```

## Debug

### Server calismiyor
```bash
netstat -ano | findstr :8090
python --version
pip list | grep -i freecad
```

### STEP parse hatasi
```python
import FreeCAD
doc = FreeCAD.openDocument("model.step")
for obj in doc.Objects:
    print(obj.Name, obj.TypeId)
```

### Memory sorunu
```python
FreeCAD.closeDocument(doc.Name)
import gc
gc.collect()
```
