mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-23 17:04:00 +01:00
fixing degree of freedom analysis
This commit is contained in:
parent
5043b681d7
commit
279db19809
4 changed files with 55 additions and 23 deletions
|
|
@ -20,7 +20,7 @@ export function ContextualControls() {
|
||||||
return <div className={ls.root}>
|
return <div className={ls.root}>
|
||||||
|
|
||||||
{
|
{
|
||||||
selection.map(s => <div className={ls.item}>{s.simpleClassName}: {s.id}</div>)
|
selection.map(s => <div onDoubleClick={debugEgg(s)} className={ls.item}>{s.simpleClassName}: {s.id}</div>)
|
||||||
}
|
}
|
||||||
|
|
||||||
<div className={ls.hr}>AVAILABLE ACTIONS:</div>
|
<div className={ls.hr}>AVAILABLE ACTIONS:</div>
|
||||||
|
|
@ -33,3 +33,9 @@ export function ContextualControls() {
|
||||||
</div>;
|
</div>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function debugEgg(obj) {
|
||||||
|
return e => {
|
||||||
|
obj.visitParams(p => console.log(p.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,8 @@ export class AlgNumSubSystem {
|
||||||
|
|
||||||
snapshot = new Map();
|
snapshot = new Map();
|
||||||
|
|
||||||
|
inTransaction = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
this.solveStatus = {
|
this.solveStatus = {
|
||||||
|
|
@ -53,6 +55,12 @@ export class AlgNumSubSystem {
|
||||||
|
|
||||||
addConstraint(constraint) {
|
addConstraint(constraint) {
|
||||||
|
|
||||||
|
if (this.inTransaction) {
|
||||||
|
constraint.objects.forEach(o => o.constraints.add(constraint));
|
||||||
|
this.allConstraints.push(constraint);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.makeSnapshot();
|
this.makeSnapshot();
|
||||||
|
|
||||||
this.allConstraints.push(constraint);
|
this.allConstraints.push(constraint);
|
||||||
|
|
@ -78,17 +86,17 @@ export class AlgNumSubSystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addConstraints(constraints) {
|
startTransaction() {
|
||||||
constraints.forEach(constraint => {
|
this.inTransaction = true;
|
||||||
if (constraint) {
|
}
|
||||||
constraint.objects.forEach(o => o.constraints.add(constraint));
|
|
||||||
this.allConstraints.push(constraint);
|
finishTransaction() {
|
||||||
}
|
this.inTransaction = false;
|
||||||
});
|
|
||||||
this.prepare();
|
this.prepare();
|
||||||
this.updateFullyConstrainedObjects();
|
this.updateFullyConstrainedObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
invalidate() {
|
invalidate() {
|
||||||
this.prepare();
|
this.prepare();
|
||||||
this.solveFine();
|
this.solveFine();
|
||||||
|
|
@ -409,20 +417,30 @@ export class AlgNumSubSystem {
|
||||||
return this.eliminatedParams.has(p) || (iso && iso.fullyConstrained);
|
return this.eliminatedParams.has(p) || (iso && iso.fullyConstrained);
|
||||||
}
|
}
|
||||||
|
|
||||||
isParamFullyConstrained(p) {
|
isParamFullyConstrained(sourceParam) {
|
||||||
const stack = [p];
|
|
||||||
while (stack.length) {
|
|
||||||
const param = stack.pop();
|
|
||||||
if (!this.isParamShallowConstrained(param)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const substitution = this.substitutedParams.get(p);
|
const visited = new Set();
|
||||||
if (substitution) {
|
|
||||||
substitution.visitParams(p => stack.push(p));
|
const dfs = param => {
|
||||||
|
if (visited.has(param)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
visited.add(param);
|
||||||
return true;
|
if (this.isParamShallowConstrained(param)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const substitution = this.substitutedParams.get(param);
|
||||||
|
let res = false;
|
||||||
|
if (substitution) {
|
||||||
|
substitution.visitParams(p => {
|
||||||
|
if (dfs(p)) {
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
return dfs(sourceParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,8 @@ IO.prototype._loadSketch = function(sketch) {
|
||||||
|
|
||||||
this.cleanUpData();
|
this.cleanUpData();
|
||||||
|
|
||||||
|
this.viewer.parametricManager.algNumSystem.startTransaction();
|
||||||
|
|
||||||
const index = {};
|
const index = {};
|
||||||
|
|
||||||
function endPoint(p) {
|
function endPoint(p) {
|
||||||
|
|
@ -210,14 +212,15 @@ IO.prototype._loadSketch = function(sketch) {
|
||||||
|
|
||||||
let sketchConstraints = sketch['constraints'];
|
let sketchConstraints = sketch['constraints'];
|
||||||
if (version > 1) {
|
if (version > 1) {
|
||||||
this.viewer.parametricManager.algNumSystem.addConstraints(sketchConstraints.map(constr => {
|
sketchConstraints.forEach(constr => {
|
||||||
try {
|
try {
|
||||||
return AlgNumConstraint.read(constr, index)
|
const constraint = AlgNumConstraint.read(constr, index);
|
||||||
|
this.viewer.parametricManager.algNumSystem.addConstraint(constraint);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error("skipping errant constraint: " + constr&&constr.typeId);
|
console.error("skipping errant constraint: " + constr&&constr.typeId);
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error("old format - need an upgrade");
|
console.error("old format - need an upgrade");
|
||||||
}
|
}
|
||||||
|
|
@ -227,6 +230,7 @@ IO.prototype._loadSketch = function(sketch) {
|
||||||
this.viewer.params.constantDefinition = constants;
|
this.viewer.params.constantDefinition = constants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.viewer.parametricManager.algNumSystem.finishTransaction();
|
||||||
this.viewer.parametricManager.notify();
|
this.viewer.parametricManager.notify();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,8 @@ export class Param {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return this.debugSymbol + this.id;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue