From ce1e31432f6a7284aac211690e32fe799aa7d322 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Mon, 28 Dec 2020 21:20:51 +0100 Subject: [PATCH] Added units switching Added layer reordering Fixed a few issues related to non-millimeter units Edge/End components were incorrectly named, whoops --- TODO.md | 8 +- src/App.vue | 10 +-- src/components/EdgeGrainPreview.vue | 72 +++++++--------- src/components/EndGrainPreview.vue | 71 +++++++++++++--- src/components/Layers.vue | 125 +++++++++++++++++++++++++++- src/components/Settings.vue | 5 +- src/lib/units.js | 37 +++++++- src/store.js | 89 +++++++++++++++----- 8 files changed, 324 insertions(+), 93 deletions(-) diff --git a/TODO.md b/TODO.md index 6581d1f..30d8bb1 100644 --- a/TODO.md +++ b/TODO.md @@ -1,20 +1,16 @@ ToDo ==== -Must have ----- -- Implement switching units -- Re-ordering of the layers (preferably drag/drop) - Should have ---- -- Render width and height of the boards in the previews - Material usage overview - Generate cutting list - Support for fractional inches (see, not all europeans look down on freedom units!) +- Save/load via URL (MessagePack encoded Base64 in URL) Nice to have ---- +- Render width and height of the boards in the previews (simplified version implemented, moved to Nice to have) - More advanced options, like custom direction per strip and mixing multiple edge grain boards with different layers for the end grain board (the code is half prepared for this by having the boards array encapsulating the layers, though it's all hardcoded to board[0] now) - 3D effect for previews emulating thickness / crosscut width - Make it a tiny bit prettier overall diff --git a/src/App.vue b/src/App.vue index 6a6b76e..3b44116 100644 --- a/src/App.vue +++ b/src/App.vue @@ -17,7 +17,7 @@

- +

@@ -35,10 +35,10 @@

Edge grain

- +

End grain

- +
@@ -80,7 +80,7 @@ export default { load() { - const loadFile = document.getElementById("loadFile").files[0]; + const loadFile = this.$refs.loadFile.files[0]; if (!loadFile) return; @@ -139,7 +139,7 @@ h1 } } -.about, .todo +.about { width: 30em; } diff --git a/src/components/EdgeGrainPreview.vue b/src/components/EdgeGrainPreview.vue index 3f365a4..baab4dd 100644 --- a/src/components/EdgeGrainPreview.vue +++ b/src/components/EdgeGrainPreview.vue @@ -1,27 +1,19 @@ @@ -40,20 +32,7 @@ export default { wood() { return this.$store.state.wood; }, layers() { return this.$store.state.boards[0].layers; }, - stripsPerBoard() - { - const stripAndKerf = this.settings.crosscutWidth + this.settings.bladeKerf; - if (stripAndKerf === 0) - return 0; - - return Math.floor((this.settings.boardLength + this.settings.bladeKerf) / stripAndKerf); - }, - - boardWidth() - { - const boardWidth = this.stripsPerBoard * this.settings.boardThickness; - return this.toPixels(boardWidth); - }, + boardWidth() { return this.settings.boardLength; }, boardHeight() { @@ -62,9 +41,19 @@ export default { .reduce((accumulator, currentValue) => accumulator + currentValue); }, - viewportWidth() { return Math.floor(this.boardWidth * this.scale); }, - viewportHeight() { return Math.floor(this.boardHeight * this.scale); }, - viewBox() { return '0 0 ' + this.boardWidth + ' ' + this.boardHeight; } + boardPixelWidth() + { + return this.toPixels(this.boardWidth); + }, + + boardPixelHeight() + { + return this.toPixels(this.boardHeight); + }, + + viewportWidth() { return Math.floor(this.boardPixelWidth * this.scale); }, + viewportHeight() { return Math.floor(this.boardPixelHeight * this.scale); }, + viewBox() { return '0 0 ' + this.boardPixelWidth + ' ' + this.boardPixelHeight; } }, @@ -74,6 +63,11 @@ export default { return units.toPixels(value, this.settings.units); }, + display(value) + { + return units.display(value, this.settings.units); + }, + getLayerOffset(index) { if (index < 0 || index >= this.layers.length) @@ -84,7 +78,7 @@ export default { for (let i = 0; i < index; i++) offset += this.layers[i].width; - return offset; + return this.toPixels(offset); }, getLayerStyle(index) @@ -101,14 +95,6 @@ export default { : ''; return 'fill: ' + this.wood[woodIndex].color + borderStyle; - }, - - getLayerTransform(index) - { - if (!this.settings.alternateDirection || (index % 2) == 0) - return ''; - - return 'scale(1, -1) translate(0, -' + this.boardHeight + ')'; } } } diff --git a/src/components/EndGrainPreview.vue b/src/components/EndGrainPreview.vue index 4cbe808..a33704b 100644 --- a/src/components/EndGrainPreview.vue +++ b/src/components/EndGrainPreview.vue @@ -1,17 +1,29 @@ @@ -30,7 +42,19 @@ export default { wood() { return this.$store.state.wood; }, layers() { return this.$store.state.boards[0].layers; }, - boardWidth() { return this.toPixels(this.settings.boardLength); }, + stripsPerBoard() + { + const stripAndKerf = this.settings.crosscutWidth + this.settings.bladeKerf; + if (stripAndKerf === 0) + return 0; + + return Math.floor((this.settings.boardLength + this.settings.bladeKerf) / stripAndKerf); + }, + + boardWidth() + { + return this.stripsPerBoard * this.settings.boardThickness; + }, boardHeight() { @@ -39,9 +63,19 @@ export default { .reduce((accumulator, currentValue) => accumulator + currentValue); }, - viewportWidth() { return Math.floor(this.boardWidth * this.scale); }, - viewportHeight() { return Math.floor(this.boardHeight * this.scale); }, - viewBox() { return '0 0 ' + this.boardWidth + ' ' + this.boardHeight; } + boardPixelWidth() + { + return this.toPixels(this.boardWidth); + }, + + boardPixelHeight() + { + return this.toPixels(this.boardHeight); + }, + + viewportWidth() { return Math.floor(this.boardPixelWidth * this.scale); }, + viewportHeight() { return Math.floor(this.boardPixelHeight * this.scale); }, + viewBox() { return '0 0 ' + this.boardPixelWidth + ' ' + this.boardPixelHeight; } }, @@ -51,6 +85,11 @@ export default { return units.toPixels(value, this.settings.units); }, + display(value) + { + return units.display(value, this.settings.units); + }, + getLayerOffset(index) { if (index < 0 || index >= this.layers.length) @@ -61,7 +100,7 @@ export default { for (let i = 0; i < index; i++) offset += this.layers[i].width; - return offset; + return this.toPixels(offset); }, getLayerStyle(index) @@ -78,6 +117,14 @@ export default { : ''; return 'fill: ' + this.wood[woodIndex].color + borderStyle; + }, + + getLayerTransform(index) + { + if (!this.settings.alternateDirection || (index % 2) == 0) + return ''; + + return 'scale(1, -1) translate(0, -' + this.boardPixelHeight + ')'; } } } diff --git a/src/components/Layers.vue b/src/components/Layers.vue index 6e59f7f..902ba0a 100644 --- a/src/components/Layers.vue +++ b/src/components/Layers.vue @@ -4,13 +4,18 @@ +
+ Tip: click and drag the layer number to move a layer +
+ +   Wood type Width