Skip to content

Commit 9f18018

Browse files
committed
Added base units
1 parent 9a71e37 commit 9f18018

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

Creator.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @see (RU) http://help.autodesk.com/view/ACD/2015/RUS/?guid=GUID-235B22E0-A567-4CF6-92D3-38A2306D73F3
1414
*
1515
* @example <code>
16-
* $dxf = new \adamasantares\dxf\Creator();
16+
* $dxf = new \adamasantares\dxf\Creator( \adamasantares\dxf\Creator::INCHES );
1717
* $dxf->addText(26, 46, 0, 'DXF testing', 8)
1818
* ->setLayer('cyan', $color::CYAN)
1919
* ->addLine(25, 0, 0, 100, 0, 0)
@@ -46,6 +46,29 @@
4646
*/
4747
class Creator {
4848

49+
// units codes
50+
const UNITLESS = 0;
51+
const INCHES = 1;
52+
const FEET = 2;
53+
const MILES = 3;
54+
const MILLIMETERS = 4;
55+
const CENTIMETERS = 5;
56+
const METERS = 6;
57+
const KILOMETERS = 7;
58+
const MICROINCHES = 8;
59+
const MILS = 9;
60+
const YARDS = 10;
61+
const ANGSTROMS = 11;
62+
const NANOMETERS = 12;
63+
const MICRONS = 13;
64+
const DECIMETERS = 14;
65+
const DECAMETERS = 15;
66+
const HECTOMETERS = 16;
67+
const GIGAMETERS = 17;
68+
const ASTRONOMICAL_UNITS = 18;
69+
const LIGHT_YEARS = 19;
70+
const PARSECS = 20;
71+
4972
/**
5073
* @var null Last error description
5174
*/
@@ -72,12 +95,18 @@ class Creator {
7295
*/
7396
private $offset = [0, 0, 0];
7497

98+
/**
99+
* @var int Units
100+
*/
101+
private $units = 1;
102+
75103

76104
/**
77105
* Create new DXF document
78106
*/
79-
function __construct()
107+
function __construct($units)
80108
{
109+
$this->units = $units;
81110
// add default layout
82111
$this->addLayer($this->layerName);
83112
}
@@ -133,7 +162,7 @@ private function getString() {
133162
* @return string
134163
*/
135164
private function getHeaderString() {
136-
$str = "0\nSECTION\n 2\nHEADER\n 9\n\$ACADVER\n 1\nAC1006\n 0\nENDSEC\n 0\n";
165+
$str = "0\nSECTION\n2\nHEADER\n9\n\$ACADVER\n1\nAC1006\n9\n$"."INSUNITS\n70\n{$this->units}\n0\nENDSEC\n0\n";
137166
//layers
138167
$str .= "SECTION\n 2\nTABLES\n 0\nTABLE\n2\n";
139168
$str .= $this->getLayersString();
@@ -374,6 +403,21 @@ public function addArc($x, $y, $z, $radius, $startAngle = 0.1, $endAngle = 90.0)
374403
return $this;
375404
}
376405

406+
407+
/**
408+
* Add Ellipse to current layer.
409+
*
410+
* @return $this
411+
* @see http://www.autodesk.com/techpubs/autocad/acad2000/dxf/ellipse_dxf_06.htm
412+
*/
413+
// TODO todo...
414+
// public function addEllipse(/* ... */)
415+
// {
416+
//
417+
// return $this;
418+
// }
419+
420+
377421
/**
378422
* Add 2D polyline to current layer.
379423
* @param array[float] $points Points array: [x, y, x2, y2, x3, y3, ...]

0 commit comments

Comments
 (0)