rest of DCEL migration
This commit is contained in:
@@ -9,7 +9,6 @@ pub mod add_layer;
|
||||
pub mod add_shape;
|
||||
pub mod modify_shape_path;
|
||||
pub mod move_clip_instances;
|
||||
pub mod move_objects;
|
||||
pub mod paint_bucket;
|
||||
pub mod remove_effect;
|
||||
pub mod set_document_properties;
|
||||
@@ -18,7 +17,6 @@ pub mod set_layer_properties;
|
||||
pub mod set_shape_properties;
|
||||
pub mod split_clip_instance;
|
||||
pub mod transform_clip_instances;
|
||||
pub mod transform_objects;
|
||||
pub mod trim_clip_instances;
|
||||
pub mod create_folder;
|
||||
pub mod rename_folder;
|
||||
@@ -27,7 +25,6 @@ pub mod move_asset_to_folder;
|
||||
pub mod update_midi_notes;
|
||||
pub mod loop_clip_instances;
|
||||
pub mod remove_clip_instances;
|
||||
pub mod remove_shapes;
|
||||
pub mod set_keyframe;
|
||||
pub mod group_shapes;
|
||||
pub mod convert_to_movie_clip;
|
||||
@@ -39,16 +36,14 @@ pub use add_layer::AddLayerAction;
|
||||
pub use add_shape::AddShapeAction;
|
||||
pub use modify_shape_path::ModifyDcelAction;
|
||||
pub use move_clip_instances::MoveClipInstancesAction;
|
||||
pub use move_objects::MoveShapeInstancesAction;
|
||||
pub use paint_bucket::PaintBucketAction;
|
||||
pub use remove_effect::RemoveEffectAction;
|
||||
pub use set_document_properties::SetDocumentPropertiesAction;
|
||||
pub use set_instance_properties::{InstancePropertyChange, SetInstancePropertiesAction};
|
||||
pub use set_layer_properties::{LayerProperty, SetLayerPropertiesAction};
|
||||
pub use set_shape_properties::{SetShapePropertiesAction, ShapePropertyChange};
|
||||
pub use set_shape_properties::SetShapePropertiesAction;
|
||||
pub use split_clip_instance::SplitClipInstanceAction;
|
||||
pub use transform_clip_instances::TransformClipInstancesAction;
|
||||
pub use transform_objects::TransformShapeInstancesAction;
|
||||
pub use trim_clip_instances::{TrimClipInstancesAction, TrimData, TrimType};
|
||||
pub use create_folder::CreateFolderAction;
|
||||
pub use rename_folder::RenameFolderAction;
|
||||
@@ -57,7 +52,6 @@ pub use move_asset_to_folder::MoveAssetToFolderAction;
|
||||
pub use update_midi_notes::UpdateMidiNotesAction;
|
||||
pub use loop_clip_instances::LoopClipInstancesAction;
|
||||
pub use remove_clip_instances::RemoveClipInstancesAction;
|
||||
pub use remove_shapes::RemoveShapesAction;
|
||||
pub use set_keyframe::SetKeyframeAction;
|
||||
pub use group_shapes::GroupAction;
|
||||
pub use convert_to_movie_clip::ConvertToMovieClipAction;
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
//! Move shapes action — STUB: needs DCEL rewrite
|
||||
|
||||
use crate::action::Action;
|
||||
use crate::document::Document;
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
use vello::kurbo::Point;
|
||||
|
||||
/// Action that moves shapes to new positions within a keyframe
|
||||
/// TODO: Replace with DCEL vertex translation
|
||||
pub struct MoveShapeInstancesAction {
|
||||
layer_id: Uuid,
|
||||
time: f64,
|
||||
shape_positions: HashMap<Uuid, (Point, Point)>,
|
||||
}
|
||||
|
||||
impl MoveShapeInstancesAction {
|
||||
pub fn new(layer_id: Uuid, time: f64, shape_positions: HashMap<Uuid, (Point, Point)>) -> Self {
|
||||
Self {
|
||||
layer_id,
|
||||
time,
|
||||
shape_positions,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Action for MoveShapeInstancesAction {
|
||||
fn execute(&mut self, _document: &mut Document) -> Result<(), String> {
|
||||
let _ = (&self.layer_id, self.time, &self.shape_positions);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback(&mut self, _document: &mut Document) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn description(&self) -> String {
|
||||
let count = self.shape_positions.len();
|
||||
if count == 1 {
|
||||
"Move shape".to_string()
|
||||
} else {
|
||||
format!("Move {} shapes", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
//! Remove shapes action — STUB: needs DCEL rewrite
|
||||
|
||||
use crate::action::Action;
|
||||
use crate::document::Document;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Action that removes shapes from a vector layer's keyframe
|
||||
/// TODO: Replace with DCEL edge/face removal actions
|
||||
pub struct RemoveShapesAction {
|
||||
layer_id: Uuid,
|
||||
shape_ids: Vec<Uuid>,
|
||||
time: f64,
|
||||
}
|
||||
|
||||
impl RemoveShapesAction {
|
||||
pub fn new(layer_id: Uuid, shape_ids: Vec<Uuid>, time: f64) -> Self {
|
||||
Self {
|
||||
layer_id,
|
||||
shape_ids,
|
||||
time,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Action for RemoveShapesAction {
|
||||
fn execute(&mut self, _document: &mut Document) -> Result<(), String> {
|
||||
let _ = (&self.layer_id, &self.shape_ids, self.time);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback(&mut self, _document: &mut Document) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn description(&self) -> String {
|
||||
let count = self.shape_ids.len();
|
||||
if count == 1 {
|
||||
"Delete shape".to_string()
|
||||
} else {
|
||||
format!("Delete {} shapes", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1,170 @@
|
||||
//! Set shape properties action — STUB: needs DCEL rewrite
|
||||
//! Set shape properties action — operates on DCEL edge/face IDs.
|
||||
|
||||
use crate::action::Action;
|
||||
use crate::dcel::{EdgeId, FaceId};
|
||||
use crate::document::Document;
|
||||
use crate::layer::AnyLayer;
|
||||
use crate::shape::ShapeColor;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Property change for a shape
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ShapePropertyChange {
|
||||
FillColor(Option<ShapeColor>),
|
||||
StrokeColor(Option<ShapeColor>),
|
||||
StrokeWidth(f64),
|
||||
}
|
||||
|
||||
/// Action that sets properties on a shape
|
||||
/// TODO: Replace with DCEL face/edge property changes
|
||||
/// Action that sets fill/stroke properties on DCEL elements.
|
||||
pub struct SetShapePropertiesAction {
|
||||
layer_id: Uuid,
|
||||
shape_id: Uuid,
|
||||
time: f64,
|
||||
new_value: ShapePropertyChange,
|
||||
old_value: Option<ShapePropertyChange>,
|
||||
change: PropertyChange,
|
||||
old_edge_values: Vec<(EdgeId, Option<ShapeColor>, Option<f64>)>,
|
||||
old_face_values: Vec<(FaceId, Option<ShapeColor>)>,
|
||||
}
|
||||
|
||||
enum PropertyChange {
|
||||
FillColor {
|
||||
face_ids: Vec<FaceId>,
|
||||
color: Option<ShapeColor>,
|
||||
},
|
||||
StrokeColor {
|
||||
edge_ids: Vec<EdgeId>,
|
||||
color: Option<ShapeColor>,
|
||||
},
|
||||
StrokeWidth {
|
||||
edge_ids: Vec<EdgeId>,
|
||||
width: f64,
|
||||
},
|
||||
}
|
||||
|
||||
impl SetShapePropertiesAction {
|
||||
pub fn new(layer_id: Uuid, shape_id: Uuid, time: f64, new_value: ShapePropertyChange) -> Self {
|
||||
pub fn set_fill_color(
|
||||
layer_id: Uuid,
|
||||
time: f64,
|
||||
face_ids: Vec<FaceId>,
|
||||
color: Option<ShapeColor>,
|
||||
) -> Self {
|
||||
Self {
|
||||
layer_id,
|
||||
shape_id,
|
||||
time,
|
||||
new_value,
|
||||
old_value: None,
|
||||
change: PropertyChange::FillColor { face_ids, color },
|
||||
old_edge_values: Vec::new(),
|
||||
old_face_values: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_fill_color(layer_id: Uuid, shape_id: Uuid, time: f64, color: Option<ShapeColor>) -> Self {
|
||||
Self::new(layer_id, shape_id, time, ShapePropertyChange::FillColor(color))
|
||||
pub fn set_stroke_color(
|
||||
layer_id: Uuid,
|
||||
time: f64,
|
||||
edge_ids: Vec<EdgeId>,
|
||||
color: Option<ShapeColor>,
|
||||
) -> Self {
|
||||
Self {
|
||||
layer_id,
|
||||
time,
|
||||
change: PropertyChange::StrokeColor { edge_ids, color },
|
||||
old_edge_values: Vec::new(),
|
||||
old_face_values: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_stroke_color(layer_id: Uuid, shape_id: Uuid, time: f64, color: Option<ShapeColor>) -> Self {
|
||||
Self::new(layer_id, shape_id, time, ShapePropertyChange::StrokeColor(color))
|
||||
pub fn set_stroke_width(
|
||||
layer_id: Uuid,
|
||||
time: f64,
|
||||
edge_ids: Vec<EdgeId>,
|
||||
width: f64,
|
||||
) -> Self {
|
||||
Self {
|
||||
layer_id,
|
||||
time,
|
||||
change: PropertyChange::StrokeWidth { edge_ids, width },
|
||||
old_edge_values: Vec::new(),
|
||||
old_face_values: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_stroke_width(layer_id: Uuid, shape_id: Uuid, time: f64, width: f64) -> Self {
|
||||
Self::new(layer_id, shape_id, time, ShapePropertyChange::StrokeWidth(width))
|
||||
fn get_dcel_mut<'a>(
|
||||
document: &'a mut Document,
|
||||
layer_id: &Uuid,
|
||||
time: f64,
|
||||
) -> Result<&'a mut crate::dcel::Dcel, String> {
|
||||
let layer = document
|
||||
.get_layer_mut(layer_id)
|
||||
.ok_or_else(|| format!("Layer {} not found", layer_id))?;
|
||||
let vl = match layer {
|
||||
AnyLayer::Vector(vl) => vl,
|
||||
_ => return Err("Not a vector layer".to_string()),
|
||||
};
|
||||
vl.dcel_at_time_mut(time)
|
||||
.ok_or_else(|| format!("No keyframe at time {}", time))
|
||||
}
|
||||
}
|
||||
|
||||
impl Action for SetShapePropertiesAction {
|
||||
fn execute(&mut self, _document: &mut Document) -> Result<(), String> {
|
||||
let _ = (&self.layer_id, &self.shape_id, self.time, &self.new_value);
|
||||
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
let dcel = Self::get_dcel_mut(document, &self.layer_id, self.time)?;
|
||||
|
||||
match &self.change {
|
||||
PropertyChange::FillColor { face_ids, color } => {
|
||||
self.old_face_values.clear();
|
||||
for &fid in face_ids {
|
||||
let face = dcel.face(fid);
|
||||
self.old_face_values.push((fid, face.fill_color));
|
||||
dcel.face_mut(fid).fill_color = *color;
|
||||
}
|
||||
}
|
||||
PropertyChange::StrokeColor { edge_ids, color } => {
|
||||
self.old_edge_values.clear();
|
||||
for &eid in edge_ids {
|
||||
let edge = dcel.edge(eid);
|
||||
let old_width = edge.stroke_style.as_ref().map(|s| s.width);
|
||||
self.old_edge_values.push((eid, edge.stroke_color, old_width));
|
||||
dcel.edge_mut(eid).stroke_color = *color;
|
||||
}
|
||||
}
|
||||
PropertyChange::StrokeWidth { edge_ids, width } => {
|
||||
self.old_edge_values.clear();
|
||||
for &eid in edge_ids {
|
||||
let edge = dcel.edge(eid);
|
||||
let old_width = edge.stroke_style.as_ref().map(|s| s.width);
|
||||
self.old_edge_values.push((eid, edge.stroke_color, old_width));
|
||||
if let Some(ref mut style) = dcel.edge_mut(eid).stroke_style {
|
||||
style.width = *width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback(&mut self, _document: &mut Document) -> Result<(), String> {
|
||||
let _ = &self.old_value;
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
let dcel = Self::get_dcel_mut(document, &self.layer_id, self.time)?;
|
||||
|
||||
match &self.change {
|
||||
PropertyChange::FillColor { .. } => {
|
||||
for &(fid, old_color) in &self.old_face_values {
|
||||
dcel.face_mut(fid).fill_color = old_color;
|
||||
}
|
||||
}
|
||||
PropertyChange::StrokeColor { .. } => {
|
||||
for &(eid, old_color, _) in &self.old_edge_values {
|
||||
dcel.edge_mut(eid).stroke_color = old_color;
|
||||
}
|
||||
}
|
||||
PropertyChange::StrokeWidth { .. } => {
|
||||
for &(eid, _, old_width) in &self.old_edge_values {
|
||||
if let Some(w) = old_width {
|
||||
if let Some(ref mut style) = dcel.edge_mut(eid).stroke_style {
|
||||
style.width = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn description(&self) -> String {
|
||||
match &self.new_value {
|
||||
ShapePropertyChange::FillColor(_) => "Set fill color".to_string(),
|
||||
ShapePropertyChange::StrokeColor(_) => "Set stroke color".to_string(),
|
||||
ShapePropertyChange::StrokeWidth(_) => "Set stroke width".to_string(),
|
||||
match &self.change {
|
||||
PropertyChange::FillColor { .. } => "Set fill color".to_string(),
|
||||
PropertyChange::StrokeColor { .. } => "Set stroke color".to_string(),
|
||||
PropertyChange::StrokeWidth { .. } => "Set stroke width".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
//! Transform shapes action — STUB: needs DCEL rewrite
|
||||
|
||||
use crate::action::Action;
|
||||
use crate::document::Document;
|
||||
use crate::object::Transform;
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Action to transform multiple shapes in a keyframe
|
||||
/// TODO: Replace with DCEL-based transforms (affine on vertices/edges)
|
||||
pub struct TransformShapeInstancesAction {
|
||||
layer_id: Uuid,
|
||||
time: f64,
|
||||
shape_transforms: HashMap<Uuid, (Transform, Transform)>,
|
||||
}
|
||||
|
||||
impl TransformShapeInstancesAction {
|
||||
pub fn new(
|
||||
layer_id: Uuid,
|
||||
time: f64,
|
||||
shape_transforms: HashMap<Uuid, (Transform, Transform)>,
|
||||
) -> Self {
|
||||
Self {
|
||||
layer_id,
|
||||
time,
|
||||
shape_transforms,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Action for TransformShapeInstancesAction {
|
||||
fn execute(&mut self, _document: &mut Document) -> Result<(), String> {
|
||||
let _ = (&self.layer_id, self.time, &self.shape_transforms);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback(&mut self, _document: &mut Document) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn description(&self) -> String {
|
||||
format!("Transform {} shape(s)", self.shape_transforms.len())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user