From b5f6a45d112dc7f80f80831515988c69f9074718 Mon Sep 17 00:00:00 2001 From: "Val Erastov (xibyte)" Date: Tue, 10 Mar 2020 00:33:50 -0700 Subject: [PATCH] backward compatibility for equals constraint --- web/app/sketcher/actions/index.js | 18 +++++++++++------- web/app/sketcher/sketcher-app.js | 9 +++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/web/app/sketcher/actions/index.js b/web/app/sketcher/actions/index.js index 3b4b1bd2..acaa20a8 100644 --- a/web/app/sketcher/actions/index.js +++ b/web/app/sketcher/actions/index.js @@ -27,21 +27,25 @@ export function matchAvailableActions(selection) { return matched; } +export function getSketcherAction(actionId) { + return index[actionId]; +} //For backward compatibility -export function runActionOrToastWhyNot(actionId, selection, ctx) { +export function runActionOrToastWhyNot(actionId, selection, ctx, silent) { const action = index[actionId]; if (action) { const matched = matchSelection(action.selectionMatcher, new MatchIndex(selection), false); if (matched) { action.invoke(ctx, matched) } else { - toast('The action "' + action.shortName + ' ' + action.kind + '" requires selection of ' + getDescription(action.selectionMatcher)); + + const msg = 'The action "' + action.shortName + ' ' + action.kind + '" requires selection of ' + getDescription(action.selectionMatcher); + if (silent) { + return msg; + } else { + toast(msg); + } } } - matchAvailableActions(selection).forEach(a => { - if (a.id === actionId) { - cb(a); - } - }) } \ No newline at end of file diff --git a/web/app/sketcher/sketcher-app.js b/web/app/sketcher/sketcher-app.js index 1aea40cd..79aad900 100644 --- a/web/app/sketcher/sketcher-app.js +++ b/web/app/sketcher/sketcher-app.js @@ -18,6 +18,7 @@ import genSerpinski from '../utils/genSerpinski'; import React from "react"; import {runActionOrToastWhyNot} from "./actions"; import {stream} from "../../../modules/lstream"; +import {toast} from "react-toastify"; function App2D() { var app = this; @@ -230,11 +231,15 @@ function App2D() { }); this.registerAction('RadiusConstraint', "Radius Constraint", function () { - app.viewer.parametricManager.radius(app.viewer.selected, prompt); + runActionOrToastWhyNot('RadiusLength', app.viewer.selected, app.context); }); this.registerAction('EntityEqualityConstraint', "Radius Equals Constraint", function () { - app.viewer.parametricManager.entityEquality(app.viewer.selected); + const fail1 = runActionOrToastWhyNot('EqualRadius', app.viewer.selected, app.context, true); + const fail2 = runActionOrToastWhyNot('EqualLength', app.viewer.selected, app.context, true); + if (fail1 && fail2) { + toast('Requires selection of either segments or circles and arcs'); + } }); this.registerAction('tangentConstraint', "Tangent Constraint", function () {