not create system on every drag

This commit is contained in:
Val Erastov 2014-10-29 19:22:46 -07:00
parent 9a0e2db885
commit dfde163457
3 changed files with 29 additions and 7 deletions

View file

@ -647,6 +647,7 @@ TCAD.TWO.DragTool = function(obj, viewer) {
this.ref = this.obj.getReferencePoint();
this.errorX = 0;
this.errorY = 0;
this.solver = null;
};
TCAD.TWO.DragTool.prototype.keydown = function(e) {};
@ -678,6 +679,7 @@ TCAD.TWO.DragTool.prototype.mousemove = function(e) {
TCAD.TWO.DragTool.prototype.mousedown = function(e) {
this.viewer.screenToModel2(e.x, e.y, this._point);
this.prepareSolver();
};
TCAD.TWO.DragTool.prototype.mouseup = function(e) {
@ -690,6 +692,11 @@ TCAD.TWO.DragTool.prototype.mousewheel = function(e) {
};
TCAD.TWO.DragTool.prototype.solveRequest = function(fineLevel) {
this.solver.solve(fineLevel);
};
TCAD.TWO.DragTool.prototype.prepareSolver = function() {
var locked;
if (this.obj._class === 'TCAD.TWO.EndPoint') {
locked = [this.obj._x, this.obj._y];
@ -704,5 +711,5 @@ TCAD.TWO.DragTool.prototype.solveRequest = function(fineLevel) {
} else {
locked = [];
}
this.viewer.parametricManager.solve(locked, fineLevel);
this.solver = this.viewer.parametricManager.prepare(locked);
};

View file

@ -197,10 +197,12 @@ TCAD.parametric.lock1 = function(constrs, locked) {
}
};
TCAD.parametric.lock2 = function(constrs, locked) {
TCAD.parametric.lock2Equals2 = function(constrs, locked) {
var _locked = [];
for (var i = 0; i < locked.length; ++i) {
constrs.push(new TCAD.constraints.EqualsTo([locked[i]], locked[i].get()));
_locked.push(new TCAD.constraints.EqualsTo([locked[i]], locked[i].get()));
}
return _locked;
};
TCAD.parametric.prepare = function(constrs, locked, alg) {
@ -209,8 +211,9 @@ TCAD.parametric.prepare = function(constrs, locked, alg) {
// this.lock1(constrs, locked);
this.lock2(constrs, locked);
var lockingConstrs = this.lock2Equals2(constrs, locked);
Array.prototype.push.apply( constrs, lockingConstrs );
var sys = new TCAD.parametric.System(constrs);
if (sys.params.length == 0) return;
@ -281,7 +284,12 @@ TCAD.parametric.prepare = function(constrs, locked, alg) {
}
var systemSolver = {
system : sys,
solveSystem : solve
solveSystem : solve,
updateLock : function(values) {
for (var i = 0; i < values.length; ++i) {
lockingConstrs[i].value = values[i];
}
}
};
return systemSolver;

View file

@ -276,9 +276,16 @@ TCAD.TWO.ParametricManager.prototype.prepare = function(locked, alg) {
lockedIds[locked[p]] = true;
}
}
var lockedValues = [];
var solver = TCAD.parametric.prepare(_constrs, _locked, alg);
function solve(fineLevel) {
if (_locked.length != 0) {
for (p = 0; p < locked.length; ++p) {
lockedValues[p] = locked[p].get() ;
}
solver.updateLock(lockedValues);
}
solver.solveSystem(fineLevel);
for (p in pdict) {
_p = pdict[p];