dxf⽂件解析库libdxf初探
之前⽂章调研过dxflib和libdxfrw,查资料发现还有⼀个类似的库libdxf,本⽂初探⼀下这个库。
官⽅说明:
libDXF is a library (written in C) with DXF related functions.
The Drawing eXchange Format (DXF) is a defacto industry standard for the exchange of drawing files between various Computer Aided Drafting programs, designed by Autodesk(TM).
Currently this project has a "Work in progress" status.
The code base is still incomplete and is not debugged to an acceptable level.
You are always welcome to help with patches or bug reports :-)
For more information see the libDXF repository on  or the project page on .
For statistics see .
尝试Windows平台使⽤
编写
cmake_minimum_required(VERSION 3.8.0)
project(libdxf)
# Find source files
file(GLOB SOURCES src/*.c)
# Include header files
include_directories(src)
# Create shared library
add_library(${PROJECT_NAME} SHARED ${SOURCES})
# Install library
install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
# Install library headers
file(GLOB HEADERS src/*.h)
install(FILES ${HEADERS} DESTINATION include/${PROJECT_NAME})
最终⽣成VS2017⼯程,打开进⾏构建。
使⽤Qt进⾏编译:libdxf.pro
1 #-------------------------------------------------
2 #
3 # Project created by QtCreator 2020-02-19T09:52:44
4 #
5 #-------------------------------------------------
6
7 QT      -= core gui
8
9 TARGET = libdxf
10 TEMPLATE = lib
11 CONFIG += staticlib
12
13 # The following define makes your compiler emit warnings if you use
14 # any feature of Qt which has been marked as deprecated (the exact warnings
15 # depend on your compiler). Please consult the documentation of the
16 # deprecated API in order to know how to port your code away from it.
17 DEFINES += QT_DEPRECATED_WARNINGS
18
19 # You can also make your code fail to compile if you use deprecated APIs.
20 # In order to do so, uncomment the following line.
21 # You can also select to disable deprecated APIs only up to a certain version of Qt.
22 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0 23
24 SOURCES += \
25        src/3dface.c \
26        src/3dline.c \
27        src/3dsolid.c \
28        src/acad_proxy_entity.c \
29        src/appid.c \
30        src/arc.c \
31        src/attdef.c \
32        src/attrib.c \
33        src/binary_data.c \
34        src/binary_entity_data.c \
35        src/binary_graphics_data.c \
36        src/block.c \
37        src/block_record.c \
38        src/body.c \
39        src/circle.c \
40        src/class.c \
41        src/color.c \
42        src/comment.c \
43        src/dictionary.c \
44        src/dictionaryvar.c \
45        src/dimension.c \
46        src/dimstyle.c \
47        src/donut.c \
48        src/drawing.c \
49        src/ellipse.c \
50        src/endblk.c \
51        src/endsec.c \
52        src/endtab.c \
53        src/entities.c \
54        src/entity.c \
55        src/file.c \
56        src/group.c \
57        src/hatch.c \
58        src/header.c \
59        src/helix.c \
60        src/idbuffer.c \
61        src/image.c \
62        src/imagedef.c \
63        src/imagedef_reactor.c \
64        src/insert.c \
65        src/layer.c \
66        src/layer_index.c \
67        src/layer_name.c \
68        src/leader.c \
69        src/light.c \
70        src/line.c \
71        src/ltype.c \
72        src/lwpolyline.c \
73        src/mesh.c \
74        src/mleader.c \
75        src/mleaderstyle.c \
76        src/mline.c \
77        src/mlinestyle.c \
78        src/mtext.c \
79        src/object.c \
80        src/object_id.c \
81        src/object_ptr.c \
82        src/ole2frame.c \
84        src/point.c \
85        src/polyline.c \
86        src/proprietary_data.c \
87        src/rastervariables.c \
88        src/ray.c \
89        src/region.c \
90        src/rtext.c \
91        src/section.c \
92        src/seqend.c \
93        src/shape.c \
94        src/solid.c \
95        src/sortentstable.c \
96        src/spatial_filter.c \
97        src/spatial_index.c \
98        src/spline.c \
99        src/style.c \
100        src/sun.c \
101        src/surface.c \
102        src/table.c \
103        src/tables.c \
104        src/text.c \
105        src/thumbnail.c \
106        src/tolerance.c \
107        src/trace.c \
108        src/ucs.c \
109        src/util.c \
110        src/vertex.c \
111        src/view.c \
112        src/viewport.c \
113        src/vport.c \
114        src/xline.c \
115        src/xrecord.c
116
117 HEADERS += \
118        src/3dface.h \
119        src/3dline.h \
120        src/3dsolid.h \
121        src/acad_proxy_entity.h \ 122        src/appid.h \
123        src/arc.h \
124        src/attdef.h \
125        src/attrib.h \
126        src/binary_data.h \
127        src/binary_entity_data.h \ 128        src/binary_graphics_data.h \ 129        src/block.h \
130        src/block_record.h \
131        src/body.h \
132        src/circle.h \
133        src/class.h \
134        src/color.h \
135        src/comment.h \
136        src/dbg.h \
137        src/dictionary.h \
138        src/dictionaryvar.h \
139        src/dimension.h \
140        src/dimstyle.h \
141        src/donut.h \
142        src/drawing.h \
143        src/dxf.h \
144        src/ellipse.h \
145        src/endblk.h \
146        src/endsec.h \
147        src/endtab.h \
148        src/entities.h \
149        src/entity.h \
150        src/file.h \
151        src/global.h \
152        src/group.h \
153        src/hatch.h \
154        src/header.h \
155        src/helix.h \
156        src/idbuffer.h \
157        src/image.h \
158        src/imagedef.h \
159        src/imagedef_reactor.h \ 160        src/insert.h \
161        src/layer.h \
162        src/layer_index.h \
163        src/layer_name.h \
164        src/leader.h \
165        src/light.h \
166        src/line.h \
168        src/lwpolyline.h \
169        src/mesh.h \
170        src/mleader.h \
171        src/mleaderstyle.h \ 172        src/mline.h \
173        src/mlinestyle.h \
174        src/mtext.h \
175        src/object.h \
176        src/object_id.h \
177        src/object_ptr.h \
178        src/ole2frame.h \
179        src/oleframe.h \
180        src/param.h \
181        src/point.h \
182        src/polyline.h \
183        src/proprietary_data.h \ 184        src/rastervariables.h \ 185        src/ray.h \
186        src/region.h \
187        src/rtext.h \
188        src/section.h \
189        src/seqend.h \
190        src/shape.h \
191        src/solid.h \
192        src/sortentstable.h \ 193        src/spatial_filter.h \ 194        src/spatial_index.h \ 195        src/spline.h \
196        src/style.h \
197        src/sun.h \
198        src/surface.h \
199        src/table.h \
200        src/tables.h \
201        src/text.h \
202        src/thumbnail.h \
203        src/tolerance.h \
204        src/trace.h \
205        src/ucs.h \
206        src/util.h \
207        src/vertex.h \
208        src/view.h \
209        src/viewport.h \ac reactor
210        src/vport.h \
211        src/xline.h \
212        src/xrecord.h
213 unix {
214    target.path = /usr/lib
215    INSTALLS += target
216 }
217
218 DISTFILES += \
219    src/Makefile.am \
220    src/libdxf.pc.in
构建⽣成静态库⽂件libdxf.a
同样滴,例⼦tests.pro
1 QT -= gui
2
3 CONFIG += c++11 console
4 CONFIG -= app_bundle
5
6 # The following define makes your compiler emit warnings if you use
7 # any Qt feature that has been marked deprecated (the exact warnings
8 # depend on your compiler). Please consult the documentation of the
9 # deprecated API in order to know how to port your code away from it.
10 DEFINES += QT_DEPRECATED_WARNINGS
11
12 # You can also make your code fail to compile if it uses deprecated APIs.
13 # In order to do so, uncomment the following line.
14 # You can also select to disable deprecated APIs only up to a certain version of Qt.
15 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0 16
17 SOURCES += \
18        test_point.c \
19        tests.c
20
21 # Default rules for deployment.
22 qnx: target.path = /tmp/$${TARGET}/bin
23else: unix:!android: target.path = /opt/$${TARGET}/bin
24 !isEmpty(target.path): INSTALLS += target
25
26 HEADERS += \
27    includes.h
28
29 INCLUDEPATH +=../
30
31 win32: LIBS += -L$$PWD/../build/bin/MinGW_32_Debug/debug/ -llibdxf
32
33 INCLUDEPATH += $$PWD/../build/bin/MinGW_32_Debug/debug
34 DEPENDPATH += $$PWD/../build/bin/MinGW_32_Debug/debug
35
36 win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../build/bin/MinGW_32_Debug/debug/libdxf.lib
37else:win32-g++: PRE_TARGETDEPS += $$PWD/../build/bin/MinGW_32_Debug/debug/liblibdxf.a
Qt构建成功!test.c⽤于读取dxf⽂件,test_point.c是⼀个写操作例⼦。
1/*!
2 * \brief Reads a dxf file using libdxf form examples dir.
3 *
4 * \version According to DXF R2000.
5*/
6int main (void)
7 {
8if (dxf_file_read ("../../examples/qcad-example_R2000.dxf"))
9        fprintf (stdout, "TESTS: R2000 exited with error\n");
10else
11        fprintf (stdout, "TESTS: R2000 exited with no error\n");
12
13return1;
14 }
但是运⾏时,读取dxf⽂件⼀直错误,看来这个库确实还存在不少bug,这就是所谓的“work in progress”。期待不断完善!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。