From aaa360e48d7ed355e3edd667208a3c812d39e772 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Mon, 29 Aug 2016 23:46:48 -0700 Subject: [PATCH] line geometry validation and recovery --- web/app/sketcher/canvas.js | 42 +++++++++++++++++++--------------- web/app/sketcher/parametric.js | 21 +++++++++++++---- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/web/app/sketcher/canvas.js b/web/app/sketcher/canvas.js index 4350d72c..fbd6276f 100644 --- a/web/app/sketcher/canvas.js +++ b/web/app/sketcher/canvas.js @@ -502,6 +502,8 @@ TCAD.TWO.SketchObject.prototype.validate = function() { return true; }; +TCAD.TWO.SketchObject.prototype.recover = function() { +}; TCAD.TWO.SketchObject.prototype.getDefaultTool = function(viewer) { return new TCAD.TWO.DragTool(this, viewer); @@ -628,14 +630,17 @@ TCAD.TWO.Segment = function(a, b) { TCAD.TWO.utils.extend(TCAD.TWO.Segment, TCAD.TWO.SketchObject); TCAD.TWO.Segment.prototype._class = 'TCAD.TWO.Segment'; -TCAD.TWO.Segment.MIN_LENGTH = 0.1; // 0.08; // if length < 0.08 canvas doesn't even draw a line TCAD.TWO.Segment.prototype.validate = function() { - return TCAD.math.distanceAB(this.a, this.b) > TCAD.TWO.Segment.MIN_LENGTH; + return TCAD.math.distanceAB(this.a, this.b) > TCAD.TOLERANCE; }; -TCAD.TWO.Segment.prototype.addFixingGeomConstraints = function(constrs) { - constrs.push(new TCAD.TWO.Constraints.MinLength(this.a, this.b, TCAD.TWO.Segment.MIN_LENGTH)); +TCAD.TWO.Segment.prototype.recover = function() { + var recoverLength = 100; + this.a.x -= recoverLength; + this.a.y -= recoverLength; + this.b.x += recoverLength; + this.b.y += recoverLength; }; TCAD.TWO.Segment.prototype.collectParams = function(params) { @@ -1051,21 +1056,22 @@ TCAD.TWO.DragTool.prototype.mousewheel = function(e) { TCAD.TWO.DragTool.prototype.solveRequest = function(rough) { this.solver.solve(rough, 1); this.solver.sync(); - if (false) { - var fixingConstrs = []; - this.viewer.accept(function(obj) { - if (obj._class === 'TCAD.TWO.Segment') { - if (!obj.validate()) { - obj.addFixingGeomConstraints(fixingConstrs); - } - } - return true; - }); - if (fixingConstrs.length !== 0) { - this.prepareSolver(fixingConstrs); - this.solver.solve(rough, 1); - this.solver.sync(); + + var paramsToUpdate = []; + this.viewer.accept(function(obj) { + if (!obj.validate()) { + obj.recover(); + obj.collectParams(paramsToUpdate); } + return true; + }); + + if (paramsToUpdate.length != 0) { + for (var i = 0; i < paramsToUpdate.length; i++) { + this.solver.updateParameter(paramsToUpdate[i]); + } + this.solver.solve(rough, 1); + this.solver.sync(); } }; diff --git a/web/app/sketcher/parametric.js b/web/app/sketcher/parametric.js index 3519d2f0..57ca58a3 100644 --- a/web/app/sketcher/parametric.js +++ b/web/app/sketcher/parametric.js @@ -517,6 +517,12 @@ TCAD.TWO.ParametricManager.prototype._prepare = function(locked, subSystems, ext } }, + updateParameter : function(p) { + for (var i = 0; i < solvers.length; i++) { + solvers[i].updateParameter(p); + } + }, + updateLock : function(values) { for (var i = 0; i < solvers.length; i++) { solvers[i].updateLock(values); @@ -798,24 +804,29 @@ TCAD.TWO.ParametricManager.prototype.prepareForSubSystem = function(locked, subS } var viewer = this.viewer; function sync() { - for (p in pdict) { - _p = pdict[p]; + for (var p in pdict) { + var _p = pdict[p]; if (!!_p._backingParam.__aux) continue; _p._backingParam.set(_p.get()); } //Make sure all coincident constraints are equal - for (ei = 0; ei < equalsIndex.length; ++ei) { + for (var ei = 0; ei < equalsIndex.length; ++ei) { var master = equalsDict[ equalsIndex[ei][0]]; - for (i = 1; i < equalsIndex[ei].length; ++i) { + for (var i = 1; i < equalsIndex[ei].length; ++i) { var slave = equalsDict[equalsIndex[ei][i]]; slave.set(master.get()); } } } - + + function updateParameter(p) { + getParam(p).set(p.get()); + } + solver.solve = solve; solver.sync = sync; + solver.updateParameter = updateParameter; return solver; };