From 4a238f9089da4eab8d880fa42c0cf0d38d5a94b6 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Tue, 18 Jul 2017 11:39:38 +0200 Subject: [PATCH] remove settings class --- example/save.js | 8 +-- example/viewer.js | 2 +- src/GCode.js | 12 ++--- src/Settings.js | 53 ------------------- src/Slicer.js | 6 +-- src/sliceActions/addBrim.js | 2 +- .../calculateLayersIntersections.js | 2 +- src/sliceActions/generateInfills.js | 2 +- src/sliceActions/generateInnerLines.js | 2 +- src/sliceActions/generateSupport.js | 4 +- src/sliceActions/slice.js | 2 +- src/slicerWorker.js | 4 +- 12 files changed, 19 insertions(+), 80 deletions(-) delete mode 100644 src/Settings.js diff --git a/example/save.js b/example/save.js index 8640e69..f7dc831 100644 --- a/example/save.js +++ b/example/save.js @@ -1,16 +1,12 @@ import 'three.js'; -import { Settings, defaultSettings, Slicer } from 'src/index.js'; +import { defaultSettings, Slicer } from 'src/index.js'; import { saveAs } from 'file-saver'; -console.log('defaultSettings: ', defaultSettings); - const settings = { ...defaultSettings.base, ...defaultSettings.material.pla, ...defaultSettings.printer.ultimaker2go, - ...defaultSettings.quality.high, - startCode: '', - endCode: '' + ...defaultSettings.quality.high }; const jsonLoader = new THREE.JSONLoader(); diff --git a/example/viewer.js b/example/viewer.js index 1abf0a4..78fe081 100644 --- a/example/viewer.js +++ b/example/viewer.js @@ -28,7 +28,7 @@ stlLoader.load('stl/Airplane.stl', (geometry) => { layerIntersectionPoints={rawData.layerIntersectionPoints} layerShapes={rawData.layerShapes} slices={rawData.slices} - settings={settings.config} + settings={settings} />, document.getElementById('container') ); diff --git a/src/GCode.js b/src/GCode.js index 0ca052d..0fd5199 100644 --- a/src/GCode.js +++ b/src/GCode.js @@ -66,7 +66,7 @@ export default class { const { layerHeight, travelSpeed - } = this._settings.config; + } = this._settings; const z = layer * layerHeight + 0.2; const speed = travelSpeed * 60; @@ -92,9 +92,9 @@ export default class { nozzleDiameter, filamentThickness, travelSpeed - } = this._settings.config; + } = this._settings; - const profile = this._settings.config[(this.bottom ? 'bottom' : type)]; + const profile = this._settings[(this.bottom ? 'bottom' : type)]; let { speed, @@ -130,7 +130,7 @@ export default class { minDistance: retractionMinDistance, speed: retractionSpeed } - } = this._settings.config; + } = this._settings; if (this._isRetracted && retractionEnabled) { this._isRetracted = false; @@ -157,7 +157,7 @@ export default class { minDistance: retractionMinDistance, speed: retractionSpeed } - } = this._settings.config; + } = this._settings; if (!this._isRetracted && retractionEnabled) { this._isRetracted = true; @@ -177,6 +177,6 @@ export default class { } getGCode() { - return this._settings.startCode() + this._gcode + this._settings.endCode(); + return this._gcode; } } diff --git a/src/Settings.js b/src/Settings.js deleted file mode 100644 index 08a3abf..0000000 --- a/src/Settings.js +++ /dev/null @@ -1,53 +0,0 @@ -export default class { - constructor(config = {}) { - this.config = config; - } - updateConfig(config) { - this.config = { ...this.config, ...config }; - - return this; - } - startCode() { - const { startCode } = this.config; - const gcode = this._subsituteVariables(startCode); - return gcode; - } - endCode() { - const { endCode } = this.config; - const gcode = this._subsituteVariables(endCode); - return gcode; - } - _subsituteVariables(gcode) { - let { - temperature, - bedTemperature, - heatTemperature, - heatBedTemperature, - travelSpeed, - printerType, - heatedBed - } = this.config; - - travelSpeed *= 60; - - switch (printerType) { - case 'makerbot_replicator2': printerType = 'r2'; break; - case 'makerbot_replicator2x': printerType = 'r2x'; break; - case 'makerbot_thingomatic': printerType = 't6'; break; - case 'makerbot_generic': printerType = 'r2'; break; - case '_3Dison_plus': printerType = 'r2'; break; - } - - const heatedBedReplacement = heatedBed ? '' : ';'; - - gcode = gcode.replace(/{printingTemp}/gi, temperature); - gcode = gcode.replace(/{printingBedTemp}/gi, bedTemperature); - gcode = gcode.replace(/{preheatTemp}/gi, heatTemperature); - gcode = gcode.replace(/{preheatBedTemp}/gi, heatBedTemperature); - gcode = gcode.replace(/{printerType}/gi, printerType); - gcode = gcode.replace(/{travelSpeed}/gi, travelSpeed); - gcode = gcode.replace(/{if heatedBed}/gi, heatedBedReplacement); - - return gcode; - } -} diff --git a/src/Slicer.js b/src/Slicer.js index 1c9c994..658c191 100644 --- a/src/Slicer.js +++ b/src/Slicer.js @@ -1,5 +1,4 @@ import * as THREE from 'three.js'; -import Settings from './Settings.js'; import slice from './sliceActions/slice.js'; import SlicerWorker from './slicerWorker.js!worker'; @@ -29,13 +28,12 @@ export default class { return this; } sliceSync(settings) { - return slice(this.geometry, new Settings(settings)); + return slice(this.geometry, settings); } slice(settings) { const slicerWorker = new SlicerWorker(); const geometry = this.geometry.toJSON(); - const { config } = new Settings(settings); return new Promise((resolve, reject) => { slicerWorker.onerror = reject; @@ -58,7 +56,7 @@ export default class { slicerWorker.postMessage({ message: 'SLICE', - data: { geometry, config } + data: { geometry, settings } }); }); } diff --git a/src/sliceActions/addBrim.js b/src/sliceActions/addBrim.js index b786491..285d94f 100644 --- a/src/sliceActions/addBrim.js +++ b/src/sliceActions/addBrim.js @@ -10,7 +10,7 @@ const offsetOptions = { export default function addBrim(slices, settings) { console.log('add brim'); - let { brim: { offset: brimOffset } } = settings.config; + let { brim: { offset: brimOffset } } = settings; brimOffset /= PRECISION; const [firstLayer] = slices; diff --git a/src/sliceActions/calculateLayersIntersections.js b/src/sliceActions/calculateLayersIntersections.js index ba25e5b..fcc198b 100644 --- a/src/sliceActions/calculateLayersIntersections.js +++ b/src/sliceActions/calculateLayersIntersections.js @@ -3,7 +3,7 @@ import * as THREE from 'three.js'; export default function calculateLayersIntersections(lines, settings) { console.log('calculating layer intersections'); - const { layerHeight, dimensions: { z: dimensionsZ } } = settings.config; + const { layerHeight, dimensions: { z: dimensionsZ } } = settings; const numLayers = Math.floor(dimensionsZ / layerHeight); diff --git a/src/sliceActions/generateInfills.js b/src/sliceActions/generateInfills.js index 4c4bb9a..7d1d43e 100644 --- a/src/sliceActions/generateInfills.js +++ b/src/sliceActions/generateInfills.js @@ -12,7 +12,7 @@ export default function generateInfills(slices, settings) { top: { thickness: topThickness }, nozzleDiameter, fill: { overlap: infillOverlap } - } = settings.config; + } = settings; fillGridSize /= PRECISION; nozzleDiameter /= PRECISION; diff --git a/src/sliceActions/generateInnerLines.js b/src/sliceActions/generateInnerLines.js index 2074079..6ead645 100644 --- a/src/sliceActions/generateInnerLines.js +++ b/src/sliceActions/generateInnerLines.js @@ -11,7 +11,7 @@ export default function generateInnerLines(slices, settings) { console.log('generating outer lines and inner lines'); // need to scale up everything because of clipper rounding errors - let { layerHeight, nozzleDiameter, shell: { thickness: shellThickness } } = settings.config; + let { layerHeight, nozzleDiameter, shell: { thickness: shellThickness } } = settings; nozzleDiameter /= PRECISION; shellThickness /= PRECISION; const nozzleRadius = nozzleDiameter / 2; diff --git a/src/sliceActions/generateSupport.js b/src/sliceActions/generateSupport.js index d01b6f0..8ea06d1 100644 --- a/src/sliceActions/generateSupport.js +++ b/src/sliceActions/generateSupport.js @@ -5,7 +5,7 @@ import { PRECISION } from '../constants.js'; export default function generateSupport(slices, settings) { console.log('generating support'); - if (!settings.config.support.enabled) return; + if (!settings.support.enabled) return; let { layerHeight, @@ -16,7 +16,7 @@ export default function generateSupport(slices, settings) { distanceY: DistanceY }, nozzleDiameter - } = settings.config; + } = settings; supportGridSize /= PRECISION; supportMargin /= PRECISION; diff --git a/src/sliceActions/slice.js b/src/sliceActions/slice.js index a5b142e..8a68d59 100644 --- a/src/sliceActions/slice.js +++ b/src/sliceActions/slice.js @@ -17,7 +17,7 @@ export default function(geometry, settings, onProgress) { let current = 0; const progressMessage = () => { current ++; - postMessage({ message: 'PROGRESS', data: { done: current, total: totalStages } }); + // postMessage({ message: 'PROGRESS', data: { done: current, total: totalStages } }); }; geometry.computeFaceNormals(); diff --git a/src/slicerWorker.js b/src/slicerWorker.js index 7218998..451456a 100644 --- a/src/slicerWorker.js +++ b/src/slicerWorker.js @@ -1,4 +1,3 @@ -import Settings from './Settings.js'; import slice from './sliceActions/slice.js'; import * as THREE from 'three.js'; @@ -8,10 +7,9 @@ self.addEventListener('message', (event) => { const { message, data } = event.data; switch (message) { case 'SLICE': { - const { geometry: JSONGeometry, config } = data; + const { geometry: JSONGeometry, settings } = data; const { geometry } = new loader.parse(JSONGeometry.data); - const settings = new Settings(config); const gcode = slice(geometry, settings);