1
/******************************************************************************
2
** libDXFrw - Library to read/write DXF files (ascii & binary) **
4
** Copyright (C) 2011 Rallaz, rallazz@gmail.com **
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 <http://www.gnu.org/licenses/>. **
11
******************************************************************************/
17
#include "dxfreader.h"
18
#include "drw_textcodec.h"
21
#include <iostream> //for debug
22
#define DBG(a) std::cerr << a
27
bool dxfReader::readRec(int *codeData, bool skip) {
32
count = count+2; //DBG
47
else if (code > 89 && code < 100) //TODO this is an int 32b
49
else if (code == 100 || code == 102 || code == 105)
51
else if (code > 109 && code < 150) //skip not used at the v2012
53
else if (code > 159 && code < 170) //skip not used at the v2012
57
else if (code > 209 && code < 240) //skip not used at the v2012
59
else if (code > 269 && code < 290) //skip not used at the v2012
61
else if (code < 300) //TODO this is a boolean indicator, int in Binary?
73
else if (code < 430) //TODO this is an int 32b
77
else if (code < 450) //TODO this is an int 32b
79
else if (code < 460) //TODO this is long??
81
else if (code < 470) //TODO this is a floating point double precision??
85
else if (code > 998 && code < 1009) //skip not used at the v2012
87
else if (code < 1060) //TODO this is a floating point double precision??
91
else if (code == 1071) //TODO this is an int 32b
94
//skip safely this dxf entry ( ok for ascii dxf)
97
//break in binary files because the conduct is unpredictable
100
return (filestr->good());
102
int dxfReader::getHandleString(){
104
#if defined(__APPLE__)
105
int Succeeded = sscanf ( strData.c_str(), "%x", &res );
106
if ( !Succeeded || Succeeded == EOF )
109
std::istringstream Convert(strData);
110
if ( !(Convert >> std::hex >>res) )
116
bool dxfReaderBinary::readCode(int *code) {
117
unsigned short *int16p;
119
filestr->read(buffer,2);
120
int16p = (unsigned short *) buffer;
121
//exist a 32bits int (code 90) with 2 bytes???
122
if ((*code == 90) && (*int16p>2000)){
123
DBG(*code); DBG(" de 16bits\n");
124
filestr->seekg(-4, std::ios_base::cur);
125
filestr->read(buffer,2);
126
int16p = (unsigned short *) buffer;
129
DBG(*code); DBG("\n");
131
return (filestr->good());
134
bool dxfReaderBinary::readString() {
135
std::getline(*filestr, strData, '\0');
136
DBG(strData); DBG("\n");
137
return (filestr->good());
140
bool dxfReaderBinary::readString(std::string *text) {
141
std::getline(*filestr, *text, '\0');
142
DBG(*text); DBG("\n");
143
return (filestr->good());
146
bool dxfReaderBinary::readInt() {
148
filestr->read(buffer,2);
149
intData = (int)((buffer[1] << 8) | buffer[0]);
150
DBG(intData); DBG("\n");
151
return (filestr->good());
154
bool dxfReaderBinary::readInt32() {
155
unsigned int *int32p;
157
filestr->read(buffer,4);
158
int32p = (unsigned int *) buffer;
160
DBG(intData); DBG("\n");
161
return (filestr->good());
164
bool dxfReaderBinary::readInt64() {
165
unsigned long long int *int64p; //64 bits integer pointer
167
filestr->read(buffer,8);
168
int64p = (unsigned long long int *) buffer;
170
DBG(int64); DBG(" int64\n");
171
return (filestr->good());
174
bool dxfReaderBinary::readDouble() {
177
filestr->read(buffer,8);
178
result = (double *) buffer;
179
doubleData = *result;
180
DBG(doubleData); DBG("\n");
181
return (filestr->good());
184
//saved as int or add a bool member??
185
bool dxfReaderBinary::readBool() {
187
filestr->read(buffer,1);
188
intData = (int)(buffer[0]);
189
DBG(intData); DBG("\n");
190
return (filestr->good());
193
bool dxfReaderAscii::readCode(int *code) {
195
std::getline(*filestr, text);
196
*code = atoi(text.c_str());
197
DBG(*code); DBG("\n");
198
return (filestr->good());
200
bool dxfReaderAscii::readString(std::string *text) {
201
std::getline(*filestr, *text);
202
if (!text->empty() && text->at(text->size()-1) == '\r')
203
text->erase(text->size()-1);
204
return (filestr->good());
207
bool dxfReaderAscii::readString() {
208
std::getline(*filestr, strData);
209
if (!strData.empty() && strData.at(strData.size()-1) == '\r')
210
strData.erase(strData.size()-1);
211
DBG(strData); DBG("\n");
212
return (filestr->good());
215
bool dxfReaderAscii::readInt() {
217
if (readString(&text)){
218
intData = atoi(text.c_str());
219
DBG(intData); DBG("\n");
225
bool dxfReaderAscii::readInt32() {
229
bool dxfReaderAscii::readInt64() {
233
bool dxfReaderAscii::readDouble() {
235
if (readString(&text)){
236
#if defined(__APPLE__)
237
int succeeded=sscanf( & (text[0]), "%lg", &doubleData);
239
DBG("dxfReaderAscii::readDouble(): reading double error: ");
244
std::istringstream sd(text);
246
DBG(doubleData); DBG('\n');
253
//saved as int or add a bool member??
254
bool dxfReaderAscii::readBool() {
256
if (readString(&text)){
257
intData = atoi(text.c_str());
258
DBG(intData); DBG("\n");