Showing preview only (625K chars total). Download the full file or copy to clipboard to get everything.
Repository: hausen/circuit-simulator
Branch: master
Commit: 293216aaee13
Files: 381
Total size: 548.9 KB
Directory structure:
gitextract_yobno83y/
├── .gitignore
├── README.md
└── src/
├── ACRailElm.java
├── ACVoltageElm.java
├── ADCElm.java
├── AnalogSwitch2Elm.java
├── AnalogSwitchElm.java
├── AndGateElm.java
├── AntennaElm.java
├── BoxElm.java
├── CC2Elm.java
├── CapacitorElm.java
├── ChipElm.java
├── CirSim.java
├── Circuit.java
├── CircuitCanvas.java
├── CircuitElm.java
├── CircuitLayout.java
├── CircuitNode.java
├── CircuitNodeLink.java
├── ClockElm.java
├── CounterElm.java
├── CurrentElm.java
├── DACElm.java
├── DCVoltageElm.java
├── DFlipFlopElm.java
├── DecadeElm.java
├── DiacElm.java
├── Diode.java
├── DiodeElm.java
├── EditDialog.java
├── EditDialogLayout.java
├── EditInfo.java
├── EditOptions.java
├── GateElm.java
├── GraphicElm.java
├── GroundElm.java
├── ImportExportAppletDialog.java
├── ImportExportClipboardDialog.java
├── ImportExportDialog.java
├── ImportExportDialogFactory.java
├── ImportExportDialogLayout.java
├── ImportExportFileDialog.java
├── Inductor.java
├── InductorElm.java
├── InverterElm.java
├── JKFlipFlopElm.java
├── JfetElm.java
├── LEDElm.java
├── LampElm.java
├── LatchElm.java
├── LogicInputElm.java
├── LogicOutputElm.java
├── Makefile
├── Manifest.txt
├── MemristorElm.java
├── MosfetElm.java
├── NJfetElm.java
├── NMosfetElm.java
├── NTransistorElm.java
├── NandGateElm.java
├── NorGateElm.java
├── OpAmpElm.java
├── OpAmpSwapElm.java
├── OrGateElm.java
├── OutputElm.java
├── PMosfetElm.java
├── PTransistorElm.java
├── PhaseCompElm.java
├── PhotoResistorElm.java
├── PotElm.java
├── ProbeElm.java
├── PushSwitchElm.java
├── RailElm.java
├── RelayElm.java
├── ResistorElm.java
├── RowInfo.java
├── SCRElm.java
├── Scope.java
├── SevenSegElm.java
├── SparkGapElm.java
├── SquareRailElm.java
├── SweepElm.java
├── Switch2Elm.java
├── SwitchElm.java
├── TappedTransformerElm.java
├── TextElm.java
├── ThermistorElm.java
├── TimerElm.java
├── TransLineElm.java
├── TransformerElm.java
├── TransistorElm.java
├── TriacElm.java
├── TriodeElm.java
├── TunnelDiodeElm.java
├── VCOElm.java
├── VarRailElm.java
├── VoltageElm.java
├── WireElm.java
├── XorGateElm.java
├── ZenerElm.java
├── circuits/
│ ├── 3-cgand.txt
│ ├── 3-cgor.txt
│ ├── 3-f211.txt
│ ├── 3-f220.txt
│ ├── 3-f221.txt
│ ├── 3-invert.txt
│ ├── 3way.txt
│ ├── 4way.txt
│ ├── 555int.txt
│ ├── 555lowduty.txt
│ ├── 555missing.txt
│ ├── 555monostable.txt
│ ├── 555pulsemod.txt
│ ├── 555saw.txt
│ ├── 555schmitt.txt
│ ├── 555sequencer.txt
│ ├── 555square.txt
│ ├── 7segdecoder.txt
│ ├── allpass1.txt
│ ├── allpass2.txt
│ ├── amdetect.txt
│ ├── amp-dfdx.txt
│ ├── amp-diff.txt
│ ├── amp-follower.txt
│ ├── amp-fullrect.txt
│ ├── amp-integ.txt
│ ├── amp-invert.txt
│ ├── amp-noninvert.txt
│ ├── amp-rect.txt
│ ├── amp-schmitt.txt
│ ├── amp-sum.txt
│ ├── bandpass.txt
│ ├── besselbutter.txt
│ ├── blank.txt
│ ├── butter10lo.txt
│ ├── cap.txt
│ ├── capac.txt
│ ├── capmult.txt
│ ├── capmultcaps.txt
│ ├── capmultfreq.txt
│ ├── cappar.txt
│ ├── capseries.txt
│ ├── cc2.txt
│ ├── cc2imp.txt
│ ├── cc2impn.txt
│ ├── cc2n.txt
│ ├── ccdiff.txt
│ ├── cciamp.txt
│ ├── ccinductor.txt
│ ├── ccint.txt
│ ├── ccitov.txt
│ ├── ccvccs.txt
│ ├── ceamp.txt
│ ├── classd.txt
│ ├── clockedsrff.txt
│ ├── cmosff.txt
│ ├── cmosinverter.txt
│ ├── cmosinvertercap.txt
│ ├── cmosinverterslow.txt
│ ├── cmosmsff.txt
│ ├── cmosnand.txt
│ ├── cmosnor.txt
│ ├── cmostransgate.txt
│ ├── cmosxor.txt
│ ├── colpitts.txt
│ ├── counter.txt
│ ├── counter8.txt
│ ├── coupled1.txt
│ ├── coupled2.txt
│ ├── coupled3.txt
│ ├── crossover.txt
│ ├── cube.txt
│ ├── currentsrc.txt
│ ├── currentsrcelm.txt
│ ├── currentsrcramp.txt
│ ├── dac.txt
│ ├── darlington.txt
│ ├── dcrestoration.txt
│ ├── deccounter.txt
│ ├── decoder.txt
│ ├── delayrc.txt
│ ├── deltasigma.txt
│ ├── diff.txt
│ ├── digcompare.txt
│ ├── digsine.txt
│ ├── diodeclip.txt
│ ├── diodecurve.txt
│ ├── diodelimit.txt
│ ├── diodevar.txt
│ ├── divideby2.txt
│ ├── divideby3.txt
│ ├── dram.txt
│ ├── dtlinverter.txt
│ ├── dtlnand.txt
│ ├── dtlnor.txt
│ ├── eclnor.txt
│ ├── eclosc.txt
│ ├── edgedff.txt
│ ├── filt-hipass-l.txt
│ ├── filt-hipass.txt
│ ├── filt-lopass-l.txt
│ ├── filt-lopass.txt
│ ├── filt-vcvs-hipass.txt
│ ├── filt-vcvs-lopass.txt
│ ├── flashadc.txt
│ ├── follower.txt
│ ├── freqdouble.txt
│ ├── fulladd.txt
│ ├── fullrect.txt
│ ├── fullrectf.txt
│ ├── graycode.txt
│ ├── grid.txt
│ ├── grid2.txt
│ ├── gyrator.txt
│ ├── halfadd.txt
│ ├── hartley.txt
│ ├── hfadc.txt
│ ├── howland.txt
│ ├── impedance.txt
│ ├── indmultfreq.txt
│ ├── indmultind.txt
│ ├── indpar.txt
│ ├── indseries.txt
│ ├── induct.txt
│ ├── inductac.txt
│ ├── inductkick-block.txt
│ ├── inductkick-snub.txt
│ ├── inductkick.txt
│ ├── inv-osc.txt
│ ├── invertamp.txt
│ ├── itov.txt
│ ├── jfetamp.txt
│ ├── jfetcurrentsrc.txt
│ ├── jfetfollower-nooff.txt
│ ├── jfetfollower.txt
│ ├── jkff.txt
│ ├── johnsonctr.txt
│ ├── ladder.txt
│ ├── leadingedge.txt
│ ├── ledflasher.txt
│ ├── lissa.txt
│ ├── logconvert.txt
│ ├── longdist.txt
│ ├── lrc-critical.txt
│ ├── lrc.txt
│ ├── majority.txt
│ ├── masterslaveff.txt
│ ├── mirror.txt
│ ├── moscurrentramp.txt
│ ├── moscurrentsrc.txt
│ ├── mosfetamp.txt
│ ├── mosfollower.txt
│ ├── mosmirror.txt
│ ├── mosswitch.txt
│ ├── mr-crossbar.txt
│ ├── mr-sine.txt
│ ├── mr-sine2.txt
│ ├── mr-sine3.txt
│ ├── mr-square.txt
│ ├── mr-triangle.txt
│ ├── mr.txt
│ ├── multivib-a.txt
│ ├── multivib-bi.txt
│ ├── multivib-mono.txt
│ ├── mux.txt
│ ├── mux3state.txt
│ ├── nandff.txt
│ ├── nic-r.txt
│ ├── nmosfet.txt
│ ├── nmosinverter.txt
│ ├── nmosinverter2.txt
│ ├── nmosnand.txt
│ ├── norton.txt
│ ├── notch.txt
│ ├── npn.txt
│ ├── ohms.txt
│ ├── opamp-regulator.txt
│ ├── opamp.txt
│ ├── opampfeedback.txt
│ ├── opint-current.txt
│ ├── opint-invert-amp.txt
│ ├── opint-slew.txt
│ ├── opint.txt
│ ├── peak-detect.txt
│ ├── phasecomp.txt
│ ├── phasecompint.txt
│ ├── phaseseq.txt
│ ├── phaseshiftosc.txt
│ ├── phasesplit.txt
│ ├── pll.txt
│ ├── pll2.txt
│ ├── pll2a.txt
│ ├── pmosfet.txt
│ ├── pnp.txt
│ ├── pot.txt
│ ├── potdivide.txt
│ ├── powerfactor1.txt
│ ├── powerfactor2.txt
│ ├── pushpull.txt
│ ├── pushpullxover.txt
│ ├── r2rladder.txt
│ ├── rectify.txt
│ ├── relaxosc.txt
│ ├── relay.txt
│ ├── relayand.txt
│ ├── relayctr.txt
│ ├── relayff.txt
│ ├── relaymux.txt
│ ├── relayor.txt
│ ├── relaytff.txt
│ ├── relayxor.txt
│ ├── res-par.txt
│ ├── res-series.txt
│ ├── resistors.txt
│ ├── ringing.txt
│ ├── ringmod.txt
│ ├── rossler.txt
│ ├── rtlinverter.txt
│ ├── rtlnand.txt
│ ├── rtlnor.txt
│ ├── samplenhold.txt
│ ├── sawtooth.txt
│ ├── schmitt.txt
│ ├── scr.txt
│ ├── scractrig.txt
│ ├── sine.txt
│ ├── sinediode.txt
│ ├── spark-marx.txt
│ ├── spark-sawtooth.txt
│ ├── spikegen.txt
│ ├── switchedcap.txt
│ ├── switchfilter.txt
│ ├── swtreedac.txt
│ ├── synccounter.txt
│ ├── tdiode.txt
│ ├── tdosc.txt
│ ├── tdrelax.txt
│ ├── tesla.txt
│ ├── thevenin.txt
│ ├── tl.txt
│ ├── tlfreq.txt
│ ├── tllight.txt
│ ├── tllopass.txt
│ ├── tlmatch1.txt
│ ├── tlmatch2.txt
│ ├── tlmis1.txt
│ ├── tlmismatch.txt
│ ├── tlstand.txt
│ ├── tlterm.txt
│ ├── traffic.txt
│ ├── trans-diffamp-common.txt
│ ├── trans-diffamp-cursrc.txt
│ ├── trans-diffamp.txt
│ ├── transformer.txt
│ ├── transformerdc.txt
│ ├── transformerdown.txt
│ ├── transformerup.txt
│ ├── transswitch.txt
│ ├── triangle.txt
│ ├── triode.txt
│ ├── triodeamp.txt
│ ├── ttlinverter.txt
│ ├── ttlnand.txt
│ ├── ttlnor.txt
│ ├── twint.txt
│ ├── vco.txt
│ ├── voltdivide.txt
│ ├── voltdouble.txt
│ ├── voltdouble2.txt
│ ├── voltinvert.txt
│ ├── voltquad.txt
│ ├── volttriple.txt
│ ├── volume.txt
│ ├── wheatstone.txt
│ ├── xor.txt
│ ├── xorphasedet.txt
│ ├── zeneriv.txt
│ ├── zenerref.txt
│ └── zenerreffollow.txt
└── setuplist.txt
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
src/*.class
================================================
FILE: README.md
================================================
circuit-simulator
=================
This is a version of Paul Falstad's circuit simulator (original available at <http://www.falstad.com/circuit/>) with the following improvements:
* fixed import/export when running as an applet
* it is now possible to save/load to/from a file when running as an application
* the circuits that appear in the "Circuit" menu may now be bundled with the jar file.
* many interface improvements: double click to edit, Delete key to delete a component, cursor changes to crosshairs when in place mode, Esc goes back to move/interact mode, ...
* separated keyboard shortcuts from dump types (this makes it easier to configure shortcuts without changing the file format)
* WireElm is now a subclass of ResistorElm (without this change, whenever you use two switches in parallel, you get the error "voltage source/wire loop with no resistance")
* some cosmetic improvements (like starting with a white background as default)
compiling and building
----------------------
If you have make installed, just `cd` to the *src* directory and run `make`, followed by a `make jar`
If not, compile with `javac *.java` and build the jar file with `jar cfm circuit.jar Manifest.txt *.class *.txt circuits/`
running
-------
As an application: `java -jar circuit.jar`
If you want to use the circuit simulator as an applet, create an html file and load the applet with:
<applet code=Circuit.class archive=circuit.jar width=600 height=50>
Sorry, you need a Java-enabled browser to see the simulation.
<param name=pause value=20>
</applet>
If you want to enable import/export of circuit files, you must define two javascript helper functions in the same page:
* `exportCircuit(dump)`, whose first parameter is a string describing the circuit in the same format used for the circuit file.
* `importCircuit()`, which must return a string describing the circuit in the same format used for the circuit file.
The definition of those functions is up to you (for instance, you may copy the string to/from a textarea).
terms and conditions
--------------------
The terms and conditions for the original code still apply. Check <http://www.falstad.com/licensing.html> before redistributing or modifying the code. You must always consult the original licensing information but, in case the link is unavailable, here is a copy of the original license (as of 2013-05-08):
You have permission to use these applets in a classroom setting or take
screenshots as long as the applets are unmodified. Modification or
redistribution for non-commercial purposes is allowed, as long as you
credit me (Paul Falstad) and provide a link to my page (the page you
found the applet(s) on, or http://www.falstad.com/mathphysics.html).
Contact me for any other uses. The source code for each applet is
generally available on that applet's web page, but some of the applets
use third-party source code that has restrictions.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Rodrigo Hausen's changes are in the public domain (but it would be nice if you credited me alongside Paul if you use this version).
================================================
FILE: src/ACRailElm.java
================================================
class ACRailElm extends RailElm {
public ACRailElm(int xx, int yy) { super(xx, yy, WF_AC); }
Class getDumpClass() { return RailElm.class; }
int getShortcut() { return 0; }
}
================================================
FILE: src/ACVoltageElm.java
================================================
class ACVoltageElm extends VoltageElm {
public ACVoltageElm(int xx, int yy) { super(xx, yy, WF_AC); }
Class getDumpClass() { return VoltageElm.class; }
}
================================================
FILE: src/ADCElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class ADCElm extends ChipElm {
public ADCElm(int xx, int yy) { super(xx, yy); }
public ADCElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
}
String getChipName() { return "ADC"; }
boolean needsBits() { return true; }
void setupPins() {
sizeX = 2;
sizeY = bits > 2 ? bits : 2;
pins = new Pin[getPostCount()];
int i;
for (i = 0; i != bits; i++) {
pins[i] = new Pin(bits-1-i, SIDE_E, "D" + i);
pins[i].output = true;
}
pins[bits] = new Pin(0, SIDE_W, "In");
pins[bits+1] = new Pin(sizeY-1, SIDE_W, "V+");
allocNodes();
}
void execute() {
int imax = (1<<bits)-1;
// if we round, the half-flash doesn't work
double val = imax*volts[bits]/volts[bits+1]; // + .5;
int ival = (int) val;
ival = min(imax, max(0, ival));
int i;
for (i = 0; i != bits; i++)
pins[i].value = ((ival & (1<<i)) != 0);
}
int getVoltageSourceCount() { return bits; }
int getPostCount() { return bits+2; }
int getDumpType() { return 167; }
}
================================================
FILE: src/AnalogSwitch2Elm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class AnalogSwitch2Elm extends AnalogSwitchElm {
public AnalogSwitch2Elm(int xx, int yy) {
super(xx, yy);
}
public AnalogSwitch2Elm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
}
final int openhs = 16;
Point swposts[], swpoles[], ctlPoint;
void setPoints() {
super.setPoints();
calcLeads(32);
swposts = newPointArray(2);
swpoles = newPointArray(2);
interpPoint2(lead1, lead2, swpoles[0], swpoles[1], 1, openhs);
interpPoint2(point1, point2, swposts[0], swposts[1], 1, openhs);
ctlPoint = interpPoint(point1, point2, .5, openhs);
}
int getPostCount() { return 4; }
void draw(Graphics g) {
setBbox(point1, point2, openhs);
// draw first lead
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, lead1);
// draw second lead
setVoltageColor(g, volts[1]);
drawThickLine(g, swpoles[0], swposts[0]);
// draw third lead
setVoltageColor(g, volts[2]);
drawThickLine(g, swpoles[1], swposts[1]);
// draw switch
g.setColor(lightGrayColor);
int position = (open) ? 1 : 0;
drawThickLine(g, lead1, swpoles[position]);
updateDotCount();
drawDots(g, point1, lead1, curcount);
drawDots(g, swpoles[position], swposts[position], curcount);
drawPosts(g);
}
Point getPost(int n) {
return (n == 0) ? point1 : (n == 3) ? ctlPoint : swposts[n-1];
}
int getDumpType() { return 160; }
void calculateCurrent() {
if (open)
current = (volts[0]-volts[2])/r_on;
else
current = (volts[0]-volts[1])/r_on;
}
void stamp() {
sim.stampNonLinear(nodes[0]);
sim.stampNonLinear(nodes[1]);
sim.stampNonLinear(nodes[2]);
}
void doStep() {
open = (volts[3] < 2.5);
if ((flags & FLAG_INVERT) != 0)
open = !open;
if (open) {
sim.stampResistor(nodes[0], nodes[2], r_on);
sim.stampResistor(nodes[0], nodes[1], r_off);
} else {
sim.stampResistor(nodes[0], nodes[1], r_on);
sim.stampResistor(nodes[0], nodes[2], r_off);
}
}
boolean getConnection(int n1, int n2) {
if (n1 == 3 || n2 == 3)
return false;
return true;
}
void getInfo(String arr[]) {
arr[0] = "analog switch (SPDT)";
arr[1] = "I = " + getCurrentDText(getCurrent());
}
}
================================================
FILE: src/AnalogSwitchElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class AnalogSwitchElm extends CircuitElm {
final int FLAG_INVERT = 1;
double resistance, r_on, r_off;
public AnalogSwitchElm(int xx, int yy) {
super(xx, yy);
r_on = 20;
r_off = 1e10;
}
public AnalogSwitchElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
r_on = 20;
r_off = 1e10;
try {
r_on = new Double(st.nextToken()).doubleValue();
r_off = new Double(st.nextToken()).doubleValue();
} catch (Exception e) { }
}
String dump() {
return super.dump() + " " + r_on + " " + r_off;
}
int getDumpType() { return 159; }
boolean open;
Point ps, point3, lead3;
void setPoints() {
super.setPoints();
calcLeads(32);
ps = new Point();
int openhs = 16;
point3 = interpPoint(point1, point2, .5, -openhs);
lead3 = interpPoint(point1, point2, .5, -openhs/2);
}
void draw(Graphics g) {
int openhs = 16;
int hs = (open) ? openhs : 0;
setBbox(point1, point2, openhs);
draw2Leads(g);
g.setColor(lightGrayColor);
interpPoint(lead1, lead2, ps, 1, hs);
drawThickLine(g, lead1, ps);
setVoltageColor(g, volts[2]);
drawThickLine(g, point3, lead3);
if (!open)
doDots(g);
drawPosts(g);
}
void calculateCurrent() {
current = (volts[0]-volts[1])/resistance;
}
// we need this to be able to change the matrix for each step
boolean nonLinear() { return true; }
void stamp() {
sim.stampNonLinear(nodes[0]);
sim.stampNonLinear(nodes[1]);
}
void doStep() {
open = (volts[2] < 2.5);
if ((flags & FLAG_INVERT) != 0)
open = !open;
resistance = (open) ? r_off : r_on;
sim.stampResistor(nodes[0], nodes[1], resistance);
}
void drag(int xx, int yy) {
xx = sim.snapGrid(xx);
yy = sim.snapGrid(yy);
if (abs(x-xx) < abs(y-yy))
xx = x;
else
yy = y;
int q1 = abs(x-xx)+abs(y-yy);
int q2 = (q1/2) % sim.gridSize;
if (q2 != 0)
return;
x2 = xx; y2 = yy;
setPoints();
}
int getPostCount() { return 3; }
Point getPost(int n) {
return (n == 0) ? point1 : (n == 1) ? point2 : point3;
}
void getInfo(String arr[]) {
arr[0] = "analog switch";
arr[1] = open ? "open" : "closed";
arr[2] = "Vd = " + getVoltageDText(getVoltageDiff());
arr[3] = "I = " + getCurrentDText(getCurrent());
arr[4] = "Vc = " + getVoltageText(volts[2]);
}
// we have to just assume current will flow either way, even though that
// might cause singular matrix errors
boolean getConnection(int n1, int n2) {
if (n1 == 2 || n2 == 2)
return false;
return true;
}
public EditInfo getEditInfo(int n) {
if (n == 0) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Normally closed",
(flags & FLAG_INVERT) != 0);
return ei;
}
if (n == 1)
return new EditInfo("On Resistance (ohms)", r_on, 0, 0);
if (n == 2)
return new EditInfo("Off Resistance (ohms)", r_off, 0, 0);
return null;
}
public void setEditValue(int n, EditInfo ei) {
if (n == 0)
flags = (ei.checkbox.getState()) ?
(flags | FLAG_INVERT) :
(flags & ~FLAG_INVERT);
if (n == 1 && ei.value > 0)
r_on = ei.value;
if (n == 2 && ei.value > 0)
r_off = ei.value;
}
}
================================================
FILE: src/AndGateElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class AndGateElm extends GateElm {
public AndGateElm(int xx, int yy) { super(xx, yy); }
public AndGateElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
}
void setPoints() {
super.setPoints();
// 0=topleft, 1-10 = top curve, 11 = right, 12-21=bottom curve,
// 22 = bottom left
Point triPoints[] = newPointArray(23);
interpPoint2(lead1, lead2, triPoints[0], triPoints[22], 0, hs2);
int i;
for (i = 0; i != 10; i++) {
double a = i*.1;
double b = Math.sqrt(1-a*a);
interpPoint2(lead1, lead2,
triPoints[i+1], triPoints[21-i],
.5+a/2, b*hs2);
}
triPoints[11] = new Point(lead2);
if (isInverting()) {
pcircle = interpPoint(point1, point2, .5+(ww+4)/dn);
lead2 = interpPoint(point1, point2, .5+(ww+8)/dn);
}
gatePoly = createPolygon(triPoints);
}
String getGateName() { return "AND gate"; }
boolean calcFunction() {
int i;
boolean f = true;
for (i = 0; i != inputCount; i++)
f &= getInput(i);
return f;
}
int getDumpType() { return 150; }
int getShortcut() { return '2'; }
}
================================================
FILE: src/AntennaElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class AntennaElm extends RailElm {
public AntennaElm(int xx, int yy) { super(xx, yy, WF_DC); }
public AntennaElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
waveform = WF_DC;
}
double fmphase;
void stamp() {
sim.stampVoltageSource(0, nodes[0], voltSource);
}
void doStep() {
sim.updateVoltageSource(0, nodes[0], voltSource, getVoltage());
}
double getVoltage() {
fmphase += 2*pi*(2200+Math.sin(2*pi*sim.t*13)*100)*sim.timeStep;
double fm = 3*Math.sin(fmphase);
return Math.sin(2*pi*sim.t*3000)*(1.3+Math.sin(2*pi*sim.t*12))*3 +
Math.sin(2*pi*sim.t*2710)*(1.3+Math.sin(2*pi*sim.t*13))*3 +
Math.sin(2*pi*sim.t*2433)*(1.3+Math.sin(2*pi*sim.t*14))*3 + fm;
}
int getDumpType() { return 'A'; }
int getShortcut() { return 0; }
}
================================================
FILE: src/BoxElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
import java.util.Vector;
class BoxElm extends GraphicElm {
public BoxElm(int xx, int yy) {
super(xx, yy);
x2 = xx + 16;
y2 = yy + 16;
setBbox(x, y, x2, y2);
}
public BoxElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
x2 = xb;
y2 = yb;
/* if ( st.hasMoreTokens() )
x = new Integer(st.nextToken()).intValue();
if ( st.hasMoreTokens() )
y = new Integer(st.nextToken()).intValue();
if ( st.hasMoreTokens() )
x2 = new Integer(st.nextToken()).intValue();
if ( st.hasMoreTokens() )
y2 = new Integer(st.nextToken()).intValue();*/
setBbox(x, y, x2, y2);
}
String dump() {
return super.dump();
}
int getDumpType() { return 'b'; }
void drag(int xx, int yy) {
x = xx;
y = yy;
}
void draw(Graphics g) {
//g.setColor(needsHighlight() ? selectColor : lightGrayColor);
g.setColor(needsHighlight() ? selectColor : Color.GRAY);
setBbox(x, y, x2, y2);
if ( x < x2 && y < y2 )
g.fillRect(x,y, x2-x, y2-y);
else if ( x > x2 && y < y2 )
g.fillRect(x2,y, x-x2, y2-y);
else if ( x < x2 && y > y2 )
g.fillRect(x, y2, x2-x, y-y2);
else
g.fillRect(x2, y2, x-x2, y-y2);
}
public EditInfo getEditInfo(int n) {
return null;
}
public void setEditValue(int n, EditInfo ei) {
}
void getInfo(String arr[]) {
}
@Override
int getShortcut() { return 0; }
}
================================================
FILE: src/CC2Elm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class CC2Elm extends ChipElm {
double gain;
public CC2Elm(int xx, int yy) { super(xx, yy); gain = 1; }
public CC2Elm(int xx, int yy, int g) { super(xx, yy); gain = g; }
public CC2Elm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
gain = new Double(st.nextToken()).doubleValue();
}
String dump() {
return super.dump() + " " + gain;
}
String getChipName() { return "CC2"; }
void setupPins() {
sizeX = 2;
sizeY = 3;
pins = new Pin[3];
pins[0] = new Pin(0, SIDE_W, "X");
pins[0].output = true;
pins[1] = new Pin(2, SIDE_W, "Y");
pins[2] = new Pin(1, SIDE_E, "Z");
}
void getInfo(String arr[]) {
arr[0] = (gain == 1) ? "CCII+" : "CCII-";
arr[1] = "X,Y = " + getVoltageText(volts[0]);
arr[2] = "Z = " + getVoltageText(volts[2]);
arr[3] = "I = " + getCurrentText(pins[0].current);
}
//boolean nonLinear() { return true; }
void stamp() {
// X voltage = Y voltage
sim.stampVoltageSource(0, nodes[0], pins[0].voltSource);
sim.stampVCVS(0, nodes[1], 1, pins[0].voltSource);
// Z current = gain * X current
sim.stampCCCS(0, nodes[2], pins[0].voltSource, gain);
}
void draw(Graphics g) {
pins[2].current = pins[0].current * gain;
drawChip(g);
}
int getPostCount() { return 3; }
int getVoltageSourceCount() { return 1; }
int getDumpType() { return 179; }
}
class CC2NegElm extends CC2Elm {
public CC2NegElm(int xx, int yy) { super(xx, yy, -1); }
Class getDumpClass() { return CC2Elm.class; }
}
================================================
FILE: src/CapacitorElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class CapacitorElm extends CircuitElm {
double capacitance;
double compResistance, voltdiff;
Point plate1[], plate2[];
public static final int FLAG_BACK_EULER = 2;
public CapacitorElm(int xx, int yy) {
super(xx, yy);
capacitance = 1e-5;
}
public CapacitorElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
capacitance = new Double(st.nextToken()).doubleValue();
voltdiff = new Double(st.nextToken()).doubleValue();
}
boolean isTrapezoidal() { return (flags & FLAG_BACK_EULER) == 0; }
void setNodeVoltage(int n, double c) {
super.setNodeVoltage(n, c);
voltdiff = volts[0]-volts[1];
}
void reset() {
current = curcount = 0;
// put small charge on caps when reset to start oscillators
voltdiff = 1e-3;
}
int getDumpType() { return 'c'; }
String dump() {
return super.dump() + " " + capacitance + " " + voltdiff;
}
void setPoints() {
super.setPoints();
double f = (dn/2-4)/dn;
// calc leads
lead1 = interpPoint(point1, point2, f);
lead2 = interpPoint(point1, point2, 1-f);
// calc plates
plate1 = newPointArray(2);
plate2 = newPointArray(2);
interpPoint2(point1, point2, plate1[0], plate1[1], f, 12);
interpPoint2(point1, point2, plate2[0], plate2[1], 1-f, 12);
}
void draw(Graphics g) {
int hs = 12;
setBbox(point1, point2, hs);
// draw first lead and plate
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, lead1);
setPowerColor(g, false);
drawThickLine(g, plate1[0], plate1[1]);
if (sim.powerCheckItem.getState())
g.setColor(Color.gray);
// draw second lead and plate
setVoltageColor(g, volts[1]);
drawThickLine(g, point2, lead2);
setPowerColor(g, false);
drawThickLine(g, plate2[0], plate2[1]);
updateDotCount();
if (sim.dragElm != this) {
drawDots(g, point1, lead1, curcount);
drawDots(g, point2, lead2, -curcount);
}
drawPosts(g);
if (sim.showValuesCheckItem.getState()) {
String s = getShortUnitText(capacitance, "F");
drawValues(g, s, hs);
}
}
void stamp() {
// capacitor companion model using trapezoidal approximation
// (Norton equivalent) consists of a current source in
// parallel with a resistor. Trapezoidal is more accurate
// than backward euler but can cause oscillatory behavior
// if RC is small relative to the timestep.
if (isTrapezoidal())
compResistance = sim.timeStep/(2*capacitance);
else
compResistance = sim.timeStep/capacitance;
sim.stampResistor(nodes[0], nodes[1], compResistance);
sim.stampRightSide(nodes[0]);
sim.stampRightSide(nodes[1]);
}
void startIteration() {
if (isTrapezoidal())
curSourceValue = -voltdiff/compResistance-current;
else
curSourceValue = -voltdiff/compResistance;
//System.out.println("cap " + compResistance + " " + curSourceValue + " " + current + " " + voltdiff);
}
void calculateCurrent() {
double voltdiff = volts[0] - volts[1];
// we check compResistance because this might get called
// before stamp(), which sets compResistance, causing
// infinite current
if (compResistance > 0)
current = voltdiff/compResistance + curSourceValue;
}
double curSourceValue;
void doStep() {
sim.stampCurrentSource(nodes[0], nodes[1], curSourceValue);
}
void getInfo(String arr[]) {
arr[0] = "capacitor";
getBasicInfo(arr);
arr[3] = "C = " + getUnitText(capacitance, "F");
arr[4] = "P = " + getUnitText(getPower(), "W");
//double v = getVoltageDiff();
//arr[4] = "U = " + getUnitText(.5*capacitance*v*v, "J");
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Capacitance (F)", capacitance, 0, 0);
if (n == 1) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Trapezoidal Approximation", isTrapezoidal());
return ei;
}
return null;
}
public void setEditValue(int n, EditInfo ei) {
if (n == 0 && ei.value > 0)
capacitance = ei.value;
if (n == 1) {
if (ei.checkbox.getState())
flags &= ~FLAG_BACK_EULER;
else
flags |= FLAG_BACK_EULER;
}
}
int getShortcut() { return 'c'; }
}
================================================
FILE: src/ChipElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
abstract class ChipElm extends CircuitElm {
int csize, cspc, cspc2;
int bits;
final int FLAG_SMALL = 1;
final int FLAG_FLIP_X = 1024;
final int FLAG_FLIP_Y = 2048;
public ChipElm(int xx, int yy) {
super(xx, yy);
if (needsBits())
bits = (this instanceof DecadeElm) ? 10 : 4;
noDiagonal = true;
setupPins();
setSize(sim.smallGridCheckItem.getState() ? 1 : 2);
}
public ChipElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
if (needsBits())
bits = new Integer(st.nextToken()).intValue();
noDiagonal = true;
setupPins();
setSize((f & FLAG_SMALL) != 0 ? 1 : 2);
int i;
for (i = 0; i != getPostCount(); i++) {
if (pins[i].state) {
volts[i] = new Double(st.nextToken()).doubleValue();
pins[i].value = volts[i] > 2.5;
}
}
}
boolean needsBits() { return false; }
void setSize(int s) {
csize = s;
cspc = 8*s;
cspc2 = cspc*2;
flags &= ~FLAG_SMALL;
flags |= (s == 1) ? FLAG_SMALL : 0;
}
abstract void setupPins();
void draw(Graphics g) {
drawChip(g);
}
void drawChip(Graphics g) {
int i;
Font f = new Font("SansSerif", 0, 10*csize);
g.setFont(f);
FontMetrics fm = g.getFontMetrics();
for (i = 0; i != getPostCount(); i++) {
Pin p = pins[i];
setVoltageColor(g, volts[i]);
Point a = p.post;
Point b = p.stub;
drawThickLine(g, a, b);
p.curcount = updateDotCount(p.current, p.curcount);
drawDots(g, b, a, p.curcount);
if (p.bubble) {
g.setColor(sim.printableCheckItem.getState() ?
Color.white : Color.black);
drawThickCircle(g, p.bubbleX, p.bubbleY, 1);
g.setColor(lightGrayColor);
drawThickCircle(g, p.bubbleX, p.bubbleY, 3);
}
g.setColor(whiteColor);
int sw = fm.stringWidth(p.text);
g.drawString(p.text, p.textloc.x-sw/2,
p.textloc.y+fm.getAscent()/2);
if (p.lineOver) {
int ya = p.textloc.y-fm.getAscent()/2;
g.drawLine(p.textloc.x-sw/2, ya, p.textloc.x+sw/2, ya);
}
}
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
drawThickPolygon(g, rectPointsX, rectPointsY, 4);
if (clockPointsX != null)
g.drawPolyline(clockPointsX, clockPointsY, 3);
for (i = 0; i != getPostCount(); i++)
drawPost(g, pins[i].post.x, pins[i].post.y, nodes[i]);
}
int rectPointsX[], rectPointsY[];
int clockPointsX[], clockPointsY[];
Pin pins[];
int sizeX, sizeY;
boolean lastClock;
void drag(int xx, int yy) {
yy = sim.snapGrid(yy);
if (xx < x) {
xx = x; yy = y;
} else {
y = y2 = yy;
x2 = sim.snapGrid(xx);
}
setPoints();
}
void setPoints() {
if (x2-x > sizeX*cspc2 && this == sim.dragElm)
setSize(2);
int hs = cspc;
int x0 = x+cspc2; int y0 = y;
int xr = x0-cspc;
int yr = y0-cspc;
int xs = sizeX*cspc2;
int ys = sizeY*cspc2;
rectPointsX = new int[] { xr, xr+xs, xr+xs, xr };
rectPointsY = new int[] { yr, yr, yr+ys, yr+ys };
setBbox(xr, yr, rectPointsX[2], rectPointsY[2]);
int i;
for (i = 0; i != getPostCount(); i++) {
Pin p = pins[i];
switch (p.side) {
case SIDE_N: p.setPoint(x0, y0, 1, 0, 0, -1, 0, 0); break;
case SIDE_S: p.setPoint(x0, y0, 1, 0, 0, 1, 0, ys-cspc2);break;
case SIDE_W: p.setPoint(x0, y0, 0, 1, -1, 0, 0, 0); break;
case SIDE_E: p.setPoint(x0, y0, 0, 1, 1, 0, xs-cspc2, 0);break;
}
}
}
Point getPost(int n) {
return pins[n].post;
}
abstract int getVoltageSourceCount(); // output count
void setVoltageSource(int j, int vs) {
int i;
for (i = 0; i != getPostCount(); i++) {
Pin p = pins[i];
if (p.output && j-- == 0) {
p.voltSource = vs;
return;
}
}
System.out.println("setVoltageSource failed for " + this);
}
void stamp() {
int i;
for (i = 0; i != getPostCount(); i++) {
Pin p = pins[i];
if (p.output)
sim.stampVoltageSource(0, nodes[i], p.voltSource);
}
}
void execute() {}
void doStep() {
int i;
for (i = 0; i != getPostCount(); i++) {
Pin p = pins[i];
if (!p.output)
p.value = volts[i] > 2.5;
}
execute();
for (i = 0; i != getPostCount(); i++) {
Pin p = pins[i];
if (p.output)
sim.updateVoltageSource(0, nodes[i], p.voltSource,
p.value ? 5 : 0);
}
}
void reset() {
int i;
for (i = 0; i != getPostCount(); i++) {
pins[i].value = false;
pins[i].curcount = 0;
volts[i] = 0;
}
lastClock = false;
}
String dump() {
int t = getDumpType();
String s = super.dump();
if (needsBits())
s += " " + bits;
int i;
for (i = 0; i != getPostCount(); i++) {
if (pins[i].state)
s += " " + volts[i];
}
return s;
}
void getInfo(String arr[]) {
arr[0] = getChipName();
int i, a = 1;
for (i = 0; i != getPostCount(); i++) {
Pin p = pins[i];
if (arr[a] != null)
arr[a] += "; ";
else
arr[a] = "";
String t = p.text;
if (p.lineOver)
t += '\'';
if (p.clock)
t = "Clk";
arr[a] += t + " = " + getVoltageText(volts[i]);
if (i % 2 == 1)
a++;
}
}
void setCurrent(int x, double c) {
int i;
for (i = 0; i != getPostCount(); i++)
if (pins[i].output && pins[i].voltSource == x)
pins[i].current = c;
}
String getChipName() { return "chip"; }
boolean getConnection(int n1, int n2) { return false; }
boolean hasGroundConnection(int n1) {
return pins[n1].output;
}
public EditInfo getEditInfo(int n) {
if (n == 0) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Flip X", (flags & FLAG_FLIP_X) != 0);
return ei;
}
if (n == 1) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Flip Y", (flags & FLAG_FLIP_Y) != 0);
return ei;
}
return null;
}
public void setEditValue(int n, EditInfo ei) {
if (n == 0) {
if (ei.checkbox.getState())
flags |= FLAG_FLIP_X;
else
flags &= ~FLAG_FLIP_X;
setPoints();
}
if (n == 1) {
if (ei.checkbox.getState())
flags |= FLAG_FLIP_Y;
else
flags &= ~FLAG_FLIP_Y;
setPoints();
}
}
final int SIDE_N = 0;
final int SIDE_S = 1;
final int SIDE_W = 2;
final int SIDE_E = 3;
class Pin {
Pin(int p, int s, String t) {
pos = p; side = s; text = t;
}
Point post, stub;
Point textloc;
int pos, side, voltSource, bubbleX, bubbleY;
String text;
boolean lineOver, bubble, clock, output, value, state;
double curcount, current;
void setPoint(int px, int py, int dx, int dy, int dax, int day,
int sx, int sy) {
if ((flags & FLAG_FLIP_X) != 0) {
dx = -dx;
dax = -dax;
px += cspc2*(sizeX-1);
sx = -sx;
}
if ((flags & FLAG_FLIP_Y) != 0) {
dy = -dy;
day = -day;
py += cspc2*(sizeY-1);
sy = -sy;
}
int xa = px+cspc2*dx*pos+sx;
int ya = py+cspc2*dy*pos+sy;
post = new Point(xa+dax*cspc2, ya+day*cspc2);
stub = new Point(xa+dax*cspc , ya+day*cspc );
textloc = new Point(xa , ya );
if (bubble) {
bubbleX = xa+dax*10*csize;
bubbleY = ya+day*10*csize;
}
if (clock) {
clockPointsX = new int[3];
clockPointsY = new int[3];
clockPointsX[0] = xa+dax*cspc-dx*cspc/2;
clockPointsY[0] = ya+day*cspc-dy*cspc/2;
clockPointsX[1] = xa;
clockPointsY[1] = ya;
clockPointsX[2] = xa+dax*cspc+dx*cspc/2;
clockPointsY[2] = ya+day*cspc+dy*cspc/2;
}
}
}
}
================================================
FILE: src/CirSim.java
================================================
// CirSim.java (c) 2010 by Paul Falstad
// For information about the theory behind this, see Electronic Circuit & System Simulation Methods by Pillage
import java.io.InputStream;
import java.awt.*;
import java.awt.image.*;
import java.applet.Applet;
import java.util.Vector;
import java.io.File;
import java.util.Random;
import java.util.Arrays;
import java.lang.Math;
import java.net.URL;
import java.awt.event.*;
import java.io.FilterInputStream;
import java.io.ByteArrayOutputStream;
import java.util.StringTokenizer;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class CirSim extends Frame
implements ComponentListener, ActionListener, AdjustmentListener,
MouseMotionListener, MouseListener, ItemListener, KeyListener {
Thread engine = null;
Dimension winSize;
Image dbimage;
Random random;
public static final int sourceRadius = 7;
public static final double freqMult = 3.14159265*2*4;
public String getAppletInfo() {
return "Circuit by Paul Falstad";
}
static Container main;
Label titleLabel;
Button resetButton;
Button dumpMatrixButton;
MenuItem exportItem, exportLinkItem, importItem, exitItem, undoItem, redoItem,
cutItem, copyItem, pasteItem, selectAllItem, optionsItem;
Menu optionsMenu;
Checkbox stoppedCheck;
CheckboxMenuItem dotsCheckItem;
CheckboxMenuItem voltsCheckItem;
CheckboxMenuItem powerCheckItem;
CheckboxMenuItem smallGridCheckItem;
CheckboxMenuItem showValuesCheckItem;
CheckboxMenuItem conductanceCheckItem;
CheckboxMenuItem euroResistorCheckItem;
CheckboxMenuItem printableCheckItem;
CheckboxMenuItem conventionCheckItem;
CheckboxMenuItem idealWireCheckItem;
Scrollbar speedBar;
Scrollbar currentBar;
Label powerLabel;
Scrollbar powerBar;
PopupMenu elmMenu;
MenuItem elmEditMenuItem;
MenuItem elmCutMenuItem;
MenuItem elmCopyMenuItem;
MenuItem elmDeleteMenuItem;
MenuItem elmScopeMenuItem;
PopupMenu scopeMenu;
PopupMenu transScopeMenu;
PopupMenu mainMenu;
CheckboxMenuItem scopeVMenuItem;
CheckboxMenuItem scopeIMenuItem;
CheckboxMenuItem scopeMaxMenuItem;
CheckboxMenuItem scopeMinMenuItem;
CheckboxMenuItem scopeFreqMenuItem;
CheckboxMenuItem scopePowerMenuItem;
CheckboxMenuItem scopeIbMenuItem;
CheckboxMenuItem scopeIcMenuItem;
CheckboxMenuItem scopeIeMenuItem;
CheckboxMenuItem scopeVbeMenuItem;
CheckboxMenuItem scopeVbcMenuItem;
CheckboxMenuItem scopeVceMenuItem;
CheckboxMenuItem scopeVIMenuItem;
CheckboxMenuItem scopeXYMenuItem;
CheckboxMenuItem scopeResistMenuItem;
CheckboxMenuItem scopeVceIcMenuItem;
MenuItem scopeSelectYMenuItem;
Class addingClass;
int mouseMode = MODE_SELECT;
int tempMouseMode = MODE_SELECT;
String mouseModeStr = "Select";
static final double pi = 3.14159265358979323846;
static final int MODE_ADD_ELM = 0;
static final int MODE_DRAG_ALL = 1;
static final int MODE_DRAG_ROW = 2;
static final int MODE_DRAG_COLUMN = 3;
static final int MODE_DRAG_SELECTED = 4;
static final int MODE_DRAG_POST = 5;
static final int MODE_SELECT = 6;
static final int infoWidth = 120;
int dragX, dragY, initDragX, initDragY;
int selectedSource;
Rectangle selectedArea;
int gridSize, gridMask, gridRound;
boolean dragging;
boolean analyzeFlag;
boolean dumpMatrix;
boolean useBufferedImage;
boolean isMac;
String ctrlMetaKey;
double t;
int pause = 10;
int scopeSelected = -1;
int menuScope = -1;
int hintType = -1, hintItem1, hintItem2;
String stopMessage;
double timeStep;
static final int HINT_LC = 1;
static final int HINT_RC = 2;
static final int HINT_3DB_C = 3;
static final int HINT_TWINT = 4;
static final int HINT_3DB_L = 5;
Vector<CircuitElm> elmList;
// Vector setupList;
CircuitElm dragElm, menuElm, mouseElm, stopElm;
boolean didSwitch = false;
int mousePost = -1;
CircuitElm plotXElm, plotYElm;
int draggingPost;
SwitchElm heldSwitchElm;
double circuitMatrix[][], circuitRightSide[],
origRightSide[], origMatrix[][];
RowInfo circuitRowInfo[];
int circuitPermute[];
boolean circuitNonLinear;
int voltageSourceCount;
int circuitMatrixSize, circuitMatrixFullSize;
boolean circuitNeedsMap;
public boolean useFrame;
int scopeCount;
Scope scopes[];
int scopeColCount[];
static EditDialog editDialog;
static ImportExportDialog impDialog, expDialog;
Class dumpTypes[], shortcuts[];
static String muString = "u";
static String ohmString = "ohm";
String clipboard;
Rectangle circuitArea;
int circuitBottom;
Vector<String> undoStack, redoStack;
int getrand(int x) {
int q = random.nextInt();
if (q < 0) q = -q;
return q % x;
}
CircuitCanvas cv;
Circuit applet;
CirSim(Circuit a) {
super("Circuit Simulator v1.6.1a");
applet = a;
useFrame = false;
}
String startCircuit = null;
String startLabel = null;
String startCircuitText = null;
String baseURL = "http://www.falstad.com/circuit/";
public void init() {
String euroResistor = null;
String useFrameStr = null;
boolean printable = true; // hausen: changed from false to true
boolean convention = true;
CircuitElm.initClass(this);
try {
baseURL = applet.getDocumentBase().getFile();
// look for circuit embedded in URL
String doc = applet.getDocumentBase().toString();
int in = doc.indexOf('#');
if (in > 0) {
String x = null;
try {
x = doc.substring(in+1);
x = URLDecoder.decode(x);
startCircuitText = x;
} catch (Exception e) {
System.out.println("can't decode " + x);
e.printStackTrace();
}
}
in = doc.lastIndexOf('/');
if (in > 0)
baseURL = doc.substring(0, in+1);
String param = applet.getParameter("PAUSE");
if (param != null)
pause = Integer.parseInt(param);
startCircuit = applet.getParameter("startCircuit");
startLabel = applet.getParameter("startLabel");
euroResistor = applet.getParameter("euroResistors");
useFrameStr = applet.getParameter("useFrame");
String x = applet.getParameter("whiteBackground");
if (x != null && x.equalsIgnoreCase("true"))
printable = true;
x = applet.getParameter("conventionalCurrent");
if (x != null && x.equalsIgnoreCase("true"))
convention = false;
} catch (Exception e) { }
boolean euro = (euroResistor != null && euroResistor.equalsIgnoreCase("true"));
useFrame = (useFrameStr == null || !useFrameStr.equalsIgnoreCase("false"));
if (useFrame)
main = this;
else
main = applet;
String os = System.getProperty("os.name");
isMac = (os.indexOf("Mac ") == 0);
ctrlMetaKey = (isMac) ? "\u2318" : "Ctrl";
String jv = System.getProperty("java.class.version");
double jvf = new Double(jv).doubleValue();
if (jvf >= 48) {
muString = "\u03bc";
ohmString = "\u03a9";
useBufferedImage = true;
}
dumpTypes = new Class[300];
shortcuts = new Class[127];
// these characters are reserved
dumpTypes[(int)'o'] = Scope.class;
dumpTypes[(int)'h'] = Scope.class;
dumpTypes[(int)'$'] = Scope.class;
dumpTypes[(int)'%'] = Scope.class;
dumpTypes[(int)'?'] = Scope.class;
dumpTypes[(int)'B'] = Scope.class;
main.setLayout(new CircuitLayout());
cv = new CircuitCanvas(this);
cv.addComponentListener(this);
cv.addMouseMotionListener(this);
cv.addMouseListener(this);
cv.addKeyListener(this);
main.add(cv);
mainMenu = new PopupMenu();
MenuBar mb = null;
if (useFrame)
mb = new MenuBar();
Menu m = new Menu("File");
if (useFrame)
mb.add(m);
else
mainMenu.add(m);
m.add(importItem = getMenuItem("Import"));
m.add(exportItem = getMenuItem("Export"));
// m.add(exportLinkItem = getMenuItem("Export Link"));
m.addSeparator();
m.add(exitItem = getMenuItem("Exit"));
m = new Menu("Edit");
m.add(undoItem = getMenuItem("Undo"));
undoItem.setShortcut(new MenuShortcut(KeyEvent.VK_Z));
m.add(redoItem = getMenuItem("Redo"));
redoItem.setShortcut(new MenuShortcut(KeyEvent.VK_Z, true));
m.addSeparator();
m.add(cutItem = getMenuItem("Cut"));
cutItem.setShortcut(new MenuShortcut(KeyEvent.VK_X));
m.add(copyItem = getMenuItem("Copy"));
copyItem.setShortcut(new MenuShortcut(KeyEvent.VK_C));
m.add(pasteItem = getMenuItem("Paste"));
pasteItem.setShortcut(new MenuShortcut(KeyEvent.VK_V));
pasteItem.setEnabled(false);
m.add(selectAllItem = getMenuItem("Select All"));
selectAllItem.setShortcut(new MenuShortcut(KeyEvent.VK_A));
if (useFrame)
mb.add(m);
else
mainMenu.add(m);
m = new Menu("Scope");
if (useFrame)
mb.add(m);
else
mainMenu.add(m);
m.add(getMenuItem("Stack All", "stackAll"));
m.add(getMenuItem("Unstack All", "unstackAll"));
optionsMenu = m = new Menu("Options");
if (useFrame)
mb.add(m);
else
mainMenu.add(m);
m.add(dotsCheckItem = getCheckItem("Show Current"));
dotsCheckItem.setState(false); // hausen: changed from true to false
m.add(voltsCheckItem = getCheckItem("Show Voltage"));
voltsCheckItem.setState(true);
m.add(powerCheckItem = getCheckItem("Show Power"));
m.add(showValuesCheckItem = getCheckItem("Show Values"));
showValuesCheckItem.setState(true);
//m.add(conductanceCheckItem = getCheckItem("Show Conductance"));
m.add(smallGridCheckItem = getCheckItem("Small Grid"));
m.add(euroResistorCheckItem = getCheckItem("European Resistors"));
euroResistorCheckItem.setState(euro);
m.add(printableCheckItem = getCheckItem("White Background"));
printableCheckItem.setState(printable);
m.add(conventionCheckItem = getCheckItem("Conventional Current Motion"));
conventionCheckItem.setState(convention);
m.add(idealWireCheckItem = getCheckItem("Ideal Wires"));
idealWireCheckItem.setState(WireElm.ideal);
idealWireCheckItem.addItemListener(
new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
WireElm.ideal = true;
} else {
WireElm.ideal = false;
}
System.err.println("ideal wires: " + WireElm.ideal);
}
}
);
m.add(optionsItem = getMenuItem("Other Options..."));
Menu circuitsMenu = new Menu("Circuits");
if (useFrame)
mb.add(circuitsMenu);
else
mainMenu.add(circuitsMenu);
mainMenu.add(getClassCheckItem("Add Wire", "WireElm"));
mainMenu.add(getClassCheckItem("Add Resistor", "ResistorElm"));
Menu passMenu = new Menu("Passive Components");
mainMenu.add(passMenu);
passMenu.add(getClassCheckItem("Add Capacitor", "CapacitorElm"));
passMenu.add(getClassCheckItem("Add Inductor", "InductorElm"));
passMenu.add(getClassCheckItem("Add Switch", "SwitchElm"));
passMenu.add(getClassCheckItem("Add Push Switch", "PushSwitchElm"));
passMenu.add(getClassCheckItem("Add SPDT Switch", "Switch2Elm"));
passMenu.add(getClassCheckItem("Add Potentiometer", "PotElm"));
passMenu.add(getClassCheckItem("Add Transformer", "TransformerElm"));
passMenu.add(getClassCheckItem("Add Tapped Transformer",
"TappedTransformerElm"));
passMenu.add(getClassCheckItem("Add Transmission Line", "TransLineElm"));
passMenu.add(getClassCheckItem("Add Relay", "RelayElm"));
passMenu.add(getClassCheckItem("Add Memristor", "MemristorElm"));
passMenu.add(getClassCheckItem("Add Spark Gap", "SparkGapElm"));
Menu inputMenu = new Menu("Inputs/Outputs");
mainMenu.add(inputMenu);
inputMenu.add(getClassCheckItem("Add Ground", "GroundElm"));
inputMenu.add(getClassCheckItem("Add Voltage Source (2-terminal)", "DCVoltageElm"));
inputMenu.add(getClassCheckItem("Add A/C Source (2-terminal)", "ACVoltageElm"));
inputMenu.add(getClassCheckItem("Add Voltage Source (1-terminal)", "RailElm"));
inputMenu.add(getClassCheckItem("Add A/C Source (1-terminal)", "ACRailElm"));
inputMenu.add(getClassCheckItem("Add Square Wave (1-terminal)", "SquareRailElm"));
inputMenu.add(getClassCheckItem("Add Analog Output", "OutputElm"));
inputMenu.add(getClassCheckItem("Add Logic Input", "LogicInputElm"));
inputMenu.add(getClassCheckItem("Add Logic Output", "LogicOutputElm"));
inputMenu.add(getClassCheckItem("Add Clock", "ClockElm"));
inputMenu.add(getClassCheckItem("Add A/C Sweep", "SweepElm"));
inputMenu.add(getClassCheckItem("Add Var. Voltage", "VarRailElm"));
inputMenu.add(getClassCheckItem("Add Antenna", "AntennaElm"));
inputMenu.add(getClassCheckItem("Add Current Source", "CurrentElm"));
inputMenu.add(getClassCheckItem("Add LED", "LEDElm"));
inputMenu.add(getClassCheckItem("Add Lamp (beta)", "LampElm"));
Menu activeMenu = new Menu("Active Components");
mainMenu.add(activeMenu);
activeMenu.add(getClassCheckItem("Add Diode", "DiodeElm"));
activeMenu.add(getClassCheckItem("Add Zener Diode", "ZenerElm"));
activeMenu.add(getClassCheckItem("Add Transistor (bipolar, NPN)",
"NTransistorElm"));
activeMenu.add(getClassCheckItem("Add Transistor (bipolar, PNP)",
"PTransistorElm"));
activeMenu.add(getClassCheckItem("Add Op Amp (- on top)", "OpAmpElm"));
activeMenu.add(getClassCheckItem("Add Op Amp (+ on top)",
"OpAmpSwapElm"));
activeMenu.add(getClassCheckItem("Add MOSFET (n-channel)",
"NMosfetElm"));
activeMenu.add(getClassCheckItem("Add MOSFET (p-channel)",
"PMosfetElm"));
activeMenu.add(getClassCheckItem("Add JFET (n-channel)",
"NJfetElm"));
activeMenu.add(getClassCheckItem("Add JFET (p-channel)",
"PJfetElm"));
activeMenu.add(getClassCheckItem("Add Analog Switch (SPST)", "AnalogSwitchElm"));
activeMenu.add(getClassCheckItem("Add Analog Switch (SPDT)", "AnalogSwitch2Elm"));
activeMenu.add(getClassCheckItem("Add SCR", "SCRElm"));
//activeMenu.add(getClassCheckItem("Add Varactor/Varicap", "VaractorElm"));
activeMenu.add(getClassCheckItem("Add Tunnel Diode", "TunnelDiodeElm"));
activeMenu.add(getClassCheckItem("Add Triode", "TriodeElm"));
//activeMenu.add(getClassCheckItem("Add Diac", "DiacElm"));
//activeMenu.add(getClassCheckItem("Add Triac", "TriacElm"));
//activeMenu.add(getClassCheckItem("Add Photoresistor", "PhotoResistorElm"));
//activeMenu.add(getClassCheckItem("Add Thermistor", "ThermistorElm"));
activeMenu.add(getClassCheckItem("Add CCII+", "CC2Elm"));
activeMenu.add(getClassCheckItem("Add CCII-", "CC2NegElm"));
Menu gateMenu = new Menu("Logic Gates");
mainMenu.add(gateMenu);
gateMenu.add(getClassCheckItem("Add Inverter", "InverterElm"));
gateMenu.add(getClassCheckItem("Add NAND Gate", "NandGateElm"));
gateMenu.add(getClassCheckItem("Add NOR Gate", "NorGateElm"));
gateMenu.add(getClassCheckItem("Add AND Gate", "AndGateElm"));
gateMenu.add(getClassCheckItem("Add OR Gate", "OrGateElm"));
gateMenu.add(getClassCheckItem("Add XOR Gate", "XorGateElm"));
Menu chipMenu = new Menu("Chips");
mainMenu.add(chipMenu);
chipMenu.add(getClassCheckItem("Add D Flip-Flop", "DFlipFlopElm"));
chipMenu.add(getClassCheckItem("Add JK Flip-Flop", "JKFlipFlopElm"));
chipMenu.add(getClassCheckItem("Add 7 Segment LED", "SevenSegElm"));
chipMenu.add(getClassCheckItem("Add VCO", "VCOElm"));
chipMenu.add(getClassCheckItem("Add Phase Comparator", "PhaseCompElm"));
chipMenu.add(getClassCheckItem("Add Counter", "CounterElm"));
chipMenu.add(getClassCheckItem("Add Decade Counter", "DecadeElm"));
chipMenu.add(getClassCheckItem("Add 555 Timer", "TimerElm"));
chipMenu.add(getClassCheckItem("Add DAC", "DACElm"));
chipMenu.add(getClassCheckItem("Add ADC", "ADCElm"));
chipMenu.add(getClassCheckItem("Add Latch", "LatchElm"));
Menu otherMenu = new Menu("Other");
mainMenu.add(otherMenu);
otherMenu.add(getClassCheckItem("Add Text", "TextElm"));
otherMenu.add(getClassCheckItem("Add Box", "BoxElm"));
otherMenu.add(getClassCheckItem("Add Scope Probe", "ProbeElm"));
otherMenu.add(getCheckItem("Drag All (Alt-drag)", "DragAll"));
otherMenu.add(getCheckItem(
isMac ? "Drag Row (Alt-S-drag, S-right)" :
"Drag Row (S-right)",
"DragRow"));
otherMenu.add(getCheckItem(
isMac ? "Drag Column (Alt-\u2318-drag, \u2318-right)" :
"Drag Column (C-right)",
"DragColumn"));
otherMenu.add(getCheckItem("Drag Selected", "DragSelected"));
otherMenu.add(getCheckItem("Drag Post (" + ctrlMetaKey + "-drag)",
"DragPost"));
mainMenu.add(getCheckItem("Select/Drag Selected (space or Shift-drag)", "Select"));
main.add(mainMenu);
main.add(resetButton = new Button("Reset"));
resetButton.addActionListener(this);
dumpMatrixButton = new Button("Dump Matrix");
//main.add(dumpMatrixButton);
dumpMatrixButton.addActionListener(this);
stoppedCheck = new Checkbox("Stopped");
stoppedCheck.addItemListener(this);
main.add(stoppedCheck);
main.add(new Label("Simulation Speed", Label.CENTER));
// was max of 140
main.add(speedBar = new Scrollbar(Scrollbar.HORIZONTAL, 3, 1, 0, 260));
speedBar.addAdjustmentListener(this);
main.add(new Label("Current Speed", Label.CENTER));
currentBar = new Scrollbar(Scrollbar.HORIZONTAL,
50, 1, 1, 100);
currentBar.addAdjustmentListener(this);
main.add(currentBar);
main.add(powerLabel = new Label("Power Brightness", Label.CENTER));
main.add(powerBar = new Scrollbar(Scrollbar.HORIZONTAL,
50, 1, 1, 100));
powerBar.addAdjustmentListener(this);
powerBar.disable();
powerLabel.disable();
main.add(new Label("www.falstad.com"));
if (useFrame)
main.add(new Label(""));
Font f = new Font("SansSerif", 0, 10);
Label l;
l = new Label("Current Circuit:");
l.setFont(f);
titleLabel = new Label("Label");
titleLabel.setFont(f);
if (useFrame) {
main.add(l);
main.add(titleLabel);
}
setGrid();
elmList = new Vector<CircuitElm>();
// setupList = new Vector();
undoStack = new Vector<String>();
redoStack = new Vector<String>();
scopes = new Scope[20];
scopeColCount = new int[20];
scopeCount = 0;
random = new Random();
cv.setBackground(Color.black);
cv.setForeground(Color.lightGray);
elmMenu = new PopupMenu();
elmMenu.add(elmEditMenuItem = getMenuItem("Edit"));
elmMenu.add(elmScopeMenuItem = getMenuItem("View in Scope"));
elmMenu.add(elmCutMenuItem = getMenuItem("Cut"));
elmMenu.add(elmCopyMenuItem = getMenuItem("Copy"));
elmMenu.add(elmDeleteMenuItem = getMenuItem("Delete"));
main.add(elmMenu);
scopeMenu = buildScopeMenu(false);
transScopeMenu = buildScopeMenu(true);
getSetupList(circuitsMenu, false);
if (useFrame)
setMenuBar(mb);
if (startCircuitText != null)
readSetup(startCircuitText);
else if (stopMessage == null && startCircuit != null)
readSetupFile(startCircuit, startLabel);
else
readSetup(null, 0, false);
if (useFrame) {
Dimension screen = getToolkit().getScreenSize();
resize(860, 640);
handleResize();
Dimension x = getSize();
setLocation((screen.width - x.width)/2,
(screen.height - x.height)/2);
show();
} else {
if (!powerCheckItem.getState()) {
main.remove(powerBar);
main.remove(powerLabel);
main.validate();
}
hide();
handleResize();
applet.validate();
}
requestFocus();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
destroyFrame();
}
}
);
}
boolean shown = false;
public void triggerShow() {
if (!shown)
show();
shown = true;
}
public void requestFocus()
{
super.requestFocus();
cv.requestFocus();
}
PopupMenu buildScopeMenu(boolean t) {
PopupMenu m = new PopupMenu();
m.add(getMenuItem("Remove", "remove"));
m.add(getMenuItem("Speed 2x", "speed2"));
m.add(getMenuItem("Speed 1/2x", "speed1/2"));
m.add(getMenuItem("Scale 2x", "scale"));
m.add(getMenuItem("Max Scale", "maxscale"));
m.add(getMenuItem("Stack", "stack"));
m.add(getMenuItem("Unstack", "unstack"));
m.add(getMenuItem("Reset", "reset"));
if (t) {
m.add(scopeIbMenuItem = getCheckItem("Show Ib"));
m.add(scopeIcMenuItem = getCheckItem("Show Ic"));
m.add(scopeIeMenuItem = getCheckItem("Show Ie"));
m.add(scopeVbeMenuItem = getCheckItem("Show Vbe"));
m.add(scopeVbcMenuItem = getCheckItem("Show Vbc"));
m.add(scopeVceMenuItem = getCheckItem("Show Vce"));
m.add(scopeVceIcMenuItem = getCheckItem("Show Vce vs Ic"));
} else {
m.add(scopeVMenuItem = getCheckItem("Show Voltage"));
m.add(scopeIMenuItem = getCheckItem("Show Current"));
m.add(scopePowerMenuItem = getCheckItem("Show Power Consumed"));
m.add(scopeMaxMenuItem = getCheckItem("Show Peak Value"));
m.add(scopeMinMenuItem = getCheckItem("Show Negative Peak Value"));
m.add(scopeFreqMenuItem = getCheckItem("Show Frequency"));
m.add(scopeVIMenuItem = getCheckItem("Show V vs I"));
m.add(scopeXYMenuItem = getCheckItem("Plot X/Y"));
m.add(scopeSelectYMenuItem = getMenuItem("Select Y", "selecty"));
m.add(scopeResistMenuItem = getCheckItem("Show Resistance"));
}
main.add(m);
return m;
}
MenuItem getMenuItem(String s) {
MenuItem mi = new MenuItem(s);
mi.addActionListener(this);
return mi;
}
MenuItem getMenuItem(String s, String ac) {
MenuItem mi = new MenuItem(s);
mi.setActionCommand(ac);
mi.addActionListener(this);
return mi;
}
CheckboxMenuItem getCheckItem(String s) {
CheckboxMenuItem mi = new CheckboxMenuItem(s);
mi.addItemListener(this);
mi.setActionCommand("");
return mi;
}
CheckboxMenuItem getClassCheckItem(String s, String t) {
try {
Class c = Class.forName(t);
CircuitElm elm = constructElement(c, 0, 0);
register(c, elm);
if ( elm.needsShortcut() ) {
s += " (" + (char)elm.getShortcut() + ")";
}
elm.delete();
} catch (Exception ee) {
ee.printStackTrace();
}
return getCheckItem(s, t);
}
CheckboxMenuItem getCheckItem(String s, String t) {
CheckboxMenuItem mi = new CheckboxMenuItem(s);
mi.addItemListener(this);
mi.setActionCommand(t);
return mi;
}
void register(Class c, CircuitElm elm) {
int t = elm.getDumpType();
if (t == 0) {
System.out.println("no dump type: " + c);
return;
}
int s = elm.getShortcut();
if ( elm.needsShortcut() && s == 0 )
{
if ( s == 0 )
{
System.err.println("no shortcut " + c + " for " + c);
return;
}
else if ( s <= ' ' || s >= 127 )
{
System.err.println("invalid shortcut " + c + " for " + c);
return;
}
}
Class dclass = elm.getDumpClass();
if ( dumpTypes[t] != null && dumpTypes[t] != dclass ) {
System.out.println("dump type conflict: " + c + " " +
dumpTypes[t]);
return;
}
dumpTypes[t] = dclass;
Class sclass = elm.getClass();
if ( elm.needsShortcut() && shortcuts[s] != null &&
shortcuts[s] != sclass )
{
System.err.println("shortcut conflict: " + c +
" (previously assigned to " +
shortcuts[s] + ")");
}
else
{
shortcuts[s] = sclass;
}
}
void handleResize() {
winSize = cv.getSize();
if (winSize.width == 0)
return;
dbimage = main.createImage(winSize.width, winSize.height);
int h = winSize.height / 5;
/*if (h < 128 && winSize.height > 300)
h = 128;*/
circuitArea = new Rectangle(0, 0, winSize.width, winSize.height-h);
int i;
int minx = 1000, maxx = 0, miny = 1000, maxy = 0;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
// centered text causes problems when trying to center the circuit,
// so we special-case it here
if (!ce.isCenteredText()) {
minx = min(ce.x, min(ce.x2, minx));
maxx = max(ce.x, max(ce.x2, maxx));
}
miny = min(ce.y, min(ce.y2, miny));
maxy = max(ce.y, max(ce.y2, maxy));
}
// center circuit; we don't use snapGrid() because that rounds
int dx = gridMask & ((circuitArea.width -(maxx-minx))/2-minx);
int dy = gridMask & ((circuitArea.height-(maxy-miny))/2-miny);
if (dx+minx < 0)
dx = gridMask & (-minx);
if (dy+miny < 0)
dy = gridMask & (-miny);
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.move(dx, dy);
}
// after moving elements, need this to avoid singular matrix probs
needAnalyze();
circuitBottom = 0;
}
void destroyFrame() {
if (applet == null)
{
dispose();
System.exit(0);
}
else
{
applet.destroyFrame();
}
}
public boolean handleEvent(Event ev) {
if (ev.id == Event.WINDOW_DESTROY) {
destroyFrame();
return true;
}
return super.handleEvent(ev);
}
public void paint(Graphics g) {
cv.repaint();
}
static final int resct = 6;
long lastTime = 0, lastFrameTime, lastIterTime, secTime = 0;
int frames = 0;
int steps = 0;
int framerate = 0, steprate = 0;
public void updateCircuit(Graphics realg) {
CircuitElm realMouseElm;
if (winSize == null || winSize.width == 0)
return;
if (analyzeFlag) {
analyzeCircuit();
analyzeFlag = false;
}
if (editDialog != null && editDialog.elm instanceof CircuitElm)
mouseElm = (CircuitElm) (editDialog.elm);
realMouseElm = mouseElm;
if (mouseElm == null)
mouseElm = stopElm;
setupScopes();
Graphics2D g = null; // hausen: changed to Graphics2D
g = (Graphics2D)dbimage.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
CircuitElm.selectColor = Color.cyan;
if (printableCheckItem.getState()) {
CircuitElm.whiteColor = Color.black;
CircuitElm.lightGrayColor = Color.black;
g.setColor(Color.white);
} else {
CircuitElm.whiteColor = Color.white;
CircuitElm.lightGrayColor = Color.lightGray;
g.setColor(Color.black);
}
g.fillRect(0, 0, winSize.width, winSize.height);
if (!stoppedCheck.getState()) {
try {
runCircuit();
} catch (Exception e) {
e.printStackTrace();
analyzeFlag = true;
cv.repaint();
return;
}
}
if (!stoppedCheck.getState()) {
long sysTime = System.currentTimeMillis();
if (lastTime != 0) {
int inc = (int) (sysTime-lastTime);
double c = currentBar.getValue();
c = java.lang.Math.exp(c/3.5-14.2);
CircuitElm.currentMult = 1.7 * inc * c;
if (!conventionCheckItem.getState())
CircuitElm.currentMult = -CircuitElm.currentMult;
}
if (sysTime-secTime >= 1000) {
framerate = frames; steprate = steps;
frames = 0; steps = 0;
secTime = sysTime;
}
lastTime = sysTime;
} else
lastTime = 0;
CircuitElm.powerMult = Math.exp(powerBar.getValue()/4.762-7);
int i;
Font oldfont = g.getFont();
for (i = 0; i != elmList.size(); i++) {
if (powerCheckItem.getState())
g.setColor(Color.gray);
/*else if (conductanceCheckItem.getState())
g.setColor(Color.white);*/
getElm(i).draw(g);
}
if (tempMouseMode == MODE_DRAG_ROW || tempMouseMode == MODE_DRAG_COLUMN ||
tempMouseMode == MODE_DRAG_POST || tempMouseMode == MODE_DRAG_SELECTED)
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.drawPost(g, ce.x , ce.y );
ce.drawPost(g, ce.x2, ce.y2);
}
int badnodes = 0;
// find bad connections, nodes not connected to other elements which
// intersect other elements' bounding boxes
// debugged by hausen: nullPointerException
if ( nodeList != null )
for (i = 0; i != nodeList.size(); i++) {
CircuitNode cn = getCircuitNode(i);
if (!cn.internal && cn.links.size() == 1) {
int bb = 0, j;
CircuitNodeLink cnl = cn.links.elementAt(0);
for (j = 0; j != elmList.size(); j++)
{ // TODO: (hausen) see if this change does not break stuff
CircuitElm ce = getElm(j);
if ( ce instanceof GraphicElm )
continue;
if (cnl.elm != ce &&
getElm(j).boundingBox.contains(cn.x, cn.y))
bb++;
}
if (bb > 0) {
g.setColor(Color.red);
g.fillOval(cn.x-3, cn.y-3, 7, 7);
badnodes++;
}
}
}
/*if (mouseElm != null) {
g.setFont(oldfont);
g.drawString("+", mouseElm.x+10, mouseElm.y);
}*/
if (dragElm != null &&
(dragElm.x != dragElm.x2 || dragElm.y != dragElm.y2))
dragElm.draw(g);
g.setFont(oldfont);
int ct = scopeCount;
if (stopMessage != null)
ct = 0;
for (i = 0; i != ct; i++)
scopes[i].draw(g);
g.setColor(CircuitElm.whiteColor);
if (stopMessage != null) {
g.drawString(stopMessage, 10, circuitArea.height);
} else {
if (circuitBottom == 0)
calcCircuitBottom();
String info[] = new String[10];
if (mouseElm != null) {
if (mousePost == -1)
mouseElm.getInfo(info);
else
info[0] = "V = " +
CircuitElm.getUnitText(mouseElm.getPostVoltage(mousePost), "V");
/* //shownodes
for (i = 0; i != mouseElm.getPostCount(); i++)
info[0] += " " + mouseElm.nodes[i];
if (mouseElm.getVoltageSourceCount() > 0)
info[0] += ";" + (mouseElm.getVoltageSource()+nodeList.size());
*/
} else {
CircuitElm.showFormat.setMinimumFractionDigits(2);
info[0] = "t = " + CircuitElm.getUnitText(t, "s");
CircuitElm.showFormat.setMinimumFractionDigits(0);
}
if (hintType != -1) {
for (i = 0; info[i] != null; i++)
;
String s = getHint();
if (s == null)
hintType = -1;
else
info[i] = s;
}
int x = 0;
if (ct != 0)
x = scopes[ct-1].rightEdge() + 20;
x = max(x, winSize.width*2/3);
// count lines of data
for (i = 0; info[i] != null; i++)
;
if (badnodes > 0)
info[i++] = badnodes + ((badnodes == 1) ?
" bad connection" : " bad connections");
// find where to show data; below circuit, not too high unless we need it
int ybase = winSize.height-15*i-5;
ybase = min(ybase, circuitArea.height);
ybase = max(ybase, circuitBottom);
for (i = 0; info[i] != null; i++)
g.drawString(info[i], x,
ybase+15*(i+1));
}
if (selectedArea != null) {
g.setColor(CircuitElm.selectColor);
g.drawRect(selectedArea.x, selectedArea.y, selectedArea.width, selectedArea.height);
}
mouseElm = realMouseElm;
frames++;
/*
g.setColor(Color.white);
g.drawString("Framerate: " + framerate, 10, 10);
g.drawString("Steprate: " + steprate, 10, 30);
g.drawString("Steprate/iter: " + (steprate/getIterCount()), 10, 50);
g.drawString("iterc: " + (getIterCount()), 10, 70);
*/
realg.drawImage(dbimage, 0, 0, this);
if (!stoppedCheck.getState() && circuitMatrix != null) {
// Limit to 50 fps (thanks to Jurgen Klotzer for this)
long delay = 1000/50 - (System.currentTimeMillis() - lastFrameTime);
//realg.drawString("delay: " + delay, 10, 90);
if (delay > 0) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
}
}
cv.repaint(0);
}
lastFrameTime = lastTime;
}
void setupScopes() {
int i;
// check scopes to make sure the elements still exist, and remove
// unused scopes/columns
int pos = -1;
for (i = 0; i < scopeCount; i++) {
if (locateElm(scopes[i].elm) < 0)
scopes[i].setElm(null);
if (scopes[i].elm == null) {
int j;
for (j = i; j != scopeCount; j++)
scopes[j] = scopes[j+1];
scopeCount--;
i--;
continue;
}
if (scopes[i].position > pos+1)
scopes[i].position = pos+1;
pos = scopes[i].position;
}
while (scopeCount > 0 && scopes[scopeCount-1].elm == null)
scopeCount--;
int h = winSize.height - circuitArea.height;
pos = 0;
for (i = 0; i != scopeCount; i++)
scopeColCount[i] = 0;
for (i = 0; i != scopeCount; i++) {
pos = max(scopes[i].position, pos);
scopeColCount[scopes[i].position]++;
}
int colct = pos+1;
int iw = infoWidth;
if (colct <= 2)
iw = iw*3/2;
int w = (winSize.width-iw) / colct;
int marg = 10;
if (w < marg*2)
w = marg*2;
pos = -1;
int colh = 0;
int row = 0;
int speed = 0;
for (i = 0; i != scopeCount; i++) {
Scope s = scopes[i];
if (s.position > pos) {
pos = s.position;
colh = h / scopeColCount[pos];
row = 0;
speed = s.speed;
}
if (s.speed != speed) {
s.speed = speed;
s.resetGraph();
}
Rectangle r = new Rectangle(pos*w, winSize.height-h+colh*row,
w-marg, colh);
row++;
if (!r.equals(s.rect))
s.setRect(r);
}
}
String getHint() {
CircuitElm c1 = getElm(hintItem1);
CircuitElm c2 = getElm(hintItem2);
if (c1 == null || c2 == null)
return null;
if (hintType == HINT_LC) {
if (!(c1 instanceof InductorElm))
return null;
if (!(c2 instanceof CapacitorElm))
return null;
InductorElm ie = (InductorElm) c1;
CapacitorElm ce = (CapacitorElm) c2;
return "res.f = " + CircuitElm.getUnitText(1/(2*pi*Math.sqrt(ie.inductance*
ce.capacitance)), "Hz");
}
if (hintType == HINT_RC) {
if (!(c1 instanceof ResistorElm))
return null;
if (!(c2 instanceof CapacitorElm))
return null;
ResistorElm re = (ResistorElm) c1;
CapacitorElm ce = (CapacitorElm) c2;
return "RC = " + CircuitElm.getUnitText(re.resistance*ce.capacitance,
"s");
}
if (hintType == HINT_3DB_C) {
if (!(c1 instanceof ResistorElm))
return null;
if (!(c2 instanceof CapacitorElm))
return null;
ResistorElm re = (ResistorElm) c1;
CapacitorElm ce = (CapacitorElm) c2;
return "f.3db = " +
CircuitElm.getUnitText(1/(2*pi*re.resistance*ce.capacitance), "Hz");
}
if (hintType == HINT_3DB_L) {
if (!(c1 instanceof ResistorElm))
return null;
if (!(c2 instanceof InductorElm))
return null;
ResistorElm re = (ResistorElm) c1;
InductorElm ie = (InductorElm) c2;
return "f.3db = " +
CircuitElm.getUnitText(re.resistance/(2*pi*ie.inductance), "Hz");
}
if (hintType == HINT_TWINT) {
if (!(c1 instanceof ResistorElm))
return null;
if (!(c2 instanceof CapacitorElm))
return null;
ResistorElm re = (ResistorElm) c1;
CapacitorElm ce = (CapacitorElm) c2;
return "fc = " +
CircuitElm.getUnitText(1/(2*pi*re.resistance*ce.capacitance), "Hz");
}
return null;
}
public void toggleSwitch(int n) {
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce instanceof SwitchElm) {
n--;
if (n == 0) {
((SwitchElm) ce).toggle();
analyzeFlag = true;
cv.repaint();
return;
}
}
}
}
void needAnalyze() {
analyzeFlag = true;
cv.repaint();
}
Vector<CircuitNode> nodeList;
CircuitElm voltageSources[];
public CircuitNode getCircuitNode(int n) {
if (n >= nodeList.size())
return null;
return nodeList.elementAt(n);
}
public CircuitElm getElm(int n) {
if (n >= elmList.size())
return null;
return elmList.elementAt(n);
}
void analyzeCircuit() {
calcCircuitBottom();
if (elmList.isEmpty())
return;
stopMessage = null;
stopElm = null;
int i, j;
int vscount = 0;
nodeList = new Vector<CircuitNode>();
boolean gotGround = false;
boolean gotRail = false;
CircuitElm volt = null;
//System.out.println("ac1");
// look for voltage or ground element
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce instanceof GroundElm) {
gotGround = true;
break;
}
if (ce instanceof RailElm)
gotRail = true;
if (volt == null && ce instanceof VoltageElm)
volt = ce;
}
// if no ground, and no rails, then the voltage elm's first terminal
// is ground
if (!gotGround && volt != null && !gotRail) {
CircuitNode cn = new CircuitNode();
Point pt = volt.getPost(0);
cn.x = pt.x;
cn.y = pt.y;
nodeList.addElement(cn);
} else {
// otherwise allocate extra node for ground
CircuitNode cn = new CircuitNode();
cn.x = cn.y = -1;
nodeList.addElement(cn);
}
//System.out.println("ac2");
// allocate nodes and voltage sources
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
int inodes = ce.getInternalNodeCount();
int ivs = ce.getVoltageSourceCount();
int posts = ce.getPostCount();
// allocate a node for each post and match posts to nodes
for (j = 0; j != posts; j++) {
Point pt = ce.getPost(j);
int k;
for (k = 0; k != nodeList.size(); k++) {
CircuitNode cn = getCircuitNode(k);
if (pt.x == cn.x && pt.y == cn.y)
break;
}
if (k == nodeList.size()) {
CircuitNode cn = new CircuitNode();
cn.x = pt.x;
cn.y = pt.y;
CircuitNodeLink cnl = new CircuitNodeLink();
cnl.num = j;
cnl.elm = ce;
cn.links.addElement(cnl);
ce.setNode(j, nodeList.size());
nodeList.addElement(cn);
} else {
CircuitNodeLink cnl = new CircuitNodeLink();
cnl.num = j;
cnl.elm = ce;
getCircuitNode(k).links.addElement(cnl);
ce.setNode(j, k);
// if it's the ground node, make sure the node voltage is 0,
// cause it may not get set later
if (k == 0)
ce.setNodeVoltage(j, 0);
}
}
for (j = 0; j != inodes; j++) {
CircuitNode cn = new CircuitNode();
cn.x = cn.y = -1;
cn.internal = true;
CircuitNodeLink cnl = new CircuitNodeLink();
cnl.num = j+posts;
cnl.elm = ce;
cn.links.addElement(cnl);
ce.setNode(cnl.num, nodeList.size());
nodeList.addElement(cn);
}
vscount += ivs;
}
voltageSources = new CircuitElm[vscount];
vscount = 0;
circuitNonLinear = false;
//System.out.println("ac3");
// determine if circuit is nonlinear
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce.nonLinear())
circuitNonLinear = true;
int ivs = ce.getVoltageSourceCount();
for (j = 0; j != ivs; j++) {
voltageSources[vscount] = ce;
ce.setVoltageSource(j, vscount++);
}
}
voltageSourceCount = vscount;
int matrixSize = nodeList.size()-1 + vscount;
circuitMatrix = new double[matrixSize][matrixSize];
circuitRightSide = new double[matrixSize];
origMatrix = new double[matrixSize][matrixSize];
origRightSide = new double[matrixSize];
circuitMatrixSize = circuitMatrixFullSize = matrixSize;
circuitRowInfo = new RowInfo[matrixSize];
circuitPermute = new int[matrixSize];
int vs = 0;
for (i = 0; i != matrixSize; i++)
circuitRowInfo[i] = new RowInfo();
circuitNeedsMap = false;
// stamp linear circuit elements
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.stamp();
}
//System.out.println("ac4");
// determine nodes that are unconnected
boolean closure[] = new boolean[nodeList.size()];
boolean tempclosure[] = new boolean[nodeList.size()];
boolean changed = true;
closure[0] = true;
while (changed) {
changed = false;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
// loop through all ce's nodes to see if they are connected
// to other nodes not in closure
for (j = 0; j < ce.getPostCount(); j++) {
if (!closure[ce.getNode(j)]) {
if (ce.hasGroundConnection(j))
closure[ce.getNode(j)] = changed = true;
continue;
}
int k;
for (k = 0; k != ce.getPostCount(); k++) {
if (j == k)
continue;
int kn = ce.getNode(k);
if (ce.getConnection(j, k) && !closure[kn]) {
closure[kn] = true;
changed = true;
}
}
}
}
if (changed)
continue;
// connect unconnected nodes
for (i = 0; i != nodeList.size(); i++)
if (!closure[i] && !getCircuitNode(i).internal) {
System.out.println("node " + i + " unconnected");
stampResistor(0, i, 1e8);
closure[i] = true;
changed = true;
break;
}
}
//System.out.println("ac5");
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
// look for inductors with no current path
if (ce instanceof InductorElm) {
FindPathInfo fpi = new FindPathInfo(FindPathInfo.INDUCT, ce,
ce.getNode(1));
// first try findPath with maximum depth of 5, to avoid slowdowns
if (!fpi.findPath(ce.getNode(0), 5) &&
!fpi.findPath(ce.getNode(0))) {
System.out.println(ce + " no path");
ce.reset();
}
}
// look for current sources with no current path
if (ce instanceof CurrentElm) {
FindPathInfo fpi = new FindPathInfo(FindPathInfo.INDUCT, ce,
ce.getNode(1));
if (!fpi.findPath(ce.getNode(0))) {
stop("No path for current source!", ce);
return;
}
}
// look for voltage source loops
if ((ce instanceof VoltageElm && ce.getPostCount() == 2) ||
ce instanceof WireElm) {
FindPathInfo fpi = new FindPathInfo(FindPathInfo.VOLTAGE, ce,
ce.getNode(1));
if (fpi.findPath(ce.getNode(0))) {
stop("Voltage source/wire loop with no resistance!", ce);
return;
}
}
// look for shorted caps, or caps w/ voltage but no R
if (ce instanceof CapacitorElm) {
FindPathInfo fpi = new FindPathInfo(FindPathInfo.SHORT, ce,
ce.getNode(1));
if (fpi.findPath(ce.getNode(0))) {
System.out.println(ce + " shorted");
ce.reset();
} else {
fpi = new FindPathInfo(FindPathInfo.CAP_V, ce, ce.getNode(1));
if (fpi.findPath(ce.getNode(0))) {
stop("Capacitor loop with no resistance!", ce);
return;
}
}
}
}
//System.out.println("ac6");
// simplify the matrix; this speeds things up quite a bit
for (i = 0; i != matrixSize; i++) {
int qm = -1, qp = -1;
double qv = 0;
RowInfo re = circuitRowInfo[i];
/*System.out.println("row " + i + " " + re.lsChanges + " " + re.rsChanges + " " +
re.dropRow);*/
if (re.lsChanges || re.dropRow || re.rsChanges)
continue;
double rsadd = 0;
// look for rows that can be removed
for (j = 0; j != matrixSize; j++) {
double q = circuitMatrix[i][j];
if (circuitRowInfo[j].type == RowInfo.ROW_CONST) {
// keep a running total of const values that have been
// removed already
rsadd -= circuitRowInfo[j].value*q;
continue;
}
if (q == 0)
continue;
if (qp == -1) {
qp = j;
qv = q;
continue;
}
if (qm == -1 && q == -qv) {
qm = j;
continue;
}
break;
}
//System.out.println("line " + i + " " + qp + " " + qm + " " + j);
/*if (qp != -1 && circuitRowInfo[qp].lsChanges) {
System.out.println("lschanges");
continue;
}
if (qm != -1 && circuitRowInfo[qm].lsChanges) {
System.out.println("lschanges");
continue;
}*/
if (j == matrixSize) {
if (qp == -1) {
stop("Matrix error", null);
return;
}
RowInfo elt = circuitRowInfo[qp];
if (qm == -1) {
// we found a row with only one nonzero entry; that value
// is a constant
int k;
for (k = 0; elt.type == RowInfo.ROW_EQUAL && k < 100; k++) {
// follow the chain
/*System.out.println("following equal chain from " +
i + " " + qp + " to " + elt.nodeEq);*/
qp = elt.nodeEq;
elt = circuitRowInfo[qp];
}
if (elt.type == RowInfo.ROW_EQUAL) {
// break equal chains
//System.out.println("Break equal chain");
elt.type = RowInfo.ROW_NORMAL;
continue;
}
if (elt.type != RowInfo.ROW_NORMAL) {
System.out.println("type already " + elt.type + " for " + qp + "!");
continue;
}
elt.type = RowInfo.ROW_CONST;
elt.value = (circuitRightSide[i]+rsadd)/qv;
circuitRowInfo[i].dropRow = true;
//System.out.println(qp + " * " + qv + " = const " + elt.value);
i = -1; // start over from scratch
} else if (circuitRightSide[i]+rsadd == 0) {
// we found a row with only two nonzero entries, and one
// is the negative of the other; the values are equal
if (elt.type != RowInfo.ROW_NORMAL) {
//System.out.println("swapping");
int qq = qm;
qm = qp; qp = qq;
elt = circuitRowInfo[qp];
if (elt.type != RowInfo.ROW_NORMAL) {
// we should follow the chain here, but this
// hardly ever happens so it's not worth worrying
// about
System.out.println("swap failed");
continue;
}
}
elt.type = RowInfo.ROW_EQUAL;
elt.nodeEq = qm;
circuitRowInfo[i].dropRow = true;
//System.out.println(qp + " = " + qm);
}
}
}
//System.out.println("ac7");
// find size of new matrix
int nn = 0;
for (i = 0; i != matrixSize; i++) {
RowInfo elt = circuitRowInfo[i];
if (elt.type == RowInfo.ROW_NORMAL) {
elt.mapCol = nn++;
//System.out.println("col " + i + " maps to " + elt.mapCol);
continue;
}
if (elt.type == RowInfo.ROW_EQUAL) {
RowInfo e2 = null;
// resolve chains of equality; 100 max steps to avoid loops
for (j = 0; j != 100; j++) {
e2 = circuitRowInfo[elt.nodeEq];
if (e2.type != RowInfo.ROW_EQUAL)
break;
if (i == e2.nodeEq)
break;
elt.nodeEq = e2.nodeEq;
}
}
if (elt.type == RowInfo.ROW_CONST)
elt.mapCol = -1;
}
for (i = 0; i != matrixSize; i++) {
RowInfo elt = circuitRowInfo[i];
if (elt.type == RowInfo.ROW_EQUAL) {
RowInfo e2 = circuitRowInfo[elt.nodeEq];
if (e2.type == RowInfo.ROW_CONST) {
// if something is equal to a const, it's a const
elt.type = e2.type;
elt.value = e2.value;
elt.mapCol = -1;
//System.out.println(i + " = [late]const " + elt.value);
} else {
elt.mapCol = e2.mapCol;
//System.out.println(i + " maps to: " + e2.mapCol);
}
}
}
//System.out.println("ac8");
/*System.out.println("matrixSize = " + matrixSize);
for (j = 0; j != circuitMatrixSize; j++) {
System.out.println(j + ": ");
for (i = 0; i != circuitMatrixSize; i++)
System.out.print(circuitMatrix[j][i] + " ");
System.out.print(" " + circuitRightSide[j] + "\n");
}
System.out.print("\n");*/
// make the new, simplified matrix
int newsize = nn;
double newmatx[][] = new double[newsize][newsize];
double newrs [] = new double[newsize];
int ii = 0;
for (i = 0; i != matrixSize; i++) {
RowInfo rri = circuitRowInfo[i];
if (rri.dropRow) {
rri.mapRow = -1;
continue;
}
newrs[ii] = circuitRightSide[i];
rri.mapRow = ii;
//System.out.println("Row " + i + " maps to " + ii);
for (j = 0; j != matrixSize; j++) {
RowInfo ri = circuitRowInfo[j];
if (ri.type == RowInfo.ROW_CONST)
newrs[ii] -= ri.value*circuitMatrix[i][j];
else
newmatx[ii][ri.mapCol] += circuitMatrix[i][j];
}
ii++;
}
circuitMatrix = newmatx;
circuitRightSide = newrs;
matrixSize = circuitMatrixSize = newsize;
for (i = 0; i != matrixSize; i++)
origRightSide[i] = circuitRightSide[i];
for (i = 0; i != matrixSize; i++)
for (j = 0; j != matrixSize; j++)
origMatrix[i][j] = circuitMatrix[i][j];
circuitNeedsMap = true;
/*
System.out.println("matrixSize = " + matrixSize + " " + circuitNonLinear);
for (j = 0; j != circuitMatrixSize; j++) {
for (i = 0; i != circuitMatrixSize; i++)
System.out.print(circuitMatrix[j][i] + " ");
System.out.print(" " + circuitRightSide[j] + "\n");
}
System.out.print("\n");*/
// if a matrix is linear, we can do the lu_factor here instead of
// needing to do it every frame
if (!circuitNonLinear) {
if (!lu_factor(circuitMatrix, circuitMatrixSize, circuitPermute)) {
stop("Singular matrix!", null);
return;
}
}
}
void calcCircuitBottom() {
int i;
circuitBottom = 0;
for (i = 0; i != elmList.size(); i++) {
Rectangle rect = getElm(i).boundingBox;
int bottom = rect.height + rect.y;
if (bottom > circuitBottom)
circuitBottom = bottom;
}
}
class FindPathInfo {
static final int INDUCT = 1;
static final int VOLTAGE = 2;
static final int SHORT = 3;
static final int CAP_V = 4;
boolean used[];
int dest;
CircuitElm firstElm;
int type;
FindPathInfo(int t, CircuitElm e, int d) {
dest = d;
type = t;
firstElm = e;
used = new boolean[nodeList.size()];
}
boolean findPath(int n1) { return findPath(n1, -1); }
boolean findPath(int n1, int depth) {
if (n1 == dest)
return true;
if (depth-- == 0)
return false;
if (used[n1]) {
//System.out.println("used " + n1);
return false;
}
used[n1] = true;
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce == firstElm)
continue;
if (type == INDUCT) {
if (ce instanceof CurrentElm)
continue;
}
if (type == VOLTAGE) {
if (!(ce.isWire() || ce instanceof VoltageElm))
continue;
}
if (type == SHORT && !ce.isWire())
continue;
if (type == CAP_V) {
if (!(ce.isWire() || ce instanceof CapacitorElm ||
ce instanceof VoltageElm))
continue;
}
if (n1 == 0) {
// look for posts which have a ground connection;
// our path can go through ground
int j;
for (j = 0; j != ce.getPostCount(); j++)
if (ce.hasGroundConnection(j) &&
findPath(ce.getNode(j), depth)) {
used[n1] = false;
return true;
}
}
int j;
for (j = 0; j != ce.getPostCount(); j++) {
//System.out.println(ce + " " + ce.getNode(j));
if (ce.getNode(j) == n1)
break;
}
if (j == ce.getPostCount())
continue;
if (ce.hasGroundConnection(j) && findPath(0, depth)) {
//System.out.println(ce + " has ground");
used[n1] = false;
return true;
}
if (type == INDUCT && ce instanceof InductorElm) {
double c = ce.getCurrent();
if (j == 0)
c = -c;
//System.out.println("matching " + c + " to " + firstElm.getCurrent());
//System.out.println(ce + " " + firstElm);
if (Math.abs(c-firstElm.getCurrent()) > 1e-10)
continue;
}
int k;
for (k = 0; k != ce.getPostCount(); k++) {
if (j == k)
continue;
//System.out.println(ce + " " + ce.getNode(j) + "-" + ce.getNode(k));
if (ce.getConnection(j, k) && findPath(ce.getNode(k), depth)) {
//System.out.println("got findpath " + n1);
used[n1] = false;
return true;
}
//System.out.println("back on findpath " + n1);
}
}
used[n1] = false;
//System.out.println(n1 + " failed");
return false;
}
}
void stop(String s, CircuitElm ce) {
stopMessage = s;
circuitMatrix = null;
stopElm = ce;
stoppedCheck.setState(true);
analyzeFlag = false;
cv.repaint();
}
// control voltage source vs with voltage from n1 to n2 (must
// also call stampVoltageSource())
void stampVCVS(int n1, int n2, double coef, int vs) {
int vn = nodeList.size()+vs;
stampMatrix(vn, n1, coef);
stampMatrix(vn, n2, -coef);
}
// stamp independent voltage source #vs, from n1 to n2, amount v
void stampVoltageSource(int n1, int n2, int vs, double v) {
int vn = nodeList.size()+vs;
stampMatrix(vn, n1, -1);
stampMatrix(vn, n2, 1);
stampRightSide(vn, v);
stampMatrix(n1, vn, 1);
stampMatrix(n2, vn, -1);
}
// use this if the amount of voltage is going to be updated in doStep()
void stampVoltageSource(int n1, int n2, int vs) {
int vn = nodeList.size()+vs;
stampMatrix(vn, n1, -1);
stampMatrix(vn, n2, 1);
stampRightSide(vn);
stampMatrix(n1, vn, 1);
stampMatrix(n2, vn, -1);
}
void updateVoltageSource(int n1, int n2, int vs, double v) {
int vn = nodeList.size()+vs;
stampRightSide(vn, v);
}
void stampResistor(int n1, int n2, double r) {
double r0 = 1/r;
if (Double.isNaN(r0) || Double.isInfinite(r0)) {
System.out.print("bad resistance " + r + " " + r0 + "\n");
int a = 0;
a /= a;
}
stampMatrix(n1, n1, r0);
stampMatrix(n2, n2, r0);
stampMatrix(n1, n2, -r0);
stampMatrix(n2, n1, -r0);
}
void stampConductance(int n1, int n2, double r0) {
stampMatrix(n1, n1, r0);
stampMatrix(n2, n2, r0);
stampMatrix(n1, n2, -r0);
stampMatrix(n2, n1, -r0);
}
// current from cn1 to cn2 is equal to voltage from vn1 to 2, divided by g
void stampVCCurrentSource(int cn1, int cn2, int vn1, int vn2, double g) {
stampMatrix(cn1, vn1, g);
stampMatrix(cn2, vn2, g);
stampMatrix(cn1, vn2, -g);
stampMatrix(cn2, vn1, -g);
}
void stampCurrentSource(int n1, int n2, double i) {
stampRightSide(n1, -i);
stampRightSide(n2, i);
}
// stamp a current source from n1 to n2 depending on current through vs
void stampCCCS(int n1, int n2, int vs, double gain) {
int vn = nodeList.size()+vs;
stampMatrix(n1, vn, gain);
stampMatrix(n2, vn, -gain);
}
// stamp value x in row i, column j, meaning that a voltage change
// of dv in node j will increase the current into node i by x dv.
// (Unless i or j is a voltage source node.)
void stampMatrix(int i, int j, double x) {
if (i > 0 && j > 0) {
if (circuitNeedsMap) {
i = circuitRowInfo[i-1].mapRow;
RowInfo ri = circuitRowInfo[j-1];
if (ri.type == RowInfo.ROW_CONST) {
//System.out.println("Stamping constant " + i + " " + j + " " + x);
circuitRightSide[i] -= x*ri.value;
return;
}
j = ri.mapCol;
//System.out.println("stamping " + i + " " + j + " " + x);
} else {
i--;
j--;
}
circuitMatrix[i][j] += x;
}
}
// stamp value x on the right side of row i, representing an
// independent current source flowing into node i
void stampRightSide(int i, double x) {
if (i > 0) {
if (circuitNeedsMap) {
i = circuitRowInfo[i-1].mapRow;
//System.out.println("stamping " + i + " " + x);
} else
i--;
circuitRightSide[i] += x;
}
}
// indicate that the value on the right side of row i changes in doStep()
void stampRightSide(int i) {
//System.out.println("rschanges true " + (i-1));
if (i > 0)
circuitRowInfo[i-1].rsChanges = true;
}
// indicate that the values on the left side of row i change in doStep()
void stampNonLinear(int i) {
if (i > 0)
circuitRowInfo[i-1].lsChanges = true;
}
double getIterCount() {
if (speedBar.getValue() == 0)
return 0;
//return (Math.exp((speedBar.getValue()-1)/24.) + .5);
return .1*Math.exp((speedBar.getValue()-61)/24.);
}
boolean converged;
int subIterations;
void runCircuit() {
if (circuitMatrix == null || elmList.size() == 0) {
circuitMatrix = null;
return;
}
int iter;
//int maxIter = getIterCount();
boolean debugprint = dumpMatrix;
dumpMatrix = false;
long steprate = (long) (160*getIterCount());
long tm = System.currentTimeMillis();
long lit = lastIterTime;
if (1000 >= steprate*(tm-lastIterTime))
return;
for (iter = 1; ; iter++) {
int i, j, k, subiter;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.startIteration();
}
steps++;
final int subiterCount = 5000;
for (subiter = 0; subiter != subiterCount; subiter++) {
converged = true;
subIterations = subiter;
for (i = 0; i != circuitMatrixSize; i++)
circuitRightSide[i] = origRightSide[i];
if (circuitNonLinear) {
for (i = 0; i != circuitMatrixSize; i++)
for (j = 0; j != circuitMatrixSize; j++)
circuitMatrix[i][j] = origMatrix[i][j];
}
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.doStep();
}
if (stopMessage != null)
return;
boolean printit = debugprint;
debugprint = false;
for (j = 0; j != circuitMatrixSize; j++) {
for (i = 0; i != circuitMatrixSize; i++) {
double x = circuitMatrix[i][j];
if (Double.isNaN(x) || Double.isInfinite(x)) {
stop("nan/infinite matrix!", null);
return;
}
}
}
if (printit) {
for (j = 0; j != circuitMatrixSize; j++) {
for (i = 0; i != circuitMatrixSize; i++)
System.out.print(circuitMatrix[j][i] + ",");
System.out.print(" " + circuitRightSide[j] + "\n");
}
System.out.print("\n");
}
if (circuitNonLinear) {
if (converged && subiter > 0)
break;
if (!lu_factor(circuitMatrix, circuitMatrixSize,
circuitPermute)) {
stop("Singular matrix!", null);
return;
}
}
lu_solve(circuitMatrix, circuitMatrixSize, circuitPermute,
circuitRightSide);
for (j = 0; j != circuitMatrixFullSize; j++) {
RowInfo ri = circuitRowInfo[j];
double res = 0;
if (ri.type == RowInfo.ROW_CONST)
res = ri.value;
else
res = circuitRightSide[ri.mapCol];
/*System.out.println(j + " " + res + " " +
ri.type + " " + ri.mapCol);*/
if (Double.isNaN(res)) {
converged = false;
//debugprint = true;
break;
}
if (j < nodeList.size()-1) {
CircuitNode cn = getCircuitNode(j+1);
for (k = 0; k != cn.links.size(); k++) {
CircuitNodeLink cnl = (CircuitNodeLink)
cn.links.elementAt(k);
cnl.elm.setNodeVoltage(cnl.num, res);
}
} else {
int ji = j-(nodeList.size()-1);
//System.out.println("setting vsrc " + ji + " to " + res);
voltageSources[ji].setCurrent(ji, res);
}
}
if (!circuitNonLinear)
break;
}
if (subiter > 5)
System.out.print("converged after " + subiter + " iterations\n");
if (subiter == subiterCount) {
stop("Convergence failed!", null);
break;
}
t += timeStep;
for (i = 0; i != scopeCount; i++)
scopes[i].timeStep();
tm = System.currentTimeMillis();
lit = tm;
if (iter*1000 >= steprate*(tm-lastIterTime) ||
(tm-lastFrameTime > 500))
break;
}
lastIterTime = lit;
//System.out.println((System.currentTimeMillis()-lastFrameTime)/(double) iter);
}
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
void editFuncPoint(int x, int y) {
// XXX
cv.repaint(pause);
}
public void componentHidden(ComponentEvent e){}
public void componentMoved(ComponentEvent e){}
public void componentShown(ComponentEvent e) {
cv.repaint();
}
public void componentResized(ComponentEvent e) {
handleResize();
cv.repaint(100);
}
public void actionPerformed(ActionEvent e) {
String ac = e.getActionCommand();
if (e.getSource() == resetButton) {
int i;
// on IE, drawImage() stops working inexplicably every once in
// a while. Recreating it fixes the problem, so we do that here.
dbimage = main.createImage(winSize.width, winSize.height);
for (i = 0; i != elmList.size(); i++)
getElm(i).reset();
for (i = 0; i != scopeCount; i++)
scopes[i].resetGraph();
analyzeFlag = true;
t = 0;
stoppedCheck.setState(false);
cv.repaint();
}
if (e.getSource() == dumpMatrixButton)
dumpMatrix = true;
if (e.getSource() == exportItem)
doExport(false);
if (e.getSource() == optionsItem)
doEdit(new EditOptions(this));
if (e.getSource() == importItem)
doImport();
if (e.getSource() == exportLinkItem)
doExport(true);
if (e.getSource() == undoItem)
doUndo();
if (e.getSource() == redoItem)
doRedo();
if (ac.compareTo("Cut") == 0) {
if (e.getSource() != elmCutMenuItem)
menuElm = null;
doCut();
}
if (ac.compareTo("Copy") == 0) {
if (e.getSource() != elmCopyMenuItem)
menuElm = null;
doCopy();
}
if (ac.compareTo("Paste") == 0)
doPaste();
if (e.getSource() == selectAllItem)
doSelectAll();
if (e.getSource() == exitItem) {
destroyFrame();
return;
}
if (ac.compareTo("stackAll") == 0)
stackAll();
if (ac.compareTo("unstackAll") == 0)
unstackAll();
if (e.getSource() == elmEditMenuItem)
doEdit(menuElm);
if (ac.compareTo("Delete") == 0) {
if (e.getSource() != elmDeleteMenuItem)
menuElm = null;
doDelete();
}
if (e.getSource() == elmScopeMenuItem && menuElm != null) {
int i;
for (i = 0; i != scopeCount; i++)
if (scopes[i].elm == null)
break;
if (i == scopeCount) {
if (scopeCount == scopes.length)
return;
scopeCount++;
scopes[i] = new Scope(this);
scopes[i].position = i;
handleResize();
}
scopes[i].setElm(menuElm);
}
if (menuScope != -1) {
if (ac.compareTo("remove") == 0)
scopes[menuScope].setElm(null);
if (ac.compareTo("speed2") == 0)
scopes[menuScope].speedUp();
if (ac.compareTo("speed1/2") == 0)
scopes[menuScope].slowDown();
if (ac.compareTo("scale") == 0)
scopes[menuScope].adjustScale(.5);
if (ac.compareTo("maxscale") == 0)
scopes[menuScope].adjustScale(1e-50);
if (ac.compareTo("stack") == 0)
stackScope(menuScope);
if (ac.compareTo("unstack") == 0)
unstackScope(menuScope);
if (ac.compareTo("selecty") == 0)
scopes[menuScope].selectY();
if (ac.compareTo("reset") == 0)
scopes[menuScope].resetGraph();
cv.repaint();
}
if (ac.indexOf("setup ") == 0) {
pushUndo();
readSetupFile(ac.substring(6),
((MenuItem) e.getSource()).getLabel());
}
}
void stackScope(int s) {
if (s == 0) {
if (scopeCount < 2)
return;
s = 1;
}
if (scopes[s].position == scopes[s-1].position)
return;
scopes[s].position = scopes[s-1].position;
for (s++; s < scopeCount; s++)
scopes[s].position--;
}
void unstackScope(int s) {
if (s == 0) {
if (scopeCount < 2)
return;
s = 1;
}
if (scopes[s].position != scopes[s-1].position)
return;
for (; s < scopeCount; s++)
scopes[s].position++;
}
void stackAll() {
int i;
for (i = 0; i != scopeCount; i++) {
scopes[i].position = 0;
scopes[i].showMax = scopes[i].showMin = false;
}
}
void unstackAll() {
int i;
for (i = 0; i != scopeCount; i++) {
scopes[i].position = i;
scopes[i].showMax = true;
}
}
void doEdit(Editable eable) {
clearSelection();
pushUndo();
if (editDialog != null) {
requestFocus();
editDialog.setVisible(false);
editDialog = null;
}
editDialog = new EditDialog(eable, this);
editDialog.show();
}
void doImport() {
if (impDialog == null)
impDialog = ImportExportDialogFactory.Create(this,
ImportExportDialog.Action.IMPORT);
// impDialog = new ImportExportClipboardDialog(this,
// ImportExportDialog.Action.IMPORT);
pushUndo();
impDialog.execute();
}
void doExport(boolean url)
{
String dump = dumpCircuit();
if (url)
dump = baseURL + "#" + URLEncoder.encode(dump);
if (expDialog == null) {
expDialog = ImportExportDialogFactory.Create(this,
ImportExportDialog.Action.EXPORT);
// expDialog = new ImportExportClipboardDialog(this,
// ImportExportDialog.Action.EXPORT);
}
expDialog.setDump(dump);
expDialog.execute();
}
String dumpCircuit() {
int i;
int f = (dotsCheckItem.getState()) ? 1 : 0;
f |= (smallGridCheckItem.getState()) ? 2 : 0;
f |= (voltsCheckItem.getState()) ? 0 : 4;
f |= (powerCheckItem.getState()) ? 8 : 0;
f |= (showValuesCheckItem.getState()) ? 0 : 16;
// 32 = linear scale in afilter
String dump = "$ " + f + " " +
timeStep + " " + getIterCount() + " " +
currentBar.getValue() + " " + CircuitElm.voltageRange + " " +
powerBar.getValue() + "\n";
for (i = 0; i != elmList.size(); i++)
dump += getElm(i).dump() + "\n";
for (i = 0; i != scopeCount; i++) {
String d = scopes[i].dump();
if (d != null)
dump += d + "\n";
}
if (hintType != -1)
dump += "h " + hintType + " " + hintItem1 + " " +
hintItem2 + "\n";
return dump;
}
public void adjustmentValueChanged(AdjustmentEvent e) {
System.out.print(((Scrollbar) e.getSource()).getValue() + "\n");
}
ByteArrayOutputStream readUrlData(URL url) throws java.io.IOException {
Object o = url.getContent();
FilterInputStream fis = (FilterInputStream) o;
ByteArrayOutputStream ba = new ByteArrayOutputStream(fis.available());
int blen = 1024;
byte b[] = new byte[blen];
while (true) {
int len = fis.read(b);
if (len <= 0)
break;
ba.write(b, 0, len);
}
return ba;
}
URL getCodeBase() {
try {
if (applet != null)
return applet.getCodeBase();
File f = new File(".");
return new URL("file:" + f.getCanonicalPath() + "/");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
void getSetupList(Menu menu, boolean retry) {
Menu stack[] = new Menu[6];
int stackptr = 0;
stack[stackptr++] = menu;
try {
// hausen: if setuplist.txt does not exist in the same
// directory, try reading from the jar file
ByteArrayOutputStream ba = null;
try {
URL url = new URL(getCodeBase() + "setuplist.txt");
ba = readUrlData(url);
} catch (Exception e) {
URL url = getClass().getClassLoader().getResource("setuplist.txt");
ba = readUrlData(url);
}
// /hausen
byte b[] = ba.toByteArray();
int len = ba.size();
int p;
if (len == 0 || b[0] != '#') {
// got a redirect, try again
getSetupList(menu, true);
return;
}
for (p = 0; p < len; ) {
int l;
for (l = 0; l != len-p; l++)
if (b[l+p] == '\n') {
l++;
break;
}
String line = new String(b, p, l-1);
if (line.charAt(0) == '#')
;
else if (line.charAt(0) == '+') {
Menu n = new Menu(line.substring(1));
menu.add(n);
menu = stack[stackptr++] = n;
} else if (line.charAt(0) == '-') {
menu = stack[--stackptr-1];
} else {
int i = line.indexOf(' ');
if (i > 0) {
String title = line.substring(i+1);
boolean first = false;
if (line.charAt(0) == '>')
first = true;
String file = line.substring(first ? 1 : 0, i);
menu.add(getMenuItem(title, "setup " + file));
if (first && startCircuit == null) {
startCircuit = file;
startLabel = title;
}
}
}
p += l;
}
} catch (Exception e) {
e.printStackTrace();
stop("Can't read setuplist.txt!", null);
}
}
void readSetup(String text) {
readSetup(text, false);
}
void readSetup(String text, boolean retain) {
readSetup(text.getBytes(), text.length(), retain);
titleLabel.setText("untitled");
}
void readSetupFile(String str, String title) {
t = 0;
System.out.println(str);
try {
URL url = new URL(getCodeBase() + "circuits/" + str);
ByteArrayOutputStream ba = readUrlData(url);
readSetup(ba.toByteArray(), ba.size(), false);
} catch (Exception e1) {
try {
URL url = getClass().getClassLoader().getResource("circuits/" + str);
ByteArrayOutputStream ba = readUrlData(url);
readSetup(ba.toByteArray(), ba.size(), false);
} catch (Exception e) {
e.printStackTrace();
stop("Unable to read " + str + "!", null);
}
}
titleLabel.setText(title);
}
void readSetup(byte b[], int len, boolean retain) {
int i;
if (!retain) {
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.delete();
}
elmList.removeAllElements();
hintType = -1;
timeStep = 5e-6;
dotsCheckItem.setState(false); // hausen: changed from true to false
smallGridCheckItem.setState(false);
powerCheckItem.setState(false);
voltsCheckItem.setState(true);
showValuesCheckItem.setState(true);
setGrid();
speedBar.setValue(117); // 57
currentBar.setValue(50);
powerBar.setValue(50);
CircuitElm.voltageRange = 5;
scopeCount = 0;
}
cv.repaint();
int p;
for (p = 0; p < len; ) {
int l;
int linelen = 0;
for (l = 0; l != len-p; l++)
if (b[l+p] == '\n' || b[l+p] == '\r') {
linelen = l++;
if (l+p < b.length && b[l+p] == '\n')
l++;
break;
}
String line = new String(b, p, linelen);
StringTokenizer st = new StringTokenizer(line);
while (st.hasMoreTokens()) {
String type = st.nextToken();
int tint = type.charAt(0);
try {
if (tint == 'o') {
Scope sc = new Scope(this);
sc.position = scopeCount;
sc.undump(st);
scopes[scopeCount++] = sc;
break;
}
if (tint == 'h') {
readHint(st);
break;
}
if (tint == '$') {
readOptions(st);
break;
}
if (tint == '%' || tint == '?' || tint == 'B') {
// ignore afilter-specific stuff
break;
}
if (tint >= '0' && tint <= '9')
tint = new Integer(type).intValue();
int x1 = new Integer(st.nextToken()).intValue();
int y1 = new Integer(st.nextToken()).intValue();
int x2 = new Integer(st.nextToken()).intValue();
int y2 = new Integer(st.nextToken()).intValue();
int f = new Integer(st.nextToken()).intValue();
CircuitElm ce = null;
Class cls = dumpTypes[tint];
if (cls == null) {
System.out.println("unrecognized dump type: " + type);
break;
}
// find element class
Class carr[] = new Class[6];
//carr[0] = getClass();
carr[0] = carr[1] = carr[2] = carr[3] = carr[4] =
int.class;
carr[5] = StringTokenizer.class;
Constructor cstr = null;
cstr = cls.getConstructor(carr);
// invoke constructor with starting coordinates
Object oarr[] = new Object[6];
//oarr[0] = this;
oarr[0] = new Integer(x1);
oarr[1] = new Integer(y1);
oarr[2] = new Integer(x2);
oarr[3] = new Integer(y2);
oarr[4] = new Integer(f );
oarr[5] = st;
ce = (CircuitElm) cstr.newInstance(oarr);
ce.setPoints();
elmList.addElement(ce);
} catch (java.lang.reflect.InvocationTargetException ee) {
ee.getTargetException().printStackTrace();
break;
} catch (Exception ee) {
ee.printStackTrace();
break;
}
break;
}
p += l;
}
enableItems();
if (!retain)
handleResize(); // for scopes
needAnalyze();
}
void readHint(StringTokenizer st) {
hintType = new Integer(st.nextToken()).intValue();
hintItem1 = new Integer(st.nextToken()).intValue();
hintItem2 = new Integer(st.nextToken()).intValue();
}
void readOptions(StringTokenizer st) {
int flags = new Integer(st.nextToken()).intValue();
dotsCheckItem.setState((flags & 1) != 0);
smallGridCheckItem.setState((flags & 2) != 0);
voltsCheckItem.setState((flags & 4) == 0);
powerCheckItem.setState((flags & 8) == 8);
showValuesCheckItem.setState((flags & 16) == 0);
timeStep = new Double (st.nextToken()).doubleValue();
double sp = new Double(st.nextToken()).doubleValue();
int sp2 = (int) (Math.log(10*sp)*24+61.5);
//int sp2 = (int) (Math.log(sp)*24+1.5);
speedBar.setValue(sp2);
currentBar.setValue(new Integer(st.nextToken()).intValue());
CircuitElm.voltageRange = new Double (st.nextToken()).doubleValue();
try {
powerBar.setValue(new Integer(st.nextToken()).intValue());
} catch (Exception e) {
}
setGrid();
}
int snapGrid(int x) {
return (x+gridRound) & gridMask;
}
boolean doSwitch(int x, int y) {
if (mouseElm == null || !(mouseElm instanceof SwitchElm))
return false;
SwitchElm se = (SwitchElm) mouseElm;
se.toggle();
if (se.momentary)
heldSwitchElm = se;
needAnalyze();
return true;
}
int locateElm(CircuitElm elm) {
int i;
for (i = 0; i != elmList.size(); i++)
if (elm == elmList.elementAt(i))
return i;
return -1;
}
public void mouseDragged(MouseEvent e) {
// ignore right mouse button with no modifiers (needed on PC)
if ((e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) {
int ex = e.getModifiersEx();
if ((ex & (MouseEvent.META_DOWN_MASK|
MouseEvent.SHIFT_DOWN_MASK|
MouseEvent.CTRL_DOWN_MASK|
MouseEvent.ALT_DOWN_MASK)) == 0)
return;
}
if (!circuitArea.contains(e.getX(), e.getY()))
return;
if (dragElm != null)
dragElm.drag(e.getX(), e.getY());
boolean success = true;
switch (tempMouseMode) {
case MODE_DRAG_ALL:
dragAll(snapGrid(e.getX()), snapGrid(e.getY()));
break;
case MODE_DRAG_ROW:
dragRow(snapGrid(e.getX()), snapGrid(e.getY()));
break;
case MODE_DRAG_COLUMN:
dragColumn(snapGrid(e.getX()), snapGrid(e.getY()));
break;
case MODE_DRAG_POST:
if (mouseElm != null)
dragPost(snapGrid(e.getX()), snapGrid(e.getY()));
break;
case MODE_SELECT:
if (mouseElm == null)
selectArea(e.getX(), e.getY());
else {
tempMouseMode = MODE_DRAG_SELECTED;
success = dragSelected(e.getX(), e.getY());
}
break;
case MODE_DRAG_SELECTED:
success = dragSelected(e.getX(), e.getY());
break;
}
dragging = true;
if (success) {
if (tempMouseMode == MODE_DRAG_SELECTED && mouseElm instanceof GraphicElm ) {
dragX = e.getX(); dragY = e.getY();
} else {
dragX = snapGrid(e.getX()); dragY = snapGrid(e.getY());
}
}
cv.repaint(pause);
}
void dragAll(int x, int y) {
int dx = x-dragX;
int dy = y-dragY;
if (dx == 0 && dy == 0)
return;
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.move(dx, dy);
}
removeZeroLengthElements();
}
void dragRow(int x, int y) {
int dy = y-dragY;
if (dy == 0)
return;
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce.y == dragY)
ce.movePoint(0, 0, dy);
if (ce.y2 == dragY)
ce.movePoint(1, 0, dy);
}
removeZeroLengthElements();
}
void dragColumn(int x, int y) {
int dx = x-dragX;
if (dx == 0)
return;
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce.x == dragX)
ce.movePoint(0, dx, 0);
if (ce.x2 == dragX)
ce.movePoint(1, dx, 0);
}
removeZeroLengthElements();
}
boolean dragSelected(int x, int y) {
boolean me = false;
if (mouseElm != null && !mouseElm.isSelected())
mouseElm.setSelected(me = true);
// snap grid, unless we're only dragging text elements
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if ( ce.isSelected() && !(ce instanceof GraphicElm) )
break;
}
if (i != elmList.size()) {
x = snapGrid(x);
y = snapGrid(y);
}
int dx = x-dragX;
int dy = y-dragY;
if (dx == 0 && dy == 0) {
// don't leave mouseElm selected if we selected it above
if (me)
mouseElm.setSelected(false);
return false;
}
boolean allowed = true;
// check if moves are allowed
for (i = 0; allowed && i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce.isSelected() && !ce.allowMove(dx, dy))
allowed = false;
}
if (allowed) {
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce.isSelected())
ce.move(dx, dy);
}
needAnalyze();
}
// don't leave mouseElm selected if we selected it above
if (me)
mouseElm.setSelected(false);
return allowed;
}
void dragPost(int x, int y) {
if (draggingPost == -1) {
draggingPost =
(distanceSq(mouseElm.x , mouseElm.y , x, y) >
distanceSq(mouseElm.x2, mouseElm.y2, x, y)) ? 1 : 0;
}
int dx = x-dragX;
int dy = y-dragY;
if (dx == 0 && dy == 0)
return;
mouseElm.movePoint(draggingPost, dx, dy);
needAnalyze();
}
void selectArea(int x, int y) {
int x1 = min(x, initDragX);
int x2 = max(x, initDragX);
int y1 = min(y, initDragY);
int y2 = max(y, initDragY);
selectedArea = new Rectangle(x1, y1, x2-x1, y2-y1);
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.selectRect(selectedArea);
}
}
void setSelectedElm(CircuitElm cs) {
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.setSelected(ce == cs);
}
mouseElm = cs;
}
void removeZeroLengthElements() {
int i;
boolean changed = false;
for (i = elmList.size()-1; i >= 0; i--) {
CircuitElm ce = getElm(i);
if (ce.x == ce.x2 && ce.y == ce.y2) {
elmList.removeElementAt(i);
ce.delete();
changed = true;
}
}
needAnalyze();
}
public void mouseMoved(MouseEvent e) {
if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0)
return;
int x = e.getX();
int y = e.getY();
dragX = snapGrid(x); dragY = snapGrid(y);
draggingPost = -1;
int i;
CircuitElm origMouse = mouseElm;
mouseElm = null;
mousePost = -1;
plotXElm = plotYElm = null;
int bestDist = 100000;
int bestArea = 100000;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
if (ce.boundingBox.contains(x, y)) {
int j;
int area = ce.boundingBox.width * ce.boundingBox.height;
int jn = ce.getPostCount();
if (jn > 2)
jn = 2;
for (j = 0; j != jn; j++) {
Point pt = ce.getPost(j);
int dist = distanceSq(x, y, pt.x, pt.y);
// if multiple elements have overlapping bounding boxes,
// we prefer selecting elements that have posts close
// to the mouse pointer and that have a small bounding
// box area.
if (dist <= bestDist && area <= bestArea) {
bestDist = dist;
bestArea = area;
mouseElm = ce;
}
}
if (ce.getPostCount() == 0)
mouseElm = ce;
}
}
scopeSelected = -1;
if (mouseElm == null) {
for (i = 0; i != scopeCount; i++) {
Scope s = scopes[i];
if (s.rect.contains(x, y)) {
s.select();
scopeSelected = i;
}
}
// the mouse pointer was not in any of the bounding boxes, but we
// might still be close to a post
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
int j;
int jn = ce.getPostCount();
for (j = 0; j != jn; j++) {
Point pt = ce.getPost(j);
int dist = distanceSq(x, y, pt.x, pt.y);
if (distanceSq(pt.x, pt.y, x, y) < 26) {
mouseElm = ce;
mousePost = j;
break;
}
}
}
} else {
mousePost = -1;
// look for post close to the mouse pointer
for (i = 0; i != mouseElm.getPostCount(); i++) {
Point pt = mouseElm.getPost(i);
if (distanceSq(pt.x, pt.y, x, y) < 26)
mousePost = i;
}
}
if (mouseElm != origMouse)
cv.repaint();
}
int distanceSq(int x1, int y1, int x2, int y2) {
x2 -= x1;
y2 -= y1;
return x2*x2+y2*y2;
}
public void mouseClicked(MouseEvent e) {
if ( e.getClickCount() == 2 && !didSwitch )
doEditMenu(e);
if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
if (mouseMode == MODE_SELECT || mouseMode == MODE_DRAG_SELECTED)
clearSelection();
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
scopeSelected = -1;
mouseElm = plotXElm = plotYElm = null;
cv.repaint();
}
public void mousePressed(MouseEvent e) {
didSwitch = false;
System.out.println(e.getModifiers());
int ex = e.getModifiersEx();
if ((ex & (MouseEvent.META_DOWN_MASK|
MouseEvent.SHIFT_DOWN_MASK)) == 0 && e.isPopupTrigger()) {
doPopupMenu(e);
return;
}
if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
// left mouse
tempMouseMode = mouseMode;
if ((ex & MouseEvent.ALT_DOWN_MASK) != 0 &&
(ex & MouseEvent.META_DOWN_MASK) != 0)
tempMouseMode = MODE_DRAG_COLUMN;
else if ((ex & MouseEvent.ALT_DOWN_MASK) != 0 &&
(ex & MouseEvent.SHIFT_DOWN_MASK) != 0)
tempMouseMode = MODE_DRAG_ROW;
else if ((ex & MouseEvent.SHIFT_DOWN_MASK) != 0)
tempMouseMode = MODE_SELECT;
else if ((ex & MouseEvent.ALT_DOWN_MASK) != 0)
tempMouseMode = MODE_DRAG_ALL;
else if ((ex & (MouseEvent.CTRL_DOWN_MASK|
MouseEvent.META_DOWN_MASK)) != 0)
tempMouseMode = MODE_DRAG_POST;
} else if ((e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) {
// right mouse
if ((ex & MouseEvent.SHIFT_DOWN_MASK) != 0)
tempMouseMode = MODE_DRAG_ROW;
else if ((ex & (MouseEvent.CTRL_DOWN_MASK|
MouseEvent.META_DOWN_MASK)) != 0)
tempMouseMode = MODE_DRAG_COLUMN;
else
return;
}
if (tempMouseMode != MODE_SELECT && tempMouseMode != MODE_DRAG_SELECTED)
clearSelection();
if (mouseMode == MODE_SELECT && doSwitch(e.getX(), e.getY()))
{
didSwitch = true;
return;
}
pushUndo();
initDragX = e.getX();
initDragY = e.getY();
dragging = true;
if (tempMouseMode != MODE_ADD_ELM || addingClass == null)
return;
int x0 = snapGrid(e.getX());
int y0 = snapGrid(e.getY());
if (!circuitArea.contains(x0, y0))
return;
dragElm = constructElement(addingClass, x0, y0);
}
CircuitElm constructElement(Class c, int x0, int y0) {
// find element class
Class carr[] = new Class[2];
//carr[0] = getClass();
carr[0] = carr[1] = int.class;
Constructor cstr = null;
try {
cstr = c.getConstructor(carr);
} catch (NoSuchMethodException ee) {
System.out.println("caught NoSuchMethodException " + c);
return null;
} catch (Exception ee) {
ee.printStackTrace();
return null;
}
// invoke constructor with starting coordinates
Object oarr[] = new Object[2];
oarr[0] = new Integer(x0);
oarr[1] = new Integer(y0);
try {
return (CircuitElm) cstr.newInstance(oarr);
} catch (Exception ee) { ee.printStackTrace(); }
return null;
}
// hausen: add doEditMenu
void doEditMenu(MouseEvent e) {
if( mouseElm != null )
doEdit(mouseElm);
}
void doPopupMenu(MouseEvent e) {
menuElm = mouseElm;
menuScope = -1;
if (scopeSelected != -1) {
PopupMenu m = scopes[scopeSelected].getMenu();
menuScope = scopeSelected;
if (m != null)
m.show(e.getComponent(), e.getX(), e.getY());
} else if (mouseElm != null) {
elmEditMenuItem .setEnabled(mouseElm.getEditInfo(0) != null);
elmScopeMenuItem.setEnabled(mouseElm.canViewInScope());
elmMenu.show(e.getComponent(), e.getX(), e.getY());
} else {
doMainMenuChecks(mainMenu);
mainMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
void doMainMenuChecks(Menu m) {
int i;
if (m == optionsMenu)
return;
for (i = 0; i != m.getItemCount(); i++) {
MenuItem mc = m.getItem(i);
if (mc instanceof Menu)
doMainMenuChecks((Menu) mc);
if (mc instanceof CheckboxMenuItem) {
CheckboxMenuItem cmi = (CheckboxMenuItem) mc;
cmi.setState(
mouseModeStr.compareTo(cmi.getActionCommand()) == 0);
}
}
}
public void mouseReleased(MouseEvent e) {
int ex = e.getModifiersEx();
if ((ex & (MouseEvent.SHIFT_DOWN_MASK|MouseEvent.CTRL_DOWN_MASK|
MouseEvent.META_DOWN_MASK)) == 0 && e.isPopupTrigger()) {
doPopupMenu(e);
return;
}
tempMouseMode = mouseMode;
selectedArea = null;
dragging = false;
boolean circuitChanged = false;
if (heldSwitchElm != null) {
heldSwitchElm.mouseUp();
heldSwitchElm = null;
circuitChanged = true;
}
if (dragElm != null) {
// if the element is zero size then don't create it
if (dragElm.x == dragElm.x2 && dragElm.y == dragElm.y2)
dragElm.delete();
else {
elmList.addElement(dragElm);
circuitChanged = true;
}
dragElm = null;
}
if (circuitChanged)
needAnalyze();
if (dragElm != null)
dragElm.delete();
dragElm = null;
cv.repaint();
}
void enableItems() {
if (powerCheckItem.getState()) {
powerBar.enable();
powerLabel.enable();
} else {
powerBar.disable();
powerLabel.disable();
}
enableUndoRedo();
}
public void itemStateChanged(ItemEvent e) {
cv.repaint(pause);
Object mi = e.getItemSelectable();
if (mi == stoppedCheck)
return;
if (mi == smallGridCheckItem)
setGrid();
if (mi == powerCheckItem) {
if (powerCheckItem.getState())
voltsCheckItem.setState(false);
else
voltsCheckItem.setState(true);
}
if (mi == voltsCheckItem && voltsCheckItem.getState())
powerCheckItem.setState(false);
enableItems();
if (menuScope != -1) {
Scope sc = scopes[menuScope];
sc.handleMenu(e, mi);
}
if (mi instanceof CheckboxMenuItem) {
MenuItem mmi = (MenuItem) mi;
int prevMouseMode = mouseMode;
setMouseMode(MODE_ADD_ELM);
String s = mmi.getActionCommand();
if (s.length() > 0)
mouseModeStr = s;
if (s.compareTo("DragAll") == 0)
setMouseMode(MODE_DRAG_ALL);
else if (s.compareTo("DragRow") == 0)
setMouseMode(MODE_DRAG_ROW);
else if (s.compareTo("DragColumn") == 0)
setMouseMode(MODE_DRAG_COLUMN);
else if (s.compareTo("DragSelected") == 0)
setMouseMode(MODE_DRAG_SELECTED);
else if (s.compareTo("DragPost") == 0)
setMouseMode(MODE_DRAG_POST);
else if (s.compareTo("Select") == 0)
setMouseMode(MODE_SELECT);
else if (s.length() > 0) {
try {
addingClass = Class.forName(s);
} catch (Exception ee) {
ee.printStackTrace();
}
}
else
setMouseMode(prevMouseMode);
tempMouseMode = mouseMode;
}
}
void setGrid() {
gridSize = (smallGridCheckItem.getState()) ? 8 : 16;
gridMask = ~(gridSize-1);
gridRound = gridSize/2-1;
}
void pushUndo() {
redoStack.removeAllElements();
String s = dumpCircuit();
if (undoStack.size() > 0 &&
s.compareTo(undoStack.lastElement()) == 0)
return;
undoStack.add(s);
enableUndoRedo();
}
void doUndo() {
if (undoStack.size() == 0)
return;
redoStack.add(dumpCircuit());
String s = undoStack.remove(undoStack.size()-1);
readSetup(s);
enableUndoRedo();
}
void doRedo() {
if (redoStack.size() == 0)
return;
undoStack.add(dumpCircuit());
String s = redoStack.remove(redoStack.size()-1);
readSetup(s);
enableUndoRedo();
}
void enableUndoRedo() {
redoItem.setEnabled(redoStack.size() > 0);
undoItem.setEnabled(undoStack.size() > 0);
}
void setMouseMode(int mode)
{
mouseMode = mode;
if ( mode == MODE_ADD_ELM )
cv.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
else
cv.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
void setMenuSelection() {
if (menuElm != null) {
if (menuElm.selected)
return;
clearSelection();
menuElm.setSelected(true);
}
}
void doCut() {
int i;
pushUndo();
setMenuSelection();
clipboard = "";
for (i = elmList.size()-1; i >= 0; i--) {
CircuitElm ce = getElm(i);
if (ce.isSelected()) {
clipboard += ce.dump() + "\n";
ce.delete();
elmList.removeElementAt(i);
}
}
enablePaste();
needAnalyze();
}
void doDelete() {
int i;
pushUndo();
setMenuSelection();
boolean hasDeleted = false;
for (i = elmList.size()-1; i >= 0; i--) {
CircuitElm ce = getElm(i);
if (ce.isSelected()) {
ce.delete();
elmList.removeElementAt(i);
hasDeleted = true;
}
}
if ( !hasDeleted )
{
for (i = elmList.size()-1; i >= 0; i--) {
CircuitElm ce = getElm(i);
if (ce == mouseElm) {
ce.delete();
elmList.removeElementAt(i);
hasDeleted = true;
mouseElm = null;
break;
}
}
}
if ( hasDeleted )
needAnalyze();
}
void doCopy() {
int i;
clipboard = "";
setMenuSelection();
for (i = elmList.size()-1; i >= 0; i--) {
CircuitElm ce = getElm(i);
if (ce.isSelected())
clipboard += ce.dump() + "\n";
}
enablePaste();
}
void enablePaste() {
pasteItem.setEnabled(clipboard.length() > 0);
}
void doPaste() {
pushUndo();
clearSelection();
int i;
Rectangle oldbb = null;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
Rectangle bb = ce.getBoundingBox();
if (oldbb != null)
oldbb = oldbb.union(bb);
else
oldbb = bb;
}
int oldsz = elmList.size();
readSetup(clipboard, true);
// select new items
Rectangle newbb = null;
for (i = oldsz; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.setSelected(true);
Rectangle bb = ce.getBoundingBox();
if (newbb != null)
newbb = newbb.union(bb);
else
newbb = bb;
}
if (oldbb != null && newbb != null && oldbb.intersects(newbb)) {
// find a place for new items
int dx = 0, dy = 0;
int spacew = circuitArea.width - oldbb.width - newbb.width;
int spaceh = circuitArea.height - oldbb.height - newbb.height;
if (spacew > spaceh)
dx = snapGrid(oldbb.x + oldbb.width - newbb.x + gridSize);
else
dy = snapGrid(oldbb.y + oldbb.height - newbb.y + gridSize);
for (i = oldsz; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.move(dx, dy);
}
// center circuit
handleResize();
}
needAnalyze();
}
void clearSelection() {
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.setSelected(false);
}
}
void doSelectAll() {
int i;
for (i = 0; i != elmList.size(); i++) {
CircuitElm ce = getElm(i);
ce.setSelected(true);
}
}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == 127)
{
doDelete();
return;
}
if (e.getKeyChar() > ' ' && e.getKeyChar() < 127) {
Class c = shortcuts[e.getKeyChar()];
if (c == null)
return;
CircuitElm elm = null;
elm = constructElement(c, 0, 0);
if (elm == null)
return;
setMouseMode(MODE_ADD_ELM);
mouseModeStr = c.getName();
addingClass = c;
}
if (e.getKeyChar() == ' ' || e.getKeyChar() == KeyEvent.VK_ESCAPE) {
setMouseMode(MODE_SELECT);
mouseModeStr = "Select";
}
tempMouseMode = mouseMode;
}
// factors a matrix into upper and lower triangular matrices by
// gaussian elimination. On entry, a[0..n-1][0..n-1] is the
// matrix to be factored. ipvt[] returns an integer vector of pivot
// indices, used in the lu_solve() routine.
boolean lu_factor(double a[][], int n, int ipvt[]) {
double scaleFactors[];
int i,j,k;
scaleFactors = new double[n];
// divide each row by its largest element, keeping track of the
// scaling factors
for (i = 0; i != n; i++) {
double largest = 0;
for (j = 0; j != n; j++) {
double x = Math.abs(a[i][j]);
if (x > largest)
largest = x;
}
// if all zeros, it's a singular matrix
if (largest == 0)
return false;
scaleFactors[i] = 1.0/largest;
}
// use Crout's method; loop through the columns
for (j = 0; j != n; j++) {
// calculate upper triangular elements for this column
for (i = 0; i != j; i++) {
double q = a[i][j];
for (k = 0; k != i; k++)
q -= a[i][k]*a[k][j];
a[i][j] = q;
}
// calculate lower triangular elements for this column
double largest = 0;
int largestRow = -1;
for (i = j; i != n; i++) {
double q = a[i][j];
for (k = 0; k != j; k++)
q -= a[i][k]*a[k][j];
a[i][j] = q;
double x = Math.abs(q);
if (x >= largest) {
largest = x;
largestRow = i;
}
}
// pivoting
if (j != largestRow) {
double x;
for (k = 0; k != n; k++) {
x = a[largestRow][k];
a[largestRow][k] = a[j][k];
a[j][k] = x;
}
scaleFactors[largestRow] = scaleFactors[j];
}
// keep track of row interchanges
ipvt[j] = largestRow;
// avoid zeros
if (a[j][j] == 0.0) {
System.out.println("avoided zero");
a[j][j]=1e-18;
}
if (j != n-1) {
double mult = 1.0/a[j][j];
for (i = j+1; i != n; i++)
a[i][j] *= mult;
}
}
return true;
}
// Solves the set of n linear equations using a LU factorization
// previously performed by lu_factor. On input, b[0..n-1] is the right
// hand side of the equations, and on output, contains the solution.
void lu_solve(double a[][], int n, int ipvt[], double b[]) {
int i;
// find first nonzero b element
for (i = 0; i != n; i++) {
int row = ipvt[i];
double swap = b[row];
b[row] = b[i];
b[i] = swap;
if (swap != 0)
break;
}
int bi = i++;
for (; i < n; i++) {
int row = ipvt[i];
int j;
double tot = b[row];
b[row] = b[i];
// forward substitution using the lower triangular matrix
for (j = bi; j < i; j++)
tot -= a[i][j]*b[j];
b[i] = tot;
}
for (i = n-1; i >= 0; i--) {
double tot = b[i];
// back-substitution using the upper triangular matrix
int j;
for (j = i+1; j != n; j++)
tot -= a[i][j]*b[j];
b[i] = tot/a[i][i];
}
}
}
================================================
FILE: src/Circuit.java
================================================
// Circuit.java (c) 2005,2008 by Paul Falstad, www.falstad.com
import java.io.InputStream;
import java.awt.*;
import java.awt.image.*;
import java.applet.Applet;
import java.util.Vector;
import java.io.File;
import java.util.Random;
import java.util.Arrays;
import java.lang.Math;
import java.net.URL;
import java.awt.event.*;
import java.io.FilterInputStream;
import java.io.ByteArrayOutputStream;
import java.util.StringTokenizer;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
public class Circuit extends Applet implements ComponentListener {
static CirSim ogf;
boolean finished = false;
void destroyFrame() {
if (ogf != null)
ogf.dispose();
ogf = null;
repaint();
finished = true;
}
boolean started = false;
public void init() {
addComponentListener(this);
}
public static void main(String args[]) {
ogf = new CirSim(null);
ogf.init();
}
public void showFrame() {
if ( finished )
{
repaint();
return;
}
if (ogf == null) {
started = true;
ogf = new CirSim(this);
ogf.init();
}
ogf.setVisible(true);
repaint();
}
public void hideFrame() {
if ( finished )
return;
ogf.setVisible(false);
repaint();
}
public void toggleSwitch(int x) { ogf.toggleSwitch(x); }
public void paint(Graphics g) {
String s = "Applet is open in a separate window.";
if ( ogf != null && !ogf.isVisible() )
s = "Applet window is hidden.";
if (!started)
s = "Applet is starting.";
else if (ogf == null || finished)
s = "Applet is finished.";
else if (ogf != null && ogf.useFrame)
ogf.triggerShow();
g.drawString(s, 10, 30);
}
public void componentHidden(ComponentEvent e){}
public void componentMoved(ComponentEvent e){}
public void componentShown(ComponentEvent e) { showFrame(); }
public void componentResized(ComponentEvent e) {
if (ogf != null)
ogf.componentResized(e);
}
public void destroy() {
if (ogf != null)
ogf.dispose();
ogf = null;
repaint();
}
};
================================================
FILE: src/CircuitCanvas.java
================================================
import java.awt.*;
class CircuitCanvas extends Canvas {
CirSim pg;
CircuitCanvas(CirSim p) {
pg = p;
}
public Dimension getPreferredSize() {
return new Dimension(300,400);
}
public void update(Graphics g) {
pg.updateCircuit(g);
}
public void paint(Graphics g) {
pg.updateCircuit(g);
}
};
================================================
FILE: src/CircuitElm.java
================================================
import java.awt.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public abstract class CircuitElm implements Editable {
static double voltageRange = 5;
static int colorScaleCount = 32;
static Color colorScale[];
static double currentMult, powerMult;
static Point ps1, ps2;
static CirSim sim;
static Color whiteColor, selectColor, lightGrayColor;
static Font unitsFont;
public static NumberFormat showFormat, shortFormat, noCommaFormat;
static final double pi = 3.14159265358979323846;
int x, y, x2, y2, flags, nodes[], voltSource;
int dx, dy, dsign;
double dn, dpx1, dpy1;
Point point1, point2, lead1, lead2;
double volts[];
double current, curcount;
Rectangle boundingBox;
boolean noDiagonal;
public boolean selected;
int getDumpType() { return 0; }
Class getDumpClass() { return getClass(); }
int getDefaultFlags() { return 0; }
static void initClass(CirSim s) {
unitsFont = new Font("SansSerif", 0, 10);
sim = s;
colorScale = new Color[colorScaleCount];
int i;
for (i = 0; i != colorScaleCount; i++) {
double v = i*2./colorScaleCount - 1;
if (v < 0) {
int n1 = (int) (128*-v)+127;
int n2 = (int) (127*(1+v));
colorScale[i] = new Color(n1, n2, n2);
} else {
int n1 = (int) (128*v)+127;
int n2 = (int) (127*(1-v));
colorScale[i] = new Color(n2, n1, n2);
}
}
ps1 = new Point();
ps2 = new Point();
showFormat = DecimalFormat.getInstance();
showFormat.setMaximumFractionDigits(2);
shortFormat = DecimalFormat.getInstance();
shortFormat.setMaximumFractionDigits(1);
noCommaFormat = DecimalFormat.getInstance();
noCommaFormat.setMaximumFractionDigits(10);
noCommaFormat.setGroupingUsed(false);
}
CircuitElm(int xx, int yy) {
x = x2 = xx;
y = y2 = yy;
flags = getDefaultFlags();
allocNodes();
initBoundingBox();
}
CircuitElm(int xa, int ya, int xb, int yb, int f) {
x = xa; y = ya; x2 = xb; y2 = yb; flags = f;
allocNodes();
initBoundingBox();
}
void initBoundingBox() {
boundingBox = new Rectangle();
boundingBox.setBounds(min(x, x2), min(y, y2),
abs(x2-x)+1, abs(y2-y)+1);
}
void allocNodes() {
nodes = new int[getPostCount()+getInternalNodeCount()];
volts = new double[getPostCount()+getInternalNodeCount()];
}
String dump() {
int t = getDumpType();
return (t < 127 ? ((char)t)+" " : t+" ") + x + " " + y + " " +
x2 + " " + y2 + " " + flags;
}
void reset() {
int i;
for (i = 0; i != getPostCount()+getInternalNodeCount(); i++)
volts[i] = 0;
curcount = 0;
}
void draw(Graphics g) {}
void setCurrent(int x, double c) { current = c; }
double getCurrent() { return current; }
void doStep() {}
void delete() {}
void startIteration() {}
double getPostVoltage(int x) { return volts[x]; }
void setNodeVoltage(int n, double c) {
volts[n] = c;
calculateCurrent();
}
void calculateCurrent() {}
void setPoints() {
dx = x2-x; dy = y2-y;
dn = Math.sqrt(dx*dx+dy*dy);
dpx1 = dy/dn;
dpy1 = -dx/dn;
dsign = (dy == 0) ? sign(dx) : sign(dy);
point1 = new Point(x , y );
point2 = new Point(x2, y2);
}
void calcLeads(int len) {
if (dn < len || len == 0) {
lead1 = point1;
lead2 = point2;
return;
}
lead1 = interpPoint(point1, point2, (dn-len)/(2*dn));
lead2 = interpPoint(point1, point2, (dn+len)/(2*dn));
}
Point interpPoint(Point a, Point b, double f) {
Point p = new Point();
interpPoint(a, b, p, f);
return p;
}
void interpPoint(Point a, Point b, Point c, double f) {
int xpd = b.x-a.x;
int ypd = b.y-a.y;
/*double q = (a.x*(1-f)+b.x*f+.48);
System.out.println(q + " " + (int) q);*/
c.x = (int) Math.floor(a.x*(1-f)+b.x*f+.48);
c.y = (int) Math.floor(a.y*(1-f)+b.y*f+.48);
}
void interpPoint(Point a, Point b, Point c, double f, double g) {
int xpd = b.x-a.x;
int ypd = b.y-a.y;
int gx = b.y-a.y;
int gy = a.x-b.x;
g /= Math.sqrt(gx*gx+gy*gy);
c.x = (int) Math.floor(a.x*(1-f)+b.x*f+g*gx+.48);
c.y = (int) Math.floor(a.y*(1-f)+b.y*f+g*gy+.48);
}
Point interpPoint(Point a, Point b, double f, double g) {
Point p = new Point();
interpPoint(a, b, p, f, g);
return p;
}
void interpPoint2(Point a, Point b, Point c, Point d, double f, double g) {
int xpd = b.x-a.x;
int ypd = b.y-a.y;
int gx = b.y-a.y;
int gy = a.x-b.x;
g /= Math.sqrt(gx*gx+gy*gy);
c.x = (int) Math.floor(a.x*(1-f)+b.x*f+g*gx+.48);
c.y = (int) Math.floor(a.y*(1-f)+b.y*f+g*gy+.48);
d.x = (int) Math.floor(a.x*(1-f)+b.x*f-g*gx+.48);
d.y = (int) Math.floor(a.y*(1-f)+b.y*f-g*gy+.48);
}
void draw2Leads(Graphics g) {
// draw first lead
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, lead1);
// draw second lead
setVoltageColor(g, volts[1]);
drawThickLine(g, lead2, point2);
}
Point [] newPointArray(int n) {
Point a[] = new Point[n];
while (n > 0)
a[--n] = new Point();
return a;
}
void drawDots(Graphics g, Point pa, Point pb, double pos) {
if (sim.stoppedCheck.getState() || pos == 0 || !sim.dotsCheckItem.getState())
return;
int dx = pb.x-pa.x;
int dy = pb.y-pa.y;
double dn = Math.sqrt(dx*dx+dy*dy);
g.setColor(Color.yellow);
int ds = 16;
pos %= ds;
if (pos < 0)
pos += ds;
double di = 0;
for (di = pos; di < dn; di += ds) {
int x0 = (int) (pa.x+di*dx/dn);
int y0 = (int) (pa.y+di*dy/dn);
g.fillRect(x0-1, y0-1, 4, 4);
}
}
Polygon calcArrow(Point a, Point b, double al, double aw) {
Polygon poly = new Polygon();
Point p1 = new Point();
Point p2 = new Point();
int adx = b.x-a.x;
int ady = b.y-a.y;
double l = Math.sqrt(adx*adx+ady*ady);
poly.addPoint(b.x, b.y);
interpPoint2(a, b, p1, p2, 1-al/l, aw);
poly.addPoint(p1.x, p1.y);
poly.addPoint(p2.x, p2.y);
return poly;
}
Polygon calcArrowReverse(Point a, Point b, double al, double aw) {
Polygon poly = new Polygon();
Point p1 = new Point();
Point p2 = new Point();
double adx = b.x-a.x;
double ady = b.y-a.y;
double l = Math.sqrt(adx*adx+ady*ady);
if (l > 0)
{
adx /= l;
ady /= l;
double bdx = -ady; // orthogonal unit vector
double bdy = adx; //
poly.addPoint((int)Math.round(b.x+1 - adx*al),
(int)Math.round(b.y+1 - ady*al));
poly.addPoint((int)Math.round(b.x+1 - bdx*al),
(int)Math.round(b.y+1 - bdy*aw));
poly.addPoint((int)Math.round(b.x+1 + bdx*al),
(int)Math.round(b.y+1 + bdy*aw));
}
return poly;
}
Polygon createPolygon(Point a, Point b, Point c) {
Polygon p = new Polygon();
p.addPoint(a.x, a.y);
p.addPoint(b.x, b.y);
p.addPoint(c.x, c.y);
return p;
}
Polygon createPolygon(Point a, Point b, Point c, Point d) {
Polygon p = new Polygon();
p.addPoint(a.x, a.y);
p.addPoint(b.x, b.y);
p.addPoint(c.x, c.y);
p.addPoint(d.x, d.y);
return p;
}
Polygon createPolygon(Point a[]) {
Polygon p = new Polygon();
int i;
for (i = 0; i != a.length; i++)
p.addPoint(a[i].x, a[i].y);
return p;
}
void drag(int xx, int yy) {
xx = sim.snapGrid(xx);
yy = sim.snapGrid(yy);
if (noDiagonal) {
if (Math.abs(x-xx) < Math.abs(y-yy)) {
xx = x;
} else {
yy = y;
}
}
x2 = xx; y2 = yy;
setPoints();
}
void move(int dx, int dy) {
x += dx; y += dy; x2 += dx; y2 += dy;
boundingBox.move(dx, dy);
setPoints();
}
// determine if moving this element by (dx,dy) will put it on top of another element
boolean allowMove(int dx, int dy) {
int nx = x+dx;
int ny = y+dy;
int nx2 = x2+dx;
int ny2 = y2+dy;
int i;
for (i = 0; i != sim.elmList.size(); i++) {
CircuitElm ce = sim.getElm(i);
if (ce.x == nx && ce.y == ny && ce.x2 == nx2 && ce.y2 == ny2)
return false;
if (ce.x == nx2 && ce.y == ny2 && ce.x2 == nx && ce.y2 == ny)
return false;
}
return true;
}
void movePoint(int n, int dx, int dy) {
if (n == 0) {
x += dx; y += dy;
} else {
x2 += dx; y2 += dy;
}
setPoints();
}
void drawPosts(Graphics g) {
int i;
for (i = 0; i != getPostCount(); i++) {
Point p = getPost(i);
drawPost(g, p.x, p.y, nodes[i]);
}
}
void stamp() {}
int getVoltageSourceCount() { return 0; }
int getInternalNodeCount() { return 0; }
void setNode(int p, int n) { nodes[p] = n; }
void setVoltageSource(int n, int v) { voltSource = v; }
int getVoltageSource() { return voltSource; }
double getVoltageDiff() {
return volts[0] - volts[1];
}
boolean nonLinear() { return false; }
int getPostCount() { return 2; }
int getNode(int n) { return nodes[n]; }
Point getPost(int n) {
return (n == 0) ? point1 : (n == 1) ? point2 : null;
}
void drawPost(Graphics g, int x0, int y0, int n) {
if (sim.dragElm == null && !needsHighlight() &&
sim.getCircuitNode(n).links.size() == 2)
return;
if (sim.mouseMode == CirSim.MODE_DRAG_ROW ||
sim.mouseMode == CirSim.MODE_DRAG_COLUMN)
return;
drawPost(g, x0, y0);
}
void drawPost(Graphics g, int x0, int y0) {
g.setColor(whiteColor);
g.fillOval(x0-3, y0-3, 7, 7);
}
void setBbox(int x1, int y1, int x2, int y2) {
if (x1 > x2) { int q = x1; x1 = x2; x2 = q; }
if (y1 > y2) { int q = y1; y1 = y2; y2 = q; }
boundingBox.setBounds(x1, y1, x2-x1+1, y2-y1+1);
}
void setBbox(Point p1, Point p2, double w) {
setBbox(p1.x, p1.y, p2.x, p2.y);
int gx = p2.y-p1.y;
int gy = p1.x-p2.x;
int dpx = (int) (dpx1*w);
int dpy = (int) (dpy1*w);
adjustBbox(p1.x+dpx, p1.y+dpy, p1.x-dpx, p1.y-dpy);
}
void adjustBbox(int x1, int y1, int x2, int y2) {
if (x1 > x2) { int q = x1; x1 = x2; x2 = q; }
if (y1 > y2) { int q = y1; y1 = y2; y2 = q; }
x1 = min(boundingBox.x, x1);
y1 = min(boundingBox.y, y1);
x2 = max(boundingBox.x+boundingBox.width-1, x2);
y2 = max(boundingBox.y+boundingBox.height-1, y2);
boundingBox.setBounds(x1, y1, x2-x1, y2-y1);
}
void adjustBbox(Point p1, Point p2) {
adjustBbox(p1.x, p1.y, p2.x, p2.y);
}
boolean isCenteredText() { return false; }
void drawCenteredText(Graphics g, String s, int x, int y, boolean cx) {
FontMetrics fm = g.getFontMetrics();
int w = fm.stringWidth(s);
if (cx)
x -= w/2;
g.drawString(s, x, y+fm.getAscent()/2);
adjustBbox(x, y-fm.getAscent()/2,
x+w, y+fm.getAscent()/2+fm.getDescent());
}
void drawValues(Graphics g, String s, double hs) {
if (s == null)
return;
g.setFont(unitsFont);
FontMetrics fm = g.getFontMetrics();
int w = fm.stringWidth(s);
g.setColor(whiteColor);
int ya = fm.getAscent()/2;
int xc, yc;
if (this instanceof RailElm || this instanceof SweepElm) {
xc = x2;
yc = y2;
} else {
xc = (x2+x)/2;
yc = (y2+y)/2;
}
int dpx = (int) (dpx1*hs);
int dpy = (int) (dpy1*hs);
if (dpx == 0) {
g.drawString(s, xc-w/2, yc-abs(dpy)-2);
} else {
int xx = xc+abs(dpx)+2;
if (this instanceof VoltageElm || (x < x2 && y > y2))
xx = xc-(w+abs(dpx)+2);
g.drawString(s, xx, yc+dpy+ya);
}
}
void drawCoil(Graphics g, int hs, Point p1, Point p2,
double v1, double v2) {
double len = distance(p1, p2);
int segments = 30; // 10*(int) (len/10);
int i;
double segf = 1./segments;
ps1.setLocation(p1);
for (i = 0; i != segments; i++) {
double cx = (((i+1)*6.*segf) % 2)-1;
double hsx = Math.sqrt(1-cx*cx);
if (hsx < 0)
hsx = -hsx;
interpPoint(p1, p2, ps2, i*segf, hsx*hs);
double v = v1+(v2-v1)*i/segments;
setVoltageColor(g, v);
drawThickLine(g, ps1, ps2);
ps1.setLocation(ps2);
}
}
static void drawThickLine(Graphics g, int x, int y, int x2, int y2) {
g.drawLine(x, y, x2, y2);
g.drawLine(x+1, y, x2+1, y2);
g.drawLine(x, y+1, x2, y2+1);
g.drawLine(x+1, y+1, x2+1, y2+1);
}
static void drawThickLine(Graphics g, Point pa, Point pb) {
g.drawLine(pa.x, pa.y, pb.x, pb.y);
g.drawLine(pa.x+1, pa.y, pb.x+1, pb.y);
g.drawLine(pa.x, pa.y+1, pb.x, pb.y+1);
g.drawLine(pa.x+1, pa.y+1, pb.x+1, pb.y+1);
}
static void drawThickPolygon(Graphics g, int xs[], int ys[], int c) {
int i;
for (i = 0; i != c-1; i++)
drawThickLine(g, xs[i], ys[i], xs[i+1], ys[i+1]);
drawThickLine(g, xs[i], ys[i], xs[0], ys[0]);
}
static void drawThickPolygon(Graphics g, Polygon p) {
drawThickPolygon(g, p.xpoints, p.ypoints, p.npoints);
}
static void drawThickCircle(Graphics g, int cx, int cy, int ri) {
int a;
double m = pi/180;
double r = ri*.98;
for (a = 0; a != 360; a += 20) {
double ax = Math.cos(a*m)*r + cx;
double ay = Math.sin(a*m)*r + cy;
double bx = Math.cos((a+20)*m)*r + cx;
double by = Math.sin((a+20)*m)*r + cy;
drawThickLine(g, (int) ax, (int) ay, (int) bx, (int) by);
}
}
static String getVoltageDText(double v) {
return getUnitText(Math.abs(v), "V");
}
static String getVoltageText(double v) {
return getUnitText(v, "V");
}
static String getUnitText(double v, String u) {
double va = Math.abs(v);
if (va < 1e-14)
return "0 " + u;
if (va < 1e-9)
return showFormat.format(v*1e12) + " p" + u;
if (va < 1e-6)
return showFormat.format(v*1e9) + " n" + u;
if (va < 1e-3)
return showFormat.format(v*1e6) + " " + CirSim.muString + u;
if (va < 1)
return showFormat.format(v*1e3) + " m" + u;
if (va < 1e3)
return showFormat.format(v) + " " + u;
if (va < 1e6)
return showFormat.format(v*1e-3) + " k" + u;
if (va < 1e9)
return showFormat.format(v*1e-6) + " M" + u;
return showFormat.format(v*1e-9) + " G" + u;
}
static String getShortUnitText(double v, String u) {
double va = Math.abs(v);
if (va < 1e-13)
return null;
if (va < 1e-9)
return shortFormat.format(v*1e12) + "p" + u;
if (va < 1e-6)
return shortFormat.format(v*1e9) + "n" + u;
if (va < 1e-3)
return shortFormat.format(v*1e6) + CirSim.muString + u;
if (va < 1)
return shortFormat.format(v*1e3) + "m" + u;
if (va < 1e3)
return shortFormat.format(v) + u;
if (va < 1e6)
return shortFormat.format(v*1e-3) + "k" + u;
if (va < 1e9)
return shortFormat.format(v*1e-6) + "M" + u;
return shortFormat.format(v*1e-9) + "G" + u;
}
static String getCurrentText(double i) {
return getUnitText(i, "A");
}
static String getCurrentDText(double i) {
return getUnitText(Math.abs(i), "A");
}
void updateDotCount() {
curcount = updateDotCount(current, curcount);
}
double updateDotCount(double cur, double cc) {
if (sim.stoppedCheck.getState())
return cc;
double cadd = cur*currentMult;
/*if (cur != 0 && cadd <= .05 && cadd >= -.05)
cadd = (cadd < 0) ? -.05 : .05;*/
cadd %= 8;
/*if (cadd > 8)
cadd = 8;
if (cadd < -8)
cadd = -8;*/
return cc + cadd;
}
void doDots(Graphics g) {
updateDotCount();
if (sim.dragElm != this)
drawDots(g, point1, point2, curcount);
}
void doAdjust() {}
void setupAdjust() {}
void getInfo(String arr[]) {
}
int getBasicInfo(String arr[]) {
arr[1] = "I = " + getCurrentDText(getCurrent());
arr[2] = "Vd = " + getVoltageDText(getVoltageDiff());
return 3;
}
void setVoltageColor(Graphics g, double volts) {
if (needsHighlight()) {
g.setColor(selectColor);
return;
}
if (!sim.voltsCheckItem.getState()) {
if (!sim.powerCheckItem.getState()) // && !conductanceCheckItem.getState())
g.setColor(whiteColor);
return;
}
int c = (int) ((volts+voltageRange)*(colorScaleCount-1)/
(voltageRange*2));
if (c < 0)
c = 0;
if (c >= colorScaleCount)
c = colorScaleCount-1;
g.setColor(colorScale[c]);
}
void setPowerColor(Graphics g, boolean yellow) {
/*if (conductanceCheckItem.getState()) {
setConductanceColor(g, current/getVoltageDiff());
return;
}*/
if (!sim.powerCheckItem.getState())
return;
setPowerColor(g, getPower());
}
void setPowerColor(Graphics g, double w0) {
w0 *= powerMult;
//System.out.println(w);
double w = (w0 < 0) ? -w0 : w0;
if (w > 1)
w = 1;
int rg = 128+(int) (w*127);
int b = (int) (128*(1-w));
/*if (yellow)
g.setColor(new Color(rg, rg, b));
else */
if (w0 > 0)
g.setColor(new Color(rg, b, b));
else
g.setColor(new Color(b, rg, b));
}
void setConductanceColor(Graphics g, double w0) {
w0 *= powerMult;
//System.out.println(w);
double w = (w0 < 0) ? -w0 : w0;
if (w > 1)
w = 1;
int rg = (int) (w*255);
g.setColor(new Color(rg, rg, rg));
}
double getPower() { return getVoltageDiff()*current; }
double getScopeValue(int x) {
return (x == 1) ? getPower() : getVoltageDiff();
}
String getScopeUnits(int x) {
return (x == 1) ? "W" : "V";
}
public EditInfo getEditInfo(int n) { return null; }
public void setEditValue(int n, EditInfo ei) {}
boolean getConnection(int n1, int n2) { return true; }
boolean hasGroundConnection(int n1) { return false; }
boolean isWire() { return false; }
boolean canViewInScope() { return getPostCount() <= 2; }
boolean comparePair(int x1, int x2, int y1, int y2) {
return ((x1 == y1 && x2 == y2) || (x1 == y2 && x2 == y1));
}
boolean needsHighlight() { return sim.mouseElm == this || selected; }
boolean isSelected() { return selected; }
void setSelected(boolean x) { selected = x; }
void selectRect(Rectangle r) {
selected = r.intersects(boundingBox);
}
static int abs(int x) { return x < 0 ? -x : x; }
static int sign(int x) { return (x < 0) ? -1 : (x == 0) ? 0 : 1; }
static int min(int a, int b) { return (a < b) ? a : b; }
static int max(int a, int b) { return (a > b) ? a : b; }
static double distance(Point p1, Point p2) {
double x = p1.x-p2.x;
double y = p1.y-p2.y;
return Math.sqrt(x*x+y*y);
}
Rectangle getBoundingBox() { return boundingBox; }
boolean needsShortcut() { return getShortcut() > 0; }
int getShortcut() { return 0; }
boolean isGraphicElmt() { return false; }
}
================================================
FILE: src/CircuitLayout.java
================================================
import java.awt.*;
class CircuitLayout implements LayoutManager {
public CircuitLayout() {}
public void addLayoutComponent(String name, Component c) {}
public void removeLayoutComponent(Component c) {}
public Dimension preferredLayoutSize(Container target) {
return new Dimension(500, 500);
}
public Dimension minimumLayoutSize(Container target) {
return new Dimension(100,100);
}
public void layoutContainer(Container target) {
Insets insets = target.insets();
int targetw = target.size().width - insets.left - insets.right;
int cw = targetw* 8/10;
int targeth = target.size().height - (insets.top+insets.bottom);
target.getComponent(0).move(insets.left, insets.top);
target.getComponent(0).resize(cw, targeth);
int barwidth = targetw - cw;
cw += insets.left;
int i;
int h = insets.top;
for (i = 1; i < target.getComponentCount(); i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
if (m instanceof Scrollbar)
d.width = barwidth;
if (m instanceof Choice && d.width > barwidth)
d.width = barwidth;
if (m instanceof Label) {
h += d.height/5;
d.width = barwidth;
}
m.move(cw, h);
m.resize(d.width, d.height);
h += d.height;
}
}
}
};
================================================
FILE: src/CircuitNode.java
================================================
import java.util.Vector;
class CircuitNode {
int x, y;
Vector<CircuitNodeLink> links;
boolean internal;
CircuitNode() { links = new Vector<CircuitNodeLink>(); }
}
================================================
FILE: src/CircuitNodeLink.java
================================================
class CircuitNodeLink {
int num;
CircuitElm elm;
}
================================================
FILE: src/ClockElm.java
================================================
class ClockElm extends RailElm {
public ClockElm(int xx, int yy) {
super(xx, yy, WF_SQUARE);
maxVoltage = 2.5;
bias = 2.5;
frequency = 100;
flags |= FLAG_CLOCK;
}
Class getDumpClass() { return RailElm.class; }
int getShortcut() { return 0; }
}
================================================
FILE: src/CounterElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class CounterElm extends ChipElm {
final int FLAG_ENABLE = 2;
public CounterElm(int xx, int yy) { super(xx, yy); }
public CounterElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
}
boolean needsBits() { return true; }
String getChipName() { return "Counter"; }
void setupPins() {
sizeX = 2;
sizeY = bits > 2 ? bits : 2;
pins = new Pin[getPostCount()];
pins[0] = new Pin(0, SIDE_W, "");
pins[0].clock = true;
pins[1] = new Pin(sizeY-1, SIDE_W, "R");
pins[1].bubble = true;
int i;
for (i = 0; i != bits; i++) {
int ii = i+2;
pins[ii] = new Pin(i, SIDE_E, "Q" + (bits-i-1));
pins[ii].output = pins[ii].state = true;
}
if (hasEnable())
pins[bits+2] = new Pin(sizeY-2, SIDE_W, "En");
allocNodes();
}
int getPostCount() {
if (hasEnable())
return bits+3;
return bits+2;
}
boolean hasEnable() { return (flags & FLAG_ENABLE) != 0; }
int getVoltageSourceCount() { return bits; }
void execute() {
boolean en = true;
if (hasEnable())
en = pins[bits+2].value;
if (pins[0].value && !lastClock && en) {
int i;
for (i = bits-1; i >= 0; i--) {
int ii = i+2;
if (!pins[ii].value) {
pins[ii].value = true;
break;
}
pins[ii].value = false;
}
}
if (!pins[1].value) {
int i;
for (i = 0; i != bits; i++)
pins[i+2].value = false;
}
lastClock = pins[0].value;
}
int getDumpType() { return 164; }
}
================================================
FILE: src/CurrentElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class CurrentElm extends CircuitElm {
double currentValue;
public CurrentElm(int xx, int yy) {
super(xx, yy);
currentValue = .01;
}
public CurrentElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
try {
currentValue = new Double(st.nextToken()).doubleValue();
} catch (Exception e) {
currentValue = .01;
}
}
String dump() {
return super.dump() + " " + currentValue;
}
int getDumpType() { return 'i'; }
Polygon arrow;
Point ashaft1, ashaft2, center;
void setPoints() {
super.setPoints();
calcLeads(26);
ashaft1 = interpPoint(lead1, lead2, .25);
ashaft2 = interpPoint(lead1, lead2, .6);
center = interpPoint(lead1, lead2, .5);
Point p2 = interpPoint(lead1, lead2, .75);
arrow = calcArrow(center, p2, 4, 4);
}
void draw(Graphics g) {
int cr = 12;
draw2Leads(g);
setVoltageColor(g, (volts[0]+volts[1])/2);
setPowerColor(g, false);
drawThickCircle(g, center.x, center.y, cr);
drawThickLine(g, ashaft1, ashaft2);
g.fillPolygon(arrow);
setBbox(point1, point2, cr);
doDots(g);
if (sim.showValuesCheckItem.getState()) {
String s = getShortUnitText(currentValue, "A");
if (dx == 0 || dy == 0)
drawValues(g, s, cr);
}
drawPosts(g);
}
void stamp() {
current = currentValue;
sim.stampCurrentSource(nodes[0], nodes[1], current);
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Current (A)", currentValue, 0, .1);
return null;
}
public void setEditValue(int n, EditInfo ei) {
currentValue = ei.value;
}
void getInfo(String arr[]) {
arr[0] = "current source";
getBasicInfo(arr);
}
double getVoltageDiff() {
return volts[1] - volts[0];
}
}
================================================
FILE: src/DACElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class DACElm extends ChipElm {
public DACElm(int xx, int yy) { super(xx, yy); }
public DACElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
}
String getChipName() { return "DAC"; }
boolean needsBits() { return true; }
void setupPins() {
sizeX = 2;
sizeY = bits > 2 ? bits : 2;
pins = new Pin[getPostCount()];
int i;
for (i = 0; i != bits; i++)
pins[i] = new Pin(bits-1-i, SIDE_W, "D" + i);
pins[bits] = new Pin(0, SIDE_E, "O");
pins[bits].output = true;
pins[bits+1] = new Pin(sizeY-1, SIDE_E, "V+");
allocNodes();
}
void doStep() {
int ival = 0;
int i;
for (i = 0; i != bits; i++)
if (volts[i] > 2.5)
ival |= 1<<i;
int ivalmax = (1<<bits)-1;
double v = ival*volts[bits+1]/ivalmax;
sim.updateVoltageSource(0, nodes[bits], pins[bits].voltSource, v);
}
int getVoltageSourceCount() { return 1; }
int getPostCount() { return bits+2; }
int getDumpType() { return 166; }
}
================================================
FILE: src/DCVoltageElm.java
================================================
class DCVoltageElm extends VoltageElm {
public DCVoltageElm(int xx, int yy) { super(xx, yy, WF_DC); }
Class getDumpClass() { return VoltageElm.class; }
int getShortcut() { return 'v'; }
}
================================================
FILE: src/DFlipFlopElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class DFlipFlopElm extends ChipElm {
final int FLAG_RESET = 2;
boolean hasReset() { return (flags & FLAG_RESET) != 0; }
public DFlipFlopElm(int xx, int yy) { super(xx, yy); }
public DFlipFlopElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
pins[2].value = !pins[1].value;
}
String getChipName() { return "D flip-flop"; }
void setupPins() {
sizeX = 2;
sizeY = 3;
pins = new Pin[getPostCount()];
pins[0] = new Pin(0, SIDE_W, "D");
pins[1] = new Pin(0, SIDE_E, "Q");
pins[1].output = pins[1].state = true;
pins[2] = new Pin(2, SIDE_E, "Q");
pins[2].output = true;
pins[2].lineOver = true;
pins[3] = new Pin(1, SIDE_W, "");
pins[3].clock = true;
if (hasReset())
pins[4] = new Pin(2, SIDE_W, "R");
}
int getPostCount() {
return hasReset() ? 5 : 4;
}
int getVoltageSourceCount() { return 2; }
void execute() {
if (pins[3].value && !lastClock) {
pins[1].value = pins[0].value;
pins[2].value = !pins[0].value;
}
if (pins.length > 4 && pins[4].value) {
pins[1].value = false;
pins[2].value = true;
}
lastClock = pins[3].value;
}
int getDumpType() { return 155; }
public EditInfo getEditInfo(int n) {
if (n == 2) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Reset Pin", hasReset());
return ei;
}
return super.getEditInfo(n);
}
public void setEditValue(int n, EditInfo ei) {
if (n == 2) {
if (ei.checkbox.getState())
flags |= FLAG_RESET;
else
flags &= ~FLAG_RESET;
setupPins();
allocNodes();
setPoints();
}
super.setEditValue(n, ei);
}
}
================================================
FILE: src/DecadeElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class DecadeElm extends ChipElm {
public DecadeElm(int xx, int yy) { super(xx, yy); }
public DecadeElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
}
String getChipName() { return "decade counter"; }
boolean needsBits() { return true; }
void setupPins() {
sizeX = bits > 2 ? bits : 2;
sizeY = 2;
pins = new Pin[getPostCount()];
pins[0] = new Pin(1, SIDE_W, "");
pins[0].clock = true;
pins[1] = new Pin(sizeX-1, SIDE_S, "R");
pins[1].bubble = true;
int i;
for (i = 0; i != bits; i++) {
int ii = i+2;
pins[ii] = new Pin(i, SIDE_N, "Q" + i);
pins[ii].output = pins[ii].state = true;
}
allocNodes();
}
int getPostCount() { return bits+2; }
int getVoltageSourceCount() { return bits; }
void execute() {
int i;
if (pins[0].value && !lastClock) {
for (i = 0; i != bits; i++)
if (pins[i+2].value)
break;
if (i < bits)
pins[i++ +2].value = false;
i %= bits;
pins[i+2].value = true;
}
if (!pins[1].value) {
for (i = 1; i != bits; i++)
pins[i+2].value = false;
pins[2].value = true;
}
lastClock = pins[0].value;
}
int getDumpType() { return 163; }
}
================================================
FILE: src/DiacElm.java
================================================
// stub implementation of DiacElm, based on SparkGapElm
// FIXME need to add DiacElm.java to srclist
// FIXME need to uncomment DiacElm line from CirSim.java
import java.awt.*;
import java.util.StringTokenizer;
class DiacElm extends CircuitElm {
double onresistance, offresistance, breakdown, holdcurrent;
boolean state;
public DiacElm(int xx, int yy) {
super(xx, yy);
// FIXME need to adjust defaults to make sense for diac
offresistance = 1e9;
onresistance = 1e3;
breakdown = 1e3;
holdcurrent = 0.001;
state = false;
}
public DiacElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
onresistance = new Double(st.nextToken()).doubleValue();
offresistance = new Double(st.nextToken()).doubleValue();
breakdown = new Double(st.nextToken()).doubleValue();
holdcurrent = new Double(st.nextToken()).doubleValue();
}
boolean nonLinear() {return true;}
int getDumpType() { return 185; }
String dump() {
return super.dump() + " " + onresistance + " " + offresistance + " "
+ breakdown + " " + holdcurrent;
}
Point ps3, ps4;
void setPoints() {
super.setPoints();
calcLeads(32);
ps3 = new Point();
ps4 = new Point();
}
void draw(Graphics g) {
// FIXME need to draw Diac
int i;
double v1 = volts[0];
double v2 = volts[1];
setBbox(point1, point2, 6);
draw2Leads(g);
setPowerColor(g, true);
doDots(g);
drawPosts(g);
}
void calculateCurrent() {
double vd = volts[0] - volts[1];
if(state)
current = vd/onresistance;
else
current = vd/offresistance;
}
void startIteration() {
double vd = volts[0] - volts[1];
if(Math.abs(current) < holdcurrent) state = false;
if(Math.abs(vd) > breakdown) state = true;
//System.out.print(this + " res current set to " + current + "\n");
}
void doStep() {
if(state)
sim.stampResistor(nodes[0], nodes[1], onresistance);
else
sim.stampResistor(nodes[0], nodes[1], offresistance);
}
void stamp() {
sim.stampNonLinear(nodes[0]);
sim.stampNonLinear(nodes[1]);
}
void getInfo(String arr[]) {
// FIXME
arr[0] = "spark gap";
getBasicInfo(arr);
arr[3] = state ? "on" : "off";
arr[4] = "Ron = " + getUnitText(onresistance, sim.ohmString);
arr[5] = "Roff = " + getUnitText(offresistance, sim.ohmString);
arr[6] = "Vbrkdn = " + getUnitText(breakdown, "V");
arr[7] = "Ihold = " + getUnitText(holdcurrent, "A");
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("On resistance (ohms)", onresistance, 0, 0);
if (n == 1)
return new EditInfo("Off resistance (ohms)", offresistance, 0, 0);
if (n == 2)
return new EditInfo("Breakdown voltage (volts)", breakdown, 0, 0);
if (n == 3)
return new EditInfo("Hold current (amps)", holdcurrent, 0, 0);
return null;
}
public void setEditValue(int n, EditInfo ei) {
if (ei.value > 0 && n == 0)
onresistance = ei.value;
if (ei.value > 0 && n == 1)
offresistance = ei.value;
if (ei.value > 0 && n == 2)
breakdown = ei.value;
if (ei.value > 0 && n == 3)
holdcurrent = ei.value;
}
}
================================================
FILE: src/Diode.java
================================================
class Diode {
int nodes[];
CirSim sim;
Diode(CirSim s) {
sim = s;
nodes = new int[2];
}
void setup(double fw, double zv) {
fwdrop = fw;
zvoltage = zv;
vdcoef = Math.log(1/leakage + 1)/fwdrop;
vt = 1/vdcoef;
// critical voltage for limiting; current is vt/sqrt(2) at
// this voltage
vcrit = vt * Math.log(vt/(Math.sqrt(2)*leakage));
if (zvoltage == 0)
zoffset = 0;
else {
// calculate offset which will give us 5mA at zvoltage
double i = -.005;
zoffset = zvoltage-Math.log(-(1+i/leakage))/vdcoef;
}
}
void reset() {
lastvoltdiff = 0;
}
public double leakage = 1e-14; // was 1e-9;
double vt, vdcoef, fwdrop, zvoltage, zoffset;
double lastvoltdiff;
double vcrit;
double limitStep(double vnew, double vold) {
double arg;
double oo = vnew;
// check new voltage; has current changed by factor of e^2?
if (vnew > vcrit && Math.abs(vnew - vold) > (vt + vt)) {
if(vold > 0) {
arg = 1 + (vnew - vold) / vt;
if(arg > 0) {
// adjust vnew so that the current is the same
// as in linearized model from previous iteration.
// current at vnew = old current * arg
vnew = vold + vt * Math.log(arg);
// current at v0 = 1uA
double v0 = Math.log(1e-6/leakage)*vt;
vnew = Math.max(v0, vnew);
} else {
vnew = vcrit;
}
} else {
// adjust vnew so that the current is the same
// as in linearized model from previous iteration.
// (1/vt = slope of load line)
vnew = vt *Math.log(vnew/vt);
}
sim.converged = false;
//System.out.println(vnew + " " + oo + " " + vold);
} else if (vnew < 0 && zoffset != 0) {
// for Zener breakdown, use the same logic but translate the values
vnew = -vnew - zoffset;
vold = -vold - zoffset;
if (vnew > vcrit && Math.abs(vnew - vold) > (vt + vt)) {
if(vold > 0) {
arg = 1 + (vnew - vold) / vt;
if(arg > 0) {
vnew = vold + vt * Math.log(arg);
double v0 = Math.log(1e-6/leakage)*vt;
vnew = Math.max(v0, vnew);
//System.out.println(oo + " " + vnew);
} else {
vnew = vcrit;
}
} else {
vnew = vt *Math.log(vnew/vt);
}
sim.converged = false;
}
vnew = -(vnew+zoffset);
}
return vnew;
}
void stamp(int n0, int n1) {
nodes[0] = n0;
nodes[1] = n1;
sim.stampNonLinear(nodes[0]);
sim.stampNonLinear(nodes[1]);
}
void doStep(double voltdiff) {
// used to have .1 here, but needed .01 for peak detector
if (Math.abs(voltdiff-lastvoltdiff) > .01)
sim.converged = false;
voltdiff = limitStep(voltdiff, lastvoltdiff);
lastvoltdiff = voltdiff;
if (voltdiff >= 0 || zvoltage == 0) {
// regular diode or forward-biased zener
double eval = Math.exp(voltdiff*vdcoef);
// make diode linear with negative voltages; aids convergence
if (voltdiff < 0)
eval = 1;
double geq = vdcoef*leakage*eval;
double nc = (eval-1)*leakage - geq*voltdiff;
sim.stampConductance(nodes[0], nodes[1], geq);
sim.stampCurrentSource(nodes[0], nodes[1], nc);
} else {
// Zener diode
/*
* I(Vd) = Is * (exp[Vd*C] - exp[(-Vd-Vz)*C] - 1 )
*
* geq is I'(Vd)
* nc is I(Vd) + I'(Vd)*(-Vd)
*/
double geq = leakage*vdcoef* (
Math.exp(voltdiff*vdcoef) + Math.exp((-voltdiff-zoffset)*vdcoef)
);
double nc = leakage* (
Math.exp(voltdiff*vdcoef)
- Math.exp((-voltdiff-zoffset)*vdcoef)
- 1
) + geq*(-voltdiff);
sim.stampConductance(nodes[0], nodes[1], geq);
sim.stampCurrentSource(nodes[0], nodes[1], nc);
}
}
double calculateCurrent(double voltdiff) {
if (voltdiff >= 0 || zvoltage == 0)
return leakage*(Math.exp(voltdiff*vdcoef)-1);
return leakage* (
Math.exp(voltdiff*vdcoef)
- Math.exp((-voltdiff-zoffset)*vdcoef)
- 1
);
}
}
================================================
FILE: src/DiodeElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class DiodeElm extends CircuitElm {
Diode diode;
static final int FLAG_FWDROP = 1;
final double defaultdrop = .805904783;
double fwdrop, zvoltage;
public DiodeElm(int xx, int yy) {
super(xx, yy);
diode = new Diode(sim);
fwdrop = defaultdrop;
zvoltage = 0;
setup();
}
public DiodeElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
diode = new Diode(sim);
fwdrop = defaultdrop;
zvoltage = 0;
if ((f & FLAG_FWDROP) > 0) {
try {
fwdrop = new Double(st.nextToken()).doubleValue();
} catch (Exception e) {
}
}
setup();
}
boolean nonLinear() { return true; }
void setup() {
diode.setup(fwdrop, zvoltage);
}
int getDumpType() { return 'd'; }
String dump() {
flags |= FLAG_FWDROP;
return super.dump() + " " + fwdrop;
}
final int hs = 8;
Polygon poly;
Point cathode[];
void setPoints() {
super.setPoints();
calcLeads(16);
cathode = newPointArray(2);
Point pa[] = newPointArray(2);
interpPoint2(lead1, lead2, pa[0], pa[1], 0, hs);
interpPoint2(lead1, lead2, cathode[0], cathode[1], 1, hs);
poly = createPolygon(pa[0], pa[1], lead2);
}
void draw(Graphics g) {
drawDiode(g);
doDots(g);
drawPosts(g);
}
void reset() {
diode.reset();
volts[0] = volts[1] = curcount = 0;
}
void drawDiode(Graphics g) {
setBbox(point1, point2, hs);
double v1 = volts[0];
double v2 = volts[1];
draw2Leads(g);
// draw arrow thingy
setPowerColor(g, true);
setVoltageColor(g, v1);
g.fillPolygon(poly);
// draw thing arrow is pointing to
setVoltageColor(g, v2);
drawThickLine(g, cathode[0], cathode[1]);
}
void stamp() { diode.stamp(nodes[0], nodes[1]); }
void doStep() {
diode.doStep(volts[0]-volts[1]);
}
void calculateCurrent() {
current = diode.calculateCurrent(volts[0]-volts[1]);
}
void getInfo(String arr[]) {
arr[0] = "diode";
arr[1] = "I = " + getCurrentText(getCurrent());
arr[2] = "Vd = " + getVoltageText(getVoltageDiff());
arr[3] = "P = " + getUnitText(getPower(), "W");
arr[4] = "Vf = " + getVoltageText(fwdrop);
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Fwd Voltage @ 1A", fwdrop, 10, 1000);
return null;
}
public void setEditValue(int n, EditInfo ei) {
fwdrop = ei.value;
setup();
}
int getShortcut() { return 'd'; }
}
================================================
FILE: src/EditDialog.java
================================================
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.text.DecimalFormat;
interface Editable {
EditInfo getEditInfo(int n);
void setEditValue(int n, EditInfo ei);
}
class EditDialog extends Dialog implements AdjustmentListener, ActionListener, ItemListener {
Editable elm;
CirSim cframe;
Button applyButton, okButton;
EditInfo einfos[];
int einfocount;
final int barmax = 1000;
NumberFormat noCommaFormat;
EditDialog(Editable ce, CirSim f) {
super(f, "Edit Component", false);
cframe = f;
elm = ce;
setLayout(new EditDialogLayout());
einfos = new EditInfo[10];
noCommaFormat = DecimalFormat.getInstance();
noCommaFormat.setMaximumFractionDigits(10);
noCommaFormat.setGroupingUsed(false);
int i;
for (i = 0; ; i++) {
einfos[i] = elm.getEditInfo(i);
if (einfos[i] == null)
break;
EditInfo ei = einfos[i];
add(new Label(ei.name));
if (ei.choice != null) {
add(ei.choice);
ei.choice.addItemListener(this);
} else if (ei.checkbox != null) {
add(ei.checkbox);
ei.checkbox.addItemListener(this);
} else {
add(ei.textf =
new TextField(unitString(ei), 10));
if (ei.text != null)
ei.textf.setText(ei.text);
ei.textf.addActionListener(this);
if (ei.text == null) {
add(ei.bar = new Scrollbar(Scrollbar.HORIZONTAL,
50, 10, 0, barmax+2));
setBar(ei);
ei.bar.addAdjustmentListener(this);
}
}
}
einfocount = i;
add(applyButton = new Button("Apply"));
applyButton.addActionListener(this);
add(okButton = new Button("OK"));
okButton.addActionListener(this);
Point x = cframe.main.getLocationOnScreen();
Dimension d = getSize();
setLocation(x.x + (cframe.winSize.width-d.width)/2,
x.y + (cframe.winSize.height-d.height)/2);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
closeDialog();
}
}
);
}
String unitString(EditInfo ei) {
double v = ei.value;
double va = Math.abs(v);
if (ei.dimensionless)
return noCommaFormat.format(v);
if (v == 0) return "0";
if (va < 1e-9)
return noCommaFormat.format(v*1e12) + "p";
if (va < 1e-6)
return noCommaFormat.format(v*1e9) + "n";
if (va < 1e-3)
return noCommaFormat.format(v*1e6) + "u";
if (va < 1 && !ei.forceLargeM)
return noCommaFormat.format(v*1e3) + "m";
if (va < 1e3)
return noCommaFormat.format(v);
if (va < 1e6)
return noCommaFormat.format(v*1e-3) + "k";
if (va < 1e9)
return noCommaFormat.format(v*1e-6) + "M";
return noCommaFormat.format(v*1e-9) + "G";
}
double parseUnits(EditInfo ei) throws java.text.ParseException {
String s = ei.textf.getText();
s = s.trim();
int len = s.length();
char uc = s.charAt(len-1);
double mult = 1;
switch (uc) {
case 'p': case 'P': mult = 1e-12; break;
case 'n': case 'N': mult = 1e-9; break;
case 'u': case 'U': mult = 1e-6; break;
// for ohm values, we assume mega for lowercase m, otherwise milli
case 'm': mult = (ei.forceLargeM) ? 1e6 : 1e-3; break;
case 'k': case 'K': mult = 1e3; break;
case 'M': mult = 1e6; break;
case 'G': case 'g': mult = 1e9; break;
}
if (mult != 1)
s = s.substring(0, len-1).trim();
return noCommaFormat.parse(s).doubleValue() * mult;
}
void apply() {
int i;
for (i = 0; i != einfocount; i++) {
EditInfo ei = einfos[i];
if (ei.textf == null)
continue;
if (ei.text == null) {
try {
double d = parseUnits(ei);
ei.value = d;
} catch (Exception ex) { /* ignored */ }
}
elm.setEditValue(i, ei);
if (ei.text == null)
setBar(ei);
}
cframe.needAnalyze();
}
public void actionPerformed(ActionEvent e) {
int i;
Object src = e.getSource();
for (i = 0; i != einfocount; i++) {
EditInfo ei = einfos[i];
if (src == ei.textf) {
if (ei.text == null) {
try {
double d = parseUnits(ei);
ei.value = d;
} catch (Exception ex) { /* ignored */ }
}
elm.setEditValue(i, ei);
if (ei.text == null)
setBar(ei);
cframe.needAnalyze();
}
}
if (e.getSource() == okButton) {
apply();
closeDialog();
}
if (e.getSource() == applyButton)
apply();
}
public void adjustmentValueChanged(AdjustmentEvent e) {
Object src = e.getSource();
int i;
for (i = 0; i != einfocount; i++) {
EditInfo ei = einfos[i];
if (ei.bar == src) {
double v = ei.bar.getValue() / 1000.;
if (v < 0)
v = 0;
if (v > 1)
v = 1;
ei.value = (ei.maxval-ei.minval)*v + ei.minval;
/*if (ei.maxval-ei.minval > 100)
ei.value = Math.round(ei.value);
else
ei.value = Math.round(ei.value*100)/100.;*/
ei.value = Math.round(ei.value/ei.minval)*ei.minval;
elm.setEditValue(i, ei);
ei.textf.setText(unitString(ei));
cframe.needAnalyze();
}
}
}
public void itemStateChanged(ItemEvent e) {
Object src = e.getItemSelectable();
int i;
boolean changed = false;
for (i = 0; i != einfocount; i++) {
EditInfo ei = einfos[i];
if (ei.choice == src || ei.checkbox == src) {
elm.setEditValue(i, ei);
if (ei.newDialog)
changed = true;
cframe.needAnalyze();
}
}
if (changed) {
setVisible(false);
cframe.editDialog = new EditDialog(elm, cframe);
cframe.editDialog.show();
}
}
public boolean handleEvent(Event ev) {
if (ev.id == Event.WINDOW_DESTROY) {
closeDialog();
return true;
}
return super.handleEvent(ev);
}
void setBar(EditInfo ei) {
int x = (int) (barmax*(ei.value-ei.minval)/(ei.maxval-ei.minval));
ei.bar.setValue(x);
}
protected void closeDialog()
{
cframe.main.requestFocus();
setVisible(false);
cframe.editDialog = null;
}
}
================================================
FILE: src/EditDialogLayout.java
================================================
import java.awt.*;
import java.awt.event.*;
class EditDialogLayout implements LayoutManager {
public EditDialogLayout() {}
public void addLayoutComponent(String name, Component c) {}
public void removeLayoutComponent(Component c) {}
public Dimension preferredLayoutSize(Container target) {
return new Dimension(500, 500);
}
public Dimension minimumLayoutSize(Container target) {
return new Dimension(100,100);
}
public void layoutContainer(Container target) {
Insets insets = target.insets();
int targetw = target.size().width - insets.left - insets.right;
int targeth = target.size().height - (insets.top+insets.bottom);
int i;
int h = insets.top;
int pw = 300;
int x = 0;
for (i = 0; i < target.getComponentCount(); i++) {
Component m = target.getComponent(i);
boolean newline = true;
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
if (pw < d.width)
pw = d.width;
if (m instanceof Scrollbar) {
h += 10;
d.width = targetw-x;
}
if (m instanceof Choice && d.width > targetw)
d.width = targetw-x;
if (m instanceof Label) {
Dimension d2 =
target.getComponent(i+1).getPreferredSize();
if (d.height < d2.height)
d.height = d2.height;
h += d.height/5;
newline = false;
}
if (m instanceof Button) {
if (x == 0)
h += 20;
if (i != target.getComponentCount()-1)
newline = false;
}
m.move(insets.left+x, h);
m.resize(d.width, d.height);
if (newline) {
h += d.height;
x = 0;
} else
x += d.width;
}
}
if (target.size().height < h)
target.resize(pw + insets.right, h + insets.bottom);
}
};
================================================
FILE: src/EditInfo.java
================================================
import java.awt.*;
class EditInfo {
EditInfo(String n, double val, double mn, double mx) {
name = n;
value = val;
if (mn == 0 && mx == 0 && val > 0) {
minval = 1e10;
while (minval > val/100)
minval /= 10.;
maxval = minval * 1000;
} else {
minval = mn;
maxval = mx;
}
forceLargeM = name.indexOf("(ohms)") > 0 ||
name.indexOf("(Hz)") > 0;
dimensionless = false;
}
EditInfo setDimensionless() { dimensionless = true; return this; }
String name, text;
double value, minval, maxval;
TextField textf;
Scrollbar bar;
Choice choice;
Checkbox checkbox;
boolean newDialog;
boolean forceLargeM;
boolean dimensionless;
}
================================================
FILE: src/EditOptions.java
================================================
class EditOptions implements Editable {
CirSim sim;
public EditOptions(CirSim s) { sim = s; }
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Time step size (s)", sim.timeStep, 0, 0);
if (n == 1)
return new EditInfo("Range for voltage color (V)",
CircuitElm.voltageRange, 0, 0);
return null;
}
public void setEditValue(int n, EditInfo ei) {
if (n == 0 && ei.value > 0)
sim.timeStep = ei.value;
if (n == 1 && ei.value > 0)
CircuitElm.voltageRange = ei.value;
}
};
================================================
FILE: src/GateElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
abstract class GateElm extends CircuitElm {
final int FLAG_SMALL = 1;
int inputCount = 2;
boolean lastOutput;
public GateElm(int xx, int yy) {
super(xx, yy);
noDiagonal = true;
inputCount = 2;
setSize(sim.smallGridCheckItem.getState() ? 1 : 2);
}
public GateElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
inputCount = new Integer(st.nextToken()).intValue();
lastOutput = new Double (st.nextToken()).doubleValue() > 2.5;
noDiagonal = true;
setSize((f & FLAG_SMALL) != 0 ? 1 : 2);
}
boolean isInverting() { return false; }
int gsize, gwidth, gwidth2, gheight, hs2;
void setSize(int s) {
gsize = s;
gwidth = 7*s;
gwidth2 = 14*s;
gheight = 8*s;
flags = (s == 1) ? FLAG_SMALL : 0;
}
String dump() {
return super.dump() + " " + inputCount + " " + volts[inputCount];
}
Point inPosts[], inGates[];
int ww;
void setPoints() {
super.setPoints();
if (dn > 150 && this == sim.dragElm)
setSize(2);
int hs = gheight;
int i;
ww = gwidth2; // was 24
if (ww > dn/2)
ww = (int) (dn/2);
if (isInverting() && ww+8 > dn/2)
ww = (int) (dn/2-8);
calcLeads(ww*2);
inPosts = new Point[inputCount];
inGates = new Point[inputCount];
allocNodes();
int i0 = -inputCount/2;
for (i = 0; i != inputCount; i++, i0++) {
if (i0 == 0 && (inputCount & 1) == 0)
i0++;
inPosts[i] = interpPoint(point1, point2, 0, hs*i0);
inGates[i] = interpPoint(lead1, lead2, 0, hs*i0);
volts[i] = (lastOutput ^ isInverting()) ? 5 : 0;
}
hs2 = gwidth*(inputCount/2+1);
setBbox(point1, point2, hs2);
}
void draw(Graphics g) {
int i;
for (i = 0; i != inputCount; i++) {
setVoltageColor(g, volts[i]);
drawThickLine(g, inPosts[i], inGates[i]);
}
setVoltageColor(g, volts[inputCount]);
drawThickLine(g, lead2, point2);
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
drawThickPolygon(g, gatePoly);
if (linePoints != null)
for (i = 0; i != linePoints.length-1; i++)
drawThickLine(g, linePoints[i], linePoints[i+1]);
if (isInverting())
drawThickCircle(g, pcircle.x, pcircle.y, 3);
curcount = updateDotCount(current, curcount);
drawDots(g, lead2, point2, curcount);
drawPosts(g);
}
Polygon gatePoly;
Point pcircle, linePoints[];
int getPostCount() { return inputCount+1; }
Point getPost(int n) {
if (n == inputCount)
return point2;
return inPosts[n];
}
int getVoltageSourceCount() { return 1; }
abstract String getGateName();
void getInfo(String arr[]) {
arr[0] = getGateName();
arr[1] = "Vout = " + getVoltageText(volts[inputCount]);
arr[2] = "Iout = " + getCurrentText(getCurrent());
}
void stamp() {
sim.stampVoltageSource(0, nodes[inputCount], voltSource);
}
boolean getInput(int x) {
return volts[x] > 2.5;
}
abstract boolean calcFunction();
void doStep() {
int i;
boolean f = calcFunction();
if (isInverting())
f = !f;
lastOutput = f;
double res = f ? 5 : 0;
sim.updateVoltageSource(0, nodes[inputCount], voltSource, res);
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("# of Inputs", inputCount, 1, 8).
setDimensionless();
return null;
}
public void setEditValue(int n, EditInfo ei) {
inputCount = (int) ei.value;
setPoints();
}
// there is no current path through the gate inputs, but there
// is an indirect path through the output to ground.
boolean getConnection(int n1, int n2) { return false; }
boolean hasGroundConnection(int n1) {
return (n1 == inputCount);
}
}
================================================
FILE: src/GraphicElm.java
================================================
class GraphicElm extends CircuitElm
{
public GraphicElm(int xx, int yy)
{
super(xx,yy);
}
public GraphicElm(int xa, int ya, int xb, int yb, int flags)
{
super(xa, ya, xb, yb, flags);
}
int getPostCount() { return 0; }
}
================================================
FILE: src/GroundElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class GroundElm extends CircuitElm {
public GroundElm(int xx, int yy) { super(xx, yy); }
public GroundElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
}
int getDumpType() { return 'g'; }
int getPostCount() { return 1; }
void draw(Graphics g) {
setVoltageColor(g, 0);
drawThickLine(g, point1, point2);
int i;
for (i = 0; i != 3; i++) {
int a = 10-i*4;
int b = i*5; // -10;
interpPoint2(point1, point2, ps1, ps2, 1+b/dn, a);
drawThickLine(g, ps1, ps2);
}
doDots(g);
interpPoint(point1, point2, ps2, 1+11./dn);
setBbox(point1, ps2, 11);
drawPost(g, x, y, nodes[0]);
}
void setCurrent(int x, double c) { current = -c; }
void stamp() {
sim.stampVoltageSource(0, nodes[0], voltSource, 0);
}
double getVoltageDiff() { return 0; }
int getVoltageSourceCount() { return 1; }
void getInfo(String arr[]) {
arr[0] = "ground";
arr[1] = "I = " + getCurrentText(getCurrent());
}
boolean hasGroundConnection(int n1) { return true; }
int getShortcut() { return 'g'; }
}
================================================
FILE: src/ImportExportAppletDialog.java
================================================
import java.awt.Dialog;
import java.applet.Applet;
import java.awt.Frame;
import netscape.javascript.*; // add plugin.jar to classpath during compilation
class ImportExportAppletDialog
extends Dialog
implements ImportExportDialog
{
Action type;
CirSim cframe;
String circuitDump;
ImportExportAppletDialog(CirSim f, Action type)
throws Exception
{
super(f, (type == Action.EXPORT) ? "Export" : "Import", false);
this.type = type;
cframe = f;
if ( cframe.applet == null )
throw new Exception("Not running as an applet!");
}
public void setDump(String dump)
{
circuitDump = dump;
}
public void execute()
{
try
{
JSObject window = JSObject.getWindow(cframe.applet);
if ( type == Action.EXPORT )
{
//cframe.setVisible(false);
window.call("exportCircuit", new Object[] { circuitDump });
}
else
{
//cframe.setVisible(false);
circuitDump = (String)window.eval("importCircuit()");
cframe.readSetup( circuitDump );
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
================================================
FILE: src/ImportExportClipboardDialog.java
================================================
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
class ImportExportClipboardDialog
extends Dialog
implements ImportExportDialog,ActionListener
{
CirSim cframe;
Button importButton, closeButton;
TextArea text;
Action type;
Clipboard clipboard = null;
ImportExportClipboardDialog(CirSim f, Action type) {
super(f, (type == Action.EXPORT) ? "Export" : "Import", false);
cframe = f;
setLayout(new ImportExportDialogLayout());
add(text = new TextArea("", 10, 60, TextArea.SCROLLBARS_BOTH));
if (type == Action.EXPORT)
importButton = new Button("Copy to clipboard");
else
importButton = new Button("Import");
this.type = type;
add(importButton);
importButton.addActionListener(this);
add(closeButton = new Button("Close"));
closeButton.addActionListener(this);
Point x = cframe.main.getLocationOnScreen();
resize(400, 300);
Dimension d = getSize();
setLocation(x.x + (cframe.winSize.width-d.width)/2,
x.y + (cframe.winSize.height-d.height)/2);
}
public void setDump(String dump)
{
text.setText(dump);
}
public void execute()
{
if ( type == Action.EXPORT )
text.selectAll();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
int i;
Object src = e.getSource();
if (src == importButton) {
if (clipboard == null)
clipboard = getToolkit().getSystemClipboard();
if ( type == Action.EXPORT )
{
StringSelection data = new StringSelection(text.getText());
clipboard.setContents(data, data);
}
else
{
cframe.readSetup(text.getText());
}
}
if (src == closeButton)
setVisible(false);
}
public boolean handleEvent(Event ev) {
if (ev.id == Event.WINDOW_DESTROY) {
CirSim.main.requestFocus();
setVisible(false);
cframe.impDialog = null;
return true;
}
return super.handleEvent(ev);
}
}
================================================
FILE: src/ImportExportDialog.java
================================================
import java.awt.*;
import java.awt.event.*;
public interface ImportExportDialog {
public enum Action { IMPORT, EXPORT };
public void setDump(String dump);
public void execute();
}
================================================
FILE: src/ImportExportDialogFactory.java
================================================
public class ImportExportDialogFactory
{
public static ImportExportDialog Create(CirSim f,
ImportExportDialog.Action type)
{
if (f.applet != null)
{
try
{
return new ImportExportAppletDialog(f, type);
}
catch (Exception e)
{
return new ImportExportClipboardDialog(f, type);
}
}
else
{
return new ImportExportFileDialog(f, type);
}
}
}
================================================
FILE: src/ImportExportDialogLayout.java
================================================
import java.awt.*;
class ImportExportDialogLayout implements LayoutManager {
public ImportExportDialogLayout() {}
public void addLayoutComponent(String name, Component c) {}
public void removeLayoutComponent(Component c) {}
public Dimension preferredLayoutSize(Container target) {
return new Dimension(500, 500);
}
public Dimension minimumLayoutSize(Container target) {
return new Dimension(100,100);
}
public void layoutContainer(Container target) {
Insets insets = target.insets();
int targetw = target.size().width - insets.left - insets.right;
int targeth = target.size().height - (insets.top+insets.bottom);
int i;
int pw = 300;
if (target.getComponentCount() == 0)
return;
Component cl = target.getComponent(target.getComponentCount()-1);
Dimension dl = cl.getPreferredSize();
target.getComponent(0).move(insets.left, insets.top);
int cw = target.size().width - insets.left - insets.right;
int ch = target.size().height - insets.top - insets.bottom -
dl.height;
target.getComponent(0).resize(cw, ch);
int h = ch + insets.top;
int x = 0;
for (i = 1; i < target.getComponentCount(); i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
m.move(insets.left+x, h);
m.resize(d.width, d.height);
x += d.width;
}
}
}
};
================================================
FILE: src/ImportExportFileDialog.java
================================================
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
class ImportExportFileDialog
implements ImportExportDialog
{
CirSim cframe;
private static String circuitDump;
Action type;
private static String directory = ".";
ImportExportFileDialog(CirSim f, Action type)
{
if ( directory.equals(".") )
{
File file = new File("circuits");
if ( file.isDirectory() )
directory = "circuits";
}
this.type = type;
cframe = f;
}
public void setDump(String dump)
{
circuitDump = dump;
}
public String getDump()
{
return circuitDump;
}
public void execute()
{
FileDialog fd = new FileDialog(new Frame(),
(type == Action.EXPORT) ? "Save File" :
"Open File",
(type == Action.EXPORT) ? FileDialog.SAVE :
FileDialog.LOAD );
fd.setDirectory(directory);
fd.setVisible(true);
String file = fd.getFile();
String dir = fd.getDirectory();
if ( dir != null )
directory = dir;
if ( file == null )
return;
System.err.println(dir + File.separator + file);
if ( type == Action.EXPORT )
{
try
{
writeFile(dir + file);
}
catch (Exception e)
{
e.printStackTrace();
}
}
else
{
try
{
String dump = readFile(dir + file);
circuitDump = dump;
cframe.readSetup(circuitDump);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
private static String readFile(String path)
throws IOException, FileNotFoundException
{
FileInputStream stream = null;
try
{
stream = new FileInputStream(new File(path));
FileChannel fc = stream.getChannel();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY,
0, fc.size());
return Charset.forName("UTF-8").decode(bb).toString();
}
finally
{
stream.close();
}
}
private static void writeFile(String path)
throws IOException, FileNotFoundException
{
FileOutputStream stream = null;
try
{
stream = new FileOutputStream(new File(path));
FileChannel fc = stream.getChannel();
ByteBuffer bb = Charset.forName("UTF-8").encode(circuitDump);
fc.write(bb);
}
finally
{
stream.close();
}
}
}
================================================
FILE: src/Inductor.java
================================================
class Inductor {
public static final int FLAG_BACK_EULER = 2;
int nodes[];
int flags;
CirSim sim;
double inductance;
double compResistance, current;
double curSourceValue;
Inductor(CirSim s) {
sim = s;
nodes = new int[2];
}
void setup(double ic, double cr, int f) {
inductance = ic;
current = cr;
flags = f;
}
boolean isTrapezoidal() { return (flags & FLAG_BACK_EULER) == 0; }
void reset() {
current = 0;
}
void stamp(int n0, int n1) {
// inductor companion model using trapezoidal or backward euler
// approximations (Norton equivalent) consists of a current
// source in parallel with a resistor. Trapezoidal is more
// accurate than backward euler but can cause oscillatory behavior.
// The oscillation is a real problem in circuits with switches.
nodes[0] = n0;
nodes[1] = n1;
if (isTrapezoidal())
compResistance = 2*inductance/sim.timeStep;
else // backward euler
compResistance = inductance/sim.timeStep;
sim.stampResistor(nodes[0], nodes[1], compResistance);
sim.stampRightSide(nodes[0]);
sim.stampRightSide(nodes[1]);
}
boolean nonLinear() { return false; }
void startIteration(double voltdiff) {
if (isTrapezoidal())
curSourceValue = voltdiff/compResistance+current;
else // backward euler
curSourceValue = current;
}
double calculateCurrent(double voltdiff) {
// we check compResistance because this might get called
// before stamp(), which sets compResistance, causing
// infinite current
if (compResistance > 0)
current = voltdiff/compResistance + curSourceValue;
return current;
}
void doStep(double voltdiff) {
sim.stampCurrentSource(nodes[0], nodes[1], curSourceValue);
}
}
================================================
FILE: src/InductorElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class InductorElm extends CircuitElm {
Inductor ind;
double inductance;
public InductorElm(int xx, int yy) {
super(xx, yy);
ind = new Inductor(sim);
inductance = 1;
ind.setup(inductance, current, flags);
}
public InductorElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
ind = new Inductor(sim);
inductance = new Double(st.nextToken()).doubleValue();
current = new Double(st.nextToken()).doubleValue();
ind.setup(inductance, current, flags);
}
int getDumpType() { return 'l'; }
String dump() {
return super.dump() + " " + inductance + " " + current;
}
void setPoints() {
super.setPoints();
calcLeads(32);
}
void draw(Graphics g) {
double v1 = volts[0];
double v2 = volts[1];
int i;
int hs = 8;
setBbox(point1, point2, hs);
draw2Leads(g);
setPowerColor(g, false);
drawCoil(g, 8, lead1, lead2, v1, v2);
if (sim.showValuesCheckItem.getState()) {
String s = getShortUnitText(inductance, "H");
drawValues(g, s, hs);
}
doDots(g);
drawPosts(g);
}
void reset() {
current = volts[0] = volts[1] = curcount = 0;
ind.reset();
}
void stamp() { ind.stamp(nodes[0], nodes[1]); }
void startIteration() {
ind.startIteration(volts[0]-volts[1]);
}
boolean nonLinear() { return ind.nonLinear(); }
void calculateCurrent() {
double voltdiff = volts[0]-volts[1];
current = ind.calculateCurrent(voltdiff);
}
void doStep() {
double voltdiff = volts[0]-volts[1];
ind.doStep(voltdiff);
}
void getInfo(String arr[]) {
arr[0] = "inductor";
getBasicInfo(arr);
arr[3] = "L = " + getUnitText(inductance, "H");
arr[4] = "P = " + getUnitText(getPower(), "W");
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Inductance (H)", inductance, 0, 0);
if (n == 1) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Trapezoidal Approximation",
ind.isTrapezoidal());
return ei;
}
return null;
}
public void setEditValue(int n, EditInfo ei) {
if (n == 0)
inductance = ei.value;
if (n == 1) {
if (ei.checkbox.getState())
flags &= ~Inductor.FLAG_BACK_EULER;
else
flags |= Inductor.FLAG_BACK_EULER;
}
ind.setup(inductance, current, flags);
}
}
================================================
FILE: src/InverterElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class InverterElm extends CircuitElm {
double slewRate; // V/ns
public InverterElm(int xx, int yy) {
super(xx, yy);
noDiagonal = true;
slewRate = .5;
}
public InverterElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
noDiagonal = true;
try {
slewRate = new Double (st.nextToken()).doubleValue();
} catch (Exception e) {
slewRate = .5;
}
}
String dump() {
return super.dump() + " " + slewRate;
}
int getDumpType() { return 'I'; }
void draw(Graphics g) {
drawPosts(g);
draw2Leads(g);
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
drawThickPolygon(g, gatePoly);
drawThickCircle(g, pcircle.x, pcircle.y, 3);
curcount = updateDotCount(current, curcount);
drawDots(g, lead2, point2, curcount);
}
Polygon gatePoly;
Point pcircle;
void setPoints() {
super.setPoints();
int hs = 16;
int ww = 16;
if (ww > dn/2)
ww = (int) (dn/2);
lead1 = interpPoint(point1, point2, .5-ww/dn);
lead2 = interpPoint(point1, point2, .5+(ww+2)/dn);
pcircle = interpPoint(point1, point2, .5+(ww-2)/dn);
Point triPoints[] = newPointArray(3);
interpPoint2(lead1, lead2, triPoints[0], triPoints[1], 0, hs);
triPoints[2] = interpPoint(point1, point2, .5+(ww-5)/dn);
gatePoly = createPolygon(triPoints);
setBbox(point1, point2, hs);
}
int getVoltageSourceCount() { return 1; }
void stamp() {
sim.stampVoltageSource(0, nodes[1], voltSource);
}
void doStep() {
double v0 = volts[1];
double out = volts[0] > 2.5 ? 0 : 5;
double maxStep = slewRate * sim.timeStep * 1e9;
out = Math.max(Math.min(v0+maxStep, out), v0-maxStep);
sim.updateVoltageSource(0, nodes[1], voltSource, out);
}
double getVoltageDiff() { return volts[0]; }
void getInfo(String arr[]) {
arr[0] = "inverter";
arr[1] = "Vi = " + getVoltageText(volts[0]);
arr[2] = "Vo = " + getVoltageText(volts[1]);
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Slew Rate (V/ns)", slewRate, 0, 0);
return null;
}
public void setEditValue(int n, EditInfo ei) {
slewRate = ei.value;
}
// there is no current path through the inverter input, but there
// is an indirect path through the output to ground.
boolean getConnection(int n1, int n2) { return false; }
boolean hasGroundConnection(int n1) {
return (n1 == 1);
}
int getShortcut() { return '1'; }
}
================================================
FILE: src/JKFlipFlopElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class JKFlipFlopElm extends ChipElm {
public JKFlipFlopElm(int xx, int yy) { super(xx, yy); }
public JKFlipFlopElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
pins[4].value = !pins[3].value;
}
String getChipName() { return "JK flip-flop"; }
void setupPins() {
sizeX = 2;
sizeY = 3;
pins = new Pin[5];
pins[0] = new Pin(0, SIDE_W, "J");
pins[1] = new Pin(1, SIDE_W, "");
pins[1].clock = true;
pins[1].bubble = true;
pins[2] = new Pin(2, SIDE_W, "K");
pins[3] = new Pin(0, SIDE_E, "Q");
pins[3].output = pins[3].state = true;
pins[4] = new Pin(2, SIDE_E, "Q");
pins[4].output = true;
pins[4].lineOver = true;
}
int getPostCount() { return 5; }
int getVoltageSourceCount() { return 2; }
void execute() {
if (!pins[1].value && lastClock) {
boolean q = pins[3].value;
if (pins[0].value) {
if (pins[2].value)
q = !q;
else
q = true;
} else if (pins[2].value)
q = false;
pins[3].value = q;
pins[4].value = !q;
}
lastClock = pins[1].value;
}
int getDumpType() { return 156; }
}
================================================
FILE: src/JfetElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class JfetElm extends MosfetElm {
JfetElm(int xx, int yy, boolean pnpflag) {
super(xx, yy, pnpflag);
noDiagonal = true;
}
public JfetElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
noDiagonal = true;
}
Polygon gatePoly;
Polygon arrowPoly;
Point gatePt;
void draw(Graphics g) {
setBbox(point1, point2, hs);
setVoltageColor(g, volts[1]);
drawThickLine(g, src[0], src[1]);
drawThickLine(g, src[1], src[2]);
setVoltageColor(g, volts[2]);
drawThickLine(g, drn[0], drn[1]);
drawThickLine(g, drn[1], drn[2]);
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, gatePt);
g.fillPolygon(arrowPoly);
setPowerColor(g, true);
g.fillPolygon(gatePoly);
curcount = updateDotCount(-ids, curcount);
if (curcount != 0) {
drawDots(g, src[0], src[1], curcount);
drawDots(g, src[1], src[2], curcount+8);
drawDots(g, drn[0], drn[1], -curcount);
drawDots(g, drn[1], drn[2], -(curcount+8));
}
drawPosts(g);
}
void setPoints() {
super.setPoints();
// find the coordinates of the various points we need to draw
// the JFET.
int hs2 = hs*dsign;
src = newPointArray(3);
drn = newPointArray(3);
interpPoint2(point1, point2, src[0], drn[0], 1, hs2);
interpPoint2(point1, point2, src[1], drn[1], 1, hs2/2);
interpPoint2(point1, point2, src[2], drn[2], 1-10/dn, hs2/2);
gatePt = interpPoint(point1, point2, 1-14/dn);
Point ra[] = newPointArray(4);
interpPoint2(point1, point2, ra[0], ra[1], 1-13/dn, hs);
interpPoint2(point1, point2, ra[2], ra[3], 1-10/dn, hs);
gatePoly = createPolygon(ra[0], ra[1], ra[3], ra[2]);
if (pnp == -1) {
Point x = interpPoint(gatePt, point1, 18/dn);
arrowPoly = calcArrow(gatePt, x, 8, 3);
} else
arrowPoly = calcArrow(point1, gatePt, 8, 3);
}
int getDumpType() { return 'j'; }
// these values are taken from Hayes+Horowitz p155
double getDefaultThreshold() { return -4; }
double getBeta() { return .00125; }
void getInfo(String arr[]) {
getFetInfo(arr, "JFET");
}
}
================================================
FILE: src/LEDElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class LEDElm extends DiodeElm {
double colorR, colorG, colorB;
public LEDElm(int xx, int yy) {
super(xx, yy);
fwdrop = 2.1024259;
setup();
colorR = 1; colorG = colorB = 0;
}
public LEDElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
if ((f & FLAG_FWDROP) == 0)
fwdrop = 2.1024259;
setup();
colorR = new Double(st.nextToken()).doubleValue();
colorG = new Double(st.nextToken()).doubleValue();
colorB = new Double(st.nextToken()).doubleValue();
}
int getDumpType() { return 162; }
String dump() {
return super.dump() + " " + colorR + " " + colorG + " " + colorB;
}
Point ledLead1, ledLead2, ledCenter;
void setPoints() {
super.setPoints();
int cr = 12;
ledLead1 = interpPoint(point1, point2, .5-cr/dn);
ledLead2 = interpPoint(point1, point2, .5+cr/dn);
ledCenter = interpPoint(point1, point2, .5);
}
void draw(Graphics g) {
if (needsHighlight() || this == sim.dragElm) {
super.draw(g);
return;
}
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, ledLead1);
setVoltageColor(g, volts[1]);
drawThickLine(g, ledLead2, point2);
g.setColor(Color.gray);
int cr = 12;
drawThickCircle(g, ledCenter.x, ledCenter.y, cr);
cr -= 4;
double w = 255*current/.01;
if (w > 255)
w = 255;
Color cc = new Color((int) (colorR*w), (int) (colorG*w),
(int) (colorB*w));
g.setColor(cc);
g.fillOval(ledCenter.x-cr, ledCenter.y-cr, cr*2, cr*2);
setBbox(point1, point2, cr);
updateDotCount();
drawDots(g, point1, ledLead1, curcount);
drawDots(g, point2, ledLead2, -curcount);
drawPosts(g);
}
void getInfo(String arr[]) {
super.getInfo(arr);
arr[0] = "LED";
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return super.getEditInfo(n);
if (n == 1)
return new EditInfo("Red Value (0-1)", colorR, 0, 1).
setDimensionless();
if (n == 2)
return new EditInfo("Green Value (0-1)", colorG, 0, 1).
setDimensionless();
if (n == 3)
return new EditInfo("Blue Value (0-1)", colorB, 0, 1).
setDimensionless();
return null;
}
public void setEditValue(int n, EditInfo ei) {
if (n == 0)
super.setEditValue(0, ei);
if (n == 1)
colorR = ei.value;
if (n == 2)
colorG = ei.value;
if (n == 3)
colorB = ei.value;
}
int getShortcut() { return 'l'; }
}
================================================
FILE: src/LampElm.java
================================================
import java.awt.*;
import java.util.StringTokenizer;
class LampElm extends CircuitElm {
double resistance;
final double roomTemp = 300;
double temp, nom_pow, nom_v, warmTime, coolTime;
public LampElm(int xx, int yy) {
super(xx, yy);
temp = roomTemp;
nom_pow = 100;
nom_v = 120;
warmTime = .4;
coolTime = .4;
}
public LampElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
temp = new Double(st.nextToken()).doubleValue();
nom_pow = new Double(st.nextToken()).doubleValue();
nom_v = new Double(st.nextToken()).doubleValue();
warmTime = new Double(st.nextToken()).doubleValue();
coolTime = new Double(st.nextToken()).doubleValue();
}
String dump() {
return super.dump() + " " + temp + " " + nom_pow + " " + nom_v +
" " + warmTime + " " + coolTime;
}
int getDumpType() { return 181; }
Point bulbLead[], filament[], bulb;
int bulbR;
void reset() {
super.reset();
temp = roomTemp;
}
final int filament_len = 24;
void setPoints() {
super.setPoints();
int llen = 16;
calcLeads(llen);
bulbLead = newPointArray(2);
filament = newPointArray(2);
bulbR = 20;
filament[0] = interpPoint(lead1, lead2, 0, filament_len);
filament[1] = interpPoint(lead1, lead2, 1, filament_len);
double br = filame
gitextract_yobno83y/
├── .gitignore
├── README.md
└── src/
├── ACRailElm.java
├── ACVoltageElm.java
├── ADCElm.java
├── AnalogSwitch2Elm.java
├── AnalogSwitchElm.java
├── AndGateElm.java
├── AntennaElm.java
├── BoxElm.java
├── CC2Elm.java
├── CapacitorElm.java
├── ChipElm.java
├── CirSim.java
├── Circuit.java
├── CircuitCanvas.java
├── CircuitElm.java
├── CircuitLayout.java
├── CircuitNode.java
├── CircuitNodeLink.java
├── ClockElm.java
├── CounterElm.java
├── CurrentElm.java
├── DACElm.java
├── DCVoltageElm.java
├── DFlipFlopElm.java
├── DecadeElm.java
├── DiacElm.java
├── Diode.java
├── DiodeElm.java
├── EditDialog.java
├── EditDialogLayout.java
├── EditInfo.java
├── EditOptions.java
├── GateElm.java
├── GraphicElm.java
├── GroundElm.java
├── ImportExportAppletDialog.java
├── ImportExportClipboardDialog.java
├── ImportExportDialog.java
├── ImportExportDialogFactory.java
├── ImportExportDialogLayout.java
├── ImportExportFileDialog.java
├── Inductor.java
├── InductorElm.java
├── InverterElm.java
├── JKFlipFlopElm.java
├── JfetElm.java
├── LEDElm.java
├── LampElm.java
├── LatchElm.java
├── LogicInputElm.java
├── LogicOutputElm.java
├── Makefile
├── Manifest.txt
├── MemristorElm.java
├── MosfetElm.java
├── NJfetElm.java
├── NMosfetElm.java
├── NTransistorElm.java
├── NandGateElm.java
├── NorGateElm.java
├── OpAmpElm.java
├── OpAmpSwapElm.java
├── OrGateElm.java
├── OutputElm.java
├── PMosfetElm.java
├── PTransistorElm.java
├── PhaseCompElm.java
├── PhotoResistorElm.java
├── PotElm.java
├── ProbeElm.java
├── PushSwitchElm.java
├── RailElm.java
├── RelayElm.java
├── ResistorElm.java
├── RowInfo.java
├── SCRElm.java
├── Scope.java
├── SevenSegElm.java
├── SparkGapElm.java
├── SquareRailElm.java
├── SweepElm.java
├── Switch2Elm.java
├── SwitchElm.java
├── TappedTransformerElm.java
├── TextElm.java
├── ThermistorElm.java
├── TimerElm.java
├── TransLineElm.java
├── TransformerElm.java
├── TransistorElm.java
├── TriacElm.java
├── TriodeElm.java
├── TunnelDiodeElm.java
├── VCOElm.java
├── VarRailElm.java
├── VoltageElm.java
├── WireElm.java
├── XorGateElm.java
├── ZenerElm.java
├── circuits/
│ ├── 3-cgand.txt
│ ├── 3-cgor.txt
│ ├── 3-f211.txt
│ ├── 3-f220.txt
│ ├── 3-f221.txt
│ ├── 3-invert.txt
│ ├── 3way.txt
│ ├── 4way.txt
│ ├── 555int.txt
│ ├── 555lowduty.txt
│ ├── 555missing.txt
│ ├── 555monostable.txt
│ ├── 555pulsemod.txt
│ ├── 555saw.txt
│ ├── 555schmitt.txt
│ ├── 555sequencer.txt
│ ├── 555square.txt
│ ├── 7segdecoder.txt
│ ├── allpass1.txt
│ ├── allpass2.txt
│ ├── amdetect.txt
│ ├── amp-dfdx.txt
│ ├── amp-diff.txt
│ ├── amp-follower.txt
│ ├── amp-fullrect.txt
│ ├── amp-integ.txt
│ ├── amp-invert.txt
│ ├── amp-noninvert.txt
│ ├── amp-rect.txt
│ ├── amp-schmitt.txt
│ ├── amp-sum.txt
│ ├── bandpass.txt
│ ├── besselbutter.txt
│ ├── blank.txt
│ ├── butter10lo.txt
│ ├── cap.txt
│ ├── capac.txt
│ ├── capmult.txt
│ ├── capmultcaps.txt
│ ├── capmultfreq.txt
│ ├── cappar.txt
│ ├── capseries.txt
│ ├── cc2.txt
│ ├── cc2imp.txt
│ ├── cc2impn.txt
│ ├── cc2n.txt
│ ├── ccdiff.txt
│ ├── cciamp.txt
│ ├── ccinductor.txt
│ ├── ccint.txt
│ ├── ccitov.txt
│ ├── ccvccs.txt
│ ├── ceamp.txt
│ ├── classd.txt
│ ├── clockedsrff.txt
│ ├── cmosff.txt
│ ├── cmosinverter.txt
│ ├── cmosinvertercap.txt
│ ├── cmosinverterslow.txt
│ ├── cmosmsff.txt
│ ├── cmosnand.txt
│ ├── cmosnor.txt
│ ├── cmostransgate.txt
│ ├── cmosxor.txt
│ ├── colpitts.txt
│ ├── counter.txt
│ ├── counter8.txt
│ ├── coupled1.txt
│ ├── coupled2.txt
│ ├── coupled3.txt
│ ├── crossover.txt
│ ├── cube.txt
│ ├── currentsrc.txt
│ ├── currentsrcelm.txt
│ ├── currentsrcramp.txt
│ ├── dac.txt
│ ├── darlington.txt
│ ├── dcrestoration.txt
│ ├── deccounter.txt
│ ├── decoder.txt
│ ├── delayrc.txt
│ ├── deltasigma.txt
│ ├── diff.txt
│ ├── digcompare.txt
│ ├── digsine.txt
│ ├── diodeclip.txt
│ ├── diodecurve.txt
│ ├── diodelimit.txt
│ ├── diodevar.txt
│ ├── divideby2.txt
│ ├── divideby3.txt
│ ├── dram.txt
│ ├── dtlinverter.txt
│ ├── dtlnand.txt
│ ├── dtlnor.txt
│ ├── eclnor.txt
│ ├── eclosc.txt
│ ├── edgedff.txt
│ ├── filt-hipass-l.txt
│ ├── filt-hipass.txt
│ ├── filt-lopass-l.txt
│ ├── filt-lopass.txt
│ ├── filt-vcvs-hipass.txt
│ ├── filt-vcvs-lopass.txt
│ ├── flashadc.txt
│ ├── follower.txt
│ ├── freqdouble.txt
│ ├── fulladd.txt
│ ├── fullrect.txt
│ ├── fullrectf.txt
│ ├── graycode.txt
│ ├── grid.txt
│ ├── grid2.txt
│ ├── gyrator.txt
│ ├── halfadd.txt
│ ├── hartley.txt
│ ├── hfadc.txt
│ ├── howland.txt
│ ├── impedance.txt
│ ├── indmultfreq.txt
│ ├── indmultind.txt
│ ├── indpar.txt
│ ├── indseries.txt
│ ├── induct.txt
│ ├── inductac.txt
│ ├── inductkick-block.txt
│ ├── inductkick-snub.txt
│ ├── inductkick.txt
│ ├── inv-osc.txt
│ ├── invertamp.txt
│ ├── itov.txt
│ ├── jfetamp.txt
│ ├── jfetcurrentsrc.txt
│ ├── jfetfollower-nooff.txt
│ ├── jfetfollower.txt
│ ├── jkff.txt
│ ├── johnsonctr.txt
│ ├── ladder.txt
│ ├── leadingedge.txt
│ ├── ledflasher.txt
│ ├── lissa.txt
│ ├── logconvert.txt
│ ├── longdist.txt
│ ├── lrc-critical.txt
│ ├── lrc.txt
│ ├── majority.txt
│ ├── masterslaveff.txt
│ ├── mirror.txt
│ ├── moscurrentramp.txt
│ ├── moscurrentsrc.txt
│ ├── mosfetamp.txt
│ ├── mosfollower.txt
│ ├── mosmirror.txt
│ ├── mosswitch.txt
│ ├── mr-crossbar.txt
│ ├── mr-sine.txt
│ ├── mr-sine2.txt
│ ├── mr-sine3.txt
│ ├── mr-square.txt
│ ├── mr-triangle.txt
│ ├── mr.txt
│ ├── multivib-a.txt
│ ├── multivib-bi.txt
│ ├── multivib-mono.txt
│ ├── mux.txt
│ ├── mux3state.txt
│ ├── nandff.txt
│ ├── nic-r.txt
│ ├── nmosfet.txt
│ ├── nmosinverter.txt
│ ├── nmosinverter2.txt
│ ├── nmosnand.txt
│ ├── norton.txt
│ ├── notch.txt
│ ├── npn.txt
│ ├── ohms.txt
│ ├── opamp-regulator.txt
│ ├── opamp.txt
│ ├── opampfeedback.txt
│ ├── opint-current.txt
│ ├── opint-invert-amp.txt
│ ├── opint-slew.txt
│ ├── opint.txt
│ ├── peak-detect.txt
│ ├── phasecomp.txt
│ ├── phasecompint.txt
│ ├── phaseseq.txt
│ ├── phaseshiftosc.txt
│ ├── phasesplit.txt
│ ├── pll.txt
│ ├── pll2.txt
│ ├── pll2a.txt
│ ├── pmosfet.txt
│ ├── pnp.txt
│ ├── pot.txt
│ ├── potdivide.txt
│ ├── powerfactor1.txt
│ ├── powerfactor2.txt
│ ├── pushpull.txt
│ ├── pushpullxover.txt
│ ├── r2rladder.txt
│ ├── rectify.txt
│ ├── relaxosc.txt
│ ├── relay.txt
│ ├── relayand.txt
│ ├── relayctr.txt
│ ├── relayff.txt
│ ├── relaymux.txt
│ ├── relayor.txt
│ ├── relaytff.txt
│ ├── relayxor.txt
│ ├── res-par.txt
│ ├── res-series.txt
│ ├── resistors.txt
│ ├── ringing.txt
│ ├── ringmod.txt
│ ├── rossler.txt
│ ├── rtlinverter.txt
│ ├── rtlnand.txt
│ ├── rtlnor.txt
│ ├── samplenhold.txt
│ ├── sawtooth.txt
│ ├── schmitt.txt
│ ├── scr.txt
│ ├── scractrig.txt
│ ├── sine.txt
│ ├── sinediode.txt
│ ├── spark-marx.txt
│ ├── spark-sawtooth.txt
│ ├── spikegen.txt
│ ├── switchedcap.txt
│ ├── switchfilter.txt
│ ├── swtreedac.txt
│ ├── synccounter.txt
│ ├── tdiode.txt
│ ├── tdosc.txt
│ ├── tdrelax.txt
│ ├── tesla.txt
│ ├── thevenin.txt
│ ├── tl.txt
│ ├── tlfreq.txt
│ ├── tllight.txt
│ ├── tllopass.txt
│ ├── tlmatch1.txt
│ ├── tlmatch2.txt
│ ├── tlmis1.txt
│ ├── tlmismatch.txt
│ ├── tlstand.txt
│ ├── tlterm.txt
│ ├── traffic.txt
│ ├── trans-diffamp-common.txt
│ ├── trans-diffamp-cursrc.txt
│ ├── trans-diffamp.txt
│ ├── transformer.txt
│ ├── transformerdc.txt
│ ├── transformerdown.txt
│ ├── transformerup.txt
│ ├── transswitch.txt
│ ├── triangle.txt
│ ├── triode.txt
│ ├── triodeamp.txt
│ ├── ttlinverter.txt
│ ├── ttlnand.txt
│ ├── ttlnor.txt
│ ├── twint.txt
│ ├── vco.txt
│ ├── voltdivide.txt
│ ├── voltdouble.txt
│ ├── voltdouble2.txt
│ ├── voltinvert.txt
│ ├── voltquad.txt
│ ├── volttriple.txt
│ ├── volume.txt
│ ├── wheatstone.txt
│ ├── xor.txt
│ ├── xorphasedet.txt
│ ├── zeneriv.txt
│ ├── zenerref.txt
│ └── zenerreffollow.txt
└── setuplist.txt
SYMBOL INDEX (1353 symbols across 97 files)
FILE: src/ACRailElm.java
class ACRailElm (line 1) | class ACRailElm extends RailElm {
method ACRailElm (line 2) | public ACRailElm(int xx, int yy) { super(xx, yy, WF_AC); }
method getDumpClass (line 3) | Class getDumpClass() { return RailElm.class; }
method getShortcut (line 4) | int getShortcut() { return 0; }
FILE: src/ACVoltageElm.java
class ACVoltageElm (line 1) | class ACVoltageElm extends VoltageElm {
method ACVoltageElm (line 2) | public ACVoltageElm(int xx, int yy) { super(xx, yy, WF_AC); }
method getDumpClass (line 3) | Class getDumpClass() { return VoltageElm.class; }
FILE: src/ADCElm.java
class ADCElm (line 4) | class ADCElm extends ChipElm {
method ADCElm (line 5) | public ADCElm(int xx, int yy) { super(xx, yy); }
method ADCElm (line 6) | public ADCElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 10) | String getChipName() { return "ADC"; }
method needsBits (line 11) | boolean needsBits() { return true; }
method setupPins (line 12) | void setupPins() {
method execute (line 25) | void execute() {
method getVoltageSourceCount (line 35) | int getVoltageSourceCount() { return bits; }
method getPostCount (line 36) | int getPostCount() { return bits+2; }
method getDumpType (line 37) | int getDumpType() { return 167; }
FILE: src/AnalogSwitch2Elm.java
class AnalogSwitch2Elm (line 4) | class AnalogSwitch2Elm extends AnalogSwitchElm {
method AnalogSwitch2Elm (line 5) | public AnalogSwitch2Elm(int xx, int yy) {
method AnalogSwitch2Elm (line 8) | public AnalogSwitch2Elm(int xa, int ya, int xb, int yb, int f,
method setPoints (line 15) | void setPoints() {
method getPostCount (line 24) | int getPostCount() { return 4; }
method draw (line 26) | void draw(Graphics g) {
method getPost (line 52) | Point getPost(int n) {
method getDumpType (line 55) | int getDumpType() { return 160; }
method calculateCurrent (line 57) | void calculateCurrent() {
method stamp (line 64) | void stamp() {
method doStep (line 69) | void doStep() {
method getConnection (line 82) | boolean getConnection(int n1, int n2) {
method getInfo (line 87) | void getInfo(String arr[]) {
FILE: src/AnalogSwitchElm.java
class AnalogSwitchElm (line 4) | class AnalogSwitchElm extends CircuitElm {
method AnalogSwitchElm (line 7) | public AnalogSwitchElm(int xx, int yy) {
method AnalogSwitchElm (line 12) | public AnalogSwitchElm(int xa, int ya, int xb, int yb, int f,
method dump (line 23) | String dump() {
method getDumpType (line 27) | int getDumpType() { return 159; }
method setPoints (line 31) | void setPoints() {
method draw (line 40) | void draw(Graphics g) {
method calculateCurrent (line 58) | void calculateCurrent() {
method nonLinear (line 63) | boolean nonLinear() { return true; }
method stamp (line 65) | void stamp() {
method doStep (line 69) | void doStep() {
method drag (line 76) | void drag(int xx, int yy) {
method getPostCount (line 90) | int getPostCount() { return 3; }
method getPost (line 91) | Point getPost(int n) {
method getInfo (line 94) | void getInfo(String arr[]) {
method getConnection (line 103) | boolean getConnection(int n1, int n2) {
method getEditInfo (line 108) | public EditInfo getEditInfo(int n) {
method setEditValue (line 121) | public void setEditValue(int n, EditInfo ei) {
FILE: src/AndGateElm.java
class AndGateElm (line 4) | class AndGateElm extends GateElm {
method AndGateElm (line 5) | public AndGateElm(int xx, int yy) { super(xx, yy); }
method AndGateElm (line 6) | public AndGateElm(int xa, int ya, int xb, int yb, int f,
method setPoints (line 10) | void setPoints() {
method getGateName (line 32) | String getGateName() { return "AND gate"; }
method calcFunction (line 33) | boolean calcFunction() {
method getDumpType (line 40) | int getDumpType() { return 150; }
method getShortcut (line 41) | int getShortcut() { return '2'; }
FILE: src/AntennaElm.java
class AntennaElm (line 4) | class AntennaElm extends RailElm {
method AntennaElm (line 5) | public AntennaElm(int xx, int yy) { super(xx, yy, WF_DC); }
method AntennaElm (line 6) | public AntennaElm(int xa, int ya, int xb, int yb, int f,
method stamp (line 12) | void stamp() {
method doStep (line 15) | void doStep() {
method getVoltage (line 18) | double getVoltage() {
method getDumpType (line 25) | int getDumpType() { return 'A'; }
method getShortcut (line 26) | int getShortcut() { return 0; }
FILE: src/BoxElm.java
class BoxElm (line 5) | class BoxElm extends GraphicElm {
method BoxElm (line 7) | public BoxElm(int xx, int yy) {
method BoxElm (line 14) | public BoxElm(int xa, int ya, int xb, int yb, int f,
method dump (line 30) | String dump() {
method getDumpType (line 34) | int getDumpType() { return 'b'; }
method drag (line 36) | void drag(int xx, int yy) {
method draw (line 41) | void draw(Graphics g) {
method getEditInfo (line 55) | public EditInfo getEditInfo(int n) {
method setEditValue (line 59) | public void setEditValue(int n, EditInfo ei) {
method getInfo (line 62) | void getInfo(String arr[]) {
method getShortcut (line 65) | @Override
FILE: src/CC2Elm.java
class CC2Elm (line 4) | class CC2Elm extends ChipElm {
method CC2Elm (line 6) | public CC2Elm(int xx, int yy) { super(xx, yy); gain = 1; }
method CC2Elm (line 7) | public CC2Elm(int xx, int yy, int g) { super(xx, yy); gain = g; }
method CC2Elm (line 8) | public CC2Elm(int xa, int ya, int xb, int yb, int f,
method dump (line 13) | String dump() {
method getChipName (line 16) | String getChipName() { return "CC2"; }
method setupPins (line 17) | void setupPins() {
method getInfo (line 26) | void getInfo(String arr[]) {
method stamp (line 33) | void stamp() {
method draw (line 40) | void draw(Graphics g) {
method getPostCount (line 44) | int getPostCount() { return 3; }
method getVoltageSourceCount (line 45) | int getVoltageSourceCount() { return 1; }
method getDumpType (line 46) | int getDumpType() { return 179; }
class CC2NegElm (line 49) | class CC2NegElm extends CC2Elm {
method CC2NegElm (line 50) | public CC2NegElm(int xx, int yy) { super(xx, yy, -1); }
method getDumpClass (line 51) | Class getDumpClass() { return CC2Elm.class; }
FILE: src/CapacitorElm.java
class CapacitorElm (line 4) | class CapacitorElm extends CircuitElm {
method CapacitorElm (line 9) | public CapacitorElm(int xx, int yy) {
method CapacitorElm (line 13) | public CapacitorElm(int xa, int ya, int xb, int yb, int f,
method isTrapezoidal (line 19) | boolean isTrapezoidal() { return (flags & FLAG_BACK_EULER) == 0; }
method setNodeVoltage (line 20) | void setNodeVoltage(int n, double c) {
method reset (line 24) | void reset() {
method getDumpType (line 29) | int getDumpType() { return 'c'; }
method dump (line 30) | String dump() {
method setPoints (line 33) | void setPoints() {
method draw (line 46) | void draw(Graphics g) {
method stamp (line 75) | void stamp() {
method startIteration (line 89) | void startIteration() {
method calculateCurrent (line 96) | void calculateCurrent() {
method doStep (line 105) | void doStep() {
method getInfo (line 108) | void getInfo(String arr[]) {
method getEditInfo (line 116) | public EditInfo getEditInfo(int n) {
method setEditValue (line 126) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 136) | int getShortcut() { return 'c'; }
FILE: src/ChipElm.java
class ChipElm (line 4) | abstract class ChipElm extends CircuitElm {
method ChipElm (line 10) | public ChipElm(int xx, int yy) {
method ChipElm (line 18) | public ChipElm(int xa, int ya, int xb, int yb, int f,
method needsBits (line 34) | boolean needsBits() { return false; }
method setSize (line 35) | void setSize(int s) {
method setupPins (line 42) | abstract void setupPins();
method draw (line 43) | void draw(Graphics g) {
method drawChip (line 46) | void drawChip(Graphics g) {
method drag (line 87) | void drag(int xx, int yy) {
method setPoints (line 97) | void setPoints() {
method getPost (line 120) | Point getPost(int n) {
method getVoltageSourceCount (line 123) | abstract int getVoltageSourceCount();
method setVoltageSource (line 124) | void setVoltageSource(int j, int vs) {
method stamp (line 135) | void stamp() {
method execute (line 143) | void execute() {}
method doStep (line 144) | void doStep() {
method reset (line 159) | void reset() {
method dump (line 169) | String dump() {
method getInfo (line 182) | void getInfo(String arr[]) {
method setCurrent (line 201) | void setCurrent(int x, double c) {
method getChipName (line 207) | String getChipName() { return "chip"; }
method getConnection (line 208) | boolean getConnection(int n1, int n2) { return false; }
method hasGroundConnection (line 209) | boolean hasGroundConnection(int n1) {
method getEditInfo (line 213) | public EditInfo getEditInfo(int n) {
method setEditValue (line 226) | public void setEditValue(int n, EditInfo ei) {
class Pin (line 247) | class Pin {
method Pin (line 248) | Pin(int p, int s, String t) {
method setPoint (line 257) | void setPoint(int px, int py, int dx, int dy, int dax, int day,
FILE: src/CirSim.java
class CirSim (line 26) | public class CirSim extends Frame
method getAppletInfo (line 39) | public String getAppletInfo() {
method getrand (line 156) | int getrand(int x) {
method CirSim (line 164) | CirSim(Circuit a) {
method init (line 175) | public void init() {
method triggerShow (line 566) | public void triggerShow() {
method requestFocus (line 572) | public void requestFocus()
method buildScopeMenu (line 578) | PopupMenu buildScopeMenu(boolean t) {
method getMenuItem (line 612) | MenuItem getMenuItem(String s) {
method getMenuItem (line 618) | MenuItem getMenuItem(String s, String ac) {
method getCheckItem (line 625) | CheckboxMenuItem getCheckItem(String s) {
method getClassCheckItem (line 632) | CheckboxMenuItem getClassCheckItem(String s, String t) {
method getCheckItem (line 647) | CheckboxMenuItem getCheckItem(String s, String t) {
method register (line 654) | void register(Class c, CircuitElm elm) {
method handleResize (line 700) | void handleResize() {
method destroyFrame (line 738) | void destroyFrame() {
method handleEvent (line 750) | public boolean handleEvent(Event ev) {
method paint (line 758) | public void paint(Graphics g) {
method updateCircuit (line 768) | public void updateCircuit(Graphics realg) {
method setupScopes (line 967) | void setupScopes() {
method getHint (line 1030) | String getHint() {
method toggleSwitch (line 1088) | public void toggleSwitch(int n) {
method needAnalyze (line 1104) | void needAnalyze() {
method getCircuitNode (line 1112) | public CircuitNode getCircuitNode(int n) {
method getElm (line 1118) | public CircuitElm getElm(int n) {
method analyzeCircuit (line 1124) | void analyzeCircuit() {
method calcCircuitBottom (line 1555) | void calcCircuitBottom() {
class FindPathInfo (line 1566) | class FindPathInfo {
method FindPathInfo (line 1575) | FindPathInfo(int t, CircuitElm e, int d) {
method findPath (line 1581) | boolean findPath(int n1) { return findPath(n1, -1); }
method findPath (line 1582) | boolean findPath(int n1, int depth) {
method stop (line 1664) | void stop(String s, CircuitElm ce) {
method stampVCVS (line 1675) | void stampVCVS(int n1, int n2, double coef, int vs) {
method stampVoltageSource (line 1682) | void stampVoltageSource(int n1, int n2, int vs, double v) {
method stampVoltageSource (line 1692) | void stampVoltageSource(int n1, int n2, int vs) {
method updateVoltageSource (line 1701) | void updateVoltageSource(int n1, int n2, int vs, double v) {
method stampResistor (line 1706) | void stampResistor(int n1, int n2, double r) {
method stampConductance (line 1719) | void stampConductance(int n1, int n2, double r0) {
method stampVCCurrentSource (line 1727) | void stampVCCurrentSource(int cn1, int cn2, int vn1, int vn2, double g) {
method stampCurrentSource (line 1734) | void stampCurrentSource(int n1, int n2, double i) {
method stampCCCS (line 1740) | void stampCCCS(int n1, int n2, int vs, double gain) {
method stampMatrix (line 1749) | void stampMatrix(int i, int j, double x) {
method stampRightSide (line 1771) | void stampRightSide(int i, double x) {
method stampRightSide (line 1783) | void stampRightSide(int i) {
method stampNonLinear (line 1790) | void stampNonLinear(int i) {
method getIterCount (line 1795) | double getIterCount() {
method runCircuit (line 1804) | void runCircuit() {
method min (line 1922) | int min(int a, int b) { return (a < b) ? a : b; }
method max (line 1923) | int max(int a, int b) { return (a > b) ? a : b; }
method editFuncPoint (line 1925) | void editFuncPoint(int x, int y) {
method componentHidden (line 1930) | public void componentHidden(ComponentEvent e){}
method componentMoved (line 1931) | public void componentMoved(ComponentEvent e){}
method componentShown (line 1932) | public void componentShown(ComponentEvent e) {
method componentResized (line 1936) | public void componentResized(ComponentEvent e) {
method actionPerformed (line 1940) | public void actionPerformed(ActionEvent e) {
method stackScope (line 2044) | void stackScope(int s) {
method unstackScope (line 2057) | void unstackScope(int s) {
method stackAll (line 2069) | void stackAll() {
method unstackAll (line 2077) | void unstackAll() {
method doEdit (line 2085) | void doEdit(Editable eable) {
method doImport (line 2097) | void doImport() {
method doExport (line 2107) | void doExport(boolean url)
method dumpCircuit (line 2122) | String dumpCircuit() {
method adjustmentValueChanged (line 2147) | public void adjustmentValueChanged(AdjustmentEvent e) {
method readUrlData (line 2151) | ByteArrayOutputStream readUrlData(URL url) throws java.io.IOException {
method getCodeBase (line 2166) | URL getCodeBase() {
method getSetupList (line 2178) | void getSetupList(Menu menu, boolean retry) {
method readSetup (line 2242) | void readSetup(String text) {
method readSetup (line 2246) | void readSetup(String text, boolean retain) {
method readSetupFile (line 2251) | void readSetupFile(String str, String title) {
method readSetup (line 2271) | void readSetup(byte b[], int len, boolean retain) {
method readHint (line 2382) | void readHint(StringTokenizer st) {
method readOptions (line 2388) | void readOptions(StringTokenizer st) {
method snapGrid (line 2409) | int snapGrid(int x) {
method doSwitch (line 2413) | boolean doSwitch(int x, int y) {
method locateElm (line 2424) | int locateElm(CircuitElm elm) {
method mouseDragged (line 2432) | public void mouseDragged(MouseEvent e) {
method dragAll (line 2484) | void dragAll(int x, int y) {
method dragRow (line 2497) | void dragRow(int x, int y) {
method dragColumn (line 2512) | void dragColumn(int x, int y) {
method dragSelected (line 2527) | boolean dragSelected(int x, int y) {
method dragPost (line 2577) | void dragPost(int x, int y) {
method selectArea (line 2591) | void selectArea(int x, int y) {
method setSelectedElm (line 2604) | void setSelectedElm(CircuitElm cs) {
method removeZeroLengthElements (line 2613) | void removeZeroLengthElements() {
method mouseMoved (line 2627) | public void mouseMoved(MouseEvent e) {
method distanceSq (line 2705) | int distanceSq(int x1, int y1, int x2, int y2) {
method mouseClicked (line 2711) | public void mouseClicked(MouseEvent e) {
method mouseEntered (line 2719) | public void mouseEntered(MouseEvent e) {
method mouseExited (line 2721) | public void mouseExited(MouseEvent e) {
method mousePressed (line 2727) | public void mousePressed(MouseEvent e) {
method constructElement (line 2787) | CircuitElm constructElement(Class c, int x0, int y0) {
method doEditMenu (line 2814) | void doEditMenu(MouseEvent e) {
method doPopupMenu (line 2819) | void doPopupMenu(MouseEvent e) {
method doMainMenuChecks (line 2837) | void doMainMenuChecks(Menu m) {
method mouseReleased (line 2853) | public void mouseReleased(MouseEvent e) {
method enableItems (line 2887) | void enableItems() {
method itemStateChanged (line 2898) | public void itemStateChanged(ItemEvent e) {
method setGrid (line 2950) | void setGrid() {
method pushUndo (line 2956) | void pushUndo() {
method doUndo (line 2966) | void doUndo() {
method doRedo (line 2975) | void doRedo() {
method enableUndoRedo (line 2984) | void enableUndoRedo() {
method setMouseMode (line 2989) | void setMouseMode(int mode)
method setMenuSelection (line 2998) | void setMenuSelection() {
method doCut (line 3007) | void doCut() {
method doDelete (line 3024) | void doDelete() {
method doCopy (line 3057) | void doCopy() {
method enablePaste (line 3069) | void enablePaste() {
method doPaste (line 3073) | void doPaste() {
method clearSelection (line 3119) | void clearSelection() {
method doSelectAll (line 3127) | void doSelectAll() {
method keyPressed (line 3135) | public void keyPressed(KeyEvent e) {}
method keyReleased (line 3136) | public void keyReleased(KeyEvent e) {}
method keyTyped (line 3138) | public void keyTyped(KeyEvent e) {
method lu_factor (line 3167) | boolean lu_factor(double a[][], int n, int ipvt[]) {
method lu_solve (line 3246) | void lu_solve(double a[][], int n, int ipvt[], double b[]) {
FILE: src/Circuit.java
class Circuit (line 22) | public class Circuit extends Applet implements ComponentListener {
method destroyFrame (line 26) | void destroyFrame() {
method init (line 34) | public void init() {
method main (line 38) | public static void main(String args[]) {
method showFrame (line 43) | public void showFrame() {
method hideFrame (line 58) | public void hideFrame() {
method toggleSwitch (line 65) | public void toggleSwitch(int x) { ogf.toggleSwitch(x); }
method paint (line 67) | public void paint(Graphics g) {
method componentHidden (line 80) | public void componentHidden(ComponentEvent e){}
method componentMoved (line 81) | public void componentMoved(ComponentEvent e){}
method componentShown (line 82) | public void componentShown(ComponentEvent e) { showFrame(); }
method componentResized (line 83) | public void componentResized(ComponentEvent e) {
method destroy (line 88) | public void destroy() {
FILE: src/CircuitCanvas.java
class CircuitCanvas (line 3) | class CircuitCanvas extends Canvas {
method CircuitCanvas (line 5) | CircuitCanvas(CirSim p) {
method getPreferredSize (line 8) | public Dimension getPreferredSize() {
method update (line 11) | public void update(Graphics g) {
method paint (line 14) | public void paint(Graphics g) {
FILE: src/CircuitElm.java
class CircuitElm (line 5) | public abstract class CircuitElm implements Editable {
method getDumpType (line 27) | int getDumpType() { return 0; }
method getDumpClass (line 28) | Class getDumpClass() { return getClass(); }
method getDefaultFlags (line 29) | int getDefaultFlags() { return 0; }
method initClass (line 31) | static void initClass(CirSim s) {
method CircuitElm (line 62) | CircuitElm(int xx, int yy) {
method CircuitElm (line 69) | CircuitElm(int xa, int ya, int xb, int yb, int f) {
method initBoundingBox (line 75) | void initBoundingBox() {
method allocNodes (line 81) | void allocNodes() {
method dump (line 85) | String dump() {
method reset (line 90) | void reset() {
method draw (line 96) | void draw(Graphics g) {}
method setCurrent (line 97) | void setCurrent(int x, double c) { current = c; }
method getCurrent (line 98) | double getCurrent() { return current; }
method doStep (line 99) | void doStep() {}
method delete (line 100) | void delete() {}
method startIteration (line 101) | void startIteration() {}
method getPostVoltage (line 102) | double getPostVoltage(int x) { return volts[x]; }
method setNodeVoltage (line 103) | void setNodeVoltage(int n, double c) {
method calculateCurrent (line 107) | void calculateCurrent() {}
method setPoints (line 108) | void setPoints() {
method calcLeads (line 117) | void calcLeads(int len) {
method interpPoint (line 126) | Point interpPoint(Point a, Point b, double f) {
method interpPoint (line 131) | void interpPoint(Point a, Point b, Point c, double f) {
method interpPoint (line 139) | void interpPoint(Point a, Point b, Point c, double f, double g) {
method interpPoint (line 148) | Point interpPoint(Point a, Point b, double f, double g) {
method interpPoint2 (line 153) | void interpPoint2(Point a, Point b, Point c, Point d, double f, double...
method draw2Leads (line 164) | void draw2Leads(Graphics g) {
method newPointArray (line 173) | Point [] newPointArray(int n) {
method drawDots (line 180) | void drawDots(Graphics g, Point pa, Point pb, double pos) {
method calcArrow (line 199) | Polygon calcArrow(Point a, Point b, double al, double aw) {
method calcArrowReverse (line 213) | Polygon calcArrowReverse(Point a, Point b, double al, double aw) {
method createPolygon (line 236) | Polygon createPolygon(Point a, Point b, Point c) {
method createPolygon (line 243) | Polygon createPolygon(Point a, Point b, Point c, Point d) {
method createPolygon (line 251) | Polygon createPolygon(Point a[]) {
method drag (line 258) | void drag(int xx, int yy) {
method move (line 271) | void move(int dx, int dy) {
method allowMove (line 278) | boolean allowMove(int dx, int dy) {
method movePoint (line 294) | void movePoint(int n, int dx, int dy) {
method drawPosts (line 302) | void drawPosts(Graphics g) {
method stamp (line 309) | void stamp() {}
method getVoltageSourceCount (line 310) | int getVoltageSourceCount() { return 0; }
method getInternalNodeCount (line 311) | int getInternalNodeCount() { return 0; }
method setNode (line 312) | void setNode(int p, int n) { nodes[p] = n; }
method setVoltageSource (line 313) | void setVoltageSource(int n, int v) { voltSource = v; }
method getVoltageSource (line 314) | int getVoltageSource() { return voltSource; }
method getVoltageDiff (line 315) | double getVoltageDiff() {
method nonLinear (line 318) | boolean nonLinear() { return false; }
method getPostCount (line 319) | int getPostCount() { return 2; }
method getNode (line 320) | int getNode(int n) { return nodes[n]; }
method getPost (line 321) | Point getPost(int n) {
method drawPost (line 324) | void drawPost(Graphics g, int x0, int y0, int n) {
method drawPost (line 333) | void drawPost(Graphics g, int x0, int y0) {
method setBbox (line 337) | void setBbox(int x1, int y1, int x2, int y2) {
method setBbox (line 342) | void setBbox(Point p1, Point p2, double w) {
method adjustBbox (line 350) | void adjustBbox(int x1, int y1, int x2, int y2) {
method adjustBbox (line 359) | void adjustBbox(Point p1, Point p2) {
method isCenteredText (line 362) | boolean isCenteredText() { return false; }
method drawCenteredText (line 364) | void drawCenteredText(Graphics g, String s, int x, int y, boolean cx) {
method drawValues (line 374) | void drawValues(Graphics g, String s, double hs) {
method drawCoil (line 401) | void drawCoil(Graphics g, int hs, Point p1, Point p2,
method drawThickLine (line 421) | static void drawThickLine(Graphics g, int x, int y, int x2, int y2) {
method drawThickLine (line 428) | static void drawThickLine(Graphics g, Point pa, Point pb) {
method drawThickPolygon (line 435) | static void drawThickPolygon(Graphics g, int xs[], int ys[], int c) {
method drawThickPolygon (line 442) | static void drawThickPolygon(Graphics g, Polygon p) {
method drawThickCircle (line 446) | static void drawThickCircle(Graphics g, int cx, int cy, int ri) {
method getVoltageDText (line 459) | static String getVoltageDText(double v) {
method getVoltageText (line 462) | static String getVoltageText(double v) {
method getUnitText (line 465) | static String getUnitText(double v, String u) {
method getShortUnitText (line 485) | static String getShortUnitText(double v, String u) {
method getCurrentText (line 505) | static String getCurrentText(double i) {
method getCurrentDText (line 508) | static String getCurrentDText(double i) {
method updateDotCount (line 512) | void updateDotCount() {
method updateDotCount (line 515) | double updateDotCount(double cur, double cc) {
method doDots (line 528) | void doDots(Graphics g) {
method doAdjust (line 533) | void doAdjust() {}
method setupAdjust (line 534) | void setupAdjust() {}
method getInfo (line 535) | void getInfo(String arr[]) {
method getBasicInfo (line 537) | int getBasicInfo(String arr[]) {
method setVoltageColor (line 542) | void setVoltageColor(Graphics g, double volts) {
method setPowerColor (line 560) | void setPowerColor(Graphics g, boolean yellow) {
method setPowerColor (line 569) | void setPowerColor(Graphics g, double w0) {
method setConductanceColor (line 585) | void setConductanceColor(Graphics g, double w0) {
method getPower (line 594) | double getPower() { return getVoltageDiff()*current; }
method getScopeValue (line 595) | double getScopeValue(int x) {
method getScopeUnits (line 598) | String getScopeUnits(int x) {
method getEditInfo (line 601) | public EditInfo getEditInfo(int n) { return null; }
method setEditValue (line 602) | public void setEditValue(int n, EditInfo ei) {}
method getConnection (line 603) | boolean getConnection(int n1, int n2) { return true; }
method hasGroundConnection (line 604) | boolean hasGroundConnection(int n1) { return false; }
method isWire (line 605) | boolean isWire() { return false; }
method canViewInScope (line 606) | boolean canViewInScope() { return getPostCount() <= 2; }
method comparePair (line 607) | boolean comparePair(int x1, int x2, int y1, int y2) {
method needsHighlight (line 610) | boolean needsHighlight() { return sim.mouseElm == this || selected; }
method isSelected (line 611) | boolean isSelected() { return selected; }
method setSelected (line 612) | void setSelected(boolean x) { selected = x; }
method selectRect (line 613) | void selectRect(Rectangle r) {
method abs (line 616) | static int abs(int x) { return x < 0 ? -x : x; }
method sign (line 617) | static int sign(int x) { return (x < 0) ? -1 : (x == 0) ? 0 : 1; }
method min (line 618) | static int min(int a, int b) { return (a < b) ? a : b; }
method max (line 619) | static int max(int a, int b) { return (a > b) ? a : b; }
method distance (line 620) | static double distance(Point p1, Point p2) {
method getBoundingBox (line 625) | Rectangle getBoundingBox() { return boundingBox; }
method needsShortcut (line 626) | boolean needsShortcut() { return getShortcut() > 0; }
method getShortcut (line 627) | int getShortcut() { return 0; }
method isGraphicElmt (line 629) | boolean isGraphicElmt() { return false; }
FILE: src/CircuitLayout.java
class CircuitLayout (line 3) | class CircuitLayout implements LayoutManager {
method CircuitLayout (line 4) | public CircuitLayout() {}
method addLayoutComponent (line 5) | public void addLayoutComponent(String name, Component c) {}
method removeLayoutComponent (line 6) | public void removeLayoutComponent(Component c) {}
method preferredLayoutSize (line 7) | public Dimension preferredLayoutSize(Container target) {
method minimumLayoutSize (line 10) | public Dimension minimumLayoutSize(Container target) {
method layoutContainer (line 13) | public void layoutContainer(Container target) {
FILE: src/CircuitNode.java
class CircuitNode (line 3) | class CircuitNode {
method CircuitNode (line 7) | CircuitNode() { links = new Vector<CircuitNodeLink>(); }
FILE: src/CircuitNodeLink.java
class CircuitNodeLink (line 1) | class CircuitNodeLink {
FILE: src/ClockElm.java
class ClockElm (line 1) | class ClockElm extends RailElm {
method ClockElm (line 2) | public ClockElm(int xx, int yy) {
method getDumpClass (line 9) | Class getDumpClass() { return RailElm.class; }
method getShortcut (line 10) | int getShortcut() { return 0; }
FILE: src/CounterElm.java
class CounterElm (line 4) | class CounterElm extends ChipElm {
method CounterElm (line 6) | public CounterElm(int xx, int yy) { super(xx, yy); }
method CounterElm (line 7) | public CounterElm(int xa, int ya, int xb, int yb, int f,
method needsBits (line 11) | boolean needsBits() { return true; }
method getChipName (line 12) | String getChipName() { return "Counter"; }
method setupPins (line 13) | void setupPins() {
method getPostCount (line 31) | int getPostCount() {
method hasEnable (line 36) | boolean hasEnable() { return (flags & FLAG_ENABLE) != 0; }
method getVoltageSourceCount (line 37) | int getVoltageSourceCount() { return bits; }
method execute (line 38) | void execute() {
method getDumpType (line 60) | int getDumpType() { return 164; }
FILE: src/CurrentElm.java
class CurrentElm (line 4) | class CurrentElm extends CircuitElm {
method CurrentElm (line 6) | public CurrentElm(int xx, int yy) {
method CurrentElm (line 10) | public CurrentElm(int xa, int ya, int xb, int yb, int f,
method dump (line 19) | String dump() {
method getDumpType (line 22) | int getDumpType() { return 'i'; }
method setPoints (line 26) | void setPoints() {
method draw (line 35) | void draw(Graphics g) {
method stamp (line 54) | void stamp() {
method getEditInfo (line 58) | public EditInfo getEditInfo(int n) {
method setEditValue (line 63) | public void setEditValue(int n, EditInfo ei) {
method getInfo (line 66) | void getInfo(String arr[]) {
method getVoltageDiff (line 70) | double getVoltageDiff() {
FILE: src/DACElm.java
class DACElm (line 4) | class DACElm extends ChipElm {
method DACElm (line 5) | public DACElm(int xx, int yy) { super(xx, yy); }
method DACElm (line 6) | public DACElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 10) | String getChipName() { return "DAC"; }
method needsBits (line 11) | boolean needsBits() { return true; }
method setupPins (line 12) | void setupPins() {
method doStep (line 24) | void doStep() {
method getVoltageSourceCount (line 34) | int getVoltageSourceCount() { return 1; }
method getPostCount (line 35) | int getPostCount() { return bits+2; }
method getDumpType (line 36) | int getDumpType() { return 166; }
FILE: src/DCVoltageElm.java
class DCVoltageElm (line 1) | class DCVoltageElm extends VoltageElm {
method DCVoltageElm (line 2) | public DCVoltageElm(int xx, int yy) { super(xx, yy, WF_DC); }
method getDumpClass (line 3) | Class getDumpClass() { return VoltageElm.class; }
method getShortcut (line 4) | int getShortcut() { return 'v'; }
FILE: src/DFlipFlopElm.java
class DFlipFlopElm (line 4) | class DFlipFlopElm extends ChipElm {
method hasReset (line 6) | boolean hasReset() { return (flags & FLAG_RESET) != 0; }
method DFlipFlopElm (line 7) | public DFlipFlopElm(int xx, int yy) { super(xx, yy); }
method DFlipFlopElm (line 8) | public DFlipFlopElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 13) | String getChipName() { return "D flip-flop"; }
method setupPins (line 14) | void setupPins() {
method getPostCount (line 29) | int getPostCount() {
method getVoltageSourceCount (line 32) | int getVoltageSourceCount() { return 2; }
method execute (line 33) | void execute() {
method getDumpType (line 44) | int getDumpType() { return 155; }
method getEditInfo (line 45) | public EditInfo getEditInfo(int n) {
method setEditValue (line 53) | public void setEditValue(int n, EditInfo ei) {
FILE: src/DecadeElm.java
class DecadeElm (line 4) | class DecadeElm extends ChipElm {
method DecadeElm (line 5) | public DecadeElm(int xx, int yy) { super(xx, yy); }
method DecadeElm (line 6) | public DecadeElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 10) | String getChipName() { return "decade counter"; }
method needsBits (line 11) | boolean needsBits() { return true; }
method setupPins (line 12) | void setupPins() {
method getPostCount (line 28) | int getPostCount() { return bits+2; }
method getVoltageSourceCount (line 29) | int getVoltageSourceCount() { return bits; }
method execute (line 30) | void execute() {
method getDumpType (line 48) | int getDumpType() { return 163; }
FILE: src/DiacElm.java
class DiacElm (line 8) | class DiacElm extends CircuitElm {
method DiacElm (line 11) | public DiacElm(int xx, int yy) {
method DiacElm (line 20) | public DiacElm(int xa, int ya, int xb, int yb, int f,
method nonLinear (line 28) | boolean nonLinear() {return true;}
method getDumpType (line 29) | int getDumpType() { return 185; }
method dump (line 30) | String dump() {
method setPoints (line 35) | void setPoints() {
method draw (line 42) | void draw(Graphics g) {
method calculateCurrent (line 54) | void calculateCurrent() {
method startIteration (line 61) | void startIteration() {
method doStep (line 67) | void doStep() {
method stamp (line 73) | void stamp() {
method getInfo (line 77) | void getInfo(String arr[]) {
method getEditInfo (line 87) | public EditInfo getEditInfo(int n) {
method setEditValue (line 98) | public void setEditValue(int n, EditInfo ei) {
FILE: src/Diode.java
class Diode (line 1) | class Diode {
method Diode (line 6) | Diode(CirSim s) {
method setup (line 10) | void setup(double fw, double zv) {
method reset (line 27) | void reset() {
method limitStep (line 36) | double limitStep(double vnew, double vold) {
method stamp (line 89) | void stamp(int n0, int n1) {
method doStep (line 96) | void doStep(double voltdiff) {
method calculateCurrent (line 138) | double calculateCurrent(double voltdiff) {
FILE: src/DiodeElm.java
class DiodeElm (line 4) | class DiodeElm extends CircuitElm {
method DiodeElm (line 10) | public DiodeElm(int xx, int yy) {
method DiodeElm (line 17) | public DiodeElm(int xa, int ya, int xb, int yb, int f,
method nonLinear (line 31) | boolean nonLinear() { return true; }
method setup (line 33) | void setup() {
method getDumpType (line 37) | int getDumpType() { return 'd'; }
method dump (line 38) | String dump() {
method setPoints (line 48) | void setPoints() {
method draw (line 58) | void draw(Graphics g) {
method reset (line 64) | void reset() {
method drawDiode (line 69) | void drawDiode(Graphics g) {
method stamp (line 87) | void stamp() { diode.stamp(nodes[0], nodes[1]); }
method doStep (line 88) | void doStep() {
method calculateCurrent (line 91) | void calculateCurrent() {
method getInfo (line 94) | void getInfo(String arr[]) {
method getEditInfo (line 101) | public EditInfo getEditInfo(int n) {
method setEditValue (line 106) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 110) | int getShortcut() { return 'd'; }
FILE: src/EditDialog.java
type Editable (line 6) | interface Editable {
method getEditInfo (line 7) | EditInfo getEditInfo(int n);
method setEditValue (line 8) | void setEditValue(int n, EditInfo ei);
class EditDialog (line 11) | class EditDialog extends Dialog implements AdjustmentListener, ActionLis...
method EditDialog (line 20) | EditDialog(Editable ce, CirSim f) {
method unitString (line 75) | String unitString(EditInfo ei) {
method parseUnits (line 98) | double parseUnits(EditInfo ei) throws java.text.ParseException {
method apply (line 121) | void apply() {
method actionPerformed (line 140) | public void actionPerformed(ActionEvent e) {
method adjustmentValueChanged (line 166) | public void adjustmentValueChanged(AdjustmentEvent e) {
method itemStateChanged (line 190) | public void itemStateChanged(ItemEvent e) {
method handleEvent (line 210) | public boolean handleEvent(Event ev) {
method setBar (line 218) | void setBar(EditInfo ei) {
method closeDialog (line 223) | protected void closeDialog()
FILE: src/EditDialogLayout.java
class EditDialogLayout (line 4) | class EditDialogLayout implements LayoutManager {
method EditDialogLayout (line 5) | public EditDialogLayout() {}
method addLayoutComponent (line 6) | public void addLayoutComponent(String name, Component c) {}
method removeLayoutComponent (line 7) | public void removeLayoutComponent(Component c) {}
method preferredLayoutSize (line 8) | public Dimension preferredLayoutSize(Container target) {
method minimumLayoutSize (line 11) | public Dimension minimumLayoutSize(Container target) {
method layoutContainer (line 14) | public void layoutContainer(Container target) {
FILE: src/EditInfo.java
class EditInfo (line 3) | class EditInfo {
method EditInfo (line 4) | EditInfo(String n, double val, double mn, double mx) {
method setDimensionless (line 20) | EditInfo setDimensionless() { dimensionless = true; return this; }
FILE: src/EditOptions.java
class EditOptions (line 1) | class EditOptions implements Editable {
method EditOptions (line 3) | public EditOptions(CirSim s) { sim = s; }
method getEditInfo (line 4) | public EditInfo getEditInfo(int n) {
method setEditValue (line 13) | public void setEditValue(int n, EditInfo ei) {
FILE: src/GateElm.java
class GateElm (line 4) | abstract class GateElm extends CircuitElm {
method GateElm (line 9) | public GateElm(int xx, int yy) {
method GateElm (line 15) | public GateElm(int xa, int ya, int xb, int yb, int f,
method isInverting (line 23) | boolean isInverting() { return false; }
method setSize (line 25) | void setSize(int s) {
method dump (line 32) | String dump() {
method setPoints (line 37) | void setPoints() {
method draw (line 63) | void draw(Graphics g) {
method getPostCount (line 84) | int getPostCount() { return inputCount+1; }
method getPost (line 85) | Point getPost(int n) {
method getVoltageSourceCount (line 90) | int getVoltageSourceCount() { return 1; }
method getGateName (line 91) | abstract String getGateName();
method getInfo (line 92) | void getInfo(String arr[]) {
method stamp (line 97) | void stamp() {
method getInput (line 100) | boolean getInput(int x) {
method calcFunction (line 103) | abstract boolean calcFunction();
method doStep (line 104) | void doStep() {
method getEditInfo (line 113) | public EditInfo getEditInfo(int n) {
method setEditValue (line 119) | public void setEditValue(int n, EditInfo ei) {
method getConnection (line 125) | boolean getConnection(int n1, int n2) { return false; }
method hasGroundConnection (line 126) | boolean hasGroundConnection(int n1) {
FILE: src/GraphicElm.java
class GraphicElm (line 1) | class GraphicElm extends CircuitElm
method GraphicElm (line 4) | public GraphicElm(int xx, int yy)
method GraphicElm (line 9) | public GraphicElm(int xa, int ya, int xb, int yb, int flags)
method getPostCount (line 14) | int getPostCount() { return 0; }
FILE: src/GroundElm.java
class GroundElm (line 4) | class GroundElm extends CircuitElm {
method GroundElm (line 5) | public GroundElm(int xx, int yy) { super(xx, yy); }
method GroundElm (line 6) | public GroundElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 10) | int getDumpType() { return 'g'; }
method getPostCount (line 11) | int getPostCount() { return 1; }
method draw (line 12) | void draw(Graphics g) {
method setCurrent (line 27) | void setCurrent(int x, double c) { current = -c; }
method stamp (line 28) | void stamp() {
method getVoltageDiff (line 31) | double getVoltageDiff() { return 0; }
method getVoltageSourceCount (line 32) | int getVoltageSourceCount() { return 1; }
method getInfo (line 33) | void getInfo(String arr[]) {
method hasGroundConnection (line 37) | boolean hasGroundConnection(int n1) { return true; }
method getShortcut (line 38) | int getShortcut() { return 'g'; }
FILE: src/ImportExportAppletDialog.java
class ImportExportAppletDialog (line 6) | class ImportExportAppletDialog
method ImportExportAppletDialog (line 14) | ImportExportAppletDialog(CirSim f, Action type)
method setDump (line 24) | public void setDump(String dump)
method execute (line 29) | public void execute()
FILE: src/ImportExportClipboardDialog.java
class ImportExportClipboardDialog (line 9) | class ImportExportClipboardDialog
method ImportExportClipboardDialog (line 20) | ImportExportClipboardDialog(CirSim f, Action type) {
method setDump (line 41) | public void setDump(String dump)
method execute (line 46) | public void execute()
method actionPerformed (line 53) | public void actionPerformed(ActionEvent e) {
method handleEvent (line 73) | public boolean handleEvent(Event ev) {
FILE: src/ImportExportDialog.java
type ImportExportDialog (line 4) | public interface ImportExportDialog {
type Action (line 5) | public enum Action { IMPORT, EXPORT }
method setDump (line 7) | public void setDump(String dump);
method execute (line 9) | public void execute();
FILE: src/ImportExportDialogFactory.java
class ImportExportDialogFactory (line 1) | public class ImportExportDialogFactory
method Create (line 3) | public static ImportExportDialog Create(CirSim f,
FILE: src/ImportExportDialogLayout.java
class ImportExportDialogLayout (line 3) | class ImportExportDialogLayout implements LayoutManager {
method ImportExportDialogLayout (line 4) | public ImportExportDialogLayout() {}
method addLayoutComponent (line 5) | public void addLayoutComponent(String name, Component c) {}
method removeLayoutComponent (line 6) | public void removeLayoutComponent(Component c) {}
method preferredLayoutSize (line 7) | public Dimension preferredLayoutSize(Container target) {
method minimumLayoutSize (line 10) | public Dimension minimumLayoutSize(Container target) {
method layoutContainer (line 13) | public void layoutContainer(Container target) {
FILE: src/ImportExportFileDialog.java
class ImportExportFileDialog (line 9) | class ImportExportFileDialog
method ImportExportFileDialog (line 17) | ImportExportFileDialog(CirSim f, Action type)
method setDump (line 29) | public void setDump(String dump)
method getDump (line 34) | public String getDump()
method execute (line 39) | public void execute()
method readFile (line 81) | private static String readFile(String path)
method writeFile (line 99) | private static void writeFile(String path)
FILE: src/Inductor.java
class Inductor (line 1) | class Inductor {
method Inductor (line 10) | Inductor(CirSim s) {
method setup (line 14) | void setup(double ic, double cr, int f) {
method isTrapezoidal (line 19) | boolean isTrapezoidal() { return (flags & FLAG_BACK_EULER) == 0; }
method reset (line 20) | void reset() {
method stamp (line 23) | void stamp(int n0, int n1) {
method nonLinear (line 39) | boolean nonLinear() { return false; }
method startIteration (line 41) | void startIteration(double voltdiff) {
method calculateCurrent (line 48) | double calculateCurrent(double voltdiff) {
method doStep (line 56) | void doStep(double voltdiff) {
FILE: src/InductorElm.java
class InductorElm (line 4) | class InductorElm extends CircuitElm {
method InductorElm (line 7) | public InductorElm(int xx, int yy) {
method InductorElm (line 13) | public InductorElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 21) | int getDumpType() { return 'l'; }
method dump (line 22) | String dump() {
method setPoints (line 25) | void setPoints() {
method draw (line 29) | void draw(Graphics g) {
method reset (line 45) | void reset() {
method stamp (line 49) | void stamp() { ind.stamp(nodes[0], nodes[1]); }
method startIteration (line 50) | void startIteration() {
method nonLinear (line 53) | boolean nonLinear() { return ind.nonLinear(); }
method calculateCurrent (line 54) | void calculateCurrent() {
method doStep (line 58) | void doStep() {
method getInfo (line 62) | void getInfo(String arr[]) {
method getEditInfo (line 68) | public EditInfo getEditInfo(int n) {
method setEditValue (line 79) | public void setEditValue(int n, EditInfo ei) {
FILE: src/InverterElm.java
class InverterElm (line 4) | class InverterElm extends CircuitElm {
method InverterElm (line 6) | public InverterElm(int xx, int yy) {
method InverterElm (line 11) | public InverterElm(int xa, int ya, int xb, int yb, int f,
method dump (line 21) | String dump() {
method getDumpType (line 25) | int getDumpType() { return 'I'; }
method draw (line 26) | void draw(Graphics g) {
method setPoints (line 37) | void setPoints() {
method getVoltageSourceCount (line 52) | int getVoltageSourceCount() { return 1; }
method stamp (line 53) | void stamp() {
method doStep (line 56) | void doStep() {
method getVoltageDiff (line 63) | double getVoltageDiff() { return volts[0]; }
method getInfo (line 64) | void getInfo(String arr[]) {
method getEditInfo (line 69) | public EditInfo getEditInfo(int n) {
method setEditValue (line 74) | public void setEditValue(int n, EditInfo ei) {
method getConnection (line 79) | boolean getConnection(int n1, int n2) { return false; }
method hasGroundConnection (line 80) | boolean hasGroundConnection(int n1) {
method getShortcut (line 83) | int getShortcut() { return '1'; }
FILE: src/JKFlipFlopElm.java
class JKFlipFlopElm (line 4) | class JKFlipFlopElm extends ChipElm {
method JKFlipFlopElm (line 5) | public JKFlipFlopElm(int xx, int yy) { super(xx, yy); }
method JKFlipFlopElm (line 6) | public JKFlipFlopElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 11) | String getChipName() { return "JK flip-flop"; }
method setupPins (line 12) | void setupPins() {
method getPostCount (line 27) | int getPostCount() { return 5; }
method getVoltageSourceCount (line 28) | int getVoltageSourceCount() { return 2; }
method execute (line 29) | void execute() {
method getDumpType (line 44) | int getDumpType() { return 156; }
FILE: src/JfetElm.java
class JfetElm (line 4) | class JfetElm extends MosfetElm {
method JfetElm (line 5) | JfetElm(int xx, int yy, boolean pnpflag) {
method JfetElm (line 9) | public JfetElm(int xa, int ya, int xb, int yb, int f,
method draw (line 19) | void draw(Graphics g) {
method setPoints (line 41) | void setPoints() {
method getDumpType (line 65) | int getDumpType() { return 'j'; }
method getDefaultThreshold (line 67) | double getDefaultThreshold() { return -4; }
method getBeta (line 68) | double getBeta() { return .00125; }
method getInfo (line 69) | void getInfo(String arr[]) {
FILE: src/LEDElm.java
class LEDElm (line 4) | class LEDElm extends DiodeElm {
method LEDElm (line 6) | public LEDElm(int xx, int yy) {
method LEDElm (line 12) | public LEDElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 22) | int getDumpType() { return 162; }
method dump (line 23) | String dump() {
method setPoints (line 28) | void setPoints() {
method draw (line 36) | void draw(Graphics g) {
method getInfo (line 64) | void getInfo(String arr[]) {
method getEditInfo (line 69) | public EditInfo getEditInfo(int n) {
method setEditValue (line 83) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 93) | int getShortcut() { return 'l'; }
FILE: src/LampElm.java
class LampElm (line 4) | class LampElm extends CircuitElm {
method LampElm (line 8) | public LampElm(int xx, int yy) {
method LampElm (line 16) | public LampElm(int xa, int ya, int xb, int yb, int f,
method dump (line 25) | String dump() {
method getDumpType (line 29) | int getDumpType() { return 181; }
method reset (line 34) | void reset() {
method setPoints (line 39) | void setPoints() {
method getTempColor (line 54) | Color getTempColor() {
method draw (line 76) | void draw(Graphics g) {
method calculateCurrent (line 110) | void calculateCurrent() {
method stamp (line 114) | void stamp() {
method nonLinear (line 118) | boolean nonLinear() { return true; }
method startIteration (line 119) | void startIteration() {
method doStep (line 136) | void doStep() {
method getInfo (line 139) | void getInfo(String arr[]) {
method getEditInfo (line 146) | public EditInfo getEditInfo(int n) {
method setEditValue (line 158) | public void setEditValue(int n, EditInfo ei) {
FILE: src/LatchElm.java
class LatchElm (line 4) | class LatchElm extends ChipElm {
method LatchElm (line 5) | public LatchElm(int xx, int yy) { super(xx, yy); }
method LatchElm (line 6) | public LatchElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 10) | String getChipName() { return "Latch"; }
method needsBits (line 11) | boolean needsBits() { return true; }
method setupPins (line 13) | void setupPins() {
method execute (line 28) | void execute() {
method getVoltageSourceCount (line 35) | int getVoltageSourceCount() { return bits; }
method getPostCount (line 36) | int getPostCount() { return bits*2+1; }
method getDumpType (line 37) | int getDumpType() { return 168; }
FILE: src/LogicInputElm.java
class LogicInputElm (line 4) | class LogicInputElm extends SwitchElm {
method LogicInputElm (line 9) | public LogicInputElm(int xx, int yy) {
method LogicInputElm (line 15) | public LogicInputElm(int xa, int ya, int xb, int yb, int f,
method isTernary (line 28) | boolean isTernary() { return (flags & FLAG_TERNARY) != 0; }
method isNumeric (line 29) | boolean isNumeric() { return (flags & (FLAG_TERNARY|FLAG_NUMERIC)) != ...
method getDumpType (line 30) | int getDumpType() { return 'L'; }
method dump (line 31) | String dump() {
method getPostCount (line 34) | int getPostCount() { return 1; }
method setPoints (line 35) | void setPoints() {
method draw (line 40) | void draw(Graphics g) {
method setCurrent (line 56) | void setCurrent(int vs, double c) { current = -c; }
method stamp (line 57) | void stamp() {
method getVoltageSourceCount (line 63) | int getVoltageSourceCount() { return 1; }
method getVoltageDiff (line 64) | double getVoltageDiff() { return volts[0]; }
method getInfo (line 65) | void getInfo(String arr[]) {
method hasGroundConnection (line 73) | boolean hasGroundConnection(int n1) { return true; }
method getEditInfo (line 74) | public EditInfo getEditInfo(int n) {
method setEditValue (line 86) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 94) | int getShortcut() { return 'i'; }
FILE: src/LogicOutputElm.java
class LogicOutputElm (line 4) | class LogicOutputElm extends CircuitElm {
method LogicOutputElm (line 11) | public LogicOutputElm(int xx, int yy) {
method LogicOutputElm (line 16) | public LogicOutputElm(int xa, int ya, int xb, int yb, int f,
method dump (line 25) | String dump() {
method getDumpType (line 28) | int getDumpType() { return 'M'; }
method getPostCount (line 29) | int getPostCount() { return 1; }
method isTernary (line 30) | boolean isTernary() { return (flags & FLAG_TERNARY) != 0; }
method isNumeric (line 32) | boolean isNumeric() { return true; }
method needsPullDown (line 33) | boolean needsPullDown() { return (flags & FLAG_PULLDOWN) != 0; }
method setPoints (line 34) | void setPoints() {
method draw (line 39) | void draw(Graphics g) {
method stamp (line 62) | void stamp() {
method getVoltageDiff (line 66) | double getVoltageDiff() { return volts[0]; }
method getInfo (line 67) | void getInfo(String arr[]) {
method getEditInfo (line 74) | public EditInfo getEditInfo(int n) {
method setEditValue (line 84) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 94) | int getShortcut() { return 'o'; }
FILE: src/MemristorElm.java
class MemristorElm (line 4) | class MemristorElm extends CircuitElm {
method MemristorElm (line 6) | public MemristorElm(int xx, int yy) {
method MemristorElm (line 15) | public MemristorElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 25) | int getDumpType() { return 'm'; }
method dump (line 26) | String dump() {
method setPoints (line 32) | void setPoints() {
method draw (line 39) | void draw(Graphics g) {
method nonLinear (line 72) | boolean nonLinear() { return true; }
method calculateCurrent (line 73) | void calculateCurrent() {
method reset (line 76) | void reset() {
method startIteration (line 79) | void startIteration() {
method stamp (line 88) | void stamp() {
method doStep (line 92) | void doStep() {
method getInfo (line 95) | void getInfo(String arr[]) {
method getScopeValue (line 101) | double getScopeValue(int x) {
method getScopeUnits (line 104) | String getScopeUnits(int x) {
method getEditInfo (line 107) | public EditInfo getEditInfo(int n) {
method setEditValue (line 120) | public void setEditValue(int n, EditInfo ei) {
FILE: src/MosfetElm.java
class MosfetElm (line 4) | class MosfetElm extends CircuitElm {
method MosfetElm (line 10) | MosfetElm(int xx, int yy, boolean pnpflag) {
method MosfetElm (line 17) | public MosfetElm(int xa, int ya, int xb, int yb, int f,
method getDefaultThreshold (line 27) | double getDefaultThreshold() { return 1.5; }
method getBeta (line 28) | double getBeta() { return .02; }
method nonLinear (line 29) | boolean nonLinear() { return true; }
method drawDigital (line 30) | boolean drawDigital() { return (flags & FLAG_DIGITAL) != 0; }
method reset (line 31) | void reset() {
method dump (line 34) | String dump() {
method getDumpType (line 37) | int getDumpType() { return 'f'; }
method draw (line 40) | void draw(Graphics g) {
method getPost (line 92) | Point getPost(int n) {
method getCurrent (line 95) | double getCurrent() { return ids; }
method getPower (line 96) | double getPower() { return ids*(volts[2]-volts[1]); }
method getPostCount (line 97) | int getPostCount() { return 3; }
method setPoints (line 103) | void setPoints() {
method stamp (line 137) | void stamp() {
method doStep (line 141) | void doStep() {
method getFetInfo (line 216) | void getFetInfo(String arr[], String n) {
method getInfo (line 226) | void getInfo(String arr[]) {
method canViewInScope (line 229) | boolean canViewInScope() { return true; }
method getVoltageDiff (line 230) | double getVoltageDiff() { return volts[2] - volts[1]; }
method getConnection (line 231) | boolean getConnection(int n1, int n2) {
method getEditInfo (line 234) | public EditInfo getEditInfo(int n) {
method setEditValue (line 245) | public void setEditValue(int n, EditInfo ei) {
FILE: src/NJfetElm.java
class NJfetElm (line 1) | class NJfetElm extends JfetElm {
method NJfetElm (line 2) | public NJfetElm(int xx, int yy) { super(xx, yy, false); }
method getDumpClass (line 3) | Class getDumpClass() { return JfetElm.class; }
class PJfetElm (line 6) | class PJfetElm extends JfetElm {
method PJfetElm (line 7) | public PJfetElm(int xx, int yy) { super(xx, yy, true); }
method getDumpClass (line 8) | Class getDumpClass() { return JfetElm.class; }
FILE: src/NMosfetElm.java
class NMosfetElm (line 1) | class NMosfetElm extends MosfetElm {
method NMosfetElm (line 2) | public NMosfetElm(int xx, int yy) { super(xx, yy, false); }
method getDumpClass (line 3) | Class getDumpClass() { return MosfetElm.class; }
FILE: src/NTransistorElm.java
class NTransistorElm (line 1) | class NTransistorElm extends TransistorElm {
method NTransistorElm (line 2) | public NTransistorElm(int xx, int yy) { super(xx, yy, false); }
method getDumpClass (line 3) | Class getDumpClass() { return TransistorElm.class; }
FILE: src/NandGateElm.java
class NandGateElm (line 4) | class NandGateElm extends AndGateElm {
method NandGateElm (line 5) | public NandGateElm(int xx, int yy) { super(xx, yy); }
method NandGateElm (line 6) | public NandGateElm(int xa, int ya, int xb, int yb, int f,
method isInverting (line 10) | boolean isInverting() { return true; }
method getGateName (line 11) | String getGateName() { return "NAND gate"; }
method getDumpType (line 12) | int getDumpType() { return 151; }
method getShortcut (line 13) | int getShortcut() { return '@'; }
FILE: src/NorGateElm.java
class NorGateElm (line 4) | class NorGateElm extends OrGateElm {
method NorGateElm (line 5) | public NorGateElm(int xx, int yy) { super(xx, yy); }
method NorGateElm (line 6) | public NorGateElm(int xa, int ya, int xb, int yb, int f,
method getGateName (line 10) | String getGateName() { return "NOR gate"; }
method isInverting (line 11) | boolean isInverting() { return true; }
method getDumpType (line 12) | int getDumpType() { return 153; }
method getShortcut (line 13) | int getShortcut() { return '#'; }
FILE: src/OpAmpElm.java
class OpAmpElm (line 4) | class OpAmpElm extends CircuitElm {
method OpAmpElm (line 11) | public OpAmpElm(int xx, int yy) {
method OpAmpElm (line 20) | public OpAmpElm(int xa, int ya, int xb, int yb, int f,
method setGain (line 38) | void setGain() {
method dump (line 44) | String dump() {
method nonLinear (line 47) | boolean nonLinear() { return true; }
method draw (line 48) | void draw(Graphics g) {
method getPower (line 66) | double getPower() { return volts[2]*current; }
method setSize (line 70) | void setSize(int s) {
method setPoints (line 76) | void setPoints() {
method getPostCount (line 98) | int getPostCount() { return 3; }
method getPost (line 99) | Point getPost(int n) {
method getVoltageSourceCount (line 102) | int getVoltageSourceCount() { return 1; }
method getInfo (line 103) | void getInfo(String arr[]) {
method stamp (line 118) | void stamp() {
method doStep (line 123) | void doStep() {
method getConnection (line 154) | boolean getConnection(int n1, int n2) { return false; }
method hasGroundConnection (line 155) | boolean hasGroundConnection(int n1) {
method getVoltageDiff (line 158) | double getVoltageDiff() { return volts[2] - volts[1]; }
method getDumpType (line 159) | int getDumpType() { return 'a'; }
method getEditInfo (line 160) | public EditInfo getEditInfo(int n) {
method setEditValue (line 167) | public void setEditValue(int n, EditInfo ei) {
FILE: src/OpAmpSwapElm.java
class OpAmpSwapElm (line 1) | class OpAmpSwapElm extends OpAmpElm {
method OpAmpSwapElm (line 2) | public OpAmpSwapElm(int xx, int yy) {
method getDumpClass (line 6) | Class getDumpClass() { return OpAmpElm.class; }
FILE: src/OrGateElm.java
class OrGateElm (line 4) | class OrGateElm extends GateElm {
method OrGateElm (line 5) | public OrGateElm(int xx, int yy) { super(xx, yy); }
method OrGateElm (line 6) | public OrGateElm(int xa, int ya, int xb, int yb, int f,
method getGateName (line 10) | String getGateName() { return "OR gate"; }
method setPoints (line 11) | void setPoints() {
method calcFunction (line 44) | boolean calcFunction() {
method getDumpType (line 51) | int getDumpType() { return 152; }
method getShortcut (line 52) | int getShortcut() { return '3'; }
FILE: src/OutputElm.java
class OutputElm (line 4) | class OutputElm extends CircuitElm {
method OutputElm (line 6) | public OutputElm(int xx, int yy) { super(xx, yy); }
method OutputElm (line 7) | public OutputElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 11) | int getDumpType() { return 'O'; }
method getPostCount (line 12) | int getPostCount() { return 1; }
method setPoints (line 13) | void setPoints() {
method draw (line 17) | void draw(Graphics g) {
method getVoltageDiff (line 37) | double getVoltageDiff() { return volts[0]; }
method getInfo (line 38) | void getInfo(String arr[]) {
method getEditInfo (line 42) | public EditInfo getEditInfo(int n) {
method setEditValue (line 51) | public void setEditValue(int n, EditInfo ei) {
FILE: src/PMosfetElm.java
class PMosfetElm (line 1) | class PMosfetElm extends MosfetElm {
method PMosfetElm (line 2) | public PMosfetElm(int xx, int yy) { super(xx, yy, true); }
method getDumpClass (line 3) | Class getDumpClass() { return MosfetElm.class; }
FILE: src/PTransistorElm.java
class PTransistorElm (line 1) | class PTransistorElm extends TransistorElm {
method PTransistorElm (line 2) | public PTransistorElm(int xx, int yy) { super(xx, yy, true); }
method getDumpClass (line 3) | Class getDumpClass() { return TransistorElm.class; }
FILE: src/PhaseCompElm.java
class PhaseCompElm (line 4) | class PhaseCompElm extends ChipElm {
method PhaseCompElm (line 5) | public PhaseCompElm(int xx, int yy) { super(xx, yy); }
method PhaseCompElm (line 6) | public PhaseCompElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 10) | String getChipName() { return "phase comparator"; }
method setupPins (line 11) | void setupPins() {
method nonLinear (line 20) | boolean nonLinear() { return true; }
method stamp (line 21) | void stamp() {
method doStep (line 28) | void doStep() {
method getPostCount (line 49) | int getPostCount() { return 3; }
method getVoltageSourceCount (line 50) | int getVoltageSourceCount() { return 1; }
method getDumpType (line 51) | int getDumpType() { return 161; }
FILE: src/PhotoResistorElm.java
class PhotoResistorElm (line 8) | class PhotoResistorElm extends CircuitElm {
method PhotoResistorElm (line 13) | public PhotoResistorElm(int xx, int yy) {
method PhotoResistorElm (line 19) | public PhotoResistorElm(int xa, int ya, int xb, int yb, int f,
method nonLinear (line 26) | boolean nonLinear() {return true;}
method getDumpType (line 27) | int getDumpType() { return 186; }
method dump (line 28) | String dump() {
method createSlider (line 32) | void createSlider() {
method setPoints (line 38) | void setPoints() {
method delete (line 44) | void delete() {
method draw (line 49) | void draw(Graphics g) {
method calculateCurrent (line 61) | void calculateCurrent() {
method startIteration (line 65) | void startIteration() {
method doStep (line 71) | void doStep() {
method stamp (line 74) | void stamp() {
method getInfo (line 78) | void getInfo(String arr[]) {
method getEditInfo (line 86) | public EditInfo getEditInfo(int n) {
method setEditValue (line 94) | public void setEditValue(int n, EditInfo ei) {
FILE: src/PotElm.java
class PotElm (line 5) | class PotElm extends CircuitElm implements AdjustmentListener {
method PotElm (line 12) | public PotElm(int xx, int yy) {
method PotElm (line 20) | public PotElm(int xa, int ya, int xb, int yb, int f,
method setup (line 30) | void setup() {
method getPostCount (line 32) | int getPostCount() { return 3; }
method getDumpType (line 33) | int getDumpType() { return 174; }
method getPost (line 34) | Point getPost(int n) {
method dump (line 37) | String dump() { return super.dump() + " " + maxResistance + " " +
method createSlider (line 39) | void createSlider() {
method adjustmentValueChanged (line 46) | public void adjustmentValueChanged(AdjustmentEvent e) {
method delete (line 50) | void delete() {
method setPoints (line 57) | void setPoints() {
method draw (line 92) | void draw(Graphics g) {
method calculateCurrent (line 158) | void calculateCurrent() {
method stamp (line 163) | void stamp() {
method getInfo (line 169) | void getInfo(String arr[]) {
method getEditInfo (line 177) | public EditInfo getEditInfo(int n) {
method setEditValue (line 188) | public void setEditValue(int n, EditInfo ei) {
FILE: src/ProbeElm.java
class ProbeElm (line 4) | class ProbeElm extends CircuitElm {
method ProbeElm (line 6) | public ProbeElm(int xx, int yy) { super(xx, yy); }
method ProbeElm (line 7) | public ProbeElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 11) | int getDumpType() { return 'p'; }
method setPoints (line 14) | void setPoints() {
method draw (line 24) | void draw(Graphics g) {
method mustShowVoltage (line 51) | boolean mustShowVoltage() {
method getInfo (line 55) | void getInfo(String arr[]) {
method getConnection (line 59) | boolean getConnection(int n1, int n2) { return false; }
method getEditInfo (line 61) | public EditInfo getEditInfo(int n) {
method setEditValue (line 69) | public void setEditValue(int n, EditInfo ei) {
FILE: src/PushSwitchElm.java
class PushSwitchElm (line 1) | class PushSwitchElm extends SwitchElm {
method PushSwitchElm (line 2) | public PushSwitchElm(int xx, int yy) { super(xx, yy, true); }
method getDumpClass (line 3) | Class getDumpClass() { return SwitchElm.class; }
method getShortcut (line 4) | int getShortcut() { return 0; }
FILE: src/RailElm.java
class RailElm (line 4) | class RailElm extends VoltageElm {
method RailElm (line 5) | public RailElm(int xx, int yy) { super(xx, yy, WF_DC); }
method RailElm (line 6) | RailElm(int xx, int yy, int wf) { super(xx, yy, wf); }
method RailElm (line 7) | public RailElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 12) | int getDumpType() { return 'R'; }
method getPostCount (line 13) | int getPostCount() { return 1; }
method setPoints (line 15) | void setPoints() {
method draw (line 19) | void draw(Graphics g) {
method getVoltageDiff (line 48) | double getVoltageDiff() { return volts[0]; }
method stamp (line 49) | void stamp() {
method doStep (line 55) | void doStep() {
method hasGroundConnection (line 59) | boolean hasGroundConnection(int n1) { return true; }
method getShortcut (line 60) | int getShortcut() { return 'V'; }
FILE: src/RelayElm.java
class RelayElm (line 12) | class RelayElm extends CircuitElm {
method RelayElm (line 29) | public RelayElm(int xx, int yy) {
method RelayElm (line 43) | public RelayElm(int xa, int ya, int xb, int yb, int f,
method setupPoles (line 59) | void setupPoles() {
method getDumpType (line 69) | int getDumpType() { return 178; }
method dump (line 71) | String dump() {
method draw (line 77) | void draw(Graphics g) {
method setPoints (line 133) | void setPoints() {
method getPost (line 171) | Point getPost(int n) {
method getPostCount (line 176) | int getPostCount() { return 2+poleCount*3; }
method getInternalNodeCount (line 177) | int getInternalNodeCount() { return 1; }
method reset (line 178) | void reset() {
method stamp (line 187) | void stamp() {
method startIteration (line 197) | void startIteration() {
method nonLinear (line 219) | boolean nonLinear() { return true; }
method doStep (line 221) | void doStep() {
method calculateCurrent (line 232) | void calculateCurrent() {
method getInfo (line 247) | void getInfo(String arr[]) {
method getEditInfo (line 258) | public EditInfo getEditInfo(int n) {
method setEditValue (line 280) | public void setEditValue(int n, EditInfo ei) {
method getConnection (line 305) | boolean getConnection(int n1, int n2) {
method getShortcut (line 308) | int getShortcut() { return 'R'; }
FILE: src/ResistorElm.java
class ResistorElm (line 4) | class ResistorElm extends CircuitElm {
method ResistorElm (line 6) | public ResistorElm(int xx, int yy) { super(xx, yy); resistance = 100; }
method ResistorElm (line 7) | public ResistorElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 12) | int getDumpType() { return 'r'; }
method dump (line 13) | String dump() {
method setPoints (line 18) | void setPoints() {
method draw (line 25) | void draw(Graphics g) {
method calculateCurrent (line 76) | void calculateCurrent() {
method stamp (line 80) | void stamp() {
method getInfo (line 83) | void getInfo(String arr[]) {
method getEditInfo (line 89) | public EditInfo getEditInfo(int n) {
method setEditValue (line 95) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 99) | int getShortcut() { return 'r'; }
FILE: src/RowInfo.java
class RowInfo (line 2) | class RowInfo {
method RowInfo (line 11) | RowInfo() { type = ROW_NORMAL; }
FILE: src/SCRElm.java
class SCRElm (line 11) | class SCRElm extends CircuitElm {
method SCRElm (line 17) | public SCRElm(int xx, int yy) {
method SCRElm (line 22) | public SCRElm(int xa, int ya, int xb, int yb, int f,
method setDefaults (line 39) | void setDefaults() {
method setup (line 44) | void setup() {
method nonLinear (line 48) | boolean nonLinear() { return true; }
method reset (line 49) | void reset() {
method getDumpType (line 54) | int getDumpType() { return 177; }
method dump (line 55) | String dump() {
method setPoints (line 68) | void setPoints() {
method draw (line 99) | void draw(Graphics g) {
method getPost (line 133) | Point getPost(int n) {
method getPostCount (line 137) | int getPostCount() { return 3; }
method getInternalNodeCount (line 138) | int getInternalNodeCount() { return 1; }
method getPower (line 139) | double getPower() {
method stamp (line 144) | void stamp() {
method doStep (line 153) | void doStep() {
method getInfo (line 169) | void getInfo(String arr[]) {
method calculateCurrent (line 180) | void calculateCurrent() {
method getEditInfo (line 185) | public EditInfo getEditInfo(int n) {
method setEditValue (line 195) | public void setEditValue(int n, EditInfo ei) {
FILE: src/Scope.java
class Scope (line 8) | class Scope {
method Scope (line 33) | Scope(CirSim s) {
method showCurrent (line 38) | void showCurrent(boolean b) { showI = b; value = ivalue = 0; }
method showVoltage (line 39) | void showVoltage(boolean b) { showV = b; value = ivalue = 0; }
method showMax (line 40) | void showMax (boolean b) { showMax = b; }
method showMin (line 41) | void showMin (boolean b) { showMin = b; }
method showFreq (line 42) | void showFreq (boolean b) { showFreq = b; }
method setLockScale (line 43) | void setLockScale (boolean b) { lockScale = b; }
method resetGraph (line 44) | void resetGraph() {
method active (line 55) | boolean active() { return elm != null; }
method reset (line 56) | void reset() {
method setRect (line 73) | void setRect(Rectangle r) {
method getWidth (line 77) | int getWidth() { return rect.width; }
method rightEdge (line 78) | int rightEdge() { return rect.x+rect.width; }
method setElm (line 80) | void setElm(CircuitElm ce) {
method timeStep (line 85) | void timeStep() {
method drawTo (line 133) | void drawTo(int x2, int y2) {
method clear2dView (line 164) | void clear2dView() {
method adjustScale (line 171) | void adjustScale(double x) {
method draw2d (line 176) | void draw2d(Graphics g) {
method draw (line 205) | void draw(Graphics g) {
method speedUp (line 457) | void speedUp() {
method slowDown (line 463) | void slowDown() {
method getMenu (line 468) | PopupMenu getMenu() {
method setValue (line 495) | void setValue(int x) { reset(); value = x; }
method dump (line 496) | String dump() {
method undump (line 516) | void undump(StringTokenizer st) {
method allocImage (line 558) | void allocImage() {
method handleMenu (line 606) | void handleMenu(ItemEvent e, Object mi) {
method select (line 654) | void select() {
method selectY (line 662) | void selectY() {
FILE: src/SevenSegElm.java
class SevenSegElm (line 4) | class SevenSegElm extends ChipElm {
method SevenSegElm (line 5) | public SevenSegElm(int xx, int yy) { super(xx, yy); }
method SevenSegElm (line 6) | public SevenSegElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 10) | String getChipName() { return "7-segment driver/display"; }
method setupPins (line 12) | void setupPins() {
method draw (line 25) | void draw(Graphics g) {
method setColor (line 45) | void setColor(Graphics g, int p) {
method getPostCount (line 49) | int getPostCount() { return 7; }
method getVoltageSourceCount (line 50) | int getVoltageSourceCount() { return 0; }
method getDumpType (line 51) | int getDumpType() { return 157; }
FILE: src/SparkGapElm.java
class SparkGapElm (line 4) | class SparkGapElm extends CircuitElm {
method SparkGapElm (line 7) | public SparkGapElm(int xx, int yy) {
method SparkGapElm (line 15) | public SparkGapElm(int xa, int ya, int xb, int yb, int f,
method nonLinear (line 23) | boolean nonLinear() {return true;}
method getDumpType (line 24) | int getDumpType() { return 187; }
method dump (line 25) | String dump() {
method setPoints (line 30) | void setPoints() {
method draw (line 41) | void draw(Graphics g) {
method calculateCurrent (line 57) | void calculateCurrent() {
method reset (line 62) | void reset() {
method startIteration (line 67) | void startIteration() {
method doStep (line 75) | void doStep() {
method stamp (line 79) | void stamp() {
method getInfo (line 83) | void getInfo(String arr[]) {
method getEditInfo (line 91) | public EditInfo getEditInfo(int n) {
method setEditValue (line 103) | public void setEditValue(int n, EditInfo ei) {
FILE: src/SquareRailElm.java
class SquareRailElm (line 1) | class SquareRailElm extends RailElm {
method SquareRailElm (line 2) | public SquareRailElm(int xx, int yy) { super(xx, yy, WF_SQUARE); }
method getDumpClass (line 3) | Class getDumpClass() { return RailElm.class; }
method getShortcut (line 4) | int getShortcut() { return 0; }
FILE: src/SweepElm.java
class SweepElm (line 4) | class SweepElm extends CircuitElm {
method SweepElm (line 9) | public SweepElm(int xx, int yy) {
method SweepElm (line 17) | public SweepElm(int xa, int ya, int xb, int yb, int f, StringTokenizer...
method getDumpType (line 25) | int getDumpType() { return 170; }
method getPostCount (line 26) | int getPostCount() { return 1; }
method dump (line 29) | String dump() {
method setPoints (line 33) | void setPoints() {
method draw (line 37) | void draw(Graphics g) {
method stamp (line 77) | void stamp() {
method setParams (line 82) | void setParams() {
method reset (line 97) | void reset() {
method startIteration (line 104) | void startIteration() {
method doStep (line 125) | void doStep() {
method getVoltageDiff (line 129) | double getVoltageDiff() { return volts[0]; }
method getVoltageSourceCount (line 130) | int getVoltageSourceCount() { return 1; }
method hasGroundConnection (line 131) | boolean hasGroundConnection(int n1) { return true; }
method getInfo (line 132) | void getInfo(String arr[]) {
method getEditInfo (line 141) | public EditInfo getEditInfo(int n) {
method setEditValue (line 162) | public void setEditValue(int n, EditInfo ei) {
FILE: src/Switch2Elm.java
class Switch2Elm (line 4) | class Switch2Elm extends SwitchElm {
method Switch2Elm (line 8) | public Switch2Elm(int xx, int yy) {
method Switch2Elm (line 12) | Switch2Elm(int xx, int yy, boolean mm) {
method Switch2Elm (line 16) | public Switch2Elm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 22) | int getDumpType() { return 'S'; }
method dump (line 23) | String dump() {
method setPoints (line 29) | void setPoints() {
method draw (line 40) | void draw(Graphics g) {
method getPost (line 66) | Point getPost(int n) {
method getPostCount (line 69) | int getPostCount() { return 3; }
method calculateCurrent (line 70) | void calculateCurrent() {
method stamp (line 74) | void stamp() {
method getVoltageSourceCount (line 79) | int getVoltageSourceCount() {
method toggle (line 82) | void toggle() {
method getConnection (line 96) | boolean getConnection(int n1, int n2) {
method getInfo (line 101) | void getInfo(String arr[]) {
method getEditInfo (line 105) | public EditInfo getEditInfo(int n) {
method setEditValue (line 113) | public void setEditValue(int n, EditInfo ei) {
method hasCenterOff (line 124) | boolean hasCenterOff() { return (flags & FLAG_CENTER_OFF) != 0; }
method getShortcut (line 125) | int getShortcut() { return 'S'; }
FILE: src/SwitchElm.java
class SwitchElm (line 4) | class SwitchElm extends CircuitElm {
method SwitchElm (line 8) | public SwitchElm(int xx, int yy) {
method SwitchElm (line 14) | SwitchElm(int xx, int yy, boolean mm) {
method SwitchElm (line 20) | public SwitchElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 33) | int getDumpType() { return 's'; }
method dump (line 34) | String dump() {
method setPoints (line 39) | void setPoints() {
method draw (line 46) | void draw(Graphics g) {
method calculateCurrent (line 65) | void calculateCurrent() {
method stamp (line 69) | void stamp() {
method getVoltageSourceCount (line 73) | int getVoltageSourceCount() {
method mouseUp (line 76) | void mouseUp() {
method toggle (line 80) | void toggle() {
method getInfo (line 85) | void getInfo(String arr[]) {
method getConnection (line 96) | boolean getConnection(int n1, int n2) { return position == 0; }
method isWire (line 97) | boolean isWire() { return true; }
method getEditInfo (line 98) | public EditInfo getEditInfo(int n) {
method setEditValue (line 106) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 110) | int getShortcut() { return 's'; }
FILE: src/TappedTransformerElm.java
class TappedTransformerElm (line 4) | class TappedTransformerElm extends CircuitElm {
method TappedTransformerElm (line 8) | public TappedTransformerElm(int xx, int yy) {
method TappedTransformerElm (line 19) | public TappedTransformerElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 36) | int getDumpType() { return 169; }
method dump (line 37) | String dump() {
method draw (line 41) | void draw(Graphics g) {
method setPoints (line 79) | void setPoints() {
method getPost (line 104) | Point getPost(int n) {
method getPostCount (line 107) | int getPostCount() { return 5; }
method reset (line 108) | void reset() {
method stamp (line 113) | void stamp() {
method startIteration (line 168) | void startIteration() {
method doStep (line 180) | void doStep() {
method calculateCurrent (line 185) | void calculateCurrent() {
method getInfo (line 196) | void getInfo(String arr[]) {
method getConnection (line 205) | boolean getConnection(int n1, int n2) {
method getEditInfo (line 216) | public EditInfo getEditInfo(int n) {
method setEditValue (line 223) | public void setEditValue(int n, EditInfo ei) {
FILE: src/TextElm.java
class TextElm (line 5) | class TextElm extends GraphicElm {
method TextElm (line 11) | public TextElm(int xx, int yy) {
method TextElm (line 18) | public TextElm(int xa, int ya, int xb, int yb, int f,
method split (line 27) | void split() {
method dump (line 46) | String dump() {
method getDumpType (line 49) | int getDumpType() { return 'x'; }
method drag (line 50) | void drag(int xx, int yy) {
method draw (line 56) | void draw(Graphics g) {
method getEditInfo (line 89) | public EditInfo getEditInfo(int n) {
method setEditValue (line 111) | public void setEditValue(int n, EditInfo ei) {
method isCenteredText (line 131) | boolean isCenteredText() { return (flags & FLAG_CENTER) != 0; }
method getInfo (line 132) | void getInfo(String arr[]) {
method getShortcut (line 135) | @Override
FILE: src/ThermistorElm.java
class ThermistorElm (line 8) | class ThermistorElm extends CircuitElm {
method ThermistorElm (line 13) | public ThermistorElm(int xx, int yy) {
method ThermistorElm (line 19) | public ThermistorElm(int xa, int ya, int xb, int yb, int f,
method nonLinear (line 26) | boolean nonLinear() {return true;}
method getDumpType (line 27) | int getDumpType() { return 188; }
method dump (line 28) | String dump() {
method createSlider (line 32) | void createSlider() {
method setPoints (line 38) | void setPoints() {
method delete (line 44) | void delete() {
method draw (line 49) | void draw(Graphics g) {
method calculateCurrent (line 61) | void calculateCurrent() {
method startIteration (line 65) | void startIteration() {
method doStep (line 71) | void doStep() {
method stamp (line 74) | void stamp() {
method getInfo (line 78) | void getInfo(String arr[]) {
method getEditInfo (line 86) | public EditInfo getEditInfo(int n) {
method setEditValue (line 94) | public void setEditValue(int n, EditInfo ei) {
FILE: src/TimerElm.java
class TimerElm (line 4) | class TimerElm extends ChipElm {
method getDefaultFlags (line 13) | int getDefaultFlags() { return FLAG_RESET; }
method TimerElm (line 14) | public TimerElm(int xx, int yy) { super(xx, yy); }
method TimerElm (line 15) | public TimerElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 19) | String getChipName() { return "555 Timer"; }
method setupPins (line 20) | void setupPins() {
method nonLinear (line 34) | boolean nonLinear() { return true; }
method hasReset (line 35) | boolean hasReset() { return (flags & FLAG_RESET) != 0; }
method stamp (line 36) | void stamp() {
method calculateCurrent (line 45) | void calculateCurrent() {
method startIteration (line 53) | void startIteration() {
method doStep (line 62) | void doStep() {
method getPostCount (line 74) | int getPostCount() { return hasReset() ? 7 : 6; }
method getVoltageSourceCount (line 75) | int getVoltageSourceCount() { return 1; }
method getDumpType (line 76) | int getDumpType() { return 165; }
FILE: src/TransLineElm.java
class TransLineElm (line 4) | class TransLineElm extends CircuitElm {
method TransLineElm (line 8) | public TransLineElm(int xx, int yy) {
method TransLineElm (line 15) | public TransLineElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 26) | int getDumpType() { return 171; }
method getPostCount (line 27) | int getPostCount() { return 4; }
method getInternalNodeCount (line 28) | int getInternalNodeCount() { return 2; }
method dump (line 29) | String dump() {
method drag (line 32) | void drag(int xx, int yy) {
method reset (line 50) | void reset() {
method setPoints (line 64) | void setPoints() {
method draw (line 82) | void draw(Graphics g) {
method setVoltageSource (line 124) | void setVoltageSource(int n, int v) {
method setCurrent (line 130) | void setCurrent(int v, double c) {
method stamp (line 137) | void stamp() {
method startIteration (line 144) | void startIteration() {
method doStep (line 158) | void doStep() {
method getPost (line 171) | Point getPost(int n) {
method getVoltageSourceCount (line 176) | int getVoltageSourceCount() { return 2; }
method hasGroundConnection (line 177) | boolean hasGroundConnection(int n1) { return false; }
method getConnection (line 178) | boolean getConnection(int n1, int n2) {
method getInfo (line 186) | void getInfo(String arr[]) {
method getEditInfo (line 192) | public EditInfo getEditInfo(int n) {
method setEditValue (line 199) | public void setEditValue(int n, EditInfo ei) {
FILE: src/TransformerElm.java
class TransformerElm (line 4) | class TransformerElm extends CircuitElm {
method TransformerElm (line 10) | public TransformerElm(int xx, int yy) {
method TransformerElm (line 20) | public TransformerElm(int xa, int ya, int xb, int yb, int f,
method drag (line 36) | void drag(int xx, int yy) {
method getDumpType (line 45) | int getDumpType() { return 'T'; }
method dump (line 46) | String dump() {
method isTrapezoidal (line 50) | boolean isTrapezoidal() { return (flags & FLAG_BACK_EULER) == 0; }
method draw (line 51) | void draw(Graphics g) {
method setPoints (line 77) | void setPoints() {
method getPost (line 97) | Point getPost(int n) {
method getPostCount (line 100) | int getPostCount() { return 4; }
method reset (line 101) | void reset() {
method stamp (line 106) | void stamp() {
method startIteration (line 153) | void startIteration() {
method doStep (line 165) | void doStep() {
method calculateCurrent (line 169) | void calculateCurrent() {
method getInfo (line 175) | void getInfo(String arr[]) {
method getConnection (line 184) | boolean getConnection(int n1, int n2) {
method getEditInfo (line 191) | public EditInfo getEditInfo(int n) {
method setEditValue (line 207) | public void setEditValue(int n, EditInfo ei) {
FILE: src/TransistorElm.java
class TransistorElm (line 4) | class TransistorElm extends CircuitElm {
method TransistorElm (line 10) | TransistorElm(int xx, int yy, boolean pnpflag) {
method TransistorElm (line 16) | public TransistorElm(int xa, int ya, int xb, int yb, int f,
method setup (line 32) | void setup() {
method nonLinear (line 37) | boolean nonLinear() { return true; }
method reset (line 38) | void reset() {
method getDumpType (line 42) | int getDumpType() { return 't'; }
method dump (line 43) | String dump() {
method draw (line 50) | void draw(Graphics g) {
method getPost (line 89) | Point getPost(int n) {
method getPostCount (line 93) | int getPostCount() { return 3; }
method getPower (line 94) | double getPower() {
method setPoints (line 99) | void setPoints() {
method limitStep (line 137) | double limitStep(double vnew, double vold) {
method stamp (line 157) | void stamp() {
method doStep (line 162) | void doStep() {
method getInfo (line 226) | void getInfo(String arr[]) {
method getScopeValue (line 242) | double getScopeValue(int x) {
method getScopeUnits (line 253) | String getScopeUnits(int x) {
method getEditInfo (line 260) | public EditInfo getEditInfo(int n) {
method setEditValue (line 271) | public void setEditValue(int n, EditInfo ei) {
method canViewInScope (line 284) | boolean canViewInScope() { return true; }
FILE: src/TriacElm.java
class TriacElm (line 15) | class TriacElm extends CircuitElm {
method TriacElm (line 21) | public TriacElm(int xx, int yy) {
method TriacElm (line 26) | public TriacElm(int xa, int ya, int xb, int yb, int f,
method setDefaults (line 43) | void setDefaults() {
method setup (line 48) | void setup() {
method nonLinear (line 52) | boolean nonLinear() { return true; }
method reset (line 53) | void reset() {
method getDumpType (line 58) | int getDumpType() { return 183; }
method dump (line 59) | String dump() {
method setPoints (line 72) | void setPoints() {
method draw (line 103) | void draw(Graphics g) {
method getPost (line 137) | Point getPost(int n) {
method getPostCount (line 141) | int getPostCount() { return 3; }
method getInternalNodeCount (line 142) | int getInternalNodeCount() { return 1; }
method getPower (line 143) | double getPower() {
method stamp (line 148) | void stamp() {
method doStep (line 157) | void doStep() {
method getInfo (line 173) | void getInfo(String arr[]) {
method calculateCurrent (line 184) | void calculateCurrent() {
method getEditInfo (line 189) | public EditInfo getEditInfo(int n) {
method setEditValue (line 199) | public void setEditValue(int n, EditInfo ei) {
FILE: src/TriodeElm.java
class TriodeElm (line 4) | class TriodeElm extends CircuitElm {
method TriodeElm (line 8) | public TriodeElm(int xx, int yy) {
method TriodeElm (line 14) | public TriodeElm(int xa, int ya, int xb, int yb, int f,
method setup (line 21) | void setup() {
method nonLinear (line 24) | boolean nonLinear() { return true; }
method reset (line 25) | void reset() {
method dump (line 29) | String dump() {
method getDumpType (line 32) | int getDumpType() { return 173; }
method setPoints (line 36) | void setPoints() {
method draw (line 65) | void draw(Graphics g) {
method getPost (line 97) | Point getPost(int n) {
method getPostCount (line 100) | int getPostCount() { return 3; }
method getPower (line 101) | double getPower() { return (volts[0]-volts[2])*current; }
method doStep (line 104) | void doStep() {
method stamp (line 166) | void stamp() {
method getInfo (line 171) | void getInfo(String arr[]) {
method getConnection (line 181) | boolean getConnection(int n1, int n2) { return !(n1 == 1 || n2 == 1); }
FILE: src/TunnelDiodeElm.java
class TunnelDiodeElm (line 4) | class TunnelDiodeElm extends CircuitElm {
method TunnelDiodeElm (line 5) | public TunnelDiodeElm(int xx, int yy) {
method TunnelDiodeElm (line 9) | public TunnelDiodeElm(int xa, int ya, int xb, int yb, int f,
method nonLinear (line 14) | boolean nonLinear() { return true; }
method setup (line 15) | void setup() {
method getDumpType (line 17) | int getDumpType() { return 175; }
method setPoints (line 23) | void setPoints() {
method draw (line 34) | void draw(Graphics g) {
method reset (line 57) | void reset() {
method limitStep (line 62) | double limitStep(double vnew, double vold) {
method stamp (line 71) | void stamp() {
method doStep (line 81) | void doStep() {
method calculateCurrent (line 101) | void calculateCurrent() {
method getInfo (line 107) | void getInfo(String arr[]) {
FILE: src/VCOElm.java
class VCOElm (line 4) | class VCOElm extends ChipElm {
method VCOElm (line 5) | public VCOElm(int xx, int yy) { super(xx, yy); }
method VCOElm (line 6) | public VCOElm(int xa, int ya, int xb, int yb, int f,
method getChipName (line 10) | String getChipName() { return "VCO"; }
method setupPins (line 11) | void setupPins() {
method nonLinear (line 25) | boolean nonLinear() { return true; }
method stamp (line 26) | void stamp() {
method doStep (line 42) | void doStep() {
method computeCurrent (line 71) | void computeCurrent() {
method draw (line 80) | void draw(Graphics g) {
method getPostCount (line 84) | int getPostCount() { return 6; }
method getVoltageSourceCount (line 85) | int getVoltageSourceCount() { return 3; }
method getDumpType (line 86) | int getDumpType() { return 158; }
FILE: src/VarRailElm.java
class VarRailElm (line 4) | class VarRailElm extends RailElm {
method VarRailElm (line 8) | public VarRailElm(int xx, int yy) {
method VarRailElm (line 14) | public VarRailElm(int xa, int ya, int xb, int yb, int f,
method dump (line 22) | String dump() {
method getDumpType (line 25) | int getDumpType() { return 172; }
method createSlider (line 26) | void createSlider() {
method getVoltage (line 33) | double getVoltage() {
method delete (line 37) | void delete() {
method getEditInfo (line 41) | public EditInfo getEditInfo(int n) {
method setEditValue (line 53) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 63) | int getShortcut() { return 0; }
FILE: src/VoltageElm.java
class VoltageElm (line 4) | class VoltageElm extends CircuitElm {
method VoltageElm (line 16) | VoltageElm(int xx, int yy, int wf) {
method VoltageElm (line 24) | public VoltageElm(int xa, int ya, int xb, int yb, int f,
method getDumpType (line 46) | int getDumpType() { return 'v'; }
method dump (line 47) | String dump() {
method reset (line 57) | void reset() {
method triangleFunc (line 61) | double triangleFunc(double x) {
method stamp (line 66) | void stamp() {
method doStep (line 73) | void doStep() {
method getVoltage (line 78) | double getVoltage() {
method setPoints (line 96) | void setPoints() {
method draw (line 100) | void draw(Graphics g) {
method drawWaveform (line 130) | void drawWaveform(Graphics g, Point center) {
method getVoltageSourceCount (line 195) | int getVoltageSourceCount() {
method getPower (line 198) | double getPower() { return -getVoltageDiff()*current; }
method getVoltageDiff (line 199) | double getVoltageDiff() { return volts[1] - volts[0]; }
method getInfo (line 200) | void getInfo(String arr[]) {
method getEditInfo (line 225) | public EditInfo getEditInfo(int n) {
method setEditValue (line 255) | public void setEditValue(int n, EditInfo ei) {
FILE: src/WireElm.java
class WireElm (line 4) | class WireElm extends ResistorElm {
method WireElm (line 7) | public WireElm(int xx, int yy) { super(xx, yy); resistance = defaultRe...
method WireElm (line 8) | public WireElm(int xa, int ya, int xb, int yb, int f,
method draw (line 15) | void draw(Graphics g) {
method calculateCurrent (line 30) | void calculateCurrent() {
method stamp (line 35) | void stamp() {
method mustShowCurrent (line 42) | boolean mustShowCurrent() {
method mustShowVoltage (line 45) | boolean mustShowVoltage() {
method getVoltageSourceCount (line 48) | int getVoltageSourceCount() {
method getInfo (line 55) | void getInfo(String arr[]) {
method getPower (line 60) | double getPower() {
method getVoltageDiff (line 67) | double getVoltageDiff() {
method isWire (line 74) | boolean isWire() {
method getEditInfo (line 77) | public EditInfo getEditInfo(int n) {
method setEditValue (line 90) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 104) | int getShortcut() { return 'w'; }
method getDumpType (line 105) | int getDumpType() { return 'w'; }
method dump (line 106) | String dump() {
FILE: src/XorGateElm.java
class XorGateElm (line 4) | class XorGateElm extends OrGateElm {
method XorGateElm (line 5) | public XorGateElm(int xx, int yy) { super(xx, yy); }
method XorGateElm (line 6) | public XorGateElm(int xa, int ya, int xb, int yb, int f,
method getGateName (line 10) | String getGateName() { return "XOR gate"; }
method calcFunction (line 11) | boolean calcFunction() {
method getDumpType (line 18) | int getDumpType() { return 154; }
method getShortcut (line 19) | int getShortcut() { return '4'; }
FILE: src/ZenerElm.java
class ZenerElm (line 6) | class ZenerElm extends DiodeElm {
method ZenerElm (line 7) | public ZenerElm(int xx, int yy) {
method ZenerElm (line 12) | public ZenerElm(int xa, int ya, int xb, int yb, int f,
method setup (line 18) | void setup() {
method getDumpType (line 22) | int getDumpType() { return 'z'; }
method dump (line 23) | String dump() {
method setPoints (line 32) | void setPoints() {
method draw (line 45) | void draw(Graphics g) {
method getInfo (line 72) | void getInfo(String arr[]) {
method getEditInfo (line 77) | public EditInfo getEditInfo(int n) {
method setEditValue (line 84) | public void setEditValue(int n, EditInfo ei) {
method getShortcut (line 91) | int getShortcut() { return 0; }
Condensed preview — 381 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (618K chars).
[
{
"path": ".gitignore",
"chars": 12,
"preview": "src/*.class\n"
},
{
"path": "README.md",
"chars": 3321,
"preview": "circuit-simulator\n=================\n\nThis is a version of Paul Falstad's circuit simulator (original available at <http:"
},
{
"path": "src/ACRailElm.java",
"chars": 185,
"preview": " class ACRailElm extends RailElm {\n\tpublic ACRailElm(int xx, int yy) { super(xx, yy, WF_AC); }\n\tClass getDumpClass() "
},
{
"path": "src/ACVoltageElm.java",
"chars": 164,
"preview": " class ACVoltageElm extends VoltageElm {\n\tpublic ACVoltageElm(int xx, int yy) { super(xx, yy, WF_AC); }\n\tClass getDum"
},
{
"path": "src/ADCElm.java",
"chars": 1098,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass ADCElm extends ChipElm {\n public ADCElm(int xx, int yy) {"
},
{
"path": "src/AnalogSwitch2Elm.java",
"chars": 2295,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass AnalogSwitch2Elm extends AnalogSwitchElm {\n public Analog"
},
{
"path": "src/AnalogSwitchElm.java",
"chars": 3286,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass AnalogSwitchElm extends CircuitElm {\n final int FLAG_INVE"
},
{
"path": "src/AndGateElm.java",
"chars": 1208,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class AndGateElm extends GateElm {\n\tpublic AndGateElm(int xx, "
},
{
"path": "src/AntennaElm.java",
"chars": 904,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class AntennaElm extends RailElm {\n\tpublic AntennaElm(int xx, "
},
{
"path": "src/BoxElm.java",
"chars": 1447,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\nimport java.util.Vector;\n\nclass BoxElm extends GraphicElm {\n\n pu"
},
{
"path": "src/CC2Elm.java",
"chars": 1628,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class CC2Elm extends ChipElm {\n\tdouble gain;\n\tpublic CC2Elm(in"
},
{
"path": "src/CapacitorElm.java",
"chars": 4333,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class CapacitorElm extends CircuitElm {\n\tdouble capacitance;\n\t"
},
{
"path": "src/ChipElm.java",
"chars": 7571,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n abstract class ChipElm extends CircuitElm {\n\tint csize, cspc, "
},
{
"path": "src/CirSim.java",
"chars": 91441,
"preview": "// CirSim.java (c) 2010 by Paul Falstad\n\n// For information about the theory behind this, see Electronic Circuit & Syste"
},
{
"path": "src/Circuit.java",
"chars": 2131,
"preview": "// Circuit.java (c) 2005,2008 by Paul Falstad, www.falstad.com\n\nimport java.io.InputStream;\nimport java.awt.*;\nimport ja"
},
{
"path": "src/CircuitCanvas.java",
"chars": 329,
"preview": "import java.awt.*;\n\nclass CircuitCanvas extends Canvas {\n CirSim pg;\n CircuitCanvas(CirSim p) {\n\tpg = p;\n }\n "
},
{
"path": "src/CircuitElm.java",
"chars": 17983,
"preview": "import java.awt.*;\nimport java.text.DecimalFormat;\nimport java.text.NumberFormat;\n\npublic abstract class CircuitElm impl"
},
{
"path": "src/CircuitLayout.java",
"chars": 1288,
"preview": "import java.awt.*;\n\nclass CircuitLayout implements LayoutManager {\n public CircuitLayout() {}\n public void addLayo"
},
{
"path": "src/CircuitNode.java",
"chars": 180,
"preview": "import java.util.Vector;\n\nclass CircuitNode {\n int x, y;\n Vector<CircuitNodeLink> links;\n boolean internal;\n "
},
{
"path": "src/CircuitNodeLink.java",
"chars": 61,
"preview": " class CircuitNodeLink {\n\tint num;\n\tCircuitElm elm;\n }\n"
},
{
"path": "src/ClockElm.java",
"chars": 281,
"preview": " class ClockElm extends RailElm {\n\tpublic ClockElm(int xx, int yy) {\n\t super(xx, yy, WF_SQUARE);\n\t maxVoltage ="
},
{
"path": "src/CounterElm.java",
"chars": 1570,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class CounterElm extends ChipElm {\n\tfinal int FLAG_ENABLE = 2;"
},
{
"path": "src/CurrentElm.java",
"chars": 1873,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class CurrentElm extends CircuitElm {\n\tdouble currentValue;\n\tp"
},
{
"path": "src/DACElm.java",
"chars": 1053,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass DACElm extends ChipElm {\n public DACElm(int xx, int yy) {"
},
{
"path": "src/DCVoltageElm.java",
"chars": 199,
"preview": " class DCVoltageElm extends VoltageElm {\n\tpublic DCVoltageElm(int xx, int yy) { super(xx, yy, WF_DC); }\n\tClass getDum"
},
{
"path": "src/DFlipFlopElm.java",
"chars": 1757,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class DFlipFlopElm extends ChipElm {\n\tfinal int FLAG_RESET = 2"
},
{
"path": "src/DecadeElm.java",
"chars": 1295,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class DecadeElm extends ChipElm {\n\tpublic DecadeElm(int xx, in"
},
{
"path": "src/DiacElm.java",
"chars": 3135,
"preview": "// stub implementation of DiacElm, based on SparkGapElm\n// FIXME need to add DiacElm.java to srclist\n// FIXME need to un"
},
{
"path": "src/Diode.java",
"chars": 3876,
"preview": "class Diode {\n int nodes[];\n CirSim sim;\n\n \n Diode(CirSim s) {\n\tsim = s;\n\tnodes = new int[2];\n }\n void"
},
{
"path": "src/DiodeElm.java",
"chars": 2481,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass DiodeElm extends CircuitElm {\n Diode diode;\n static fi"
},
{
"path": "src/EditDialog.java",
"chars": 5721,
"preview": "import java.awt.*;\nimport java.awt.event.*;\nimport java.text.NumberFormat;\nimport java.text.DecimalFormat;\n\ninterface Ed"
},
{
"path": "src/EditDialogLayout.java",
"chars": 1677,
"preview": "import java.awt.*;\nimport java.awt.event.*;\n\nclass EditDialogLayout implements LayoutManager {\n public EditDialogLayo"
},
{
"path": "src/EditInfo.java",
"chars": 702,
"preview": "import java.awt.*;\n\nclass EditInfo {\n EditInfo(String n, double val, double mn, double mx) {\n\tname = n;\n\tvalue = val;"
},
{
"path": "src/EditOptions.java",
"chars": 544,
"preview": "class EditOptions implements Editable {\n CirSim sim;\n public EditOptions(CirSim s) { sim = s; }\n public EditInf"
},
{
"path": "src/GateElm.java",
"chars": 3760,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n abstract class GateElm extends CircuitElm {\n\tfinal int FLAG_SM"
},
{
"path": "src/GraphicElm.java",
"chars": 254,
"preview": "class GraphicElm extends CircuitElm\n{\n\n public GraphicElm(int xx, int yy)\n {\n\tsuper(xx,yy);\n }\n\n public Grap"
},
{
"path": "src/GroundElm.java",
"chars": 1149,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class GroundElm extends CircuitElm {\n\tpublic GroundElm(int xx,"
},
{
"path": "src/ImportExportAppletDialog.java",
"chars": 1085,
"preview": "import java.awt.Dialog;\nimport java.applet.Applet;\nimport java.awt.Frame;\nimport netscape.javascript.*; // add plugin.ja"
},
{
"path": "src/ImportExportClipboardDialog.java",
"chars": 2044,
"preview": "import java.awt.*;\nimport java.awt.event.*;\n\nimport java.awt.datatransfer.Clipboard;\nimport java.awt.datatransfer.DataFl"
},
{
"path": "src/ImportExportDialog.java",
"chars": 196,
"preview": "import java.awt.*;\nimport java.awt.event.*;\n\npublic interface ImportExportDialog {\n public enum Action { IMPORT, EXPO"
},
{
"path": "src/ImportExportDialogFactory.java",
"chars": 393,
"preview": "public class ImportExportDialogFactory\n{\n public static ImportExportDialog Create(CirSim f,\n\tImportExportDialog.Actio"
},
{
"path": "src/ImportExportDialogLayout.java",
"chars": 1356,
"preview": "import java.awt.*;\n\nclass ImportExportDialogLayout implements LayoutManager {\n public ImportExportDialogLayout() {}\n "
},
{
"path": "src/ImportExportFileDialog.java",
"chars": 2317,
"preview": "import java.awt.*;\nimport java.awt.event.*;\nimport java.io.*;\nimport java.nio.ByteBuffer;\nimport java.nio.MappedByteBuff"
},
{
"path": "src/Inductor.java",
"chars": 1745,
"preview": "class Inductor {\n public static final int FLAG_BACK_EULER = 2;\n int nodes[];\n int flags;\n CirSim sim;\n \n "
},
{
"path": "src/InductorElm.java",
"chars": 2433,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class InductorElm extends CircuitElm {\n\tInductor ind;\n\tdouble "
},
{
"path": "src/InverterElm.java",
"chars": 2563,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class InverterElm extends CircuitElm {\n\tdouble slewRate; // V/"
},
{
"path": "src/JKFlipFlopElm.java",
"chars": 1220,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class JKFlipFlopElm extends ChipElm {\n\tpublic JKFlipFlopElm(in"
},
{
"path": "src/JfetElm.java",
"chars": 2206,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class JfetElm extends MosfetElm {\n\tJfetElm(int xx, int yy, boo"
},
{
"path": "src/LEDElm.java",
"chars": 2535,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class LEDElm extends DiodeElm {\n\tdouble colorR, colorG, colorB"
},
{
"path": "src/LampElm.java",
"chars": 5038,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class LampElm extends CircuitElm {\n\tdouble resistance;\n\tfinal "
},
{
"path": "src/LatchElm.java",
"chars": 1083,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass LatchElm extends ChipElm {\n public LatchElm(int xx, int y"
},
{
"path": "src/LogicInputElm.java",
"chars": 2799,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class LogicInputElm extends SwitchElm {\n\tfinal int FLAG_TERNAR"
},
{
"path": "src/LogicOutputElm.java",
"chars": 2745,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class LogicOutputElm extends CircuitElm {\n\tfinal int FLAG_TERN"
},
{
"path": "src/Makefile",
"chars": 393,
"preview": "PLUGINJAR=/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/plugin.jar\n#PLUGINJAR=/usr/share/icedtea-web/plugin.jar\n\nall:\n\tjavac "
},
{
"path": "src/Manifest.txt",
"chars": 20,
"preview": "Main-Class: Circuit\n"
},
{
"path": "src/MemristorElm.java",
"chars": 3567,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass MemristorElm extends CircuitElm {\n double r_on, r_off, do"
},
{
"path": "src/MosfetElm.java",
"chars": 7756,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class MosfetElm extends CircuitElm {\n\tint pnp;\n\tint FLAG_PNP ="
},
{
"path": "src/NJfetElm.java",
"chars": 301,
"preview": " class NJfetElm extends JfetElm {\n\tpublic NJfetElm(int xx, int yy) { super(xx, yy, false); }\n\tClass getDumpClass() { "
},
{
"path": "src/NMosfetElm.java",
"chars": 158,
"preview": " class NMosfetElm extends MosfetElm {\n\tpublic NMosfetElm(int xx, int yy) { super(xx, yy, false); }\n\tClass getDumpClas"
},
{
"path": "src/NTransistorElm.java",
"chars": 174,
"preview": " class NTransistorElm extends TransistorElm {\n\tpublic NTransistorElm(int xx, int yy) { super(xx, yy, false); }\n\tClass"
},
{
"path": "src/NandGateElm.java",
"chars": 439,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class NandGateElm extends AndGateElm {\n\tpublic NandGateElm(int"
},
{
"path": "src/NorGateElm.java",
"chars": 434,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class NorGateElm extends OrGateElm {\n\tpublic NorGateElm(int xx"
},
{
"path": "src/OpAmpElm.java",
"chars": 5578,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class OpAmpElm extends CircuitElm {\n\tint opsize, opheight, opw"
},
{
"path": "src/OpAmpSwapElm.java",
"chars": 184,
"preview": " class OpAmpSwapElm extends OpAmpElm {\n\tpublic OpAmpSwapElm(int xx, int yy) {\n\t super(xx, yy);\n\t flags |= FLAG_"
},
{
"path": "src/OrGateElm.java",
"chars": 1484,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class OrGateElm extends GateElm {\n\tpublic OrGateElm(int xx, in"
},
{
"path": "src/OutputElm.java",
"chars": 1703,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class OutputElm extends CircuitElm {\n\tfinal int FLAG_VALUE = 1"
},
{
"path": "src/PMosfetElm.java",
"chars": 157,
"preview": " class PMosfetElm extends MosfetElm {\n\tpublic PMosfetElm(int xx, int yy) { super(xx, yy, true); }\n\tClass getDumpClass"
},
{
"path": "src/PTransistorElm.java",
"chars": 173,
"preview": " class PTransistorElm extends TransistorElm {\n\tpublic PTransistorElm(int xx, int yy) { super(xx, yy, true); }\n\tClass "
},
{
"path": "src/PhaseCompElm.java",
"chars": 1458,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass PhaseCompElm extends ChipElm {\n public PhaseCompElm(int x"
},
{
"path": "src/PhotoResistorElm.java",
"chars": 2820,
"preview": "// stub PhotoResistorElm based on SparkGapElm\n// FIXME need to uncomment PhotoResistorElm line from CirSim.java\n// FIXME"
},
{
"path": "src/PotElm.java",
"chars": 5942,
"preview": "import java.awt.*;\nimport java.awt.event.*;\nimport java.util.StringTokenizer;\n\nclass PotElm extends CircuitElm implement"
},
{
"path": "src/ProbeElm.java",
"chars": 2053,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass ProbeElm extends CircuitElm {\n static final int FLAG_SHOW"
},
{
"path": "src/PushSwitchElm.java",
"chars": 196,
"preview": " class PushSwitchElm extends SwitchElm {\n\tpublic PushSwitchElm(int xx, int yy) { super(xx, yy, true); }\n\tClass getDum"
},
{
"path": "src/RailElm.java",
"chars": 1873,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass RailElm extends VoltageElm {\n public RailElm(int xx, int "
},
{
"path": "src/RelayElm.java",
"chars": 9198,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n// 0 = switch\n// 1 = switch end 1\n// 2 = switch end 2\n// ...\n// 3n"
},
{
"path": "src/ResistorElm.java",
"chars": 2822,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class ResistorElm extends CircuitElm {\n\tdouble resistance;\n\tpu"
},
{
"path": "src/RowInfo.java",
"chars": 511,
"preview": " // info about each row/column of the matrix for simplification purposes\n class RowInfo {\n\tstatic final int ROW_NO"
},
{
"path": "src/SCRElm.java",
"chars": 5837,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n// Silicon-Controlled Rectifier\n// 3 nodes, 1 internal node\n// 0 ="
},
{
"path": "src/Scope.java",
"chars": 18653,
"preview": "import java.awt.*;\nimport java.awt.image.*;\nimport java.awt.event.*;\nimport java.util.StringTokenizer;\nimport java.lang."
},
{
"path": "src/SevenSegElm.java",
"chars": 1645,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class SevenSegElm extends ChipElm {\n\tpublic SevenSegElm(int xx"
},
{
"path": "src/SparkGapElm.java",
"chars": 3145,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass SparkGapElm extends CircuitElm {\n double resistance, onre"
},
{
"path": "src/SquareRailElm.java",
"chars": 197,
"preview": " class SquareRailElm extends RailElm {\n\tpublic SquareRailElm(int xx, int yy) { super(xx, yy, WF_SQUARE); }\n\tClass get"
},
{
"path": "src/SweepElm.java",
"chars": 5039,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass SweepElm extends CircuitElm {\n double maxV, maxF, minF, s"
},
{
"path": "src/Switch2Elm.java",
"chars": 3271,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class Switch2Elm extends SwitchElm {\n\tint link;\n\tstatic final "
},
{
"path": "src/SwitchElm.java",
"chars": 2755,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass SwitchElm extends CircuitElm {\n boolean momentary;\n //"
},
{
"path": "src/TappedTransformerElm.java",
"chars": 8084,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class TappedTransformerElm extends CircuitElm {\n\tdouble induct"
},
{
"path": "src/TextElm.java",
"chars": 3354,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\nimport java.util.Vector;\n\nclass TextElm extends GraphicElm {\n St"
},
{
"path": "src/ThermistorElm.java",
"chars": 2802,
"preview": "// stub ThermistorElm based on SparkGapElm\n// FIXME need to uncomment ThermistorElm line from CirSim.java\n// FIXME need "
},
{
"path": "src/TimerElm.java",
"chars": 2682,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass TimerElm extends ChipElm {\n final int FLAG_RESET = 2;\n "
},
{
"path": "src/TransLineElm.java",
"chars": 6251,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass TransLineElm extends CircuitElm {\n double delay, imped;\n "
},
{
"path": "src/TransformerElm.java",
"chars": 7396,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class TransformerElm extends CircuitElm {\n\tdouble inductance, "
},
{
"path": "src/TransistorElm.java",
"chars": 9156,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class TransistorElm extends CircuitElm {\n\tint pnp;\n\tdouble bet"
},
{
"path": "src/TriacElm.java",
"chars": 5995,
"preview": "// stub implementation of TriacElm, based on SCRElm\n// FIXME need to add TriacElm to srclist\n// FIXME need to uncomment "
},
{
"path": "src/TriodeElm.java",
"chars": 5256,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass TriodeElm extends CircuitElm {\n double mu, kg1;\n doubl"
},
{
"path": "src/TunnelDiodeElm.java",
"chars": 3192,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass TunnelDiodeElm extends CircuitElm {\n public TunnelDiodeEl"
},
{
"path": "src/VCOElm.java",
"chars": 2839,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class VCOElm extends ChipElm {\n\tpublic VCOElm(int xx, int yy) "
},
{
"path": "src/VarRailElm.java",
"chars": 1713,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class VarRailElm extends RailElm {\n\tScrollbar slider;\n\tLabel l"
},
{
"path": "src/VoltageElm.java",
"chars": 8441,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\nclass VoltageElm extends CircuitElm {\n static final int FLAG_CO"
},
{
"path": "src/WireElm.java",
"chars": 2811,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class WireElm extends ResistorElm {\n\tpublic static boolean ide"
},
{
"path": "src/XorGateElm.java",
"chars": 532,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n class XorGateElm extends OrGateElm {\n\tpublic XorGateElm(int xx"
},
{
"path": "src/ZenerElm.java",
"chars": 2210,
"preview": "import java.awt.*;\nimport java.util.StringTokenizer;\n\n// Zener code contributed by J. Mike Rollins\n// http://www.camotru"
},
{
"path": "src/circuits/3-cgand.txt",
"chars": 1070,
"preview": "$ 1 5.0E-6 11.251013186076355 50 5.0 50\nf 352 416 464 416 6 3.25\nf 352 368 464 368 6 3.25\nw 464 384 464 400 0\nf 304 304 "
},
{
"path": "src/circuits/3-cgor.txt",
"chars": 1091,
"preview": "$ 1 5.0E-6 10.812258501325767 50 5.0 50\nf 368 368 480 368 6 3.25\nw 480 384 480 400 0\nw 368 320 368 336 0\nw 288 320 288 3"
},
{
"path": "src/circuits/3-f211.txt",
"chars": 317,
"preview": "$ 1 5.0E-6 10.812258501325767 50 5.0 50\nf 288 288 352 288 6 -1.75\nw 352 272 352 240 0\nw 352 240 352 208 0\nf 288 192 352 "
},
{
"path": "src/circuits/3-f220.txt",
"chars": 293,
"preview": "$ 1 5.0E-6 10.812258501325767 50 5.0 50\nf 288 288 352 288 6 3.25\nw 352 272 352 240 0\nw 352 240 352 208 0\nf 288 192 352 1"
},
{
"path": "src/circuits/3-f221.txt",
"chars": 316,
"preview": "$ 1 5.0E-6 10.812258501325767 50 5.0 50\nf 288 288 352 288 6 0.75\nw 352 272 352 240 0\nw 352 240 352 208 0\nf 288 192 352 1"
},
{
"path": "src/circuits/3-invert.txt",
"chars": 527,
"preview": "$ 1 5.0E-6 10.812258501325767 50 5.0 50\nf 336 352 384 352 6 3.25\nf 256 272 304 272 6 -1.75\nf 256 208 304 208 7 -1.75\nw 3"
},
{
"path": "src/circuits/3way.txt",
"chars": 283,
"preview": "$ 1 5.0E-6 3 44 120.0 15\nv 32 320 32 80 0 1 60.0 120.0 0.0\nr 496 80 496 320 0 150.0\nw 32 80 112 80 0\nw 416 80 496 80 0\nS"
},
{
"path": "src/circuits/4way.txt",
"chars": 506,
"preview": "$ 1 5.0E-6 3 44 120.0 15\nv 32 320 32 80 0 1 60.0 120.0 0.0\nr 480 80 480 320 0 150.0\nw 32 80 80 80 0\nS 336 176 240 176 0 "
},
{
"path": "src/circuits/555int.txt",
"chars": 1145,
"preview": "$ 3 5.0E-6 5 64 7.0\na 288 168 384 168 1 5.0 0.0\na 288 264 384 264 1 5.0 0.0\nr 240 56 240 104 0 5000.0\nr 240 104 240 152 "
},
{
"path": "src/circuits/555lowduty.txt",
"chars": 428,
"preview": "$ 1 5.0E-6 10 69 10.0 50\n165 224 144 272 144 0 0.0\nw 224 176 192 176 0\nr 192 176 192 240 0 150000.0\nw 192 240 224 240 0\n"
},
{
"path": "src/circuits/555missing.txt",
"chars": 667,
"preview": "$ 1 5.0E-6 10.391409633455755 56 5.0 50\n165 336 176 448 176 0 5.0\nw 336 208 336 304 0\nw 336 208 304 208 0\nw 304 208 304 "
},
{
"path": "src/circuits/555monostable.txt",
"chars": 508,
"preview": "$ 1 5.0E-6 10 56 5.0 50\n165 208 144 320 144 0 0.0\nw 208 176 208 272 0\nw 208 176 176 176 0\nw 208 240 128 240 0\nw 176 176 "
},
{
"path": "src/circuits/555pulsemod.txt",
"chars": 422,
"preview": "$ 1 5.0E-6 4.8 56 5.0 50\n165 240 128 256 128 0 5.0\nR 304 96 304 80 0 0 40.0 5.0 0.0\nR 304 288 304 336 0 3 20.0 2.0 3.0\nO"
},
{
"path": "src/circuits/555saw.txt",
"chars": 640,
"preview": "$ 1 5.0E-6 16.817414165184545 66 15.0 50\nr 240 112 240 48 0 39000.0\nr 192 128 192 48 0 27000.0\nr 192 128 192 208 0 12000"
},
{
"path": "src/circuits/555schmitt.txt",
"chars": 368,
"preview": "$ 1 5.0E-6 10.391409633455755 56 5.0 50\n165 304 160 416 160 0 0.0\nw 256 128 368 128 0\nR 256 128 144 128 0 0 40.0 5.0 0.0"
},
{
"path": "src/circuits/555sequencer.txt",
"chars": 1541,
"preview": "$ 3 5.0E-6 2.800975890892825 50 5.0 50\n165 160 208 168 208 1 -0.0\nw 160 224 152 224 0\nw 152 224 152 272 0\nw 152 272 160 "
},
{
"path": "src/circuits/555square.txt",
"chars": 459,
"preview": "$ 1 5.0E-6 5.023272298708815 64 7.0 50\nw 272 176 240 176 0\nr 240 176 240 240 0 10000.0\nw 240 240 272 240 0\nw 240 240 240"
},
{
"path": "src/circuits/7segdecoder.txt",
"chars": 3912,
"preview": "$ 3 5.0E-6 10.20027730826997 50 5.0 50\r\nL 240 40 240 16 2 0 false 5.0 0.0\r\nL 288 40 288 16 2 1 false 5.0 0.0\r\nL 336 40 3"
},
{
"path": "src/circuits/allpass1.txt",
"chars": 415,
"preview": "$ 1 5.0E-6 10.634267539816555 50 5.0 50\na 320 224 416 224 0 15.0 -15.0\nr 320 208 240 208 0 1000.0\nr 320 240 240 240 0 10"
},
{
"path": "src/circuits/allpass2.txt",
"chars": 384,
"preview": "$ 1 5.0E-6 10.634267539816555 55 5.0 50\na 320 224 416 224 0 15.0 -15.0\nr 320 208 240 208 0 1000.0\nr 320 240 240 240 0 10"
},
{
"path": "src/circuits/amdetect.txt",
"chars": 670,
"preview": "$ 4 5.0E-6 25.23 50 5.0 50\nr 144 272 208 272 0 3000.0\nl 208 144 208 272 0 0.0010 0.18734471432590385\nw 208 144 272 144 0"
},
{
"path": "src/circuits/amp-dfdx.txt",
"chars": 341,
"preview": "$ 1 5.0E-6 10 57 5.0\nv 112 256 112 96 0 3 40.0 5.0 0.0\ng 112 256 112 304 0\nw 352 128 352 192 0\nw 208 128 208 176 0\nw 112"
},
{
"path": "src/circuits/amp-diff.txt",
"chars": 472,
"preview": "$ 1 5.0E-6 10 57 5.0 50\na 288 192 432 192 0 15.0 -15.0\nw 288 112 288 176 0\nw 432 192 432 112 0\nr 288 112 432 112 0 1000."
},
{
"path": "src/circuits/amp-follower.txt",
"chars": 378,
"preview": "$ 1 5.0E-6 10.391409633455755 57 5.0 50\nv 96 224 96 80 0 1 40.0 5.0 0.0 0.0 0.5\ng 96 224 96 272 0\nw 192 176 192 224 0\na "
},
{
"path": "src/circuits/amp-fullrect.txt",
"chars": 539,
"preview": "$ 1 5.0E-6 16 62 1.0 50\na 176 288 272 288 0 15.0 -15.0\ng 176 304 176 336 0\nw 272 288 272 240 0\nd 272 240 176 240 0\nw 272"
},
{
"path": "src/circuits/amp-integ.txt",
"chars": 496,
"preview": "$ 1 5.0E-6 10.391409633455755 57 5.0 50\ng 96 224 96 272 0\nw 336 112 336 160 0\nw 192 80 192 112 0\nw 192 112 192 144 0\nw 1"
},
{
"path": "src/circuits/amp-invert.txt",
"chars": 314,
"preview": "$ 1 5.0E-6 10 57 5.0\nv 96 256 96 112 0 1 40.0 5.0 0.0\ng 96 256 96 304 0\nr 96 112 192 112 0 1000.0\nr 192 144 336 144 0 30"
},
{
"path": "src/circuits/amp-noninvert.txt",
"chars": 299,
"preview": "$ 1 5.0E-6 10 57 5.0\nv 96 256 96 112 0 1 40.0 5.0 0.0\ng 96 256 96 304 0\nw 192 208 192 256 0\na 192 192 336 192 1\nw 336 19"
},
{
"path": "src/circuits/amp-rect.txt",
"chars": 351,
"preview": "$ 1 5.0E-6 10 71 1.0\na 240 192 352 192 0\nw 240 176 240 128 0\nd 352 192 352 128 0\nw 208 176 240 176 0\nr 208 176 128 176 0"
},
{
"path": "src/circuits/amp-schmitt.txt",
"chars": 595,
"preview": "$ 1 5.0E-6 10 66 5.0\na 320 208 432 208 0 15.0 -15.0\nw 432 208 432 272 0\nr 432 272 288 272 0 100000.0\nw 288 224 320 224 0"
},
{
"path": "src/circuits/amp-sum.txt",
"chars": 447,
"preview": "$ 1 5.0E-6 16 57 5.0 50\na 288 208 432 208 0 15.0 -15.0\nw 288 128 288 192 0\nw 432 208 432 128 0\nr 288 128 432 128 0 1000."
},
{
"path": "src/circuits/bandpass.txt",
"chars": 401,
"preview": "$ 1 5.0E-6 10.391409633455755 50 5.0 46\nw 352 144 352 208 0\nw 352 288 352 336 0\nw 304 288 352 288 0\nw 352 288 400 288 0\n"
},
{
"path": "src/circuits/besselbutter.txt",
"chars": 1776,
"preview": "$ 1 5.0E-6 1.1685319768402522 49 5.0 50\nc 208 96 208 192 0 6.083084599140672E-6 -4.999993387010308\nl 144 96 208 96 0 0.0"
},
{
"path": "src/circuits/blank.txt",
"chars": 21,
"preview": "$ 1 5.0E-6 10 50 5.0\n"
},
{
"path": "src/circuits/butter10lo.txt",
"chars": 902,
"preview": "$ 1 5.0E-6 5.023272298708815 49 5.0 50\nc 208 176 208 288 0 5.9051646250635805E-6 4.062633211426473\nl 144 176 208 176 0 0"
},
{
"path": "src/circuits/cap.txt",
"chars": 278,
"preview": "$ 1 5.0E-6 16 50 5.0\nv 96 336 96 64 0 0 40.0 5.0 0.0\nS 256 144 256 64 0 false false 0\nw 96 64 240 64 0\nw 272 64 400 64 0"
},
{
"path": "src/circuits/capac.txt",
"chars": 167,
"preview": "$ 1 5.0E-6 14.3 55 5.0\nv 176 256 176 80 0 1 40.0 5.0 0.0\nr 176 80 336 80 0 180.0\nc 336 80 336 256 0 3.3E-5 0.20495321439"
},
{
"path": "src/circuits/capmult.txt",
"chars": 690,
"preview": "$ 1 5.0E-6 18.278915558614752 60 5.0 50\na 368 192 480 192 0 15.0 -15.0 1000000.0\nw 368 176 368 128 0\nw 368 128 480 128 0"
},
{
"path": "src/circuits/capmultcaps.txt",
"chars": 474,
"preview": "$ 1 5.0E-6 10 54 5.0 50\nv 176 96 176 32 0 1 80.0 5.0 0.0\nr 176 32 336 32 0 200.0\nc 336 32 336 96 0 7.999999999999999E-5 "
},
{
"path": "src/circuits/capmultfreq.txt",
"chars": 517,
"preview": "$ 1 5.0E-6 10 54 5.0 50\nv 224 144 224 80 0 1 15.0 5.0 0.0\nr 224 80 384 80 0 200.0\nc 384 80 384 144 0 2.9999999999999997E"
},
{
"path": "src/circuits/cappar.txt",
"chars": 602,
"preview": "$ 1 5.0E-6 18 50 5.0\nv 48 336 48 64 0 0 40.0 5.0 0.0\nS 144 144 144 64 0 false false 1\nw 240 64 240 336 0\nr 48 336 144 33"
},
{
"path": "src/circuits/capseries.txt",
"chars": 468,
"preview": "$ 1 5.0E-6 10 50 5.0\nv 48 336 48 64 0 0 40.0 5.0 0.0\nS 144 144 144 64 0 false false 1\nw 240 64 240 336 0\nr 48 336 144 33"
},
{
"path": "src/circuits/cc2.txt",
"chars": 257,
"preview": "$ 1 5.0E-6 10.20027730826997 50 5.0 50\n179 272 224 304 224 0 1.0\nr 368 256 480 256 0 100.0\ng 480 256 480 288 0\n172 272 2"
},
{
"path": "src/circuits/cc2imp.txt",
"chars": 1028,
"preview": "$ 1 5.0E-6 1.1208435524800693 51 5.0 50\na 160 208 272 208 1 15.0 -15.0\nf 272 176 336 176 0 1.5\nf 272 240 336 240 1 1.5\nw"
},
{
"path": "src/circuits/cc2impn.txt",
"chars": 1509,
"preview": "$ 1 5.0E-6 1.1208435524800693 51 5.0 50\na 144 208 240 208 1 15.0 -15.0\nf 240 176 288 176 0 1.5\nf 240 240 288 240 1 1.5\nw"
},
{
"path": "src/circuits/cc2n.txt",
"chars": 258,
"preview": "$ 1 5.0E-6 10.20027730826997 50 5.0 50\n179 272 224 304 224 0 -1.0\nr 368 256 480 256 0 100.0\ng 480 256 480 288 0\n172 272 "
},
{
"path": "src/circuits/ccdiff.txt",
"chars": 479,
"preview": "$ 1 5.0E-6 10.20027730826997 50 5.0 50\n179 368 160 400 160 0 1.0\nc 368 160 304 160 0 1.0E-5 0\nr 304 160 256 160 0 1.0\ng "
},
{
"path": "src/circuits/cciamp.txt",
"chars": 361,
"preview": "$ 1 5.0E-6 10.20027730826997 50 5.0 50\n179 208 176 304 176 0 1.0\ni 144 304 208 304 0 0.01\ng 144 304 144 320 0\nw 208 240 "
},
{
"path": "src/circuits/ccinductor.txt",
"chars": 700,
"preview": "$ 1 5.0E-6 10.20027730826997 48 5.0 50\n179 240 80 256 80 1024 1.0\n179 240 256 272 256 1024 -1.0\nR 128 176 96 176 0 1 40."
},
{
"path": "src/circuits/ccint.txt",
"chars": 488,
"preview": "$ 1 5.0E-6 10.20027730826997 50 5.0 50\n179 368 160 400 160 0 1.0\ng 304 160 304 176 0\nr 464 192 544 192 0 100.0\ng 544 192"
},
{
"path": "src/circuits/ccitov.txt",
"chars": 457,
"preview": "$ 1 5.0E-6 10.20027730826997 59 5.0 50\nS 224 320 224 240 0 1 false 0\nS 224 160 224 240 0 1 false 0\nw 144 160 144 240 0\nw"
},
{
"path": "src/circuits/ccvccs.txt",
"chars": 326,
"preview": "$ 1 5.0E-6 10.20027730826997 50 5.0 50\n179 208 192 336 192 0 1.0\nr 208 192 160 192 0 100.0\ng 160 192 160 208 0\nR 208 256"
},
{
"path": "src/circuits/ceamp.txt",
"chars": 574,
"preview": "$ 1 5.0E-6 16 60 15.0 53\nw 240 48 336 48 0\nr 240 48 240 208 0 110000.0\nr 240 208 240 352 0 10000.0\nt 240 208 336 208 0 1"
},
{
"path": "src/circuits/classd.txt",
"chars": 729,
"preview": "$ 1 5.0E-6 8.531194996067258 50 5.0 50\na 160 224 256 224 0 15.0 -15.0\nf 256 256 304 256 1 1.5\nf 256 192 304 192 0 1.5\nw "
},
{
"path": "src/circuits/clockedsrff.txt",
"chars": 568,
"preview": "$ 1 5.0E-6 10 50 5.0\n151 256 272 368 272 0 2 5\n151 256 144 368 144 0 2 0\nw 368 144 368 176 0\nw 368 176 256 240 0\nw 368 2"
},
{
"path": "src/circuits/cmosff.txt",
"chars": 1035,
"preview": "$ 0 5.0E-6 10 50 5.0\nf 160 80 208 80 5\nf 160 176 208 176 4\nw 208 96 208 128 0\nw 208 128 208 160 0\nf 160 240 208 240 4\nw "
},
{
"path": "src/circuits/cmosinverter.txt",
"chars": 248,
"preview": "$ 0 5.0E-6 10 50 5.0\nf 208 176 272 176 1\nf 208 272 272 272 0\nw 272 192 272 224 0\nw 272 224 272 256 0\nw 208 176 208 224 0"
},
{
"path": "src/circuits/cmosinvertercap.txt",
"chars": 522,
"preview": "$ 1 1.0E-12 10 50 5.0 38\nf 224 144 288 144 1\nf 224 272 288 272 0\nw 288 160 288 208 0\nM 288 208 352 208 0\nw 288 128 288 9"
},
{
"path": "src/circuits/cmosinverterslow.txt",
"chars": 466,
"preview": "$ 1 3.0E-13 10 52 5.0\nf 272 144 336 144 1\nf 272 240 336 240 0\nw 336 160 336 192 0\nw 336 192 336 224 0\nw 272 144 272 192 "
},
{
"path": "src/circuits/cmosmsff.txt",
"chars": 683,
"preview": "$ 0 5.0E-6 9 50 5.0 50\n159 144 112 208 112 0\nw 208 112 208 192 0\n159 208 192 272 192 0\nI 208 112 272 112 0 2.0E-4\nI 272 "
},
{
"path": "src/circuits/cmosnand.txt",
"chars": 454,
"preview": "$ 0 5.0E-6 10 50 5.0\nf 288 128 352 128 5\nf 288 224 352 224 4\nw 352 144 352 176 0\nw 352 176 352 208 0\nM 352 176 416 176 0"
},
{
"path": "src/circuits/cmosnor.txt",
"chars": 419,
"preview": "$ 0 5.0E-6 10 50 5.0\nf 272 144 336 144 5\nw 336 160 336 192 0\nR 336 128 336 80 0 0 40.0 5.0 0.0\nf 272 208 336 208 5\nw 336"
},
{
"path": "src/circuits/cmostransgate.txt",
"chars": 290,
"preview": "$ 1 5.0E-6 16.13108636308289 50 5.0 50\nw 320 192 400 192 0\nr 400 192 400 272 0 100.0\ng 400 272 400 304 0\nw 208 240 208 1"
},
{
"path": "src/circuits/cmosxor.txt",
"chars": 583,
"preview": "$ 0 5.0E-6 10 50 5.0\nf 192 128 256 128 5\nf 192 224 256 224 4\nw 256 144 256 176 0\nw 256 176 256 208 0\nw 192 128 192 176 0"
},
{
"path": "src/circuits/colpitts.txt",
"chars": 626,
"preview": "$ 1 5.0E-6 2.898875293967098 50 5.0 50\nl 80 128 80 304 0 0.01 -0.010136293111238402\nc 192 128 192 224 0 9.99999999999999"
},
{
"path": "src/circuits/counter.txt",
"chars": 956,
"preview": "$ 1 5.0E-6 10 50 5.0\n156 80 224 128 224 0 0.0\n156 208 224 240 224 0 0.0\n156 336 224 368 224 0 0.0\n156 464 224 480 224 0 "
},
{
"path": "src/circuits/counter8.txt",
"chars": 1902,
"preview": "$ 3 5.0E-6 23 50 5.0\n156 88 272 104 272 1 0\n156 152 272 168 272 1 0\nw 152 272 144 272 0\nw 144 272 144 304 0\nw 144 304 15"
},
{
"path": "src/circuits/coupled1.txt",
"chars": 541,
"preview": "$ 1 5.0E-6 12.682493960703473 55 5.0 50\nl 192 240 304 240 0 1.0 0.0\nl 304 240 416 240 0 1.0 0.0\nc 192 240 192 368 0 1.0E"
},
{
"path": "src/circuits/coupled2.txt",
"chars": 557,
"preview": "$ 1 5.0E-6 11.251013186076355 63 5.0 50\nl 208 160 320 160 0 1.0 -0.001826652874703726\nl 320 160 432 160 0 1.0 3.59207891"
},
{
"path": "src/circuits/coupled3.txt",
"chars": 1378,
"preview": "$ 1 5.0E-6 17.50203994009402 55 5.0 50\nl 144 32 256 32 0 1.0 -0.010526054531836967\nl 256 32 368 32 0 1.0 -0.014780859108"
},
{
"path": "src/circuits/crossover.txt",
"chars": 1025,
"preview": "$ 0 5.0E-6 10.812258501325767 50 5.0 50\n170 208 48 160 48 3 100.0 20000.0 5.0 0.25\nl 208 48 304 48 0 0.00212 -0.08881265"
},
{
"path": "src/circuits/cube.txt",
"chars": 408,
"preview": "$ 1 5.0E-6 10.391409633455755 50 5.0 50\nr 224 144 384 144 0 100.0\nr 384 144 384 304 0 100.0\nr 384 304 224 304 0 100.0\nr "
},
{
"path": "src/circuits/currentsrc.txt",
"chars": 399,
"preview": "$ 1 5.0E-6 10.391409633455755 58 10.0 50\nt 192 224 256 224 0 1 0.25888403915739877 0.5839501020424223 100.0\nr 256 240 25"
},
{
"path": "src/circuits/currentsrcelm.txt",
"chars": 590,
"preview": "$ 1 5.0E-6 10 50 5.0\nw 112 32 208 32 0\nw 208 32 304 32 0\nw 304 32 400 32 0\ns 208 32 208 112 0 false false\ns 304 32 304 1"
},
{
"path": "src/circuits/currentsrcramp.txt",
"chars": 419,
"preview": "$ 1 5.0E-6 15 53 10.0\nt 176 256 240 256 0 1 0.6557323083416877 0.6568475020864442\nr 240 272 240 320 0 100.0\ng 240 320 24"
},
{
"path": "src/circuits/dac.txt",
"chars": 531,
"preview": "$ 1 5.0E-6 10 50 5.0\nw 208 128 208 192 0\nw 320 208 320 128 0\nr 208 128 320 128 0 160.6\ng 208 288 208 320 0\nw 208 192 176"
},
{
"path": "src/circuits/darlington.txt",
"chars": 439,
"preview": "$ 1 5.0E-6 10.20027730826997 56 5.0 50\nt 368 288 400 288 0 1 -4.687537934791563 0.09853954519174213 100.0\nr 304 112 304 "
},
{
"path": "src/circuits/dcrestoration.txt",
"chars": 257,
"preview": "$ 1 1.0E-6 7 59 5.0\nR 160 144 96 144 0 1 500.0 5.0 0.0\nc 160 144 272 144 0 5.0E-6 -3.0584720734913993\nd 272 256 272 144 "
},
{
"path": "src/circuits/deccounter.txt",
"chars": 1461,
"preview": "$ 3 5.0E-6 13 50 5.0\n156 72 248 128 248 0 5.0\n156 208 248 240 248 0 0.0\n156 336 248 368 248 0 0.0\n156 464 248 480 248 0 "
},
{
"path": "src/circuits/decoder.txt",
"chars": 666,
"preview": "$ 1 5.0E-6 1.5 50 5.0\n150 416 128 512 128 0 2 0.0\n150 416 192 512 192 0 2 0.0\n150 416 256 512 256 0 2 0.0\n150 416 320 51"
},
{
"path": "src/circuits/delayrc.txt",
"chars": 600,
"preview": "$ 1 5.0E-9 10 54 5.0\nf 144 144 208 144 1\nf 144 240 208 240 0\nw 208 160 208 192 0\nw 208 192 208 224 0\nw 144 144 144 192 0"
},
{
"path": "src/circuits/deltasigma.txt",
"chars": 1196,
"preview": "$ 3 5.0E-6 12.185319768402522 50 5.0 50\na 144 248 224 248 0 15.0 -15.0\nw 144 232 144 200 0\nc 144 200 224 200 0 1.4999999"
},
{
"path": "src/circuits/diff.txt",
"chars": 207,
"preview": "$ 1 5.0E-6 10 50 5.0\nv 160 288 160 144 0 2 40.0 5.0 0.0\nc 160 144 352 144 0 9.0E-6 4.999340978003125\nr 352 144 352 288 0"
},
{
"path": "src/circuits/digcompare.txt",
"chars": 1366,
"preview": "$ 3 5.0E-6 1.5 50 5.0\nL 64 88 64 56 2 true false 5.0 0.0\nw 64 88 88 88 0\nI 88 88 88 144 0\nL 112 88 112 56 2 true false 5"
},
{
"path": "src/circuits/digsine.txt",
"chars": 1360,
"preview": "$ 3 5.0E-6 10 69 5.0\n155 80 224 88 224 1 5.0\n155 144 224 152 224 1 5.0\n155 208 224 216 224 1 0.0\n155 272 224 280 224 1 0"
},
{
"path": "src/circuits/diodeclip.txt",
"chars": 279,
"preview": "$ 1 5.0E-6 11.251013186076355 58 5.0 50\nr 272 160 320 160 0 200.0\nr 320 160 320 240 0 100.0\nd 320 240 320 288 0\nR 320 28"
},
{
"path": "src/circuits/diodecurve.txt",
"chars": 214,
"preview": "$ 1 5.0E-6 10.812258501325767 50 2.0 50\nR 288 208 288 160 0 3 50.0 0.65 0.25 0.0 0.5\nd 288 208 288 288 0\ng 288 288 288 3"
},
{
"path": "src/circuits/diodelimit.txt",
"chars": 292,
"preview": "$ 1 5.0E-6 10 50 5.0\nv 176 288 176 144 0 1 40.0 5.0 0.0\nr 176 144 272 144 0 110.0\nw 272 144 272 192 0\nw 272 192 304 192 "
},
{
"path": "src/circuits/diodevar.txt",
"chars": 155,
"preview": "$ 1 5.0E-6 10.391409633455755 50 1.0 50\n172 336 176 336 128 0 6 0.72 0.77 -1.0 0.0 0.5 Voltage\nw 336 304 336 336 1\ng 336"
},
{
"path": "src/circuits/divideby2.txt",
"chars": 214,
"preview": "$ 1 5.0E-6 10 50 5.0\n155 272 96 320 96 0 0.0\nR 272 128 208 128 1 2 100.0 2.5 2.5\nw 368 160 368 64 0\nw 368 64 272 64 0\nw "
},
{
"path": "src/circuits/divideby3.txt",
"chars": 398,
"preview": "$ 1 5.0E-6 10 50 5.0\n155 112 192 144 192 0 0.0\n155 304 192 352 192 0 0.0\nw 304 176 304 192 0\nw 304 224 304 304 0\nw 112 2"
},
{
"path": "src/circuits/dram.txt",
"chars": 1674,
"preview": "$ 3 5.0E-6 5 86 5.0 50\nw 400 16 424 16 0\nc 424 16 424 48 0 1.0E-8 0\nw 368 16 344 16 0\ng 424 48 424 56 0\nf 384 72 384 16 "
},
{
"path": "src/circuits/dtlinverter.txt",
"chars": 335,
"preview": "$ 1 5.0E-6 10 54 5.0\ng 320 272 320 320 0\nr 224 176 224 96 0 4700.0\nr 320 96 320 176 0 1000.0\nw 320 176 320 240 0\nM 320 1"
},
{
"path": "src/circuits/dtlnand.txt",
"chars": 479,
"preview": "$ 1 5.0E-6 10 54 5.0\ng 336 272 336 320 0\nr 240 176 240 96 0 4700.0\nr 336 96 336 176 0 1000.0\nw 336 176 336 240 0\nM 336 1"
},
{
"path": "src/circuits/dtlnor.txt",
"chars": 692,
"preview": "$ 1 5.0E-6 10 54 5.0\nt 160 240 208 240 0 1 0.5852076661116881 0.6224167269731172\nr 128 160 128 80 0 4700.0\nR 128 80 64 8"
},
{
"path": "src/circuits/eclnor.txt",
"chars": 1685,
"preview": "$ 1 5.0E-6 2.2188692582893284 54 1.5 58\nt 48 240 96 240 0 1 -1.3934257822325842 0.1535491976387855 100.0\nt 128 240 176 2"
},
{
"path": "src/circuits/eclosc.txt",
"chars": 789,
"preview": "$ 1 5.0E-6 8.63434833026695 49 1.0 50\nl 128 192 128 256 0 0.1 0.009389546443369765\nc 192 192 192 256 0 4.999999999999999"
},
{
"path": "src/circuits/edgedff.txt",
"chars": 1037,
"preview": "$ 1 5.0E-6 10 50 5.0\n151 320 272 432 272 0 2 -0.0\n151 320 144 432 144 0 2 5.0\nw 432 144 432 176 0\nw 432 176 320 240 0\nw "
},
{
"path": "src/circuits/filt-hipass-l.txt",
"chars": 251,
"preview": "$ 1 5.0E-6 6.499443210467817 50 5.0 50\nO 400 160 512 160 0\ng 400 288 400 320 0\nr 240 160 400 160 0 187.0\nl 400 160 400 2"
}
]
// ... and 181 more files (download for full content)
About this extraction
This page contains the full source code of the hausen/circuit-simulator GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 381 files (548.9 KB), approximately 247.6k tokens, and a symbol index with 1353 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.