File size: 19,347 Bytes
703f5e6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!-- Meta -->
<meta name="Description" content="KLayout layout viewer and editor project page" />
<meta name="Keywords" content="KLayout OASIS GDS2 viewer editor layout semiconductor mask chip design" />
<meta name="abstract" content="KLayout is a free layout viewer and editor for several formats commonly used in the semiconductor industry to transfer layout data" />
<meta name="URL" content="https://www.klayout.de/" />
<meta name="Author" content="Matthias Koefferlein" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>KLayout Layout Viewer And Editor</title>
<!-- General -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.klayout.de/news.xml"/>
<link rel="stylesheet" type="text/css" href="https://www.klayout.de/format.css?v2.0"/>
<link rel="shortcut icon" href="https://www.klayout.de/favicon.ico"/>
<!-- Fonts -->
<link rel="stylesheet" type="text/css" href="https://www.klayout.de/fonts.css"/>
<!-- jQuery -->
<script src="https://www.klayout.de/jquery-3.4.1.min.js"></script>
<!-- bootstrap -->
<link href="https://www.klayout.de/bootstrap-4.3.1-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://www.klayout.de/bootstrap-4.3.1-dist/js/bootstrap.min.js"></script>
</head>
<body>
<div class="klayout-header">
<div class="container mb-5">
<nav class="navbar navbar-dark navbar-expand-lg">
<a class="navbar-brand" href="https://www.klayout.de"><img src="https://www.klayout.de/klayout.png" srcset="https://www.klayout.de/klayout-x2.png 2x" alt="KLayout"></a>
<div class="collapse navbar-collapse" id="navbarToggleExternalContent">
<ul class="navbar-nav ml-auto mr-auto">
<li class="nav-item dropdown active mr-4">
<a class="nav-link dropdown-toggle klayout-menu" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
About
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="https://www.klayout.de/intro.html">KLayout Project</a>
<a class="dropdown-item" href="https://www.klayout.de/doc.html">Documentation</a>
<a class="dropdown-item" href="https://www.klayout.de/galleries.html">Galleries</a>
<a class="dropdown-item" href="https://www.klayout.de/credits.html">Credits</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="https://www.klayout.de/contact.html">Contact</a>
<a class="dropdown-item" href="https://www.klayout.de/impressum.html">Impressum / Imprint</a>
<a class="dropdown-item" href="https://www.klayout.de/privacy_policy.html">Datenschutz / Privacy Policy</a>
</div>
</li>
<li class="nav-item active mr-4">
<a class="nav-link klayout-menu" href="https://www.klayout.de/build.html">Get KLayout</a>
</li>
<li class="nav-item active mr-4">
<a class="nav-link klayout-menu" href="https://sami.klayout.org">Package Index</a>
</li>
<li class="nav-item active mr-5">
<a class="nav-link klayout-menu" href="https://www.klayout.de/forum">Forum</a>
</li>
<li class="nav-item active">
<span class="nav-link klayout-menu">
<a href="https://f-si.org"><img src="https://www.klayout.de/f-si_logo_32h_w.png" border="0" title="Free Silicon Foundation" alt="F-Si"/></a>
<a class="ml-4" href="https://github.com/KLayout"><img src="https://www.klayout.de/GitHub-Mark-32px-white.png" border="0" title="KLayout on GitHub" alt="GitHub"/></a>
</span>
</li>
</ul>
</div>
<!-- collapse button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
</div>
</div>
<div class="container">
<h1>DXF Format</h1>
<p>
This is a brief description of the DXF format or more precisely: the subset of DXF that KLayout understands.
Syntactically, DXF is a very simple format. The basic problem when reading DXF however is how to interpret it.
Apparently, it is more or less a dump of the object properties of the CAD tool, and many questions regarding the
interpretation of the properties are left open.
</p>
<p>
The implementation of KLayout is based on a number of test cases and comparison with other viewers.
In some cases, the interpretation of features was varying (for example, the interpretation of array instances).
In that case, TrueView (see link below) was believed to be the main authority in DXF interpretation.
</p>
<p>
Here are some links and references to other free viewers:
</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/AutoCAD_DXF">DXF page on Wikipedia</a></li>
<li><a href="http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12272454&linkID=10809853">DXF specification page</a></li>
<li><a href="http://usa.autodesk.com/adsk/servlet/pc/index?id=6703438&siteID=123112">TrueView viewer</a></li>
<li><a href="http://www.sharecad.org">Online viewer (www.ShareCAD.org)</a></li>
<li><a href="http://www.edrawingsviewer.com">eDrawings viewer</a></li>
</ul>
<h2>Basic format</h2>
<p>
DXF consists of records of a very simple structure:
</p>
<pre>
<Group-Code> <Value>
</pre>
<p>
The group code is an integer which implicitly defines the value type and
acts as a key for the value.
In ASCII DXF, group codes and values are written in a single line each.
These are the group codes and values relevant for layout data:
</p>
<ul>
<li><b>0</b>: string (keyword)</li>
<li><b>2</b>: string (arbitrary)</li>
<li><b>6</b>: string</li>
<li><b>8</b>: string</li>
<li><b>10..13</b>: double precision coordinate</li>
<li><b>20..23</b>: double precision coordinate</li>
<li><b>30..33</b>: double precision coordinate</li>
<li><b>39</b>: double precision coordinate</li>
<li><b>40..45</b>: double precision floating point value</li>
<li><b>50</b>: double precision angle (in degree)</li>
<li><b>62</b>: 16 bit integer value</li>
<li><b>66</b>: 16 bit integer value </li>
<li><b>70</b>: 16 bit integer value</li>
<li><b>210</b>: double precision coordinate</li>
<li><b>220</b>: double precision coordinate</li>
<li><b>230</b>: double precision coordinate</li>
</ul>
<p>
Pure ASCII DXF allows the lines to contain leading or trailing blanks. KLayout also tries to identify
stray blank lines and skip them. Some systems generate such files.
</p>
<p>
There is also a binary version of the DXF format with this basic structure:
</p>
<ul>
<li>Header (22 Bytes): "AutoCAD Binary DXF<CR><LF><SUB><NULL></li>
<li>16 bit integers: 2 btyes, LSB firs</li>
<li>double: 8 bytes, LSB firs</li>
<li>string: zero-terminated</li>
</ul>
<p>
Apparently the binary format is rarely used. It suffers from a pretty basic issue: since the data type
of a value - hence the byte count - is implicitly determined by the group code, exact knowledge of the data type
associated with each group code is required.
</p>
<h2>General structure</h2>
<p>
This is the general structure of a DXF file as KLayout understands it. This is a schematic representation.
The "//" comments are not part of the file - they are provided for readability.
In addition, group codes and values have been written on one line. In ASCII DXF, group codes and values are on separate lines.
The indentation indicates coherent sections. "..." indicates that other group code / value pairs may be present which are read over:
</p>
<pre>
// header section
0 "SECTION"
2 "HEADER"
...
0 "ENDSEC"
...
// tables section
0 "SECTION"
2 "TABLES"
...
// layer table
0 "TABLE"
2 "LAYER"
70 (# of layers - do not use for reading)
...
// each layer
0 "LAYER"
2 (layer name)
62 (color code)
6 (line style)
...
0 "ENDTAB"
...
0 "ENDSEC"
...
// blocks section
0 "SECTION"
2 "BLOCKS"
...
// each block
0 "BLOCK"
8 (layer name - always 0?)
2 (block name)
70 (flags - always 64?)
10 (base point X)
20 (base point Y)
...
// each entity
0 (entity type)
... (specific for entity)
...
0 "ENDBLK"
...
0 "ENDSEC"
...
// entities (top level cell)
0 "SECTION"
2 "ENTITIES"
...
// each entity
0 (entity type)
... (specific for entity)
...
0 "ENDSEC"
...
// end of file
0 "EOF"
</pre>
<p>KLayout reads these entities which are described in detail below:</p>
<ul>
<li><b>POLYLINE</b>: polygon, paths</li>
<li><b>LWPOLYLINE</b>: polygon, paths</li>
<li><b>SPLINE</b>: a spline line segment</li>
<li><b>TRACE</b>: a four-point polygon</li>
<li><b>ARC</b>: an arc segment</li>
<li><b>ELLIPSE</b>: an elliptic segment</li>
<li><b>INSERT</b>: cell reference</li>
<li><b>LINE</b>: parts of polygon contours, path</li>
<li><b>SOLID</b>: triangle or tetragon</li>
<li><b>HATCH</b>: a filled area (polygon)</li>
<li><b>CIRCLE</b>: a circle</li>
<li><b>DIMENSION</b>: a dimension drawing</li>
<li><b>TEXT</b>: text</li>
<li><b>ATTRIB</b>: text</li>
<li><b>MTEXT</b>: multi-line text</li>
</ul>
<h3>POLYLINE entity</h3>
<pre>
0 "POLYLINE"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
70 (flags - bit 0 for closed (1) or open (0) polyline)
40 (start width)
41 (end width)
...
// each vertex
0 "VERTEX"
8 (layer name - what for?)
10 (position X)
20 (position Y)
42 (bulge)
40 (start width)
41 (end width)
...
0 "SEQEND"
</pre>
<p>
A closed polyline with a width of 0 usually creates a polygon (unless in "keep lines" mode - see below).
A polyline with a width > 0 creates a path.
A non-closed polyline with a width of 0 creates a path with width 0 or contributes to the edges that
will be merged in "merge lines" mode.
</p>
<p>
Polylines with constant width are translated into GDS PATH objects. Polylines with non-constant
width are translated into polygons.
</p>
<p>
For paths: no round ends are provided. Variable extensions have to be emulated by extending the first and last segment.
</p>
<h3>LWPOLYLINE entity for polygons</h3>
<pre>
0 "LWPOLYLINE"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
70 (flags - see POLYLINE)
42 (bulge)
43 (common width)
...
// each vertex
10 (position X)
20 (position Y)
40 (start width of segment)
41 (end width of segment)
...
0 "SEQEND"
</pre>
<p>
LWPOLYLINE entities are alternative representations of POLYLINE entities and are treated alike.
</p>
<h3>ARC entity</h3>
<pre>
0 "ARC"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
10 (center X)
20 (center Y)
50 (start angle)
51 (end angle)
...
</pre>
<p>
An ARC creates a path with width 0 or contributes to the edges that
will be merged in "merge lines" mode.
The arc will be interpolated according to the number of points per circle specified
in the reader options.
</p>
<h3>ELLIPSE entity</h3>
<pre>
0 "ELLIPSE"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
10 (center X)
20 (center Y)
11 (main axis X)
21 (main axis Y)
40 (minor axis radius)
41 (start angle)
42 (end angle)
...
</pre>
<p>
An ELLIPSE creates a path with width 0 or contributes to the edges that
will be merged in "merge lines" mode.
The arc will be interpolated according to the number of points per circle specified
in the reader options.
</p>
<h3>SPLINE entity</h3>
<pre>
0 "SPLINE"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
71 (degree)
...
// each vertex
10 (position X)
20 (position Y)
...
// each knot
40 (knot value)
...
</pre>
<p>
A spline creates a path with width 0 or contributes to the edges that
will be merged in "merge lines" mode.
</p>
<h3>TRACE entity</h3>
<pre>
0 "TRACE"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
2 (block name)
10 (position1 X)
20 (position1 Y)
11 (position2 X)
21 (position2 Y)
12 (position3 X)
22 (position3 Y)
13 (position4 X)
23 (position4 Y)
...
</pre>
<p>
A TRACE entity generates a polygon with four vertices.
</p>
<h3>SOLID entity</h3>
<pre>
0 "SOLID"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
2 (block name)
10 (position1 X)
20 (position1 Y)
11 (position2 X)
21 (position2 Y)
12 (position3 X)
22 (position3 Y)
13 (position4 X)
23 (position4 Y)
...
</pre>
<p>
To get a correctly ordered tetragon, points 3 and 4 must be swapped. A triangle is formed by setting position 3 and 4 to the same coordinates.
</p>
<h3>DIMENSION entity</h3>
<pre>
0 "DIMENSION"
2 (block name)
8 (layer)
...
</pre>
<p>
A DIMENSION entity is only implemented as importing the drawing block without a displacement
using the given layer on "0" wildcard layers inside the block.
</p>
<h3>INSERT entity</h3>
<pre>
0 "INSERT"
8 (layer name)
2 (block name)
10 (position X)
20 (position Y)
41 (scale factor X - can be negative for mirroring)
42 (scale factor Y - can be negative for mirroring)
50 (rotation angle)
70 (number of columns - optional)
71 (number of rows - optional)
44 (column spacing - optional)
45 (row spacing - optional)
...
</pre>
<p>
The layer specified overrides the "0" layer inside the block. This requires layer specific variants.
This override is inherited by child cells as well.
</p>
<p>
The array vectors specified by number of column spacing and row spacing is rotated by the given angle, but not scaled or mirrored.
</p>
<h3>LINE entity</h3>
<pre>
0 "LINE"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
10 (start position X)
20 (start position Y)
11 (start position X)
21 (start position Y)
41 (scale factor X - can be -1 for mirroring)
42 (scale factor Y - can be -1 for mirroring)
39 (thickness - can be 0)
...
</pre>
<p>
Lines are converted into paths with the specified width or contribute to the lines merged in "merge lines" mode.
</p>
<h3>CIRCLE entity</h3>
<pre>
0 "CIRCLE"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
10 (center position X)
20 (center position Y)
40 (radius)
...
</pre>
<p>
Circles are converted to single-point, round-ended paths.
</p>
<h3>TEXT entity</h3>
<pre>
0 "TEXT"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
10 (position X)
20 (position Y)
11 (second alignment position X)
21 (second alignment position Y)
40 (height)
50 (rotation)
71 (mirror flags)
72 (horizontal alignment)
73 (vertical alignment)
1 (text string)
</pre>
<h3>MTEXT entity</h3>
<pre>
0 "MTEXT"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
10 (position X)
20 (position Y)
11 (baseline vector X)
21 (baseline vector Y)
40 (height)
41 (width)
46 (alternative width)
50 (rotation)
71 (alignment flags)
75 (columns flag)
1 (text string)
3 (text string continuation)
</pre>
<h3>ATTRIB entity</h3>
<p>
The ATTRIB entity is basically handled like the TEXT entity except
that group 74 is used for the vertical alignment.
</p>
<h3>HATCH entity</h3>
<pre>
0 "HATCH"
8 (layer name)
210 (extrusion direction x)
220 (extrusion direction y)
230 (extrusion direction z)
91 (number of loops (contours))
// each loop:
92 (flags, usually 3: External (bit 0) | Polyline (bit 1))
93 (number of edges in the first loop)
// each point:
10 (position X)
20 (position Y)
... more points with 10/20 group codes
... more loops (group codes 92, 93, 10, 20 ...)
...
</pre>
<p>
A hatch entity creates a polygon. Individual polygon parts are combined with the even-odd union rule: an overlapping contour
can cancel an area of another contour even if the orientation of both is the same.
</p>
<h2>Other topics</h2>
<h3><a name="polygon_modes"/>Polygon formation and LINE/POLYLINE interpretation</a></h3>
<p>
The are several ways to form polygons from DXF input, which are controlled by the LINE/POLYLINE mode setting on the
reader options page. The following modes are provided:
</p>
<ul>
<li>Automatic</li>
<li>Keep lines</li>
<li>Create polygons from closed polylines with width = 0</li>
<li>Merge lines with width = 0 into polygons</li>
<li>Merge lines and auto-close open contours</li>
</ul>
<p>
"Automatic" mode will select the following modes:
</p>
<ul>
<li>"Keep lines" if at least one SOLID or HATCH entity is present</li>
<li>"Create polygons from closed polylines with width = 0" if at least one closed POLYLINE or LWPOLYLINE entity with width = 0 is present</li>
<li>"Merge lines with width = 0 into polygons" otherwise.</li>
</ul>
<p>
The modes have the following effect:
</p>
<ul>
<li>SOLID entities always form filled tetragons or triangles.</li>
<li>HATCH entities always form complex polygons.</li>
<li>Closed POLYLINE or LWPOLYLINE entities with width = 0 form polygons unless "keep lines" mode is selected. In "auto-close" mode, non-closed polylines will form a closed polygon by connecting the first and last point.</li>
<li>Multiple segments specified by either SPLINE,ARC,ELLIPSE,LINE or POLYLINE/LWPOLYLINE entities with width = 0 are joined and, if they form a loop, create a polygon in the "merge lines" modes. In "auto-close" mode, open contours will be closed by connecting the first and last point.
Reverse-oriented loops can create holes in outer loops.</li>
</ul>
<h3>Extrusion direction</h3>
<p>
The extrusion direction specified by the group codes 210, 220 and 230 is by default (0,0,1). This is the normal case. Extrusion direction (0,0,-1)
is also supported. In this case, the shapes will be mirrored at the Y axis.
</p>
<h3>INSERT entities with layer specification</h3>
<p>
Layer "0" is a "wildcard" layer and can be overridden on a per-instance
basis by a instance specific layer. If the instance has itself "0" layer assigned, no
override takes place (or it does not have any effect).
</p>
</div>
</body>
</html>
|