Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fix bug on four-axis part #626

Merged
merged 3 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/app/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const recoverProjectFile = defaultAPIFactory((data) => request.post('/api/file/r


const uploadImage = defaultAPIFactory((formdata) => request.post('/api/image').send(formdata));
const uploadLaserCaseImage = defaultAPIFactory((formdata) => request.post('/api/image/laserCaseImage').send(formdata));


// Stock Remap
Expand Down Expand Up @@ -311,7 +310,6 @@ export default {
packageEnv,
recoverProjectFile,
uploadImage,
uploadLaserCaseImage,
stockRemapProcess,
processImage,
processTrace,
Expand Down
1 change: 1 addition & 0 deletions src/app/components/SMCanvas/TransformControls2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class TransformControls2D extends Object3D {

updateFramePeripheralVisible(visible) {
this.framePeripheral.visible = visible;
this.dispatchEvent(EVENTS.UPDATE);
}


Expand Down
10 changes: 9 additions & 1 deletion src/app/flux/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,16 @@ export const actions = {
},

uploadCaseImage: (headType, file, mode, caseConfigs, caseTransformation, onError) => (dispatch) => {
api.uploadLaserCaseImage(file)
dispatch(actions.updateState(headType, {
stage: CNC_LASER_STAGE.UPLOADING_IMAGE,
progress: 0.25
}));
api.uploadImage(file)
.then((res) => {
dispatch(actions.updateState(headType, {
stage: CNC_LASER_STAGE.UPLOAD_IMAGE_SUCCESS,
progress: 1
}));
const { width, height, originalName, uploadName } = res.body;
const { config } = caseConfigs;
const { gcodeConfig } = caseConfigs;
Expand Down
10 changes: 5 additions & 5 deletions src/app/flux/machine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const actions = {
dispatch(editorActions.updateMaterials(headType.toLowerCase(), {
isRotate: true
}));
dispatch(actions.updateState({
dispatch(baseActions.updateState({
workPosition: {
...machineState.workPosition,
...pos
Expand All @@ -237,7 +237,7 @@ export const actions = {
dispatch(editorActions.updateMaterials(headType.toLowerCase(), {
isRotate: false
}));
dispatch(actions.updateState({
dispatch(baseActions.updateState({
workPosition: {
...machineState.workPosition,
...pos
Expand Down Expand Up @@ -572,7 +572,7 @@ export const actions = {
dispatch(editorActions.updateMaterials(headType.toLowerCase(), {
isRotate: true
}));
dispatch(actions.updateState({
dispatch(baseActions.updateState({
workPosition: {
x: `${x.toFixed(3)}`,
y: `${y.toFixed(3)}`,
Expand All @@ -590,7 +590,7 @@ export const actions = {
dispatch(editorActions.updateMaterials(headType.toLowerCase(), {
isRotate: false
}));
dispatch(actions.updateState({
dispatch(baseActions.updateState({
workPosition: {
x: `${x.toFixed(3)}`,
y: `${y.toFixed(3)}`,
Expand All @@ -604,7 +604,7 @@ export const actions = {
if (Number(originOffset.x) !== offsetX
|| Number(originOffset.y) !== offsetY
|| Number(originOffset.z) !== offsetZ) {
dispatch(actions.updateState({
dispatch(baseActions.updateState({
originOffset: {
x: `${offsetX.toFixed(3)}`,
y: `${offsetY.toFixed(3)}`,
Expand Down
18 changes: 1 addition & 17 deletions src/app/widgets/CaseLibrary/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import classNames from 'classnames';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import log from '../../lib/log';
import { MACHINE_SERIES } from '../../constants';
import api from '../../api';
import modal from '../../lib/modal';
Expand Down Expand Up @@ -99,21 +98,7 @@ class CaseLibrary extends PureComponent {
}
},
loadLaserCncCaseSettings: async (config) => {
if (config.mode === 'trace') {
const res = await api.uploadLaserCaseImage(config.pathConfig, config.mode, () => {
modal({
title: i18n._('Parse Error'),
body: i18n._('Failed to parse image file {{filename}}.', { filename: config.pathConfig.name })
});
});
const result = await api.processTrace({
originalName: res.body.originalName,
uploadName: res.body.uploadName,
width: res.body.width,
height: res.body.height
});
log.warn('trace', res, result);
} else if (config.mode === 'text') {
if (config.mode === 'text') {
if (config.tag === 'laser') {
await this.props.insertDefaultLaserTextVector(config.caseConfigs, config.caseTransformation);
} else {
Expand Down Expand Up @@ -163,7 +148,6 @@ class CaseLibrary extends PureComponent {
const casePath = config.pathConfig.casePath;
formData.append('casePath', casePath);
formData.append('name', name);
formData.append('isCaseGcode', config.isCaseGcode);
api.uploadGcodeFile(formData)
.then((res) => {
const response = res.body;
Expand Down
8 changes: 4 additions & 4 deletions src/app/widgets/LaserVisualizer/Visualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Visualizer extends Component {

onSetSelectedModelPosition: PropTypes.func.isRequired,
onFlipSelectedModel: PropTypes.func.isRequired,
selectTargetModel: PropTypes.func.isRequired,
selectModelInProcess: PropTypes.func.isRequired,
removeSelectedModel: PropTypes.func.isRequired,
duplicateSelectedModel: PropTypes.func.isRequired,
// onModelTransform: PropTypes.func.isRequired,
Expand Down Expand Up @@ -109,10 +109,10 @@ class Visualizer extends Component {
this.props.updateScale(1);
this.props.updateTarget({ x: 0, y: 0 });
},
onSelectModels: (intersect) => { // this is a toolpath model? mesh object??
onSelectModels: (intersect, selectEvent) => { // this is a toolpath model? mesh object??
// todo
// console.log('----on process select----', model);
this.props.selectTargetModel(intersect);
this.props.selectModelInProcess(intersect, selectEvent);
},
/*
onModelAfterTransform: () => {
Expand Down Expand Up @@ -541,7 +541,7 @@ const mapDispatchToProps = (dispatch) => {
insertDefaultTextVector: () => dispatch(editorActions.insertDefaultTextVector('laser')),
onSetSelectedModelPosition: (position) => dispatch(editorActions.onSetSelectedModelPosition('laser', position)),
onFlipSelectedModel: (flip) => dispatch(editorActions.onFlipSelectedModel('laser', flip)),
selectTargetModel: (intersect) => dispatch(editorActions.selectModelInProcess('laser', intersect)),
selectModelInProcess: (intersect, selectEvent) => dispatch(editorActions.selectModelInProcess('laser', intersect, selectEvent)),
removeSelectedModel: () => dispatch(editorActions.removeSelectedModel('laser')),
duplicateSelectedModel: () => dispatch(editorActions.duplicateSelectedModel('laser')),

Expand Down
2 changes: 1 addition & 1 deletion src/server/lib/MeshProcess/MeshProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export class MeshProcess {

const layerThickness = 1 / this.sliceDensity;
const initialLayerThickness = layerThickness / 2;

const imageWidth = Math.floor((width - initialLayerThickness) / layerThickness) + 1;
const imageHeight = Math.floor((height - initialLayerThickness) / layerThickness) + 1;

Expand Down Expand Up @@ -254,6 +253,7 @@ export class MeshProcess {

const imageWidth = Math.ceil(width * this.sliceDensity);
const imageHeight = Math.floor((height - initialLayerThickness) / layerThickness) + 1;
console.log('convertTo3AxisImage', r, r * Math.PI * 2, this.mesh.aabb.length, this.sliceDensity, width, imageWidth);

const slicer = new Slicer(this.mesh, layerThickness, imageHeight, initialLayerThickness);

Expand Down
103 changes: 24 additions & 79 deletions src/server/services/api/api-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,92 +21,36 @@ import { mmToPixel } from '../../../shared/lib/utils';
const log = logger('api:image');

export const set = (req, res) => {
const file = req.files.image;
const originalName = path.basename(file.name);

const uploadName = pathWithRandomSuffix(originalName);
const uploadPath = `${DataStorage.tmpDir}/${uploadName}`;
const extname = path.extname(uploadName).toLowerCase();
const files = req.files;
const { isRotate } = req.body;
let originalName, uploadName, uploadPath, originalPath;
// if 'files' does not exist, the model in the case library is being loaded
if (files) {
const file = files.image;
originalName = path.basename(file.name);
uploadName = pathWithRandomSuffix(originalName);
uploadPath = `${DataStorage.tmpDir}/${uploadName}`;
originalPath = file.path;
} else {
const { name, casePath } = req.body;
originalName = path.basename(name);
originalPath = `${DataStorage.userCaseDir}/${casePath}/${name}`;
uploadName = pathWithRandomSuffix(originalName);
uploadPath = `${DataStorage.tmpDir}/${uploadName}`;
}
const extname = path.extname(uploadName).toLowerCase();

async.series([
(next) => {
mv(file.path, uploadPath, () => {
next();
});
},
async (next) => {
if (extname === '.svg') {
const svgParser = new SVGParser();
const svg = await svgParser.parseFile(uploadPath);

res.send({
originalName: originalName,
uploadName: uploadName,
width: svg.width,
height: svg.height
});

next();
} else if (extname === '.dxf') {
const result = await parseDxf(uploadPath);
const { width, height } = result;

res.send({
originalName: originalName,
uploadName: uploadName,
width,
height
});

next();
} else if (extname === '.stl') {
const meshProcess = new MeshProcess({ uploadName, materials: { isRotate: isRotate === 'true' } });
const { width, height } = meshProcess.getWidthAndHeight();
res.send({
originalName: originalName,
uploadName: uploadName,
width: mmToPixel(width),
height: mmToPixel(height)
if (files) {
mv(originalPath, uploadPath, () => {
next();
});
next();
} else {
jimp.read(uploadPath).then((image) => {
res.send({
originalName: originalName,
uploadName: uploadName,
width: image.bitmap.width,
height: image.bitmap.height
});
fs.copyFile(originalPath, uploadPath, () => {
next();
}).catch((err) => {
next(err);
});
}
}
], (err) => {
if (err) {
log.error(`Failed to read image ${uploadName}`);
res.status(ERR_INTERNAL_SERVER_ERROR).end();
} else {
res.end();
}
});
};

export const laserCaseImage = (req, res) => {
const { name, casePath, isRotate } = req.body;
let originalName = path.basename(name);
const originalPath = `${DataStorage.userCaseDir}/${casePath}/${name}`;
let uploadName = pathWithRandomSuffix(originalName);
const uploadPath = `${DataStorage.tmpDir}/${uploadName}`;
const extname = path.extname(uploadName).toLowerCase();

async.series([
(next) => {
fs.copyFile(originalPath, uploadPath, () => {
next();
});
},
async (next) => {
if (extname === '.svg') {
Expand All @@ -119,6 +63,7 @@ export const laserCaseImage = (req, res) => {
width: svg.width,
height: svg.height
});

next();
} else if (extname === '.dxf') {
const result = await parseDxf(uploadPath);
Expand All @@ -130,9 +75,9 @@ export const laserCaseImage = (req, res) => {
width,
height
});

next();
} else if (extname === '.stl' || extname === '.zip') {
console.log('uploadName', originalName, uploadName, extname);
if (extname === '.zip') {
await unzipFile(`${uploadName}`, `${DataStorage.tmpDir}`);
originalName = originalName.replace(/\.zip$/, '');
Expand Down Expand Up @@ -163,7 +108,7 @@ export const laserCaseImage = (req, res) => {
}
], (err) => {
if (err) {
log.error(`Failed to read image ${uploadName} and err is ${err}`);
log.error(`Failed to read image ${uploadName}`);
res.status(ERR_INTERNAL_SERVER_ERROR).end();
} else {
res.end();
Expand Down
1 change: 0 additions & 1 deletion src/server/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function registerApis(app) {

// Image
app.post(urljoin(settings.route, 'api/image'), api.image.set);
app.post(urljoin(settings.route, 'api/image/laserCaseImage'), api.image.laserCaseImage);
app.post(urljoin(settings.route, 'api/image/process'), api.image.process);
app.post(urljoin(settings.route, 'api/image/stock'), api.image.stockRemapProcess);
app.post(urljoin(settings.route, 'api/image/trace'), api.image.processTrace);
Expand Down