2016-08-30 20:55:00 +02:00
|
|
|
|
|
|
|
namespace pxsim.visuals {
|
2016-09-01 04:37:20 +02:00
|
|
|
export function mkGenericPartSVG(partVisual: PartVisualDefinition): SVGAndSize<SVGImageElement> {
|
|
|
|
let imgAndSize = mkImageSVG({
|
|
|
|
image: partVisual.image,
|
|
|
|
width: partVisual.width,
|
|
|
|
height: partVisual.height,
|
|
|
|
imageUnitDist: partVisual.pinDist,
|
|
|
|
targetUnitDist: PIN_DIST
|
|
|
|
});
|
|
|
|
return imgAndSize;
|
|
|
|
}
|
|
|
|
|
2016-09-01 04:01:59 +02:00
|
|
|
export class GenericPart implements IBoardComponent<any> {
|
|
|
|
public style: string = "";
|
2016-08-30 20:55:00 +02:00
|
|
|
public element: SVGElement;
|
2016-09-01 04:01:59 +02:00
|
|
|
defs: SVGElement[] = [];
|
|
|
|
|
|
|
|
constructor(partVisual: PartVisualDefinition) {
|
2016-09-01 04:37:20 +02:00
|
|
|
let imgAndSize = mkGenericPartSVG(partVisual);
|
2016-09-01 04:01:59 +02:00
|
|
|
let img = imgAndSize.el;
|
|
|
|
let scaleFn = mkScaleFn(partVisual.pinDist, PIN_DIST);
|
|
|
|
let [pinX, pinY] = partVisual.firstPin;
|
|
|
|
let left = -scaleFn(pinX);
|
|
|
|
let top = -scaleFn(pinY);
|
|
|
|
translateEl(img, [left, top]); // So that 0,0 is on the first pin
|
|
|
|
this.element = svg.elt("g");
|
|
|
|
this.element.appendChild(img);
|
2016-08-30 20:55:00 +02:00
|
|
|
}
|
2016-09-01 04:01:59 +02:00
|
|
|
|
2016-08-30 20:55:00 +02:00
|
|
|
moveToCoord(xy: Coord): void {
|
2016-09-01 04:01:59 +02:00
|
|
|
translateEl(this.element, xy);
|
2016-08-30 20:55:00 +02:00
|
|
|
}
|
2016-09-01 04:01:59 +02:00
|
|
|
|
|
|
|
//unused
|
|
|
|
init(bus: EventBus, state: any, svgEl: SVGSVGElement, gpioPins: string[], otherArgs: string[]): void { }
|
|
|
|
updateState(): void { }
|
|
|
|
updateTheme(): void { }
|
2016-08-30 20:55:00 +02:00
|
|
|
}
|
|
|
|
}
|