~ubuntu-branches/debian/jessie/dxflib/jessie

« back to all changes in this revision

Viewing changes to .pc/hatches_fixes.patch/src/dl_dxf.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2013-12-13 16:41:48 UTC
  • mfrom: (8.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20131213164148-m20ph2ja1d4vlxv4
Tags: 2.5.0.0-2
Merge from experimental to unstable. (Closes: #731577)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
** $Id: dl_dxf.cpp 8865 2008-02-04 18:54:02Z andrew $
3
 
**
4
 
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5
 
**
6
 
** This file is part of the dxflib project.
7
 
**
8
 
** This file may be distributed and/or modified under the terms of the
9
 
** GNU General Public License version 2 as published by the Free Software
10
 
** Foundation and appearing in the file LICENSE.GPL included in the
11
 
** packaging of this file.
12
 
**
13
 
** Licensees holding valid dxflib Professional Edition licenses may use 
14
 
** this file in accordance with the dxflib Commercial License
15
 
** Agreement provided with the Software.
16
 
**
17
 
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18
 
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19
 
**
20
 
** See http://www.ribbonsoft.com for further details.
21
 
**
22
 
** Contact info@ribbonsoft.com if any conditions of this licensing are
23
 
** not clear to you.
24
 
**
25
 
**********************************************************************/
26
 
 
27
 
#include "dl_dxf.h"
28
 
 
29
 
#include <algorithm>
30
 
#include <string>
31
 
#include <cstdio>
32
 
#include <cassert>
33
 
#include <cmath>
34
 
 
35
 
#include "dl_attributes.h"
36
 
#include "dl_codes.h"
37
 
#include "dl_creationinterface.h"
38
 
#include "dl_writer_ascii.h"
39
 
 
40
 
 
41
 
/**
42
 
 * Default constructor.
43
 
 */
44
 
DL_Dxf::DL_Dxf() {
45
 
    styleHandleStd = 0;
46
 
    version = VER_2000;
47
 
 
48
 
    vertices = NULL;
49
 
    maxVertices = 0;
50
 
    vertexIndex = 0;
51
 
 
52
 
    knots = NULL;
53
 
    maxKnots = 0;
54
 
    knotIndex = 0;
55
 
 
56
 
    controlPoints = NULL;
57
 
    maxControlPoints = 0;
58
 
    controlPointIndex = 0;
59
 
 
60
 
    leaderVertices = NULL;
61
 
    maxLeaderVertices = 0;
62
 
    leaderVertexIndex = 0;
63
 
 
64
 
    hatchLoops = NULL;
65
 
    maxHatchLoops = 0;
66
 
    hatchLoopIndex = -1;
67
 
    hatchEdges = NULL;
68
 
    maxHatchEdges = NULL;
69
 
    hatchEdgeIndex = NULL;
70
 
    dropEdges = false;
71
 
}
72
 
 
73
 
 
74
 
 
75
 
/**
76
 
 * Destructor.
77
 
 */
78
 
DL_Dxf::~DL_Dxf() {
79
 
    if (vertices!=NULL) {
80
 
        delete[] vertices;
81
 
    }
82
 
    if (knots!=NULL) {
83
 
        delete[] knots;
84
 
    }
85
 
    if (controlPoints!=NULL) {
86
 
        delete[] controlPoints;
87
 
    }
88
 
    if (leaderVertices!=NULL) {
89
 
        delete[] leaderVertices;
90
 
    }
91
 
    if (hatchLoops!=NULL) {
92
 
        delete[] hatchLoops;
93
 
    }
94
 
    if (hatchEdges!=NULL) {
95
 
        for (int i=0; i<maxHatchLoops; ++i) {
96
 
            if (hatchEdges[i]!=NULL) {
97
 
                delete[] hatchEdges[i];
98
 
            }
99
 
        }
100
 
        delete[] hatchEdges;
101
 
    }
102
 
    if (maxHatchEdges!=NULL) {
103
 
        delete[] maxHatchEdges;
104
 
    }
105
 
    if (hatchEdgeIndex!=NULL) {
106
 
        delete[] hatchEdgeIndex;
107
 
    }
108
 
}
109
 
 
110
 
 
111
 
 
112
 
/**
113
 
 * @brief Reads the given file and calls the appropriate functions in
114
 
 * the given creation interface for every entity found in the file.
115
 
 *
116
 
 * @param file Input
117
 
 *              Path and name of file to read
118
 
 * @param creationInterface
119
 
 *              Pointer to the class which takes care of the entities in the file.
120
 
 *
121
 
 * @retval true If \p file could be opened.
122
 
 * @retval false If \p file could not be opened.
123
 
 */
124
 
bool DL_Dxf::in(const string& file, DL_CreationInterface* creationInterface) {
125
 
    FILE *fp;
126
 
    firstCall = true;
127
 
    currentEntity = DL_UNKNOWN;
128
 
    int errorCounter = 0;
129
 
 
130
 
    fp = fopen(file.c_str(), "rt");
131
 
    if (fp) {
132
 
        while (readDxfGroups(fp, creationInterface, &errorCounter)) {}
133
 
        fclose(fp);
134
 
        if (errorCounter>0) {
135
 
            std::cerr << "DXF Filter: There have been " << errorCounter <<
136
 
            " errors. The drawing might be incomplete / incorrect.\n";
137
 
        }
138
 
        return true;
139
 
    }
140
 
 
141
 
    return false;
142
 
}
143
 
 
144
 
 
145
 
 
146
 
/**
147
 
 * Reads a DXF file from an existing stream.
148
 
 *
149
 
 * @param stream The string stream.
150
 
 * @param creationInterface
151
 
 *              Pointer to the class which takes care of the entities in the file.
152
 
 *
153
 
 * @retval true If \p file could be opened.
154
 
 * @retval false If \p file could not be opened.
155
 
 */
156
 
#ifndef __GCC2x__
157
 
bool DL_Dxf::in(std::stringstream& stream,
158
 
                DL_CreationInterface* creationInterface) {
159
 
    
160
 
    int errorCounter = 0;
161
 
 
162
 
    if (stream.good()) {
163
 
        firstCall=true;
164
 
        currentEntity = DL_UNKNOWN;
165
 
        while (readDxfGroups(stream, creationInterface, &errorCounter)) {}
166
 
        if (errorCounter>0) {
167
 
            std::cerr << "DXF Filter: There have been " << errorCounter <<
168
 
            " errors. The drawing might be incomplete / incorrect.\n";
169
 
        }
170
 
        return true;
171
 
    }
172
 
    return false;
173
 
}
174
 
#endif
175
 
 
176
 
 
177
 
 
178
 
/**
179
 
 * @brief Reads a group couplet from a DXF file.  Calls another function
180
 
 * to process it.
181
 
 *
182
 
 * A group couplet consists of two lines that represent a single
183
 
 * piece of data.  An integer constant on the first line indicates
184
 
 * the type of data.  The value is on the next line.\n
185
 
 *
186
 
 * This function reads a couplet, determines the type of data, and
187
 
 * passes the value to the the appropriate handler function of
188
 
 * \p creationInterface.\n
189
 
 * 
190
 
 * \p fp is advanced so that the next call to \p readDXFGroups() reads
191
 
 * the next couplet in the file.
192
 
 *
193
 
 * @param fp Handle of input file
194
 
 * @param creationInterface Handle of class which processes entities
195
 
 *              in the file
196
 
 *
197
 
 * @retval true If EOF not reached.
198
 
 * @retval false If EOF reached.
199
 
 */
200
 
bool DL_Dxf::readDxfGroups(FILE *fp, DL_CreationInterface* creationInterface,
201
 
                           int* errorCounter) {
202
 
 
203
 
    bool ok = true;
204
 
    static int line = 1;
205
 
 
206
 
    // Read one group of the DXF file and chop the lines:
207
 
    if (DL_Dxf::getChoppedLine(groupCodeTmp, DL_DXF_MAXLINE, fp) &&
208
 
            DL_Dxf::getChoppedLine(groupValue, DL_DXF_MAXLINE, fp) ) {
209
 
 
210
 
        groupCode = (unsigned int)stringToInt(groupCodeTmp, &ok);
211
 
 
212
 
        if (ok) {
213
 
            //std::cerr << groupCode << "\n";
214
 
            //std::cerr << groupValue << "\n";
215
 
            line+=2;
216
 
            processDXFGroup(creationInterface, groupCode, groupValue);
217
 
        } else {
218
 
            std::cerr << "DXF read error: Line: " << line << "\n";
219
 
            if (errorCounter!=NULL) {
220
 
                (*errorCounter)++;
221
 
            }
222
 
            // try to fix:
223
 
            std::cerr << "DXF read error: trying to fix..\n";
224
 
            // drop a line to sync:
225
 
            DL_Dxf::getChoppedLine(groupCodeTmp, DL_DXF_MAXLINE, fp);
226
 
        }
227
 
    }
228
 
 
229
 
    return !feof(fp);
230
 
}
231
 
 
232
 
 
233
 
 
234
 
/**
235
 
 * Same as above but for stringstreams.
236
 
 */
237
 
#ifndef __GCC2x__
238
 
bool DL_Dxf::readDxfGroups(std::stringstream& stream,
239
 
                           DL_CreationInterface* creationInterface,
240
 
                           int* errorCounter) {
241
 
 
242
 
    bool ok = true;
243
 
    static int line = 1;
244
 
 
245
 
    // Read one group of the DXF file and chop the lines:
246
 
    if (DL_Dxf::getChoppedLine(groupCodeTmp, DL_DXF_MAXLINE, stream) &&
247
 
            DL_Dxf::getChoppedLine(groupValue, DL_DXF_MAXLINE, stream) ) {
248
 
 
249
 
        groupCode = (unsigned int)stringToInt(groupCodeTmp, &ok);
250
 
 
251
 
        if (ok) {
252
 
            //std::cout << "group code: " << groupCode << "\n";
253
 
            //std::cout << "group value: " << groupValue << "\n";
254
 
            line+=2;
255
 
            processDXFGroup(creationInterface, groupCode, groupValue);
256
 
        } else {
257
 
            std::cerr << "DXF read error: Line: " << line << "\n";
258
 
            if (errorCounter!=NULL) {
259
 
                (*errorCounter)++;
260
 
            }
261
 
            // try to fix:
262
 
            //std::cerr << "DXF read error: trying to fix..\n";
263
 
            // drop a line to sync:
264
 
            //DL_Dxf::getChoppedLine(groupCodeTmp, DL_DXF_MAXLINE, stream);
265
 
        }
266
 
    }
267
 
    return !stream.eof();
268
 
}
269
 
#endif
270
 
 
271
 
 
272
 
 
273
 
/**
274
 
 * @brief Reads line from file & strips whitespace at start and newline 
275
 
 * at end.
276
 
 *
277
 
 * @param s Output\n
278
 
 *              Pointer to character array that chopped line will be returned in.
279
 
 * @param size Size of \p s.  (Including space for NULL.)
280
 
 * @param fp Input\n
281
 
 *              Handle of input file.
282
 
 *
283
 
 * @retval true if line could be read
284
 
 * @retval false if \p fp is already at end of file
285
 
 *
286
 
 * @todo Change function to use safer FreeBSD strl* functions
287
 
 * @todo Is it a problem if line is blank (i.e., newline only)?
288
 
 *              Then, when function returns, (s==NULL).
289
 
 */
290
 
bool DL_Dxf::getChoppedLine(char *s, unsigned int size, FILE *fp) {
291
 
    if (!feof(fp)) {
292
 
        // The whole line in the file.  Includes space for NULL.
293
 
        char* wholeLine = new char[size];
294
 
        // Only the useful part of the line
295
 
        char* line;
296
 
 
297
 
        line = fgets(wholeLine, size, fp);
298
 
 
299
 
        if (line!=NULL && line[0] != '\0') { // Evaluates to fgets() retval
300
 
            // line == wholeLine at this point.
301
 
            // Both guaranteed to be NULL terminated.
302
 
 
303
 
            // Strip leading whitespace and trailing CR/LF.
304
 
            stripWhiteSpace(&line);
305
 
 
306
 
            strncpy(s, line, size);
307
 
            s[size] = '\0';
308
 
            // s should always be NULL terminated, because:
309
 
            assert(size > strlen(line));
310
 
        }
311
 
 
312
 
        delete[] wholeLine; // Done with wholeLine
313
 
 
314
 
        return true;
315
 
    } else {
316
 
        s[0] = '\0';
317
 
        return false;
318
 
    }
319
 
}
320
 
 
321
 
 
322
 
 
323
 
/**
324
 
 * Same as above but for stringstreams.
325
 
 */
326
 
#ifndef __GCC2x__
327
 
bool DL_Dxf::getChoppedLine(char *s, unsigned int size,
328
 
                            std::stringstream& stream) {
329
 
 
330
 
    if (!stream.eof()) {
331
 
        // Only the useful part of the line
332
 
        char* line = new char[size+1];
333
 
        char* oriLine = line;
334
 
        stream.getline(line, size);
335
 
        stripWhiteSpace(&line);
336
 
        strncpy(s, line, size);
337
 
        s[size] = '\0';
338
 
        assert(size > strlen(s));
339
 
        delete[] oriLine;
340
 
        return true;
341
 
    } else {
342
 
        s[0] = '\0';
343
 
        return false;
344
 
    }
345
 
}
346
 
#endif
347
 
 
348
 
 
349
 
 
350
 
/**
351
 
 * @brief Strips leading whitespace and trailing Carriage Return (CR)
352
 
 * and Line Feed (LF) from NULL terminated string.
353
 
 *
354
 
 * @param s Input and output.
355
 
 *              NULL terminates string.
356
 
 *
357
 
 * @retval true if \p s is non-NULL
358
 
 * @retval false if \p s is NULL
359
 
 */
360
 
bool DL_Dxf::stripWhiteSpace(char** s) {
361
 
    // last non-NULL char:
362
 
    int lastChar = strlen(*s) - 1;
363
 
 
364
 
    // Is last character CR or LF?
365
 
    while ( (lastChar >= 0) &&
366
 
            (((*s)[lastChar] == 10) || ((*s)[lastChar] == 13) ||
367
 
             ((*s)[lastChar] == ' ' || ((*s)[lastChar] == '\t'))) ) {
368
 
        (*s)[lastChar] = '\0';
369
 
        lastChar--;
370
 
    }
371
 
 
372
 
    // Skip whitespace, excluding \n, at beginning of line
373
 
    while ((*s)[0]==' ' || (*s)[0]=='\t') {
374
 
        ++(*s);
375
 
    }
376
 
    
377
 
    return ((*s) ? true : false);
378
 
}
379
 
 
380
 
 
381
 
 
382
 
/**
383
 
 * Processes a group (pair of group code and value).
384
 
 *
385
 
 * @param creationInterface Handle to class that creates entities and
386
 
 * other CAD data from DXF group codes
387
 
 *
388
 
 * @param groupCode Constant indicating the data type of the group.
389
 
 * @param groupValue The data value.
390
 
 *
391
 
 * @retval true if done processing current entity and new entity begun
392
 
 * @retval false if not done processing current entity
393
 
*/
394
 
bool DL_Dxf::processDXFGroup(DL_CreationInterface* creationInterface,
395
 
                             int groupCode, const char *groupValue) {
396
 
 
397
 
    // Init on first call
398
 
    if (firstCall) {
399
 
        for (int i=0; i<DL_DXF_MAXGROUPCODE; ++i) {
400
 
            values[i][0] = '\0';
401
 
        }
402
 
        settingValue[0] = '\0';
403
 
        firstCall=false;
404
 
    }
405
 
 
406
 
    // Indicates comment or dxflib version:
407
 
    if (groupCode==999) {
408
 
        if (groupValue!=NULL) {
409
 
            if (!strncmp(groupValue, "dxflib", 6)) {
410
 
                libVersion = getLibVersion(&groupValue[7]);
411
 
            }
412
 
            
413
 
            addComment(creationInterface, groupValue);
414
 
        }
415
 
    }
416
 
 
417
 
    // Indicates start of new entity or var
418
 
    else if (groupCode==0 || groupCode==9) {
419
 
 
420
 
        // If new entity is encountered, the last one must be complete
421
 
        // prepare attributes which can be used for most entities:
422
 
        char name[DL_DXF_MAXLINE+1];
423
 
        if ((values[8])[0]!='\0') {
424
 
            strcpy(name, values[8]);
425
 
        }
426
 
        // defaults to layer '0':
427
 
        else {
428
 
            strcpy(name, "0");
429
 
        }
430
 
 
431
 
        int width;
432
 
        // Compatibillity with qcad1:
433
 
        if ((values[39])[0]!='\0' &&
434
 
                (values[370])[0]=='\0') {
435
 
            width = toInt(values[39], -1);
436
 
        }
437
 
        // since autocad 2002:
438
 
        else if ((values[370])[0]!='\0') {
439
 
            width = toInt(values[370], -1);
440
 
        }
441
 
        // default to BYLAYER:
442
 
        else {
443
 
            width = -1;
444
 
        }
445
 
 
446
 
        int color;
447
 
        color = toInt(values[62], 256);
448
 
 
449
 
        char linetype[DL_DXF_MAXLINE+1];
450
 
        strcpy(linetype, toString(values[6], "BYLAYER"));
451
 
 
452
 
        attrib = DL_Attributes(values[8],          // layer
453
 
                               color,              // color
454
 
                               width,              // width
455
 
                               linetype);          // linetype
456
 
        creationInterface->setAttributes(attrib);
457
 
 
458
 
        creationInterface->setExtrusion(toReal(values[210], 0.0),
459
 
                                        toReal(values[220], 0.0),
460
 
                                        toReal(values[230], 1.0),
461
 
                                        toReal(values[30], 0.0));
462
 
 
463
 
        // Add the last entity via creationInterface
464
 
        switch (currentEntity) {
465
 
        case DL_SETTING:
466
 
            addSetting(creationInterface);
467
 
            break;
468
 
 
469
 
        case DL_LAYER:
470
 
            addLayer(creationInterface);
471
 
            break;
472
 
 
473
 
        case DL_BLOCK:
474
 
            addBlock(creationInterface);
475
 
            break;
476
 
 
477
 
        case DL_ENDBLK:
478
 
            endBlock(creationInterface);
479
 
            break;
480
 
 
481
 
        case DL_ENTITY_POINT:
482
 
            addPoint(creationInterface);
483
 
            break;
484
 
 
485
 
        case DL_ENTITY_LINE:
486
 
            addLine(creationInterface);
487
 
            break;
488
 
 
489
 
        case DL_ENTITY_POLYLINE:
490
 
            //bulge = toReal(values[42]);
491
 
            // fall through
492
 
        case DL_ENTITY_LWPOLYLINE:
493
 
            addPolyline(creationInterface);
494
 
            break;
495
 
 
496
 
        case DL_ENTITY_VERTEX:
497
 
            addVertex(creationInterface);
498
 
            break;
499
 
 
500
 
        case DL_ENTITY_SPLINE:
501
 
            addSpline(creationInterface);
502
 
            break;
503
 
 
504
 
        case DL_ENTITY_ARC:
505
 
            addArc(creationInterface);
506
 
            break;
507
 
 
508
 
        case DL_ENTITY_CIRCLE:
509
 
            addCircle(creationInterface);
510
 
            break;
511
 
 
512
 
        case DL_ENTITY_ELLIPSE:
513
 
            addEllipse(creationInterface);
514
 
            break;
515
 
 
516
 
        case DL_ENTITY_INSERT:
517
 
            addInsert(creationInterface);
518
 
            break;
519
 
 
520
 
        case DL_ENTITY_MTEXT:
521
 
            addMText(creationInterface);
522
 
            break;
523
 
 
524
 
        case DL_ENTITY_TEXT:
525
 
            addText(creationInterface);
526
 
            break;
527
 
 
528
 
        case DL_ENTITY_ATTRIB:
529
 
            addAttrib(creationInterface);
530
 
            break;
531
 
 
532
 
        case DL_ENTITY_DIMENSION: {
533
 
                int type = (toInt(values[70], 0)&0x07);
534
 
 
535
 
                switch (type) {
536
 
                case 0:
537
 
                    addDimLinear(creationInterface);
538
 
                    break;
539
 
 
540
 
                case 1:
541
 
                    addDimAligned(creationInterface);
542
 
                    break;
543
 
 
544
 
                case 2:
545
 
                    addDimAngular(creationInterface);
546
 
                    break;
547
 
 
548
 
                case 3:
549
 
                    addDimDiametric(creationInterface);
550
 
                    break;
551
 
 
552
 
                case 4:
553
 
                    addDimRadial(creationInterface);
554
 
                    break;
555
 
 
556
 
                case 5:
557
 
                    addDimAngular3P(creationInterface);
558
 
                    break;
559
 
                
560
 
                case 6:
561
 
                    addDimOrdinate(creationInterface);
562
 
                    break;
563
 
 
564
 
                default:
565
 
                    break;
566
 
                }
567
 
            }
568
 
            break;
569
 
 
570
 
        case DL_ENTITY_LEADER:
571
 
            addLeader(creationInterface);
572
 
            break;
573
 
 
574
 
        case DL_ENTITY_HATCH:
575
 
            addHatch(creationInterface);
576
 
            break;
577
 
 
578
 
        case DL_ENTITY_IMAGE:
579
 
            addImage(creationInterface);
580
 
            break;
581
 
 
582
 
        case DL_ENTITY_IMAGEDEF:
583
 
            addImageDef(creationInterface);
584
 
            break;
585
 
 
586
 
        case DL_ENTITY_TRACE:
587
 
            addTrace(creationInterface);
588
 
            break;
589
 
        
590
 
        case DL_ENTITY_3DFACE:
591
 
            add3dFace(creationInterface);
592
 
            break;
593
 
 
594
 
        case DL_ENTITY_SOLID:
595
 
            addSolid(creationInterface);
596
 
            break;
597
 
 
598
 
        case DL_ENTITY_SEQEND:
599
 
            endSequence(creationInterface);
600
 
            break;
601
 
        
602
 
        default:
603
 
            break;
604
 
        }
605
 
 
606
 
 
607
 
        // reset all values (they are not persistent and only this
608
 
        //  way we can detect default values for unstored settings)
609
 
        for (int i=0; i<DL_DXF_MAXGROUPCODE; ++i) {
610
 
            values[i][0] = '\0';
611
 
        }
612
 
        settingValue[0] = '\0';
613
 
        settingKey[0] = '\0';
614
 
 
615
 
 
616
 
        // Last DXF entity or setting has been handled
617
 
        // Now determine what the next entity or setting type is
618
 
 
619
 
                int prevEntity = currentEntity;
620
 
 
621
 
        // Read DXF settings:
622
 
        if (groupValue[0]=='$') {
623
 
            currentEntity = DL_SETTING;
624
 
            strncpy(settingKey, groupValue, DL_DXF_MAXLINE);
625
 
            settingKey[DL_DXF_MAXLINE] = '\0';
626
 
        }
627
 
        // Read Layers:
628
 
        else if (!strcmp(groupValue, "LAYER")) {
629
 
            currentEntity = DL_LAYER;
630
 
 
631
 
        }
632
 
        // Read Blocks:
633
 
        else if (!strcmp(groupValue, "BLOCK")) {
634
 
            currentEntity = DL_BLOCK;
635
 
        } else if (!strcmp(groupValue, "ENDBLK")) {
636
 
            currentEntity = DL_ENDBLK;
637
 
 
638
 
        }
639
 
        // Read entities:
640
 
        else if (!strcmp(groupValue, "POINT")) {
641
 
            currentEntity = DL_ENTITY_POINT;
642
 
        } else if (!strcmp(groupValue, "LINE")) {
643
 
            currentEntity = DL_ENTITY_LINE;
644
 
        } else if (!strcmp(groupValue, "POLYLINE")) {
645
 
            currentEntity = DL_ENTITY_POLYLINE;
646
 
        } else if (!strcmp(groupValue, "LWPOLYLINE")) {
647
 
            currentEntity = DL_ENTITY_LWPOLYLINE;
648
 
        } else if (!strcmp(groupValue, "VERTEX")) {
649
 
            currentEntity = DL_ENTITY_VERTEX;
650
 
        } else if (!strcmp(groupValue, "SPLINE")) {
651
 
            currentEntity = DL_ENTITY_SPLINE;
652
 
        } else if (!strcmp(groupValue, "ARC")) {
653
 
            currentEntity = DL_ENTITY_ARC;
654
 
        } else if (!strcmp(groupValue, "ELLIPSE")) {
655
 
            currentEntity = DL_ENTITY_ELLIPSE;
656
 
        } else if (!strcmp(groupValue, "CIRCLE")) {
657
 
            currentEntity = DL_ENTITY_CIRCLE;
658
 
        } else if (!strcmp(groupValue, "INSERT")) {
659
 
            currentEntity = DL_ENTITY_INSERT;
660
 
        } else if (!strcmp(groupValue, "TEXT")) {
661
 
            currentEntity = DL_ENTITY_TEXT;
662
 
        } else if (!strcmp(groupValue, "MTEXT")) {
663
 
            currentEntity = DL_ENTITY_MTEXT;
664
 
        } else if (!strcmp(groupValue, "ATTRIB")) {
665
 
            currentEntity = DL_ENTITY_ATTRIB;
666
 
        } else if (!strcmp(groupValue, "DIMENSION")) {
667
 
            currentEntity = DL_ENTITY_DIMENSION;
668
 
        } else if (!strcmp(groupValue, "LEADER")) {
669
 
            currentEntity = DL_ENTITY_LEADER;
670
 
        } else if (!strcmp(groupValue, "HATCH")) {
671
 
            currentEntity = DL_ENTITY_HATCH;
672
 
        } else if (!strcmp(groupValue, "IMAGE")) {
673
 
            currentEntity = DL_ENTITY_IMAGE;
674
 
        } else if (!strcmp(groupValue, "IMAGEDEF")) {
675
 
            currentEntity = DL_ENTITY_IMAGEDEF;
676
 
        } else if (!strcmp(groupValue, "TRACE")) {
677
 
           currentEntity = DL_ENTITY_TRACE;
678
 
        } else if (!strcmp(groupValue, "SOLID")) {
679
 
           currentEntity = DL_ENTITY_SOLID;
680
 
        } else if (!strcmp(groupValue, "3DFACE")) {
681
 
           currentEntity = DL_ENTITY_3DFACE;
682
 
        } else if (!strcmp(groupValue, "SEQEND")) {
683
 
            currentEntity = DL_ENTITY_SEQEND;
684
 
        } else {
685
 
            currentEntity = DL_UNKNOWN;
686
 
        }
687
 
 
688
 
                // end of old style POLYLINE entity
689
 
                if (prevEntity==DL_ENTITY_VERTEX && currentEntity!=DL_ENTITY_VERTEX) {
690
 
                        endEntity(creationInterface);
691
 
                }
692
 
 
693
 
        return true;
694
 
 
695
 
    } else {
696
 
        // Group code does not indicate start of new entity or setting,
697
 
        // so this group must be continuation of data for the current
698
 
        // one.
699
 
        if (groupCode<DL_DXF_MAXGROUPCODE) {
700
 
 
701
 
            bool handled = false;
702
 
 
703
 
            switch (currentEntity) {
704
 
            case DL_ENTITY_MTEXT:
705
 
                handled = handleMTextData(creationInterface);
706
 
                break;
707
 
 
708
 
            case DL_ENTITY_LWPOLYLINE:
709
 
                handled = handleLWPolylineData(creationInterface);
710
 
                break;
711
 
 
712
 
            case DL_ENTITY_SPLINE:
713
 
                handled = handleSplineData(creationInterface);
714
 
                break;
715
 
 
716
 
            case DL_ENTITY_LEADER:
717
 
                handled = handleLeaderData(creationInterface);
718
 
                break;
719
 
 
720
 
            case DL_ENTITY_HATCH:
721
 
                handled = handleHatchData(creationInterface);
722
 
                break;
723
 
 
724
 
            default:
725
 
                break;
726
 
            }
727
 
 
728
 
            if (!handled) {
729
 
                // Normal group / value pair:
730
 
                strncpy(values[groupCode], groupValue, DL_DXF_MAXLINE);
731
 
                values[groupCode][DL_DXF_MAXLINE] = '\0';
732
 
            }
733
 
        }
734
 
 
735
 
        return false;
736
 
    }
737
 
    return false;
738
 
}
739
 
 
740
 
 
741
 
 
742
 
/**
743
 
 * Adds a comment from the DXF file.
744
 
 */
745
 
void DL_Dxf::addComment(DL_CreationInterface* creationInterface, const char* comment) {
746
 
    creationInterface->addComment(comment);
747
 
}
748
 
 
749
 
 
750
 
 
751
 
/**
752
 
 * Adds a variable from the DXF file.
753
 
 */
754
 
void DL_Dxf::addSetting(DL_CreationInterface* creationInterface) {
755
 
    int c = -1;
756
 
    for (int i=0; i<=380; ++i) {
757
 
        if (values[i][0]!='\0') {
758
 
            c = i;
759
 
            break;
760
 
        }
761
 
    }
762
 
 
763
 
    // string
764
 
    if (c>=0 && c<=9) {
765
 
        creationInterface->setVariableString(settingKey,
766
 
                                             values[c], c);
767
 
    }
768
 
    // vector
769
 
    else if (c>=10 && c<=39) {
770
 
        if (c==10) {
771
 
            creationInterface->setVariableVector(
772
 
                settingKey,
773
 
                toReal(values[c]),
774
 
                toReal(values[c+10]),
775
 
                toReal(values[c+20]),
776
 
                c);
777
 
        }
778
 
    }
779
 
    // double
780
 
    else if (c>=40 && c<=59) {
781
 
        creationInterface->setVariableDouble(settingKey,
782
 
                                             toReal(values[c]),
783
 
                                             c);
784
 
    }
785
 
    // int
786
 
    else if (c>=60 && c<=99) {
787
 
        creationInterface->setVariableInt(settingKey,
788
 
                                          toInt(values[c]),
789
 
                                          c);
790
 
    }
791
 
    // misc
792
 
    else if (c>=0) {
793
 
        creationInterface->setVariableString(settingKey,
794
 
                                             values[c],
795
 
                                             c);
796
 
    }
797
 
}
798
 
 
799
 
 
800
 
 
801
 
/**
802
 
 * Adds a layer that was read from the file via the creation interface.
803
 
 */
804
 
void DL_Dxf::addLayer(DL_CreationInterface* creationInterface) {
805
 
    // correct some impossible attributes for layers:
806
 
    attrib = creationInterface->getAttributes();
807
 
    if (attrib.getColor()==256 || attrib.getColor()==0) {
808
 
        attrib.setColor(7);
809
 
    }
810
 
    if (attrib.getWidth()<0) {
811
 
        attrib.setWidth(1);
812
 
    }
813
 
    if (!strcasecmp(attrib.getLineType().c_str(), "BYLAYER") ||
814
 
            !strcasecmp(attrib.getLineType().c_str(), "BYBLOCK")) {
815
 
        attrib.setLineType("CONTINUOUS");
816
 
    }
817
 
 
818
 
    // add layer
819
 
    creationInterface->addLayer(DL_LayerData(values[2],
820
 
                                toInt(values[70])));
821
 
}
822
 
 
823
 
 
824
 
 
825
 
/**
826
 
 * Adds a block that was read from the file via the creation interface.
827
 
 */
828
 
void DL_Dxf::addBlock(DL_CreationInterface* creationInterface) {
829
 
    DL_BlockData d(
830
 
        // Name:
831
 
        values[2],
832
 
        // flags:
833
 
        toInt(values[70]),
834
 
        // base point:
835
 
        toReal(values[10]),
836
 
        toReal(values[20]),
837
 
        toReal(values[30]));
838
 
 
839
 
    creationInterface->addBlock(d);
840
 
}
841
 
 
842
 
 
843
 
 
844
 
/**
845
 
 * Ends a block that was read from the file via the creation interface.
846
 
 */
847
 
void DL_Dxf::endBlock(DL_CreationInterface* creationInterface) {
848
 
    creationInterface->endBlock();
849
 
}
850
 
 
851
 
 
852
 
 
853
 
/**
854
 
 * Adds a point entity that was read from the file via the creation interface.
855
 
 */
856
 
void DL_Dxf::addPoint(DL_CreationInterface* creationInterface) {
857
 
    DL_PointData d(toReal(values[10]),
858
 
                   toReal(values[20]),
859
 
                   toReal(values[30]));
860
 
    creationInterface->addPoint(d);
861
 
}
862
 
 
863
 
 
864
 
 
865
 
/**
866
 
 * Adds a line entity that was read from the file via the creation interface.
867
 
 */
868
 
void DL_Dxf::addLine(DL_CreationInterface* creationInterface) {
869
 
    DL_LineData d(toReal(values[10]),
870
 
                  toReal(values[20]),
871
 
                  toReal(values[30]),
872
 
                  toReal(values[11]),
873
 
                  toReal(values[21]),
874
 
                  toReal(values[31]));
875
 
 
876
 
    creationInterface->addLine(d);
877
 
}
878
 
 
879
 
 
880
 
 
881
 
/**
882
 
 * Adds a polyline entity that was read from the file via the creation interface.
883
 
 */
884
 
void DL_Dxf::addPolyline(DL_CreationInterface* creationInterface) {
885
 
    DL_PolylineData pd(maxVertices, toInt(values[71], 0), toInt(values[72], 0), toInt(values[70], 0));
886
 
    creationInterface->addPolyline(pd);
887
 
 
888
 
    if (currentEntity==DL_ENTITY_LWPOLYLINE) {
889
 
        for (int i=0; i<maxVertices; i++) {
890
 
            DL_VertexData d(vertices[i*4],
891
 
                            vertices[i*4+1],
892
 
                            vertices[i*4+2],
893
 
                            vertices[i*4+3]);
894
 
 
895
 
            creationInterface->addVertex(d);
896
 
        }
897
 
                creationInterface->endEntity();
898
 
    }
899
 
}
900
 
 
901
 
 
902
 
 
903
 
/**
904
 
 * Adds a polyline vertex entity that was read from the file 
905
 
 * via the creation interface.
906
 
 */
907
 
void DL_Dxf::addVertex(DL_CreationInterface* creationInterface) {
908
 
    DL_VertexData d(toReal(values[10]),
909
 
                    toReal(values[20]),
910
 
                    toReal(values[30]),
911
 
                    //bulge);
912
 
                    toReal(values[42]));
913
 
 
914
 
    //bulge = toReal(values[42]);
915
 
 
916
 
    creationInterface->addVertex(d);
917
 
}
918
 
 
919
 
 
920
 
 
921
 
/**
922
 
 * Adds a spline entity that was read from the file via the creation interface.
923
 
 */
924
 
void DL_Dxf::addSpline(DL_CreationInterface* creationInterface) {
925
 
    DL_SplineData sd(toInt(values[71], 3), 
926
 
                     maxKnots, 
927
 
                     maxControlPoints, 
928
 
                     toInt(values[70], 4));
929
 
    /*DL_SplineData sd(toInt(values[71], 3), toInt(values[72], 0),
930
 
                     toInt(values[73], 0), toInt(values[70], 4));*/
931
 
    creationInterface->addSpline(sd);
932
 
 
933
 
    int i;
934
 
    for (i=0; i<maxControlPoints; i++) {
935
 
        DL_ControlPointData d(controlPoints[i*3],
936
 
                              controlPoints[i*3+1],
937
 
                              controlPoints[i*3+2]);
938
 
 
939
 
        creationInterface->addControlPoint(d);
940
 
    }
941
 
    for (i=0; i<maxKnots; i++) {
942
 
      DL_KnotData k(knots[i]);
943
 
 
944
 
      creationInterface->addKnot(k);
945
 
    }
946
 
}
947
 
 
948
 
 
949
 
 
950
 
/**
951
 
 * Adds an arc entity that was read from the file via the creation interface.
952
 
 */
953
 
void DL_Dxf::addArc(DL_CreationInterface* creationInterface) {
954
 
    DL_ArcData d(toReal(values[10]),
955
 
                 toReal(values[20]),
956
 
                 toReal(values[30]),
957
 
                 toReal(values[40]),
958
 
                 toReal(values[50]),
959
 
                 toReal(values[51]));
960
 
 
961
 
    creationInterface->addArc(d);
962
 
}
963
 
 
964
 
 
965
 
 
966
 
/**
967
 
 * Adds a circle entity that was read from the file via the creation interface.
968
 
 */
969
 
void DL_Dxf::addCircle(DL_CreationInterface* creationInterface) {
970
 
    DL_CircleData d(toReal(values[10]),
971
 
                    toReal(values[20]),
972
 
                    toReal(values[30]),
973
 
                    toReal(values[40]));
974
 
 
975
 
    creationInterface->addCircle(d);
976
 
}
977
 
 
978
 
 
979
 
 
980
 
/**
981
 
 * Adds an ellipse entity that was read from the file via the creation interface.
982
 
 */
983
 
void DL_Dxf::addEllipse(DL_CreationInterface* creationInterface) {
984
 
    DL_EllipseData d(toReal(values[10]),
985
 
                     toReal(values[20]),
986
 
                     toReal(values[30]),
987
 
                     toReal(values[11]),
988
 
                     toReal(values[21]),
989
 
                     toReal(values[31]),
990
 
                     toReal(values[40], 1.0),
991
 
                     toReal(values[41], 0.0),
992
 
                     toReal(values[42], 2*M_PI));
993
 
 
994
 
    creationInterface->addEllipse(d);
995
 
}
996
 
 
997
 
 
998
 
 
999
 
/**
1000
 
 * Adds an insert entity that was read from the file via the creation interface.
1001
 
 */
1002
 
void DL_Dxf::addInsert(DL_CreationInterface* creationInterface) {
1003
 
    DL_InsertData d(values[2],
1004
 
                    // insertion point
1005
 
                    toReal(values[10], 0.0),
1006
 
                    toReal(values[20], 0.0),
1007
 
                    toReal(values[30], 0.0),
1008
 
                    // scale:
1009
 
                    toReal(values[41], 1.0),
1010
 
                    toReal(values[42], 1.0),
1011
 
                    toReal(values[43], 1.0),
1012
 
                    // angle:
1013
 
                    toReal(values[50], 0.0),
1014
 
                    // cols / rows:
1015
 
                    toInt(values[70], 1),
1016
 
                    toInt(values[71], 1),
1017
 
                    // spacing:
1018
 
                    toReal(values[44], 0.0),
1019
 
                    toReal(values[45], 0.0));
1020
 
 
1021
 
    creationInterface->addInsert(d);
1022
 
}
1023
 
 
1024
 
 
1025
 
 
1026
 
/**
1027
 
 * Adds a trace entity (4 edge closed polyline) that was read from the file via the creation interface.
1028
 
 *
1029
 
 * @author AHM
1030
 
 */
1031
 
void DL_Dxf::addTrace(DL_CreationInterface* creationInterface) {
1032
 
    DL_TraceData td;
1033
 
    
1034
 
    for (int k = 0; k < 4; k++) {
1035
 
       td.x[k] = toReal(values[10 + k]);
1036
 
       td.y[k] = toReal(values[20 + k]);
1037
 
       td.z[k] = toReal(values[30 + k]);
1038
 
    }
1039
 
    creationInterface->addTrace(td);
1040
 
}
1041
 
 
1042
 
 
1043
 
 
1044
 
/**
1045
 
 * Adds a 3dface entity that was read from the file via the creation interface.
1046
 
 */
1047
 
void DL_Dxf::add3dFace(DL_CreationInterface* creationInterface) {
1048
 
    DL_3dFaceData td;
1049
 
    
1050
 
    for (int k = 0; k < 4; k++) {
1051
 
       td.x[k] = toReal(values[10 + k]);
1052
 
       td.y[k] = toReal(values[20 + k]);
1053
 
       td.z[k] = toReal(values[30 + k]);
1054
 
    }
1055
 
    creationInterface->add3dFace(td);
1056
 
}
1057
 
 
1058
 
 
1059
 
 
1060
 
/**
1061
 
 * Adds a solid entity (filled trace) that was read from the file via the creation interface.
1062
 
 * 
1063
 
 * @author AHM
1064
 
 */
1065
 
void DL_Dxf::addSolid(DL_CreationInterface* creationInterface) {
1066
 
    DL_SolidData sd;
1067
 
    
1068
 
    for (int k = 0; k < 4; k++) {
1069
 
       sd.x[k] = toReal(values[10 + k]);
1070
 
       sd.y[k] = toReal(values[20 + k]);
1071
 
       sd.z[k] = toReal(values[30 + k]);
1072
 
    }
1073
 
    creationInterface->addSolid(sd);
1074
 
}
1075
 
 
1076
 
 
1077
 
/**
1078
 
 * Adds an MText entity that was read from the file via the creation interface.
1079
 
 */
1080
 
void DL_Dxf::addMText(DL_CreationInterface* creationInterface) {
1081
 
    double angle = 0.0;
1082
 
 
1083
 
    if (values[50][0]!='\0') {
1084
 
        if (libVersion<=0x02000200) {
1085
 
            // wrong but compatible with dxflib <=2.0.2.0:
1086
 
            angle = toReal(values[50], 0.0);
1087
 
        } else {
1088
 
            angle = (toReal(values[50], 0.0)*2*M_PI)/360.0;
1089
 
        }
1090
 
    } else if (values[11][0]!='\0' && values[21][0]!='\0') {
1091
 
        double x = toReal(values[11], 0.0);
1092
 
        double y = toReal(values[21], 0.0);
1093
 
 
1094
 
        if (fabs(x)<1.0e-6) {
1095
 
            if (y>0.0) {
1096
 
                angle = M_PI/2.0;
1097
 
            } else {
1098
 
                angle = M_PI/2.0*3.0;
1099
 
            }
1100
 
        } else {
1101
 
            angle = atan(y/x);
1102
 
        }
1103
 
    }
1104
 
 
1105
 
    DL_MTextData d(
1106
 
        // insertion point
1107
 
        toReal(values[10], 0.0),
1108
 
        toReal(values[20], 0.0),
1109
 
        toReal(values[30], 0.0),
1110
 
        // height
1111
 
        toReal(values[40], 2.5),
1112
 
        // width
1113
 
        toReal(values[41], 100.0),
1114
 
        // attachment point
1115
 
        toInt(values[71], 1),
1116
 
        // drawing direction
1117
 
        toInt(values[72], 1),
1118
 
        // line spacing style
1119
 
        toInt(values[73], 1),
1120
 
        // line spacing factor
1121
 
        toReal(values[44], 1.0),
1122
 
        // text
1123
 
        values[1],
1124
 
        // style
1125
 
        values[7],
1126
 
        // angle
1127
 
        angle);
1128
 
    creationInterface->addMText(d);
1129
 
}
1130
 
 
1131
 
 
1132
 
 
1133
 
/**
1134
 
 * Handles additional MText data.
1135
 
 */
1136
 
bool DL_Dxf::handleMTextData(DL_CreationInterface* creationInterface) {
1137
 
    // Special handling of text chunks for MTEXT entities:
1138
 
    if (groupCode==3) {
1139
 
        creationInterface->addMTextChunk(groupValue);
1140
 
        return true;
1141
 
    }
1142
 
 
1143
 
    return false;
1144
 
}
1145
 
 
1146
 
 
1147
 
 
1148
 
/**
1149
 
 * Handles additional polyline data.
1150
 
 */
1151
 
bool DL_Dxf::handleLWPolylineData(DL_CreationInterface* /*creationInterface*/) {
1152
 
    // Allocate LWPolyline vertices (group code 90):
1153
 
    if (groupCode==90) {
1154
 
        maxVertices = toInt(groupValue);
1155
 
        if (maxVertices>0) {
1156
 
            if (vertices!=NULL) {
1157
 
                delete[] vertices;
1158
 
            }
1159
 
            vertices = new double[4*maxVertices];
1160
 
            for (int i=0; i<maxVertices; ++i) {
1161
 
                vertices[i*4] = 0.0;
1162
 
                vertices[i*4+1] = 0.0;
1163
 
                vertices[i*4+2] = 0.0;
1164
 
                vertices[i*4+3] = 0.0;
1165
 
            }
1166
 
        }
1167
 
        vertexIndex=-1;
1168
 
        return true;
1169
 
    }
1170
 
 
1171
 
    // Compute LWPolylines vertices (group codes 10/20/30/42):
1172
 
    else if (groupCode==10 || groupCode==20 ||
1173
 
             groupCode==30 || groupCode==42) {
1174
 
 
1175
 
        if (vertexIndex<maxVertices-1 && groupCode==10) {
1176
 
            vertexIndex++;
1177
 
        }
1178
 
 
1179
 
        if (groupCode<=30) {
1180
 
            if (vertexIndex>=0 && vertexIndex<maxVertices) {
1181
 
                vertices[4*vertexIndex + (groupCode/10-1)]
1182
 
                = toReal(groupValue);
1183
 
            }
1184
 
        } else if (groupCode==42 && vertexIndex<maxVertices) {
1185
 
            vertices[4*vertexIndex + 3] = toReal(groupValue);
1186
 
        }
1187
 
        return true;
1188
 
    }
1189
 
    return false;
1190
 
}
1191
 
 
1192
 
 
1193
 
 
1194
 
/**
1195
 
 * Handles additional spline data.
1196
 
 */
1197
 
bool DL_Dxf::handleSplineData(DL_CreationInterface* /*creationInterface*/) {
1198
 
    // Allocate Spline knots (group code 72):
1199
 
    if (groupCode==72) {
1200
 
        maxKnots = toInt(groupValue);
1201
 
        if (maxKnots>0) {
1202
 
            if (knots!=NULL) {
1203
 
                delete[] knots;
1204
 
            }
1205
 
            knots = new double[maxKnots];
1206
 
            for (int i=0; i<maxKnots; ++i) {
1207
 
                knots[i] = 0.0;
1208
 
            }
1209
 
        }
1210
 
        knotIndex=-1;
1211
 
        return true;
1212
 
    }
1213
 
 
1214
 
    // Allocate Spline control points (group code 73):
1215
 
    else if (groupCode==73) {
1216
 
        maxControlPoints = toInt(groupValue);
1217
 
        if (maxControlPoints>0) {
1218
 
            if (controlPoints!=NULL) {
1219
 
                delete[] controlPoints;
1220
 
            }
1221
 
            controlPoints = new double[3*maxControlPoints];
1222
 
            for (int i=0; i<maxControlPoints; ++i) {
1223
 
                controlPoints[i*3] = 0.0;
1224
 
                controlPoints[i*3+1] = 0.0;
1225
 
                controlPoints[i*3+2] = 0.0;
1226
 
            }
1227
 
        }
1228
 
        controlPointIndex=-1;
1229
 
        return true;
1230
 
    }
1231
 
 
1232
 
    // Compute spline knot vertices (group code 40):
1233
 
    else if (groupCode==40) {
1234
 
        if (knotIndex<maxKnots-1) {
1235
 
            knotIndex++;
1236
 
            knots[knotIndex] = toReal(groupValue);
1237
 
        }
1238
 
        return true;
1239
 
    }
1240
 
 
1241
 
    // Compute spline control points (group codes 10/20/30):
1242
 
    else if (groupCode==10 || groupCode==20 ||
1243
 
             groupCode==30) {
1244
 
 
1245
 
        if (controlPointIndex<maxControlPoints-1 && groupCode==10) {
1246
 
            controlPointIndex++;
1247
 
        }
1248
 
 
1249
 
        if (controlPointIndex>=0 && controlPointIndex<maxControlPoints) {
1250
 
            controlPoints[3*controlPointIndex + (groupCode/10-1)]
1251
 
            = toReal(groupValue);
1252
 
        }
1253
 
        return true;
1254
 
    }
1255
 
    return false;
1256
 
}
1257
 
 
1258
 
 
1259
 
 
1260
 
/**
1261
 
 * Handles additional leader data.
1262
 
 */
1263
 
bool DL_Dxf::handleLeaderData(DL_CreationInterface* /*creationInterface*/) {
1264
 
    // Allocate Leader vertices (group code 76):
1265
 
    if (groupCode==76) {
1266
 
        maxLeaderVertices = toInt(groupValue);
1267
 
        if (maxLeaderVertices>0) {
1268
 
            if (leaderVertices!=NULL) {
1269
 
                delete[] leaderVertices;
1270
 
            }
1271
 
            leaderVertices = new double[3*maxLeaderVertices];
1272
 
            for (int i=0; i<maxLeaderVertices; ++i) {
1273
 
                leaderVertices[i*3] = 0.0;
1274
 
                leaderVertices[i*3+1] = 0.0;
1275
 
                leaderVertices[i*3+2] = 0.0;
1276
 
            }
1277
 
        }
1278
 
        leaderVertexIndex=-1;
1279
 
        return true;
1280
 
    }
1281
 
 
1282
 
    // Compute Leader vertices (group codes 10/20/30):
1283
 
    else if (groupCode==10 || groupCode==20 || groupCode==30) {
1284
 
 
1285
 
        if (leaderVertexIndex<maxLeaderVertices-1 && groupCode==10) {
1286
 
            leaderVertexIndex++;
1287
 
        }
1288
 
 
1289
 
        if (groupCode<=30) {
1290
 
            if (leaderVertexIndex>=0 &&
1291
 
                    leaderVertexIndex<maxLeaderVertices) {
1292
 
                leaderVertices[3*leaderVertexIndex + (groupCode/10-1)]
1293
 
                = toReal(groupValue);
1294
 
            }
1295
 
        }
1296
 
        return true;
1297
 
    }
1298
 
 
1299
 
    return false;
1300
 
}
1301
 
 
1302
 
 
1303
 
 
1304
 
/**
1305
 
 * Handles additional hatch data.
1306
 
 */
1307
 
bool DL_Dxf::handleHatchData(DL_CreationInterface* /*creationInterface*/) {
1308
 
 
1309
 
    static int firstPolylineStatus = 0;
1310
 
 
1311
 
    // Allocate hatch loops (group code 91):
1312
 
    if (groupCode==91 && toInt(groupValue)>0) {
1313
 
 
1314
 
        if (hatchLoops!=NULL) {
1315
 
            delete[] hatchLoops;
1316
 
            hatchLoops = NULL;
1317
 
        }
1318
 
        if (maxHatchEdges!=NULL) {
1319
 
            delete[] maxHatchEdges;
1320
 
            maxHatchEdges = NULL;
1321
 
        }
1322
 
        if (hatchEdgeIndex!=NULL) {
1323
 
            delete[] hatchEdgeIndex;
1324
 
            hatchEdgeIndex = NULL;
1325
 
        }
1326
 
        if (hatchEdges!=NULL) {
1327
 
            for (int i=0; i<maxHatchLoops; ++i) {
1328
 
                delete[] hatchEdges[i];
1329
 
            }
1330
 
            delete[] hatchEdges;
1331
 
            hatchEdges = NULL;
1332
 
        }
1333
 
        maxHatchLoops = toInt(groupValue);
1334
 
 
1335
 
        if (maxHatchLoops>0) {
1336
 
            hatchLoops = new DL_HatchLoopData[maxHatchLoops];
1337
 
            maxHatchEdges = new int[maxHatchLoops];
1338
 
            hatchEdgeIndex = new int[maxHatchLoops];
1339
 
            hatchEdges = new DL_HatchEdgeData*[maxHatchLoops];
1340
 
            for (int i=0; i<maxHatchLoops; ++i) {
1341
 
                hatchEdges[i] = NULL;
1342
 
                maxHatchEdges[i] = 0;
1343
 
            }
1344
 
            hatchLoopIndex = -1;
1345
 
            dropEdges = false;
1346
 
        }
1347
 
        return true;
1348
 
    }
1349
 
 
1350
 
    // Allocate hatch edges, group code 93
1351
 
    if (groupCode==93 && toInt(groupValue)>0) {
1352
 
        if (hatchLoopIndex<maxHatchLoops-1 && hatchLoops!=NULL &&
1353
 
                maxHatchEdges!=NULL && hatchEdgeIndex!=NULL &&
1354
 
                hatchEdges!=NULL) {
1355
 
 
1356
 
            dropEdges = false;
1357
 
 
1358
 
            hatchLoopIndex++;
1359
 
            hatchLoops[hatchLoopIndex]
1360
 
            = DL_HatchLoopData(toInt(groupValue));
1361
 
 
1362
 
            maxHatchEdges[hatchLoopIndex] = toInt(groupValue);
1363
 
            hatchEdgeIndex[hatchLoopIndex] = -1;
1364
 
            hatchEdges[hatchLoopIndex]
1365
 
                = new DL_HatchEdgeData[toInt(groupValue)];
1366
 
            firstPolylineStatus = 0;
1367
 
        } else {
1368
 
            dropEdges = true;
1369
 
        }
1370
 
        return true;
1371
 
    }
1372
 
 
1373
 
    // Init hatch edge for non-polyline boundary (group code 72)
1374
 
    if (hatchEdges!=NULL &&
1375
 
            hatchEdgeIndex!=NULL &&
1376
 
            maxHatchEdges!=NULL &&
1377
 
            hatchLoopIndex>=0 &&
1378
 
            hatchLoopIndex<maxHatchLoops &&
1379
 
            hatchEdgeIndex[hatchLoopIndex] <
1380
 
            maxHatchEdges[hatchLoopIndex] &&
1381
 
            (atoi(values[92])&2)==0 &&   // not a polyline
1382
 
            groupCode==72 &&
1383
 
            !dropEdges) {
1384
 
 
1385
 
        hatchEdgeIndex[hatchLoopIndex]++;
1386
 
 
1387
 
        hatchEdges[hatchLoopIndex][hatchEdgeIndex[hatchLoopIndex]]
1388
 
        .type = toInt(groupValue);
1389
 
        hatchEdges[hatchLoopIndex][hatchEdgeIndex[hatchLoopIndex]]
1390
 
        .defined = false;
1391
 
 
1392
 
        return true;
1393
 
    }
1394
 
 
1395
 
    // Handle hatch edges for non-polyline boundaries
1396
 
    //   (group codes 10, 20, 11, 21, 40, 50, 51, 73)
1397
 
    if (!dropEdges &&
1398
 
            hatchEdges!=NULL &&
1399
 
            hatchEdgeIndex!=NULL &&
1400
 
            hatchLoopIndex>=0 &&
1401
 
            hatchLoopIndex<maxHatchLoops &&
1402
 
            hatchEdges[hatchLoopIndex]!=NULL &&
1403
 
            hatchEdgeIndex[hatchLoopIndex]>=0 &&
1404
 
            hatchEdgeIndex[hatchLoopIndex] <
1405
 
            maxHatchEdges[hatchLoopIndex] &&
1406
 
            ((atoi(values[92])&2)==0) &&        // not a polyline
1407
 
            (groupCode==10 || groupCode==20 ||
1408
 
             groupCode==11 || groupCode==21 ||
1409
 
             groupCode==40 || groupCode==50 ||
1410
 
             groupCode==51 || groupCode==73)) {
1411
 
 
1412
 
        if (hatchEdges[hatchLoopIndex]
1413
 
                [hatchEdgeIndex[hatchLoopIndex]].defined==false) {
1414
 
            if (hatchEdges[hatchLoopIndex]
1415
 
                    [hatchEdgeIndex[hatchLoopIndex]].type==1) {
1416
 
                switch (groupCode) {
1417
 
                case 10:
1418
 
                    hatchEdges[hatchLoopIndex]
1419
 
                    [hatchEdgeIndex[hatchLoopIndex]].x1
1420
 
                    = toReal(groupValue);
1421
 
                    break;
1422
 
                case 20:
1423
 
                    hatchEdges[hatchLoopIndex]
1424
 
                    [hatchEdgeIndex[hatchLoopIndex]].y1
1425
 
                    = toReal(groupValue);
1426
 
                    break;
1427
 
                case 11:
1428
 
                    hatchEdges[hatchLoopIndex]
1429
 
                    [hatchEdgeIndex[hatchLoopIndex]].x2
1430
 
                    = toReal(groupValue);
1431
 
                    break;
1432
 
                case 21:
1433
 
                    hatchEdges[hatchLoopIndex]
1434
 
                    [hatchEdgeIndex[hatchLoopIndex]].y2
1435
 
                    = toReal(groupValue);
1436
 
                    hatchEdges[hatchLoopIndex]
1437
 
                    [hatchEdgeIndex[hatchLoopIndex]].defined = true;
1438
 
                    break;
1439
 
                default:
1440
 
                    break;
1441
 
                }
1442
 
            }
1443
 
 
1444
 
            if (hatchEdges[hatchLoopIndex]
1445
 
                    [hatchEdgeIndex[hatchLoopIndex]].type==2) {
1446
 
                switch (groupCode) {
1447
 
                case 10:
1448
 
                    hatchEdges[hatchLoopIndex]
1449
 
                    [hatchEdgeIndex[hatchLoopIndex]].cx
1450
 
                    = toReal(groupValue);
1451
 
                    break;
1452
 
                case 20:
1453
 
                    hatchEdges[hatchLoopIndex]
1454
 
                    [hatchEdgeIndex[hatchLoopIndex]].cy
1455
 
                    = toReal(groupValue);
1456
 
                    break;
1457
 
                case 40:
1458
 
                    hatchEdges[hatchLoopIndex]
1459
 
                    [hatchEdgeIndex[hatchLoopIndex]].radius
1460
 
                    = toReal(groupValue);
1461
 
                    break;
1462
 
                case 50:
1463
 
                    hatchEdges[hatchLoopIndex]
1464
 
                    [hatchEdgeIndex[hatchLoopIndex]].angle1
1465
 
                    = toReal(groupValue)/360.0*2*M_PI;
1466
 
                    break;
1467
 
                case 51:
1468
 
                    hatchEdges[hatchLoopIndex]
1469
 
                    [hatchEdgeIndex[hatchLoopIndex]].angle2
1470
 
                    = toReal(groupValue)/360.0*2*M_PI;
1471
 
                    break;
1472
 
                case 73:
1473
 
                    hatchEdges[hatchLoopIndex]
1474
 
                    [hatchEdgeIndex[hatchLoopIndex]].ccw
1475
 
                    = (bool)toInt(groupValue);
1476
 
                    hatchEdges[hatchLoopIndex]
1477
 
                    [hatchEdgeIndex[hatchLoopIndex]].defined = true;
1478
 
                    break;
1479
 
                default:
1480
 
                    break;
1481
 
                }
1482
 
            }
1483
 
        }
1484
 
        return true;
1485
 
    }
1486
 
 
1487
 
    /*
1488
 
    // 2003/12/31: polyline hatches can be extremely slow and are rarely used
1489
 
    //
1490
 
       // Handle hatch edges for polyline boundaries
1491
 
       //  (group codes 10, 20, 42)
1492
 
       if (!dropEdges &&
1493
 
               hatchEdges!=NULL &&
1494
 
               hatchEdgeIndex!=NULL &&
1495
 
               hatchLoopIndex>=0 &&
1496
 
               hatchLoopIndex<maxHatchLoops &&
1497
 
               hatchEdges[hatchLoopIndex]!=NULL &&
1498
 
               //hatchEdgeIndex[hatchLoopIndex]>=0 &&
1499
 
               hatchEdgeIndex[hatchLoopIndex] <
1500
 
               maxHatchEdges[hatchLoopIndex] &&
1501
 
               ((atoi(values[92])&2)==2)) {        // a polyline
1502
 
 
1503
 
           if (groupCode==10 || groupCode==20 ||
1504
 
                   groupCode==42) {
1505
 
 
1506
 
               std::cout << "  found polyline edge data: " << groupCode << "\n";
1507
 
               std::cout << "     value: " << toReal(groupValue) << "\n";
1508
 
 
1509
 
               static double lastX = 0.0;
1510
 
               static double lastY = 0.0;
1511
 
               static double lastB = 0.0;
1512
 
 
1513
 
               if (firstPolylineStatus<2) {
1514
 
                   switch (groupCode) {
1515
 
                   case 10:
1516
 
                       firstPolylineStatus++;
1517
 
                       if (firstPolylineStatus==1) {
1518
 
                           lastX = toReal(groupValue);
1519
 
                           std::cout << "     firstX: " << lastX << "\n";
1520
 
                       }
1521
 
                       break;
1522
 
 
1523
 
                   case 20:
1524
 
                       lastY = toReal(groupValue);
1525
 
                       std::cout << "     firstY: " << lastY << "\n";
1526
 
                       break;
1527
 
 
1528
 
                   case 42:
1529
 
                       lastB = toReal(groupValue);
1530
 
                       break;
1531
 
 
1532
 
                   default:
1533
 
                       break;
1534
 
                   }
1535
 
 
1536
 
                   if (firstPolylineStatus!=2) {
1537
 
                       return true;
1538
 
                   }
1539
 
               }
1540
 
 
1541
 
 
1542
 
               switch (groupCode) {
1543
 
               case 10:
1544
 
                   hatchEdgeIndex[hatchLoopIndex]++;
1545
 
                   hatchEdges[hatchLoopIndex]
1546
 
                   [hatchEdgeIndex[hatchLoopIndex]].type = 1;
1547
 
                   hatchEdges[hatchLoopIndex]
1548
 
                   [hatchEdgeIndex[hatchLoopIndex]].x1
1549
 
                   = lastX;
1550
 
                   hatchEdges[hatchLoopIndex]
1551
 
                   [hatchEdgeIndex[hatchLoopIndex]].x2
1552
 
                   = lastX = toReal(groupValue);
1553
 
                   std::cout << "     X: " << lastX << "\n";
1554
 
                   break;
1555
 
               case 20:
1556
 
                   hatchEdges[hatchLoopIndex]
1557
 
                   [hatchEdgeIndex[hatchLoopIndex]].y1
1558
 
                   = lastY;
1559
 
                   hatchEdges[hatchLoopIndex]
1560
 
                   [hatchEdgeIndex[hatchLoopIndex]].y2
1561
 
                   = lastY = toReal(groupValue);
1562
 
                   std::cout << "     Y: " << lastY << "\n";
1563
 
                   break;
1564
 
                   / *
1565
 
                               case 42: {
1566
 
                        // convert to arc:
1567
 
                        double x1 = hatchEdges[hatchLoopIndex]
1568
 
                                [hatchEdgeIndex[hatchLoopIndex]].x1;
1569
 
                        double y1 = hatchEdges[hatchLoopIndex]
1570
 
                                [hatchEdgeIndex[hatchLoopIndex]].y1;
1571
 
                        double x2 = hatchEdges[hatchLoopIndex]
1572
 
                                [hatchEdgeIndex[hatchLoopIndex]].x2;
1573
 
                        double y2 = hatchEdges[hatchLoopIndex]
1574
 
                                [hatchEdgeIndex[hatchLoopIndex]].y2;
1575
 
 
1576
 
                        double bulge = toReal(groupValue);
1577
 
 
1578
 
                        bool reversed = (bulge<0.0);
1579
 
                        double alpha = atan(bulge)*4.0;
1580
 
                        double radius;
1581
 
                             double cx;
1582
 
                             double cy;
1583
 
                        double a1;
1584
 
                        double a2;
1585
 
                             double mx = (x2+x1)/2.0;
1586
 
                             double my = (y2+y1)/2.0;
1587
 
                        double dist = sqrt(pow(x2-x1,2) + pow(y2-y1,2)) / 2.0;
1588
 
 
1589
 
                        // alpha can't be 0.0 at this point
1590
 
                             radius = fabs(dist / sin(alpha/2.0));
1591
 
 
1592
 
                             double wu = fabs(pow(radius, 2.0) - pow(dist, 2.0));
1593
 
                             double h = sqrt(wu);
1594
 
                        double angle = acos((x2-x1) / dist);
1595
 
 
1596
 
                             if (bulge>0.0) {
1597
 
                                        angle+=M_PI/2.0;
1598
 
                             } else {
1599
 
                                 angle-=M_PI/2.0;
1600
 
                             }
1601
 
 
1602
 
                             if (fabs(alpha)>M_PI) {
1603
 
                                 h*=-1.0;
1604
 
                             }
1605
 
 
1606
 
                        cx = mx + cos(angle) * h;
1607
 
                        cy = my + sin(angle) * h;
1608
 
 
1609
 
                        a1 = hatchEdges[hatchLoopIndex]
1610
 
                                        [hatchEdgeIndex[hatchLoopIndex]].type = 2;
1611
 
                                   hatchEdges[hatchLoopIndex]
1612
 
                                        [hatchEdgeIndex[hatchLoopIndex]].ccw = (toReal(groupValue)>0.0);
1613
 
                                   hatchEdges[hatchLoopIndex]
1614
 
                                        [hatchEdgeIndex[hatchLoopIndex]].cx = cx;
1615
 
                                   hatchEdges[hatchLoopIndex]
1616
 
                                        [hatchEdgeIndex[hatchLoopIndex]].cy = cy;
1617
 
                                   hatchEdges[hatchLoopIndex]
1618
 
                                        [hatchEdgeIndex[hatchLoopIndex]].radius = radius;
1619
 
                                   } break;
1620
 
                        * /
1621
 
 
1622
 
               default:
1623
 
                   break;
1624
 
               }
1625
 
           } else {
1626
 
               // end polyline boundary
1627
 
               dropEdges = true;
1628
 
           }
1629
 
 
1630
 
           return true;
1631
 
       }
1632
 
    */
1633
 
 
1634
 
    return false;
1635
 
}
1636
 
 
1637
 
 
1638
 
 
1639
 
 
1640
 
/**
1641
 
 * Adds an text entity that was read from the file via the creation interface.
1642
 
 */
1643
 
void DL_Dxf::addText(DL_CreationInterface* creationInterface) {
1644
 
    DL_TextData d(
1645
 
        // insertion point
1646
 
        toReal(values[10], 0.0),
1647
 
        toReal(values[20], 0.0),
1648
 
        toReal(values[30], 0.0),
1649
 
        // alignment point
1650
 
        toReal(values[11], 0.0),
1651
 
        toReal(values[21], 0.0),
1652
 
        toReal(values[31], 0.0),
1653
 
        // height
1654
 
        toReal(values[40], 2.5),
1655
 
        // x scale
1656
 
        toReal(values[41], 1.0),
1657
 
        // generation flags
1658
 
        toInt(values[71], 0),
1659
 
        // h just
1660
 
        toInt(values[72], 0),
1661
 
        // v just
1662
 
        toInt(values[73], 0),
1663
 
        // text
1664
 
        values[1],
1665
 
        // style
1666
 
        values[7],
1667
 
        // angle
1668
 
        (toReal(values[50], 0.0)*2*M_PI)/360.0);
1669
 
 
1670
 
    creationInterface->addText(d);
1671
 
}
1672
 
 
1673
 
 
1674
 
 
1675
 
/**
1676
 
 * Adds an attrib entity that was read from the file via the creation interface.
1677
 
 * @todo add attrib instead of normal text
1678
 
 */
1679
 
void DL_Dxf::addAttrib(DL_CreationInterface* creationInterface) {
1680
 
    DL_TextData d(
1681
 
        // insertion point
1682
 
        toReal(values[10], 0.0),
1683
 
        toReal(values[20], 0.0),
1684
 
        toReal(values[30], 0.0),
1685
 
        // alignment point
1686
 
        toReal(values[11], 0.0),
1687
 
        toReal(values[21], 0.0),
1688
 
        toReal(values[31], 0.0),
1689
 
        // height
1690
 
        toReal(values[40], 2.5),
1691
 
        // x scale
1692
 
        toReal(values[41], 1.0),
1693
 
        // generation flags
1694
 
        toInt(values[71], 0),
1695
 
        // h just
1696
 
        toInt(values[72], 0),
1697
 
        // v just
1698
 
        toInt(values[74], 0),
1699
 
        // text
1700
 
        values[1],
1701
 
        // style
1702
 
        values[7],
1703
 
        // angle
1704
 
        (toReal(values[50], 0.0)*2*M_PI)/360.0);
1705
 
 
1706
 
    creationInterface->addText(d);
1707
 
}
1708
 
 
1709
 
 
1710
 
 
1711
 
/**
1712
 
 * @return dimension data from current values.
1713
 
 */
1714
 
DL_DimensionData DL_Dxf::getDimData() {
1715
 
    // generic dimension data:
1716
 
    return DL_DimensionData(
1717
 
               // def point
1718
 
               toReal(values[10], 0.0),
1719
 
               toReal(values[20], 0.0),
1720
 
               toReal(values[30], 0.0),
1721
 
               // text middle point
1722
 
               toReal(values[11], 0.0),
1723
 
               toReal(values[21], 0.0),
1724
 
               toReal(values[31], 0.0),
1725
 
               // type
1726
 
               toInt(values[70], 0),
1727
 
               // attachment point
1728
 
               toInt(values[71], 5),
1729
 
               // line sp. style
1730
 
               toInt(values[72], 1),
1731
 
               // line sp. factor
1732
 
               toReal(values[41], 1.0),
1733
 
               // text
1734
 
               values[1],
1735
 
               // style
1736
 
               values[3],
1737
 
               // angle
1738
 
               toReal(values[53], 0.0));
1739
 
}
1740
 
 
1741
 
 
1742
 
 
1743
 
/**
1744
 
 * Adds a linear dimension entity that was read from the file via the creation interface.
1745
 
 */
1746
 
void DL_Dxf::addDimLinear(DL_CreationInterface* creationInterface) {
1747
 
    DL_DimensionData d = getDimData();
1748
 
 
1749
 
    // horizontal / vertical / rotated dimension:
1750
 
    DL_DimLinearData dl(
1751
 
        // definition point 1
1752
 
        toReal(values[13], 0.0),
1753
 
        toReal(values[23], 0.0),
1754
 
        toReal(values[33], 0.0),
1755
 
        // definition point 2
1756
 
        toReal(values[14], 0.0),
1757
 
        toReal(values[24], 0.0),
1758
 
        toReal(values[34], 0.0),
1759
 
        // angle
1760
 
        toReal(values[50], 0.0),
1761
 
        // oblique
1762
 
        toReal(values[52], 0.0));
1763
 
    creationInterface->addDimLinear(d, dl);
1764
 
}
1765
 
 
1766
 
 
1767
 
 
1768
 
/**
1769
 
 * Adds an aligned dimension entity that was read from the file via the creation interface.
1770
 
 */
1771
 
void DL_Dxf::addDimAligned(DL_CreationInterface* creationInterface) {
1772
 
    DL_DimensionData d = getDimData();
1773
 
 
1774
 
    // aligned dimension:
1775
 
    DL_DimAlignedData da(
1776
 
        // extension point 1
1777
 
        toReal(values[13], 0.0),
1778
 
        toReal(values[23], 0.0),
1779
 
        toReal(values[33], 0.0),
1780
 
        // extension point 2
1781
 
        toReal(values[14], 0.0),
1782
 
        toReal(values[24], 0.0),
1783
 
        toReal(values[34], 0.0));
1784
 
    creationInterface->addDimAlign(d, da);
1785
 
}
1786
 
 
1787
 
 
1788
 
 
1789
 
/**
1790
 
 * Adds a radial dimension entity that was read from the file via the creation interface.
1791
 
 */
1792
 
void DL_Dxf::addDimRadial(DL_CreationInterface* creationInterface) {
1793
 
    DL_DimensionData d = getDimData();
1794
 
 
1795
 
    DL_DimRadialData dr(
1796
 
        // definition point
1797
 
        toReal(values[15], 0.0),
1798
 
        toReal(values[25], 0.0),
1799
 
        toReal(values[35], 0.0),
1800
 
        // leader length:
1801
 
        toReal(values[40], 0.0));
1802
 
    creationInterface->addDimRadial(d, dr);
1803
 
}
1804
 
 
1805
 
 
1806
 
 
1807
 
/**
1808
 
 * Adds a diametric dimension entity that was read from the file via the creation interface.
1809
 
 */
1810
 
void DL_Dxf::addDimDiametric(DL_CreationInterface* creationInterface) {
1811
 
    DL_DimensionData d = getDimData();
1812
 
 
1813
 
    // diametric dimension:
1814
 
    DL_DimDiametricData dr(
1815
 
        // definition point
1816
 
        toReal(values[15], 0.0),
1817
 
        toReal(values[25], 0.0),
1818
 
        toReal(values[35], 0.0),
1819
 
        // leader length:
1820
 
        toReal(values[40], 0.0));
1821
 
    creationInterface->addDimDiametric(d, dr);
1822
 
}
1823
 
 
1824
 
 
1825
 
 
1826
 
/**
1827
 
 * Adds an angular dimension entity that was read from the file via the creation interface.
1828
 
 */
1829
 
void DL_Dxf::addDimAngular(DL_CreationInterface* creationInterface) {
1830
 
    DL_DimensionData d = getDimData();
1831
 
 
1832
 
    // angular dimension:
1833
 
    DL_DimAngularData da(
1834
 
        // definition point 1
1835
 
        toReal(values[13], 0.0),
1836
 
        toReal(values[23], 0.0),
1837
 
        toReal(values[33], 0.0),
1838
 
        // definition point 2
1839
 
        toReal(values[14], 0.0),
1840
 
        toReal(values[24], 0.0),
1841
 
        toReal(values[34], 0.0),
1842
 
        // definition point 3
1843
 
        toReal(values[15], 0.0),
1844
 
        toReal(values[25], 0.0),
1845
 
        toReal(values[35], 0.0),
1846
 
        // definition point 4
1847
 
        toReal(values[16], 0.0),
1848
 
        toReal(values[26], 0.0),
1849
 
        toReal(values[36], 0.0));
1850
 
    creationInterface->addDimAngular(d, da);
1851
 
}
1852
 
 
1853
 
 
1854
 
/**
1855
 
 * Adds an angular dimension entity that was read from the file via the creation interface.
1856
 
 */
1857
 
void DL_Dxf::addDimAngular3P(DL_CreationInterface* creationInterface) {
1858
 
    DL_DimensionData d = getDimData();
1859
 
 
1860
 
    // angular dimension (3P):
1861
 
    DL_DimAngular3PData da(
1862
 
        // definition point 1
1863
 
        toReal(values[13], 0.0),
1864
 
        toReal(values[23], 0.0),
1865
 
        toReal(values[33], 0.0),
1866
 
        // definition point 2
1867
 
        toReal(values[14], 0.0),
1868
 
        toReal(values[24], 0.0),
1869
 
        toReal(values[34], 0.0),
1870
 
        // definition point 3
1871
 
        toReal(values[15], 0.0),
1872
 
        toReal(values[25], 0.0),
1873
 
        toReal(values[35], 0.0));
1874
 
    creationInterface->addDimAngular3P(d, da);
1875
 
}
1876
 
 
1877
 
 
1878
 
 
1879
 
/**
1880
 
 * Adds an ordinate dimension entity that was read from the file via the creation interface.
1881
 
 */
1882
 
void DL_Dxf::addDimOrdinate(DL_CreationInterface* creationInterface) {
1883
 
    DL_DimensionData d = getDimData();
1884
 
 
1885
 
    // ordinate dimension:
1886
 
    DL_DimOrdinateData dl(
1887
 
        // definition point 1
1888
 
        toReal(values[13], 0.0),
1889
 
        toReal(values[23], 0.0),
1890
 
        toReal(values[33], 0.0),
1891
 
        // definition point 2
1892
 
        toReal(values[14], 0.0),
1893
 
        toReal(values[24], 0.0),
1894
 
        toReal(values[34], 0.0),
1895
 
        (toInt(values[70])&64)==64         // true: X-type, false: Y-type
1896
 
    );
1897
 
    creationInterface->addDimOrdinate(d, dl);
1898
 
}
1899
 
 
1900
 
 
1901
 
 
1902
 
/**
1903
 
 * Adds a leader entity that was read from the file via the creation interface.
1904
 
 */
1905
 
void DL_Dxf::addLeader(DL_CreationInterface* creationInterface) {
1906
 
    // leader (arrow)
1907
 
    DL_LeaderData le(
1908
 
        // arrow head flag
1909
 
        toInt(values[71], 1),
1910
 
        // leader path type
1911
 
        toInt(values[72], 0),
1912
 
        // Leader creation flag
1913
 
        toInt(values[73], 3),
1914
 
        // Hookline direction flag
1915
 
        toInt(values[74], 1),
1916
 
        // Hookline flag
1917
 
        toInt(values[75], 0),
1918
 
        // Text annotation height
1919
 
        toReal(values[40], 1.0),
1920
 
        // Text annotation width
1921
 
        toReal(values[41], 1.0),
1922
 
        // Number of vertices in leader
1923
 
        toInt(values[76], 0)
1924
 
    );
1925
 
    creationInterface->addLeader(le);
1926
 
 
1927
 
    for (int i=0; i<maxLeaderVertices; i++) {
1928
 
        DL_LeaderVertexData d(leaderVertices[i*3],
1929
 
                              leaderVertices[i*3+1],
1930
 
                              leaderVertices[i*3+2]);
1931
 
 
1932
 
        creationInterface->addLeaderVertex(d);
1933
 
    }
1934
 
}
1935
 
 
1936
 
 
1937
 
 
1938
 
/**
1939
 
 * Adds a hatch entity that was read from the file via the creation interface.
1940
 
 */
1941
 
void DL_Dxf::addHatch(DL_CreationInterface* creationInterface) {
1942
 
    DL_HatchData hd(toInt(values[91], 1),
1943
 
                    toInt(values[70], 0),
1944
 
                    toReal(values[41], 1.0),
1945
 
                    toReal(values[52], 0.0),
1946
 
                    values[2]);
1947
 
    creationInterface->addHatch(hd);
1948
 
 
1949
 
    for (int l=0; l<maxHatchLoops; l++) {
1950
 
        DL_HatchLoopData ld(maxHatchEdges[l]);
1951
 
        creationInterface->addHatchLoop(ld);
1952
 
        for (int b=0; b<maxHatchEdges[l]; b++) {
1953
 
            creationInterface->addHatchEdge(hatchEdges[l][b]);
1954
 
        }
1955
 
    }
1956
 
    creationInterface->endEntity();
1957
 
    currentEntity = DL_UNKNOWN;
1958
 
}
1959
 
 
1960
 
 
1961
 
 
1962
 
/**
1963
 
 * Adds an image entity that was read from the file via the creation interface.
1964
 
 */
1965
 
void DL_Dxf::addImage(DL_CreationInterface* creationInterface) {
1966
 
    DL_ImageData id(// pass ref insead of name we don't have yet
1967
 
        values[340],
1968
 
        // ins point:
1969
 
        toReal(values[10], 0.0),
1970
 
        toReal(values[20], 0.0),
1971
 
        toReal(values[30], 0.0),
1972
 
        // u vector:
1973
 
        toReal(values[11], 1.0),
1974
 
        toReal(values[21], 0.0),
1975
 
        toReal(values[31], 0.0),
1976
 
        // v vector:
1977
 
        toReal(values[12], 0.0),
1978
 
        toReal(values[22], 1.0),
1979
 
        toReal(values[32], 0.0),
1980
 
        // image size (pixel):
1981
 
        toInt(values[13], 1),
1982
 
        toInt(values[23], 1),
1983
 
        // brightness, contrast, fade
1984
 
        toInt(values[281], 50),
1985
 
        toInt(values[282], 50),
1986
 
        toInt(values[283], 0));
1987
 
 
1988
 
    creationInterface->addImage(id);
1989
 
    creationInterface->endEntity();
1990
 
    currentEntity = DL_UNKNOWN;
1991
 
}
1992
 
 
1993
 
 
1994
 
 
1995
 
/**
1996
 
 * Adds an image definition that was read from the file via the creation interface.
1997
 
 */
1998
 
void DL_Dxf::addImageDef(DL_CreationInterface* creationInterface) {
1999
 
    DL_ImageDefData id(// handle
2000
 
        values[5],
2001
 
        values[1]);
2002
 
 
2003
 
    creationInterface->linkImage(id);
2004
 
    creationInterface->endEntity();
2005
 
    currentEntity = DL_UNKNOWN;
2006
 
}
2007
 
 
2008
 
 
2009
 
 
2010
 
/**
2011
 
 * Ends some special entities like hatches or old style polylines.
2012
 
 */
2013
 
void DL_Dxf::endEntity(DL_CreationInterface* creationInterface) {
2014
 
        creationInterface->endEntity();
2015
 
}
2016
 
 
2017
 
 
2018
 
/**
2019
 
 * Ends a sequence and notifies the creation interface.
2020
 
 */
2021
 
void DL_Dxf::endSequence(DL_CreationInterface* creationInterface) {
2022
 
    creationInterface->endSequence();
2023
 
}
2024
 
 
2025
 
 
2026
 
/**
2027
 
 * Converts the given string into an int.
2028
 
 * ok is set to false if there was an error.
2029
 
 */
2030
 
int DL_Dxf::stringToInt(const char* s, bool* ok) {
2031
 
    if (ok!=NULL) {
2032
 
        // check string:
2033
 
        *ok = true;
2034
 
        int i=0;
2035
 
        bool dot = false;
2036
 
        do {
2037
 
            if (s[i]=='\0') {
2038
 
                break;
2039
 
            } else if (s[i]=='.') {
2040
 
                if (dot==true) {
2041
 
                    //std::cerr << "two dots\n";
2042
 
                    *ok = false;
2043
 
                } else {
2044
 
                    dot = true;
2045
 
                }
2046
 
            } else if (s[i]<'0' || s[i]>'9') {
2047
 
                //std::cerr << "NaN: '" << s[i] << "'\n";
2048
 
                *ok = false;
2049
 
            }
2050
 
            i++;
2051
 
        } while(s[i]!='\0' && *ok==true);
2052
 
    }
2053
 
 
2054
 
    return atoi(s);
2055
 
}
2056
 
 
2057
 
 
2058
 
/**
2059
 
 * @brief Opens the given file for writing and returns a pointer
2060
 
 * to the dxf writer. This pointer needs to be passed on to other
2061
 
 * writing functions.
2062
 
 *
2063
 
 * @param file Full path of the file to open.
2064
 
 *
2065
 
 * @return Pointer to an ascii dxf writer object.
2066
 
 */
2067
 
DL_WriterA* DL_Dxf::out(const char* file, DL_Codes::version version) {
2068
 
    char* f = new char[strlen(file)+1];
2069
 
    strcpy(f, file);
2070
 
    this->version = version;
2071
 
 
2072
 
    DL_WriterA* dw = new DL_WriterA(f, version);
2073
 
    if (dw->openFailed()) {
2074
 
        delete dw;
2075
 
        delete[] f;
2076
 
        return NULL;
2077
 
    } else {
2078
 
        delete[] f;
2079
 
        return dw;
2080
 
    }
2081
 
}
2082
 
 
2083
 
 
2084
 
 
2085
 
/**
2086
 
 * @brief Writes a DXF header to the file currently opened 
2087
 
 * by the given DXF writer object.
2088
 
 */
2089
 
void DL_Dxf::writeHeader(DL_WriterA& dw) {
2090
 
    dw.comment("dxflib " DL_VERSION);
2091
 
    dw.sectionHeader();
2092
 
 
2093
 
    dw.dxfString(9, "$ACADVER");
2094
 
    switch (version) {
2095
 
    case DL_Codes::AC1009:
2096
 
        dw.dxfString(1, "AC1009");
2097
 
        break;
2098
 
    case DL_Codes::AC1012:
2099
 
        dw.dxfString(1, "AC1012");
2100
 
        break;
2101
 
    case DL_Codes::AC1014:
2102
 
        dw.dxfString(1, "AC1014");
2103
 
        break;
2104
 
    case DL_Codes::AC1015:
2105
 
        dw.dxfString(1, "AC1015");
2106
 
        break;
2107
 
    }
2108
 
 
2109
 
    // Newer version require that (otherwise a*cad crashes..)
2110
 
    if (version==VER_2000) {
2111
 
        dw.dxfString(9, "$HANDSEED");
2112
 
        dw.dxfHex(5, 0xFFFF);
2113
 
    }
2114
 
 
2115
 
    //dw.sectionEnd();
2116
 
}
2117
 
 
2118
 
 
2119
 
 
2120
 
 
2121
 
/**
2122
 
 * Writes a point entity to the file.
2123
 
 *
2124
 
 * @param dw DXF writer
2125
 
 * @param data Entity data from the file
2126
 
 * @param attrib Attributes
2127
 
 */
2128
 
void DL_Dxf::writePoint(DL_WriterA& dw,
2129
 
                        const DL_PointData& data,
2130
 
                        const DL_Attributes& attrib) {
2131
 
    dw.entity("POINT");
2132
 
    if (version==VER_2000) {
2133
 
        dw.dxfString(100, "AcDbEntity");
2134
 
        dw.dxfString(100, "AcDbPoint");
2135
 
    }
2136
 
    dw.entityAttributes(attrib);
2137
 
    dw.coord(POINT_COORD_CODE, data.x, data.y);
2138
 
}
2139
 
 
2140
 
 
2141
 
 
2142
 
/**
2143
 
 * Writes a line entity to the file.
2144
 
 *
2145
 
 * @param dw DXF writer
2146
 
 * @param data Entity data from the file
2147
 
 * @param attrib Attributes
2148
 
 */
2149
 
void DL_Dxf::writeLine(DL_WriterA& dw,
2150
 
                       const DL_LineData& data,
2151
 
                       const DL_Attributes& attrib) {
2152
 
    dw.entity("LINE");
2153
 
    if (version==VER_2000) {
2154
 
        dw.dxfString(100, "AcDbEntity");
2155
 
        dw.dxfString(100, "AcDbLine");
2156
 
    }
2157
 
    dw.entityAttributes(attrib);
2158
 
    dw.coord(LINE_START_CODE, data.x1, data.y1);
2159
 
    dw.coord(LINE_END_CODE, data.x2, data.y2);
2160
 
}
2161
 
 
2162
 
 
2163
 
 
2164
 
/**
2165
 
 * Writes a polyline entity to the file.
2166
 
 *
2167
 
 * @param dw DXF writer
2168
 
 * @param data Entity data from the file
2169
 
 * @param attrib Attributes
2170
 
 * @see writeVertex
2171
 
 */
2172
 
void DL_Dxf::writePolyline(DL_WriterA& dw,
2173
 
                           const DL_PolylineData& data,
2174
 
                           const DL_Attributes& attrib) {
2175
 
    if (version==VER_2000) {
2176
 
        dw.entity("LWPOLYLINE");
2177
 
        dw.entityAttributes(attrib);
2178
 
        dw.dxfString(100, "AcDbEntity");
2179
 
        dw.dxfString(100, "AcDbPolyline");
2180
 
        dw.dxfInt(90, (int)data.number);
2181
 
        dw.dxfInt(70, data.flags);
2182
 
    } else {
2183
 
        dw.entity("POLYLINE");
2184
 
        dw.entityAttributes(attrib);
2185
 
                polylineLayer = attrib.getLayer();
2186
 
        dw.dxfInt(66, 1);
2187
 
        dw.dxfInt(70, data.flags);
2188
 
        dw.coord(VERTEX_COORD_CODE, 0.0, 0.0);
2189
 
    }
2190
 
}
2191
 
 
2192
 
 
2193
 
 
2194
 
/**
2195
 
 * Writes a single vertex of a polyline to the file.
2196
 
 *
2197
 
 * @param dw DXF writer
2198
 
 * @param data Entity data from the file
2199
 
 * @param attrib Attributes
2200
 
 */
2201
 
void DL_Dxf::writeVertex(DL_WriterA& dw,
2202
 
                         const DL_VertexData& data) {
2203
 
 
2204
 
 
2205
 
    if (version==VER_2000) {
2206
 
        dw.dxfReal(10, data.x);
2207
 
        dw.dxfReal(20, data.y);
2208
 
        if (fabs(data.bulge)>1.0e-10) {
2209
 
            dw.dxfReal(42, data.bulge);
2210
 
        }
2211
 
    } else {
2212
 
        dw.entity("VERTEX");
2213
 
        //dw.entityAttributes(attrib);
2214
 
        dw.dxfString(8, polylineLayer);
2215
 
        dw.coord(VERTEX_COORD_CODE, data.x, data.y);
2216
 
        if (fabs(data.bulge)>1.0e-10) {
2217
 
            dw.dxfReal(42, data.bulge);
2218
 
        }
2219
 
    }
2220
 
}
2221
 
 
2222
 
    
2223
 
        
2224
 
/**
2225
 
 * Writes the polyline end. Only needed for DXF R12.
2226
 
 */
2227
 
void DL_Dxf::writePolylineEnd(DL_WriterA& dw) {
2228
 
    if (version==VER_2000) {
2229
 
    } else {
2230
 
        dw.entity("SEQEND");
2231
 
    }
2232
 
}
2233
 
 
2234
 
 
2235
 
/**
2236
 
 * Writes a spline entity to the file.
2237
 
 *
2238
 
 * @param dw DXF writer
2239
 
 * @param data Entity data from the file
2240
 
 * @param attrib Attributes
2241
 
 * @see writeControlPoint
2242
 
 */
2243
 
void DL_Dxf::writeSpline(DL_WriterA& dw,
2244
 
                         const DL_SplineData& data,
2245
 
                         const DL_Attributes& attrib) {
2246
 
 
2247
 
    dw.entity("SPLINE");
2248
 
    dw.entityAttributes(attrib);
2249
 
    if (version==VER_2000) {
2250
 
        dw.dxfString(100, "AcDbEntity");
2251
 
        dw.dxfString(100, "AcDbSpline");
2252
 
    }
2253
 
    dw.dxfInt(70, data.flags);
2254
 
    dw.dxfInt(71, data.degree);
2255
 
    dw.dxfInt(72, data.nKnots);            // number of knots
2256
 
    dw.dxfInt(73, data.nControl);          // number of control points
2257
 
    dw.dxfInt(74, 0);                      // number of fit points
2258
 
}
2259
 
 
2260
 
 
2261
 
 
2262
 
/**
2263
 
 * Writes a single control point of a spline to the file.
2264
 
 *
2265
 
 * @param dw DXF writer
2266
 
 * @param data Entity data from the file
2267
 
 * @param attrib Attributes
2268
 
 */
2269
 
void DL_Dxf::writeControlPoint(DL_WriterA& dw,
2270
 
                               const DL_ControlPointData& data) {
2271
 
 
2272
 
    dw.dxfReal(10, data.x);
2273
 
    dw.dxfReal(20, data.y);
2274
 
    dw.dxfReal(30, data.z);
2275
 
}
2276
 
 
2277
 
 
2278
 
 
2279
 
/**
2280
 
 * Writes a single knot of a spline to the file.
2281
 
 *
2282
 
 * @param dw DXF writer
2283
 
 * @param data Entity data from the file
2284
 
 * @param attrib Attributes
2285
 
 */
2286
 
void DL_Dxf::writeKnot(DL_WriterA& dw,
2287
 
                       const DL_KnotData& data) {
2288
 
 
2289
 
    dw.dxfReal(40, data.k);
2290
 
}
2291
 
 
2292
 
 
2293
 
 
2294
 
/**
2295
 
 * Writes a circle entity to the file.
2296
 
 *
2297
 
 * @param dw DXF writer
2298
 
 * @param data Entity data from the file
2299
 
 * @param attrib Attributes
2300
 
 */
2301
 
void DL_Dxf::writeCircle(DL_WriterA& dw,
2302
 
                         const DL_CircleData& data,
2303
 
                         const DL_Attributes& attrib) {
2304
 
    dw.entity("CIRCLE");
2305
 
    if (version==VER_2000) {
2306
 
        dw.dxfString(100, "AcDbEntity");
2307
 
        dw.dxfString(100, "AcDbCircle");
2308
 
    }
2309
 
    dw.entityAttributes(attrib);
2310
 
    dw.coord(10, data.cx, data.cy);
2311
 
    dw.dxfReal(40, data.radius);
2312
 
}
2313
 
 
2314
 
 
2315
 
 
2316
 
/**
2317
 
 * Writes an arc entity to the file.
2318
 
 *
2319
 
 * @param dw DXF writer
2320
 
 * @param data Entity data from the file
2321
 
 * @param attrib Attributes
2322
 
 */
2323
 
void DL_Dxf::writeArc(DL_WriterA& dw,
2324
 
                      const DL_ArcData& data,
2325
 
                      const DL_Attributes& attrib) {
2326
 
    dw.entity("ARC");
2327
 
    if (version==VER_2000) {
2328
 
        dw.dxfString(100, "AcDbEntity");
2329
 
    }
2330
 
    dw.entityAttributes(attrib);
2331
 
    if (version==VER_2000) {
2332
 
        dw.dxfString(100, "AcDbCircle");
2333
 
    }
2334
 
    dw.coord(10, data.cx, data.cy);
2335
 
    dw.dxfReal(40, data.radius);
2336
 
    if (version==VER_2000) {
2337
 
        dw.dxfString(100, "AcDbArc");
2338
 
    }
2339
 
    dw.dxfReal(50, data.angle1);
2340
 
    dw.dxfReal(51, data.angle2);
2341
 
}
2342
 
 
2343
 
 
2344
 
 
2345
 
/**
2346
 
 * Writes an ellipse entity to the file.
2347
 
 *
2348
 
 * @param dw DXF writer
2349
 
 * @param data Entity data from the file
2350
 
 * @param attrib Attributes
2351
 
 */
2352
 
void DL_Dxf::writeEllipse(DL_WriterA& dw,
2353
 
                          const DL_EllipseData& data,
2354
 
                          const DL_Attributes& attrib) {
2355
 
 
2356
 
    if (version>VER_R12) {
2357
 
        dw.entity("ELLIPSE");
2358
 
        if (version==VER_2000) {
2359
 
            dw.dxfString(100, "AcDbEntity");
2360
 
            dw.dxfString(100, "AcDbEllipse");
2361
 
        }
2362
 
        dw.entityAttributes(attrib);
2363
 
        dw.coord(10, data.cx, data.cy);
2364
 
        dw.coord(11, data.mx, data.my);
2365
 
        dw.dxfReal(40, data.ratio);
2366
 
        dw.dxfReal(41, data.angle1);
2367
 
        dw.dxfReal(42, data.angle2);
2368
 
    }
2369
 
}
2370
 
    
2371
 
    
2372
 
 
2373
 
/**
2374
 
 * Writes a solid entity to the file.
2375
 
 *
2376
 
 * @param dw DXF writer
2377
 
 * @param data Entity data from the file
2378
 
 * @param attrib Attributes
2379
 
 */
2380
 
void DL_Dxf::writeSolid(DL_WriterA& dw,
2381
 
                   const DL_SolidData& data,
2382
 
                   const DL_Attributes& attrib) {
2383
 
    dw.entity("SOLID");
2384
 
    if (version==VER_2000) {
2385
 
        dw.dxfString(100, "AcDbEntity");
2386
 
        dw.dxfString(100, "AcDbTrace");
2387
 
    }
2388
 
    dw.entityAttributes(attrib);
2389
 
    dw.coord(10, data.x[0], data.y[0], data.z[0]);
2390
 
    dw.coord(11, data.x[1], data.y[1], data.z[1]);
2391
 
    dw.coord(12, data.x[2], data.y[2], data.z[2]);
2392
 
    dw.coord(13, data.x[3], data.y[3], data.z[3]);
2393
 
    dw.dxfReal(39, data.thickness);
2394
 
}
2395
 
 
2396
 
 
2397
 
 
2398
 
/**
2399
 
 * Writes a 3d face entity to the file.
2400
 
 *
2401
 
 * @param dw DXF writer
2402
 
 * @param data Entity data from the file
2403
 
 * @param attrib Attributes
2404
 
 */
2405
 
void DL_Dxf::write3dFace(DL_WriterA& dw,
2406
 
                   const DL_3dFaceData& data,
2407
 
                   const DL_Attributes& attrib) {
2408
 
    dw.entity("3DFACE");
2409
 
    if (version==VER_2000) {
2410
 
        dw.dxfString(100, "AcDbEntity");
2411
 
        dw.dxfString(100, "AcDbFace");
2412
 
    }
2413
 
    dw.entityAttributes(attrib);
2414
 
    dw.coord(10, data.x[0], data.y[0], data.z[0]);
2415
 
    dw.coord(11, data.x[1], data.y[1], data.z[1]);
2416
 
    dw.coord(12, data.x[2], data.y[2], data.z[2]);
2417
 
    dw.coord(13, data.x[3], data.y[3], data.z[3]);
2418
 
}
2419
 
 
2420
 
 
2421
 
 
2422
 
/**
2423
 
 * Writes an insert to the file.
2424
 
 *
2425
 
 * @param dw DXF writer
2426
 
 * @param data Entity data from the file
2427
 
 * @param attrib Attributes
2428
 
 */
2429
 
void DL_Dxf::writeInsert(DL_WriterA& dw,
2430
 
                         const DL_InsertData& data,
2431
 
                         const DL_Attributes& attrib) {
2432
 
 
2433
 
    if (data.name.empty()) {
2434
 
        std::cerr << "DL_Dxf::writeInsert: "
2435
 
        << "Block name must not be empty\n";
2436
 
        return;
2437
 
    }
2438
 
 
2439
 
    dw.entity("INSERT");
2440
 
    if (version==VER_2000) {
2441
 
        dw.dxfString(100, "AcDbEntity");
2442
 
        dw.dxfString(100, "AcDbBlockReference");
2443
 
    }
2444
 
    dw.entityAttributes(attrib);
2445
 
    dw.dxfString(2, data.name);
2446
 
    dw.dxfReal(10, data.ipx);
2447
 
    dw.dxfReal(20, data.ipy);
2448
 
    dw.dxfReal(30, 0.0);
2449
 
    if (data.sx!=1.0 || data.sy!=1.0) {
2450
 
        dw.dxfReal(41, data.sx);
2451
 
        dw.dxfReal(42, data.sy);
2452
 
        dw.dxfReal(43, 1.0);
2453
 
    }
2454
 
    if (data.angle!=0.0) {
2455
 
        dw.dxfReal(50, data.angle);
2456
 
    }
2457
 
    if (data.cols!=1 || data.rows!=1) {
2458
 
        dw.dxfInt(70, data.cols);
2459
 
        dw.dxfInt(71, data.rows);
2460
 
    }
2461
 
    if (data.colSp!=0.0 || data.rowSp!=0.0) {
2462
 
        dw.dxfReal(44, data.colSp);
2463
 
        dw.dxfReal(45, data.rowSp);
2464
 
    }
2465
 
 
2466
 
}
2467
 
 
2468
 
 
2469
 
 
2470
 
/**
2471
 
 * Writes a multi text entity to the file.
2472
 
 *
2473
 
 * @param dw DXF writer
2474
 
 * @param data Entity data from the file
2475
 
 * @param attrib Attributes
2476
 
 */
2477
 
void DL_Dxf::writeMText(DL_WriterA& dw,
2478
 
                        const DL_MTextData& data,
2479
 
                        const DL_Attributes& attrib) {
2480
 
 
2481
 
    dw.entity("MTEXT");
2482
 
    if (version==VER_2000) {
2483
 
        dw.dxfString(100, "AcDbEntity");
2484
 
        dw.dxfString(100, "AcDbMText");
2485
 
    }
2486
 
    dw.entityAttributes(attrib);
2487
 
    dw.dxfReal(10, data.ipx);
2488
 
    dw.dxfReal(20, data.ipy);
2489
 
    dw.dxfReal(30, 0.0);
2490
 
    dw.dxfReal(40, data.height);
2491
 
    dw.dxfReal(41, data.width);
2492
 
 
2493
 
    dw.dxfInt(71, data.attachmentPoint);
2494
 
    dw.dxfInt(72, data.drawingDirection);
2495
 
 
2496
 
    // Creare text chunks of 250 characters each:
2497
 
    int length = data.text.length();
2498
 
    char chunk[251];
2499
 
    int i;
2500
 
    for (i=250; i<length; i+=250) {
2501
 
        strncpy(chunk, &data.text.c_str()[i-250], 250);
2502
 
        chunk[250]='\0';
2503
 
        dw.dxfString(3, chunk);
2504
 
    }
2505
 
    strncpy(chunk, &data.text.c_str()[i-250], 250);
2506
 
    chunk[250]='\0';
2507
 
    dw.dxfString(1, chunk);
2508
 
 
2509
 
    dw.dxfString(7, data.style);
2510
 
 
2511
 
    // since dxflib 2.0.2.1: degrees not rad (error in autodesk dxf doc)
2512
 
    dw.dxfReal(50, data.angle/(2.0*M_PI)*360.0);
2513
 
 
2514
 
    dw.dxfInt(73, data.lineSpacingStyle);
2515
 
    dw.dxfReal(44, data.lineSpacingFactor);
2516
 
}
2517
 
 
2518
 
 
2519
 
 
2520
 
/**
2521
 
 * Writes a text entity to the file.
2522
 
 *
2523
 
 * @param dw DXF writer
2524
 
 * @param data Entity data from the file
2525
 
 * @param attrib Attributes
2526
 
 */
2527
 
void DL_Dxf::writeText(DL_WriterA& dw,
2528
 
                       const DL_TextData& data,
2529
 
                       const DL_Attributes& attrib) {
2530
 
 
2531
 
    dw.entity("TEXT");
2532
 
    if (version==VER_2000) {
2533
 
        dw.dxfString(100, "AcDbEntity");
2534
 
        dw.dxfString(100, "AcDbText");
2535
 
    }
2536
 
    dw.entityAttributes(attrib);
2537
 
    dw.dxfReal(10, data.ipx);
2538
 
    dw.dxfReal(20, data.ipy);
2539
 
    dw.dxfReal(30, 0.0);
2540
 
    dw.dxfReal(40, data.height);
2541
 
    dw.dxfString(1, data.text);
2542
 
    dw.dxfReal(50, data.angle/(2*M_PI)*360.0);
2543
 
    dw.dxfReal(41, data.xScaleFactor);
2544
 
    dw.dxfString(7, data.style);
2545
 
 
2546
 
    dw.dxfInt(71, data.textGenerationFlags);
2547
 
    dw.dxfInt(72, data.hJustification);
2548
 
 
2549
 
    dw.dxfReal(11, data.apx);
2550
 
    dw.dxfReal(21, data.apy);
2551
 
    dw.dxfReal(31, 0.0);
2552
 
 
2553
 
    dw.dxfInt(73, data.vJustification);
2554
 
}
2555
 
 
2556
 
 
2557
 
/**
2558
 
 * Writes an aligned dimension entity to the file.
2559
 
 *
2560
 
 * @param dw DXF writer
2561
 
 * @param data Generic dimension data for from the file
2562
 
 * @param data Specific aligned dimension data from the file
2563
 
 * @param attrib Attributes
2564
 
 */
2565
 
void DL_Dxf::writeDimAligned(DL_WriterA& dw,
2566
 
                             const DL_DimensionData& data,
2567
 
                             const DL_DimAlignedData& edata,
2568
 
                             const DL_Attributes& attrib) {
2569
 
 
2570
 
    dw.entity("DIMENSION");
2571
 
 
2572
 
    if (version==VER_2000) {
2573
 
        dw.dxfString(100, "AcDbEntity");
2574
 
    }
2575
 
    dw.entityAttributes(attrib);
2576
 
    if (version==VER_2000) {
2577
 
        dw.dxfString(100, "AcDbDimension");
2578
 
    }
2579
 
 
2580
 
    dw.dxfReal(10, data.dpx);
2581
 
    dw.dxfReal(20, data.dpy);
2582
 
    dw.dxfReal(30, 0.0);
2583
 
 
2584
 
    dw.dxfReal(11, data.mpx);
2585
 
    dw.dxfReal(21, data.mpy);
2586
 
    dw.dxfReal(31, 0.0);
2587
 
 
2588
 
    dw.dxfInt(70, 1);
2589
 
    if (version>VER_R12) {
2590
 
        dw.dxfInt(71, data.attachmentPoint);
2591
 
        dw.dxfInt(72, data.lineSpacingStyle); // opt
2592
 
        dw.dxfReal(41, data.lineSpacingFactor); // opt
2593
 
    }
2594
 
 
2595
 
    dw.dxfReal(42, data.angle);
2596
 
 
2597
 
    dw.dxfString(1, data.text);   // opt
2598
 
    //dw.dxfString(3, data.style);
2599
 
    dw.dxfString(3, "Standard");
2600
 
 
2601
 
    if (version==VER_2000) {
2602
 
        dw.dxfString(100, "AcDbAlignedDimension");
2603
 
    }
2604
 
 
2605
 
    dw.dxfReal(13, edata.epx1);
2606
 
    dw.dxfReal(23, edata.epy1);
2607
 
    dw.dxfReal(33, 0.0);
2608
 
 
2609
 
    dw.dxfReal(14, edata.epx2);
2610
 
    dw.dxfReal(24, edata.epy2);
2611
 
    dw.dxfReal(34, 0.0);
2612
 
}
2613
 
 
2614
 
 
2615
 
 
2616
 
/**
2617
 
 * Writes a linear dimension entity to the file.
2618
 
 *
2619
 
 * @param dw DXF writer
2620
 
 * @param data Generic dimension data for from the file
2621
 
 * @param data Specific linear dimension data from the file
2622
 
 * @param attrib Attributes
2623
 
 */
2624
 
void DL_Dxf::writeDimLinear(DL_WriterA& dw,
2625
 
                            const DL_DimensionData& data,
2626
 
                            const DL_DimLinearData& edata,
2627
 
                            const DL_Attributes& attrib) {
2628
 
 
2629
 
    dw.entity("DIMENSION");
2630
 
 
2631
 
    if (version==VER_2000) {
2632
 
        dw.dxfString(100, "AcDbEntity");
2633
 
    }
2634
 
    dw.entityAttributes(attrib);
2635
 
    if (version==VER_2000) {
2636
 
        dw.dxfString(100, "AcDbDimension");
2637
 
    }
2638
 
 
2639
 
    dw.dxfReal(10, data.dpx);
2640
 
    dw.dxfReal(20, data.dpy);
2641
 
    dw.dxfReal(30, 0.0);
2642
 
 
2643
 
    dw.dxfReal(11, data.mpx);
2644
 
    dw.dxfReal(21, data.mpy);
2645
 
    dw.dxfReal(31, 0.0);
2646
 
 
2647
 
    dw.dxfInt(70, 0);
2648
 
    if (version>VER_R12) {
2649
 
        dw.dxfInt(71, data.attachmentPoint);
2650
 
        dw.dxfInt(72, data.lineSpacingStyle); // opt
2651
 
        dw.dxfReal(41, data.lineSpacingFactor); // opt
2652
 
    }
2653
 
 
2654
 
    dw.dxfReal(42, data.angle);
2655
 
 
2656
 
    dw.dxfString(1, data.text);   // opt
2657
 
    //dw.dxfString(3, data.style);
2658
 
    dw.dxfString(3, "Standard");
2659
 
 
2660
 
    if (version==VER_2000) {
2661
 
        dw.dxfString(100, "AcDbAlignedDimension");
2662
 
    }
2663
 
 
2664
 
    dw.dxfReal(13, edata.dpx1);
2665
 
    dw.dxfReal(23, edata.dpy1);
2666
 
    dw.dxfReal(33, 0.0);
2667
 
 
2668
 
    dw.dxfReal(14, edata.dpx2);
2669
 
    dw.dxfReal(24, edata.dpy2);
2670
 
    dw.dxfReal(34, 0.0);
2671
 
 
2672
 
    dw.dxfReal(50, edata.angle/(2.0*M_PI)*360.0);
2673
 
 
2674
 
    if (version==VER_2000) {
2675
 
        dw.dxfString(100, "AcDbRotatedDimension");
2676
 
        /*
2677
 
        dw.dxfString(1001, "ACAD");
2678
 
        dw.dxfString(1000, "DSTYLE");
2679
 
        dw.dxfString(1002, "{");
2680
 
        dw.dxfInt(1070, 340);
2681
 
        dw.dxfInt(1005, 11);
2682
 
        dw.dxfString(1002, "}");
2683
 
        */
2684
 
    }
2685
 
}
2686
 
 
2687
 
 
2688
 
 
2689
 
/**
2690
 
 * Writes a radial dimension entity to the file.
2691
 
 *
2692
 
 * @param dw DXF writer
2693
 
 * @param data Generic dimension data for from the file
2694
 
 * @param data Specific radial dimension data from the file
2695
 
 * @param attrib Attributes
2696
 
 */
2697
 
void DL_Dxf::writeDimRadial(DL_WriterA& dw,
2698
 
                            const DL_DimensionData& data,
2699
 
                            const DL_DimRadialData& edata,
2700
 
                            const DL_Attributes& attrib) {
2701
 
 
2702
 
    dw.entity("DIMENSION");
2703
 
 
2704
 
    if (version==VER_2000) {
2705
 
        dw.dxfString(100, "AcDbEntity");
2706
 
    }
2707
 
    dw.entityAttributes(attrib);
2708
 
    if (version==VER_2000) {
2709
 
        dw.dxfString(100, "AcDbDimension");
2710
 
    }
2711
 
 
2712
 
    dw.dxfReal(10, data.dpx);
2713
 
    dw.dxfReal(20, data.dpy);
2714
 
    dw.dxfReal(30, 0.0);
2715
 
 
2716
 
    dw.dxfReal(11, data.mpx);
2717
 
    dw.dxfReal(21, data.mpy);
2718
 
    dw.dxfReal(31, 0.0);
2719
 
 
2720
 
    dw.dxfInt(70, 4);
2721
 
    if (version>VER_R12) {
2722
 
        dw.dxfInt(71, data.attachmentPoint);
2723
 
        dw.dxfInt(72, data.lineSpacingStyle); // opt
2724
 
        dw.dxfReal(41, data.lineSpacingFactor); // opt
2725
 
    }
2726
 
 
2727
 
    dw.dxfReal(42, data.angle);
2728
 
 
2729
 
    dw.dxfString(1, data.text);   // opt
2730
 
    //dw.dxfString(3, data.style);
2731
 
    dw.dxfString(3, "Standard");
2732
 
 
2733
 
    if (version==VER_2000) {
2734
 
        dw.dxfString(100, "AcDbRadialDimension");
2735
 
    }
2736
 
 
2737
 
    dw.dxfReal(15, edata.dpx);
2738
 
    dw.dxfReal(25, edata.dpy);
2739
 
    dw.dxfReal(35, 0.0);
2740
 
 
2741
 
    dw.dxfReal(40, edata.leader);
2742
 
}
2743
 
 
2744
 
 
2745
 
 
2746
 
/**
2747
 
 * Writes a diametric dimension entity to the file.
2748
 
 *
2749
 
 * @param dw DXF writer
2750
 
 * @param data Generic dimension data for from the file
2751
 
 * @param data Specific diametric dimension data from the file
2752
 
 * @param attrib Attributes
2753
 
 */
2754
 
void DL_Dxf::writeDimDiametric(DL_WriterA& dw,
2755
 
                               const DL_DimensionData& data,
2756
 
                               const DL_DimDiametricData& edata,
2757
 
                               const DL_Attributes& attrib) {
2758
 
 
2759
 
    dw.entity("DIMENSION");
2760
 
 
2761
 
    if (version==VER_2000) {
2762
 
        dw.dxfString(100, "AcDbEntity");
2763
 
    }
2764
 
    dw.entityAttributes(attrib);
2765
 
    if (version==VER_2000) {
2766
 
        dw.dxfString(100, "AcDbDimension");
2767
 
    }
2768
 
 
2769
 
    dw.dxfReal(10, data.dpx);
2770
 
    dw.dxfReal(20, data.dpy);
2771
 
    dw.dxfReal(30, 0.0);
2772
 
 
2773
 
    dw.dxfReal(11, data.mpx);
2774
 
    dw.dxfReal(21, data.mpy);
2775
 
    dw.dxfReal(31, 0.0);
2776
 
 
2777
 
    dw.dxfInt(70, 3);
2778
 
    if (version>VER_R12) {
2779
 
        dw.dxfInt(71, data.attachmentPoint);
2780
 
        dw.dxfInt(72, data.lineSpacingStyle); // opt
2781
 
        dw.dxfReal(41, data.lineSpacingFactor); // opt
2782
 
    }
2783
 
 
2784
 
    dw.dxfReal(42, data.angle);
2785
 
 
2786
 
    dw.dxfString(1, data.text);   // opt
2787
 
    //dw.dxfString(3, data.style);
2788
 
    dw.dxfString(3, "Standard");
2789
 
 
2790
 
    if (version==VER_2000) {
2791
 
        dw.dxfString(100, "AcDbDiametricDimension");
2792
 
    }
2793
 
 
2794
 
    dw.dxfReal(15, edata.dpx);
2795
 
    dw.dxfReal(25, edata.dpy);
2796
 
    dw.dxfReal(35, 0.0);
2797
 
 
2798
 
    dw.dxfReal(40, edata.leader);
2799
 
}
2800
 
 
2801
 
 
2802
 
 
2803
 
/**
2804
 
 * Writes an angular dimension entity to the file.
2805
 
 *
2806
 
 * @param dw DXF writer
2807
 
 * @param data Generic dimension data for from the file
2808
 
 * @param data Specific angular dimension data from the file
2809
 
 * @param attrib Attributes
2810
 
 */
2811
 
void DL_Dxf::writeDimAngular(DL_WriterA& dw,
2812
 
                             const DL_DimensionData& data,
2813
 
                             const DL_DimAngularData& edata,
2814
 
                             const DL_Attributes& attrib) {
2815
 
 
2816
 
    dw.entity("DIMENSION");
2817
 
 
2818
 
    if (version==VER_2000) {
2819
 
        dw.dxfString(100, "AcDbEntity");
2820
 
    }
2821
 
    dw.entityAttributes(attrib);
2822
 
    if (version==VER_2000) {
2823
 
        dw.dxfString(100, "AcDbDimension");
2824
 
    }
2825
 
 
2826
 
    dw.dxfReal(10, data.dpx);
2827
 
    dw.dxfReal(20, data.dpy);
2828
 
    dw.dxfReal(30, 0.0);
2829
 
 
2830
 
    dw.dxfReal(11, data.mpx);
2831
 
    dw.dxfReal(21, data.mpy);
2832
 
    dw.dxfReal(31, 0.0);
2833
 
 
2834
 
    dw.dxfInt(70, 2);
2835
 
    if (version>VER_R12) {
2836
 
        dw.dxfInt(71, data.attachmentPoint);
2837
 
        dw.dxfInt(72, data.lineSpacingStyle); // opt
2838
 
        dw.dxfReal(41, data.lineSpacingFactor); // opt
2839
 
    }
2840
 
 
2841
 
    dw.dxfReal(42, data.angle);
2842
 
 
2843
 
    dw.dxfString(1, data.text);   // opt
2844
 
    //dw.dxfString(3, data.style);
2845
 
    dw.dxfString(3, "Standard");
2846
 
 
2847
 
    if (version==VER_2000) {
2848
 
        dw.dxfString(100, "AcDb2LineAngularDimension");
2849
 
    }
2850
 
 
2851
 
    dw.dxfReal(13, edata.dpx1);
2852
 
    dw.dxfReal(23, edata.dpy1);
2853
 
    dw.dxfReal(33, 0.0);
2854
 
 
2855
 
    dw.dxfReal(14, edata.dpx2);
2856
 
    dw.dxfReal(24, edata.dpy2);
2857
 
    dw.dxfReal(34, 0.0);
2858
 
 
2859
 
    dw.dxfReal(15, edata.dpx3);
2860
 
    dw.dxfReal(25, edata.dpy3);
2861
 
    dw.dxfReal(35, 0.0);
2862
 
 
2863
 
    dw.dxfReal(16, edata.dpx4);
2864
 
    dw.dxfReal(26, edata.dpy4);
2865
 
    dw.dxfReal(36, 0.0);
2866
 
}
2867
 
 
2868
 
 
2869
 
 
2870
 
/**
2871
 
 * Writes an angular dimension entity (3 points version) to the file.
2872
 
 *
2873
 
 * @param dw DXF writer
2874
 
 * @param data Generic dimension data for from the file
2875
 
 * @param data Specific angular dimension data from the file
2876
 
 * @param attrib Attributes
2877
 
 */
2878
 
void DL_Dxf::writeDimAngular3P(DL_WriterA& dw,
2879
 
                               const DL_DimensionData& data,
2880
 
                               const DL_DimAngular3PData& edata,
2881
 
                               const DL_Attributes& attrib) {
2882
 
 
2883
 
    dw.entity("DIMENSION");
2884
 
 
2885
 
    if (version==VER_2000) {
2886
 
        dw.dxfString(100, "AcDbEntity");
2887
 
    }
2888
 
    dw.entityAttributes(attrib);
2889
 
    if (version==VER_2000) {
2890
 
        dw.dxfString(100, "AcDbDimension");
2891
 
    }
2892
 
 
2893
 
    dw.dxfReal(10, data.dpx);
2894
 
    dw.dxfReal(20, data.dpy);
2895
 
    dw.dxfReal(30, 0.0);
2896
 
 
2897
 
    dw.dxfReal(11, data.mpx);
2898
 
    dw.dxfReal(21, data.mpy);
2899
 
    dw.dxfReal(31, 0.0);
2900
 
 
2901
 
    dw.dxfInt(70, 5);
2902
 
    if (version>VER_R12) {
2903
 
        dw.dxfInt(71, data.attachmentPoint);
2904
 
        dw.dxfInt(72, data.lineSpacingStyle); // opt
2905
 
        dw.dxfReal(41, data.lineSpacingFactor); // opt
2906
 
    }
2907
 
 
2908
 
    dw.dxfReal(42, data.angle);
2909
 
 
2910
 
    dw.dxfString(1, data.text);   // opt
2911
 
    //dw.dxfString(3, data.style);
2912
 
    dw.dxfString(3, "Standard");
2913
 
 
2914
 
    if (version==VER_2000) {
2915
 
        dw.dxfString(100, "AcDb3PointAngularDimension");
2916
 
    }
2917
 
 
2918
 
    dw.dxfReal(13, edata.dpx1);
2919
 
    dw.dxfReal(23, edata.dpy1);
2920
 
    dw.dxfReal(33, 0.0);
2921
 
 
2922
 
    dw.dxfReal(14, edata.dpx2);
2923
 
    dw.dxfReal(24, edata.dpy2);
2924
 
    dw.dxfReal(34, 0.0);
2925
 
 
2926
 
    dw.dxfReal(15, edata.dpx3);
2927
 
    dw.dxfReal(25, edata.dpy3);
2928
 
    dw.dxfReal(35, 0.0);
2929
 
}
2930
 
 
2931
 
 
2932
 
 
2933
 
 
2934
 
/**
2935
 
 * Writes an ordinate dimension entity to the file.
2936
 
 *
2937
 
 * @param dw DXF writer
2938
 
 * @param data Generic dimension data for from the file
2939
 
 * @param data Specific ordinate dimension data from the file
2940
 
 * @param attrib Attributes
2941
 
 */
2942
 
void DL_Dxf::writeDimOrdinate(DL_WriterA& dw,
2943
 
                             const DL_DimensionData& data,
2944
 
                             const DL_DimOrdinateData& edata,
2945
 
                             const DL_Attributes& attrib) {
2946
 
 
2947
 
    dw.entity("DIMENSION");
2948
 
 
2949
 
    if (version==VER_2000) {
2950
 
        dw.dxfString(100, "AcDbEntity");
2951
 
    }
2952
 
    dw.entityAttributes(attrib);
2953
 
    if (version==VER_2000) {
2954
 
        dw.dxfString(100, "AcDbDimension");
2955
 
    }
2956
 
 
2957
 
    dw.dxfReal(10, data.dpx);
2958
 
    dw.dxfReal(20, data.dpy);
2959
 
    dw.dxfReal(30, 0.0);
2960
 
 
2961
 
    dw.dxfReal(11, data.mpx);
2962
 
    dw.dxfReal(21, data.mpy);
2963
 
    dw.dxfReal(31, 0.0);
2964
 
 
2965
 
    int type = 6;
2966
 
    if (edata.xtype) {
2967
 
        type+=64;
2968
 
    }
2969
 
 
2970
 
    dw.dxfInt(70, type);
2971
 
    if (version>VER_R12) {
2972
 
        dw.dxfInt(71, data.attachmentPoint);
2973
 
        dw.dxfInt(72, data.lineSpacingStyle); // opt
2974
 
        dw.dxfReal(41, data.lineSpacingFactor); // opt
2975
 
    }
2976
 
 
2977
 
    dw.dxfString(1, data.text);   // opt
2978
 
    //dw.dxfString(3, data.style);
2979
 
    dw.dxfString(3, "Standard");
2980
 
 
2981
 
    if (version==VER_2000) {
2982
 
        dw.dxfString(100, "AcDbOrdinateDimension");
2983
 
    }
2984
 
 
2985
 
    dw.dxfReal(13, edata.dpx1);
2986
 
    dw.dxfReal(23, edata.dpy1);
2987
 
    dw.dxfReal(33, 0.0);
2988
 
 
2989
 
    dw.dxfReal(14, edata.dpx2);
2990
 
    dw.dxfReal(24, edata.dpy2);
2991
 
    dw.dxfReal(34, 0.0);
2992
 
}
2993
 
 
2994
 
 
2995
 
 
2996
 
/**
2997
 
 * Writes a leader entity to the file.
2998
 
 *
2999
 
 * @param dw DXF writer
3000
 
 * @param data Entity data from the file
3001
 
 * @param attrib Attributes
3002
 
 * @see writeVertex
3003
 
 */
3004
 
void DL_Dxf::writeLeader(DL_WriterA& dw,
3005
 
                         const DL_LeaderData& data,
3006
 
                         const DL_Attributes& attrib) {
3007
 
    if (version>VER_R12) {
3008
 
        dw.entity("LEADER");
3009
 
        dw.entityAttributes(attrib);
3010
 
        if (version==VER_2000) {
3011
 
            dw.dxfString(100, "AcDbEntity");
3012
 
            dw.dxfString(100, "AcDbLeader");
3013
 
        }
3014
 
        dw.dxfString(3, "Standard");
3015
 
        dw.dxfInt(71, data.arrowHeadFlag);
3016
 
        dw.dxfInt(72, data.leaderPathType);
3017
 
        dw.dxfInt(73, data.leaderCreationFlag);
3018
 
        dw.dxfInt(74, data.hooklineDirectionFlag);
3019
 
        dw.dxfInt(75, data.hooklineFlag);
3020
 
        dw.dxfReal(40, data.textAnnotationHeight);
3021
 
        dw.dxfReal(41, data.textAnnotationWidth);
3022
 
        dw.dxfInt(76, data.number);
3023
 
    }
3024
 
}
3025
 
 
3026
 
 
3027
 
 
3028
 
/**
3029
 
 * Writes a single vertex of a leader to the file.
3030
 
 *
3031
 
 * @param dw DXF writer
3032
 
 * @param data Entity data
3033
 
 */
3034
 
void DL_Dxf::writeLeaderVertex(DL_WriterA& dw,
3035
 
                               const DL_LeaderVertexData& data) {
3036
 
    if (version>VER_R12) {
3037
 
        dw.dxfReal(10, data.x);
3038
 
        dw.dxfReal(20, data.y);
3039
 
    }
3040
 
}
3041
 
 
3042
 
 
3043
 
 
3044
 
/**
3045
 
 * Writes the beginning of a hatch entity to the file.
3046
 
 * This must be followed by one or more writeHatchLoop()
3047
 
 * calls and a writeHatch2() call.
3048
 
 *
3049
 
 * @param dw DXF writer
3050
 
 * @param data Entity data.
3051
 
 * @param attrib Attributes
3052
 
 */
3053
 
void DL_Dxf::writeHatch1(DL_WriterA& dw,
3054
 
                         const DL_HatchData& data,
3055
 
                         const DL_Attributes& attrib) {
3056
 
 
3057
 
    dw.entity("HATCH");
3058
 
    dw.entityAttributes(attrib);
3059
 
    if (version==VER_2000) {
3060
 
        dw.dxfString(100, "AcDbEntity");
3061
 
        dw.dxfString(100, "AcDbHatch");
3062
 
    }
3063
 
    dw.dxfReal(10, 0.0);             // elevation
3064
 
    dw.dxfReal(20, 0.0);
3065
 
    dw.dxfReal(30, 0.0);
3066
 
    dw.dxfReal(210, 0.0);             // extrusion dir.
3067
 
    dw.dxfReal(220, 0.0);
3068
 
    dw.dxfReal(230, 1.0);
3069
 
    if (data.solid==false) {
3070
 
        dw.dxfString(2, data.pattern);
3071
 
    } else {
3072
 
        dw.dxfString(2, "SOLID");
3073
 
    }
3074
 
    dw.dxfInt(70, (int)data.solid);
3075
 
    dw.dxfInt(71, 0);                // associative
3076
 
    dw.dxfInt(91, data.numLoops);
3077
 
}
3078
 
 
3079
 
 
3080
 
 
3081
 
/**
3082
 
 * Writes the end of a hatch entity to the file.
3083
 
 *
3084
 
 * @param dw DXF writer
3085
 
 * @param data Entity data.
3086
 
 * @param attrib Attributes
3087
 
 */
3088
 
void DL_Dxf::writeHatch2(DL_WriterA& dw,
3089
 
                         const DL_HatchData& data,
3090
 
                         const DL_Attributes& /*attrib*/) {
3091
 
 
3092
 
    dw.dxfInt(75, 0);                // odd parity
3093
 
    dw.dxfInt(76, 1);                // pattern type
3094
 
    if (data.solid==false) {
3095
 
        dw.dxfReal(52, data.angle);
3096
 
        dw.dxfReal(41, data.scale);
3097
 
        dw.dxfInt(77, 0);            // not double
3098
 
        //dw.dxfInt(78, 0);
3099
 
        dw.dxfInt(78, 1);
3100
 
        dw.dxfReal(53, 45.0);
3101
 
        dw.dxfReal(43, 0.0);
3102
 
        dw.dxfReal(44, 0.0);
3103
 
        dw.dxfReal(45, -0.0883883476483184);
3104
 
        dw.dxfReal(46, 0.0883883476483185);
3105
 
        dw.dxfInt(79, 0);
3106
 
    }
3107
 
    dw.dxfInt(98, 0);
3108
 
}
3109
 
 
3110
 
 
3111
 
 
3112
 
/**
3113
 
 * Writes the beginning of a hatch loop to the file. This
3114
 
 * must happen after writing the beginning of a hatch entity.
3115
 
 *
3116
 
 * @param dw DXF writer
3117
 
 * @param data Entity data.
3118
 
 * @param attrib Attributes
3119
 
 */
3120
 
void DL_Dxf::writeHatchLoop1(DL_WriterA& dw,
3121
 
                             const DL_HatchLoopData& data) {
3122
 
 
3123
 
    dw.dxfInt(92, 1);
3124
 
    dw.dxfInt(93, data.numEdges);
3125
 
    //dw.dxfInt(97, 0);
3126
 
}
3127
 
 
3128
 
 
3129
 
 
3130
 
/**
3131
 
 * Writes the end of a hatch loop to the file.
3132
 
 *
3133
 
 * @param dw DXF writer
3134
 
 * @param data Entity data.
3135
 
 * @param attrib Attributes
3136
 
 */
3137
 
void DL_Dxf::writeHatchLoop2(DL_WriterA& dw,
3138
 
                             const DL_HatchLoopData& /*data*/) {
3139
 
 
3140
 
    dw.dxfInt(97, 0);
3141
 
}
3142
 
 
3143
 
 
3144
 
/**
3145
 
 * Writes the beginning of a hatch entity to the file.
3146
 
 *
3147
 
 * @param dw DXF writer
3148
 
 * @param data Entity data.
3149
 
 * @param attrib Attributes
3150
 
 */
3151
 
void DL_Dxf::writeHatchEdge(DL_WriterA& dw,
3152
 
                            const DL_HatchEdgeData& data) {
3153
 
 
3154
 
    dw.dxfInt(72, data.type);
3155
 
 
3156
 
    switch (data.type) {
3157
 
    case 1:
3158
 
        dw.dxfReal(10, data.x1);
3159
 
        dw.dxfReal(20, data.y1);
3160
 
        dw.dxfReal(11, data.x2);
3161
 
        dw.dxfReal(21, data.y2);
3162
 
        break;
3163
 
    case 2:
3164
 
        dw.dxfReal(10, data.cx);
3165
 
        dw.dxfReal(20, data.cy);
3166
 
        dw.dxfReal(40, data.radius);
3167
 
        dw.dxfReal(50, data.angle1/(2*M_PI)*360.0);
3168
 
        dw.dxfReal(51, data.angle2/(2*M_PI)*360.0);
3169
 
        dw.dxfInt(73, (int)(data.ccw));
3170
 
        break;
3171
 
    default:
3172
 
        break;
3173
 
    }
3174
 
}
3175
 
 
3176
 
 
3177
 
 
3178
 
/**
3179
 
 * Writes an image entity.
3180
 
 *
3181
 
 * @return IMAGEDEF handle. Needed for the IMAGEDEF counterpart.
3182
 
 */
3183
 
int DL_Dxf::writeImage(DL_WriterA& dw,
3184
 
                       const DL_ImageData& data,
3185
 
                       const DL_Attributes& attrib) {
3186
 
 
3187
 
    /*if (data.file.empty()) {
3188
 
        std::cerr << "DL_Dxf::writeImage: "
3189
 
        << "Image file must not be empty\n";
3190
 
        return;
3191
 
}*/
3192
 
 
3193
 
    dw.entity("IMAGE");
3194
 
 
3195
 
    dw.entityAttributes(attrib);
3196
 
    if (version==VER_2000) {
3197
 
        dw.dxfString(100, "AcDbEntity");
3198
 
        dw.dxfString(100, "AcDbRasterImage");
3199
 
        dw.dxfInt(90, 0);
3200
 
    }
3201
 
    // insertion point
3202
 
    dw.dxfReal(10, data.ipx);
3203
 
    dw.dxfReal(20, data.ipy);
3204
 
    dw.dxfReal(30, 0.0);
3205
 
 
3206
 
    // vector along bottom side (1 pixel long)
3207
 
    dw.dxfReal(11, data.ux);
3208
 
    dw.dxfReal(21, data.uy);
3209
 
    dw.dxfReal(31, 0.0);
3210
 
 
3211
 
    // vector along left side (1 pixel long)
3212
 
    dw.dxfReal(12, data.vx);
3213
 
    dw.dxfReal(22, data.vy);
3214
 
    dw.dxfReal(32, 0.0);
3215
 
 
3216
 
    // image size in pixel
3217
 
    dw.dxfReal(13, data.width);
3218
 
    dw.dxfReal(23, data.height);
3219
 
 
3220
 
    // handle of IMAGEDEF object
3221
 
    int handle = dw.incHandle();
3222
 
    dw.dxfHex(340, handle);
3223
 
 
3224
 
    // flags
3225
 
    dw.dxfInt(70, 15);
3226
 
 
3227
 
    // clipping:
3228
 
    dw.dxfInt(280, 0);
3229
 
 
3230
 
    // brightness, contrast, fade
3231
 
    dw.dxfInt(281, data.brightness);
3232
 
    dw.dxfInt(282, data.contrast);
3233
 
    dw.dxfInt(283, data.fade);
3234
 
 
3235
 
    return handle;
3236
 
}
3237
 
 
3238
 
 
3239
 
 
3240
 
/**
3241
 
 * Writes an image definiition entity.
3242
 
 */
3243
 
void DL_Dxf::writeImageDef(DL_WriterA& dw,
3244
 
                           int handle,
3245
 
                           const DL_ImageData& data) {
3246
 
 
3247
 
    /*if (data.file.empty()) {
3248
 
        std::cerr << "DL_Dxf::writeImage: "
3249
 
        << "Image file must not be empty\n";
3250
 
        return;
3251
 
}*/
3252
 
 
3253
 
    dw.dxfString(0, "IMAGEDEF");
3254
 
    if (version==VER_2000) {
3255
 
        dw.dxfHex(5, handle);
3256
 
        }
3257
 
 
3258
 
    if (version==VER_2000) {
3259
 
        dw.dxfString(100, "AcDbRasterImageDef");
3260
 
        dw.dxfInt(90, 0);
3261
 
    }
3262
 
    // file name:
3263
 
    dw.dxfString(1, data.ref);
3264
 
 
3265
 
    // image size in pixel
3266
 
    dw.dxfReal(10, data.width);
3267
 
    dw.dxfReal(20, data.height);
3268
 
 
3269
 
    dw.dxfReal(11, 1.0);
3270
 
    dw.dxfReal(21, 1.0);
3271
 
 
3272
 
    // loaded:
3273
 
    dw.dxfInt(280, 1);
3274
 
    // units:
3275
 
    dw.dxfInt(281, 0);
3276
 
}
3277
 
 
3278
 
 
3279
 
/**
3280
 
 * Writes a layer to the file. Layers are stored in the 
3281
 
 * tables section of a DXF file.
3282
 
 *
3283
 
 * @param dw DXF writer
3284
 
 * @param data Entity data from the file
3285
 
 * @param attrib Attributes
3286
 
 */
3287
 
void DL_Dxf::writeLayer(DL_WriterA& dw,
3288
 
                        const DL_LayerData& data,
3289
 
                        const DL_Attributes& attrib) {
3290
 
 
3291
 
    if (data.name.empty()) {
3292
 
        std::cerr << "DL_Dxf::writeLayer: "
3293
 
        << "Layer name must not be empty\n";
3294
 
        return;
3295
 
    }
3296
 
 
3297
 
    int color = attrib.getColor();
3298
 
    if (color>=256) {
3299
 
        std::cerr << "Layer color cannot be " << color << ". Changed to 7.\n";
3300
 
        color = 7;
3301
 
    }
3302
 
 
3303
 
    if (data.name == "0") {
3304
 
        dw.tableLayerEntry(0x10);
3305
 
    } else {
3306
 
        dw.tableLayerEntry();
3307
 
    }
3308
 
 
3309
 
    dw.dxfString(2, data.name);
3310
 
    dw.dxfInt(70, data.flags);
3311
 
    dw.dxfInt(62, color);
3312
 
 
3313
 
    dw.dxfString(6, (attrib.getLineType().length()==0 ?
3314
 
                     string("CONTINUOUS") : attrib.getLineType()));
3315
 
 
3316
 
    if (version>=VER_2000) {
3317
 
        // layer defpoints cannot be plotted
3318
 
        std::string lstr = data.name;
3319
 
        std::transform(lstr.begin(), lstr.end(), lstr.begin(), tolower);
3320
 
        if (lstr=="defpoints") {
3321
 
            dw.dxfInt(290, 0);
3322
 
        }
3323
 
    }
3324
 
    if (version>=VER_2000 && attrib.getWidth()!=-1) {
3325
 
        dw.dxfInt(370, attrib.getWidth());
3326
 
    }
3327
 
    if (version>=VER_2000) {
3328
 
        dw.dxfHex(390, 0xF);
3329
 
    }
3330
 
}
3331
 
 
3332
 
 
3333
 
 
3334
 
/**
3335
 
 * Writes a line type to the file. Line types are stored in the 
3336
 
 * tables section of a DXF file.
3337
 
 */
3338
 
void DL_Dxf::writeLineType(DL_WriterA& dw,
3339
 
                           const DL_LineTypeData& data) {
3340
 
    //const char* description,
3341
 
    //int elements,
3342
 
    //double patternLength) {
3343
 
 
3344
 
    if (data.name.empty()) {
3345
 
        std::cerr << "DL_Dxf::writeLineType: "
3346
 
        << "Line type name must not be empty\n";
3347
 
        return;
3348
 
    }
3349
 
 
3350
 
        // ignore BYLAYER, BYBLOCK for R12
3351
 
        if (version<VER_2000) {
3352
 
                if (!strcasecmp(data.name.c_str(), "BYBLOCK") ||
3353
 
                    !strcasecmp(data.name.c_str(), "BYLAYER")) {
3354
 
                        return;
3355
 
                }
3356
 
        }
3357
 
 
3358
 
        // write id (not for R12)
3359
 
    if (!strcasecmp(data.name.c_str(), "BYBLOCK")) {
3360
 
        dw.tableLineTypeEntry(0x14);
3361
 
    } else if (!strcasecmp(data.name.c_str(), "BYLAYER")) {
3362
 
        dw.tableLineTypeEntry(0x15);
3363
 
    } else if (!strcasecmp(data.name.c_str(), "CONTINUOUS")) {
3364
 
        dw.tableLineTypeEntry(0x16);
3365
 
    } else {
3366
 
        dw.tableLineTypeEntry();
3367
 
    }
3368
 
 
3369
 
    dw.dxfString(2, data.name);
3370
 
        //if (version>=VER_2000) {
3371
 
        dw.dxfInt(70, data.flags);
3372
 
        //}
3373
 
 
3374
 
    if (!strcasecmp(data.name.c_str(), "BYBLOCK")) {
3375
 
        dw.dxfString(3, "");
3376
 
        dw.dxfInt(72, 65);
3377
 
        dw.dxfInt(73, 0);
3378
 
        dw.dxfReal(40, 0.0);
3379
 
    } else if (!strcasecmp(data.name.c_str(), "BYLAYER")) {
3380
 
        dw.dxfString(3, "");
3381
 
        dw.dxfInt(72, 65);
3382
 
        dw.dxfInt(73, 0);
3383
 
        dw.dxfReal(40, 0.0);
3384
 
    } else if (!strcasecmp(data.name.c_str(), "CONTINUOUS")) {
3385
 
        dw.dxfString(3, "Solid line");
3386
 
        dw.dxfInt(72, 65);
3387
 
        dw.dxfInt(73, 0);
3388
 
        dw.dxfReal(40, 0.0);
3389
 
    } else if (!strcasecmp(data.name.c_str(), "ACAD_ISO02W100")) {
3390
 
        dw.dxfString(3, "ISO Dashed __ __ __ __ __ __ __ __ __ __ _");
3391
 
        dw.dxfInt(72, 65);
3392
 
        dw.dxfInt(73, 2);
3393
 
        dw.dxfReal(40, 15.0);
3394
 
        dw.dxfReal(49, 12.0);
3395
 
        if (version>=VER_R13)
3396
 
            dw.dxfInt(74, 0);
3397
 
        dw.dxfReal(49, -3.0);
3398
 
        if (version>=VER_R13)
3399
 
            dw.dxfInt(74, 0);
3400
 
    } else if (!strcasecmp(data.name.c_str(), "ACAD_ISO03W100")) {
3401
 
        dw.dxfString(3, "ISO Dashed with Distance __    __    __    _");
3402
 
        dw.dxfInt(72, 65);
3403
 
        dw.dxfInt(73, 2);
3404
 
        dw.dxfReal(40, 30.0);
3405
 
        dw.dxfReal(49, 12.0);
3406
 
        if (version>=VER_R13)
3407
 
            dw.dxfInt(74, 0);
3408
 
        dw.dxfReal(49, -18.0);
3409
 
        if (version>=VER_R13)
3410
 
            dw.dxfInt(74, 0);
3411
 
    } else if (!strcasecmp(data.name.c_str(), "ACAD_ISO04W100")) {
3412
 
        dw.dxfString(3, "ISO Long Dashed Dotted ____ . ____ . __");
3413
 
        dw.dxfInt(72, 65);
3414
 
        dw.dxfInt(73, 4);
3415
 
        dw.dxfReal(40, 30.0);
3416
 
        dw.dxfReal(49, 24.0);
3417
 
        if (version>=VER_R13)
3418
 
            dw.dxfInt(74, 0);
3419
 
        dw.dxfReal(49, -3.0);
3420
 
        if (version>=VER_R13)
3421
 
            dw.dxfInt(74, 0);
3422
 
        dw.dxfReal(49, 0.0);
3423
 
        if (version>=VER_R13)
3424
 
            dw.dxfInt(74, 0);
3425
 
        dw.dxfReal(49, -3.0);
3426
 
        if (version>=VER_R13)
3427
 
            dw.dxfInt(74, 0);
3428
 
    } else if (!strcasecmp(data.name.c_str(), "ACAD_ISO05W100")) {
3429
 
        dw.dxfString(3, "ISO Long Dashed Double Dotted ____ .. __");
3430
 
        dw.dxfInt(72, 65);
3431
 
        dw.dxfInt(73, 6);
3432
 
        dw.dxfReal(40, 33.0);
3433
 
        dw.dxfReal(49, 24.0);
3434
 
        if (version>=VER_R13)
3435
 
            dw.dxfInt(74, 0);
3436
 
        dw.dxfReal(49, -3.0);
3437
 
        if (version>=VER_R13)
3438
 
            dw.dxfInt(74, 0);
3439
 
        dw.dxfReal(49, 0.0);
3440
 
        if (version>=VER_R13)
3441
 
            dw.dxfInt(74, 0);
3442
 
        dw.dxfReal(49, -3.0);
3443
 
        if (version>=VER_R13)
3444
 
            dw.dxfInt(74, 0);
3445
 
        dw.dxfReal(49, 0.0);
3446
 
        if (version>=VER_R13)
3447
 
            dw.dxfInt(74, 0);
3448
 
        dw.dxfReal(49, -3.0);
3449
 
        if (version>=VER_R13)
3450
 
            dw.dxfInt(74, 0);
3451
 
    } else if (!strcasecmp(data.name.c_str(), "BORDER")) {
3452
 
        dw.dxfString(3, "Border __ __ . __ __ . __ __ . __ __ . __ __ .");
3453
 
        dw.dxfInt(72, 65);
3454
 
        dw.dxfInt(73, 6);
3455
 
        dw.dxfReal(40, 44.45);
3456
 
        dw.dxfReal(49, 12.7);
3457
 
        if (version>=VER_R13)
3458
 
            dw.dxfInt(74, 0);
3459
 
        dw.dxfReal(49, -6.35);
3460
 
        if (version>=VER_R13)
3461
 
            dw.dxfInt(74, 0);
3462
 
        dw.dxfReal(49, 12.7);
3463
 
        if (version>=VER_R13)
3464
 
            dw.dxfInt(74, 0);
3465
 
        dw.dxfReal(49, -6.35);
3466
 
        if (version>=VER_R13)
3467
 
            dw.dxfInt(74, 0);
3468
 
        dw.dxfReal(49, 0.0);
3469
 
        if (version>=VER_R13)
3470
 
            dw.dxfInt(74, 0);
3471
 
        dw.dxfReal(49, -6.35);
3472
 
        if (version>=VER_R13)
3473
 
            dw.dxfInt(74, 0);
3474
 
    } else if (!strcasecmp(data.name.c_str(), "BORDER2")) {
3475
 
        dw.dxfString(3, "Border (.5x) __.__.__.__.__.__.__.__.__.__.__.");
3476
 
        dw.dxfInt(72, 65);
3477
 
        dw.dxfInt(73, 6);
3478
 
        dw.dxfReal(40, 22.225);
3479
 
        dw.dxfReal(49, 6.35);
3480
 
        if (version>=VER_R13)
3481
 
            dw.dxfInt(74, 0);
3482
 
        dw.dxfReal(49, -3.175);
3483
 
        if (version>=VER_R13)
3484
 
            dw.dxfInt(74, 0);
3485
 
        dw.dxfReal(49, 6.35);
3486
 
        if (version>=VER_R13)
3487
 
            dw.dxfInt(74, 0);
3488
 
        dw.dxfReal(49, -3.175);
3489
 
        if (version>=VER_R13)
3490
 
            dw.dxfInt(74, 0);
3491
 
        dw.dxfReal(49, 0.0);
3492
 
        if (version>=VER_R13)
3493
 
            dw.dxfInt(74, 0);
3494
 
        dw.dxfReal(49, -3.175);
3495
 
        if (version>=VER_R13)
3496
 
            dw.dxfInt(74, 0);
3497
 
    } else if (!strcasecmp(data.name.c_str(), "BORDERX2")) {
3498
 
        dw.dxfString(3, "Border (2x) ____  ____  .  ____  ____  .  ___");
3499
 
        dw.dxfInt(72, 65);
3500
 
        dw.dxfInt(73, 6);
3501
 
        dw.dxfReal(40, 88.9);
3502
 
        dw.dxfReal(49, 25.4);
3503
 
        if (version>=VER_R13)
3504
 
            dw.dxfInt(74, 0);
3505
 
        dw.dxfReal(49, -12.7);
3506
 
        if (version>=VER_R13)
3507
 
            dw.dxfInt(74, 0);
3508
 
        dw.dxfReal(49, 25.4);
3509
 
        if (version>=VER_R13)
3510
 
            dw.dxfInt(74, 0);
3511
 
        dw.dxfReal(49, -12.7);
3512
 
        if (version>=VER_R13)
3513
 
            dw.dxfInt(74, 0);
3514
 
        dw.dxfReal(49, 0.0);
3515
 
        if (version>=VER_R13)
3516
 
            dw.dxfInt(74, 0);
3517
 
        dw.dxfReal(49, -12.7);
3518
 
        if (version>=VER_R13)
3519
 
            dw.dxfInt(74, 0);
3520
 
    } else if (!strcasecmp(data.name.c_str(), "CENTER")) {
3521
 
        dw.dxfString(3, "Center ____ _ ____ _ ____ _ ____ _ ____ _ ____");
3522
 
        dw.dxfInt(72, 65);
3523
 
        dw.dxfInt(73, 4);
3524
 
        dw.dxfReal(40, 50.8);
3525
 
        dw.dxfReal(49, 31.75);
3526
 
        if (version>=VER_R13)
3527
 
            dw.dxfInt(74, 0);
3528
 
        dw.dxfReal(49, -6.35);
3529
 
        if (version>=VER_R13)
3530
 
            dw.dxfInt(74, 0);
3531
 
        dw.dxfReal(49, 6.35);
3532
 
        if (version>=VER_R13)
3533
 
            dw.dxfInt(74, 0);
3534
 
        dw.dxfReal(49, -6.35);
3535
 
        if (version>=VER_R13)
3536
 
            dw.dxfInt(74, 0);
3537
 
    } else if (!strcasecmp(data.name.c_str(), "CENTER2")) {
3538
 
        dw.dxfString(3, "Center (.5x) ___ _ ___ _ ___ _ ___ _ ___ _ ___");
3539
 
        dw.dxfInt(72, 65);
3540
 
        dw.dxfInt(73, 4);
3541
 
        dw.dxfReal(40, 28.575);
3542
 
        dw.dxfReal(49, 19.05);
3543
 
        if (version>=VER_R13)
3544
 
            dw.dxfInt(74, 0);
3545
 
        dw.dxfReal(49, -3.175);
3546
 
        if (version>=VER_R13)
3547
 
            dw.dxfInt(74, 0);
3548
 
        dw.dxfReal(49, 3.175);
3549
 
        if (version>=VER_R13)
3550
 
            dw.dxfInt(74, 0);
3551
 
        dw.dxfReal(49, -3.175);
3552
 
        if (version>=VER_R13)
3553
 
            dw.dxfInt(74, 0);
3554
 
    } else if (!strcasecmp(data.name.c_str(), "CENTERX2")) {
3555
 
        dw.dxfString(3, "Center (2x) ________  __  ________  __  _____");
3556
 
        dw.dxfInt(72, 65);
3557
 
        dw.dxfInt(73, 4);
3558
 
        dw.dxfReal(40, 101.6);
3559
 
        dw.dxfReal(49, 63.5);
3560
 
        if (version>=VER_R13)
3561
 
            dw.dxfInt(74, 0);
3562
 
        dw.dxfReal(49, -12.7);
3563
 
        if (version>=VER_R13)
3564
 
            dw.dxfInt(74, 0);
3565
 
        dw.dxfReal(49, 12.7);
3566
 
        if (version>=VER_R13)
3567
 
            dw.dxfInt(74, 0);
3568
 
        dw.dxfReal(49, -12.7);
3569
 
        if (version>=VER_R13)
3570
 
            dw.dxfInt(74, 0);
3571
 
    } else if (!strcasecmp(data.name.c_str(), "DASHDOT")) {
3572
 
        dw.dxfString(3, "Dash dot __ . __ . __ . __ . __ . __ . __ . __");
3573
 
        dw.dxfInt(72, 65);
3574
 
        dw.dxfInt(73, 4);
3575
 
        dw.dxfReal(40, 25.4);
3576
 
        dw.dxfReal(49, 12.7);
3577
 
        if (version>=VER_R13)
3578
 
            dw.dxfInt(74, 0);
3579
 
        dw.dxfReal(49, -6.35);
3580
 
        if (version>=VER_R13)
3581
 
            dw.dxfInt(74, 0);
3582
 
        dw.dxfReal(49, 0.0);
3583
 
        if (version>=VER_R13)
3584
 
            dw.dxfInt(74, 0);
3585
 
        dw.dxfReal(49, -6.35);
3586
 
        if (version>=VER_R13)
3587
 
            dw.dxfInt(74, 0);
3588
 
    } else if (!strcasecmp(data.name.c_str(), "DASHDOT2")) {
3589
 
        dw.dxfString(3, "Dash dot (.5x) _._._._._._._._._._._._._._._.");
3590
 
        dw.dxfInt(72, 65);
3591
 
        dw.dxfInt(73, 4);
3592
 
        dw.dxfReal(40, 12.7);
3593
 
        dw.dxfReal(49, 6.35);
3594
 
        if (version>=VER_R13)
3595
 
            dw.dxfInt(74, 0);
3596
 
        dw.dxfReal(49, -3.175);
3597
 
        if (version>=VER_R13)
3598
 
            dw.dxfInt(74, 0);
3599
 
        dw.dxfReal(49, 0.0);
3600
 
        if (version>=VER_R13)
3601
 
            dw.dxfInt(74, 0);
3602
 
        dw.dxfReal(49, -3.175);
3603
 
        if (version>=VER_R13)
3604
 
            dw.dxfInt(74, 0);
3605
 
    } else if (!strcasecmp(data.name.c_str(), "DASHDOTX2")) {
3606
 
        dw.dxfString(3, "Dash dot (2x) ____  .  ____  .  ____  .  ___");
3607
 
        dw.dxfInt(72, 65);
3608
 
        dw.dxfInt(73, 4);
3609
 
        dw.dxfReal(40, 50.8);
3610
 
        dw.dxfReal(49, 25.4);
3611
 
        if (version>=VER_R13)
3612
 
            dw.dxfInt(74, 0);
3613
 
        dw.dxfReal(49, -12.7);
3614
 
        if (version>=VER_R13)
3615
 
            dw.dxfInt(74, 0);
3616
 
        dw.dxfReal(49, 0.0);
3617
 
        if (version>=VER_R13)
3618
 
            dw.dxfInt(74, 0);
3619
 
        dw.dxfReal(49, -12.7);
3620
 
        if (version>=VER_R13)
3621
 
            dw.dxfInt(74, 0);
3622
 
    } else if (!strcasecmp(data.name.c_str(), "DASHED")) {
3623
 
        dw.dxfString(3, "Dashed __ __ __ __ __ __ __ __ __ __ __ __ __ _");
3624
 
        dw.dxfInt(72, 65);
3625
 
        dw.dxfInt(73, 2);
3626
 
        dw.dxfReal(40, 19.05);
3627
 
        dw.dxfReal(49, 12.7);
3628
 
        if (version>=VER_R13)
3629
 
            dw.dxfInt(74, 0);
3630
 
        dw.dxfReal(49, -6.35);
3631
 
        if (version>=VER_R13)
3632
 
            dw.dxfInt(74, 0);
3633
 
    } else if (!strcasecmp(data.name.c_str(), "DASHED2")) {
3634
 
        dw.dxfString(3, "Dashed (.5x) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _");
3635
 
        dw.dxfInt(72, 65);
3636
 
        dw.dxfInt(73, 2);
3637
 
        dw.dxfReal(40, 9.525);
3638
 
        dw.dxfReal(49, 6.35);
3639
 
        if (version>=VER_R13)
3640
 
            dw.dxfInt(74, 0);
3641
 
        dw.dxfReal(49, -3.175);
3642
 
        if (version>=VER_R13)
3643
 
            dw.dxfInt(74, 0);
3644
 
    } else if (!strcasecmp(data.name.c_str(), "DASHEDX2")) {
3645
 
        dw.dxfString(3, "Dashed (2x) ____  ____  ____  ____  ____  ___");
3646
 
        dw.dxfInt(72, 65);
3647
 
        dw.dxfInt(73, 2);
3648
 
        dw.dxfReal(40, 38.1);
3649
 
        dw.dxfReal(49, 25.4);
3650
 
        if (version>=VER_R13)
3651
 
            dw.dxfInt(74, 0);
3652
 
        dw.dxfReal(49, -12.7);
3653
 
        if (version>=VER_R13)
3654
 
            dw.dxfInt(74, 0);
3655
 
    } else if (!strcasecmp(data.name.c_str(), "DIVIDE")) {
3656
 
        dw.dxfString(3, "Divide ____ . . ____ . . ____ . . ____ . . ____");
3657
 
        dw.dxfInt(72, 65);
3658
 
        dw.dxfInt(73, 6);
3659
 
        dw.dxfReal(40, 31.75);
3660
 
        dw.dxfReal(49, 12.7);
3661
 
        if (version>=VER_R13)
3662
 
            dw.dxfInt(74, 0);
3663
 
        dw.dxfReal(49, -6.35);
3664
 
        if (version>=VER_R13)
3665
 
            dw.dxfInt(74, 0);
3666
 
        dw.dxfReal(49, 0.0);
3667
 
        if (version>=VER_R13)
3668
 
            dw.dxfInt(74, 0);
3669
 
        dw.dxfReal(49, -6.35);
3670
 
        if (version>=VER_R13)
3671
 
            dw.dxfInt(74, 0);
3672
 
        dw.dxfReal(49, 0.0);
3673
 
        if (version>=VER_R13)
3674
 
            dw.dxfInt(74, 0);
3675
 
        dw.dxfReal(49, -6.35);
3676
 
        if (version>=VER_R13)
3677
 
            dw.dxfInt(74, 0);
3678
 
    } else if (!strcasecmp(data.name.c_str(), "DIVIDE2")) {
3679
 
        dw.dxfString(3, "Divide (.5x) __..__..__..__..__..__..__..__.._");
3680
 
        dw.dxfInt(72, 65);
3681
 
        dw.dxfInt(73, 6);
3682
 
        dw.dxfReal(40, 15.875);
3683
 
        dw.dxfReal(49, 6.35);
3684
 
        if (version>=VER_R13)
3685
 
            dw.dxfInt(74, 0);
3686
 
        dw.dxfReal(49, -3.175);
3687
 
        if (version>=VER_R13)
3688
 
            dw.dxfInt(74, 0);
3689
 
        dw.dxfReal(49, 0.0);
3690
 
        if (version>=VER_R13)
3691
 
            dw.dxfInt(74, 0);
3692
 
        dw.dxfReal(49, -3.175);
3693
 
        if (version>=VER_R13)
3694
 
            dw.dxfInt(74, 0);
3695
 
        dw.dxfReal(49, 0.0);
3696
 
        if (version>=VER_R13)
3697
 
            dw.dxfInt(74, 0);
3698
 
        dw.dxfReal(49, -3.175);
3699
 
        if (version>=VER_R13)
3700
 
            dw.dxfInt(74, 0);
3701
 
    } else if (!strcasecmp(data.name.c_str(), "DIVIDEX2")) {
3702
 
        dw.dxfString(3, "Divide (2x) ________  .  .  ________  .  .  _");
3703
 
        dw.dxfInt(72, 65);
3704
 
        dw.dxfInt(73, 6);
3705
 
        dw.dxfReal(40, 63.5);
3706
 
        dw.dxfReal(49, 25.4);
3707
 
        if (version>=VER_R13)
3708
 
            dw.dxfInt(74, 0);
3709
 
        dw.dxfReal(49, -12.7);
3710
 
        if (version>=VER_R13)
3711
 
            dw.dxfInt(74, 0);
3712
 
        dw.dxfReal(49, 0.0);
3713
 
        if (version>=VER_R13)
3714
 
            dw.dxfInt(74, 0);
3715
 
        dw.dxfReal(49, -12.7);
3716
 
        if (version>=VER_R13)
3717
 
            dw.dxfInt(74, 0);
3718
 
        dw.dxfReal(49, 0.0);
3719
 
        if (version>=VER_R13)
3720
 
            dw.dxfInt(74, 0);
3721
 
        dw.dxfReal(49, -12.7);
3722
 
        if (version>=VER_R13)
3723
 
            dw.dxfInt(74, 0);
3724
 
    } else if (!strcasecmp(data.name.c_str(), "DOT")) {
3725
 
        dw.dxfString(3, "Dot . . . . . . . . . . . . . . . . . . . . . .");
3726
 
        dw.dxfInt(72, 65);
3727
 
        dw.dxfInt(73, 2);
3728
 
        dw.dxfReal(40, 6.35);
3729
 
        dw.dxfReal(49, 0.0);
3730
 
        if (version>=VER_R13)
3731
 
            dw.dxfInt(74, 0);
3732
 
        dw.dxfReal(49, -6.35);
3733
 
        if (version>=VER_R13)
3734
 
            dw.dxfInt(74, 0);
3735
 
    } else if (!strcasecmp(data.name.c_str(), "DOT2")) {
3736
 
        dw.dxfString(3, "Dot (.5x) .....................................");
3737
 
        dw.dxfInt(72, 65);
3738
 
        dw.dxfInt(73, 2);
3739
 
        dw.dxfReal(40, 3.175);
3740
 
        dw.dxfReal(49, 0.0);
3741
 
        if (version>=VER_R13)
3742
 
            dw.dxfInt(74, 0);
3743
 
        dw.dxfReal(49, -3.175);
3744
 
        if (version>=VER_R13)
3745
 
            dw.dxfInt(74, 0);
3746
 
    } else if (!strcasecmp(data.name.c_str(), "DOTX2")) {
3747
 
        dw.dxfString(3, "Dot (2x) .  .  .  .  .  .  .  .  .  .  .  .  .");
3748
 
        dw.dxfInt(72, 65);
3749
 
        dw.dxfInt(73, 2);
3750
 
        dw.dxfReal(40, 12.7);
3751
 
        dw.dxfReal(49, 0.0);
3752
 
        if (version>=VER_R13)
3753
 
            dw.dxfInt(74, 0);
3754
 
        dw.dxfReal(49, -12.7);
3755
 
        if (version>=VER_R13)
3756
 
            dw.dxfInt(74, 0);
3757
 
    } else {
3758
 
        std::cerr << "dxflib warning: DL_Dxf::writeLineType: Unknown Line Type\n";
3759
 
    }
3760
 
}
3761
 
 
3762
 
 
3763
 
 
3764
 
/**
3765
 
 * Writes the APPID section to the DXF file.
3766
 
 *
3767
 
 * @param name Application name
3768
 
 */
3769
 
void DL_Dxf::writeAppid(DL_WriterA& dw, const string& name) {
3770
 
    if (name.empty()) {
3771
 
        std::cerr << "DL_Dxf::writeAppid: "
3772
 
        << "Application  name must not be empty\n";
3773
 
        return;
3774
 
    }
3775
 
 
3776
 
    if (!strcasecmp(name.c_str(), "ACAD")) {
3777
 
        dw.tableAppidEntry(0x12);
3778
 
    } else {
3779
 
        dw.tableAppidEntry();
3780
 
    }
3781
 
    dw.dxfString(2, name);
3782
 
    dw.dxfInt(70, 0);
3783
 
}
3784
 
 
3785
 
 
3786
 
 
3787
 
/**
3788
 
 * Writes a block's definition (no entities) to the DXF file.
3789
 
 */
3790
 
void DL_Dxf::writeBlock(DL_WriterA& dw, const DL_BlockData& data) {
3791
 
    if (data.name.empty()) {
3792
 
        std::cerr << "DL_Dxf::writeBlock: "
3793
 
        << "Block name must not be empty\n";
3794
 
        return;
3795
 
    }
3796
 
 
3797
 
    //bool paperSpace = !strcasecmp(name, "*paper_space");
3798
 
    //!strcasecmp(name, "*paper_space0");
3799
 
 
3800
 
    if (!strcasecmp(data.name.c_str(), "*paper_space")) {
3801
 
        dw.sectionBlockEntry(0x1C);
3802
 
    } else if (!strcasecmp(data.name.c_str(), "*model_space")) {
3803
 
        dw.sectionBlockEntry(0x20);
3804
 
    } else if (!strcasecmp(data.name.c_str(), "*paper_space0")) {
3805
 
        dw.sectionBlockEntry(0x24);
3806
 
    } else {
3807
 
        dw.sectionBlockEntry();
3808
 
    }
3809
 
    dw.dxfString(2, data.name);
3810
 
    dw.dxfInt(70, 0);
3811
 
    dw.coord(10, data.bpx, data.bpy);
3812
 
    dw.dxfString(3, data.name);
3813
 
    dw.dxfString(1, "");
3814
 
}
3815
 
 
3816
 
 
3817
 
 
3818
 
/**
3819
 
 * Writes a block end.
3820
 
 *
3821
 
 * @param name Block name
3822
 
 */
3823
 
void DL_Dxf::writeEndBlock(DL_WriterA& dw, const string& name) {
3824
 
    if (!strcasecmp(name.c_str(), "*paper_space")) {
3825
 
        dw.sectionBlockEntryEnd(0x1D);
3826
 
    } else if (!strcasecmp(name.c_str(), "*model_space")) {
3827
 
        dw.sectionBlockEntryEnd(0x21);
3828
 
    } else if (!strcasecmp(name.c_str(), "*paper_space0")) {
3829
 
        dw.sectionBlockEntryEnd(0x25);
3830
 
    } else {
3831
 
        dw.sectionBlockEntryEnd();
3832
 
    }
3833
 
}
3834
 
 
3835
 
 
3836
 
 
3837
 
/**
3838
 
 * Writes a viewport section. This section is needed in VER_R13.
3839
 
 * Note that this method currently only writes a faked VPORT section
3840
 
 * to make the file readable by Aut*cad.
3841
 
 */
3842
 
void DL_Dxf::writeVPort(DL_WriterA& dw) {
3843
 
    dw.dxfString(0, "TABLE");
3844
 
    dw.dxfString(2, "VPORT");
3845
 
    if (version==VER_2000) {
3846
 
        dw.dxfHex(5, 0x8);
3847
 
    }
3848
 
    //dw.dxfHex(330, 0);
3849
 
    if (version==VER_2000) {
3850
 
        dw.dxfString(100, "AcDbSymbolTable");
3851
 
    }
3852
 
    dw.dxfInt(70, 1);
3853
 
    dw.dxfString(0, "VPORT");
3854
 
    //dw.dxfHex(5, 0x2F);
3855
 
    if (version==VER_2000) {
3856
 
        dw.handle();
3857
 
    }
3858
 
    //dw.dxfHex(330, 8);
3859
 
    if (version==VER_2000) {
3860
 
        dw.dxfString(100, "AcDbSymbolTableRecord");
3861
 
        dw.dxfString(100, "AcDbViewportTableRecord");
3862
 
    }
3863
 
    dw.dxfString(  2, "*Active");
3864
 
    dw.dxfInt( 70, 0);
3865
 
    dw.dxfReal( 10, 0.0);
3866
 
    dw.dxfReal( 20, 0.0);
3867
 
    dw.dxfReal( 11, 1.0);
3868
 
    dw.dxfReal( 21, 1.0);
3869
 
    dw.dxfReal( 12, 286.3055555555555);
3870
 
    dw.dxfReal( 22, 148.5);
3871
 
    dw.dxfReal( 13, 0.0);
3872
 
    dw.dxfReal( 23, 0.0);
3873
 
    dw.dxfReal( 14, 10.0);
3874
 
    dw.dxfReal( 24, 10.0);
3875
 
    dw.dxfReal( 15, 10.0);
3876
 
    dw.dxfReal( 25, 10.0);
3877
 
    dw.dxfReal( 16, 0.0);
3878
 
    dw.dxfReal( 26, 0.0);
3879
 
    dw.dxfReal( 36, 1.0);
3880
 
    dw.dxfReal( 17, 0.0);
3881
 
    dw.dxfReal( 27, 0.0);
3882
 
    dw.dxfReal( 37, 0.0);
3883
 
    dw.dxfReal( 40, 297.0);
3884
 
    dw.dxfReal( 41, 1.92798353909465);
3885
 
    dw.dxfReal( 42, 50.0);
3886
 
    dw.dxfReal( 43, 0.0);
3887
 
    dw.dxfReal( 44, 0.0);
3888
 
    dw.dxfReal( 50, 0.0);
3889
 
    dw.dxfReal( 51, 0.0);
3890
 
    dw.dxfInt( 71, 0);
3891
 
    dw.dxfInt( 72, 100);
3892
 
    dw.dxfInt( 73, 1);
3893
 
    dw.dxfInt( 74, 3);
3894
 
    dw.dxfInt( 75, 1);
3895
 
    dw.dxfInt( 76, 1);
3896
 
    dw.dxfInt( 77, 0);
3897
 
    dw.dxfInt( 78, 0);
3898
 
 
3899
 
    if (version==VER_2000) {
3900
 
        dw.dxfInt(281, 0);
3901
 
        dw.dxfInt( 65, 1);
3902
 
        dw.dxfReal(110, 0.0);
3903
 
        dw.dxfReal(120, 0.0);
3904
 
        dw.dxfReal(130, 0.0);
3905
 
        dw.dxfReal(111, 1.0);
3906
 
        dw.dxfReal(121, 0.0);
3907
 
        dw.dxfReal(131, 0.0);
3908
 
        dw.dxfReal(112, 0.0);
3909
 
        dw.dxfReal(122, 1.0);
3910
 
        dw.dxfReal(132, 0.0);
3911
 
        dw.dxfInt( 79, 0);
3912
 
        dw.dxfReal(146, 0.0);
3913
 
    }
3914
 
    dw.dxfString(  0, "ENDTAB");
3915
 
}
3916
 
 
3917
 
 
3918
 
 
3919
 
/**
3920
 
 * Writes a style section. This section is needed in VER_R13.
3921
 
 * Note that this method currently only writes a faked STYLE section
3922
 
 * to make the file readable by Aut*cad.
3923
 
 */
3924
 
void DL_Dxf::writeStyle(DL_WriterA& dw) {
3925
 
    dw.dxfString(  0, "TABLE");
3926
 
    dw.dxfString(  2, "STYLE");
3927
 
    if (version==VER_2000) {
3928
 
        dw.dxfHex(5, 3);
3929
 
        }
3930
 
    //dw.dxfHex(330, 0);
3931
 
    if (version==VER_2000) {
3932
 
        dw.dxfString(100, "AcDbSymbolTable");
3933
 
    }
3934
 
    dw.dxfInt( 70, 1);
3935
 
    dw.dxfString(  0, "STYLE");
3936
 
    if (version==VER_2000) {
3937
 
        dw.dxfHex(5, 0x11);
3938
 
        }
3939
 
    //styleHandleStd = dw.handle();
3940
 
    //dw.dxfHex(330, 3);
3941
 
    if (version==VER_2000) {
3942
 
        dw.dxfString(100, "AcDbSymbolTableRecord");
3943
 
        dw.dxfString(100, "AcDbTextStyleTableRecord");
3944
 
    }
3945
 
    dw.dxfString(  2, "Standard");
3946
 
    dw.dxfInt( 70, 0);
3947
 
    dw.dxfReal( 40, 0.0);
3948
 
    dw.dxfReal( 41, 0.75);
3949
 
    dw.dxfReal( 50, 0.0);
3950
 
    dw.dxfInt( 71, 0);
3951
 
    dw.dxfReal( 42, 2.5);
3952
 
    dw.dxfString(  3, "txt");
3953
 
    dw.dxfString(  4, "");
3954
 
    dw.dxfString(  0, "ENDTAB");
3955
 
}
3956
 
 
3957
 
 
3958
 
 
3959
 
/**
3960
 
 * Writes a view section. This section is needed in VER_R13.
3961
 
 * Note that this method currently only writes a faked VIEW section
3962
 
 * to make the file readable by Aut*cad.
3963
 
 */
3964
 
void DL_Dxf::writeView(DL_WriterA& dw) {
3965
 
    dw.dxfString(  0, "TABLE");
3966
 
    dw.dxfString(  2, "VIEW");
3967
 
    if (version==VER_2000) {
3968
 
        dw.dxfHex(5, 6);
3969
 
        }
3970
 
    //dw.dxfHex(330, 0);
3971
 
    if (version==VER_2000) {
3972
 
        dw.dxfString(100, "AcDbSymbolTable");
3973
 
    }
3974
 
    dw.dxfInt( 70, 0);
3975
 
    dw.dxfString(  0, "ENDTAB");
3976
 
}
3977
 
 
3978
 
 
3979
 
 
3980
 
/**
3981
 
 * Writes a ucs section. This section is needed in VER_R13.
3982
 
 * Note that this method currently only writes a faked UCS section
3983
 
 * to make the file readable by Aut*cad.
3984
 
 */
3985
 
void DL_Dxf::writeUcs(DL_WriterA& dw) {
3986
 
    dw.dxfString(  0, "TABLE");
3987
 
    dw.dxfString(  2, "UCS");
3988
 
    if (version==VER_2000) {
3989
 
        dw.dxfHex(5, 7);
3990
 
        }
3991
 
    //dw.dxfHex(330, 0);
3992
 
    if (version==VER_2000) {
3993
 
        dw.dxfString(100, "AcDbSymbolTable");
3994
 
    }
3995
 
    dw.dxfInt( 70, 0);
3996
 
    dw.dxfString(  0, "ENDTAB");
3997
 
}
3998
 
 
3999
 
 
4000
 
 
4001
 
/**
4002
 
 * Writes a dimstyle section. This section is needed in VER_R13.
4003
 
 * Note that this method currently only writes a faked DIMSTYLE section
4004
 
 * to make the file readable by Aut*cad.
4005
 
 */
4006
 
void DL_Dxf::writeDimStyle(DL_WriterA& dw, 
4007
 
                                        double dimasz, double dimexe, double dimexo,
4008
 
                       double dimgap, double dimtxt) {
4009
 
 
4010
 
    dw.dxfString(  0, "TABLE");
4011
 
    dw.dxfString(  2, "DIMSTYLE");
4012
 
    if (version==VER_2000) {
4013
 
        dw.dxfHex(5, 0xA);
4014
 
        dw.dxfString(100, "AcDbSymbolTable");
4015
 
    }
4016
 
    dw.dxfInt( 70, 1);
4017
 
    if (version==VER_2000) {
4018
 
        dw.dxfString(100, "AcDbDimStyleTable");
4019
 
        dw.dxfInt( 71, 0);
4020
 
    }
4021
 
 
4022
 
 
4023
 
    dw.dxfString(  0, "DIMSTYLE");
4024
 
    if (version==VER_2000) {
4025
 
        dw.dxfHex(105, 0x27);
4026
 
    }
4027
 
    //dw.handle(105);
4028
 
    //dw.dxfHex(330, 0xA);
4029
 
    if (version==VER_2000) {
4030
 
        dw.dxfString(100, "AcDbSymbolTableRecord");
4031
 
        dw.dxfString(100, "AcDbDimStyleTableRecord");
4032
 
    }
4033
 
    dw.dxfString(  2, "Standard");
4034
 
    if (version==VER_R12) {
4035
 
        dw.dxfString(  3, "");
4036
 
        dw.dxfString(  4, "");
4037
 
        dw.dxfString(  5, "");
4038
 
        dw.dxfString(  6, "");
4039
 
        dw.dxfString(  7, "");
4040
 
        dw.dxfReal( 40, 1.0);
4041
 
    }
4042
 
 
4043
 
    dw.dxfReal( 41, dimasz);
4044
 
    dw.dxfReal( 42, dimexo);
4045
 
    dw.dxfReal( 43, 3.75);
4046
 
    dw.dxfReal( 44, dimexe);
4047
 
    if (version==VER_R12) {
4048
 
        dw.dxfReal( 45, 0.0);
4049
 
        dw.dxfReal( 46, 0.0);
4050
 
        dw.dxfReal( 47, 0.0);
4051
 
        dw.dxfReal( 48, 0.0);
4052
 
    }
4053
 
    dw.dxfInt( 70, 0);
4054
 
    if (version==VER_R12) {
4055
 
        dw.dxfInt( 71, 0);
4056
 
        dw.dxfInt( 72, 0);
4057
 
    }
4058
 
    dw.dxfInt( 73, 0);
4059
 
    dw.dxfInt( 74, 0);
4060
 
    if (version==VER_R12) {
4061
 
        dw.dxfInt( 75, 0);
4062
 
        dw.dxfInt( 76, 0);
4063
 
    }
4064
 
    dw.dxfInt( 77, 1);
4065
 
    dw.dxfInt( 78, 8);
4066
 
    dw.dxfReal(140, dimtxt);
4067
 
    dw.dxfReal(141, 2.5);
4068
 
    if (version==VER_R12) {
4069
 
        dw.dxfReal(142, 0.0);
4070
 
    }
4071
 
    dw.dxfReal(143, 0.03937007874016);
4072
 
    if (version==VER_R12) {
4073
 
        dw.dxfReal(144, 1.0);
4074
 
        dw.dxfReal(145, 0.0);
4075
 
        dw.dxfReal(146, 1.0);
4076
 
    }
4077
 
    dw.dxfReal(147, dimgap);
4078
 
    if (version==VER_R12) {
4079
 
        dw.dxfInt(170, 0);
4080
 
    }
4081
 
    dw.dxfInt(171, 3);
4082
 
    dw.dxfInt(172, 1);
4083
 
    if (version==VER_R12) {
4084
 
        dw.dxfInt(173, 0);
4085
 
        dw.dxfInt(174, 0);
4086
 
        dw.dxfInt(175, 0);
4087
 
        dw.dxfInt(176, 0);
4088
 
        dw.dxfInt(177, 0);
4089
 
        dw.dxfInt(178, 0);
4090
 
    }
4091
 
    if (version==VER_2000) {
4092
 
        dw.dxfInt(271, 2);
4093
 
        dw.dxfInt(272, 2);
4094
 
        dw.dxfInt(274, 3);
4095
 
        dw.dxfInt(278, 44);
4096
 
        dw.dxfInt(283, 0);
4097
 
        dw.dxfInt(284, 8);
4098
 
        //dw.dxfHex(340, styleHandleStd);
4099
 
        dw.dxfHex(340, 0x11);
4100
 
    }
4101
 
    // * /
4102
 
    dw.dxfString(  0, "ENDTAB");
4103
 
}
4104
 
 
4105
 
 
4106
 
 
4107
 
/**
4108
 
 * Writes a blockrecord section. This section is needed in VER_R13.
4109
 
 * Note that this method currently only writes a faked BLOCKRECORD section
4110
 
 * to make the file readable by Aut*cad.
4111
 
 */
4112
 
void DL_Dxf::writeBlockRecord(DL_WriterA& dw) {
4113
 
    dw.dxfString(  0, "TABLE");
4114
 
    dw.dxfString(  2, "BLOCK_RECORD");
4115
 
    if (version==VER_2000) {
4116
 
        dw.dxfHex(5, 1);
4117
 
        }
4118
 
    //dw.dxfHex(330, 0);
4119
 
    if (version==VER_2000) {
4120
 
        dw.dxfString(100, "AcDbSymbolTable");
4121
 
    }
4122
 
    dw.dxfInt( 70, 1);
4123
 
 
4124
 
    dw.dxfString(  0, "BLOCK_RECORD");
4125
 
    if (version==VER_2000) {
4126
 
        dw.dxfHex(5, 0x1F);
4127
 
        }
4128
 
    //int msh = dw.handle();
4129
 
    //dw.setModelSpaceHandle(msh);
4130
 
    //dw.dxfHex(330, 1);
4131
 
    if (version==VER_2000) {
4132
 
        dw.dxfString(100, "AcDbSymbolTableRecord");
4133
 
        dw.dxfString(100, "AcDbBlockTableRecord");
4134
 
    }
4135
 
    dw.dxfString(  2, "*Model_Space");
4136
 
    dw.dxfHex(340, 0x22);
4137
 
 
4138
 
    dw.dxfString(  0, "BLOCK_RECORD");
4139
 
    if (version==VER_2000) {
4140
 
        dw.dxfHex(5, 0x1B);
4141
 
        }
4142
 
    //int psh = dw.handle();
4143
 
    //dw.setPaperSpaceHandle(psh);
4144
 
    //dw.dxfHex(330, 1);
4145
 
    if (version==VER_2000) {
4146
 
        dw.dxfString(100, "AcDbSymbolTableRecord");
4147
 
        dw.dxfString(100, "AcDbBlockTableRecord");
4148
 
    }
4149
 
    dw.dxfString(  2, "*Paper_Space");
4150
 
    dw.dxfHex(340, 0x1E);
4151
 
 
4152
 
    dw.dxfString(  0, "BLOCK_RECORD");
4153
 
    if (version==VER_2000) {
4154
 
        dw.dxfHex(5, 0x23);
4155
 
        }
4156
 
    //int ps0h = dw.handle();
4157
 
    //dw.setPaperSpace0Handle(ps0h);
4158
 
    //dw.dxfHex(330, 1);
4159
 
    if (version==VER_2000) {
4160
 
        dw.dxfString(100, "AcDbSymbolTableRecord");
4161
 
        dw.dxfString(100, "AcDbBlockTableRecord");
4162
 
    }
4163
 
    dw.dxfString(  2, "*Paper_Space0");
4164
 
    dw.dxfHex(340, 0x26);
4165
 
 
4166
 
    //dw.dxfString(  0, "ENDTAB");
4167
 
}
4168
 
 
4169
 
 
4170
 
 
4171
 
/**
4172
 
 * Writes a single block record with the given name.
4173
 
 */
4174
 
void DL_Dxf::writeBlockRecord(DL_WriterA& dw, const string& name) {
4175
 
    dw.dxfString(  0, "BLOCK_RECORD");
4176
 
    if (version==VER_2000) {
4177
 
        dw.handle();
4178
 
        }
4179
 
    //dw->dxfHex(330, 1);
4180
 
    if (version==VER_2000) {
4181
 
        dw.dxfString(100, "AcDbSymbolTableRecord");
4182
 
        dw.dxfString(100, "AcDbBlockTableRecord");
4183
 
    }
4184
 
    dw.dxfString(  2, name);
4185
 
    dw.dxfHex(340, 0);
4186
 
}
4187
 
 
4188
 
 
4189
 
 
4190
 
/**
4191
 
 * Writes a objects section. This section is needed in VER_R13.
4192
 
 * Note that this method currently only writes a faked OBJECTS section
4193
 
 * to make the file readable by Aut*cad.
4194
 
 */
4195
 
void DL_Dxf::writeObjects(DL_WriterA& dw) {
4196
 
    //int dicId, dicId2, dicId3, dicId4, dicId5;
4197
 
    //int dicId5;
4198
 
 
4199
 
    dw.dxfString(  0, "SECTION");
4200
 
    dw.dxfString(  2, "OBJECTS");
4201
 
    dw.dxfString(  0, "DICTIONARY");
4202
 
    dw.dxfHex(5, 0xC);                            // C
4203
 
    //dw.dxfHex(330, 0);
4204
 
    dw.dxfString(100, "AcDbDictionary");
4205
 
    dw.dxfInt(280, 0);
4206
 
    dw.dxfInt(281, 1);
4207
 
    dw.dxfString(  3, "ACAD_GROUP");
4208
 
    //dw.dxfHex(350, dw.getNextHandle());          // D
4209
 
    dw.dxfHex(350, 0xD);          // D
4210
 
    dw.dxfString(  3, "ACAD_LAYOUT");
4211
 
    dw.dxfHex(350, 0x1A);
4212
 
    //dw.dxfHex(350, dw.getNextHandle()+0);        // 1A
4213
 
    dw.dxfString(  3, "ACAD_MLINESTYLE");
4214
 
    dw.dxfHex(350, 0x17);
4215
 
    //dw.dxfHex(350, dw.getNextHandle()+1);        // 17
4216
 
    dw.dxfString(  3, "ACAD_PLOTSETTINGS");
4217
 
    dw.dxfHex(350, 0x19);
4218
 
    //dw.dxfHex(350, dw.getNextHandle()+2);        // 19
4219
 
    dw.dxfString(  3, "ACAD_PLOTSTYLENAME");
4220
 
    dw.dxfHex(350, 0xE);
4221
 
    //dw.dxfHex(350, dw.getNextHandle()+3);        // E
4222
 
    dw.dxfString(  3, "AcDbVariableDictionary");
4223
 
    dw.dxfHex(350, dw.getNextHandle());        // 2C
4224
 
    dw.dxfString(  0, "DICTIONARY");
4225
 
    dw.dxfHex(5, 0xD);
4226
 
    //dw.handle();                                    // D
4227
 
    //dw.dxfHex(330, 0xC);
4228
 
    dw.dxfString(100, "AcDbDictionary");
4229
 
    dw.dxfInt(280, 0);
4230
 
    dw.dxfInt(281, 1);
4231
 
    dw.dxfString(  0, "ACDBDICTIONARYWDFLT");
4232
 
    dw.dxfHex(5, 0xE);
4233
 
    //dicId4 = dw.handle();                           // E
4234
 
    //dw.dxfHex(330, 0xC);                       // C
4235
 
    dw.dxfString(100, "AcDbDictionary");
4236
 
    dw.dxfInt(281, 1);
4237
 
    dw.dxfString(  3, "Normal");
4238
 
    dw.dxfHex(350, 0xF);
4239
 
    //dw.dxfHex(350, dw.getNextHandle()+5);        // F
4240
 
    dw.dxfString(100, "AcDbDictionaryWithDefault");
4241
 
    dw.dxfHex(340, 0xF);
4242
 
    //dw.dxfHex(340, dw.getNextHandle()+5);        // F
4243
 
    dw.dxfString(  0, "ACDBPLACEHOLDER");
4244
 
    dw.dxfHex(5, 0xF);
4245
 
    //dw.handle();                                    // F
4246
 
    //dw.dxfHex(330, dicId4);                      // E
4247
 
    dw.dxfString(  0, "DICTIONARY");
4248
 
    //dicId3 = dw.handle();                           // 17
4249
 
    dw.dxfHex(5, 0x17);
4250
 
    //dw.dxfHex(330, 0xC);                       // C
4251
 
    dw.dxfString(100, "AcDbDictionary");
4252
 
    dw.dxfInt(280, 0);
4253
 
    dw.dxfInt(281, 1);
4254
 
    dw.dxfString(  3, "Standard");
4255
 
    dw.dxfHex(350, 0x18);
4256
 
    //dw.dxfHex(350, dw.getNextHandle()+5);        // 18
4257
 
    dw.dxfString(  0, "MLINESTYLE");
4258
 
    dw.dxfHex(5, 0x18);
4259
 
    //dw.handle();                                    // 18
4260
 
    //dw.dxfHex(330, dicId3);                      // 17
4261
 
    dw.dxfString(100, "AcDbMlineStyle");
4262
 
    dw.dxfString(  2, "STANDARD");
4263
 
    dw.dxfInt( 70, 0);
4264
 
    dw.dxfString(  3, "");
4265
 
    dw.dxfInt( 62, 256);
4266
 
    dw.dxfReal( 51, 90.0);
4267
 
    dw.dxfReal( 52, 90.0);
4268
 
    dw.dxfInt( 71, 2);
4269
 
    dw.dxfReal( 49, 0.5);
4270
 
    dw.dxfInt( 62, 256);
4271
 
    dw.dxfString(  6, "BYLAYER");
4272
 
    dw.dxfReal( 49, -0.5);
4273
 
    dw.dxfInt( 62, 256);
4274
 
    dw.dxfString(  6, "BYLAYER");
4275
 
    dw.dxfString(  0, "DICTIONARY");
4276
 
    dw.dxfHex(5, 0x19);
4277
 
    //dw.handle();                           // 17
4278
 
    //dw.dxfHex(330, 0xC);                       // C
4279
 
    dw.dxfString(100, "AcDbDictionary");
4280
 
    dw.dxfInt(280, 0);
4281
 
    dw.dxfInt(281, 1);
4282
 
    dw.dxfString(  0, "DICTIONARY");
4283
 
    //dicId2 = dw.handle();                           // 1A
4284
 
    dw.dxfHex(5, 0x1A);
4285
 
    //dw.dxfHex(330, 0xC);
4286
 
    dw.dxfString(100, "AcDbDictionary");
4287
 
    dw.dxfInt(281, 1);
4288
 
    dw.dxfString(  3, "Layout1");
4289
 
    dw.dxfHex(350, 0x1E);
4290
 
    //dw.dxfHex(350, dw.getNextHandle()+2);        // 1E
4291
 
    dw.dxfString(  3, "Layout2");
4292
 
    dw.dxfHex(350, 0x26);
4293
 
    //dw.dxfHex(350, dw.getNextHandle()+4);        // 26
4294
 
    dw.dxfString(  3, "Model");
4295
 
    dw.dxfHex(350, 0x22);
4296
 
    //dw.dxfHex(350, dw.getNextHandle()+5);        // 22
4297
 
 
4298
 
    dw.dxfString(  0, "LAYOUT");
4299
 
    dw.dxfHex(5, 0x1E);
4300
 
    //dw.handle();                                    // 1E
4301
 
    //dw.dxfHex(330, dicId2);                      // 1A
4302
 
    dw.dxfString(100, "AcDbPlotSettings");
4303
 
    dw.dxfString(  1, "");
4304
 
    dw.dxfString(  2, "C:\\Program Files\\AutoCAD 2002\\plotters\\DWF ePlot (optimized for plotting).pc3");
4305
 
    dw.dxfString(  4, "");
4306
 
    dw.dxfString(  6, "");
4307
 
    dw.dxfReal( 40, 0.0);
4308
 
    dw.dxfReal( 41, 0.0);
4309
 
    dw.dxfReal( 42, 0.0);
4310
 
    dw.dxfReal( 43, 0.0);
4311
 
    dw.dxfReal( 44, 0.0);
4312
 
    dw.dxfReal( 45, 0.0);
4313
 
    dw.dxfReal( 46, 0.0);
4314
 
    dw.dxfReal( 47, 0.0);
4315
 
    dw.dxfReal( 48, 0.0);
4316
 
    dw.dxfReal( 49, 0.0);
4317
 
    dw.dxfReal(140, 0.0);
4318
 
    dw.dxfReal(141, 0.0);
4319
 
    dw.dxfReal(142, 1.0);
4320
 
    dw.dxfReal(143, 1.0);
4321
 
    dw.dxfInt( 70, 688);
4322
 
    dw.dxfInt( 72, 0);
4323
 
    dw.dxfInt( 73, 0);
4324
 
    dw.dxfInt( 74, 5);
4325
 
    dw.dxfString(  7, "");
4326
 
    dw.dxfInt( 75, 16);
4327
 
    dw.dxfReal(147, 1.0);
4328
 
    dw.dxfReal(148, 0.0);
4329
 
    dw.dxfReal(149, 0.0);
4330
 
    dw.dxfString(100, "AcDbLayout");
4331
 
    dw.dxfString(  1, "Layout1");
4332
 
    dw.dxfInt( 70, 1);
4333
 
    dw.dxfInt( 71, 1);
4334
 
    dw.dxfReal( 10, 0.0);
4335
 
    dw.dxfReal( 20, 0.0);
4336
 
    dw.dxfReal( 11, 420.0);
4337
 
    dw.dxfReal( 21, 297.0);
4338
 
    dw.dxfReal( 12, 0.0);
4339
 
    dw.dxfReal( 22, 0.0);
4340
 
    dw.dxfReal( 32, 0.0);
4341
 
    dw.dxfReal( 14, 1.000000000000000E+20);
4342
 
    dw.dxfReal( 24, 1.000000000000000E+20);
4343
 
    dw.dxfReal( 34, 1.000000000000000E+20);
4344
 
    dw.dxfReal( 15, -1.000000000000000E+20);
4345
 
    dw.dxfReal( 25, -1.000000000000000E+20);
4346
 
    dw.dxfReal( 35, -1.000000000000000E+20);
4347
 
    dw.dxfReal(146, 0.0);
4348
 
    dw.dxfReal( 13, 0.0);
4349
 
    dw.dxfReal( 23, 0.0);
4350
 
    dw.dxfReal( 33, 0.0);
4351
 
    dw.dxfReal( 16, 1.0);
4352
 
    dw.dxfReal( 26, 0.0);
4353
 
    dw.dxfReal( 36, 0.0);
4354
 
    dw.dxfReal( 17, 0.0);
4355
 
    dw.dxfReal( 27, 1.0);
4356
 
    dw.dxfReal( 37, 0.0);
4357
 
    dw.dxfInt( 76, 0);
4358
 
    //dw.dxfHex(330, dw.getPaperSpaceHandle());    // 1B
4359
 
    dw.dxfHex(330, 0x1B);
4360
 
    dw.dxfString(  0, "LAYOUT");
4361
 
    dw.dxfHex(5, 0x22);
4362
 
    //dw.handle();                                    // 22
4363
 
    //dw.dxfHex(330, dicId2);                      // 1A
4364
 
    dw.dxfString(100, "AcDbPlotSettings");
4365
 
    dw.dxfString(  1, "");
4366
 
    dw.dxfString(  2, "C:\\Program Files\\AutoCAD 2002\\plotters\\DWF ePlot (optimized for plotting).pc3");
4367
 
    dw.dxfString(  4, "");
4368
 
    dw.dxfString(  6, "");
4369
 
    dw.dxfReal( 40, 0.0);
4370
 
    dw.dxfReal( 41, 0.0);
4371
 
    dw.dxfReal( 42, 0.0);
4372
 
    dw.dxfReal( 43, 0.0);
4373
 
    dw.dxfReal( 44, 0.0);
4374
 
    dw.dxfReal( 45, 0.0);
4375
 
    dw.dxfReal( 46, 0.0);
4376
 
    dw.dxfReal( 47, 0.0);
4377
 
    dw.dxfReal( 48, 0.0);
4378
 
    dw.dxfReal( 49, 0.0);
4379
 
    dw.dxfReal(140, 0.0);
4380
 
    dw.dxfReal(141, 0.0);
4381
 
    dw.dxfReal(142, 1.0);
4382
 
    dw.dxfReal(143, 1.0);
4383
 
    dw.dxfInt( 70, 1712);
4384
 
    dw.dxfInt( 72, 0);
4385
 
    dw.dxfInt( 73, 0);
4386
 
    dw.dxfInt( 74, 0);
4387
 
    dw.dxfString(  7, "");
4388
 
    dw.dxfInt( 75, 0);
4389
 
    dw.dxfReal(147, 1.0);
4390
 
    dw.dxfReal(148, 0.0);
4391
 
    dw.dxfReal(149, 0.0);
4392
 
    dw.dxfString(100, "AcDbLayout");
4393
 
    dw.dxfString(  1, "Model");
4394
 
    dw.dxfInt( 70, 1);
4395
 
    dw.dxfInt( 71, 0);
4396
 
    dw.dxfReal( 10, 0.0);
4397
 
    dw.dxfReal( 20, 0.0);
4398
 
    dw.dxfReal( 11, 12.0);
4399
 
    dw.dxfReal( 21, 9.0);
4400
 
    dw.dxfReal( 12, 0.0);
4401
 
    dw.dxfReal( 22, 0.0);
4402
 
    dw.dxfReal( 32, 0.0);
4403
 
    dw.dxfReal( 14, 0.0);
4404
 
    dw.dxfReal( 24, 0.0);
4405
 
    dw.dxfReal( 34, 0.0);
4406
 
    dw.dxfReal( 15, 0.0);
4407
 
    dw.dxfReal( 25, 0.0);
4408
 
    dw.dxfReal( 35, 0.0);
4409
 
    dw.dxfReal(146, 0.0);
4410
 
    dw.dxfReal( 13, 0.0);
4411
 
    dw.dxfReal( 23, 0.0);
4412
 
    dw.dxfReal( 33, 0.0);
4413
 
    dw.dxfReal( 16, 1.0);
4414
 
    dw.dxfReal( 26, 0.0);
4415
 
    dw.dxfReal( 36, 0.0);
4416
 
    dw.dxfReal( 17, 0.0);
4417
 
    dw.dxfReal( 27, 1.0);
4418
 
    dw.dxfReal( 37, 0.0);
4419
 
    dw.dxfInt( 76, 0);
4420
 
    //dw.dxfHex(330, dw.getModelSpaceHandle());    // 1F
4421
 
    dw.dxfHex(330, 0x1F);
4422
 
    dw.dxfString(  0, "LAYOUT");
4423
 
    //dw.handle();                                    // 26
4424
 
    dw.dxfHex(5, 0x26);
4425
 
    //dw.dxfHex(330, dicId2);                      // 1A
4426
 
    dw.dxfString(100, "AcDbPlotSettings");
4427
 
    dw.dxfString(  1, "");
4428
 
    dw.dxfString(  2, "C:\\Program Files\\AutoCAD 2002\\plotters\\DWF ePlot (optimized for plotting).pc3");
4429
 
    dw.dxfString(  4, "");
4430
 
    dw.dxfString(  6, "");
4431
 
    dw.dxfReal( 40, 0.0);
4432
 
    dw.dxfReal( 41, 0.0);
4433
 
    dw.dxfReal( 42, 0.0);
4434
 
    dw.dxfReal( 43, 0.0);
4435
 
    dw.dxfReal( 44, 0.0);
4436
 
    dw.dxfReal( 45, 0.0);
4437
 
    dw.dxfReal( 46, 0.0);
4438
 
    dw.dxfReal( 47, 0.0);
4439
 
    dw.dxfReal( 48, 0.0);
4440
 
    dw.dxfReal( 49, 0.0);
4441
 
    dw.dxfReal(140, 0.0);
4442
 
    dw.dxfReal(141, 0.0);
4443
 
    dw.dxfReal(142, 1.0);
4444
 
    dw.dxfReal(143, 1.0);
4445
 
    dw.dxfInt( 70, 688);
4446
 
    dw.dxfInt( 72, 0);
4447
 
    dw.dxfInt( 73, 0);
4448
 
    dw.dxfInt( 74, 5);
4449
 
    dw.dxfString(  7, "");
4450
 
    dw.dxfInt( 75, 16);
4451
 
    dw.dxfReal(147, 1.0);
4452
 
    dw.dxfReal(148, 0.0);
4453
 
    dw.dxfReal(149, 0.0);
4454
 
    dw.dxfString(100, "AcDbLayout");
4455
 
    dw.dxfString(  1, "Layout2");
4456
 
    dw.dxfInt( 70, 1);
4457
 
    dw.dxfInt( 71, 2);
4458
 
    dw.dxfReal( 10, 0.0);
4459
 
    dw.dxfReal( 20, 0.0);
4460
 
    dw.dxfReal( 11, 12.0);
4461
 
    dw.dxfReal( 21, 9.0);
4462
 
    dw.dxfReal( 12, 0.0);
4463
 
    dw.dxfReal( 22, 0.0);
4464
 
    dw.dxfReal( 32, 0.0);
4465
 
    dw.dxfReal( 14, 0.0);
4466
 
    dw.dxfReal( 24, 0.0);
4467
 
    dw.dxfReal( 34, 0.0);
4468
 
    dw.dxfReal( 15, 0.0);
4469
 
    dw.dxfReal( 25, 0.0);
4470
 
    dw.dxfReal( 35, 0.0);
4471
 
    dw.dxfReal(146, 0.0);
4472
 
    dw.dxfReal( 13, 0.0);
4473
 
    dw.dxfReal( 23, 0.0);
4474
 
    dw.dxfReal( 33, 0.0);
4475
 
    dw.dxfReal( 16, 1.0);
4476
 
    dw.dxfReal( 26, 0.0);
4477
 
    dw.dxfReal( 36, 0.0);
4478
 
    dw.dxfReal( 17, 0.0);
4479
 
    dw.dxfReal( 27, 1.0);
4480
 
    dw.dxfReal( 37, 0.0);
4481
 
    dw.dxfInt( 76, 0);
4482
 
    //dw.dxfHex(330, dw.getPaperSpace0Handle());   // 23
4483
 
    dw.dxfHex(330, 0x23);
4484
 
    dw.dxfString(  0, "DICTIONARY");
4485
 
    //dw.dxfHex(5, 0x2C);
4486
 
    //dicId5 =
4487
 
    dw.handle();                           // 2C
4488
 
    //dw.dxfHex(330, 0xC);                       // C
4489
 
    dw.dxfString(100, "AcDbDictionary");
4490
 
    dw.dxfInt(281, 1);
4491
 
    dw.dxfString(  3, "DIMASSOC");
4492
 
    //dw.dxfHex(350, 0x2F);
4493
 
    dw.dxfHex(350, dw.getNextHandle()+1);        // 2E
4494
 
    dw.dxfString(  3, "HIDETEXT");
4495
 
    //dw.dxfHex(350, 0x2E);
4496
 
    dw.dxfHex(350, dw.getNextHandle());        // 2D
4497
 
    dw.dxfString(  0, "DICTIONARYVAR");
4498
 
    //dw.dxfHex(5, 0x2E);
4499
 
    dw.handle();                                    // 2E
4500
 
    //dw.dxfHex(330, dicId5);                      // 2C
4501
 
    dw.dxfString(100, "DictionaryVariables");
4502
 
    dw.dxfInt(280, 0);
4503
 
    dw.dxfInt(  1, 2);
4504
 
    dw.dxfString(  0, "DICTIONARYVAR");
4505
 
    //dw.dxfHex(5, 0x2D);
4506
 
    dw.handle();                                    // 2D
4507
 
    //dw.dxfHex(330, dicId5);                      // 2C
4508
 
    dw.dxfString(100, "DictionaryVariables");
4509
 
    dw.dxfInt(280, 0);
4510
 
    dw.dxfInt(  1, 1);
4511
 
}
4512
 
 
4513
 
 
4514
 
/**
4515
 
 * Writes the end of the objects section. This section is needed in VER_R13.
4516
 
 * Note that this method currently only writes a faked OBJECTS section
4517
 
 * to make the file readable by Aut*cad.
4518
 
 */
4519
 
void DL_Dxf::writeObjectsEnd(DL_WriterA& dw) {
4520
 
    dw.dxfString(  0, "ENDSEC");
4521
 
}
4522
 
 
4523
 
    
4524
 
 
4525
 
/**
4526
 
 * Writes a comment to the DXF file.
4527
 
 */
4528
 
void DL_Dxf::writeComment(DL_WriterA& dw, const string& comment) {
4529
 
    dw.dxfString(999, comment);
4530
 
}
4531
 
 
4532
 
 
4533
 
/**
4534
 
 * Checks if the given variable is known by the given DXF version.
4535
 
 */
4536
 
bool DL_Dxf::checkVariable(const char* var, DL_Codes::version version) {
4537
 
    if (version>=VER_2000) {
4538
 
        return true;
4539
 
    } else if (version==VER_R12) {
4540
 
        // these are all the variables recognized by dxf r12:
4541
 
        if (!strcmp(var, "$ACADVER")) {
4542
 
            return true;
4543
 
        }
4544
 
        if (!strcmp(var, "$ACADVER")) {
4545
 
            return true;
4546
 
        }
4547
 
        if (!strcmp(var, "$ANGBASE")) {
4548
 
            return true;
4549
 
        }
4550
 
        if (!strcmp(var, "$ANGDIR")) {
4551
 
            return true;
4552
 
        }
4553
 
        if (!strcmp(var, "$ATTDIA")) {
4554
 
            return true;
4555
 
        }
4556
 
        if (!strcmp(var, "$ATTMODE")) {
4557
 
            return true;
4558
 
        }
4559
 
        if (!strcmp(var, "$ATTREQ")) {
4560
 
            return true;
4561
 
        }
4562
 
        if (!strcmp(var, "$AUNITS")) {
4563
 
            return true;
4564
 
        }
4565
 
        if (!strcmp(var, "$AUPREC")) {
4566
 
            return true;
4567
 
        }
4568
 
        if (!strcmp(var, "$AXISMODE")) {
4569
 
            return true;
4570
 
        }
4571
 
        if (!strcmp(var, "$AXISUNIT")) {
4572
 
            return true;
4573
 
        }
4574
 
        if (!strcmp(var, "$BLIPMODE")) {
4575
 
            return true;
4576
 
        }
4577
 
        if (!strcmp(var, "$CECOLOR")) {
4578
 
            return true;
4579
 
        }
4580
 
        if (!strcmp(var, "$CELTYPE")) {
4581
 
            return true;
4582
 
        }
4583
 
        if (!strcmp(var, "$CHAMFERA")) {
4584
 
            return true;
4585
 
        }
4586
 
        if (!strcmp(var, "$CHAMFERB")) {
4587
 
            return true;
4588
 
        }
4589
 
        if (!strcmp(var, "$CLAYER")) {
4590
 
            return true;
4591
 
        }
4592
 
        if (!strcmp(var, "$COORDS")) {
4593
 
            return true;
4594
 
        }
4595
 
        if (!strcmp(var, "$DIMALT")) {
4596
 
            return true;
4597
 
        }
4598
 
        if (!strcmp(var, "$DIMALTD")) {
4599
 
            return true;
4600
 
        }
4601
 
        if (!strcmp(var, "$DIMALTF")) {
4602
 
            return true;
4603
 
        }
4604
 
        if (!strcmp(var, "$DIMAPOST")) {
4605
 
            return true;
4606
 
        }
4607
 
        if (!strcmp(var, "$DIMASO")) {
4608
 
            return true;
4609
 
        }
4610
 
        if (!strcmp(var, "$DIMASZ")) {
4611
 
            return true;
4612
 
        }
4613
 
        if (!strcmp(var, "$DIMBLK")) {
4614
 
            return true;
4615
 
        }
4616
 
        if (!strcmp(var, "$DIMBLK1")) {
4617
 
            return true;
4618
 
        }
4619
 
        if (!strcmp(var, "$DIMBLK2")) {
4620
 
            return true;
4621
 
        }
4622
 
        if (!strcmp(var, "$DIMCEN")) {
4623
 
            return true;
4624
 
        }
4625
 
        if (!strcmp(var, "$DIMCLRD")) {
4626
 
            return true;
4627
 
        }
4628
 
        if (!strcmp(var, "$DIMCLRE")) {
4629
 
            return true;
4630
 
        }
4631
 
        if (!strcmp(var, "$DIMCLRT")) {
4632
 
            return true;
4633
 
        }
4634
 
        if (!strcmp(var, "$DIMDLE")) {
4635
 
            return true;
4636
 
        }
4637
 
        if (!strcmp(var, "$DIMDLI")) {
4638
 
            return true;
4639
 
        }
4640
 
        if (!strcmp(var, "$DIMEXE")) {
4641
 
            return true;
4642
 
        }
4643
 
        if (!strcmp(var, "$DIMEXO")) {
4644
 
            return true;
4645
 
        }
4646
 
        if (!strcmp(var, "$DIMGAP")) {
4647
 
            return true;
4648
 
        }
4649
 
        if (!strcmp(var, "$DIMLFAC")) {
4650
 
            return true;
4651
 
        }
4652
 
        if (!strcmp(var, "$DIMLIM")) {
4653
 
            return true;
4654
 
        }
4655
 
        if (!strcmp(var, "$DIMPOST")) {
4656
 
            return true;
4657
 
        }
4658
 
        if (!strcmp(var, "$DIMRND")) {
4659
 
            return true;
4660
 
        }
4661
 
        if (!strcmp(var, "$DIMSAH")) {
4662
 
            return true;
4663
 
        }
4664
 
        if (!strcmp(var, "$DIMSCALE")) {
4665
 
            return true;
4666
 
        }
4667
 
        if (!strcmp(var, "$DIMSE1")) {
4668
 
            return true;
4669
 
        }
4670
 
        if (!strcmp(var, "$DIMSE2")) {
4671
 
            return true;
4672
 
        }
4673
 
        if (!strcmp(var, "$DIMSHO")) {
4674
 
            return true;
4675
 
        }
4676
 
        if (!strcmp(var, "$DIMSOXD")) {
4677
 
            return true;
4678
 
        }
4679
 
        if (!strcmp(var, "$DIMSTYLE")) {
4680
 
            return true;
4681
 
        }
4682
 
        if (!strcmp(var, "$DIMTAD")) {
4683
 
            return true;
4684
 
        }
4685
 
        if (!strcmp(var, "$DIMTFAC")) {
4686
 
            return true;
4687
 
        }
4688
 
        if (!strcmp(var, "$DIMTIH")) {
4689
 
            return true;
4690
 
        }
4691
 
        if (!strcmp(var, "$DIMTIX")) {
4692
 
            return true;
4693
 
        }
4694
 
        if (!strcmp(var, "$DIMTM")) {
4695
 
            return true;
4696
 
        }
4697
 
        if (!strcmp(var, "$DIMTOFL")) {
4698
 
            return true;
4699
 
        }
4700
 
        if (!strcmp(var, "$DIMTOH")) {
4701
 
            return true;
4702
 
        }
4703
 
        if (!strcmp(var, "$DIMTOL")) {
4704
 
            return true;
4705
 
        }
4706
 
        if (!strcmp(var, "$DIMTP")) {
4707
 
            return true;
4708
 
        }
4709
 
        if (!strcmp(var, "$DIMTSZ")) {
4710
 
            return true;
4711
 
        }
4712
 
        if (!strcmp(var, "$DIMTVP")) {
4713
 
            return true;
4714
 
        }
4715
 
        if (!strcmp(var, "$DIMTXT")) {
4716
 
            return true;
4717
 
        }
4718
 
        if (!strcmp(var, "$DIMZIN")) {
4719
 
            return true;
4720
 
        }
4721
 
        if (!strcmp(var, "$DWGCODEPAGE")) {
4722
 
            return true;
4723
 
        }
4724
 
        if (!strcmp(var, "$DRAGMODE")) {
4725
 
            return true;
4726
 
        }
4727
 
        if (!strcmp(var, "$ELEVATION")) {
4728
 
            return true;
4729
 
        }
4730
 
        if (!strcmp(var, "$EXTMAX")) {
4731
 
            return true;
4732
 
        }
4733
 
        if (!strcmp(var, "$EXTMIN")) {
4734
 
            return true;
4735
 
        }
4736
 
        if (!strcmp(var, "$FILLETRAD")) {
4737
 
            return true;
4738
 
        }
4739
 
        if (!strcmp(var, "$FILLMODE")) {
4740
 
            return true;
4741
 
        }
4742
 
        if (!strcmp(var, "$HANDLING")) {
4743
 
            return true;
4744
 
        }
4745
 
        if (!strcmp(var, "$HANDSEED")) {
4746
 
            return true;
4747
 
        }
4748
 
        if (!strcmp(var, "$INSBASE")) {
4749
 
            return true;
4750
 
        }
4751
 
        if (!strcmp(var, "$LIMCHECK")) {
4752
 
            return true;
4753
 
        }
4754
 
        if (!strcmp(var, "$LIMMAX")) {
4755
 
            return true;
4756
 
        }
4757
 
        if (!strcmp(var, "$LIMMIN")) {
4758
 
            return true;
4759
 
        }
4760
 
        if (!strcmp(var, "$LTSCALE")) {
4761
 
            return true;
4762
 
        }
4763
 
        if (!strcmp(var, "$LUNITS")) {
4764
 
            return true;
4765
 
        }
4766
 
        if (!strcmp(var, "$LUPREC")) {
4767
 
            return true;
4768
 
        }
4769
 
        if (!strcmp(var, "$MAXACTVP")) {
4770
 
            return true;
4771
 
        }
4772
 
        if (!strcmp(var, "$MENU")) {
4773
 
            return true;
4774
 
        }
4775
 
        if (!strcmp(var, "$MIRRTEXT")) {
4776
 
            return true;
4777
 
        }
4778
 
        if (!strcmp(var, "$ORTHOMODE")) {
4779
 
            return true;
4780
 
        }
4781
 
        if (!strcmp(var, "$OSMODE")) {
4782
 
            return true;
4783
 
        }
4784
 
        if (!strcmp(var, "$PDMODE")) {
4785
 
            return true;
4786
 
        }
4787
 
        if (!strcmp(var, "$PDSIZE")) {
4788
 
            return true;
4789
 
        }
4790
 
        if (!strcmp(var, "$PELEVATION")) {
4791
 
            return true;
4792
 
        }
4793
 
        if (!strcmp(var, "$PEXTMAX")) {
4794
 
            return true;
4795
 
        }
4796
 
        if (!strcmp(var, "$PEXTMIN")) {
4797
 
            return true;
4798
 
        }
4799
 
        if (!strcmp(var, "$PLIMCHECK")) {
4800
 
            return true;
4801
 
        }
4802
 
        if (!strcmp(var, "$PLIMMAX")) {
4803
 
            return true;
4804
 
        }
4805
 
        if (!strcmp(var, "$PLIMMIN")) {
4806
 
            return true;
4807
 
        }
4808
 
        if (!strcmp(var, "$PLINEGEN")) {
4809
 
            return true;
4810
 
        }
4811
 
        if (!strcmp(var, "$PLINEWID")) {
4812
 
            return true;
4813
 
        }
4814
 
        if (!strcmp(var, "$PSLTSCALE")) {
4815
 
            return true;
4816
 
        }
4817
 
        if (!strcmp(var, "$PUCSNAME")) {
4818
 
            return true;
4819
 
        }
4820
 
        if (!strcmp(var, "$PUCSORG")) {
4821
 
            return true;
4822
 
        }
4823
 
        if (!strcmp(var, "$PUCSXDIR")) {
4824
 
            return true;
4825
 
        }
4826
 
        if (!strcmp(var, "$PUCSYDIR")) {
4827
 
            return true;
4828
 
        }
4829
 
        if (!strcmp(var, "$QTEXTMODE")) {
4830
 
            return true;
4831
 
        }
4832
 
        if (!strcmp(var, "$REGENMODE")) {
4833
 
            return true;
4834
 
        }
4835
 
        if (!strcmp(var, "$SHADEDGE")) {
4836
 
            return true;
4837
 
        }
4838
 
        if (!strcmp(var, "$SHADEDIF")) {
4839
 
            return true;
4840
 
        }
4841
 
        if (!strcmp(var, "$SKETCHINC")) {
4842
 
            return true;
4843
 
        }
4844
 
        if (!strcmp(var, "$SKPOLY")) {
4845
 
            return true;
4846
 
        }
4847
 
        if (!strcmp(var, "$SPLFRAME")) {
4848
 
            return true;
4849
 
        }
4850
 
        if (!strcmp(var, "$SPLINESEGS")) {
4851
 
            return true;
4852
 
        }
4853
 
        if (!strcmp(var, "$SPLINETYPE")) {
4854
 
            return true;
4855
 
        }
4856
 
        if (!strcmp(var, "$SURFTAB1")) {
4857
 
            return true;
4858
 
        }
4859
 
        if (!strcmp(var, "$SURFTAB2")) {
4860
 
            return true;
4861
 
        }
4862
 
        if (!strcmp(var, "$SURFTYPE")) {
4863
 
            return true;
4864
 
        }
4865
 
        if (!strcmp(var, "$SURFU")) {
4866
 
            return true;
4867
 
        }
4868
 
        if (!strcmp(var, "$SURFV")) {
4869
 
            return true;
4870
 
        }
4871
 
        if (!strcmp(var, "$TDCREATE")) {
4872
 
            return true;
4873
 
        }
4874
 
        if (!strcmp(var, "$TDINDWG")) {
4875
 
            return true;
4876
 
        }
4877
 
        if (!strcmp(var, "$TDUPDATE")) {
4878
 
            return true;
4879
 
        }
4880
 
        if (!strcmp(var, "$TDUSRTIMER")) {
4881
 
            return true;
4882
 
        }
4883
 
        if (!strcmp(var, "$TEXTSIZE")) {
4884
 
            return true;
4885
 
        }
4886
 
        if (!strcmp(var, "$TEXTSTYLE")) {
4887
 
            return true;
4888
 
        }
4889
 
        if (!strcmp(var, "$THICKNESS")) {
4890
 
            return true;
4891
 
        }
4892
 
        if (!strcmp(var, "$TILEMODE")) {
4893
 
            return true;
4894
 
        }
4895
 
        if (!strcmp(var, "$TRACEWID")) {
4896
 
            return true;
4897
 
        }
4898
 
        if (!strcmp(var, "$UCSNAME")) {
4899
 
            return true;
4900
 
        }
4901
 
        if (!strcmp(var, "$UCSORG")) {
4902
 
            return true;
4903
 
        }
4904
 
        if (!strcmp(var, "$UCSXDIR")) {
4905
 
            return true;
4906
 
        }
4907
 
        if (!strcmp(var, "$UCSYDIR")) {
4908
 
            return true;
4909
 
        }
4910
 
        if (!strcmp(var, "$UNITMODE")) {
4911
 
            return true;
4912
 
        }
4913
 
        if (!strcmp(var, "$USERI1")) {
4914
 
            return true;
4915
 
        }
4916
 
        if (!strcmp(var, "$USERR1")) {
4917
 
            return true;
4918
 
        }
4919
 
        if (!strcmp(var, "$USRTIMER")) {
4920
 
            return true;
4921
 
        }
4922
 
        if (!strcmp(var, "$VISRETAIN")) {
4923
 
            return true;
4924
 
        }
4925
 
        if (!strcmp(var, "$WORLDVIEW")) {
4926
 
            return true;
4927
 
        }
4928
 
        if (!strcmp(var, "$FASTZOOM")) {
4929
 
            return true;
4930
 
        }
4931
 
        if (!strcmp(var, "$GRIDMODE")) {
4932
 
            return true;
4933
 
        }
4934
 
        if (!strcmp(var, "$GRIDUNIT")) {
4935
 
            return true;
4936
 
        }
4937
 
        if (!strcmp(var, "$SNAPANG")) {
4938
 
            return true;
4939
 
        }
4940
 
        if (!strcmp(var, "$SNAPBASE")) {
4941
 
            return true;
4942
 
        }
4943
 
        if (!strcmp(var, "$SNAPISOPAIR")) {
4944
 
            return true;
4945
 
        }
4946
 
        if (!strcmp(var, "$SNAPMODE")) {
4947
 
            return true;
4948
 
        }
4949
 
        if (!strcmp(var, "$SNAPSTYLE")) {
4950
 
            return true;
4951
 
        }
4952
 
        if (!strcmp(var, "$SNAPUNIT")) {
4953
 
            return true;
4954
 
        }
4955
 
        if (!strcmp(var, "$VIEWCTR")) {
4956
 
            return true;
4957
 
        }
4958
 
        if (!strcmp(var, "$VIEWDIR")) {
4959
 
            return true;
4960
 
        }
4961
 
        if (!strcmp(var, "$VIEWSIZE")) {
4962
 
            return true;
4963
 
        }
4964
 
        return false;
4965
 
    }
4966
 
 
4967
 
    return false;
4968
 
}
4969
 
 
4970
 
 
4971
 
 
4972
 
/**
4973
 
 * @returns the library version as int (4 bytes, each byte one version number).
4974
 
 * e.g. if str = "2.0.2.0" getLibVersion returns 0x02000200
4975
 
 */
4976
 
int DL_Dxf::getLibVersion(const char* str) {
4977
 
    int d[4];
4978
 
    int idx = 0;
4979
 
    char v[4][5];
4980
 
    int ret = 0;
4981
 
 
4982
 
    for (unsigned int i=0; i<strlen(str) && idx<3; ++i) {
4983
 
        if (str[i]=='.') {
4984
 
            d[idx] = i;
4985
 
            idx++;
4986
 
        }
4987
 
    }
4988
 
 
4989
 
    if (idx==3) {
4990
 
        d[3] = strlen(str);
4991
 
 
4992
 
        strncpy(v[0], str, d[0]);
4993
 
        v[0][d[0]] = '\0';
4994
 
 
4995
 
        strncpy(v[1], &str[d[0]+1], d[1]-d[0]-1);
4996
 
        v[1][d[1]-d[0]-1] = '\0';
4997
 
 
4998
 
        strncpy(v[2], &str[d[1]+1], d[2]-d[1]-1);
4999
 
        v[2][d[2]-d[1]-1] = '\0';
5000
 
 
5001
 
        strncpy(v[3], &str[d[2]+1], d[3]-d[2]-1);
5002
 
        v[3][d[3]-d[2]-1] = '\0';
5003
 
 
5004
 
        ret = (atoi(v[0])<<(3*8)) +
5005
 
              (atoi(v[1])<<(2*8)) +
5006
 
              (atoi(v[2])<<(1*8)) +
5007
 
              (atoi(v[3])<<(0*8));
5008
 
 
5009
 
        return ret;
5010
 
    } else {
5011
 
        std::cerr << "DL_Dxf::getLibVersion: invalid version number: " << str << "\n";
5012
 
        return 0;
5013
 
    }
5014
 
}
5015
 
 
5016
 
 
5017
 
 
5018
 
/**
5019
 
 * Some test routines.
5020
 
 */
5021
 
void DL_Dxf::test() {
5022
 
    char* buf1;
5023
 
    char* buf2;
5024
 
    char* buf3;
5025
 
    char* buf4;
5026
 
    char* buf5;
5027
 
    char* buf6;
5028
 
 
5029
 
    buf1 = new char[10];
5030
 
    buf2 = new char[10];
5031
 
    buf3 = new char[10];
5032
 
    buf4 = new char[10];
5033
 
    buf5 = new char[10];
5034
 
    buf6 = new char[10];
5035
 
 
5036
 
    strcpy(buf1, "  10\n");
5037
 
    strcpy(buf2, "10");
5038
 
    strcpy(buf3, "10\n");
5039
 
    strcpy(buf4, "  10 \n");
5040
 
    strcpy(buf5, "  10 \r");
5041
 
    strcpy(buf6, "\t10 \n");
5042
 
 
5043
 
    std::cout << "1 buf1: '" << buf1 << "'\n";
5044
 
    stripWhiteSpace(&buf1);
5045
 
    std::cout << "2 buf1: '" << buf1 << "'\n";
5046
 
    //assert(!strcmp(buf1, "10"));
5047
 
 
5048
 
    std::cout << "1 buf2: '" << buf2 << "'\n";
5049
 
    stripWhiteSpace(&buf2);
5050
 
    std::cout << "2 buf2: '" << buf2 << "'\n";
5051
 
 
5052
 
    std::cout << "1 buf3: '" << buf3 << "'\n";
5053
 
    stripWhiteSpace(&buf3);
5054
 
    std::cout << "2 buf3: '" << buf3 << "'\n";
5055
 
 
5056
 
    std::cout << "1 buf4: '" << buf4 << "'\n";
5057
 
    stripWhiteSpace(&buf4);
5058
 
    std::cout << "2 buf4: '" << buf4 << "'\n";
5059
 
 
5060
 
    std::cout << "1 buf5: '" << buf5 << "'\n";
5061
 
    stripWhiteSpace(&buf5);
5062
 
    std::cout << "2 buf5: '" << buf5 << "'\n";
5063
 
 
5064
 
    std::cout << "1 buf6: '" << buf6 << "'\n";
5065
 
    stripWhiteSpace(&buf6);
5066
 
    std::cout << "2 buf6: '" << buf6 << "'\n";
5067
 
 
5068
 
}
5069
 
 
5070