From dad3e89577a94d5893de94e29d7087a697ed47a3 Mon Sep 17 00:00:00 2001 From: darzu Date: Wed, 31 Aug 2016 19:28:28 -0700 Subject: [PATCH 1/2] adds "extraColumnOffset" for generic parts --- sim/definitions.ts | 4 +++- sim/instructions/instructions.ts | 3 ++- sim/visuals/boardhost.ts | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sim/definitions.ts b/sim/definitions.ts index e8e9bf26..4a5531f8 100644 --- a/sim/definitions.ts +++ b/sim/definitions.ts @@ -48,6 +48,7 @@ namespace pxsim { width: number, height: number, pinDist: number, + extraColumnOffset?: number, firstPin: [number, number], } export interface PartDefinition { @@ -294,8 +295,9 @@ namespace pxsim { image: "/static/hardware/speaker.svg", width: 500, height: 500, - firstPin: [110, 135], + firstPin: [180, 135], pinDist: 70, + extraColumnOffset: 1, }, breadboardColumnsNeeded: 5, breadboardStartRow: "f", diff --git a/sim/instructions/instructions.ts b/sim/instructions/instructions.ts index de295bf7..1ecf25da 100644 --- a/sim/instructions/instructions.ts +++ b/sim/instructions/instructions.ts @@ -414,7 +414,8 @@ namespace pxsim.instructions { if (cmps) { cmps.forEach(cmpInst => { let cmp = board.addComponent(cmpInst) - let rowCol: BBRowCol = [`${cmpInst.breadboardStartRow}`, `${cmpInst.breadboardStartColumn}`]; + let colOffset = (cmpInst.visual).breadboardStartColIdx || 0; + let rowCol: BBRowCol = [`${cmpInst.breadboardStartRow}`, `${colOffset + cmpInst.breadboardStartColumn}`]; //last step if (i === step) { board.highlightBreadboardPin(rowCol); diff --git a/sim/visuals/boardhost.ts b/sim/visuals/boardhost.ts index de7ae0f7..fdbffb50 100644 --- a/sim/visuals/boardhost.ts +++ b/sim/visuals/boardhost.ts @@ -149,6 +149,7 @@ namespace pxsim.visuals { public addComponent(cmpDesc: CmpInst): IBoardComponent { let cmp: IBoardComponent = null; + let colOffset = 0; if (typeof cmpDesc.visual === "string") { let builtinVisual = cmpDesc.visual as string; let cnstr = builtinComponentSimVisual[builtinVisual]; @@ -158,13 +159,14 @@ namespace pxsim.visuals { } else { let vis = cmpDesc.visual as PartVisualDefinition; cmp = new GenericPart(vis); + colOffset = vis.extraColumnOffset || 0; } this.components.push(cmp); this.view.appendChild(cmp.element); if (cmp.defs) cmp.defs.forEach(d => this.defs.appendChild(d)); this.style.textContent += cmp.style || ""; - let rowCol = [`${cmpDesc.breadboardStartRow}`, `${cmpDesc.breadboardStartColumn}`]; + let rowCol = [`${cmpDesc.breadboardStartRow}`, `${colOffset + cmpDesc.breadboardStartColumn}`]; let coord = this.getBBCoord(rowCol); cmp.moveToCoord(coord); let getCmpClass = (type: string) => `sim-${type}-cmp`; From 1f3a2ab6fe7af9738bc1fc0cad6c97b0e8b9b909 Mon Sep 17 00:00:00 2001 From: darzu Date: Wed, 31 Aug 2016 19:37:20 -0700 Subject: [PATCH 2/2] adds generic parts to instructions parts list and requirements panels --- sim/instructions/instructions.ts | 52 ++++++++++++++------------------ sim/visuals/genericpart.ts | 19 +++++++----- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/sim/instructions/instructions.ts b/sim/instructions/instructions.ts index 1ecf25da..25cb44ec 100644 --- a/sim/instructions/instructions.ts +++ b/sim/instructions/instructions.ts @@ -278,14 +278,18 @@ namespace pxsim.instructions { div.appendChild(svgEl); return div; } - function mkCmpDiv(type: "wire" | string, opts: mkCmpDivOpts): HTMLElement { + function mkCmpDiv(cmp: "wire" | string | PartVisualDefinition, opts: mkCmpDivOpts): HTMLElement { let el: visuals.SVGElAndSize; - if (type == "wire") { + if (cmp == "wire") { //TODO: support non-croc wire parts el = visuals.mkWirePart([0, 0], opts.wireClr || "red", true); - } else { - let cnstr = builtinComponentPartVisual[type]; + } else if (typeof cmp == "string") { + let builtinVis = cmp; + let cnstr = builtinComponentPartVisual[builtinVis]; el = cnstr([0, 0]); + } else { + let partVis = cmp; + el = visuals.mkGenericPartSVG(partVis); } return wrapSvg(el, opts); } @@ -456,18 +460,13 @@ namespace pxsim.instructions { if (c.visual === "buttonpair") { quant = 2; } - if (typeof c.visual === "string") { - let builtinVisual = c.visual; - let cmp = mkCmpDiv(builtinVisual, { - left: QUANT_LBL(quant), - leftSize: QUANT_LBL_SIZE, - cmpScale: PARTS_CMP_SCALE, - }); - addClass(cmp, "partslist-cmp"); - panel.appendChild(cmp); - } else { - //TODO: handle generic components - } + let cmp = mkCmpDiv(c.visual, { + left: QUANT_LBL(quant), + leftSize: QUANT_LBL_SIZE, + cmpScale: PARTS_CMP_SCALE, + }); + addClass(cmp, "partslist-cmp"); + panel.appendChild(cmp); }); // wires @@ -538,19 +537,14 @@ namespace pxsim.instructions { } locs.forEach((l, i) => { let [row, col] = l; - if (typeof c.visual === "string") { - let builtinVisual = c.visual; - let cmp = mkCmpDiv(builtinVisual, { - top: `(${row},${col})`, - topSize: LOC_LBL_SIZE, - cmpHeight: REQ_CMP_HEIGHT, - cmpScale: REQ_CMP_SCALE - }) - addClass(cmp, "cmp-div"); - reqsDiv.appendChild(cmp); - } else { - //TODO: generic component - } + let cmp = mkCmpDiv(c.visual, { + top: `(${row},${col})`, + topSize: LOC_LBL_SIZE, + cmpHeight: REQ_CMP_HEIGHT, + cmpScale: REQ_CMP_SCALE + }) + addClass(cmp, "cmp-div"); + reqsDiv.appendChild(cmp); }); }); diff --git a/sim/visuals/genericpart.ts b/sim/visuals/genericpart.ts index 3c737d46..e31eee72 100644 --- a/sim/visuals/genericpart.ts +++ b/sim/visuals/genericpart.ts @@ -1,18 +1,23 @@ namespace pxsim.visuals { + export function mkGenericPartSVG(partVisual: PartVisualDefinition): SVGAndSize { + 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 { public style: string = ""; public element: SVGElement; defs: SVGElement[] = []; constructor(partVisual: PartVisualDefinition) { - let imgAndSize = mkImageSVG({ - image: partVisual.image, - width: partVisual.width, - height: partVisual.height, - imageUnitDist: partVisual.pinDist, - targetUnitDist: PIN_DIST - }); + let imgAndSize = mkGenericPartSVG(partVisual); let img = imgAndSize.el; let scaleFn = mkScaleFn(partVisual.pinDist, PIN_DIST); let [pinX, pinY] = partVisual.firstPin;