# dxflib **Repository Path**: naught/dxflib ## Basic Information - **Project Name**: dxflib - **Description**: dxflib is an open source C++ library mainly for parsing DXFTM files. QCAD, CAM Expert and vec2web all use dxflib to import DXF files. - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2023-11-23 - **Last Updated**: 2026-08-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dxflib - DXF文件读写库 dxflib 是一个用于读取和写入 DXF(Drawing Interchange Format)文件的 C++ 库。DXF 是 Autodesk 公司开发的 CAD 数据交换格式,广泛应用于各种 CAD 软件之间进行数据交换。 ## 功能特性 - **DXF文件读取**: 支持从 DXF 文件中读取各种实体数据 - **DXF文件写入**: 支持创建和写入标准 DXF 格式文件 - **丰富实体支持**: 点、线、圆弧、多段线、样条曲线、填充、尺寸标注等 - **跨平台兼容**: 基于 CMake 构建,支持 Windows、Linux、macOS 等平台 - **简单易用**: 提供清晰接口和详细示例代码 ## 项目结构 ``` dxflib/ ├── src/ # 核心源代码 │ ├── dl_codes.h # DXF 编码定义 │ ├── dl_creationadapter.h # 创建适配器 │ ├── dl_creationinterface.h # 创建接口 │ ├── dl_dxf.cpp/h # DXF 读写主类 │ ├── dl_entities.h # 实体定义 │ ├── dl_exception.h # 异常处理 │ ├── dl_extrusion.h # extrusion 数据 │ ├── dl_global.h # 全局定义 │ ├── dl_writer.h # 写入器接口 │ └── dl_writer_ascii.cpp/h # ASCII 写入器实现 ├── examples/ # 示例程序 │ ├── readwrite/ # 读写示例 │ ├── writedimension/ # 尺寸标注示例 │ └── writehatch/ # 填充示例 ├── cmake/ # CMake 配置文件 └── gpl-2.0greater.txt # GPL-2.0+ 许可证 ``` ## 依赖要求 - C++ 编译器(支持 C++11 或更高版本) - CMake 3.0 或更高版本 - 标准 C++ 开发库 ## 编译安装 ### Linux/macOS ```bash mkdir build cd build cmake .. make sudo make install ``` ### Windows ```bash mkdir build cd build cmake .. # 使用 Visual Studio 或其他 IDE 打开生成的解决方案 ``` ## 快速开始 ### 读取 DXF 文件 ```cpp #include "dl_dxf.h" #include "dl_creationadapter.h" class MyCreationClass : public DL_CreationAdapter { void addPoint(const DL_PointData& data) override { printf("Point: (%.2f, %.2f)\n", data.x, data.y); } void addLine(const DL_LineData& data) override { printf("Line: (%.2f, %.2f) -> (%.2f, %.2f)\n", data.x1, data.y1, data.x2, data.y2); } }; int main() { DL_Dxf dxf; MyCreationClass creator; if (dxf.in("input.dxf", &creator)) { printf("DXF 文件读取成功\n"); } return 0; } ``` ### 写入 DXF 文件 ```cpp #include "dl_dxf.h" int main() { DL_Dxf dxf; DL_WriterA* dw = dxf.out("output.dxf", DL_Codes::AC1009); if (!dw) { printf("文件打开失败\n"); return 1; } dxf.writeHeader(*dw); // 写入点 DL_PointData point(10, 20); dxf.writePoint(*dw, point, DL_Attributes("0", 1, "CONTINUOUS")); // 写入线 DL_LineData line(0, 0, 100, 100); dxf.writeLine(*dw, line, DL_Attributes("0", 1, "CONTINUOUS")); // 写入圆 DL_CircleData circle(50, 50, 25); dxf.writeCircle(*dw, circle, DL_Attributes("0", 1, "CONTINUOUS")); dw->close(); delete dw; printf("DXF 文件写入成功\n"); return 0; } ``` ## API 概览 ### 主要类 | 类名 | 说明 | |------|------| | `DL_Dxf` | DXF 文件读写核心类 | | `DL_WriterA` | ASCII 格式 DXF 写入器 | | `DL_CreationAdapter` | 实体创建的适配器基类 | | `DL_CreationInterface` | 实体创建接口 | ### 读取支持的实体 - 点(Point)、线(Line)、射线(Ray)、构造线(XLine) - 圆(Circle)、圆弧(Arc)、椭圆(Ellipse) - 多段线(Polyline)、顶点(Vertex)、样条曲线(Spline) - 填充(Hatch)、图像(Image) - 文本(Text)、多行文本(MText) - 尺寸标注(Dimension) - 块(Block)、图层(Layer)、线型(Linetype)等 ### 写入支持的实体 覆盖所有读取支持的实体类型,并提供完整的属性控制。 ## 示例程序 项目提供了三个示例程序: 1. **readwrite**: 演示基本读写操作 - 读取 existing DXF 文件 - 创建新图形并保存 - 创建类回调处理示例 2. **writedimension**: 演示尺寸标注写入 - 线性尺寸、对齐尺寸 - 半径尺寸、直径尺寸 - 角度尺寸、坐标尺寸 3. **writehatch**: 演示填充创建 - 边界填充 - 填充边定义 ## 许可证 本项目采用 **GPL-2.0+**(GNU General Public License v2.0 或更高版本)开源协议。 详细内容请参阅 [gpl-2.0greater.txt](gpl-2.0greater.txt) 文件。 ## 贡献指南 欢迎提交 Issue 和 Pull Request 来帮助改进本项目。在提交代码前,请确保: - 代码风格与项目一致 - 添加必要的注释和文档 - 通过所有测试用例 ## 联系方式 - 项目主页: https://gitee.com/naught/dxflib - 问题反馈: https://gitee.com/naught/dxflib/issues