feat(common): add RevertDocument API and CLI command

This commit is contained in:
Milind Sharma 2026-02-20 18:25:23 +08:00
parent 14856ec9d6
commit e03bc9ab89
4 changed files with 41 additions and 4 deletions

View File

@ -37,6 +37,7 @@ Deferred manual/runtime verification (implemented after 2026-02-20 while user un
- `GetPluginSettingsPath` - `GetPluginSettingsPath`
- `SaveDocument` - `SaveDocument`
- `SaveCopyOfDocument` - `SaveCopyOfDocument`
- `RevertDocument`
## KiCad v10 RC1.1 API Completion Matrix ## KiCad v10 RC1.1 API Completion Matrix
@ -57,11 +58,11 @@ Legend:
| Section | Proto Commands | Implemented | Coverage | | Section | Proto Commands | Implemented | Coverage |
| --- | ---: | ---: | ---: | | --- | ---: | ---: | ---: |
| Common (base) | 6 | 6 | 100% | | Common (base) | 6 | 6 | 100% |
| Common editor/document | 23 | 17 | 74% | | Common editor/document | 23 | 18 | 78% |
| Project manager | 5 | 3 | 60% | | Project manager | 5 | 3 | 60% |
| Board editor (PCB) | 22 | 20 | 91% | | Board editor (PCB) | 22 | 20 | 91% |
| Schematic editor (dedicated proto commands) | 0 | 0 | n/a | | Schematic editor (dedicated proto commands) | 0 | 0 | n/a |
| **Total** | **56** | **46** | **82%** | | **Total** | **56** | **47** | **84%** |
### Common (base) ### Common (base)
@ -82,7 +83,7 @@ Legend:
| `GetOpenDocuments` | Implemented | `KiCadClient::get_open_documents`, `KiCadClient::get_current_project_path`, `KiCadClient::has_open_board` | | `GetOpenDocuments` | Implemented | `KiCadClient::get_open_documents`, `KiCadClient::get_current_project_path`, `KiCadClient::has_open_board` |
| `SaveDocument` | Implemented | `KiCadClient::save_document_raw`, `KiCadClient::save_document` | | `SaveDocument` | Implemented | `KiCadClient::save_document_raw`, `KiCadClient::save_document` |
| `SaveCopyOfDocument` | Implemented | `KiCadClient::save_copy_of_document_raw`, `KiCadClient::save_copy_of_document` | | `SaveCopyOfDocument` | Implemented | `KiCadClient::save_copy_of_document_raw`, `KiCadClient::save_copy_of_document` |
| `RevertDocument` | Not yet | - | | `RevertDocument` | Implemented | `KiCadClient::revert_document_raw`, `KiCadClient::revert_document` |
| `RunAction` | Not yet | - | | `RunAction` | Not yet | - |
| `BeginCommit` | Implemented | `KiCadClient::begin_commit_raw`, `KiCadClient::begin_commit` | | `BeginCommit` | Implemented | `KiCadClient::begin_commit_raw`, `KiCadClient::begin_commit` |
| `EndCommit` | Implemented | `KiCadClient::end_commit_raw`, `KiCadClient::end_commit` | | `EndCommit` | Implemented | `KiCadClient::end_commit_raw`, `KiCadClient::end_commit` |

View File

@ -175,6 +175,12 @@ Save a copy of current board document:
cargo run --bin kicad-ipc-cli -- save-copy --path /tmp/example.kicad_pcb --overwrite --include-project cargo run --bin kicad-ipc-cli -- save-copy --path /tmp/example.kicad_pcb --overwrite --include-project
``` ```
Revert current board document from disk:
```bash
cargo run --bin kicad-ipc-cli -- revert-doc
```
Show summary of current PCB selection by item type: Show summary of current PCB selection by item type:
```bash ```bash

View File

@ -82,6 +82,7 @@ const CMD_HIT_TEST: &str = "kiapi.common.commands.HitTest";
const CMD_GET_TITLE_BLOCK_INFO: &str = "kiapi.common.commands.GetTitleBlockInfo"; const CMD_GET_TITLE_BLOCK_INFO: &str = "kiapi.common.commands.GetTitleBlockInfo";
const CMD_SAVE_DOCUMENT: &str = "kiapi.common.commands.SaveDocument"; const CMD_SAVE_DOCUMENT: &str = "kiapi.common.commands.SaveDocument";
const CMD_SAVE_COPY_OF_DOCUMENT: &str = "kiapi.common.commands.SaveCopyOfDocument"; const CMD_SAVE_COPY_OF_DOCUMENT: &str = "kiapi.common.commands.SaveCopyOfDocument";
const CMD_REVERT_DOCUMENT: &str = "kiapi.common.commands.RevertDocument";
const CMD_SAVE_DOCUMENT_TO_STRING: &str = "kiapi.common.commands.SaveDocumentToString"; const CMD_SAVE_DOCUMENT_TO_STRING: &str = "kiapi.common.commands.SaveDocumentToString";
const CMD_SAVE_SELECTION_TO_STRING: &str = "kiapi.common.commands.SaveSelectionToString"; const CMD_SAVE_SELECTION_TO_STRING: &str = "kiapi.common.commands.SaveSelectionToString";
@ -1425,6 +1426,22 @@ impl KiCadClient {
Ok(()) Ok(())
} }
pub async fn revert_document_raw(&self) -> Result<prost_types::Any, KiCadError> {
let command = common_commands::RevertDocument {
document: Some(self.current_board_document_proto().await?),
};
let response = self
.send_command(envelope::pack_any(&command, CMD_REVERT_DOCUMENT))
.await?;
response_payload_as_any(response, RES_PROTOBUF_EMPTY)
}
pub async fn revert_document(&self) -> Result<(), KiCadError> {
let _ = self.revert_document_raw().await?;
Ok(())
}
pub async fn get_board_as_string(&self) -> Result<String, KiCadError> { pub async fn get_board_as_string(&self) -> Result<String, KiCadError> {
let command = common_commands::SaveDocumentToString { let command = common_commands::SaveDocumentToString {
document: Some(self.current_board_document_proto().await?), document: Some(self.current_board_document_proto().await?),

File diff suppressed because one or more lines are too long