diff --git a/web/app/sketcher/parametric.js b/web/app/sketcher/parametric.js index b43492fc..39d1438b 100644 --- a/web/app/sketcher/parametric.js +++ b/web/app/sketcher/parametric.js @@ -14,6 +14,8 @@ class ParametricManager { $update = stream(); + inTransaction = false; + $constraints = this.$update .map(() => [...this.algNumSystem.allConstraints, ...this.algNumSystem.modifiers].sort((c1, c2) => c1.id - c2.id)) .remember([]); @@ -28,6 +30,17 @@ class ParametricManager { this.reset(); } + startTransaction() { + this.inTransaction = true; + this.algNumSystem.startTransaction(); + } + + finishTransaction() { + this.inTransaction = false; + this.algNumSystem.finishTransaction(); + this.refresh(); + } + get allConstraints() { return this.$constraints.value; } @@ -112,8 +125,7 @@ class ParametricManager { }; commit() { - this.notify(); - this.viewer.refresh(); + this.refresh(); }; _add(constr) { @@ -124,6 +136,9 @@ class ParametricManager { }; refresh() { + if (this.inTransaction) { + return; + } this.notify(); this.viewer.refresh(); } diff --git a/web/app/sketcher/tools/rectangle.js b/web/app/sketcher/tools/rectangle.js index a92126f7..09c222ee 100644 --- a/web/app/sketcher/tools/rectangle.js +++ b/web/app/sketcher/tools/rectangle.js @@ -1,8 +1,8 @@ import {Tool} from './tool' -import * as math from '../../math/math'; import {EndPoint} from '../shapes/point' import {Segment} from '../shapes/segment' import {Constraints} from '../parametric' +import {AlgNumConstraint, ConstraintDefinitions} from "../constr/ANConstraints"; export class RectangleTool extends Tool { @@ -92,19 +92,22 @@ export class RectangleTool extends Tool { stepFinish(p) { this.pointPicked(p.x, p.y); - var pm = this.viewer.parametricManager; - pm.linkObjects([this.rectangle[3].b, this.rectangle[0].a]); - pm.linkObjects([this.rectangle[0].b, this.rectangle[1].a]); - pm.linkObjects([this.rectangle[1].b, this.rectangle[2].a]); - pm.linkObjects([this.rectangle[2].b, this.rectangle[3].a]); + const pm = this.viewer.parametricManager; + pm.startTransaction(); + pm.coincidePoints(this.rectangle[3].b, this.rectangle[0].a); + pm.coincidePoints(this.rectangle[0].b, this.rectangle[1].a); + pm.coincidePoints(this.rectangle[1].b, this.rectangle[2].a); + pm.coincidePoints(this.rectangle[2].b, this.rectangle[3].a); const constraints = [ - new Constraints.Horizontal(this.rectangle[0]), - new Constraints.Horizontal(this.rectangle[2]), - new Constraints.Vertical(this.rectangle[3]), - new Constraints.Vertical(this.rectangle[1]) + new AlgNumConstraint(ConstraintDefinitions.Horizontal, [this.rectangle[0]], {angle: 0}), + new AlgNumConstraint(ConstraintDefinitions.Horizontal, [this.rectangle[2]], {angle: 180}), + new AlgNumConstraint(ConstraintDefinitions.Vertical, [this.rectangle[3]], {angle: 270}), + new AlgNumConstraint(ConstraintDefinitions.Vertical, [this.rectangle[1]], {angle: 90}), ]; + // constraints.forEach(c => c.initConstants()); + this.rectangle.forEach(s => s.stabilize(this.viewer)); pm.addAll(constraints); - this.viewer.refresh(); + pm.finishTransaction(); this.viewer.toolManager.releaseControl(); }