diff --git a/web/app/canvas.js b/web/app/canvas.js index ed985fc4..a7108ad4 100644 --- a/web/app/canvas.js +++ b/web/app/canvas.js @@ -609,8 +609,8 @@ TCAD.TWO.DragTool.prototype.mousemove = function(e) { var y = this._point.y; this.viewer.screenToModel2(e.x, e.y, this._point); this.obj.translate(this._point.x - x, this._point.y - y); + this.solveRequest(2); this.viewer.refresh(); - this.solveRequest(); }; TCAD.TWO.DragTool.prototype.mousedown = function(e) { @@ -618,19 +618,20 @@ TCAD.TWO.DragTool.prototype.mousedown = function(e) { }; TCAD.TWO.DragTool.prototype.mouseup = function(e) { - this.solveRequest(); + this.solveRequest(0); + this.viewer.refresh(); this.viewer.toolManager.releaseControl(); }; TCAD.TWO.DragTool.prototype.mousewheel = function(e) { }; -TCAD.TWO.DragTool.prototype.solveRequest = function(e) { +TCAD.TWO.DragTool.prototype.solveRequest = function(fineLevel) { var locked; if (this.obj._class == 'TCAD.TWO.EndPoint') { locked = [this.obj._x, this.obj._y]; } else { locked = []; } - this.viewer.parametricManager.solve(locked); + this.viewer.parametricManager.solve(locked, fineLevel); }; diff --git a/web/app/constr/solver.js b/web/app/constr/solver.js index 66e22704..6da67ac1 100644 --- a/web/app/constr/solver.js +++ b/web/app/constr/solver.js @@ -77,7 +77,7 @@ TCAD.parametric.System.prototype.getValues = function() { return values; }; -TCAD.parametric.solve = function(constrs, locked) { +TCAD.parametric.solve = function(constrs, locked, fineLevel) { if (constrs.length == 0) return; @@ -109,9 +109,21 @@ TCAD.parametric.solve = function(constrs, locked) { }; var opt = new LMOptimizer(sys.getParams(), arr(sys.constraints.length), model, jacobian); - opt.init(); + + switch (fineLevel) { + case 1: + eps = 0.01; + opt.init0(eps, eps, eps); + break; + case 2: + eps = 0.1; + opt.init0(eps, eps, eps); + break; + default: + eps = 0.00000001; + opt.init0(eps, eps, eps); + } + var res = opt.doOptimize(); - sys.setParams(res[0]); - }; diff --git a/web/app/parametric.js b/web/app/parametric.js index 36648b84..f1f4dcb0 100644 --- a/web/app/parametric.js +++ b/web/app/parametric.js @@ -9,6 +9,7 @@ TCAD.TWO.ParametricManager = function(viewer) { TCAD.TWO.ParametricManager.prototype.add = function(constr) { this.system.push(constr); this.solve(); + this.viewer.refresh(); }; TCAD.TWO.ParametricManager.prototype._fetchTwoPoints = function(objs) { @@ -189,7 +190,7 @@ TCAD.TWO.ParametricManager.prototype.solve1 = function(locked, onSolved) { }; -TCAD.TWO.ParametricManager.prototype.solve = function(locked, onSolved) { +TCAD.TWO.ParametricManager.prototype.solve = function(locked, fineLevel) { var pdict = {}; var params; var i; @@ -226,15 +227,12 @@ TCAD.TWO.ParametricManager.prototype.solve = function(locked, onSolved) { } } - TCAD.parametric.solve(_constrs, _locked); + TCAD.parametric.solve(_constrs, _locked, fineLevel); for (var p in pdict) { var _p = pdict[p]; _p._backingParam.set(_p.get()); } - if (onSolved !== undefined) { - onSolved(); - } }; TCAD.TWO.Constraints.Equal = function(p1, p2) {