# python-CAD-tool **Repository Path**: kcat11/python-cad-tool ## Basic Information - **Project Name**: python-CAD-tool - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-05 - **Last Updated**: 2026-08-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Python CAD Tool 从 DWG 识别安防/通讯图例,框定范围 + 指定中心点,生成可写入设备库的记录。 ## 目录 | 路径 | 说明 | |------|------| | `DWG/` | 原图纸;`DWG/cache/` 为 DXF 缓存与识别结果 | | `lib/cad_recog/` | 转换 / 扫描 / 坐标变换 / 入库绑定 | | `lib/tools/libredwg/` | LibreDWG(`dwg2dxf`) | | `backed/` | FastAPI 后端 | | `DB/` | 本地 SQLite(`.wb`)及远程库配置 | | `DBLogic/` | 本地库查询(内网 scene/model、公网 t_modeltype) | | `Front/` | Vue3 前端(预览 / 框选 / 绑定 / 识别) | ## 环境准备(首次) 在项目根目录 `G:\backed\Python-CAD-Tool`: ```bash pip install -r requirements.txt cd Front npm install cd .. ``` 可选配置(含账号,勿提交到 Git): - `DB/remote_db.json` — 公网同步(参考 `DB/remote_db.example.json`) - `DB/intranet_db.json` — 内网同步(参考 `DB/intranet_db.example.json`) ## 如何启动 需要 **两个终端**,都在项目根目录操作。 ### 1. 启动后端(端口 8000) ```bash cd G:\backed\Python-CAD-Tool python -m uvicorn backed.main:app --host 0.0.0.0 --port 8000 --reload ``` 看到 `Uvicorn running on http://0.0.0.0:8000` 即成功。健康检查: ### 2. 启动前端(端口 6670) 另开一个终端: ```bash cd G:\backed\Python-CAD-Tool\Front npm run dev ``` 看到 `Local: http://127.0.0.1:6670/` 即成功。 ### 3. 打开页面 - 本机: - 局域网:`http://<本机IP>:6670` 前端会把 `/api` 代理到 `127.0.0.1:8000`,因此 **后端必须先起来**,且监听 `0.0.0.0:8000`。 ### 停止 在对应终端按 `Ctrl+C`。 ## 使用流程 1. **上传转换**:选择 DWG → 填写转换后名称 →「转换并保存」(输出到 `DWG/cache/`) 2. 选择图纸 →「加载预览」(可勾选图层) 3. 填写 **SceneId**,选择 **内网 / 公网** 数据源 4. **框选图例**(紫)→「定位图例表并提取」→ 为每条图例绑定模型/类型 - 内网:绑定名为 `model.abName` - 公网:绑定 `t_modeltype` 5. **框选识别**(橙)/ 中心点 →「开始识别」 6. 需要时点「从公网更新数据库信息」或「从内网更新数据库信息」 ## CLI(可选) ```bash python backed/recognize_cli.py DWG/cache/hospital_t3.dxf --layer-contains 安防 --roi 360000,-10000,390000,15000 ``` ## 主要 API | 方法 | 路径 | 说明 | |------|------|------| | `GET` | `/health` | 健康检查 | | `GET` | `/api/drawings` | 图纸列表 | | `POST` | `/api/preview` | DXF 预览几何 | | `POST` | `/api/layers` | 图层列表 | | `POST` | `/api/recognize` | 框选识别 | | `POST` | `/api/legends/extract` | 提取图例表 | | `POST` | `/api/legends/bind` | 图例绑定 | | `GET` | `/api/db/scene` | 按 SceneId 查场景名 | | `GET` | `/api/db/bind-options` | 内网 model / 公网 t_modeltype | | `POST` | `/api/db/sync-public` | 从公网同步(只读远端) | | `POST` | `/api/db/sync-intranet` | 从内网同步(只读远端) | | `POST` | `/api/dwg/upload-convert` | 上传并转换 DWG | 识别请求示例: ```json { "drawing": "DWG/cache/hospital_t3.dxf", "layer_contains": ["安防"], "roi": [360000, -10000, 390000, 15000], "center": [0, 0, 0], "scale": 0.001, "sence_id": 81 } ``` ## 坐标约定 `scene_pos = center + R * ((cad_xy - origin) * scale)` - **roi**:本次识别的 CAD 世界坐标范围 - **origin**:CAD 侧锚点(默认取命中包围盒中心) - **center**:三维场景里指定的中心点 - **scale**:单位换算(默认 mm→m 用 `0.001`) 写入库前请在 Front 预览确认;当前 PoC **只生成 JSON,不自动 INSERT**。