remove settings class

This commit is contained in:
casperlamboo 2017-07-18 11:39:38 +02:00
parent 622be82706
commit 4a238f9089
12 changed files with 19 additions and 80 deletions

View File

@ -1,16 +1,12 @@
import 'three.js'; import 'three.js';
import { Settings, defaultSettings, Slicer } from 'src/index.js'; import { defaultSettings, Slicer } from 'src/index.js';
import { saveAs } from 'file-saver'; import { saveAs } from 'file-saver';
console.log('defaultSettings: ', defaultSettings);
const settings = { const settings = {
...defaultSettings.base, ...defaultSettings.base,
...defaultSettings.material.pla, ...defaultSettings.material.pla,
...defaultSettings.printer.ultimaker2go, ...defaultSettings.printer.ultimaker2go,
...defaultSettings.quality.high, ...defaultSettings.quality.high
startCode: '',
endCode: ''
}; };
const jsonLoader = new THREE.JSONLoader(); const jsonLoader = new THREE.JSONLoader();

View File

@ -28,7 +28,7 @@ stlLoader.load('stl/Airplane.stl', (geometry) => {
layerIntersectionPoints={rawData.layerIntersectionPoints} layerIntersectionPoints={rawData.layerIntersectionPoints}
layerShapes={rawData.layerShapes} layerShapes={rawData.layerShapes}
slices={rawData.slices} slices={rawData.slices}
settings={settings.config} settings={settings}
/>, />,
document.getElementById('container') document.getElementById('container')
); );

View File

@ -66,7 +66,7 @@ export default class {
const { const {
layerHeight, layerHeight,
travelSpeed travelSpeed
} = this._settings.config; } = this._settings;
const z = layer * layerHeight + 0.2; const z = layer * layerHeight + 0.2;
const speed = travelSpeed * 60; const speed = travelSpeed * 60;
@ -92,9 +92,9 @@ export default class {
nozzleDiameter, nozzleDiameter,
filamentThickness, filamentThickness,
travelSpeed travelSpeed
} = this._settings.config; } = this._settings;
const profile = this._settings.config[(this.bottom ? 'bottom' : type)]; const profile = this._settings[(this.bottom ? 'bottom' : type)];
let { let {
speed, speed,
@ -130,7 +130,7 @@ export default class {
minDistance: retractionMinDistance, minDistance: retractionMinDistance,
speed: retractionSpeed speed: retractionSpeed
} }
} = this._settings.config; } = this._settings;
if (this._isRetracted && retractionEnabled) { if (this._isRetracted && retractionEnabled) {
this._isRetracted = false; this._isRetracted = false;
@ -157,7 +157,7 @@ export default class {
minDistance: retractionMinDistance, minDistance: retractionMinDistance,
speed: retractionSpeed speed: retractionSpeed
} }
} = this._settings.config; } = this._settings;
if (!this._isRetracted && retractionEnabled) { if (!this._isRetracted && retractionEnabled) {
this._isRetracted = true; this._isRetracted = true;
@ -177,6 +177,6 @@ export default class {
} }
getGCode() { getGCode() {
return this._settings.startCode() + this._gcode + this._settings.endCode(); return this._gcode;
} }
} }

View File

@ -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;
}
}

View File

@ -1,5 +1,4 @@
import * as THREE from 'three.js'; import * as THREE from 'three.js';
import Settings from './Settings.js';
import slice from './sliceActions/slice.js'; import slice from './sliceActions/slice.js';
import SlicerWorker from './slicerWorker.js!worker'; import SlicerWorker from './slicerWorker.js!worker';
@ -29,13 +28,12 @@ export default class {
return this; return this;
} }
sliceSync(settings) { sliceSync(settings) {
return slice(this.geometry, new Settings(settings)); return slice(this.geometry, settings);
} }
slice(settings) { slice(settings) {
const slicerWorker = new SlicerWorker(); const slicerWorker = new SlicerWorker();
const geometry = this.geometry.toJSON(); const geometry = this.geometry.toJSON();
const { config } = new Settings(settings);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
slicerWorker.onerror = reject; slicerWorker.onerror = reject;
@ -58,7 +56,7 @@ export default class {
slicerWorker.postMessage({ slicerWorker.postMessage({
message: 'SLICE', message: 'SLICE',
data: { geometry, config } data: { geometry, settings }
}); });
}); });
} }

