为线的动画做扩展准备

This commit is contained in:
艾竹
2023-04-29 15:29:22 +08:00
parent 7d8b19e4e0
commit f4268b9fc2
23 changed files with 397 additions and 120 deletions

View File

@@ -0,0 +1,96 @@
using System;
using System.Windows.Media;
namespace AIStudio.Wpf.DiagramDesigner
{
[Serializable]
public class AnimationViewModel : BindableBase, IAnimationViewModel
{
private LineAnimation _lineAnimation = LineAnimation.None;
[CanDo]
public LineAnimation LineAnimation
{
get
{
return _lineAnimation;
}
set
{
SetProperty(ref _lineAnimation, value);
}
}
private double _duration = 1;
[CanDo]
public double Duration
{
get
{
return _duration;
}
set
{
SetProperty(ref _duration, value);
}
}
private Color _color = Colors.Red;
[CanDo]
public Color Color
{
get
{
return _color;
}
set
{
if (!SetProperty(ref _color, value))
{
RaisePropertyChanged(nameof(Color));
}
}
}
private string _path = "M 10,20 A 20,20 0 1 1 50,20 A 20,20 0 1 1 10,20";
[CanDo]
public string Path
{
get
{
return _path;
}
set
{
SetProperty(ref _path, value);
}
}
private double _witdh;
[CanDo]
public double Width
{
get
{
return _witdh;
}
set
{
SetProperty(ref _witdh, value);
}
}
private double _height;
[CanDo]
public double Height
{
get
{
return _height;
}
set
{
SetProperty(ref _height, value);
}
}
}
}

View File

