2023-01-26 18:27:17 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ShapeViewModel : BindableBase, IShapeViewModel
|
|
|
|
|
|
{
|
2023-04-29 15:29:22 +08:00
|
|
|
|
private ISharpPath _sourceMarker = SharpPath.None;
|
|
|
|
|
|
public ISharpPath SourceMarker
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _sourceMarker;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_sourceMarker != value)
|
|
|
|
|
|
{
|
2023-04-29 15:29:22 +08:00
|
|
|
|
if (_sourceMarker != null && _sourceMarker is SharpPath _linkMarker1)
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
_linkMarker1.PropertyChanged -= ShapeViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
SetProperty(ref _sourceMarker, value);
|
2023-04-29 15:29:22 +08:00
|
|
|
|
if (_sourceMarker != null && _sourceMarker is SharpPath _linkMarker2)
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
_linkMarker2.PropertyChanged += ShapeViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
RaisePropertyChanged(nameof(SourceMarker));
|
2023-02-04 11:16:39 +08:00
|
|
|
|
}
|
2023-01-26 18:27:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
private ISharpPath _sinkMarker = SharpPath.Arrow;
|
|
|
|
|
|
public ISharpPath SinkMarker
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _sinkMarker;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_sinkMarker != value)
|
|
|
|
|
|
{
|
2023-04-29 15:29:22 +08:00
|
|
|
|
if (_sinkMarker != null && _sinkMarker is SharpPath _linkMarker1)
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
_linkMarker1.PropertyChanged -= ShapeViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
SetProperty(ref _sinkMarker, value);
|
2023-04-29 15:29:22 +08:00
|
|
|
|
if (_sinkMarker != null && _sinkMarker is SharpPath _linkMarker2)
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
_linkMarker2.PropertyChanged += ShapeViewModel_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
RaisePropertyChanged(nameof(SinkMarker));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ShapeViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sender == SourceMarker)
|
|
|
|
|
|
{
|
|
|
|
|
|
RaisePropertyChanged(nameof(SourceMarker));
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (sender == SinkMarker)
|
|
|
|
|
|
{
|
|
|
|
|
|
RaisePropertyChanged(nameof(SinkMarker));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
public class SharpPath : BindableBase, ISharpPath
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
2023-04-29 15:29:22 +08:00
|
|
|
|
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);
|
2023-01-26 18:27:17 +08:00
|
|
|
|
|
|
|
|
|
|
public static readonly Dictionary<ArrowPathStyle, string> ArrowDictionary = new Dictionary<ArrowPathStyle, string>()
|
|
|
|
|
|
{
|
|
|
|
|
|
{ ArrowPathStyle.None, None.Path },
|
|
|
|
|
|
{ ArrowPathStyle.Arrow, Arrow.Path },
|
|
|
|
|
|
{ ArrowPathStyle.Circle, Circle.Path },
|
|
|
|
|
|
{ ArrowPathStyle.Square, Square.Path },
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
public SharpPath()
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
public SharpPath(string path, double width, double height, ArrowPathStyle arrowPathStyle, ArrowSizeStyle arrowSizeStyle)
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
Path = path;
|
|
|
|
|
|
Width = width;
|
2023-02-04 11:16:39 +08:00
|
|
|
|
Height = height;
|
2023-01-26 18:27:17 +08:00
|
|
|
|
_pathStyle = arrowPathStyle;
|
|
|
|
|
|
_sizeStyle = arrowSizeStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string _path;
|
2023-04-08 23:38:01 +08:00
|
|
|
|
[CanDo]
|
2023-01-26 18:27:17 +08:00
|
|
|
|
public string Path
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _path;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2023-02-04 11:16:39 +08:00
|
|
|
|
SetProperty(ref _path, value);
|
2023-01-26 18:27:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private double _witdh;
|
2023-04-08 23:38:01 +08:00
|
|
|
|
[CanDo]
|
2023-01-26 18:27:17 +08:00
|
|
|
|
public double Width
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _witdh;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _witdh, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-04 11:16:39 +08:00
|
|
|
|
private double _height;
|
2023-04-08 23:38:01 +08:00
|
|
|
|
[CanDo]
|
2023-02-04 11:16:39 +08:00
|
|
|
|
public double Height
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _height;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _height, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-26 18:27:17 +08:00
|
|
|
|
private ArrowPathStyle _pathStyle = ArrowPathStyle.None;
|
2023-04-08 23:38:01 +08:00
|
|
|
|
[CanDo]
|
2023-01-26 18:27:17 +08:00
|
|
|
|
public ArrowPathStyle PathStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _pathStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SetProperty(ref _pathStyle, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ArrowDictionary.ContainsKey(_pathStyle))
|
|
|
|
|
|
{
|
|
|
|
|
|
Path = ArrowDictionary[_pathStyle];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ArrowSizeStyle _sizeStyle = ArrowSizeStyle.Middle;
|
2023-04-08 23:38:01 +08:00
|
|
|
|
[CanDo]
|
2023-01-26 18:27:17 +08:00
|
|
|
|
public ArrowSizeStyle SizeStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _sizeStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SetProperty(ref _sizeStyle, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
Width = (double)_sizeStyle;
|
2023-02-19 21:38:28 +08:00
|
|
|
|
Height = (double)_sizeStyle;
|
2023-01-26 18:27:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
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);
|
2023-01-26 18:27:17 +08:00
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
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));
|
2023-01-26 18:27:17 +08:00
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
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);
|
2023-01-26 18:27:17 +08:00
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
public static SharpPath NewSquare(double size) => NewRectangle(size, size);
|
2023-01-26 18:27:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-29 15:29:22 +08:00
|
|
|
|
public interface ISharpPath
|
2023-01-26 18:27:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
string Path
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Width
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-04 11:16:39 +08:00
|
|
|
|
double Height
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-26 18:27:17 +08:00
|
|
|
|
ArrowPathStyle PathStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ArrowSizeStyle SizeStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|