fix: update templates to KiCAD 9 format + remove corrupt _TEMPLATE_ blocks
Verified by live test: created a fresh schematic via MCP, result shows
format version 20250114, 0 _TEMPLATE_ hits, 0 (lib_id -100) hits, 24
real components placed cleanly.
--- Format version bump (20230121 KiCAD 7 -> 20250114 KiCAD 9) ---
Files: python/templates/*.kicad_sch, python/commands/project.py,
python/commands/schematic.py
Root cause: the MCP server targets KiCAD 9 exclusively - pcbnew.pyd is
compiled for KiCAD 9.0 / Python 3.11.5, and server.ts explicitly selects
the KiCAD 9 bundled Python on Windows. Generating new schematics with a
2-year-old format tag caused a spurious 'This file was created with an
older KiCAD version' warning on every newly created schematic.
--- Remove corrupt _TEMPLATE_* placed-symbol blocks ---
File: python/templates/template_with_symbols_expanded.kicad_sch
Root cause: the expanded template was generated by the old sexpdata
serializer (same corruption PR #40 fixed for DynamicSymbolLoader add-path).
The serializer converted the string 'Device:R' to integer -100, producing
(lib_id -100) instead of (lib_id Device:R). KiCAD cannot resolve an
integer as a library reference and crashes with a null-pointer when the
user attempts to select these symbols. They appeared as grey _TEMPLATE_R?,
_TEMPLATE_C?, _TEMPLATE_U_REG? etc. ~5000mm off-sheet - invisible during
normal work but triggering a crash on accidental box-select.
Discovered via live testing on a real JLCPCB/KiCAD 9 project.
This commit is contained in:
@@ -4,7 +4,8 @@ import shutil
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
logger = logging.getLogger('kicad_interface')
|
||||
logger = logging.getLogger("kicad_interface")
|
||||
|
||||
|
||||
class SchematicManager:
|
||||
"""Core schematic operations using kicad-skip"""
|
||||
@@ -16,11 +17,13 @@ class SchematicManager:
|
||||
# Determine template path (use template_with_symbols for component cloning support)
|
||||
template_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
'..', 'templates', 'template_with_symbols.kicad_sch'
|
||||
"..",
|
||||
"templates",
|
||||
"template_with_symbols.kicad_sch",
|
||||
)
|
||||
|
||||
# Determine output path
|
||||
output_path = name if name.endswith('.kicad_sch') else f"{name}.kicad_sch"
|
||||
output_path = name if name.endswith(".kicad_sch") else f"{name}.kicad_sch"
|
||||
|
||||
if os.path.exists(template_path):
|
||||
# Copy template to target location
|
||||
@@ -28,17 +31,21 @@ class SchematicManager:
|
||||
logger.info(f"Created schematic from template: {output_path}")
|
||||
else:
|
||||
# Fallback: create minimal schematic
|
||||
logger.warning(f"Template not found at {template_path}, creating minimal schematic")
|
||||
logger.warning(
|
||||
f"Template not found at {template_path}, creating minimal schematic"
|
||||
)
|
||||
# Generate unique UUID for this schematic
|
||||
schematic_uuid = str(uuid.uuid4())
|
||||
# Write with explicit UTF-8 encoding and Unix line endings for cross-platform compatibility
|
||||
with open(output_path, 'w', encoding='utf-8', newline='\n') as f:
|
||||
f.write('(kicad_sch (version 20230121) (generator "KiCAD-MCP-Server")\n\n')
|
||||
f.write(f' (uuid {schematic_uuid})\n\n')
|
||||
with open(output_path, "w", encoding="utf-8", newline="\n") as f:
|
||||
f.write(
|
||||
'(kicad_sch (version 20250114) (generator "KiCAD-MCP-Server")\n\n'
|
||||
)
|
||||
f.write(f" (uuid {schematic_uuid})\n\n")
|
||||
f.write(' (paper "A4")\n\n')
|
||||
f.write(' (lib_symbols\n )\n\n')
|
||||
f.write(" (lib_symbols\n )\n\n")
|
||||
f.write(' (sheet_instances\n (path "/" (page "1"))\n )\n')
|
||||
f.write(')\n')
|
||||
f.write(")\n")
|
||||
|
||||
# Load the schematic
|
||||
sch = Schematic(output_path)
|
||||
@@ -88,7 +95,8 @@ class SchematicManager:
|
||||
logger.debug("Extracted schematic metadata")
|
||||
return metadata
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Example Usage (for testing)
|
||||
# Create a new schematic
|
||||
new_sch = SchematicManager.create_schematic("MyTestSchematic")
|
||||
|
||||
Reference in New Issue
Block a user