├── .github └── workflows │ ├── c-cpp.yml │ └── cmake.yml ├── .gitignore ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── ChangeLog ├── Dockerfile ├── Makefile.am ├── Makefile.in ├── NEWS ├── README ├── README.md ├── TODO ├── aclocal.m4 ├── ar-lib ├── autogen.sh ├── bin ├── dwg2txt ├── dxf2txt └── dxf2txt.py ├── build.sh ├── config.guess ├── config.sub ├── configure ├── configure.ac ├── depcomp ├── dwg2dxf ├── Makefile.am ├── Makefile.in ├── dwg2dxf.1 ├── dx_data.h ├── dx_iface.cpp ├── dx_iface.h ├── main.cpp └── vs2013 │ ├── dwg2dxf.sln │ ├── dwg2dxf.vcxproj │ └── dwg2dxf.vcxproj.filters ├── dwg2text ├── Makefile.am ├── Makefile.in ├── dwg2text.1 ├── dx_data.h ├── dx_iface.cpp ├── dx_iface.h ├── main.cpp └── vs2013 │ ├── dwg2text.sln │ ├── dwg2text.vcxproj │ └── dwg2text.vcxproj.filters ├── install-sh ├── libdxfrw.dox ├── libdxfrw.pc.in ├── ltmain.sh ├── makefile.mingw ├── missing ├── src ├── Makefile.am ├── Makefile.in ├── drw_base.h ├── drw_classes.cpp ├── drw_classes.h ├── drw_entities.cpp ├── drw_entities.h ├── drw_header.cpp ├── drw_header.h ├── drw_interface.h ├── drw_objects.cpp ├── drw_objects.h ├── intern │ ├── drw_cptable932.h │ ├── drw_cptable936.h │ ├── drw_cptable949.h │ ├── drw_cptable950.h │ ├── drw_cptables.h │ ├── drw_dbg.cpp │ ├── drw_dbg.h │ ├── drw_textcodec.cpp │ ├── drw_textcodec.h │ ├── dwgbuffer.cpp │ ├── dwgbuffer.h │ ├── dwgreader.cpp │ ├── dwgreader.h │ ├── dwgreader15.cpp │ ├── dwgreader15.h │ ├── dwgreader18.cpp │ ├── dwgreader18.h │ ├── dwgreader21.cpp │ ├── dwgreader21.h │ ├── dwgreader24.cpp │ ├── dwgreader24.h │ ├── dwgreader27.cpp │ ├── dwgreader27.h │ ├── dwgutil.cpp │ ├── dwgutil.h │ ├── dxfreader.cpp │ ├── dxfreader.h │ ├── dxfwriter.cpp │ ├── dxfwriter.h │ ├── rscodec.cpp │ └── rscodec.h ├── libdwgr.cpp ├── libdwgr.h ├── libdxfrw.cpp ├── libdxfrw.h └── main_doc.h └── vs2013 ├── libdxfrw.sln ├── libdxfrw.vcxproj ├── libdxfrw.vcxproj.filters └── packages.config /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: autoreconf 17 | run: autoreconf -vfi 18 | - name: configure 19 | run: ./configure 20 | - name: make 21 | run: make 22 | - name: make check 23 | run: make check 24 | # - name: make distcheck 25 | # run: make distcheck 26 | -------------------------------------------------------------------------------- /.github/workflows/cmake.yml: -------------------------------------------------------------------------------- 1 | name: CMake 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 11 | BUILD_TYPE: Release 12 | 13 | jobs: 14 | build: 15 | # The CMake configure and build commands are platform agnostic and should work equally 16 | # well on Windows or Mac. You can convert this to a matrix build if you need 17 | # cross-platform coverage. 18 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | 24 | - name: Configure CMake 25 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 26 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 27 | run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} 28 | 29 | - name: Build 30 | # Build your program with the given configuration 31 | run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} 32 | 33 | - name: Test 34 | working-directory: ${{github.workspace}}/build 35 | # Execute tests defined by the CMake configuration. 36 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 37 | run: ctest -C ${{env.BUILD_TYPE}} 38 | 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated directories and files 2 | obj/ 3 | m4/ 4 | autom4te.cache/ 5 | libdxfrw.pro* 6 | Makefile 7 | *.o 8 | *.lo 9 | *.a 10 | *.la 11 | *so 12 | *lo 13 | *.la 14 | *.o 15 | *.dll 16 | *~ 17 | *bz2 18 | #vim files 19 | *.swp 20 | *.orig 21 | .deps 22 | .libs 23 | doc/ 24 | config.log 25 | config.status 26 | libdxfrw*.pc 27 | libtool 28 | .vs/ 29 | packages/ 30 | /vs2013/libdxfrw.sdf 31 | /vs2013/libdxfrw.v12.suo 32 | /vs2013/Debug 33 | /vs2013/Release 34 | /vs2013/libdxfrw.opensdf 35 | /vs2013/libdxfrw.vcxproj.user 36 | /dwg2dxf/vs2013/Debug 37 | /dwg2dxf/vs2013/Release 38 | /dwg2dxf/vs2013/dwg2dxf.opensdf 39 | /dwg2dxf/vs2013/dwg2dxf.sdf 40 | /dwg2dxf/vs2013/dwg2dxf.v12.suo 41 | /dwg2text/vs2013/Debug 42 | /dwg2text/vs2013/Release 43 | /dwg2text/vs2013/dwg2dxf.opensdf 44 | /dwg2text/vs2013/dwg2dxf.sdf 45 | /dwg2text/vs2013/dwg2dxf.v12.suo 46 | .idea 47 | build 48 | debug 49 | compile 50 | .cproject 51 | .project 52 | CMakeCache.txt 53 | cmake_install.cmake 54 | src/intern/.dirstamp 55 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | Rallaz 3 | Original author. 4 | Nicu Tofan 5 | contributor. 6 | Miguel E. Hernández Cuervo 7 | contributor. -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10 FATAL_ERROR) 2 | project(libdxfrw) 3 | 4 | file(GLOB libdxfrw_sources src/*.cpp) 5 | file(GLOB libdxfrw_headers include/*.h) 6 | file(GLOB libdxfrw_intern_sources src/intern/*.cpp) 7 | 8 | if(WIN32) 9 | 10 | include_directories(vs2013/packages/libiconv.1.14.0.11/build/native/include) 11 | link_directories(vs2013/packages/libiconv.1.14.0.11/build/native/lib) 12 | endif() 13 | include_directories(include) 14 | 15 | add_library(dxfrw STATIC ${libdxfrw_sources} ${libdxfrw_intern_sources}) 16 | 17 | install(FILES ${libdxfrw_headers} DESTINATION include) 18 | 19 | if(WIN32) 20 | install(TARGETS dxfrw 21 | CONFIGURATIONS Debug 22 | LIBRARY DESTINATION Debug/lib 23 | ARCHIVE DESTINATION Debug/lib) 24 | install(TARGETS dxfrw 25 | CONFIGURATIONS Release 26 | LIBRARY DESTINATION Release/lib 27 | ARCHIVE DESTINATION Release/lib) 28 | else() 29 | install(TARGETS dxfrw 30 | LIBRARY DESTINATION lib 31 | ARCHIVE DESTINATION lib) 32 | endif() -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Author: Rallaz 2 | Date: Mon Sep 10 17:39:05 2012 +0200 3 | 4 | vports, text bugs & update to 0.5.4 5 | 6 | Author: Rallaz 7 | Date: Wed Aug 15 12:11:14 2012 +0200 8 | 9 | complete update autotools 10 | 11 | Author: Rallaz 12 | Date: Wed Aug 15 11:46:52 2012 +0200 13 | 14 | update autotools 15 | 16 | Author: Rallaz 17 | Date: Tue Aug 14 19:27:52 2012 +0200 18 | 19 | updated to version 0.5.2 20 | 21 | Author: Rallaz 22 | Date: Tue Aug 14 19:27:12 2012 +0200 23 | 24 | patch for textstyle and dimstyle 25 | 26 | Author: Rallaz 27 | Date: Mon Jun 11 20:59:29 2012 +0200 28 | 29 | a bit more write header 30 | 31 | Author: Rallaz 32 | Date: Mon Jun 11 08:33:25 2012 +0200 33 | 34 | solve bug reading empty string 35 | 36 | Author: Rallaz 37 | Date: Fri Jun 8 18:01:51 2012 +0200 38 | 39 | added VPORT, v0.5.0 reached 40 | 41 | Author: Rallaz 42 | Date: Wed Jun 6 17:39:04 2012 +0200 43 | 44 | complete text style table 45 | 46 | Author: Rallaz 47 | Date: Tue Jun 5 21:00:46 2012 +0200 48 | 49 | start VPORT, STYLE, add viewport & complete dimstyle 50 | 51 | Author: Rallaz 52 | Date: Tue May 29 18:27:04 2012 +0200 53 | 54 | solve bug reading text into 90/270 deg. 55 | 56 | Author: Rallaz 57 | Date: Fri May 25 19:27:00 2012 +0200 58 | 59 | overflow in drw_textcodec.cpp 60 | 61 | Author: Rallaz 62 | Date: Fri May 25 18:57:40 2012 +0200 63 | 64 | polyline bug & correct configure 65 | 66 | Author: Rallaz 67 | Date: Thu May 24 19:14:58 2012 +0200 68 | 69 | missing files & complete dimstyle v12 70 | 71 | Author: Rallaz 72 | Date: Thu May 10 19:55:58 2012 +0200 73 | 74 | updated to 0.4.2 locale support 75 | 76 | Author: Rallaz 77 | Date: Thu Apr 19 20:54:39 2012 +0200 78 | 79 | update to 0.4 ray, xline, polyline 80 | 81 | Author: Rallaz 82 | Date: Tue Apr 17 17:06:27 2012 +0200 83 | 84 | write leader support & update to v0.3.1 85 | 86 | Author: Rallaz 87 | Date: Thu Apr 12 20:29:53 2012 +0200 88 | 89 | added write image support 90 | 91 | Author: Rallaz 92 | Date: Thu Apr 5 13:11:51 2012 +0200 93 | 94 | update to v0.3.0, blocks texts & splines 95 | 96 | Author: Rallaz 97 | Date: Fri Mar 30 19:44:07 2012 +0200 98 | 99 | Added write spline support 100 | 101 | Author: Rallaz 102 | Date: Thu Mar 22 20:59:03 2012 +0100 103 | 104 | added support for write more than v2000 105 | 106 | Author: Rallaz 107 | Date: Wed Feb 1 20:00:40 2012 +0100 108 | 109 | corect bugs in mtext angle & layer plot flag 110 | 111 | Author: Rallaz 112 | Date: Wed Feb 1 19:41:15 2012 +0100 113 | 114 | writer: start supportig versions 115 | 116 | Author: Rallaz 117 | Date: Wed Jan 4 13:42:42 2012 +0100 118 | 119 | deleted some autogenerated files 120 | 121 | Author: Rallaz 122 | Date: Wed Jan 4 13:36:07 2012 +0100 123 | 124 | Added autotools build system 125 | 126 | Author: Rallaz 127 | Date: Wed Jan 4 11:25:45 2012 +0100 128 | 129 | write header support, not handled all vars 130 | 131 | Author: Rallaz 132 | Date: Wed Jan 4 10:03:00 2012 +0100 133 | 134 | writer bug thanks to Dongxu Li 135 | 136 | Author: Rallaz 137 | Date: Wed Dec 21 19:48:37 2011 +0100 138 | 139 | added ability to apply extrusion 140 | 141 | Author: Rallaz 142 | Date: Sun Dec 18 13:50:47 2011 +0100 143 | 144 | :remove little bug in makefile 145 | 146 | Author: Rallaz 147 | Date: Sun Dec 18 13:42:43 2011 +0100 148 | 149 | update makefile 150 | 151 | Author: Rallaz 152 | Date: Sun Dec 18 13:09:17 2011 +0100 153 | 154 | added read of dimensions, leader & header vars 155 | 156 | Author: Rallaz 157 | Date: Tue Dec 13 19:03:45 2011 +0100 158 | 159 | added read image & polyline loop in hatch 160 | 161 | Author: Rallaz 162 | Date: Mon Dec 12 21:02:53 2011 +0100 163 | 164 | added read spline support 165 | 166 | Author: Rallaz 167 | Date: Sun Dec 11 14:15:26 2011 +0100 168 | 169 | added 3dface read/write support 170 | 171 | Author: Rallaz 172 | Date: Sun Dec 11 13:18:09 2011 +0100 173 | 174 | read polyline & hatch 175 | 176 | Author: Rallaz 177 | Date: Sun Dec 4 11:49:22 2011 +0100 178 | 179 | add lwpolyline write support 180 | 181 | Author: Rallaz 182 | Date: Sat Dec 3 11:22:06 2011 +0100 183 | 184 | add read support for lightweight polyline 185 | 186 | Author: Rallaz 187 | Date: Fri Dec 2 20:07:17 2011 +0100 188 | 189 | can read block and insert 190 | 191 | Author: Rallaz 192 | Date: Thu Dec 1 17:31:01 2011 +0100 193 | 194 | fix \r\n and \n on read 195 | 196 | Author: Rallaz 197 | Date: Wed Nov 30 21:04:27 2011 +0100 198 | 199 | updated makefile 200 | 201 | Author: Rallaz 202 | Date: Wed Nov 30 20:58:16 2011 +0100 203 | 204 | added read/write support for ellipse, trace & solid 205 | 206 | Author: Rallaz 207 | Date: Tue Nov 29 19:46:52 2011 +0100 208 | 209 | add write layers 210 | 211 | Author: Rallaz 212 | Date: Tue Nov 29 16:49:47 2011 +0100 213 | 214 | read/write linetypes 215 | 216 | Author: Rallaz 217 | Date: Mon Nov 28 18:12:47 2011 +0100 218 | 219 | Completed basic write support 220 | 221 | Author: Rallaz 222 | Date: Fri Nov 25 20:09:37 2011 +0100 223 | 224 | Minor patch 225 | 226 | Author: Rallaz 227 | Date: Fri Nov 25 19:46:50 2011 +0100 228 | 229 | Initial commit of version 0.0.1 230 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM centos:7 2 | 3 | MAINTAINER CodeLibs Project 4 | 5 | RUN yum -y groupinstall base "Development tools" --setopt=group_package_types=mandatory,default,optional 6 | RUN yum clean all 7 | 8 | RUN mkdir /work 9 | WORKDIR /work 10 | 11 | CMD ["sh", "/opt/bin/run.sh"] 12 | 13 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | SUBDIRS = src dwg2dxf dwg2text 4 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 0.6.0 2 | First version with dwg read support 3 | 4 | 0.6.2 5 | Support for VC++ 2013 -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | libdxfrw 2 | 3 | libdxfrw is a free C++ library to read and write DXF files in both formats, ascii and binary form. 4 | Also can read DWG files from R14 to the last V2015. 5 | It is licensed under the terms of the GNU General Public License version 2 (or at you option 6 | any later version). 7 | 8 | 9 | If you are looking for general information about the project, check our website: 10 | http://sourceforge.net/projects/libdxfrw 11 | 12 | == Building and installing the library == 13 | 14 | Use the tipical 15 | ./configure 16 | make 17 | make install (as root) 18 | 19 | [VC++] 20 | - Open vs2013\libdxfrw.sln with VS2013 21 | - Build Solution 22 | There is also a dwg to dxf converter that depends on libdxfrw that can be built the same way. 23 | - Open dwg2dxf\vs2013\dwg2dxf.sln with VS2013 24 | - Build Solution 25 | 26 | == Example usage of the library == 27 | 28 | The dwg to dxf converter (dwg2dxf) included in this package can be used as reference. 29 | 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libdxfrw 2 | ========== 3 | 4 | libdxfrw is a free C++ library to read and write DXF files in both formats, ascii and binary form. 5 | Also can read DWG files from R14 to the last V2015. 6 | It is licensed under the terms of the GNU General Public License version 2 (or at you option 7 | any later version). 8 | 9 | 10 | If you are looking for general information about the project, check our website: 11 | http://sourceforge.net/projects/libdxfrw 12 | 13 | Building and installing the library 14 | ========== 15 | 16 | Use the tipical 17 | ``` 18 | autoreconf -vfi (optional) 19 | ./configure 20 | make 21 | make install (as root) 22 | ``` 23 | 24 | Use CMake 25 | 26 | 27 | ``` 28 | mkdir build 29 | cd build 30 | cmake .. -DCMAKE_BUILD_TYPE=Release 31 | cmake --build . --config Release --target install 32 | ``` 33 | 34 | [VC++] 35 | - Open vs2013\libdxfrw.sln with VS2013 36 | - Build Solution 37 | There is also a dwg to dxf converter that depends on libdxfrw that can be built the same way. 38 | - Open dwg2dxf\vs2013\dwg2dxf.sln with VS2013 39 | - Build Solution 40 | - 41 | [VC++ with CMakeLists.txt] 42 | 43 | - Open the CMakeLists.txt from vs 2019 directly 44 | - build 45 | 46 | Example usage of the library 47 | ========== 48 | 49 | The dwg to dxf converter (dwg2dxf) included in this package can be used as reference. 50 | 51 | Test files 52 | ========== 53 | 54 | [Test files](https://github.com/codelibs/fess-testdata/tree/master/autocad) are supported. 55 | 56 | ## Docker 57 | 58 | ### Build Docker Image 59 | 60 | ``` 61 | docker build --rm -t codelibs/libdxfrw . 62 | docker push codelibs/libdxfrw:latest 63 | ``` 64 | 65 | ### Build libdxfrw on Docker 66 | 67 | ``` 68 | docker run -t --rm -v `pwd`:/work codelibs/libdxfrw:latest /work/build.sh 69 | ``` 70 | 71 | dxfrw.tar.gz is created. 72 | Extract this file under /opt. 73 | 74 | ### Push Release Images 75 | 76 | ``` 77 | docker tag codelibs/libdxfrw codelibs/libdxfrw:centos7 78 | docker push codelibs/libdxfrw:centos7 79 | ``` 80 | 81 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | conplete all dxf spec :( 2 | -------------------------------------------------------------------------------- /ar-lib: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for Microsoft lib.exe 3 | 4 | me=ar-lib 5 | scriptversion=2012-03-01.08; # UTC 6 | 7 | # Copyright (C) 2010-2013 Free Software Foundation, Inc. 8 | # Written by Peter Rosin . 9 | # 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2, or (at your option) 13 | # any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | 33 | # func_error message 34 | func_error () 35 | { 36 | echo "$me: $1" 1>&2 37 | exit 1 38 | } 39 | 40 | file_conv= 41 | 42 | # func_file_conv build_file 43 | # Convert a $build file to $host form and store it in $file 44 | # Currently only supports Windows hosts. 45 | func_file_conv () 46 | { 47 | file=$1 48 | case $file in 49 | / | /[!/]*) # absolute file, and not a UNC file 50 | if test -z "$file_conv"; then 51 | # lazily determine how to convert abs files 52 | case `uname -s` in 53 | MINGW*) 54 | file_conv=mingw 55 | ;; 56 | CYGWIN*) 57 | file_conv=cygwin 58 | ;; 59 | *) 60 | file_conv=wine 61 | ;; 62 | esac 63 | fi 64 | case $file_conv in 65 | mingw) 66 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 67 | ;; 68 | cygwin) 69 | file=`cygpath -m "$file" || echo "$file"` 70 | ;; 71 | wine) 72 | file=`winepath -w "$file" || echo "$file"` 73 | ;; 74 | esac 75 | ;; 76 | esac 77 | } 78 | 79 | # func_at_file at_file operation archive 80 | # Iterate over all members in AT_FILE performing OPERATION on ARCHIVE 81 | # for each of them. 82 | # When interpreting the content of the @FILE, do NOT use func_file_conv, 83 | # since the user would need to supply preconverted file names to 84 | # binutils ar, at least for MinGW. 85 | func_at_file () 86 | { 87 | operation=$2 88 | archive=$3 89 | at_file_contents=`cat "$1"` 90 | eval set x "$at_file_contents" 91 | shift 92 | 93 | for member 94 | do 95 | $AR -NOLOGO $operation:"$member" "$archive" || exit $? 96 | done 97 | } 98 | 99 | case $1 in 100 | '') 101 | func_error "no command. Try '$0 --help' for more information." 102 | ;; 103 | -h | --h*) 104 | cat < $OUTPUT_FILE 7 | if [ $? != 0 ] ; then 8 | echo > $OUTPUT_FILE 9 | fi 10 | -------------------------------------------------------------------------------- /bin/dxf2txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | INPUT_FILE=$1 4 | OUTPUT_FILE=$2 5 | 6 | python `dirname $0`/dxf2txt.py $INPUT_FILE $OUTPUT_FILE 7 | 8 | -------------------------------------------------------------------------------- /bin/dxf2txt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import print_function 3 | from __future__ import unicode_literals 4 | from __future__ import absolute_import 5 | from __future__ import generators 6 | from __future__ import division 7 | 8 | import re 9 | import sys 10 | import ezdxf 11 | 12 | if len(sys.argv) != 3: 13 | print("Invalid arguments: " + str(sys.argv)) 14 | exit(1) 15 | 16 | dwg = ezdxf.readfile(sys.argv[1], encoding='utf-8') 17 | 18 | print(dwg.dxfversion) 19 | old_enc_versions = ['AC1009', 'AC1015', 'AC1018'] 20 | if dwg.dxfversion in old_enc_versions: 21 | dwg = ezdxf.readfile(sys.argv[1], encoding='cp932') 22 | 23 | texts = [] 24 | block_pattern = r'\{\f.*;([^}]+)\}' 25 | modelspace = dwg.modelspace() 26 | for e in modelspace: 27 | if e.dxftype() == 'TEXT': 28 | texts.append(e.dxf.text) 29 | elif e.dxftype() == 'MTEXT': 30 | v = re.sub(r'\{\\f[^;]+;([^}]+)\}', r'\1', e.plain_text()).replace('\\P', '\n') 31 | texts.append(v) 32 | 33 | with open(sys.argv[2], 'w', encoding='utf-8') as f: 34 | f.writelines([(t+'\n') for t in texts]) 35 | 36 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | autoreconf -vfi 4 | ./configure --prefix=/opt/dxfrw 5 | make 6 | make install 7 | make clean 8 | cp bin/* /opt/dxfrw/bin 9 | cd /opt 10 | tar zcvf /work/dxfrw.tar.gz dxfrw 11 | chmod 777 /work/dxfrw.tar.gz 12 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.63]) 5 | AC_INIT([libdxfrw], [0.6.3], [https://sourceforge.net/projects/libdxfrw/]) 6 | AM_INIT_AUTOMAKE([foreign -Wall -Werror dist-bzip2 subdir-objects]) 7 | AC_CONFIG_SRCDIR([src/drw_interface.h]) 8 | 9 | # Checks for programs. 10 | AC_PROG_CXX 11 | AC_PROG_CC 12 | AM_PROG_AR 13 | LT_INIT 14 | AC_PROG_LIBTOOL 15 | AC_CONFIG_MACRO_DIR([m4]) 16 | 17 | # 18 | # Libtool library revision control info 19 | # See the libtool documentation under the heading "Libtool's versioning 20 | # system" in order to understand the meaning of these fields 21 | # 22 | # Here are a set of rules to help you update your library version 23 | # information: 24 | # 25 | # 1. Start with version information of `0:0:0' for each libtool library. 26 | # 2. Update the version information only immediately before a public 27 | # release of your software. More frequent updates are unnecessary, and 28 | # only guarantee that the current interface number gets larger faster. 29 | # 3. If the library source code has changed at all since the last update, 30 | # then increment revision (`c:r:a' becomes `c:r+1:a'). 31 | # 4. If any interfaces have been added, removed, or changed since the last 32 | # update, increment current, and set revision to 0. 33 | # 5. If any interfaces have been added since the last public release, then 34 | # increment age. 35 | # 6. If any interfaces have been removed since the last public release, 36 | # then set age to 0. 37 | # 38 | #AGE.CURRENT.REVISION 39 | LIBRARY_CURRENT=6 40 | LIBRARY_REVISION=3 41 | LIBRARY_AGE=0 42 | 43 | AC_SUBST(LIBRARY_CURRENT)dnl 44 | AC_SUBST(LIBRARY_REVISION)dnl 45 | AC_SUBST(LIBRARY_AGE)dnl 46 | 47 | # Checks for libraries. 48 | AC_CHECK_LIB(iconv, iconv_open) 49 | 50 | # Checks for header files. 51 | AC_CHECK_HEADERS([stdlib.h string.h]) 52 | 53 | # Checks for typedefs, structures, and compiler characteristics. 54 | AC_HEADER_STDBOOL 55 | 56 | # Checks for library functions. 57 | AC_FUNC_STRTOD 58 | AC_CHECK_FUNCS([sqrt]) 59 | 60 | AC_ENABLE_SHARED 61 | AC_ENABLE_STATIC 62 | 63 | AC_CONFIG_FILES([ 64 | Makefile 65 | src/Makefile 66 | dwg2dxf/Makefile 67 | dwg2text/Makefile 68 | libdxfrw${LIBRARY_AGE}.pc:libdxfrw.pc.in 69 | ]) 70 | AC_OUTPUT 71 | -------------------------------------------------------------------------------- /dwg2dxf/Makefile.am: -------------------------------------------------------------------------------- 1 | # -*- Makefile.am -*- 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | dwg2dxfdir = $(srcdir) 5 | 6 | bin_PROGRAMS = dwg2dxf 7 | 8 | AM_LDFLAGS = -L../src -ldxfrw 9 | 10 | dist_noinst_HEADERS = dx_iface.h dx_data.h 11 | 12 | dwg2dxf_SOURCES = dx_iface.cpp main.cpp 13 | 14 | AM_CPPFLAGS = ${my_CPPFLAGS} -Wall -I$(top_srcdir)/src 15 | 16 | man_MANS = dwg2dxf.1 17 | 18 | EXTRA_DIST = $(dwg2dxf_HEADERS) $(dwg2dxf_SOURCES) $(man_MANS) ./vs2013/* 19 | -------------------------------------------------------------------------------- /dwg2dxf/dwg2dxf.1: -------------------------------------------------------------------------------- 1 | .TH DWG2DXF 1 "November 2015" "version 1.0" 2 | .SH NAME 3 | dwg2dxf \- Conversor from dwg/dxf to dxf 4 | .SH SYNOPSIS 5 | dwg2dxf [-b] <-version> 6 | .SH DESCRIPTION 7 | dwg2dxf is a Console conversor from dwg/dxf to dxf. You can convert from dwg or dxf to another dxf version. 8 | .SH OPTIONS 9 | input existing file to convert 10 | -b optional, sets output as binary dxf 11 | -B optional, batch mode reads a text file whit a list of full path input 12 | files and saves with the same name in the indicated folder as output 13 | -y -Y optional, Warning! if output dxf exist overwrite without ask 14 | -version version output of dxf file 15 | output output file name 16 | 17 | version can be: 18 | -R12 dxf release 12 version 19 | -v2000 dxf version 2000 20 | -v2004 dxf version 2004 21 | -v2007 dxf version 2007 22 | -v2010 dxf version 2010 23 | .SH AUTHOR 24 | José F. Soriano - -------------------------------------------------------------------------------- /dwg2dxf/dx_data.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DX_DATA_H 14 | #define DX_DATA_H 15 | #include "libdxfrw.h" 16 | 17 | //class to store image data and path from DRW_ImageDef 18 | class dx_ifaceImg : public DRW_Image { 19 | public: 20 | dx_ifaceImg(){} 21 | dx_ifaceImg(const DRW_Image& p):DRW_Image(p){} 22 | ~dx_ifaceImg(){} 23 | std::string path; //stores the image path 24 | }; 25 | 26 | //container class to store entites. 27 | class dx_ifaceBlock : public DRW_Block { 28 | public: 29 | dx_ifaceBlock(){} 30 | dx_ifaceBlock(const DRW_Block& p):DRW_Block(p){} 31 | ~dx_ifaceBlock(){ 32 | for (std::list::const_iterator it=ent.begin(); it!=ent.end(); ++it) 33 | delete *it; 34 | } 35 | std::listent; //stores the entities list 36 | }; 37 | 38 | 39 | //container class to store full dwg/dxf data. 40 | class dx_data { 41 | public: 42 | dx_data(){ 43 | mBlock = new dx_ifaceBlock(); 44 | } 45 | ~dx_data(){ 46 | //cleanup, 47 | for (std::list::const_iterator it=blocks.begin(); it!=blocks.end(); ++it) 48 | delete *it; 49 | delete mBlock; 50 | } 51 | 52 | DRW_Header headerC; //stores a copy of the header vars 53 | std::listlineTypes; //stores a copy of all line types 54 | std::listlayers; //stores a copy of all layers 55 | std::listdimStyles; //stores a copy of all dimension styles 56 | std::listVPorts; //stores a copy of all vports 57 | std::listtextStyles; //stores a copy of all text styles 58 | std::listappIds; //stores a copy of all line types 59 | std::listblocks; //stores a copy of all blocks and the entities in it 60 | std::listimages; //temporary list to find images for link with DRW_ImageDef. Do not delete it!! 61 | 62 | dx_ifaceBlock* mBlock; //container to store model entities 63 | 64 | 65 | }; 66 | 67 | #endif // DX_DATA_H 68 | -------------------------------------------------------------------------------- /dwg2dxf/dx_iface.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include "dx_iface.h" 16 | #include "libdwgr.h" 17 | #include "libdxfrw.h" 18 | 19 | 20 | bool dx_iface::fileImport(const std::string& fileI, dx_data *fData){ 21 | unsigned int found = fileI.find_last_of("."); 22 | std::string fileExt = fileI.substr(found+1); 23 | std::transform(fileExt.begin(), fileExt.end(),fileExt.begin(), ::toupper); 24 | cData = fData; 25 | currentBlock = cData->mBlock; 26 | 27 | if (fileExt == "DXF"){ 28 | //loads dxf 29 | dxfRW* dxf = new dxfRW(fileI.c_str()); 30 | bool success = dxf->read(this, false); 31 | delete dxf; 32 | return success; 33 | } else if (fileExt == "DWG"){ 34 | //loads dwg 35 | dwgR* dwg = new dwgR(fileI.c_str()); 36 | bool success = dwg->read(this, false); 37 | delete dwg; 38 | return success; 39 | } 40 | std::cout << "file extension can be dxf or dwg" << std::endl; 41 | return false; 42 | } 43 | 44 | bool dx_iface::fileExport(const std::string& file, DRW::Version v, bool binary, dx_data *fData){ 45 | cData = fData; 46 | dxfW = new dxfRW(file.c_str()); 47 | bool success = dxfW->write(this, v, binary); 48 | delete dxfW; 49 | return success; 50 | 51 | } 52 | 53 | void dx_iface::writeEntity(DRW_Entity* e){ 54 | switch (e->eType) { 55 | case DRW::POINT: 56 | dxfW->writePoint(static_cast(e)); 57 | break; 58 | case DRW::LINE: 59 | dxfW->writeLine(static_cast(e)); 60 | break; 61 | case DRW::CIRCLE: 62 | dxfW->writeCircle(static_cast(e)); 63 | break; 64 | case DRW::ARC: 65 | dxfW->writeArc(static_cast(e)); 66 | break; 67 | case DRW::SOLID: 68 | dxfW->writeSolid(static_cast(e)); 69 | break; 70 | case DRW::ELLIPSE: 71 | dxfW->writeEllipse(static_cast(e)); 72 | break; 73 | case DRW::LWPOLYLINE: 74 | dxfW->writeLWPolyline(static_cast(e)); 75 | break; 76 | case DRW::POLYLINE: 77 | dxfW->writePolyline(static_cast(e)); 78 | break; 79 | case DRW::SPLINE: 80 | dxfW->writeSpline(static_cast(e)); 81 | break; 82 | // case RS2::EntitySplinePoints: 83 | // writeSplinePoints(static_cast(e)); 84 | // break; 85 | // case RS2::EntityVertex: 86 | // break; 87 | case DRW::INSERT: 88 | dxfW->writeInsert(static_cast(e)); 89 | break; 90 | case DRW::MTEXT: 91 | dxfW->writeMText(static_cast(e)); 92 | break; 93 | case DRW::TEXT: 94 | dxfW->writeText(static_cast(e)); 95 | break; 96 | case DRW::DIMLINEAR: 97 | case DRW::DIMALIGNED: 98 | case DRW::DIMANGULAR: 99 | case DRW::DIMANGULAR3P: 100 | case DRW::DIMRADIAL: 101 | case DRW::DIMDIAMETRIC: 102 | case DRW::DIMORDINATE: 103 | dxfW->writeDimension(static_cast(e)); 104 | break; 105 | case DRW::LEADER: 106 | dxfW->writeLeader(static_cast(e)); 107 | break; 108 | case DRW::HATCH: 109 | dxfW->writeHatch(static_cast(e)); 110 | break; 111 | case DRW::IMAGE: 112 | dxfW->writeImage(static_cast(e), static_cast(e)->path); 113 | break; 114 | default: 115 | break; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /dwg2dxf/dx_iface.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DX_IFACE_H 14 | #define DX_IFACE_H 15 | 16 | #include "drw_interface.h" 17 | #include "libdxfrw.h" 18 | #include "dx_data.h" 19 | 20 | class dx_iface : public DRW_Interface { 21 | public: 22 | dx_iface(){dxfW = NULL;} 23 | ~dx_iface(){} 24 | bool fileImport(const std::string& fileI, dx_data *fData); 25 | bool fileExport(const std::string& file, DRW::Version v, bool binary, dx_data *fData); 26 | void writeEntity(DRW_Entity* e); 27 | 28 | //reimplement virtual DRW_Interface functions 29 | 30 | //reader part, stores all in class dx_data 31 | //header 32 | void addHeader(const DRW_Header* data){ 33 | cData->headerC = *data; 34 | } 35 | 36 | //tables 37 | virtual void addLType(const DRW_LType& data){ 38 | cData->lineTypes.push_back(data); 39 | } 40 | virtual void addLayer(const DRW_Layer& data){ 41 | cData->layers.push_back(data); 42 | } 43 | virtual void addDimStyle(const DRW_Dimstyle& data){ 44 | cData->dimStyles.push_back(data); 45 | } 46 | virtual void addVport(const DRW_Vport& data){ 47 | cData->VPorts.push_back(data); 48 | } 49 | virtual void addTextStyle(const DRW_Textstyle& data){ 50 | cData->textStyles.push_back(data); 51 | } 52 | virtual void addAppId(const DRW_AppId& data){ 53 | cData->appIds.push_back(data); 54 | } 55 | 56 | //blocks 57 | virtual void addBlock(const DRW_Block& data){ 58 | dx_ifaceBlock* bk = new dx_ifaceBlock(data); 59 | currentBlock = bk; 60 | cData->blocks.push_back(bk); 61 | } 62 | virtual void endBlock(){ 63 | currentBlock = cData->mBlock; 64 | } 65 | 66 | virtual void setBlock(const int /*handle*/){}//unused 67 | 68 | //entities 69 | virtual void addPoint(const DRW_Point& data){ 70 | currentBlock->ent.push_back(new DRW_Point(data)); 71 | } 72 | virtual void addLine(const DRW_Line& data){ 73 | currentBlock->ent.push_back(new DRW_Line(data)); 74 | } 75 | virtual void addRay(const DRW_Ray& data){ 76 | currentBlock->ent.push_back(new DRW_Ray(data)); 77 | } 78 | virtual void addXline(const DRW_Xline& data){ 79 | currentBlock->ent.push_back(new DRW_Xline(data)); 80 | } 81 | virtual void addArc(const DRW_Arc& data){ 82 | currentBlock->ent.push_back(new DRW_Arc(data)); 83 | } 84 | virtual void addCircle(const DRW_Circle& data){ 85 | currentBlock->ent.push_back(new DRW_Circle(data)); 86 | } 87 | virtual void addEllipse(const DRW_Ellipse& data){ 88 | currentBlock->ent.push_back(new DRW_Ellipse(data)); 89 | } 90 | virtual void addLWPolyline(const DRW_LWPolyline& data){ 91 | currentBlock->ent.push_back(new DRW_LWPolyline(data)); 92 | } 93 | virtual void addPolyline(const DRW_Polyline& data){ 94 | currentBlock->ent.push_back(new DRW_Polyline(data)); 95 | } 96 | virtual void addSpline(const DRW_Spline* data){ 97 | currentBlock->ent.push_back(new DRW_Spline(*data)); 98 | } 99 | // ¿para que se usa? 100 | virtual void addKnot(const DRW_Entity& data){} 101 | 102 | virtual void addInsert(const DRW_Insert& data){ 103 | currentBlock->ent.push_back(new DRW_Insert(data)); 104 | } 105 | virtual void addTrace(const DRW_Trace& data){ 106 | currentBlock->ent.push_back(new DRW_Trace(data)); 107 | } 108 | virtual void add3dFace(const DRW_3Dface& data){ 109 | currentBlock->ent.push_back(new DRW_3Dface(data)); 110 | } 111 | virtual void addSolid(const DRW_Solid& data){ 112 | currentBlock->ent.push_back(new DRW_Solid(data)); 113 | } 114 | virtual void addMText(const DRW_MText& data){ 115 | currentBlock->ent.push_back(new DRW_MText(data)); 116 | } 117 | virtual void addText(const DRW_Text& data){ 118 | currentBlock->ent.push_back(new DRW_Text(data)); 119 | } 120 | virtual void addDimAlign(const DRW_DimAligned *data){ 121 | currentBlock->ent.push_back(new DRW_DimAligned(*data)); 122 | } 123 | virtual void addDimLinear(const DRW_DimLinear *data){ 124 | currentBlock->ent.push_back(new DRW_DimLinear(*data)); 125 | } 126 | virtual void addDimRadial(const DRW_DimRadial *data){ 127 | currentBlock->ent.push_back(new DRW_DimRadial(*data)); 128 | } 129 | virtual void addDimDiametric(const DRW_DimDiametric *data){ 130 | currentBlock->ent.push_back(new DRW_DimDiametric(*data)); 131 | } 132 | virtual void addDimAngular(const DRW_DimAngular *data){ 133 | currentBlock->ent.push_back(new DRW_DimAngular(*data)); 134 | } 135 | virtual void addDimAngular3P(const DRW_DimAngular3p *data){ 136 | currentBlock->ent.push_back(new DRW_DimAngular3p(*data)); 137 | } 138 | virtual void addDimOrdinate(const DRW_DimOrdinate *data){ 139 | currentBlock->ent.push_back(new DRW_DimOrdinate(*data)); 140 | } 141 | virtual void addLeader(const DRW_Leader *data){ 142 | currentBlock->ent.push_back(new DRW_Leader(*data)); 143 | } 144 | virtual void addHatch(const DRW_Hatch *data){ 145 | currentBlock->ent.push_back(new DRW_Hatch(*data)); 146 | } 147 | virtual void addViewport(const DRW_Viewport& data){ 148 | currentBlock->ent.push_back(new DRW_Viewport(data)); 149 | } 150 | virtual void addImage(const DRW_Image *data){ 151 | dx_ifaceImg *img = new dx_ifaceImg(*data); 152 | currentBlock->ent.push_back(new dx_ifaceImg(*data)); 153 | cData->images.push_back(img); 154 | } 155 | 156 | virtual void linkImage(const DRW_ImageDef *data){ 157 | duint32 handle = data->handle; 158 | std::string path(data->name); 159 | for (std::list::iterator it=cData->images.begin(); it != cData->images.end(); ++it){ 160 | if ((*it)->ref == handle){ 161 | dx_ifaceImg *img = *it; 162 | img->path = path; 163 | } 164 | } 165 | } 166 | 167 | //writer part, send all in class dx_data to writer 168 | virtual void addComment(const char* /*comment*/){} 169 | 170 | virtual void writeHeader(DRW_Header& data){ 171 | //complete copy of header vars: 172 | data = cData->headerC; 173 | //or copy one by one: 174 | // for (std::map::iterator it=cData->headerC.vars.begin(); it != cData->headerC.vars.end(); ++it) 175 | // data.vars[it->first] = new DRW_Variant( *(it->second) ); 176 | } 177 | 178 | virtual void writeBlocks(){ 179 | //write each block 180 | for (std::list::iterator it=cData->blocks.begin(); it != cData->blocks.end(); ++it){ 181 | dx_ifaceBlock* bk = *it; 182 | dxfW->writeBlock(bk); 183 | //and write each entity in block 184 | for (std::list::const_iterator it=bk->ent.begin(); it!=bk->ent.end(); ++it) 185 | writeEntity(*it); 186 | } 187 | } 188 | //only send the name, needed by the reader to prepare handles of blocks & blockRecords 189 | virtual void writeBlockRecords(){ 190 | for (std::list::iterator it=cData->blocks.begin(); it != cData->blocks.end(); ++it) 191 | dxfW->writeBlockRecord((*it)->name); 192 | } 193 | //write entities of model space and first paper_space 194 | virtual void writeEntities(){ 195 | for (std::list::const_iterator it=cData->mBlock->ent.begin(); it!=cData->mBlock->ent.end(); ++it) 196 | writeEntity(*it); 197 | } 198 | virtual void writeLTypes(){ 199 | for (std::list::iterator it=cData->lineTypes.begin(); it != cData->lineTypes.end(); ++it) 200 | dxfW->writeLineType(&(*it)); 201 | } 202 | virtual void writeLayers(){ 203 | for (std::list::iterator it=cData->layers.begin(); it != cData->layers.end(); ++it) 204 | dxfW->writeLayer(&(*it)); 205 | } 206 | virtual void writeTextstyles(){ 207 | for (std::list::iterator it=cData->textStyles.begin(); it != cData->textStyles.end(); ++it) 208 | dxfW->writeTextstyle(&(*it)); 209 | } 210 | virtual void writeVports(){ 211 | for (std::list::iterator it=cData->VPorts.begin(); it != cData->VPorts.end(); ++it) 212 | dxfW->writeVport(&(*it)); 213 | } 214 | virtual void writeDimstyles(){ 215 | for (std::list::iterator it=cData->dimStyles.begin(); it != cData->dimStyles.end(); ++it) 216 | dxfW->writeDimstyle(&(*it)); 217 | } 218 | virtual void writeAppId(){ 219 | for (std::list::iterator it=cData->appIds.begin(); it != cData->appIds.end(); ++it) 220 | dxfW->writeAppId(&(*it)); 221 | } 222 | 223 | dxfRW* dxfW; //pointer to writer, needed to send data 224 | dx_data* cData; // class to store or read data 225 | dx_ifaceBlock* currentBlock; 226 | }; 227 | 228 | #endif // DX_IFACE_H 229 | -------------------------------------------------------------------------------- /dwg2dxf/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "dx_iface.h" 18 | #include "dx_data.h" 19 | 20 | #ifndef S_ISDIR 21 | #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 22 | #endif 23 | 24 | void usage(){ 25 | std::cout << "Usage: " << std::endl; 26 | std::cout << " dwg2dxf [-b] <-version> " << std::endl << std::endl; 27 | std::cout << " input existing file to convert" << std::endl; 28 | std::cout << " -b optional, sets output as binary dxf" << std::endl; 29 | std::cout << " -B optional, batch mode reads a text file whit a list of full path input" << std::endl; 30 | std::cout << " files and saves with the same name in the indicated folder as output" << std::endl; 31 | std::cout << " -y -Y optional, Warning! if output dxf exist overwrite without ask" << std::endl; 32 | std::cout << " -version version output of dxf file" << std::endl; 33 | std::cout << " output output file name" << std::endl << std::endl; 34 | std::cout << " version can be:" << std::endl; 35 | std::cout << " -R12 dxf release 12 version" << std::endl; 36 | std::cout << " -v2000 dxf version 2000" << std::endl; 37 | std::cout << " -v2004 dxf version 2004" << std::endl; 38 | std::cout << " -v2007 dxf version 2007" << std::endl; 39 | std::cout << " -v2010 dxf version 2010" << std::endl; 40 | } 41 | 42 | DRW::Version checkVersion(std::string param){ 43 | if (param == "-R12") 44 | return DRW::AC1009; 45 | else if (param == "-v2000") 46 | return DRW::AC1015; 47 | else if (param == "-v2004") 48 | return DRW::AC1018; 49 | else if (param == "-v2007") 50 | return DRW::AC1021; 51 | else if (param == "-v2010") 52 | return DRW::AC1024; 53 | return DRW::UNKNOWNV; 54 | } 55 | 56 | bool convertFile(std::string inName, std::string outName, DRW::Version ver, bool binary, bool overwrite){ 57 | bool badState = false; 58 | //verify if input file exist 59 | std::ifstream ifs; 60 | ifs.open (inName.c_str(), std::ifstream::in); 61 | badState = ifs.fail(); 62 | ifs.close(); 63 | if (badState) { 64 | std::cout << "Error can't open " << inName << std::endl; 65 | return false; 66 | } 67 | //verify if output file exist 68 | std::ifstream ofs; 69 | ofs.open (outName.c_str(), std::ifstream::in); 70 | badState = ofs.fail(); 71 | ofs.close(); 72 | if (!badState) { 73 | if (!overwrite){ 74 | std::cout << "File " << outName << " already exist, overwrite Y/N ?" << std::endl; 75 | int c = getchar(); 76 | if (c == 'Y' || c=='y') 77 | ; 78 | else { 79 | std::cout << "Cancelled."; 80 | return false; 81 | } 82 | } 83 | } 84 | //All ok proceed whit conversion 85 | //class to store file read: 86 | dx_data fData; 87 | //First read a dwg or dxf file 88 | dx_iface *input = new dx_iface(); 89 | badState = input->fileImport( inName, &fData ); 90 | if (!badState) { 91 | std::cout << "Error reading file " << inName << std::endl; 92 | return false; 93 | } 94 | 95 | //And write a dxf file 96 | dx_iface *output = new dx_iface(); 97 | badState = output->fileExport(outName, ver, binary, &fData); 98 | delete input; 99 | delete output; 100 | 101 | return badState; 102 | } 103 | 104 | int main(int argc, char *argv[]) { 105 | bool badState = false; 106 | bool binary = false; 107 | bool overwrite = false; 108 | bool batch = false; 109 | std::string outName; 110 | DRW::Version ver = DRW::UNKNOWNV; 111 | if (argc < 3) { 112 | usage(); 113 | return 1; 114 | } 115 | 116 | //parse params. 117 | std::string fileName = argv[1]; 118 | for (int i= 2; i < argc; ++i){ 119 | std::string param = argv[i]; 120 | if (i == (argc - 1) ) 121 | outName = param; 122 | else { 123 | if (param.at(0) == '-') { 124 | if (param.at(1) == 'b') 125 | binary = true; 126 | else if (param.at(1) == 'y') 127 | overwrite = true; 128 | else if (param.at(1) == 'B') 129 | batch = true; 130 | else { 131 | ver = checkVersion(param); 132 | if (ver == DRW::UNKNOWNV) { 133 | badState = true; 134 | } 135 | } 136 | } else 137 | badState = true; 138 | } 139 | } 140 | 141 | if (badState) { 142 | std::cout << "Bad options." << std::endl; 143 | usage(); 144 | return 1; 145 | } 146 | 147 | if (!batch){ //no batch mode, only one file 148 | bool ok = convertFile(fileName, outName, ver, binary, overwrite); 149 | if (ok) 150 | return 0; 151 | else 152 | return 1; 153 | 154 | } 155 | 156 | //batch mode, prepare input file and output folder. 157 | //verify if input file exist 158 | std::ifstream ifs; 159 | ifs.open (fileName.c_str(), std::ifstream::in); 160 | badState = ifs.fail(); 161 | ifs.close(); 162 | if (badState) { 163 | std::cout << "Batch mode, Error can't open " << fileName << std::endl; 164 | return 2; 165 | } 166 | 167 | //verify existence of output directory 168 | struct stat statBuf; 169 | int dirStat = stat(outName.c_str(), &statBuf); 170 | if(dirStat != 0 || S_ISDIR(statBuf.st_mode) == 0) { 171 | std::cout << "Batch mode: " << outName << " must be an existing directory" << std::endl; 172 | usage(); 173 | return 4; 174 | } 175 | outName+="/"; 176 | //create a list with the files to convert. 177 | std::ifstream bfs; 178 | bfs.open (fileName.c_str(), std::ifstream::in); 179 | std::listinList; 180 | std::string line; 181 | while ( bfs.good() ){ 182 | std::getline(bfs, line); 183 | if(!line.empty()) 184 | inList.push_back(line); 185 | } 186 | for (std::list::const_iterator it=inList.begin(); it!=inList.end(); ++it){ 187 | std::string input = *it; 188 | unsigned found = input.find_last_of("/\\"); 189 | std::string output = outName + input.substr(found+1); 190 | std::cout << "Converting file " << input << " to " << output << std::endl; 191 | bool ok = convertFile(input, output, ver, binary, overwrite); 192 | if (!ok) 193 | std::cout << "Failed" << std::endl; 194 | } 195 | 196 | return 0; 197 | } 198 | 199 | -------------------------------------------------------------------------------- /dwg2dxf/vs2013/dwg2dxf.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dwg2dxf", "dwg2dxf.vcxproj", "{81C80084-FF38-4F62-AE0B-8B262294D75F}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdxfrw", "..\..\vs2013\libdxfrw.vcxproj", "{357A8016-9AD4-47EF-B23C-2071C264793B}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Win32 = Debug|Win32 13 | Release|Win32 = Release|Win32 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {81C80084-FF38-4F62-AE0B-8B262294D75F}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {81C80084-FF38-4F62-AE0B-8B262294D75F}.Debug|Win32.Build.0 = Debug|Win32 18 | {81C80084-FF38-4F62-AE0B-8B262294D75F}.Release|Win32.ActiveCfg = Release|Win32 19 | {81C80084-FF38-4F62-AE0B-8B262294D75F}.Release|Win32.Build.0 = Release|Win32 20 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Debug|Win32.ActiveCfg = Debug|Win32 21 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Debug|Win32.Build.0 = Debug|Win32 22 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Release|Win32.ActiveCfg = Release|Win32 23 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Release|Win32.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /dwg2dxf/vs2013/dwg2dxf.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {81C80084-FF38-4F62-AE0B-8B262294D75F} 15 | dwg2dxf 16 | 17 | 18 | 19 | Application 20 | true 21 | v120 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v120 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | ../../src;%(AdditionalIncludeDirectories) 48 | 49 | 50 | true 51 | 52 | 53 | 54 | 55 | Level3 56 | MaxSpeed 57 | true 58 | true 59 | true 60 | ../../src;%(AdditionalIncludeDirectories) 61 | 62 | 63 | true 64 | true 65 | true 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | {357a8016-9ad4-47ef-b23c-2071c264793b} 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /dwg2dxf/vs2013/dwg2dxf.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /dwg2text/Makefile.am: -------------------------------------------------------------------------------- 1 | # -*- Makefile.am -*- 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | dwg2textdir = $(srcdir) 5 | 6 | bin_PROGRAMS = dwg2text 7 | 8 | AM_LDFLAGS = -L../src -ldxfrw 9 | 10 | dist_noinst_HEADERS = dx_iface.h dx_data.h 11 | 12 | dwg2text_SOURCES = dx_iface.cpp main.cpp 13 | 14 | AM_CPPFLAGS = ${my_CPPFLAGS} -Wall -I$(top_srcdir)/src 15 | 16 | man_MANS = dwg2text.1 17 | 18 | EXTRA_DIST = $(dwg2text_HEADERS) $(dwg2text_SOURCES) $(man_MANS) ./vs2013/* 19 | -------------------------------------------------------------------------------- /dwg2text/dwg2text.1: -------------------------------------------------------------------------------- 1 | .TH DWG2DXF 1 "November 2015" "version 1.0" 2 | .SH NAME 3 | dwg2text \- Extract text from dwg/dxf 4 | .SH SYNOPSIS 5 | dwg2text [-b] <-version> 6 | .SH DESCRIPTION 7 | dwg2text is a Console conversor from dwg/dxf to dxf. 8 | .SH OPTIONS 9 | input dwg or dxf file to extract text 10 | .SH AUTHOR 11 | José F. Soriano - -------------------------------------------------------------------------------- /dwg2text/dx_data.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DX_DATA_H 14 | #define DX_DATA_H 15 | #include "libdxfrw.h" 16 | 17 | //class to store image data and path from DRW_ImageDef 18 | class dx_ifaceImg : public DRW_Image { 19 | public: 20 | dx_ifaceImg(){} 21 | dx_ifaceImg(const DRW_Image& p):DRW_Image(p){} 22 | ~dx_ifaceImg(){} 23 | std::string path; //stores the image path 24 | }; 25 | 26 | //container class to store entites. 27 | class dx_ifaceBlock : public DRW_Block { 28 | public: 29 | dx_ifaceBlock(){} 30 | dx_ifaceBlock(const DRW_Block& p):DRW_Block(p){} 31 | ~dx_ifaceBlock(){ 32 | for (std::list::const_iterator it=ent.begin(); it!=ent.end(); ++it) 33 | delete *it; 34 | } 35 | std::listent; //stores the entities list 36 | }; 37 | 38 | 39 | //container class to store full dwg/dxf data. 40 | class dx_data { 41 | public: 42 | dx_data(){ 43 | mBlock = new dx_ifaceBlock(); 44 | } 45 | ~dx_data(){ 46 | //cleanup, 47 | for (std::list::const_iterator it=blocks.begin(); it!=blocks.end(); ++it) 48 | delete *it; 49 | delete mBlock; 50 | } 51 | 52 | DRW_Header headerC; //stores a copy of the header vars 53 | std::listlineTypes; //stores a copy of all line types 54 | std::listlayers; //stores a copy of all layers 55 | std::listdimStyles; //stores a copy of all dimension styles 56 | std::listVPorts; //stores a copy of all vports 57 | std::listtextStyles; //stores a copy of all text styles 58 | std::listappIds; //stores a copy of all line types 59 | std::listblocks; //stores a copy of all blocks and the entities in it 60 | std::listimages; //temporary list to find images for link with DRW_ImageDef. Do not delete it!! 61 | 62 | dx_ifaceBlock* mBlock; //container to store model entities 63 | 64 | 65 | }; 66 | 67 | #endif // DX_DATA_H 68 | -------------------------------------------------------------------------------- /dwg2text/dx_iface.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include "dx_iface.h" 16 | #include "libdwgr.h" 17 | #include "libdxfrw.h" 18 | 19 | 20 | bool dx_iface::printText(const std::string& fileI, dx_data *fData){ 21 | unsigned int found = fileI.find_last_of("."); 22 | std::string fileExt = fileI.substr(found+1); 23 | std::transform(fileExt.begin(), fileExt.end(),fileExt.begin(), ::toupper); 24 | cData = fData; 25 | currentBlock = cData->mBlock; 26 | 27 | bool success = false; 28 | if (fileExt == "DXF"){ 29 | //loads dxf 30 | dxfRW* dxf = new dxfRW(fileI.c_str()); 31 | success = dxf->read(this, false); 32 | delete dxf; 33 | } else if (fileExt == "DWG"){ 34 | //loads dwg 35 | dwgR* dwg = new dwgR(fileI.c_str()); 36 | success = dwg->read(this, false); 37 | delete dwg; 38 | } 39 | 40 | if (success) { 41 | for (std::list::const_iterator it = 42 | cData->mBlock->ent.begin(); it != cData->mBlock->ent.end(); 43 | ++it) { 44 | DRW_Entity* e = *it; 45 | switch (e->eType) { 46 | case DRW::TEXT: 47 | std::cout << static_cast(e)->text << std::endl; 48 | break; 49 | default: 50 | break; 51 | } 52 | } 53 | } 54 | return success; 55 | } 56 | 57 | void dx_iface::writeEntity(DRW_Entity* e){ 58 | switch (e->eType) { 59 | case DRW::POINT: 60 | dxfW->writePoint(static_cast(e)); 61 | break; 62 | case DRW::LINE: 63 | dxfW->writeLine(static_cast(e)); 64 | break; 65 | case DRW::CIRCLE: 66 | dxfW->writeCircle(static_cast(e)); 67 | break; 68 | case DRW::ARC: 69 | dxfW->writeArc(static_cast(e)); 70 | break; 71 | case DRW::SOLID: 72 | dxfW->writeSolid(static_cast(e)); 73 | break; 74 | case DRW::ELLIPSE: 75 | dxfW->writeEllipse(static_cast(e)); 76 | break; 77 | case DRW::LWPOLYLINE: 78 | dxfW->writeLWPolyline(static_cast(e)); 79 | break; 80 | case DRW::POLYLINE: 81 | dxfW->writePolyline(static_cast(e)); 82 | break; 83 | case DRW::SPLINE: 84 | dxfW->writeSpline(static_cast(e)); 85 | break; 86 | // case RS2::EntitySplinePoints: 87 | // writeSplinePoints(static_cast(e)); 88 | // break; 89 | // case RS2::EntityVertex: 90 | // break; 91 | case DRW::INSERT: 92 | dxfW->writeInsert(static_cast(e)); 93 | break; 94 | case DRW::MTEXT: 95 | dxfW->writeMText(static_cast(e)); 96 | break; 97 | case DRW::TEXT: 98 | dxfW->writeText(static_cast(e)); 99 | break; 100 | case DRW::DIMLINEAR: 101 | case DRW::DIMALIGNED: 102 | case DRW::DIMANGULAR: 103 | case DRW::DIMANGULAR3P: 104 | case DRW::DIMRADIAL: 105 | case DRW::DIMDIAMETRIC: 106 | case DRW::DIMORDINATE: 107 | dxfW->writeDimension(static_cast(e)); 108 | break; 109 | case DRW::LEADER: 110 | dxfW->writeLeader(static_cast(e)); 111 | break; 112 | case DRW::HATCH: 113 | dxfW->writeHatch(static_cast(e)); 114 | break; 115 | case DRW::IMAGE: 116 | dxfW->writeImage(static_cast(e), static_cast(e)->path); 117 | break; 118 | default: 119 | break; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /dwg2text/dx_iface.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** dwg2text - Program to convert dwg/dxf to dxf(ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DX_IFACE_H 14 | #define DX_IFACE_H 15 | 16 | #include "drw_interface.h" 17 | #include "libdxfrw.h" 18 | #include "dx_data.h" 19 | 20 | class dx_iface : public DRW_Interface { 21 | public: 22 | dx_iface(){dxfW = NULL;} 23 | ~dx_iface(){} 24 | bool printText(const std::string& fileI, dx_data *fData); 25 | void writeEntity(DRW_Entity* e); 26 | 27 | //reimplement virtual DRW_Interface functions 28 | 29 | //reader part, stores all in class dx_data 30 | //header 31 | void addHeader(const DRW_Header* data){ 32 | cData->headerC = *data; 33 | } 34 | 35 | //tables 36 | virtual void addLType(const DRW_LType& data){ 37 | cData->lineTypes.push_back(data); 38 | } 39 | virtual void addLayer(const DRW_Layer& data){ 40 | cData->layers.push_back(data); 41 | } 42 | virtual void addDimStyle(const DRW_Dimstyle& data){ 43 | cData->dimStyles.push_back(data); 44 | } 45 | virtual void addVport(const DRW_Vport& data){ 46 | cData->VPorts.push_back(data); 47 | } 48 | virtual void addTextStyle(const DRW_Textstyle& data){ 49 | cData->textStyles.push_back(data); 50 | } 51 | virtual void addAppId(const DRW_AppId& data){ 52 | cData->appIds.push_back(data); 53 | } 54 | 55 | //blocks 56 | virtual void addBlock(const DRW_Block& data){ 57 | dx_ifaceBlock* bk = new dx_ifaceBlock(data); 58 | currentBlock = bk; 59 | cData->blocks.push_back(bk); 60 | } 61 | virtual void endBlock(){ 62 | currentBlock = cData->mBlock; 63 | } 64 | 65 | virtual void setBlock(const int /*handle*/){}//unused 66 | 67 | //entities 68 | virtual void addPoint(const DRW_Point& data){ 69 | currentBlock->ent.push_back(new DRW_Point(data)); 70 | } 71 | virtual void addLine(const DRW_Line& data){ 72 | currentBlock->ent.push_back(new DRW_Line(data)); 73 | } 74 | virtual void addRay(const DRW_Ray& data){ 75 | currentBlock->ent.push_back(new DRW_Ray(data)); 76 | } 77 | virtual void addXline(const DRW_Xline& data){ 78 | currentBlock->ent.push_back(new DRW_Xline(data)); 79 | } 80 | virtual void addArc(const DRW_Arc& data){ 81 | currentBlock->ent.push_back(new DRW_Arc(data)); 82 | } 83 | virtual void addCircle(const DRW_Circle& data){ 84 | currentBlock->ent.push_back(new DRW_Circle(data)); 85 | } 86 | virtual void addEllipse(const DRW_Ellipse& data){ 87 | currentBlock->ent.push_back(new DRW_Ellipse(data)); 88 | } 89 | virtual void addLWPolyline(const DRW_LWPolyline& data){ 90 | currentBlock->ent.push_back(new DRW_LWPolyline(data)); 91 | } 92 | virtual void addPolyline(const DRW_Polyline& data){ 93 | currentBlock->ent.push_back(new DRW_Polyline(data)); 94 | } 95 | virtual void addSpline(const DRW_Spline* data){ 96 | currentBlock->ent.push_back(new DRW_Spline(*data)); 97 | } 98 | // ¿para que se usa? 99 | virtual void addKnot(const DRW_Entity& data){} 100 | 101 | virtual void addInsert(const DRW_Insert& data){ 102 | currentBlock->ent.push_back(new DRW_Insert(data)); 103 | } 104 | virtual void addTrace(const DRW_Trace& data){ 105 | currentBlock->ent.push_back(new DRW_Trace(data)); 106 | } 107 | virtual void add3dFace(const DRW_3Dface& data){ 108 | currentBlock->ent.push_back(new DRW_3Dface(data)); 109 | } 110 | virtual void addSolid(const DRW_Solid& data){ 111 | currentBlock->ent.push_back(new DRW_Solid(data)); 112 | } 113 | virtual void addMText(const DRW_MText& data){ 114 | currentBlock->ent.push_back(new DRW_MText(data)); 115 | } 116 | virtual void addText(const DRW_Text& data){ 117 | currentBlock->ent.push_back(new DRW_Text(data)); 118 | } 119 | virtual void addDimAlign(const DRW_DimAligned *data){ 120 | currentBlock->ent.push_back(new DRW_DimAligned(*data)); 121 | } 122 | virtual void addDimLinear(const DRW_DimLinear *data){ 123 | currentBlock->ent.push_back(new DRW_DimLinear(*data)); 124 | } 125 | virtual void addDimRadial(const DRW_DimRadial *data){ 126 | currentBlock->ent.push_back(new DRW_DimRadial(*data)); 127 | } 128 | virtual void addDimDiametric(const DRW_DimDiametric *data){ 129 | currentBlock->ent.push_back(new DRW_DimDiametric(*data)); 130 | } 131 | virtual void addDimAngular(const DRW_DimAngular *data){ 132 | currentBlock->ent.push_back(new DRW_DimAngular(*data)); 133 | } 134 | virtual void addDimAngular3P(const DRW_DimAngular3p *data){ 135 | currentBlock->ent.push_back(new DRW_DimAngular3p(*data)); 136 | } 137 | virtual void addDimOrdinate(const DRW_DimOrdinate *data){ 138 | currentBlock->ent.push_back(new DRW_DimOrdinate(*data)); 139 | } 140 | virtual void addLeader(const DRW_Leader *data){ 141 | currentBlock->ent.push_back(new DRW_Leader(*data)); 142 | } 143 | virtual void addHatch(const DRW_Hatch *data){ 144 | currentBlock->ent.push_back(new DRW_Hatch(*data)); 145 | } 146 | virtual void addViewport(const DRW_Viewport& data){ 147 | currentBlock->ent.push_back(new DRW_Viewport(data)); 148 | } 149 | virtual void addImage(const DRW_Image *data){ 150 | dx_ifaceImg *img = new dx_ifaceImg(*data); 151 | currentBlock->ent.push_back(new dx_ifaceImg(*data)); 152 | cData->images.push_back(img); 153 | } 154 | 155 | virtual void linkImage(const DRW_ImageDef *data){ 156 | duint32 handle = data->handle; 157 | std::string path(data->name); 158 | for (std::list::iterator it=cData->images.begin(); it != cData->images.end(); ++it){ 159 | if ((*it)->ref == handle){ 160 | dx_ifaceImg *img = *it; 161 | img->path = path; 162 | } 163 | } 164 | } 165 | 166 | //writer part, send all in class dx_data to writer 167 | virtual void addComment(const char* /*comment*/){} 168 | 169 | virtual void writeHeader(DRW_Header& data){ 170 | //complete copy of header vars: 171 | data = cData->headerC; 172 | //or copy one by one: 173 | // for (std::map::iterator it=cData->headerC.vars.begin(); it != cData->headerC.vars.end(); ++it) 174 | // data.vars[it->first] = new DRW_Variant( *(it->second) ); 175 | } 176 | 177 | virtual void writeBlocks(){ 178 | //write each block 179 | for (std::list::iterator it=cData->blocks.begin(); it != cData->blocks.end(); ++it){ 180 | dx_ifaceBlock* bk = *it; 181 | dxfW->writeBlock(bk); 182 | //and write each entity in block 183 | for (std::list::const_iterator it=bk->ent.begin(); it!=bk->ent.end(); ++it) 184 | writeEntity(*it); 185 | } 186 | } 187 | //only send the name, needed by the reader to prepare handles of blocks & blockRecords 188 | virtual void writeBlockRecords(){ 189 | for (std::list::iterator it=cData->blocks.begin(); it != cData->blocks.end(); ++it) 190 | dxfW->writeBlockRecord((*it)->name); 191 | } 192 | //write entities of model space and first paper_space 193 | virtual void writeEntities(){ 194 | for (std::list::const_iterator it=cData->mBlock->ent.begin(); it!=cData->mBlock->ent.end(); ++it) 195 | writeEntity(*it); 196 | } 197 | virtual void writeLTypes(){ 198 | for (std::list::iterator it=cData->lineTypes.begin(); it != cData->lineTypes.end(); ++it) 199 | dxfW->writeLineType(&(*it)); 200 | } 201 | virtual void writeLayers(){ 202 | for (std::list::iterator it=cData->layers.begin(); it != cData->layers.end(); ++it) 203 | dxfW->writeLayer(&(*it)); 204 | } 205 | virtual void writeTextstyles(){ 206 | for (std::list::iterator it=cData->textStyles.begin(); it != cData->textStyles.end(); ++it) 207 | dxfW->writeTextstyle(&(*it)); 208 | } 209 | virtual void writeVports(){ 210 | for (std::list::iterator it=cData->VPorts.begin(); it != cData->VPorts.end(); ++it) 211 | dxfW->writeVport(&(*it)); 212 | } 213 | virtual void writeDimstyles(){ 214 | for (std::list::iterator it=cData->dimStyles.begin(); it != cData->dimStyles.end(); ++it) 215 | dxfW->writeDimstyle(&(*it)); 216 | } 217 | virtual void writeAppId(){ 218 | for (std::list::iterator it=cData->appIds.begin(); it != cData->appIds.end(); ++it) 219 | dxfW->writeAppId(&(*it)); 220 | } 221 | 222 | dxfRW* dxfW; //pointer to writer, needed to send data 223 | dx_data* cData; // class to store or read data 224 | dx_ifaceBlock* currentBlock; 225 | }; 226 | 227 | #endif // DX_IFACE_H 228 | -------------------------------------------------------------------------------- /dwg2text/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** dwg2text - Program to extract text from dwg/dxf ** 3 | ** ** 4 | ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "dx_iface.h" 18 | #include "dx_data.h" 19 | 20 | void usage(){ 21 | std::cout << "Usage: " << std::endl; 22 | std::cout << " dwg2text " << std::endl << std::endl; 23 | std::cout << " input dwg or dxf file to extract text" << std::endl; 24 | } 25 | 26 | bool extractText(std::string inName){ 27 | bool badState = false; 28 | //verify if input file exist 29 | std::ifstream ifs; 30 | ifs.open (inName.c_str(), std::ifstream::in); 31 | badState = ifs.fail(); 32 | ifs.close(); 33 | if (badState) { 34 | std::cout << "Error can't open " << inName << std::endl; 35 | return false; 36 | } 37 | 38 | dx_data fData; 39 | dx_iface *input = new dx_iface(); 40 | badState = input->printText( inName, &fData ); 41 | if (!badState) { 42 | std::cout << "Error reading file " << inName << std::endl; 43 | return false; 44 | } 45 | delete input; 46 | 47 | return badState; 48 | } 49 | 50 | int main(int argc, char *argv[]) { 51 | bool badState = false; 52 | std::string outName; 53 | if (argc != 2) { 54 | usage(); 55 | return 1; 56 | } 57 | 58 | std::string fileName = argv[1]; 59 | 60 | if (badState) { 61 | std::cout << "Bad options." << std::endl; 62 | usage(); 63 | return 1; 64 | } 65 | 66 | bool ok = extractText(fileName); 67 | if (ok) 68 | return 0; 69 | else 70 | return 1; 71 | } 72 | -------------------------------------------------------------------------------- /dwg2text/vs2013/dwg2text.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dwg2text", "dwg2text.vcxproj", "{81C80084-FF38-4F62-AE0B-8B262294D75F}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdxfrw", "..\..\vs2013\libdxfrw.vcxproj", "{357A8016-9AD4-47EF-B23C-2071C264793B}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Win32 = Debug|Win32 13 | Release|Win32 = Release|Win32 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {81C80084-FF38-4F62-AE0B-8B262294D75F}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {81C80084-FF38-4F62-AE0B-8B262294D75F}.Debug|Win32.Build.0 = Debug|Win32 18 | {81C80084-FF38-4F62-AE0B-8B262294D75F}.Release|Win32.ActiveCfg = Release|Win32 19 | {81C80084-FF38-4F62-AE0B-8B262294D75F}.Release|Win32.Build.0 = Release|Win32 20 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Debug|Win32.ActiveCfg = Debug|Win32 21 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Debug|Win32.Build.0 = Debug|Win32 22 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Release|Win32.ActiveCfg = Release|Win32 23 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Release|Win32.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /dwg2text/vs2013/dwg2text.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {81C80084-FF38-4F62-AE0B-8B262294D75F} 15 | dwg2text 16 | 17 | 18 | 19 | Application 20 | true 21 | v120 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v120 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | ../../src;%(AdditionalIncludeDirectories) 48 | 49 | 50 | true 51 | 52 | 53 | 54 | 55 | Level3 56 | MaxSpeed 57 | true 58 | true 59 | true 60 | ../../src;%(AdditionalIncludeDirectories) 61 | 62 | 63 | true 64 | true 65 | true 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | {357a8016-9ad4-47ef-b23c-2071c264793b} 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /dwg2text/vs2013/dwg2text.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /libdxfrw.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libdxfrw 7 | Description: c++ library to read/write dxf files in binary and ascii form 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -ldxfrw 10 | Cflags: -I${includedir}/libdxfrw@LIBRARY_AGE@ 11 | -------------------------------------------------------------------------------- /missing: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Common wrapper for a few potentially missing GNU programs. 3 | 4 | scriptversion=2012-06-26.16; # UTC 5 | 6 | # Copyright (C) 1996-2013 Free Software Foundation, Inc. 7 | # Originally written by Fran,cois Pinard , 1996. 8 | 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | if test $# -eq 0; then 28 | echo 1>&2 "Try '$0 --help' for more information" 29 | exit 1 30 | fi 31 | 32 | case $1 in 33 | 34 | --is-lightweight) 35 | # Used by our autoconf macros to check whether the available missing 36 | # script is modern enough. 37 | exit 0 38 | ;; 39 | 40 | --run) 41 | # Back-compat with the calling convention used by older automake. 42 | shift 43 | ;; 44 | 45 | -h|--h|--he|--hel|--help) 46 | echo "\ 47 | $0 [OPTION]... PROGRAM [ARGUMENT]... 48 | 49 | Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due 50 | to PROGRAM being missing or too old. 51 | 52 | Options: 53 | -h, --help display this help and exit 54 | -v, --version output version information and exit 55 | 56 | Supported PROGRAM values: 57 | aclocal autoconf autoheader autom4te automake makeinfo 58 | bison yacc flex lex help2man 59 | 60 | Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and 61 | 'g' are ignored when checking the name. 62 | 63 | Send bug reports to ." 64 | exit $? 65 | ;; 66 | 67 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version) 68 | echo "missing $scriptversion (GNU Automake)" 69 | exit $? 70 | ;; 71 | 72 | -*) 73 | echo 1>&2 "$0: unknown '$1' option" 74 | echo 1>&2 "Try '$0 --help' for more information" 75 | exit 1 76 | ;; 77 | 78 | esac 79 | 80 | # Run the given program, remember its exit status. 81 | "$@"; st=$? 82 | 83 | # If it succeeded, we are done. 84 | test $st -eq 0 && exit 0 85 | 86 | # Also exit now if we it failed (or wasn't found), and '--version' was 87 | # passed; such an option is passed most likely to detect whether the 88 | # program is present and works. 89 | case $2 in --version|--help) exit $st;; esac 90 | 91 | # Exit code 63 means version mismatch. This often happens when the user 92 | # tries to use an ancient version of a tool on a file that requires a 93 | # minimum version. 94 | if test $st -eq 63; then 95 | msg="probably too old" 96 | elif test $st -eq 127; then 97 | # Program was missing. 98 | msg="missing on your system" 99 | else 100 | # Program was found and executed, but failed. Give up. 101 | exit $st 102 | fi 103 | 104 | perl_URL=http://www.perl.org/ 105 | flex_URL=http://flex.sourceforge.net/ 106 | gnu_software_URL=http://www.gnu.org/software 107 | 108 | program_details () 109 | { 110 | case $1 in 111 | aclocal|automake) 112 | echo "The '$1' program is part of the GNU Automake package:" 113 | echo "<$gnu_software_URL/automake>" 114 | echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" 115 | echo "<$gnu_software_URL/autoconf>" 116 | echo "<$gnu_software_URL/m4/>" 117 | echo "<$perl_URL>" 118 | ;; 119 | autoconf|autom4te|autoheader) 120 | echo "The '$1' program is part of the GNU Autoconf package:" 121 | echo "<$gnu_software_URL/autoconf/>" 122 | echo "It also requires GNU m4 and Perl in order to run:" 123 | echo "<$gnu_software_URL/m4/>" 124 | echo "<$perl_URL>" 125 | ;; 126 | esac 127 | } 128 | 129 | give_advice () 130 | { 131 | # Normalize program name to check for. 132 | normalized_program=`echo "$1" | sed ' 133 | s/^gnu-//; t 134 | s/^gnu//; t 135 | s/^g//; t'` 136 | 137 | printf '%s\n' "'$1' is $msg." 138 | 139 | configure_deps="'configure.ac' or m4 files included by 'configure.ac'" 140 | case $normalized_program in 141 | autoconf*) 142 | echo "You should only need it if you modified 'configure.ac'," 143 | echo "or m4 files included by it." 144 | program_details 'autoconf' 145 | ;; 146 | autoheader*) 147 | echo "You should only need it if you modified 'acconfig.h' or" 148 | echo "$configure_deps." 149 | program_details 'autoheader' 150 | ;; 151 | automake*) 152 | echo "You should only need it if you modified 'Makefile.am' or" 153 | echo "$configure_deps." 154 | program_details 'automake' 155 | ;; 156 | aclocal*) 157 | echo "You should only need it if you modified 'acinclude.m4' or" 158 | echo "$configure_deps." 159 | program_details 'aclocal' 160 | ;; 161 | autom4te*) 162 | echo "You might have modified some maintainer files that require" 163 | echo "the 'automa4te' program to be rebuilt." 164 | program_details 'autom4te' 165 | ;; 166 | bison*|yacc*) 167 | echo "You should only need it if you modified a '.y' file." 168 | echo "You may want to install the GNU Bison package:" 169 | echo "<$gnu_software_URL/bison/>" 170 | ;; 171 | lex*|flex*) 172 | echo "You should only need it if you modified a '.l' file." 173 | echo "You may want to install the Fast Lexical Analyzer package:" 174 | echo "<$flex_URL>" 175 | ;; 176 | help2man*) 177 | echo "You should only need it if you modified a dependency" \ 178 | "of a man page." 179 | echo "You may want to install the GNU Help2man package:" 180 | echo "<$gnu_software_URL/help2man/>" 181 | ;; 182 | makeinfo*) 183 | echo "You should only need it if you modified a '.texi' file, or" 184 | echo "any other file indirectly affecting the aspect of the manual." 185 | echo "You might want to install the Texinfo package:" 186 | echo "<$gnu_software_URL/texinfo/>" 187 | echo "The spurious makeinfo call might also be the consequence of" 188 | echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" 189 | echo "want to install GNU make:" 190 | echo "<$gnu_software_URL/make/>" 191 | ;; 192 | *) 193 | echo "You might have modified some files without having the proper" 194 | echo "tools for further handling them. Check the 'README' file, it" 195 | echo "often tells you about the needed prerequisites for installing" 196 | echo "this package. You may also peek at any GNU archive site, in" 197 | echo "case some other package contains this missing '$1' program." 198 | ;; 199 | esac 200 | } 201 | 202 | give_advice "$1" | sed -e '1s/^/WARNING: /' \ 203 | -e '2,$s/^/ /' >&2 204 | 205 | # Propagate the correct exit status (expected to be 127 for a program 206 | # not found, 63 for a program that failed due to version mismatch). 207 | exit $st 208 | 209 | # Local variables: 210 | # eval: (add-hook 'write-file-hooks 'time-stamp) 211 | # time-stamp-start: "scriptversion=" 212 | # time-stamp-format: "%:y-%02m-%02d.%02H" 213 | # time-stamp-time-zone: "UTC" 214 | # time-stamp-end: "; # UTC" 215 | # End: 216 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | 3 | AM_CPPFLAGS = ${my_CPPFLAGS} -Wall -Woverloaded-virtual 4 | ACLOCAL_AMFLAGS = -I m4 5 | 6 | library_includedir=$(includedir)/libdxfrw$(LIBRARY_AGE) 7 | library_include_HEADERS = drw_base.h drw_entities.h drw_interface.h \ 8 | drw_objects.h drw_header.h drw_classes.h libdxfrw.h libdwgr.h 9 | dist_noinst_HEADERS = intern/dxfreader.h intern/dxfwriter.h intern/drw_dbg.h \ 10 | intern/dwgutil.h intern/dwgreader.h intern/dwgreader15.h \ 11 | intern/dwgreader18.h intern/dwgreader21.h intern/dwgreader24.h \ 12 | intern/dwgreader27.h intern/dwgbuffer.h intern/drw_cptable932.h \ 13 | intern/drw_cptable936.h intern/drw_cptable949.h intern/drw_cptable950.h \ 14 | intern/drw_cptables.h intern/drw_textcodec.h intern/rscodec.h 15 | 16 | lib_LTLIBRARIES = libdxfrw.la 17 | 18 | libdxfrw_la_SOURCES = drw_entities.cpp drw_objects.cpp drw_header.cpp intern/drw_dbg.cpp \ 19 | drw_classes.cpp libdwgr.cpp libdxfrw.cpp intern/dwgutil.cpp \ 20 | intern/dxfreader.cpp intern/dwgreader15.cpp intern/dwgreader18.cpp intern/dwgreader21.cpp \ 21 | intern/dwgreader24.cpp intern/dwgreader27.cpp intern/dxfwriter.cpp intern/dwgreader.cpp \ 22 | intern/dwgbuffer.cpp intern/drw_textcodec.cpp intern/rscodec.cpp 23 | 24 | libdxfrw_la_LDFLAGS = -no-undefined -version-number $(LIBRARY_AGE):$(LIBRARY_CURRENT):$(LIBRARY_REVISION) 25 | 26 | libdxfrw_la_LIBADD = 27 | 28 | pkgconfigdir = ${libdir}/pkgconfig 29 | pkgconfig_DATA = ${top_builddir}/libdxfrw$(LIBRARY_AGE).pc 30 | 31 | EXTRA_DIST = ${top_builddir}/autogen.sh ${top_builddir}/makefile.mingw ${top_builddir}/vs2013/* 32 | 33 | libdxfrw.pc: ${top_builddir}/config.status 34 | -------------------------------------------------------------------------------- /src/drw_classes.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include "drw_classes.h" 14 | #include "intern/dxfreader.h" 15 | #include "intern/dxfwriter.h" 16 | #include "intern/dwgbuffer.h" 17 | #include "intern/drw_dbg.h" 18 | 19 | void DRW_Class::parseCode(int code, dxfReader *reader){ 20 | switch (code) { 21 | case 1: 22 | recName = reader->getUtf8String(); 23 | break; 24 | case 2: 25 | className = reader->getUtf8String(); 26 | break; 27 | case 3: 28 | appName = reader->getUtf8String(); 29 | break; 30 | case 90: 31 | proxyFlag = reader->getInt32(); 32 | break; 33 | case 91: 34 | instanceCount = reader->getInt32(); 35 | break; 36 | case 280: 37 | wasaProxyFlag = reader->getInt32(); 38 | break; 39 | case 281: 40 | entityFlag = reader->getInt32(); 41 | break; 42 | default: 43 | break; 44 | } 45 | } 46 | 47 | bool DRW_Class::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *strBuf){ 48 | DRW_DBG("\n***************************** parsing Class *********************************************\n"); 49 | 50 | classNum = buf->getBitShort(); 51 | DRW_DBG("Class number: "); DRW_DBG(classNum); 52 | proxyFlag = buf->getBitShort(); //in dwg specs says "version" 53 | 54 | appName = strBuf->getVariableText(version, false); 55 | className = strBuf->getVariableText(version, false); 56 | recName = strBuf->getVariableText(version, false); 57 | 58 | DRW_DBG("\napp name: "); DRW_DBG(appName.c_str()); 59 | DRW_DBG("\nclass name: "); DRW_DBG(className.c_str()); 60 | DRW_DBG("\ndxf rec name: "); DRW_DBG(recName.c_str()); 61 | wasaProxyFlag = buf->getBit(); //in dwg says wasazombie 62 | entityFlag = buf->getBitShort(); 63 | entityFlag = entityFlag == 0x1F2 ? 1: 0; 64 | 65 | DRW_DBG("\nProxy capabilities flag: "); DRW_DBG(proxyFlag); 66 | DRW_DBG(", proxy flag (280): "); DRW_DBG(wasaProxyFlag); 67 | DRW_DBG(", entity flag: "); DRW_DBGH(entityFlag); 68 | 69 | if (version > DRW::AC1015) {//2004+ 70 | instanceCount = buf->getBitLong(); 71 | DRW_DBG("\nInstance Count: "); DRW_DBG(instanceCount); 72 | duint32 dwgVersion = buf->getBitLong(); 73 | DRW_DBG("\nDWG version: "); DRW_DBG(dwgVersion); 74 | DRW_DBG("\nmaintenance version: "); DRW_DBG(buf->getBitLong()); 75 | DRW_DBG("\nunknown 1: "); DRW_DBG(buf->getBitLong()); 76 | DRW_DBG("\nunknown 2: "); DRW_DBG(buf->getBitLong()); 77 | } 78 | DRW_DBG("\n"); 79 | toDwgType(); 80 | return buf->isGood(); 81 | } 82 | 83 | void DRW_Class::write(dxfWriter *writer, DRW::Version ver){ 84 | if (ver > DRW::AC1009) { 85 | writer->writeString(0, "CLASS"); 86 | writer->writeString(1, recName); 87 | writer->writeString(2, className); 88 | writer->writeString(3, appName); 89 | writer->writeInt32(90, proxyFlag); 90 | if (ver > DRW::AC1015) { //2004+ 91 | writer->writeInt32(91, instanceCount); 92 | } 93 | writer->writeInt16(280, wasaProxyFlag); 94 | writer->writeInt16(281, entityFlag); 95 | } 96 | } 97 | 98 | void DRW_Class::toDwgType(){ 99 | if (recName == "LWPOLYLINE") 100 | dwgType = 77; 101 | else if (recName == "HATCH") 102 | dwgType = 78; 103 | else if (recName == "GROUP") 104 | dwgType = 72; 105 | /* else if (recName == "GROUP") 106 | dwgType = 72;*/ 107 | else if (recName == "LAYOUT") 108 | dwgType = 82; 109 | else if (recName == "IMAGE") 110 | dwgType = 101; 111 | else if (recName == "IMAGEDEF") 112 | dwgType = 102; 113 | else 114 | dwgType =0; 115 | } 116 | -------------------------------------------------------------------------------- /src/drw_classes.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DRW_CLASSES_H 14 | #define DRW_CLASSES_H 15 | 16 | 17 | #include "drw_base.h" 18 | //#include "libdwgr.h" 19 | 20 | class dxfReader; 21 | class dxfWriter; 22 | class dwgBuffer; 23 | 24 | //! Class to handle classes entries 25 | /*! 26 | * Class to handle classes table entries 27 | * TODO: verify the dxf read/write part 28 | * @author Rallaz 29 | */ 30 | class DRW_Class { 31 | public: 32 | DRW_Class() { 33 | } 34 | ~DRW_Class() { 35 | } 36 | 37 | void parseCode(int code, dxfReader *reader); 38 | void write(dxfWriter *writer, DRW::Version ver); 39 | bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *strBuf); 40 | 41 | private: 42 | void toDwgType(); 43 | public: 44 | UTF8STRING recName; /*!< record name, code 1 */ 45 | UTF8STRING className; /*!< C++ class name, code 2 */ 46 | UTF8STRING appName; /*!< app name, code 3 */ 47 | int proxyFlag; /*!< Proxy capabilities flag, code 90 */ 48 | int instanceCount; /*!< number of instances for a custom class, code 91*/ 49 | int wasaProxyFlag; /*!< proxy flag (app loaded on save), code 280 */ 50 | int entityFlag; /*!< entity flag, code 281 (0 object, 1 entity)*/ 51 | public: //only for read dwg 52 | duint16 classNum; 53 | int dwgType; 54 | }; 55 | 56 | #endif 57 | 58 | // EOF 59 | 60 | -------------------------------------------------------------------------------- /src/drw_header.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DRW_HEADER_H 14 | #define DRW_HEADER_H 15 | 16 | 17 | #include 18 | #include "drw_base.h" 19 | 20 | class dxfReader; 21 | class dxfWriter; 22 | class dwgBuffer; 23 | 24 | #define SETHDRFRIENDS friend class dxfRW; \ 25 | friend class dwgReader; 26 | 27 | //! Class to handle header entries 28 | /*! 29 | * Class to handle header vars, to read iterate over "std::map vars" 30 | * to write add a DRW_Variant* into "std::map vars" (do not delete it, are cleared in dtor) 31 | * or use add* helper functions. 32 | * @author Rallaz 33 | */ 34 | class DRW_Header { 35 | SETHDRFRIENDS 36 | public: 37 | DRW_Header(); 38 | ~DRW_Header() { 39 | clearVars(); 40 | } 41 | 42 | DRW_Header(const DRW_Header& h){ 43 | this->version = h.version; 44 | this->comments = h.comments; 45 | for (std::map::const_iterator it=h.vars.begin(); it!=h.vars.end(); ++it){ 46 | this->vars[it->first] = new DRW_Variant( *(it->second) ); 47 | } 48 | this->curr = NULL; 49 | } 50 | DRW_Header& operator=(const DRW_Header &h) { 51 | if(this != &h) { 52 | clearVars(); 53 | this->version = h.version; 54 | this->comments = h.comments; 55 | for (std::map::const_iterator it=h.vars.begin(); it!=h.vars.end(); ++it){ 56 | this->vars[it->first] = new DRW_Variant( *(it->second) ); 57 | } 58 | } 59 | return *this; 60 | } 61 | 62 | void addDouble(std::string key, double value, int code); 63 | void addInt(std::string key, int value, int code); 64 | void addStr(std::string key, std::string value, int code); 65 | void addCoord(std::string key, DRW_Coord value, int code); 66 | std::string getComments() const {return comments;} 67 | void write(dxfWriter *writer, DRW::Version ver); 68 | void addComment(std::string c); 69 | 70 | protected: 71 | void parseCode(int code, dxfReader *reader); 72 | bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf, duint8 mv=0); 73 | private: 74 | bool getDouble(std::string key, double *varDouble); 75 | bool getInt(std::string key, int *varInt); 76 | bool getStr(std::string key, std::string *varStr); 77 | bool getCoord(std::string key, DRW_Coord *varStr); 78 | void clearVars(){ 79 | for (std::map::iterator it=vars.begin(); it!=vars.end(); ++it) 80 | delete it->second; 81 | 82 | vars.clear(); 83 | } 84 | 85 | public: 86 | std::map vars; 87 | private: 88 | std::string comments; 89 | std::string name; 90 | DRW_Variant* curr; 91 | int version; //to use on read 92 | 93 | duint32 linetypeCtrl; 94 | duint32 layerCtrl; 95 | duint32 styleCtrl; 96 | duint32 dimstyleCtrl; 97 | duint32 appidCtrl; 98 | duint32 blockCtrl; 99 | duint32 viewCtrl; 100 | duint32 ucsCtrl; 101 | duint32 vportCtrl; 102 | duint32 vpEntHeaderCtrl; 103 | }; 104 | 105 | #endif 106 | 107 | // EOF 108 | 109 | -------------------------------------------------------------------------------- /src/drw_interface.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DRW_INTERFACE_H 14 | #define DRW_INTERFACE_H 15 | 16 | #include 17 | 18 | #include "drw_entities.h" 19 | #include "drw_objects.h" 20 | #include "drw_header.h" 21 | 22 | /** 23 | * Abstract class (interface) for comunicate dxfReader with the application. 24 | * Inherit your class which takes care of the entities in the 25 | * processed DXF file from this interface. 26 | * 27 | * @author Rallaz 28 | */ 29 | class DRW_Interface { 30 | public: 31 | DRW_Interface() { 32 | } 33 | virtual ~DRW_Interface() { 34 | } 35 | 36 | /** Called when header is parsed. */ 37 | virtual void addHeader(const DRW_Header* data) = 0; 38 | 39 | /** Called for every line Type. */ 40 | virtual void addLType(const DRW_LType& data) = 0; 41 | /** Called for every layer. */ 42 | virtual void addLayer(const DRW_Layer& data) = 0; 43 | /** Called for every dim style. */ 44 | virtual void addDimStyle(const DRW_Dimstyle& data) = 0; 45 | /** Called for every VPORT table. */ 46 | virtual void addVport(const DRW_Vport& data) = 0; 47 | /** Called for every text style. */ 48 | virtual void addTextStyle(const DRW_Textstyle& data) = 0; 49 | /** Called for every AppId entry. */ 50 | virtual void addAppId(const DRW_AppId& data) = 0; 51 | 52 | /** 53 | * Called for every block. Note: all entities added after this 54 | * command go into this block until endBlock() is called. 55 | * 56 | * @see endBlock() 57 | */ 58 | virtual void addBlock(const DRW_Block& data) = 0; 59 | 60 | /** 61 | * In DWG called when the following entities corresponding to a 62 | * block different from the current. Note: all entities added after this 63 | * command go into this block until setBlock() is called already. 64 | * 65 | * int handle are the value of DRW_Block::handleBlock added with addBlock() 66 | */ 67 | virtual void setBlock(const int handle) = 0; 68 | 69 | /** Called to end the current block */ 70 | virtual void endBlock() = 0; 71 | 72 | /** Called for every point */ 73 | virtual void addPoint(const DRW_Point& data) = 0; 74 | 75 | /** Called for every line */ 76 | virtual void addLine(const DRW_Line& data) = 0; 77 | 78 | /** Called for every ray */ 79 | virtual void addRay(const DRW_Ray& data) = 0; 80 | 81 | /** Called for every xline */ 82 | virtual void addXline(const DRW_Xline& data) = 0; 83 | 84 | /** Called for every arc */ 85 | virtual void addArc(const DRW_Arc& data) = 0; 86 | 87 | /** Called for every circle */ 88 | virtual void addCircle(const DRW_Circle& data) = 0; 89 | 90 | /** Called for every ellipse */ 91 | virtual void addEllipse(const DRW_Ellipse& data) = 0; 92 | 93 | /** Called for every lwpolyline */ 94 | virtual void addLWPolyline(const DRW_LWPolyline& data) = 0; 95 | 96 | /** Called for every polyline start */ 97 | virtual void addPolyline(const DRW_Polyline& data) = 0; 98 | 99 | /** Called for every spline */ 100 | virtual void addSpline(const DRW_Spline* data) = 0; 101 | 102 | /** Called for every spline knot value */ 103 | virtual void addKnot(const DRW_Entity& data) = 0; 104 | 105 | /** Called for every insert. */ 106 | virtual void addInsert(const DRW_Insert& data) = 0; 107 | 108 | /** Called for every trace start */ 109 | virtual void addTrace(const DRW_Trace& data) = 0; 110 | 111 | /** Called for every 3dface start */ 112 | virtual void add3dFace(const DRW_3Dface& data) = 0; 113 | 114 | /** Called for every solid start */ 115 | virtual void addSolid(const DRW_Solid& data) = 0; 116 | 117 | 118 | /** Called for every Multi Text entity. */ 119 | virtual void addMText(const DRW_MText& data) = 0; 120 | 121 | /** Called for every Text entity. */ 122 | virtual void addText(const DRW_Text& data) = 0; 123 | 124 | /** 125 | * Called for every aligned dimension entity. 126 | */ 127 | virtual void addDimAlign(const DRW_DimAligned *data) = 0; 128 | /** 129 | * Called for every linear or rotated dimension entity. 130 | */ 131 | virtual void addDimLinear(const DRW_DimLinear *data) = 0; 132 | 133 | /** 134 | * Called for every radial dimension entity. 135 | */ 136 | virtual void addDimRadial(const DRW_DimRadial *data) = 0; 137 | 138 | /** 139 | * Called for every diametric dimension entity. 140 | */ 141 | virtual void addDimDiametric(const DRW_DimDiametric *data) = 0; 142 | 143 | /** 144 | * Called for every angular dimension (2 lines version) entity. 145 | */ 146 | virtual void addDimAngular(const DRW_DimAngular *data) = 0; 147 | 148 | /** 149 | * Called for every angular dimension (3 points version) entity. 150 | */ 151 | virtual void addDimAngular3P(const DRW_DimAngular3p *data) = 0; 152 | 153 | /** 154 | * Called for every ordinate dimension entity. 155 | */ 156 | virtual void addDimOrdinate(const DRW_DimOrdinate *data) = 0; 157 | 158 | /** 159 | * Called for every leader start. 160 | */ 161 | virtual void addLeader(const DRW_Leader *data) = 0; 162 | 163 | /** 164 | * Called for every hatch entity. 165 | */ 166 | virtual void addHatch(const DRW_Hatch *data) = 0; 167 | 168 | /** 169 | * Called for every viewport entity. 170 | */ 171 | virtual void addViewport(const DRW_Viewport& data) = 0; 172 | 173 | /** 174 | * Called for every image entity. 175 | */ 176 | virtual void addImage(const DRW_Image *data) = 0; 177 | 178 | /** 179 | * Called for every image definition. 180 | */ 181 | virtual void linkImage(const DRW_ImageDef *data) = 0; 182 | 183 | /** 184 | * Called for every comment in the DXF file (code 999). 185 | */ 186 | virtual void addComment(const char* comment) = 0; 187 | 188 | virtual void writeHeader(DRW_Header& data) = 0; 189 | virtual void writeBlocks() = 0; 190 | virtual void writeBlockRecords() = 0; 191 | virtual void writeEntities() = 0; 192 | virtual void writeLTypes() = 0; 193 | virtual void writeLayers() = 0; 194 | virtual void writeTextstyles() = 0; 195 | virtual void writeVports() = 0; 196 | virtual void writeDimstyles() = 0; 197 | virtual void writeAppId() = 0; 198 | }; 199 | 200 | #endif 201 | -------------------------------------------------------------------------------- /src/intern/drw_dbg.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include "drw_dbg.h" 16 | 17 | DRW_dbg *DRW_dbg::instance= NULL; 18 | 19 | /*********private clases*************/ 20 | class print_none { 21 | public: 22 | virtual void printS(std::string s){(void)s;} 23 | virtual void printI(long long int i){(void)i;} 24 | virtual void printUI(long long unsigned int i){(void)i;} 25 | virtual void printD(double d){(void)d;} 26 | virtual void printH(long long int i){(void)i;} 27 | virtual void printB(int i){(void)i;} 28 | virtual void printHL(int c, int s, int h){(void)c;(void)s;(void)h;} 29 | virtual void printPT(double x, double y, double z){(void)x;(void)y;(void)z;} 30 | print_none(){} 31 | virtual ~print_none(){} 32 | }; 33 | 34 | class print_debug : public print_none { 35 | public: 36 | virtual void printS(std::string s); 37 | virtual void printI(long long int i); 38 | virtual void printUI(long long unsigned int i); 39 | virtual void printD(double d); 40 | virtual void printH(long long int i); 41 | virtual void printB(int i); 42 | virtual void printHL(int c, int s, int h); 43 | virtual void printPT(double x, double y, double z); 44 | print_debug(); 45 | virtual ~print_debug(){} 46 | private: 47 | std::ios_base::fmtflags flags; 48 | }; 49 | 50 | /********* debug class *************/ 51 | DRW_dbg *DRW_dbg::getInstance(){ 52 | if (instance == NULL){ 53 | instance = new DRW_dbg; 54 | } 55 | return instance; 56 | } 57 | 58 | DRW_dbg::DRW_dbg(){ 59 | level = NONE; 60 | prClass = new print_none; 61 | flags = std::cerr.flags(); 62 | } 63 | 64 | void DRW_dbg::setLevel(LEVEL lvl){ 65 | level = lvl; 66 | delete prClass; 67 | switch (level){ 68 | case DEBUG: 69 | prClass = new print_debug; 70 | break; 71 | default: 72 | prClass = new print_none; 73 | } 74 | } 75 | 76 | DRW_dbg::LEVEL DRW_dbg::getLevel(){ 77 | return level; 78 | } 79 | 80 | void DRW_dbg::print(std::string s){ 81 | prClass->printS(s); 82 | } 83 | 84 | void DRW_dbg::print(int i){ 85 | prClass->printI(i); 86 | } 87 | 88 | void DRW_dbg::print(unsigned int i){ 89 | prClass->printUI(i); 90 | } 91 | 92 | void DRW_dbg::print(long long int i){ 93 | prClass->printI(i); 94 | } 95 | 96 | void DRW_dbg::print(long unsigned int i){ 97 | prClass->printUI(i); 98 | } 99 | 100 | void DRW_dbg::print(long long unsigned int i){ 101 | prClass->printUI(i); 102 | } 103 | 104 | void DRW_dbg::print(double d){ 105 | prClass->printD(d); 106 | } 107 | 108 | void DRW_dbg::printH(long long int i){ 109 | prClass->printH(i); 110 | } 111 | 112 | void DRW_dbg::printB(int i){ 113 | prClass->printB(i); 114 | } 115 | void DRW_dbg::printHL(int c, int s, int h){ 116 | prClass->printHL(c, s, h); 117 | } 118 | 119 | void DRW_dbg::printPT(double x, double y, double z){ 120 | prClass->printPT(x, y, z); 121 | } 122 | 123 | print_debug::print_debug(){ 124 | flags = std::cerr.flags(); 125 | } 126 | 127 | void print_debug::printS(std::string s){ 128 | std::cerr << s; 129 | } 130 | 131 | void print_debug::printI(long long int i){ 132 | std::cerr << i; 133 | } 134 | 135 | void print_debug::printUI(long long unsigned int i){ 136 | std::cerr << i; 137 | } 138 | 139 | void print_debug::printD(double d){ 140 | std::cerr << std::fixed << d; 141 | } 142 | 143 | void print_debug::printH(long long i){ 144 | std::cerr << "0x" << std::setw(2) << std::setfill('0'); 145 | std::cerr << std::hex << i; 146 | std::cerr.flags(flags); 147 | } 148 | 149 | void print_debug::printB(int i){ 150 | std::cerr << std::setw(8) << std::setfill('0'); 151 | std::cerr << std::setbase(2) << i; 152 | std::cerr.flags(flags); 153 | } 154 | 155 | void print_debug::printHL(int c, int s, int h){ 156 | std::cerr << c << '.' << s << '.'; 157 | std::cerr << "0x" << std::setw(2) << std::setfill('0'); 158 | std::cerr << std::hex << h; 159 | std::cerr.flags(flags); 160 | } 161 | 162 | void print_debug::printPT(double x, double y, double z){ 163 | std::cerr << std::fixed << "x: " << x << ", y: " << y << ", z: "<< z; 164 | } 165 | -------------------------------------------------------------------------------- /src/intern/drw_dbg.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DRW_DBG_H 14 | #define DRW_DBG_H 15 | 16 | #include 17 | #include 18 | //#include 19 | 20 | #define DRW_DBGSL(a) DRW_dbg::getInstance()->setLevel(a) 21 | #define DRW_DBGGL DRW_dbg::getInstance()->getLevel() 22 | #define DRW_DBG(a) DRW_dbg::getInstance()->print(a) 23 | #define DRW_DBGH(a) DRW_dbg::getInstance()->printH(a) 24 | #define DRW_DBGB(a) DRW_dbg::getInstance()->printB(a) 25 | #define DRW_DBGHL(a, b, c) DRW_dbg::getInstance()->printHL(a, b ,c) 26 | #define DRW_DBGPT(a, b, c) DRW_dbg::getInstance()->printPT(a, b, c) 27 | 28 | 29 | class print_none; 30 | 31 | class DRW_dbg { 32 | public: 33 | enum LEVEL { 34 | NONE, 35 | DEBUG 36 | }; 37 | void setLevel(LEVEL lvl); 38 | LEVEL getLevel(); 39 | static DRW_dbg *getInstance(); 40 | void print(std::string s); 41 | void print(int i); 42 | void print(unsigned int i); 43 | void print(long long int i); 44 | void print(long unsigned int i); 45 | void print(long long unsigned int i); 46 | void print(double d); 47 | void printH(long long int i); 48 | void printB(int i); 49 | void printHL(int c, int s, int h); 50 | void printPT(double x, double y, double z); 51 | 52 | private: 53 | DRW_dbg(); 54 | static DRW_dbg *instance; 55 | LEVEL level; 56 | std::ios_base::fmtflags flags; 57 | print_none* prClass; 58 | }; 59 | 60 | 61 | #endif // DRW_DBG_H 62 | -------------------------------------------------------------------------------- /src/intern/drw_textcodec.h: -------------------------------------------------------------------------------- 1 | #ifndef DRW_TEXTCODEC_H 2 | #define DRW_TEXTCODEC_H 3 | 4 | #include 5 | 6 | class DRW_Converter; 7 | 8 | class DRW_TextCodec 9 | { 10 | public: 11 | DRW_TextCodec(); 12 | ~DRW_TextCodec(); 13 | std::string fromUtf8(std::string s); 14 | std::string toUtf8(std::string s); 15 | int getVersion(){return version;} 16 | void setVersion(std::string *v, bool dxfFormat); 17 | void setVersion(int v, bool dxfFormat); 18 | void setCodePage(std::string *c, bool dxfFormat); 19 | void setCodePage(std::string c, bool dxfFormat){setCodePage(&c, dxfFormat);} 20 | std::string getCodePage(){return cp;} 21 | 22 | private: 23 | std::string correctCodePage(const std::string& s); 24 | 25 | private: 26 | int version; 27 | std::string cp; 28 | DRW_Converter *conv; 29 | }; 30 | 31 | class DRW_Converter 32 | { 33 | public: 34 | DRW_Converter(const int *t, int l){table = t; 35 | cpLenght = l;} 36 | virtual ~DRW_Converter(){} 37 | virtual std::string fromUtf8(std::string *s) {return *s;} 38 | virtual std::string toUtf8(std::string *s); 39 | std::string encodeText(std::string stmp); 40 | std::string decodeText(int c); 41 | std::string encodeNum(int c); 42 | int decodeNum(std::string s, int *b); 43 | const int *table; 44 | int cpLenght; 45 | }; 46 | 47 | class DRW_ConvUTF16 : public DRW_Converter { 48 | public: 49 | DRW_ConvUTF16():DRW_Converter(NULL, 0) {} 50 | virtual std::string fromUtf8(std::string *s); 51 | virtual std::string toUtf8(std::string *s); 52 | }; 53 | 54 | class DRW_ConvTable : public DRW_Converter { 55 | public: 56 | DRW_ConvTable(const int *t, int l):DRW_Converter(t, l) {} 57 | virtual std::string fromUtf8(std::string *s); 58 | virtual std::string toUtf8(std::string *s); 59 | }; 60 | 61 | class DRW_ConvDBCSTable : public DRW_Converter { 62 | public: 63 | DRW_ConvDBCSTable(const int *t, const int *lt, const int dt[][2], int l):DRW_Converter(t, l) { 64 | leadTable = lt; 65 | doubleTable = dt; 66 | } 67 | 68 | virtual std::string fromUtf8(std::string *s); 69 | virtual std::string toUtf8(std::string *s); 70 | private: 71 | const int *leadTable; 72 | const int (*doubleTable)[2]; 73 | 74 | }; 75 | 76 | class DRW_Conv932Table : public DRW_Converter { 77 | public: 78 | DRW_Conv932Table(const int *t, const int *lt, const int dt[][2], int l):DRW_Converter(t, l) { 79 | leadTable = lt; 80 | doubleTable = dt; 81 | } 82 | 83 | virtual std::string fromUtf8(std::string *s); 84 | virtual std::string toUtf8(std::string *s); 85 | private: 86 | const int *leadTable; 87 | const int (*doubleTable)[2]; 88 | 89 | }; 90 | 91 | class DRW_ExtConverter : public DRW_Converter { 92 | public: 93 | DRW_ExtConverter(const char *enc):DRW_Converter(NULL, 0) { 94 | encoding = enc; 95 | } 96 | virtual std::string fromUtf8(std::string *s); 97 | virtual std::string toUtf8(std::string *s); 98 | private: 99 | const char *encoding; 100 | std::string convertByiconv(const char *in_encode, 101 | const char *out_encode, 102 | const std::string *s); 103 | }; 104 | 105 | #endif // DRW_TEXTCODEC_H 106 | -------------------------------------------------------------------------------- /src/intern/dwgbuffer.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DWGBUFFER_H 14 | #define DWGBUFFER_H 15 | 16 | #include 17 | #include 18 | #include "../drw_base.h" 19 | 20 | class DRW_Coord; 21 | class DRW_TextCodec; 22 | 23 | class dwgBasicStream{ 24 | protected: 25 | dwgBasicStream(){} 26 | public: 27 | virtual ~dwgBasicStream(){} 28 | virtual bool read(duint8* s, duint64 n) = 0; 29 | virtual duint64 size() = 0; 30 | virtual duint64 getPos() = 0; 31 | virtual bool setPos(duint64 p) = 0; 32 | virtual bool good() = 0; 33 | virtual dwgBasicStream* clone() = 0; 34 | }; 35 | 36 | class dwgFileStream: public dwgBasicStream{ 37 | public: 38 | dwgFileStream(std::ifstream *s){ 39 | stream =s; 40 | stream->seekg (0, std::ios::end); 41 | sz = stream->tellg(); 42 | stream->seekg(0, std::ios_base::beg); 43 | } 44 | virtual ~dwgFileStream(){} 45 | virtual bool read(duint8* s, duint64 n); 46 | virtual duint64 size(){return sz;} 47 | virtual duint64 getPos(){return stream->tellg();} 48 | virtual bool setPos(duint64 p); 49 | virtual bool good(){return stream->good();} 50 | virtual dwgBasicStream* clone(){return new dwgFileStream(stream);} 51 | private: 52 | std::ifstream *stream; 53 | duint64 sz; 54 | }; 55 | 56 | class dwgCharStream: public dwgBasicStream{ 57 | public: 58 | dwgCharStream(duint8 *buf, int s){ 59 | stream =buf; 60 | sz = s; 61 | pos = 0; 62 | isOk = true; 63 | } 64 | virtual ~dwgCharStream(){} 65 | virtual bool read(duint8* s, duint64 n); 66 | virtual duint64 size(){return sz;} 67 | virtual duint64 getPos(){return pos;} 68 | virtual bool setPos(duint64 p); 69 | virtual bool good(){return isOk;} 70 | virtual dwgBasicStream* clone(){return new dwgCharStream(stream, sz);} 71 | private: 72 | duint8 *stream; 73 | duint64 sz; 74 | duint64 pos; 75 | bool isOk; 76 | }; 77 | 78 | class dwgBuffer { 79 | public: 80 | dwgBuffer(std::ifstream *stream, DRW_TextCodec *decoder = NULL); 81 | dwgBuffer(duint8 *buf, int size, DRW_TextCodec *decoder= NULL); 82 | dwgBuffer( const dwgBuffer& org ); 83 | dwgBuffer& operator=( const dwgBuffer& org ); 84 | ~dwgBuffer(); 85 | duint64 size(){return filestr->size();} 86 | bool setPosition(duint64 pos); 87 | duint64 getPosition(); 88 | void resetPosition(){setPosition(0); setBitPos(0);} 89 | void setBitPos(duint8 pos); 90 | duint8 getBitPos(){return bitPos;} 91 | bool moveBitPos(dint32 size); 92 | 93 | duint8 getBit(); //B 94 | bool getBoolBit(); //B as bool 95 | duint8 get2Bits(); //BB 96 | duint8 get3Bits(); //3B 97 | duint16 getBitShort(); //BS 98 | dint16 getSBitShort(); //BS 99 | dint32 getBitLong(); //BL 100 | duint64 getBitLongLong(); //BLL (R24) 101 | double getBitDouble(); //BD 102 | //2BD => call BD 2 times 103 | DRW_Coord get3BitDouble(); //3BD 104 | duint8 getRawChar8(); //RC 105 | duint16 getRawShort16(); //RS 106 | double getRawDouble(); //RD 107 | duint32 getRawLong32(); //RL 108 | duint64 getRawLong64(); //RLL 109 | DRW_Coord get2RawDouble(); //2RD 110 | //3RD => call RD 3 times 111 | duint32 getUModularChar(); //UMC, unsigned for offsets in 1015 112 | dint32 getModularChar(); //MC 113 | dint32 getModularShort(); //MS 114 | dwgHandle getHandle(); //H 115 | dwgHandle getOffsetHandle(duint32 href); //H converted to hard 116 | UTF8STRING getVariableText(DRW::Version v, bool nullTerm = true); //TV => call TU for 2007+ or T for previous versions 117 | UTF8STRING getCP8Text(); //T 8 bit text converted from codepage to utf8 118 | UTF8STRING getUCSText(bool nullTerm = true); //TU unicode 16 bit (UCS) text converted to utf8 119 | UTF8STRING getUCSStr(duint16 ts); 120 | 121 | duint16 getObjType(DRW::Version v); //OT 122 | 123 | //X, U, SN, 124 | 125 | DRW_Coord getExtrusion(bool b_R2000_style); //BE 126 | double getDefaultDouble(double d); //DD 127 | double getThickness(bool b_R2000_style);//BT 128 | //3DD 129 | duint32 getCmColor(DRW::Version v); //CMC 130 | duint32 getEnColor(DRW::Version v); //ENC 131 | //TC 132 | 133 | duint16 getBERawShort16(); //RS big-endian order 134 | 135 | bool isGood(){return filestr->good();} 136 | bool getBytes(duint8 *buf, int size); 137 | int numRemainingBytes(){return (maxSize- filestr->getPos());} 138 | 139 | duint16 crc8(duint16 dx,dint32 start,dint32 end); 140 | duint32 crc32(duint32 seed,dint32 start,dint32 end); 141 | 142 | // duint8 getCurrByte(){return currByte;} 143 | DRW_TextCodec *decoder; 144 | 145 | private: 146 | dwgBasicStream *filestr; 147 | int maxSize; 148 | duint8 currByte; 149 | duint8 bitPos; 150 | 151 | UTF8STRING get8bitStr(); 152 | UTF8STRING get16bitStr(duint16 textSize, bool nullTerm = true); 153 | }; 154 | 155 | #endif // DWGBUFFER_H 156 | -------------------------------------------------------------------------------- /src/intern/dwgreader.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DWGREADER_H 14 | #define DWGREADER_H 15 | 16 | #include 17 | #include 18 | #include "drw_textcodec.h" 19 | #include "dwgutil.h" 20 | #include "dwgbuffer.h" 21 | #include "../libdwgr.h" 22 | 23 | class objHandle{ 24 | public: 25 | objHandle(){ handle = type = loc = 0; } 26 | objHandle(duint32 t, duint32 h, duint32 l){ 27 | type = t; 28 | handle = h; 29 | loc = l; 30 | } 31 | duint32 type; 32 | duint32 handle; 33 | duint32 loc; 34 | }; 35 | 36 | //until 2000 = 2000- 37 | //since 2004 except 2007 = 2004+ 38 | // 2007 = 2007 39 | // pages of section 40 | /* 2000-: No pages, only sections 41 | * 2004+: Id, page number (index) 42 | * size, size of page in file stream 43 | * address, address in file stream 44 | * dataSize, data size for this page 45 | * startOffset, start offset for this page 46 | * cSize, compresed size of data 47 | * uSize, uncompresed size of data 48 | * 2007: page Id, pageCount & pages 49 | * size, size in file 50 | * dataSize 51 | * startOffset, start position in decompresed data stream 52 | * cSize, compresed size of data 53 | * uSize, uncompresed size of data 54 | * address, address in file stream 55 | * */ 56 | class dwgPageInfo { 57 | public: 58 | dwgPageInfo(){} 59 | dwgPageInfo(duint64 i, duint64 ad, duint32 sz){ 60 | Id=i; address=ad; size=sz; 61 | } 62 | ~dwgPageInfo(){} 63 | duint64 Id; 64 | duint64 address; //in file stream, for rd18, rd21 65 | duint64 size; //in file stream, for rd18, rd21 66 | duint64 dataSize; //for rd18, rd21 67 | duint32 startOffset; //for rd18, rd21 68 | duint64 cSize; //compresed page size, for rd21 69 | duint64 uSize; //uncompresed page size, for rd21 70 | }; 71 | 72 | // sections of file 73 | /* 2000-: No pages, only section Id, size & address in file 74 | * 2004+: Id, Section Id 75 | * size, total size of uncompresed data 76 | * pageCount & pages, number of pages in section 77 | * maxSize, max decompressed Size per page 78 | * compresed, (1 = no, 2 = yes, normally 2) 79 | * encrypted, (0 = no, 1 = yes, 2 = unknown) 80 | * name, read & stored but not used 81 | * 2007: same as 2004+ except encoding, saved in compresed field 82 | * */ 83 | class dwgSectionInfo { 84 | public: 85 | dwgSectionInfo(){ 86 | compresed = 1;//1=no, 2=yes 87 | encrypted = 0;//??? 88 | pageCount = 0; 89 | Id=-1; 90 | } 91 | ~dwgSectionInfo(){} 92 | dint32 Id; //section Id, 2000- rd15 rd18 93 | std::string name; //section name rd18 94 | duint32 compresed;//is compresed? 1=no, 2=yes rd18, rd21(encoding) 95 | duint32 encrypted;//encrypted (doc: 0=no, 1=yes, 2=unkn) on read: objects 0 and encrypted yes rd18 96 | std::mappages;//index, size, offset 97 | duint64 size;//size of section, 2000- rd15, rd18, rd21 (data size) 98 | duint64 pageCount; //number of pages (dwgPageInfo) in section rd18, rd21 99 | duint64 maxSize; //max decompressed size (needed??) rd18 rd21 100 | duint64 address; //address (seek) , 2000- 101 | }; 102 | 103 | 104 | //! Class to handle dwg obj control entries 105 | /*! 106 | * Class to handle dwg obj control entries 107 | * @author Rallaz 108 | */ 109 | class DRW_ObjControl : public DRW_TableEntry { 110 | public: 111 | DRW_ObjControl() { reset();} 112 | 113 | void reset(){ 114 | } 115 | bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); 116 | std::listhadlesList; 117 | }; 118 | 119 | 120 | class dwgReader { 121 | friend class dwgR; 122 | public: 123 | dwgReader(std::ifstream *stream, dwgR *p){ 124 | fileBuf = new dwgBuffer(stream); 125 | parent = p; 126 | decoder.setVersion(DRW::AC1021, false);//default 2007 in utf8(no convert) 127 | decoder.setCodePage("UTF-16", false); 128 | // blockCtrl=0; //RLZ: temporary 129 | // blockCtrl=layerCtrl=styleCtrl=linetypeCtrl=viewCtrl=0; 130 | // ucsCtrl=vportCtrl=appidCtrl=dimstyleCtrl=vpEntHeaderCtrl=0; 131 | nextEntLink = prevEntLink = 0; 132 | maintenanceVersion=0; 133 | } 134 | virtual ~dwgReader(); 135 | 136 | protected: 137 | virtual bool readMetaData() = 0; 138 | virtual bool readPreview(){return false;} 139 | virtual bool readFileHeader() = 0; 140 | virtual bool readDwgHeader(DRW_Header& hdr)=0; 141 | virtual bool readDwgClasses() = 0; 142 | virtual bool readDwgHandles() = 0; 143 | virtual bool readDwgTables(DRW_Header& hdr)=0; 144 | virtual bool readDwgBlocks(DRW_Interface& intfa) = 0; 145 | virtual bool readDwgEntities(DRW_Interface& intfa) = 0; 146 | virtual bool readDwgObjects(DRW_Interface& intfa) = 0; 147 | 148 | virtual bool readDwgEntity(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa); 149 | bool readDwgObject(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa); 150 | void parseAttribs(DRW_Entity* e); 151 | std::string findTableName(DRW::TTYPE table, dint32 handle); 152 | 153 | void setCodePage(std::string *c){decoder.setCodePage(c, false);} 154 | std::string getCodePage(){ return decoder.getCodePage();} 155 | bool readDwgHeader(DRW_Header& hdr, dwgBuffer *buf, dwgBuffer *hBuf); 156 | bool readDwgHandles(dwgBuffer *dbuf, duint32 offset, duint32 size); 157 | bool readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf); 158 | bool checkSentinel(dwgBuffer *buf, enum secEnum::DWGSection, bool start); 159 | 160 | bool readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf); 161 | bool readDwgEntities(DRW_Interface& intfa, dwgBuffer *dbuf); 162 | bool readDwgObjects(DRW_Interface& intfa, dwgBuffer *dbuf); 163 | bool readPlineVertex(DRW_Polyline& pline, dwgBuffer *dbuf); 164 | 165 | public: 166 | std::mapObjectMap; 167 | std::mapobjObjectMap; //stores the ojects & entities not read in readDwgEntities 168 | std::mapremainingMap; //stores the ojects & entities not read in all proces, for debug only 169 | std::map ltypemap; 170 | std::map layermap; 171 | std::map blockmap; 172 | std::map stylemap; 173 | std::map dimstylemap; 174 | std::map vportmap; 175 | std::map blockRecordmap; 176 | std::map appIdmap; 177 | // duint32 currBlock; 178 | duint8 maintenanceVersion; 179 | 180 | protected: 181 | dwgBuffer *fileBuf; 182 | dwgR *parent; 183 | DRW::Version version; 184 | 185 | //seeker (position) for the beginning sentinel of the image data (R13 to R15) 186 | duint32 previewImagePos; 187 | 188 | //sections map 189 | std::mapsections; 190 | std::map classesmap; 191 | 192 | protected: 193 | DRW_TextCodec decoder; 194 | 195 | protected: 196 | // duint32 blockCtrl; 197 | duint32 nextEntLink; 198 | duint32 prevEntLink; 199 | }; 200 | 201 | 202 | 203 | #endif // DWGREADER_H 204 | -------------------------------------------------------------------------------- /src/intern/dwgreader15.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "drw_dbg.h" 19 | #include "dwgreader15.h" 20 | #include "drw_textcodec.h" 21 | #include "../libdwgr.h" 22 | 23 | bool dwgReader15::readMetaData() { 24 | version = parent->getVersion(); 25 | decoder.setVersion(version, false); 26 | DRW_DBG("dwgReader15::readMetaData\n"); 27 | if (! fileBuf->setPosition(13)) 28 | return false; 29 | previewImagePos = fileBuf->getRawLong32(); 30 | DRW_DBG("previewImagePos (seekerImageData) = "); DRW_DBG(previewImagePos); 31 | /* MEASUREMENT system variable 2 bytes*/ 32 | duint16 meas = fileBuf->getRawShort16(); 33 | DRW_DBG("\nMEASUREMENT (0 = English, 1 = Metric)= "); DRW_DBG(meas); 34 | duint16 cp = fileBuf->getRawShort16(); 35 | DRW_DBG("\ncodepage= "); DRW_DBG(cp); DRW_DBG("\n"); 36 | if (cp == 29) //TODO RLZ: locate wath code page and correct this 37 | decoder.setCodePage("ANSI_1252", false); 38 | if (cp == 30) 39 | decoder.setCodePage("ANSI_1252", false); 40 | return true; 41 | } 42 | 43 | bool dwgReader15::readFileHeader() { 44 | bool ret = true; 45 | DRW_DBG("dwgReader15::readFileHeader\n"); 46 | if (! fileBuf->setPosition(21)) 47 | return false; 48 | duint32 count = fileBuf->getRawLong32(); 49 | DRW_DBG("count records= "); DRW_DBG(count); DRW_DBG("\n"); 50 | 51 | for (unsigned int i = 0; i < count; i++) { 52 | duint8 rec = fileBuf->getRawChar8(); 53 | duint32 address = fileBuf->getRawLong32(); 54 | duint32 size = fileBuf->getRawLong32(); 55 | dwgSectionInfo si; 56 | si.Id = rec; 57 | si.size = size; 58 | si.address = address; 59 | if (rec == 0) { 60 | DRW_DBG("\nSection HEADERS address= "); 61 | DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); 62 | sections[secEnum::HEADER] = si; 63 | } else if (rec == 1) { 64 | DRW_DBG("\nSection CLASSES address= "); 65 | DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); 66 | sections[secEnum::CLASSES] = si; 67 | } else if (rec == 2) { 68 | DRW_DBG("\nSection OBJECTS (handles) address= "); 69 | DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); 70 | sections[secEnum::HANDLES] = si; 71 | } else if (rec == 3) { 72 | DRW_DBG("\nSection UNKNOWN address= "); 73 | DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); 74 | sections[secEnum::UNKNOWNS] = si; 75 | } else if (rec == 4) { 76 | DRW_DBG("\nSection R14DATA (AcDb:Template) address= "); 77 | DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); 78 | sections[secEnum::TEMPLATE] = si; 79 | } else if (rec == 5) { 80 | DRW_DBG("\nSection R14REC5 (AcDb:AuxHeader) address= "); 81 | DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); 82 | sections[secEnum::AUXHEADER] = si; 83 | } else { 84 | std::cerr << "\nUnsupported section number\n"; 85 | } 86 | } 87 | if (! fileBuf->isGood()) 88 | return false; 89 | DRW_DBG("\nposition after read section locator records= "); DRW_DBG(fileBuf->getPosition()); 90 | DRW_DBG(", bit are= "); DRW_DBG(fileBuf->getBitPos()); 91 | duint32 ckcrc = fileBuf->crc8(0,0,fileBuf->getPosition()); 92 | DRW_DBG("\nfile header crc8 0 result= "); DRW_DBG(ckcrc); 93 | switch (count){ 94 | case 3: 95 | ckcrc = ckcrc ^ 0xA598; 96 | break; 97 | case 4: 98 | ckcrc = ckcrc ^ 0x8101; 99 | break; 100 | case 5: 101 | ckcrc = ckcrc ^ 0x3CC4; 102 | break; 103 | case 6: 104 | ckcrc = ckcrc ^ 0x8461; 105 | } 106 | DRW_DBG("\nfile header crc8 xor result= "); DRW_DBG(ckcrc); 107 | DRW_DBG("\nfile header CRC= "); DRW_DBG(fileBuf->getRawShort16()); 108 | DRW_DBG("\nfile header sentinel= "); 109 | checkSentinel(fileBuf, secEnum::FILEHEADER, false); 110 | 111 | DRW_DBG("\nposition after read file header sentinel= "); DRW_DBG(fileBuf->getPosition()); 112 | DRW_DBG(", bit are= "); DRW_DBG(fileBuf->getBitPos()); 113 | 114 | DRW_DBG("\ndwgReader15::readFileHeader END\n"); 115 | return ret; 116 | } 117 | 118 | bool dwgReader15::readDwgHeader(DRW_Header& hdr){ 119 | DRW_DBG("dwgReader15::readDwgHeader\n"); 120 | dwgSectionInfo si = sections[secEnum::HEADER]; 121 | if (si.Id<0)//not found, ends 122 | return false; 123 | if (!fileBuf->setPosition(si.address)) 124 | return false; 125 | duint8 *tmpByteStr = new duint8[si.size]; 126 | fileBuf->getBytes(tmpByteStr, si.size); 127 | dwgBuffer buff(tmpByteStr, si.size, &decoder); 128 | DRW_DBG("Header section sentinel= "); 129 | checkSentinel(&buff, secEnum::HEADER, true); 130 | bool ret = dwgReader::readDwgHeader(hdr, &buff, &buff); 131 | delete[]tmpByteStr; 132 | return ret; 133 | } 134 | 135 | 136 | bool dwgReader15::readDwgClasses(){ 137 | DRW_DBG("\ndwgReader15::readDwgClasses\n"); 138 | dwgSectionInfo si = sections[secEnum::CLASSES]; 139 | if (si.Id<0)//not found, ends 140 | return false; 141 | if (!fileBuf->setPosition(si.address)) 142 | return false; 143 | 144 | DRW_DBG("classes section sentinel= "); 145 | checkSentinel(fileBuf, secEnum::CLASSES, true); 146 | 147 | duint32 size = fileBuf->getRawLong32(); 148 | if (size != (si.size - 38)) { 149 | DRW_DBG("\nWARNING dwgReader15::readDwgClasses size are "); DRW_DBG(size); 150 | DRW_DBG(" and secSize - 38 are "); DRW_DBG(si.size - 38); DRW_DBG("\n"); 151 | } 152 | duint8 *tmpByteStr = new duint8[size]; 153 | fileBuf->getBytes(tmpByteStr, size); 154 | dwgBuffer buff(tmpByteStr, size, &decoder); 155 | size--; //reduce 1 byte instead of check pos + bitPos 156 | while (size > buff.getPosition()) { 157 | DRW_Class *cl = new DRW_Class(); 158 | cl->parseDwg(version, &buff, &buff); 159 | classesmap[cl->classNum] = cl; 160 | } 161 | DRW_DBG("\nCRC: "); DRW_DBGH(fileBuf->getRawShort16()); 162 | DRW_DBG("\nclasses section end sentinel= "); 163 | checkSentinel(fileBuf, secEnum::CLASSES, false); 164 | bool ret = buff.isGood(); 165 | delete[]tmpByteStr; 166 | return ret; 167 | } 168 | 169 | bool dwgReader15::readDwgHandles() { 170 | DRW_DBG("\ndwgReader15::readDwgHandles\n"); 171 | dwgSectionInfo si = sections[secEnum::HANDLES]; 172 | if (si.Id<0)//not found, ends 173 | return false; 174 | 175 | bool ret = dwgReader::readDwgHandles(fileBuf, si.address, si.size); 176 | return ret; 177 | } 178 | 179 | /*********** objects ************************/ 180 | /** 181 | * Reads all the object referenced in the object map section of the DWG file 182 | * (using their object file offsets) 183 | */ 184 | bool dwgReader15::readDwgTables(DRW_Header& hdr) { 185 | bool ret = dwgReader::readDwgTables(hdr, fileBuf); 186 | 187 | return ret; 188 | } 189 | 190 | /** 191 | * Reads all the object referenced in the object map section of the DWG file 192 | * (using their object file offsets) 193 | */ 194 | bool dwgReader15::readDwgBlocks(DRW_Interface& intfa) { 195 | bool ret = true; 196 | ret = dwgReader::readDwgBlocks(intfa, fileBuf); 197 | return ret; 198 | } 199 | 200 | -------------------------------------------------------------------------------- /src/intern/dwgreader15.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DWGREADER15_H 14 | #define DWGREADER15_H 15 | 16 | #include 17 | #include 18 | #include "drw_textcodec.h" 19 | #include "dwgbuffer.h" 20 | #include "dwgreader.h" 21 | 22 | class dwgReader15 : public dwgReader { 23 | public: 24 | dwgReader15(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ } 25 | virtual ~dwgReader15() {} 26 | bool readMetaData(); 27 | bool readFileHeader(); 28 | bool readDwgHeader(DRW_Header& hdr); 29 | bool readDwgClasses(); 30 | bool readDwgHandles(); 31 | bool readDwgTables(DRW_Header& hdr); 32 | bool readDwgBlocks(DRW_Interface& intfa); 33 | bool readDwgEntities(DRW_Interface& intfa){ 34 | bool ret = true; 35 | ret = dwgReader::readDwgEntities(intfa, fileBuf); 36 | return ret; 37 | } 38 | bool readDwgObjects(DRW_Interface& intfa){ 39 | bool ret = true; 40 | ret = dwgReader::readDwgObjects(intfa, fileBuf); 41 | return ret; 42 | } 43 | // bool readDwgEntity(objHandle& obj, DRW_Interface& intfa); 44 | }; 45 | 46 | 47 | #endif // DWGREADER15_H 48 | -------------------------------------------------------------------------------- /src/intern/dwgreader18.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DWGREADER18_H 14 | #define DWGREADER18_H 15 | 16 | #include 17 | #include 18 | #include "dwgreader.h" 19 | //#include "../drw_textcodec.h" 20 | #include "dwgbuffer.h" 21 | 22 | static const int DRW_magicNum18[] = { 23 | 0x29, 0x23, 0xbe, 0x84, 0xe1, 0x6c, 0xd6, 0xae, 24 | 0x52, 0x90, 0x49, 0xf1, 0xf1, 0xbb, 0xe9, 0xeb, 25 | 0xb3, 0xa6, 0xdb, 0x3c, 0x87, 0x0c, 0x3e, 0x99, 26 | 0x24, 0x5e, 0x0d, 0x1c, 0x06, 0xb7, 0x47, 0xde, 27 | 0xb3, 0x12, 0x4d, 0xc8, 0x43, 0xbb, 0x8b, 0xa6, 28 | 0x1f, 0x03, 0x5a, 0x7d, 0x09, 0x38, 0x25, 0x1f, 29 | 0x5d, 0xd4, 0xcb, 0xfc, 0x96, 0xf5, 0x45, 0x3b, 30 | 0x13, 0x0d, 0x89, 0x0a, 0x1c, 0xdb, 0xae, 0x32, 31 | 0x20, 0x9a, 0x50, 0xee, 0x40, 0x78, 0x36, 0xfd, 32 | 0x12, 0x49, 0x32, 0xf6, 0x9e, 0x7d, 0x49, 0xdc, 33 | 0xad, 0x4f, 0x14, 0xf2, 0x44, 0x40, 0x66, 0xd0, 34 | 0x6b, 0xc4, 0x30, 0xb7, 0x32, 0x3b, 0xa1, 0x22, 35 | 0xf6, 0x22, 0x91, 0x9d, 0xe1, 0x8b, 0x1f, 0xda, 36 | 0xb0, 0xca, 0x99, 0x02 37 | }; 38 | 39 | static const int DRW_magicNumEnd18[] = { 40 | 0xf8, 0x46, 0x6a, 0x04, 0x96, 0x73, 0x0e, 0xd9, 41 | 0x16, 0x2f, 0x67, 0x68, 0xd4, 0xf7, 0x4a, 0x4a, 42 | 0xd0, 0x57, 0x68, 0x76}; 43 | 44 | class dwgReader18 : public dwgReader { 45 | public: 46 | dwgReader18(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ 47 | objData = NULL; 48 | } 49 | virtual ~dwgReader18(){ 50 | if (objData != NULL) 51 | delete[] objData; 52 | } 53 | bool readMetaData(); 54 | bool readFileHeader(); 55 | bool readDwgHeader(DRW_Header& hdr); 56 | bool readDwgClasses(); 57 | bool readDwgHandles(); 58 | bool readDwgTables(DRW_Header& hdr); 59 | bool readDwgBlocks(DRW_Interface& intfa){ 60 | bool ret = true; 61 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 62 | ret = dwgReader::readDwgBlocks(intfa, &dataBuf); 63 | return ret; 64 | } 65 | 66 | virtual bool readDwgEntities(DRW_Interface& intfa){ 67 | bool ret = true; 68 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 69 | ret = dwgReader::readDwgEntities(intfa, &dataBuf); 70 | return ret; 71 | } 72 | virtual bool readDwgObjects(DRW_Interface& intfa){ 73 | bool ret = true; 74 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 75 | ret = dwgReader::readDwgObjects(intfa, &dataBuf); 76 | return ret; 77 | } 78 | 79 | // bool readDwgEntity(objHandle& obj, DRW_Interface& intfa){ 80 | // bool ret = true; 81 | // return ret; 82 | // } 83 | 84 | protected: 85 | duint8 *objData; 86 | duint64 uncompSize; 87 | 88 | private: 89 | void genMagicNumber(); 90 | // dwgBuffer* bufObj; 91 | void parseSysPage(duint8 *decompSec, duint32 decompSize); //called: Section page map: 0x41630e3b 92 | bool parseDataPage(dwgSectionInfo si/*, duint8 *dData*/); //called ???: Section map: 0x4163003b 93 | duint32 checksum(duint32 seed, duint8* data, duint32 sz); 94 | 95 | private: 96 | duint32 securityFlags; 97 | }; 98 | 99 | #endif // DWGREADER18_H 100 | -------------------------------------------------------------------------------- /src/intern/dwgreader21.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DWGREADER21_H 14 | #define DWGREADER21_H 15 | 16 | #include 17 | #include 18 | #include "drw_textcodec.h" 19 | #include "dwgbuffer.h" 20 | #include "dwgreader.h" 21 | 22 | //reader for AC1021 aka v2007, chapter 5 23 | class dwgReader21 : public dwgReader { 24 | public: 25 | dwgReader21(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ 26 | objData = NULL; 27 | dataSize = 0; 28 | } 29 | virtual ~dwgReader21(){ 30 | if (objData != NULL) 31 | delete[] objData; 32 | } 33 | bool readMetaData(); 34 | bool readFileHeader(); 35 | bool readDwgHeader(DRW_Header& hdr); 36 | bool readDwgClasses(); 37 | bool readDwgHandles(); 38 | bool readDwgTables(DRW_Header& hdr); 39 | bool readDwgBlocks(DRW_Interface& intfa); 40 | virtual bool readDwgEntities(DRW_Interface& intfa){ 41 | bool ret = true; 42 | dwgBuffer dataBuf(objData, dataSize, &decoder); 43 | ret = dwgReader::readDwgEntities(intfa, &dataBuf); 44 | return ret; 45 | } 46 | virtual bool readDwgObjects(DRW_Interface& intfa){ 47 | bool ret = true; 48 | dwgBuffer dataBuf(objData, dataSize, &decoder); 49 | ret = dwgReader::readDwgObjects(intfa, &dataBuf); 50 | return ret; 51 | } 52 | //bool readDwgEntity(objHandle& obj, DRW_Interface& intfa){ 53 | // return false; 54 | //} 55 | 56 | private: 57 | bool parseSysPage(duint64 sizeCompressed, duint64 sizeUncompressed, duint64 correctionFactor, duint64 offset, duint8 *decompData); 58 | bool parseDataPage(dwgSectionInfo si, duint8 *dData); 59 | 60 | duint8 *objData; 61 | duint64 dataSize; 62 | 63 | }; 64 | 65 | #endif // DWGREADER21_H 66 | -------------------------------------------------------------------------------- /src/intern/dwgreader24.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "drw_dbg.h" 19 | #include "dwgreader24.h" 20 | #include "drw_textcodec.h" 21 | #include "../libdwgr.h" 22 | 23 | 24 | bool dwgReader24::readFileHeader() { 25 | DRW_DBG("dwgReader24::readFileHeader\n"); 26 | bool ret = dwgReader18::readFileHeader(); 27 | DRW_DBG("dwgReader24::readFileHeader END\n"); 28 | return ret; 29 | } 30 | 31 | bool dwgReader24::readDwgHeader(DRW_Header& hdr){ 32 | DRW_DBG("dwgReader24::readDwgHeader\n"); 33 | bool ret = dwgReader18::readDwgHeader(hdr); 34 | DRW_DBG("dwgReader24::readDwgHeader END\n"); 35 | return ret; 36 | } 37 | 38 | bool dwgReader24::readDwgClasses(){ 39 | DRW_DBG("\ndwgReader24::readDwgClasses"); 40 | bool ret = dwgReader18::readDwgClasses(); 41 | DRW_DBG("\ndwgReader24::readDwgClasses END\n"); 42 | return ret; 43 | } 44 | -------------------------------------------------------------------------------- /src/intern/dwgreader24.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DWGREADER24_H 14 | #define DWGREADER24_H 15 | 16 | #include 17 | #include 18 | #include "drw_textcodec.h" 19 | #include "dwgbuffer.h" 20 | #include "dwgreader18.h" 21 | 22 | class dwgReader24 : public dwgReader18 { 23 | public: 24 | dwgReader24(std::ifstream *stream, dwgR *p):dwgReader18(stream, p){ } 25 | virtual ~dwgReader24(){} 26 | bool readFileHeader(); 27 | bool readDwgHeader(DRW_Header& hdr); 28 | bool readDwgClasses(); 29 | // bool readDwgHandles(){return false;} 30 | // bool readDwgTables(){return false;} 31 | bool readDwgBlocks(DRW_Interface& intfa){ 32 | bool ret = true; 33 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 34 | ret = dwgReader::readDwgBlocks(intfa, &dataBuf); 35 | return ret; 36 | } 37 | virtual bool readDwgEntities(DRW_Interface& intfa){ 38 | bool ret = true; 39 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 40 | ret = dwgReader::readDwgEntities(intfa, &dataBuf); 41 | return ret; 42 | } 43 | virtual bool readDwgObjects(DRW_Interface& intfa){ 44 | bool ret = true; 45 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 46 | ret = dwgReader::readDwgObjects(intfa, &dataBuf); 47 | return ret; 48 | } 49 | 50 | // bool readDwgEntity(objHandle& obj, DRW_Interface& intfa){ 51 | // DRW_UNUSED(obj); 52 | // DRW_UNUSED(intfa); 53 | // return false;} 54 | }; 55 | 56 | #endif // DWGREADER24_H 57 | -------------------------------------------------------------------------------- /src/intern/dwgreader27.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "drw_dbg.h" 19 | #include "dwgreader27.h" 20 | #include "drw_textcodec.h" 21 | #include "../libdwgr.h" 22 | 23 | 24 | bool dwgReader27::readFileHeader() { 25 | DRW_DBG("dwgReader27::readFileHeader\n"); 26 | bool ret = dwgReader18::readFileHeader(); 27 | DRW_DBG("dwgReader27::readFileHeader END\n"); 28 | return ret; 29 | } 30 | 31 | bool dwgReader27::readDwgHeader(DRW_Header& hdr){ 32 | DRW_DBG("dwgReader27::readDwgHeader\n"); 33 | bool ret = dwgReader18::readDwgHeader(hdr); 34 | DRW_DBG("dwgReader27::readDwgHeader END\n"); 35 | return ret; 36 | } 37 | 38 | bool dwgReader27::readDwgClasses(){ 39 | DRW_DBG("dwgReader27::readDwgClasses"); 40 | bool ret = dwgReader18::readDwgClasses(); 41 | DRW_DBG("\ndwgReader27::readDwgClasses END\n"); 42 | return ret; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/intern/dwgreader27.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DWGREADER27_H 14 | #define DWGREADER27_H 15 | 16 | #include 17 | #include 18 | #include "drw_textcodec.h" 19 | #include "dwgbuffer.h" 20 | #include "dwgreader18.h" 21 | 22 | class dwgReader27 : public dwgReader18 { 23 | public: 24 | dwgReader27(std::ifstream *stream, dwgR *p):dwgReader18(stream, p){ } 25 | virtual ~dwgReader27(){} 26 | bool readFileHeader(); 27 | bool readDwgHeader(DRW_Header& hdr); 28 | bool readDwgClasses(); 29 | // bool readDwgHandles(){return false;} 30 | // bool readDwgTables(){return false;} 31 | bool readDwgBlocks(DRW_Interface& intfa){ 32 | bool ret = true; 33 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 34 | ret = dwgReader::readDwgBlocks(intfa, &dataBuf); 35 | return ret; 36 | } 37 | virtual bool readDwgEntities(DRW_Interface& intfa){ 38 | bool ret = true; 39 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 40 | ret = dwgReader::readDwgEntities(intfa, &dataBuf); 41 | return ret; 42 | } 43 | virtual bool readDwgObjects(DRW_Interface& intfa){ 44 | bool ret = true; 45 | dwgBuffer dataBuf(objData, uncompSize, &decoder); 46 | ret = dwgReader::readDwgObjects(intfa, &dataBuf); 47 | return ret; 48 | } 49 | // bool readDwgEntity(objHandle& obj, DRW_Interface& intfa){ 50 | // DRW_UNUSED(obj); 51 | // DRW_UNUSED(intfa); 52 | // return false;} 53 | }; 54 | 55 | #endif // DWGREADER21_H 56 | -------------------------------------------------------------------------------- /src/intern/dwgutil.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DWGUTIL_H 14 | #define DWGUTIL_H 15 | 16 | #include "../drw_base.h" 17 | 18 | namespace DRW { 19 | std::string toHexStr(int n); 20 | } 21 | 22 | class dwgRSCodec { 23 | public: 24 | dwgRSCodec(){} 25 | ~dwgRSCodec(){} 26 | static void decode239I(duint8 *in, duint8 *out, duint32 blk); 27 | static void decode251I(duint8 *in, duint8 *out, duint32 blk); 28 | }; 29 | 30 | class dwgCompressor { 31 | public: 32 | dwgCompressor(){} 33 | ~dwgCompressor(){} 34 | 35 | void decompress18(duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize); 36 | static void decrypt18Hdr(duint8 *buf, duint32 size, duint32 offset); 37 | // static void decrypt18Data(duint8 *buf, duint32 size, duint32 offset); 38 | static void decompress21(duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize); 39 | 40 | private: 41 | duint32 litLength18(); 42 | static duint32 litLength21(duint8 *cbuf, duint8 oc, duint32 *si); 43 | static void copyCompBytes21(duint8 *cbuf, duint8 *dbuf, duint32 l, duint32 si, duint32 di); 44 | static void readInstructions21(duint8 *cbuf, duint32 *si, duint8 *oc, duint32 *so, duint32 *l); 45 | 46 | duint32 longCompressionOffset(); 47 | duint32 long20CompressionOffset(); 48 | duint32 twoByteOffset(duint32 *ll); 49 | 50 | duint8 *bufC; 51 | duint8 *bufD; 52 | duint32 sizeC; 53 | duint32 sizeD; 54 | duint32 pos; 55 | duint32 rpos; 56 | 57 | }; 58 | 59 | class secEnum { 60 | public: 61 | enum DWGSection { 62 | UNKNOWNS, /*!< UNKNOWN section. */ 63 | FILEHEADER, /*!< File Header (in R3-R15*/ 64 | HEADER, /*!< AcDb:Header */ 65 | CLASSES, /*!< AcDb:Classes */ 66 | SUMARYINFO, /*!< AcDb:SummaryInfo */ 67 | PREVIEW, /*!< AcDb:Preview */ 68 | VBAPROY, /*!< AcDb:VBAProject */ 69 | APPINFO, /*!< AcDb:AppInfo */ 70 | FILEDEP, /*!< AcDb:FileDepList */ 71 | REVHISTORY, /*!< AcDb:RevHistory */ 72 | SECURITY, /*!< AcDb:Security */ 73 | OBJECTS, /*!< AcDb:AcDbObjects */ 74 | OBJFREESPACE, /*!< AcDb:ObjFreeSpace */ 75 | TEMPLATE, /*!< AcDb:Template */ 76 | HANDLES, /*!< AcDb:Handles */ 77 | PROTOTYPE, /*!< AcDb:AcDsPrototype_1b */ 78 | AUXHEADER, /*!< AcDb:AuxHeader, in (R13-R15) second file header */ 79 | SIGNATURE, /*!< AcDb:Signature */ 80 | APPINFOHISTORY, /*!< AcDb:AppInfoHistory (in ac1021 may be a renamed section?*/ 81 | EXTEDATA, /*!< Extended Entity Data */ 82 | PROXYGRAPHICS /*!< PROXY ENTITY GRAPHICS */ 83 | }; 84 | 85 | secEnum(){} 86 | ~secEnum(){} 87 | 88 | static DWGSection getEnum(std::string nameSec); 89 | }; 90 | 91 | #endif // DWGUTIL_H 92 | -------------------------------------------------------------------------------- /src/intern/dxfreader.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "dxfreader.h" 18 | #include "drw_textcodec.h" 19 | #include "drw_dbg.h" 20 | 21 | bool dxfReader::readRec(int *codeData) { 22 | // std::string text; 23 | int code; 24 | 25 | if (!readCode(&code)) 26 | return false; 27 | *codeData = code; 28 | 29 | if (code < 10) 30 | readString(); 31 | else if (code < 60) 32 | readDouble(); 33 | else if (code < 80) 34 | readInt16(); 35 | else if (code > 89 && code < 100) //TODO this is an int 32b 36 | readInt32(); 37 | else if (code == 100 || code == 102 || code == 105) 38 | readString(); 39 | else if (code > 109 && code < 150) //skip not used at the v2012 40 | readDouble(); 41 | else if (code > 159 && code < 170) //skip not used at the v2012 42 | readInt64(); 43 | else if (code < 180) 44 | readInt16(); 45 | else if (code > 209 && code < 240) //skip not used at the v2012 46 | readDouble(); 47 | else if (code > 269 && code < 290) //skip not used at the v2012 48 | readInt16(); 49 | else if (code < 300) //TODO this is a boolean indicator, int in Binary? 50 | readBool(); 51 | else if (code < 370) 52 | readString(); 53 | else if (code < 390) 54 | readInt16(); 55 | else if (code < 400) 56 | readString(); 57 | else if (code < 410) 58 | readInt16(); 59 | else if (code < 420) 60 | readString(); 61 | else if (code < 430) //TODO this is an int 32b 62 | readInt32(); 63 | else if (code < 440) 64 | readString(); 65 | else if (code < 450) //TODO this is an int 32b 66 | readInt32(); 67 | else if (code < 460) //TODO this is long?? 68 | readInt32(); 69 | else if (code < 470) //TODO this is a floating point double precision?? 70 | readDouble(); 71 | else if (code < 481) 72 | readString(); 73 | else if (code > 998 && code < 1009) //skip not used at the v2012 74 | readString(); 75 | else if (code < 1060) //TODO this is a floating point double precision?? 76 | readDouble(); 77 | else if (code < 1071) 78 | readInt16(); 79 | else if (code == 1071) //TODO this is an int 32b 80 | readInt32(); 81 | else if (skip) 82 | //skip safely this dxf entry ( ok for ascii dxf) 83 | readString(); 84 | else 85 | //break in binary files because the conduct is unpredictable 86 | return false; 87 | 88 | return (filestr->good()); 89 | } 90 | int dxfReader::getHandleString(){ 91 | int res; 92 | #if defined(__APPLE__) 93 | int Succeeded = sscanf ( strData.c_str(), "%x", &res ); 94 | if ( !Succeeded || Succeeded == EOF ) 95 | res = 0; 96 | #else 97 | std::istringstream Convert(strData); 98 | if ( !(Convert >> std::hex >>res) ) 99 | res = 0; 100 | #endif 101 | return res; 102 | } 103 | 104 | bool dxfReaderBinary::readCode(int *code) { 105 | unsigned short *int16p; 106 | char buffer[2]; 107 | filestr->read(buffer,2); 108 | int16p = (unsigned short *) buffer; 109 | //exist a 32bits int (code 90) with 2 bytes??? 110 | if ((*code == 90) && (*int16p>2000)){ 111 | DRW_DBG(*code); DRW_DBG(" de 16bits\n"); 112 | filestr->seekg(-4, std::ios_base::cur); 113 | filestr->read(buffer,2); 114 | int16p = (unsigned short *) buffer; 115 | } 116 | *code = *int16p; 117 | DRW_DBG(*code); DRW_DBG("\n"); 118 | 119 | return (filestr->good()); 120 | } 121 | 122 | bool dxfReaderBinary::readString() { 123 | type = STRING; 124 | std::getline(*filestr, strData, '\0'); 125 | DRW_DBG(strData); DRW_DBG("\n"); 126 | return (filestr->good()); 127 | } 128 | 129 | bool dxfReaderBinary::readString(std::string *text) { 130 | type = STRING; 131 | std::getline(*filestr, *text, '\0'); 132 | DRW_DBG(*text); DRW_DBG("\n"); 133 | return (filestr->good()); 134 | } 135 | 136 | bool dxfReaderBinary::readInt16() { 137 | type = INT32; 138 | char buffer[2]; 139 | filestr->read(buffer,2); 140 | intData = (int)((buffer[1] << 8) | buffer[0]); 141 | DRW_DBG(intData); DRW_DBG("\n"); 142 | return (filestr->good()); 143 | } 144 | 145 | bool dxfReaderBinary::readInt32() { 146 | type = INT32; 147 | unsigned int *int32p; 148 | char buffer[4]; 149 | filestr->read(buffer,4); 150 | int32p = (unsigned int *) buffer; 151 | intData = *int32p; 152 | DRW_DBG(intData); DRW_DBG("\n"); 153 | return (filestr->good()); 154 | } 155 | 156 | bool dxfReaderBinary::readInt64() { 157 | type = INT64; 158 | unsigned long long int *int64p; //64 bits integer pointer 159 | char buffer[8]; 160 | filestr->read(buffer,8); 161 | int64p = (unsigned long long int *) buffer; 162 | int64 = *int64p; 163 | DRW_DBG(int64); DRW_DBG(" int64\n"); 164 | return (filestr->good()); 165 | } 166 | 167 | bool dxfReaderBinary::readDouble() { 168 | type = DOUBLE; 169 | double *result; 170 | char buffer[8]; 171 | filestr->read(buffer,8); 172 | result = (double *) buffer; 173 | doubleData = *result; 174 | DRW_DBG(doubleData); DRW_DBG("\n"); 175 | return (filestr->good()); 176 | } 177 | 178 | //saved as int or add a bool member?? 179 | bool dxfReaderBinary::readBool() { 180 | char buffer[1]; 181 | filestr->read(buffer,1); 182 | intData = (int)(buffer[0]); 183 | DRW_DBG(intData); DRW_DBG("\n"); 184 | return (filestr->good()); 185 | } 186 | 187 | bool dxfReaderAscii::readCode(int *code) { 188 | std::string text; 189 | std::getline(*filestr, text); 190 | *code = atoi(text.c_str()); 191 | DRW_DBG(*code); DRW_DBG("\n"); 192 | return (filestr->good()); 193 | } 194 | bool dxfReaderAscii::readString(std::string *text) { 195 | type = STRING; 196 | std::getline(*filestr, *text); 197 | if (!text->empty() && text->at(text->size()-1) == '\r') 198 | text->erase(text->size()-1); 199 | return (filestr->good()); 200 | } 201 | 202 | bool dxfReaderAscii::readString() { 203 | type = STRING; 204 | std::getline(*filestr, strData); 205 | if (!strData.empty() && strData.at(strData.size()-1) == '\r') 206 | strData.erase(strData.size()-1); 207 | DRW_DBG(strData); DRW_DBG("\n"); 208 | return (filestr->good()); 209 | } 210 | 211 | bool dxfReaderAscii::readInt16() { 212 | type = INT32; 213 | std::string text; 214 | if (readString(&text)){ 215 | intData = atoi(text.c_str()); 216 | DRW_DBG(intData); DRW_DBG("\n"); 217 | return true; 218 | } else 219 | return false; 220 | } 221 | 222 | bool dxfReaderAscii::readInt32() { 223 | type = INT32; 224 | return readInt16(); 225 | } 226 | 227 | bool dxfReaderAscii::readInt64() { 228 | type = INT64; 229 | return readInt16(); 230 | } 231 | 232 | bool dxfReaderAscii::readDouble() { 233 | type = DOUBLE; 234 | std::string text; 235 | if (readString(&text)){ 236 | #if defined(__APPLE__) 237 | int succeeded=sscanf( & (text[0]), "%lg", &doubleData); 238 | if(succeeded != 1) { 239 | DRW_DBG("dxfReaderAscii::readDouble(): reading double error: "); 240 | DRW_DBG(text); 241 | DRW_DBG('\n'); 242 | } 243 | #else 244 | std::istringstream sd(text); 245 | sd >> doubleData; 246 | DRW_DBG(doubleData); DRW_DBG('\n'); 247 | #endif 248 | return true; 249 | } else 250 | return false; 251 | } 252 | 253 | //saved as int or add a bool member?? 254 | bool dxfReaderAscii::readBool() { 255 | type = BOOL; 256 | std::string text; 257 | if (readString(&text)){ 258 | intData = atoi(text.c_str()); 259 | DRW_DBG(intData); DRW_DBG("\n"); 260 | return true; 261 | } else 262 | return false; 263 | } 264 | 265 | -------------------------------------------------------------------------------- /src/intern/dxfreader.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DXFREADER_H 14 | #define DXFREADER_H 15 | 16 | #include "drw_textcodec.h" 17 | 18 | class dxfReader { 19 | public: 20 | enum TYPE { 21 | STRING, 22 | INT32, 23 | INT64, 24 | DOUBLE, 25 | BOOL, 26 | INVALID 27 | }; 28 | enum TYPE type; 29 | public: 30 | dxfReader(std::ifstream *stream){ 31 | filestr = stream; 32 | type = INVALID; 33 | } 34 | virtual ~dxfReader(){} 35 | bool readRec(int *code); 36 | 37 | std::string getString() {return strData;} 38 | int getHandleString();//Convert hex string to int 39 | std::string toUtf8String(std::string t) {return decoder.toUtf8(t);} 40 | std::string getUtf8String() {return decoder.toUtf8(strData);} 41 | double getDouble() {return doubleData;} 42 | int getInt32() {return intData;} 43 | unsigned long long int getInt64() {return int64;} 44 | bool getBool() { return (intData==0) ? false : true;} 45 | int getVersion(){return decoder.getVersion();} 46 | void setVersion(std::string *v, bool dxfFormat){decoder.setVersion(v, dxfFormat);} 47 | void setCodePage(std::string *c){decoder.setCodePage(c, true);} 48 | std::string getCodePage(){ return decoder.getCodePage();} 49 | 50 | protected: 51 | virtual bool readCode(int *code) = 0; //return true if sucesful (not EOF) 52 | virtual bool readString(std::string *text) = 0; 53 | virtual bool readString() = 0; 54 | virtual bool readInt16() = 0; 55 | virtual bool readInt32() = 0; 56 | virtual bool readInt64() = 0; 57 | virtual bool readDouble() = 0; 58 | virtual bool readBool() = 0; 59 | 60 | protected: 61 | std::ifstream *filestr; 62 | std::string strData; 63 | double doubleData; 64 | signed int intData; //32 bits integer 65 | unsigned long long int int64; //64 bits integer 66 | bool skip; //set to true for ascii dxf, false for binary 67 | private: 68 | DRW_TextCodec decoder; 69 | }; 70 | 71 | class dxfReaderBinary : public dxfReader { 72 | public: 73 | dxfReaderBinary(std::ifstream *stream):dxfReader(stream){skip = false; } 74 | virtual ~dxfReaderBinary() {} 75 | virtual bool readCode(int *code); 76 | virtual bool readString(std::string *text); 77 | virtual bool readString(); 78 | virtual bool readInt16(); 79 | virtual bool readInt32(); 80 | virtual bool readInt64(); 81 | virtual bool readDouble(); 82 | virtual bool readBool(); 83 | }; 84 | 85 | class dxfReaderAscii : public dxfReader { 86 | public: 87 | dxfReaderAscii(std::ifstream *stream):dxfReader(stream){skip = true; } 88 | virtual ~dxfReaderAscii(){} 89 | virtual bool readCode(int *code); 90 | virtual bool readString(std::string *text); 91 | virtual bool readString(); 92 | virtual bool readInt16(); 93 | virtual bool readDouble(); 94 | virtual bool readInt32(); 95 | virtual bool readInt64(); 96 | virtual bool readBool(); 97 | }; 98 | 99 | #endif // DXFREADER_H 100 | -------------------------------------------------------------------------------- /src/intern/dxfwriter.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "dxfwriter.h" 18 | 19 | //RLZ TODO change std::endl to x0D x0A (13 10) 20 | /*bool dxfWriter::readRec(int *codeData, bool skip) { 21 | // std::string text; 22 | int code; 23 | 24 | #ifdef DRW_DBG 25 | count = count+2; //DBG 26 | #endif 27 | 28 | if (!readCode(&code)) 29 | return false; 30 | *codeData = code; 31 | 32 | if (code < 10) 33 | readString(); 34 | else if (code < 60) 35 | readDouble(); 36 | else if (code < 80) 37 | readInt(); 38 | else if (code > 89 && code < 100) //TODO this is an int 32b 39 | readInt32(); 40 | else if (code == 100 || code == 102 || code == 105) 41 | readString(); 42 | else if (code > 109 && code < 150) //skip not used at the v2012 43 | readDouble(); 44 | else if (code > 159 && code < 170) //skip not used at the v2012 45 | readInt64(); 46 | else if (code < 180) 47 | readInt(); 48 | else if (code > 209 && code < 240) //skip not used at the v2012 49 | readDouble(); 50 | else if (code > 269 && code < 290) //skip not used at the v2012 51 | readInt(); 52 | else if (code < 300) //TODO this is a boolean indicator, int in Binary? 53 | readBool(); 54 | else if (code < 370) 55 | readString(); 56 | else if (code < 390) 57 | readInt(); 58 | else if (code < 400) 59 | readString(); 60 | else if (code < 410) 61 | readInt(); 62 | else if (code < 420) 63 | readString(); 64 | else if (code < 430) //TODO this is an int 32b 65 | readInt32(); 66 | else if (code < 440) 67 | readString(); 68 | else if (code < 450) //TODO this is an int 32b 69 | readInt32(); 70 | else if (code < 460) //TODO this is long?? 71 | readInt(); 72 | else if (code < 470) //TODO this is a floating point double precision?? 73 | readDouble(); 74 | else if (code < 481) 75 | readString(); 76 | else if (code > 998 && code < 1009) //skip not used at the v2012 77 | readString(); 78 | else if (code < 1060) //TODO this is a floating point double precision?? 79 | readDouble(); 80 | else if (code < 1071) 81 | readInt(); 82 | else if (code == 1071) //TODO this is an int 32b 83 | readInt32(); 84 | else if (skip) 85 | //skip safely this dxf entry ( ok for ascii dxf) 86 | readString(); 87 | else 88 | //break in binary files because the conduct is unpredictable 89 | return false; 90 | 91 | return (filestr->good()); 92 | }*/ 93 | 94 | bool dxfWriter::writeUtf8String(int code, std::string text) { 95 | std::string t = encoder.fromUtf8(text); 96 | return writeString(code, t); 97 | } 98 | 99 | bool dxfWriter::writeUtf8Caps(int code, std::string text) { 100 | std::string strname = text; 101 | std::transform(strname.begin(), strname.end(), strname.begin(),::toupper); 102 | std::string t = encoder.fromUtf8(strname); 103 | return writeString(code, t); 104 | } 105 | 106 | bool dxfWriterBinary::writeString(int code, std::string text) { 107 | char bufcode[2]; 108 | bufcode[0] =code & 0xFF; 109 | bufcode[1] =code >> 8; 110 | filestr->write(bufcode, 2); 111 | *filestr << text << '\0'; 112 | return (filestr->good()); 113 | } 114 | 115 | /*bool dxfWriterBinary::readCode(int *code) { 116 | unsigned short *int16p; 117 | char buffer[2]; 118 | filestr->read(buffer,2); 119 | int16p = (unsigned short *) buffer; 120 | //exist a 32bits int (code 90) with 2 bytes??? 121 | if ((*code == 90) && (*int16p>2000)){ 122 | DBG(*code); DBG(" de 16bits\n"); 123 | filestr->seekg(-4, std::ios_base::cur); 124 | filestr->read(buffer,2); 125 | int16p = (unsigned short *) buffer; 126 | } 127 | *code = *int16p; 128 | DBG(*code); DBG("\n"); 129 | 130 | return (filestr->good()); 131 | }*/ 132 | 133 | /*bool dxfWriterBinary::readString() { 134 | std::getline(*filestr, strData, '\0'); 135 | DBG(strData); DBG("\n"); 136 | return (filestr->good()); 137 | }*/ 138 | 139 | /*bool dxfWriterBinary::readString(std::string *text) { 140 | std::getline(*filestr, *text, '\0'); 141 | DBG(*text); DBG("\n"); 142 | return (filestr->good()); 143 | }*/ 144 | 145 | bool dxfWriterBinary::writeInt16(int code, int data) { 146 | char bufcode[2]; 147 | char buffer[2]; 148 | bufcode[0] =code & 0xFF; 149 | bufcode[1] =code >> 8; 150 | buffer[0] =data & 0xFF; 151 | buffer[1] =data >> 8; 152 | filestr->write(bufcode, 2); 153 | filestr->write(buffer, 2); 154 | return (filestr->good()); 155 | } 156 | 157 | bool dxfWriterBinary::writeInt32(int code, int data) { 158 | char buffer[4]; 159 | buffer[0] =code & 0xFF; 160 | buffer[1] =code >> 8; 161 | filestr->write(buffer, 2); 162 | 163 | buffer[0] =data & 0xFF; 164 | buffer[1] =data >> 8; 165 | buffer[2] =data >> 16; 166 | buffer[3] =data >> 24; 167 | filestr->write(buffer, 4); 168 | return (filestr->good()); 169 | } 170 | 171 | bool dxfWriterBinary::writeInt64(int code, unsigned long long int data) { 172 | char buffer[8]; 173 | buffer[0] =code & 0xFF; 174 | buffer[1] =code >> 8; 175 | filestr->write(buffer, 2); 176 | 177 | buffer[0] =data & 0xFF; 178 | buffer[1] =data >> 8; 179 | buffer[2] =data >> 16; 180 | buffer[3] =data >> 24; 181 | buffer[4] =data >> 32; 182 | buffer[5] =data >> 40; 183 | buffer[6] =data >> 48; 184 | buffer[7] =data >> 56; 185 | filestr->write(buffer, 8); 186 | return (filestr->good()); 187 | } 188 | 189 | bool dxfWriterBinary::writeDouble(int code, double data) { 190 | char bufcode[2]; 191 | char buffer[8]; 192 | bufcode[0] =code & 0xFF; 193 | bufcode[1] =code >> 8; 194 | filestr->write(bufcode, 2); 195 | 196 | unsigned char *val; 197 | val = (unsigned char *) &data; 198 | for (int i=0; i<8; i++) { 199 | buffer[i] =val[i]; 200 | } 201 | filestr->write(buffer, 8); 202 | return (filestr->good()); 203 | } 204 | 205 | //saved as int or add a bool member?? 206 | bool dxfWriterBinary::writeBool(int code, bool data) { 207 | char buffer[1]; 208 | char bufcode[2]; 209 | bufcode[0] =code & 0xFF; 210 | bufcode[1] =code >> 8; 211 | filestr->write(bufcode, 2); 212 | buffer[0] = data; 213 | filestr->write(buffer, 1); 214 | return (filestr->good()); 215 | } 216 | 217 | dxfWriterAscii::dxfWriterAscii(std::ofstream *stream):dxfWriter(stream){ 218 | filestr->precision(16); 219 | } 220 | 221 | bool dxfWriterAscii::writeString(int code, std::string text) { 222 | // *filestr << code << std::endl << text << std::endl ; 223 | filestr->width(3); 224 | *filestr << std::right << code << std::endl; 225 | filestr->width(0); 226 | *filestr << std::left << text << std::endl; 227 | /* std::getline(*filestr, strData, '\0'); 228 | DBG(strData); DBG("\n");*/ 229 | return (filestr->good()); 230 | } 231 | 232 | bool dxfWriterAscii::writeInt16(int code, int data) { 233 | // *filestr << std::right << code << std::endl << data << std::endl; 234 | filestr->width(3); 235 | *filestr << std::right << code << std::endl; 236 | filestr->width(5); 237 | *filestr << data << std::endl; 238 | return (filestr->good()); 239 | } 240 | 241 | bool dxfWriterAscii::writeInt32(int code, int data) { 242 | return writeInt16(code, data); 243 | } 244 | 245 | bool dxfWriterAscii::writeInt64(int code, unsigned long long int data) { 246 | // *filestr << code << std::endl << data << std::endl; 247 | filestr->width(3); 248 | *filestr << std::right << code << std::endl; 249 | filestr->width(5); 250 | *filestr << data << std::endl; 251 | return (filestr->good()); 252 | } 253 | 254 | bool dxfWriterAscii::writeDouble(int code, double data) { 255 | // std::streamsize prec = filestr->precision(); 256 | // filestr->precision(12); 257 | // *filestr << code << std::endl << data << std::endl; 258 | filestr->width(3); 259 | *filestr << std::right << code << std::endl; 260 | *filestr << data << std::endl; 261 | // filestr->precision(prec); 262 | return (filestr->good()); 263 | } 264 | 265 | //saved as int or add a bool member?? 266 | bool dxfWriterAscii::writeBool(int code, bool data) { 267 | *filestr << code << std::endl << data << std::endl; 268 | return (filestr->good()); 269 | } 270 | 271 | -------------------------------------------------------------------------------- /src/intern/dxfwriter.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef DXFWRITER_H 14 | #define DXFWRITER_H 15 | 16 | #include "drw_textcodec.h" 17 | 18 | class dxfWriter { 19 | public: 20 | dxfWriter(std::ofstream *stream){filestr = stream; /*count =0;*/} 21 | virtual ~dxfWriter(){} 22 | virtual bool writeString(int code, std::string text) = 0; 23 | bool writeUtf8String(int code, std::string text); 24 | bool writeUtf8Caps(int code, std::string text); 25 | std::string fromUtf8String(std::string t) {return encoder.fromUtf8(t);} 26 | virtual bool writeInt16(int code, int data) = 0; 27 | virtual bool writeInt32(int code, int data) = 0; 28 | virtual bool writeInt64(int code, unsigned long long int data) = 0; 29 | virtual bool writeDouble(int code, double data) = 0; 30 | virtual bool writeBool(int code, bool data) = 0; 31 | void setVersion(std::string *v, bool dxfFormat){encoder.setVersion(v, dxfFormat);} 32 | void setCodePage(std::string *c){encoder.setCodePage(c, true);} 33 | std::string getCodePage(){return encoder.getCodePage();} 34 | protected: 35 | std::ofstream *filestr; 36 | private: 37 | DRW_TextCodec encoder; 38 | }; 39 | 40 | class dxfWriterBinary : public dxfWriter { 41 | public: 42 | dxfWriterBinary(std::ofstream *stream):dxfWriter(stream){} 43 | virtual ~dxfWriterBinary() {} 44 | virtual bool writeString(int code, std::string text); 45 | virtual bool writeInt16(int code, int data); 46 | virtual bool writeInt32(int code, int data); 47 | virtual bool writeInt64(int code, unsigned long long int data); 48 | virtual bool writeDouble(int code, double data); 49 | virtual bool writeBool(int code, bool data); 50 | }; 51 | 52 | class dxfWriterAscii : public dxfWriter { 53 | public: 54 | dxfWriterAscii(std::ofstream *stream); 55 | virtual ~dxfWriterAscii(){} 56 | virtual bool writeString(int code, std::string text); 57 | virtual bool writeInt16(int code, int data); 58 | virtual bool writeInt32(int code, int data); 59 | virtual bool writeInt64(int code, unsigned long long int data); 60 | virtual bool writeDouble(int code, double data); 61 | virtual bool writeBool(int code, bool data); 62 | }; 63 | 64 | #endif // DXFWRITER_H 65 | -------------------------------------------------------------------------------- /src/intern/rscodec.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2014 J.F. Soriano (Rallaz), rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | /** 14 | * Reed-Solomon codec 15 | * Reed Solomon code lifted from encoder/decoder for Reed-Solomon written by Simon Rockliff 16 | * 17 | * Original code: 18 | * This program may be freely modified and/or given to whoever wants it. 19 | * A condition of such distribution is that the author's contribution be 20 | * acknowledged by his name being left in the comments heading the program, 21 | * however no responsibility is accepted for any financial or other loss which 22 | * may result from some unforseen errors or malfunctioning of the program 23 | * during use. 24 | * Simon Rockliff, 26th June 1991 25 | */ 26 | 27 | 28 | 29 | #ifndef RSCODEC_H 30 | #define RSCODEC_H 31 | /** 32 | mm: RS code over GF(2^4) 33 | nn: nn= (2^mm) - 1 length of codeword 34 | tt: number of errors that can be corrected 35 | kk: kk = nn-2*tt 36 | pp: irreducible polynomial coeffts, pp [mm] send as int 37 | */ 38 | class RScodec { 39 | public: 40 | RScodec(unsigned int pp, int mm, int tt); 41 | 42 | ~RScodec(); 43 | // bool encode(int *data, int *parity); 44 | // int decode(int *recd); 45 | bool encode(unsigned char *data, unsigned char *parity); 46 | int decode(unsigned char *data); 47 | bool isOkey(){return isOk;} 48 | const unsigned int* indexOf() {return index_of;} 49 | const int* alphaTo() {return alpha_to;} 50 | 51 | private: 52 | void RSgenerate_gf(unsigned int pp); 53 | void RSgen_poly(); 54 | int calcDecode(unsigned char* data, int* recd, int** elp, int* d, int* l, int* u_lu, int* s, int* root, int* loc, int* z, int* err, int* reg, int bb); 55 | 56 | 57 | private: 58 | int mm; //RS code over GF(2^4) 59 | int tt; //number of errors that can be corrected 60 | int nn; //(2^mm) - 1 length of codeword 61 | int kk; //nn-2*tt length of original data 62 | 63 | int *gg; 64 | bool isOk; 65 | unsigned int *index_of; 66 | int *alpha_to; 67 | }; 68 | 69 | #endif // RSCODEC_H 70 | -------------------------------------------------------------------------------- /src/libdwgr.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef LIBDWGR_H 14 | #define LIBDWGR_H 15 | 16 | #include 17 | //#include 18 | #include "drw_entities.h" 19 | #include "drw_objects.h" 20 | #include "drw_classes.h" 21 | #include "drw_interface.h" 22 | 23 | class dwgReader; 24 | 25 | class dwgR { 26 | public: 27 | dwgR(const char* name); 28 | ~dwgR(); 29 | //read: return true if all ok 30 | bool read(DRW_Interface *interface_, bool ext); 31 | bool getPreview(); 32 | DRW::Version getVersion(){return version;} 33 | DRW::error getError(){return error;} 34 | bool testReader(); 35 | void setDebug(DRW::DBG_LEVEL lvl); 36 | 37 | private: 38 | bool openFile(std::ifstream *filestr); 39 | bool processDwg(); 40 | private: 41 | DRW::Version version; 42 | DRW::error error; 43 | std::string fileName; 44 | bool applyExt; /*apply extrusion in entities to conv in 2D?*/ 45 | std::string codePage; 46 | DRW_Interface *iface; 47 | dwgReader *reader; 48 | 49 | }; 50 | 51 | #endif // LIBDWGR_H 52 | -------------------------------------------------------------------------------- /src/libdxfrw.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** libDXFrw - Library to read/write DXF files (ascii & binary) ** 3 | ** ** 4 | ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** 5 | ** ** 6 | ** This library is free software, licensed under the terms of the GNU ** 7 | ** General Public License as published by the Free Software Foundation, ** 8 | ** either version 2 of the License, or (at your option) any later version. ** 9 | ** You should have received a copy of the GNU General Public License ** 10 | ** along with this program. If not, see . ** 11 | ******************************************************************************/ 12 | 13 | #ifndef LIBDXFRW_H 14 | #define LIBDXFRW_H 15 | 16 | #include 17 | #include "drw_entities.h" 18 | #include "drw_objects.h" 19 | #include "drw_header.h" 20 | #include "drw_interface.h" 21 | 22 | 23 | class dxfReader; 24 | class dxfWriter; 25 | 26 | class dxfRW { 27 | public: 28 | dxfRW(const char* name); 29 | ~dxfRW(); 30 | void setDebug(DRW::DBG_LEVEL lvl); 31 | /// reads the file specified in constructor 32 | /*! 33 | * An interface must be provided. It is used by the class to signal various 34 | * components being added. 35 | * @param interface_ the interface to use 36 | * @param ext should the extrusion be applied to convert in 2D? 37 | * @return true for success 38 | */ 39 | bool read(DRW_Interface *interface_, bool ext); 40 | void setBinary(bool b) {binFile = b;} 41 | 42 | bool write(DRW_Interface *interface_, DRW::Version ver, bool bin); 43 | bool writeLineType(DRW_LType *ent); 44 | bool writeLayer(DRW_Layer *ent); 45 | bool writeDimstyle(DRW_Dimstyle *ent); 46 | bool writeTextstyle(DRW_Textstyle *ent); 47 | bool writeVport(DRW_Vport *ent); 48 | bool writeAppId(DRW_AppId *ent); 49 | bool writePoint(DRW_Point *ent); 50 | bool writeLine(DRW_Line *ent); 51 | bool writeRay(DRW_Ray *ent); 52 | bool writeXline(DRW_Xline *ent); 53 | bool writeCircle(DRW_Circle *ent); 54 | bool writeArc(DRW_Arc *ent); 55 | bool writeEllipse(DRW_Ellipse *ent); 56 | bool writeTrace(DRW_Trace *ent); 57 | bool writeSolid(DRW_Solid *ent); 58 | bool write3dface(DRW_3Dface *ent); 59 | bool writeLWPolyline(DRW_LWPolyline *ent); 60 | bool writePolyline(DRW_Polyline *ent); 61 | bool writeSpline(DRW_Spline *ent); 62 | bool writeBlockRecord(std::string name); 63 | bool writeBlock(DRW_Block *ent); 64 | bool writeInsert(DRW_Insert *ent); 65 | bool writeMText(DRW_MText *ent); 66 | bool writeText(DRW_Text *ent); 67 | bool writeHatch(DRW_Hatch *ent); 68 | bool writeViewport(DRW_Viewport *ent); 69 | DRW_ImageDef *writeImage(DRW_Image *ent, std::string name); 70 | bool writeLeader(DRW_Leader *ent); 71 | bool writeDimension(DRW_Dimension *ent); 72 | void setEllipseParts(int parts){elParts = parts;} /*!< set parts munber when convert ellipse to polyline */ 73 | 74 | private: 75 | /// used by read() to parse the content of the file 76 | bool processDxf(); 77 | bool processHeader(); 78 | bool processTables(); 79 | bool processBlocks(); 80 | bool processBlock(); 81 | bool processEntities(bool isblock); 82 | bool processObjects(); 83 | 84 | bool processLType(); 85 | bool processLayer(); 86 | bool processDimStyle(); 87 | bool processTextStyle(); 88 | bool processVports(); 89 | bool processAppId(); 90 | 91 | bool processPoint(); 92 | bool processLine(); 93 | bool processRay(); 94 | bool processXline(); 95 | bool processCircle(); 96 | bool processArc(); 97 | bool processEllipse(); 98 | bool processTrace(); 99 | bool processSolid(); 100 | bool processInsert(); 101 | bool processLWPolyline(); 102 | bool processPolyline(); 103 | bool processVertex(DRW_Polyline* pl); 104 | bool processText(); 105 | bool processMText(); 106 | bool processHatch(); 107 | bool processSpline(); 108 | bool process3dface(); 109 | bool processViewport(); 110 | bool processImage(); 111 | bool processImageDef(); 112 | bool processDimension(); 113 | bool processLeader(); 114 | 115 | // bool writeHeader(); 116 | bool writeEntity(DRW_Entity *ent); 117 | bool writeTables(); 118 | bool writeBlocks(); 119 | bool writeObjects(); 120 | bool writeExtData(const std::vector &ed); 121 | /*use version from dwgutil.h*/ 122 | std::string toHexStr(int n);//RLZ removeme 123 | 124 | private: 125 | DRW::Version version; 126 | std::string fileName; 127 | std::string codePage; 128 | bool binFile; 129 | dxfReader *reader; 130 | dxfWriter *writer; 131 | DRW_Interface *iface; 132 | DRW_Header header; 133 | // int section; 134 | std::string nextentity; 135 | int entCount; 136 | bool wlayer0; 137 | bool dimstyleStd; 138 | bool applyExt; 139 | bool writingBlock; 140 | int elParts; /*!< parts munber when convert ellipse to polyline */ 141 | std::map blockMap; 142 | std::vector imageDef; /*!< imageDef list */ 143 | 144 | int currHandle; 145 | 146 | }; 147 | 148 | #endif // LIBDXFRW_H 149 | -------------------------------------------------------------------------------- /src/main_doc.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @mainpage 4 | * 5 | * This manual documents the use of libdxfrw. 6 | * 7 | * With libdxfrw you can read and write several parts of a dxf files.

