var chipmaker={
clear:function(elem){
if ( elem.hasChildNodes() )
{
while ( elem.childNodes.length >= 1 )
{
elem.removeChild( elem.firstChild );
}
}
elem.removeAttribute('connects');
},
openmaker:function(){
$("webtronics_chip_display").parentNode.removeChild($("webtronics_chip_display"));
var div=new Element("div",{id:"webtronics_chip_display"});
$("webtronics_chips_box").insertBefore(div,$("webtronics_chips_box").firstChild);
document.forms['webtronics_chips_form'].reset();
$("webtronics_chip_spice_select").options.length=0;
$("webtronics_chip_spice_select").appendChild(new Element("option",{"value":""}).update("none"));
for(var part in webtronics.model){
$("webtronics_chip_spice_select").insert(new Element("option",{"value":part}).update(part));
}
},
createwtx:function(pins){
var data=new Element("metadata",{"class":"part"})
.update(new Element("wtx:part",{"xmlns:wtx":"http://code.google.com/p/webtronics"})
.insert(new Element("wtx:pins").insert(pins))
.insert(new Element("wtx:id").update("u"))
.insert(new Element("wtx:type").update("u"))
.insert(new Element("wtx:name").update("model"))
.insert(new Element("wtx:category").update("ic"))
.insert(new Element("wtx:value"))
.insert(new Element("wtx:label"))
.insert(new Element("wtx:spice"))
.insert(new Element("wtx:flip"))
.insert(new Element("wtx:model")));
return data;
/*
r
r
resistor
resistors
*/
},
drawchip:function(h,v){
var svgNamespace = 'http://www.w3.org/2000/svg';
var svg;
var fontsize=8;
svgRoot=document.createElementNS(svgNamespace, "svg");
svgRoot.setAttributeNS(null, 'stroke','black');
svgRoot.setAttributeNS(null, 'width','99%');
svgRoot.setAttributeNS(null, 'height','99%');
var chipG = svgRoot.getElementsByTagName("g")[0];
chipG=document.createElementNS(svgNamespace, 'g');
chipG.setAttributeNS(null, 'stroke', 'black');
chipG.setAttributeNS(null, 'stroke-width', '2px');
svgRoot.appendChild(chipG);
/*space between pins*/
var space=20;
/*length of pins */
var pinl=10;
var y=space
var start=pinl;
var hor=h*space;
var pincount=0;
var connections=new Element("wtx:analog");
if(h==0)
{
hor=60;
y=pinl;
start=0;
}
svg = document.createElementNS(svgNamespace, 'rect');
svg.setAttributeNS(null, 'x', pinl);
svg.setAttributeNS(null, 'y', start);
svg.setAttributeNS(null, 'width', hor);
svg.setAttributeNS(null, 'height', v*space);
svg.setAttributeNS(null, 'fill','none');
chipG.appendChild(svg);
/* left horizontal pins*/
for(;y<(v*space+start+10);y+=space){
svg = document.createElementNS(svgNamespace, 'line');
svg.setAttributeNS(null, 'x1',0 );
svg.setAttributeNS(null, 'y1', y);
svg.setAttributeNS(null, 'x2', pinl);
svg.setAttributeNS(null, 'y2', y);
chipG.appendChild(svg);
svg = document.createElementNS(svgNamespace, 'text');
svg.setAttributeNS(null, 'x', 0);
svg.setAttributeNS(null, 'y', y);
svg.setAttributeNS(null, 'font-size', fontsize);
svg.setAttributeNS(null, 'stroke','blue');
svg.setAttributeNS(null, 'stroke-width','0px');
svg.appendChild(document.createTextNode(pincount+1));
chipG.appendChild(svg);
connections.insert(new Element("wtx:node",{"index":pincount,"x":"0","y":y}));
pincount++;
}
y=space
start=pinl;
hor=h*space;
if(h==0)
{
hor=60;
y=pinl;
start=0;
}
/*vertical bottom pins*/
for(var x=space;x=y;y2-=space){
svg = document.createElementNS(svgNamespace, 'line');
svg.setAttributeNS(null, 'x1',hor );
svg.setAttributeNS(null, 'y1',y2);
svg.setAttributeNS(null, 'x2',hor+pinl);
svg.setAttributeNS(null, 'y2',y2);
chipG.appendChild(svg);
svg = document.createElementNS(svgNamespace, 'text');
svg.setAttributeNS(null, 'x', hor);
svg.setAttributeNS(null, 'y', y2);
svg.setAttributeNS(null, 'font-size', fontsize);
svg.setAttributeNS(null, 'stroke','blue');
svg.setAttributeNS(null, 'stroke-width','0px');
svg.appendChild(document.createTextNode(pincount+1));
chipG.appendChild(svg);
connections.insert(new Element("wtx:node",{"index":pincount,"x":hor+pinl,"y":y2}));
pincount++;
}
y=space
start=pinl;
hor=h*space-pinl;
if(h==0){
hor=60;
y=pinl;
start=0;
}
/*vertical top pins*/
for(var x=h*space;x>=space;x-=space){
svg = document.createElementNS(svgNamespace, 'line');
svg.setAttributeNS(null, 'x1',x );
svg.setAttributeNS(null, 'y1', 0);
svg.setAttributeNS(null, 'x2', x);
svg.setAttributeNS(null, 'y2', pinl);
chipG.appendChild(svg);
svg = document.createElementNS(svgNamespace, 'text');
svg.setAttributeNS(null, 'font-size', fontsize);
svg.setAttributeNS(null, 'stroke','blue');
svg.setAttributeNS(null, 'stroke-width','0px');
svg.appendChild(document.createTextNode(pincount+1));
chipG.appendChild(svg);
var box=svg.getBoundingClientRect();
svg.setAttributeNS(null, 'x', x);
svg.setAttributeNS(null, 'y', fontsize);
connections.insert(new Element("wtx:node",{"index":pincount,"x":x,"y":0}));
pincount++;
}
svg=document.createElementNS(svgNamespace,'circle');
svg.setAttributeNS(null, 'cx', 20);
svg.setAttributeNS(null, 'cy', start+10);
svg.setAttributeNS(null, 'r', 3);
chipG.id = 'U-' + createUUID();
chipG.appendChild(svg);
chipG.appendChild(this.createwtx(connections));
return svgRoot;
}
}