-
Notifications
You must be signed in to change notification settings - Fork 8
/
drw_entities.cpp
3073 lines (2918 loc) · 111 KB
/
drw_entities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
** libDXFrw - Library to read/write DXF files (ascii & binary) **
** **
** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com **
** **
** This library is free software, licensed under the terms of the GNU **
** General Public License as published by the Free Software Foundation, **
** either version 2 of the License, or (at your option) any later version. **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
******************************************************************************/
#include <cstdlib>
#include "drw_entities.h"
#include "intern/dxfreader.h"
#include "intern/dwgbuffer.h"
#include "intern/drw_dbg.h"
//! Calculate arbitrary axis
/*!
* Calculate arbitrary axis for apply extrusions
* @author Rallaz
*/
void DRW_Entity::calculateAxis(DRW_Coord extPoint){
//Follow the arbitrary DXF definitions for extrusion axes.
if (fabs(extPoint.x) < 0.015625 && fabs(extPoint.y) < 0.015625) {
//If we get here, implement Ax = Wy x N where Wy is [0,1,0] per the DXF spec.
//The cross product works out to Wy.y*N.z-Wy.z*N.y, Wy.z*N.x-Wy.x*N.z, Wy.x*N.y-Wy.y*N.x
//Factoring in the fixed values for Wy gives N.z,0,-N.x
extAxisX.x = extPoint.z;
extAxisX.y = 0;
extAxisX.z = -extPoint.x;
} else {
//Otherwise, implement Ax = Wz x N where Wz is [0,0,1] per the DXF spec.
//The cross product works out to Wz.y*N.z-Wz.z*N.y, Wz.z*N.x-Wz.x*N.z, Wz.x*N.y-Wz.y*N.x
//Factoring in the fixed values for Wz gives -N.y,N.x,0.
extAxisX.x = -extPoint.y;
extAxisX.y = extPoint.x;
extAxisX.z = 0;
}
extAxisX.unitize();
//Ay = N x Ax
extAxisY.x = (extPoint.y * extAxisX.z) - (extAxisX.y * extPoint.z);
extAxisY.y = (extPoint.z * extAxisX.x) - (extAxisX.z * extPoint.x);
extAxisY.z = (extPoint.x * extAxisX.y) - (extAxisX.x * extPoint.y);
extAxisY.unitize();
}
//! Extrude a point using arbitrary axis
/*!
* apply extrusion in a point using arbitrary axis (previous calculated)
* @author Rallaz
*/
void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point){
double px, py, pz;
px = (extAxisX.x*point->x)+(extAxisY.x*point->y)+(extPoint.x*point->z);
py = (extAxisX.y*point->x)+(extAxisY.y*point->y)+(extPoint.y*point->z);
pz = (extAxisX.z*point->x)+(extAxisY.z*point->y)+(extPoint.z*point->z);
point->x = px;
point->y = py;
point->z = pz;
}
bool DRW_Entity::parseCode(int code, dxfReader *reader){
switch (code) {
case 5:
handle = reader->getHandleString();
break;
case 330:
parentHandle = reader->getHandleString();
break;
case 8:
layer = reader->getUtf8String();
break;
case 6:
lineType = reader->getUtf8String();
break;
case 62:
color = reader->getInt32();
break;
case 370:
lWeight = DRW_LW_Conv::dxfInt2lineWidth(reader->getInt32());
break;
case 48:
ltypeScale = reader->getDouble();
break;
case 60:
visible = reader->getBool();
break;
case 420:
color24 = reader->getInt32();
break;
case 430:
colorName = reader->getString();
break;
case 67:
space = static_cast<DRW::Space>(reader->getInt32());
break;
case 102:
parseDxfGroups(code, reader);
break;
case 1000:
case 1001:
case 1002:
case 1003:
case 1004:
case 1005:
extData.push_back(new DRW_Variant(code, reader->getString()));
break;
case 1010:
case 1011:
case 1012:
case 1013:
curr = new DRW_Variant();
curr->addCoord();
curr->setCoordX(reader->getDouble());
curr->code = code;
extData.push_back(curr);
break;
case 1020:
case 1021:
case 1022:
case 1023:
if (curr)
curr->setCoordY(reader->getDouble());
break;
case 1030:
case 1031:
case 1032:
case 1033:
if (curr)
curr->setCoordZ(reader->getDouble());
curr=NULL;
break;
case 1040:
case 1041:
case 1042:
extData.push_back(new DRW_Variant(code, reader->getDouble() ));
break;
case 1070:
case 1071:
extData.push_back(new DRW_Variant(code, reader->getInt32() ));
break;
default:
break;
}
return true;
}
//parses dxf 102 groups to read entity
bool DRW_Entity::parseDxfGroups(int code, dxfReader *reader){
std::list<DRW_Variant> ls;
DRW_Variant curr;
int nc;
std::string appName= reader->getString();
if (!appName.empty() && appName.at(0)== '{'){
curr.addString(appName.substr(1, (int) appName.size()-1));
curr.code = code;
ls.push_back(curr);
while (code !=102 && appName.at(0)== '}'){
reader->readRec(&nc);
curr.code = code;
if (code == 330 || code == 360)
curr.addInt(reader->getHandleString());
else {
switch (reader->type) {
case dxfReader::STRING:
curr.addString(reader->getString());
break;
case dxfReader::INT32:
case dxfReader::INT64:
curr.addInt(reader->getInt32());
break;
case dxfReader::DOUBLE:
curr.addDouble(reader->getDouble());
break;
case dxfReader::BOOL:
curr.addInt(reader->getInt32());
break;
default:
break;
}
}
ls.push_back(curr);
}
}
appData.push_back(ls);
return true;
}
bool DRW_Entity::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer* strBuf, duint32 bs){
objSize=0;
DRW_DBG("\n***************************** parsing entity *********************************************\n");
oType = buf->getObjType(version);
DRW_DBG("Object type: "); DRW_DBG(oType); DRW_DBG(", "); DRW_DBGH(oType);
if (version > DRW::AC1014 && version < DRW::AC1024) {//2000 & 2004
objSize = buf->getRawLong32(); //RL 32bits object size in bits
DRW_DBG(" Object size: "); DRW_DBG(objSize); DRW_DBG("\n");
}
if (version > DRW::AC1021) {//2010+
duint32 ms = buf->size();
objSize = ms*8 - bs;
DRW_DBG(" Object size: "); DRW_DBG(objSize); DRW_DBG("\n");
}
if (strBuf != NULL && version > DRW::AC1018) {//2007+
strBuf->moveBitPos(objSize-1);
DRW_DBG(" strBuf strbit pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n");
if (strBuf->getBit() == 1){
DRW_DBG("DRW_TableEntry::parseDwg string bit is 1\n");
strBuf->moveBitPos(-17);
duint16 strDataSize = strBuf->getRawShort16();
DRW_DBG("\nDRW_TableEntry::parseDwg string strDataSize: "); DRW_DBGH(strDataSize); DRW_DBG("\n");
if ( (strDataSize& 0x8000) == 0x8000){
DRW_DBG("\nDRW_TableEntry::parseDwg string 0x8000 bit is set");
strBuf->moveBitPos(-33);//RLZ pending to verify
duint16 hiSize = strBuf->getRawShort16();
strDataSize = ((strDataSize&0x7fff) | (hiSize<<15));
}
strBuf->moveBitPos( -strDataSize -16); //-14
DRW_DBG("strBuf start strDataSize pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n");
} else
DRW_DBG("\nDRW_TableEntry::parseDwg string bit is 0");
DRW_DBG("strBuf start pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n");
}
dwgHandle ho = buf->getHandle();
handle = ho.ref;
DRW_DBG("Entity Handle: "); DRW_DBGHL(ho.code, ho.size, ho.ref);
dint16 extDataSize = buf->getBitShort(); //BS
DRW_DBG(" ext data size: "); DRW_DBG(extDataSize);
while (extDataSize>0 && buf->isGood()) {
/* RLZ: TODO */
dwgHandle ah = buf->getHandle();
DRW_DBG("App Handle: "); DRW_DBGHL(ah.code, ah.size, ah.ref);
duint8 *tmpExtData = new duint8[extDataSize];
buf->getBytes(tmpExtData, extDataSize);
dwgBuffer tmpExtDataBuf(tmpExtData, extDataSize, buf->decoder);
duint8 dxfCode = tmpExtDataBuf.getRawChar8();
DRW_DBG(" dxfCode: "); DRW_DBG(dxfCode);
switch (dxfCode){
case 0:{
duint8 strLength = tmpExtDataBuf.getRawChar8();
DRW_DBG(" strLength: "); DRW_DBG(strLength);
duint16 cp = tmpExtDataBuf.getBERawShort16();
DRW_DBG(" str codepage: "); DRW_DBG(cp);
for (int i=0;i< strLength+1;i++) {//string length + null terminating char
duint8 dxfChar = tmpExtDataBuf.getRawChar8();
DRW_DBG(" dxfChar: "); DRW_DBG(dxfChar);
}
break;
}
default:
/* RLZ: TODO */
break;
}
delete[]tmpExtData;
extDataSize = buf->getBitShort(); //BS
DRW_DBG(" ext data size: "); DRW_DBG(extDataSize);
} //end parsing extData (EED)
duint8 graphFlag = buf->getBit(); //B
DRW_DBG(" graphFlag: "); DRW_DBG(graphFlag); DRW_DBG("\n");
if (graphFlag) {
duint32 graphDataSize = buf->getRawLong32(); //RL 32bits
DRW_DBG("graphData in bytes: "); DRW_DBG(graphDataSize); DRW_DBG("\n");
// RLZ: TODO
//skip graphData bytes
duint8 *tmpGraphData = new duint8[graphDataSize];
buf->getBytes(tmpGraphData, graphDataSize);
dwgBuffer tmpGraphDataBuf(tmpGraphData, graphDataSize, buf->decoder);
DRW_DBG("graph data remaining bytes: "); DRW_DBG(tmpGraphDataBuf.numRemainingBytes()); DRW_DBG("\n");
delete[]tmpGraphData;
}
if (version < DRW::AC1015) {//14-
objSize = buf->getRawLong32(); //RL 32bits object size in bits
DRW_DBG(" Object size in bits: "); DRW_DBG(objSize); DRW_DBG("\n");
}
duint8 entmode = buf->get2Bits(); //BB
if (entmode == 0)
ownerHandle= true;
// entmode = 2;
else if(entmode ==2)
entmode = 0;
space = (DRW::Space)entmode; //RLZ verify cast values
DRW_DBG("entmode: "); DRW_DBG(entmode);
numReactors = buf->getBitShort(); //BS
DRW_DBG(", numReactors: "); DRW_DBG(numReactors);
if (version < DRW::AC1015) {//14-
if(buf->getBit()) {//is bylayer line type
lineType = "BYLAYER";
ltFlags = 0;
} else {
lineType = "";
ltFlags = 3;
}
DRW_DBG(" lineType: "); DRW_DBG(lineType.c_str());
DRW_DBG(" ltFlags: "); DRW_DBG(ltFlags);
}
if (version > DRW::AC1015) {//2004+
xDictFlag = buf->getBit();
DRW_DBG(" xDictFlag: "); DRW_DBG(xDictFlag); DRW_DBG("\n");
}
if (version > DRW::AC1024 || version < DRW::AC1018) {
haveNextLinks = buf->getBit(); //aka nolinks //B
DRW_DBG(", haveNextLinks (0 yes, 1 prev next): "); DRW_DBG(haveNextLinks); DRW_DBG("\n");
} else {
haveNextLinks = 1; //aka nolinks //B
DRW_DBG(", haveNextLinks (forced): "); DRW_DBG(haveNextLinks); DRW_DBG("\n");
}
//ENC color
color = buf->getEnColor(version); //BS or CMC //ok for R14 or negate
ltypeScale = buf->getBitDouble(); //BD
DRW_DBG(" entity color: "); DRW_DBG(color);
DRW_DBG(" ltScale: "); DRW_DBG(ltypeScale); DRW_DBG("\n");
if (version > DRW::AC1014) {//2000+
UTF8STRING plotStyleName;
for (duint8 i = 0; i<2;++i) { //two flags in one
plotFlags = buf->get2Bits(); //BB
if (plotFlags == 1)
plotStyleName = "byblock";
else if (plotFlags == 2)
plotStyleName = "continuous";
else if (plotFlags == 0)
plotStyleName = "bylayer";
else //handle at end
plotStyleName = "";
if (i == 0) {
ltFlags = plotFlags;
lineType = plotStyleName; //RLZ: howto solve? if needed plotStyleName;
DRW_DBG("ltFlags: "); DRW_DBG(ltFlags);
DRW_DBG(" lineType: "); DRW_DBG(lineType.c_str());
} else {
DRW_DBG(", plotFlags: "); DRW_DBG(plotFlags);
}
}
}
if (version > DRW::AC1018) {//2007+
materialFlag = buf->get2Bits(); //BB
DRW_DBG("materialFlag: "); DRW_DBG(materialFlag);
shadowFlag = buf->getRawChar8(); //RC
DRW_DBG("shadowFlag: "); DRW_DBG(shadowFlag); DRW_DBG("\n");
}
if (version > DRW::AC1021) {//2010+
duint8 visualFlags = buf->get2Bits(); //full & face visual style
DRW_DBG("shadowFlag 2: "); DRW_DBG(visualFlags); DRW_DBG("\n");
duint8 unk = buf->getBit(); //edge visual style
DRW_DBG("unknown bit: "); DRW_DBG(unk); DRW_DBG("\n");
}
dint16 invisibleFlag = buf->getBitShort(); //BS
DRW_DBG(" invisibleFlag: "); DRW_DBG(invisibleFlag);
if (version > DRW::AC1014) {//2000+
lWeight = DRW_LW_Conv::dwgInt2lineWidth( buf->getRawChar8() ); //RC
DRW_DBG(" lwFlag (lWeight): "); DRW_DBG(lWeight); DRW_DBG("\n");
}
//Only in blocks ????????
// if (version > DRW::AC1018) {//2007+
// duint8 unk = buf->getBit();
// DRW_DBG("unknown bit: "); DRW_DBG(unk); DRW_DBG("\n");
// }
return buf->isGood();
}
bool DRW_Entity::parseDwgEntHandle(DRW::Version version, dwgBuffer *buf){
if (version > DRW::AC1018) {//2007+ skip string area
buf->setPosition(objSize >> 3);
buf->setBitPos(objSize & 7);
}
if(ownerHandle){//entity are in block or in a polyline
dwgHandle ownerH = buf->getOffsetHandle(handle);
DRW_DBG("owner (parent) Handle: "); DRW_DBGHL(ownerH.code, ownerH.size, ownerH.ref); DRW_DBG("\n");
DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
parentHandle = ownerH.ref;
DRW_DBG("Block (parent) Handle: "); DRW_DBGHL(ownerH.code, ownerH.size, parentHandle); DRW_DBG("\n");
} else
DRW_DBG("NO Block (parent) Handle\n");
DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
for (int i=0; i< numReactors;++i) {
dwgHandle reactorsH = buf->getHandle();
DRW_DBG(" reactorsH control Handle: "); DRW_DBGHL(reactorsH.code, reactorsH.size, reactorsH.ref); DRW_DBG("\n");
}
if (xDictFlag !=1){//linetype in 2004 seems not have XDicObjH or NULL handle
dwgHandle XDicObjH = buf->getHandle();
DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n");
}
DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
if (version < DRW::AC1015) {//R14-
//layer handle
layerH = buf->getOffsetHandle(handle);
DRW_DBG(" layer Handle: "); DRW_DBGHL(layerH.code, layerH.size, layerH.ref); DRW_DBG("\n");
DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
//lineType handle
if(ltFlags == 3){
lTypeH = buf->getOffsetHandle(handle);
DRW_DBG("linetype Handle: "); DRW_DBGHL(lTypeH.code, lTypeH.size, lTypeH.ref); DRW_DBG("\n");
DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
}
}
if (version < DRW::AC1018) {//2000+
if (haveNextLinks == 0) {
dwgHandle nextLinkH = buf->getOffsetHandle(handle);
DRW_DBG(" prev nextLinkers Handle: "); DRW_DBGHL(nextLinkH.code, nextLinkH.size, nextLinkH.ref); DRW_DBG("\n");
DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
prevEntLink = nextLinkH.ref;
nextLinkH = buf->getOffsetHandle(handle);
DRW_DBG(" next nextLinkers Handle: "); DRW_DBGHL(nextLinkH.code, nextLinkH.size, nextLinkH.ref); DRW_DBG("\n");
DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
nextEntLink = nextLinkH.ref;
} else {
nextEntLink = handle+1;
prevEntLink = handle-1;
}
}
if (version > DRW::AC1015) {//2004+
//Parses Bookcolor handle
}
if (version > DRW::AC1014) {//2000+
//layer handle
layerH = buf->getOffsetHandle(handle);
DRW_DBG(" layer Handle: "); DRW_DBGHL(layerH.code, layerH.size, layerH.ref); DRW_DBG("\n");
DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
//lineType handle
if(ltFlags == 3){
lTypeH = buf->getOffsetHandle(handle);
DRW_DBG("linetype Handle: "); DRW_DBGHL(lTypeH.code, lTypeH.size, lTypeH.ref); DRW_DBG("\n");
DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
}
}
if (version > DRW::AC1014) {//2000+
if (version > DRW::AC1018) {//2007+
if (materialFlag == 3) {
dwgHandle materialH = buf->getOffsetHandle(handle);
DRW_DBG(" material Handle: "); DRW_DBGHL(materialH.code, materialH.size, materialH.ref); DRW_DBG("\n");
DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
}
if (shadowFlag == 3) {
dwgHandle shadowH = buf->getOffsetHandle(handle);
DRW_DBG(" shadow Handle: "); DRW_DBGHL(shadowH.code, shadowH.size, shadowH.ref); DRW_DBG("\n");
DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
}
}
if (plotFlags == 3) {
dwgHandle plotStyleH = buf->getOffsetHandle(handle);
DRW_DBG(" plot style Handle: "); DRW_DBGHL(plotStyleH.code, plotStyleH.size, plotStyleH.ref); DRW_DBG("\n");
DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
}
}
DRW_DBG("\n DRW_Entity::parseDwgEntHandle Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n");
return buf->isGood();
}
void DRW_Point::parseCode(int code, dxfReader *reader){
switch (code) {
case 10:
basePoint.x = reader->getDouble();
break;
case 20:
basePoint.y = reader->getDouble();
break;
case 30:
basePoint.z = reader->getDouble();
break;
case 39:
thickness = reader->getDouble();
break;
case 210:
haveExtrusion = true;
extPoint.x = reader->getDouble();
break;
case 220:
extPoint.y = reader->getDouble();
break;
case 230:
extPoint.z = reader->getDouble();
break;
default:
DRW_Entity::parseCode(code, reader);
break;
}
}
bool DRW_Point::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs);
if (!ret)
return ret;
DRW_DBG("\n***************************** parsing point *********************************************\n");
basePoint.x = buf->getBitDouble();
basePoint.y = buf->getBitDouble();
basePoint.z = buf->getBitDouble();
DRW_DBG("point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z);
thickness = buf->getThickness(version > DRW::AC1014);//BD
DRW_DBG("\nthickness: "); DRW_DBG(thickness);
extPoint = buf->getExtrusion(version > DRW::AC1014);
DRW_DBG(", Extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z);
double x_axis = buf->getBitDouble();//BD
DRW_DBG("\n x_axis: ");DRW_DBG(x_axis);DRW_DBG("\n");
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)
return ret;
// RS crc; //RS */
return buf->isGood();
}
void DRW_Line::parseCode(int code, dxfReader *reader){
switch (code) {
case 11:
secPoint.x = reader->getDouble();
break;
case 21:
secPoint.y = reader->getDouble();
break;
case 31:
secPoint.z = reader->getDouble();
break;
default:
DRW_Point::parseCode(code, reader);
break;
}
}
bool DRW_Line::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs);
if (!ret)
return ret;
DRW_DBG("\n***************************** parsing line *********************************************\n");
if (version < DRW::AC1015) {//14-
basePoint.x = buf->getBitDouble();
basePoint.y = buf->getBitDouble();
basePoint.z = buf->getBitDouble();
secPoint.x = buf->getBitDouble();
secPoint.y = buf->getBitDouble();
secPoint.z = buf->getBitDouble();
}
if (version > DRW::AC1014) {//2000+
bool zIsZero = buf->getBit(); //B
basePoint.x = buf->getRawDouble();//RD
secPoint.x = buf->getDefaultDouble(basePoint.x);//DD
basePoint.y = buf->getRawDouble();//RD
secPoint.y = buf->getDefaultDouble(basePoint.y);//DD
if (!zIsZero) {
basePoint.z = buf->getRawDouble();//RD
secPoint.z = buf->getDefaultDouble(basePoint.z);//DD
}
}
DRW_DBG("start point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z);
DRW_DBG("\nend point: "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z);
thickness = buf->getThickness(version > DRW::AC1014);//BD
DRW_DBG("\nthickness: "); DRW_DBG(thickness);
extPoint = buf->getExtrusion(version > DRW::AC1014);
DRW_DBG(", Extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z);DRW_DBG("\n");
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)
return ret;
// RS crc; //RS */
return buf->isGood();
}
bool DRW_Ray::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs);
if (!ret)
return ret;
DRW_DBG("\n***************************** parsing ray/xline *********************************************\n");
basePoint.x = buf->getBitDouble();
basePoint.y = buf->getBitDouble();
basePoint.z = buf->getBitDouble();
secPoint.x = buf->getBitDouble();
secPoint.y = buf->getBitDouble();
secPoint.z = buf->getBitDouble();
DRW_DBG("start point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z);
DRW_DBG("\nvector: "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z);
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)
return ret;
// RS crc; //RS */
return buf->isGood();
}
void DRW_Circle::applyExtrusion(){
if (haveExtrusion) {
//NOTE: Commenting these out causes the the arcs being tested to be located
//on the other side of the y axis (all x dimensions are negated).
calculateAxis(extPoint);
extrudePoint(extPoint, &basePoint);
}
}
void DRW_Circle::parseCode(int code, dxfReader *reader){
switch (code) {
case 40:
radious = reader->getDouble();
break;
default:
DRW_Point::parseCode(code, reader);
break;
}
}
bool DRW_Circle::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs);
if (!ret)
return ret;
DRW_DBG("\n***************************** parsing circle *********************************************\n");
basePoint.x = buf->getBitDouble();
basePoint.y = buf->getBitDouble();
basePoint.z = buf->getBitDouble();
DRW_DBG("center: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z);
radious = buf->getBitDouble();
DRW_DBG("\nradius: "); DRW_DBG(radious);
thickness = buf->getThickness(version > DRW::AC1014);
DRW_DBG(" thickness: "); DRW_DBG(thickness);
extPoint = buf->getExtrusion(version > DRW::AC1014);
DRW_DBG("\nextrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); DRW_DBG("\n");
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)
return ret;
// RS crc; //RS */
return buf->isGood();
}
void DRW_Arc::applyExtrusion(){
DRW_Circle::applyExtrusion();
if(haveExtrusion){
// If the extrusion vector has a z value less than 0, the angles for the arc
// have to be mirrored since DXF files use the right hand rule.
// Note that the following code only handles the special case where there is a 2D
// drawing with the z axis heading into the paper (or rather screen). An arbitrary
// extrusion axis (with x and y values greater than 1/64) may still have issues.
if (fabs(extPoint.x) < 0.015625 && fabs(extPoint.y) < 0.015625 && extPoint.z < 0.0) {
staangle=M_PI-staangle;
endangle=M_PI-endangle;
double temp = staangle;
staangle=endangle;
endangle=temp;
}
}
}
void DRW_Arc::parseCode(int code, dxfReader *reader){
switch (code) {
case 50:
staangle = reader->getDouble()/ ARAD;
break;
case 51:
endangle = reader->getDouble()/ ARAD;
break;
default:
DRW_Circle::parseCode(code, reader);
break;
}
}
bool DRW_Arc::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs);
if (!ret)
return ret;
DRW_DBG("\n***************************** parsing circle arc *********************************************\n");
basePoint.x = buf->getBitDouble();
basePoint.y = buf->getBitDouble();
basePoint.z = buf->getBitDouble();
DRW_DBG("center point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z);
radious = buf->getBitDouble();
DRW_DBG("\nradius: "); DRW_DBG(radious);
thickness = buf->getThickness(version > DRW::AC1014);
DRW_DBG(" thickness: "); DRW_DBG(thickness);
extPoint = buf->getExtrusion(version > DRW::AC1014);
DRW_DBG("\nextrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z);
staangle = buf->getBitDouble();
DRW_DBG("\nstart angle: "); DRW_DBG(staangle);
endangle = buf->getBitDouble();
DRW_DBG(" end angle: "); DRW_DBG(endangle); DRW_DBG("\n");
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)
return ret;
return buf->isGood();
}
void DRW_Ellipse::parseCode(int code, dxfReader *reader){
switch (code) {
case 40:
ratio = reader->getDouble();
break;
case 41:
staparam = reader->getDouble();
break;
case 42:
endparam = reader->getDouble();
break;
default:
DRW_Line::parseCode(code, reader);
break;
}
}
void DRW_Ellipse::applyExtrusion(){
if (haveExtrusion) {
calculateAxis(extPoint);
extrudePoint(extPoint, &secPoint);
double intialparam = staparam;
if (extPoint.z < 0.){
staparam = M_PIx2 - endparam;
endparam = M_PIx2 - intialparam;
}
}
}
//if ratio > 1 minor axis are greather than major axis, correct it
void DRW_Ellipse::correctAxis(){
bool complete = false;
if (staparam == endparam) {
staparam = 0.0;
endparam = M_PIx2; //2*M_PI;
complete = true;
}
if (ratio > 1){
if ( fabs(endparam - staparam - M_PIx2) < 1.0e-10)
complete = true;
double incX = secPoint.x;
secPoint.x = -(secPoint.y * ratio);
secPoint.y = incX*ratio;
ratio = 1/ratio;
if (!complete){
if (staparam < M_PI_2)
staparam += M_PI *2;
if (endparam < M_PI_2)
endparam += M_PI *2;
endparam -= M_PI_2;
staparam -= M_PI_2;
}
}
}
bool DRW_Ellipse::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs);
if (!ret)
return ret;
DRW_DBG("\n***************************** parsing ellipse *********************************************\n");
basePoint =buf->get3BitDouble();
DRW_DBG("center: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z);
secPoint =buf->get3BitDouble();
DRW_DBG(", axis: "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z); DRW_DBG("\n");
extPoint =buf->get3BitDouble();
DRW_DBG("Extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z);
ratio = buf->getBitDouble();//BD
DRW_DBG("\nratio: "); DRW_DBG(ratio);
staparam = buf->getBitDouble();//BD
DRW_DBG(" start param: "); DRW_DBG(staparam);
endparam = buf->getBitDouble();//BD
DRW_DBG(" end param: "); DRW_DBG(endparam); DRW_DBG("\n");
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)
return ret;
// RS crc; //RS */
return buf->isGood();
}
//parts are the number of vertex to split polyline, default 128
void DRW_Ellipse::toPolyline(DRW_Polyline *pol, int parts){
double radMajor, radMinor, cosRot, sinRot, incAngle, curAngle;
double cosCurr, sinCurr;
radMajor = sqrt(secPoint.x*secPoint.x + secPoint.y*secPoint.y);
radMinor = radMajor*ratio;
//calculate sin & cos of included angle
incAngle = atan2(secPoint.y, secPoint.x);
cosRot = cos(incAngle);
sinRot = sin(incAngle);
incAngle = M_PIx2 / parts;
curAngle = staparam;
int i = static_cast<int>(curAngle / incAngle);
do {
if (curAngle > endparam) {
curAngle = endparam;
i = parts+2;
}
cosCurr = cos(curAngle);
sinCurr = sin(curAngle);
double x = basePoint.x + (cosCurr*cosRot*radMajor) - (sinCurr*sinRot*radMinor);
double y = basePoint.y + (cosCurr*sinRot*radMajor) + (sinCurr*cosRot*radMinor);
pol->addVertex( DRW_Vertex(x, y, 0.0, 0.0));
curAngle = (++i)*incAngle;
} while (i<parts);
if ( fabs(endparam - staparam - M_PIx2) < 1.0e-10){
pol->flags = 1;
}
pol->layer = this->layer;
pol->lineType = this->lineType;
pol->color = this->color;
pol->lWeight = this->lWeight;
pol->extPoint = this->extPoint;
}
void DRW_Trace::applyExtrusion(){
if (haveExtrusion) {
calculateAxis(extPoint);
extrudePoint(extPoint, &basePoint);
extrudePoint(extPoint, &secPoint);
extrudePoint(extPoint, &thirdPoint);
extrudePoint(extPoint, &fourPoint);
}
}
void DRW_Trace::parseCode(int code, dxfReader *reader){
switch (code) {
case 12:
thirdPoint.x = reader->getDouble();
break;
case 22:
thirdPoint.y = reader->getDouble();
break;
case 32:
thirdPoint.z = reader->getDouble();
break;
case 13:
fourPoint.x = reader->getDouble();
break;
case 23:
fourPoint.y = reader->getDouble();
break;
case 33:
fourPoint.z = reader->getDouble();
break;
default:
DRW_Line::parseCode(code, reader);
break;
}
}
bool DRW_Trace::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs);
if (!ret)
return ret;
DRW_DBG("\n***************************** parsing Trace *********************************************\n");
thickness = buf->getThickness(version>DRW::AC1014);
basePoint.z = buf->getBitDouble();
basePoint.x = buf->getRawDouble();
basePoint.y = buf->getRawDouble();
secPoint.x = buf->getRawDouble();
secPoint.y = buf->getRawDouble();
secPoint.z = basePoint.z;
thirdPoint.x = buf->getRawDouble();
thirdPoint.y = buf->getRawDouble();
thirdPoint.z = basePoint.z;
fourPoint.x = buf->getRawDouble();
fourPoint.y = buf->getRawDouble();
fourPoint.z = basePoint.z;
extPoint = buf->getExtrusion(version>DRW::AC1014);
DRW_DBG(" - base "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z);
DRW_DBG("\n - sec "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z);
DRW_DBG("\n - third "); DRW_DBGPT(thirdPoint.x, thirdPoint.y, thirdPoint.z);
DRW_DBG("\n - fourth "); DRW_DBGPT(fourPoint.x, fourPoint.y, fourPoint.z);
DRW_DBG("\n - extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z);
DRW_DBG("\n - thickness: "); DRW_DBG(thickness); DRW_DBG("\n");
/* Common Entity Handle Data */
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)
return ret;
/* CRC X --- */
return buf->isGood();
}
void DRW_Solid::parseCode(int code, dxfReader *reader){
DRW_Trace::parseCode(code, reader);
}
bool DRW_Solid::parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs){
DRW_DBG("\n***************************** parsing Solid *********************************************\n");
return DRW_Trace::parseDwg(v, buf, bs);
}
void DRW_3Dface::parseCode(int code, dxfReader *reader){
switch (code) {
case 70:
invisibleflag = reader->getInt32();
break;
default:
DRW_Trace::parseCode(code, reader);
break;
}
}
bool DRW_3Dface::parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs){
bool ret = DRW_Entity::parseDwg(v, buf, NULL, bs);
if (!ret)
return ret;
DRW_DBG("\n***************************** parsing 3Dface *********************************************\n");
if ( v < DRW::AC1015 ) {// R13 & R14
basePoint.x = buf->getBitDouble();
basePoint.y = buf->getBitDouble();
basePoint.z = buf->getBitDouble();
secPoint.x = buf->getBitDouble();
secPoint.y = buf->getBitDouble();
secPoint.z = buf->getBitDouble();
thirdPoint.x = buf->getBitDouble();
thirdPoint.y = buf->getBitDouble();
thirdPoint.z = buf->getBitDouble();
fourPoint.x = buf->getBitDouble();
fourPoint.y = buf->getBitDouble();
fourPoint.z = buf->getBitDouble();
invisibleflag = buf->getBitShort();
} else { // 2000+
bool has_no_flag = buf->getBit();
bool z_is_zero = buf->getBit();
basePoint.x = buf->getRawDouble();
basePoint.y = buf->getRawDouble();
basePoint.z = z_is_zero ? 0.0 : buf->getRawDouble();
secPoint.x = buf->getDefaultDouble(basePoint.x);
secPoint.y = buf->getDefaultDouble(basePoint.y);
secPoint.z = buf->getDefaultDouble(basePoint.z);
thirdPoint.x = buf->getDefaultDouble(secPoint.x);
thirdPoint.y = buf->getDefaultDouble(secPoint.y);
thirdPoint.z = buf->getDefaultDouble(secPoint.z);
fourPoint.x = buf->getDefaultDouble(thirdPoint.x);
fourPoint.y = buf->getDefaultDouble(thirdPoint.y);
fourPoint.z = buf->getDefaultDouble(thirdPoint.z);
invisibleflag = has_no_flag ? (int)NoEdge : buf->getBitShort();
}
drw_assert(invisibleflag>=NoEdge);
drw_assert(invisibleflag<=AllEdges);
DRW_DBG(" - base "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); DRW_DBG("\n");
DRW_DBG(" - sec "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z); DRW_DBG("\n");
DRW_DBG(" - third "); DRW_DBGPT(thirdPoint.x, thirdPoint.y, thirdPoint.z); DRW_DBG("\n");
DRW_DBG(" - fourth "); DRW_DBGPT(fourPoint.x, fourPoint.y, fourPoint.z); DRW_DBG("\n");
DRW_DBG(" - Invisibility mask: "); DRW_DBG(invisibleflag); DRW_DBG("\n");
/* Common Entity Handle Data */
ret = DRW_Entity::parseDwgEntHandle(v, buf);
if (!ret)
return ret;
return buf->isGood();
}
void DRW_Block::parseCode(int code, dxfReader *reader){
switch (code) {
case 2:
name = reader->getUtf8String();
break;
case 70:
flags = reader->getInt32();
break;
default:
DRW_Point::parseCode(code, reader);
break;
}
}
bool DRW_Block::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
dwgBuffer sBuff = *buf;
dwgBuffer *sBuf = buf;
if (version > DRW::AC1018) {//2007+
sBuf = &sBuff; //separate buffer for strings
}
bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs);
if (!ret)
return ret;
if (!isEnd){
DRW_DBG("\n***************************** parsing block *********************************************\n");
name = sBuf->getVariableText(version, false);
DRW_DBG("Block name: "); DRW_DBG(name.c_str()); DRW_DBG("\n");
} else {
DRW_DBG("\n***************************** parsing end block *********************************************\n");
}
if (version > DRW::AC1018) {//2007+
duint8 unk = buf->getBit();
DRW_DBG("unknown bit: "); DRW_DBG(unk); DRW_DBG("\n");
}
// X handleAssoc; //X
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)