adds generic parts to instructions parts list and requirements panels

This commit is contained in:
darzu 2016-08-31 19:37:20 -07:00
parent dad3e89577
commit 1f3a2ab6fe
2 changed files with 35 additions and 36 deletions

View File

@ -278,14 +278,18 @@ namespace pxsim.instructions {
div.appendChild(svgEl); div.appendChild(svgEl);
return div; return div;
} }
function mkCmpDiv(type: "wire" | string, opts: mkCmpDivOpts): HTMLElement { function mkCmpDiv(cmp: "wire" | string | PartVisualDefinition, opts: mkCmpDivOpts): HTMLElement {
let el: visuals.SVGElAndSize; let el: visuals.SVGElAndSize;
if (type == "wire") { if (cmp == "wire") {
//TODO: support non-croc wire parts //TODO: support non-croc wire parts
el = visuals.mkWirePart([0, 0], opts.wireClr || "red", true); el = visuals.mkWirePart([0, 0], opts.wireClr || "red", true);
} else { } else if (typeof cmp == "string") {
let cnstr = builtinComponentPartVisual[type]; let builtinVis = <string>cmp;
let cnstr = builtinComponentPartVisual[builtinVis];
el = cnstr([0, 0]); el = cnstr([0, 0]);
} else {
let partVis = <PartVisualDefinition> cmp;
el = visuals.mkGenericPartSVG(partVis);
} }
return wrapSvg(el, opts); return wrapSvg(el, opts);
} }
@ -456,18 +460,13 @@ namespace pxsim.instructions {
if (c.visual === "buttonpair") { if (c.visual === "buttonpair") {
quant = 2; quant = 2;
} }
if (typeof c.visual === "string") { let cmp = mkCmpDiv(c.visual, {
let builtinVisual = <string>c.visual; left: QUANT_LBL(quant),
let cmp = mkCmpDiv(builtinVisual, { leftSize: QUANT_LBL_SIZE,
left: QUANT_LBL(quant), cmpScale: PARTS_CMP_SCALE,
leftSize: QUANT_LBL_SIZE, });
cmpScale: PARTS_CMP_SCALE, addClass(cmp, "partslist-cmp");
}); panel.appendChild(cmp);
addClass(cmp, "partslist-cmp");
panel.appendChild(cmp);
} else {
//TODO: handle generic components
}
}); });
// wires // wires
@ -538,19 +537,14 @@ namespace pxsim.instructions {
} }
locs.forEach((l, i) => { locs.forEach((l, i) => {
let [row, col] = l; let [row, col] = l;
if (typeof c.visual === "string") { let cmp = mkCmpDiv(c.visual, {
let builtinVisual = <string>c.visual; top: `(${row},${col})`,
let cmp = mkCmpDiv(builtinVisual, { topSize: LOC_LBL_SIZE,
top: `(${row},${col})`, cmpHeight: REQ_CMP_HEIGHT,
topSize: LOC_LBL_SIZE, cmpScale: REQ_CMP_SCALE
cmpHeight: REQ_CMP_HEIGHT, })
cmpScale: REQ_CMP_SCALE addClass(cmp, "cmp-div");
}) reqsDiv.appendChild(cmp);
addClass(cmp, "cmp-div");
reqsDiv.appendChild(cmp);
} else {
//TODO: generic component
}
}); });
}); });

View File

@ -1,18 +1,23 @@
namespace pxsim.visuals { namespace pxsim.visuals {
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;
}
export class GenericPart implements IBoardComponent<any> { export class GenericPart implements IBoardComponent<any> {
public style: string = ""; public style: string = "";
public element: SVGElement; public element: SVGElement;
defs: SVGElement[] = []; defs: SVGElement[] = [];
constructor(partVisual: PartVisualDefinition) { constructor(partVisual: PartVisualDefinition) {
let imgAndSize = mkImageSVG({ let imgAndSize = mkGenericPartSVG(partVisual);
image: partVisual.image,
width: partVisual.width,
height: partVisual.height,
imageUnitDist: partVisual.pinDist,
targetUnitDist: PIN_DIST
});
let img = imgAndSize.el; let img = imgAndSize.el;
let scaleFn = mkScaleFn(partVisual.pinDist, PIN_DIST); let scaleFn = mkScaleFn(partVisual.pinDist, PIN_DIST);
let [pinX, pinY] = partVisual.firstPin; let [pinX, pinY] = partVisual.firstPin;