mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-03 07:36:35 +08:00
整理一下项目文件
This commit is contained in:
@@ -0,0 +1,519 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
[Serializable]
|
||||
public class ColorViewModel : BindableBase, IColorViewModel
|
||||
{
|
||||
#region 界面使用
|
||||
public static Color[] FillColors { get; } = new Color[] { Colors.Red, Colors.Green, Colors.Blue, Colors.White, Colors.Black, Colors.Purple };
|
||||
public static Color[] LineColors { get; } = new Color[] { Colors.Red, Colors.Green, Colors.Blue, Colors.White, Colors.Black, Colors.Purple };
|
||||
#endregion
|
||||
|
||||
public ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Colors.Gray };
|
||||
FillColor = new ColorObject() { Color = Colors.Transparent };
|
||||
}
|
||||
private IColorObject _lineColor;
|
||||
public IColorObject LineColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lineColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_lineColor != value)
|
||||
{
|
||||
if (_lineColor != null && _lineColor is ColorObject _lineColor1)
|
||||
{
|
||||
_lineColor1.PropertyChanged -= ColorViewModel_PropertyChanged;
|
||||
}
|
||||
SetProperty(ref _lineColor, value);
|
||||
if (_lineColor != null && _lineColor is ColorObject _lineColor2)
|
||||
{
|
||||
_lineColor2.PropertyChanged += ColorViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RaisePropertyChanged(nameof(LineColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IColorObject _fillcolor;
|
||||
public IColorObject FillColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fillcolor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_fillcolor != value)
|
||||
{
|
||||
if (_fillcolor != null && _fillcolor is ColorObject colorObject1)
|
||||
{
|
||||
colorObject1.PropertyChanged -= ColorViewModel_PropertyChanged;
|
||||
}
|
||||
SetProperty(ref _fillcolor, value);
|
||||
if (_fillcolor != null && _fillcolor is ColorObject colorObject2)
|
||||
{
|
||||
colorObject2.PropertyChanged += ColorViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RaisePropertyChanged(nameof(FillColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ColorViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (sender == LineColor)
|
||||
{
|
||||
RaisePropertyChanged(nameof(LineColor));
|
||||
}
|
||||
else if (sender == FillColor)
|
||||
{
|
||||
RaisePropertyChanged(nameof(FillColor));
|
||||
}
|
||||
}
|
||||
|
||||
private Color _shadowColor = Colors.Transparent;
|
||||
public Color ShadowColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _shadowColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _shadowColor, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(ShadowColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double _lineWidth = 1;
|
||||
public double LineWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lineWidth;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _lineWidth, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(LineWidth));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrowPathStyle _leftArrowPathStyle = ArrowPathStyle.None;
|
||||
public ArrowPathStyle LeftArrowPathStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _leftArrowPathStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _leftArrowPathStyle, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(LeftArrowPathStyle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrowPathStyle _rightArrowPathStyle = ArrowPathStyle.Arrow1;
|
||||
public ArrowPathStyle RightArrowPathStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _rightArrowPathStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _rightArrowPathStyle, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(RightArrowPathStyle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrowSizeStyle _leftArrowSizeStyle = ArrowSizeStyle.Middle;
|
||||
public ArrowSizeStyle LeftArrowSizeStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _leftArrowSizeStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _leftArrowSizeStyle, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(LeftArrowSizeStyle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrowSizeStyle _rightArrowSizeStyle = ArrowSizeStyle.Middle;
|
||||
public ArrowSizeStyle RightArrowSizeStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _rightArrowSizeStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _rightArrowSizeStyle, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(RightArrowSizeStyle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LineDashStyle _lineDashStyle = LineDashStyle.None;
|
||||
public LineDashStyle LineDashStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lineDashStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _lineDashStyle, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(LineDashStyle));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class ColorObject : BindableBase, IColorObject
|
||||
{
|
||||
public ColorObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void GradientStop_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (e.OldItems != null)
|
||||
{
|
||||
foreach (var old in e.OldItems.OfType<GradientStop>())
|
||||
{
|
||||
old.PropertyChanged -= GradientStop_PropertyChanged;
|
||||
}
|
||||
}
|
||||
if (e.NewItems != null)
|
||||
{
|
||||
foreach (var old in e.NewItems.OfType<GradientStop>())
|
||||
{
|
||||
old.PropertyChanged += GradientStop_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GradientStop_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
RaisePropertyChanged(nameof(GradientStop));
|
||||
}
|
||||
|
||||
|
||||
public void BrushTypeChanged()
|
||||
{
|
||||
if (BrushType == BrushType.LinearGradientBrush || BrushType == BrushType.RadialGradientBrush)
|
||||
{
|
||||
if (GradientStop == null)
|
||||
{
|
||||
GradientStop = new ObservableCollection<GradientStop>();
|
||||
GradientStop.Add(new GradientStop(Color, 0));
|
||||
GradientStop.Add(new GradientStop(Colors.Gray, 1));
|
||||
SelectedGradientStop = GradientStop.FirstOrDefault();
|
||||
RaisePropertyChanged(nameof(GradientStop));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BrushType _brushType = BrushType.SolidColorBrush;
|
||||
public BrushType BrushType
|
||||
{
|
||||
get
|
||||
{
|
||||
return _brushType;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _brushType, value))
|
||||
{
|
||||
BrushTypeChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color _color = new Color();
|
||||
public Color Color
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _color, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private ObservableCollection<GradientStop> _gradientStop;
|
||||
public ObservableCollection<GradientStop> GradientStop
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gradientStop;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_gradientStop != value)
|
||||
{
|
||||
if (_gradientStop != null)
|
||||
{
|
||||
_gradientStop.CollectionChanged -= GradientStop_CollectionChanged;
|
||||
}
|
||||
SetProperty(ref _gradientStop, value);
|
||||
if (_gradientStop != null)
|
||||
{
|
||||
_gradientStop.CollectionChanged += GradientStop_CollectionChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GradientStop _selectedGradientStop;
|
||||
public GradientStop SelectedGradientStop
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedGradientStop;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedGradientStop, value);
|
||||
}
|
||||
}
|
||||
private Point _startPoint;
|
||||
public Point StartPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _startPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _startPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Point _endPoint;
|
||||
public Point EndPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _endPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _endPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _opacity = 1;
|
||||
public double Opacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _opacity;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _opacity, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _light;
|
||||
public double Light
|
||||
{
|
||||
get
|
||||
{
|
||||
return _light;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _light, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _image;
|
||||
public string Image
|
||||
{
|
||||
get
|
||||
{
|
||||
return _image;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _image, value);
|
||||
}
|
||||
}
|
||||
|
||||
private LinearOrientation _linearOrientation;
|
||||
public LinearOrientation LinearOrientation
|
||||
{
|
||||
get
|
||||
{
|
||||
return _linearOrientation;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _linearOrientation, value);
|
||||
}
|
||||
}
|
||||
|
||||
private RadialOrientation _radialOrientation;
|
||||
public RadialOrientation RadialOrientation
|
||||
{
|
||||
get
|
||||
{
|
||||
return _radialOrientation;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _radialOrientation, value);
|
||||
}
|
||||
}
|
||||
|
||||
private int _angle;
|
||||
public int Angle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _angle;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _angle, value);
|
||||
}
|
||||
}
|
||||
|
||||
private int _subType;
|
||||
|
||||
public int SubType
|
||||
{
|
||||
get
|
||||
{
|
||||
return _subType;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _subType, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand AddGradientStopCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
var offset = GradientStop.Skip(GradientStop.Count - 2).Select(p => p.Offset).Average();
|
||||
GradientStop.Add(new GradientStop(Colors.Gray, offset));
|
||||
});
|
||||
}
|
||||
}
|
||||
public ICommand DeleteGradientStopCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
if (SelectedGradientStop != null && GradientStop != null && GradientStop.Count > 2)
|
||||
{
|
||||
GradientStop.Remove(SelectedGradientStop);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IColorObject
|
||||
{
|
||||
BrushType BrushType { get; set; }
|
||||
Color Color { get; set; }
|
||||
ObservableCollection<GradientStop> GradientStop { get; set; }
|
||||
Point StartPoint { get; set; }
|
||||
Point EndPoint { get; set; }
|
||||
double Opacity { get; set; }
|
||||
LinearOrientation LinearOrientation { get; set; }
|
||||
RadialOrientation RadialOrientation { get; set; }
|
||||
int Angle { get; set; }
|
||||
string Image { get; set; }
|
||||
int SubType { get; set; }
|
||||
}
|
||||
|
||||
public class GradientStop : BindableBase
|
||||
{
|
||||
public GradientStop()
|
||||
{
|
||||
|
||||
}
|
||||
public GradientStop(Color color, double offset)
|
||||
{
|
||||
Color = color;
|
||||
Offset = offset;
|
||||
}
|
||||
private Color _color = new Color();
|
||||
public Color Color
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _color, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _offset;
|
||||
public double Offset
|
||||
{
|
||||
get
|
||||
{
|
||||
return _offset;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple service interface
|
||||
/// </summary>
|
||||
public interface IDiagramServiceProvider : INotifyPropertyChanged
|
||||
{
|
||||
IColorViewModel ColorViewModel { get; }
|
||||
IFontViewModel FontViewModel { get; }
|
||||
IDrawModeViewModel DrawModeViewModel { get; }
|
||||
IQuickThemeViewModel QuickThemeViewModel { get; }
|
||||
ILockObjectViewModel LockObjectViewModel { get; }
|
||||
SelectableDesignerItemViewModelBase SelectedItem { get; set; }
|
||||
IColorViewModel CopyDefaultColorViewModel();
|
||||
IFontViewModel CopyDefaultFontViewModel();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Simple service locator
|
||||
/// </summary>
|
||||
public class DiagramServiceProvider : BindableBase, IDiagramServiceProvider
|
||||
{
|
||||
public DiagramServiceProvider()
|
||||
{
|
||||
ColorViewModel = new ColorViewModel();
|
||||
FontViewModel = new FontViewModel();
|
||||
LockObjectViewModel = new LockObjectViewModel();
|
||||
_drawModeViewModel = new DrawModeViewModel();
|
||||
_quickThemeViewModel = new QuickThemeViewModel();
|
||||
|
||||
_drawModeViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
_quickThemeViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
|
||||
SetOldValue<IColorViewModel>(ColorViewModel, nameof(ColorViewModel));
|
||||
SetOldValue<IFontViewModel>(FontViewModel, nameof(FontViewModel));
|
||||
SetOldValue<ILockObjectViewModel>(LockObjectViewModel, nameof(LockObjectViewModel));
|
||||
}
|
||||
|
||||
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
RaisePropertyChanged(sender, e.PropertyName);
|
||||
}
|
||||
|
||||
public IColorViewModel CopyDefaultColorViewModel()
|
||||
{
|
||||
var viewModel = GetOldValue<ColorViewModel>(nameof(ColorViewModel));
|
||||
return CopyHelper.Mapper(viewModel);
|
||||
}
|
||||
|
||||
public IFontViewModel CopyDefaultFontViewModel()
|
||||
{
|
||||
var viewModel = GetOldValue<FontViewModel>(nameof(FontViewModel));
|
||||
return CopyHelper.Mapper<FontViewModel, IFontViewModel>(viewModel);
|
||||
}
|
||||
|
||||
private IColorViewModel _colorViewModel;
|
||||
public IColorViewModel ColorViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_colorViewModel != null)
|
||||
{
|
||||
_colorViewModel.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
}
|
||||
SetProperty(ref _colorViewModel, value);
|
||||
if (_colorViewModel != null)
|
||||
{
|
||||
_colorViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IFontViewModel _fontViewModel;
|
||||
public IFontViewModel FontViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_fontViewModel != null)
|
||||
{
|
||||
_fontViewModel.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
}
|
||||
SetProperty(ref _fontViewModel, value);
|
||||
if (_fontViewModel != null)
|
||||
{
|
||||
_fontViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DrawModeViewModel _drawModeViewModel;
|
||||
public IDrawModeViewModel DrawModeViewModel
|
||||
{
|
||||
get { return _drawModeViewModel; }
|
||||
}
|
||||
|
||||
private QuickThemeViewModel _quickThemeViewModel;
|
||||
public IQuickThemeViewModel QuickThemeViewModel
|
||||
{
|
||||
get { return _quickThemeViewModel; }
|
||||
}
|
||||
|
||||
private ILockObjectViewModel _lockObjectViewModel;
|
||||
public ILockObjectViewModel LockObjectViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lockObjectViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_lockObjectViewModel != null)
|
||||
{
|
||||
_lockObjectViewModel.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
}
|
||||
SetProperty(ref _lockObjectViewModel, value);
|
||||
if (_lockObjectViewModel != null)
|
||||
{
|
||||
_lockObjectViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SelectableDesignerItemViewModelBase _selectedItem;
|
||||
public SelectableDesignerItemViewModelBase SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedItem;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
}
|
||||
if (SetProperty(ref _selectedItem, value))
|
||||
{
|
||||
if (_selectedItem == null)
|
||||
{
|
||||
ColorViewModel = GetOldValue<ColorViewModel>(nameof(ColorViewModel));
|
||||
FontViewModel = GetOldValue<FontViewModel>(nameof(FontViewModel));
|
||||
LockObjectViewModel = GetOldValue<LockObjectViewModel>(nameof(LockObjectViewModel));
|
||||
}
|
||||
else
|
||||
{
|
||||
ColorViewModel = _selectedItem.ColorViewModel;
|
||||
FontViewModel = _selectedItem.FontViewModel;
|
||||
LockObjectViewModel = _selectedItem.LockObjectViewModel;
|
||||
}
|
||||
}
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.PropertyChanged += ViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Simple service locator helper
|
||||
/// </summary>
|
||||
public class DiagramServicesProvider
|
||||
{
|
||||
private static Lazy<DiagramServicesProvider> instance = new Lazy<DiagramServicesProvider>(() => new DiagramServicesProvider());
|
||||
private IDiagramServiceProvider serviceProvider = new DiagramServiceProvider();
|
||||
|
||||
public void SetNewServiceProvider(IDiagramServiceProvider provider)
|
||||
{
|
||||
serviceProvider = provider;
|
||||
}
|
||||
|
||||
public IDiagramServiceProvider Provider
|
||||
{
|
||||
get { return serviceProvider; }
|
||||
}
|
||||
|
||||
public static DiagramServicesProvider Instance
|
||||
{
|
||||
get { return instance.Value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DrawModeViewModel : BindableBase, IDrawModeViewModel
|
||||
{
|
||||
public DrawMode GetDrawMode()
|
||||
{
|
||||
if (CursorDrawModeSelected)
|
||||
{
|
||||
return CursorDrawMode;
|
||||
}
|
||||
else if (VectorLineDrawModeSelected)
|
||||
{
|
||||
return VectorLineDrawMode;
|
||||
}
|
||||
else if (ShapeDrawModeSelected)
|
||||
{
|
||||
return ShapeDrawMode;
|
||||
}
|
||||
else if (TextDrawModeSelected)
|
||||
{
|
||||
return TextDrawMode;
|
||||
}
|
||||
|
||||
return DrawMode.Normal;
|
||||
}
|
||||
|
||||
public void ResetDrawMode()
|
||||
{
|
||||
CursorDrawModeSelected = true;
|
||||
CursorDrawMode = DrawMode.Normal;
|
||||
}
|
||||
|
||||
public void SetDrawMode(DrawMode drawMode)
|
||||
{
|
||||
CursorDrawMode = drawMode;
|
||||
}
|
||||
|
||||
private bool _cursordrawModeSelected = true;
|
||||
public bool CursorDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cursordrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _cursordrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _vectorLineDrawModeSelected;
|
||||
public bool VectorLineDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _vectorLineDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _vectorLineDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _shapeDrawModeSelected;
|
||||
public bool ShapeDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _shapeDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _shapeDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _textDrawModeSelected;
|
||||
public bool TextDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _textDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _textDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode _cursordrawMode = DrawMode.Normal;
|
||||
public DrawMode CursorDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cursordrawMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _cursordrawMode, value);
|
||||
CursorDrawModeSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode _vectorLineDrawMode = DrawMode.CornerConnectingLine;
|
||||
public DrawMode VectorLineDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _vectorLineDrawMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _vectorLineDrawMode, value);
|
||||
VectorLineDrawModeSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode _shapeDrawMode = DrawMode.Rectangle;
|
||||
public DrawMode ShapeDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _shapeDrawMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _shapeDrawMode, value);
|
||||
ShapeDrawModeSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode _textDrawMode = DrawMode.Text;
|
||||
public DrawMode TextDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _textDrawMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _textDrawMode, value);
|
||||
TextDrawModeSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private CursorMode _cursorMode;
|
||||
public CursorMode CursorMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cursorMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _cursorMode, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class FontViewModel : BindableBase, IFontViewModel
|
||||
{
|
||||
#region 界面使用
|
||||
static FontViewModel()
|
||||
{
|
||||
var systemFontFamilies = new List<FontFamily>();
|
||||
foreach (FontFamily _f in Fonts.SystemFontFamilies)
|
||||
{
|
||||
LanguageSpecificStringDictionary _fontDic = _f.FamilyNames;
|
||||
if (_fontDic.ContainsKey(XmlLanguage.GetLanguage("zh-cn")))
|
||||
{
|
||||
string _fontName = null;
|
||||
if (_fontDic.TryGetValue(XmlLanguage.GetLanguage("zh-cn"), out _fontName))
|
||||
{
|
||||
systemFontFamilies.Add(new FontFamily(_fontName));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string _fontName = null;
|
||||
if (_fontDic.TryGetValue(XmlLanguage.GetLanguage("en-us"), out _fontName))
|
||||
{
|
||||
systemFontFamilies.Add(new FontFamily(_fontName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FontFamilys = systemFontFamilies.Select(fontFamily => fontFamily.ToString()).ToArray();
|
||||
}
|
||||
public static string[] FontFamilys { get; }
|
||||
public static double[] FontSizes { get; } = new double[] { 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 48, 72 };
|
||||
public static FontCase[] FontCases { get; } = new FontCase[] { FontCase.None, FontCase.Upper, FontCase.Lower };
|
||||
public static Color[] FontColors { get; } = new Color[] { Colors.Red, Colors.Green, Colors.Blue, Colors.White, Colors.Black, Colors.Purple };
|
||||
|
||||
public ICommand GrowFontCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
if (FontSize < 72)
|
||||
FontSize++;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand ShrinkFontCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
if (FontSize > 1)
|
||||
FontSize--;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand ClearFormattingCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
FontFamily = "Arial";
|
||||
FontSize = 12;
|
||||
FontColor = Colors.Black;
|
||||
FontWeight = FontWeights.Regular;
|
||||
FontStyle = FontStyles.Normal;
|
||||
FontStretch = FontStretches.Normal;
|
||||
Underline = false;
|
||||
Strikethrough = false;
|
||||
OverLine = false;
|
||||
TextEffectColor = Colors.Transparent;
|
||||
HighlightColor = Colors.Transparent;
|
||||
FontCase = FontCase.None;
|
||||
HorizontalAlignment = HorizontalAlignment.Center;
|
||||
VerticalAlignment = VerticalAlignment.Center;
|
||||
LineHeight = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand TextEffectColorCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
TextEffectColor = (Color)para;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand HighlightColorCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
HighlightColor = (Color)para;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand FontColorCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
FontColor = (Color)para;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private HorizontalVerticalAlignment _horizontalVerticalAlignment = HorizontalVerticalAlignment.CenterAlignCenter;
|
||||
public HorizontalVerticalAlignment HorizontalVerticalAlignment
|
||||
{
|
||||
get
|
||||
{
|
||||
return _horizontalVerticalAlignment;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _horizontalVerticalAlignment, value))
|
||||
{
|
||||
_horizontalVerticalAlignment = value;
|
||||
switch (value)
|
||||
{
|
||||
case HorizontalVerticalAlignment.TopAlignLeft:
|
||||
HorizontalAlignment = HorizontalAlignment.Left;
|
||||
VerticalAlignment = VerticalAlignment.Top;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.TopAlignCenter:
|
||||
HorizontalAlignment = HorizontalAlignment.Center;
|
||||
VerticalAlignment = VerticalAlignment.Top;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.TopAlignRight:
|
||||
HorizontalAlignment = HorizontalAlignment.Right;
|
||||
VerticalAlignment = VerticalAlignment.Top;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.TopAlignJustify:
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
VerticalAlignment = VerticalAlignment.Top;
|
||||
break;
|
||||
|
||||
case HorizontalVerticalAlignment.CenterAlignLeft:
|
||||
HorizontalAlignment = HorizontalAlignment.Left;
|
||||
VerticalAlignment = VerticalAlignment.Center;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.CenterAlignCenter:
|
||||
HorizontalAlignment = HorizontalAlignment.Center;
|
||||
VerticalAlignment = VerticalAlignment.Center;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.CenterAlignRight:
|
||||
HorizontalAlignment = HorizontalAlignment.Right;
|
||||
VerticalAlignment = VerticalAlignment.Center;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.CenterAlignJustify:
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
VerticalAlignment = VerticalAlignment.Center;
|
||||
break;
|
||||
|
||||
case HorizontalVerticalAlignment.BottomAlignLeft:
|
||||
HorizontalAlignment = HorizontalAlignment.Left;
|
||||
VerticalAlignment = VerticalAlignment.Bottom;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.BottomAlignCenter:
|
||||
HorizontalAlignment = HorizontalAlignment.Center;
|
||||
VerticalAlignment = VerticalAlignment.Bottom;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.BottomAlignRight:
|
||||
HorizontalAlignment = HorizontalAlignment.Right;
|
||||
VerticalAlignment = VerticalAlignment.Bottom;
|
||||
break;
|
||||
case HorizontalVerticalAlignment.BottomAlignJustify:
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
VerticalAlignment = VerticalAlignment.Bottom;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private string _fontFamily = "Arial";
|
||||
public string FontFamily
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontFamily;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _fontFamily, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(FontFamily));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double _fontSize = 12;
|
||||
public double FontSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _fontSize, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(FontSize));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Color _fontColor = Colors.Black;
|
||||
public Color FontColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _fontColor, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(FontColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FontWeight _fontWeight = FontWeights.Regular;
|
||||
|
||||
public FontWeight FontWeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontWeight;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _fontWeight, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(FontWeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FontStyle _fontStyle = FontStyles.Normal;
|
||||
public FontStyle FontStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _fontStyle, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(FontStyle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FontStretch _fontStretch = FontStretches.Normal;
|
||||
|
||||
public FontStretch FontStretch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontStretch;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _fontStretch, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(FontStretch));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _underline;
|
||||
public bool Underline
|
||||
{
|
||||
get
|
||||
{
|
||||
return _underline;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _underline, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(TextDecorations));
|
||||
}
|
||||
else
|
||||
{
|
||||
RaisePropertyChanged(nameof(Underline));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _strikethrough;
|
||||
public bool Strikethrough
|
||||
{
|
||||
get
|
||||
{
|
||||
return _strikethrough;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _strikethrough, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(TextDecorations));
|
||||
}
|
||||
else
|
||||
{
|
||||
RaisePropertyChanged(nameof(Strikethrough));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _overLine;
|
||||
public bool OverLine
|
||||
{
|
||||
get
|
||||
{
|
||||
return _overLine;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _overLine, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(TextDecorations));
|
||||
}
|
||||
else
|
||||
{
|
||||
RaisePropertyChanged(nameof(OverLine));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TextDecorationCollection _textDecorations;
|
||||
|
||||
public TextDecorationCollection TextDecorations
|
||||
{
|
||||
get
|
||||
{
|
||||
_textDecorations = new TextDecorationCollection();
|
||||
if (Underline)
|
||||
{
|
||||
_textDecorations.Add(System.Windows.TextDecorations.Underline);
|
||||
}
|
||||
if (Strikethrough)
|
||||
{
|
||||
_textDecorations.Add(System.Windows.TextDecorations.Strikethrough);
|
||||
}
|
||||
if (OverLine)
|
||||
{
|
||||
_textDecorations.Add(System.Windows.TextDecorations.OverLine);
|
||||
}
|
||||
return _textDecorations;
|
||||
}
|
||||
//set
|
||||
//{
|
||||
// NotifyChanged(nameof(TextDecorations));
|
||||
//}
|
||||
}
|
||||
|
||||
private Color _textEffectColor = Colors.Transparent;
|
||||
public Color TextEffectColor
|
||||
{
|
||||
get { return _textEffectColor; }
|
||||
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _textEffectColor, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(TextEffectColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color _highlightColor = Colors.Transparent;
|
||||
public Color HighlightColor
|
||||
{
|
||||
get { return _highlightColor; }
|
||||
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _highlightColor, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(HighlightColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FontCase _fontCase = FontCase.None;
|
||||
public FontCase FontCase
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontCase;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _fontCase, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(FontCase));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HorizontalAlignment _horizontalAlignment = HorizontalAlignment.Center;
|
||||
public HorizontalAlignment HorizontalAlignment
|
||||
{
|
||||
get
|
||||
{
|
||||
return _horizontalAlignment;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _horizontalAlignment, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(HorizontalAlignment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private VerticalAlignment _verticalAlignment = VerticalAlignment.Center;
|
||||
public VerticalAlignment VerticalAlignment
|
||||
{
|
||||
get
|
||||
{
|
||||
return _verticalAlignment;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _verticalAlignment, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(VerticalAlignment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double _lineHeight;
|
||||
public double LineHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lineHeight;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _lineHeight, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(LineHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IColorViewModel
|
||||
{
|
||||
IColorObject LineColor { get; set; }
|
||||
IColorObject FillColor { get; set; }
|
||||
Color ShadowColor { get; set; }
|
||||
double LineWidth { get; set; }
|
||||
ArrowPathStyle LeftArrowPathStyle { get; set; }
|
||||
ArrowPathStyle RightArrowPathStyle { get; set; }
|
||||
ArrowSizeStyle LeftArrowSizeStyle { get; set; }
|
||||
ArrowSizeStyle RightArrowSizeStyle { get; set; }
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IDrawModeViewModel
|
||||
{
|
||||
DrawMode GetDrawMode();
|
||||
void SetDrawMode(DrawMode drawMode);
|
||||
|
||||
void ResetDrawMode();
|
||||
|
||||
CursorMode CursorMode { get; set; }
|
||||
DrawMode VectorLineDrawMode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IFontViewModel
|
||||
{
|
||||
string FontFamily { get; set; }
|
||||
Color FontColor { get; set; }
|
||||
double FontSize { get; set; }
|
||||
Color TextEffectColor { get; set; }
|
||||
Color HighlightColor { get; set; }
|
||||
FontCase FontCase { get; set; }
|
||||
FontWeight FontWeight { get; set; }
|
||||
FontStyle FontStyle { get; set; }
|
||||
FontStretch FontStretch { get; set; }
|
||||
bool Underline { get; set; }
|
||||
bool Strikethrough { get; set; }
|
||||
bool OverLine { get; set; }
|
||||
HorizontalAlignment HorizontalAlignment { get; set; }
|
||||
VerticalAlignment VerticalAlignment { get; set; }
|
||||
double LineHeight { get; set; }
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface ILockObjectViewModel
|
||||
{
|
||||
List<LockObject> LockObject { get; set; }
|
||||
void SetValue(LockObject obj);
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IQuickThemeViewModel
|
||||
{
|
||||
QuickTheme[] QuickThemes { get; }
|
||||
QuickTheme QuickTheme { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class LockObjectViewModel : ILockObjectViewModel
|
||||
{
|
||||
public List<LockObject> LockObject { get; set; }
|
||||
|
||||
public LockObjectViewModel()
|
||||
{
|
||||
LockObject = CopyHelper.DeepCopy<List<LockObject>>(LockObjectViewModelhelper.SourceLockObject);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void SetValue(LockObject obj)
|
||||
{
|
||||
var item = LockObject.FirstOrDefault(p => p.LockFlag == obj.LockFlag);
|
||||
item.IsChecked = obj.IsChecked;
|
||||
}
|
||||
}
|
||||
|
||||
public class LockObjectViewModelhelper
|
||||
{
|
||||
public static List<LockObject> SourceLockObject { get; private set; }
|
||||
static LockObjectViewModelhelper()
|
||||
{
|
||||
SourceLockObject = new List<LockObject>();
|
||||
var enums = Enum.GetValues(typeof(LockFlag));
|
||||
foreach (var _enum in enums.OfType<LockFlag>())
|
||||
{
|
||||
if (_enum == LockFlag.None) continue;
|
||||
|
||||
var item = new LockObject() { Name = _enum.ToString(), LockFlag = _enum };
|
||||
SourceLockObject.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LockObject : BindableBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public LockFlag LockFlag { get; set; }
|
||||
|
||||
private LockFlag _lockFlagValue = LockFlag.None;
|
||||
public LockFlag LockFlagValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lockFlagValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _lockFlagValue, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isChecked;
|
||||
public bool IsChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isChecked;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _isChecked, value))
|
||||
{
|
||||
if (_isChecked == true)
|
||||
{
|
||||
LockFlagValue = LockFlag;
|
||||
}
|
||||
else
|
||||
{
|
||||
LockFlagValue = LockFlag.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class QuickThemeViewModel : BindableBase, IQuickThemeViewModel
|
||||
{
|
||||
public QuickTheme[] QuickThemes { get; } = new QuickTheme[] {
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x50,0x9D,0x73)}, FillColor = new ColorObject() { Color = Colors.Transparent}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x51,0x76,0xAD)}, FillColor = new ColorObject() { Color = Colors.Transparent}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x83,0x83,0x83)}, FillColor = new ColorObject() { Color = Colors.Transparent}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x50,0x91,0xBA)}, FillColor = new ColorObject() { Color = Colors.Transparent}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xC5,0x9C,0x50)}, FillColor = new ColorObject() { Color = Colors.Transparent}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x7A,0xA6,0x59)}, FillColor = new ColorObject() { Color = Colors.Transparent}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xC3,0x78,0x55)}, FillColor = new ColorObject() { Color = Colors.Transparent}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xF5,0xC4,0xC5)}, FillColor = new ColorObject() { Color = Colors.Transparent }, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x50,0x9D,0x73)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE9,0xF4,0xED)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x51,0x76,0xAD)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE9,0xED,0xF8)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x83,0x83,0x83)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xEF,0xEF,0xEF)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x50,0x91,0xBA)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE7,0xF2,0xFC)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xC5,0x9C,0x50)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFF,0xF4,0xE8)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x7A,0xA6,0x59)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xED,0xF6,0xEA)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xC3,0x78,0x55)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFF,0xED,0xE9)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xF5,0xC4,0xC5)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFA,0xE9,0xE9) }, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE9,0xF4,0xED)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE9,0xF4,0xED)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE9,0xED,0xF8)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE9,0xED,0xF8)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xEF,0xEF,0xEF)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xEF,0xEF,0xEF)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE7,0xF2,0xFC)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE7,0xF2,0xFC)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFF,0xF4,0xE8)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFF,0xF4,0xE8)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xED,0xF6,0xEA)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xED,0xF6,0xEA)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFF,0xED,0xE9)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFF,0xED,0xE9)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFA,0xE9,0xE9)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFA,0xE9,0xE9) }, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x50,0x9D,0x73)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE9,0xF4,0xED)}, LineWidth = 2}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x51,0x76,0xAD)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE9,0xED,0xF8)}, LineWidth = 2}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x83,0x83,0x83)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xEF,0xEF,0xEF)}, LineWidth = 2}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x50,0x91,0xBA)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xE7,0xF2,0xFC)}, LineWidth = 2}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xC5,0x9C,0x50)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFF,0xF4,0xE8)}, LineWidth = 2}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x7A,0xA6,0x59)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xED,0xF6,0xEA)}, LineWidth = 2}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xC3,0x78,0x55)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFF,0xED,0xE9)}, LineWidth = 2}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xF5,0xC4,0xC5)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0xFA,0xE9,0xE9)}, LineWidth = 2}, FontViewModel = new FontViewModel(){ FontColor = Colors.Black } },
|
||||
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x1B,0x5C,0x3B)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x1B,0x5C,0x3B)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.White } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x20,0x3D,0x68)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x20,0x3D,0x68)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.White } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x47,0x47,0x47)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x47,0x47,0x47)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.White } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x00,0x52,0x73)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x00,0x52,0x73)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.White } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x7C,0x5B,0x0E)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x7C,0x5B,0x0E)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.White } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x40,0x63,0x26)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x40,0x63,0x26)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.White } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x7B,0x3F,0x23)}, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x7B,0x3F,0x23)}, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.White } },
|
||||
new QuickTheme(){ ColorViewModel= new ColorViewModel(){LineColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x6E,0x1D,0x1E) }, FillColor = new ColorObject() { Color = Color.FromArgb(0xFF,0x6E,0x1D,0x1E) }, LineWidth = 1}, FontViewModel = new FontViewModel(){ FontColor = Colors.White } },
|
||||
};
|
||||
|
||||
|
||||
private QuickTheme _quickTheme;
|
||||
public QuickTheme QuickTheme
|
||||
{
|
||||
get
|
||||
{
|
||||
return _quickTheme;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _quickTheme, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public class QuickTheme
|
||||
{
|
||||
public IColorViewModel ColorViewModel { get; set; }
|
||||
public IFontViewModel FontViewModel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets text
|
||||
/// </summary>
|
||||
public string Text { get; set; } = "Abc";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets group name
|
||||
/// </summary>
|
||||
public string Group { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public abstract class ConnectorInfoBase : BindableBase
|
||||
{
|
||||
|
||||
public ConnectorInfoBase(ConnectorOrientation orientation)
|
||||
{
|
||||
this.Orientation = orientation;
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
}
|
||||
|
||||
private ConnectorOrientation _orientation;
|
||||
public ConnectorOrientation Orientation
|
||||
{
|
||||
get { return _orientation; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _orientation, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double connectorWidth = 8;
|
||||
public double ConnectorWidth
|
||||
{
|
||||
get { return connectorWidth; }
|
||||
set { connectorWidth = value; }
|
||||
}
|
||||
|
||||
private double connectorHeight = 8;
|
||||
public double ConnectorHeight
|
||||
{
|
||||
get { return connectorHeight; }
|
||||
set { connectorHeight = value; }
|
||||
}
|
||||
|
||||
private IColorViewModel _colorViewModel;
|
||||
public IColorViewModel ColorViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _colorViewModel, value);
|
||||
}
|
||||
}
|
||||
|
||||
public double _connectorValue;
|
||||
public double ConnectorValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _connectorValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _connectorValue, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public abstract class DesignerItemViewModelBase : SelectableDesignerItemViewModelBase
|
||||
{
|
||||
public DesignerItemViewModelBase() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public DesignerItemViewModelBase(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
InitConnector();
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(parent, designerbase);
|
||||
|
||||
DesignerItemBase designer = designerbase as DesignerItemBase;
|
||||
|
||||
this.Left = designer.Left;
|
||||
this.Top = designer.Top;
|
||||
this.Angle = designer.Angle;
|
||||
this.ScaleX = designer.ScaleX;
|
||||
this.ScaleY = designer.ScaleY;
|
||||
this.ItemWidth = designer.ItemWidth;
|
||||
this.ItemHeight = designer.ItemHeight;
|
||||
this.Icon = designer.Icon;
|
||||
}
|
||||
|
||||
protected virtual void InitConnector()
|
||||
{
|
||||
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top));
|
||||
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Bottom));
|
||||
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Left));
|
||||
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Right));
|
||||
}
|
||||
|
||||
public FullyCreatedConnectorInfo TopConnector
|
||||
{
|
||||
get { return (connectors != null && connectors.Count >= 1) ? connectors[0] : null; }
|
||||
}
|
||||
|
||||
public FullyCreatedConnectorInfo BottomConnector
|
||||
{
|
||||
get { return (connectors != null && connectors.Count >= 2) ? connectors[1] : null; }
|
||||
}
|
||||
|
||||
public FullyCreatedConnectorInfo LeftConnector
|
||||
{
|
||||
get { return (connectors != null && connectors.Count >= 3) ? connectors[2] : null; }
|
||||
}
|
||||
|
||||
public FullyCreatedConnectorInfo RightConnector
|
||||
{
|
||||
get { return (connectors != null && connectors.Count >= 4) ? connectors[3] : null; }
|
||||
}
|
||||
|
||||
|
||||
private string _icon;
|
||||
[CanDo]
|
||||
public string Icon
|
||||
{
|
||||
get
|
||||
{
|
||||
return _icon;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _icon, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _itemWidth = 65;
|
||||
[Browsable(true)]
|
||||
[CanDo]
|
||||
public double ItemWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _itemWidth;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value <= 0) return;
|
||||
SetProperty(ref _itemWidth, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _itemHeight = 65;
|
||||
[Browsable(true)]
|
||||
[CanDo]
|
||||
public double ItemHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _itemHeight;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value <= 0) return;
|
||||
SetProperty(ref _itemHeight, value);
|
||||
}
|
||||
}
|
||||
|
||||
[CanDo]
|
||||
public Point ItemWidthHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Point(ItemWidth, ItemHeight);
|
||||
}
|
||||
set
|
||||
{
|
||||
ItemWidth = value.X;
|
||||
ItemHeight = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _showConnectors = false;
|
||||
[Browsable(false)]
|
||||
public bool ShowConnectors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showConnectors;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _showConnectors, value))
|
||||
{
|
||||
foreach (var connector in connectors)
|
||||
{
|
||||
connector.ShowConnectors = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _showResize = true;
|
||||
[Browsable(false)]
|
||||
public bool ShowResize
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showResize;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _showResize, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowRotate { get; set; } = true;
|
||||
public bool ShowArrow { get; set; } = true;
|
||||
|
||||
private double _left;
|
||||
[Browsable(true)]
|
||||
[CanDo]
|
||||
public double Left
|
||||
{
|
||||
get
|
||||
{
|
||||
return _left;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _left, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _top;
|
||||
[Browsable(true)]
|
||||
[CanDo]
|
||||
public double Top
|
||||
{
|
||||
get
|
||||
{
|
||||
return _top;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _top, value);
|
||||
}
|
||||
}
|
||||
|
||||
[CanDo]
|
||||
public Point TopLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Point(Left, Top);
|
||||
}
|
||||
set
|
||||
{
|
||||
Left = value.X;
|
||||
Top = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
private double _angle;
|
||||
[CanDo]
|
||||
public double Angle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _angle;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _angle, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _scaleX = 1;
|
||||
[CanDo]
|
||||
public double ScaleX
|
||||
{
|
||||
get
|
||||
{
|
||||
return _scaleX;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _scaleX, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _scaleY = 1;
|
||||
[CanDo]
|
||||
public double ScaleY
|
||||
{
|
||||
get
|
||||
{
|
||||
return _scaleY;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _scaleY, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _margin;
|
||||
|
||||
public double Margin
|
||||
{
|
||||
get
|
||||
{
|
||||
return _margin;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _margin, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接点是否可以按偏移自定义
|
||||
/// </summary>
|
||||
public bool IsInnerConnector { get; set; }
|
||||
|
||||
private ObservableCollection<FullyCreatedConnectorInfo> connectors = new ObservableCollection<FullyCreatedConnectorInfo>();
|
||||
public IEnumerable<FullyCreatedConnectorInfo> Connectors { get { return connectors; } }
|
||||
|
||||
protected ObservableCollection<CinchMenuItem> menuOptions;
|
||||
public IEnumerable<CinchMenuItem> MenuOptions { get { return menuOptions; } }
|
||||
|
||||
public bool ShowMenuOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MenuOptions == null || MenuOptions.Count() == 0)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool BeginDo { get; set; }
|
||||
|
||||
public IObservable<NotifyCollectionChangedEventArgs> WhenConnectorsChanged
|
||||
{
|
||||
get
|
||||
{
|
||||
return Observable
|
||||
.FromEventPattern<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(
|
||||
h => this.connectors.CollectionChanged += h,
|
||||
h => this.connectors.CollectionChanged -= h)
|
||||
.Select(x => x.EventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddConnector(FullyCreatedConnectorInfo connector)
|
||||
{
|
||||
if (!connectors.Contains(connector))
|
||||
{
|
||||
connectors.Add(connector);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveConnector(FullyCreatedConnectorInfo connector)
|
||||
{
|
||||
if (connectors.Contains(connector))
|
||||
{
|
||||
connectors.Remove(connector);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearConnectors()
|
||||
{
|
||||
connectors.Clear();
|
||||
}
|
||||
|
||||
public void SetCellAlignment()
|
||||
{
|
||||
if (!(this is TextDesignerItemViewModel))
|
||||
{
|
||||
if (Parent.CellHorizontalAlignment == CellHorizontalAlignment.Center)
|
||||
{
|
||||
if (Parent.GridCellSize.Width > this.ItemWidth)
|
||||
{
|
||||
this.Left = (int)(this.Left / Parent.GridCellSize.Width) * Parent.GridCellSize.Width + Parent.GridMargin + (Parent.GridCellSize.Width - this.ItemWidth) / 2;
|
||||
}
|
||||
}
|
||||
else if (Parent.CellHorizontalAlignment == CellHorizontalAlignment.Left)
|
||||
{
|
||||
this.Left = (int)(this.Left / Parent.GridCellSize.Width) * Parent.GridCellSize.Width + Parent.GridMargin;
|
||||
}
|
||||
else if (Parent.CellHorizontalAlignment == CellHorizontalAlignment.Right)
|
||||
{
|
||||
if (Parent.GridCellSize.Width > this.ItemWidth)
|
||||
{
|
||||
this.Left = (int)(this.Left / Parent.GridCellSize.Width) * Parent.GridCellSize.Width + Parent.GridMargin + (Parent.GridCellSize.Width - this.ItemWidth);
|
||||
}
|
||||
}
|
||||
|
||||
if (Parent.CellVerticalAlignment == CellVerticalAlignment.Center)
|
||||
{
|
||||
if (Parent.GridCellSize.Height > this.ItemHeight)
|
||||
{
|
||||
this.Top = (int)(this.Top / Parent.GridCellSize.Height) * Parent.GridCellSize.Height + Parent.GridMargin + (Parent.GridCellSize.Height - this.ItemHeight) / 2;
|
||||
}
|
||||
}
|
||||
else if (Parent.CellVerticalAlignment == CellVerticalAlignment.Top)
|
||||
{
|
||||
this.Top = (int)(this.Top / Parent.GridCellSize.Height) * Parent.GridCellSize.Height + Parent.GridMargin;
|
||||
}
|
||||
else if (Parent.CellVerticalAlignment == CellVerticalAlignment.Bottom)
|
||||
{
|
||||
if (Parent.GridCellSize.Height > this.ItemHeight)
|
||||
{
|
||||
this.Top = (int)(this.Top / Parent.GridCellSize.Height) * Parent.GridCellSize.Height + Parent.GridMargin + (Parent.GridCellSize.Height - this.ItemHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RaiseTopLeft()
|
||||
{
|
||||
this.RaisePropertyChanged(nameof(TopLeft), new Point(GetOldValue<double>(nameof(Left)), GetOldValue<double>(nameof(Top))), TopLeft);
|
||||
}
|
||||
|
||||
public void RaiseItemWidthHeight()
|
||||
{
|
||||
this.RaisePropertyChanged(nameof(ItemWidthHeight), new Point(GetOldValue<double>(nameof(ItemWidth)), GetOldValue<double>(nameof(ItemHeight))), ItemWidthHeight);
|
||||
}
|
||||
|
||||
public void RaiseAngle()
|
||||
{
|
||||
this.RaisePropertyChanged(nameof(Angle), GetOldValue<double>(nameof(Angle)), Angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class GroupDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
public GroupDesignerItemViewModel() : base()
|
||||
{
|
||||
this.ClearConnectors();
|
||||
this.IsHitTestVisible = false;
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object param)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class LogicalGateItemViewModelBase : DesignerItemViewModelBase
|
||||
{
|
||||
public SimpleCommand AddInputCommand { get; private set; }
|
||||
public SimpleCommand AddOutputCommand { get; private set; }
|
||||
|
||||
|
||||
public LogicalGateItemViewModelBase(LogicalType logicalType) : base()
|
||||
{
|
||||
this.LogicalType = logicalType;
|
||||
|
||||
if (this.LogicalType == LogicalType.Input)
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddOutput(null);
|
||||
}
|
||||
else if (this.LogicalType == LogicalType.Output)
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddInput(null);
|
||||
}
|
||||
else if (this.LogicalType == LogicalType.Constant)
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddOutput(null);
|
||||
}
|
||||
else if (this.LogicalType == LogicalType.Time)
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddOutput(null);
|
||||
}
|
||||
else if (this.LogicalType == LogicalType.None)
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddOutput(null);
|
||||
}
|
||||
else if (this.LogicalType == LogicalType.NOT)
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddInput(null);
|
||||
ExecuteAddOutput(null);
|
||||
}
|
||||
else if (this.LogicalType == LogicalType.SEL)
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddInput(null, 0);
|
||||
ExecuteAddInput(null, 1);
|
||||
ExecuteAddInput(null, 2);
|
||||
ExecuteAddOutput(null, 0);
|
||||
}
|
||||
else if (this.LogicalType >= LogicalType.ABS && this.LogicalType <= LogicalType.EXPT)
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddInput(null);
|
||||
ExecuteAddOutput(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearConnectors();
|
||||
ExecuteAddInput(null);
|
||||
ExecuteAddInput(null);
|
||||
ExecuteAddOutput(null);
|
||||
}
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
public LogicalGateItemViewModelBase(IDiagramViewModel parent, LogicalGateDesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
ShowRotate = false;
|
||||
ShowArrow = false;
|
||||
AddInputCommand = new SimpleCommand(para => ExecuteAddInput(para));
|
||||
AddOutputCommand = new SimpleCommand(para => ExecuteAddOutput(para));
|
||||
|
||||
base.Init();
|
||||
}
|
||||
|
||||
private void BuildMenuOptions()
|
||||
{
|
||||
bool enAddInput = false;
|
||||
bool enAddOutput = false;
|
||||
if (LogicalType >= LogicalType.ADD && LogicalType <= LogicalType.AVE)
|
||||
{
|
||||
enAddInput = true;
|
||||
enAddOutput = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
enAddInput = false;
|
||||
enAddOutput = false;
|
||||
}
|
||||
|
||||
menuOptions = new ObservableCollection<CinchMenuItem>();
|
||||
if (enAddInput == true)
|
||||
{
|
||||
CinchMenuItem menuItem = new CinchMenuItem();
|
||||
menuItem.Text = "添加输入";
|
||||
menuItem.Command = AddInputCommand;
|
||||
menuItem.CommandParameter = menuItem;
|
||||
menuOptions.Add(menuItem);
|
||||
}
|
||||
if (enAddOutput == true)
|
||||
{
|
||||
CinchMenuItem menuItem = new CinchMenuItem();
|
||||
menuItem.Text = "添加输出";
|
||||
menuItem.Command = AddOutputCommand;
|
||||
menuItem.CommandParameter = menuItem;
|
||||
menuOptions.Add(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(parent, designerbase);
|
||||
|
||||
LogicalGateDesignerItemBase designer = designerbase as LogicalGateDesignerItemBase;
|
||||
this.LogicalType = designer.LogicalType;
|
||||
this.OrderNumber = designer.OrderNumber;
|
||||
this.Value = designer.Value;
|
||||
this.IsEnabled = designer.IsEnabled;
|
||||
|
||||
ClearConnectors();
|
||||
Input.Clear();
|
||||
Output.Clear();
|
||||
|
||||
foreach (var connector in designer.Connectors)
|
||||
{
|
||||
FullyCreatedConnectorInfo fullyCreatedConnectorInfo = new FullyCreatedConnectorInfo(this, connector.Orientation, true);
|
||||
fullyCreatedConnectorInfo.XRatio = connector.XRatio;
|
||||
fullyCreatedConnectorInfo.YRatio = connector.YRatio;
|
||||
fullyCreatedConnectorInfo.ConnectorWidth = connector.ConnectorWidth;
|
||||
fullyCreatedConnectorInfo.ConnectorHeight = connector.ConnectorHeight;
|
||||
fullyCreatedConnectorInfo.Orientation = connector.Orientation;
|
||||
fullyCreatedConnectorInfo.IsInnerPoint = connector.IsInnerPoint;
|
||||
fullyCreatedConnectorInfo.ValueTypePoint = connector.ValueTypePoint;
|
||||
fullyCreatedConnectorInfo.ConnectorValue = connector.ConnectorValue;
|
||||
|
||||
if (fullyCreatedConnectorInfo.Orientation == ConnectorOrientation.Left)
|
||||
{
|
||||
Input.Add(Input.Count, fullyCreatedConnectorInfo);
|
||||
}
|
||||
else if (fullyCreatedConnectorInfo.Orientation == ConnectorOrientation.Right)
|
||||
{
|
||||
Output.Add(Output.Count, fullyCreatedConnectorInfo);
|
||||
}
|
||||
AddConnector(fullyCreatedConnectorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private int _orderNumber;
|
||||
public int OrderNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
return _orderNumber;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _orderNumber, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _isEnabled, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private double _value;
|
||||
public double Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _value, value);
|
||||
}
|
||||
}
|
||||
|
||||
public LogicalType LogicalType { get; set; }
|
||||
|
||||
|
||||
public Dictionary<int, FullyCreatedConnectorInfo> Input { get; set; } = new Dictionary<int, FullyCreatedConnectorInfo>();
|
||||
public Dictionary<int, FullyCreatedConnectorInfo> Output { get; set; } = new Dictionary<int, FullyCreatedConnectorInfo>();
|
||||
|
||||
public virtual void ExecuteAddInput(object parameter, int index = 0)
|
||||
{
|
||||
if (Input.Values.Count >= 2)
|
||||
{
|
||||
this.ItemHeight = this.ItemHeight * (Input.Values.Count + 1) / Input.Values.Count;
|
||||
}
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Left, true, ValueTypeInput.Count > index ? ValueTypeInput[index] : ValueTypeInput[0]);
|
||||
connector.XRatio = 0;
|
||||
Input.Add(Input.Count, connector);
|
||||
for (int i = 0; i < Input.Values.Count; i++)
|
||||
{
|
||||
Input[i].YRatio = (i + 1.0) / (Input.Values.Count + 1.0);
|
||||
}
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public virtual void ExecuteAddOutput(object parameter, int index = 0)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Right, true, ValueTypeOutput.Count > index ? ValueTypeOutput[index] : ValueTypeInput[0]);
|
||||
connector.XRatio = 1;
|
||||
Output.Add(Output.Count, connector);
|
||||
for (int i = 0; i < Output.Values.Count; i++)
|
||||
{
|
||||
Output[i].YRatio = (i + 1.0) / (Output.Values.Count + 1.0);
|
||||
}
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public List<ValueTypePoint> ValueTypeInput
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LogicalType == LogicalType.NOT)
|
||||
{
|
||||
return new List<ValueTypePoint>() { ValueTypePoint.Bool };
|
||||
}
|
||||
else if (LogicalType == LogicalType.AND || LogicalType == LogicalType.OR || LogicalType == LogicalType.XOR
|
||||
|| LogicalType == LogicalType.SHL || LogicalType == LogicalType.SHR || LogicalType == LogicalType.ROL || LogicalType == LogicalType.ROR)
|
||||
{
|
||||
return new List<ValueTypePoint>() { ValueTypePoint.Int };
|
||||
}
|
||||
else if (LogicalType == LogicalType.SEL)
|
||||
{
|
||||
return new List<ValueTypePoint>() { ValueTypePoint.Bool, ValueTypePoint.Real, ValueTypePoint.Real };
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<ValueTypePoint>() { ValueTypePoint.Real };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ValueTypePoint> ValueTypeOutput
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LogicalType == LogicalType.GT || LogicalType == LogicalType.LT || LogicalType == LogicalType.GE || LogicalType == LogicalType.LE || LogicalType == LogicalType.EQ || LogicalType == LogicalType.NE
|
||||
|| LogicalType == LogicalType.NOT)
|
||||
{
|
||||
return new List<ValueTypePoint>() { ValueTypePoint.Bool };
|
||||
}
|
||||
else if (LogicalType == LogicalType.AND || LogicalType == LogicalType.OR || LogicalType == LogicalType.XOR
|
||||
|| LogicalType == LogicalType.SHL || LogicalType == LogicalType.SHR || LogicalType == LogicalType.ROL || LogicalType == LogicalType.ROR)
|
||||
{
|
||||
return new List<ValueTypePoint>() { ValueTypePoint.Int };
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<ValueTypePoint>() { ValueTypePoint.Real };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PointInfoBase : BindableBase
|
||||
{
|
||||
public PointInfoBase()
|
||||
{
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
}
|
||||
|
||||
public PointInfoBase(Point point) : this()
|
||||
{
|
||||
X = point.X;
|
||||
Y = point.Y;
|
||||
}
|
||||
|
||||
|
||||
private double _x;
|
||||
public double X
|
||||
{
|
||||
get
|
||||
{
|
||||
return _x;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(SetProperty(ref _x, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(Left));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double _y;
|
||||
public double Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return _y;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _y, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(Top));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double Left
|
||||
{
|
||||
get
|
||||
{
|
||||
return X - ConnectorWidth / 2;
|
||||
}
|
||||
}
|
||||
|
||||
public double Top
|
||||
{
|
||||
get
|
||||
{
|
||||
return Y - ConnectorHeight / 2;
|
||||
}
|
||||
}
|
||||
|
||||
private double connectorWidth = 8;
|
||||
public double ConnectorWidth
|
||||
{
|
||||
get { return connectorWidth; }
|
||||
set { connectorWidth = value; }
|
||||
}
|
||||
|
||||
private double connectorHeight = 8;
|
||||
public double ConnectorHeight
|
||||
{
|
||||
get { return connectorHeight; }
|
||||
set { connectorHeight = value; }
|
||||
}
|
||||
|
||||
private IColorViewModel _colorViewModel;
|
||||
public IColorViewModel ColorViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _colorViewModel, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator PointInfoBase(Point point)
|
||||
{
|
||||
return new PointInfoBase(point);
|
||||
}
|
||||
|
||||
public static implicit operator Point(PointInfoBase pointInfoBase)
|
||||
{
|
||||
return new Point(pointInfoBase.X, pointInfoBase.Y);
|
||||
}
|
||||
|
||||
public static List<PointInfoBase> ToList(List<Point> lst)
|
||||
{
|
||||
return lst.Select(p => (PointInfoBase)p).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
|
||||
public interface ISelectItems
|
||||
{
|
||||
SimpleCommand SelectItemCommand { get; }
|
||||
}
|
||||
|
||||
|
||||
public abstract class SelectableDesignerItemViewModelBase : BindableBase, ISelectItems, ISelectable, IGroupable
|
||||
{
|
||||
private IDiagramServiceProvider _service { get { return DiagramServicesProvider.Instance.Provider; } }
|
||||
|
||||
public SelectableDesignerItemViewModelBase()
|
||||
{
|
||||
Init();
|
||||
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
||||
}
|
||||
|
||||
public SelectableDesignerItemViewModelBase(IDiagramViewModel parent, SelectableDesignerItemBase designer)
|
||||
{
|
||||
Init();
|
||||
LoadDesignerItemViewModel(parent, designer);
|
||||
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
|
||||
}
|
||||
|
||||
protected virtual void Init()
|
||||
{
|
||||
ColorViewModel = _service.CopyDefaultColorViewModel();
|
||||
FontViewModel = _service.CopyDefaultFontViewModel();
|
||||
|
||||
LockObjectViewModel = new LockObjectViewModel();
|
||||
SelectItemCommand = new SimpleCommand(ExecuteSelectItemCommand);
|
||||
EditCommand = new SimpleCommand(ExecuteEditCommand);
|
||||
}
|
||||
|
||||
protected virtual void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
{
|
||||
this.Parent = parent;
|
||||
|
||||
this.Id = designerbase.Id;
|
||||
this.ParentId = designerbase.ParentId;
|
||||
this.IsGroup = designerbase.IsGroup;
|
||||
this.ZIndex = designerbase.ZIndex;
|
||||
this.Text = designerbase.Text;
|
||||
|
||||
ColorViewModel = CopyHelper.Mapper(designerbase.ColorItem);
|
||||
FontViewModel = CopyHelper.Mapper<FontViewModel, FontItem>(designerbase.FontItem);
|
||||
}
|
||||
|
||||
public virtual bool InitData()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public virtual bool EditData()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<SelectableDesignerItemViewModelBase> SelectedItems
|
||||
{
|
||||
//todo
|
||||
get { return Parent.SelectedItems; }
|
||||
}
|
||||
|
||||
public IDiagramViewModel Parent { get; set; }
|
||||
public SimpleCommand SelectItemCommand { get; private set; }
|
||||
public ICommand EditCommand { get; private set; }
|
||||
public Guid Id { get; set; }
|
||||
|
||||
private Guid _parentId;
|
||||
public Guid ParentId
|
||||
{
|
||||
get
|
||||
{
|
||||
return _parentId;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _parentId, value);
|
||||
}
|
||||
}
|
||||
public SelectableDesignerItemViewModelBase ParentItem { get; set; }
|
||||
|
||||
public bool IsGroup { get; set; }
|
||||
|
||||
private bool _isSelected;
|
||||
[Browsable(false)]
|
||||
public bool IsSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _isSelected, value))
|
||||
{
|
||||
//如果没有文字,失去焦点自动清除
|
||||
if (_isSelected == false && string.IsNullOrEmpty(Text))
|
||||
{
|
||||
ShowText = false;
|
||||
if (this is TextDesignerItemViewModel)
|
||||
{
|
||||
if (ParentItem != null)
|
||||
{
|
||||
ParentItem.OutTextItem = null;
|
||||
}
|
||||
Parent.DirectRemoveItemCommand.Execute(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private int _zIndex;
|
||||
[Browsable(true)]
|
||||
[CanDo]
|
||||
public int ZIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _zIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isReadOnly;
|
||||
[Browsable(false)]
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LockObjectViewModel != null && LockObjectViewModel.LockObject.FirstOrDefault(p => p.LockFlag == LockFlag.All).IsChecked == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return _isReadOnly;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _isReadOnly, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isHitTestVisible = true;
|
||||
[Browsable(false)]
|
||||
public bool IsHitTestVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isHitTestVisible;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _isHitTestVisible, value))
|
||||
{
|
||||
RaisePropertyChanged("IsReadOnly");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IColorViewModel _colorViewModel;
|
||||
public IColorViewModel ColorViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _colorViewModel, value);
|
||||
}
|
||||
}
|
||||
|
||||
private IFontViewModel _fontViewModel;
|
||||
public IFontViewModel FontViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fontViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _fontViewModel, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ILockObjectViewModel LockObjectViewModel { get; set; }
|
||||
|
||||
|
||||
private string _text;
|
||||
[Browsable(true)]
|
||||
[CanDo]
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
var text = _text;
|
||||
if (OutTextItem != null)
|
||||
{
|
||||
text = OutTextItem._text;
|
||||
}
|
||||
if (FontViewModel.FontCase == FontCase.Upper)
|
||||
{
|
||||
return text?.ToUpper();
|
||||
}
|
||||
else if (FontViewModel.FontCase == FontCase.Lower)
|
||||
{
|
||||
return text?.ToLower();
|
||||
}
|
||||
else
|
||||
{
|
||||
return text;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (OutTextItem != null)
|
||||
{
|
||||
OutTextItem.Text = value;
|
||||
}
|
||||
else if (SetProperty(ref _text, value))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_text))
|
||||
{
|
||||
ShowText = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isReadOnlyText = false;
|
||||
public bool IsReadOnlyText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsReadOnly)
|
||||
return true;
|
||||
return _isReadOnlyText;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _isReadOnlyText, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _showText;
|
||||
public virtual bool ShowText
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showText;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _showText, value);
|
||||
}
|
||||
}
|
||||
|
||||
public SelectableDesignerItemViewModelBase OutTextItem { get; set; }
|
||||
|
||||
private void ExecuteSelectItemCommand(object param)
|
||||
{
|
||||
SelectItem((bool)param, !IsSelected);
|
||||
}
|
||||
|
||||
private void SelectItem(bool newselect, bool select)
|
||||
{
|
||||
if (newselect)
|
||||
{
|
||||
foreach (var designerItemViewModelBase in Parent.SelectedItems.ToList())
|
||||
{
|
||||
designerItemViewModelBase._isSelected = false;
|
||||
}
|
||||
}
|
||||
|
||||
IsSelected = select;
|
||||
}
|
||||
|
||||
private void FontViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "FontCase")
|
||||
{
|
||||
RaisePropertyChanged("Text");
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ExecuteEditCommand(object param)
|
||||
{
|
||||
if (IsReadOnly == true) return;
|
||||
|
||||
ShowText = true;
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
163
AIStudio.Wpf.DiagramDesigner/ViewModels/BindableBase.cs
Normal file
163
AIStudio.Wpf.DiagramDesigner/ViewModels/BindableBase.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="INotifyPropertyChanged"/> to simplify models.
|
||||
/// </summary>
|
||||
public abstract class BindableBase : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Occurs when a property value changes.
|
||||
/// </summary>
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a property already matches a desired value. Sets the property and
|
||||
/// notifies listeners only when necessary.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the property.</typeparam>
|
||||
/// <param name="storage">Reference to a property with both getter and setter.</param>
|
||||
/// <param name="value">Desired value for the property.</param>
|
||||
/// <param name="propertyName">Name of the property used to notify listeners. This
|
||||
/// value is optional and can be provided automatically when invoked from compilers that
|
||||
/// support CallerMemberName.</param>
|
||||
/// <returns>True if the value was changed, false if the existing value matched the
|
||||
/// desired value.</returns>
|
||||
protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(storage, value))
|
||||
return false;
|
||||
|
||||
if (propertyName == "IsSelected")
|
||||
{
|
||||
|
||||
}
|
||||
else if (this.ContainsProperty("IsReadOnly"))
|
||||
{
|
||||
if (object.Equals(this.GetPropertyValue("IsReadOnly"), true))
|
||||
return false;
|
||||
}
|
||||
|
||||
var old = storage;
|
||||
storage = value;
|
||||
RaisePropertyChanged(propertyName, old, value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Dictionary<string, object> _oldDic = new Dictionary<string, object>();
|
||||
public void SetOldValue<T>(T value, string propertyName, string guid = null)
|
||||
{
|
||||
_oldDic[propertyName + guid ?? string.Empty] = value;
|
||||
}
|
||||
|
||||
public T GetOldValue<T>(string propertyName, string guid = null)
|
||||
{
|
||||
if (_oldDic.ContainsKey(propertyName + guid ?? string.Empty))
|
||||
{
|
||||
var old = (T)_oldDic[propertyName + guid ?? string.Empty];
|
||||
return old;
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearOldValue<T>(string propertyName, string guid = null)
|
||||
{
|
||||
if (_oldDic.ContainsKey(propertyName + guid ?? string.Empty))
|
||||
{
|
||||
_oldDic.Remove(propertyName + guid ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a property already matches a desired value. Sets the property and
|
||||
/// notifies listeners only when necessary.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the property.</typeparam>
|
||||
/// <param name="storage">Reference to a property with both getter and setter.</param>
|
||||
/// <param name="value">Desired value for the property.</param>
|
||||
/// <param name="propertyName">Name of the property used to notify listeners. This
|
||||
/// value is optional and can be provided automatically when invoked from compilers that
|
||||
/// support CallerMemberName.</param>
|
||||
/// <param name="onChanged">Action that is called after the property value has been changed.</param>
|
||||
/// <returns>True if the value was changed, false if the existing value matched the
|
||||
/// desired value.</returns>
|
||||
protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
onChanged?.Invoke();
|
||||
RaisePropertyChanged(propertyName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises this object's PropertyChanged event.
|
||||
/// </summary>
|
||||
/// <param name="propertyName">Name of the property used to notify listeners. This
|
||||
/// value is optional and can be provided automatically when invoked from compilers
|
||||
/// that support <see cref="CallerMemberNameAttribute"/>.</param>
|
||||
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null, object oldvalue = null, object newvalue = null)
|
||||
{
|
||||
OnPropertyChanged(new ValuePropertyChangedEventArgs(propertyName, oldvalue, newvalue));
|
||||
}
|
||||
|
||||
protected void RaisePropertyChanged(object sender, [CallerMemberName] string propertyName = null, object oldvalue = null, object newvalue = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(sender, new ValuePropertyChangedEventArgs(propertyName, oldvalue, newvalue));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises this object's PropertyChanged event.
|
||||
/// </summary>
|
||||
/// <param name="args">The PropertyChangedEventArgs</param>
|
||||
protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
public IObservable<string> WhenPropertyChanged
|
||||
{
|
||||
get
|
||||
{
|
||||
return Observable
|
||||
.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(
|
||||
h => this.PropertyChanged += h,
|
||||
h => this.PropertyChanged -= h)
|
||||
.Select(x => x.EventArgs.PropertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ValuePropertyChangedEventArgs : PropertyChangedEventArgs
|
||||
{
|
||||
public ValuePropertyChangedEventArgs(string propertyName, object oldValue, object newValue) : base(propertyName)
|
||||
{
|
||||
OldValue = oldValue;
|
||||
NewValue = newValue;
|
||||
}
|
||||
|
||||
public object OldValue { get; set; }
|
||||
public object NewValue { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
477
AIStudio.Wpf.DiagramDesigner/ViewModels/ConnectorViewModel.cs
Normal file
477
AIStudio.Wpf.DiagramDesigner/ViewModels/ConnectorViewModel.cs
Normal file
@@ -0,0 +1,477 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ConnectorViewModel : SelectableDesignerItemViewModelBase
|
||||
{
|
||||
public ConnectorViewModel(IDiagramViewModel parent, FullyCreatedConnectorInfo sourceConnectorInfo, FullyCreatedConnectorInfo sinkConnectorInfo,
|
||||
SelectableDesignerItemBase designer, DrawMode vectorLineDrawMode) : base(parent, designer)
|
||||
{
|
||||
VectorLineDrawMode = vectorLineDrawMode;
|
||||
Init(sourceConnectorInfo, sinkConnectorInfo);
|
||||
}
|
||||
|
||||
public ConnectorViewModel(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo, DrawMode vectorLineDrawMode)
|
||||
{
|
||||
VectorLineDrawMode = vectorLineDrawMode;
|
||||
Init(sourceConnectorInfo, sinkConnectorInfo);
|
||||
}
|
||||
|
||||
|
||||
public static IPathFinder PathFinder { get; set; }
|
||||
|
||||
public bool IsFullConnection
|
||||
{
|
||||
get { return _sinkConnectorInfo is FullyCreatedConnectorInfo; }
|
||||
}
|
||||
|
||||
private Point _sourceA;
|
||||
public Point SourceA
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sourceA;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _sourceA, value))
|
||||
{
|
||||
UpdateArea();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Point _sourceB;
|
||||
public Point SourceB
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sourceB;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _sourceB, value))
|
||||
{
|
||||
UpdateArea();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<PointInfoBase> _connectionPoints;
|
||||
public List<PointInfoBase> ConnectionPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
return _connectionPoints;
|
||||
}
|
||||
private set
|
||||
{
|
||||
if (_connectionPoints != null)
|
||||
{
|
||||
_connectionPoints.ForEach(p => p.PropertyChanged -= new WeakINPCEventHandler(ConnectionPoint_PropertyChanged).Handler);
|
||||
}
|
||||
SetProperty(ref _connectionPoints, value);
|
||||
if (_connectionPoints != null)
|
||||
{
|
||||
_connectionPoints.ForEach(p => p.PropertyChanged += new WeakINPCEventHandler(ConnectionPoint_PropertyChanged).Handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Point _startPoint;
|
||||
public Point StartPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _startPoint;
|
||||
}
|
||||
private set
|
||||
{
|
||||
SetProperty(ref _startPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Point _endPoint;
|
||||
public Point EndPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _endPoint;
|
||||
}
|
||||
private set
|
||||
{
|
||||
SetProperty(ref _endPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Rect _area;
|
||||
public Rect Area
|
||||
{
|
||||
get
|
||||
{
|
||||
return _area;
|
||||
}
|
||||
private set
|
||||
{
|
||||
if (SetProperty(ref _area, value))
|
||||
{
|
||||
UpdateConnectionPoints();
|
||||
OutTextItemLocation(_area, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DrawMode VectorLineDrawMode { get; set; }
|
||||
|
||||
public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, double width, double height, Point position)
|
||||
{
|
||||
|
||||
return new ConnectorInfo()
|
||||
{
|
||||
Orientation = orientation,
|
||||
DesignerItemSize = new Size(width, height),
|
||||
DesignerItemLeft = left,
|
||||
DesignerItemTop = top,
|
||||
Position = position
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private FullyCreatedConnectorInfo _sourceConnectorInfo;
|
||||
public FullyCreatedConnectorInfo SourceConnectorInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sourceConnectorInfo;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _sourceConnectorInfo, value))
|
||||
{
|
||||
SourceA = PointHelper.GetPointForConnector(_sourceConnectorInfo);
|
||||
(_sourceConnectorInfo.DataItem as INotifyPropertyChanged).PropertyChanged += new WeakINPCEventHandler(ConnectorViewModel_PropertyChanged).Handler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ConnectorInfoBase _sinkConnectorInfo;
|
||||
public ConnectorInfoBase SinkConnectorInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sinkConnectorInfo;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _sinkConnectorInfo, value))
|
||||
{
|
||||
if (_sinkConnectorInfo is FullyCreatedConnectorInfo)
|
||||
{
|
||||
SourceB = PointHelper.GetPointForConnector((FullyCreatedConnectorInfo)_sinkConnectorInfo);
|
||||
(((FullyCreatedConnectorInfo)_sinkConnectorInfo).DataItem as INotifyPropertyChanged).PropertyChanged += new WeakINPCEventHandler(ConnectorViewModel_PropertyChanged).Handler;
|
||||
}
|
||||
else
|
||||
{
|
||||
SourceB = ((PartCreatedConnectionInfo)SinkConnectorInfo).CurrentLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateArea()
|
||||
{
|
||||
Area = new Rect(SourceA, SourceB);
|
||||
}
|
||||
|
||||
private void UpdateConnectionPoints()
|
||||
{
|
||||
if (VectorLineDrawMode == DrawMode.ConnectingLine)
|
||||
{
|
||||
UpdateConnectionPointsByLine();
|
||||
}
|
||||
else if (VectorLineDrawMode == DrawMode.BoundaryConnectingLine)
|
||||
{
|
||||
UpdateConnectionPointsByBoundary();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateConnectionPointsByCorner();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void UpdateConnectionPointsByLine()
|
||||
{
|
||||
ConnectionPoints = PointInfoBase.ToList(new List<Point>()
|
||||
{
|
||||
|
||||
new Point(SourceA.X < SourceB.X ? 0d : Area.Width, SourceA.Y < SourceB.Y ? 0d : Area.Height ),
|
||||
new Point(SourceA.X > SourceB.X ? 0d : Area.Width, SourceA.Y > SourceB.Y ? 0d : Area.Height)
|
||||
});
|
||||
StartPoint = ConnectionPoints[0];
|
||||
EndPoint = ConnectionPoints.Last();
|
||||
}
|
||||
|
||||
private void UpdateConnectionPointsByCorner()
|
||||
{
|
||||
var points = new List<Point>()
|
||||
{
|
||||
|
||||
new Point(SourceA.X < SourceB.X ? 0d : Area.Width, SourceA.Y < SourceB.Y ? 0d : Area.Height ),
|
||||
new Point(SourceA.X > SourceB.X ? 0d : Area.Width, SourceA.Y > SourceB.Y ? 0d : Area.Height)
|
||||
};
|
||||
|
||||
ConnectorInfo sourceInfo = ConnectorInfo(SourceConnectorInfo.Orientation,
|
||||
points[0].X,
|
||||
points[0].Y,
|
||||
SourceConnectorInfo.DataItem.ItemWidth,
|
||||
SourceConnectorInfo.DataItem.ItemHeight,
|
||||
points[0]);
|
||||
|
||||
StartPoint = points[0];
|
||||
if (IsFullConnection)
|
||||
{
|
||||
EndPoint = points.Last();
|
||||
ConnectorInfo sinkInfo = ConnectorInfo(SinkConnectorInfo.Orientation,
|
||||
points[1].X,
|
||||
points[1].Y,
|
||||
((FullyCreatedConnectorInfo)_sinkConnectorInfo).DataItem.ItemWidth,
|
||||
((FullyCreatedConnectorInfo)_sinkConnectorInfo).DataItem.ItemHeight,
|
||||
points[1]);
|
||||
|
||||
ConnectionPoints = PointInfoBase.ToList(PathFinder.GetConnectionLine(sourceInfo, sinkInfo, false, SourceConnectorInfo.IsInnerPoint));
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectionPoints = PointInfoBase.ToList(PathFinder.GetConnectionLine(sourceInfo, points[1], SourceConnectorInfo.Orientation, false, SourceConnectorInfo.IsInnerPoint));
|
||||
EndPoint = new Point();
|
||||
}
|
||||
}
|
||||
|
||||
#region
|
||||
private void UpdateConnectionPointsByBoundary()
|
||||
{
|
||||
var points = new List<Point>();
|
||||
var ends = GetEndPoinds();
|
||||
|
||||
points.Add(ends[0]);
|
||||
points.AddRange(GetMiddlePoints(ends[0], ends[1]));
|
||||
points.Add(ends[1]);
|
||||
var res = points.ToArray();
|
||||
//UpdateEdges(res);
|
||||
DoShift(res);
|
||||
ConnectionPoints = PointInfoBase.ToList(res.ToList());
|
||||
StartPoint = ConnectionPoints[0];
|
||||
EndPoint = ConnectionPoints.Last();
|
||||
}
|
||||
|
||||
private IEnumerable<Point> GetMiddlePoints(Point start, Point end)
|
||||
{
|
||||
var points = new List<Point>();
|
||||
if (IsFullConnection)
|
||||
{
|
||||
var p0 = GetFirstSegment(SourceConnectorInfo, start, Parent.GridCellSize, Parent.GridMargin);
|
||||
var p1 = GetFirstSegment(SinkConnectorInfo, end, Parent.GridCellSize, Parent.GridMargin);
|
||||
|
||||
if (p0 == p1)
|
||||
return points;
|
||||
|
||||
|
||||
var p2 = new Point(GetNearestCross(p0.X, p1.X), GetNearestCross(p0.Y, p1.Y));
|
||||
var p3 = new Point(GetNearestCross(p1.X, p0.X), GetNearestCross(p1.Y, p0.Y));
|
||||
if (p2 == p3)
|
||||
{
|
||||
points.Add(p0);
|
||||
points.Add(p2);
|
||||
points.Add(p1);
|
||||
}
|
||||
else
|
||||
{
|
||||
points.Add(p0);
|
||||
points.Add(p2);
|
||||
if (!(Math.Abs(p2.X - p3.X) < 0.0001) && !(Math.Abs(p2.Y - p3.Y) < 0.0001))
|
||||
points.Add(new Point(p2.X, p3.Y));
|
||||
points.Add(p3);
|
||||
points.Add(p1);
|
||||
}
|
||||
DoScale(points, Parent.GridCellSize, Parent.GridMargin);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
private Point[] GetEndPoinds()
|
||||
{
|
||||
var linePoints = new Point[2];
|
||||
linePoints[0] = SourceA;
|
||||
linePoints[1] = SourceB;
|
||||
|
||||
return linePoints;
|
||||
}
|
||||
|
||||
private Point GetFirstSegment(ConnectorInfoBase port, Point point, Size cellSize, double margin)
|
||||
{
|
||||
double x = (int)((point.X - margin) / cellSize.Width) + 0.5;
|
||||
double y = (int)((point.Y - margin) / cellSize.Height) + 0.5;
|
||||
if (port.Orientation == ConnectorOrientation.Top)
|
||||
return new Point(x, y - 0.5);
|
||||
else if (port.Orientation == ConnectorOrientation.Bottom)
|
||||
return new Point(x, y + 0.5);
|
||||
else if (port.Orientation == ConnectorOrientation.Left)
|
||||
return new Point(x - 0.5, y);
|
||||
else
|
||||
return new Point(x + 0.5, y);
|
||||
}
|
||||
|
||||
private double GetNearestCross(double a, double b)
|
||||
{
|
||||
if (Math.Abs(a - b) < 0.0001 && (int)a == a)
|
||||
return a;
|
||||
else if (a < b)
|
||||
return Math.Ceiling(a);
|
||||
else
|
||||
return Math.Floor(a);
|
||||
}
|
||||
|
||||
private void DoScale(List<Point> points, Size cellSize, double margin)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
points[i] = new Point(points[i].X * cellSize.Width + margin,
|
||||
points[i].Y * cellSize.Height + margin);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoShift(Point[] points)
|
||||
{
|
||||
double left = new Point[] { points.FirstOrDefault(), points.LastOrDefault() }.Min(p => p.X);
|
||||
double top = new Point[] { points.FirstOrDefault(), points.LastOrDefault() }.Min(p => p.Y);
|
||||
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
points[i].X = points[i].X - left;
|
||||
points[i].Y = points[i].Y - top;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Point SegmentMiddlePoint(Point p1, Point p2)
|
||||
{
|
||||
return new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void ConnectorViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case "ItemHeight":
|
||||
case "ItemWidth":
|
||||
case "Left":
|
||||
case "Top":
|
||||
SourceA = PointHelper.GetPointForConnector(this.SourceConnectorInfo);
|
||||
if (this.SinkConnectorInfo is FullyCreatedConnectorInfo)
|
||||
{
|
||||
SourceB = PointHelper.GetPointForConnector((FullyCreatedConnectorInfo)this.SinkConnectorInfo);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ConnectionPoint_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case "Left":
|
||||
case "Top":
|
||||
RaisePropertyChanged(nameof(ConnectionPoints));
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
this.Parent = sourceConnectorInfo.DataItem.Parent;
|
||||
this.SourceConnectorInfo = sourceConnectorInfo;
|
||||
this.SinkConnectorInfo = sinkConnectorInfo;
|
||||
PathFinder = new OrthogonalPathFinder();
|
||||
DeleteConnectionCommand = new SimpleCommand(DeleteConnection);
|
||||
|
||||
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
|
||||
{
|
||||
this.ColorViewModel.RightArrowPathStyle = ArrowPathStyle.None;
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCommand DeleteConnectionCommand { get; set; }
|
||||
private void DeleteConnection(object args)
|
||||
{
|
||||
if (this.Parent is IDiagramViewModel)
|
||||
{
|
||||
var diagramVM = this.Parent as IDiagramViewModel;
|
||||
diagramVM.RemoveItemCommand.Execute(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object param)
|
||||
{
|
||||
if (this.OutTextItem != null) return;
|
||||
AddText("");
|
||||
}
|
||||
|
||||
public void AddText(string text)
|
||||
{
|
||||
if (this.Parent is IDiagramViewModel)
|
||||
{
|
||||
var diagramVM = this.Parent as IDiagramViewModel;
|
||||
|
||||
TextDesignerItemViewModel textitem = new TextDesignerItemViewModel();
|
||||
textitem.ItemWidth = Double.NaN;
|
||||
textitem.ItemHeight = double.NaN;
|
||||
if (diagramVM.DiagramType == DiagramType.FlowChart)
|
||||
{
|
||||
var mid = (int)(ConnectionPoints.Count / 2);
|
||||
var p = SegmentMiddlePoint(ConnectionPoints[mid - 1], ConnectionPoints[mid]);
|
||||
textitem.Left = this.Area.Left + p.X + 2;
|
||||
textitem.Top = this.Area.Top + p.Y - 15;
|
||||
}
|
||||
else
|
||||
{
|
||||
textitem.Left = this.Area.Left + this.Area.Width / 2 - 16;
|
||||
textitem.Top = this.Area.Top + this.Area.Height / 2 - 5;
|
||||
}
|
||||
textitem.Watermark = null;
|
||||
textitem.ZIndex = diagramVM.Items.Count;
|
||||
textitem.ParentId = this.Id;
|
||||
textitem.ParentItem = this;
|
||||
textitem.ColorViewModel.FillColor = new ColorObject() { Color = Colors.White };
|
||||
textitem.Text = text;
|
||||
|
||||
diagramVM.DirectAddItemCommand.Execute(textitem);
|
||||
|
||||
this.OutTextItem = textitem;
|
||||
}
|
||||
}
|
||||
|
||||
public void OutTextItemLocation(Rect oldArea, Rect newArea)
|
||||
{
|
||||
if (this.OutTextItem is TextDesignerItemViewModel text)
|
||||
{
|
||||
var oldpoint = new Point(oldArea.Left + oldArea.Width / 2, oldArea.Top + oldArea.Height / 2);
|
||||
var newpoint = new Point(newArea.Left + newArea.Width / 2, newArea.Top + newArea.Height / 2);
|
||||
|
||||
text.Left = text.Left + newpoint.X - oldpoint.X;
|
||||
text.Top = text.Top + newpoint.Y - oldpoint.Y;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
1262
AIStudio.Wpf.DiagramDesigner/ViewModels/DiagramViewModel.cs
Normal file
1262
AIStudio.Wpf.DiagramDesigner/ViewModels/DiagramViewModel.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class FullyCreatedConnectorInfo : ConnectorInfoBase
|
||||
{
|
||||
|
||||
private List<CinchMenuItem> menuOptions;
|
||||
|
||||
public FullyCreatedConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint=false, ValueTypePoint valueTypePoint = 0)
|
||||
: base(orientation)
|
||||
{
|
||||
this.DataItem = dataItem;
|
||||
this.IsInnerPoint = isInnerPoint;
|
||||
this.ValueTypePoint = valueTypePoint;
|
||||
|
||||
menuOptions = new List<CinchMenuItem>();
|
||||
MenuItemCommand = new SimpleCommand(ExecuteMenuItemCommand);
|
||||
DeleteCommand = new SimpleCommand(ExecuteDeleteCommand);
|
||||
if (IsInnerPoint == true)
|
||||
{
|
||||
BuildMenuOptions();
|
||||
}
|
||||
}
|
||||
|
||||
public void ExecuteMenuItemCommand(object arg)
|
||||
{
|
||||
Orientation = (ConnectorOrientation)arg;
|
||||
}
|
||||
|
||||
public void ExecuteDeleteCommand(object arg)
|
||||
{
|
||||
DataItem.RemoveConnector(this);
|
||||
|
||||
}
|
||||
|
||||
private void BuildMenuOptions()
|
||||
{
|
||||
menuOptions.Clear();
|
||||
var orientation = new CinchMenuItem("方向");
|
||||
var top = new CinchMenuItem("上");
|
||||
top.Command = MenuItemCommand;
|
||||
top.CommandParameter = ConnectorOrientation.Top;
|
||||
var bottom = new CinchMenuItem("下");
|
||||
bottom.Command = MenuItemCommand;
|
||||
bottom.CommandParameter = ConnectorOrientation.Bottom;
|
||||
var left = new CinchMenuItem("左");
|
||||
left.Command = MenuItemCommand;
|
||||
left.CommandParameter = ConnectorOrientation.Left;
|
||||
var right = new CinchMenuItem("右");
|
||||
right.Command = MenuItemCommand;
|
||||
right.CommandParameter = ConnectorOrientation.Right;
|
||||
orientation.Children.Add(top);
|
||||
orientation.Children.Add(bottom);
|
||||
orientation.Children.Add(left);
|
||||
orientation.Children.Add(right);
|
||||
|
||||
var delete = new CinchMenuItem("删除");
|
||||
delete.Command = DeleteCommand;
|
||||
|
||||
menuOptions.Add(orientation);
|
||||
menuOptions.Add(delete);
|
||||
}
|
||||
|
||||
public DesignerItemViewModelBase DataItem { get; private set; }
|
||||
|
||||
private bool _showConnectors = false;
|
||||
public bool ShowConnectors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showConnectors;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _showConnectors, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _xRatio;
|
||||
public double XRatio
|
||||
{
|
||||
get { return _xRatio; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _xRatio, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _yRatio;
|
||||
public double YRatio
|
||||
{
|
||||
get { return _yRatio; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _yRatio, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInnerPoint { get; set; }
|
||||
|
||||
public ValueTypePoint _valueTypePoint;
|
||||
public ValueTypePoint ValueTypePoint
|
||||
{
|
||||
get { return _valueTypePoint; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _valueTypePoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCommand DeleteCommand { get; private set; }
|
||||
public SimpleCommand MenuItemCommand { get; private set; }
|
||||
|
||||
public IEnumerable<CinchMenuItem> MenuOptions { get { return menuOptions; } }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
65
AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs
Normal file
65
AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IDiagramViewModel
|
||||
{
|
||||
string Name { get; set; }
|
||||
List<SelectableDesignerItemViewModelBase> SelectedItems { get; }
|
||||
ObservableCollection<SelectableDesignerItemViewModelBase> Items { get; }
|
||||
SelectionService SelectionService { get; }
|
||||
|
||||
SimpleCommand CreateNewDiagramCommand { get; }
|
||||
SimpleCommand DirectAddItemCommand { get; }
|
||||
SimpleCommand AddItemCommand { get; }
|
||||
SimpleCommand RemoveItemCommand { get; }
|
||||
SimpleCommand DirectRemoveItemCommand { get; }
|
||||
SimpleCommand ClearSelectedItemsCommand { get; }
|
||||
SimpleCommand AlignTopCommand { get; }
|
||||
SimpleCommand AlignVerticalCentersCommand { get; }
|
||||
SimpleCommand AlignBottomCommand { get; }
|
||||
SimpleCommand AlignLeftCommand { get; }
|
||||
SimpleCommand AlignHorizontalCentersCommand { get; }
|
||||
SimpleCommand AlignRightCommand { get; }
|
||||
SimpleCommand BringForwardCommand { get; }
|
||||
SimpleCommand BringToFrontCommand { get; }
|
||||
SimpleCommand SendBackwardCommand { get; }
|
||||
SimpleCommand SendToBackCommand { get; }
|
||||
|
||||
SimpleCommand DistributeHorizontalCommand { get; }
|
||||
SimpleCommand DistributeVerticalCommand { get; }
|
||||
SimpleCommand SelectAllCommand { get; }
|
||||
SimpleCommand UndoCommand { get; }
|
||||
SimpleCommand RedoCommand { get; }
|
||||
|
||||
Func<SelectableDesignerItemViewModelBase, bool> OutAddVerify { get; set; }
|
||||
void ClearSelectedItems();
|
||||
bool BelongToSameGroup(IGroupable item1, IGroupable item2);
|
||||
Rect GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items);
|
||||
void UpdateZIndex();
|
||||
|
||||
Size PageSize { get; set; }
|
||||
PageSizeType PageSizeType { get; set; }
|
||||
bool ShowGrid { get; set; }
|
||||
Size GridCellSize { get; set; }
|
||||
PageSizeOrientation PageSizeOrientation { get; set; }
|
||||
CellHorizontalAlignment CellHorizontalAlignment { get; set; }
|
||||
CellVerticalAlignment CellVerticalAlignment { get; set; }
|
||||
double GridMargin { get; set; }
|
||||
Color GridColor { get; set; }
|
||||
DiagramType DiagramType { get; set; }
|
||||
|
||||
Point CurrentPoint { get; set; }
|
||||
Color CurrentColor { get; set; }
|
||||
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
}
|
||||
}
|
||||
14
AIStudio.Wpf.DiagramDesigner/ViewModels/IGroupable.cs
Normal file
14
AIStudio.Wpf.DiagramDesigner/ViewModels/IGroupable.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IGroupable
|
||||
{
|
||||
Guid Id { get; }
|
||||
Guid ParentId { get; set; }
|
||||
bool IsGroup { get; set; }
|
||||
}
|
||||
}
|
||||
61
AIStudio.Wpf.DiagramDesigner/ViewModels/INPCBase.cs
Normal file
61
AIStudio.Wpf.DiagramDesigner/ViewModels/INPCBase.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
//[Serializable]
|
||||
//public abstract class BindableBase : INotifyPropertyChanged
|
||||
//{
|
||||
// #region INotifyPropertyChanged Implementation
|
||||
// /// <summary>
|
||||
// /// Occurs when any properties are changed on this object.
|
||||
// /// </summary>
|
||||
// public event PropertyChangedEventHandler PropertyChanged
|
||||
// {
|
||||
// add { this.propertyChanged += value; }
|
||||
// remove { this.propertyChanged -= value; }
|
||||
// }
|
||||
|
||||
// protected event PropertyChangedEventHandler propertyChanged;
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// A helper method that raises the PropertyChanged event for a property.
|
||||
// /// </summary>
|
||||
// /// <param name="propertyNames">The names of the properties that changed.</param>
|
||||
// public virtual void NotifyChanged(params string[] propertyNames)
|
||||
// {
|
||||
// foreach (string name in propertyNames)
|
||||
// {
|
||||
// OnPropertyChanged(new PropertyChangedEventArgs(name));
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Raises the PropertyChanged event.
|
||||
// /// </summary>
|
||||
// /// <param name="e">Event arguments.</param>
|
||||
// protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
|
||||
// {
|
||||
// if (this.propertyChanged != null)
|
||||
// {
|
||||
// this.propertyChanged(this, e);
|
||||
// }
|
||||
// }
|
||||
// #endregion
|
||||
|
||||
// public IObservable<string> WhenPropertyChanged
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return Observable
|
||||
// .FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(
|
||||
// h => this.propertyChanged += h,
|
||||
// h => this.propertyChanged -= h)
|
||||
// .Select(x => x.EventArgs.PropertyName);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
12
AIStudio.Wpf.DiagramDesigner/ViewModels/ISelectable.cs
Normal file
12
AIStudio.Wpf.DiagramDesigner/ViewModels/ISelectable.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface ISelectable
|
||||
{
|
||||
bool IsSelected { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PartCreatedConnectionInfo : ConnectorInfoBase
|
||||
{
|
||||
public Point CurrentLocation { get; private set; }
|
||||
|
||||
public PartCreatedConnectionInfo(Point currentLocation) : base(ConnectorOrientation.None)
|
||||
{
|
||||
this.CurrentLocation = currentLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
102
AIStudio.Wpf.DiagramDesigner/ViewModels/SelectionService.cs
Normal file
102
AIStudio.Wpf.DiagramDesigner/ViewModels/SelectionService.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class SelectionService
|
||||
{
|
||||
private IDiagramViewModel DiagramViewModel;
|
||||
|
||||
public SelectionService(IDiagramViewModel diagramViewModel)
|
||||
{
|
||||
this.DiagramViewModel = diagramViewModel;
|
||||
}
|
||||
|
||||
public void AddToSelection(ISelectable item)
|
||||
{
|
||||
if (item is IGroupable)
|
||||
{
|
||||
List<IGroupable> groupItems = GetGroupMembers(item as IGroupable);
|
||||
|
||||
foreach (ISelectable groupItem in groupItems)
|
||||
{
|
||||
groupItem.IsSelected = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
item.IsSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveFromSelection(ISelectable item)
|
||||
{
|
||||
if (item is IGroupable)
|
||||
{
|
||||
List<IGroupable> groupItems = GetGroupMembers(item as IGroupable);
|
||||
|
||||
foreach (ISelectable groupItem in groupItems)
|
||||
{
|
||||
groupItem.IsSelected = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
item.IsSelected = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal List<IGroupable> GetGroupMembers(IGroupable item)
|
||||
{
|
||||
IEnumerable<IGroupable> list = DiagramViewModel.Items.OfType<IGroupable>();
|
||||
IGroupable rootItem = GetRoot(list, item);
|
||||
if (rootItem == null)
|
||||
{
|
||||
return new List<IGroupable>();
|
||||
}
|
||||
return GetGroupMembers(list, rootItem);
|
||||
}
|
||||
|
||||
internal IGroupable GetGroupRoot(IGroupable item)
|
||||
{
|
||||
IEnumerable<IGroupable> list = DiagramViewModel.Items.OfType<IGroupable>();
|
||||
return GetRoot(list, item);
|
||||
}
|
||||
|
||||
private IGroupable GetRoot(IEnumerable<IGroupable> list, IGroupable node)
|
||||
{
|
||||
if (node == null || node.ParentId == Guid.Empty)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (IGroupable item in list)
|
||||
{
|
||||
if (item.Id == node.ParentId)
|
||||
{
|
||||
return GetRoot(list, item);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<IGroupable> GetGroupMembers(IEnumerable<IGroupable> list, IGroupable parent)
|
||||
{
|
||||
List<IGroupable> groupMembers = new List<IGroupable>();
|
||||
groupMembers.Add(parent);
|
||||
|
||||
var children = list.Where(node => node.ParentId == parent.Id && node.ParentId != Guid.Empty);
|
||||
|
||||
foreach (IGroupable child in children)
|
||||
{
|
||||
groupMembers.AddRange(GetGroupMembers(list, child));
|
||||
}
|
||||
|
||||
return groupMembers;
|
||||
}
|
||||
}
|
||||
}
|
||||
66
AIStudio.Wpf.DiagramDesigner/ViewModels/SimpleCommand.cs
Normal file
66
AIStudio.Wpf.DiagramDesigner/ViewModels/SimpleCommand.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class SimpleCommand : ICommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Predicate to execute when the CanExecute of the command gets called
|
||||
/// </summary>
|
||||
public Predicate<object> CanExecuteDelegate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the action to be called when the Execute method of the command gets called
|
||||
/// </summary>
|
||||
public Action<object> ExecuteDelegate { get; set; }
|
||||
|
||||
|
||||
public SimpleCommand(Predicate<object> canExecuteDelegate, Action<object> executeDelegate)
|
||||
{
|
||||
CanExecuteDelegate = canExecuteDelegate;
|
||||
ExecuteDelegate = executeDelegate;
|
||||
}
|
||||
|
||||
public SimpleCommand(Action<object> executeDelegate)
|
||||
{
|
||||
ExecuteDelegate = executeDelegate;
|
||||
}
|
||||
|
||||
#region ICommand Members
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the command Execute method can run
|
||||
/// </summary>
|
||||
/// <param name="parameter">THe command parameter to be passed</param>
|
||||
/// <returns>Returns true if the command can execute. By default true is returned so that if the user of SimpleCommand does not specify a CanExecuteCommand delegate the command still executes.</returns>
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
if (CanExecuteDelegate != null)
|
||||
return CanExecuteDelegate(parameter);
|
||||
|
||||
return true;// if there is no can execute default to true
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the actual command
|
||||
/// </summary>
|
||||
/// <param name="parameter">THe command parameter to be passed</param>
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
if (ExecuteDelegate != null)
|
||||
ExecuteDelegate(parameter);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class GifImageItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
private IDisposable propertyChangedSubscription;
|
||||
private IDisposable connectorsChangedSubscription;
|
||||
|
||||
|
||||
public SimpleCommand AddItemCommand { get; private set; }
|
||||
public SimpleCommand ImageSwitchCommand { get; private set; }
|
||||
|
||||
public GifImageItemViewModel() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public GifImageItemViewModel(IDiagramViewModel parent, MediaDesignerItem designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
AddItemCommand = new SimpleCommand(ExecuteAddItemCommand);
|
||||
ImageSwitchCommand = new SimpleCommand(ExecuteImageSwitchCommand);
|
||||
|
||||
base.Init();
|
||||
|
||||
ClearConnectors();
|
||||
//propertyChangedSubscription = WhenPropertyChanged.Where(o => o.ToString() == "Left" || o.ToString() == "Top" || o.ToString() == "ItemWidth" || o.ToString() == "ItemHeight").Subscribe(ChangeImageElement);
|
||||
connectorsChangedSubscription = WhenConnectorsChanged.Subscribe(OnConnectorsChanged);
|
||||
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(parent, designerbase);
|
||||
|
||||
MediaDesignerItem designer = designerbase as MediaDesignerItem;
|
||||
|
||||
this.Icon = designer.Icon;
|
||||
foreach (var connector in designer.Connectors)
|
||||
{
|
||||
FullyCreatedConnectorInfo fullyCreatedConnectorInfo = new FullyCreatedConnectorInfo(this, connector.Orientation, true);
|
||||
fullyCreatedConnectorInfo.XRatio = connector.XRatio;
|
||||
fullyCreatedConnectorInfo.YRatio = connector.YRatio;
|
||||
fullyCreatedConnectorInfo.ConnectorWidth = connector.ConnectorWidth;
|
||||
fullyCreatedConnectorInfo.ConnectorHeight = connector.ConnectorHeight;
|
||||
AddConnector(fullyCreatedConnectorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _shouldInsertAnchor;
|
||||
public bool ShouldInsertAnchor
|
||||
{
|
||||
get { return _shouldInsertAnchor; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _shouldInsertAnchor, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string dir = System.AppDomain.CurrentDomain.BaseDirectory + "Images\\Gifs";
|
||||
private void BuildMenuOptions()
|
||||
{
|
||||
if (Directory.Exists(dir))
|
||||
{
|
||||
menuOptions = new ObservableCollection<CinchMenuItem>();
|
||||
var equipmentImages = Directory.GetFiles(dir).Select(Path.GetFileName);
|
||||
foreach (var item in equipmentImages)
|
||||
{
|
||||
CinchMenuItem menuItem = new CinchMenuItem();
|
||||
menuItem.Text = item;
|
||||
menuItem.Command = ImageSwitchCommand;
|
||||
menuItem.CommandParameter = item;
|
||||
menuOptions.Add(menuItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteAddItemCommand(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top, true);
|
||||
MouseButtonEventArgs mosueArg = ((EventToCommandArgs)parameter).EventArgs as MouseButtonEventArgs;
|
||||
var position = mosueArg.GetPosition(((EventToCommandArgs)parameter).Sender as IInputElement);
|
||||
connector.XRatio = (position.X - connector.ConnectorWidth / 2) / connector.DataItem.ItemWidth;
|
||||
connector.YRatio = (position.Y - connector.ConnectorHeight / 2) / connector.DataItem.ItemHeight;
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
private void ExecuteImageSwitchCommand(object parameter)
|
||||
{
|
||||
string image = parameter as string;
|
||||
string path = dir + @"\{0}";
|
||||
string filePath = string.Format(path, image);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
Icon = filePath;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnConnectorsChanged(NotifyCollectionChangedEventArgs args)
|
||||
{
|
||||
if (args.Action == NotifyCollectionChangedAction.Add)
|
||||
{
|
||||
if (args.NewItems.Count > 0)
|
||||
{
|
||||
foreach (var item in args.NewItems)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args.Action == NotifyCollectionChangedAction.Remove)
|
||||
{
|
||||
if (args.OldItems.Count > 0)
|
||||
{
|
||||
foreach (var item in args.OldItems)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args.Action == NotifyCollectionChangedAction.Reset)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ImageItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
|
||||
private static readonly string filter = "图片|*.bmp;*.jpg;*.jpeg;*.gif;*.png";
|
||||
public ImageItemViewModel() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public ImageItemViewModel(IDiagramViewModel parent, ImageDesignerItem designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
this.PropertyChanged += ImageItemViewModel_PropertyChanged;
|
||||
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
private void ImageItemViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(ItemWidth) || e.PropertyName == nameof(ItemHeight) || e.PropertyName == nameof(ResizeMargin) || e.PropertyName == nameof(ClipMode))
|
||||
{
|
||||
RaisePropertyChanged(nameof(Object));
|
||||
}
|
||||
else if (e.PropertyName == nameof(IsSelected))
|
||||
{
|
||||
if (IsSelected == false)
|
||||
{
|
||||
EndResize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _suffix;
|
||||
public string Suffix
|
||||
{
|
||||
get { return _suffix; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _suffix, filter.Contains(value) ? value : ".txt");
|
||||
}
|
||||
}
|
||||
|
||||
public ImageItemViewModel Object
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public double ImageWidth { get; set; }
|
||||
public double ImageHeight { get; set; }
|
||||
|
||||
private bool _resizeMode;
|
||||
public bool ResizeMode
|
||||
{
|
||||
get { return _resizeMode; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _resizeMode, value);
|
||||
}
|
||||
}
|
||||
|
||||
//显示的时候是真实的Marigin,不显示的时候是按比例换算的Marigin
|
||||
private Thickness _resizeMargin = new Thickness(0);
|
||||
public Thickness ResizeMargin
|
||||
{
|
||||
get { return _resizeMargin; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _resizeMargin, value);
|
||||
}
|
||||
}
|
||||
|
||||
private ClipMode _clipMode;
|
||||
public ClipMode ClipMode
|
||||
{
|
||||
get { return _clipMode; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _clipMode, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(parent, designerbase);
|
||||
|
||||
ImageDesignerItem designer = designerbase as ImageDesignerItem;
|
||||
|
||||
this.Icon = designer.Icon;
|
||||
Suffix = Path.GetExtension(this.Icon).ToLower();
|
||||
foreach (var connector in designer.Connectors)
|
||||
{
|
||||
FullyCreatedConnectorInfo fullyCreatedConnectorInfo = new FullyCreatedConnectorInfo(this, connector.Orientation, true);
|
||||
fullyCreatedConnectorInfo.XRatio = connector.XRatio;
|
||||
fullyCreatedConnectorInfo.YRatio = connector.YRatio;
|
||||
fullyCreatedConnectorInfo.ConnectorWidth = connector.ConnectorWidth;
|
||||
fullyCreatedConnectorInfo.ConnectorHeight = connector.ConnectorHeight;
|
||||
AddConnector(fullyCreatedConnectorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildMenuOptions()
|
||||
{
|
||||
menuOptions = new ObservableCollection<CinchMenuItem>();
|
||||
CinchMenuItem menuItem = new CinchMenuItem();
|
||||
menuItem.Text = "更换";
|
||||
menuItem.Command = MenuItemCommand;
|
||||
menuItem.CommandParameter = menuItem;
|
||||
menuOptions.Add(menuItem);
|
||||
}
|
||||
|
||||
private SimpleCommand _menuItemCommand;
|
||||
public SimpleCommand MenuItemCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._menuItemCommand ?? (this._menuItemCommand = new SimpleCommand(ExecuteMenuItemCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteMenuItemCommand(object obj)
|
||||
{
|
||||
EditData();
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object param)
|
||||
{
|
||||
if (IsReadOnly == true) return;
|
||||
|
||||
if (ResizeMode == true)
|
||||
{
|
||||
EndResize();
|
||||
return;
|
||||
}
|
||||
|
||||
System.Diagnostics.Process.Start(Icon);
|
||||
|
||||
}
|
||||
|
||||
public void InitWidthAndHeight()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(this.Icon, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
|
||||
this.ImageWidth = image.Width;
|
||||
this.ImageHeight = image.Height;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.Suffix = ".txt";
|
||||
this.ImageWidth = 32;
|
||||
this.ImageHeight = 32;
|
||||
}
|
||||
}
|
||||
public void AutoSize()
|
||||
{
|
||||
this.ItemWidth = this.ImageWidth;
|
||||
this.ItemHeight = this.ImageHeight;
|
||||
}
|
||||
|
||||
public override bool InitData()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Icon))
|
||||
return EditData();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool EditData()
|
||||
{
|
||||
Microsoft.Win32.OpenFileDialog openFile = new Microsoft.Win32.OpenFileDialog();
|
||||
openFile.Filter = filter;
|
||||
|
||||
if (openFile.ShowDialog() == true)
|
||||
{
|
||||
bool needauto = Icon == null;
|
||||
Icon = openFile.FileName;
|
||||
Suffix = Path.GetExtension(Icon).ToLower();
|
||||
InitWidthAndHeight();
|
||||
if (needauto)
|
||||
{
|
||||
AutoSize();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void StartResize()
|
||||
{
|
||||
if (ResizeMode == true) return;
|
||||
|
||||
ResizeMode = true;
|
||||
if (ResizeMargin == new Thickness(0, 0, 0, 0))
|
||||
{
|
||||
ResizeMargin = new Thickness(ItemWidth * 0.1, ItemHeight * 0.1, ItemWidth * 0.1, ItemHeight * 0.1);
|
||||
}
|
||||
else
|
||||
{
|
||||
var margin = ResizeMargin;
|
||||
double xradio = ItemWidth / ImageWidth;
|
||||
double yradio = ItemHeight / ImageHeight;
|
||||
ResizeMargin = new Thickness(margin.Left * xradio, margin.Top * yradio, margin.Right * xradio, margin.Bottom * yradio);
|
||||
|
||||
ItemWidth = ItemWidth + ResizeMargin.Left + ResizeMargin.Right;
|
||||
ItemHeight = ItemHeight + ResizeMargin.Top + ResizeMargin.Bottom;
|
||||
Left = Left - ResizeMargin.Left;
|
||||
Top = Top - ResizeMargin.Top;
|
||||
}
|
||||
}
|
||||
|
||||
public void EndResize()
|
||||
{
|
||||
if (ResizeMode == false)
|
||||
return;
|
||||
|
||||
ResizeMode = false;
|
||||
var margin = ResizeMargin;
|
||||
double xradio = ItemWidth / ImageWidth;
|
||||
double yradio = ItemHeight / ImageHeight;
|
||||
|
||||
ResizeMargin = new Thickness(margin.Left / xradio, margin.Top / yradio, margin.Right / xradio, margin.Bottom / yradio);
|
||||
ItemWidth = ItemWidth - margin.Left - margin.Right;
|
||||
ItemHeight = ItemHeight - margin.Top - margin.Bottom;
|
||||
Left = Left + margin.Left;
|
||||
Top = Top + margin.Top;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (ResizeMode == true)
|
||||
{
|
||||
ResizeMargin = new Thickness(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (ResizeMargin == new Thickness(0, 0, 0, 0))
|
||||
{
|
||||
ResizeMode = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var margin = ResizeMargin;
|
||||
ResizeMargin = new Thickness(0, 0, 0, 0);
|
||||
ItemWidth = ItemWidth + margin.Left + margin.Right;
|
||||
ItemHeight = ItemHeight + margin.Top + margin.Bottom;
|
||||
Left = Left - margin.Left;
|
||||
Top = Top - margin.Top;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public enum ClipMode
|
||||
{
|
||||
RectangleGeometry,
|
||||
EllipseGeometry
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class LinkPointDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
public Point CurrentLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Point() { X = Left + ItemWidth / 2, Y = Top + ItemHeight / 2 };
|
||||
}
|
||||
}
|
||||
|
||||
public LinkPointDesignerItemViewModel(Point location) : base()
|
||||
{
|
||||
Left = Math.Max(0, location.X - ItemWidth / 2);
|
||||
Top = Math.Max(0, location.Y - ItemHeight / 2);
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
this.ClearConnectors();
|
||||
this.AddConnector(new FullyCreatedConnectorInfo(this, ConnectorOrientation.None, true));
|
||||
ItemWidth = 5;
|
||||
ItemHeight = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class MediaItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
protected virtual string Filter { get; set; } = "媒体·|*.*";
|
||||
|
||||
public MediaItemViewModel() : base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public MediaItemViewModel(IDiagramViewModel parent, MediaDesignerItem designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(parent, designerbase);
|
||||
|
||||
MediaDesignerItem designer = designerbase as MediaDesignerItem;
|
||||
|
||||
this.Icon = designer.Icon;
|
||||
|
||||
foreach (var connector in designer.Connectors)
|
||||
{
|
||||
FullyCreatedConnectorInfo fullyCreatedConnectorInfo = new FullyCreatedConnectorInfo(this, connector.Orientation, true);
|
||||
fullyCreatedConnectorInfo.XRatio = connector.XRatio;
|
||||
fullyCreatedConnectorInfo.YRatio = connector.YRatio;
|
||||
fullyCreatedConnectorInfo.ConnectorWidth = connector.ConnectorWidth;
|
||||
fullyCreatedConnectorInfo.ConnectorHeight = connector.ConnectorHeight;
|
||||
AddConnector(fullyCreatedConnectorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildMenuOptions()
|
||||
{
|
||||
menuOptions = new ObservableCollection<CinchMenuItem>();
|
||||
CinchMenuItem menuItem = new CinchMenuItem();
|
||||
menuItem.Text = "更换";
|
||||
menuItem.Command = MenuItemCommand;
|
||||
menuItem.CommandParameter = menuItem;
|
||||
menuOptions.Add(menuItem);
|
||||
}
|
||||
|
||||
private SimpleCommand _menuItemCommand;
|
||||
public SimpleCommand MenuItemCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._menuItemCommand ?? (this._menuItemCommand = new SimpleCommand(ExecuteMenuItemCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteMenuItemCommand(object obj)
|
||||
{
|
||||
EditData();
|
||||
}
|
||||
|
||||
public override bool InitData()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Icon))
|
||||
return EditData();
|
||||
return true;
|
||||
}
|
||||
public override bool EditData()
|
||||
{
|
||||
Microsoft.Win32.OpenFileDialog openFile = new Microsoft.Win32.OpenFileDialog();
|
||||
openFile.Filter = Filter;
|
||||
|
||||
if (openFile.ShowDialog() == true)
|
||||
{
|
||||
Icon = openFile.FileName;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object param)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PointDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
private bool _showConnectors = false;
|
||||
public new bool ShowConnectors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showConnectors;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _showConnectors, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Point CurrentLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Point() { X = Left + ItemWidth / 2, Y = Top + ItemHeight / 2 };
|
||||
}
|
||||
}
|
||||
|
||||
public PointDesignerItemViewModel(Point location) : base()
|
||||
{
|
||||
Left = Math.Max(0, location.X - ItemWidth / 2);
|
||||
Top = Math.Max(0, location.Y - ItemHeight / 2);
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
this.ClearConnectors();
|
||||
this.AddConnector(new FullyCreatedConnectorInfo(this, ConnectorOrientation.None, true));
|
||||
|
||||
ItemWidth = 5;
|
||||
ItemHeight = 5;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ShapeDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
public List<PointDesignerItemViewModel> PointDesignerItemViewModels { get; set; }
|
||||
|
||||
private List<Point> _connectionPoints;
|
||||
public List<Point> ConnectionPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
return _connectionPoints;
|
||||
}
|
||||
private set
|
||||
{
|
||||
SetProperty(ref _connectionPoints, value);
|
||||
}
|
||||
}
|
||||
public DrawMode DrawMode { get; set; }
|
||||
|
||||
private bool _showConnectors = false;
|
||||
public new bool ShowConnectors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showConnectors;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _showConnectors, value))
|
||||
{
|
||||
foreach (var connector in PointDesignerItemViewModels)
|
||||
{
|
||||
connector.ShowConnectors = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCommand MenuItemCommand { get; private set; }
|
||||
|
||||
public ShapeDesignerItemViewModel(DrawMode drawMode, List<Point> points) : base()
|
||||
{
|
||||
DrawMode = drawMode;
|
||||
ConnectionPoints = points;
|
||||
|
||||
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
||||
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
||||
Left = ConnectionPoints.Min(p => p.X);
|
||||
Top = ConnectionPoints.Min(p => p.Y);
|
||||
|
||||
PointDesignerItemViewModels = new List<PointDesignerItemViewModel>();
|
||||
ConnectionPoints.ForEach((Action<Point>)(p =>
|
||||
{
|
||||
var item = new PointDesignerItemViewModel(p);
|
||||
PointDesignerItemViewModels.Add((PointDesignerItemViewModel)item);
|
||||
}));
|
||||
|
||||
PointDesignerItemViewModels.ForEach(p => p.PropertyChanged += PointDesignerItemViewModel_PropertyChanged);
|
||||
}
|
||||
|
||||
private void PointDesignerItemViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Left) || e.PropertyName == nameof(Top))
|
||||
{
|
||||
UpdatePoints();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePoints()
|
||||
{
|
||||
ConnectionPoints = PointDesignerItemViewModels.Select(p => p.CurrentLocation).ToList();
|
||||
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
||||
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
||||
Left = ConnectionPoints.Min(p => p.X);
|
||||
Top = ConnectionPoints.Min(p => p.Y);
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
MenuItemCommand = new SimpleCommand(ExecuteMenuItemCommand);
|
||||
base.Init();
|
||||
|
||||
this.ClearConnectors();
|
||||
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
private void ExecuteMenuItemCommand(object obj)
|
||||
{
|
||||
ShowConnectors = (obj as CinchMenuItem).IsChecked;
|
||||
}
|
||||
|
||||
private void BuildMenuOptions()
|
||||
{
|
||||
menuOptions = new ObservableCollection<CinchMenuItem>();
|
||||
CinchMenuItem menuItem = new CinchMenuItem();
|
||||
menuItem.Text = "显示点";
|
||||
menuItem.IsCheckable = true;
|
||||
menuItem.Command = MenuItemCommand;
|
||||
menuItem.CommandParameter = menuItem;
|
||||
menuOptions.Add(menuItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class TextDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
|
||||
public TextDesignerItemViewModel(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TextDesignerItemViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
this.ItemWidth = 150;
|
||||
this.ClearConnectors();
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object param)
|
||||
{
|
||||
if (IsReadOnly == true) return;
|
||||
}
|
||||
|
||||
private string _watermark = "请输入文本";
|
||||
public string Watermark
|
||||
{
|
||||
get
|
||||
{
|
||||
return _watermark;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _watermark, value);
|
||||
}
|
||||
}
|
||||
|
||||
//固定在DataTemplate中处理
|
||||
private bool _showText;
|
||||
public override bool ShowText
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _showText, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class VideoItemViewModel : MediaItemViewModel
|
||||
{
|
||||
protected override string Filter { get; set; } = "视频|*.wmv;*.asf;*.asx;*.rm;*.rmvb;*.mp4;*.3gp;*.mov;*.m4v;*.avi;*.dat;*.mkv;*.flv;*.vob";
|
||||
|
||||
public VideoItemViewModel() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public VideoItemViewModel(IDiagramViewModel parent, MediaDesignerItem designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user