@@ -144,34 +144,6 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
}
private LineAnimation _lineAnimation = LineAnimation.None;
[CanDo]
public LineAnimation LineAnimation
{
get
{
return _lineAnimation;
}
set
{
SetProperty(ref _lineAnimation, value);
}
}
private double _lineAnimationDuration = 1;
[CanDo]
public double LineAnimationDuration
{
get
{
return _lineAnimationDuration;
}
set
{
SetProperty(ref _lineAnimationDuration, value);
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace AIStudio.Wpf.DiagramDesigner
{
public interface IAnimationViewModel
{
LineAnimation LineAnimation
{
get; set;
}
double Duration
{
get; set;
}
Color Color
{
get; set;
}
string Path
{
get; set;
}
double Width
{
get; set;
}
double Height
{
get; set;
}
event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@@ -28,15 +28,7 @@ namespace AIStudio.Wpf.DiagramDesigner
LineDashStyle LineDashStyle
{
get; set;
}
LineAnimation LineAnimation
{
get; set;
}
double LineAnimationDuration
{
get; set;
}
}
event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@@ -7,12 +7,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public interface IShapeViewModel
{
ILinkMarker SourceMarker
ISharpPath SourceMarker
{
get; set;
}
ILinkMarker SinkMarker
ISharpPath SinkMarker
{
get; set;
}

View File

@@ -6,8 +6,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public class ShapeViewModel : BindableBase, IShapeViewModel
{
private ILinkMarker _sourceMarker = LinkMarker.None;
public ILinkMarker SourceMarker
private ISharpPath _sourceMarker = SharpPath.None;
public ISharpPath SourceMarker
{
get
{
@@ -17,12 +17,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (_sourceMarker != value)
{
if (_sourceMarker != null && _sourceMarker is LinkMarker _linkMarker1)
if (_sourceMarker != null && _sourceMarker is SharpPath _linkMarker1)
{
_linkMarker1.PropertyChanged -= ShapeViewModel_PropertyChanged;
}
SetProperty(ref _sourceMarker, value);
if (_sourceMarker != null && _sourceMarker is LinkMarker _linkMarker2)
if (_sourceMarker != null && _sourceMarker is SharpPath _linkMarker2)
{
_linkMarker2.PropertyChanged += ShapeViewModel_PropertyChanged;
}
@@ -34,8 +34,8 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private ILinkMarker _sinkMarker = LinkMarker.Arrow;
public ILinkMarker SinkMarker
private ISharpPath _sinkMarker = SharpPath.Arrow;
public ISharpPath SinkMarker
{
get
{
@@ -45,12 +45,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (_sinkMarker != value)
{
if (_sinkMarker != null && _sinkMarker is LinkMarker _linkMarker1)
if (_sinkMarker != null && _sinkMarker is SharpPath _linkMarker1)
{
_linkMarker1.PropertyChanged -= ShapeViewModel_PropertyChanged;
}
SetProperty(ref _sinkMarker, value);
if (_sinkMarker != null && _sinkMarker is LinkMarker _linkMarker2)
if (_sinkMarker != null && _sinkMarker is SharpPath _linkMarker2)
{
_linkMarker2.PropertyChanged += ShapeViewModel_PropertyChanged;
}
@@ -75,12 +75,12 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public class LinkMarker : BindableBase, ILinkMarker
public class SharpPath : BindableBase, ISharpPath
{
public static LinkMarker None { get; } = new LinkMarker("", 10, 10, ArrowPathStyle.None, ArrowSizeStyle.Middle);
public static LinkMarker Arrow { get; } = new LinkMarker("M 0 -5 10 0 0 5 z", 10, 10, ArrowPathStyle.Arrow, ArrowSizeStyle.Middle);
public static LinkMarker Circle { get; } = new LinkMarker("M 0, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0", 10, 10, ArrowPathStyle.Circle, ArrowSizeStyle.Middle);
public static LinkMarker Square { get; } = new LinkMarker("M 0 -5 10 -5 10 5 0 5 z", 10, 10, ArrowPathStyle.Square, ArrowSizeStyle.Middle);
public static SharpPath None { get; } = new SharpPath("", 10, 10, ArrowPathStyle.None, ArrowSizeStyle.Middle);
public static SharpPath Arrow { get; } = new SharpPath("M 0 -5 10 0 0 5 z", 10, 10, ArrowPathStyle.Arrow, ArrowSizeStyle.Middle);
public static SharpPath Circle { get; } = new SharpPath("M 0, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0", 10, 10, ArrowPathStyle.Circle, ArrowSizeStyle.Middle);
public static SharpPath Square { get; } = new SharpPath("M 0 -5 10 -5 10 5 0 5 z", 10, 10, ArrowPathStyle.Square, ArrowSizeStyle.Middle);
public static readonly Dictionary<ArrowPathStyle, string> ArrowDictionary = new Dictionary<ArrowPathStyle, string>()
{
@@ -90,12 +90,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{ ArrowPathStyle.Square, Square.Path },
};
public LinkMarker()
public SharpPath()
{
}
public LinkMarker(string path, double width, double height, ArrowPathStyle arrowPathStyle, ArrowSizeStyle arrowSizeStyle)
public SharpPath(string path, double width, double height, ArrowPathStyle arrowPathStyle, ArrowSizeStyle arrowSizeStyle)
{
Path = path;
Width = width;
@@ -184,19 +184,19 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public static LinkMarker NewArrow(double width, double height)
=> new LinkMarker(FormattableString.Invariant($"M 0 -{height / 2} {width} 0 0 {height / 2}"), width, height, ArrowPathStyle.Arrow, (ArrowSizeStyle)width);
public static SharpPath NewArrow(double width, double height)
=> new SharpPath(FormattableString.Invariant($"M 0 -{height / 2} {width} 0 0 {height / 2}"), width, height, ArrowPathStyle.Arrow, (ArrowSizeStyle)width);
public static LinkMarker NewCircle(double r)
=> new LinkMarker(FormattableString.Invariant($"M 0, 0 a {r},{r} 0 1,0 {r * 2},0 a {r},{r} 0 1,0 -{r * 2},0"), r * 2, r * 2, ArrowPathStyle.Circle, (ArrowSizeStyle)(r * 2));
public static SharpPath NewCircle(double r)
=> new SharpPath(FormattableString.Invariant($"M 0, 0 a {r},{r} 0 1,0 {r * 2},0 a {r},{r} 0 1,0 -{r * 2},0"), r * 2, r * 2, ArrowPathStyle.Circle, (ArrowSizeStyle)(r * 2));
public static LinkMarker NewRectangle(double width, double height)
=> new LinkMarker(FormattableString.Invariant($"M 0 -{height / 2} {width} -{height / 2} {width} {height / 2} 0 {height / 2} z"), width, height, ArrowPathStyle.Square, (ArrowSizeStyle)width);
public static SharpPath NewRectangle(double width, double height)
=> new SharpPath(FormattableString.Invariant($"M 0 -{height / 2} {width} -{height / 2} {width} {height / 2} 0 {height / 2} z"), width, height, ArrowPathStyle.Square, (ArrowSizeStyle)width);
public static LinkMarker NewSquare(double size) => NewRectangle(size, size);
public static SharpPath NewSquare(double size) => NewRectangle(size, size);
}
public interface ILinkMarker
public interface ISharpPath
{
string Path
{

View File

@@ -62,7 +62,7 @@ namespace AIStudio.Wpf.DiagramDesigner
this.Root = root ?? sourceConnectorInfo.Root;
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
{
this.ShapeViewModel.SinkMarker = new LinkMarker("", 10, 10, ArrowPathStyle.None, ArrowSizeStyle.Middle);
this.ShapeViewModel.SinkMarker = new SharpPath("", 10, 10, ArrowPathStyle.None, ArrowSizeStyle.Middle);
}
var routetype = TypeHelper.GetType(RouterMode);
Router = routetype != null ? (System.Activator.CreateInstance(routetype) as IRouter) : new RouterNormal();

View File

@@ -14,6 +14,7 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
ColorViewModel = new ColorViewModel();
FontViewModel = new FontViewModel();
ShapeViewModel = new ShapeViewModel();
AnimationViewModel= new AnimationViewModel();
LockObjectViewModel = new LockObjectViewModel();
_drawModeViewModel = new DrawModeViewModel();
@@ -25,6 +26,7 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
SetOldValue(ColorViewModel, nameof(ColorViewModel));
SetOldValue(FontViewModel, nameof(FontViewModel));
SetOldValue(ShapeViewModel, nameof(ShapeViewModel));
SetOldValue(AnimationViewModel, nameof(AnimationViewModel));
SetOldValue(LockObjectViewModel, nameof(LockObjectViewModel));
}
@@ -51,6 +53,12 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
return CopyHelper.Mapper(viewModel);
}
public IAnimationViewModel CopyDefaultAnimationViewModel()
{
var viewModel = GetOldValue<AnimationViewModel>(nameof(AnimationViewModel));
return CopyHelper.Mapper(viewModel);
}
private IColorViewModel _colorViewModel;
public IColorViewModel ColorViewModel
{
@@ -90,6 +98,19 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
}
}
private IAnimationViewModel _animationViewModel;
public IAnimationViewModel AnimationViewModel
{
get
{
return _animationViewModel;
}
set
{
SetProperty(ref _animationViewModel, value);
}
}
private IDrawModeViewModel _drawModeViewModel;
public IDrawModeViewModel DrawModeViewModel
{
@@ -147,6 +168,7 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
ColorViewModel = GetOldValue<ColorViewModel>(nameof(ColorViewModel));
FontViewModel = GetOldValue<FontViewModel>(nameof(FontViewModel));
ShapeViewModel = GetOldValue<ShapeViewModel>(nameof(ShapeViewModel));
AnimationViewModel = GetOldValue<AnimationViewModel>(nameof(AnimationViewModel));
LockObjectViewModel = GetOldValue<LockObjectViewModel>(nameof(LockObjectViewModel));
}
else
@@ -154,6 +176,7 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
ColorViewModel = _selectedItem.ColorViewModel;
FontViewModel = _selectedItem.FontViewModel;
ShapeViewModel = _selectedItem.ShapeViewModel;
AnimationViewModel = _selectedItem.AnimationViewModel;
LockObjectViewModel = _selectedItem.LockObjectViewModel;
}
}

View File

@@ -87,6 +87,11 @@ namespace AIStudio.Wpf.DiagramDesigner
get; set;
}
public IAnimationViewModel AnimationViewModel
{
get; set;
}
private PageSizeType _pageSizeType = PageSizeType.A4;
public PageSizeType PageSizeType
{
@@ -2971,6 +2976,28 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public void SetAnimation(IAnimationViewModel animationViewModel, string propertyName, List<SelectableDesignerItemViewModelBase> items)
{
if (items.Any())
{
Dictionary<SelectableDesignerItemViewModelBase, object> infos = items.ToDictionary(p => p, p => p.AnimationViewModel.GetPropertyValue(propertyName));
DoCommandManager.DoNewCommand(this.ToString(),
() => {
var value = animationViewModel.GetPropertyValue(propertyName);
foreach (var item in items)
{
item.AnimationViewModel.SetPropertyValue(propertyName, value);
}
},
() => {
foreach (var item in infos)
{
item.Key.AnimationViewModel.SetPropertyValue(propertyName, item.Value);
}
});
}
}
public void SetQuickItem(IQuickThemeViewModel quickThemeViewModel, string propertyName, List<SelectableDesignerItemViewModelBase> items)
{
if (propertyName == nameof(QuickTheme) && quickThemeViewModel.QuickTheme != null)
@@ -2979,19 +3006,19 @@ namespace AIStudio.Wpf.DiagramDesigner
{
Dictionary<SelectableDesignerItemViewModelBase, Tuple<object, object, object, object>> infos
= items.ToDictionary(p => p, p => new Tuple<object, object, object, object>(
p.FontViewModel.GetPropertyValue("FontColor"),
p.FontViewModel.GetPropertyValue("Color"),
p.ColorViewModel.GetPropertyValue("FillColor"),
p.ColorViewModel.GetPropertyValue("LineColor"),
p.ColorViewModel.GetPropertyValue("LineWidth")));
DoCommandManager.DoNewCommand(this.ToString(),
() => {
var value1 = quickThemeViewModel.QuickTheme.FontViewModel.GetPropertyValue("FontColor");
var value1 = quickThemeViewModel.QuickTheme.FontViewModel.GetPropertyValue("Color");
var value2 = quickThemeViewModel.QuickTheme.ColorViewModel.GetPropertyValue("FillColor");
var value3 = quickThemeViewModel.QuickTheme.ColorViewModel.GetPropertyValue("LineColor");
var value4 = quickThemeViewModel.QuickTheme.ColorViewModel.GetPropertyValue("LineWidth");
foreach (var item in items)
{
item.FontViewModel.SetPropertyValue("FontColor", value1);
item.FontViewModel.SetPropertyValue("Color", value1);
item.ColorViewModel.SetPropertyValue("FillColor", value2);
item.ColorViewModel.SetPropertyValue("LineColor", value3);
item.ColorViewModel.SetPropertyValue("LineWidth", value4);
@@ -3000,7 +3027,7 @@ namespace AIStudio.Wpf.DiagramDesigner
() => {
foreach (var item in infos)
{
item.Key.FontViewModel.SetPropertyValue("FontColor", item.Value.Item1);
item.Key.FontViewModel.SetPropertyValue("Color", item.Value.Item1);
item.Key.ColorViewModel.SetPropertyValue("FillColor", item.Value.Item2);
item.Key.ColorViewModel.SetPropertyValue("LineColor", item.Value.Item3);
item.Key.ColorViewModel.SetPropertyValue("LineWidth", item.Value.Item4);

View File

@@ -102,6 +102,15 @@ namespace AIStudio.Wpf.DiagramDesigner
this.ShapeViewModel = _service.CopyDefaultShapeViewModel();
}
if (Root?.AnimationViewModel != null)
{
this.AnimationViewModel = CopyHelper.Mapper(Root.AnimationViewModel);
}
else
{
this.AnimationViewModel = _service.CopyDefaultAnimationViewModel();
}
LockObjectViewModel = new LockObjectViewModel();
if (initNew)
@@ -130,6 +139,7 @@ namespace AIStudio.Wpf.DiagramDesigner
ColorViewModel = CopyHelper.Mapper(designerbase.ColorItem);
FontViewModel = CopyHelper.Mapper<FontViewModel, FontItem>(designerbase.FontItem);
ShapeViewModel = CopyHelper.Mapper(designerbase.SharpItem);
AnimationViewModel = CopyHelper.Mapper(designerbase.AnimationItem);
}
public bool IsLoaded
@@ -367,6 +377,27 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private IAnimationViewModel _animationViewModel;
public IAnimationViewModel AnimationViewModel
{
get
{
return _animationViewModel;
}
set
{
if (_animationViewModel != null)
{
_animationViewModel.PropertyChanged -= AnimationViewModel_PropertyChanged;
}
SetProperty(ref _animationViewModel, value);
if (_animationViewModel != null)
{
_animationViewModel.PropertyChanged += AnimationViewModel_PropertyChanged;
}
}
}
public ILockObjectViewModel LockObjectViewModel
{
get; set;
@@ -459,6 +490,14 @@ namespace AIStudio.Wpf.DiagramDesigner
RaisePropertyChanged(sender, e);
}
protected void AnimationViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (IsLoaded == false) { return; }
RaisePropertyChanged(sender, e);
}
public override string ToString()
{
return $"{Id}-{Name}-{Text}";

View File

@@ -22,6 +22,10 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels
{
get;
}
IAnimationViewModel AnimationViewModel
{
get;
}
IDrawModeViewModel DrawModeViewModel
{
get;
@@ -42,5 +46,6 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels
IColorViewModel CopyDefaultColorViewModel();
IFontViewModel CopyDefaultFontViewModel();
IShapeViewModel CopyDefaultShapeViewModel();
IAnimationViewModel CopyDefaultAnimationViewModel();
}
}

View File

@@ -360,6 +360,10 @@ namespace AIStudio.Wpf.DiagramDesigner
{
get; set;
}
IAnimationViewModel AnimationViewModel
{
get; set;
}
#endregion
DoCommandManager DoCommandManager