mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-10 03:30:50 +08:00
整理一下项目文件
This commit is contained in:
@@ -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