forked from 1b-agent/opencadstudio-upstream
feat(python): command runner and modify wrappers (doc.command, doc.modify)
HostApi::run_command drives the real OCS command through the same primitives the automation channel uses, synchronously on the host thread: run a line, start a command and answer point/text/token/entity/selection/enter prompts, or cancel (closing anything the command opened). Refused while another command is active, for a denylist (QUIT, NEW, OPEN, SAVE*, PY_* ...) and off the active tab. Python: doc.command, doc.start_command and doc.modify (offset, trim, extend, fillet, move, copy, rotate, scale, mirror, erase). Real-IPC audit checks exact geometry for every wrapper plus guards and undo; IPC and Python unit tests; docs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
795aa922b4
commit
1b1785eefb
13 files changed
+867
-1
No files matched your search
@@ -85,6 +85,56 @@ pub enum SolidBoolean {
|
||||
Intersect,
|
||||
}
|
||||
|
||||
/// One step of driving an OCS command from a script (API v7, additive). The
|
||||
/// host runs the real command, so every tool behaves exactly as at the command
|
||||
/// line, and answers with where the command stands.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum CommandRequest {
|
||||
/// Run a whole command line (`OFFSET 5 ...`): the tokens after the name
|
||||
/// answer the prompts in order and a final Enter finishes the command.
|
||||
Run { line: String },
|
||||
/// Start a command and leave it waiting for its first input.
|
||||
Start { name: String },
|
||||
/// Answer the current prompt with a world-coordinate point.
|
||||
Point { point: [f64; 3] },
|
||||
/// Answer with typed text (a distance, an angle, a name).
|
||||
Text { text: String },
|
||||
/// Answer with a keyword option.
|
||||
Token { text: String },
|
||||
/// Pick an entity at a point.
|
||||
Entity { handle: Handle, point: [f64; 3] },
|
||||
/// Complete an object-selection prompt with the current selection.
|
||||
Selection,
|
||||
/// Press Enter.
|
||||
Enter,
|
||||
/// Cancel the running command and close anything it left open.
|
||||
Cancel,
|
||||
}
|
||||
|
||||
/// Where a command stands after a [`CommandRequest`].
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
|
||||
pub struct CommandOutcome {
|
||||
/// `completed` when nothing is waiting, `waiting_input` when the command
|
||||
/// (or an editor or dialog it opened) needs more.
|
||||
pub status: String,
|
||||
/// What is still open: `command`, `text_editor`, `mtext_editor` or `modal:<kind>`.
|
||||
pub blocked_by: Option<String>,
|
||||
/// The waiting command's name and prompt (empty when none).
|
||||
pub command: String,
|
||||
pub prompt: String,
|
||||
/// The kinds of input the prompt accepts (`point`, `entity`, `selection`,
|
||||
/// `text`, `token`, `enter`) and its keyword options.
|
||||
pub accepts: Vec<String>,
|
||||
pub options: Vec<String>,
|
||||
/// Entities in the drawing after the step, and the change.
|
||||
pub entities: u64,
|
||||
pub added: i64,
|
||||
/// Typed tokens no prompt asked for.
|
||||
pub unconsumed: Vec<String>,
|
||||
/// The command line's error message when the step failed.
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
/// A change to a drawing table record (API v7, additive). The host validates
|
||||
/// the request, records one undo step and refuses without changing anything
|
||||
/// when it cannot honour it; the result is the record's handle.
|
||||
@@ -808,6 +858,13 @@ pub trait HostApi {
|
||||
Err("solid operations are not supported by this host".to_owned())
|
||||
}
|
||||
|
||||
/// Drive an OCS command from a script (API v7, additive). Refused, with
|
||||
/// nothing run, when another command is already active or the request names
|
||||
/// a command that could end the session or re-enter the plugin.
|
||||
fn run_command(&mut self, _request: CommandRequest) -> Result<CommandOutcome, String> {
|
||||
Err("running commands is not supported by this host".to_owned())
|
||||
}
|
||||
|
||||
/// Create, change, rename, delete or select a drawing table record (API v7,
|
||||
/// additive). Returns the record's handle; a refusal changes nothing.
|
||||
fn table_operation(&mut self, _operation: TableOperation) -> Result<Handle, String> {
|
||||
|
||||
Reference in new issue
Block a user