From bf6df958cbba27e9b13e297b4562adad04395ccf Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Wed, 10 Feb 2016 23:31:03 -0800 Subject: [PATCH] Point in the middle --- web/app/sketcher/main2d.js | 4 +++ web/app/sketcher/parametric.js | 47 ++++++++++++++++++++++++++++++++++ web/sketcher.html | 1 + 3 files changed, 52 insertions(+) diff --git a/web/app/sketcher/main2d.js b/web/app/sketcher/main2d.js index 5c1029e1..3b42823d 100644 --- a/web/app/sketcher/main2d.js +++ b/web/app/sketcher/main2d.js @@ -157,6 +157,10 @@ TCAD.App2D = function() { app.viewer.parametricManager.pointOnArc(app.viewer.selected); }); + this.registerAction('pointInMiddle', "Point In the Middle", function () { + app.viewer.parametricManager.pointInMiddle(app.viewer.selected); + }); + this.registerAction('llAngle', "Angle Between 2 Lines", function () { app.viewer.parametricManager.llAngle(app.viewer.selected, prompt); }); diff --git a/web/app/sketcher/parametric.js b/web/app/sketcher/parametric.js index a929c761..df98e42b 100644 --- a/web/app/sketcher/parametric.js +++ b/web/app/sketcher/parametric.js @@ -216,6 +216,11 @@ TCAD.TWO.ParametricManager.prototype.p2lDistance = function(objs, promptCallback } }; +TCAD.TWO.ParametricManager.prototype.pointInMiddle = function(objs) { + var pl = this._fetchPointAndLine(objs); + this.add(new TCAD.TWO.Constraints.PointInMiddle(pl[0], pl[1])); +}; + TCAD.TWO.ParametricManager.prototype.pointOnArc = function(objs) { var points = this._fetch(objs, ['TCAD.TWO.EndPoint'], 1); var arcs = this._fetch(objs, ['TCAD.TWO.Arc', 'TCAD.TWO.Circle'], 1); @@ -1169,6 +1174,48 @@ TCAD.TWO.Constraints.PointOnArc.prototype.getObjects = function() { // ------------------------------------------------------------------------------------------------------------------ // +/** @constructor */ +TCAD.TWO.Constraints.PointInMiddle = function(point, line) { + this.point = point; + this.line = line; + this.length = new TCAD.TWO.Ref(TCAD.math.distanceAB(line.a, line.b) / 2); +}; + +TCAD.TWO.Constraints.PointInMiddle.prototype.NAME = 'PointInMiddle'; +TCAD.TWO.Constraints.PointInMiddle.prototype.UI_NAME = 'Point In the Middle'; + +TCAD.TWO.Constraints.PointInMiddle.prototype.getSolveData = function() { + var params1 = []; + var params2 = []; + + this.line.a.collectParams(params1); + this.point.collectParams(params1); + params1.push(this.length); + + this.line.b.collectParams(params2); + this.point.collectParams(params2); + params2.push(this.length); + + return [ + ['P2PDistanceV', params1, []], + ['P2PDistanceV', params2, []] + ]; +}; + +TCAD.TWO.Constraints.PointInMiddle.prototype.serialize = function() { + return [this.NAME, [this.point.id, this.line.id]]; +}; + +TCAD.TWO.Constraints.Factory[TCAD.TWO.Constraints.PointInMiddle.prototype.NAME] = function(refs, data) { + return new TCAD.TWO.Constraints.PointInMiddle(refs(data[0]), refs(data[1])); +}; + +TCAD.TWO.Constraints.PointInMiddle.prototype.getObjects = function() { + return [this.point, this.line]; +}; + +// ------------------------------------------------------------------------------------------------------------------ // + /** @constructor */ TCAD.TWO.Constraints.Angle = function(p1, p2, p3, p4, angle) { this.p1 = p1; diff --git a/web/sketcher.html b/web/sketcher.html index d32f9ad7..e2c2bc76 100644 --- a/web/sketcher.html +++ b/web/sketcher.html @@ -94,6 +94,7 @@ +