Flowchart

This commit is contained in:
艾竹
2022-12-04 23:07:20 +08:00
parent dc42f75610
commit 0487857d7b
30 changed files with 1621 additions and 383 deletions

View File

@@ -72,14 +72,14 @@ namespace AIStudio.Wpf.DiagramDesigner
if (e.LeftButton != MouseButtonState.Pressed)
dragStartPoint = null;
if (dragStartPoint.HasValue)
if (dragStartPoint.HasValue && ((FrameworkElement)sender).DataContext is ToolBoxData toolBoxData)
{
DragObject dataObject = new DragObject();
dataObject.ContentType = (((FrameworkElement)sender).DataContext as ToolBoxData).Type;
dataObject.DesiredSize = new Size(65, 65);
dataObject.Icon = (((FrameworkElement)sender).DataContext as ToolBoxData).Icon;
dataObject.ColorViewModel = (((FrameworkElement)sender).DataContext as ToolBoxData).ColorViewModel;
dataObject.DesignerItem = (((FrameworkElement)sender).DataContext as ToolBoxData).Addition as DesignerItemBase;
dataObject.ContentType = toolBoxData.Type;
dataObject.DesiredSize = toolBoxData.DesiredSize;
dataObject.Icon = toolBoxData.Icon;
dataObject.ColorViewModel = toolBoxData.ColorViewModel;
dataObject.DesignerItem = toolBoxData.Addition as DesignerItemBase;
DragDrop.DoDragDrop((DependencyObject)sender, dataObject, DragDropEffects.Copy);
e.Handled = true;

View File

@@ -25,6 +25,21 @@ namespace AIStudio.Wpf.DiagramDesigner
private Point? rubberbandSelectionStartPoint = null;
private DrawMode VectorLineDrawMode
{
get
{
if (_viewModel.VectorLineDrawMode != null)
{
return _viewModel.VectorLineDrawMode.Value;
}
else
{
return _service.DrawModeViewModel.VectorLineDrawMode;
}
}
}
#region GridCellSize
public static readonly DependencyProperty GridCellSizeProperty =
@@ -188,7 +203,7 @@ namespace AIStudio.Wpf.DiagramDesigner
Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize));
Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
partialConnection = new ConnectorViewModel(sourceDataItem, new PartCreatedConnectionInfo(point), _service.DrawModeViewModel.VectorLineDrawMode);
partialConnection = new ConnectorViewModel(sourceDataItem, new PartCreatedConnectionInfo(point), VectorLineDrawMode);
_viewModel.DirectAddItemCommand.Execute(partialConnection);
}
}
@@ -209,7 +224,7 @@ namespace AIStudio.Wpf.DiagramDesigner
Rect rectangleBounds = new Rect(sourceConnectorInfo.DataItem.Left, sourceConnectorInfo.DataItem.Top, 3, 3);
Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
partialConnection = new ConnectorViewModel(sourceConnectorInfo, new PartCreatedConnectionInfo(point), _service.DrawModeViewModel.VectorLineDrawMode);
partialConnection = new ConnectorViewModel(sourceConnectorInfo, new PartCreatedConnectionInfo(point), VectorLineDrawMode);
_viewModel.DirectAddItemCommand.Execute(partialConnection);
}
}
@@ -218,6 +233,7 @@ namespace AIStudio.Wpf.DiagramDesigner
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (_viewModel.IsReadOnly) return;
if (_service.DrawModeViewModel.CursorMode == CursorMode.Format)
{
@@ -271,6 +287,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
base.OnMouseMove(e);
if (_viewModel.IsReadOnly) return;
Point currentPoint = e.GetPosition(this);
_viewModel.CurrentPoint = currentPoint;
var point = CursorPointManager.GetCursorPosition();
@@ -323,6 +341,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
base.OnMouseUp(e);
if (_viewModel.IsReadOnly) return;
if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine)
{
return;
@@ -341,7 +361,7 @@ namespace AIStudio.Wpf.DiagramDesigner
int indexOfLastTempConnection = sinkDataItem.DataItem.Parent.Items.Count - 1;
sinkDataItem.DataItem.Parent.DirectRemoveItemCommand.Execute(
sinkDataItem.DataItem.Parent.Items[indexOfLastTempConnection]);
sinkDataItem.DataItem.Parent.AddItemCommand.Execute(new ConnectorViewModel(sourceDataItem, sinkDataItem, _service.DrawModeViewModel.VectorLineDrawMode));
sinkDataItem.DataItem.Parent.AddItemCommand.Execute(new ConnectorViewModel(sourceDataItem, sinkDataItem, VectorLineDrawMode));
}
else if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.ConnectingLine && connectorsHit.Count() == 1)
{
@@ -352,7 +372,7 @@ namespace AIStudio.Wpf.DiagramDesigner
_viewModel.DirectRemoveItemCommand.Execute(_viewModel.Items[indexOfLastTempConnection]);
_viewModel.DirectAddItemCommand.Execute(pointItemView);
var connector = new ConnectorViewModel(sourceDataItem, sinkDataItem, _service.DrawModeViewModel.VectorLineDrawMode);
var connector = new ConnectorViewModel(sourceDataItem, sinkDataItem, VectorLineDrawMode);
_viewModel.AddItemCommand.Execute(connector);
sourceDataItem.DataItem.ZIndex++;
@@ -380,6 +400,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
base.OnPreviewKeyDown(e);
if (_viewModel.IsReadOnly) return;
if (e.Key == Key.Left)
{
if (_viewModel.SelectedItems != null)
@@ -472,6 +494,9 @@ namespace AIStudio.Wpf.DiagramDesigner
protected override void OnDrop(DragEventArgs e)
{
base.OnDrop(e);
if (_viewModel.IsReadOnly) return;
DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
if (dragObject != null)
{
@@ -480,17 +505,22 @@ namespace AIStudio.Wpf.DiagramDesigner
DesignerItemViewModelBase itemBase = null;
if (dragObject.DesignerItem != null)
{
itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(dragObject.ContentType, null, dragObject.DesignerItem);
itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(dragObject.ContentType, _viewModel, dragObject.DesignerItem);
}
else
{
itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(dragObject.ContentType);
itemBase.Icon = dragObject.Icon;
itemBase.ColorViewModel = CopyHelper.Mapper(dragObject.ColorViewModel);
if (dragObject.DesiredSize != null)
{
itemBase.ItemWidth = dragObject.DesiredSize.Value.Width;
itemBase.ItemHeight = dragObject.DesiredSize.Value.Height;
}
}
itemBase.Left = Math.Max(0, position.X - itemBase.ItemWidth / 2);
itemBase.Top = Math.Max(0, position.Y - itemBase.ItemHeight / 2);
(DataContext as IDiagramViewModel).AddItemCommand.Execute(itemBase);
_viewModel.AddItemCommand.Execute(itemBase);
}
var dragFile = e.Data.GetData(DataFormats.FileDrop);
if (dragFile != null && dragFile is string[] files)

View File

@@ -31,8 +31,10 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
if (designerItem is ConnectorViewModel connector)
{
designerItems.Add(connector.SourceConnectorInfo.DataItem);
designerItems.Add((connector.SinkConnectorInfo as FullyCreatedConnectorInfo).DataItem);
if (connector.SinkConnectorInfo is FullyCreatedConnectorInfo)
{
designerItems.Add((connector.SinkConnectorInfo as FullyCreatedConnectorInfo).DataItem);
}
if (designerItem.OutTextItem != null)
{
designerItems.Remove(designerItem.OutTextItem);//这个自动计算位置

View File

@@ -6,6 +6,17 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public static class EnumExtension
{
/// <summary>
/// Converts to enum.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="str">The string.</param>
/// <returns></returns>
public static T ToEnum<T>(this string str)
{
return (T)Enum.Parse(typeof(T), str);
}
public static string GetDescription(this Enum value)
{
FieldInfo field = value.GetType().GetField(value.ToString());

View File

@@ -0,0 +1,48 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace AIStudio.Wpf.DiagramDesigner
{
public static class ScreenHelper
{
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(
IntPtr hWnd,
IntPtr hDc
);
[DllImport("gdi32.dll")]
public static extern int GetDeviceCaps(
IntPtr hdc, // handle to DC
int nIndex // index of capability
);
public static System.Drawing.Size GetPhysicalDisplaySize()
{
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
int physicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.Desktopvertres);
int physicalScreenWidth = GetDeviceCaps(desktop, (int)DeviceCap.Desktophorzres);
ReleaseDC(IntPtr.Zero, desktop);
g.Dispose();
return new System.Drawing.Size(physicalScreenWidth, physicalScreenHeight);
}
public enum DeviceCap
{
Desktopvertres = 117,
Desktophorzres = 118
}
public static double ResetScreenScale()
{
using (var g = Graphics.FromHwnd(IntPtr.Zero))
{
IntPtr desktop = g.GetHdc();
int physicalScreenWidth = GetDeviceCaps(desktop, (int)DeviceCap.Desktophorzres);
return physicalScreenWidth * 1.0000 / System.Windows.SystemParameters.PrimaryScreenWidth;
}
}
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace AIStudio.Wpf.DiagramDesigner.Helpers
{
@@ -13,16 +14,18 @@ namespace AIStudio.Wpf.DiagramDesigner.Helpers
public IColorViewModel ColorViewModel { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public Size? DesiredSize{ get; set; }
public object Addition { get; set; }
public ToolBoxData(string text, string icon, Type type, double width, double height)
public ToolBoxData(string text, string icon, Type type, double width, double height, Size? desiredSize = null)
{
this.Text = text;
this.Icon = icon;
this.Type = type;
this.Width = width;
this.Height = height;
this.Height = height;
this.DesiredSize = desiredSize;
this.ColorViewModel = new ColorViewModel();
}
}

View File

@@ -46,32 +46,56 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlAttribute]
public Guid Id { get; set; }
public Guid Id
{
get; set;
}
[XmlAttribute]
public int ZIndex { get; set; }
public int ZIndex
{
get; set;
}
[XmlAttribute]
public bool IsGroup { get; set; }
public bool IsGroup
{
get; set;
}
[XmlAttribute]
public Guid ParentId { get; set; }
public Guid ParentId
{
get; set;
}
[XmlAttribute]
public string Text { get; set; }
public string Text
{
get; set;
}
[XmlElement]
public ColorItem ColorItem { get; set; }
public ColorItem ColorItem
{
get; set;
}
[XmlElement]
public FontItem FontItem { get; set; }
public FontItem FontItem
{
get; set;
}
}
public class ColorItem : IColorViewModel
{
{
[XmlIgnore]
public IColorObject LineColor { get; set; }
public IColorObject LineColor
{
get; set;
}
[JsonIgnore]
[XmlElement("LineColor")]
@@ -88,7 +112,10 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlIgnore]
public IColorObject FillColor { get; set; }
public IColorObject FillColor
{
get; set;
}
[JsonIgnore]
[XmlElement("FillColor")]
@@ -106,7 +133,10 @@ namespace AIStudio.Wpf.DiagramDesigner
[XmlIgnore]
public Color ShadowColor { get; set; }
public Color ShadowColor
{
get; set;
}
[JsonIgnore]
[XmlElement("ShadowColor")]
@@ -123,19 +153,34 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlAttribute]
public double LineWidth { get; set; }
public double LineWidth
{
get; set;
}
[XmlAttribute]
public ArrowPathStyle LeftArrowPathStyle { get; set; }
public ArrowPathStyle LeftArrowPathStyle
{
get; set;
}
[XmlAttribute]
public ArrowPathStyle RightArrowPathStyle { get; set; }
public ArrowPathStyle RightArrowPathStyle
{
get; set;
}
[XmlAttribute]
public ArrowSizeStyle LeftArrowSizeStyle { get; set; }
public ArrowSizeStyle LeftArrowSizeStyle
{
get; set;
}
[XmlAttribute]
public ArrowSizeStyle RightArrowSizeStyle { get; set; }
public ArrowSizeStyle RightArrowSizeStyle
{
get; set;
}
public event PropertyChangedEventHandler PropertyChanged;
}
@@ -144,20 +189,41 @@ namespace AIStudio.Wpf.DiagramDesigner
public class FontItem : IFontViewModel
{
[XmlIgnore]
public FontWeight FontWeight { get; set; }
public FontWeight FontWeight
{
get; set;
}
[XmlIgnore]
public FontStyle FontStyle { get; set; }
public FontStyle FontStyle
{
get; set;
}
[XmlIgnore]
public FontStretch FontStretch { get; set; }
public FontStretch FontStretch
{
get; set;
}
[XmlAttribute]
public bool Underline { get; set; }
public bool Underline
{
get; set;
}
[XmlAttribute]
public bool Strikethrough { get; set; }
public bool Strikethrough
{
get; set;
}
[XmlAttribute]
public bool OverLine { get; set; }
public bool OverLine
{
get; set;
}
[XmlIgnore]
public Color FontColor { get; set; }
public Color FontColor
{
get; set;
}
[JsonIgnore]
[XmlElement("FontColor")]
@@ -174,10 +240,16 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlIgnore]
public string FontFamily { get; set; }
public string FontFamily
{
get; set;
}
[XmlIgnore]
public double FontSize { get; set; }
public double FontSize
{
get; set;
}
[XmlIgnore]
@@ -237,7 +309,10 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlIgnore]
public Color TextEffectColor { get; set; }
public Color TextEffectColor
{
get; set;
}
[JsonIgnore]
[XmlElement("TextEffectColor")]
@@ -254,7 +329,10 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlIgnore]
public Color HighlightColor { get; set; }
public Color HighlightColor
{
get; set;
}
[JsonIgnore]
[XmlElement("HighlightColor")]
@@ -271,13 +349,25 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlAttribute]
public FontCase FontCase { get; set; }
public FontCase FontCase
{
get; set;
}
[XmlAttribute]
public HorizontalAlignment HorizontalAlignment { get; set; }
public HorizontalAlignment HorizontalAlignment
{
get; set;
}
[XmlAttribute]
public VerticalAlignment VerticalAlignment { get; set; }
public VerticalAlignment VerticalAlignment
{
get; set;
}
[XmlAttribute]
public double LineHeight { get; set; }
public double LineHeight
{
get; set;
}
public event PropertyChangedEventHandler PropertyChanged;
}
@@ -286,18 +376,38 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public static string SerializeColor(Color color)
{
return string.Format("{0}:{1}:{2}:{3}", color.A, color.R, color.G, color.B);
return string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.A, color.R, color.G, color.B);
}
public static Color DeserializeColor(string color)
{
{
byte a, r, g, b;
string[] pieces = color.Split(new char[] { ':' });
a = byte.Parse(pieces[0]);
r = byte.Parse(pieces[1]);
g = byte.Parse(pieces[2]);
b = byte.Parse(pieces[3]);
return Color.FromArgb(a, r, g, b);
try
{
if (color?.Length == 9)
{
a = Convert.ToByte(color.Substring(1, 2), 16);
r = Convert.ToByte(color.Substring(3, 2), 16);
g = Convert.ToByte(color.Substring(5, 2), 16);
b = Convert.ToByte(color.Substring(7, 2), 16);
return Color.FromArgb(a, r, g, b);
}
else if (color?.Length == 7)
{
r = Convert.ToByte(color.Substring(1, 2), 16);
g = Convert.ToByte(color.Substring(3, 2), 16);
b = Convert.ToByte(color.Substring(5, 2), 16);
return Color.FromRgb(r, g, b);
}
else
{
return Colors.Black;
}
}
catch
{
return Colors.Black;
}
}
public static GradientStop DeserializeGradientStop(string str)
@@ -308,7 +418,7 @@ namespace AIStudio.Wpf.DiagramDesigner
public static string SerializeColorList(IEnumerable<Color> colors)
{
return string.Join("-", colors.Select(color => string.Format("{0}:{1}:{2}:{3}", color.A, color.R, color.G, color.B)));
return string.Join("-", colors.Select(color => string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.A, color.R, color.G, color.B)));
}
public static List<Color> DeserializeColorList(string colorstring)
@@ -317,13 +427,7 @@ namespace AIStudio.Wpf.DiagramDesigner
var colors = colorstring.Split('-');
foreach (var color in colors)
{
byte a, r, g, b;
string[] pieces = color.Split(new char[] { ':' });
a = byte.Parse(pieces[0]);
r = byte.Parse(pieces[1]);
g = byte.Parse(pieces[2]);
b = byte.Parse(pieces[3]);
colorlist.Add(Color.FromArgb(a, r, g, b));
colorlist.Add(DeserializeColor(color));
}
return colorlist;
}
@@ -388,10 +492,16 @@ namespace AIStudio.Wpf.DiagramDesigner
{
[XmlAttribute]
public BrushType BrushType { get; set; }
public BrushType BrushType
{
get; set;
}
[XmlIgnore]
public Color Color { get; set; }
public Color Color
{
get; set;
}
[JsonIgnore]
[XmlElement("FillColor")]
@@ -408,7 +518,10 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlIgnore]
public ObservableCollection<GradientStop> GradientStop { get; set; }
public ObservableCollection<GradientStop> GradientStop
{
get; set;
}
[JsonIgnore]
[XmlArray("GradientStop")]
@@ -427,7 +540,10 @@ namespace AIStudio.Wpf.DiagramDesigner
[XmlIgnore]
public IEnumerable<double> Offset { get; set; }
public IEnumerable<double> Offset
{
get; set;
}
[JsonIgnore]
[XmlArray("Offset")]
@@ -444,13 +560,22 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlAttribute]
public string Image { get; set; }
public string Image
{
get; set;
}
[XmlAttribute]
public int SubType { get; set; }
public int SubType
{
get; set;
}
[XmlIgnore]
public Point StartPoint { get; set; }
public Point StartPoint
{
get; set;
}
[JsonIgnore]
[XmlAttribute("StartPoint")]
@@ -467,7 +592,10 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlIgnore]
public Point EndPoint { get; set; }
public Point EndPoint
{
get; set;
}
[JsonIgnore]
[XmlAttribute("EndPoint")]
@@ -484,13 +612,25 @@ namespace AIStudio.Wpf.DiagramDesigner
}
[XmlAttribute]
public double Opacity { get; set; }
public double Opacity
{
get; set;
}
[XmlAttribute]
public LinearOrientation LinearOrientation { get; set; }
public LinearOrientation LinearOrientation
{
get; set;
}
[XmlAttribute]
public RadialOrientation RadialOrientation { get; set; }
public RadialOrientation RadialOrientation
{
get; set;
}
[XmlAttribute]
public int Angle { get; set; }
public int Angle
{
get; set;
}
}
}

