jsketcher/web/app/cad/model/mdatum.ts
2020-07-13 17:02:58 -07:00

60 lines
No EOL
1.4 KiB
TypeScript

import {MObject, MObjectIdGenerator, MRootObject} from './mobject';
import CSys from "math/csys";
import Vector from "math/vector";
import {Matrix3} from "math/l3space";
export class MDatum extends MObject {
static TYPE = 'datum';
csys: CSys;
xAxis: MDatumAxis;
yAxis: MDatumAxis;
zAxis: MDatumAxis;
constructor(csys) {
super(MDatum.TYPE, MObjectIdGenerator.next(MDatum.TYPE, 'D'));
this.csys = csys;
this.xAxis = new MDatumAxis(this.id + '/X', this.csys.origin, this.csys.x, this);
this.yAxis = new MDatumAxis(this.id + '/Y', this.csys.origin, this.csys.y, this);
this.zAxis = new MDatumAxis(this.id + '/Z', this.csys.origin, this.csys.z, this);
}
getAxisByLiteral(literal) {
switch (literal) {
case 'X': return this.xAxis;
case 'Y': return this.yAxis;
case 'Z': return this.zAxis;
default: return null;
}
}
traverse(callback: (obj: MObject) => void) {
super.traverse(callback);
this.xAxis.traverse(callback);
this.yAxis.traverse(callback);
this.zAxis.traverse(callback);
}
get parent() {
return null;
}
}
export class MDatumAxis extends MObject {
static TYPE = 'datumAxis';
origin: Vector;
dir: Vector;
holder: MObject;
constructor(id, origin, dir, holder) {
super(MDatumAxis.TYPE, id);
this.origin = origin;
this.dir = dir;
this.holder = holder;
}
get parent() {
return this.holder;
}
}