Skip to content

Fix: component value label on canvas doesn't update after editing#27

Open
ImranFarhat01 wants to merge 1 commit into
FOSSEE:developfrom
ImranFarhat01:fix/component-label-update-clean
Open

Fix: component value label on canvas doesn't update after editing#27
ImranFarhat01 wants to merge 1 commit into
FOSSEE:developfrom
ImranFarhat01:fix/component-label-update-clean

Conversation

@ImranFarhat01

Copy link
Copy Markdown

Problem

Component value label on the canvas did not update after using SET
PARAMETERS in the Component Properties panel.

Root Cause

The Redux state was updated correctly, but nothing told mxGraph to
refresh the displayed cell label. The canvas label is built from
per-component-type rules (plain value for resistors/inductors/
capacitors, no value line for transistors/MOSFETs, an extra
expression appended with a space, etc), and that logic only existed
inside the netlist generation function, never wired up to the
Properties panel.

Fix

  • Extracted the label-building rules into a single shared function,
    buildComponentCanvasLabel(baseName, properties)
  • Netlist generation now calls this function once instead of
    repeating the same label-building line across 7 different branches
  • The Properties panel now looks up the edited cell directly via the
    graph model, preserves the component's base name, rebuilds the
    value portion using the shared function, and applies it
    immediately to the canvas

Testing

  • Resistor: edited value, canvas immediately shows the component name
    and new value together, name preserved
  • Capacitor: same, name preserved
  • Voltage source with a custom waveform expression: edited value,
    canvas immediately shows the name and new expression together
  • Generated a netlist after these edits to confirm the underlying
    simulation output is unaffected by the refactor

Component value label on the canvas did not update after using SET
PARAMETERS in the Component Properties panel. The Redux state was
updated, but nothing told mxGraph to refresh the displayed cell label.

A previous attempt at fixing this called model.setValue() with just
the raw VALUE field, which did make the canvas update immediately,
but replaced the entire label (e.g. 'R1\n1k' became just '10k'),
losing the component name.

The canvas label is actually built from per-component-type rules
(plain VALUE for R/L/C, 'DC value' phrasing only affects the netlist
string not the label, no value line at all for transistors/MOSFETs,
EXTRA_EXPRESSION appended with a space, etc), and that logic already
existed inside buildNetlistFromGraph() in NetlistExporter.js, just
duplicated across every branch.

Fix:
- Extracted the label-building rules into a single shared function,
  buildComponentCanvasLabel(baseName, properties)
- buildNetlistFromGraph() now calls this function once instead of
  repeating 'component.value = component.value + ...' in 7 places
- ComponentProperties.js's setProps() now looks up the edited cell
  directly via the graph model (not via canvas selection, which can
  be stale or include unrelated cells), splits its current label to
  preserve the base name, calls the shared function to rebuild the
  value portion, and applies it via model.setValue()
- Added a small getGraph() export from ComponentDrag.js so
  ComponentProperties.js can access the live graph instance

Testing:
- Resistor: edited VALUE, canvas immediately shows 'R1' / new value
  on two lines, name preserved
- Capacitor: same, name preserved
- Voltage source (PWL waveform): edited VALUE, canvas immediately
  shows 'V1' / new waveform expression, name preserved
- Generated a netlist after these edits: output is correct and
  unaffected by the refactor (same SPICE syntax as before)
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.

1 participant