8 | * Dxf files can be written in assci and binary form, both are supported.

9 | * Dwg support (only read) are work in progress.

10 | * 11 | * the complete documentation and examples are pending to free time, 12 | * but to start see DRW_Interface, dxfRW & dwgR, clases 13 | */ 14 | 15 | -------------------------------------------------------------------------------- /vs2013/libdxfrw.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdxfrw", "libdxfrw.vcxproj", "{357A8016-9AD4-47EF-B23C-2071C264793B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Debug|Win32.Build.0 = Debug|Win32 16 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Release|Win32.ActiveCfg = Release|Win32 17 | {357A8016-9AD4-47EF-B23C-2071C264793B}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /vs2013/libdxfrw.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {357A8016-9AD4-47EF-B23C-2071C264793B} 15 | libdxfrw 16 | 17 | 18 | 19 | StaticLibrary 20 | true 21 | v142 22 | MultiByte 23 | 24 | 25 | StaticLibrary 26 | false 27 | v142 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | 48 | 49 | true 50 | 51 | 52 | 53 | 54 | Level3 55 | MaxSpeed 56 | true 57 | true 58 | true 59 | 60 | 61 | true 62 | true 63 | true 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /vs2013/libdxfrw.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | Header Files 62 | 63 | 64 | Header Files 65 | 66 | 67 | Header Files 68 | 69 | 70 | Header Files 71 | 72 | 73 | Header Files 74 | 75 | 76 | Header Files 77 | 78 | 79 | Header Files 80 | 81 | 82 | Header Files 83 | 84 | 85 | Header Files 86 | 87 | 88 | Header Files 89 | 90 | 91 | Header Files 92 | 93 | 94 | Header Files 95 | 96 | 97 | Header Files 98 | 99 | 100 | 101 | 102 | Source Files 103 | 104 | 105 | Source Files 106 | 107 | 108 | Source Files 109 | 110 | 111 | Source Files 112 | 113 | 114 | Source Files 115 | 116 | 117 | Source Files 118 | 119 | 120 | Source Files 121 | 122 | 123 | Source Files 124 | 125 | 126 | Source Files 127 | 128 | 129 | Source Files 130 | 131 | 132 | Source Files 133 | 134 | 135 | Source Files 136 | 137 | 138 | Source Files 139 | 140 | 141 | Source Files 142 | 143 | 144 | Source Files 145 | 146 | 147 | Source Files 148 | 149 | 150 | Source Files 151 | 152 | 153 | Source Files 154 | 155 | 156 | Source Files 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /vs2013/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | --------------------------------------------------------------------------------