Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/FullyCreatedConnectorInfo.cs

279 lines
7.7 KiB
C#
Raw Normal View History

2021-07-23 09:42:22 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
2023-01-12 23:02:53 +08:00
using AIStudio.Wpf.DiagramDesigner.Geometrys;
2023-01-25 11:11:27 +08:00
using AIStudio.Wpf.DiagramDesigner.Models;
2021-07-23 09:42:22 +08:00
2022-10-28 22:45:39 +08:00
namespace AIStudio.Wpf.DiagramDesigner
2021-07-23 09:42:22 +08:00
{
public class FullyCreatedConnectorInfo : ConnectorInfoBase
{
2023-01-24 17:53:04 +08:00
public FullyCreatedConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, ValueTypePoint valueTypePoint = 0)
2023-01-27 14:54:03 +08:00
: this(null, dataItem, orientation, isInnerPoint, valueTypePoint)
{
}
public FullyCreatedConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, ValueTypePoint valueTypePoint = 0)
: base(root, orientation)
2023-01-08 09:22:37 +08:00
{
2023-01-26 20:05:21 +08:00
this.Parent = dataItem;
2023-01-24 17:53:04 +08:00
this.IsInnerPoint = isInnerPoint;
this.ValueTypePoint = valueTypePoint;
if (IsInnerPoint == true)
2023-01-08 09:22:37 +08:00
{
2023-01-24 17:53:04 +08:00
BuildMenuOptions();
2023-01-08 09:22:37 +08:00
}
}
2022-12-06 21:28:42 +08:00
2023-01-24 17:53:04 +08:00
public FullyCreatedConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, SelectableItemBase designer) : base(root, designer)
2021-07-23 09:42:22 +08:00
{
2023-01-26 20:05:21 +08:00
this.Parent = dataItem;
2023-01-24 17:53:04 +08:00
if (IsInnerPoint == true)
{
BuildMenuOptions();
}
}
2021-07-23 09:42:22 +08:00
2023-01-25 11:11:27 +08:00
public FullyCreatedConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
2023-01-24 17:53:04 +08:00
{
2023-01-26 20:05:21 +08:00
this.Parent = dataItem;
2021-07-23 09:42:22 +08:00
if (IsInnerPoint == true)
{
BuildMenuOptions();
}
}
2023-01-25 11:11:27 +08:00
public override SelectableItemBase GetSerializableObject()
{
return new FullyCreatedConnectorInfoItem(this);
}
2023-01-27 14:54:03 +08:00
protected override void Init(IDiagramViewModel root)
2021-07-23 09:42:22 +08:00
{
2023-01-27 14:54:03 +08:00
base.Init(root);
2023-01-24 17:53:04 +08:00
menuOptions = new List<CinchMenuItem>();
2023-01-25 23:55:30 +08:00
MenuItemCommand = new SimpleCommand(Command_Enable, ExecuteMenuItemCommand);
DeleteCommand = new SimpleCommand(Command_Enable, ExecuteDeleteCommand);
2023-01-24 17:53:04 +08:00
2021-07-23 09:42:22 +08:00
}
2023-01-27 14:54:03 +08:00
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
2021-07-23 09:42:22 +08:00
{
2023-01-27 14:54:03 +08:00
base.LoadDesignerItemViewModel(designerbase);
2021-07-23 09:42:22 +08:00
2023-01-24 17:53:04 +08:00
if (designerbase is FullyCreatedConnectorInfoItem designer)
{
XRatio = designer.XRatio;
YRatio = designer.YRatio;
IsInnerPoint = designer.IsInnerPoint;
ValueTypePoint = designer.ValueTypePoint;
}
2021-07-23 09:42:22 +08:00
}
2023-01-24 17:53:04 +08:00
#region
public override PointBase Position
{
get
{
return PointHelper.GetPointForConnector(this);
}
}
private List<CinchMenuItem> menuOptions;
public IEnumerable<CinchMenuItem> MenuOptions
{
get
{
return menuOptions;
}
2021-07-23 09:42:22 +08:00
}
2022-12-06 21:28:42 +08:00
public DesignerItemViewModelBase DataItem
{
2023-01-26 20:05:21 +08:00
get
{
return Parent as DesignerItemViewModelBase;
}
2022-12-06 21:28:42 +08:00
}
2021-07-23 09:42:22 +08:00
private bool _showConnectors = false;
public bool ShowConnectors
{
get
{
return _showConnectors;
}
set
{
2022-12-06 21:28:42 +08:00
SetProperty(ref _showConnectors, value);
2021-07-23 09:42:22 +08:00
}
}
private double _xRatio;
public double XRatio
{
2022-12-06 21:28:42 +08:00
get
{
return _xRatio;
}
2021-07-23 09:42:22 +08:00
set
{
SetProperty(ref _xRatio, value);
}
}
private double _yRatio;
public double YRatio
{
2022-12-06 21:28:42 +08:00
get
{
return _yRatio;
}
2021-07-23 09:42:22 +08:00
set
{
SetProperty(ref _yRatio, value);
}
}
2022-12-06 21:28:42 +08:00
public bool IsInnerPoint
{
get; set;
}
2021-07-23 09:42:22 +08:00
2023-01-27 20:10:17 +08:00
public bool IsPortless
{
get; set;
}
2021-07-23 09:42:22 +08:00
public ValueTypePoint _valueTypePoint;
public ValueTypePoint ValueTypePoint
{
2022-12-06 21:28:42 +08:00
get
{
return _valueTypePoint;
}
2021-07-23 09:42:22 +08:00
set
{
SetProperty(ref _valueTypePoint, value);
}
}
2023-01-23 15:43:44 +08:00
private Style _style;
public Style Style
{
get
{
return _style;
}
set
{
SetProperty(ref _style, value);
}
}
2023-01-24 17:53:04 +08:00
#endregion
2023-01-23 15:43:44 +08:00
2023-01-24 17:53:04 +08:00
#region
2022-12-06 21:28:42 +08:00
public SimpleCommand DeleteCommand
{
get; private set;
}
public SimpleCommand MenuItemCommand
{
get; private set;
}
2023-01-24 17:53:04 +08:00
#endregion
2021-07-23 09:42:22 +08:00
2023-01-24 17:53:04 +08:00
public void ExecuteMenuItemCommand(object arg)
2022-12-06 21:28:42 +08:00
{
2023-01-24 17:53:04 +08:00
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);
2022-12-06 21:28:42 +08:00
}
2023-01-12 23:02:53 +08:00
public double GetXRatioFromConnector()
{
if (IsInnerPoint)
{
return XRatio;
}
else
{
switch (Orientation)
{
case ConnectorOrientation.Top:
return 0.5;
case ConnectorOrientation.Left:
return 0;
case ConnectorOrientation.Bottom:
return 0.5;
case ConnectorOrientation.Right:
return 1;
default: return XRatio;
}
}
}
public double GetYRatioFromConnector()
{
if (IsInnerPoint)
{
return YRatio;
}
else
{
switch (Orientation)
{
case ConnectorOrientation.Top:
return 0;
case ConnectorOrientation.Left:
return 0.5;
case ConnectorOrientation.Bottom:
return 1;
case ConnectorOrientation.Right:
return 0.5;
default: return YRatio;
}
}
}
2023-01-26 20:05:21 +08:00
public virtual bool CanAttachTo(FullyCreatedConnectorInfo port) => port != this && !port.IsReadOnly && DataItem != port.DataItem;
2021-07-23 09:42:22 +08:00
}
}