Skip to content

Commit

Permalink
Fix: v4.10.2 part2 (#2451)
Browse files Browse the repository at this point in the history
* Fix: Image slice default param greyscaleAlgorithm (all process mode)

* Fix: Svg bw process mode  miss param 'algorithm' to slice

* Fix: Blank gcode file name can't send to device

* Fix: Gcode file name consists only of spaces

* Fix: Laser text svg input refresh, input text is lost during refresh

* Fix: Workspace GcodeList update filename affect last item

* Fix: TextArea's value and default using
  • Loading branch information
IDKHTS authored Jan 16, 2024
1 parent 6712031 commit 8e1a0f2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
10 changes: 9 additions & 1 deletion src/app/models/ModelInfoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ const defaultConfigs = {

// Laser
[toKey(HEAD_LASER, PROCESS_MODE_BW)]: {
greyscaleAlgorithm: 'Luma',
algorithm: 'Atkinson',
invert: false,
bwThreshold: 168
},
[toKey(HEAD_LASER, PROCESS_MODE_HALFTONE)]: {
greyscaleAlgorithm: 'Luma',
algorithm: 'Atkinson',
invert: false,
threshold: 255, // turn pixel to white
bwThreshold: 168, // used by toolpath generator
Expand All @@ -116,11 +120,15 @@ const defaultConfigs = {
algorithm: 'Atkinson'
},
[toKey(HEAD_LASER, PROCESS_MODE_VECTOR, SOURCE_TYPE.RASTER)]: {
greyscaleAlgorithm: 'Luma',
algorithm: 'Atkinson',
vectorThreshold: 128,
invert: false,
turdSize: 2
},
[toKey(HEAD_LASER, PROCESS_MODE_VECTOR, SOURCE_TYPE.SVG)]: {
greyscaleAlgorithm: 'Luma',
algorithm: 'Atkinson',
'stroke-width': '0.25'
},
[toKey(HEAD_LASER, PROCESS_MODE_VECTOR, SOURCE_TYPE.TEXT)]: {
Expand Down Expand Up @@ -380,7 +388,7 @@ const generateModelDefaultConfigs = (headType, sourceType, mode, isRotate = fals
|| defaultConfigs[toKey(headType, mode, isRotate)]
|| defaultConfigs[toKey(headType, mode)]
|| defaultConfigs[toKey(headType)]
|| {};
|| { greyscaleAlgorithm: 'Luma' };
const gcodeConfig = defaultGcodeConfigs[toKey(headType, mode, sourceType, isRotate)]
|| defaultGcodeConfigs[toKey(headType, mode, sourceType)]
|| defaultGcodeConfigs[toKey(headType, mode, isRotate)]
Expand Down
11 changes: 3 additions & 8 deletions src/app/ui/components/Input/TextArea.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { debounce } from 'lodash';
import React, { useState, useCallback, useEffect } from 'react';
import React, { useState, useCallback } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Input } from 'antd';
Expand All @@ -8,13 +8,9 @@ import styles from './styles.styl';
const { TextArea } = Input;

const TextAreaInput = React.memo(({
className = '', value, defaultValue, disabled = false, onChange, ...rest
className = '', defaultValue, disabled = false, onChange, ...rest
}) => {
const [displayValue, setDisplayValue] = useState(value);

useEffect(() => {
setDisplayValue(value);
}, [value]);
const [displayValue, setDisplayValue] = useState(defaultValue);

const changeHandler = useCallback((newValue) => {
onChange && onChange(newValue);
Expand Down Expand Up @@ -53,7 +49,6 @@ const TextAreaInput = React.memo(({

TextAreaInput.propTypes = {
className: PropTypes.string,
value: PropTypes.string,
defaultValue: PropTypes.string,
disabled: PropTypes.bool,
onChange: PropTypes.func
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/widgets/CncLaserShared/TextParameters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const TextParameters = ({ headType, modifyText, disabled }) => {
disabled={disabled}
className="sm-flex-width"
rows="3"
value={text}
defaultValue={text}
onChange={actions.onChangeText}
/>
</div>
Expand Down
21 changes: 15 additions & 6 deletions src/app/ui/widgets/ConnectionFileTransfer/FileTransferView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ const WifiTransport: React.FC<FileTransferViewProps> = (props) => {

const [showLaserStartJobModal, setShowLaserStartJobModal] = useState(false);
const fileInput = useRef();
const gcodeItemRef = useRef();
const gcodeItemRef = useRef([]);
const canvas = useRef();
const prevProps = usePrevious({
previewStage
});

const onSelectFile = useCallback((_selectFileName, name, event, needToUnselect = true) => {
const onSelectFile = useCallback((_selectFileName: string, event?: MouseEvent, needToUnselect: boolean = true) => {
if (event && event.target && event.target.className && typeof event.target.className.indexOf === 'function') {
if (event.target.className.indexOf('input-select') > -1
|| event.target.className.indexOf('fa-check') > -1) {
Expand Down Expand Up @@ -455,10 +455,10 @@ const WifiTransport: React.FC<FileTransferViewProps> = (props) => {
<React.Fragment key={index}>
<GcodePreviewItem
gcodeFile={gcodeFile}
index={index}
index={parseInt(index, 10)}
selected={selectFileName === gcodeFile.uploadName}
onSelectFile={onSelectFile}
gRef={gcodeItemRef}
gRef={ref => { gcodeItemRef?.current[index] = ref; }}
setSelectFileIndex={setSelectFileIndex}
/>
</React.Fragment>
Expand All @@ -474,7 +474,16 @@ const WifiTransport: React.FC<FileTransferViewProps> = (props) => {
size={24}
title={i18n._('key-Workspace/Transport-Edit')}
disabled={!selectedFile}
onClick={(e) => gcodeItemRef.current.remaneStart(selectedFile.uploadName, selectFileIndex, e)}
onClick={
(e) => {
gcodeItemRef.current[selectFileIndex].remaneStart(
selectedFile.uploadName,
selectFileIndex,
selectedFile.renderGcodeFileName,
e
);
}
}
/>
<SvgIcon
name="Import"
Expand All @@ -494,7 +503,7 @@ const WifiTransport: React.FC<FileTransferViewProps> = (props) => {
size={24}
title={i18n._('key-Workspace/Transport-Delete')}
disabled={!selectedFile}
onClick={() => gcodeItemRef.current.removeFile(selectedFile)}
onClick={() => gcodeItemRef.current[selectFileIndex].removeFile(selectedFile)}
/>
</div>
<div className={classNames('sm-flex', 'justify-space-between', 'align-center', 'margin-top-8')}>
Expand Down
23 changes: 15 additions & 8 deletions src/app/ui/widgets/ConnectionFileTransfer/GCodeListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
import React, { useEffect, useImperativeHandle, useRef } from 'react';
import { useDispatch } from 'react-redux';

import { message } from 'antd';
import { pathWithRandomSuffix } from '../../../../shared/lib/random-utils';
import { actions as workspaceActions } from '../../../flux/workspace';
import gcodeActions from '../../../flux/workspace/actions-gcode';
Expand All @@ -20,9 +21,9 @@ declare interface GcodePreviewItemProps {
gcodeFile: object;
index: number;
selected: boolean;
onSelectFile: () => {};
onSelectFile: (_selectFileName: string, event: MouseEvent, needToUnselect?: boolean) => void;
gRef: object;
setSelectFileIndex: () => {};
setSelectFileIndex: (index: number) => void;
}


Expand All @@ -36,7 +37,7 @@ const GcodePreviewItem: React.FC<GcodePreviewItemProps> = React.memo((props) =>
const { prefixName, suffixName } = normalizeNameDisplay(gcodeFile?.renderGcodeFileName || gcodeFile?.name, suffixLength);

let size = '';
const { isRenaming, uploadName } = gcodeFile;
const { isRenaming } = gcodeFile;
if (!gcodeFile.size) {
size = '';
} else if (gcodeFile.size / 1024 / 1024 > 1) {
Expand Down Expand Up @@ -69,6 +70,11 @@ const GcodePreviewItem: React.FC<GcodePreviewItemProps> = React.memo((props) =>
if (!changeNameInput.current) {
return;
}
if (!changeNameInput.current.value || !changeNameInput.current.value.trim()) {
message.error("file name can't be blank");
changeNameInput.current.focus();
return;
}
let newName = changeNameInput.current.value;
const m = _uploadName.match(/(\.gcode|\.cnc|\.nc)$/);
if (m) {
Expand All @@ -78,8 +84,9 @@ const GcodePreviewItem: React.FC<GcodePreviewItemProps> = React.memo((props) =>
};

const onRenameStart = (_uploadName, _index, _renderGcodeFileName = '', event) => {
if (!selected) return;
dispatch(workspaceActions.renameGcodeFile(_uploadName, null, true));
event.stopPropagation();
event && event.stopPropagation();
setTimeout(() => {
changeNameInput.current.value = replace(_renderGcodeFileName, /(\.gcode|\.cnc|\.nc)$/, '') || _uploadName;
changeNameInput.current.focus();
Expand All @@ -91,7 +98,7 @@ const GcodePreviewItem: React.FC<GcodePreviewItemProps> = React.memo((props) =>
};

useImperativeHandle(gRef, () => ({
remaneStart: (_uploadName, _index, e) => onRenameStart(_uploadName, _index, e),
remaneStart: (_uploadName, _index, _renderGcodeFileName, e) => onRenameStart(_uploadName, _index, _renderGcodeFileName, e),
removeFile: (_gcodeFile) => onRemoveFile(_gcodeFile)
}));

Expand All @@ -109,7 +116,7 @@ const GcodePreviewItem: React.FC<GcodePreviewItemProps> = React.memo((props) =>
)}
key={pathWithRandomSuffix(gcodeFile.uploadName)}
onClick={
(event) => onSelectFile(gcodeFile.uploadName, null, event)
(event) => onSelectFile(gcodeFile.uploadName, event)
}
onKeyDown={noop}
role="button"
Expand Down Expand Up @@ -163,7 +170,7 @@ const GcodePreviewItem: React.FC<GcodePreviewItemProps> = React.memo((props) =>
<input
defaultValue={gcodeFile?.renderGcodeFileName?.replace(/(\.gcode|\.cnc|\.nc)$/, '')}
className={classNames('input-select')}
onBlur={() => onRenameEnd(uploadName)}
onBlur={() => onRenameEnd(gcodeFile?.uploadName)}
onKeyDown={(event) => onKeyDown(event)}
ref={changeNameInput}
/>
Expand All @@ -180,7 +187,7 @@ const GcodePreviewItem: React.FC<GcodePreviewItemProps> = React.memo((props) =>
className="height-48 position-absolute right-16"
size={24}
onClick={() => {
onSelectFile(gcodeFile.uploadName, null, null, false);
onSelectFile(gcodeFile.uploadName, null, false);
dispatch(gcodeActions.renderPreviewGcodeFile(gcodeFile));
}}
/>
Expand Down

0 comments on commit 8e1a0f2

Please sign in to comment.