Skip to content

Add resistor/capacitor/SMD value calculator with component image generation#1435

Open
Sebbeben wants to merge 1 commit into
Part-DB:masterfrom
Sebbeben:claude/partdb-resistor-capacitor-icons
Open

Add resistor/capacitor/SMD value calculator with component image generation#1435
Sebbeben wants to merge 1 commit into
Part-DB:masterfrom
Sebbeben:claude/partdb-resistor-capacitor-icons

Conversation

@Sebbeben

@Sebbeben Sebbeben commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Component value calculator & image generator

Adds a Value calculator tool (Tools menu) that decodes/encodes the value of common components and generates a clean SVG picture you can attach to a part — handy for assortments (e.g. AliExpress kits) imported with blank thumbnails and sparse data.

Calculator tabs

Each tab is a bidirectional decoder/encoder, draws the part to the selected package with a collapsible "appearance" panel, and can attach the rendered image (optionally as the master picture):

  • Resistor — 4/5/6-band colour code
  • Capacitor — value ↔ 3-digit code ↔ tolerance
  • SMD resistor — value ↔ 3-digit / 4-digit / EIA-96 code
  • Inductor — colour-band code
  • SMD inductor — value ↔ µH code

Bulk "Generate component images" (parts-table action)

  • Classifies each selected part (resistor / capacitor / inductor / diode / LED, THT or SMD) with ComponentValueGuesser and detects value, voltage, tolerance, power, ppm, pitch, diameter, colour, SMD package and marking from the name, description and parameters.
  • Renders a preview per part, lets you tweak appearance, and attaches the images in one go.
  • Can also write matching KiCad symbol/footprint/reference-prefix EDA fields for the whole selection.

Implementation

  • ComponentValueGuesser — classification + detection + EDA suggestion.
  • GeneratedImageAttachmentHelper — stores the SVG through the existing attachment pipeline, so every generated image is run through the SVG sanitizer on save.
  • Two POST endpoints on PartController (generate_image, set_eda) guarded by edit + CSRF.
  • New @tools.value_calculator permission, a Tools-tree entry, and docs.
  • All drawing is client-side in a Stimulus controller; the un-sanitized live preview escapes part-derived text and validates colours as defence-in-depth.

Tests

Unit tests for ComponentValueGuesser and functional tests for the endpoints, including permission/CSRF enforcement and the persisted side effects.

Open question for review

The tool is currently called a "calculator", but roughly half its value is image generation for real parts, and some tabs are really decoders/converters. Happy to rename or restructure (e.g. "Component value & image tool", or split "Decoder" vs "Image generator") — whatever fits Part-DB best.

Screenshots to follow.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.96803% with 79 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.11%. Comparing base (12b53f1) to head (0ec45ac).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/Services/Tools/ComponentValueGuesser.php 90.55% 34 Missing ⚠️
src/Controller/ToolsController.php 84.00% 16 Missing ⚠️
...ces/Attachments/GeneratedImageAttachmentHelper.php 70.45% 13 Missing ⚠️
src/Controller/PartController.php 78.26% 10 Missing ⚠️
src/Services/Parts/PartsTableActionHandler.php 14.28% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1435      +/-   ##
============================================
+ Coverage     58.50%   59.11%   +0.61%     
- Complexity     8713     8946     +233     
============================================
  Files           640      642       +2     
  Lines         28197    28762     +565     
============================================
+ Hits          16496    17003     +507     
- Misses        11701    11759      +58     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Sebbeben
Sebbeben force-pushed the claude/partdb-resistor-capacitor-icons branch 4 times, most recently from 27e99c8 to 9ebf399 Compare July 5, 2026 04:07
@Sebbeben
Sebbeben force-pushed the claude/partdb-resistor-capacitor-icons branch from 9ebf399 to af9c923 Compare July 20, 2026 20:16
Adds a "Value calculator" tool (Tools menu) that decodes/encodes the value of
common components and generates a clean SVG picture you can attach to a part —
handy for assortments imported with blank thumbnails and sparse data.

Calculator tabs (bidirectional decode <-> encode), each drawing the part to the
selected package with a collapsible appearance panel and an "attach to part"
action (optionally as the master picture):
- Resistor: 4/5/6-band colour code
- Capacitor: value <-> 3-digit code <-> tolerance
- SMD resistor: value <-> 3-digit / 4-digit / EIA-96 code
- Inductor: colour-band code
- SMD inductor: value <-> uH code

Bulk "Generate component images" parts-table action:
- Classifies each selected part (resistor / capacitor / inductor / diode / LED,
  THT or SMD) with ComponentValueGuesser and detects value, voltage, tolerance,
  power, ppm, pitch, diameter, colour, SMD package and marking from the name,
  description and parameters.
- Renders a preview per part, lets you tweak appearance, and attaches the images
  in one go; can also write matching KiCad symbol/footprint/reference-prefix EDA
  fields.

Backend: ComponentValueGuesser (classification + detection + EDA suggestion),
GeneratedImageAttachmentHelper (stores the SVG through the existing attachment
pipeline, so it is sanitised on save), two POST endpoints on PartController
(generate_image, set_eda) guarded by `edit` + CSRF, a new `@tools.value_calculator`
permission, a Tools-tree entry and docs. All drawing is client-side in a Stimulus
controller; the un-sanitised live preview escapes part-derived text and validates
colours as defence-in-depth.

Tests: unit tests for ComponentValueGuesser and functional tests for the
endpoints, including permission and CSRF enforcement and the persisted side
effects.
@Sebbeben
Sebbeben force-pushed the claude/partdb-resistor-capacitor-icons branch from af9c923 to 0ec45ac Compare July 21, 2026 05:26
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