mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 05:37:55 +01:00
add download code
This commit is contained in:
parent
3b4df148ed
commit
ccc676ebd1
@ -3,9 +3,17 @@ import * as THREE from 'three';
|
||||
import { Interface } from 'doodle3d-slicer';
|
||||
import fileURL from '!url-loader!./models/shape.json';
|
||||
import { render } from 'react-dom';
|
||||
// import fileSaver from 'file-saver';
|
||||
import fileSaver from 'file-saver';
|
||||
|
||||
const downloadGCode = gcode => {
|
||||
const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
|
||||
fileSaver.saveAs(file);
|
||||
};
|
||||
|
||||
const jsonLoader = new THREE.JSONLoader();
|
||||
jsonLoader.load(fileURL, geometry => {
|
||||
render(<Interface geometry={geometry} />, document.getElementById('app'));
|
||||
render(<Interface
|
||||
geometry={geometry}
|
||||
onCompleteActions={[{ title: 'Download', callback: downloadGCode }]}
|
||||
/>, document.getElementById('app'));
|
||||
});
|
||||
|
@ -46,6 +46,7 @@ class Interface extends React.Component {
|
||||
classes: PropTypes.objectOf(PropTypes.string),
|
||||
printers: PropTypes.object.isRequired,
|
||||
defaultPrinter: PropTypes.string.isRequired,
|
||||
onCompleteActions: PropTypes.arrayOf(PropTypes.shape({ title: PropTypes.string, callback: PropTypes.func })).isRequired,
|
||||
};
|
||||
state = {
|
||||
controlMode: 'translate',
|
||||
@ -126,8 +127,9 @@ class Interface extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { width, height, classes } = this.props;
|
||||
const { sliced } = this.state;
|
||||
const { width, height, classes, onCompleteActions } = this.props;
|
||||
const { sliced, gcode } = this.state;
|
||||
|
||||
return (
|
||||
<div style={{ width, height }} className={classes.container}>
|
||||
<canvas className={classes.canvas} ref="canvas" width={width} height={height} />
|
||||
@ -142,7 +144,9 @@ class Interface extends React.Component {
|
||||
</div>}
|
||||
{sliced && <div className={classes.sliceBar}>
|
||||
<button onClick={this.reset}>Slice Again</button>
|
||||
<button>Download</button>
|
||||
{onCompleteActions.map(({ title, callback }, i) => (
|
||||
<button key={i} onClick={() => callback(gcode.gcode)}>{title}</button>
|
||||
))}
|
||||
</div>}
|
||||
</div>
|
||||
);
|
||||
|
@ -96,7 +96,7 @@ function gcodeToString(gcode) {
|
||||
const value = command[action];
|
||||
const currentValue = currentValues[action];
|
||||
if (first) {
|
||||
string = action + value;
|
||||
string += action + value;
|
||||
first = false;
|
||||
} else if (currentValue !== value) {
|
||||
string += ` ${action}${value}`;
|
||||
@ -104,6 +104,7 @@ function gcodeToString(gcode) {
|
||||
}
|
||||
}
|
||||
string += '\n';
|
||||
return string;
|
||||
}, '');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user