From 908e46aec9b8a13cd5aa73ac723e8669d5990e60 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Wed, 29 Oct 2014 01:25:16 -0700 Subject: [PATCH] fix bugs --- web/app/canvas.js | 1 + web/app/main2d.js | 9 +++++---- web/app/parametric.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/web/app/canvas.js b/web/app/canvas.js index 16221a8c..a4278d8b 100644 --- a/web/app/canvas.js +++ b/web/app/canvas.js @@ -89,6 +89,7 @@ TCAD.TWO.Viewer.prototype.remove = function(obj) { if (obj.layer != null) { var idx = obj.layer.objects.indexOf(obj); if (idx != -1) { + this.parametricManager.removeConstraintsByObj(obj); obj.layer.objects.splice(idx, 1); } } diff --git a/web/app/main2d.js b/web/app/main2d.js index b2d18d32..8d20a019 100644 --- a/web/app/main2d.js +++ b/web/app/main2d.js @@ -13,7 +13,7 @@ TCAD.App2D = function() { if (sketchData == null) { //PUT SAMPLES - this.viewer.addSegment(20, 20, 300, 300, layer); +// this.viewer.addSegment(20, 20, 300, 300, layer); // var points = [{x: 10, y: 10}, {x: 100, y: 10}, {x: 100, y: 100}]; // var poly = new TCAD.TWO.Polygon(points); // layer.objects.push(poly); @@ -67,7 +67,6 @@ TCAD.App2D = function() { var sketch = {}; sketch.boundary = boundary; sketch.layers = []; - sketch.index = {}; function point(p) { return [ p.id, [p._x.id, p.x], [p._y.id, p.y] ]; } @@ -239,7 +238,9 @@ TCAD.App2D.prototype.loadSketch = function(sketch) { TCAD.App2D.prototype.parseConstr = function (c, index) { function find(id) { var p = index[id]; - if (!p) throw "CAN'T READ SKETCH"; + if (!p) { + throw "CAN'T READ SKETCH"; + } return p; } var name = c[0]; @@ -287,7 +288,7 @@ TCAD.App2D.prototype.serializeConstr = function (c) { TCAD.App2D.prototype.getSketchId = function() { var id = window.location.hash.substring(1); - if (!!id) { + if (!id) { id = "untitled"; } return "TCAD.projects." + id; diff --git a/web/app/parametric.js b/web/app/parametric.js index b686fa61..c7b9bba5 100644 --- a/web/app/parametric.js +++ b/web/app/parametric.js @@ -12,6 +12,34 @@ TCAD.TWO.ParametricManager.prototype.add = function(constr) { this.viewer.refresh(); }; +TCAD.TWO.ParametricManager.prototype.removeConstraintsByObj = function(obj) { + var ownedParams = []; + obj.collectParams(ownedParams); + this.removeConstraintsByParams(ownedParams); +}; + +TCAD.TWO.ParametricManager.prototype.removeConstraintsByParams = function(ownedParams) { + var toRemove = []; + for (var i = 0; i < this.system.length; ++i) { + var params = this.system[i].getSolveData()[1]; + MAIN: + for (var j = 0; j < ownedParams.length; ++j) { + for (var k = 0; k < params.length; ++k) { + if (ownedParams[j].id === params[k].id) { + toRemove.push(i); + break MAIN; + } + } + } + } + + toRemove.sort(); + + for (var i = toRemove.length - 1; i >= 0 ; --i) { + this.system.splice( toRemove[i], 1); + } +}; + TCAD.TWO.ParametricManager.prototype.lock = function(objs) { var p = this._fetchPoints(objs); for (var i = 0; i < p.length; ++i) {