BlueGit

timfa timdraw

feat: startscript, verschoven blad en stip bij joggen

start-server.sh start de backend en opent de pagina. Het A4 ligt van (-10, 4) tot (190, -293), met de rode wagenlijn van (0, 0) tot (200, -297). De stip blijft zichtbaar en glijdt mee bij joggen.

timfa Tim Falken · pushed by timfa

Authored 2026-09-29 · 7 weeks ago

Hash
10e8f7e7755eadb891eca247aa81fa47030b4643
Parent
c87e0249
6 files changed +157 −42
start-server.sh added +44 −0
@@ -0,0 +1,44 @@
1 #!/usr/bin/env bash
2 # Start de Timdraw-backend en open de pagina in de browser.
3 set -euo pipefail
4 cd "$(dirname "$0")"
5
6 pick_url() {
7 if curl -sf -o /dev/null --max-time 1 "http://timdraw.localhost/"; then
8 echo "http://timdraw.localhost/"
9 else
10 echo "http://127.0.0.1:8765/"
11 fi
12 }
13
14 open_page() {
15 local url
16 url="$(pick_url)"
17 echo "Timdraw staat op $url"
18 if command -v xdg-open >/dev/null 2>&1; then
19 xdg-open "$url" >/dev/null 2>&1 || true
20 fi
21 }
22
23 if curl -sf -o /dev/null --max-time 1 "http://127.0.0.1:8765/"; then
24 open_page
25 exit 0
26 fi
27
28 python3 -m timdraw &
29 server_pid=$!
30 trap 'kill "$server_pid" 2>/dev/null || true' INT TERM
31
32 for _ in $(seq 1 50); do
33 if ! kill -0 "$server_pid" 2>/dev/null; then
34 wait "$server_pid"
35 exit $?
36 fi
37 if curl -sf -o /dev/null --max-time 1 "http://127.0.0.1:8765/"; then
38 open_page
39 break
40 fi
41 sleep 0.1
42 done
43
44 wait "$server_pid"
@@ -0,0 +1,44 @@
1#!/usr/bin/env bash
2# Start de Timdraw-backend en open de pagina in de browser.
3set -euo pipefail
4cd "$(dirname "$0")"
5
6pick_url() {
7 if curl -sf -o /dev/null --max-time 1 "http://timdraw.localhost/"; then
8 echo "http://timdraw.localhost/"
9 else
10 echo "http://127.0.0.1:8765/"
11 fi
12}
13
14open_page() {
15 local url
16 url="$(pick_url)"
17 echo "Timdraw staat op $url"
18 if command -v xdg-open >/dev/null 2>&1; then
19 xdg-open "$url" >/dev/null 2>&1 || true
20 fi
21}
22
23if curl -sf -o /dev/null --max-time 1 "http://127.0.0.1:8765/"; then
24 open_page
25 exit 0
26fi
27
28python3 -m timdraw &
29server_pid=$!
30trap 'kill "$server_pid" 2>/dev/null || true' INT TERM
31
32for _ in $(seq 1 50); do
33 if ! kill -0 "$server_pid" 2>/dev/null; then
34 wait "$server_pid"
35 exit $?
36 fi
37 if curl -sf -o /dev/null --max-time 1 "http://127.0.0.1:8765/"; then
38 open_page
39 break
40 fi
41 sleep 0.1
42done
43
44wait "$server_pid"
static/app.js +98 −30
@@ -1,7 +1,10 @@
1 1 const PAPER_LEFT = -10;
2 2 const PAPER_TOP = 4;
3 const PAPER_BOTTOM = -297;
4 const A4W = 210;
3 const PAPER_RIGHT = 190;
4 const PAPER_BOTTOM = -293;
5 const BED_W = 200;
6 const BED_H = 297;
7 const A4W = PAPER_RIGHT - PAPER_LEFT;
5 8 const A4H = PAPER_TOP - PAPER_BOTTOM;
6 9 const PEN_MM = 0.4;
7 10
@@ -132,17 +135,27 @@ function layout ()
132 135 {
133 136 const rect = canvas.getBoundingClientRect();
134 137 const margin = 28;
135 const fit = Math.min((rect.width - margin * 2) / A4W, (rect.height - margin * 2) / A4H);
138 const span = viewSpan();
139 const fit = Math.min((rect.width - margin * 2) / span.w, (rect.height - margin * 2) / span.h);
136 140 const scale = fit * zoom;
137 141 return {
138 142 scale,
139 ox: (rect.width - A4W * scale) / 2 + panX,
140 oy: (rect.height - A4H * scale) / 2 + panY,
143 ox: (rect.width - span.w * scale) / 2 + panX,
144 oy: (rect.height - span.h * scale) / 2 + panY,
141 145 width: rect.width,
142 146 height: rect.height,
143 147 };
144 148 }
145 149
150 function viewSpan ()
151 {
152 const far = pageFromMachine(BED_W, -BED_H);
153 return {
154 w: Math.max(A4W, far.x) - Math.min(0, far.x),
155 h: Math.max(A4H, far.y) - Math.min(0, far.y),
156 };
157 }
158
146 159 function mmToPx (x, y)
147 160 {
148 161 const view = layout();
@@ -226,12 +239,9 @@ function drawSheet (view)
226 239 ctx.fillStyle = "#f6f1e6";
227 240 ctx.fillRect(x, y, w, h);
228 241 ctx.fillStyle = "rgba(70, 52, 36, 0.16)";
229 const reachLeft = -PAPER_LEFT;
230 const reachTop = A4H - PAPER_TOP;
231 const reachBottom = -PAPER_BOTTOM - 297;
232 fillMmRect(0, 0, reachLeft, A4H);
233 fillMmRect(reachLeft, reachTop, A4W, A4H);
234 fillMmRect(reachLeft, 0, A4W, reachBottom);
242 const home = pageFromMachine(0, 0);
243 fillMmRect(0, 0, home.x, A4H);
244 fillMmRect(home.x, home.y, A4W, A4H);
235 245 ctx.strokeStyle = "rgba(80,60,40,0.18)";
236 246 ctx.lineWidth = 1;
237 247 ctx.beginPath();
@@ -253,10 +263,22 @@ function drawSheet (view)
253 263 ctx.strokeStyle = "#2b241e";
254 264 ctx.lineWidth = 1.5;
255 265 ctx.strokeRect(x, y, w, h);
266 const frameHome = pageFromMachine(0, 0);
267 const frameFar = pageFromMachine(BED_W, -BED_H);
268 const frameA = mmToPx(frameHome.x, frameHome.y);
269 const frameB = mmToPx(frameFar.x, frameFar.y);
270 ctx.strokeStyle = "#d7263d";
271 ctx.lineWidth = 1.5;
272 ctx.strokeRect(
273 Math.min(frameA[0], frameB[0]),
274 Math.min(frameA[1], frameB[1]),
275 Math.abs(frameB[0] - frameA[0]),
276 Math.abs(frameB[1] - frameA[1]),
277 );
256 278 ctx.fillStyle = "#8a7b6c";
257 279 ctx.font = "12px Liberation Sans, sans-serif";
258 280 const originTop = $("origin").value === "top-left";
259 const zero = originTop ? mmToPx(reachLeft, reachTop) : mmToPx(0, 0);
281 const zero = originTop ? mmToPx(frameHome.x, frameHome.y) : mmToPx(0, 0);
260 282 ctx.fillText("0,0", zero[0] + 6, zero[1] + (originTop ? 16 : -8));
261 283 ctx.fillText("A4", x + w - 26, y + h - 8);
262 284 ctx.restore();
@@ -412,25 +434,66 @@ function showPen (page, speed)
412 434 penGoal = length;
413 435 }
414 436
437 function ensurePenLoop ()
438 {
439 if (penFrame) return;
440 penStamp = 0;
441 penFrame = requestAnimationFrame(tickPen);
442 }
443
415 444 function tickPen (now)
416 445 {
417 if (!penJob)
446 if (!penGuide)
418 447 {
419 448 penFrame = 0;
420 449 return;
421 450 }
422 451 penFrame = requestAnimationFrame(tickPen);
423 if (!penGuide) return;
424 452 const dt = penStamp ? Math.min(0.05, (now - penStamp) / 1000) : 0;
425 453 penStamp = now;
454 if (Math.abs(penGoal - penAlong) < 0.02)
455 {
456 penAlong = penGoal;
457 const arrived = penAt(penGuide, penAlong);
458 pen = { x: arrived[0], y: arrived[1] };
459 if (!penJob) penGuide = null;
460 if (!drag) draw();
461 return;
462 }
463 if (dt <= 0) return;
426 464 const next = penStep(penAlong, penGoal, penSpeed, dt);
427 if (Math.abs(next - penAlong) < 1e-4) return;
428 465 penAlong = next;
429 466 const point = penAt(penGuide, penAlong);
430 467 pen = { x: point[0], y: point[1] };
431 468 if (!drag) draw();
432 469 }
433 470
471 function placePen (page)
472 {
473 penJob = false;
474 penRoute = null;
475 penDraw = null;
476 penSpeed = Number($("travel-speed").value) || 5000;
477 if (!pen)
478 {
479 pen = page;
480 penGuide = null;
481 return true;
482 }
483 const length = Math.hypot(page.x - pen.x, page.y - pen.y);
484 if (length < 0.05)
485 {
486 pen = page;
487 return false;
488 }
489 penGuide = { pts: [[pen.x, pen.y], [page.x, page.y]], cum: [0, length] };
490 penAlong = 0;
491 penGoal = length;
492 penHint = 0;
493 ensurePenLoop();
494 return true;
495 }
496
434 497 function startPenJob (page, speed)
435 498 {
436 499 penJob = true;
@@ -464,11 +527,7 @@ function startPenJob (page, speed)
464 527 penGoal = 0;
465 528 penHint = 0;
466 529 }
467 if (!penFrame)
468 {
469 penStamp = 0;
470 penFrame = requestAnimationFrame(tickPen);
471 }
530 ensurePenLoop();
472 531 }
473 532
474 533 function stopPenJob ()
@@ -1058,6 +1117,7 @@ async function machineCall (path, body, confirmText)
1058 1117 {
1059 1118 toast("");
1060 1119 const result = await api(path, body || {});
1120 if (result && result.wpos) paintStatus(result);
1061 1121 if (result && result.notice) toast(result.notice, 5000);
1062 1122 } catch (error)
1063 1123 {
@@ -1227,16 +1287,24 @@ function paintStatus (status)
1227 1287 }
1228 1288 const progress = status.jobActive ? (status.progress || 0) : (status.progress === 1 ? 1 : 0);
1229 1289 $("bar").style.width = `${Math.round((progress || 0) * 100)}%`;
1230 if (status.jobActive && status.wpos)
1231 {
1232 const page = pageFromMachine(status.wpos[0], status.wpos[1]);
1233 const down = Number($("pen-down").value);
1234 const up = Number($("pen-up").value);
1235 const drawing = Math.abs(status.wpos[2] - down) <= Math.abs(status.wpos[2] - up);
1236 const speed = drawing ? Number($("draw-speed").value) : Number($("travel-speed").value);
1237 if (!penJob) startPenJob(page, speed);
1238 else showPen(page, speed);
1239 if (!drag) draw();
1290 if (status.connected && status.wpos)
1291 {
1292 const xy = !status.jobActive && status.target ? status.target : status.wpos;
1293 const page = pageFromMachine(xy[0], xy[1]);
1294 if (status.jobActive)
1295 {
1296 const down = Number($("pen-down").value);
1297 const up = Number($("pen-up").value);
1298 const drawing = Math.abs(status.wpos[2] - down) <= Math.abs(status.wpos[2] - up);
1299 const speed = drawing ? Number($("draw-speed").value) : Number($("travel-speed").value);
1300 if (!penJob) startPenJob(page, speed);
1301 else showPen(page, speed);
1302 if (!drag) draw();
1303 }
1304 else if (placePen(page) && !drag)
1305 {
1306 draw();
1307 }
1240 1308 }
1241 1309 else if (penJob || pen)
1242 1310 {
@@ -1,7 +1,10 @@
1const PAPER_LEFT = -10;
1const PAPER_LEFT = -10;
2const PAPER_TOP = 4;
2const PAPER_TOP = 4;
3const PAPER_BOTTOM = -297;
3const PAPER_RIGHT = 190;
4const A4W = 210;
4const PAPER_BOTTOM = -293;
5const BED_W = 200;
6const BED_H = 297;
7const A4W = PAPER_RIGHT - PAPER_LEFT;
5const A4H = PAPER_TOP - PAPER_BOTTOM;
8const A4H = PAPER_TOP - PAPER_BOTTOM;
6const PEN_MM = 0.4;
9const PEN_MM = 0.4;
7
10
@@ -132,17 +135,27 @@ function layout ()
132{
135{
133 const rect = canvas.getBoundingClientRect();
136 const rect = canvas.getBoundingClientRect();
134 const margin = 28;
137 const margin = 28;
135 const fit = Math.min((rect.width - margin * 2) / A4W, (rect.height - margin * 2) / A4H);
138 const span = viewSpan();
139 const fit = Math.min((rect.width - margin * 2) / span.w, (rect.height - margin * 2) / span.h);
136 const scale = fit * zoom;
140 const scale = fit * zoom;
137 return {
141 return {
138 scale,
142 scale,
139 ox: (rect.width - A4W * scale) / 2 + panX,
143 ox: (rect.width - span.w * scale) / 2 + panX,
140 oy: (rect.height - A4H * scale) / 2 + panY,
144 oy: (rect.height - span.h * scale) / 2 + panY,
141 width: rect.width,
145 width: rect.width,
142 height: rect.height,
146 height: rect.height,
143 };
147 };
144}
148}
145
149
150function viewSpan ()
151{
152 const far = pageFromMachine(BED_W, -BED_H);
153 return {
154 w: Math.max(A4W, far.x) - Math.min(0, far.x),
155 h: Math.max(A4H, far.y) - Math.min(0, far.y),
156 };
157}
158
146function mmToPx (x, y)
159function mmToPx (x, y)
147{
160{
148 const view = layout();
161 const view = layout();
@@ -226,12 +239,9 @@ function drawSheet (view)
226 ctx.fillStyle = "#f6f1e6";
239 ctx.fillStyle = "#f6f1e6";
227 ctx.fillRect(x, y, w, h);
240 ctx.fillRect(x, y, w, h);
228 ctx.fillStyle = "rgba(70, 52, 36, 0.16)";
241 ctx.fillStyle = "rgba(70, 52, 36, 0.16)";
229 const reachLeft = -PAPER_LEFT;
242 const home = pageFromMachine(0, 0);
230 const reachTop = A4H - PAPER_TOP;
243 fillMmRect(0, 0, home.x, A4H);
231 const reachBottom = -PAPER_BOTTOM - 297;
244 fillMmRect(home.x, home.y, A4W, A4H);
232 fillMmRect(0, 0, reachLeft, A4H);
233 fillMmRect(reachLeft, reachTop, A4W, A4H);
234 fillMmRect(reachLeft, 0, A4W, reachBottom);
235 ctx.strokeStyle = "rgba(80,60,40,0.18)";
245 ctx.strokeStyle = "rgba(80,60,40,0.18)";
236 ctx.lineWidth = 1;
246 ctx.lineWidth = 1;
237 ctx.beginPath();
247 ctx.beginPath();
@@ -253,10 +263,22 @@ function drawSheet (view)
253 ctx.strokeStyle = "#2b241e";
263 ctx.strokeStyle = "#2b241e";
254 ctx.lineWidth = 1.5;
264 ctx.lineWidth = 1.5;
255 ctx.strokeRect(x, y, w, h);
265 ctx.strokeRect(x, y, w, h);
266 const frameHome = pageFromMachine(0, 0);
267 const frameFar = pageFromMachine(BED_W, -BED_H);
268 const frameA = mmToPx(frameHome.x, frameHome.y);
269 const frameB = mmToPx(frameFar.x, frameFar.y);
270 ctx.strokeStyle = "#d7263d";
271 ctx.lineWidth = 1.5;
272 ctx.strokeRect(
273 Math.min(frameA[0], frameB[0]),
274 Math.min(frameA[1], frameB[1]),
275 Math.abs(frameB[0] - frameA[0]),
276 Math.abs(frameB[1] - frameA[1]),
277 );
256 ctx.fillStyle = "#8a7b6c";
278 ctx.fillStyle = "#8a7b6c";
257 ctx.font = "12px Liberation Sans, sans-serif";
279 ctx.font = "12px Liberation Sans, sans-serif";
258 const originTop = $("origin").value === "top-left";
280 const originTop = $("origin").value === "top-left";
259 const zero = originTop ? mmToPx(reachLeft, reachTop) : mmToPx(0, 0);
281 const zero = originTop ? mmToPx(frameHome.x, frameHome.y) : mmToPx(0, 0);
260 ctx.fillText("0,0", zero[0] + 6, zero[1] + (originTop ? 16 : -8));
282 ctx.fillText("0,0", zero[0] + 6, zero[1] + (originTop ? 16 : -8));
261 ctx.fillText("A4", x + w - 26, y + h - 8);
283 ctx.fillText("A4", x + w - 26, y + h - 8);
262 ctx.restore();
284 ctx.restore();
@@ -412,25 +434,66 @@ function showPen (page, speed)
412 penGoal = length;
434 penGoal = length;
413}
435}
414
436
437function ensurePenLoop ()
438{
439 if (penFrame) return;
440 penStamp = 0;
441 penFrame = requestAnimationFrame(tickPen);
442}
443
415function tickPen (now)
444function tickPen (now)
416{
445{
417 if (!penJob)
446 if (!penGuide)
418 {
447 {
419 penFrame = 0;
448 penFrame = 0;
420 return;
449 return;
421 }
450 }
422 penFrame = requestAnimationFrame(tickPen);
451 penFrame = requestAnimationFrame(tickPen);
423 if (!penGuide) return;
424 const dt = penStamp ? Math.min(0.05, (now - penStamp) / 1000) : 0;
452 const dt = penStamp ? Math.min(0.05, (now - penStamp) / 1000) : 0;
425 penStamp = now;
453 penStamp = now;
454 if (Math.abs(penGoal - penAlong) < 0.02)
455 {
456 penAlong = penGoal;
457 const arrived = penAt(penGuide, penAlong);
458 pen = { x: arrived[0], y: arrived[1] };
459 if (!penJob) penGuide = null;
460 if (!drag) draw();
461 return;
462 }
463 if (dt <= 0) return;
426 const next = penStep(penAlong, penGoal, penSpeed, dt);
464 const next = penStep(penAlong, penGoal, penSpeed, dt);
427 if (Math.abs(next - penAlong) < 1e-4) return;
428 penAlong = next;
465 penAlong = next;
429 const point = penAt(penGuide, penAlong);
466 const point = penAt(penGuide, penAlong);
430 pen = { x: point[0], y: point[1] };
467 pen = { x: point[0], y: point[1] };
431 if (!drag) draw();
468 if (!drag) draw();
432}
469}
433
470
471function placePen (page)
472{
473 penJob = false;
474 penRoute = null;
475 penDraw = null;
476 penSpeed = Number($("travel-speed").value) || 5000;
477 if (!pen)
478 {
479 pen = page;
480 penGuide = null;
481 return true;
482 }
483 const length = Math.hypot(page.x - pen.x, page.y - pen.y);
484 if (length < 0.05)
485 {
486 pen = page;
487 return false;
488 }
489 penGuide = { pts: [[pen.x, pen.y], [page.x, page.y]], cum: [0, length] };
490 penAlong = 0;
491 penGoal = length;
492 penHint = 0;
493 ensurePenLoop();
494 return true;
495}
496
434function startPenJob (page, speed)
497function startPenJob (page, speed)
435{
498{
436 penJob = true;
499 penJob = true;
@@ -464,11 +527,7 @@ function startPenJob (page, speed)
464 penGoal = 0;
527 penGoal = 0;
465 penHint = 0;
528 penHint = 0;
466 }
529 }
467 if (!penFrame)
530 ensurePenLoop();
468 {
469 penStamp = 0;
470 penFrame = requestAnimationFrame(tickPen);
471 }
472}
531}
473
532
474function stopPenJob ()
533function stopPenJob ()
@@ -1058,6 +1117,7 @@ async function machineCall (path, body, confirmText)
1058 {
1117 {
1059 toast("");
1118 toast("");
1060 const result = await api(path, body || {});
1119 const result = await api(path, body || {});
1120 if (result && result.wpos) paintStatus(result);
1061 if (result && result.notice) toast(result.notice, 5000);
1121 if (result && result.notice) toast(result.notice, 5000);
1062 } catch (error)
1122 } catch (error)
1063 {
1123 {
@@ -1227,16 +1287,24 @@ function paintStatus (status)
1227 }
1287 }
1228 const progress = status.jobActive ? (status.progress || 0) : (status.progress === 1 ? 1 : 0);
1288 const progress = status.jobActive ? (status.progress || 0) : (status.progress === 1 ? 1 : 0);
1229 $("bar").style.width = `${Math.round((progress || 0) * 100)}%`;
1289 $("bar").style.width = `${Math.round((progress || 0) * 100)}%`;
1230 if (status.jobActive && status.wpos)
1290 if (status.connected && status.wpos)
1231 {
1291 {
1232 const page = pageFromMachine(status.wpos[0], status.wpos[1]);
1292 const xy = !status.jobActive && status.target ? status.target : status.wpos;
1233 const down = Number($("pen-down").value);
1293 const page = pageFromMachine(xy[0], xy[1]);
1234 const up = Number($("pen-up").value);
1294 if (status.jobActive)
1235 const drawing = Math.abs(status.wpos[2] - down) <= Math.abs(status.wpos[2] - up);
1295 {
1236 const speed = drawing ? Number($("draw-speed").value) : Number($("travel-speed").value);
1296 const down = Number($("pen-down").value);
1237 if (!penJob) startPenJob(page, speed);
1297 const up = Number($("pen-up").value);
1238 else showPen(page, speed);
1298 const drawing = Math.abs(status.wpos[2] - down) <= Math.abs(status.wpos[2] - up);
1239 if (!drag) draw();
1299 const speed = drawing ? Number($("draw-speed").value) : Number($("travel-speed").value);
1300 if (!penJob) startPenJob(page, speed);
1301 else showPen(page, speed);
1302 if (!drag) draw();
1303 }
1304 else if (placePen(page) && !drag)
1305 {
1306 draw();
1307 }
1240 }
1308 }
1241 else if (penJob || pen)
1309 else if (penJob || pen)
1242 {
1310 {
timdraw/gcode.py +1 −1
@@ -32,7 +32,7 @@ def _clamp(value: float, low: float, high: float) -> float:
32 32 return max(low, min(high, value))
33 33
34 34
35 # Bereik na homing, met het nulpunt linksboven. De papierbreedte is 210, de wagen haalt 200.
35 # Bereik na homing, met het nulpunt linksboven. De wagen haalt X 0..200 en Y 0..-297.
36 36 BED_W = 200.0
37 37 BED_H = 297.0
38 38
@@ -32,7 +32,7 @@ def _clamp(value: float, low: float, high: float) -> float:
32 return max(low, min(high, value))
32 return max(low, min(high, value))
33
33
34
34
35# Bereik na homing, met het nulpunt linksboven. De papierbreedte is 210, de wagen haalt 200.
35# Bereik na homing, met het nulpunt linksboven. De wagen haalt X 0..200 en Y 0..-297.
36BED_W = 200.0
36BED_W = 200.0
37BED_H = 297.0
37BED_H = 297.0
38
38
timdraw/geom.py +4 −4
@@ -8,12 +8,12 @@ Point = tuple[float, float]
8 8 Polyline = list[Point]
9 9
10 10 # Fysiek papier t.o.v. machinehome. Y omhoog is positief.
11 # De linkerrand ligt 10 mm links van X=0, de bovenrand 4 mm boven Y=0.
12 # X=200 valt op de rechterrand. Y=-297 valt op de onderrand.
11 # Het blad loopt van X=-10, Y=4 tot X=190, Y=-293.
12 # De wagen loopt van X=0, Y=0 tot X=200, Y=-297 en valt daar niet mee samen.
13 13 PAPER_LEFT = -10.0
14 14 PAPER_TOP = 4.0
15 PAPER_RIGHT = 200.0
16 PAPER_BOTTOM = -297.0
15 PAPER_RIGHT = 190.0
16 PAPER_BOTTOM = -293.0
17 17 A4_W = PAPER_RIGHT - PAPER_LEFT
18 18 A4_H = PAPER_TOP - PAPER_BOTTOM
19 19
@@ -8,12 +8,12 @@ Point = tuple[float, float]
8Polyline = list[Point]
8Polyline = list[Point]
9
9
10# Fysiek papier t.o.v. machinehome. Y omhoog is positief.
10# Fysiek papier t.o.v. machinehome. Y omhoog is positief.
11# De linkerrand ligt 10 mm links van X=0, de bovenrand 4 mm boven Y=0.
11# Het blad loopt van X=-10, Y=4 tot X=190, Y=-293.
12# X=200 valt op de rechterrand. Y=-297 valt op de onderrand.
12# De wagen loopt van X=0, Y=0 tot X=200, Y=-297 en valt daar niet mee samen.
13PAPER_LEFT = -10.0
13PAPER_LEFT = -10.0
14PAPER_TOP = 4.0
14PAPER_TOP = 4.0
15PAPER_RIGHT = 200.0
15PAPER_RIGHT = 190.0
16PAPER_BOTTOM = -297.0
16PAPER_BOTTOM = -293.0
17A4_W = PAPER_RIGHT - PAPER_LEFT
17A4_W = PAPER_RIGHT - PAPER_LEFT
18A4_H = PAPER_TOP - PAPER_BOTTOM
18A4_H = PAPER_TOP - PAPER_BOTTOM
19
19
timdraw/grbl.py +1 −0
@@ -171,6 +171,7 @@ class Machine:
171 171 "state": self.state,
172 172 "wpos": list(self.wpos),
173 173 "mpos": list(self.mpos),
174 "target": list(self._track_xy) if self._track_xy and time.time() < self._track_until else None,
174 175 "message": self.message,
175 176 "error": self.error,
176 177 "progress": self.progress if self.job_active else None,
@@ -171,6 +171,7 @@ class Machine:
171 "state": self.state,
171 "state": self.state,
172 "wpos": list(self.wpos),
172 "wpos": list(self.wpos),
173 "mpos": list(self.mpos),
173 "mpos": list(self.mpos),
174 "target": list(self._track_xy) if self._track_xy and time.time() < self._track_until else None,
174 "message": self.message,
175 "message": self.message,
175 "error": self.error,
176 "error": self.error,
176 "progress": self.progress if self.job_active else None,
177 "progress": self.progress if self.job_active else None,
timdraw/selftest.py +9 −7
@@ -10,7 +10,7 @@ import subprocess
10 10 import time
11 11
12 12 from timdraw.font import render_text
13 from timdraw.gcode import plan
13 from timdraw.gcode import _page_point, plan
14 14 from timdraw.grbl import chord_for_arc, limit_step, resolve_work_position
15 15 from timdraw.geom import arc_points, bounds, dist, fit_arcs, grbl_arc_ok
16 16 from timdraw.svgimport import import_svg
@@ -81,10 +81,12 @@ def test_text_and_gcode() -> None:
81 81 check("grijswaarden tekenen", gray_job["stats"]["drawMm"] > 100, str(gray_job["stats"]))
82 82 corner = plan([{
83 83 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
84 "strokes": [{"pts": [(10, 297), (30, 277)]}],
84 "strokes": [{"pts": [(10, 293), (30, 273)]}],
85 85 }], {"origin": "top-left"})
86 86 check("homehoek blijft X0 Y0", "X0.000 Y0.000" in corner["gcode"], corner["gcode"])
87 87 check("blad ligt rechts en onder het nulpunt", "X20.000 Y-20.000" in corner["gcode"])
88 check("papierrand linksboven", _page_point(0, 297, True) == (-10.0, 4.0), str(_page_point(0, 297, True)))
89 check("papierrand rechtsonder", _page_point(200, 0, True) == (190.0, -293.0), str(_page_point(200, 0, True)))
88 90 check("pen gebruikt verplaatsingssnelheid", "G1 Z5.000 F4000" in planned["gcode"])
89 91 check("pen omhoog houdt de as vast", "G1 Z0.000" in planned["gcode"] and "$1=25\n" not in planned["gcode"])
90 92 check("pen omlaag vergrendelt", "$1=255\nG1 Z5.000" in planned["gcode"])
@@ -92,8 +94,8 @@ def test_text_and_gcode() -> None:
92 94 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
93 95 "strokes": [
94 96 {"pts": [(110, 110), (130, 110)]},
95 {"pts": [(20, 297), (10, 297)]},
96 {"pts": [(20, 287), (20, 297)]},
97 {"pts": [(20, 293), (10, 293)]},
98 {"pts": [(20, 283), (20, 293)]},
97 99 ],
98 100 }], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})
99 101 moves = [line for line in linked["gcode"].splitlines() if line.startswith("G1 X")]
@@ -105,7 +107,7 @@ def test_text_and_gcode() -> None:
105 107 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
106 108 "strokes": [{"pts": [(110, 110), (130, 110)]}]},
107 109 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
108 "strokes": [{"pts": [(10, 297), (30, 297)]}]},
110 "strokes": [{"pts": [(10, 293), (30, 293)]}]},
109 111 ], {"origin": "top-left", "perObject": True, "returnHome": False, "travelSpeed": 4000})
110 112 grouped_moves = [line for line in grouped["gcode"].splitlines() if line.startswith("G1 X")]
111 113 check("eerst het eerste object", "X100.000" in grouped_moves[0], " | ".join(grouped_moves[:3]))
@@ -113,7 +115,7 @@ def test_text_and_gcode() -> None:
113 115 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
114 116 "strokes": [{"pts": [(110, 110), (130, 110)]}]},
115 117 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
116 "strokes": [{"pts": [(10, 297), (30, 297)]}]},
118 "strokes": [{"pts": [(10, 293), (30, 293)]}]},
117 119 ], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})
118 120 mixed_moves = [line for line in mixed["gcode"].splitlines() if line.startswith("G1 X")]
119 121 check("zonder groeperen de dichtstbijzijnde", mixed_moves[0].startswith("G1 X0.000 Y0.000"), " | ".join(mixed_moves[:2]))
@@ -296,7 +298,7 @@ def test_virtual_machine() -> None:
296 298 try:
297 299 corner = plan([{
298 300 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
299 "strokes": [{"pts": [(10, 297), (30, 277)]}],
301 "strokes": [{"pts": [(10, 293), (30, 273)]}],
300 302 }], {"origin": "top-left"})
301 303 gcode = corner["gcode"] + "\nG3 X30.000 Y-20.000 I0.000 J10.000 F3000\n"
302 304 machine.start_job(gcode)
@@ -10,7 +10,7 @@ import subprocess
10import time
10import time
11
11
12from timdraw.font import render_text
12from timdraw.font import render_text
13from timdraw.gcode import plan
13from timdraw.gcode import _page_point, plan
14from timdraw.grbl import chord_for_arc, limit_step, resolve_work_position
14from timdraw.grbl import chord_for_arc, limit_step, resolve_work_position
15from timdraw.geom import arc_points, bounds, dist, fit_arcs, grbl_arc_ok
15from timdraw.geom import arc_points, bounds, dist, fit_arcs, grbl_arc_ok
16from timdraw.svgimport import import_svg
16from timdraw.svgimport import import_svg
@@ -81,10 +81,12 @@ def test_text_and_gcode() -> None:
81 check("grijswaarden tekenen", gray_job["stats"]["drawMm"] > 100, str(gray_job["stats"]))
81 check("grijswaarden tekenen", gray_job["stats"]["drawMm"] > 100, str(gray_job["stats"]))
82 corner = plan([{
82 corner = plan([{
83 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
83 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
84 "strokes": [{"pts": [(10, 297), (30, 277)]}],
84 "strokes": [{"pts": [(10, 293), (30, 273)]}],
85 }], {"origin": "top-left"})
85 }], {"origin": "top-left"})
86 check("homehoek blijft X0 Y0", "X0.000 Y0.000" in corner["gcode"], corner["gcode"])
86 check("homehoek blijft X0 Y0", "X0.000 Y0.000" in corner["gcode"], corner["gcode"])
87 check("blad ligt rechts en onder het nulpunt", "X20.000 Y-20.000" in corner["gcode"])
87 check("blad ligt rechts en onder het nulpunt", "X20.000 Y-20.000" in corner["gcode"])
88 check("papierrand linksboven", _page_point(0, 297, True) == (-10.0, 4.0), str(_page_point(0, 297, True)))
89 check("papierrand rechtsonder", _page_point(200, 0, True) == (190.0, -293.0), str(_page_point(200, 0, True)))
88 check("pen gebruikt verplaatsingssnelheid", "G1 Z5.000 F4000" in planned["gcode"])
90 check("pen gebruikt verplaatsingssnelheid", "G1 Z5.000 F4000" in planned["gcode"])
89 check("pen omhoog houdt de as vast", "G1 Z0.000" in planned["gcode"] and "$1=25\n" not in planned["gcode"])
91 check("pen omhoog houdt de as vast", "G1 Z0.000" in planned["gcode"] and "$1=25\n" not in planned["gcode"])
90 check("pen omlaag vergrendelt", "$1=255\nG1 Z5.000" in planned["gcode"])
92 check("pen omlaag vergrendelt", "$1=255\nG1 Z5.000" in planned["gcode"])
@@ -92,8 +94,8 @@ def test_text_and_gcode() -> None:
92 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
94 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
93 "strokes": [
95 "strokes": [
94 {"pts": [(110, 110), (130, 110)]},
96 {"pts": [(110, 110), (130, 110)]},
95 {"pts": [(20, 297), (10, 297)]},
97 {"pts": [(20, 293), (10, 293)]},
96 {"pts": [(20, 287), (20, 297)]},
98 {"pts": [(20, 283), (20, 293)]},
97 ],
99 ],
98 }], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})
100 }], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})
99 moves = [line for line in linked["gcode"].splitlines() if line.startswith("G1 X")]
101 moves = [line for line in linked["gcode"].splitlines() if line.startswith("G1 X")]
@@ -105,7 +107,7 @@ def test_text_and_gcode() -> None:
105 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
107 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
106 "strokes": [{"pts": [(110, 110), (130, 110)]}]},
108 "strokes": [{"pts": [(110, 110), (130, 110)]}]},
107 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
109 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
108 "strokes": [{"pts": [(10, 297), (30, 297)]}]},
110 "strokes": [{"pts": [(10, 293), (30, 293)]}]},
109 ], {"origin": "top-left", "perObject": True, "returnHome": False, "travelSpeed": 4000})
111 ], {"origin": "top-left", "perObject": True, "returnHome": False, "travelSpeed": 4000})
110 grouped_moves = [line for line in grouped["gcode"].splitlines() if line.startswith("G1 X")]
112 grouped_moves = [line for line in grouped["gcode"].splitlines() if line.startswith("G1 X")]
111 check("eerst het eerste object", "X100.000" in grouped_moves[0], " | ".join(grouped_moves[:3]))
113 check("eerst het eerste object", "X100.000" in grouped_moves[0], " | ".join(grouped_moves[:3]))
@@ -113,7 +115,7 @@ def test_text_and_gcode() -> None:
113 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
115 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
114 "strokes": [{"pts": [(110, 110), (130, 110)]}]},
116 "strokes": [{"pts": [(110, 110), (130, 110)]}]},
115 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
117 {"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
116 "strokes": [{"pts": [(10, 297), (30, 297)]}]},
118 "strokes": [{"pts": [(10, 293), (30, 293)]}]},
117 ], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})
119 ], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})
118 mixed_moves = [line for line in mixed["gcode"].splitlines() if line.startswith("G1 X")]
120 mixed_moves = [line for line in mixed["gcode"].splitlines() if line.startswith("G1 X")]
119 check("zonder groeperen de dichtstbijzijnde", mixed_moves[0].startswith("G1 X0.000 Y0.000"), " | ".join(mixed_moves[:2]))
121 check("zonder groeperen de dichtstbijzijnde", mixed_moves[0].startswith("G1 X0.000 Y0.000"), " | ".join(mixed_moves[:2]))
@@ -296,7 +298,7 @@ def test_virtual_machine() -> None:
296 try:
298 try:
297 corner = plan([{
299 corner = plan([{
298 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
300 "x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
299 "strokes": [{"pts": [(10, 297), (30, 277)]}],
301 "strokes": [{"pts": [(10, 293), (30, 273)]}],
300 }], {"origin": "top-left"})
302 }], {"origin": "top-left"})
301 gcode = corner["gcode"] + "\nG3 X30.000 Y-20.000 I0.000 J10.000 F3000\n"
303 gcode = corner["gcode"] + "\nG3 X30.000 Y-20.000 I0.000 J10.000 F3000\n"
302 machine.start_job(gcode)
304 machine.start_job(gcode)