Match Smooth connected-endpoint workflow

This commit is contained in:
ramox81 committed 2026-09-17 13:37:25 +03:00
1 parent 7c6665153c
commit dfa75f45b5
4 files changed
+221 -161

No files matched your search

+30
View File
@@ -849,6 +849,36 @@ impl OpenCADStudio {
/// command, so `was_active` is false and their selection is preserved.
pub(super) fn apply_cmd_result(&mut self, mut result: CmdResult) -> Task<Message> {
let i = self.active_tab;
if let CmdResult::AddParametricConstraint {
kind,
refs,
..
} = &mut result
{
if *kind == crate::scene::parametric_constraints::ConstraintKind::Smooth
&& refs.len() == 1
{
let source = refs[0];
let scope = self.tabs[i].current_parametric_scope();
let Some(resolved) = self.tabs[i]
.scene
.smooth_refs_from_connected_spline(scope, source.entity, source.marker)
else {
self.tabs[i].snap_result = None;
self.command_line
.push_error("No valid constraint point found.");
if let Some(prompt) = self.tabs[i]
.active_cmd
.as_ref()
.map(|command| command.prompt())
{
self.command_line.push_info(&prompt);
}
return Task::none();
};
*refs = resolved;
}
}
if let CmdResult::ReturnPoint(pt) = result {
self.tabs[i].scene.clear_preview_wire();
if let Some(mut suspended) = self.tabs[i].suspended_cmd.take() {
+21 -30
View File
@@ -1213,41 +1213,32 @@ impl OpenCADStudio {
let command = SmoothConstraintCommand::new();
self.command_line.push_info(&command.prompt());
self.tabs[i].active_cmd = Some(Box::new(command));
} else if handles.len() != 2 {
self.tabs[i].scene.deselect_all();
self.command_line.push_error(
"Smooth requires an open spline first and a target curve second.",
);
let command = SmoothConstraintCommand::new();
self.command_line.push_info(&command.prompt());
self.tabs[i].active_cmd = Some(Box::new(command));
} else {
let first = self.tabs[i].scene.document.get_entity(handles[0]);
let second = self.tabs[i].scene.document.get_entity(handles[1]);
let refs = first.zip(second).and_then(|(first, second)| {
SmoothConstraintCommand::preselected_refs(
(first, handles[0]),
(second, handles[1]),
)
});
let Some(refs) = refs else {
let scope = self.tabs[i].current_parametric_scope();
let refs = (handles.len() == 1)
.then(|| {
self.tabs[i]
.scene
.smooth_refs_from_connected_spline(scope, handles[0], None)
})
.flatten();
if let Some(refs) = refs {
use crate::command::CmdResult;
use crate::scene::parametric_constraints::ConstraintKind;
return Some(self.apply_cmd_result(CmdResult::AddParametricConstraint {
kind: ConstraintKind::Smooth,
refs,
driving_param: None,
label: "Smooth constraint",
}));
} else {
self.tabs[i].scene.deselect_all();
self.command_line.push_error(
"Smooth requires an open spline first and a line, arc, polyline segment or open spline second.",
);
self.command_line
.push_error("No valid constraint point found.");
let command = SmoothConstraintCommand::new();
self.command_line.push_info(&command.prompt());
self.tabs[i].active_cmd = Some(Box::new(command));
return None;
};
use crate::command::CmdResult;
use crate::scene::parametric_constraints::ConstraintKind;
return Some(self.apply_cmd_result(CmdResult::AddParametricConstraint {
kind: ConstraintKind::Smooth,
refs,
driving_param: None,
label: "Smooth constraint",
}));
}
}
}