This commit is contained in:
Val Erastov 2014-10-29 01:25:16 -07:00
parent 5e79a35691
commit 908e46aec9
3 changed files with 34 additions and 4 deletions

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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) {