From c0990339c4a5654e3bdecebd2a76e226a848a8b1 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Fri, 10 Oct 2014 01:27:32 -0700 Subject: [PATCH] create radius constraint --- web/app/constr/constraints.js | 2 ++ web/app/fetchers.js | 6 +++--- web/app/main2d.js | 7 ++++++- web/app/parametric.js | 28 +++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/web/app/constr/constraints.js b/web/app/constr/constraints.js index 286b47e8..88553313 100644 --- a/web/app/constr/constraints.js +++ b/web/app/constr/constraints.js @@ -4,6 +4,8 @@ TCAD.constraints.create = function(name, params, values) { switch (name) { case "equal": return new TCAD.constraints.Equal(params); + case "equalsTo": + return new TCAD.constraints.EqualsTo(params, values[0]); case "perpendicular": return new TCAD.constraints.Perpendicular(params); case "parallel": diff --git a/web/app/fetchers.js b/web/app/fetchers.js index 8a27d408..87f8b917 100644 --- a/web/app/fetchers.js +++ b/web/app/fetchers.js @@ -14,15 +14,15 @@ TCAD.TWO.ParametricManager.prototype._fetchTwoPoints = function(objs) { return points; }; -TCAD.TWO.ParametricManager.prototype._fetchTwoOrMoreArcs = function(objs) { +TCAD.TWO.ParametricManager.prototype._fetchArcs = function(objs, min) { var arcs = []; for (var i = 0; i < objs.length; ++i) { if (objs[i]._class == 'TCAD.TWO.Arc') { arcs.push(objs[i]); } } - if (arcs.length < 2) { - throw "Illegal Argument. Constraint requires ata least 2 arcs." + if (arcs.length < min) { + throw "Illegal Argument. Constraint requires ata least " + min + " arcs." } return arcs; }; diff --git a/web/app/main2d.js b/web/app/main2d.js index e984e7a5..b3c51fa8 100644 --- a/web/app/main2d.js +++ b/web/app/main2d.js @@ -93,8 +93,12 @@ TCAD.App2D = function() { app.viewer.parametricManager.p2pDistance(app.viewer.selected, prompt); }, + Radius : function() { + app.viewer.parametricManager.radius(app.viewer.selected, prompt); + }, + "R = R" : function() { - app.viewer.parametricManager.rr(app.viewer.selected, prompt); + app.viewer.parametricManager.rr(app.viewer.selected); } }; @@ -109,6 +113,7 @@ TCAD.App2D = function() { actionsF.add(actions, 'perpendicular'); actionsF.add(actions, 'P2LDistance'); actionsF.add(actions, 'P2PDistance'); + actionsF.add(actions, 'Radius'); actionsF.add(actions, 'R = R'); actionsF.open(); diff --git a/web/app/parametric.js b/web/app/parametric.js index 1f587ad1..2d2df2ec 100644 --- a/web/app/parametric.js +++ b/web/app/parametric.js @@ -33,7 +33,7 @@ TCAD.TWO.ParametricManager.prototype.perpendicular = function(objs) { }; TCAD.TWO.ParametricManager.prototype.rr = function(objs) { - var arcs = this._fetchTwoOrMoreArcs(objs); + var arcs = this._fetchArcs(objs, 2); var prev = arcs[0].r; for (var i = 1; i < arcs.length; ++i) { this.system.push(new TCAD.TWO.Constraints.Equal(prev, arcs[i].r)); @@ -81,6 +81,23 @@ TCAD.TWO.ParametricManager.prototype.p2pDistance = function(objs, promptCallback } }; +TCAD.TWO.ParametricManager.prototype.radius = function(objs, promptCallback) { + var arcs = this._fetchArcs(objs, 1); + var radius = arcs[0].r.get(); + var promptDistance = promptCallback("Enter the radius value", radius.toFixed(2)); + + if (promptDistance != null) { + promptDistance = Number(promptDistance); + if (promptDistance == promptDistance) { // check for NaN + for (var i = 0; i < arcs.length; ++i) { + this.system.push(new TCAD.TWO.Constraints.EqualsTo(arcs[i].r, promptDistance)); + } + this.solve(); + this.viewer.refresh(); + } + } +}; + TCAD.TWO.ParametricManager.prototype.coincident = function(objs) { if (objs.length == 0) return; var last = objs.length - 1; @@ -233,6 +250,15 @@ TCAD.TWO.Constraints.Equal.prototype.getSolveData = function() { return ['equal', [this.p1, this.p2], []]; }; +TCAD.TWO.Constraints.EqualsTo = function(p, v) { + this.p = p; + this.v = v; +}; + +TCAD.TWO.Constraints.EqualsTo.prototype.getSolveData = function() { + return ['equalsTo', [this.p], [this.v]]; +}; + TCAD.TWO.Constraints.Parallel = function(l1, l2) { this.l1 = l1; this.l2 = l2;