Skip to content

Commit 9a71e37

Browse files
committed
Update Creator.php
1 parent 9e5e7b7 commit 9a71e37

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

Creator.php

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @since 2015/08
1111
*
1212
* @see http://www.autodesk.com/techpubs/autocad/acad2000/dxf/
13+
* @see (RU) http://help.autodesk.com/view/ACD/2015/RUS/?guid=GUID-235B22E0-A567-4CF6-92D3-38A2306D73F3
1314
*
1415
* @example <code>
1516
* $dxf = new \adamasantares\dxf\Creator();
@@ -66,6 +67,11 @@ class Creator {
6667
*/
6768
private $shapes = [];
6869

70+
/**
71+
* @var array Center offser
72+
*/
73+
private $offset = [0, 0, 0];
74+
6975

7076
/**
7177
* Create new DXF document
@@ -174,6 +180,28 @@ public function getError()
174180
}
175181

176182

183+
/**
184+
* Set offset
185+
* @param $x
186+
* @param $y
187+
* @param $z
188+
*/
189+
public function setOffset($x, $y, $z = 0)
190+
{
191+
$this->offset = [$x, $y, $z];
192+
}
193+
194+
195+
/**
196+
* Get offset
197+
* @return array
198+
*/
199+
public function getOffset()
200+
{
201+
return $this->offset;
202+
}
203+
204+
177205
/**
178206
* Add new layer to document
179207
* @param string $name
@@ -251,6 +279,9 @@ public function setLineType($lineType)
251279
*/
252280
public function addPoint($x, $y, $z)
253281
{
282+
$x += $this->offset[0];
283+
$y += $this->offset[1];
284+
$z += $this->offset[2];
254285
$this->shapes[] = "POINT\n8\n{$this->layerName}\n100\nAcDbPoint\n10\n{$x}\n20\n{$y}\n30\n{$z}\n0\n";
255286
return $this;
256287
}
@@ -269,6 +300,12 @@ public function addPoint($x, $y, $z)
269300
*/
270301
public function addLine($x, $y, $z, $x2, $y2, $z2)
271302
{
303+
$x += $this->offset[0];
304+
$y += $this->offset[1];
305+
$z += $this->offset[2];
306+
$x2 += $this->offset[0];
307+
$y2 += $this->offset[1];
308+
$z2 += $this->offset[2];
272309
$this->shapes[] = "LINE\n8\n{$this->layerName}\n10\n{$x}\n20\n{$y}\n30\n{$z}\n11\n{$x2}\n21\n{$y2}\n31\n{$z2}\n0\n";
273310
return $this;
274311
}
@@ -288,6 +325,9 @@ public function addLine($x, $y, $z, $x2, $y2, $z2)
288325
*/
289326
public function addText($x, $y, $z, $text, $textHeight, $position = 7, $angle = 0)
290327
{
328+
$x += $this->offset[0];
329+
$y += $this->offset[1];
330+
$z += $this->offset[2];
291331
$angle = deg2rad($angle);
292332
$this->shapes[] = "TEXT\n8\n{$this->layerName}\n10\n{$x}\n20\n{$y}\n30\n{$z}\n40\n{$textHeight}\n71\n{$position}\n1\n{$text}\n50\n{$angle}\n0\n";
293333
return $this;
@@ -305,6 +345,9 @@ public function addText($x, $y, $z, $text, $textHeight, $position = 7, $angle =
305345
*/
306346
public function addCircle($x, $y, $z, $radius)
307347
{
348+
$x += $this->offset[0];
349+
$y += $this->offset[1];
350+
$z += $this->offset[2];
308351
$this->shapes[] = "CIRCLE\n8\n{$this->layerName}\n10\n{$x}\n20\n{$y}\n30\n{$z}\n40\n{$radius}\n0\n";
309352
return $this;
310353
}
@@ -324,25 +367,13 @@ public function addCircle($x, $y, $z, $radius)
324367
*/
325368
public function addArc($x, $y, $z, $radius, $startAngle = 0.1, $endAngle = 90.0)
326369
{
370+
$x += $this->offset[0];
371+
$y += $this->offset[1];
372+
$z += $this->offset[2];
327373
$this->shapes[] = "ARC\n8\n{$this->layerName}\n10\n{$x}\n20\n{$y}\n30\n{$z}\n40\n{$radius}\n50\n{$startAngle}\n51\n{$endAngle}\n0\n";
328374
return $this;
329375
}
330376

331-
332-
/**
333-
* Add Ellipse to current layer.
334-
*
335-
* @return $this
336-
* @see http://www.autodesk.com/techpubs/autocad/acad2000/dxf/ellipse_dxf_06.htm
337-
*/
338-
// TODO todo...
339-
// public function addEllipse(/* ... */)
340-
// {
341-
//
342-
// return $this;
343-
// }
344-
345-
346377
/**
347378
* Add 2D polyline to current layer.
348379
* @param array[float] $points Points array: [x, y, x2, y2, x3, y3, ...]
@@ -356,6 +387,8 @@ public function addPolyline2d($points)
356387
$dots = "90\n" . ($count / 2 + 1) . "\n";
357388
$polyline = "LWPOLYLINE\n8\n{$this->layerName}\n{$dots}";
358389
for ($i=0; $i<$count; $i+=2) {
390+
$points[$i] += $this->offset[0];
391+
$points[$i+1] += $this->offset[1];
359392
$polyline .= "10\n{$points[$i]}\n20\n{$points[$i+1]}\n30\n0\n";
360393
}
361394
$this->shapes[] = $polyline . " 0\n";

0 commit comments

Comments
 (0)