feat(common): add ParseAndCreateItemsFromString API and CLI command
This commit is contained in:
parent
a2a3dbc771
commit
1c57eef959
|
|
@ -42,6 +42,7 @@ Deferred manual/runtime verification (implemented after 2026-02-20 while user un
|
|||
- `CreateItems`
|
||||
- `UpdateItems`
|
||||
- `DeleteItems`
|
||||
- `ParseAndCreateItemsFromString`
|
||||
|
||||
## KiCad v10 RC1.1 API Completion Matrix
|
||||
|
||||
|
|
@ -62,11 +63,11 @@ Legend:
|
|||
| Section | Proto Commands | Implemented | Coverage |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| Common (base) | 6 | 6 | 100% |
|
||||
| Common editor/document | 23 | 22 | 96% |
|
||||
| Common editor/document | 23 | 23 | 100% |
|
||||
| Project manager | 5 | 3 | 60% |
|
||||
| Board editor (PCB) | 22 | 20 | 91% |
|
||||
| Schematic editor (dedicated proto commands) | 0 | 0 | n/a |
|
||||
| **Total** | **56** | **51** | **91%** |
|
||||
| **Total** | **56** | **52** | **93%** |
|
||||
|
||||
### Common (base)
|
||||
|
||||
|
|
@ -105,7 +106,7 @@ Legend:
|
|||
| `GetTitleBlockInfo` | Implemented | `KiCadClient::get_title_block_info` |
|
||||
| `SaveDocumentToString` | Implemented | `KiCadClient::get_board_as_string` |
|
||||
| `SaveSelectionToString` | Implemented | `KiCadClient::get_selection_as_string` |
|
||||
| `ParseAndCreateItemsFromString` | Not yet | - |
|
||||
| `ParseAndCreateItemsFromString` | Implemented | `KiCadClient::parse_and_create_items_from_string_raw`, `KiCadClient::parse_and_create_items_from_string` |
|
||||
|
||||
### Project manager
|
||||
|
||||
|
|
|
|||
|
|
@ -205,6 +205,12 @@ Delete items by ID:
|
|||
cargo run --bin kicad-ipc-cli -- delete-items --id <uuid> --id <uuid>
|
||||
```
|
||||
|
||||
Parse and create items from s-expression:
|
||||
|
||||
```bash
|
||||
cargo run --bin kicad-ipc-cli -- parse-create-items --contents "(kicad_pcb (version 20240108))"
|
||||
```
|
||||
|
||||
Show summary of current PCB selection by item type:
|
||||
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ const CMD_END_COMMIT: &str = "kiapi.common.commands.EndCommit";
|
|||
const CMD_CREATE_ITEMS: &str = "kiapi.common.commands.CreateItems";
|
||||
const CMD_UPDATE_ITEMS: &str = "kiapi.common.commands.UpdateItems";
|
||||
const CMD_DELETE_ITEMS: &str = "kiapi.common.commands.DeleteItems";
|
||||
const CMD_PARSE_AND_CREATE_ITEMS_FROM_STRING: &str =
|
||||
"kiapi.common.commands.ParseAndCreateItemsFromString";
|
||||
const CMD_GET_ITEMS: &str = "kiapi.common.commands.GetItems";
|
||||
const CMD_GET_ITEMS_BY_ID: &str = "kiapi.common.commands.GetItemsById";
|
||||
const CMD_GET_BOUNDING_BOX: &str = "kiapi.common.commands.GetBoundingBox";
|
||||
|
|
@ -735,6 +737,47 @@ impl KiCadClient {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub async fn parse_and_create_items_from_string_raw(
|
||||
&self,
|
||||
contents: impl Into<String>,
|
||||
) -> Result<prost_types::Any, KiCadError> {
|
||||
let command = common_commands::ParseAndCreateItemsFromString {
|
||||
document: Some(self.current_board_document_proto().await?),
|
||||
contents: contents.into(),
|
||||
};
|
||||
|
||||
let response = self
|
||||
.send_command(envelope::pack_any(
|
||||
&command,
|
||||
CMD_PARSE_AND_CREATE_ITEMS_FROM_STRING,
|
||||
))
|
||||
.await?;
|
||||
response_payload_as_any(response, RES_CREATE_ITEMS_RESPONSE)
|
||||
}
|
||||
|
||||
pub async fn parse_and_create_items_from_string(
|
||||
&self,
|
||||
contents: impl Into<String>,
|
||||
) -> Result<Vec<prost_types::Any>, KiCadError> {
|
||||
let payload = self
|
||||
.parse_and_create_items_from_string_raw(contents)
|
||||
.await?;
|
||||
let response: common_commands::CreateItemsResponse =
|
||||
decode_any(&payload, RES_CREATE_ITEMS_RESPONSE)?;
|
||||
ensure_item_request_ok(response.status)?;
|
||||
|
||||
response
|
||||
.created_items
|
||||
.into_iter()
|
||||
.map(|row| {
|
||||
ensure_item_status_ok(row.status)?;
|
||||
row.item.ok_or_else(|| KiCadError::InvalidResponse {
|
||||
reason: "CreateItemsResponse missing created item payload".to_string(),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub async fn get_nets(&self) -> Result<Vec<BoardNet>, KiCadError> {
|
||||
let board = self.current_board_document_proto().await?;
|
||||
let command = board_commands::GetNets {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue