adds generic parts to instructions parts list and requirements panels
This commit is contained in:
parent
dad3e89577
commit
1f3a2ab6fe
@ -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;
|
|
||||||
let cmp = mkCmpDiv(builtinVisual, {
|
|
||||||
left: QUANT_LBL(quant),
|
left: QUANT_LBL(quant),
|
||||||
leftSize: QUANT_LBL_SIZE,
|
leftSize: QUANT_LBL_SIZE,
|
||||||
cmpScale: PARTS_CMP_SCALE,
|
cmpScale: PARTS_CMP_SCALE,
|
||||||
});
|
});
|
||||||
addClass(cmp, "partslist-cmp");
|
addClass(cmp, "partslist-cmp");
|
||||||
panel.appendChild(cmp);
|
panel.appendChild(cmp);
|
||||||
} else {
|
|
||||||
//TODO: handle generic components
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// wires
|
// wires
|
||||||
@ -538,9 +537,7 @@ 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;
|
|
||||||
let cmp = mkCmpDiv(builtinVisual, {
|
|
||||||
top: `(${row},${col})`,
|
top: `(${row},${col})`,
|
||||||
topSize: LOC_LBL_SIZE,
|
topSize: LOC_LBL_SIZE,
|
||||||
cmpHeight: REQ_CMP_HEIGHT,
|
cmpHeight: REQ_CMP_HEIGHT,
|
||||||
@ -548,9 +545,6 @@ namespace pxsim.instructions {
|
|||||||
})
|
})
|
||||||
addClass(cmp, "cmp-div");
|
addClass(cmp, "cmp-div");
|
||||||
reqsDiv.appendChild(cmp);
|
reqsDiv.appendChild(cmp);
|
||||||
} else {
|
|
||||||
//TODO: generic component
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
|
|
||||||
namespace pxsim.visuals {
|
namespace pxsim.visuals {
|
||||||
export class GenericPart implements IBoardComponent<any> {
|
export function mkGenericPartSVG(partVisual: PartVisualDefinition): SVGAndSize<SVGImageElement> {
|
||||||
public style: string = "";
|
|
||||||
public element: SVGElement;
|
|
||||||
defs: SVGElement[] = [];
|
|
||||||
|
|
||||||
constructor(partVisual: PartVisualDefinition) {
|
|
||||||
let imgAndSize = mkImageSVG({
|
let imgAndSize = mkImageSVG({
|
||||||
image: partVisual.image,
|
image: partVisual.image,
|
||||||
width: partVisual.width,
|
width: partVisual.width,
|
||||||
@ -13,6 +8,16 @@ namespace pxsim.visuals {
|
|||||||
imageUnitDist: partVisual.pinDist,
|
imageUnitDist: partVisual.pinDist,
|
||||||
targetUnitDist: PIN_DIST
|
targetUnitDist: PIN_DIST
|
||||||
});
|
});
|
||||||
|
return imgAndSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GenericPart implements IBoardComponent<any> {
|
||||||
|
public style: string = "";
|
||||||
|
public element: SVGElement;
|
||||||
|
defs: SVGElement[] = [];
|
||||||
|
|
||||||
|
constructor(partVisual: PartVisualDefinition) {
|
||||||
|
let imgAndSize = mkGenericPartSVG(partVisual);
|
||||||
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user