towards pin placement

This commit is contained in:
Peli de Halleux
2016-10-14 06:46:56 -07:00
parent 7d4b800637
commit e2fe660012
3 changed files with 15 additions and 6 deletions

View File

@ -1060,11 +1060,10 @@ namespace pxsim.visuals {
private thermometerText: SVGTextElement;
private shakeButton: SVGElement;
public board: pxsim.DalBoard;
private pinNmToCoord: Map<Coord> = {};
private pinNmToCoord: Map<Coord>;
private rgbLed: SVGElement;
constructor(public props: IBoardProps) {
this.recordPinCoords();
this.buildDom();
if (props && props.wireframe)
svg.addClass(this.element, "sim-wireframe");
@ -1091,6 +1090,7 @@ namespace pxsim.visuals {
}
public getCoord(pinNm: string): Coord {
if (!this.pinNmToCoord) this.recordPinCoords();
return this.pinNmToCoord[pinNm];
}
@ -1103,9 +1103,12 @@ namespace pxsim.visuals {
}
public recordPinCoords() {
this.pinNmToCoord = {};
pinNames.forEach((nm,i) => {
// TODO: position pins from SVG
this.pinNmToCoord[nm] = [0,0];
const p = this.pins[i];
const r = p.getBoundingClientRect();
this.pinNmToCoord[nm] = [r.left + r.width / 2, r.top + r.height / 2];
});
}