Skip to content

fix scope charge checkbox toggling#303

Open
esaruoho wants to merge 1 commit intopfalstad:v3-devfrom
esaruoho:fix-scope-charge-checkbox
Open

fix scope charge checkbox toggling#303
esaruoho wants to merge 1 commit intopfalstad:v3-devfrom
esaruoho:fix-scope-charge-checkbox

Conversation

@esaruoho
Copy link
Copy Markdown

@esaruoho esaruoho commented Mar 6, 2026

What this fixes (beyond #248)

PR #248 added charge plotting and fixed the initial issue you reported (Show Charge hiding voltage/current). However, the showCharge() implementation directly adds/removes plots from the list, unlike showVoltage()/showCurrent() which use boolean flags (showV/showI) filtered by calcVisiblePlots(). This mismatch causes three remaining bugs:

  1. setValue() destroys charge plots. Toggling scope values (e.g. clicking "Show Resistance") calls setValue(), which rebuilds the plots vector from scratch. Charge plots are lost because addValue() doesn't know to re-add them. With a showC flag, addValue() can restore the charge plot after a rebuild.

  2. Charge state not persisted on save/load. getFlags()/setFlags() don't include charge state, so saving a circuit and reloading it loses the "Show Charge" setting.

  3. No visibility toggle — only add/destroy. Unchecking "Show Charge" removes the plot entirely and calls resetGraph(), destroying accumulated data. Voltage and current instead just toggle visibility via showV/showI without removing the underlying plot data.

Fix

Adds a showC boolean flag that mirrors the existing showV/showI pattern:

  • showCharge() sets showC and adds the plot if needed, but no longer removes plots or resets the graph
  • calcVisiblePlots() filters UNITS_C plots by showC (like UNITS_V/showV and UNITS_A/showI)
  • addValue() re-adds the charge plot when showC is true after a setValue() rebuild
  • initialize() detects existing charge plots and sets showC
  • getFlags()/setFlags() persist showC using bit 1<<23
  • ScopePropertiesDialog.updateUi() reads scope.showC instead of scope.hasPlotValue()

Steps to reproduce the bugs (on current v3-dev)

  1. Place a capacitor with a scope → enable Show Charge → enable Show Resistance → charge plot disappears (bug 1)
  2. Place a capacitor with a scope → enable Show Charge → save circuit → reload → charge not shown (bug 2)
  3. Place a capacitor with a scope → enable Show Charge → uncheck Show Charge → recheck Show Charge → graph history is gone (bug 3)

🤖 Generated with Claude Code

…oltage/current

Show Charge now adds a charge plot alongside existing plots
instead of replacing them. Unchecking charge removes only
the charge plot.

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

pfalstad commented Mar 6, 2026

You already fixed the issue I noted on #248. What does this fix?

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