Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/com/lushprojects/circuitjs1/client/CircuitElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public abstract class CircuitElm implements Editable {
static final int SCALE_MU = 3;

static int decimalDigits, shortDecimalDigits;


static boolean showOperatingRegion;

// initial point where user created element. For simple two-terminal elements, this is the first node/post.
int x, y;

Expand Down Expand Up @@ -1231,6 +1233,7 @@ static double distance(Point p1, Point p2) {
int getShortcut() { return 0; }
boolean showValues() { return app.menus.showValuesCheckItem.getState(); }
boolean showPower() { return app.menus.powerCheckItem.getState(); }
boolean showOperatingRegion() { return showOperatingRegion; }
boolean showEuroResistors() { return app.menus.euroResistorCheckItem.getState(); }
boolean useSmallGrid() { return app.menus.smallGridCheckItem.getState(); }
boolean doDcAnalysis() { return app.dcAnalysisFlag; }
Expand Down
15 changes: 13 additions & 2 deletions src/com/lushprojects/circuitjs1/client/EditOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ public EditInfo getEditInfo(int n) {
return ei;
}
if (n == 15) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Show Operating Region", CircuitElm.showOperatingRegion);
return ei;
}
if (n == 16) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Auto-Adjust Timestep", sim.adjustTimeStep);
return ei;
}
if (n == 16 && sim.adjustTimeStep)
if (n == 17 && sim.adjustTimeStep)
return new EditInfo("Minimum time step size (s)", sim.minTimeStep, 0, 0).setPositive();

// don't add new options here. they are only visible if sim.adjustTimeStemp is set, and it isn't by default.
Expand Down Expand Up @@ -194,10 +199,16 @@ public void setEditValue(int n, EditInfo ei) {
if (n == 14)
app.autoDCOnReset = ei.checkbox.getState();
if (n == 15) {
CircuitElm.showOperatingRegion = ei.checkbox.getState();
Storage stor = Storage.getLocalStorageIfSupported();
if (stor != null)
stor.setItem("showOperatingRegion", CircuitElm.showOperatingRegion ? "true" : "false");
}
if (n == 16) {
sim.adjustTimeStep = ei.checkbox.getState();
ei.newDialog = true;
}
if (n == 16)
if (n == 17 && ei.value > 0)
sim.minTimeStep = ei.value;
}

Expand Down
15 changes: 15 additions & 0 deletions src/com/lushprojects/circuitjs1/client/MosfetElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ void draw(Graphics g) {
setVoltageColor(g, volts[2]);
drawThickLine(g, drn[0], drn[1]);

// draw operating region indicator on channel
if (showOperatingRegion()) {
Color regionColor;
if (mode == 0)
regionColor = Color.gray; // cutoff
else if (mode == 1)
regionColor = new Color(64, 128, 255); // linear/triode - blue
else
regionColor = new Color(0, 192, 0); // saturation - green
g.setColor(regionColor);
g.setLineWidth(6);
g.drawLine(src[1], drn[1]);
g.setLineWidth(3);
}

// draw line connecting source and drain
int segments = 6;
int i;
Expand Down
13 changes: 13 additions & 0 deletions src/com/lushprojects/circuitjs1/client/OpAmpElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ void draw(Graphics g) {
drawThickLine(g, in2p[0], in2p[1]);
setVoltageColor(g, volts[2]);
drawThickLine(g, lead2, point2);
// draw operating region indicator (saturation coloring)
if (showOperatingRegion()) {
double saturationMargin = (maxOut - minOut) * 0.01;
if (saturationMargin < 0.01)
saturationMargin = 0.01;
if (volts[2] >= maxOut - saturationMargin) {
g.setColor(new Color(180, 60, 60)); // positive saturation - red tint
g.fillPolygon(triangle);
} else if (volts[2] <= minOut + saturationMargin) {
g.setColor(new Color(60, 60, 180)); // negative saturation - blue tint
g.fillPolygon(triangle);
}
}
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
setPowerColor(g, true);
drawThickPolygon(g, triangle);
Expand Down
16 changes: 16 additions & 0 deletions src/com/lushprojects/circuitjs1/client/OpAmpRealElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ void draw(Graphics g) {
drawThickLine(g, rail1p[0], rail1p[1]);
setVoltageColor(g, volts[4]);
drawThickLine(g, rail2p[0], rail2p[1]);
// draw operating region indicator (saturation coloring)
if (showOperatingRegion()) {
double vPlus = volts[3];
double vMinus = volts[4];
double range = vPlus - vMinus;
double saturationMargin = range * 0.02;
if (saturationMargin < 0.05)
saturationMargin = 0.05;
if (volts[2] >= vPlus - saturationMargin) {
g.setColor(new Color(180, 60, 60)); // positive saturation - red tint
g.fillPolygon(triangle);
} else if (volts[2] <= vMinus + saturationMargin) {
g.setColor(new Color(60, 60, 180)); // negative saturation - blue tint
g.fillPolygon(triangle);
}
}
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
setPowerColor(g, true);
drawThickPolygon(g, triangle);
Expand Down
2 changes: 2 additions & 0 deletions src/com/lushprojects/circuitjs1/client/UIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ else if (usRes)
menus.noEditCheckItem.setState(noEditing);
menus.mouseWheelEditCheckItem.setState(mouseWheelEdit);

CircuitElm.showOperatingRegion = getOptionFromStorage("showOperatingRegion", false);

loadShortcuts();

DOM.appendChild(layoutPanel.getElement(), topPanelCheckbox);
Expand Down
Loading