Skip to content

Commit 2e8c2ec

Browse files
committed
Allow dropping a new gcode file to replace the first
1 parent b708fff commit 2e8c2ec

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

src/App.svelte

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
2-
import Dropzone from "svelte-file-dropzone";
2+
import { onMount } from 'svelte';
3+
// import Dropzone from "svelte-file-dropzone";
34
import * as GCodePreview from "gcode-preview";
45
import * as FileSaver from 'file-saver';
56
@@ -47,7 +48,33 @@
4748
maxFlow } = aggregateLayerStats(analyzedLayers));
4849
$: tempChanges = generateTempChanges(analyzedLayers, minFlow, maxFlow, minTemp, maxTemp, tempInc, skipFirstLayers, skipLastLayers);
4950
50-
//init()
51+
// init()
52+
53+
onMount(() => {
54+
canvasElement.addEventListener('dragover', function(evt) {
55+
evt.stopPropagation();
56+
evt.preventDefault();
57+
evt.dataTransfer.dropEffect = 'copy';
58+
// document.body.className = "dragging";
59+
});
60+
61+
canvasElement.addEventListener('dragleave', function(evt) {
62+
evt.stopPropagation();
63+
evt.preventDefault();
64+
// document.body.className = "";
65+
});
66+
67+
canvasElement.addEventListener('drop', function(evt) {
68+
evt.stopPropagation();
69+
evt.preventDefault();
70+
// document.body.className = "";
71+
const reader = new FileReader();
72+
reader.onload = function() {
73+
handleGCode(reader.result);
74+
};
75+
reader.readAsText(evt.dataTransfer.files[0]);
76+
});
77+
});
5178
5279
async function init() {
5380
const response = await fetch('double-cylinder.gcode');
@@ -262,17 +289,17 @@
262289

263290
<div class="columns">
264291
<section>
265-
<h2>1. Specify gcode file</h2>
292+
<h2>1. Drag n drop gcode file</h2>
266293

267294
<div class="preview-wrapper">
268-
{#if !file}
269-
<Dropzone on:drop={handleFilesSelect}>
295+
296+
<!-- {#if !file}
270297
<button>Choose images to upload</button>
271298
272299
<p>or</p>
273300
<p>Drag and drop them here</p>
274-
</Dropzone>
275-
{/if}
301+
302+
{/if} -->
276303

277304
{#if file}
278305

@@ -294,8 +321,8 @@
294321
</div>
295322
{/if}
296323

297-
<canvas hidden={!file} bind:this={canvasElement}></canvas>
298-
324+
<canvas width=400 height=300 bind:this={canvasElement}></canvas>
325+
299326
</div>
300327

301328
<section>
@@ -429,6 +456,13 @@
429456
.preview-wrapper {
430457
display: inline-block;
431458
}
459+
460+
canvas {
461+
border: 1px solid grey;
462+
width: 600px;
463+
height: 300px;
464+
box-sizing: border-box;
465+
}
432466
canvas:focus {
433467
outline: none;
434468
}
@@ -458,4 +492,4 @@
458492
[disabled] {
459493
opacity: 0.5;
460494
}
461-
</style>
495+
</style>

0 commit comments

Comments
 (0)