kcaa 0.2.6__tar.gz → 0.2.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kcaa-0.2.6 → kcaa-0.2.8}/PKG-INFO +48 -11
- {kcaa-0.2.6 → kcaa-0.2.8}/README.md +47 -10
- {kcaa-0.2.6 → kcaa-0.2.8}/README_CN.md +1 -0
- kcaa-0.2.8/kcaa/router/__init__.py +20 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/router/grid_a_star.py +152 -23
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/router/path_postprocess.py +48 -1
- kcaa-0.2.8/kcaa/router/pns/__init__.py +15 -0
- kcaa-0.2.8/kcaa/router/pns/direction45.py +417 -0
- kcaa-0.2.8/kcaa/router/pns/node.py +118 -0
- kcaa-0.2.8/kcaa/router/pns/shove.py +792 -0
- kcaa-0.2.8/kcaa/router/pns/walkaround.py +485 -0
- kcaa-0.2.8/kcaa/router/route_engine.py +1683 -0
- kcaa-0.2.8/kcaa/router/router.py +4444 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/router/visibility_graph.py +118 -37
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/router/world_model.py +123 -20
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/server.py +6 -0
- kcaa-0.2.8/kcaa/tools/erc_tools.py +183 -0
- kcaa-0.2.8/kcaa/tools/no_connect_tools.py +221 -0
- kcaa-0.2.8/kcaa/tools/pcb_library_tools.py +1791 -0
- kcaa-0.2.8/kcaa/tools/pcb_routing_tools.py +1571 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/placement_helpers.py +4 -2
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/render_board_tools.py +117 -14
- kcaa-0.2.8/kcaa/tools/render_route_state.py +234 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/symbol_edit_tools.py +1325 -11
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/symbol_tools.py +129 -22
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/config.py +81 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/footprint_database.py +10 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/footprint_index_manager.py +25 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/fp_lib_table_utils.py +71 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/pcb_library_utils.py +12 -7
- kcaa-0.2.8/kcaa/utils/sym_lib_table_utils.py +205 -0
- kcaa-0.2.8/kcaa/utils/symbol_database.py +806 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/symbol_extractor.py +1 -1
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/symbol_index_manager.py +188 -30
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/symbol_index_reader.py +47 -14
- kcaa-0.2.8/kcaa/utils/symbol_library_utils.py +542 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/pyproject.toml +1 -1
- kcaa-0.2.6/kcaa/router/__init__.py +0 -16
- kcaa-0.2.6/kcaa/router/a_star.py +0 -166
- kcaa-0.2.6/kcaa/router/router.py +0 -2107
- kcaa-0.2.6/kcaa/tools/pcb_library_tools.py +0 -907
- kcaa-0.2.6/kcaa/tools/pcb_routing_tools.py +0 -605
- kcaa-0.2.6/kcaa/utils/symbol_database.py +0 -507
- {kcaa-0.2.6 → kcaa-0.2.8}/.gitignore +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/LICENSE +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/__init__.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/context.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/prompts/__init__.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/prompts/bom_prompts.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/prompts/drc_prompt.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/prompts/pattern_prompts.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/prompts/templates.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/resources/__init__.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/resources/bom_resources.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/resources/drc_resources.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/resources/files.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/resources/netlist_resources.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/resources/pattern_resources.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/resources/projects.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/router/via_check.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/__init__.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/analysis_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/bom_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/drc_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/export_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/kipy_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/netlist_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/pattern_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/pcb_edit_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/pcb_group_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/pcb_placement_helpers.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/pcb_placement_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/pcb_query_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/pcb_zone_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/project_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/schematic_group_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/sheet_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/skill_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/validation_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/version_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/tools/wire_edit_tools.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/__init__.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/boundary_validator.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/component_utils.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/file_utils.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/ipc_drc.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/kicad_api_detection.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/kicad_cli.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/kicad_utils.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/kipy_reload.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/net_settings.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/netlist_parser.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/path_validator.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/pattern_recognition.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/pcb_board_utils.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/pcb_design_rules.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/pcb_footprint_utils.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/pcb_sexp_utils.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/schematic_sexp_utils.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/secure_subprocess.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/skip_compat.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/skip_helpers.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/symbol_geometry.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/temp_dir_manager.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kcaa/utils/version_manager.py +0 -0
- {kcaa-0.2.6 → kcaa-0.2.8}/kicad_plugin/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: kcaa
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.8
|
|
4
4
|
Summary: Model Context Protocol (MCP) server for KiCad electronic design automation (EDA) files
|
|
5
5
|
Project-URL: Homepage, https://github.com/paul356/KiCad-AI-Assistant
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/paul356/KiCad-AI-Assistant/issues
|
|
@@ -52,7 +52,7 @@ Tested on **KiCad 10.0 / Linux & Windows**.
|
|
|
52
52
|
- [Table of Contents](#table-of-contents)
|
|
53
53
|
- [Prerequisites](#prerequisites)
|
|
54
54
|
- [Installation](#installation)
|
|
55
|
-
- [1. Clone the repository](#1-clone-the-repository)
|
|
55
|
+
- [1. Clone the repository (optional)](#1-clone-the-repository-optional)
|
|
56
56
|
- [2. Install the plugin](#2-install-the-plugin)
|
|
57
57
|
- [3. Create the plugin virtual environment](#3-create-the-plugin-virtual-environment)
|
|
58
58
|
- [4. Load the plugin in KiCad](#4-load-the-plugin-in-kicad)
|
|
@@ -71,8 +71,8 @@ Tested on **KiCad 10.0 / Linux & Windows**.
|
|
|
71
71
|
- [PCB Placement](#pcb-placement)
|
|
72
72
|
- [PCB Groups](#pcb-groups)
|
|
73
73
|
- [PCB Zones](#pcb-zones)
|
|
74
|
-
- [DRC
|
|
75
|
-
- [Versioning
|
|
74
|
+
- [DRC \& Design Rules](#drc--design-rules)
|
|
75
|
+
- [Versioning \& Export](#versioning--export)
|
|
76
76
|
- [Skill System](#skill-system)
|
|
77
77
|
- [KiCad IPC](#kicad-ipc)
|
|
78
78
|
- [Project Structure](#project-structure)
|
|
@@ -85,7 +85,7 @@ Tested on **KiCad 10.0 / Linux & Windows**.
|
|
|
85
85
|
- KiCad 10.0 or higher
|
|
86
86
|
- [`uv`](https://github.com/astral-sh/uv) — manages the Python virtual environment and installs the correct Python version automatically
|
|
87
87
|
- `curl -Lsf https://astral.sh/uv/install.sh | sh`
|
|
88
|
-
- An API key for OpenAI, Anthropic, or a compatible LLM provider
|
|
88
|
+
- An API key for OpenAI, Anthropic, Amazon Bedrock, or a compatible LLM provider (Ollama needs none)
|
|
89
89
|
|
|
90
90
|
## Installation
|
|
91
91
|
|
|
@@ -94,8 +94,8 @@ Tested on **KiCad 10.0 / Linux & Windows**.
|
|
|
94
94
|
Only needed if you want to build the plugin from source or contribute to the project. Skip this step if you're downloading the pre-built plugin from the Releases page.
|
|
95
95
|
|
|
96
96
|
```bash
|
|
97
|
-
git clone https://github.com/paul356/
|
|
98
|
-
cd
|
|
97
|
+
git clone https://github.com/paul356/KiCad-AI-Assistant.git
|
|
98
|
+
cd KiCad-AI-Assistant
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
### 2. Install the plugin
|
|
@@ -109,6 +109,13 @@ mkdir -p "$KICAD_PLUGIN_DIR"
|
|
|
109
109
|
unzip kicad_ai_assistant.zip -d "$KICAD_PLUGIN_DIR"
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
+
**macOS:**
|
|
113
|
+
```bash
|
|
114
|
+
KICAD_PLUGIN_DIR=~/Documents/KiCad/10.0/scripting/plugins
|
|
115
|
+
mkdir -p "$KICAD_PLUGIN_DIR"
|
|
116
|
+
unzip kicad_ai_assistant.zip -d "$KICAD_PLUGIN_DIR"
|
|
117
|
+
```
|
|
118
|
+
|
|
112
119
|
**Windows (PowerShell):**
|
|
113
120
|
```powershell
|
|
114
121
|
$KICAD_PLUGIN_DIR = "$env:USERPROFILE\Documents\KiCad\10.0\scripting\plugins"
|
|
@@ -126,6 +133,11 @@ make dist-plugin # produces dist/kicad_ai_assistant.zip
|
|
|
126
133
|
KICAD_PLUGIN_DIR=~/.local/share/kicad/10.0/scripting/plugins
|
|
127
134
|
mkdir -p "$KICAD_PLUGIN_DIR"
|
|
128
135
|
unzip dist/kicad_ai_assistant.zip -d "$KICAD_PLUGIN_DIR"
|
|
136
|
+
|
|
137
|
+
# macOS:
|
|
138
|
+
KICAD_PLUGIN_DIR=~/Documents/KiCad/10.0/scripting/plugins
|
|
139
|
+
mkdir -p "$KICAD_PLUGIN_DIR"
|
|
140
|
+
unzip dist/kicad_ai_assistant.zip -d "$KICAD_PLUGIN_DIR"
|
|
129
141
|
```
|
|
130
142
|
|
|
131
143
|
### 3. Create the plugin virtual environment
|
|
@@ -138,6 +150,12 @@ cd ~/.local/share/kicad/10.0/scripting/plugins/kicad_ai_assistant
|
|
|
138
150
|
./setup_plugin.sh
|
|
139
151
|
```
|
|
140
152
|
|
|
153
|
+
**macOS:**
|
|
154
|
+
```bash
|
|
155
|
+
cd ~/Documents/KiCad/10.0/scripting/plugins/kicad_ai_assistant
|
|
156
|
+
./setup_plugin.sh
|
|
157
|
+
```
|
|
158
|
+
|
|
141
159
|
**Windows (PowerShell):**
|
|
142
160
|
```powershell
|
|
143
161
|
cd "$env:USERPROFILE\Documents\KiCad\10.0\scripting\plugins\kicad_ai_assistant"
|
|
@@ -170,15 +188,29 @@ All settings can be changed through **Options → Settings** in the plugin panel
|
|
|
170
188
|
|
|
171
189
|
| Setting | Description | Default |
|
|
172
190
|
|---------|-------------|---------|
|
|
173
|
-
| `llm_provider` | LLM provider: `openai`, `anthropic`, or `
|
|
174
|
-
| `llm_api_key` | Your LLM API key (stored with owner-only permissions) | *(empty)* |
|
|
175
|
-
| `llm_model` | Model name | `gpt-4o` |
|
|
176
|
-
| `llm_base_url` | Custom endpoint URL (
|
|
191
|
+
| `llm_provider` | LLM provider: `openai`, `anthropic`, `ollama`, or `bedrock` | `openai` |
|
|
192
|
+
| `llm_api_key` | Your LLM API key (stored with owner-only permissions). For `bedrock`, a Bedrock API key used as a bearer token | *(empty)* |
|
|
193
|
+
| `llm_model` | Model name. For `bedrock`, a Bedrock model or inference-profile id — newer Claude models need the cross-region profile form, e.g. `us.anthropic.claude-opus-5-5` (swap `us.` for your region) | `gpt-4o` |
|
|
194
|
+
| `llm_base_url` | Custom endpoint URL (overrides the provider default) | *(provider default)* |
|
|
195
|
+
| `llm_aws_region` | AWS region for the Bedrock endpoint (also used for SigV4 signing) | `us-east-1` |
|
|
196
|
+
| `llm_aws_access_key_id` | AWS access key id — set this (plus the secret) to use SigV4 instead of a Bedrock API key | *(empty)* |
|
|
197
|
+
| `llm_aws_secret_access_key` | AWS secret access key for SigV4 auth | *(empty)* |
|
|
198
|
+
| `llm_aws_session_token` | Optional STS session token for temporary AWS credentials | *(empty)* |
|
|
177
199
|
| `server_port` | Fixed port for the built-in MCP server (`0` = auto) | `0` |
|
|
200
|
+
| `mcp_tool_timeout_seconds` | Per-call deadline (s) for MCP tool calls (e.g. PCB routing); longer calls end the turn with an explicit timeout error. Takes effect after the plugin restarts | `300` |
|
|
178
201
|
| `show_tool_log` | Show tool-call log panel by default | `true` |
|
|
179
202
|
| `llm_context_tokens` | Total context window size in tokens | `128000` |
|
|
180
203
|
| `llm_compact_threshold` | Trigger context compaction at this usage fraction | `0.70` |
|
|
181
204
|
|
|
205
|
+
### Amazon Bedrock
|
|
206
|
+
|
|
207
|
+
Bedrock requests go to the native Bedrock Runtime `InvokeModel` API (not the OpenAI-compatible endpoint, which only serves non-Claude models), using the Anthropic Messages format. Authentication is chosen automatically:
|
|
208
|
+
|
|
209
|
+
- **Bedrock API key** — leave the AWS credential fields blank and put the key in `llm_api_key`; it is sent as a bearer token.
|
|
210
|
+
- **AWS SigV4** — set `llm_aws_access_key_id` + `llm_aws_secret_access_key` (and optionally `llm_aws_session_token`); requests are signed with SigV4 for the configured `llm_aws_region`.
|
|
211
|
+
|
|
212
|
+
Use a model id enabled in your account/region — the cross-region inference-profile ids work well, e.g. `us.anthropic.claude-opus-5-5` or a versioned id like `us.anthropic.claude-sonnet-4-5-20250929-v1:0`. List yours with `aws bedrock list-inference-profiles --region <region>`. Responses are streamed to the chat panel in a single block, since Bedrock's streaming uses a binary framing the plugin's transport does not decode.
|
|
213
|
+
|
|
182
214
|
## Standalone MCP Server
|
|
183
215
|
|
|
184
216
|
You can also run `kcaa` as a standalone MCP server without the KiCad plugin. This is useful for integrating with other MCP clients (e.g., Claude Desktop, Cursor).
|
|
@@ -241,6 +273,7 @@ kcaa
|
|
|
241
273
|
| Tool | Description |
|
|
242
274
|
|------|-------------|
|
|
243
275
|
| `add_symbol_to_schematic` | Place a symbol on the schematic |
|
|
276
|
+
| `create_symbol` | Define a new symbol into a symbol library (definition only — no schematic placement) |
|
|
244
277
|
| `place_symbol_relative` | Place a symbol relative to an existing component |
|
|
245
278
|
| `remove_symbol_from_schematic` | Remove placed symbol by reference |
|
|
246
279
|
| `move_component` | Move and/or rotate a placed component |
|
|
@@ -256,6 +289,9 @@ kcaa
|
|
|
256
289
|
| `add_label_to_schematic` | Add a local net label |
|
|
257
290
|
| `list_labels_in_schematic` | List all local net labels |
|
|
258
291
|
| `delete_label_from_schematic` | Delete net labels |
|
|
292
|
+
| `add_no_connect` | Add a no-connect flag at a pin coordinate |
|
|
293
|
+
| `list_no_connects` | List all no-connect flags |
|
|
294
|
+
| `remove_no_connect` | Remove no-connect flag(s) by coordinate |
|
|
259
295
|
| `get_schematic_sheet_info` | Get drawing area, paper size, and grid |
|
|
260
296
|
| `find_free_area` | Find candidate areas for placing a block |
|
|
261
297
|
|
|
@@ -265,6 +301,7 @@ kcaa
|
|
|
265
301
|
|------|-------------|
|
|
266
302
|
| `extract_schematic_netlist` | Extract netlist from a schematic |
|
|
267
303
|
| `find_component_connections` | Find all connections for a component |
|
|
304
|
+
| `run_erc` | Run Electrical Rules Check (headless `kicad-cli`) and return violations |
|
|
268
305
|
| `identify_circuit_patterns` | Identify common circuit patterns |
|
|
269
306
|
| `validate_project` | Basic validation of a KiCad project |
|
|
270
307
|
| `validate_project_boundaries` | Validate component boundaries |
|
|
@@ -12,7 +12,7 @@ Tested on **KiCad 10.0 / Linux & Windows**.
|
|
|
12
12
|
- [Table of Contents](#table-of-contents)
|
|
13
13
|
- [Prerequisites](#prerequisites)
|
|
14
14
|
- [Installation](#installation)
|
|
15
|
-
- [1. Clone the repository](#1-clone-the-repository)
|
|
15
|
+
- [1. Clone the repository (optional)](#1-clone-the-repository-optional)
|
|
16
16
|
- [2. Install the plugin](#2-install-the-plugin)
|
|
17
17
|
- [3. Create the plugin virtual environment](#3-create-the-plugin-virtual-environment)
|
|
18
18
|
- [4. Load the plugin in KiCad](#4-load-the-plugin-in-kicad)
|
|
@@ -31,8 +31,8 @@ Tested on **KiCad 10.0 / Linux & Windows**.
|
|
|
31
31
|
- [PCB Placement](#pcb-placement)
|
|
32
32
|
- [PCB Groups](#pcb-groups)
|
|
33
33
|
- [PCB Zones](#pcb-zones)
|
|
34
|
-
- [DRC
|
|
35
|
-
- [Versioning
|
|
34
|
+
- [DRC \& Design Rules](#drc--design-rules)
|
|
35
|
+
- [Versioning \& Export](#versioning--export)
|
|
36
36
|
- [Skill System](#skill-system)
|
|
37
37
|
- [KiCad IPC](#kicad-ipc)
|
|
38
38
|
- [Project Structure](#project-structure)
|
|
@@ -45,7 +45,7 @@ Tested on **KiCad 10.0 / Linux & Windows**.
|
|
|
45
45
|
- KiCad 10.0 or higher
|
|
46
46
|
- [`uv`](https://github.com/astral-sh/uv) — manages the Python virtual environment and installs the correct Python version automatically
|
|
47
47
|
- `curl -Lsf https://astral.sh/uv/install.sh | sh`
|
|
48
|
-
- An API key for OpenAI, Anthropic, or a compatible LLM provider
|
|
48
|
+
- An API key for OpenAI, Anthropic, Amazon Bedrock, or a compatible LLM provider (Ollama needs none)
|
|
49
49
|
|
|
50
50
|
## Installation
|
|
51
51
|
|
|
@@ -54,8 +54,8 @@ Tested on **KiCad 10.0 / Linux & Windows**.
|
|
|
54
54
|
Only needed if you want to build the plugin from source or contribute to the project. Skip this step if you're downloading the pre-built plugin from the Releases page.
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
|
-
git clone https://github.com/paul356/
|
|
58
|
-
cd
|
|
57
|
+
git clone https://github.com/paul356/KiCad-AI-Assistant.git
|
|
58
|
+
cd KiCad-AI-Assistant
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
### 2. Install the plugin
|
|
@@ -69,6 +69,13 @@ mkdir -p "$KICAD_PLUGIN_DIR"
|
|
|
69
69
|
unzip kicad_ai_assistant.zip -d "$KICAD_PLUGIN_DIR"
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
**macOS:**
|
|
73
|
+
```bash
|
|
74
|
+
KICAD_PLUGIN_DIR=~/Documents/KiCad/10.0/scripting/plugins
|
|
75
|
+
mkdir -p "$KICAD_PLUGIN_DIR"
|
|
76
|
+
unzip kicad_ai_assistant.zip -d "$KICAD_PLUGIN_DIR"
|
|
77
|
+
```
|
|
78
|
+
|
|
72
79
|
**Windows (PowerShell):**
|
|
73
80
|
```powershell
|
|
74
81
|
$KICAD_PLUGIN_DIR = "$env:USERPROFILE\Documents\KiCad\10.0\scripting\plugins"
|
|
@@ -86,6 +93,11 @@ make dist-plugin # produces dist/kicad_ai_assistant.zip
|
|
|
86
93
|
KICAD_PLUGIN_DIR=~/.local/share/kicad/10.0/scripting/plugins
|
|
87
94
|
mkdir -p "$KICAD_PLUGIN_DIR"
|
|
88
95
|
unzip dist/kicad_ai_assistant.zip -d "$KICAD_PLUGIN_DIR"
|
|
96
|
+
|
|
97
|
+
# macOS:
|
|
98
|
+
KICAD_PLUGIN_DIR=~/Documents/KiCad/10.0/scripting/plugins
|
|
99
|
+
mkdir -p "$KICAD_PLUGIN_DIR"
|
|
100
|
+
unzip dist/kicad_ai_assistant.zip -d "$KICAD_PLUGIN_DIR"
|
|
89
101
|
```
|
|
90
102
|
|
|
91
103
|
### 3. Create the plugin virtual environment
|
|
@@ -98,6 +110,12 @@ cd ~/.local/share/kicad/10.0/scripting/plugins/kicad_ai_assistant
|
|
|
98
110
|
./setup_plugin.sh
|
|
99
111
|
```
|
|
100
112
|
|
|
113
|
+
**macOS:**
|
|
114
|
+
```bash
|
|
115
|
+
cd ~/Documents/KiCad/10.0/scripting/plugins/kicad_ai_assistant
|
|
116
|
+
./setup_plugin.sh
|
|
117
|
+
```
|
|
118
|
+
|
|
101
119
|
**Windows (PowerShell):**
|
|
102
120
|
```powershell
|
|
103
121
|
cd "$env:USERPROFILE\Documents\KiCad\10.0\scripting\plugins\kicad_ai_assistant"
|
|
@@ -130,15 +148,29 @@ All settings can be changed through **Options → Settings** in the plugin panel
|
|
|
130
148
|
|
|
131
149
|
| Setting | Description | Default |
|
|
132
150
|
|---------|-------------|---------|
|
|
133
|
-
| `llm_provider` | LLM provider: `openai`, `anthropic`, or `
|
|
134
|
-
| `llm_api_key` | Your LLM API key (stored with owner-only permissions) | *(empty)* |
|
|
135
|
-
| `llm_model` | Model name | `gpt-4o` |
|
|
136
|
-
| `llm_base_url` | Custom endpoint URL (
|
|
151
|
+
| `llm_provider` | LLM provider: `openai`, `anthropic`, `ollama`, or `bedrock` | `openai` |
|
|
152
|
+
| `llm_api_key` | Your LLM API key (stored with owner-only permissions). For `bedrock`, a Bedrock API key used as a bearer token | *(empty)* |
|
|
153
|
+
| `llm_model` | Model name. For `bedrock`, a Bedrock model or inference-profile id — newer Claude models need the cross-region profile form, e.g. `us.anthropic.claude-opus-5-5` (swap `us.` for your region) | `gpt-4o` |
|
|
154
|
+
| `llm_base_url` | Custom endpoint URL (overrides the provider default) | *(provider default)* |
|
|
155
|
+
| `llm_aws_region` | AWS region for the Bedrock endpoint (also used for SigV4 signing) | `us-east-1` |
|
|
156
|
+
| `llm_aws_access_key_id` | AWS access key id — set this (plus the secret) to use SigV4 instead of a Bedrock API key | *(empty)* |
|
|
157
|
+
| `llm_aws_secret_access_key` | AWS secret access key for SigV4 auth | *(empty)* |
|
|
158
|
+
| `llm_aws_session_token` | Optional STS session token for temporary AWS credentials | *(empty)* |
|
|
137
159
|
| `server_port` | Fixed port for the built-in MCP server (`0` = auto) | `0` |
|
|
160
|
+
| `mcp_tool_timeout_seconds` | Per-call deadline (s) for MCP tool calls (e.g. PCB routing); longer calls end the turn with an explicit timeout error. Takes effect after the plugin restarts | `300` |
|
|
138
161
|
| `show_tool_log` | Show tool-call log panel by default | `true` |
|
|
139
162
|
| `llm_context_tokens` | Total context window size in tokens | `128000` |
|
|
140
163
|
| `llm_compact_threshold` | Trigger context compaction at this usage fraction | `0.70` |
|
|
141
164
|
|
|
165
|
+
### Amazon Bedrock
|
|
166
|
+
|
|
167
|
+
Bedrock requests go to the native Bedrock Runtime `InvokeModel` API (not the OpenAI-compatible endpoint, which only serves non-Claude models), using the Anthropic Messages format. Authentication is chosen automatically:
|
|
168
|
+
|
|
169
|
+
- **Bedrock API key** — leave the AWS credential fields blank and put the key in `llm_api_key`; it is sent as a bearer token.
|
|
170
|
+
- **AWS SigV4** — set `llm_aws_access_key_id` + `llm_aws_secret_access_key` (and optionally `llm_aws_session_token`); requests are signed with SigV4 for the configured `llm_aws_region`.
|
|
171
|
+
|
|
172
|
+
Use a model id enabled in your account/region — the cross-region inference-profile ids work well, e.g. `us.anthropic.claude-opus-5-5` or a versioned id like `us.anthropic.claude-sonnet-4-5-20250929-v1:0`. List yours with `aws bedrock list-inference-profiles --region <region>`. Responses are streamed to the chat panel in a single block, since Bedrock's streaming uses a binary framing the plugin's transport does not decode.
|
|
173
|
+
|
|
142
174
|
## Standalone MCP Server
|
|
143
175
|
|
|
144
176
|
You can also run `kcaa` as a standalone MCP server without the KiCad plugin. This is useful for integrating with other MCP clients (e.g., Claude Desktop, Cursor).
|
|
@@ -201,6 +233,7 @@ kcaa
|
|
|
201
233
|
| Tool | Description |
|
|
202
234
|
|------|-------------|
|
|
203
235
|
| `add_symbol_to_schematic` | Place a symbol on the schematic |
|
|
236
|
+
| `create_symbol` | Define a new symbol into a symbol library (definition only — no schematic placement) |
|
|
204
237
|
| `place_symbol_relative` | Place a symbol relative to an existing component |
|
|
205
238
|
| `remove_symbol_from_schematic` | Remove placed symbol by reference |
|
|
206
239
|
| `move_component` | Move and/or rotate a placed component |
|
|
@@ -216,6 +249,9 @@ kcaa
|
|
|
216
249
|
| `add_label_to_schematic` | Add a local net label |
|
|
217
250
|
| `list_labels_in_schematic` | List all local net labels |
|
|
218
251
|
| `delete_label_from_schematic` | Delete net labels |
|
|
252
|
+
| `add_no_connect` | Add a no-connect flag at a pin coordinate |
|
|
253
|
+
| `list_no_connects` | List all no-connect flags |
|
|
254
|
+
| `remove_no_connect` | Remove no-connect flag(s) by coordinate |
|
|
219
255
|
| `get_schematic_sheet_info` | Get drawing area, paper size, and grid |
|
|
220
256
|
| `find_free_area` | Find candidate areas for placing a block |
|
|
221
257
|
|
|
@@ -225,6 +261,7 @@ kcaa
|
|
|
225
261
|
|------|-------------|
|
|
226
262
|
| `extract_schematic_netlist` | Extract netlist from a schematic |
|
|
227
263
|
| `find_component_connections` | Find all connections for a component |
|
|
264
|
+
| `run_erc` | Run Electrical Rules Check (headless `kicad-cli`) and return violations |
|
|
228
265
|
| `identify_circuit_patterns` | Identify common circuit patterns |
|
|
229
266
|
| `validate_project` | Basic validation of a KiCad project |
|
|
230
267
|
| `validate_project_boundaries` | Validate component boundaries |
|
|
@@ -134,6 +134,7 @@ setup_plugin.bat
|
|
|
134
134
|
| `llm_model` | 模型名称 | `gpt-4o` |
|
|
135
135
|
| `llm_base_url` | 自定义接口地址(`llm_provider` 为 `custom` 时使用) | *(使用提供商默认值)* |
|
|
136
136
|
| `server_port` | 内置 MCP 服务器固定端口(`0` = 自动选择) | `0` |
|
|
137
|
+
| `mcp_tool_timeout_seconds` | MCP 工具调用的单次超时(秒);超过后本轮对话以明确的超时错误结束。重启插件后生效 | `300` |
|
|
137
138
|
| `show_tool_log` | 默认显示工具调用日志面板 | `true` |
|
|
138
139
|
| `llm_context_tokens` | LLM 上下文窗口总 token 数 | `128000` |
|
|
139
140
|
| `llm_compact_threshold` | 上下文使用率超过此比例时触发压缩 | `0.70` |
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PCB routing algorithm library for the KiCad MCP server.
|
|
3
|
+
|
|
4
|
+
Implements a simplified version of KiCad's PNS (Push and Shove) router.
|
|
5
|
+
Given a start pad and an end pad on the same net, the router produces a
|
|
6
|
+
DRC-clean sequence of ``segment`` and ``via`` S-expression nodes that
|
|
7
|
+
connect them while avoiding obstacles: the route walks around fixed
|
|
8
|
+
solids and shoves movable tracks out of the way. Single-layer and
|
|
9
|
+
multi-layer routes emit straight 0/45/90 segments — corner mode is
|
|
10
|
+
fixed (mitered45); the sole exception is a cocircular waypoint chain,
|
|
11
|
+
which emits one covering arc. Disturbed legs and via junctions
|
|
12
|
+
themselves stay straight segments.
|
|
13
|
+
|
|
14
|
+
Module map:
|
|
15
|
+
|
|
16
|
+
* :mod:`kcaa.router.world_model` — PCB → obstacle list
|
|
17
|
+
* :mod:`kcaa.router.visibility_graph` — Obstacles → visibility graph
|
|
18
|
+
* :mod:`kcaa.router.path_postprocess` — Miter corners, segment emission
|
|
19
|
+
* :mod:`kcaa.router.router` — Orchestration / public API
|
|
20
|
+
"""
|
|
@@ -33,7 +33,7 @@ from dataclasses import dataclass
|
|
|
33
33
|
import heapq
|
|
34
34
|
import math
|
|
35
35
|
|
|
36
|
-
from shapely.geometry import LineString, Point
|
|
36
|
+
from shapely.geometry import LineString, Point, box
|
|
37
37
|
|
|
38
38
|
# Grid resolution (mm per cell).
|
|
39
39
|
# 0.1 mm is a good balance: it captures fine-pitch pin gaps (~0.5 mm → 5 cells)
|
|
@@ -97,19 +97,42 @@ class GridMap:
|
|
|
97
97
|
origin_y: float
|
|
98
98
|
blocked: list[bool]
|
|
99
99
|
|
|
100
|
+
# ``True`` for cells blocked because their centre lies outside the
|
|
101
|
+
# board fence (``build_grid_map(fence_bbox=...)``), as opposed to
|
|
102
|
+
# obstacle coverage. ``None`` when no fence was applied.
|
|
103
|
+
# ``grid_a_star`` relocates A* anchors that land on fence-blocked
|
|
104
|
+
# cells (an edge-connector pad may straddle the outline) but keeps
|
|
105
|
+
# obstacle-blocked anchors failing the search.
|
|
106
|
+
fence_blocked: list[bool] | None = None
|
|
107
|
+
|
|
100
108
|
# ── coordinate helpers ──────────────────────────────────────────
|
|
101
109
|
|
|
102
110
|
def to_grid(self, x: float, y: float) -> tuple[int, int]:
|
|
103
|
-
"""World coordinate → (col, row).
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
"""World coordinate → (col, row).
|
|
112
|
+
|
|
113
|
+
Cell ``g``'s centre is at ``origin + (g + 0.5) * resolution``
|
|
114
|
+
(see :meth:`to_world`), so the inverse mapping subtracts half a
|
|
115
|
+
cell before rounding: ``round((x - origin) / res - 0.5)`` picks
|
|
116
|
+
the cell whose centre is nearest, and ``to_grid(to_world(g))``
|
|
117
|
+
round-trips exactly.
|
|
118
|
+
"""
|
|
119
|
+
gx = round((x - self.origin_x) / self.resolution - 0.5)
|
|
120
|
+
gy = round((y - self.origin_y) / self.resolution - 0.5)
|
|
106
121
|
return int(gx), int(gy)
|
|
107
122
|
|
|
108
123
|
def to_world(self, gx: int, gy: int) -> tuple[float, float]:
|
|
109
|
-
"""(col, row) → world coordinate (cell centre).
|
|
124
|
+
"""(col, row) → world coordinate (cell centre).
|
|
125
|
+
|
|
126
|
+
Rasterisation marks a cell blocked by testing the cell's centre
|
|
127
|
+
against obstacle polygons; A* walks cell centres, so the path
|
|
128
|
+
output must be the same cell centres (not the corner). A path
|
|
129
|
+
built from corners sits ``resolution / 2`` closer to every
|
|
130
|
+
obstacle than the grid promised, which passes the grid check and
|
|
131
|
+
then fails the true clearance audit.
|
|
132
|
+
"""
|
|
110
133
|
return (
|
|
111
|
-
gx * self.resolution + self.origin_x,
|
|
112
|
-
gy * self.resolution + self.origin_y,
|
|
134
|
+
(gx + 0.5) * self.resolution + self.origin_x,
|
|
135
|
+
(gy + 0.5) * self.resolution + self.origin_y,
|
|
113
136
|
)
|
|
114
137
|
|
|
115
138
|
def in_bounds(self, gx: int, gy: int) -> bool:
|
|
@@ -135,13 +158,24 @@ def build_grid_map(
|
|
|
135
158
|
board_bbox: tuple[float, float, float, float] | None,
|
|
136
159
|
resolution: float = GRID_RESOLUTION,
|
|
137
160
|
margin: float = 2.0,
|
|
161
|
+
fence_bbox: tuple[float, float, float, float] | None = None,
|
|
138
162
|
) -> GridMap:
|
|
139
163
|
"""Rasterise *obstacles* onto a uniform grid.
|
|
140
164
|
|
|
141
165
|
Each obstacle is a ``shapely`` Polygon stored as the ``.shape``
|
|
142
166
|
attribute of whatever object is in the list (typically
|
|
143
167
|
:class:`~kcaa.router.world_model.Obstacle`). A cell is BLOCKED if
|
|
144
|
-
its
|
|
168
|
+
its square footprint intersects **any** obstacle shape.
|
|
169
|
+
|
|
170
|
+
When ``fence_bbox`` is given, cells whose centre lies **outside** it
|
|
171
|
+
are also blocked: the search can never step past the fence even
|
|
172
|
+
though the grid extent (and margin) covers it. The router passes the
|
|
173
|
+
board's Edge.Cuts bbox here so A* cannot wander into the margin
|
|
174
|
+
around the board and emit an out-of-board first segment. The fence
|
|
175
|
+
uses the cell centre, so an edge-connector pad whose centre sits on
|
|
176
|
+
the outline keeps a free terminus cell (pad copper is a legal
|
|
177
|
+
endpoint, exempted elsewhere); the segment-level board check still
|
|
178
|
+
verifies the copper stays inside.
|
|
145
179
|
|
|
146
180
|
Args:
|
|
147
181
|
obstacles: Iterable of objects with a ``.shape`` (``Polygon``).
|
|
@@ -149,6 +183,8 @@ def build_grid_map(
|
|
|
149
183
|
When ``None`` a 100×100 mm area is assumed.
|
|
150
184
|
resolution: Grid cell size in mm.
|
|
151
185
|
margin: Extra space (mm) around the board bbox.
|
|
186
|
+
fence_bbox: Optional ``(min_x, min_y, max_x, max_y)`` restricting
|
|
187
|
+
free cells to its interior (default: no restriction).
|
|
152
188
|
|
|
153
189
|
Returns:
|
|
154
190
|
A populated :class:`GridMap`.
|
|
@@ -175,18 +211,14 @@ def build_grid_map(
|
|
|
175
211
|
s = getattr(obs, "shape", obs)
|
|
176
212
|
if s is not None and not s.is_empty:
|
|
177
213
|
shapes.append(s)
|
|
178
|
-
if not shapes:
|
|
179
|
-
return GridMap(
|
|
180
|
-
width=width,
|
|
181
|
-
height=height,
|
|
182
|
-
resolution=resolution,
|
|
183
|
-
origin_x=origin_x,
|
|
184
|
-
origin_y=origin_y,
|
|
185
|
-
blocked=blocked,
|
|
186
|
-
)
|
|
187
214
|
|
|
188
215
|
# Rasterise: iterate over each obstacle's bounding box and mark
|
|
189
|
-
# cells whose
|
|
216
|
+
# cells whose square footprint intersects the obstacle polygon.
|
|
217
|
+
# A centre-point test would let an 8-direction diagonal segment cross
|
|
218
|
+
# an obstacle corner (cells on both sides free, the segment between
|
|
219
|
+
# them clips the corner) and pass the grid check only to fail the
|
|
220
|
+
# true clearance audit. The cell-square test blocks any cell the
|
|
221
|
+
# obstacle touches, so every walked segment keeps its promised gap.
|
|
190
222
|
for shp in shapes:
|
|
191
223
|
bxmin, bymin, bxmax, bymax = shp.bounds
|
|
192
224
|
gx0 = max(0, int(math.floor((bxmin - origin_x) / resolution)))
|
|
@@ -200,9 +232,34 @@ def build_grid_map(
|
|
|
200
232
|
if blocked[gy * width + gx]:
|
|
201
233
|
continue
|
|
202
234
|
wx = gx * resolution + origin_x + resolution / 2
|
|
203
|
-
|
|
235
|
+
cell = box(
|
|
236
|
+
wx - resolution / 2,
|
|
237
|
+
cy - resolution / 2,
|
|
238
|
+
wx + resolution / 2,
|
|
239
|
+
cy + resolution / 2,
|
|
240
|
+
)
|
|
241
|
+
if shp.intersects(cell):
|
|
204
242
|
blocked[gy * width + gx] = True
|
|
205
243
|
|
|
244
|
+
# Board fence: block every cell whose centre is outside fence_bbox.
|
|
245
|
+
fence_blocked: list[bool] | None = None
|
|
246
|
+
if fence_bbox is not None:
|
|
247
|
+
fence_blocked = [False] * (width * height)
|
|
248
|
+
fmin_x, fmin_y, fmax_x, fmax_y = fence_bbox
|
|
249
|
+
for gy in range(height):
|
|
250
|
+
cy = gy * resolution + origin_y + resolution / 2
|
|
251
|
+
if cy < fmin_y or cy > fmax_y:
|
|
252
|
+
row = gy * width
|
|
253
|
+
for gx in range(width):
|
|
254
|
+
blocked[row + gx] = True
|
|
255
|
+
fence_blocked[row + gx] = True
|
|
256
|
+
continue
|
|
257
|
+
for gx in range(width):
|
|
258
|
+
wx = gx * resolution + origin_x + resolution / 2
|
|
259
|
+
if wx < fmin_x or wx > fmax_x:
|
|
260
|
+
blocked[gy * width + gx] = True
|
|
261
|
+
fence_blocked[gy * width + gx] = True
|
|
262
|
+
|
|
206
263
|
return GridMap(
|
|
207
264
|
width=width,
|
|
208
265
|
height=height,
|
|
@@ -210,6 +267,7 @@ def build_grid_map(
|
|
|
210
267
|
origin_x=origin_x,
|
|
211
268
|
origin_y=origin_y,
|
|
212
269
|
blocked=blocked,
|
|
270
|
+
fence_blocked=fence_blocked,
|
|
213
271
|
)
|
|
214
272
|
|
|
215
273
|
|
|
@@ -244,6 +302,55 @@ def _octile_dist(gx: int, gy: int, ex: int, ey: int) -> float:
|
|
|
244
302
|
return _DIAG_COST * dx + (dy - dx)
|
|
245
303
|
|
|
246
304
|
|
|
305
|
+
# How far an A* start/end anchor may be relocated (in cells) to reach the
|
|
306
|
+
# nearest walkable cell. 10 cells = 1 mm at the default 0.1 mm resolution:
|
|
307
|
+
# enough to absorb an edge-connector pad whose centre sits exactly on (or
|
|
308
|
+
# marginally outside) the Edge.Cuts line, while a pad that is truly beyond
|
|
309
|
+
# the board still fails the search instead of being rescued from far away.
|
|
310
|
+
_RELOCATE_RADIUS_CELLS = 10
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def _nearest_free_cell(
|
|
314
|
+
gx: int,
|
|
315
|
+
gy: int,
|
|
316
|
+
grid: GridMap,
|
|
317
|
+
max_radius: int = _RELOCATE_RADIUS_CELLS,
|
|
318
|
+
) -> tuple[int, int]:
|
|
319
|
+
"""Return the closest free cell to ``(gx, gy)`` within ``max_radius``.
|
|
320
|
+
|
|
321
|
+
The closest cell is found by expanding square rings outward, so the
|
|
322
|
+
result is deterministic. Falls back to the original cell when no
|
|
323
|
+
free cell exists in range — the caller's ``is_free`` guard then
|
|
324
|
+
fails the search with ``path=None``.
|
|
325
|
+
"""
|
|
326
|
+
if grid.is_free(gx, gy):
|
|
327
|
+
return gx, gy
|
|
328
|
+
for r in range(1, max_radius + 1):
|
|
329
|
+
for dy in range(-r, r + 1):
|
|
330
|
+
for dx in range(-r, r + 1):
|
|
331
|
+
if abs(dx) != r and abs(dy) != r:
|
|
332
|
+
continue # ring only, not the already-visited interior
|
|
333
|
+
nx, ny = gx + dx, gy + dy
|
|
334
|
+
if grid.in_bounds(nx, ny) and grid.is_free(nx, ny):
|
|
335
|
+
return nx, ny
|
|
336
|
+
return gx, gy
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def _clamp_to_walkable(gx: int, gy: int, grid: GridMap) -> tuple[int, int]:
|
|
340
|
+
"""Relocate an A* anchor blocked by the board fence to a free cell.
|
|
341
|
+
|
|
342
|
+
A start/end on a *fence*-blocked cell (outside the Edge.Cuts outline)
|
|
343
|
+
moves to the nearest free cell — an edge-connector pad may straddle
|
|
344
|
+
the outline. An anchor blocked by a real obstacle stays put, so the
|
|
345
|
+
search fails as before instead of silently bypassing a keepout.
|
|
346
|
+
"""
|
|
347
|
+
if grid.is_free(gx, gy):
|
|
348
|
+
return gx, gy
|
|
349
|
+
if grid.fence_blocked is not None and grid.fence_blocked[gy * grid.width + gx]:
|
|
350
|
+
return _nearest_free_cell(gx, gy, grid)
|
|
351
|
+
return gx, gy
|
|
352
|
+
|
|
353
|
+
|
|
247
354
|
def grid_a_star(
|
|
248
355
|
grids: list[GridMap],
|
|
249
356
|
start_world: tuple[float, float],
|
|
@@ -296,6 +403,18 @@ def grid_a_star(
|
|
|
296
403
|
ex = max(0, min(W - 1, ex))
|
|
297
404
|
ey = max(0, min(H - 1, ey))
|
|
298
405
|
|
|
406
|
+
# Clamp to the nearest walkable cell. An anchor that lands on a
|
|
407
|
+
# fence-blocked cell (board margin — e.g. an edge-connector pad whose
|
|
408
|
+
# centre sits on the Edge.Cuts line) moves to the closest free cell
|
|
409
|
+
# so the search still finds the board interior; the router
|
|
410
|
+
# post-process re-anchors the route onto the exact pad centres
|
|
411
|
+
# afterwards. Anchors blocked by a real obstacle keep their cell and
|
|
412
|
+
# fail the search (no silent bypass of keepouts). When no free cell
|
|
413
|
+
# exists nearby, the clamped cell is kept and the is_free guards
|
|
414
|
+
# below fail the search.
|
|
415
|
+
sx, sy = _clamp_to_walkable(sx, sy, grids[start_layer_idx])
|
|
416
|
+
ex, ey = _clamp_to_walkable(ex, ey, grids[end_layer_idx])
|
|
417
|
+
|
|
299
418
|
if not grids[start_layer_idx].is_free(sx, sy):
|
|
300
419
|
return AStarResult(path=None)
|
|
301
420
|
if not grids[end_layer_idx].is_free(ex, ey):
|
|
@@ -455,6 +574,7 @@ def hierarchical_a_star(
|
|
|
455
574
|
fine_resolution: float = GRID_RESOLUTION,
|
|
456
575
|
route_bbox: tuple[float, float, float, float] | None = None,
|
|
457
576
|
turn_penalty: float = _TURN_PENALTY,
|
|
577
|
+
fence_bbox: tuple[float, float, float, float] | None = None,
|
|
458
578
|
) -> AStarResult:
|
|
459
579
|
"""Run hierarchical A* with auto-detection of single-pass vs two-pass.
|
|
460
580
|
|
|
@@ -468,6 +588,10 @@ def hierarchical_a_star(
|
|
|
468
588
|
end_world: ``(x, y)`` in mm.
|
|
469
589
|
fine_resolution: Grid cell size in mm for the fine pass.
|
|
470
590
|
route_bbox: ``(min_x, min_y, max_x, max_y)`` of the route area.
|
|
591
|
+
turn_penalty: Turn-penalty distance equivalent (mm).
|
|
592
|
+
fence_bbox: Optional board bbox; cells outside it are blocked in
|
|
593
|
+
every pass (including the fine band, which may extend past
|
|
594
|
+
the board), so the search cannot step outside the board.
|
|
471
595
|
|
|
472
596
|
Returns:
|
|
473
597
|
:class:`AStarResult`.
|
|
@@ -489,11 +613,11 @@ def hierarchical_a_star(
|
|
|
489
613
|
fine_cells = int(math.ceil(bw / fine_resolution)) * int(math.ceil(bh / fine_resolution))
|
|
490
614
|
|
|
491
615
|
if fine_cells < _SINGLE_PASS_THRESHOLD:
|
|
492
|
-
grid = build_grid_map(obstacles, bbox, resolution=fine_resolution)
|
|
616
|
+
grid = build_grid_map(obstacles, bbox, resolution=fine_resolution, fence_bbox=fence_bbox)
|
|
493
617
|
return grid_a_star([grid], start_world, end_world, turn_penalty=turn_penalty)
|
|
494
618
|
|
|
495
619
|
coarse_res = fine_resolution * COARSE_FACTOR
|
|
496
|
-
coarse_grid = build_grid_map(obstacles, bbox, resolution=coarse_res)
|
|
620
|
+
coarse_grid = build_grid_map(obstacles, bbox, resolution=coarse_res, fence_bbox=fence_bbox)
|
|
497
621
|
coarse_result = grid_a_star([coarse_grid], start_world, end_world, turn_penalty=turn_penalty)
|
|
498
622
|
if coarse_result.path is None:
|
|
499
623
|
return AStarResult(path=None, cells_visited=coarse_result.cells_visited)
|
|
@@ -509,7 +633,7 @@ def hierarchical_a_star(
|
|
|
509
633
|
min(bbox[3], band[3]),
|
|
510
634
|
)
|
|
511
635
|
|
|
512
|
-
fine_grid = build_grid_map(obstacles, band, resolution=fine_resolution)
|
|
636
|
+
fine_grid = build_grid_map(obstacles, band, resolution=fine_resolution, fence_bbox=fence_bbox)
|
|
513
637
|
result = grid_a_star([fine_grid], start_world, end_world, turn_penalty=turn_penalty)
|
|
514
638
|
if result.path is not None:
|
|
515
639
|
result.cells_visited += coarse_result.cells_visited
|
|
@@ -569,6 +693,7 @@ def multi_layer_a_star(
|
|
|
569
693
|
via_cost: float = _VIA_COST,
|
|
570
694
|
via_forbidden_zones: list | None = None,
|
|
571
695
|
turn_penalty: float = _TURN_PENALTY,
|
|
696
|
+
fence_bbox: tuple[float, float, float, float] | None = None,
|
|
572
697
|
) -> MultiLayerAStarResult:
|
|
573
698
|
"""Run A* across multiple copper layers.
|
|
574
699
|
|
|
@@ -587,6 +712,8 @@ def multi_layer_a_star(
|
|
|
587
712
|
via_cost: Distance-equivalent cost per via transition.
|
|
588
713
|
via_forbidden_zones: ``shapely`` Polygon list where vias are
|
|
589
714
|
forbidden (e.g. start/end pad AABBs).
|
|
715
|
+
fence_bbox: Optional board bbox; cells outside it are blocked on
|
|
716
|
+
every layer grid.
|
|
590
717
|
|
|
591
718
|
Returns:
|
|
592
719
|
:class:`MultiLayerAStarResult`.
|
|
@@ -598,7 +725,9 @@ def multi_layer_a_star(
|
|
|
598
725
|
grids_list: list[GridMap] = []
|
|
599
726
|
for layer in layers:
|
|
600
727
|
obs = obstacles_by_layer.get(layer, [])
|
|
601
|
-
grids_list.append(
|
|
728
|
+
grids_list.append(
|
|
729
|
+
build_grid_map(obs, route_bbox, resolution=fine_resolution, fence_bbox=fence_bbox)
|
|
730
|
+
)
|
|
602
731
|
|
|
603
732
|
# Build via adjacency index.
|
|
604
733
|
via_from: dict[int, set[int]] = {}
|