mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 09:52:34 +01:00
lock constraint
This commit is contained in:
parent
c441cd3e34
commit
5d73b05405
3 changed files with 32 additions and 1 deletions
|
|
@ -14,6 +14,22 @@ TCAD.TWO.ParametricManager.prototype._fetchTwoPoints = function(objs) {
|
|||
return points;
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchPoints = function(objs) {
|
||||
var points = [];
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
objs[i].visit(false, function(o) {
|
||||
if (o._class === 'TCAD.TWO.EndPoint') {
|
||||
points.push(o);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
if (points.length == 0) {
|
||||
throw "Illegal Argument. Constraint requires at least 1 point/line/arc."
|
||||
}
|
||||
return points;
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchArcs = function(objs, min) {
|
||||
var arcs = [];
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
|
|
@ -22,7 +38,7 @@ TCAD.TWO.ParametricManager.prototype._fetchArcs = function(objs, min) {
|
|||
}
|
||||
}
|
||||
if (arcs.length < min) {
|
||||
throw "Illegal Argument. Constraint requires ata least " + min + " arcs."
|
||||
throw "Illegal Argument. Constraint requires at least " + min + " arcs."
|
||||
}
|
||||
return arcs;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ TCAD.App2D = function() {
|
|||
app.viewer.parametricManager.tangent(app.viewer.selected);
|
||||
},
|
||||
|
||||
lock : function() {
|
||||
app.viewer.parametricManager.lock(app.viewer.selected);
|
||||
},
|
||||
|
||||
analyze : function() {
|
||||
app.viewer.parametricManager.analyze(alert);
|
||||
}
|
||||
|
|
@ -124,6 +128,7 @@ TCAD.App2D = function() {
|
|||
actionsF.add(actions, 'Radius');
|
||||
actionsF.add(actions, 'R = R');
|
||||
actionsF.add(actions, 'tangent');
|
||||
actionsF.add(actions, 'lock');
|
||||
actionsF.add(actions, 'analyze');
|
||||
actionsF.open();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,16 @@ TCAD.TWO.ParametricManager.prototype.add = function(constr) {
|
|||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.lock = function(objs) {
|
||||
var p = this._fetchPoints(objs);
|
||||
for (var i = 0; i < p.length; ++i) {
|
||||
this.system.push(new TCAD.TWO.Constraints.EqualsTo(p[i]._x, p[i].x));
|
||||
this.system.push(new TCAD.TWO.Constraints.EqualsTo(p[i]._y, p[i].y));
|
||||
}
|
||||
this.solve();
|
||||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.vertical = function(objs) {
|
||||
var p = this._fetchTwoPoints(objs);
|
||||
this.add(new TCAD.TWO.Constraints.Equal(p[0]._x, p[1]._x));
|
||||
|
|
|
|||
Loading…
Reference in a new issue