showing error info for invalid boolean results

This commit is contained in:
Val Erastov 2018-01-03 00:49:47 -08:00
parent d5c46e9ab0
commit b876818ce5
4 changed files with 41 additions and 6 deletions

View file

@ -1,5 +1,6 @@
import * as tk from '../../../../ui/toolkit'
import {camelCaseSplit} from '../../../../utils/utils'
import {isTCADError} from "../../../../utils/errors";
export class Wizard {
@ -46,6 +47,7 @@ export class Wizard {
}
const buttons = new tk.ButtonRow(["Cancel", "OK"], [() => this.cancelClick(), () => this.okClick()]);
tk.add(folder, buttons);
tk.add(folder, {root: $('<div class="errors-message" />')});
box.root.keydown((e) => {
switch (e.keyCode) {
case 27 : this.cancelClick(); break;
@ -61,12 +63,32 @@ export class Wizard {
}
okClick() {
this.dispose();
this.apply();
if (this.apply()) {
this.dispose();
}
}
apply() {
this.app.craft.modify(this.createRequest(), this.overridingHistory);
let errors = this.app.craft.modify(this.createRequest(), this.overridingHistory);
if (errors) {
this.showErrors(errors);
return false;
} else {
return true;
}
}
showErrors(error) {
this.showErrorText('performing operation with current parameters leads to an invalid object' +
'(manifold / self-intersecting / zero-thickness / complete degeneration or unsupported cases)');
if (!isTCADError(error)) {
console.error('internal error while performing operation');
throw error;
}
}
showErrorText(message) {
this.box.root.find('.errors-message').text(message);
}
onUIChange() {}

View file

@ -67,7 +67,12 @@ Craft.prototype.modifyInternal = function(request) {
var op = this.operations[request.type];
if (!op) return;
const result = op(this.app, request.params);
let result;
try {
result = op(this.app, request.params);
} catch(err) {
return err;
}
for (let solid of result.outdated) {
solid.vanish();
@ -89,7 +94,10 @@ Craft.prototype.modifyInternal = function(request) {
};
Craft.prototype.modify = function(request, overriding) {
this.modifyInternal(request);
let errors = this.modifyInternal(request);
if (errors !== undefined) {
return errors;
}
if (!overriding && this._historyPointer != this.history.length) {
this.history.splice(this._historyPointer + 1, 0, null);
}

View file

@ -11,6 +11,6 @@ export default class CadError extends Error {
super(code);
this.code = code;
this.payload = payload;
this.type = ERROR_TYPE;
}
}
CadError.prototype.type = ERROR_TYPE;

View file

@ -290,4 +290,9 @@ iframe {
.history-selected .modification-right-buttons, .modification-item:hover .modification-right-buttons {
display: initial;
}
.errors-message {
padding: 5px;
color: lightgoldenrodyellow;
}