Feat: BREAK command (BR) — split Line/Arc/Circle/LwPolyline at two points

3-step interactive flow:
  1. Entity pick (first break point recorded at click location)
  2. Optional first point refinement
  3. Second break point → CmdResult::BreakEntity applied in cmd_result

Geometry:
- Line: project p1/p2 onto line parameter space → two line fragments
- Arc:  project p1/p2 to arc angles → trim CCW from p1 to p2
- Circle: same as Arc, converts Circle → Arc
- LwPolyline: nearest-vertex split → two polyline fragments

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-04-02 23:39:51 +03:00
commit 4b8ae08a19
5 changed files with 330 additions and 1 deletions

View file

@ -371,6 +371,37 @@ impl H7CAD {
self.restore_pre_cmd_tangent();
self.command_line.push_output(&msg);
}
CmdResult::BreakEntity { handle, p1, p2 } => {
use crate::modules::home::modify::break_cmd::break_entity;
let replacement = self.tabs[i].scene.document
.get_entity(handle)
.and_then(|e| break_entity(e, p1, p2));
match replacement {
Some(frags) => {
let label = self.history_label_from_active_cmd(i, "BREAK");
self.push_undo_snapshot(i, label);
self.tabs[i].scene.erase_entities(&[handle]);
let count = frags.len();
for e in frags {
self.tabs[i].scene.add_entity(e);
}
self.tabs[i].dirty = true;
self.tabs[i].scene.clear_preview_wire();
self.tabs[i].active_cmd = None;
self.tabs[i].snap_result = None;
self.restore_pre_cmd_tangent();
self.command_line.push_output(&format!("BREAK: {} fragment(s).", count));
self.refresh_properties();
}
None => {
self.tabs[i].active_cmd = None;
self.tabs[i].snap_result = None;
self.tabs[i].scene.clear_preview_wire();
self.restore_pre_cmd_tangent();
self.command_line.push_error("BREAK: entity type not supported.");
}
}
}
}
// Focus the command-line input while a command is active; blur it when the command ends.
if self.tabs[i].active_cmd.is_some() {

View file

@ -970,6 +970,14 @@ impl H7CAD {
}
}
// ── Break ────────────────────────────────────────────────────────
"BREAK"|"BR" => {
use crate::modules::home::modify::break_cmd::BreakInteractiveCommand;
let cmd = BreakInteractiveCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
// ── Inquiry ──────────────────────────────────────────────────────
"DIST"|"DI" => {
use crate::modules::home::inquiry::dist::DistCommand;
@ -995,7 +1003,7 @@ impl H7CAD {
"HELP"|"?" => {
self.command_line.push_output(
"Draw: LINE CIRCLE ARC PLINE RECT POLY POINT ELLIPSE SPLINE RAY XLINE HATCH | \
Modify: MOVE COPY ROTATE SCALE MIRROR ERASE OFFSET EXTEND FILLET CHAMFER STRETCH EXPLODE TRIM | \
Modify: MOVE COPY ROTATE SCALE MIRROR ERASE OFFSET EXTEND FILLET CHAMFER STRETCH EXPLODE TRIM BREAK | \
Array: ARRAY ARRAYRECT ARRAYPOLAR ARRAYPATH | \
Text: TEXT MTEXT LEADER MLEADER | \
Dimension: DIMLINEAR DIMANGULAR DIMRADIUS | \