diff --git a/web/app/sketcher/components/ContextualControls.jsx b/web/app/sketcher/components/ContextualControls.jsx index 132c0d3f..0a4bcdf0 100644 --- a/web/app/sketcher/components/ContextualControls.jsx +++ b/web/app/sketcher/components/ContextualControls.jsx @@ -20,7 +20,7 @@ export function ContextualControls() { return
{ - selection.map(s =>
{s.simpleClassName}: {s.id}
) + selection.map(s =>
{s.simpleClassName}: {s.id}
) }
AVAILABLE ACTIONS:
@@ -33,3 +33,9 @@ export function ContextualControls() {
; } + +function debugEgg(obj) { + return e => { + obj.visitParams(p => console.log(p.toString())); + } +} \ No newline at end of file diff --git a/web/app/sketcher/constr/AlgNumSystem.js b/web/app/sketcher/constr/AlgNumSystem.js index c96383ef..12d37db1 100644 --- a/web/app/sketcher/constr/AlgNumSystem.js +++ b/web/app/sketcher/constr/AlgNumSystem.js @@ -30,6 +30,8 @@ export class AlgNumSubSystem { snapshot = new Map(); + inTransaction = false; + constructor() { this.solveStatus = { @@ -53,6 +55,12 @@ export class AlgNumSubSystem { addConstraint(constraint) { + if (this.inTransaction) { + constraint.objects.forEach(o => o.constraints.add(constraint)); + this.allConstraints.push(constraint); + return; + } + this.makeSnapshot(); this.allConstraints.push(constraint); @@ -78,17 +86,17 @@ export class AlgNumSubSystem { } } - addConstraints(constraints) { - constraints.forEach(constraint => { - if (constraint) { - constraint.objects.forEach(o => o.constraints.add(constraint)); - this.allConstraints.push(constraint); - } - }); + startTransaction() { + this.inTransaction = true; + } + + finishTransaction() { + this.inTransaction = false; this.prepare(); this.updateFullyConstrainedObjects(); } + invalidate() { this.prepare(); this.solveFine(); @@ -409,20 +417,30 @@ export class AlgNumSubSystem { return this.eliminatedParams.has(p) || (iso && iso.fullyConstrained); } - isParamFullyConstrained(p) { - const stack = [p]; - while (stack.length) { - const param = stack.pop(); - if (!this.isParamShallowConstrained(param)) { - return false; - } + isParamFullyConstrained(sourceParam) { - const substitution = this.substitutedParams.get(p); - if (substitution) { - substitution.visitParams(p => stack.push(p)); + const visited = new Set(); + + const dfs = param => { + if (visited.has(param)) { + return; } - } - return true; + visited.add(param); + if (this.isParamShallowConstrained(param)) { + return true; + } + const substitution = this.substitutedParams.get(param); + let res = false; + if (substitution) { + substitution.visitParams(p => { + if (dfs(p)) { + res = true; + } + }); + } + return res; + }; + return dfs(sourceParam); } } diff --git a/web/app/sketcher/io.js b/web/app/sketcher/io.js index 28240659..c96b26e1 100644 --- a/web/app/sketcher/io.js +++ b/web/app/sketcher/io.js @@ -52,6 +52,8 @@ IO.prototype._loadSketch = function(sketch) { this.cleanUpData(); + this.viewer.parametricManager.algNumSystem.startTransaction(); + const index = {}; function endPoint(p) { @@ -210,14 +212,15 @@ IO.prototype._loadSketch = function(sketch) { let sketchConstraints = sketch['constraints']; if (version > 1) { - this.viewer.parametricManager.algNumSystem.addConstraints(sketchConstraints.map(constr => { + sketchConstraints.forEach(constr => { try { - return AlgNumConstraint.read(constr, index) + const constraint = AlgNumConstraint.read(constr, index); + this.viewer.parametricManager.algNumSystem.addConstraint(constraint); } catch (e) { console.error(e); console.error("skipping errant constraint: " + constr&&constr.typeId); } - })); + }); } else { console.error("old format - need an upgrade"); } @@ -227,6 +230,7 @@ IO.prototype._loadSketch = function(sketch) { this.viewer.params.constantDefinition = constants; } + this.viewer.parametricManager.algNumSystem.finishTransaction(); this.viewer.parametricManager.notify(); }; diff --git a/web/app/sketcher/shapes/param.js b/web/app/sketcher/shapes/param.js index befe913d..e6ebd2f2 100644 --- a/web/app/sketcher/shapes/param.js +++ b/web/app/sketcher/shapes/param.js @@ -18,4 +18,8 @@ export class Param { return this.value; } + toString() { + return this.debugSymbol + this.id; + } + } \ No newline at end of file