Phase 1: Schematic Workflow Fix (Issue #26) - Fixed broken schematic workflow using template-based symbol cloning - Updated create_project to generate both PCB and schematic files - Rewrote add_schematic_component to use kicad-skip clone() API - Added template schematics with cloneable R, C, LED symbols - All schematic tests now passing Phase 2: JLCPCB Integration Complete - Integrated JLCSearch public API (no authentication required) - Access to ~100k JLCPCB parts with real-time stock and pricing - Implemented parametric search for resistors, capacitors, components - Added package-to-footprint mapping for KiCad integration - Cost optimization with Basic vs Extended library classification - Alternative part suggestions with price comparison New Components: - python/commands/jlcsearch.py - JLCSearch API client - python/templates/ - Template schematics for symbol cloning - docs/JLCPCB_INTEGRATION.md - Comprehensive API documentation - docs/SCHEMATIC_WORKFLOW_FIX.md - Phase 1 technical details - CHANGELOG.md - Consolidated unified changelog - PHASE_2_COMPLETE.md - Phase 2 implementation summary MCP Tools Available: - download_jlcpcb_database - Download full parts catalog - search_jlcpcb_parts - Parametric search with filters - get_jlcpcb_part - Part details + footprint suggestions - get_jlcpcb_database_stats - Database statistics - suggest_jlcpcb_alternatives - Find similar/cheaper parts Technical Improvements: - SQLite database with FTS5 full-text search - HMAC-SHA256 authentication support (official JLCPCB API) - Improved .gitignore to exclude credentials and databases - Template-based schematic creation workflow Testing: - All integration tests passing - Database operations validated - Live API connectivity confirmed - Schematic workflow end-to-end verified Credits: - JLCSearch API: @tscircuit - Local JLCPCB search: @l3wi Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
4.4 KiB
4.4 KiB
Schematic Workflow Fix - Issue #26
Problem Summary
The schematic workflow was completely broken due to incorrect usage of the kicad-skip library:
create_projectonly created PCB files, no schematiccreate_schematiccreated orphaned schematic files not linked to projectsadd_schematic_componentcalled non-existentschematic.add_symbol()method- Project files didn't reference schematics in their structure
Root Cause
The kicad-skip library does not support creating symbols from scratch. The only way to add symbols is by cloning existing symbol instances.
From kicad-skip documentation:
"symbols: these don't have a new()" because they require complex mappings to library elements, pins, and properties.
Solution
1. Template-Based Approach
Created a template schematic (python/templates/template_with_symbols.kicad_sch) with:
- Complete
lib_symbolssection defining R, C, LED symbols - Three template symbol instances placed off-screen at (-100, -110, -120)
- Template symbols marked as
dnp yes,in_bom no,on_board noso they don't interfere
2. Updated Files
python/commands/project.py:
- Now creates both
.kicad_pcbAND.kicad_schfiles - Project file includes schematic reference in
sheetsarray - Copies template schematic with cloneable symbols
python/commands/schematic.py:
- Uses template file instead of creating from scratch
- Proper minimal schematic structure when template unavailable
python/commands/component_schematic.py:
- Completely rewritten to use
clone()API - Maps component types to template symbols
- Proper UUID generation for each cloned symbol
- Correct position setting:
symbol.at.value = [x, y, rotation]
3. Correct Workflow
from commands.project import ProjectCommands
from commands.schematic import SchematicManager
from commands.component_schematic import ComponentManager
# Step 1: Create project (creates both PCB and schematic)
project_cmd = ProjectCommands()
result = project_cmd.create_project({
"name": "MyProject",
"path": "/path/to/project"
})
# Step 2: Load the schematic
sch = SchematicManager.load_schematic(result['project']['schematicPath'])
# Step 3: Add components by cloning templates
component_def = {
"type": "R", # Maps to _TEMPLATE_R
"reference": "R1", # Component reference
"value": "10k", # Component value
"footprint": "Resistor_SMD:R_0603_1608Metric",
"x": 50.8, # Position in mm
"y": 50.8, # Position in mm
"rotation": 0 # Rotation in degrees
}
symbol = ComponentManager.add_component(sch, component_def)
# Step 4: Save the schematic
SchematicManager.save_schematic(sch, result['project']['schematicPath'])
Supported Component Types
Currently supported template symbols:
R- Resistor (maps to_TEMPLATE_R)C- Capacitor (maps to_TEMPLATE_C)DorLED- LED (maps to_TEMPLATE_D)
To add more component types, update:
python/templates/template_with_symbols.kicad_sch- Add lib_symbol definition and template instancepython/commands/component_schematic.py- Add mapping inTEMPLATE_MAP
Testing
Comprehensive test created at /tmp/test_schematic_workflow.py:
- Creates project with schematic
- Loads schematic
- Adds R, C, LED components
- Saves schematic
- Validates with
kicad-cli sch export pdf
All tests passing ✓
Files Modified
python/commands/project.py- Added schematic creationpython/commands/schematic.py- Fixed template usagepython/commands/component_schematic.py- Rewritten to use clone() APIpython/templates/empty.kicad_sch- Minimal template (created)python/templates/template_with_symbols.kicad_sch- Template with cloneable symbols (created)
Limitations
- Can only add components that have templates defined
- Template symbols remain in schematic (but marked as DNP/not in BOM)
- Complex symbols (multi-unit, hierarchical) may need custom templates
Future Improvements
- Add more component templates (transistors, connectors, ICs)
- Dynamic template generation from KiCad symbol libraries
- Auto-hide template symbols in schematic
- Support for custom user templates
References
- GitHub Issue: #26
- kicad-skip documentation: https://github.com/psychogenic/kicad-skip
- Test results:
/tmp/test_schematic_workflow/