View File

@ -10,7 +10,7 @@ const offsetOptions = {
export default function addBrim(slices, settings) { export default function addBrim(slices, settings) {
console.log('add brim'); console.log('add brim');
let { brim: { offset: brimOffset } } = settings.config; let { brim: { offset: brimOffset } } = settings;
brimOffset /= PRECISION; brimOffset /= PRECISION;
const [firstLayer] = slices; const [firstLayer] = slices;

View File

@ -3,7 +3,7 @@ import * as THREE from 'three.js';
export default function calculateLayersIntersections(lines, settings) { export default function calculateLayersIntersections(lines, settings) {
console.log('calculating layer intersections'); console.log('calculating layer intersections');
const { layerHeight, dimensions: { z: dimensionsZ } } = settings.config; const { layerHeight, dimensions: { z: dimensionsZ } } = settings;
const numLayers = Math.floor(dimensionsZ / layerHeight); const numLayers = Math.floor(dimensionsZ / layerHeight);

View File

@ -12,7 +12,7 @@ export default function generateInfills(slices, settings) {
top: { thickness: topThickness }, top: { thickness: topThickness },
nozzleDiameter, nozzleDiameter,
fill: { overlap: infillOverlap } fill: { overlap: infillOverlap }
} = settings.config; } = settings;
fillGridSize /= PRECISION; fillGridSize /= PRECISION;
nozzleDiameter /= PRECISION; nozzleDiameter /= PRECISION;

View File

@ -11,7 +11,7 @@ export default function generateInnerLines(slices, settings) {
console.log('generating outer lines and inner lines'); console.log('generating outer lines and inner lines');
// need to scale up everything because of clipper rounding errors // 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; nozzleDiameter /= PRECISION;
shellThickness /= PRECISION; shellThickness /= PRECISION;
const nozzleRadius = nozzleDiameter / 2; const nozzleRadius = nozzleDiameter / 2;

View File

@ -5,7 +5,7 @@ import { PRECISION } from '../constants.js';
export default function generateSupport(slices, settings) { export default function generateSupport(slices, settings) {
console.log('generating support'); console.log('generating support');
if (!settings.config.support.enabled) return; if (!settings.support.enabled) return;
let { let {
layerHeight, layerHeight,
@ -16,7 +16,7 @@ export default function generateSupport(slices, settings) {
distanceY: DistanceY distanceY: DistanceY
}, },
nozzleDiameter nozzleDiameter
} = settings.config; } = settings;
supportGridSize /= PRECISION; supportGridSize /= PRECISION;
supportMargin /= PRECISION; supportMargin /= PRECISION;

View File

@ -17,7 +17,7 @@ export default function(geometry, settings, onProgress) {
let current = 0; let current = 0;
const progressMessage = () => { const progressMessage = () => {
current ++; current ++;
postMessage({ message: 'PROGRESS', data: { done: current, total: totalStages } }); // postMessage({ message: 'PROGRESS', data: { done: current, total: totalStages } });
}; };
geometry.computeFaceNormals(); geometry.computeFaceNormals();

View File

@ -1,4 +1,3 @@
import Settings from './Settings.js';
import slice from './sliceActions/slice.js'; import slice from './sliceActions/slice.js';
import * as THREE from 'three.js'; import * as THREE from 'three.js';
@ -8,10 +7,9 @@ self.addEventListener('message', (event) => {
const { message, data } = event.data; const { message, data } = event.data;
switch (message) { switch (message) {
case 'SLICE': { case 'SLICE': {
const { geometry: JSONGeometry, config } = data; const { geometry: JSONGeometry, settings } = data;
const { geometry } = new loader.parse(JSONGeometry.data); const { geometry } = new loader.parse(JSONGeometry.data);
const settings = new Settings(config);
const gcode = slice(geometry, settings); const gcode = slice(geometry, settings);