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

Why

I often order component assortments — resistor and capacitor kits — from AliExpress. They show up as a big box of values, and when I import them into Part-DB it's honestly a bit sad to see rows of blank thumbnails with almost no information. So I built a tool that draws a clean, consistent picture for each passive component straight from its value, and can illustrate a whole assortment in one go.

What it does

Value calculator (Tools → Value calculator) — interactively draw a:

  • resistor as colour bands (4/5/6 band; tolerance, power and temperature-coefficient reflected),
  • SMD resistor with the 3-digit / 4-digit / EIA-96 marking for its package,
  • ceramic capacitor as a radial disc or MLCC blob (printed code, voltage line, tolerance letter).

Value ⇄ code ⇄ bands are bidirectionally linked and the picture redraws live. Output is a transparent SVG, so it stays crisp at any size.

Generate on a part — a part with no picture shows a Generate image button in the picture area that opens the calculator pre-filled from the part's value; attach it without leaving the page.

Bulk "Generate component images" — a parts-table action that classifies the selected parts, reads their value and properties (from parameters, else the name/description), and shows a review table with a live preview per part. From there you can attach the pictures and/or write suggested KiCad symbol / footprint / reference to the parts. Only parts without a picture are listed; an overwrite mode can re-generate ones that already have a (generated) picture.

Detection follows real-world conventions: capacitor tolerance → code letter (104K), through-hole resistor tolerance/ppm → colour bands, SMD resistor tolerance → 3- vs 4-digit code, power → resistor body size, etc.

Implementation notes

  • New ComponentValueGuesser service classifies a part and parses value / tolerance / voltage / power / ppm / pitch / diameter / body-colour / SMD-package from parameters or free text (name/description), and suggests a KiCad symbol + footprint.
  • New GeneratedImageAttachmentHelper stores the SVG as a picture attachment through the existing upload pipeline (so the SVG is sanitized), optionally replacing a previous generated image — manually uploaded pictures are never removed.
  • All drawing is client-side in a Stimulus controller (no server-side image libraries). The bulk previews reuse the exact same drawing code via a hidden calculator instance.
  • The generate_image and set_eda endpoints require edit on the part plus a per-part CSRF token; the tool sits behind a new @tools.value_calculator permission.
  • Unit tests for ComponentValueGuesser; usage docs at docs/usage/component_image_generator.md.

The generated images are illustrations (code/bands + dimension callouts), not photographs.

Screenshots

Value calculator (resistor / SMD / capacitor tabs)
calculator-capacitor
calculator-smd
calculator-tht

"How to get the most auto-filled" help panel
helper-text

Bulk action in the parts table
menu-action

Bulk review with live previews
smd-resistor-generate

tht-resistor-generate capacitor-generate

Testing

  • ComponentValueGuesserTest covers value parsing (including the kΩ/MΩ cases), classification, and the property/EDA detection.
  • Manually tested end-to-end (single-part generate + bulk generate) for resistors, SMD resistors and ceramic capacitors.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.83538% with 78 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.86%. Comparing base (7244803) to head (9ebf399).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/Services/Tools/ComponentValueGuesser.php 81.98% 40 Missing ⚠️
...ces/Attachments/GeneratedImageAttachmentHelper.php 70.45% 13 Missing ⚠️
src/Controller/PartController.php 76.08% 11 Missing ⚠️
src/Controller/ToolsController.php 90.24% 8 Missing ⚠️
src/Services/Parts/PartsTableActionHandler.php 14.28% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1435      +/-   ##
============================================
+ Coverage     58.49%   58.86%   +0.36%     
- Complexity     8701     8856     +155     
============================================
  Files           638      640       +2     
  Lines         28123    28530     +407     
============================================
+ Hits          16451    16793     +342     
- Misses        11672    11737      +65     

☔ 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 3 times, most recently from bedfb8b to 27e99c8 Compare July 5, 2026 03:45
…ration

Draws schematic-style SVG pictures of passive components from their value and
attaches them to parts — for illustrating bulk assortments imported without pictures.

- Value calculator tool (Tools menu): interactive resistor (colour bands), SMD
  resistor (3/4-digit/EIA-96 code) and ceramic capacitor (disc/MLCC) drawing, with
  bidirectionally-linked value/code/band fields and appearance controls.
- "Generate image" button on parts without a picture, opening the calculator
  pre-filled from the part's value and attaching via AJAX.
- "Generate component images" parts-table bulk action: classifies the selected
  parts, reads their properties, shows a live-preview review table, then
  batch-attaches pictures and/or writes suggested KiCad symbol/footprint/reference.
- ComponentValueGuesser service: classification + value/tolerance/voltage/power/
  ppm/pitch/diameter/colour/SMD-package detection from parameters or name/description.
- GeneratedImageAttachmentHelper: stores the SVG as a sanitized picture attachment
  via the existing upload pipeline, with optional overwrite of a prior generated image.
- New @tools.value_calculator permission; edit-permission + CSRF-guarded endpoints.
- Unit tests (ComponentValueGuesser) + functional tests (tool controllers);
  usage documentation.
@Sebbeben Sebbeben force-pushed the claude/partdb-resistor-capacitor-icons branch from 27e99c8 to 9ebf399 Compare July 5, 2026 04:07
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