Skip to content

Commit

Permalink
Refactor: Rename multipleSelectedModel to duplicateSelectedModel
Browse files Browse the repository at this point in the history
- Add CNC duplicate
- rename isPreview to isProcess
  • Loading branch information
zjiefee committed Apr 27, 2020
1 parent 2c64c64 commit c5086ba
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/app/containers/Header/PageControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PageControl extends Component {
return null;
}
const isEditor = page === PAGE_EDITOR;
const isPreview = page === PAGE_PROCESS;
const isProcess = page === PAGE_PROCESS;

return (
<div className={classNames(styles['editor-and-preview'])}>
Expand All @@ -43,7 +43,7 @@ class PageControl extends Component {
</button>
<button
type="button"
className={classNames('btn', { [styles.selected]: isPreview })}
className={classNames('btn', { [styles.selected]: isProcess })}
onClick={() => {
this.props.togglePage(from, PAGE_PROCESS);
}}
Expand Down
18 changes: 9 additions & 9 deletions src/app/flux/cncLaserShared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,12 +736,12 @@ export const actions = {
toolPathModelGroup.hideAllToolPathModelsObj3D();
},

changeModelVisualizer: (headType, modelID, isPreview) => (dispatch, getState) => {
changeModelVisualizer: (headType, modelID, isProcess) => (dispatch, getState) => {
const { page, modelGroup, toolPathModelGroup } = getState()[headType];
if (page === PAGE_PROCESS) {
const model = modelGroup.getModel(modelID);
const toolPathModel = toolPathModelGroup.getToolPathModel(modelID);
if (isPreview) {
if (isProcess) {
model.updateVisible(false);
toolPathModel.updateVisible(true);
} else {
Expand All @@ -751,12 +751,12 @@ export const actions = {
}
},

manualPreview: (headType, isPreview) => (dispatch, getState) => {
manualPreview: (headType, isProcess) => (dispatch, getState) => {
const { page, modelGroup, toolPathModelGroup, autoPreviewEnabled } = getState()[headType];
if (page === PAGE_EDITOR) {
return;
}
if (isPreview || autoPreviewEnabled) {
if (isProcess || autoPreviewEnabled) {
for (const model of modelGroup.getModels()) {
const modelTaskInfo = model.getTaskInfo();
const toolPathModelTaskInfo = toolPathModelGroup.getToolPathModelTaskInfo(modelTaskInfo.modelID);
Expand All @@ -775,12 +775,12 @@ export const actions = {
}
},

previewModel: (headType, isPreview) => (dispatch, getState) => {
previewModel: (headType, isProcess) => (dispatch, getState) => {
const { page, modelGroup, toolPathModelGroup, autoPreviewEnabled } = getState()[headType];
if (page === PAGE_EDITOR) {
return;
}
if (isPreview || autoPreviewEnabled) {
if (isProcess || autoPreviewEnabled) {
const modelState = modelGroup.getSelectedModel().getTaskInfo();
if (modelState) {
const toolPathModelTaskInfo = toolPathModelGroup.getToolPathModelTaskInfo(modelState.modelID);
Expand Down Expand Up @@ -841,10 +841,10 @@ export const actions = {
}
},

multiplySelectedModel: (headType) => (dispatch, getState) => {
duplicateSelectedModel: (headType) => (dispatch, getState) => {
const { modelGroup, toolPathModelGroup } = getState()[headType];
const modelState = modelGroup.multiplySelectedModel(1);
toolPathModelGroup.multiplySelectedModel(modelState.modelID);
const modelState = modelGroup.duplicateSelectedModel();
toolPathModelGroup.duplicateSelectedModel(modelState.modelID);

dispatch(actions.recordSnapshot(headType));
dispatch(actions.manualPreview(headType));
Expand Down
4 changes: 2 additions & 2 deletions src/app/flux/keyboardShortcut/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const actions = {
const from = window.location.hash.split('/')[1];
if (from === '3dp') {
const { displayedType } = getState().printing;
displayedType === 'model' && (dispatch(printingActions.multiplySelectedModel(1)));
displayedType === 'model' && (dispatch(printingActions.duplicateSelectedModel()));
} else {
dispatch(cncLaserSharedActions.multiplySelectedModel(from));
dispatch(cncLaserSharedActions.duplicateSelectedModel(from));
}
},
'JOG': (event, { direction }) => {
Expand Down
50 changes: 24 additions & 26 deletions src/app/flux/models/ModelGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,36 +319,34 @@ class ModelGroup {
return this.selectedModel ? this.getState(this.selectedModel) : this._emptyState;
}

multiplySelectedModel(count) {
duplicateSelectedModel() {
const selected = this.getSelectedModel();
if (selected && count > 0) {
if (selected) {
let modelID;
for (let i = 0; i < count; i++) {
const model = selected.clone();
if (selected.sourceType === '3d') {
model.stickToPlate();
model.meshObject.position.x = 0;
model.meshObject.position.z = 0;
const xz = this._computeAvailableXZ(model);
model.meshObject.position.x = xz.x;
model.meshObject.position.z = xz.z;
} else {
model.meshObject.addEventListener('update', this.onModelUpdate);
model.modelID = uuid.v4();
modelID = model.modelID;
model.computeBoundingBox();
model.updateTransformation({
positionX: 0,
positionY: 0,
positionZ: 0
});
}

// this.add(model);
this.models.push(model);
this.object.add(model.meshObject);
const model = selected.clone();
if (selected.sourceType === '3d') {
model.stickToPlate();
model.meshObject.position.x = 0;
model.meshObject.position.z = 0;
const xz = this._computeAvailableXZ(model);
model.meshObject.position.x = xz.x;
model.meshObject.position.z = xz.z;
} else {
model.meshObject.addEventListener('update', this.onModelUpdate);
model.modelID = uuid.v4();
modelID = model.modelID;
model.computeBoundingBox();
model.updateTransformation({
positionX: 0,
positionY: 0,
positionZ: 0
});
}

// this.add(model);
this.models.push(model);
this.object.add(model.meshObject);

return {
modelID: modelID,
hasModel: this._hasModel(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/flux/models/ToolPathModelGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ToolPathModelGroup {
return null;
}

multiplySelectedModel(modelID) {
duplicateSelectedModel(modelID) {
const clone = this.selectedToolPathModel.clone();
clone.modelID = modelID;
clone.updateNeedPreview(true);
Expand Down
4 changes: 2 additions & 2 deletions src/app/flux/printing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,9 +1007,9 @@ export const actions = {
dispatch(actions.displayModel());
},

multiplySelectedModel: (count) => (dispatch, getState) => {
duplicateSelectedModel: () => (dispatch, getState) => {
const { modelGroup } = getState().printing;
const modelState = modelGroup.multiplySelectedModel(count);
const modelState = modelGroup.duplicateSelectedModel();
dispatch(actions.updateState(modelState));
dispatch(actions.recordSnapshot());
dispatch(actions.destroyGcodeLine());
Expand Down
11 changes: 11 additions & 0 deletions src/app/widgets/CNCVisualizer/Visualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Visualizer extends Component {
selectModel: PropTypes.func.isRequired,
unselectAllModels: PropTypes.func.isRequired,
removeSelectedModel: PropTypes.func.isRequired,
duplicateSelectedModel: PropTypes.func.isRequired,
onModelTransform: PropTypes.func.isRequired,
onModelAfterTransform: PropTypes.func.isRequired
};
Expand Down Expand Up @@ -104,6 +105,9 @@ class Visualizer extends Component {
},
arrangeAllModels: () => {
this.props.arrangeAllModels2D();
},
duplicateSelectedModel: () => {
this.props.duplicateSelectedModel();
}
};

Expand Down Expand Up @@ -326,6 +330,12 @@ class Visualizer extends Component {
id="cnc"
menuItems={
[
{
type: 'item',
label: i18n._('Duplicate Selected Model'),
disabled: !isModelSelected,
onClick: this.actions.duplicateSelectedModel
},
{
type: 'item',
label: i18n._('Bring to Front'),
Expand Down Expand Up @@ -464,6 +474,7 @@ const mapDispatchToProps = (dispatch) => {
onFlipSelectedModel: (flip) => dispatch(actions.onFlipSelectedModel('cnc', flip)),
selectModel: (model) => dispatch(actions.selectModel('cnc', model)),
unselectAllModels: () => dispatch(actions.unselectAllModels('cnc')),
duplicateSelectedModel: () => dispatch(actions.duplicateSelectedModel('cnc')),
removeSelectedModel: () => dispatch(actions.removeSelectedModel('cnc')),
onModelTransform: () => dispatch(actions.onModelTransform('cnc')),
onModelAfterTransform: () => dispatch(actions.onModelAfterTransform('cnc'))
Expand Down
6 changes: 3 additions & 3 deletions src/app/widgets/LaserOutput/Output.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ class Output extends PureComponent {
const actions = this.actions;
const { workflowState, isAllModelsPreviewed, isGcodeGenerating, autoPreviewEnabled, gcodeFile } = this.props;
const isEditor = this.props.page === PAGE_EDITOR;
const isPreview = this.props.page === PAGE_PROCESS;
const isProcess = this.props.page === PAGE_PROCESS;

return (
<div>
<div>
<button
type="button"
className="sm-btn-large sm-btn-default"
disabled={isPreview && autoPreviewEnabled}
disabled={isProcess && autoPreviewEnabled}
onClick={this.actions.onProcess}
style={{ display: 'block', width: '100%' }}
>
{isPreview ? i18n._('Preview') : i18n._('Process')}
{isProcess ? i18n._('Preview') : i18n._('Process')}
</button>
<TipTrigger
title={i18n._('Auto Preview')}
Expand Down
14 changes: 7 additions & 7 deletions src/app/widgets/LaserParams/LaserParameters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class LaserParameters extends PureComponent {
const { width, height } = this.state.modalSetting;

const isEditor = this.props.page === PAGE_EDITOR;
const isPreview = this.props.page === PAGE_PROCESS;
const isProcess = this.props.page === PAGE_PROCESS;
const isBW = (sourceType === 'raster' && mode === 'bw');
const isGreyscale = (sourceType === 'raster' && mode === 'greyscale');
const isRasterVector = (sourceType === 'raster' && mode === 'vector');
Expand Down Expand Up @@ -251,26 +251,26 @@ class LaserParameters extends PureComponent {
updateSelectedModelTextConfig={updateSelectedModelTextConfig}
/>
)}
{isPreview && isBW && (
{isProcess && isBW && (
<GcodeConfigRasterBW />
)}
{isPreview && isGreyscale && (
{isProcess && isGreyscale && (
<GcodeConfigGreyscale />
)}
{isPreview && isRasterVector && (
{isProcess && isRasterVector && (
<GcodeConfigRasterVector />
)}
{isPreview && isSvgVector && (
{isProcess && isSvgVector && (
<GcodeConfigSvgVector />
)}
{isPreview && isTextVector && (
{isProcess && isTextVector && (
<GcodeConfigSvgVector />
)}
</div>
</div>

)}
{isPreview && (
{isProcess && (
<GcodeParameters
selectedModelID={selectedModelID}
printOrder={printOrder}
Expand Down
10 changes: 5 additions & 5 deletions src/app/widgets/LaserVisualizer/Visualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Visualizer extends Component {
selectModel: PropTypes.func.isRequired,
unselectAllModels: PropTypes.func.isRequired,
removeSelectedModel: PropTypes.func.isRequired,
multiplySelectedModel: PropTypes.func.isRequired,
duplicateSelectedModel: PropTypes.func.isRequired,
onModelTransform: PropTypes.func.isRequired,
onModelAfterTransform: PropTypes.func.isRequired
};
Expand Down Expand Up @@ -106,8 +106,8 @@ class Visualizer extends Component {
arrangeAllModels: () => {
this.props.arrangeAllModels2D();
},
multiplySelectedModel: () => {
this.props.multiplySelectedModel();
duplicateSelectedModel: () => {
this.props.duplicateSelectedModel();
}
};

Expand Down Expand Up @@ -295,7 +295,7 @@ class Visualizer extends Component {
type: 'item',
label: i18n._('Duplicate Selected Model'),
disabled: !isModelSelected,
onClick: this.actions.multiplySelectedModel
onClick: this.actions.duplicateSelectedModel
},
{
type: 'item',
Expand Down Expand Up @@ -440,7 +440,7 @@ const mapDispatchToProps = (dispatch) => {
selectModel: (model) => dispatch(actions.selectModel('laser', model)),
unselectAllModels: () => dispatch(actions.unselectAllModels('laser')),
removeSelectedModel: () => dispatch(actions.removeSelectedModel('laser')),
multiplySelectedModel: () => dispatch(actions.multiplySelectedModel('laser')),
duplicateSelectedModel: () => dispatch(actions.duplicateSelectedModel('laser')),
onModelTransform: () => dispatch(actions.onModelTransform('laser')),
onModelAfterTransform: () => dispatch(actions.onModelAfterTransform('laser'))
};
Expand Down
6 changes: 3 additions & 3 deletions src/app/widgets/PrintingVisualizer/Visualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Visualizer extends PureComponent {
onModelTransform: PropTypes.func.isRequired,
onModelAfterTransform: PropTypes.func.isRequired,
updateSelectedModelTransformation: PropTypes.func.isRequired,
multiplySelectedModel: PropTypes.func.isRequired,
duplicateSelectedModel: PropTypes.func.isRequired,
layFlatSelectedModel: PropTypes.func.isRequired
};

Expand Down Expand Up @@ -98,7 +98,7 @@ class Visualizer extends PureComponent {
this.props.removeSelectedModel();
},
duplicateSelectedModel: () => {
this.props.multiplySelectedModel(1);
this.props.duplicateSelectedModel();
},
resetSelectedModelTransformation: () => {
this.props.updateSelectedModelTransformation({
Expand Down Expand Up @@ -370,7 +370,7 @@ const mapDispatchToProps = (dispatch) => ({
onModelTransform: () => dispatch(printingActions.onModelTransform()),
onModelAfterTransform: () => dispatch(printingActions.onModelAfterTransform()),
updateSelectedModelTransformation: (transformation) => dispatch(printingActions.updateSelectedModelTransformation(transformation)),
multiplySelectedModel: (count) => dispatch(printingActions.multiplySelectedModel(count)),
duplicateSelectedModel: () => dispatch(printingActions.duplicateSelectedModel()),
layFlatSelectedModel: () => dispatch(printingActions.layFlatSelectedModel())
});

Expand Down

0 comments on commit c5086ba

Please sign in to comment.