From b876818ce58314edca39bf44277d82a79a956e25 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Wed, 3 Jan 2018 00:49:47 -0800 Subject: [PATCH] showing error info for invalid boolean results --- web/app/3d/craft/brep/wizards/wizard.js | 28 ++++++++++++++++++++++--- web/app/3d/craft/craft.js | 12 +++++++++-- web/app/utils/errors.js | 2 +- web/css/app3d.less | 5 +++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/web/app/3d/craft/brep/wizards/wizard.js b/web/app/3d/craft/brep/wizards/wizard.js index 1798dd67..26ee964e 100644 --- a/web/app/3d/craft/brep/wizards/wizard.js +++ b/web/app/3d/craft/brep/wizards/wizard.js @@ -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: $('
')}); 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() {} diff --git a/web/app/3d/craft/craft.js b/web/app/3d/craft/craft.js index de053662..1651d407 100644 --- a/web/app/3d/craft/craft.js +++ b/web/app/3d/craft/craft.js @@ -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); } diff --git a/web/app/utils/errors.js b/web/app/utils/errors.js index 3419ce3d..18e9a88a 100644 --- a/web/app/utils/errors.js +++ b/web/app/utils/errors.js @@ -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; diff --git a/web/css/app3d.less b/web/css/app3d.less index 1457a439..090bcaac 100644 --- a/web/css/app3d.less +++ b/web/css/app3d.less @@ -290,4 +290,9 @@ iframe { .history-selected .modification-right-buttons, .modification-item:hover .modification-right-buttons { display: initial; +} + +.errors-message { + padding: 5px; + color: lightgoldenrodyellow; } \ No newline at end of file