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,129 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public abstract class ConnectorInfoBase : SelectableViewModelBase
|
||||
{
|
||||
public ConnectorInfoBase(ConnectorOrientation orientation)
|
||||
{
|
||||
this.Orientation = orientation;
|
||||
}
|
||||
|
||||
public ConnectorInfoBase(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ConnectorInfoBase(IDiagramViewModel root, string json) : base(root, json)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(root, designerbase);
|
||||
|
||||
if (designerbase is ConnectorInfoItemBase designer)
|
||||
{
|
||||
ConnectorWidth = designer.ConnectorWidth;
|
||||
ConnectorHeight = designer.ConnectorHeight;
|
||||
Orientation = designer.Orientation;
|
||||
ConnectorValue = designer.ConnectorValue;
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectableItemBase ToXmlObject()
|
||||
{
|
||||
return new ConnectorInfoItemBase(this);
|
||||
}
|
||||
|
||||
public override Type ToXmlType()
|
||||
{
|
||||
return typeof(ConnectorInfoBase);
|
||||
}
|
||||
|
||||
#region 属性
|
||||
public virtual PointBase Position
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public virtual PointBase MiddlePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PointBase(Position.X + ConnectorWidth / 2, Position.Y + ConnectorHeight / 2);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public double _connectorValue;
|
||||
public double ConnectorValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _connectorValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _connectorValue, value);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
using SvgPathProperties;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ConnectorLabelModel : ConnectorPointModel, ISelectable
|
||||
{
|
||||
public ConnectorLabelModel(ConnectionViewModel connector, string content, double? distance = null, PointBase? offset = null)
|
||||
{
|
||||
Parent = connector;
|
||||
Text = content;
|
||||
Distance = distance;
|
||||
Offset = offset ?? new PointBase();
|
||||
}
|
||||
|
||||
public ConnectorLabelModel(IDiagramViewModel root, ConnectionViewModel connector, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
Parent = connector;
|
||||
}
|
||||
|
||||
public ConnectorLabelModel(IDiagramViewModel root, ConnectionViewModel connector, string json) : base(root, json)
|
||||
{
|
||||
Parent = connector;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
DeleteLabelCommand = new SimpleCommand(DeleteLabel);
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(root, designerbase);
|
||||
|
||||
if (designerbase is ConnectorLabelItem designer)
|
||||
{
|
||||
Distance = designer.Distance;
|
||||
Offset = designer.Offset;
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectableItemBase ToXmlObject()
|
||||
{
|
||||
return new ConnectorLabelItem(this);
|
||||
}
|
||||
|
||||
public override Type ToXmlType()
|
||||
{
|
||||
return typeof(ConnectorLabelItem);
|
||||
}
|
||||
|
||||
#region 属性
|
||||
public ConnectionViewModel Connector
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent as ConnectionViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 3 types of values are possible:
|
||||
/// <para>- A number between 0 and 1: Position relative to the link's length</para>
|
||||
/// <para>- A positive number, greater than 1: Position away from the start</para>
|
||||
/// <para>- A negative number, less than 0: Position away from the end</para>
|
||||
/// </summary>
|
||||
public double? Distance
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public PointBase Offset
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
//private bool _isSelected;
|
||||
public override bool IsSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _isSelected, value))
|
||||
{
|
||||
//如果没有文字,失去焦点自动清除
|
||||
if (_isSelected == false && string.IsNullOrEmpty(Text))
|
||||
{
|
||||
Connector.Labels.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCommand DeleteLabelCommand
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
private bool updating = false;
|
||||
|
||||
public void UpdatePosition(SvgPath[] paths)
|
||||
{
|
||||
var position = FindPosition(paths);
|
||||
if (position == null)
|
||||
return;
|
||||
|
||||
updating = true;
|
||||
X = position.Value.X;
|
||||
Y = position.Value.Y;
|
||||
updating = false;
|
||||
}
|
||||
|
||||
public PointBase? FindPosition(SvgPath[] paths)
|
||||
{
|
||||
var totalLength = paths.Sum(p => p.Length);
|
||||
|
||||
double length;
|
||||
|
||||
|
||||
if (Distance >= 0 && Distance <= 1)
|
||||
{
|
||||
length = Distance.Value * totalLength;
|
||||
}
|
||||
else if (Distance > 1)
|
||||
{
|
||||
length = Distance.Value;
|
||||
}
|
||||
else if (Distance < 0)
|
||||
{
|
||||
length = totalLength + Distance.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = totalLength * (Connector.Labels.IndexOf(this) + 1) / (Connector.Labels.Count + 1);
|
||||
}
|
||||
|
||||
|
||||
foreach (var path in paths)
|
||||
{
|
||||
var pathLength = path.Length;
|
||||
if (length < pathLength)
|
||||
{
|
||||
var pt = path.GetPointAtLength(length);
|
||||
return new PointBase(pt.X + Offset.X, pt.Y + Offset.Y);
|
||||
}
|
||||
|
||||
length -= pathLength;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void UpdateOffsetX(double oldvalue, double newvalue)
|
||||
{
|
||||
if (updating == true) return;
|
||||
|
||||
Offset += new VectorBase(newvalue - oldvalue, 0);
|
||||
}
|
||||
|
||||
public void UpdateOffsetY(double oldvalue, double newvalue)
|
||||
{
|
||||
if (updating == true) return;
|
||||
|
||||
Offset += new VectorBase(0, newvalue - oldvalue);
|
||||
}
|
||||
|
||||
public override void AddToSelection(bool selected)
|
||||
{
|
||||
foreach (var item in Connector.Labels.ToList())
|
||||
item.IsSelected = false;
|
||||
|
||||
if (selected == true)
|
||||
{
|
||||
IsSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteLabel(object parameter)
|
||||
{
|
||||
if (parameter is ConnectorLabelModel label)
|
||||
{
|
||||
Connector.Labels.Remove(label);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ConnectorPointModel : SelectableViewModelBase
|
||||
{
|
||||
public ConnectorPointModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ConnectorPointModel(PointBase point) : this()
|
||||
{
|
||||
X = point.X;
|
||||
Y = point.Y;
|
||||
}
|
||||
|
||||
public ConnectorPointModel(double x, double y) : this()
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public ConnectorPointModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ConnectorPointModel(IDiagramViewModel root, string json) : base(root, json)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(root, designerbase);
|
||||
|
||||
if (designerbase is ConnectorPointItem designer)
|
||||
{
|
||||
X = designer.X;
|
||||
Y = designer.Y;
|
||||
ConnectorWidth = designer.ConnectorWidth;
|
||||
ConnectorHeight = designer.ConnectorHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectableItemBase ToXmlObject()
|
||||
{
|
||||
return new ConnectorPointItem(this);
|
||||
}
|
||||
|
||||
public override Type ToXmlType()
|
||||
{
|
||||
return typeof(ConnectorPointItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中间X
|
||||
/// </summary>
|
||||
private double _x;
|
||||
public double X
|
||||
{
|
||||
get
|
||||
{
|
||||
return _x;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(SetProperty(ref _x, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(Left));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中间Y
|
||||
/// </summary>
|
||||
private double _y;
|
||||
public double Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return _y;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _y, value))
|
||||
{
|
||||
RaisePropertyChanged(nameof(Top));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 边界Left
|
||||
/// </summary>
|
||||
public double Left
|
||||
{
|
||||
get
|
||||
{
|
||||
return X - ConnectorWidth / 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 边界Top
|
||||
/// </summary>
|
||||
public double Top
|
||||
{
|
||||
get
|
||||
{
|
||||
return Y - ConnectorHeight / 2;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PointBase(Left, Top);
|
||||
}
|
||||
}
|
||||
public virtual PointBase MiddlePosition => new PointBase(X, Y);
|
||||
|
||||
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; }
|
||||
}
|
||||
|
||||
public static ConnectorPointModel operator -(ConnectorPointModel a, ConnectorPointModel b)
|
||||
{
|
||||
return new ConnectorPointModel(a.X - b.X, a.Y - b.Y);
|
||||
}
|
||||
public static ConnectorPointModel operator +(ConnectorPointModel a, ConnectorPointModel b)
|
||||
{
|
||||
return new ConnectorPointModel(a.X + b.X, a.Y + b.Y);
|
||||
}
|
||||
|
||||
public static implicit operator ConnectorPointModel(PointBase point)
|
||||
{
|
||||
return new ConnectorPointModel(point);
|
||||
}
|
||||
|
||||
public static implicit operator PointBase(ConnectorPointModel pointInfoBase)
|
||||
{
|
||||
return new PointBase(pointInfoBase.X, pointInfoBase.Y);
|
||||
}
|
||||
|
||||
public static List<ConnectorPointModel> ToList(List<PointBase> lst)
|
||||
{
|
||||
return lst.Select(p => (ConnectorPointModel)p).ToList();
|
||||
}
|
||||
|
||||
public override string ToString() => $"ConnectorPoint(x={X}, y={Y})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ConnectorVertexModel : ConnectorPointModel
|
||||
{
|
||||
public ConnectorVertexModel(ConnectionViewModel connector, PointBase? position = null)
|
||||
{
|
||||
Parent = connector;
|
||||
X = position?.X ?? 0;
|
||||
Y = position?.Y ?? 0;
|
||||
}
|
||||
|
||||
public ConnectorVertexModel(IDiagramViewModel root, ConnectionViewModel connector, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
Parent = connector;
|
||||
}
|
||||
|
||||
public ConnectorVertexModel(IDiagramViewModel root, ConnectionViewModel connector, string json) : base(root, json)
|
||||
{
|
||||
Parent = connector;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
DeleteVertexCommand = new SimpleCommand(DeleteVertex);
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(root, designerbase);
|
||||
|
||||
if (designerbase is ConnectorVertexItem designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override SelectableItemBase ToXmlObject()
|
||||
{
|
||||
return new ConnectorVertexItem(this);
|
||||
}
|
||||
|
||||
public override Type ToXmlType()
|
||||
{
|
||||
return typeof(ConnectorVertexModel);
|
||||
}
|
||||
|
||||
public ConnectionViewModel Connector
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent as ConnectionViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public override PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PointBase(Connector.Area.Left + Left, Connector.Area.Top + Top);
|
||||
}
|
||||
}
|
||||
|
||||
public override PointBase MiddlePosition => new PointBase(Connector.Area.Left + Left + ConnectorWidth / 2, Connector.Area.Top + Top + ConnectorHeight / 2);
|
||||
|
||||
public SimpleCommand DeleteVertexCommand
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
private void DeleteVertex(object parameter)
|
||||
{
|
||||
if (parameter is ConnectorVertexModel vertice)
|
||||
{
|
||||
Connector.Vertices.Remove(vertice);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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 PartCreatedConnectorInfo : ConnectorInfoBase
|
||||
{
|
||||
private PointBase position;
|
||||
public override PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
public PartCreatedConnectorInfo(double X, double Y) : base(ConnectorOrientation.None)
|
||||
{
|
||||
this.position = new PointBase(X, Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user