mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-12 11:25:04 +01:00
error reporting for craft operations
This commit is contained in:
parent
f1c055c77c
commit
ee659f97c4
4 changed files with 47 additions and 32 deletions
|
|
@ -41,23 +41,13 @@ export function activate({bus, services}) {
|
|||
let op = services.operation.registry[request.type];
|
||||
if (!op) return `unknown operation ${request.type}`;
|
||||
|
||||
let result;
|
||||
try {
|
||||
result = op.run(services.cadRegistry, request.params);
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
let result = op.run(services.cadRegistry, request.params);
|
||||
|
||||
services.cadRegistry.update(result.outdated, result.created);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function modify(request) {
|
||||
let errors = modifyInternal(request);
|
||||
if (errors !== undefined) {
|
||||
// return errors;
|
||||
throw 'not implemented, should reported by a wizard';
|
||||
}
|
||||
modifyInternal(request);
|
||||
|
||||
bus.updateState(TOKENS.MODIFICATIONS,
|
||||
({history, pointer}) => {
|
||||
|
|
|
|||
|
|
@ -11,11 +11,16 @@ import Button from 'ui/components/controls/Button';
|
|||
import ButtonGroup from 'ui/components/controls/ButtonGroup';
|
||||
import FaceSelectionControl from './FaceSelectionControl';
|
||||
import {CURRENT_SELECTION} from "../../../craft/wizard/wizardPlugin";
|
||||
import {isTCADError} from "../../../../utils/errors";
|
||||
|
||||
import ls from './Wizard.less';
|
||||
|
||||
|
||||
export default class Wizard extends React.Component {
|
||||
|
||||
constructor({initialState, metadata, previewer}, {services: {selection}}) {
|
||||
super();
|
||||
this.state = {hasError: false};
|
||||
this.params = {};
|
||||
|
||||
metadata.forEach(([name, type, v]) => {
|
||||
|
|
@ -31,19 +36,9 @@ export default class Wizard extends React.Component {
|
|||
this.preview = previewer(this.params);
|
||||
}
|
||||
|
||||
shouldComponentUpdate() {
|
||||
// all controls are unmanaged and they should keep their state
|
||||
// if the wizard manager gets updated when a new wizard appears
|
||||
return false;
|
||||
}
|
||||
|
||||
render() {
|
||||
let {left, title, metadata, onOK, onCancel} = this.props;
|
||||
let onClose = () => {
|
||||
this.onClose();
|
||||
onCancel();
|
||||
};
|
||||
return <Window initWidth={250} initLeft={left} title={title} onClose={onClose}>
|
||||
let {left, title, metadata} = this.props;
|
||||
return <Window initWidth={250} initLeft={left} title={title} onClose={this.onClose}>
|
||||
<Stack >
|
||||
{metadata.map(([name, type, , params], index) => {
|
||||
return <Field key={index}>
|
||||
|
|
@ -52,19 +47,42 @@ export default class Wizard extends React.Component {
|
|||
</Field>
|
||||
} )}
|
||||
<ButtonGroup>
|
||||
<Button text='Cancel' onClick={onClose} />
|
||||
<Button text='OK' type='accent' onClick={() => {
|
||||
this.onClose();
|
||||
onOK(this.params);
|
||||
}} />
|
||||
<Button text='Cancel' onClick={this.onClose} />
|
||||
<Button text='OK' type='accent' onClick={this.onOK} />
|
||||
</ButtonGroup>
|
||||
{this.state.hasError && <div className={ls.errorMessage}>
|
||||
performing operation with current parameters leads to an invalid object
|
||||
(manifold / self-intersecting / zero-thickness / complete degeneration or unsupported cases)
|
||||
{this.state.code && <span className={ls.errorCode}>{this.state.code}</span>}
|
||||
</div>}
|
||||
|
||||
</Stack>
|
||||
</Window>;
|
||||
}
|
||||
|
||||
onClose() {
|
||||
onClose = () => {
|
||||
this.preview.dispose();
|
||||
}
|
||||
this.props.onCancel();
|
||||
};
|
||||
|
||||
onOK = () => {
|
||||
try {
|
||||
this.props.onOK(this.params);
|
||||
this.onClose();
|
||||
} catch (error) {
|
||||
let state = {
|
||||
hasError: true
|
||||
};
|
||||
if (!isTCADError(error)) {
|
||||
console.error('internal error while performing operation');
|
||||
console.error(error);
|
||||
} else {
|
||||
state.cadCode = error.code;
|
||||
console.log(error);
|
||||
}
|
||||
this.setState(state);
|
||||
}
|
||||
};
|
||||
|
||||
controlForType(name, type, params) {
|
||||
const onChange = val => {
|
||||
|
|
|
|||
7
web/app/cad/dom/components/wizard/Wizard.less
Normal file
7
web/app/cad/dom/components/wizard/Wizard.less
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
.errorMessage {
|
||||
color: lightgoldenrodyellow;
|
||||
}
|
||||
|
||||
.errorCode {
|
||||
font-size: 9px;
|
||||
}
|
||||
|
|
@ -10,8 +10,8 @@ function WizardManager({wizards, close}, {services}) {
|
|||
let {metadata, previewGeomProvider, run} = services.operation.get(type);
|
||||
|
||||
function onOK(params) {
|
||||
close();
|
||||
services.craft.modify({type, params});
|
||||
close();
|
||||
}
|
||||
|
||||
let previewer = createPreviewer(previewGeomProvider, {services});
|
||||
|
|
|
|||
Loading…
Reference in a new issue