feat(client): add SetVisibleLayers API and CLI command
This commit is contained in:
parent
35f6773b11
commit
438b4999b9
|
|
@ -41,9 +41,9 @@ Legend:
|
|||
| Common (base) | 6 | 4 | 67% |
|
||||
| Common editor/document | 23 | 12 | 52% |
|
||||
| Project manager | 5 | 3 | 60% |
|
||||
| Board editor (PCB) | 22 | 14 | 64% |
|
||||
| Board editor (PCB) | 22 | 15 | 68% |
|
||||
| Schematic editor (dedicated proto commands) | 0 | 0 | n/a |
|
||||
| **Total** | **56** | **33** | **59%** |
|
||||
| **Total** | **56** | **34** | **61%** |
|
||||
|
||||
### Common (base)
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ Legend:
|
|||
| `CheckPadstackPresenceOnLayers` | Implemented | `KiCadClient::check_padstack_presence_on_layers_raw`, `KiCadClient::check_padstack_presence_on_layers` |
|
||||
| `InjectDrcError` | Not yet | - |
|
||||
| `GetVisibleLayers` | Implemented | `KiCadClient::get_visible_layers` |
|
||||
| `SetVisibleLayers` | Not yet | - |
|
||||
| `SetVisibleLayers` | Implemented | `KiCadClient::set_visible_layers` |
|
||||
| `GetActiveLayer` | Implemented | `KiCadClient::get_active_layer` |
|
||||
| `SetActiveLayer` | Implemented | `KiCadClient::set_active_layer` |
|
||||
| `GetBoardEditorAppearanceSettings` | Implemented | `KiCadClient::get_board_editor_appearance_settings_raw`, `KiCadClient::get_board_editor_appearance_settings` |
|
||||
|
|
|
|||
|
|
@ -101,6 +101,12 @@ Show visible layers:
|
|||
cargo run --bin kicad-ipc-cli -- visible-layers
|
||||
```
|
||||
|
||||
Set visible layers:
|
||||
|
||||
```bash
|
||||
cargo run --bin kicad-ipc-cli -- set-visible-layers --layer-id 0 --layer-id 31
|
||||
```
|
||||
|
||||
Show board origin (grid origin by default):
|
||||
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ const CMD_GET_BOARD_ENABLED_LAYERS: &str = "kiapi.board.commands.GetBoardEnabled
|
|||
const CMD_GET_ACTIVE_LAYER: &str = "kiapi.board.commands.GetActiveLayer";
|
||||
const CMD_SET_ACTIVE_LAYER: &str = "kiapi.board.commands.SetActiveLayer";
|
||||
const CMD_GET_VISIBLE_LAYERS: &str = "kiapi.board.commands.GetVisibleLayers";
|
||||
const CMD_SET_VISIBLE_LAYERS: &str = "kiapi.board.commands.SetVisibleLayers";
|
||||
const CMD_GET_BOARD_ORIGIN: &str = "kiapi.board.commands.GetBoardOrigin";
|
||||
const CMD_GET_BOARD_STACKUP: &str = "kiapi.board.commands.GetBoardStackup";
|
||||
const CMD_GET_GRAPHICS_DEFAULTS: &str = "kiapi.board.commands.GetGraphicsDefaults";
|
||||
|
|
@ -608,6 +609,18 @@ impl KiCadClient {
|
|||
Ok(payload.layers.into_iter().map(layer_to_model).collect())
|
||||
}
|
||||
|
||||
pub async fn set_visible_layers(&self, layer_ids: Vec<i32>) -> Result<(), KiCadError> {
|
||||
let board = self.current_board_document_proto().await?;
|
||||
let command = board_commands::SetVisibleLayers {
|
||||
board: Some(board),
|
||||
layers: layer_ids,
|
||||
};
|
||||
|
||||
self.send_command(envelope::pack_any(&command, CMD_SET_VISIBLE_LAYERS))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_board_origin(&self, kind: BoardOriginKind) -> Result<Vector2Nm, KiCadError> {
|
||||
let board = self.current_board_document_proto().await?;
|
||||
let command = board_commands::GetBoardOrigin {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ enum Command {
|
|||
layer_id: i32,
|
||||
},
|
||||
VisibleLayers,
|
||||
SetVisibleLayers {
|
||||
layer_ids: Vec<i32>,
|
||||
},
|
||||
BoardOrigin {
|
||||
kind: BoardOriginKind,
|
||||
},
|
||||
|
|
@ -323,6 +326,10 @@ async fn run() -> Result<(), KiCadError> {
|
|||
}
|
||||
}
|
||||
}
|
||||
Command::SetVisibleLayers { layer_ids } => {
|
||||
client.set_visible_layers(layer_ids.clone()).await?;
|
||||
println!("set_visible_layer_count={}", layer_ids.len());
|
||||
}
|
||||
Command::BoardOrigin { kind } => {
|
||||
let origin = client.get_board_origin(kind).await?;
|
||||
println!(
|
||||
|
|
@ -814,6 +821,32 @@ fn parse_args_from(mut args: Vec<String>) -> Result<(CliConfig, Command), KiCadE
|
|||
}
|
||||
}
|
||||
"visible-layers" => Command::VisibleLayers,
|
||||
"set-visible-layers" => {
|
||||
let mut layer_ids = Vec::new();
|
||||
let mut i = 1;
|
||||
while i < args.len() {
|
||||
if args[i] == "--layer-id" {
|
||||
let value = args.get(i + 1).ok_or_else(|| KiCadError::Config {
|
||||
reason: "missing value for set-visible-layers --layer-id".to_string(),
|
||||
})?;
|
||||
layer_ids.push(value.parse::<i32>().map_err(|err| KiCadError::Config {
|
||||
reason: format!("invalid set-visible-layers --layer-id `{value}`: {err}"),
|
||||
})?);
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
||||
if layer_ids.is_empty() {
|
||||
return Err(KiCadError::Config {
|
||||
reason: "set-visible-layers requires one or more `--layer-id <i32>` arguments"
|
||||
.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
Command::SetVisibleLayers { layer_ids }
|
||||
}
|
||||
"board-origin" => {
|
||||
let mut kind = BoardOriginKind::Grid;
|
||||
let mut i = 1;
|
||||
|
|
@ -1207,7 +1240,7 @@ fn default_config() -> CliConfig {
|
|||
|
||||
fn print_help() {
|
||||
println!(
|
||||
"kicad-ipc-cli\n\nUSAGE:\n cargo run --bin kicad-ipc-cli -- [--socket URI] [--token TOKEN] [--client-name NAME] [--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 expand-text-variables Expand variables in provided text values\n Options: --text <value> (repeatable)\n text-extents Measure text bounding box\n Options: --text <value>\n text-as-shapes Convert text to rendered shapes\n Options: --text <value> (repeatable)\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 set-active-layer --layer-id <i32>\n Set active board layer\n visible-layers Show currently visible board layers\n board-origin [--type <t>] Show board origin (`grid` default, or `drill`)\n refresh-editor [--frame <f>] Refresh a specific editor frame (default: pcb)\n begin-commit Start staged commit and print commit ID\n end-commit --id <uuid> [--action <commit|drop>] [--message <text>]\n End staged commit with commit/drop action\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] [--client-name NAME] [--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 expand-text-variables Expand variables in provided text values\n Options: --text <value> (repeatable)\n text-extents Measure text bounding box\n Options: --text <value>\n text-as-shapes Convert text to rendered shapes\n Options: --text <value> (repeatable)\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 set-active-layer --layer-id <i32>\n Set active board layer\n visible-layers Show currently visible board layers\n set-visible-layers --layer-id <i32> ...\n Set visible board layers\n board-origin [--type <t>] Show board origin (`grid` default, or `drill`)\n refresh-editor [--frame <f>] Refresh a specific editor frame (default: pcb)\n begin-commit Start staged commit and print commit ID\n end-commit --id <uuid> [--action <commit|drop>] [--message <text>]\n End staged commit with commit/drop action\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"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1833,4 +1866,21 @@ mod tests {
|
|||
other => panic!("unexpected command variant: {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_args_parses_set_visible_layers() {
|
||||
let (_, command) = parse_args_from(vec![
|
||||
"set-visible-layers".to_string(),
|
||||
"--layer-id".to_string(),
|
||||
"3".to_string(),
|
||||
"--layer-id".to_string(),
|
||||
"47".to_string(),
|
||||
])
|
||||
.expect("set-visible-layers args should parse");
|
||||
|
||||
match command {
|
||||
Command::SetVisibleLayers { layer_ids } => assert_eq!(layer_ids, vec![3, 47]),
|
||||
other => panic!("unexpected command variant: {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue