comply with linter

This commit is contained in:
Casper Lamboo 2018-04-17 14:17:28 +02:00
parent 5a40c7c647
commit 0be1ee6d51
25 changed files with 663 additions and 1053 deletions

1429
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@
}, },
"devDependencies": { "devDependencies": {
"babel-cli": "6.24.1", "babel-cli": "6.24.1",
"babel-eslint": "^8.2.3", "babel-eslint": "^5.0.4",
"babel-loader": "7.0.0", "babel-loader": "7.0.0",
"babel-plugin-transform-es2015-classes": "^6.24.1", "babel-plugin-transform-es2015-classes": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-object-rest-spread": "^6.26.0",
@ -53,11 +53,9 @@
"babel-preset-react": "^6.24.1", "babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1", "babel-preset-stage-0": "^6.24.1",
"babel-runtime": "^6.26.0", "babel-runtime": "^6.26.0",
"eslint": "^4.19.1", "eslint": "^1.10.3",
"eslint-config-airbnb": "^16.1.0", "eslint-config-airbnb": "^3.1.0",
"eslint-plugin-import": "^2.11.0", "eslint-plugin-react": "^3.16.1",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"file-loader": "^1.1.11", "file-loader": "^1.1.11",
"html-webpack-plugin": "^2.29.0", "html-webpack-plugin": "^2.29.0",
"html-webpack-template": "^6.0.2", "html-webpack-template": "^6.0.2",

View File

@ -1,8 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'proptypes'; import PropTypes from 'proptypes';
import _ from 'lodash'; import _ from 'lodash';
import injectSheet from 'react-jss'; import MaterialUISelectField from 'material-ui/SelectField';
import MaterialUISelectField from 'material-ui/SelectField'
import MaterialUICheckbox from 'material-ui/Checkbox'; import MaterialUICheckbox from 'material-ui/Checkbox';
import TextFieldIcon from 'material-ui-textfield-icon'; import TextFieldIcon from 'material-ui-textfield-icon';
import RefreshIcon from 'material-ui-icons/Refresh'; import RefreshIcon from 'material-ui-icons/Refresh';
@ -59,8 +58,8 @@ const _NumberField = ({ name, min, max, muiTheme: { palette }, ...props }, conte
type="number" type="number"
icon={context.advancedFields.includes(name) && <RefreshIcon icon={context.advancedFields.includes(name) && <RefreshIcon
style={{ fill: palette.textColor }} style={{ fill: palette.textColor }}
onTouchTap={() => context.onChange(name, null)} /> onTouchTap={() => context.onChange(name, null)}
} />}
floatingLabelStyle={{ floatingLabelStyle={{
color: context.advancedFields.includes(name) ? palette.primary1Color : palette.primary3Color color: context.advancedFields.includes(name) ? palette.primary1Color : palette.primary3Color
}} }}

View File

@ -1,61 +0,0 @@
import React from 'react';
import PropTypes from 'proptypes';
import muiThemeable from 'material-ui/styles/muiThemeable';
import injectSheet from 'react-jss';
import FlatButton from 'material-ui/FlatButton';
import { sleep, getMalyanStatus } from './utils.js';
const styles = {
};
class MalyanControl extends React.Component {
static propTypes = {
ip: PropTypes.string.isRequired
};
state = {
status: null,
mounted: true
};
// componentDidMount = async () => {
// const { ip } = this.props;
// while (this.state.mounted) {
// const status = await getMalyanStatus(ip).catch(() => null);
// this.setState({ status });
// await sleep(1000);
// }
// };
home = () => {
const { ip } = this.props;
fetch(`http://${ip}/set?code=G28`, { method: 'GET', mode: 'no-cors' });
};
stop = () => {
const { ip } = this.props;
fetch(`http://${ip}/set?cmd={P:X}`, { method: 'GET', mode: 'no-cors' });
};
componentWillUnmount() {
this.setState({ mounted: false });
}
render() {
const { status } = this.state;
return (
<div>
{status && <span>
<p>Nozzle temperature: {status.nozzleTemperature}/{status.nozzleTargetTemperature}</p>
<p>Bed temperature: {status.bedTemperature}/{status.bedTargetTemperature}</p>
{status.state === 'printing' && <p>Progress: {status.progress}%</p>}
</span>}
<FlatButton label="Stop" onTouchTap={this.stop} />
<FlatButton label="Home" onTouchTap={this.home} />
</div>
);
}
}
export default muiThemeable()(injectSheet(styles)(MalyanControl));

View File

@ -45,13 +45,16 @@ const styles = {
'& h3': { '& h3': {
fontWeight: 'bold', fontWeight: 'bold',
marginTop: '20px', marginTop: '20px',
marginBottom: '20px', marginBottom: '20px'
} }
}, },
error: { error: {
color: red500 color: red500
}, }
};
const updateLocalStorage = (localStorage) => {
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(localStorage));
}; };
const getLocalStorage = () => { const getLocalStorage = () => {
@ -66,10 +69,6 @@ const getLocalStorage = () => {
return localStorage; return localStorage;
}; };
const updateLocalStorage = (localStorage) => {
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(localStorage));
};
class Settings extends React.Component { class Settings extends React.Component {
static propTypes = { static propTypes = {
selectedPrinter: PropTypes.string, selectedPrinter: PropTypes.string,
@ -110,9 +109,8 @@ class Settings extends React.Component {
const { localStorage } = this.state; const { localStorage } = this.state;
if (selectedPrinter && localStorage.active) { if (selectedPrinter && localStorage.active) {
const activePrinter = selectedPrinter && Object.entries(localStorage.printers) const activePrinter = selectedPrinter && Object.values(localStorage.printers)
.map(([key, value]) => ({ key, value })) .find(({ ip }) => ip === selectedPrinter);
.find(({ key, value: { ip } }) => ip === selectedPrinter);
if (activePrinter) { if (activePrinter) {
const state = this.changeSettings('activePrinter', activePrinter.key); const state = this.changeSettings('activePrinter', activePrinter.key);
@ -212,7 +210,6 @@ class Settings extends React.Component {
case 'settings.support.density': case 'settings.support.density':
case 'settings.support.minArea': case 'settings.support.minArea':
case 'settings.support.margin': case 'settings.support.margin':
case 'settings.support.speed':
case 'settings.support.flowRate': case 'settings.support.flowRate':
if (!localStorage.active) return this.openAddPrinterDialog(); if (!localStorage.active) return this.openAddPrinterDialog();
@ -307,14 +304,22 @@ class Settings extends React.Component {
}; };
editPrinter = () => { editPrinter = () => {
const { localStorage: { active, printers }, managePrinter: { printer, name, ip } } = this.state; const { localStorage: { active }, managePrinter: { printer, name, ip } } = this.state;
if (!name) { if (!name) {
this.setState(update(this.state, { managePrinter: { error: { $set: 'Please enter a name' } } })); this.setState(update(this.state, {
managePrinter: {
error: { $set: 'Please enter a name' }
}
}));
return; return;
} }
if (printer === 'doodle3d_printer' && !validateIp(ip)) { if (printer === 'doodle3d_printer' && !validateIp(ip)) {
this.setState(update(this.state, { managePrinter: { error: { $set: 'Please enter a valid IP adress' } } })); this.setState(update(this.state, {
managePrinter: {
error: { $set: 'Please enter a valid IP adress' }
}
}));
return; return;
} }
@ -384,8 +389,8 @@ class Settings extends React.Component {
} }
render() { render() {
const { addPrinter, managePrinter, localStorage, wifiBoxes } = this.state; const { addPrinter, managePrinter, localStorage } = this.state;
const { classes, disabled } = this.props; const { classes } = this.props;
return ( return (
<div className={classes.container}> <div className={classes.container}>
@ -540,5 +545,8 @@ function printDialog(props, state, title, form, submitText, data, closeDialog, r
</Dialog> </Dialog>
); );
} }
printDialog.propTypes = {
classes: PropTypes.objectOf(PropTypes.string)
};
export default injectSheet(styles)(Settings); export default injectSheet(styles)(Settings);

View File

@ -1,59 +0,0 @@
import React from 'react';
import PropTypes from 'proptypes';
import muiThemeable from 'material-ui/styles/muiThemeable';
import injectSheet from 'react-jss';
import FlatButton from 'material-ui/FlatButton';
import { Doodle3DBox } from 'doodle3d-api';
const styles = {
};
class WifiBoxControl extends React.Component {
static propTypes = {
ip: PropTypes.string.isRequired
};
state = {
box: null,
status: null
};
componentDidMount = async () => {
const { ip } = this.props;
const box = new Doodle3DBox(ip);
window.d3dbox = box;
box.addEventListener('update', ({ state }) => this.setState({ status: state }));
box.setAutoUpdate(true, 5000);
this.setState({ box });
const alive = await box.checkAlive();
};
stop = async () => {
const { box } = this.state;
const result = await box.printer.stop();
console.log('result: ', result);
};
componentWillUnmount() {
const { box } = this.state;
if (box) box.setAutoUpdate(false);
this.setState({ mounted: false });
}
render() {
const { status } = this.state;
return (
<div>
<FlatButton label="Stop" onTouchTap={this.stop} />
</div>
);
}
}
export default muiThemeable()(injectSheet(styles)(WifiBoxControl));

View File

@ -1,12 +1,9 @@
import * as THREE from 'three'; import * as THREE from 'three';
import _ from 'lodash';
import React from 'react'; import React from 'react';
import PropTypes from 'proptypes'; import PropTypes from 'proptypes';
import { centerGeometry, placeOnGround, createScene, slice, TabTemplate } from './utils.js'; import { centerGeometry, placeOnGround, createScene, slice, TabTemplate } from './utils.js';
import injectSheet from 'react-jss'; import injectSheet from 'react-jss';
import RaisedButton from 'material-ui/RaisedButton'; import RaisedButton from 'material-ui/RaisedButton';
import FlatButton from 'material-ui/FlatButton';
import Slider from 'material-ui/Slider';
import LinearProgress from 'material-ui/LinearProgress'; import LinearProgress from 'material-ui/LinearProgress';
import { grey50, grey300, grey800, red500 } from 'material-ui/styles/colors'; import { grey50, grey300, grey800, red500 } from 'material-ui/styles/colors';
import Popover from 'material-ui/Popover/Popover'; import Popover from 'material-ui/Popover/Popover';
@ -14,14 +11,11 @@ import Menu from 'material-ui/Menu';
import MenuItem from 'material-ui/MenuItem'; import MenuItem from 'material-ui/MenuItem';
import { Tabs, Tab } from 'material-ui/Tabs'; import { Tabs, Tab } from 'material-ui/Tabs';
import Settings from './Settings.js'; import Settings from './Settings.js';
// import MalyanControl from './MalyanControl.js';
// import WifiBoxControl from './WifiBoxControl.js';
import ReactResizeDetector from 'react-resize-detector'; import ReactResizeDetector from 'react-resize-detector';
import JSONToSketchData from 'doodle3d-core/shape/JSONToSketchData'; import JSONToSketchData from 'doodle3d-core/shape/JSONToSketchData';
import createSceneData from 'doodle3d-core/d3/createSceneData.js'; import createSceneData from 'doodle3d-core/d3/createSceneData.js';
import { generateExportMesh } from 'doodle3d-core/utils/exportUtils.js'; import { generateExportMesh } from 'doodle3d-core/utils/exportUtils.js';
import muiThemeable from 'material-ui/styles/muiThemeable'; import muiThemeable from 'material-ui/styles/muiThemeable';
import Dialog from 'material-ui/Dialog';
import logo from '../../img/logo.png'; import logo from '../../img/logo.png';
const MAX_FULLSCREEN_WIDTH = 720; const MAX_FULLSCREEN_WIDTH = 720;
@ -58,7 +52,7 @@ const styles = {
borderLeft: `1px solid ${grey300}` borderLeft: `1px solid ${grey300}`
}, },
sliceActions: { sliceActions: {
flexShrink: 0, flexShrink: 0
}, },
sliceInfo: { sliceInfo: {
margin: '10px 0', margin: '10px 0',
@ -232,7 +226,7 @@ class Interface extends React.Component {
}; };
slice = async (action) => { slice = async (action) => {
const { isSlicing, settings, mesh, scene: { material, mesh: { matrix } } } = this.state; const { isSlicing, settings, mesh, scene: { mesh: { matrix } } } = this.state;
const { name } = this.props; const { name } = this.props;
if (isSlicing) return; if (isSlicing) return;
@ -342,7 +336,7 @@ class Interface extends React.Component {
render() { render() {
const { classes, onCancel, selectedPrinter, actions } = this.props; const { classes, onCancel, selectedPrinter, actions } = this.props;
const { isSlicing, progress, showFullScreen, error, objectDimensions, settings } = this.state; const { isSlicing, progress, showFullScreen, error, objectDimensions } = this.state;
const style = { ...(showFullScreen ? {} : { maxWidth: 'inherit', width: '100%', height: '100%' }) }; const style = { ...(showFullScreen ? {} : { maxWidth: 'inherit', width: '100%', height: '100%' }) };
@ -365,10 +359,6 @@ class Interface extends React.Component {
className={`${classes.button}`} className={`${classes.button}`}
onTouchTap={onCancel} onTouchTap={onCancel}
/>} />}
{/* (settings && settings.ip) && ((settings.printer === 'doodle3d_printer') ?
<MalyanControl ip={settings.ip} /> :
<WifiBoxControl ip={settings.ip} />
) */}
{actions.length === 1 ? ( {actions.length === 1 ? (
<RaisedButton <RaisedButton
primary primary
@ -390,8 +380,8 @@ class Interface extends React.Component {
<Popover <Popover
open={this.state.popover.open} open={this.state.popover.open}
anchorEl={this.state.popover.element} anchorEl={this.state.popover.element}
anchorOrigin={{horizontal: 'left', vertical: 'bottom'}} anchorOrigin={{ horizontal: 'left', vertical: 'bottom' }}
targetOrigin={{horizontal: 'left', vertical: 'bottom'}} targetOrigin={{ horizontal: 'left', vertical: 'bottom' }}
onRequestClose={this.closePopover} onRequestClose={this.closePopover}
> >
<Menu> <Menu>

View File

@ -4,7 +4,6 @@ import printerSettings from '../settings/printer.yml';
import materialSettings from '../settings/material.yml'; import materialSettings from '../settings/material.yml';
import qualitySettings from '../settings/quality.yml'; import qualitySettings from '../settings/quality.yml';
import { sliceGeometry } from '../slicer.js'; import { sliceGeometry } from '../slicer.js';
import { grey800, red500 } from 'material-ui/styles/colors';
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import fileSaver from 'file-saver'; import fileSaver from 'file-saver';
@ -24,7 +23,7 @@ export function centerGeometry(mesh) {
mesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-center.x, -center.y, -center.z)); mesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-center.x, -center.y, -center.z));
} }
export function createScene({ pixelRatio, muiTheme }) { export function createScene({ muiTheme }) {
const scene = new THREE.Scene(); const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(50, 1, 1, 10000); const camera = new THREE.PerspectiveCamera(50, 1, 1, 10000);
@ -52,7 +51,7 @@ export function createScene({ pixelRatio, muiTheme }) {
let renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true }); let renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
let editorControls = new THREE.EditorControls(camera, renderer.domElement); let editorControls = new THREE.EditorControls(camera, renderer.domElement);
box.scale.set(1., 1., 1.); box.scale.set(1, 1, 1);
box.updateMatrix(); box.updateMatrix();
const render = () => renderer.render(scene, camera); const render = () => renderer.render(scene, camera);
@ -95,16 +94,16 @@ export function fetchProgress(url, data = {}, onProgress) {
// const headers = new Headers(xhr.getAllResponseHeaders() || ''); // const headers = new Headers(xhr.getAllResponseHeaders() || '');
// const { status, statusText, response, responseText, responseURL: url = headers.get('X-Request-URL') } = xhr; // const { status, statusText, response, responseText, responseURL: url = headers.get('X-Request-URL') } = xhr;
// resolve(new Response(response || responseText, { headers, status, statusText, url })); // resolve(new Response(response || responseText, { headers, status, statusText, url }));
} };
xhr.onerror = () => reject(new TypeError('Network request failed')); xhr.onerror = () => reject(new TypeError('Network request failed'));
xhr.ontimeout = () => reject(new TypeError('Network request failed')); xhr.ontimeout = () => reject(new TypeError('Network request failed'));
xhr.open(request.method, url, true); xhr.open(request.method, url, true);
if (request.credentials === 'include') { if (request.credentials === 'include') {
xhr.withCredentials = true xhr.withCredentials = true;
} else if (request.credentials === 'omit') { } else if (request.credentials === 'omit') {
xhr.withCredentials = false xhr.withCredentials = false;
} }
if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress; if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress;
if (xhr.responseType) xhr.responseType = 'blob'; if (xhr.responseType) xhr.responseType = 'blob';
@ -134,7 +133,7 @@ export function getMalyanStatus(ip) {
break; break;
} }
return status; return status;
}) });
} }
export function sleep(time) { export function sleep(time) {
@ -153,12 +152,11 @@ export async function slice(action, name, mesh, settings, updateProgress) {
break; break;
case 'WIFI_PRINT': case 'WIFI_PRINT':
if (settings.printer === 'doodle3d_printer') { if (settings.printer === 'doodle3d_printer') {
const { state } = await getMalyanStatus(settings.ip); // const { state } = await getMalyanStatus(settings.ip);
if (state !== 'idle') throw { message: 'printer is busy', code: 0 }; // if (state !== 'idle') throw { message: 'printer is busy', code: 0 };
} else { } else {
wifiBox = new Doodle3DBox(settings.ip); wifiBox = new Doodle3DBox(settings.ip);
if (!await wifiBox.checkAlive()) throw { message: `can't connect to printer`, code: 4 } if (! await wifiBox.checkAlive()) throw { message: `can't connect to printer`, code: 4 };
const { state } = await wifiBox.info.status(); const { state } = await wifiBox.info.status();
if (state !== 'idle') throw { message: 'printer is busy', code: 0 }; if (state !== 'idle') throw { message: 'printer is busy', code: 0 };
@ -170,7 +168,6 @@ export async function slice(action, name, mesh, settings, updateProgress) {
break; break;
default: default:
throw { message: 'unknown target', code: 1 }; throw { message: 'unknown target', code: 1 };
break;
} }
const { dimensions } = settings; const { dimensions } = settings;
@ -250,7 +247,7 @@ export async function slice(action, name, mesh, settings, updateProgress) {
}); });
currentStep ++; currentStep ++;
const result = await wifiBox.printer.fetch(id); await wifiBox.printer.fetch(id);
} }
break; break;
} }
@ -270,7 +267,6 @@ export async function slice(action, name, mesh, settings, updateProgress) {
default: default:
throw { message: 'unknown target', code: 1 }; throw { message: 'unknown target', code: 1 };
break;
} }
} }
@ -297,5 +293,5 @@ export const TabTemplate = ({ children, selected, style }) => {
TabTemplate.propTypes = { TabTemplate.propTypes = {
children: PropTypes.node, children: PropTypes.node,
selected: PropTypes.bool, selected: PropTypes.bool,
style: PropTypes.object, style: PropTypes.object
}; };

View File

@ -20,8 +20,8 @@ export default function addBrim(slices, settings) {
const [firstLayer] = slices; const [firstLayer] = slices;
const brim = firstLayer.parts.reduce((brim, { shape }) => ( const brim = firstLayer.parts.reduce((_brim, { shape }) => (
brim.join(shape.offset(nozzleRadius, { _brim.join(shape.offset(nozzleRadius, {
...OFFSET_OPTIONS, ...OFFSET_OPTIONS,
endType: shape.closed ? 'etClosedPolygon' : 'etOpenRound' endType: shape.closed ? 'etClosedPolygon' : 'etOpenRound'
})) }))

View File

@ -1,5 +1,5 @@
import { PRECISION } from '../constants.js';
import { divide } from './helpers/vector2.js'; import { divide } from './helpers/vector2.js';
import { PRECISION } from '../constants.js'
export default function applyPrecision(layers) { export default function applyPrecision(layers) {
for (let layer = 0; layer < layers.length; layer ++) { for (let layer = 0; layer < layers.length; layer ++) {

View File

@ -21,7 +21,8 @@ export default function calculateLayersIntersections(lines, settings) {
if (layerIndex >= 0 && layerIndex < numLayers) { if (layerIndex >= 0 && layerIndex < numLayers) {
const y = layerIndex * layerHeight + Z_OFFSET; const y = layerIndex * layerHeight + Z_OFFSET;
let x, z; let x;
let z;
if (line.start.y === line.end.y) { if (line.start.y === line.end.y) {
x = line.start.x; x = line.start.x;
z = line.start.z; z = line.start.z;

View File

@ -1,7 +1,7 @@
import * as vector2 from './helpers/vector2.js'; import * as vector2 from './helpers/vector2.js';
import * as vector3 from './helpers/vector3.js'; import * as vector3 from './helpers/vector3.js';
export default function createLines(geometry, settings) { export default function createLines(geometry) {
const faces = []; const faces = [];
const lines = []; const lines = [];
const lineLookup = {}; const lineLookup = {};
@ -12,7 +12,7 @@ export default function createLines(geometry, settings) {
const normal = calculateNormal(geometry.vertices, a, b, c); const normal = calculateNormal(geometry.vertices, a, b, c);
// skip faces that point up or down // skip faces that point up or down
if (normal.y > .999 || normal.y < -.999) { if (normal.y > 0.999 || normal.y < -0.999) {
faces.push(null); faces.push(null);
continue; continue;
} }

View File

@ -1,6 +1,5 @@
import { PRECISION } from '../constants.js' import { PRECISION } from '../constants.js';
import getFillTemplate from './getFillTemplate.js'; import getFillTemplate from './getFillTemplate.js';
import Shape from 'clipper-js';
export default function generateInfills(slices, settings) { export default function generateInfills(slices, settings) {
let { let {

View File

@ -1,4 +1,4 @@
import { PRECISION } from '../constants.js' import { PRECISION } from '../constants.js';
const OFFSET_OPTIONS = { const OFFSET_OPTIONS = {
jointType: 'jtSquare', jointType: 'jtSquare',
@ -10,7 +10,6 @@ const OFFSET_OPTIONS = {
export default function generateInnerLines(slices, settings) { export default function generateInnerLines(slices, settings) {
// need to scale up everything because of clipper rounding errors // need to scale up everything because of clipper rounding errors
let { let {
layerHeight,
nozzleDiameter, nozzleDiameter,
thickness: { shell: shellThickness } thickness: { shell: shellThickness }
} = settings; } = settings;

View File

@ -1,6 +1,6 @@
import Shape from 'clipper-js'; import Shape from 'clipper-js';
export default function calculateOutlines(slices, settings) { export default function calculateOutlines(slices) {
for (let layer = 0; layer < slices.length; layer ++) { for (let layer = 0; layer < slices.length; layer ++) {
const slice = slices[layer]; const slice = slices[layer];

View File

@ -17,7 +17,7 @@ export default function generateSupport(slices, settings) {
margin /= PRECISION; margin /= PRECISION;
nozzleDiameter /= PRECISION; nozzleDiameter /= PRECISION;
const infillGridSize = nozzleDiameter * 2 / density; const infillGridSize = nozzleDiameter * 2 / density;
const supportDistanceLayers = Math.max(Math.ceil(distanceY / layerHeight), 1); const supportDistanceLayers = Math.max(Math.ceil(distanceY / layerHeight), 1);
let supportArea = new Shape([], true); let supportArea = new Shape([], true);

View File

@ -1,8 +1,10 @@
export function hslToRgb(h, s, l){ export function hslToRgb(h, s, l) {
let r, g, b; let r;
let g;
let b;
if (s === 0) { if (s === 0) {
r = g = b = lightness; r = g = b = l;
} else { } else {
const q = l < 0.5 ? l * (1 + s) : l + s - l * s; const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q; const p = 2 * l - q;
@ -14,7 +16,7 @@ export function hslToRgb(h, s, l){
return [r, g, b]; return [r, g, b];
} }
function hueToRgb(p, q, t){ function hueToRgb(p, q, t) {
if (t < 0) t += 1; if (t < 0) t += 1;
if (t > 1) t -= 1; if (t > 1) t -= 1;
if (t < 1 / 6) return p + (q - p) * 6 * t; if (t < 1 / 6) return p + (q - p) * 6 * t;

View File

@ -45,9 +45,9 @@ export default function comb(outline, start, end) {
if (snappedCombPaths.length === 0) { if (snappedCombPaths.length === 0) {
snappedCombPaths.push([start], [end]); snappedCombPaths.push([start], [end]);
} else if (distanceTo(firstPath[0], start) > 1.) { } else if (distanceTo(firstPath[0], start) > 1.0) {
snappedCombPaths.unshift([start]); snappedCombPaths.unshift([start]);
} else if (distanceTo(lastPath[lastPath.length - 1], end) > 1.) { } else if (distanceTo(lastPath[lastPath.length - 1], end) > 1.0) {
snappedCombPaths.push([end]); snappedCombPaths.push([end]);
} }

View File

@ -1,6 +1,6 @@
import { subtract, normal, normalize, dot, almostEquals } from './helpers/vector2.js'; import { subtract, normal, normalize, dot, almostEquals } from './helpers/vector2.js';
export default function intersectionsToShapes(layerPoints, layerFaceIndexes, faces, openObjectIndexes, settings) { export default function intersectionsToShapes(layerPoints, layerFaceIndexes, faces, openObjectIndexes) {
const layers = []; const layers = [];
for (let layer = 0; layer < layerPoints.length; layer ++) { for (let layer = 0; layer < layerPoints.length; layer ++) {

View File

@ -1,7 +1,7 @@
import { length, distanceTo } from './helpers/vector2.js'; import { distanceTo } from './helpers/vector2.js';
import Shape from 'clipper-js'; import Shape from 'clipper-js';
export default function optimizePaths(slices, settings) { export default function optimizePaths(slices) {
let start = { x: 0, y: 0 }; let start = { x: 0, y: 0 };
for (let layer = 0; layer < slices.length; layer ++) { for (let layer = 0; layer < slices.length; layer ++) {

View File

@ -3,7 +3,7 @@ import Slice from './helpers/Slice.js';
import { PRECISION, MIN_AREA } from '../constants.js'; import { PRECISION, MIN_AREA } from '../constants.js';
export default function shapesToSlices(shapes, settings) { export default function shapesToSlices(shapes) {
const sliceLayers = []; const sliceLayers = [];
for (let layer = 0; layer < shapes.length; layer ++) { for (let layer = 0; layer < shapes.length; layer ++) {

View File

@ -13,7 +13,7 @@ import applyPrecision from './applyPrecision.js';
import { hslToRgb } from './helpers/color.js'; import { hslToRgb } from './helpers/color.js';
// // import removePrecision from './removePrecision.js'; // // import removePrecision from './removePrecision.js';
export default function(settings, geometry, openObjectIndexes, constructLinePreview, onProgress) { export default function slice(settings, geometry, openObjectIndexes, constructLinePreview, onProgress) {
const total = 11; const total = 11;
let done = -1; let done = -1;
const updateProgress = action => { const updateProgress = action => {

View File

@ -10,14 +10,13 @@ export default function slicesToGCode(slices, settings) {
layerHeight, layerHeight,
filamentThickness, filamentThickness,
nozzleDiameter, nozzleDiameter,
travelSpeed,
retraction, retraction,
travel, travel,
combing combing
} = settings; } = settings;
const gcode = new GCode(settings); const gcode = new GCode(settings);
gcode.updateLayerHeight(Z_OFFSET, nozzleDiameter, filamentThickness) gcode.updateLayerHeight(Z_OFFSET, nozzleDiameter, filamentThickness);
if (settings.startCode) gcode.addGCode(settings.startCode, settings); if (settings.startCode) gcode.addGCode(settings.startCode, settings);
@ -37,12 +36,12 @@ export default function slicesToGCode(slices, settings) {
isFirstLayer = false; isFirstLayer = false;
} }
const profiles = PROFILE_TYPES.reduce((profiles, profileType) => { const profiles = PROFILE_TYPES.reduce((_profiles, profileType) => {
profiles[profileType] = { _profiles[profileType] = {
...defaultProfile, ...defaultProfile,
lineProfile: isFirstLayer ? settings.firstLayer : settings[profileType] lineProfile: isFirstLayer ? settings.firstLayer : settings[profileType]
}; };
return profiles; return _profiles;
}, {}); }, {});
if (typeof slice.brim !== 'undefined') { if (typeof slice.brim !== 'undefined') {
@ -82,7 +81,8 @@ export default function slicesToGCode(slices, settings) {
return gcode.getGCode(); return gcode.getGCode();
} }
function pathToGCode(outline, combing, gcode, shape, retract, unRetract, z, { lineProfile, travelProfile, retractionProfile }) { function pathToGCode(outline, combing, gcode, shape, retract, unRetract, z, profiles) {
const { lineProfile, travelProfile, retractionProfile } = profiles;
const { closed } = shape; const { closed } = shape;
const paths = shape.mapToLower(); const paths = shape.mapToLower();

View File

@ -99,6 +99,9 @@ function sliceAsync(settings, geometry, openObjectIndexes, constructLinePreview,
if (typeof onProgress !== 'undefined') onProgress(data); if (typeof onProgress !== 'undefined') onProgress(data);
break; break;
} }
default:
break;
} }
}); });

View File

@ -6,7 +6,7 @@ const onProgress = progress => {
message: 'PROGRESS', message: 'PROGRESS',
data: progress data: progress
}); });
} };
self.addEventListener('message', (event) => { self.addEventListener('message', (event) => {
const { message, data } = event.data; const { message, data } = event.data;
@ -28,5 +28,7 @@ self.addEventListener('message', (event) => {
}, buffers); }, buffers);
break; break;
} }
default:
break;
} }
}, false); }, false);