View File

@@ -144,7 +144,11 @@ namespace AIStudio.Wpf.DiagramDesigner
{
get
{
if (LockObjectViewModel != null && LockObjectViewModel.LockObject.FirstOrDefault(p => p.LockFlag == LockFlag.All).IsChecked == true)
if (Parent?.IsReadOnly == true)
{
return true;
}
if (LockObjectViewModel?.LockObject.FirstOrDefault(p => p.LockFlag == LockFlag.All)?.IsChecked == true)
{
return true;
}

View File

@@ -14,6 +14,24 @@ namespace AIStudio.Wpf.DiagramDesigner
public class DiagramViewModel : BindableBase, IDiagramViewModel
{
#region
private bool _isReadOnly;
public bool IsReadOnly
{
get
{
return _isReadOnly;
}
set
{
SetProperty(ref _isReadOnly, value);
}
}
public DrawMode? VectorLineDrawMode
{
get; set;
}
private PageSizeType _pageSizeType = PageSizeType.A4;
public PageSizeType PageSizeType
{
@@ -320,6 +338,11 @@ namespace AIStudio.Wpf.DiagramDesigner
SetProperty(ref _currentColor, value);
}
}
/// <summary>
/// 用于wpf大小与物理像素之间转换
/// </summary>
public double ScreenScale { get; set; } = 1;
#endregion
private DoCommandManager DoCommandManager = new DoCommandManager();
@@ -439,26 +462,83 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public SimpleCommand CreateNewDiagramCommand { get; private set; }
public SimpleCommand DirectAddItemCommand { get; private set; }
public SimpleCommand AddItemCommand { get; private set; }
public SimpleCommand DirectRemoveItemCommand { get; private set; }
public SimpleCommand RemoveItemCommand { get; private set; }
public SimpleCommand ClearSelectedItemsCommand { get; private set; }
public SimpleCommand AlignTopCommand { get; private set; }
public SimpleCommand AlignVerticalCentersCommand { get; private set; }
public SimpleCommand AlignBottomCommand { get; private set; }
public SimpleCommand AlignLeftCommand { get; private set; }
public SimpleCommand AlignHorizontalCentersCommand { get; private set; }
public SimpleCommand AlignRightCommand { get; private set; }
public SimpleCommand BringForwardCommand { get; private set; }
public SimpleCommand BringToFrontCommand { get; private set; }
public SimpleCommand SendBackwardCommand { get; private set; }
public SimpleCommand SendToBackCommand { get; private set; }
public SimpleCommand CreateNewDiagramCommand
{
get; private set;
}
public SimpleCommand DirectAddItemCommand
{
get; private set;
}
public SimpleCommand AddItemCommand
{
get; private set;
}
public SimpleCommand DirectRemoveItemCommand
{
get; private set;
}
public SimpleCommand RemoveItemCommand
{
get; private set;
}
public SimpleCommand ClearSelectedItemsCommand
{
get; private set;
}
public SimpleCommand AlignTopCommand
{
get; private set;
}
public SimpleCommand AlignVerticalCentersCommand
{
get; private set;
}
public SimpleCommand AlignBottomCommand
{
get; private set;
}
public SimpleCommand AlignLeftCommand
{
get; private set;
}
public SimpleCommand AlignHorizontalCentersCommand
{
get; private set;
}
public SimpleCommand AlignRightCommand
{
get; private set;
}
public SimpleCommand BringForwardCommand
{
get; private set;
}
public SimpleCommand BringToFrontCommand
{
get; private set;
}
public SimpleCommand SendBackwardCommand
{
get; private set;
}
public SimpleCommand SendToBackCommand
{
get; private set;
}
public SimpleCommand DistributeHorizontalCommand { get; private set; }
public SimpleCommand DistributeVerticalCommand { get; private set; }
public SimpleCommand SelectAllCommand { get; private set; }
public SimpleCommand DistributeHorizontalCommand
{
get; private set;
}
public SimpleCommand DistributeVerticalCommand
{
get; private set;
}
public SimpleCommand SelectAllCommand
{
get; private set;
}
private SimpleCommand _undoCommand;
public SimpleCommand UndoCommand
@@ -483,7 +563,10 @@ namespace AIStudio.Wpf.DiagramDesigner
public List<SelectableDesignerItemViewModelBase> SelectedItems
{
get { return Items.Where(x => x.IsSelected).ToList(); }
get
{
return Items.Where(x => x.IsSelected).ToList();
}
}
@@ -499,7 +582,10 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public Func<SelectableDesignerItemViewModelBase, bool> OutAddVerify { get; set; }
public Func<SelectableDesignerItemViewModelBase, bool> OutAddVerify
{
get; set;
}
public bool AddVerify(SelectableDesignerItemViewModelBase item)
{
@@ -567,13 +653,11 @@ namespace AIStudio.Wpf.DiagramDesigner
if (AddVerify(ite) != true) return;
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
ClearSelectedItems();
Add(ite);
},
() =>
{
() => {
Items.Remove(ite);
});
}
@@ -582,16 +666,14 @@ namespace AIStudio.Wpf.DiagramDesigner
if (items.Select(p => AddVerify(p)).Any() != true) return;
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
ClearSelectedItems();
foreach (var item in items)
{
Add(item);
}
},
() =>
{
() => {
items.ForEach(item => Items.Remove(item));
});
}
@@ -626,8 +708,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (parameter is SelectableDesignerItemViewModelBase ite)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
ite.IsSelected = false;
Items.Remove(ite);
if (ite.OutTextItem != null)
@@ -636,16 +717,14 @@ namespace AIStudio.Wpf.DiagramDesigner
}
},
() =>
{
() => {
Items.Add(ite);
});
}
else if (parameter is List<SelectableDesignerItemViewModelBase> items)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
foreach (var item in items)
{
item.IsSelected = false;
@@ -657,8 +736,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
},
() =>
{
() => {
foreach (var item in items)
{
Items.Add(item);
@@ -693,8 +771,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count() > 1)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
double top = selectedItems.OrderBy(p => p.Top).Select(p => p.Top).FirstOrDefault();
foreach (DesignerItemViewModelBase item in selectedItems)
@@ -703,15 +780,13 @@ namespace AIStudio.Wpf.DiagramDesigner
item.Top = top;
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Top = item.GetOldValue<double>(nameof(item.Top), guid.ToString());
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.ClearOldValue<double>(nameof(item.Top), guid.ToString());
@@ -728,8 +803,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count() > 1)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
double mid = selectedItems.Select(p => p.Top + p.ItemHeight / 2).Average();
foreach (DesignerItemViewModelBase item in selectedItems)
@@ -738,15 +812,13 @@ namespace AIStudio.Wpf.DiagramDesigner
item.Top = mid - item.ItemHeight / 2;
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Top = item.GetOldValue<double>(nameof(item.Top), guid.ToString());
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.ClearOldValue<double>(nameof(item.Top), guid.ToString());
@@ -763,8 +835,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count() > 1)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
double top = selectedItems.OrderBy(p => p.Top + p.ItemHeight).Select(p => p.Top + p.ItemHeight).LastOrDefault();
foreach (DesignerItemViewModelBase item in selectedItems)
@@ -773,15 +844,13 @@ namespace AIStudio.Wpf.DiagramDesigner
item.Top = top - item.ItemHeight;
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Top = item.GetOldValue<double>(nameof(item.Top), guid.ToString());
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.ClearOldValue<double>(nameof(item.Top), guid.ToString());
@@ -798,8 +867,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count() > 1)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
double left = selectedItems.OrderBy(p => p.Left).Select(p => p.Left).FirstOrDefault();
foreach (DesignerItemViewModelBase item in selectedItems)
@@ -808,15 +876,13 @@ namespace AIStudio.Wpf.DiagramDesigner
item.Left = left;
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Left = item.GetOldValue<double>(nameof(item.Left), guid.ToString());
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.ClearOldValue<double>(nameof(item.Left), guid.ToString());
@@ -833,8 +899,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count() > 1)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
double mid = selectedItems.Select(p => p.Left + p.ItemWidth / 2).Average();
foreach (DesignerItemViewModelBase item in selectedItems)
@@ -843,15 +908,13 @@ namespace AIStudio.Wpf.DiagramDesigner
item.Left = mid - item.ItemWidth / 2;
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Left = item.GetOldValue<double>(nameof(item.Left), guid.ToString());
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.ClearOldValue<double>(nameof(item.Left), guid.ToString());
@@ -868,8 +931,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count() > 1)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
double right = selectedItems.OrderBy(p => p.Left + p.ItemWidth).Select(p => p.Left + p.ItemWidth).LastOrDefault();
foreach (DesignerItemViewModelBase item in selectedItems)
@@ -878,15 +940,13 @@ namespace AIStudio.Wpf.DiagramDesigner
item.Left = right - item.ItemWidth;
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.Left = item.GetOldValue<double>(nameof(item.Left), guid.ToString());
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
item.ClearOldValue<double>(nameof(item.Left), guid.ToString());
@@ -904,8 +964,7 @@ namespace AIStudio.Wpf.DiagramDesigner
var guid = Guid.NewGuid();
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
int count = this.Items.Count;
for (int i = 0; i < ordered.Count; i++)
{
@@ -933,15 +992,13 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
},
() =>
{
() => {
foreach (var item in changeditems)
{
item.ZIndex = item.GetOldValue<int>(nameof(item.ZIndex), guid.ToString());
}
},
() =>
{
() => {
foreach (var item in changeditems)
{
item.ClearOldValue<double>(nameof(item.ZIndex), guid.ToString());
@@ -957,8 +1014,7 @@ namespace AIStudio.Wpf.DiagramDesigner
var guid = Guid.NewGuid();
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
int i = childrenSorted.Count - 1;
int j = childrenSorted.Count - selectionSorted.Count - 1;
@@ -976,15 +1032,13 @@ namespace AIStudio.Wpf.DiagramDesigner
changeditems.Add(item);
}
},
() =>
{
() => {
foreach (var item in changeditems)
{
item.ZIndex = item.GetOldValue<int>(nameof(item.ZIndex), guid.ToString());
}
},
() =>
{
() => {
foreach (var item in changeditems)
{
item.ClearOldValue<double>(nameof(item.ZIndex), guid.ToString());
@@ -1000,8 +1054,7 @@ namespace AIStudio.Wpf.DiagramDesigner
var guid = Guid.NewGuid();
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
for (int i = 0; i < ordered.Count; i++)
{
var item = ordered[i];
@@ -1028,15 +1081,13 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
},
() =>
{
() => {
foreach (var item in changeditems)
{
item.ZIndex = item.GetOldValue<int>(nameof(item.ZIndex), guid.ToString());
}
},
() =>
{
() => {
foreach (var item in changeditems)
{
item.ClearOldValue<double>(nameof(item.ZIndex), guid.ToString());
@@ -1052,8 +1103,7 @@ namespace AIStudio.Wpf.DiagramDesigner
var guid = Guid.NewGuid();
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
int i = childrenSorted.Count - 1;
int j = selectionSorted.Count - 1;
@@ -1071,15 +1121,13 @@ namespace AIStudio.Wpf.DiagramDesigner
changeditems.Add(item);
}
},
() =>
{
() => {
foreach (var item in changeditems)
{
item.ZIndex = item.GetOldValue<int>(nameof(item.ZIndex), guid.ToString());
}
},
() =>
{
() => {
foreach (var item in changeditems)
{
item.ClearOldValue<double>(nameof(item.ZIndex), guid.ToString());
@@ -1097,8 +1145,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count() > 1)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
double left = Double.MaxValue;
double right = Double.MinValue;
double sumWidth = 0;
@@ -1124,8 +1171,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
foreach (DesignerItemViewModelBase di in SelectionService.GetGroupMembers(item))
@@ -1134,8 +1180,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
foreach (DesignerItemViewModelBase di in SelectionService.GetGroupMembers(item))
@@ -1158,8 +1203,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (selectedItems.Count() > 1)
{
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
double top = Double.MaxValue;
double bottom = Double.MinValue;
double sumHeight = 0;
@@ -1184,8 +1228,7 @@ namespace AIStudio.Wpf.DiagramDesigner
offset = offset + item.ItemHeight + distance;
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
foreach (DesignerItemViewModelBase di in SelectionService.GetGroupMembers(item))
@@ -1194,8 +1237,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
},
() =>
{
() => {
foreach (DesignerItemViewModelBase item in selectedItems)
{
foreach (DesignerItemViewModelBase di in SelectionService.GetGroupMembers(item))
@@ -1253,7 +1295,12 @@ namespace AIStudio.Wpf.DiagramDesigner
return new Rect(new Point(x1, y1), new Point(x2, y2));
}
#region wpf大小与物理像素之间转换
public void SetScreenScale()
{
ScreenScale = ScreenHelper.ResetScreenScale();
}
#endregion
}

View File

@@ -45,6 +45,7 @@ namespace AIStudio.Wpf.DiagramDesigner
Rect GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items);
void UpdateZIndex();
bool IsReadOnly{ get; set; }
Size PageSize { get; set; }
PageSizeType PageSizeType { get; set; }
bool ShowGrid { get; set; }
@@ -58,6 +59,12 @@ namespace AIStudio.Wpf.DiagramDesigner
Point CurrentPoint { get; set; }
Color CurrentColor { get; set; }
//如果这个赋值了,优先用这个的
DrawMode? VectorLineDrawMode { get; set; }
//用于wpf大小与物理像素之间转换
double ScreenScale { get; set; }
void SetScreenScale();
event PropertyChangedEventHandler PropertyChanged;