Merge branch 'arduino' into generic-part
This commit is contained in:
commit
e3671ca809
@ -48,6 +48,7 @@ namespace pxsim {
|
|||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
pinDist: number,
|
pinDist: number,
|
||||||
|
extraColumnOffset?: number,
|
||||||
firstPin: [number, number],
|
firstPin: [number, number],
|
||||||
}
|
}
|
||||||
export interface PartDefinition {
|
export interface PartDefinition {
|
||||||
@ -167,8 +168,9 @@ namespace pxsim {
|
|||||||
image: "/static/hardware/speaker.svg",
|
image: "/static/hardware/speaker.svg",
|
||||||
width: 500,
|
width: 500,
|
||||||
height: 500,
|
height: 500,
|
||||||
firstPin: [110, 135],
|
firstPin: [180, 135],
|
||||||
pinDist: 70,
|
pinDist: 70,
|
||||||
|
extraColumnOffset: 1,
|
||||||
},
|
},
|
||||||
breadboardColumnsNeeded: 5,
|
breadboardColumnsNeeded: 5,
|
||||||
breadboardStartRow: "f",
|
breadboardStartRow: "f",
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
@ -414,7 +418,8 @@ namespace pxsim.instructions {
|
|||||||
if (cmps) {
|
if (cmps) {
|
||||||
cmps.forEach(cmpInst => {
|
cmps.forEach(cmpInst => {
|
||||||
let cmp = board.addComponent(cmpInst)
|
let cmp = board.addComponent(cmpInst)
|
||||||
let rowCol: BBRowCol = [`${cmpInst.breadboardStartRow}`, `${cmpInst.breadboardStartColumn}`];
|
let colOffset = (<any>cmpInst.visual).breadboardStartColIdx || 0;
|
||||||
|
let rowCol: BBRowCol = [`${cmpInst.breadboardStartRow}`, `${colOffset + cmpInst.breadboardStartColumn}`];
|
||||||
//last step
|
//last step
|
||||||
if (i === step) {
|
if (i === step) {
|
||||||
board.highlightBreadboardPin(rowCol);
|
board.highlightBreadboardPin(rowCol);
|
||||||
@ -455,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
|
||||||
@ -537,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
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -149,6 +149,7 @@ namespace pxsim.visuals {
|
|||||||
|
|
||||||
public addComponent(cmpDesc: CmpInst): IBoardComponent<any> {
|
public addComponent(cmpDesc: CmpInst): IBoardComponent<any> {
|
||||||
let cmp: IBoardComponent<any> = null;
|
let cmp: IBoardComponent<any> = null;
|
||||||
|
let colOffset = 0;
|
||||||
if (typeof cmpDesc.visual === "string") {
|
if (typeof cmpDesc.visual === "string") {
|
||||||
let builtinVisual = cmpDesc.visual as string;
|
let builtinVisual = cmpDesc.visual as string;
|
||||||
let cnstr = builtinComponentSimVisual[builtinVisual];
|
let cnstr = builtinComponentSimVisual[builtinVisual];
|
||||||
@ -158,13 +159,14 @@ namespace pxsim.visuals {
|
|||||||
} else {
|
} else {
|
||||||
let vis = cmpDesc.visual as PartVisualDefinition;
|
let vis = cmpDesc.visual as PartVisualDefinition;
|
||||||
cmp = new GenericPart(vis);
|
cmp = new GenericPart(vis);
|
||||||
|
colOffset = vis.extraColumnOffset || 0;
|
||||||
}
|
}
|
||||||
this.components.push(cmp);
|
this.components.push(cmp);
|
||||||
this.view.appendChild(cmp.element);
|
this.view.appendChild(cmp.element);
|
||||||
if (cmp.defs)
|
if (cmp.defs)
|
||||||
cmp.defs.forEach(d => this.defs.appendChild(d));
|
cmp.defs.forEach(d => this.defs.appendChild(d));
|
||||||
this.style.textContent += cmp.style || "";
|
this.style.textContent += cmp.style || "";
|
||||||
let rowCol = <BBRowCol>[`${cmpDesc.breadboardStartRow}`, `${cmpDesc.breadboardStartColumn}`];
|
let rowCol = <BBRowCol>[`${cmpDesc.breadboardStartRow}`, `${colOffset + cmpDesc.breadboardStartColumn}`];
|
||||||
let coord = this.getBBCoord(rowCol);
|
let coord = this.getBBCoord(rowCol);
|
||||||
cmp.moveToCoord(coord);
|
cmp.moveToCoord(coord);
|
||||||
let getCmpClass = (type: string) => `sim-${type}-cmp`;
|
let getCmpClass = (type: string) => `sim-${type}-cmp`;
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user