Bug Summary

File:intern/dwgreader.cpp
Warning:line 695, column 21
Value stored to 'bs' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name dwgreader.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/runner/work/LibreCAD/LibreCAD/libraries/libdxfrw -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D _REENTRANT -D MUPARSER_STATIC -D QT_NO_DEBUG -I . -I ../../../Qt/5.15.2/gcc_64/mkspecs/linux-g++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/home/runner/work/LibreCAD/LibreCAD/libraries/libdxfrw -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/runner/work/LibreCAD/LibreCAD/out/2026-11-25-172134-4186-1 -x c++ src/intern/dwgreader.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 <http://www.gnu.org/licenses/>. **
11******************************************************************************/
12
13#include <cstdlib>
14#include <iostream>
15#include <fstream>
16#include <string>
17#include <sstream>
18#include "dwgreader.h"
19#include "drw_textcodec.h"
20#include "drw_dbg.h"
21
22namespace {
23 //helper function to cleanup pointers in Look Up Tables
24 template<typename T>
25 void mapCleanUp(std::unordered_map<duint32, T*>& table)
26 {
27 for (auto& item: table)
28 delete item.second;
29 }
30}
31
32dwgReader::~dwgReader() {
33 mapCleanUp(ltypemap);
34 mapCleanUp(layermap);
35 mapCleanUp(blockmap);
36 mapCleanUp(stylemap);
37 mapCleanUp(dimstylemap);
38 mapCleanUp(vportmap);
39 mapCleanUp(classesmap);
40 mapCleanUp(blockRecordmap);
41 mapCleanUp(appIdmap);
42}
43
44void dwgReader::parseAttribs(DRW_Entity* e) {
45 if (nullptr == e) {
46 return;
47 }
48
49 duint32 ltref =e->lTypeH.ref;
50 duint32 lyref =e->layerH.ref;
51 auto lt_it = ltypemap.find(ltref);
52 if (lt_it != ltypemap.end()) {
53 e->lineType = (lt_it->second)->name;
54 }
55 auto ly_it = layermap.find(lyref);
56 if (ly_it != layermap.end()) {
57 e->layer = (ly_it->second)->name;
58 }
59}
60
61std::string dwgReader::findTableName(DRW::TTYPE table, dint32 handle){
62 std::string name;
63 switch (table){
64 case DRW::STYLE:{
65 auto st_it = stylemap.find(handle);
66 if (st_it != stylemap.end())
67 name = (st_it->second)->name;
68 break;}
69 case DRW::DIMSTYLE:{
70 auto ds_it = dimstylemap.find(handle);
71 if (ds_it != dimstylemap.end())
72 name = (ds_it->second)->name;
73 break;}
74 case DRW::BLOCK_RECORD:{ //use DRW_Block because name are more correct
75// auto bk_it = blockmap.find(handle);
76// if (bk_it != blockmap.end())
77 auto bk_it = blockRecordmap.find(handle);
78 if (bk_it != blockRecordmap.end())
79 name = (bk_it->second)->name;
80 break;}
81/* case DRW::VPORT:{
82 auto vp_it = vportmap.find(handle);
83 if (vp_it != vportmap.end())
84 name = (vp_it->second)->name;
85 break;}*/
86 case DRW::LAYER:{
87 auto ly_it = layermap.find(handle);
88 if (ly_it != layermap.end())
89 name = (ly_it->second)->name;
90 break;}
91 case DRW::LTYPE:{
92 auto lt_it = ltypemap.find(handle);
93 if (lt_it != ltypemap.end())
94 name = (lt_it->second)->name;
95 break;}
96 default:
97 break;
98 }
99 return name;
100}
101
102bool dwgReader::readDwgHeader(DRW_Header& hdr, dwgBuffer *buf, dwgBuffer *hBuf){
103 bool ret = hdr.parseDwg(version, buf, hBuf, maintenanceVersion);
104 //RLZ: copy objectControl handles
105 return ret;
106}
107
108//RLZ: TODO add check instead print
109bool dwgReader::checkSentinel(dwgBuffer *buf, enum secEnum::DWGSection, bool start){
110 DRW_UNUSED(start)(void)start;
111 for (int i=0; i<16;i++) {
112 DRW_DBGH(buf->getRawChar8())DRW_dbg::getInstance()->printH(buf->getRawChar8()); DRW_DBG(" ")DRW_dbg::getInstance()->print(" ");
113 }
114 return true;
115}
116
117/*********** objects map ************************/
118/** Note: object map are split in sections with max size 2035?
119 * heach section are 2 bytes size + data bytes + 2 bytes crc
120 * size value are data bytes + 2 and to calculate crc are used
121 * 2 bytes size + data bytes
122 * last section are 2 bytes size + 2 bytes crc (size value always 2)
123**/
124bool dwgReader::readDwgHandles(dwgBuffer *dbuf, duint64 offset, duint64 size) {
125 DRW_DBG("\ndwgReader::readDwgHandles\n")DRW_dbg::getInstance()->print("\ndwgReader::readDwgHandles\n"
)
;
126 if (!dbuf->setPosition(offset))
127 return false;
128
129 duint32 maxPos = offset + size;
130 DRW_DBG("\nSection HANDLES offset= ")DRW_dbg::getInstance()->print("\nSection HANDLES offset= "
)
; DRW_DBG(offset)DRW_dbg::getInstance()->print(offset);
131 DRW_DBG("\nSection HANDLES size= ")DRW_dbg::getInstance()->print("\nSection HANDLES size= "); DRW_DBG(size)DRW_dbg::getInstance()->print(size);
132 DRW_DBG("\nSection HANDLES maxPos= ")DRW_dbg::getInstance()->print("\nSection HANDLES maxPos= "
)
; DRW_DBG(maxPos)DRW_dbg::getInstance()->print(maxPos);
133
134 int startPos = offset;
135
136 std::vector<duint8> tmpByteStr;
137 while (maxPos > dbuf->getPosition()) {
138 DRW_DBG("\nstart handles section buf->curPosition()= ")DRW_dbg::getInstance()->print("\nstart handles section buf->curPosition()= "
)
; DRW_DBG(dbuf->getPosition())DRW_dbg::getInstance()->print(dbuf->getPosition()); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
139 duint16 size = dbuf->getBERawShort16();
140 DRW_DBG("object map section size= ")DRW_dbg::getInstance()->print("object map section size= "); DRW_DBG(size)DRW_dbg::getInstance()->print(size); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
141 dbuf->setPosition(startPos);
142 tmpByteStr.resize(size);
143 dbuf->getBytes(tmpByteStr.data(), size);
144 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
145 if (size != 2){
146 buff.setPosition(2);
147 int lastHandle = 0;
148 int lastLoc = 0;
149 //read data
150 while(buff.getPosition()< size){
151 lastHandle += buff.getUModularChar();
152 DRW_DBG("object map lastHandle= ")DRW_dbg::getInstance()->print("object map lastHandle= "); DRW_DBGH(lastHandle)DRW_dbg::getInstance()->printH(lastHandle);
153 lastLoc += buff.getModularChar();
154 DRW_DBG(" lastLoc= ")DRW_dbg::getInstance()->print(" lastLoc= "); DRW_DBG(lastLoc)DRW_dbg::getInstance()->print(lastLoc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
155 ObjectMap[lastHandle]= objHandle(0, lastHandle, lastLoc);
156 }
157 }
158 //verify crc
159 duint16 crcCalc = buff.crc8(0xc0c1,0,size);
160 duint16 crcRead = dbuf->getBERawShort16();
161 DRW_DBG("object map section crc8 read= ")DRW_dbg::getInstance()->print("object map section crc8 read= "
)
; DRW_DBG(crcRead)DRW_dbg::getInstance()->print(crcRead);
162 DRW_DBG("\nobject map section crc8 calculated= ")DRW_dbg::getInstance()->print("\nobject map section crc8 calculated= "
)
; DRW_DBG(crcCalc)DRW_dbg::getInstance()->print(crcCalc);
163 DRW_DBG("\nobject section buf->curPosition()= ")DRW_dbg::getInstance()->print("\nobject section buf->curPosition()= "
)
; DRW_DBG(dbuf->getPosition())DRW_dbg::getInstance()->print(dbuf->getPosition()); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
164 startPos = dbuf->getPosition();
165 }
166
167 bool ret = dbuf->isGood();
168 return ret;
169}
170
171/*********** objects ************************/
172/**
173 * Reads all the object referenced in the object map section of the DWG file
174 * (using their object file offsets)
175 */
176bool dwgReader::readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf) {
177 DRW_DBG("\ndwgReader::readDwgTables start\n")DRW_dbg::getInstance()->print("\ndwgReader::readDwgTables start\n"
)
;
178 bool ret = true;
179 bool ret2 = true;
180 objHandle oc;
181 dint16 oType;
182 duint32 bs = 0; //bit size of handle stream 2010+
183 std::vector<duint8> tmpByteStr;
184
185 //parse linetypes, start with linetype Control
186 auto mit = ObjectMap.find(hdr.linetypeCtrl);
187 if (mit==ObjectMap.end()) {
188 DRW_DBG("\nWARNING: LineType control not found\n")DRW_dbg::getInstance()->print("\nWARNING: LineType control not found\n"
)
;
189 ret = false;
190 } else {
191 DRW_DBG("\n**********Parsing LineType control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing LineType control*******\n"
)
;
192 oc = mit->second;
193 ObjectMap.erase(mit);
194 DRW_ObjControl ltControl;
195 dbuf->setPosition(oc.loc);
196 int csize = dbuf->getModularShort();
197 if (version > DRW::AC1021) //2010+
198 bs = dbuf->getUModularChar();
199 else
200 bs = 0;
201 tmpByteStr.resize(csize);
202 dbuf->getBytes(tmpByteStr.data(), csize);
203 dwgBuffer cbuff(tmpByteStr.data(), csize, &decoder);
204 //verify if object are correct
205 oType = cbuff.getObjType(version);
206 if (oType != 0x38) {
207 DRW_DBG("\nWARNING: Not LineType control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not LineType control object, found oType "
)
;
208 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x38\n")DRW_dbg::getInstance()->print(" instead 0x38\n");
209 ret = false;
210 } else { //reset position
211 cbuff.resetPosition();
212 ret2 = ltControl.parseDwg(version, &cbuff, bs);
213 if(ret)
214 ret = ret2;
215 }
216 for (auto it = ltControl.handlesList.begin(); it != ltControl.handlesList.end(); ++it) {
217 mit = ObjectMap.find(*it);
218 if (mit==ObjectMap.end()) {
219 DRW_DBG("\nWARNING: LineType not found\n")DRW_dbg::getInstance()->print("\nWARNING: LineType not found\n"
)
;
220 ret = false;
221 } else {
222 oc = mit->second;
223 ObjectMap.erase(mit);
224 DRW_DBG("\nLineType Handle= ")DRW_dbg::getInstance()->print("\nLineType Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" loc.: ")DRW_dbg::getInstance()->print(" loc.: "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
225 DRW_LType *lt = new DRW_LType();
226 dbuf->setPosition(oc.loc);
227 int lsize = dbuf->getModularShort();
228 DRW_DBG("LineType size in bytes= ")DRW_dbg::getInstance()->print("LineType size in bytes= "); DRW_DBG(lsize)DRW_dbg::getInstance()->print(lsize);
229 if (version > DRW::AC1021) //2010+
230 bs = dbuf->getUModularChar();
231 else
232 bs = 0;
233 tmpByteStr.resize(lsize);
234 dbuf->getBytes(tmpByteStr.data(), lsize);
235 dwgBuffer lbuff(tmpByteStr.data(), lsize, &decoder);
236 ret2 = lt->parseDwg(version, &lbuff, bs);
237 ltypemap[lt->handle] = lt;
238 if(ret)
239 ret = ret2;
240 }
241 }
242 }
243
244 //parse layers, start with layer Control
245 mit = ObjectMap.find(hdr.layerCtrl);
246 if (mit==ObjectMap.end()) {
247 DRW_DBG("\nWARNING: Layer control not found\n")DRW_dbg::getInstance()->print("\nWARNING: Layer control not found\n"
)
;
248 ret = false;
249 } else {
250 DRW_DBG("\n**********Parsing Layer control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing Layer control*******\n"
)
;
251 oc = mit->second;
252 ObjectMap.erase(mit);
253 DRW_ObjControl layControl;
254 dbuf->setPosition(oc.loc);
255 int size = dbuf->getModularShort();
256 if (version > DRW::AC1021) //2010+
257 bs = dbuf->getUModularChar();
258 else
259 bs = 0;
260 tmpByteStr.resize(size);
261 dbuf->getBytes(tmpByteStr.data(), size);
262 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
263 //verify if object are correct
264 oType = buff.getObjType(version);
265 if (oType != 0x32) {
266 DRW_DBG("\nWARNING: Not Layer control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not Layer control object, found oType "
)
;
267 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x32\n")DRW_dbg::getInstance()->print(" instead 0x32\n");
268 ret = false;
269 } else { //reset position
270 buff.resetPosition();
271 ret2 = layControl.parseDwg(version, &buff, bs);
272 if(ret)
273 ret = ret2;
274 }
275 for (auto it = layControl.handlesList.begin(); it != layControl.handlesList.end(); ++it) {
276 mit = ObjectMap.find(*it);
277 if (mit==ObjectMap.end()) {
278 DRW_DBG("\nWARNING: Layer not found\n")DRW_dbg::getInstance()->print("\nWARNING: Layer not found\n"
)
;
279 ret = false;
280 } else {
281 oc = mit->second;
282 ObjectMap.erase(mit);
283 DRW_DBG("Layer Handle= ")DRW_dbg::getInstance()->print("Layer Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
284 DRW_Layer *la = new DRW_Layer();
285 dbuf->setPosition(oc.loc);
286 int size = dbuf->getModularShort();
287 if (version > DRW::AC1021) //2010+
288 bs = dbuf->getUModularChar();
289 else
290 bs = 0;
291 tmpByteStr.resize(size);
292 dbuf->getBytes(tmpByteStr.data(), size);
293 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
294 ret2 = la->parseDwg(version, &buff, bs);
295 layermap[la->handle] = la;
296 if(ret)
297 ret = ret2;
298 }
299 }
300 }
301
302 //set linetype in layer
303 for (auto it=layermap.begin(); it!=layermap.end(); ++it) {
304 DRW_Layer *ly = it->second;
305 duint32 ref =ly->lTypeH.ref;
306 auto lt_it = ltypemap.find(ref);
307 if (lt_it != ltypemap.end()){
308 ly->lineType = (lt_it->second)->name;
309 }
310 }
311
312 // the header names the current layer by handle (CLAYER): give it by name,
313 // as the DXF header does ($CLAYER)
314 {
315 auto cl = layermap.find(hdr.clayerHandle);
316 if (cl != layermap.end())
317 hdr.addStr("$CLAYER", cl->second->name, 8);
318 }
319
320 //parse text styles, start with style Control
321 mit = ObjectMap.find(hdr.styleCtrl);
322 if (mit==ObjectMap.end()) {
323 DRW_DBG("\nWARNING: Style control not found\n")DRW_dbg::getInstance()->print("\nWARNING: Style control not found\n"
)
;
324 ret = false;
325 } else {
326 DRW_DBG("\n**********Parsing Style control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing Style control*******\n"
)
;
327 oc = mit->second;
328 ObjectMap.erase(mit);
329 DRW_ObjControl styControl;
330 dbuf->setPosition(oc.loc);
331 int size = dbuf->getModularShort();
332 if (version > DRW::AC1021) //2010+
333 bs = dbuf->getUModularChar();
334 else
335 bs = 0;
336 tmpByteStr.resize(size);
337 dbuf->getBytes(tmpByteStr.data(), size);
338 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
339 //verify if object are correct
340 oType = buff.getObjType(version);
341 if (oType != 0x34) {
342 DRW_DBG("\nWARNING: Not Text Style control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not Text Style control object, found oType "
)
;
343 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x34\n")DRW_dbg::getInstance()->print(" instead 0x34\n");
344 ret = false;
345 } else { //reset position
346 buff.resetPosition();
347 ret2 = styControl.parseDwg(version, &buff, bs);
348 if(ret)
349 ret = ret2;
350 }
351 for (auto it = styControl.handlesList.begin(); it != styControl.handlesList.end(); ++it) {
352 mit = ObjectMap.find(*it);
353 if (mit==ObjectMap.end()) {
354 DRW_DBG("\nWARNING: Style not found\n")DRW_dbg::getInstance()->print("\nWARNING: Style not found\n"
)
;
355 ret = false;
356 } else {
357 oc = mit->second;
358 ObjectMap.erase(mit);
359 DRW_DBG("Style Handle= ")DRW_dbg::getInstance()->print("Style Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
360 DRW_Textstyle *sty = new DRW_Textstyle();
361 dbuf->setPosition(oc.loc);
362 int size = dbuf->getModularShort();
363 if (version > DRW::AC1021) //2010+
364 bs = dbuf->getUModularChar();
365 else
366 bs = 0;
367 tmpByteStr.resize(size);
368 dbuf->getBytes(tmpByteStr.data(), size);
369 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
370 ret2 = sty->parseDwg(version, &buff, bs);
371 stylemap[sty->handle] = sty;
372 if(ret)
373 ret = ret2;
374 }
375 }
376 }
377
378 //parse dim styles, start with dimstyle Control
379 mit = ObjectMap.find(hdr.dimstyleCtrl);
380 if (mit==ObjectMap.end()) {
381 DRW_DBG("\nWARNING: Dimension Style control not found\n")DRW_dbg::getInstance()->print("\nWARNING: Dimension Style control not found\n"
)
;
382 ret = false;
383 } else {
384 DRW_DBG("\n**********Parsing Dimension Style control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing Dimension Style control*******\n"
)
;
385 oc = mit->second;
386 ObjectMap.erase(mit);
387 DRW_ObjControl dimstyControl;
388 dbuf->setPosition(oc.loc);
389 duint32 size = dbuf->getModularShort();
390 if (version > DRW::AC1021) //2010+
391 bs = dbuf->getUModularChar();
392 else
393 bs = 0;
394 tmpByteStr.resize(size);
395 dbuf->getBytes(tmpByteStr.data(), size);
396 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
397 //verify if object are correct
398 oType = buff.getObjType(version);
399 if (oType != 0x44) {
400 DRW_DBG("\nWARNING: Not Dim Style control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not Dim Style control object, found oType "
)
;
401 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x44\n")DRW_dbg::getInstance()->print(" instead 0x44\n");
402 ret = false;
403 } else { //reset position
404 buff.resetPosition();
405 ret2 = dimstyControl.parseDwg(version, &buff, bs);
406 if(ret)
407 ret = ret2;
408 }
409 for (auto it = dimstyControl.handlesList.begin(); it != dimstyControl.handlesList.end(); ++it) {
410 mit = ObjectMap.find(*it);
411 if (mit==ObjectMap.end()) {
412 DRW_DBG("\nWARNING: Dimension Style not found\n")DRW_dbg::getInstance()->print("\nWARNING: Dimension Style not found\n"
)
;
413 ret = false;
414 } else {
415 oc = mit->second;
416 ObjectMap.erase(mit);
417 DRW_DBG("Dimstyle Handle= ")DRW_dbg::getInstance()->print("Dimstyle Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
418 DRW_Dimstyle *sty = new DRW_Dimstyle();
419 dbuf->setPosition(oc.loc);
420 int size = dbuf->getModularShort();
421 if (version > DRW::AC1021) //2010+
422 bs = dbuf->getUModularChar();
423 else
424 bs = 0;
425 tmpByteStr.resize(size);
426 dbuf->getBytes(tmpByteStr.data(), size);
427 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
428 ret2 = sty->parseDwg(version, &buff, bs);
429 dimstylemap[sty->handle] = sty;
430 if(ret)
431 ret = ret2;
432 }
433 }
434 }
435
436 //parse vports, start with vports Control
437 mit = ObjectMap.find(hdr.vportCtrl);
438 if (mit==ObjectMap.end()) {
439 DRW_DBG("\nWARNING: vports control not found\n")DRW_dbg::getInstance()->print("\nWARNING: vports control not found\n"
)
;
440 ret = false;
441 } else {
442 DRW_DBG("\n**********Parsing vports control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing vports control*******\n"
)
;
443 oc = mit->second;
444 ObjectMap.erase(mit);
445 DRW_ObjControl vportControl;
446 dbuf->setPosition(oc.loc);
447 int size = dbuf->getModularShort();
448 if (version > DRW::AC1021) //2010+
449 bs = dbuf->getUModularChar();
450 else
451 bs = 0;
452 tmpByteStr.resize(size);
453 dbuf->getBytes(tmpByteStr.data(), size);
454 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
455 //verify if object are correct
456 oType = buff.getObjType(version);
457 if (oType != 0x40) {
458 DRW_DBG("\nWARNING: Not VPorts control object, found oType: ")DRW_dbg::getInstance()->print("\nWARNING: Not VPorts control object, found oType: "
)
;
459 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x40\n")DRW_dbg::getInstance()->print(" instead 0x40\n");
460 ret = false;
461 } else { //reset position
462 buff.resetPosition();
463 ret2 = vportControl.parseDwg(version, &buff, bs);
464 if(ret)
465 ret = ret2;
466 }
467 for (auto it = vportControl.handlesList.begin(); it != vportControl.handlesList.end(); ++it) {
468 mit = ObjectMap.find(*it);
469 if (mit==ObjectMap.end()) {
470 DRW_DBG("\nWARNING: vport not found\n")DRW_dbg::getInstance()->print("\nWARNING: vport not found\n"
)
;
471 ret = false;
472 } else {
473 oc = mit->second;
474 ObjectMap.erase(mit);
475 DRW_DBG("Vport Handle= ")DRW_dbg::getInstance()->print("Vport Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
476 DRW_Vport *vp = new DRW_Vport();
477 dbuf->setPosition(oc.loc);
478 int size = dbuf->getModularShort();
479 if (version > DRW::AC1021) //2010+
480 bs = dbuf->getUModularChar();
481 else
482 bs = 0;
483 tmpByteStr.resize(size);
484 dbuf->getBytes(tmpByteStr.data(), size);
485 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
486 ret2 = vp->parseDwg(version, &buff, bs);
487 vportmap[vp->handle] = vp;
488 if(ret)
489 ret = ret2;
490 }
491 }
492 }
493
494 //parse Block_records , start with Block_record Control
495 mit = ObjectMap.find(hdr.blockCtrl);
496 if (mit==ObjectMap.end()) {
497 DRW_DBG("\nWARNING: Block_record control not found\n")DRW_dbg::getInstance()->print("\nWARNING: Block_record control not found\n"
)
;
498 ret = false;
499 } else {
500 DRW_DBG("\n**********Parsing Block_record control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing Block_record control*******\n"
)
;
501 oc = mit->second;
502 ObjectMap.erase(mit);
503 DRW_ObjControl blockControl;
504 dbuf->setPosition(oc.loc);
505 int csize = dbuf->getModularShort();
506 if (version > DRW::AC1021) //2010+
507 bs = dbuf->getUModularChar();
508 else
509 bs = 0;
510 tmpByteStr.resize(csize);
511 dbuf->getBytes(tmpByteStr.data(), csize);
512 dwgBuffer buff(tmpByteStr.data(), csize, &decoder);
513 //verify if object are correct
514 oType = buff.getObjType(version);
515 if (oType != 0x30) {
516 DRW_DBG("\nWARNING: Not Block Record control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not Block Record control object, found oType "
)
;
517 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x30\n")DRW_dbg::getInstance()->print(" instead 0x30\n");
518 ret = false;
519 } else { //reset position
520 buff.resetPosition();
521 ret2 = blockControl.parseDwg(version, &buff, bs);
522 if(ret)
523 ret = ret2;
524 }
525 for (auto it = blockControl.handlesList.begin(); it != blockControl.handlesList.end(); ++it) {
526 mit = ObjectMap.find(*it);
527 if (mit==ObjectMap.end()) {
528 DRW_DBG("\nWARNING: block record not found\n")DRW_dbg::getInstance()->print("\nWARNING: block record not found\n"
)
;
529 ret = false;
530 } else {
531 oc = mit->second;
532 ObjectMap.erase(mit);
533 DRW_DBG("block record Handle= ")DRW_dbg::getInstance()->print("block record Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
534 DRW_Block_Record *br = new DRW_Block_Record();
535 dbuf->setPosition(oc.loc);
536 int size = dbuf->getModularShort();
537 if (version > DRW::AC1021) //2010+
538 bs = dbuf->getUModularChar();
539 else
540 bs = 0;
541 tmpByteStr.resize(size);
542 dbuf->getBytes(tmpByteStr.data(), size);
543 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
544 ret2 = br->parseDwg(version, &buff, bs);
545 blockRecordmap[br->handle] = br;
546 if(ret)
547 ret = ret2;
548 }
549 }
550 }
551
552 //parse appId , start with appId Control
553 mit = ObjectMap.find(hdr.appidCtrl);
554 if (mit==ObjectMap.end()) {
555 DRW_DBG("\nWARNING: AppId control not found\n")DRW_dbg::getInstance()->print("\nWARNING: AppId control not found\n"
)
;
556 ret = false;
557 } else {
558 DRW_DBG("\n**********Parsing AppId control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing AppId control*******\n"
)
;
559 oc = mit->second;
560 ObjectMap.erase(mit);
561 DRW_DBG("AppId Control Obj Handle= ")DRW_dbg::getInstance()->print("AppId Control Obj Handle= "
)
; DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
562 DRW_ObjControl appIdControl;
563 dbuf->setPosition(oc.loc);
564 int size = dbuf->getModularShort();
565 if (version > DRW::AC1021) //2010+
566 bs = dbuf->getUModularChar();
567 else
568 bs = 0;
569 tmpByteStr.resize(size);
570 dbuf->getBytes(tmpByteStr.data(), size);
571 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
572 //verify if object are correct
573 oType = buff.getObjType(version);
574 if (oType != 0x42) {
575 DRW_DBG("\nWARNING: Not AppId control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not AppId control object, found oType "
)
;
576 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x42\n")DRW_dbg::getInstance()->print(" instead 0x42\n");
577 ret = false;
578 } else { //reset position
579 buff.resetPosition();
580 ret2 = appIdControl.parseDwg(version, &buff, bs);
581 if(ret)
582 ret = ret2;
583 }
584 for (auto it = appIdControl.handlesList.begin(); it != appIdControl.handlesList.end(); ++it) {
585 mit = ObjectMap.find(*it);
586 if (mit==ObjectMap.end()) {
587 DRW_DBG("\nWARNING: AppId not found\n")DRW_dbg::getInstance()->print("\nWARNING: AppId not found\n"
)
;
588 ret = false;
589 } else {
590 oc = mit->second;
591 ObjectMap.erase(mit);
592 DRW_DBG("AppId Handle= ")DRW_dbg::getInstance()->print("AppId Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
593 DRW_AppId *ai = new DRW_AppId();
594 dbuf->setPosition(oc.loc);
595 int size = dbuf->getModularShort();
596 if (version > DRW::AC1021) //2010+
597 bs = dbuf->getUModularChar();
598 else
599 bs = 0;
600 tmpByteStr.resize(size);
601 dbuf->getBytes(tmpByteStr.data(), size);
602 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
603 ret2 = ai->parseDwg(version, &buff, bs);
604 appIdmap[ai->handle] = ai;
605 if(ret)
606 ret = ret2;
607 }
608 }
609 }
610
611 //RLZ: parse remaining object controls, TODO: implement all
612 if (DRW_DBGGLDRW_dbg::getInstance()->getLevel() == DRW_dbg::Level::Debug){
613 mit = ObjectMap.find(hdr.viewCtrl);
614 if (mit==ObjectMap.end()) {
615 DRW_DBG("\nWARNING: View control not found\n")DRW_dbg::getInstance()->print("\nWARNING: View control not found\n"
)
;
616 ret = false;
617 } else {
618 DRW_DBG("\n**********Parsing View control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing View control*******\n"
)
;
619 oc = mit->second;
620 ObjectMap.erase(mit);
621 DRW_DBG("View Control Obj Handle= ")DRW_dbg::getInstance()->print("View Control Obj Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
622 DRW_ObjControl viewControl;
623 dbuf->setPosition(oc.loc);
624 int size = dbuf->getModularShort();
625 if (version > DRW::AC1021) //2010+
626 bs = dbuf->getUModularChar();
627 else
628 bs = 0;
629 tmpByteStr.resize(size);
630 dbuf->getBytes(tmpByteStr.data(), size);
631 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
632 //verify if object are correct
633 oType = buff.getObjType(version);
634 if (oType != 0x3C) {
635 DRW_DBG("\nWARNING: Not View control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not View control object, found oType "
)
;
636 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x3C\n")DRW_dbg::getInstance()->print(" instead 0x3C\n");
637 ret = false;
638 } else { //reset position
639 buff.resetPosition();
640 ret2 = viewControl.parseDwg(version, &buff, bs);
641 if(ret)
642 ret = ret2;
643 }
644 }
645
646 mit = ObjectMap.find(hdr.ucsCtrl);
647 if (mit==ObjectMap.end()) {
648 DRW_DBG("\nWARNING: Ucs control not found\n")DRW_dbg::getInstance()->print("\nWARNING: Ucs control not found\n"
)
;
649 ret = false;
650 } else {
651 oc = mit->second;
652 ObjectMap.erase(mit);
653 DRW_DBG("\n**********Parsing Ucs control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing Ucs control*******\n"
)
;
654 DRW_DBG("Ucs Control Obj Handle= ")DRW_dbg::getInstance()->print("Ucs Control Obj Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
655 DRW_ObjControl ucsControl;
656 dbuf->setPosition(oc.loc);
657 int size = dbuf->getModularShort();
658 if (version > DRW::AC1021) //2010+
659 bs = dbuf->getUModularChar();
660 else
661 bs = 0;
662 tmpByteStr.resize(size);
663 dbuf->getBytes(tmpByteStr.data(), size);
664 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
665 //verify if object are correct
666 oType = buff.getObjType(version);
667 if (oType != 0x3E) {
668 DRW_DBG("\nWARNING: Not Ucs control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not Ucs control object, found oType "
)
;
669 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x3E\n")DRW_dbg::getInstance()->print(" instead 0x3E\n");
670 ret = false;
671 } else { //reset position
672 buff.resetPosition();
673 ret2 = ucsControl.parseDwg(version, &buff, bs);
674 if(ret)
675 ret = ret2;
676 }
677 }
678
679 if (version < DRW::AC1018) {//r2000-
680 mit = ObjectMap.find(hdr.vpEntHeaderCtrl);
681 if (mit==ObjectMap.end()) {
682 DRW_DBG("\nWARNING: vpEntHeader control not found\n")DRW_dbg::getInstance()->print("\nWARNING: vpEntHeader control not found\n"
)
;
683 ret = false;
684 } else {
685 DRW_DBG("\n**********Parsing vpEntHeader control*******\n")DRW_dbg::getInstance()->print("\n**********Parsing vpEntHeader control*******\n"
)
;
686 oc = mit->second;
687 ObjectMap.erase(mit);
688 DRW_DBG("vpEntHeader Control Obj Handle= ")DRW_dbg::getInstance()->print("vpEntHeader Control Obj Handle= "
)
; DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
689 DRW_ObjControl vpEntHeaderCtrl;
690 dbuf->setPosition(oc.loc);
691 int size = dbuf->getModularShort();
692 if (version > DRW::AC1021) //2010+
693 bs = dbuf->getUModularChar();
694 else
695 bs = 0;
Value stored to 'bs' is never read
696 tmpByteStr.resize(size);
697 dbuf->getBytes(tmpByteStr.data(), size);
698 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
699 //verify if object are correct
700 oType = buff.getObjType(version);
701 if (oType != 0x46) {
702 DRW_DBG("\nWARNING: Not vpEntHeader control object, found oType ")DRW_dbg::getInstance()->print("\nWARNING: Not vpEntHeader control object, found oType "
)
;
703 DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG(" instead 0x46\n")DRW_dbg::getInstance()->print(" instead 0x46\n");
704 ret = false;
705 } else { //reset position
706 buff.resetPosition();
707/* RLZ: writeme ret2 = vpEntHeader.parseDwg(version, &buff, bs);
708 if(ret)
709 ret = ret2;*/
710 }
711 }
712 }
713 }
714
715 return ret;
716}
717
718bool dwgReader::readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf){
719 bool ret = true;
720 bool ret2 = true;
721 duint32 bs =0;
722 DRW_DBG("\nobject map total size= ")DRW_dbg::getInstance()->print("\nobject map total size= "); DRW_DBG(ObjectMap.size())DRW_dbg::getInstance()->print(ObjectMap.size());
723
724 for (auto it=blockRecordmap.begin(); it != blockRecordmap.end(); ++it){
725 DRW_Block_Record* bkr= it->second;
726 DRW_DBG("\nParsing Block, record handle= ")DRW_dbg::getInstance()->print("\nParsing Block, record handle= "
)
; DRW_DBGH(it->first)DRW_dbg::getInstance()->printH(it->first); DRW_DBG(" Name= ")DRW_dbg::getInstance()->print(" Name= "); DRW_DBG(bkr->name)DRW_dbg::getInstance()->print(bkr->name); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
727 DRW_DBG("\nFinding Block, handle= ")DRW_dbg::getInstance()->print("\nFinding Block, handle= "); DRW_DBGH(bkr->block)DRW_dbg::getInstance()->printH(bkr->block); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
728 auto mit = ObjectMap.find(bkr->block);
729 if (mit==ObjectMap.end()) {
730 DRW_DBG("\nWARNING: block entity not found\n")DRW_dbg::getInstance()->print("\nWARNING: block entity not found\n"
)
;
731 ret = false;
732 continue;
733 }
734 objHandle oc = mit->second;
735 ObjectMap.erase(mit);
736 DRW_DBG("Block Handle= ")DRW_dbg::getInstance()->print("Block Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" Location: ")DRW_dbg::getInstance()->print(" Location: "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
737 if ( !(dbuf->setPosition(oc.loc)) ){
738 DRW_DBG("Bad Location reading blocks\n")DRW_dbg::getInstance()->print("Bad Location reading blocks\n"
)
;
739 ret = false;
740 continue;
741 }
742 int size = dbuf->getModularShort();
743 if (version > DRW::AC1021) //2010+
744 bs = dbuf->getUModularChar();
745 else
746 bs = 0;
747
748 std::vector<duint8> tmpByteStr(size);
749 dbuf->getBytes(tmpByteStr.data(), size);
750 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
751 DRW_Block bk;
752 ret2 = bk.parseDwg(version, &buff, bs);
753 ret = ret && ret2;
754 parseAttribs(&bk);
755 //complete block entity with block record data
756 bk.basePoint = bkr->basePoint;
757 bk.flags = bkr->flags;
758 intfa.addBlock(bk);
759 //and update block record name
760 bkr->name = bk.name;
761
762 /**read & send block entities**/
763 // in dwg code 330 are not set like dxf in ModelSpace & PaperSpace, set it (RLZ: only tested in 2000)
764 if (bk.parentHandle == DRW::NoHandle) {
765 // in dwg code 330 are not set like dxf in ModelSpace & PaperSpace, set it
766 bk.parentHandle= bkr->handle;
767 //and do not send block entities like dxf
768 } else {
769 if (version < DRW::AC1018) { //pre 2004
770 duint32 nextH = bkr->firstEH;
771 while (nextH != 0){
772 mit = ObjectMap.find(nextH);
773 if (mit==ObjectMap.end()) {
774 nextH = 0;//end while if entity not found
775 DRW_DBG("\nWARNING: Entity of block not found\n")DRW_dbg::getInstance()->print("\nWARNING: Entity of block not found\n"
)
;
776 ret = false;
777 continue;
778 } else {//foud entity reads it
779 oc = mit->second;
780 ObjectMap.erase(mit);
781 ret2 = readDwgEntity(dbuf, oc, intfa);
782 ret = ret && ret2;
783 }
784 if (nextH == bkr->lastEH)
785 nextH = 0; //redundant, but prevent read errors
786 else
787 nextH = nextEntLink;
788 }
789 } else {//2004+
790 for (std::vector<duint32>::iterator it = bkr->entMap.begin() ; it != bkr->entMap.end(); ++it){
791 duint32 nextH = *it;
792 mit = ObjectMap.find(nextH);
793 if (mit==ObjectMap.end()) {
794 DRW_DBG("\nWARNING: Entity of block not found\n")DRW_dbg::getInstance()->print("\nWARNING: Entity of block not found\n"
)
;
795 ret = false;
796 continue;
797 } else {//foud entity reads it
798 oc = mit->second;
799 ObjectMap.erase(mit);
800 DRW_DBG("\nBlocks, parsing entity: ")DRW_dbg::getInstance()->print("\nBlocks, parsing entity: "
)
; DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(", pos: ")DRW_dbg::getInstance()->print(", pos: "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
801 ret2 = readDwgEntity(dbuf, oc, intfa);
802 ret = ret && ret2;
803 }
804 }
805 }//end 2004+
806 }
807
808 //end block entity, really needed to parse a dummy entity??
809 mit = ObjectMap.find(bkr->endBlock);
810 if (mit==ObjectMap.end()) {
811 DRW_DBG("\nWARNING: end block entity not found\n")DRW_dbg::getInstance()->print("\nWARNING: end block entity not found\n"
)
;
812 ret = false;
813 continue;
814 }
815 oc = mit->second;
816 ObjectMap.erase(mit);
817 DRW_DBG("End block Handle= ")DRW_dbg::getInstance()->print("End block Handle= "); DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(" Location: ")DRW_dbg::getInstance()->print(" Location: "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
818 dbuf->setPosition(oc.loc);
819 size = dbuf->getModularShort();
820 if (version > DRW::AC1021) //2010+
821 bs = dbuf->getUModularChar();
822 else
823 bs = 0;
824 tmpByteStr.resize(size);
825 dbuf->getBytes(tmpByteStr.data(), size);
826 dwgBuffer buff1(tmpByteStr.data(), size, &decoder);
827 DRW_Block end;
828 end.isEnd = true;
829 ret2 = end.parseDwg(version, &buff1, bs);
830 ret = ret && ret2;
831 if (bk.parentHandle == DRW::NoHandle) bk.parentHandle= bkr->handle;
832 parseAttribs(&end);
833 intfa.endBlock();
834 }
835
836 return ret;
837}
838
839bool dwgReader::readPlineVertex(DRW_Polyline& pline, dwgBuffer *dbuf){
840 bool ret = true;
841 bool ret2 = true;
842 objHandle oc;
843 duint32 bs = 0;
844
845 if (version < DRW::AC1018) { //pre 2004
846 duint32 nextH = pline.firstEH;
847 while (nextH != 0){
848 auto mit = ObjectMap.find(nextH);
849 if (mit==ObjectMap.end()) {
850 nextH = 0;//end while if entity not found
851 DRW_DBG("\nWARNING: pline vertex not found\n")DRW_dbg::getInstance()->print("\nWARNING: pline vertex not found\n"
)
;
852 ret = false;
853 continue;
854 } else {//foud entity reads it
855 oc = mit->second;
856 ObjectMap.erase(mit);
857 DRW_Vertex vt;
858 dbuf->setPosition(oc.loc);
859 //RLZ: verify if pos is ok
860 int size = dbuf->getModularShort();
861 if (version > DRW::AC1021) {//2010+
862 bs = dbuf->getUModularChar();
863 }
864 std::vector<duint8> tmpByteStr(size);
865 dbuf->getBytes(tmpByteStr.data(), size);
866 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
867 dint16 oType = buff.getObjType(version);
868 buff.resetPosition();
869 DRW_DBG(" object type= ")DRW_dbg::getInstance()->print(" object type= "); DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
870 ret2 = vt.parseDwg(version, &buff, bs, pline.basePoint.z);
871 pline.addVertex(vt);
872 nextEntLink = vt.nextEntLink; \
873 prevEntLink = vt.prevEntLink;
874 ret = ret && ret2;
875 }
876 if (nextH == pline.lastEH)
877 nextH = 0; //redundant, but prevent read errors
878 else
879 nextH = nextEntLink;
880 }
881 } else {//2004+
882 for (std::list<duint32>::iterator it = pline.hadlesList.begin() ; it != pline.hadlesList.end(); ++it){
883 duint32 nextH = *it;
884 auto mit = ObjectMap.find(nextH);
885 if (mit==ObjectMap.end()) {
886 DRW_DBG("\nWARNING: Entity of block not found\n")DRW_dbg::getInstance()->print("\nWARNING: Entity of block not found\n"
)
;
887 ret = false;
888 continue;
889 } else {//foud entity reads it
890 oc = mit->second;
891 ObjectMap.erase(mit);
892 DRW_DBG("\nPline vertex, parsing entity: ")DRW_dbg::getInstance()->print("\nPline vertex, parsing entity: "
)
; DRW_DBGH(oc.handle)DRW_dbg::getInstance()->printH(oc.handle); DRW_DBG(", pos: ")DRW_dbg::getInstance()->print(", pos: "); DRW_DBG(oc.loc)DRW_dbg::getInstance()->print(oc.loc); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
893 DRW_Vertex vt;
894 dbuf->setPosition(oc.loc);
895 //RLZ: verify if pos is ok
896 int size = dbuf->getModularShort();
897 if (version > DRW::AC1021) {//2010+
898 bs = dbuf->getUModularChar();
899 }
900 std::vector<duint8> tmpByteStr(size);
901 dbuf->getBytes(tmpByteStr.data(), size);
902 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
903 dint16 oType = buff.getObjType(version);
904 buff.resetPosition();
905 DRW_DBG(" object type= ")DRW_dbg::getInstance()->print(" object type= "); DRW_DBG(oType)DRW_dbg::getInstance()->print(oType); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
906 ret2 = vt.parseDwg(version, &buff, bs, pline.basePoint.z);
907 pline.addVertex(vt);
908 nextEntLink = vt.nextEntLink; \
909 prevEntLink = vt.prevEntLink;
910 ret = ret && ret2;
911 }
912 }
913 }//end 2004+
914 DRW_DBG("\nRemoved SEQEND entity: ")DRW_dbg::getInstance()->print("\nRemoved SEQEND entity: "); DRW_DBGH(pline.seqEndH.ref)DRW_dbg::getInstance()->printH(pline.seqEndH.ref);DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
915 ObjectMap.erase(pline.seqEndH.ref);
916
917 return ret;
918}
919
920bool dwgReader::readDwgEntities(DRW_Interface& intfa, dwgBuffer *dbuf){
921 bool ret = true;
922
923 DRW_DBG("\nobject map total size= ")DRW_dbg::getInstance()->print("\nobject map total size= "); DRW_DBG(ObjectMap.size())DRW_dbg::getInstance()->print(ObjectMap.size());
924 auto itB=ObjectMap.begin();
925 auto itE=ObjectMap.end();
926 while (itB != itE) {
927 if (ret) {
928 // once readDwgEntity() failed, just clear the ObjectMap
929 ret = readDwgEntity( dbuf, itB->second, intfa);
930 }
931 ObjectMap.erase( itB);
932 itB = ObjectMap.begin();
933 }
934 return ret;
935}
936
937/**
938 * Reads a dwg drawing entity (dwg object entity) given its offset in the file
939 */
940bool dwgReader::readDwgEntity(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa){
941 bool ret = true;
942 duint32 bs = 0;
943
944 nextEntLink = prevEntLink = 0;// set to 0 to skip unimplemented entities
945 dbuf->setPosition(obj.loc);
946 //verify if position is ok:
947 if (!dbuf->isGood()){
948 DRW_DBG(" Warning: readDwgEntity, bad location\n")DRW_dbg::getInstance()->print(" Warning: readDwgEntity, bad location\n"
)
;
949 return false;
950 }
951 int size = dbuf->getModularShort();
952 if (version > DRW::AC1021) {//2010+
953 bs = dbuf->getUModularChar();
954 }
955 std::vector<duint8> tmpByteStr(size);
956 dbuf->getBytes(tmpByteStr.data(), size);
957 //verify if getBytes is ok:
958 if (!dbuf->isGood()) {
959 DRW_DBG(" Warning: readDwgEntity, bad size\n")DRW_dbg::getInstance()->print(" Warning: readDwgEntity, bad size\n"
)
;
960 return false;
961 }
962 dwgBuffer buff(tmpByteStr.data(), size, &decoder);
963 dint16 oType = buff.getObjType(version);
964 buff.resetPosition();
965
966 if (oType > 499){
967 auto it = classesmap.find(oType);
968 if (it == classesmap.end()){//fail, not found in classes set error
969 DRW_DBG("Class ")DRW_dbg::getInstance()->print("Class "); DRW_DBG(oType)DRW_dbg::getInstance()->print(oType);DRW_DBG("not found, handle: ")DRW_dbg::getInstance()->print("not found, handle: "); DRW_DBG(obj.handle)DRW_dbg::getInstance()->print(obj.handle); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
970 return false;
971 } else {
972 DRW_Class *cl = it->second;
973 if (cl->dwgType != 0)
974 oType = cl->dwgType;
975 }
976 }
977
978 obj.type = oType;
979 switch (oType) {
980 case 17: {
981 DRW_Arc e;
982 if (entryParse( e, buff, bs, ret)) {
983 intfa.addArc(e);
984 }
985 break; }
986 case 18: {
987 DRW_Circle e;
988 if (entryParse( e, buff, bs, ret)) {
989 intfa.addCircle(e);
990 }
991 break; }
992 case 19:{
993 DRW_Line e;
994 if (entryParse( e, buff, bs, ret)) {
995 intfa.addLine(e);
996 }
997 break;}
998 case 27: {
999 DRW_Point e;
1000 if (entryParse( e, buff, bs, ret)) {
1001 intfa.addPoint(e);
1002 }
1003 break; }
1004 case 35: {
1005 DRW_Ellipse e;
1006 if (entryParse( e, buff, bs, ret)) {
1007 intfa.addEllipse(e);
1008 }
1009 break; }
1010 case 7:
1011 case 8: {//minsert = 8
1012 DRW_Insert e;
1013 if (entryParse( e, buff, bs, ret)) {
1014 e.name = findTableName(DRW::BLOCK_RECORD,
1015 e.blockRecH.ref);//RLZ: find as block or blockrecord (ps & ps0)
1016 intfa.addInsert(e);
1017 }
1018 break; }
1019 case 77: {
1020 DRW_LWPolyline e;
1021 if (entryParse( e, buff, bs, ret)) {
1022 intfa.addLWPolyline(e);
1023 }
1024 break; }
1025 case 1: {
1026 DRW_Text e;
1027 if (entryParse( e, buff, bs, ret)) {
1028 e.style = findTableName(DRW::STYLE, e.styleH.ref);
1029 intfa.addText(e);
1030 }
1031 break; }
1032 case 44: {
1033 DRW_MText e;
1034 if (entryParse( e, buff, bs, ret)) {
1035 e.style = findTableName(DRW::STYLE, e.styleH.ref);
1036 intfa.addMText(e);
1037 }
1038 break; }
1039 case 28: {
1040 DRW_3Dface e;
1041 if (entryParse( e, buff, bs, ret)) {
1042 intfa.add3dFace(e);
1043 }
1044 break; }
1045 case 20: {
1046 DRW_DimOrdinate e;
1047 if (entryParse( e, buff, bs, ret)) {
1048 e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref);
1049 intfa.addDimOrdinate(&e);
1050 }
1051 break; }
1052 case 21: {
1053 DRW_DimLinear e;
1054 if (entryParse( e, buff, bs, ret)) {
1055 e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref);
1056 intfa.addDimLinear(&e);
1057 }
1058 break; }
1059 case 22: {
1060 DRW_DimAligned e;
1061 if (entryParse( e, buff, bs, ret)) {
1062 e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref);
1063 intfa.addDimAlign(&e);
1064 }
1065 break; }
1066 case 23: {
1067 DRW_DimAngular3p e;
1068 if (entryParse( e, buff, bs, ret)) {
1069 e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref);
1070 intfa.addDimAngular3P(&e);
1071 }
1072 break; }
1073 case 24: {
1074 DRW_DimAngular e;
1075 if (entryParse( e, buff, bs, ret)) {
1076 e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref);
1077 intfa.addDimAngular(&e);
1078 }
1079 break; }
1080 case 25: {
1081 DRW_DimRadial e;
1082 if (entryParse( e, buff, bs, ret)) {
1083 e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref);
1084 intfa.addDimRadial(&e);
1085 }
1086 break; }
1087 case 26: {
1088 DRW_DimDiametric e;
1089 if (entryParse( e, buff, bs, ret)) {
1090 e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref);
1091 intfa.addDimDiametric(&e);
1092 }
1093 break; }
1094 case 45: {
1095 DRW_Leader e;
1096 if (entryParse( e, buff, bs, ret)) {
1097 e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref);
1098 intfa.addLeader(&e);
1099 }
1100 break; }
1101 case 31: {
1102 DRW_Solid e;
1103 if (entryParse( e, buff, bs, ret)) {
1104 intfa.addSolid(e);
1105 }
1106 break; }
1107 case 78: {
1108 DRW_Hatch e;
1109 if (entryParse( e, buff, bs, ret)) {
1110 intfa.addHatch(&e);
1111 }
1112 break; }
1113 case 32: {
1114 DRW_Trace e;
1115 if (entryParse( e, buff, bs, ret)) {
1116 intfa.addTrace(e);
1117 }
1118 break; }
1119 case 34: {
1120 DRW_Viewport e;
1121 if (entryParse( e, buff, bs, ret)) {
1122 intfa.addViewport(e);
1123 }
1124 break; }
1125 case 36: {
1126 DRW_Spline e;
1127 if (entryParse( e, buff, bs, ret)) {
1128 intfa.addSpline(&e);
1129 }
1130 break; }
1131 case 40: {
1132 DRW_Ray e;
1133 if (entryParse( e, buff, bs, ret)) {
1134 intfa.addRay(e);
1135 }
1136 break; }
1137 case 15: // pline 2D
1138 case 16: // pline 3D
1139 case 29: { // pline PFACE
1140 DRW_Polyline e;
1141 if (entryParse( e, buff, bs, ret)) {
1142 readPlineVertex(e, dbuf);
1143 intfa.addPolyline(e);
1144 }
1145 break; }
1146// case 30: {
1147// DRW_Polyline e;// MESH (not pline)
1148// ENTRY_PARSE(e)
1149// intfa.addRay(e);
1150// break; }
1151 case 41: {
1152 DRW_Xline e;
1153 if (entryParse( e, buff, bs, ret)) {
1154 intfa.addXline(e);
1155 }
1156 break; }
1157 case 101: {
1158 DRW_Image e;
1159 if (entryParse( e, buff, bs, ret)) {
1160 intfa.addImage(&e);
1161 }
1162 break; }
1163
1164 default:
1165 //not supported or are object add to remaining map
1166 objObjectMap[obj.handle]= obj;
1167 break;
1168 }
1169 if (!ret){
1170 DRW_DBG("Warning: Entity type ")DRW_dbg::getInstance()->print("Warning: Entity type "); DRW_DBG(oType)DRW_dbg::getInstance()->print(oType);DRW_DBG("has failed, handle: ")DRW_dbg::getInstance()->print("has failed, handle: "); DRW_DBG(obj.handle)DRW_dbg::getInstance()->print(obj.handle); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1171 }
1172
1173 return ret;
1174}
1175
1176bool dwgReader::readDwgObjects(DRW_Interface& intfa, dwgBuffer *dbuf){
1177 bool ret = true;
1178
1179 duint32 i=0;
1180 DRW_DBG("\nentities map total size= ")DRW_dbg::getInstance()->print("\nentities map total size= "
)
; DRW_DBG(ObjectMap.size())DRW_dbg::getInstance()->print(ObjectMap.size());
1181 DRW_DBG("\nobjects map total size= ")DRW_dbg::getInstance()->print("\nobjects map total size= "
)
; DRW_DBG(objObjectMap.size())DRW_dbg::getInstance()->print(objObjectMap.size());
1182 auto itB=objObjectMap.begin();
1183 auto itE=objObjectMap.end();
1184 while (itB != itE){
1185 if (ret) {
1186 // once readDwgObject() failed, just clear the ObjectMap
1187 ret = readDwgObject(dbuf, itB->second, intfa);
1188 }
1189 objObjectMap.erase(itB);
1190 itB=objObjectMap.begin();
1191 }
1192 if (DRW_DBGGLDRW_dbg::getInstance()->getLevel() == DRW_dbg::Level::Debug) {
1193 for (auto it=remainingMap.begin(); it != remainingMap.end(); ++it){
1194 DRW_DBG("\nnum.# ")DRW_dbg::getInstance()->print("\nnum.# "); DRW_DBG(i++)DRW_dbg::getInstance()->print(i++); DRW_DBG(" Remaining object Handle, loc, type= ")DRW_dbg::getInstance()->print(" Remaining object Handle, loc, type= "
)
; DRW_DBG(it->first)DRW_dbg::getInstance()->print(it->first);
1195 DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(it->second.loc)DRW_dbg::getInstance()->print(it->second.loc); DRW_DBG(" ")DRW_dbg::getInstance()->print(" "); DRW_DBG(it->second.type)DRW_dbg::getInstance()->print(it->second.type);
1196 }
1197 DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1198 }
1199 return ret;
1200}
1201
1202/**
1203 * Reads a dwg drawing object (dwg object object) given its offset in the file
1204 */
1205bool dwgReader::readDwgObject(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa){
1206 bool ret = true;
1207 duint32 bs = 0;
1208
1209 dbuf->setPosition(obj.loc);
1210 //verify if position is ok:
1211 if (!dbuf->isGood()){
1212 DRW_DBG(" Warning: readDwgObject, bad location\n")DRW_dbg::getInstance()->print(" Warning: readDwgObject, bad location\n"
)
;
1213 return false;
1214 }
1215 int size = dbuf->getModularShort();
1216 if (version > DRW::AC1021) {//2010+
1217 bs = dbuf->getUModularChar();
1218 }
1219 duint8 *tmpByteStr = new duint8[size];
1220 dbuf->getBytes(tmpByteStr, size);
1221 //verify if getBytes is ok:
1222 if (!dbuf->isGood()){
1223 DRW_DBG(" Warning: readDwgObject, bad size\n")DRW_dbg::getInstance()->print(" Warning: readDwgObject, bad size\n"
)
;
1224 delete[]tmpByteStr;
1225 return false;
1226 }
1227 dwgBuffer buff(tmpByteStr, size, &decoder);
1228 //oType are set parsing entities
1229 dint16 oType = obj.type;
1230
1231 switch (oType){
1232 case 102: {
1233 DRW_ImageDef e;
1234 ret = e.parseDwg(version, &buff, bs);
1235 intfa.linkImage(&e);
1236 break; }
1237 default:
1238 //not supported object or entity add to remaining map for debug
1239 remainingMap[obj.handle]= obj;
1240 break;
1241 }
1242 if (!ret){
1243 DRW_DBG("Warning: Object type ")DRW_dbg::getInstance()->print("Warning: Object type "); DRW_DBG(oType)DRW_dbg::getInstance()->print(oType);DRW_DBG("has failed, handle: ")DRW_dbg::getInstance()->print("has failed, handle: "); DRW_DBG(obj.handle)DRW_dbg::getInstance()->print(obj.handle); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1244 }
1245 delete[]tmpByteStr;
1246 return ret;
1247}
1248
1249
1250
1251bool DRW_ObjControl::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
1252int unkData=0;
1253 bool ret = DRW_TableEntry::parseDwg(version, buf, nullptr, bs);
1254 DRW_DBG("\n***************************** parsing object control entry *********************************************\n")DRW_dbg::getInstance()->print("\n***************************** parsing object control entry *********************************************\n"
)
;
1255 if (!ret)
1256 return ret;
1257 //last parsed is: XDic Missing Flag 2004+
1258 int numEntries = buf->getBitLong();
1259 DRW_DBG(" num entries: ")DRW_dbg::getInstance()->print(" num entries: "); DRW_DBG(numEntries)DRW_dbg::getInstance()->print(numEntries); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1260 DRW_DBG("Remaining bytes: ")DRW_dbg::getInstance()->print("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes())DRW_dbg::getInstance()->print(buf->numRemainingBytes()); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1261
1262// if (oType == 68 && version== DRW::AC1015){//V2000 dimstyle seems have one unknown byte hard handle counter??
1263 if (oType == 68 && version > DRW::AC1014){//dimstyle seems have one unknown byte hard handle counter??
1264 unkData = buf->getRawChar8();
1265 DRW_DBG(" unknown v2000 byte: ")DRW_dbg::getInstance()->print(" unknown v2000 byte: "); DRW_DBG( unkData)DRW_dbg::getInstance()->print(unkData); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1266 }
1267 if (version > DRW::AC1018){//from v2007+ have a bit for strings follows (ObjControl do not have)
1268 int stringBit = buf->getBit();
1269 DRW_DBG(" string bit for v2007+: ")DRW_dbg::getInstance()->print(" string bit for v2007+: "); DRW_DBG( stringBit)DRW_dbg::getInstance()->print(stringBit); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1270 }
1271
1272 dwgHandle objectH = buf->getHandle();
1273 DRW_DBG(" NULL Handle: ")DRW_dbg::getInstance()->print(" NULL Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref)DRW_dbg::getInstance()->printHL(objectH.code, objectH.size
,objectH.ref)
; DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1274 DRW_DBG("Remaining bytes: ")DRW_dbg::getInstance()->print("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes())DRW_dbg::getInstance()->print(buf->numRemainingBytes()); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1275
1276// if (oType == 56 && version== DRW::AC1015){//linetype in 2004 seems not have XDicObjH or NULL handle
1277 if (xDictFlag !=1){//linetype in 2004 seems not have XDicObjH or NULL handle
1278 dwgHandle XDicObjH = buf->getHandle();
1279 DRW_DBG(" XDicObj control Handle: ")DRW_dbg::getInstance()->print(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref)DRW_dbg::getInstance()->printHL(XDicObjH.code, XDicObjH.size
,XDicObjH.ref)
; DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1280 DRW_DBG("Remaining bytes: ")DRW_dbg::getInstance()->print("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes())DRW_dbg::getInstance()->print(buf->numRemainingBytes()); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1281 }
1282//add 2 for modelspace, paperspace blocks & bylayer, byblock linetypes
1283 numEntries = ((oType == 48) || (oType == 56)) ? (numEntries +2) : numEntries;
1284
1285 for (int i =0; i< numEntries; i++){
1286 objectH = buf->getOffsetHandle(handle);
1287 if (objectH.ref != 0) //in vports R14 I found some NULL handles
1288 handlesList.push_back (objectH.ref);
1289 DRW_DBG(" objectH Handle: ")DRW_dbg::getInstance()->print(" objectH Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref)DRW_dbg::getInstance()->printHL(objectH.code, objectH.size
,objectH.ref)
; DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1290 DRW_DBG("Remaining bytes: ")DRW_dbg::getInstance()->print("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes())DRW_dbg::getInstance()->print(buf->numRemainingBytes()); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1291 }
1292
1293 for (int i =0; i< unkData; i++){
1294 objectH = buf->getOffsetHandle(handle);
1295 DRW_DBG(" unknown Handle: ")DRW_dbg::getInstance()->print(" unknown Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref)DRW_dbg::getInstance()->printHL(objectH.code, objectH.size
,objectH.ref)
; DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1296 DRW_DBG("Remaining bytes: ")DRW_dbg::getInstance()->print("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes())DRW_dbg::getInstance()->print(buf->numRemainingBytes()); DRW_DBG("\n")DRW_dbg::getInstance()->print("\n");
1297 }
1298 return buf->isGood();
1299}
1300