//***************************************************************************** // Polyloop editor + Js refinement, Jarek Rossignac, Feb 2007 // To do: // Compute current and output value // compute cost // optimize tree //***************************************************************************** int ng=28; // number of gates color red, yellow, green, cyan, blue, magenta, dred, dyellow, dgreen, dcyan, dblue, dmagenta, white, black, orange, grey, metal; pt pmouse = new pt(0,0); // remembers where mouse was pressed for translations pt closest = new pt(0,0); // tracks closest point on control polyloop boolean showHelpText=false, showMenu=true, showLeaves=true, beautify=false, showTF=false, showCurrent=false, showGates=false, refreshingGates=false, showDrops=true, drawWires=false, raiseBlist=true, showBlist=true; String [] fn= {"p4w3.csg","p4w3b.csg","p7w4.csg","p9w3.csg","p10w4.csg","p10w4b.csg","p12w3.csg","p14w2.csg","p14w4.csg","p14w4b.csg","p14w4c.csg", "p15w9.csg","p16w4.csg","p17w5.csg","p19w4.csg","p22w5.csg","p26w3.csg","p26w3b.csg","p26w4b.csg","p26w4c.csg","p26w4d.csg","p26w5.csg","p26w6.csg","p26w7.csg","p27w5.csg"}; int fni=fn.length-1; // pointer to the next file to load float r=10, s, d, dd,ss, ds, vs,bs,bt,bl,bss; int nL=6; gates Gs; nodes Ns; int depth=1; String [] S={""}; int outWire=0; void setup() { size(1200, 900); smooth(); colorMode(HSB,121); strokeJoin(ROUND); strokeCap(ROUND); ellipseMode(CENTER); PFont font = loadFont("Courier-14.vlw"); textFont(font, 12); red = color(0, 120, 120); yellow = color(20, 120, 120); green = color(40, 120, 120); cyan = color(60, 120, 120); blue = color(80, 120, 120); magenta = color(100, 120, 120); dred = color(0, 120, 60); dyellow = color(20, 120, 60); dgreen = color(40, 120, 60); dcyan = color(60, 120, 60); dblue = color(80, 120, 60); dmagenta = color(100, 120, 60); white = color(0, 0, 120); black = color(0, 120,0); grey = color(0, 120,60); orange = color(10, 100, 120); metal = color(70, 60, 100); loadButtons(); loadToggles(); resize(); Gs = new gates(ng); Ns = new nodes(ng,Gs); } void resize2() {d=height*0.7; s=min (4*r,float(height)/(ng+1)); vs=min(8*r,d/(depth+4)); ds=d/(s+2); dd=(height-d)/16; ss=2*r;} void resize() { d=height*0.5; // where gates are drawn s=min (4*r,float(height)/(ng+1)); // horizontal spacing between gates vs=min(8*r,d/(depth+6)); // vetical spacing between tree nodes ds=d/(s+2)+200; dd=(height-d)/32; // interline spacing ss=2*r; // vertical drop of true wire for swivel bs=height*0.8; // horizontal for Blist triangles bt=height*0.05; // triangle half-size bl=height*0.01; // line offset } void compile() {Ns.setTF(); Ns.passTF(); Ns.R[0].rm(true); Gs.assignLabels();} void draw() { background(121); strokeWeight(2); noFill(); if(raiseBlist) bss=height*0.25; else bss=height*0.07; // horizontal for Blist triangles if (showHelpText) { showHelp(); } else { if ((mousePressed)&&(mouse().isInWindow())&&(keyPressed)) { //println(key+"="+int(key)); if ((key=='+')||(key=='=')) ; if ((key=='*')||(key=='8')) ; } Ns.depth(); resize(); Ns.snap(); Ns.show(); if(refreshingGates) { Ns.setTF(); Ns.passTF(); Ns.R[0].rm(true); Gs.assignLabels(); }; if(showGates) Gs.show(); if(drawWires) { /* stroke(white); strokeWeight(8); Gs.drawWires(); */ stroke(metal); strokeWeight(4); Gs.drawWires(); strokeWeight(2);} if(showGates) Gs.showConnections(); if(showTF) Ns.showTF(); if(showCurrent) {strokeWeight(2); stroke(red); Gs.drawWire(); strokeWeight(2);} Ns.reveal(); Gs.reveal(); // fill(black); text(Ns.R[0].toStringP(),20,20); noFill(); fill(black); text(Ns.R[Ns.p].toStringM(false,Ns.R[Ns.p].O),20,20); noFill(); if (showBlist) {Gs.showBlist(); Ns.showBlist();}; }; if(showMenu) { Buttons.show(); Toggles.show(); pushMatrix(); translate(width-290,Buttons.depth()); text("Blist optimization and compilation of",0,0); translate(0,20); text("Programmable Logical Lists (PLLs)",0,0); translate(0,20); text("from Boolean (CSG) expressions",0,0); translate(0,20); text("built in Processing by Jarek Rossignac",0,0); translate(0,20); translate(0,20); text("File["+fni+"]: "+fn[fni],0,0); translate(0,20); text("primitives = "+ng,0,0); translate(0,20); text("depth = "+depth,0,0); translate(0,20); text("lines = "+Lab.m,0,0); translate(0,20); popMatrix(); } } void loadButtons() { Buttons.add(new button("primitives",0,ng,64,1,1)); } void loadToggles() { Toggles.add(new toggle(" Show blist",showBlist)); Toggles.add(new toggle(" Raise Blist",raiseBlist)); Toggles.add(new toggle(" Show active lines",drawWires)); Toggles.add(new toggle(" Show current",showCurrent)); Toggles.add(new toggle(" Show drops",showDrops)); Toggles.add(new toggle(" Show gates",showGates)); Toggles.add(new toggle(" Load next expression",false)); Toggles.add(new toggle(" Load previous expression",false)); Toggles.add(new toggle(" Gates updated",refreshingGates)); Toggles.add(new toggle(" Make left-heavy",false)); Toggles.add(new toggle(" Optimize",false)); Toggles.add(new toggle(" Cost",false)); } void mousePressed() { int k= Buttons.click(); int m=-1; if(k==++m) {ng=int(Buttons.v(m)); resize(); if (ng>Gs.nG) {Gs.addGate();Ns.addNode();} else {Gs.nG--; Ns.nR--;};} k= Toggles.click(); m=-1; if(k==++m) showBlist=Toggles.v(m); if(k==++m) raiseBlist=Toggles.v(m); if(k==++m) drawWires=Toggles.v(m); if(k==++m) showCurrent=Toggles.v(m); if(k==++m) showDrops=Toggles.v(m); if(k==++m) showGates=Toggles.v(m); if(k==++m) {Toggles.B[m].V=false; fni++; if(fni>=fn.length) fni=0; println("+fni="+fni+"/"+fn.length); S= loadStrings(fn[fni]); fromStringR(); compile();}; if(k==++m) {Toggles.B[m].V=false; fni=(fni-1+fn.length)%fn.length; println("-fni="+fni+"/"+fn.length); S= loadStrings(fn[fni]); fromStringR(); compile();}; if(k==++m) refreshingGates=Toggles.v(m); if(k==++m) {Toggles.B[m].V=false; println("H="+Ns.R[0].pH()); Ns.p=0; Ns.writeString(); fromStringR(); compile(); }; if(k==++m) {Toggles.B[m].V=false; Ns.R[0].pO(); Ns.p=0; Ns.writeString(); fromStringR(); compile(); }; if(k==++m) {Toggles.B[m].V=false; Ns.R[0].pO(); Ns.p=0; }; pmouse=mouse(); if (mouse().isInWindow()) { if (keyPressed) { if ((key=='m')||(key=='a')) if (Ns.pickRoot()) { Ns.merge('+'); compile(); }; if (key=='b') if (Ns.pickRoot()) { Ns.split(); compile();}; if (key=='w') if (Ns.pickRoot()) println(Ns.R[Ns.p].toStringM(false,Ns.R[Ns.p].O)); if (key=='W') if (Ns.pickRoot()) Ns.write(); if (key=='r') if (Ns.pickRoot()) {Ns.writeString(); fromString(); compile(); }; if (key=='R') if (Ns.pickRoot()) {Ns.writeString(); fromStringR(); compile();}; if ((key=='p')||(key=='f')) { Ns.pivot(); Ns.writeString(); fromStringR(); compile();}; } else { if(Gs.pickGate()) Gs.flipGate(); else Ns.flipOp(); }; } } void mouseReleased() { } void keyReleased() { }; void keyPressed() { // println(key+"="+int(key)); if (key=='h') showHelpText=!showHelpText ; if (key=='c') {Ns.p=0; Ns.writeString(); fromStringR(); compile();}; if (key=='M') showMenu=!showMenu; if (key=='n') Ns.reveal(); if (key=='g') Gs.reveal(); if (key=='P') Ns.writeRoots(); if (key=='S') {S[0]=Ns.R[0].toString(); saveStrings("p"+ng+"w"+Lab.m+".csg",S); }; if (key=='s') {S[0]=Ns.R[0].toString(); saveStrings("E.csg",S); fni=fn.length-1;}; if (key=='L') {fni++; if(fni>=fn.length) fni=0; S= loadStrings(fn[fni]); fromStringR(); compile();}; if (key=='l') {S= loadStrings("E.csg"); fromStringR(); compile();}; if (key=='X') {String SP=" "+"-####.tif"; saveFrame(SP);}; };