Skip to content

Add oscilloscope charge plotting for capacitors#248

Merged
pfalstad merged 2 commits intopfalstad:v3-devfrom
esaruoho:capacitor-charge-scope
Mar 3, 2026
Merged

Add oscilloscope charge plotting for capacitors#248
pfalstad merged 2 commits intopfalstad:v3-devfrom
esaruoho:capacitor-charge-scope

Conversation

@esaruoho
Copy link
Copy Markdown

@esaruoho esaruoho commented Mar 2, 2026

Summary

  • Adds charge (Q = C*V) as a plottable scope value for capacitors (Feature request: Support viewing the stored charges within the capacitor #202)
  • New VAL_CHARGE and UNITS_C constants in Scope.java
  • CapacitorElm overrides getScopeValue()/getScopeUnits() for charge display
  • ScopePropertiesDialog shows "Show Charge" checkbox when a capacitor is selected
  • Also adds charge readout to the capacitor info panel

Test plan

  • Place a capacitor in a circuit with an oscilloscope
  • Right-click scope → verify "Show Charge" option appears
  • Enable charge display → verify Q tracks C*V correctly
  • Click on capacitor → verify info panel shows charge value
  • Verify no charge option appears for non-capacitor elements

Fixes #202

🤖 Generated with Claude Code

Add VAL_CHARGE and UNITS_C to Scope so users can view stored
charge (Q=CV) on the oscilloscope for capacitor elements. Adds a
"Show Charge" checkbox in scope properties when the scope is
attached to a capacitor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pfalstad
Copy link
Copy Markdown
Owner

pfalstad commented Mar 2, 2026

When you check "Show Charge" it doesn't show the voltage/current anymore but they are still checked.

Then if you uncheck Voltage and check it again, it shows the voltage and not the charge, even though charge is still checked.

esaruoho added a commit to esaruoho/circuitjs1 that referenced this pull request Mar 3, 2026
…Current() to AnalogMuxElm

- Reverted all charge plotting additions (VAL_CHARGE, UNITS_C, canShowCharge,
  showcharge) from Scope.java, ScopePropertiesDialog.java, and CapacitorElm.java.
  Charge plotting is handled separately in PR pfalstad#248.
- Added calculateCurrent() to AnalogMuxElm to compute pin currents for correct
  current animation and wire current behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Show Charge checkbox was calling setValue(VAL_CHARGE) which replaced
all existing plots (voltage, current) with just a charge plot. Now uses
a new showCharge() method that additively adds/removes a charge plot
without affecting other plots. Also updates showingVoltageAndMaybeCurrent()
to allow charge plots alongside voltage/current, and adds chargeBox state
tracking in the scope properties dialog.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@esaruoho
Copy link
Copy Markdown
Author

esaruoho commented Mar 3, 2026

Fixed charge plotting toggle — Show Charge now works independently alongside Show Voltage and Show Current. All three can be displayed simultaneously without interfering with each other.

@esaruoho
Copy link
Copy Markdown
Author

esaruoho commented Mar 3, 2026

Fixed charge plotting toggle:

The root cause was that handleMenu(showcharge) called setValue(VAL_CHARGE), which replaced the entire plots vector -- destroying voltage and current plots.

Now uses a new showCharge(boolean) method that additively adds/removes the charge plot without affecting other plots. Also updated showingVoltageAndMaybeCurrent() to allow charge alongside voltage/current, preventing the destroy-on-recheck behavior.

All three (voltage, current, charge) can now be displayed simultaneously and toggled independently.

@pfalstad pfalstad merged commit 698ad1e into pfalstad:v3-dev Mar 3, 2026
@esaruoho esaruoho deleted the capacitor-charge-scope branch March 4, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants