dxfedit/03_Python_OpenSource_DXF/README_IMPROVED.md
2025-09-09 18:42:30 +08:00

250 lines
5.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# CAD Automation System (改进版)
[![CI](https://github.com/your-repo/cad-automation/actions/workflows/ci.yml/badge.svg)](https://github.com/your-repo/cad-automation/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/your-repo/cad-automation/branch/main/graph/badge.svg)](https://codecov.io/gh/your-repo/cad-automation)
[![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
一个基于Python的CAD文件自动化处理系统支持DWG/DXF文件的读取、修改、格式转换和表格绘制。
## ✨ 特性
- 🔄 **DWG到DXF转换**: 自动将DWG文件转换为DXF格式
- 📊 **模板化绘图**: 基于JSON模板精确绘制CAD表格
- 🛠️ **实体操作**: 读取、查询、修改CAD实体属性
- 📄 **格式转换**: 将DXF转换为PDF等格式
- 🎯 **精确控制**: 像素级别的几何和样式控制
- 🧪 **测试驱动**: 完整的单元测试和集成测试
- 📦 **模块化设计**: 清晰的架构和可扩展性
## 🚀 快速开始
### 环境要求
- Python 3.8+
- ODA File Converter (用于DWG转换)
### 安装
```bash
# 克隆项目
git clone https://github.com/your-repo/cad-automation.git
cd cad-automation
# 安装依赖
make install-dev
# 或者手动安装
pip install -e .[dev]
```
### 配置
1. 复制配置文件:
```bash
cp config.example.json config.json
```
2. 编辑 `config.json` 中的ODA转换器路径
3. 验证安装:
```bash
make check-all
```
### 使用示例
#### 1. 命令行使用
```bash
# 转换DWG到DXF
python -m cad_automation.cli convert input.dwg
# 转换并绘制表格
python -m cad_automation.cli convert input.dwg --with-table --template bom_template.json
# 处理现有DXF文件
python -m cad_automation.cli process input.dxf --color 5
```
#### 2. Python API使用
```python
from cad_automation import CADAutomationWorkflow
# 创建工作流实例
workflow = CADAutomationWorkflow()
# 执行完整工作流
results = workflow.run_complete_workflow(
input_file="input.dwg",
output_dir="output/",
template_path="bom_template.json",
data_rows=bom_data
)
```
## 📁 项目结构
```
cad-automation/
├── src/cad_automation/ # 主包
│ ├── __init__.py
│ ├── cli.py # 命令行接口
│ ├── config.py # 配置管理
│ ├── converter.py # 文件转换器
│ ├── dxf_processor.py # DXF处理器
│ ├── exceptions.py # 自定义异常
│ ├── template_processor.py # 模板处理器
│ └── workflow.py # 工作流管理
├── tests/ # 测试文件
│ ├── __init__.py
│ ├── conftest.py
│ └── test_*.py
├── docs/ # 文档
├── config.example.json # 配置示例
├── pyproject.toml # 项目配置
├── requirements.txt # 依赖列表
├── Makefile # 开发工具
└── README.md # 项目文档
```
## 🧪 测试
```bash
# 运行所有测试
make test
# 带覆盖率测试
make test-cov
# 监听模式测试
make test-watch
```
## 🛠️ 开发
### 代码质量
```bash
# 格式化代码
make format
# 类型检查
make type-check
# 代码检查
make lint
# 全量检查
make check-all
```
### 开发工作流
```bash
# 设置开发环境
make dev-setup
# 快速开发周期
make dev
# 构建包
make build
```
## 📚 API文档
### 核心类
#### `DXFProcessor`
DXF文件处理的核心类。
```python
processor = DXFProcessor("file.dxf")
processor.load_file()
# 查询实体
lines = processor.query_entities("LINE[color==5]")
# 添加实体
processor.add_line((0, 0), (100, 100), color=1)
processor.add_text("Hello", (50, 50))
# 保存文件
processor.save_file("output.dxf")
```
#### `TemplateProcessor`
模板处理类,用于基于模板绘制表格。
```python
template = TemplateProcessor("template.json")
template.draw_table_from_template(processor, (260, 50), bom_data)
```
#### `CADAutomationWorkflow`
完整的工作流管理类。
```python
workflow = CADAutomationWorkflow()
results = workflow.run_complete_workflow("input.dwg", "output/")
```
## 🔧 配置
系统使用JSON配置文件进行设置。主要配置项
```json
{
"oda_converter": {
"path": "C:\\Program Files\\ODA\\ODAFileConverter.exe",
"version": "ACAD2018"
},
"paths": {
"input_dir": "../04_Test_Files",
"output_dir": "./output"
},
"table_settings": {
"row_height": 8.0,
"default_color": 7
}
}
```
## 🤝 贡献
1. Fork 项目
2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
4. 推送到分支 (`git push origin feature/AmazingFeature`)
5. 创建 Pull Request
### 开发规范
- 遵循PEP 8代码风格
- 添加类型注解
- 编写测试用例
- 更新文档
## 📄 许可证
本项目采用MIT许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。
## 🙏 致谢
- [ezdxf](https://github.com/mozman/ezdxf) - 优秀的DXF处理库
- [ODA File Converter](https://www.opendesign.com/guestfiles/oda-file-converter) - DWG转换工具
## 📞 支持
如果您有问题或建议,请:
1. 查看[问题页面](https://github.com/your-repo/cad-automation/issues)
2. 创建新问题
3. 联系维护者
---
**注意**: 请确保在使用前正确配置ODA File Converter路径。