mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-14 20:33:30 +01:00
line to line constraint
This commit is contained in:
parent
bd17ee4b12
commit
2af66f0807
3 changed files with 134 additions and 81 deletions
|
|
@ -1,79 +1,80 @@
|
|||
function start() {
|
||||
var app = new TCAD.App2D();
|
||||
app.loadFromLocalStorage();
|
||||
var actionsWin = new TCAD.ui.Window($('#actions'));
|
||||
function start() {
|
||||
var app = new TCAD.App2D();
|
||||
app.loadFromLocalStorage();
|
||||
app.fit();
|
||||
var actionsWin = new TCAD.ui.Window($('#actions'));
|
||||
|
||||
TCAD.ui.bindOpening( $('#showActions'), actionsWin );
|
||||
var addAction = TCAD.ui.createActionsWinBuilder(actionsWin);
|
||||
TCAD.ui.bindOpening( $('#showActions'), actionsWin );
|
||||
var addAction = TCAD.ui.createActionsWinBuilder(actionsWin);
|
||||
|
||||
for (var p = 0; p < app._actionsOrder.length; ++p) {
|
||||
var act = app.actions[app._actionsOrder[p]];
|
||||
addAction(act.desc, act.action);
|
||||
$('.act-' + act.id).click(act.action).attr('title', act.desc);
|
||||
}
|
||||
for (var p = 0; p < app._actionsOrder.length; ++p) {
|
||||
var act = app.actions[app._actionsOrder[p]];
|
||||
addAction(act.desc, act.action);
|
||||
$('.act-' + act.id).click(act.action).attr('title', act.desc);
|
||||
}
|
||||
|
||||
function infoStr(c) {
|
||||
if (c.SettableFields === undefined) return "";
|
||||
var info = Object.keys(c.SettableFields).map(function(f) {
|
||||
return Number(c[f]).toFixed(2);
|
||||
}).join(", ");
|
||||
if (info.length != 0) {
|
||||
info = " <span style='font-size: 8px;'>[" + info + "]</span>";
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
var pm = app.viewer.parametricManager;
|
||||
var constrList = new TCAD.ui.List($('#constrs'), {
|
||||
items : function() {
|
||||
var theItems = [];
|
||||
for (var j = 0; j < pm.subSystems.length; j++) {
|
||||
var sub = pm.subSystems[j];
|
||||
for (var i = 0; i < sub.constraints.length; ++i) {
|
||||
var constr = sub.constraints[i];
|
||||
if (constr.aux !== true) {
|
||||
theItems.push({name : constr.UI_NAME + infoStr(constr), constr : constr});
|
||||
}
|
||||
}
|
||||
}
|
||||
return theItems;
|
||||
},
|
||||
|
||||
remove : function(item) {
|
||||
pm.remove(item.constr);
|
||||
},
|
||||
|
||||
mouseleave : function(item) {
|
||||
app.viewer.deselectAll();
|
||||
app.viewer.refresh();
|
||||
},
|
||||
|
||||
hover : function(item) {
|
||||
app.viewer.select(item.constr.getObjects(), true);
|
||||
app.viewer.refresh();
|
||||
},
|
||||
|
||||
click : function(item) {
|
||||
var c = item.constr;
|
||||
if (c.SettableFields === undefined) return;
|
||||
for (var f in c.SettableFields) {
|
||||
var value = c[f];
|
||||
var intro = c.SettableFields[f];
|
||||
value = TCAD.TWO.utils.askNumber(intro, value.toFixed(4), prompt);
|
||||
c[f] = value;
|
||||
}
|
||||
app.viewer.parametricManager.refresh();
|
||||
}
|
||||
});
|
||||
app.viewer.parametricManager.listeners.push(function() {constrList.refresh()});
|
||||
constrList.refresh();
|
||||
function infoStr(c) {
|
||||
if (c.SettableFields === undefined) return "";
|
||||
var info = Object.keys(c.SettableFields).map(function(f) {
|
||||
return Number(c[f]).toFixed(2);
|
||||
}).join(", ");
|
||||
if (info.length != 0) {
|
||||
info = " <span style='font-size: 8px;'>[" + info + "]</span>";
|
||||
}
|
||||
window.___log = function(log) {
|
||||
$('#log').append( " *****************<br><br><br><br>");
|
||||
for (var i = 0; i < log.length; i++) {
|
||||
$('#log').append( log[i] + " <br>");
|
||||
return info;
|
||||
}
|
||||
|
||||
var pm = app.viewer.parametricManager;
|
||||
var constrList = new TCAD.ui.List($('#constrs'), {
|
||||
items : function() {
|
||||
var theItems = [];
|
||||
for (var j = 0; j < pm.subSystems.length; j++) {
|
||||
var sub = pm.subSystems[j];
|
||||
for (var i = 0; i < sub.constraints.length; ++i) {
|
||||
var constr = sub.constraints[i];
|
||||
if (constr.aux !== true) {
|
||||
theItems.push({name : constr.UI_NAME + infoStr(constr), constr : constr});
|
||||
}
|
||||
}
|
||||
};
|
||||
window.onload = function() {
|
||||
setTimeout(start, 0);
|
||||
};
|
||||
}
|
||||
return theItems;
|
||||
},
|
||||
|
||||
remove : function(item) {
|
||||
pm.remove(item.constr);
|
||||
},
|
||||
|
||||
mouseleave : function(item) {
|
||||
app.viewer.deselectAll();
|
||||
app.viewer.refresh();
|
||||
},
|
||||
|
||||
hover : function(item) {
|
||||
app.viewer.select(item.constr.getObjects(), true);
|
||||
app.viewer.refresh();
|
||||
},
|
||||
|
||||
click : function(item) {
|
||||
var c = item.constr;
|
||||
if (c.SettableFields === undefined) return;
|
||||
for (var f in c.SettableFields) {
|
||||
var value = c[f];
|
||||
var intro = c.SettableFields[f];
|
||||
value = TCAD.TWO.utils.askNumber(intro, value.toFixed(4), prompt);
|
||||
c[f] = value;
|
||||
}
|
||||
app.viewer.parametricManager.refresh();
|
||||
}
|
||||
});
|
||||
app.viewer.parametricManager.listeners.push(function() {constrList.refresh()});
|
||||
constrList.refresh();
|
||||
}
|
||||
window.___log = function(log) {
|
||||
$('#log').append( " *****************<br><br><br><br>");
|
||||
for (var i = 0; i < log.length; i++) {
|
||||
$('#log').append( log[i] + " <br>");
|
||||
}
|
||||
};
|
||||
window.onload = function() {
|
||||
setTimeout(start, 0);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -137,8 +137,8 @@ TCAD.App2D = function() {
|
|||
app.viewer.parametricManager.radius(app.viewer.selected, prompt);
|
||||
});
|
||||
|
||||
this.registerAction('REqualsRConstraint', "Radius Equals Constraint", function () {
|
||||
app.viewer.parametricManager.rr(app.viewer.selected);
|
||||
this.registerAction('EntityEqualityConstraint', "Radius Equals Constraint", function () {
|
||||
app.viewer.parametricManager.entityEquality(app.viewer.selected);
|
||||
});
|
||||
|
||||
this.registerAction('tangentConstraint', "Tangent Constraint", function () {
|
||||
|
|
|
|||
|
|
@ -174,8 +174,7 @@ TCAD.TWO.ParametricManager.prototype.tangent = function(objs) {
|
|||
this.add(new TCAD.TWO.Constraints.Tangent( arc, line));
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.rr = function(objs) {
|
||||
var arcs = this._fetchArkCirc(objs, 2);
|
||||
TCAD.TWO.ParametricManager.prototype.rr = function(arcs) {
|
||||
var prev = arcs[0];
|
||||
for (var i = 1; i < arcs.length; ++i) {
|
||||
this._add(new TCAD.TWO.Constraints.RR(prev, arcs[i]));
|
||||
|
|
@ -184,6 +183,25 @@ TCAD.TWO.ParametricManager.prototype.rr = function(objs) {
|
|||
this.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.ll = function(lines) {
|
||||
this.add(new TCAD.TWO.Constraints.LL(lines[0], lines[1]));
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.entityEquality = function(objs) {
|
||||
var arcs, lines = undefined;
|
||||
try {
|
||||
arcs = this._fetchArkCirc(objs, 2);
|
||||
} catch (e1) {
|
||||
try {
|
||||
lines = this._fetchTwoLines(objs);
|
||||
} catch (e2) {
|
||||
throw e1 + "\n" + e2;
|
||||
}
|
||||
}
|
||||
if (!!arcs) this.rr(arcs);
|
||||
if (!!lines) this.ll(lines);
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.p2lDistance = function(objs, promptCallback) {
|
||||
var pl = this._fetchPointAndLine(objs);
|
||||
|
||||
|
|
@ -408,9 +426,6 @@ TCAD.TWO.ParametricManager.prototype.prepareForSubSystem = function(locked, subS
|
|||
|
||||
var lockedIds = locked.map(function(p) {return p.id});
|
||||
|
||||
function peq(p1, p2) {
|
||||
return Math.abs(p1.get() - p2.get()) <= 0.000001
|
||||
}
|
||||
var system = [];
|
||||
this.__getSolveData(subSystemConstraints, system);
|
||||
if (!!extraConstraints) this.__getSolveData(extraConstraints, system);
|
||||
|
|
@ -927,6 +942,43 @@ TCAD.TWO.Constraints.RR.prototype.getObjects = function() {
|
|||
return [this.arc1, this.arc2];
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------ //
|
||||
|
||||
/** @constructor */
|
||||
TCAD.TWO.Constraints.LL = function(line1, line2) {
|
||||
this.line1 = line1;
|
||||
this.line2 = line2;
|
||||
this.length = new TCAD.TWO.Ref(TCAD.math.distanceAB(line1.a, line1.b));
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.LL.prototype.NAME = 'LL';
|
||||
TCAD.TWO.Constraints.LL.prototype.UI_NAME = 'Lines Equality';
|
||||
|
||||
TCAD.TWO.Constraints.LL.prototype.getSolveData = function() {
|
||||
var params1 = [];
|
||||
var params2 = [];
|
||||
this.line1.collectParams(params1);
|
||||
this.line2.collectParams(params2);
|
||||
params1.push(this.length);
|
||||
params2.push(this.length);
|
||||
return [
|
||||
['P2PDistanceV', params1, []],
|
||||
['P2PDistanceV', params2, []]
|
||||
];
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.LL.prototype.serialize = function() {
|
||||
return [this.NAME, [this.line1.id, this.line2.id]];
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Factory[TCAD.TWO.Constraints.LL.prototype.NAME] = function(refs, data) {
|
||||
return new TCAD.TWO.Constraints.LL(refs(data[0]), refs(data[1]));
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.LL.prototype.getObjects = function() {
|
||||
return [this.line1, this.line2];
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------ //
|
||||
|
||||
/** @constructor */
|
||||
|
|
|
|||
Loading…
Reference in a new issue