mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-15 04:45:06 +01:00
parallel constraint
This commit is contained in:
parent
2d3c15ef02
commit
f0d36b0a82
5 changed files with 84 additions and 21 deletions
|
|
@ -201,7 +201,7 @@ export default [
|
|||
{
|
||||
id: 'Perpendicular',
|
||||
shortName: 'Perpendicular',
|
||||
description: 'Perpendicularity between two lines',
|
||||
description: 'Perpendicularity between two or more lines',
|
||||
selectionMatcher: (selection, sortedByType) => matchAll(sortedByType, Segment, 2),
|
||||
|
||||
invoke: ctx => {
|
||||
|
|
@ -210,18 +210,31 @@ export default [
|
|||
const pm = viewer.parametricManager;
|
||||
|
||||
for (let i = 1; i < viewer.selected.length; ++i) {
|
||||
// ConstraintDefinitions.Perpendicular, [viewer.selected[i-1], viewer.selected[i]]);
|
||||
// pm._add(new AlgNumConstraint();
|
||||
const constr = new AlgNumConstraint(ConstraintDefinitions.Perpendicular, [viewer.selected[i-1], viewer.selected[i]]);
|
||||
constr.initConstants();
|
||||
pm._add(constr);
|
||||
}
|
||||
pm.commit();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
id: 'Parallel',
|
||||
shortName: 'Parallel',
|
||||
description: 'Parallelism between two or more lines',
|
||||
selectionMatcher: (selection, sortedByType) => matchAll(sortedByType, Segment, 2),
|
||||
|
||||
const firstConstr = new AlgNumConstraint(ConstraintDefinitions.Perpendicular, [firstSegment, secondSegment]);
|
||||
firstConstr.initConstants();
|
||||
invoke: ctx => {
|
||||
const {viewer} = ctx;
|
||||
|
||||
editConstraint(ctx, firstConstr, () => {
|
||||
pm._add(firstConstr);
|
||||
pm.commit();
|
||||
});
|
||||
const pm = viewer.parametricManager;
|
||||
|
||||
for (let i = 1; i < viewer.selected.length; ++i) {
|
||||
const constr = new AlgNumConstraint(ConstraintDefinitions.Parallel, [viewer.selected[i-1], viewer.selected[i]]);
|
||||
constr.initConstants();
|
||||
pm._add(constr);
|
||||
}
|
||||
pm.commit();
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ export function ConstraintList() {
|
|||
const {viewer, ui} = useContext(SketcherAppContext);
|
||||
|
||||
const edit = (constraint) => {
|
||||
editConstraint(ui.$constraintEditRequest, constraint, NOOP);
|
||||
if (constraint.editable) {
|
||||
editConstraint(ui.$constraintEditRequest, constraint, NOOP);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = constr => {
|
||||
|
|
@ -44,6 +46,9 @@ export function ConstraintList() {
|
|||
|
||||
|
||||
return constraints.map((c, i) => {
|
||||
if (c.internal) {
|
||||
return null;
|
||||
}
|
||||
const conflicting = viewer.parametricManager.algNumSystem.conflicting.has(c);
|
||||
const redundant = viewer.parametricManager.algNumSystem.redundant.has(c);
|
||||
|
||||
|
|
|
|||
|
|
@ -217,8 +217,7 @@ export const ConstraintDefinitions = {
|
|||
const a1 = segment1.params.ang.get();
|
||||
const a2 = segment2.params.ang.get();
|
||||
|
||||
let degrees = (a2 - a1) / DEG_RAD;
|
||||
return (degrees + 360) % 360;
|
||||
return makeAngle0_360(a2 - a1) / DEG_RAD;
|
||||
},
|
||||
transform: degree => degree * DEG_RAD
|
||||
}
|
||||
|
|
@ -247,18 +246,52 @@ export const ConstraintDefinitions = {
|
|||
const a1 = segment1.params.ang.get();
|
||||
const a2 = segment2.params.ang.get();
|
||||
const deg = makeAngle0_360(a2 - a1);
|
||||
|
||||
return deg < Math.PI ? _90 : _270;
|
||||
return Math.abs(270 - deg) > Math.abs(90 - deg) ? 90 : 270;
|
||||
},
|
||||
transform: degree => degree * DEG_RAD
|
||||
}
|
||||
},
|
||||
|
||||
// defineParamsScope: ConstraintDefinitions.AngleBetween.defineParamsScope,
|
||||
defineParamsScope: (objs, cb) => {
|
||||
ConstraintDefinitions.AngleBetween.defineParamsScope(objs, cb);
|
||||
},
|
||||
|
||||
// collectPolynomials: ConstraintDefinitions.AngleBetween.collectPolynomials,
|
||||
collectPolynomials: (polynomials, params, constants) => {
|
||||
ConstraintDefinitions.AngleBetween.collectPolynomials(polynomials, params, constants);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
Parallel: {
|
||||
id: 'Parallel',
|
||||
name: 'Parallel',
|
||||
|
||||
constants: {
|
||||
angle: {
|
||||
type: 'number',
|
||||
description: 'line angle',
|
||||
internal: true,
|
||||
initialValue: ([segment1, segment2]) => {
|
||||
const a1 = segment1.params.ang.get();
|
||||
const a2 = segment2.params.ang.get();
|
||||
const ang = makeAngle0_360(a2 - a1);
|
||||
return Math.abs(180 - ang) > Math.min(Math.abs(360 - ang), Math.abs(0 - ang)) ? 0 : 180;
|
||||
},
|
||||
transform: degree => degree * DEG_RAD
|
||||
}
|
||||
},
|
||||
|
||||
defineParamsScope: (objs, cb) => {
|
||||
ConstraintDefinitions.AngleBetween.defineParamsScope(objs, cb);
|
||||
},
|
||||
|
||||
collectPolynomials: (polynomials, params, constants) => {
|
||||
ConstraintDefinitions.AngleBetween.collectPolynomials(polynomials, params, constants);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
SegmentLength: {
|
||||
id: 'SegmentLength',
|
||||
name: 'Segment Length',
|
||||
|
|
@ -561,6 +594,19 @@ export class AlgNumConstraint {
|
|||
}
|
||||
}
|
||||
|
||||
get editable() {
|
||||
if (!this.schema.constants) {
|
||||
return false;
|
||||
}
|
||||
const defs = Object.values(this.schema.constants);
|
||||
for (let cd of defs) {
|
||||
if (cd.readOnly) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
setConstantsFromGeometry() {
|
||||
if (this.schema.setConstantsFromGeometry) {
|
||||
this.schema.setConstantsFromGeometry(this.objects, this.constants);
|
||||
|
|
|
|||
|
|
@ -50,8 +50,7 @@ export class Segment extends SketchObject {
|
|||
}
|
||||
|
||||
angleDeg() {
|
||||
const degrees = this.params.ang.get() / DEG_RAD;
|
||||
return (degrees + 360) % 360;
|
||||
return makeAngle0_360(this.params.ang.get()) / DEG_RAD;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -206,15 +206,15 @@ function App2D() {
|
|||
});
|
||||
|
||||
this.registerAction('horizontalConstraint', "Horizontal Constraint", function () {
|
||||
app.viewer.parametricManager.horizontal(app.viewer.selected);
|
||||
getActionIfAvailable('Horizontal', app.viewer.selected, action => action.invoke(app.context));
|
||||
});
|
||||
|
||||
this.registerAction('parallelConstraint', "Parallel Constraint", function () {
|
||||
app.viewer.parametricManager.parallel(app.viewer.selected);
|
||||
getActionIfAvailable('Parallel', app.viewer.selected, action => action.invoke(app.context));
|
||||
});
|
||||
|
||||
this.registerAction('perpendicularConstraint', "Perpendicular Constraint", function () {
|
||||
app.viewer.parametricManager.perpendicular(app.viewer.selected);
|
||||
getActionIfAvailable('Perpendicular', app.viewer.selected, action => action.invoke(app.context));
|
||||
});
|
||||
|
||||
this.registerAction('P2LDistanceConstraint', "Distance Between Point and Line", function () {
|
||||
|
|
|
|||
Loading…
Reference in a new issue