diff --git a/web/app/sketcher/main2d.js b/web/app/sketcher/main2d.js index 0729a02d..6b37d97f 100644 --- a/web/app/sketcher/main2d.js +++ b/web/app/sketcher/main2d.js @@ -152,6 +152,10 @@ TCAD.App2D = function() { app.viewer.parametricManager.lock(app.viewer.selected); }); + this.registerAction('pointOnLine', "Point On Line", function () { + app.viewer.parametricManager.pointOnLine(app.viewer.selected); + }); + this.registerAction('analyzeConstraint', "Analyze Constraint", function () { app.viewer.parametricManager.analyze(alert); }); diff --git a/web/app/sketcher/parametric.js b/web/app/sketcher/parametric.js index aa9f0996..805e6073 100644 --- a/web/app/sketcher/parametric.js +++ b/web/app/sketcher/parametric.js @@ -196,6 +196,13 @@ TCAD.TWO.ParametricManager.prototype.p2lDistance = function(objs, promptCallback } }; +TCAD.TWO.ParametricManager.prototype.pointOnLine = function(objs) { + var pl = this._fetchPointAndLine(objs); + var target = pl[0]; + var segment = pl[1]; + this.add(new TCAD.TWO.Constraints.PointOnLine(target, segment)); +}; + TCAD.TWO.utils.constRef = function(value) { return function() { return value; @@ -890,3 +897,31 @@ TCAD.TWO.Constraints.Tangent.prototype.getObjects = function() { }; // ------------------------------------------------------------------------------------------------------------------ // + +TCAD.TWO.Constraints.PointOnLine = function(point, line) { + this.point = point; + this.line = line; +}; + +TCAD.TWO.Constraints.PointOnLine.prototype.NAME = 'PointOnLine'; + +TCAD.TWO.Constraints.PointOnLine.prototype.getSolveData = function() { + var params = []; + this.point.collectParams(params); + this.line.collectParams(params); + return [['P2LDistance', params, [0]]]; +}; + +TCAD.TWO.Constraints.PointOnLine.prototype.serialize = function() { + return [this.NAME, [this.point.id, this.line.id]]; +}; + +TCAD.TWO.Constraints.Factory[TCAD.TWO.Constraints.PointOnLine.prototype.NAME] = function(refs, data) { + return new TCAD.TWO.Constraints.PointOnLine(refs(data[0]), refs(data[1])); +}; + +TCAD.TWO.Constraints.PointOnLine.prototype.getObjects = function() { + return [this.point, this.line]; +}; + +// ------------------------------------------------------------------------------------------------------------------ // diff --git a/web/sketcher.html b/web/sketcher.html index 91a718e0..8ad07b43 100644 --- a/web/sketcher.html +++ b/web/sketcher.html @@ -304,6 +304,7 @@ +