feat: Implement IPC backend for real-time UI synchronization

Add KiCAD IPC API backend using kicad-python library for real-time
communication with KiCAD 9.0+. Changes now appear instantly in KiCAD
UI without manual reload.

Key changes:
- Implement IPCBackend and IPCBoardAPI classes for IPC communication
- Auto-detect IPC availability and fall back to SWIG when unavailable
- Route existing commands (route_trace, add_via, place_component, etc.)
  through IPC automatically when available
- Add transaction support for proper undo/redo
- Add socket path auto-detection for Linux (/tmp/kicad/api.sock)

New commands:
- get_backend_info: Check which backend is active

Supported IPC operations:
- Board: set_size, get_board_info, save
- Routing: route_trace, add_via, add_net
- Components: place, move, delete, list
- Text: add_text, add_board_text

SWIG backend is now deprecated and will be removed when KiCAD 10.0
drops SWIG support.

Requires: kicad-python>=0.5.0, KiCAD 9.0+ with IPC enabled

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
KiCAD MCP Bot
2025-11-30 14:33:27 -05:00
parent dd12d21f46
commit 319473b1d8
8 changed files with 2116 additions and 135 deletions

View File

@@ -185,8 +185,92 @@ class BoardAPI(ABC):
"""
pass
# Add more abstract methods for routing, DRC, export, etc.
# These will be filled in during migration
# Routing Operations
def add_track(
self,
start_x: float,
start_y: float,
end_x: float,
end_y: float,
width: float = 0.25,
layer: str = "F.Cu",
net_name: Optional[str] = None
) -> bool:
"""
Add a track (trace) to the board
Args:
start_x: Start X position (mm)
start_y: Start Y position (mm)
end_x: End X position (mm)
end_y: End Y position (mm)
width: Track width (mm)
layer: Layer name
net_name: Optional net name
Returns:
True if successful
"""
raise NotImplementedError()
def add_via(
self,
x: float,
y: float,
diameter: float = 0.8,
drill: float = 0.4,
net_name: Optional[str] = None,
via_type: str = "through"
) -> bool:
"""
Add a via to the board
Args:
x: X position (mm)
y: Y position (mm)
diameter: Via diameter (mm)
drill: Drill diameter (mm)
net_name: Optional net name
via_type: Via type ("through", "blind", "micro")
Returns:
True if successful
"""
raise NotImplementedError()
# Transaction support for undo/redo
def begin_transaction(self, description: str = "MCP Operation") -> None:
"""Begin a transaction for grouping operations."""
pass # Optional - not all backends support this
def commit_transaction(self, description: str = "MCP Operation") -> None:
"""Commit the current transaction."""
pass # Optional
def rollback_transaction(self) -> None:
"""Roll back the current transaction."""
pass # Optional
def save(self) -> bool:
"""Save the board."""
raise NotImplementedError()
# Query operations
def get_tracks(self) -> List[Dict[str, Any]]:
"""Get all tracks on the board."""
raise NotImplementedError()
def get_vias(self) -> List[Dict[str, Any]]:
"""Get all vias on the board."""
raise NotImplementedError()
def get_nets(self) -> List[Dict[str, Any]]:
"""Get all nets on the board."""
raise NotImplementedError()
def get_selection(self) -> List[Dict[str, Any]]:
"""Get currently selected items."""
raise NotImplementedError()
class BackendError(Exception):