1 /**********************************************************
2  * Version $Id: dl_codes.h 911 2011-02-14 16:38:15Z reklov_w $
3  *********************************************************/
4 /****************************************************************************
5 ** $Id: dl_codes.h 911 2011-02-14 16:38:15Z reklov_w $
6 **
7 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
8 ** Copyright (C) 2001 Robert J. Campbell Jr.
9 **
10 ** This file is part of the dxflib project.
11 **
12 ** This file may be distributed and/or modified under the terms of the
13 ** GNU General Public License version 2 as published by the Free Software
14 ** Foundation and appearing in the file LICENSE.GPL included in the
15 ** packaging of this file.
16 **
17 ** Licensees holding valid dxflib Professional Edition licenses may use
18 ** this file in accordance with the dxflib Commercial License
19 ** Agreement provided with the Software.
20 **
21 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
22 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 **
24 ** See http://www.ribbonsoft.com for further details.
25 **
26 ** Contact info@ribbonsoft.com if any conditions of this licensing are
27 ** not clear to you.
28 **
29 **********************************************************************/
30 
31 /**
32  * Defines common DXF codes and constants.
33  */
34 
35 #ifndef DXF_CODES_H
36 #define DXF_CODES_H
37 
38 #if _MSC_VER > 1000
39 #pragma once
40 #endif // _MSC_VER > 1000
41 
42 #if defined(__OS2__)||defined(__EMX__)
43 #define strcasecmp(s,t) stricmp(s,t)
44 #endif
45 
46 #if defined(_WIN32)
47 #define strcasecmp(s,t) _stricmp(s,t)
48 #endif
49 
50 
51 #ifdef _WIN32
52 #undef M_PI
53 #define M_PI   3.14159265358979323846
54 #pragma warning(disable : 4800)
55 #endif
56 
57 #ifndef M_PI
58 #define M_PI 3.1415926535897932384626433832795
59 #endif
60 
61 #define DL_DXF_MAXLINE 1024
62 #define DL_DXF_MAXGROUPCODE 1100
63 
64 // used to mark invalid vectors:
65 //#define DL_DXF_MAXDOUBLE 1.0E+10
66 
67 /**
68  * Codes for colors and DXF versions.
69  */
70 class DL_Codes {
71 public:
72     /**
73      * Standard DXF colors.
74      */
75     enum color {
76         black = 250,
77         green = 3,
78         red = 1,
79         brown = 15,
80         yellow = 2,
81         cyan = 4,
82         magenta = 6,
83         gray = 8,
84         blue = 5,
85         l_blue = 163,
86         l_green = 121,
87         l_cyan = 131,
88         l_red = 23,
89         l_magenta = 221,
90         l_gray = 252,
91         white = 7,
92         bylayer = 256,
93         byblock = 0
94     };
95 
96     /**
97      * Version numbers for the DXF Format.
98      */
99     enum version {
100         AC1009, AC1012, AC1014, AC1015
101     };
102 };
103 
104 
105 // Extended color palette:
106 // The first entry is only for direct indexing starting with [1]
107 // Color 1 is red (1,0,0)
108 const double dxfColors[][3] = {
109                                   {0,0,0},                // unused
110                                   {1,0,0},                // 1
111                                   {1,1,0},
112                                   {0,1,0},
113                                   {0,1,1},
114                                   {0,0,1},
115                                   {1,0,1},
116                                   {1,1,1},                // black or white
117                                   {0.5,0.5,0.5},
118                                   {0.75,0.75,0.75},
119                                   {1,0,0},                // 10
120                                   {1,0.5,0.5},
121                                   {0.65,0,0},
122                                   {0.65,0.325,0.325},
123                                   {0.5,0,0},
124                                   {0.5,0.25,0.25},
125                                   {0.3,0,0},
126                                   {0.3,0.15,0.15},
127                                   {0.15,0,0},
128                                   {0.15,0.075,0.075},
129                                   {1,0.25,0},             // 20
130                                   {1,0.625,0.5},
131                                   {0.65,0.1625,0},
132                                   {0.65,0.4063,0.325},
133                                   {0.5,0.125,0},
134                                   {0.5,0.3125,0.25},
135                                   {0.3,0.075,0},
136                                   {0.3,0.1875,0.15},
137                                   {0.15,0.0375,0},
138                                   {0.15,0.0938,0.075},
139                                   {1,0.5,0},              // 30
140                                   {1,0.75,0.5},
141                                   {0.65,0.325,0},
142                                   {0.65,0.4875,0.325},
143                                   {0.5,0.25,0},
144                                   {0.5,0.375,0.25},
145                                   {0.3,0.15,0},
146                                   {0.3,0.225,0.15},
147                                   {0.15,0.075,0},
148                                   {0.15,0.1125,0.075},
149                                   {1,0.75,0},             // 40
150                                   {1,0.875,0.5},
151                                   {0.65,0.4875,0},
152                                   {0.65,0.5688,0.325},
153                                   {0.5,0.375,0},
154                                   {0.5,0.4375,0.25},
155                                   {0.3,0.225,0},
156                                   {0.3,0.2625,0.15},
157                                   {0.15,0.1125,0},
158                                   {0.15,0.1313,0.075},
159                                   {1,1,0},                // 50
160                                   {1,1,0.5},
161                                   {0.65,0.65,0},
162                                   {0.65,0.65,0.325},
163                                   {0.5,0.5,0},
164                                   {0.5,0.5,0.25},
165                                   {0.3,0.3,0},
166                                   {0.3,0.3,0.15},
167                                   {0.15,0.15,0},
168                                   {0.15,0.15,0.075},
169                                   {0.75,1,0},             // 60
170                                   {0.875,1,0.5},
171                                   {0.4875,0.65,0},
172                                   {0.5688,0.65,0.325},
173                                   {0.375,0.5,0},
174                                   {0.4375,0.5,0.25},
175                                   {0.225,0.3,0},
176                                   {0.2625,0.3,0.15},
177                                   {0.1125,0.15,0},
178                                   {0.1313,0.15,0.075},
179                                   {0.5,1,0},              // 70
180                                   {0.75,1,0.5},
181                                   {0.325,0.65,0},
182                                   {0.4875,0.65,0.325},
183                                   {0.25,0.5,0},
184                                   {0.375,0.5,0.25},
185                                   {0.15,0.3,0},
186                                   {0.225,0.3,0.15},
187                                   {0.075,0.15,0},
188                                   {0.1125,0.15,0.075},
189                                   {0.25,1,0},             // 80
190                                   {0.625,1,0.5},
191                                   {0.1625,0.65,0},
192                                   {0.4063,0.65,0.325},
193                                   {0.125,0.5,0},
194                                   {0.3125,0.5,0.25},
195                                   {0.075,0.3,0},
196                                   {0.1875,0.3,0.15},
197                                   {0.0375,0.15,0},
198                                   {0.0938,0.15,0.075},
199                                   {0,1,0},                // 90
200                                   {0.5,1,0.5},
201                                   {0,0.65,0},
202                                   {0.325,0.65,0.325},
203                                   {0,0.5,0},
204                                   {0.25,0.5,0.25},
205                                   {0,0.3,0},
206                                   {0.15,0.3,0.15},
207                                   {0,0.15,0},
208                                   {0.075,0.15,0.075},
209                                   {0,1,0.25},             // 100
210                                   {0.5,1,0.625},
211                                   {0,0.65,0.1625},
212                                   {0.325,0.65,0.4063},
213                                   {0,0.5,0.125},
214                                   {0.25,0.5,0.3125},
215                                   {0,0.3,0.075},
216                                   {0.15,0.3,0.1875},
217                                   {0,0.15,0.0375},
218                                   {0.075,0.15,0.0938},
219                                   {0,1,0.5},              // 110
220                                   {0.5,1,0.75},
221                                   {0,0.65,0.325},
222                                   {0.325,0.65,0.4875},
223                                   {0,0.5,0.25},
224                                   {0.25,0.5,0.375},
225                                   {0,0.3,0.15},
226                                   {0.15,0.3,0.225},
227                                   {0,0.15,0.075},
228                                   {0.075,0.15,0.1125},
229                                   {0,1,0.75},             // 120
230                                   {0.5,1,0.875},
231                                   {0,0.65,0.4875},
232                                   {0.325,0.65,0.5688},
233                                   {0,0.5,0.375},
234                                   {0.25,0.5,0.4375},
235                                   {0,0.3,0.225},
236                                   {0.15,0.3,0.2625},
237                                   {0,0.15,0.1125},
238                                   {0.075,0.15,0.1313},
239                                   {0,1,1},                // 130
240                                   {0.5,1,1},
241                                   {0,0.65,0.65},
242                                   {0.325,0.65,0.65},
243                                   {0,0.5,0.5},
244                                   {0.25,0.5,0.5},
245                                   {0,0.3,0.3},
246                                   {0.15,0.3,0.3},
247                                   {0,0.15,0.15},
248                                   {0.075,0.15,0.15},
249                                   {0,0.75,1},             // 140
250                                   {0.5,0.875,1},
251                                   {0,0.4875,0.65},
252                                   {0.325,0.5688,0.65},
253                                   {0,0.375,0.5},
254                                   {0.25,0.4375,0.5},
255                                   {0,0.225,0.3},
256                                   {0.15,0.2625,0.3},
257                                   {0,0.1125,0.15},
258                                   {0.075,0.1313,0.15},
259                                   {0,0.5,1},              // 150
260                                   {0.5,0.75,1},
261                                   {0,0.325,0.65},
262                                   {0.325,0.4875,0.65},
263                                   {0,0.25,0.5},
264                                   {0.25,0.375,0.5},
265                                   {0,0.15,0.3},
266                                   {0.15,0.225,0.3},
267                                   {0,0.075,0.15},
268                                   {0.075,0.1125,0.15},
269                                   {0,0.25,1},             // 160
270                                   {0.5,0.625,1},
271                                   {0,0.1625,0.65},
272                                   {0.325,0.4063,0.65},
273                                   {0,0.125,0.5},
274                                   {0.25,0.3125,0.5},
275                                   {0,0.075,0.3},
276                                   {0.15,0.1875,0.3},
277                                   {0,0.0375,0.15},
278                                   {0.075,0.0938,0.15},
279                                   {0,0,1},                // 170
280                                   {0.5,0.5,1},
281                                   {0,0,0.65},
282                                   {0.325,0.325,0.65},
283                                   {0,0,0.5},
284                                   {0.25,0.25,0.5},
285                                   {0,0,0.3},
286                                   {0.15,0.15,0.3},
287                                   {0,0,0.15},
288                                   {0.075,0.075,0.15},
289                                   {0.25,0,1},             // 180
290                                   {0.625,0.5,1},
291                                   {0.1625,0,0.65},
292                                   {0.4063,0.325,0.65},
293                                   {0.125,0,0.5},
294                                   {0.3125,0.25,0.5},
295                                   {0.075,0,0.3},
296                                   {0.1875,0.15,0.3},
297                                   {0.0375,0,0.15},
298                                   {0.0938,0.075,0.15},
299                                   {0.5,0,1},              // 190
300                                   {0.75,0.5,1},
301                                   {0.325,0,0.65},
302                                   {0.4875,0.325,0.65},
303                                   {0.25,0,0.5},
304                                   {0.375,0.25,0.5},
305                                   {0.15,0,0.3},
306                                   {0.225,0.15,0.3},
307                                   {0.075,0,0.15},
308                                   {0.1125,0.075,0.15},
309                                   {0.75,0,1},             // 200
310                                   {0.875,0.5,1},
311                                   {0.4875,0,0.65},
312                                   {0.5688,0.325,0.65},
313                                   {0.375,0,0.5},
314                                   {0.4375,0.25,0.5},
315                                   {0.225,0,0.3},
316                                   {0.2625,0.15,0.3},
317                                   {0.1125,0,0.15},
318                                   {0.1313,0.075,0.15},
319                                   {1,0,1},                // 210
320                                   {1,0.5,1},
321                                   {0.65,0,0.65},
322                                   {0.65,0.325,0.65},
323                                   {0.5,0,0.5},
324                                   {0.5,0.25,0.5},
325                                   {0.3,0,0.3},
326                                   {0.3,0.15,0.3},
327                                   {0.15,0,0.15},
328                                   {0.15,0.075,0.15},
329                                   {1,0,0.75},             // 220
330                                   {1,0.5,0.875},
331                                   {0.65,0,0.4875},
332                                   {0.65,0.325,0.5688},
333                                   {0.5,0,0.375},
334                                   {0.5,0.25,0.4375},
335                                   {0.3,0,0.225},
336                                   {0.3,0.15,0.2625},
337                                   {0.15,0,0.1125},
338                                   {0.15,0.075,0.1313},
339                                   {1,0,0.5},              // 230
340                                   {1,0.5,0.75},
341                                   {0.65,0,0.325},
342                                   {0.65,0.325,0.4875},
343                                   {0.5,0,0.25},
344                                   {0.5,0.25,0.375},
345                                   {0.3,0,0.15},
346                                   {0.3,0.15,0.225},
347                                   {0.15,0,0.075},
348                                   {0.15,0.075,0.1125},
349                                   {1,0,0.25},             // 240
350                                   {1,0.5,0.625},
351                                   {0.65,0,0.1625},
352                                   {0.65,0.325,0.4063},
353                                   {0.5,0,0.125},
354                                   {0.5,0.25,0.3125},
355                                   {0.3,0,0.075},
356                                   {0.3,0.15,0.1875},
357                                   {0.15,0,0.0375},
358                                   {0.15,0.075,0.0938},
359                                   {0.33,0.33,0.33},       // 250
360                                   {0.464,0.464,0.464},
361                                   {0.598,0.598,0.598},
362                                   {0.732,0.732,0.732},
363                                   {0.866,0.866,0.866},
364                                   {1,1,1}                 // 255
365                               }
366                               ;
367 
368 
369 // AutoCAD VERSION aliases
370 #define VER_R12    DL_Codes::AC1009
371 #define VER_LT2    DL_Codes::AC1009
372 #define VER_R13    DL_Codes::AC1012   // not supported yet
373 #define VER_LT95   DL_Codes::AC1012   // not supported yet
374 #define VER_R14    DL_Codes::AC1014   // not supported yet
375 #define VER_LT97   DL_Codes::AC1014   // not supported yet
376 #define VER_LT98   DL_Codes::AC1014   // not supported yet
377 #define VER_2000   DL_Codes::AC1015
378 #define VER_2002   DL_Codes::AC1015
379 
380 
381 // DXF Group Codes:
382 
383 // Strings
384 #define STRGRP_START      0
385 #define STRGRP_END        9
386 
387 // Coordinates
388 #define CRDGRP_START     10
389 #define CRDGRP_END       19
390 
391 // Real values
392 #define RLGRP_START      38
393 #define RLGRP_END        59
394 
395 // Short integer values
396 #define SHOGRP_START     60
397 #define SHOGRP_END       79
398 
399 // New in Release 13,
400 #define SUBCLASS        100
401 
402 // More coordinates
403 #define CRD2GRP_START   210
404 #define CRD2GRP_END     239
405 
406 // Extended data strings
407 #define ESTRGRP_START  1000
408 #define ESTRGRP_END    1009
409 
410 // Extended data reals
411 #define ERLGRP_START   1010
412 #define ERLGRP_END     1059
413 
414 
415 #define Y8_COORD_CODE       28
416 #define Z0_COORD_CODE       30
417 #define Z8_COORD_CODE       38
418 
419 #define POINT_COORD_CODE    10
420 #define INSERT_COORD_CODE   10
421 
422 #define CRD2GRP_START      210
423 #define CRD2GRP_END        239
424 
425 #define THICKNESS            39
426 #define FIRST_REAL_CODE      THICKNESS
427 #define LAST_REAL_CODE       59
428 #define FIRST_INT_CODE       60
429 #define ATTFLAGS_CODE        70
430 #define PLINE_FLAGS_CODE     70
431 #define LAYER_FLAGS_CODE     70
432 #define FLD_LEN_CODE         73 // Inside ATTRIB resbuf
433 #define LAST_INT_CODE        79
434 #define X_EXTRU_CODE        210
435 #define Y_EXTRU_CODE        220
436 #define Z_EXTRU_CODE        230
437 #define COMMENT_CODE        999
438 
439 // Start and endpoints of a line
440 #define LINE_START_CODE      10  // Followed by x coord
441 #define LINE_END_CODE        11  // Followed by x coord
442 
443 // Some codes used by blocks
444 #define BLOCK_FLAGS_CODE     70  // An int containing flags
445 #define BLOCK_BASE_CODE      10  // Origin of block definition
446 #define XREF_DEPENDENT       16  // If a block contains an XREF
447 #define XREF_RESOLVED        32  // If a XREF resolved ok
448 #define REFERENCED           64  // If a block is ref'd in DWG
449 
450 #define XSCALE_CODE          41
451 #define YSCALE_CODE          42
452 #define ANGLE_CODE           50
453 #define INS_POINT_CODE       10  // Followed by x of ins pnt
454 #define NAME2_CODE            3  // Second appearance of name
455 
456 // Some codes used by circle entities
457 #define CENTER_CODE          10  // Followed by x of center
458 #define RADIUS_CODE          40  // Followd by radius of circle
459 
460 #define COND_OP_CODE         -4  // Conditional op,ads_ssget
461 
462 // When using ads_buildlist you MUST use RTDXF0 instead of these
463 #define ENTITY_TYPE_CODE      0  // Then there is LINE, 3DFACE..
464 #define SES_CODE              0  // Start End String Code
465 #define FILE_SEP_CODE         0  // File separator
466 #define SOT_CODE              0  // Start Of Table
467 #define TEXTVAL_CODE          1
468 #define NAME_CODE             2
469 #define BLOCK_NAME_CODE       2
470 #define SECTION_NAME_CODE     2
471 #define ENT_HAND_CODE         5  // What follows is hexa string
472 #define TXT_STYLE_CODE        7  // Inside attributes
473 #define LAYER_NAME_CODE       8  // What follows is layer name
474 #define FIRST_XCOORD_CODE    10  // Group code x of 1st coord
475 #define FIRST_YCOORD_CODE    20  // Group code y of 1st coord
476 #define FIRST_ZCOORD_CODE    30  // Group code z of 1st coord
477 #define L_START_CODE         10
478 #define L_END_CODE           11
479 #define TXTHI_CODE           40
480 #define SCALE_X_CODE         41
481 #define SCALE_Y_CODE         42
482 #define SCALE_Z_CODE         43
483 #define BULGE_CODE           42  // Used in PLINE verts for arcs
484 #define ROTATION_CODE        50
485 #define COLOUR_CODE          62  // What follows is a color int
486 #define LTYPE_CODE            6  // What follows is a linetype
487 
488 
489 // Attribute flags
490 #define ATTS_FOLLOW_CODE     66
491 #define ATT_TAG_CODE          2
492 #define ATT_VAL_CODE          1
493 #define ATT_FLAGS_CODE       70  // 4 1 bit flags as follows...
494 #define ATT_INVIS_FLAG        1
495 #define ATT_CONST_FLAG        2
496 #define ATT_VERIFY_FLAG       4 // Prompt and verify
497 #define ATT_PRESET_FLAG       8 // No prompt and no verify
498 
499 // PLINE defines
500 // Flags
501 #define OPEN_PLINE       0x00
502 #define CLOSED_PLINE     0x01
503 #define POLYLINE3D       0x80
504 #define PFACE_MESH       0x40
505 #define PGON_MESH        0x10
506 // Vertices follow entity, required in POLYLINES
507 #define VERTS_FOLLOW_CODE   66 // Value should always be 1
508 #define VERTEX_COORD_CODE   10
509 
510 
511 // LAYER flags
512 #define FROZEN           1
513 #define FROZEN_BY_DEF    2
514 #define LOCKED           4
515 #define OBJECT_USED     64   // Object is ref'd in the dwg
516 
517 #define BLOCK_EN_CODE   -2   // Block entity definition
518 #define E_NAME          -1   // Entity name
519 
520 // Extended data codes
521 #define EXTD_SENTINEL    (-3)
522 #define EXTD_STR         1000
523 #define EXTD_APP_NAME    1001
524 #define EXTD_CTL_STR     1002
525 #define EXTD_LYR_STR     1003
526 #define EXTD_CHUNK       1004
527 #define EXTD_HANDLE      1005
528 #define EXTD_POINT       1010
529 #define EXTD_POS         1011
530 #define EXTD_DISP        1012
531 #define EXTD_DIR         1013
532 #define EXTD_FLOAT       1040
533 #define EXTD_DIST        1041
534 #define EXTD_SCALE       1042
535 #define EXTD_INT16       1070
536 #define EXTD_INT32       1071
537 
538 // UCS codes for use in ads_trans
539 #define WCS_TRANS_CODE      0
540 #define UCS_TRANS_CODE      1
541 #define DCS_TRANS_CODE      2
542 #define PCS_TRANS_CODE      3
543 
544 #endif
545 
546