feat(common): add SaveDocument API and CLI command

This commit is contained in:
Milind Sharma 2026-02-20 18:21:38 +08:00
parent 7bd0313b30
commit 1a7c125316
4 changed files with 41 additions and 4 deletions

View File

@ -35,6 +35,7 @@ Deferred manual/runtime verification (implemented after 2026-02-20 while user un
- `GetKiCadBinaryPath`
- `GetPluginSettingsPath`
- `SaveDocument`
## KiCad v10 RC1.1 API Completion Matrix
@ -55,11 +56,11 @@ Legend:
| Section | Proto Commands | Implemented | Coverage |
| --- | ---: | ---: | ---: |
| Common (base) | 6 | 6 | 100% |
| Common editor/document | 23 | 15 | 65% |
| Common editor/document | 23 | 16 | 70% |
| Project manager | 5 | 3 | 60% |
| Board editor (PCB) | 22 | 20 | 91% |
| Schematic editor (dedicated proto commands) | 0 | 0 | n/a |
| **Total** | **56** | **44** | **79%** |
| **Total** | **56** | **45** | **80%** |
### Common (base)
@ -78,7 +79,7 @@ Legend:
| --- | --- | --- |
| `RefreshEditor` | Implemented | `KiCadClient::refresh_editor` |
| `GetOpenDocuments` | Implemented | `KiCadClient::get_open_documents`, `KiCadClient::get_current_project_path`, `KiCadClient::has_open_board` |
| `SaveDocument` | Not yet | - |
| `SaveDocument` | Implemented | `KiCadClient::save_document_raw`, `KiCadClient::save_document` |
| `SaveCopyOfDocument` | Not yet | - |
| `RevertDocument` | Not yet | - |
| `RunAction` | Not yet | - |

View File

@ -163,6 +163,12 @@ End a staged commit:
cargo run --bin kicad-ipc-cli -- --client-name write-test end-commit --id <commit-id> --action drop --message "cli test cleanup"
```
Save current board document:
```bash
cargo run --bin kicad-ipc-cli -- save-doc
```
Show summary of current PCB selection by item type:
```bash

View File

@ -80,6 +80,7 @@ const CMD_GET_ITEMS_BY_ID: &str = "kiapi.common.commands.GetItemsById";
const CMD_GET_BOUNDING_BOX: &str = "kiapi.common.commands.GetBoundingBox";
const CMD_HIT_TEST: &str = "kiapi.common.commands.HitTest";
const CMD_GET_TITLE_BLOCK_INFO: &str = "kiapi.common.commands.GetTitleBlockInfo";
const CMD_SAVE_DOCUMENT: &str = "kiapi.common.commands.SaveDocument";
const CMD_SAVE_DOCUMENT_TO_STRING: &str = "kiapi.common.commands.SaveDocumentToString";
const CMD_SAVE_SELECTION_TO_STRING: &str = "kiapi.common.commands.SaveSelectionToString";
@ -1374,6 +1375,22 @@ impl KiCadClient {
})
}
pub async fn save_document_raw(&self) -> Result<prost_types::Any, KiCadError> {
let command = common_commands::SaveDocument {
document: Some(self.current_board_document_proto().await?),
};
let response = self
.send_command(envelope::pack_any(&command, CMD_SAVE_DOCUMENT))
.await?;
response_payload_as_any(response, RES_PROTOBUF_EMPTY)
}
pub async fn save_document(&self) -> Result<(), KiCadError> {
let _ = self.save_document_raw().await?;
Ok(())
}
pub async fn get_board_as_string(&self) -> Result<String, KiCadError> {
let command = common_commands::SaveDocumentToString {
document: Some(self.current_board_document_proto().await?),

File diff suppressed because one or more lines are too long