10
10
* @since 2015/08
11
11
*
12
12
* @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
13
14
*
14
15
* @example <code>
15
16
* $dxf = new \adamasantares\dxf\Creator();
@@ -66,6 +67,11 @@ class Creator {
66
67
*/
67
68
private $ shapes = [];
68
69
70
+ /**
71
+ * @var array Center offser
72
+ */
73
+ private $ offset = [0 , 0 , 0 ];
74
+
69
75
70
76
/**
71
77
* Create new DXF document
@@ -174,6 +180,28 @@ public function getError()
174
180
}
175
181
176
182
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
+
177
205
/**
178
206
* Add new layer to document
179
207
* @param string $name
@@ -251,6 +279,9 @@ public function setLineType($lineType)
251
279
*/
252
280
public function addPoint ($ x , $ y , $ z )
253
281
{
282
+ $ x += $ this ->offset [0 ];
283
+ $ y += $ this ->offset [1 ];
284
+ $ z += $ this ->offset [2 ];
254
285
$ this ->shapes [] = "POINT \n8 \n{$ this ->layerName }\n100 \nAcDbPoint \n10 \n{$ x }\n20 \n{$ y }\n30 \n{$ z }\n0 \n" ;
255
286
return $ this ;
256
287
}
@@ -269,6 +300,12 @@ public function addPoint($x, $y, $z)
269
300
*/
270
301
public function addLine ($ x , $ y , $ z , $ x2 , $ y2 , $ z2 )
271
302
{
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 ];
272
309
$ 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" ;
273
310
return $ this ;
274
311
}
@@ -288,6 +325,9 @@ public function addLine($x, $y, $z, $x2, $y2, $z2)
288
325
*/
289
326
public function addText ($ x , $ y , $ z , $ text , $ textHeight , $ position = 7 , $ angle = 0 )
290
327
{
328
+ $ x += $ this ->offset [0 ];
329
+ $ y += $ this ->offset [1 ];
330
+ $ z += $ this ->offset [2 ];
291
331
$ angle = deg2rad ($ angle );
292
332
$ 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" ;
293
333
return $ this ;
@@ -305,6 +345,9 @@ public function addText($x, $y, $z, $text, $textHeight, $position = 7, $angle =
305
345
*/
306
346
public function addCircle ($ x , $ y , $ z , $ radius )
307
347
{
348
+ $ x += $ this ->offset [0 ];
349
+ $ y += $ this ->offset [1 ];
350
+ $ z += $ this ->offset [2 ];
308
351
$ this ->shapes [] = "CIRCLE \n8 \n{$ this ->layerName }\n10 \n{$ x }\n20 \n{$ y }\n30 \n{$ z }\n40 \n{$ radius }\n0 \n" ;
309
352
return $ this ;
310
353
}
@@ -324,25 +367,13 @@ public function addCircle($x, $y, $z, $radius)
324
367
*/
325
368
public function addArc ($ x , $ y , $ z , $ radius , $ startAngle = 0.1 , $ endAngle = 90.0 )
326
369
{
370
+ $ x += $ this ->offset [0 ];
371
+ $ y += $ this ->offset [1 ];
372
+ $ z += $ this ->offset [2 ];
327
373
$ 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" ;
328
374
return $ this ;
329
375
}
330
376
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
-
346
377
/**
347
378
* Add 2D polyline to current layer.
348
379
* @param array[float] $points Points array: [x, y, x2, y2, x3, y3, ...]
@@ -356,6 +387,8 @@ public function addPolyline2d($points)
356
387
$ dots = "90 \n" . ($ count / 2 + 1 ) . "\n" ;
357
388
$ polyline = "LWPOLYLINE \n8 \n{$ this ->layerName }\n{$ dots }" ;
358
389
for ($ i =0 ; $ i <$ count ; $ i +=2 ) {
390
+ $ points [$ i ] += $ this ->offset [0 ];
391
+ $ points [$ i +1 ] += $ this ->offset [1 ];
359
392
$ polyline .= "10 \n{$ points [$ i ]}\n20 \n{$ points [$ i +1 ]}\n30 \n0 \n" ;
360
393
}
361
394
$ this ->shapes [] = $ polyline . " 0 \n" ;
0 commit comments