From e052255c5567ae7b43c0456dc6efc2d520aa819e Mon Sep 17 00:00:00 2001 From: BigEd Date: Mon, 29 Nov 2010 20:07:29 +0000 Subject: [PATCH] add first cut of zooming to fit found objects: transistors and nodes. Renamed "Highlight:" button to "Find:" --- expert.html | 2 +- expertWires.js | 26 +++++++++++++++++++++++++- wires.js | 29 +++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/expert.html b/expert.html index f11f9f6..3291c7e 100644 --- a/expert.html +++ b/expert.html @@ -86,7 +86,7 @@ $().ready(function(){ (protection)
- + diff --git a/expertWires.js b/expertWires.js index fbb014a..c80aabe 100644 --- a/expertWires.js +++ b/expertWires.js @@ -299,6 +299,7 @@ function recenter(){ var highlightThese; // flash some set of nodes according to user input +// also zoom to fit those nodes (not presently optional) function hiliteNodeList(){ var tmplist = document.getElementById('HighlightThese').value.split(/[\s,]+/); if(tmplist.length==0){ @@ -307,14 +308,26 @@ function hiliteNodeList(){ return; } highlightThese = []; + var seglist=[]; for(var i=0;ixmax) xmax=seglist[s][i]; + if(seglist[s][i+1]ymax) ymax=seglist[s][i+1]; + } + } + zoomToBox(xmin,xmax,ymin,ymax); clearHighlight(); // nullify the simulation overlay (orange/purple) hiliteNode(-1); // unhighlight all nodes setTimeout("hiliteNode(highlightThese);", 400); diff --git a/wires.js b/wires.js index f527570..bb9f963 100644 --- a/wires.js +++ b/wires.js @@ -150,26 +150,33 @@ function overlayNode(w){ } } +// originally to highlight using a list of node numbers +// but can now include transistor names function hiliteNode(n){ var ctx = hilite.getContext('2d'); ctx.clearRect(0,0,grCanvasSize,grCanvasSize); - ctx.fillStyle = 'rgba(255,255,255,0.7)'; if(n==-1) return; - if(isNodeHigh(n[0])) - ctx.fillStyle = 'rgba(255,0,0,0.7)'; for(var i in n){ + if(typeof n[i] != "number") { + hiliteTrans([n[i]]); + continue; + } + if(isNodeHigh(n[i])) { + ctx.fillStyle = 'rgba(255,0,0,0.7)'; + } else { + ctx.fillStyle = 'rgba(255,255,255,0.7)'; + } var segs = nodes[n[i]].segs; for(var s in segs){drawSeg(ctx, segs[s]); ctx.fill();} } } +// highlight a single transistor (additively - does not clear highlighting) function hiliteTrans(n){ var ctx = hilite.getContext('2d'); - ctx.clearRect(0,0,grCanvasSize,grCanvasSize); - ctx.strokeStyle = 'rgba(255,255,255,1.0)'; + ctx.strokeStyle = 'rgba(255,255,255,0.7)'; ctx.lineWidth = 4 - if(n==-1) return; for(var t in n){ var bb = transistors[n[t]].bb var segs = [[bb[0], bb[2], bb[1], bb[2], bb[1], bb[3], bb[0], bb[3]]] @@ -177,6 +184,16 @@ function hiliteTrans(n){ } } +// takes a bounding box in chip coords and centres the display over it +function zoomToBox(xmin,xmax,ymin,ymax){ + var xmid=(xmin+xmax)/2; + var ymid=(ymin+ymax)/2; + var x=xmid/grChipSize*600; + var y=600-ymid/grChipSize*600; + var zoom=5; // pending a more careful calculation + moveHere([x,y,zoom]); +} + function drawSeg(ctx, seg){ var dx = 400; ctx.beginPath();