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}>
|
||||
|
||||
{
|
||||
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>
|
||||
|
|
@ -33,3 +33,9 @@ export function ContextualControls() {
|
|||
</div>;
|
||||
|
||||
}
|
||||
|
||||
function debugEgg(obj) {
|
||||
return e => {
|
||||
obj.visitParams(p => console.log(p.toString()));
|
||||
}
|
||||
}
|
||||
|
|
@ -30,6 +30,8 @@ export class AlgNumSubSystem {
|
|||
|
||||
snapshot = new Map();
|
||||
|
||||
inTransaction = false;
|
||||
|
||||
constructor() {
|
||||
|
||||
this.solveStatus = {
|
||||
|
|
@ -53,6 +55,12 @@ export class AlgNumSubSystem {
|
|||
|
||||
addConstraint(constraint) {
|
||||
|
||||
if (this.inTransaction) {
|
||||
constraint.objects.forEach(o => o.constraints.add(constraint));
|
||||
this.allConstraints.push(constraint);
|
||||
return;
|
||||
}
|
||||
|
||||
this.makeSnapshot();
|
||||
|
||||
this.allConstraints.push(constraint);
|
||||
|
|
@ -78,17 +86,17 @@ export class AlgNumSubSystem {
|
|||
}
|
||||
}
|
||||
|
||||
addConstraints(constraints) {
|
||||
constraints.forEach(constraint => {
|
||||
if (constraint) {
|
||||
constraint.objects.forEach(o => o.constraints.add(constraint));
|
||||
this.allConstraints.push(constraint);
|
||||
}
|
||||
});
|
||||
startTransaction() {
|
||||
this.inTransaction = true;
|
||||
}
|
||||
|
||||
finishTransaction() {
|
||||
this.inTransaction = false;
|
||||
this.prepare();
|
||||
this.updateFullyConstrainedObjects();
|
||||
}
|
||||
|
||||
|
||||
invalidate() {
|
||||
this.prepare();
|
||||
this.solveFine();
|
||||
|
|
@ -409,20 +417,30 @@ export class AlgNumSubSystem {
|
|||
return this.eliminatedParams.has(p) || (iso && iso.fullyConstrained);
|
||||
}
|
||||
|
||||
isParamFullyConstrained(p) {
|
||||
const stack = [p];
|
||||
while (stack.length) {
|
||||
const param = stack.pop();
|
||||
if (!this.isParamShallowConstrained(param)) {
|
||||
return false;
|
||||
}
|
||||
isParamFullyConstrained(sourceParam) {
|
||||
|
||||
const substitution = this.substitutedParams.get(p);
|
||||
if (substitution) {
|
||||
substitution.visitParams(p => stack.push(p));
|
||||
const visited = new Set();
|
||||
|
||||
const dfs = param => {
|
||||
if (visited.has(param)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
visited.add(param);
|
||||
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.viewer.parametricManager.algNumSystem.startTransaction();
|
||||
|
||||
const index = {};
|
||||
|
||||
function endPoint(p) {
|
||||
|
|
@ -210,14 +212,15 @@ IO.prototype._loadSketch = function(sketch) {
|
|||
|
||||
let sketchConstraints = sketch['constraints'];
|
||||
if (version > 1) {
|
||||
this.viewer.parametricManager.algNumSystem.addConstraints(sketchConstraints.map(constr => {
|
||||
sketchConstraints.forEach(constr => {
|
||||
try {
|
||||
return AlgNumConstraint.read(constr, index)
|
||||
const constraint = AlgNumConstraint.read(constr, index);
|
||||
this.viewer.parametricManager.algNumSystem.addConstraint(constraint);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.error("skipping errant constraint: " + constr&&constr.typeId);
|
||||
}
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
console.error("old format - need an upgrade");
|
||||
}
|
||||
|
|
@ -227,6 +230,7 @@ IO.prototype._loadSketch = function(sketch) {
|
|||
this.viewer.params.constantDefinition = constants;
|
||||
}
|
||||
|
||||
this.viewer.parametricManager.algNumSystem.finishTransaction();
|
||||
this.viewer.parametricManager.notify();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,4 +18,8 @@ export class Param {
|
|||
return this.value;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.debugSymbol + this.id;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue