Reverse selected curves while preserving spline shape

This commit is contained in:
ramox81 committed 2026-09-11 10:25:11 +03:00
1 parent 7d0c059b30
commit f80e9f742c
2 files changed
+25 -9

No files matched your search

+17 -3
View File
@@ -596,9 +596,23 @@ impl OpenCADStudio {
"REVERSE" => { "REVERSE" => {
use crate::modules::draw::modify::reverse::ReverseCommand; use crate::modules::draw::modify::reverse::ReverseCommand;
let new_cmd = ReverseCommand::new(); if self.tabs[i].scene.selected.is_empty() {
self.command_line.push_info(&new_cmd.prompt()); use crate::modules::draw::select::SelectObjectsCommand;
self.tabs[i].active_cmd = Some(Box::new(new_cmd)); let selection = SelectObjectsCommand::new("REVERSE");
self.command_line.push_info(&selection.prompt());
self.tabs[i].active_cmd = Some(Box::new(selection));
} else {
let replacements = self.tabs[i].scene.selected_entities().into_iter()
.filter(|(handle, _)| !self.tabs[i].scene.is_layer_locked(*handle))
.filter_map(|(handle, entity)| ReverseCommand::reversed(entity)
.map(|reversed| (handle, vec![reversed])))
.collect::<Vec<_>>();
if !replacements.is_empty() {
return Some(self.apply_cmd_result(crate::command::CmdResult::ReplaceMany(
replacements, Vec::new(),
)));
}
}
} }
"MEASUREGEOM" => { "MEASUREGEOM" => {
+8 -6
View File
@@ -54,7 +54,7 @@ impl ReverseCommand {
} }
/// Build a reversed copy of `entity`, or `None` for an unsupported type. /// Build a reversed copy of `entity`, or `None` for an unsupported type.
fn reversed(entity: &EntityType) -> Option<EntityType> { pub fn reversed(entity: &EntityType) -> Option<EntityType> {
match entity { match entity {
EntityType::Line(line) => { EntityType::Line(line) => {
let mut out = line.clone(); let mut out = line.clone();
@@ -176,9 +176,8 @@ fn reverse_polyline2d(pl: &acadrust::entities::Polyline2D) -> acadrust::entities
out out
} }
/// Reverse a Spline: flip control points and fit points, regenerate the /// Reverse stored coordinates in 3D and let the kernel mirror the knot domain.
/// clamped knot vector. Mirrors `splinedit::apply_spline_op`'s REVERSE branch. pub(super) fn reverse_spline(sp: &Spline) -> Spline {
fn reverse_spline(sp: &Spline) -> Spline {
let mut out = sp.clone(); let mut out = sp.clone();
out.control_points.reverse(); out.control_points.reverse();
out.fit_points.reverse(); out.fit_points.reverse();
@@ -186,8 +185,11 @@ fn reverse_spline(sp: &Spline) -> Spline {
if out.weights.len() == out.control_points.len() { if out.weights.len() == out.control_points.len() {
out.weights.reverse(); out.weights.reverse();
} }
out.knots = if let Some(curve) = super::spline_ops::spline_to_nurbs(sp) {
Spline::generate_clamped_knots(out.degree as usize, out.control_points.len()); out.knots = curve.reversed().knots().to_vec();
}
out.begin_tangent = acadrust::types::Vector3::new(-sp.end_tangent.x, -sp.end_tangent.y, -sp.end_tangent.z);
out.end_tangent = acadrust::types::Vector3::new(-sp.begin_tangent.x, -sp.begin_tangent.y, -sp.begin_tangent.z);
out out
} }