feat(project): add GetTextVariables API bindings
This commit is contained in:
parent
8ffdf4b2d6
commit
94581a7c6b
|
|
@ -40,10 +40,10 @@ Legend:
|
||||||
| --- | ---: | ---: | ---: |
|
| --- | ---: | ---: | ---: |
|
||||||
| Common (base) | 6 | 2 | 33% |
|
| Common (base) | 6 | 2 | 33% |
|
||||||
| Common editor/document | 23 | 9 | 39% |
|
| Common editor/document | 23 | 9 | 39% |
|
||||||
| Project manager | 5 | 1 | 20% |
|
| Project manager | 5 | 2 | 40% |
|
||||||
| Board editor (PCB) | 22 | 13 | 59% |
|
| Board editor (PCB) | 22 | 13 | 59% |
|
||||||
| Schematic editor (dedicated proto commands) | 0 | 0 | n/a |
|
| Schematic editor (dedicated proto commands) | 0 | 0 | n/a |
|
||||||
| **Total** | **56** | **25** | **45%** |
|
| **Total** | **56** | **26** | **46%** |
|
||||||
|
|
||||||
### Common (base)
|
### Common (base)
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ Legend:
|
||||||
| `GetNetClasses` | Implemented | `KiCadClient::get_net_classes_raw`, `KiCadClient::get_net_classes` |
|
| `GetNetClasses` | Implemented | `KiCadClient::get_net_classes_raw`, `KiCadClient::get_net_classes` |
|
||||||
| `SetNetClasses` | Not yet | - |
|
| `SetNetClasses` | Not yet | - |
|
||||||
| `ExpandTextVariables` | Not yet | - |
|
| `ExpandTextVariables` | Not yet | - |
|
||||||
| `GetTextVariables` | Not yet | - |
|
| `GetTextVariables` | Implemented | `KiCadClient::get_text_variables_raw`, `KiCadClient::get_text_variables` |
|
||||||
| `SetTextVariables` | Not yet | - |
|
| `SetTextVariables` | Not yet | - |
|
||||||
|
|
||||||
### Board editor (PCB)
|
### Board editor (PCB)
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,12 @@ List project net classes:
|
||||||
cargo run --bin kicad-ipc-cli -- net-classes
|
cargo run --bin kicad-ipc-cli -- net-classes
|
||||||
```
|
```
|
||||||
|
|
||||||
|
List text variables for current board document:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo run --bin kicad-ipc-cli -- text-variables
|
||||||
|
```
|
||||||
|
|
||||||
List enabled board layers:
|
List enabled board layers:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ const KICAD_API_TOKEN_ENV: &str = "KICAD_API_TOKEN";
|
||||||
const CMD_PING: &str = "kiapi.common.commands.Ping";
|
const CMD_PING: &str = "kiapi.common.commands.Ping";
|
||||||
const CMD_GET_VERSION: &str = "kiapi.common.commands.GetVersion";
|
const CMD_GET_VERSION: &str = "kiapi.common.commands.GetVersion";
|
||||||
const CMD_GET_NET_CLASSES: &str = "kiapi.common.commands.GetNetClasses";
|
const CMD_GET_NET_CLASSES: &str = "kiapi.common.commands.GetNetClasses";
|
||||||
|
const CMD_GET_TEXT_VARIABLES: &str = "kiapi.common.commands.GetTextVariables";
|
||||||
const CMD_GET_OPEN_DOCUMENTS: &str = "kiapi.common.commands.GetOpenDocuments";
|
const CMD_GET_OPEN_DOCUMENTS: &str = "kiapi.common.commands.GetOpenDocuments";
|
||||||
const CMD_GET_NETS: &str = "kiapi.board.commands.GetNets";
|
const CMD_GET_NETS: &str = "kiapi.board.commands.GetNets";
|
||||||
const CMD_GET_BOARD_ENABLED_LAYERS: &str = "kiapi.board.commands.GetBoardEnabledLayers";
|
const CMD_GET_BOARD_ENABLED_LAYERS: &str = "kiapi.board.commands.GetBoardEnabledLayers";
|
||||||
|
|
@ -63,6 +64,7 @@ const CMD_SAVE_SELECTION_TO_STRING: &str = "kiapi.common.commands.SaveSelectionT
|
||||||
|
|
||||||
const RES_GET_VERSION: &str = "kiapi.common.commands.GetVersionResponse";
|
const RES_GET_VERSION: &str = "kiapi.common.commands.GetVersionResponse";
|
||||||
const RES_NET_CLASSES_RESPONSE: &str = "kiapi.common.commands.NetClassesResponse";
|
const RES_NET_CLASSES_RESPONSE: &str = "kiapi.common.commands.NetClassesResponse";
|
||||||
|
const RES_TEXT_VARIABLES: &str = "kiapi.common.project.TextVariables";
|
||||||
const RES_GET_OPEN_DOCUMENTS: &str = "kiapi.common.commands.GetOpenDocumentsResponse";
|
const RES_GET_OPEN_DOCUMENTS: &str = "kiapi.common.commands.GetOpenDocumentsResponse";
|
||||||
const RES_GET_NETS: &str = "kiapi.board.commands.NetsResponse";
|
const RES_GET_NETS: &str = "kiapi.board.commands.NetsResponse";
|
||||||
const RES_GET_BOARD_ENABLED_LAYERS: &str = "kiapi.board.commands.BoardEnabledLayersResponse";
|
const RES_GET_BOARD_ENABLED_LAYERS: &str = "kiapi.board.commands.BoardEnabledLayersResponse";
|
||||||
|
|
@ -341,6 +343,22 @@ impl KiCadClient {
|
||||||
Ok(classes)
|
Ok(classes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_text_variables_raw(&self) -> Result<prost_types::Any, KiCadError> {
|
||||||
|
let command = common_commands::GetTextVariables {
|
||||||
|
document: Some(self.current_board_document_proto().await?),
|
||||||
|
};
|
||||||
|
let response = self
|
||||||
|
.send_command(envelope::pack_any(&command, CMD_GET_TEXT_VARIABLES))
|
||||||
|
.await?;
|
||||||
|
response_payload_as_any(response, RES_TEXT_VARIABLES)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_text_variables(&self) -> Result<BTreeMap<String, String>, KiCadError> {
|
||||||
|
let payload = self.get_text_variables_raw().await?;
|
||||||
|
let response: common_project::TextVariables = decode_any(&payload, RES_TEXT_VARIABLES)?;
|
||||||
|
Ok(response.variables.into_iter().collect())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_current_project_path(&self) -> Result<PathBuf, KiCadError> {
|
pub async fn get_current_project_path(&self) -> Result<PathBuf, KiCadError> {
|
||||||
let docs = self.get_open_documents(DocumentType::Pcb).await?;
|
let docs = self.get_open_documents(DocumentType::Pcb).await?;
|
||||||
select_single_project_path(&docs)
|
select_single_project_path(&docs)
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ enum Command {
|
||||||
ProjectPath,
|
ProjectPath,
|
||||||
BoardOpen,
|
BoardOpen,
|
||||||
NetClasses,
|
NetClasses,
|
||||||
|
TextVariables,
|
||||||
Nets,
|
Nets,
|
||||||
EnabledLayers,
|
EnabledLayers,
|
||||||
ActiveLayer,
|
ActiveLayer,
|
||||||
|
|
@ -196,6 +197,13 @@ async fn run() -> Result<(), KiCadError> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Command::TextVariables => {
|
||||||
|
let variables = client.get_text_variables().await?;
|
||||||
|
println!("text_variable_count={}", variables.len());
|
||||||
|
for (name, value) in variables {
|
||||||
|
println!("name={} value={}", name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
Command::Nets => {
|
Command::Nets => {
|
||||||
let nets = client.get_nets().await?;
|
let nets = client.get_nets().await?;
|
||||||
if nets.is_empty() {
|
if nets.is_empty() {
|
||||||
|
|
@ -589,6 +597,7 @@ fn parse_args() -> Result<(CliConfig, Command), KiCadError> {
|
||||||
"project-path" => Command::ProjectPath,
|
"project-path" => Command::ProjectPath,
|
||||||
"board-open" => Command::BoardOpen,
|
"board-open" => Command::BoardOpen,
|
||||||
"net-classes" => Command::NetClasses,
|
"net-classes" => Command::NetClasses,
|
||||||
|
"text-variables" => Command::TextVariables,
|
||||||
"nets" => Command::Nets,
|
"nets" => Command::Nets,
|
||||||
"enabled-layers" => Command::EnabledLayers,
|
"enabled-layers" => Command::EnabledLayers,
|
||||||
"active-layer" => Command::ActiveLayer,
|
"active-layer" => Command::ActiveLayer,
|
||||||
|
|
@ -924,7 +933,7 @@ fn default_config() -> CliConfig {
|
||||||
|
|
||||||
fn print_help() {
|
fn print_help() {
|
||||||
println!(
|
println!(
|
||||||
"kicad-ipc-cli\n\nUSAGE:\n cargo run --bin kicad-ipc-cli -- [--socket URI] [--token TOKEN] [--timeout-ms N] <command> [command options]\n\nCOMMANDS:\n ping Check IPC connectivity\n version Fetch KiCad version\n open-docs [--type <type>] List open docs (default type: pcb)\n project-path Get current project path from open PCB docs\n board-open Exit non-zero if no PCB doc is open\n net-classes List project netclass definitions\n nets List board nets (requires one open PCB)\n netlist-pads Emit pad-level netlist data (with footprint context)\n items-by-id --id <uuid> ... Show parsed details for specific item IDs\n item-bbox --id <uuid> ... Show bounding boxes for item IDs\n hit-test --id <uuid> --x-nm <x> --y-nm <y> [--tolerance-nm <n>]\n Hit-test one item at a point\n types-pcb List PCB KiCad object type IDs from proto enum\n items-raw --type-id <id> ... Dump raw Any payloads for requested item type IDs\n items-raw-all-pcb [--debug] Dump all PCB item payloads across all PCB object types\n pad-shape-polygon --pad-id <uuid> ... --layer-id <i32> [--debug]\n Dump pad polygons on a target layer\n padstack-presence --item-id <uuid> ... --layer-id <i32> ... [--debug]\n Check padstack shape presence matrix across layers\n title-block Show title block fields\n board-as-string Dump board as KiCad s-expression text\n selection-as-string Dump current selection as KiCad s-expression text\n stackup Show typed board stackup\n graphics-defaults Show typed graphics defaults\n appearance Show typed editor appearance settings\n netclass Show typed netclass map for current board nets\n proto-coverage-board-read Print board-read command coverage vs proto\n board-read-report [--out P] Write markdown board reconstruction report\n enabled-layers List enabled board layers\n active-layer Show active board layer\n visible-layers Show currently visible board layers\n board-origin [--type <t>] Show board origin (`grid` default, or `drill`)\n selection-summary Show current selection item type counts\n selection-details Show parsed details for selected items\n selection-raw Show raw Any payload bytes for selected items\n smoke ping + version + board-open summary\n help Show help\n\nTYPES:\n schematic | symbol | pcb | footprint | drawing-sheet | project\n"
|
"kicad-ipc-cli\n\nUSAGE:\n cargo run --bin kicad-ipc-cli -- [--socket URI] [--token TOKEN] [--timeout-ms N] <command> [command options]\n\nCOMMANDS:\n ping Check IPC connectivity\n version Fetch KiCad version\n open-docs [--type <type>] List open docs (default type: pcb)\n project-path Get current project path from open PCB docs\n board-open Exit non-zero if no PCB doc is open\n net-classes List project netclass definitions\n text-variables List text variables for current board document\n nets List board nets (requires one open PCB)\n netlist-pads Emit pad-level netlist data (with footprint context)\n items-by-id --id <uuid> ... Show parsed details for specific item IDs\n item-bbox --id <uuid> ... Show bounding boxes for item IDs\n hit-test --id <uuid> --x-nm <x> --y-nm <y> [--tolerance-nm <n>]\n Hit-test one item at a point\n types-pcb List PCB KiCad object type IDs from proto enum\n items-raw --type-id <id> ... Dump raw Any payloads for requested item type IDs\n items-raw-all-pcb [--debug] Dump all PCB item payloads across all PCB object types\n pad-shape-polygon --pad-id <uuid> ... --layer-id <i32> [--debug]\n Dump pad polygons on a target layer\n padstack-presence --item-id <uuid> ... --layer-id <i32> ... [--debug]\n Check padstack shape presence matrix across layers\n title-block Show title block fields\n board-as-string Dump board as KiCad s-expression text\n selection-as-string Dump current selection as KiCad s-expression text\n stackup Show typed board stackup\n graphics-defaults Show typed graphics defaults\n appearance Show typed editor appearance settings\n netclass Show typed netclass map for current board nets\n proto-coverage-board-read Print board-read command coverage vs proto\n board-read-report [--out P] Write markdown board reconstruction report\n enabled-layers List enabled board layers\n active-layer Show active board layer\n visible-layers Show currently visible board layers\n board-origin [--type <t>] Show board origin (`grid` default, or `drill`)\n selection-summary Show current selection item type counts\n selection-details Show parsed details for selected items\n selection-raw Show raw Any payload bytes for selected items\n smoke ping + version + board-open summary\n help Show help\n\nTYPES:\n schematic | symbol | pcb | footprint | drawing-sheet | project\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1332,6 +1341,11 @@ fn proto_coverage_board_read_rows() -> Vec<(&'static str, &'static str, &'static
|
||||||
"implemented",
|
"implemented",
|
||||||
"get_net_classes_raw/get_net_classes",
|
"get_net_classes_raw/get_net_classes",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"kiapi.common.commands.GetTextVariables",
|
||||||
|
"implemented",
|
||||||
|
"get_text_variables_raw/get_text_variables",
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"kiapi.common.commands.GetItems",
|
"kiapi.common.commands.GetItems",
|
||||||
"implemented",
|
"implemented",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue