mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
整理一下项目文件
This commit is contained in:
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user