mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
268 lines
7.1 KiB
C#
268 lines
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
{
|
|
public class FullyCreatedConnectorInfo : ConnectorInfoBase
|
|
{
|
|
public FullyCreatedConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, ValueTypePoint valueTypePoint = 0)
|
|
: base(orientation)
|
|
{
|
|
this.DataItem = dataItem;
|
|
this.IsInnerPoint = isInnerPoint;
|
|
this.ValueTypePoint = valueTypePoint;
|
|
if (IsInnerPoint == true)
|
|
{
|
|
BuildMenuOptions();
|
|
}
|
|
}
|
|
|
|
public FullyCreatedConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, SelectableItemBase designer) : base(root, designer)
|
|
{
|
|
this.DataItem = dataItem;
|
|
if (IsInnerPoint == true)
|
|
{
|
|
BuildMenuOptions();
|
|
}
|
|
}
|
|
|
|
public FullyCreatedConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, string json) : base(root, json)
|
|
{
|
|
this.DataItem = dataItem;
|
|
if (IsInnerPoint == true)
|
|
{
|
|
BuildMenuOptions();
|
|
}
|
|
}
|
|
|
|
protected override void Init()
|
|
{
|
|
base.Init();
|
|
|
|
menuOptions = new List<CinchMenuItem>();
|
|
MenuItemCommand = new SimpleCommand(ExecuteMenuItemCommand);
|
|
DeleteCommand = new SimpleCommand(ExecuteDeleteCommand);
|
|
|
|
}
|
|
|
|
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
|
{
|
|
base.LoadDesignerItemViewModel(root, designerbase);
|
|
|
|
if (designerbase is FullyCreatedConnectorInfoItem designer)
|
|
{
|
|
XRatio = designer.XRatio;
|
|
YRatio = designer.YRatio;
|
|
IsInnerPoint = designer.IsInnerPoint;
|
|
ValueTypePoint = designer.ValueTypePoint;
|
|
}
|
|
}
|
|
|
|
public override SelectableItemBase ToXmlObject()
|
|
{
|
|
return new FullyCreatedConnectorInfoItem(this);
|
|
}
|
|
|
|
public override Type ToXmlType()
|
|
{
|
|
return typeof(FullyCreatedConnectorInfo);
|
|
}
|
|
|
|
#region 属性
|
|
public override PointBase Position
|
|
{
|
|
get
|
|
{
|
|
return PointHelper.GetPointForConnector(this);
|
|
}
|
|
}
|
|
|
|
private List<CinchMenuItem> menuOptions;
|
|
public IEnumerable<CinchMenuItem> MenuOptions
|
|
{
|
|
get
|
|
{
|
|
return menuOptions;
|
|
}
|
|
}
|
|
|
|
public DesignerItemViewModelBase DataItem
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
private bool _showConnectors = false;
|
|
public bool ShowConnectors
|
|
{
|
|
get
|
|
{
|
|
return _showConnectors;
|
|
}
|
|
set
|
|
{
|
|
SetProperty(ref _showConnectors, value);
|
|
}
|
|
}
|
|
|
|
private double _xRatio;
|
|
public double XRatio
|
|
{
|
|
get
|
|
{
|
|
return _xRatio;
|
|
}
|
|
set
|
|
{
|
|
SetProperty(ref _xRatio, value);
|
|
}
|
|
}
|
|
|
|
private double _yRatio;
|
|
public double YRatio
|
|
{
|
|
get
|
|
{
|
|
return _yRatio;
|
|
}
|
|
set
|
|
{
|
|
SetProperty(ref _yRatio, value);
|
|
}
|
|
}
|
|
|
|
public bool IsInnerPoint
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public ValueTypePoint _valueTypePoint;
|
|
public ValueTypePoint ValueTypePoint
|
|
{
|
|
get
|
|
{
|
|
return _valueTypePoint;
|
|
}
|
|
set
|
|
{
|
|
SetProperty(ref _valueTypePoint, value);
|
|
}
|
|
}
|
|
|
|
private Style _style;
|
|
public Style Style
|
|
{
|
|
get
|
|
{
|
|
return _style;
|
|
}
|
|
set
|
|
{
|
|
SetProperty(ref _style, value);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 方法
|
|
public SimpleCommand DeleteCommand
|
|
{
|
|
get; private set;
|
|
}
|
|
public SimpleCommand MenuItemCommand
|
|
{
|
|
get; private set;
|
|
}
|
|
#endregion
|
|
|
|
public void ExecuteMenuItemCommand(object arg)
|
|
{
|
|
Orientation = (ConnectorOrientation)arg;
|
|
}
|
|
|
|
public void ExecuteDeleteCommand(object arg)
|
|
{
|
|
DataItem.RemoveConnector(this);
|
|
|
|
}
|
|
|
|
private void BuildMenuOptions()
|
|
{
|
|
menuOptions.Clear();
|
|
var orientation = new CinchMenuItem("方向");
|
|
var top = new CinchMenuItem("上");
|
|
top.Command = MenuItemCommand;
|
|
top.CommandParameter = ConnectorOrientation.Top;
|
|
var bottom = new CinchMenuItem("下");
|
|
bottom.Command = MenuItemCommand;
|
|
bottom.CommandParameter = ConnectorOrientation.Bottom;
|
|
var left = new CinchMenuItem("左");
|
|
left.Command = MenuItemCommand;
|
|
left.CommandParameter = ConnectorOrientation.Left;
|
|
var right = new CinchMenuItem("右");
|
|
right.Command = MenuItemCommand;
|
|
right.CommandParameter = ConnectorOrientation.Right;
|
|
orientation.Children.Add(top);
|
|
orientation.Children.Add(bottom);
|
|
orientation.Children.Add(left);
|
|
orientation.Children.Add(right);
|
|
|
|
var delete = new CinchMenuItem("删除");
|
|
delete.Command = DeleteCommand;
|
|
|
|
menuOptions.Add(orientation);
|
|
menuOptions.Add(delete);
|
|
}
|
|
|
|
public 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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|