1 | <?php |
||
10 | class SvgBuilder implements PlotBuilder |
||
11 | { |
||
12 | /** |
||
13 | * Current position. |
||
14 | */ |
||
15 | protected $x = 0; |
||
16 | protected $y = 0; |
||
17 | |||
18 | /** |
||
19 | * Extent of drawing |
||
20 | */ |
||
21 | protected $maxX = 0; |
||
22 | protected $maxY = 0; |
||
23 | |||
24 | protected $instructions = []; |
||
25 | |||
26 | protected $axesFlipped = false; |
||
27 | protected $penIsDown = true; |
||
28 | protected $tool = 'regular'; |
||
29 | protected $unit = 'mm'; |
||
30 | protected $scale = 0.1; |
||
31 | |||
32 | const TOOLS = [ |
||
33 | 0 => 'regular', |
||
34 | 6 => 'flex', |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * Adds a new plot of x and y to machine instructions. |
||
39 | */ |
||
40 | public function plot(int $x, int $y): PlotBuilder |
||
68 | |||
69 | /** |
||
70 | * Changes the pen of the plotter. |
||
71 | */ |
||
72 | public function changePen(int $pen): PlotBuilder |
||
78 | |||
79 | /** |
||
80 | * Compiles a string in target format with machine instructions. |
||
81 | */ |
||
82 | public function compile(): string |
||
109 | |||
110 | /** |
||
111 | * Pushes a command to the instructions. |
||
112 | * |
||
113 | * No effect in the SVG output. |
||
114 | */ |
||
115 | public function pushCommand(string $command): PlotBuilder |
||
119 | |||
120 | /** |
||
121 | * Lifts the pen up. |
||
122 | */ |
||
123 | public function penUp(): PlotBuilder |
||
129 | |||
130 | /** |
||
131 | * Pushes the pen down on paper. |
||
132 | */ |
||
133 | public function penDown(): PlotBuilder |
||
139 | |||
140 | /** |
||
141 | * Changes the plotter pen to use flexcut. |
||
142 | */ |
||
143 | public function flexCut(): PlotBuilder |
||
147 | |||
148 | /** |
||
149 | * Change to the regular plotter pen. |
||
150 | */ |
||
151 | public function regularCut(): PlotBuilder |
||
155 | |||
156 | /** |
||
157 | * Changes the pen pressure in gram. |
||
158 | * |
||
159 | * No effect in the SVG output. |
||
160 | */ |
||
161 | public function pressure(int $gramPressure): PlotBuilder |
||
165 | |||
166 | /** |
||
167 | * Specifies measuring unit. |
||
168 | * 1 selects 0.001 inch |
||
169 | * 5 selects 0.005 inch |
||
170 | * M selects 0.1 mm |
||
171 | * |
||
172 | * @throws Exception |
||
173 | */ |
||
174 | public function setMeasuringUnit($unit): PlotBuilder |
||
195 | |||
196 | /** |
||
197 | * Changes the plotter velocity. |
||
198 | * |
||
199 | * No effect in the SVG output. |
||
200 | */ |
||
201 | public function velocity(int $velocity): PlotBuilder |
||
205 | |||
206 | /** |
||
207 | * Flips the x, y coordinates. |
||
208 | */ |
||
209 | public function flipAxes(): PlotBuilder |
||
215 | |||
216 | /** |
||
217 | * Cuts off paper when a operation finishes. |
||
218 | * |
||
219 | * No effect in the SVG output. |
||
220 | */ |
||
221 | public function cutOff(): PlotBuilder |
||
225 | |||
226 | protected function pushInstruction(string $name, array $parameters): PlotBuilder |
||
236 | |||
237 | } |
||
238 |