backward compatibility for equals constraint

This commit is contained in:
Val Erastov (xibyte) 2020-03-10 00:33:50 -07:00
parent d5b35d1740
commit b5f6a45d11
2 changed files with 18 additions and 9 deletions

View file

@ -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);
}
})
}

View file

@ -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 () {