mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-04 16:16:34 +08:00
使用PointBase代替Point
This commit is contained in:
@@ -106,7 +106,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private double _lineWidth = 1;
|
||||
private double _lineWidth = 1d;
|
||||
public double LineWidth
|
||||
{
|
||||
get
|
||||
|
||||
@@ -4,12 +4,17 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometry;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public abstract class ConnectorInfoBase : BindableBase
|
||||
{
|
||||
|
||||
public virtual PointBase Position
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public ConnectorInfoBase(ConnectorOrientation orientation)
|
||||
{
|
||||
this.Orientation = orientation;
|
||||
@@ -23,7 +28,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
private ConnectorOrientation _orientation;
|
||||
public ConnectorOrientation Orientation
|
||||
{
|
||||
get { return _orientation; }
|
||||
get
|
||||
{
|
||||
return _orientation;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _orientation, value);
|
||||
@@ -33,15 +41,27 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
private double connectorWidth = 8;
|
||||
public double ConnectorWidth
|
||||
{
|
||||
get { return connectorWidth; }
|
||||
set { connectorWidth = value; }
|
||||
get
|
||||
{
|
||||
return connectorWidth;
|
||||
}
|
||||
set
|
||||
{
|
||||
connectorWidth = value;
|
||||
}
|
||||
}
|
||||
|
||||
private double connectorHeight = 8;
|
||||
public double ConnectorHeight
|
||||
{
|
||||
get { return connectorHeight; }
|
||||
set { connectorHeight = value; }
|
||||
get
|
||||
{
|
||||
return connectorHeight;
|
||||
}
|
||||
set
|
||||
{
|
||||
connectorHeight = value;
|
||||
}
|
||||
}
|
||||
|
||||
private IColorViewModel _colorViewModel;
|
||||
@@ -68,6 +88,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SetProperty(ref _connectorValue, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometry;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PointInfoBase : BindableBase
|
||||
public class ConnectorPoint : BindableBase
|
||||
{
|
||||
public static PointInfoBase Zero { get; } = new PointInfoBase(0, 0);
|
||||
|
||||
public PointInfoBase()
|
||||
public ConnectorPoint()
|
||||
{
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
@@ -20,18 +19,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
};
|
||||
}
|
||||
|
||||
public PointInfoBase(Point point) : this()
|
||||
public ConnectorPoint(PointBase point) : this()
|
||||
{
|
||||
X = point.X;
|
||||
Y = point.Y;
|
||||
}
|
||||
|
||||
public PointInfoBase(double x, double y) : this()
|
||||
public ConnectorPoint(double x, double y) : this()
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中间X
|
||||
/// </summary>
|
||||
private double _x;
|
||||
public double X
|
||||
{
|
||||
@@ -48,6 +50,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中间Y
|
||||
/// </summary>
|
||||
private double _y;
|
||||
public double Y
|
||||
{
|
||||
@@ -64,6 +69,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 边界Left
|
||||
/// </summary>
|
||||
public double Left
|
||||
{
|
||||
get
|
||||
@@ -72,6 +80,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 边界Top
|
||||
/// </summary>
|
||||
public double Top
|
||||
{
|
||||
get
|
||||
@@ -80,6 +91,15 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PointBase(Left, Top);
|
||||
}
|
||||
}
|
||||
public PointBase MiddlePosition => new PointBase(Left + ConnectorWidth / 2, Top + ConnectorHeight / 2);
|
||||
|
||||
private double connectorWidth = 8;
|
||||
public double ConnectorWidth
|
||||
{
|
||||
@@ -105,53 +125,32 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SetProperty(ref _colorViewModel, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConnectorPoint operator -(ConnectorPoint a, ConnectorPoint b)
|
||||
{
|
||||
return new ConnectorPoint(a.X - b.X, a.Y - b.Y);
|
||||
}
|
||||
public static ConnectorPoint operator +(ConnectorPoint a, ConnectorPoint b)
|
||||
{
|
||||
return new ConnectorPoint(a.X + b.X, a.Y + b.Y);
|
||||
}
|
||||
|
||||
public double Dot(PointInfoBase other) => X * other.X + Y * other.Y;
|
||||
|
||||
public PointInfoBase Lerp(PointInfoBase other, double t)
|
||||
=> new PointInfoBase(X * (1.0 - t) + other.X * t, Y * (1.0 - t) + other.Y * t);
|
||||
|
||||
// Maybe just make Points mutable?
|
||||
public PointInfoBase Add(double value) => new PointInfoBase(X + value, Y + value);
|
||||
public PointInfoBase Add(double x, double y) => new PointInfoBase(X + x, Y + y);
|
||||
|
||||
public PointInfoBase Substract(double value) => new PointInfoBase(X - value, Y - value);
|
||||
public PointInfoBase Substract(double x, double y) => new PointInfoBase(X - x, Y - y);
|
||||
|
||||
public double DistanceTo(PointInfoBase other)
|
||||
=> Math.Sqrt(Math.Pow(X - other.X, 2) + Math.Pow(Y - other.Y, 2));
|
||||
|
||||
public void Deconstruct(out double x, out double y)
|
||||
public static implicit operator ConnectorPoint(PointBase point)
|
||||
{
|
||||
x = X;
|
||||
y = Y;
|
||||
}
|
||||
|
||||
public static PointInfoBase operator -(PointInfoBase a, PointInfoBase b)
|
||||
{
|
||||
return new Point(a.X - b.X, a.Y - b.Y);
|
||||
}
|
||||
public static PointInfoBase operator +(PointInfoBase a, PointInfoBase b)
|
||||
{
|
||||
return new Point(a.X + b.X, a.Y + b.Y);
|
||||
return new ConnectorPoint(point);
|
||||
}
|
||||
|
||||
public static implicit operator PointInfoBase(Point point)
|
||||
public static implicit operator PointBase(ConnectorPoint pointInfoBase)
|
||||
{
|
||||
return new PointInfoBase(point);
|
||||
return new PointBase(pointInfoBase.X, pointInfoBase.Y);
|
||||
}
|
||||
|
||||
public static implicit operator Point(PointInfoBase pointInfoBase)
|
||||
public static List<ConnectorPoint> ToList(List<PointBase> lst)
|
||||
{
|
||||
return new Point(pointInfoBase.X, pointInfoBase.Y);
|
||||
return lst.Select(p => (ConnectorPoint)p).ToList();
|
||||
}
|
||||
|
||||
public static List<PointInfoBase> ToList(List<Point> lst)
|
||||
{
|
||||
return lst.Select(p => (PointInfoBase)p).ToList();
|
||||
}
|
||||
|
||||
public override string ToString() => $"PointInfoBase(x={X}, y={Y})";
|
||||
public override string ToString() => $"ConnectorPoint(x={X}, y={Y})";
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
//using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometry;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
@@ -32,7 +33,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public override SelectableDesignerItemBase ToXmlObject()
|
||||
{
|
||||
if (SinkConnectorInfo is FullyCreatedConnectorInfo sinkConnector)
|
||||
if (IsFullConnection)
|
||||
{
|
||||
ConnectionItem connection = new ConnectionItem(
|
||||
SourceConnectorInfo.DataItem.Id,
|
||||
@@ -41,12 +42,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
GetXRatioFromConnector(SourceConnectorInfo),
|
||||
GetYRatioFromConnector(SourceConnectorInfo),
|
||||
SourceConnectorInfo.IsInnerPoint,
|
||||
sinkConnector.DataItem.Id,
|
||||
sinkConnector.Orientation,
|
||||
sinkConnector.DataItem.GetType(),
|
||||
GetXRatioFromConnector(sinkConnector),
|
||||
GetYRatioFromConnector(sinkConnector),
|
||||
sinkConnector.IsInnerPoint,
|
||||
SinkConnectorInfoFully.DataItem.Id,
|
||||
SinkConnectorInfoFully.Orientation,
|
||||
SinkConnectorInfoFully.DataItem.GetType(),
|
||||
GetXRatioFromConnector(SinkConnectorInfoFully),
|
||||
GetYRatioFromConnector(SinkConnectorInfoFully),
|
||||
SinkConnectorInfoFully.IsInnerPoint,
|
||||
this);
|
||||
|
||||
return connection;
|
||||
@@ -67,16 +68,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
public bool IsFullConnection
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sinkConnectorInfo is FullyCreatedConnectorInfo;
|
||||
}
|
||||
}
|
||||
|
||||
private Point _sourceA;
|
||||
public Point SourceA
|
||||
private PointBase _sourceA;
|
||||
public PointBase SourceA
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -91,8 +84,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private Point _sourceB;
|
||||
public Point SourceB
|
||||
private PointBase _sourceB;
|
||||
public PointBase SourceB
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -107,8 +100,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private List<PointInfoBase> _connectionPoints;
|
||||
public List<PointInfoBase> ConnectionPoints
|
||||
private List<ConnectorPoint> _connectionPoints;
|
||||
public List<ConnectorPoint> ConnectionPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -128,8 +121,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private Point _startPoint;
|
||||
public Point StartPoint
|
||||
private PointBase _startPoint;
|
||||
public PointBase StartPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -141,8 +134,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private Point _endPoint;
|
||||
public Point EndPoint
|
||||
private PointBase _endPoint;
|
||||
public PointBase EndPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -154,8 +147,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private Rect _area;
|
||||
public Rect Area
|
||||
private RectangleBase _area;
|
||||
public RectangleBase Area
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -163,7 +156,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
private set
|
||||
{
|
||||
Rect oldarea = _area;
|
||||
RectangleBase oldarea = _area;
|
||||
if (SetProperty(ref _area, value))
|
||||
{
|
||||
UpdateConnectionPoints();
|
||||
@@ -177,6 +170,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
//待完善这两处
|
||||
public List<LinkVertexModel> Vertices { get; } = new List<LinkVertexModel>();
|
||||
public List<LinkLabelModel> Labels { get; set; } = new List<LinkLabelModel>();
|
||||
|
||||
public virtual Dictionary<string, string> PropertiesSetting
|
||||
{
|
||||
get
|
||||
@@ -188,13 +185,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, double width, double height, Point position)
|
||||
public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, double width, double height, PointBase position)
|
||||
{
|
||||
|
||||
return new ConnectorInfo()
|
||||
{
|
||||
Orientation = orientation,
|
||||
DesignerItemSize = new Size(width, height),
|
||||
DesignerItemSize = new SizeBase(width, height),
|
||||
DesignerItemLeft = left,
|
||||
DesignerItemTop = top,
|
||||
Position = position
|
||||
@@ -237,12 +234,46 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
SourceB = ((PartCreatedConnectionInfo)SinkConnectorInfo).CurrentLocation;
|
||||
SourceB = SinkConnectorInfoPart.Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FullyCreatedConnectorInfo SinkConnectorInfoFully
|
||||
{
|
||||
get
|
||||
{
|
||||
return SinkConnectorInfo as FullyCreatedConnectorInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public PartCreatedConnectionInfo SinkConnectorInfoPart
|
||||
{
|
||||
get
|
||||
{
|
||||
return SinkConnectorInfo as PartCreatedConnectionInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectorPoint OnGoingPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return SinkConnectorInfoPart?.Position;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFullConnection
|
||||
{
|
||||
get
|
||||
{
|
||||
return SinkConnectorInfoFully != null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPortless => SourceConnectorInfo?.DataItem?.Connectors?.Count() == 0;
|
||||
|
||||
public double GetXRatioFromConnector(FullyCreatedConnectorInfo info)
|
||||
{
|
||||
if (info.IsInnerPoint)
|
||||
@@ -291,7 +322,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void UpdateArea()
|
||||
{
|
||||
Area = new Rect(SourceA, SourceB);
|
||||
Area = new RectangleBase(SourceA, SourceB);
|
||||
}
|
||||
|
||||
private void UpdateConnectionPoints()
|
||||
@@ -300,6 +331,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
StartPoint = ConnectionPoints.First();
|
||||
EndPoint = ConnectionPoints.Last();
|
||||
|
||||
//var router = Routers.Normal(Parent, this);
|
||||
//var pathGenerator = PathGenerators.Smooth(Parent, this, router, SourceA, SourceB);
|
||||
|
||||
}
|
||||
|
||||
private void ConnectorViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
@@ -311,9 +345,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
case "Left":
|
||||
case "Top":
|
||||
SourceA = PointHelper.GetPointForConnector(this.SourceConnectorInfo);
|
||||
if (this.SinkConnectorInfo is FullyCreatedConnectorInfo)
|
||||
if (IsFullConnection)
|
||||
{
|
||||
SourceB = PointHelper.GetPointForConnector((FullyCreatedConnectorInfo)this.SinkConnectorInfo);
|
||||
SourceB = PointHelper.GetPointForConnector(this.SinkConnectorInfoFully);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -365,6 +399,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
private void DeleteConnection(object args)
|
||||
{
|
||||
if (this.Parent is IDiagramViewModel)
|
||||
@@ -414,17 +449,46 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public void OutTextItemLocation(Rect oldArea, Rect newArea)
|
||||
public void OutTextItemLocation(RectangleBase oldArea, RectangleBase newArea)
|
||||
{
|
||||
if (this.OutTextItem is TextDesignerItemViewModel text)
|
||||
{
|
||||
var oldpoint = new Point(oldArea.Left + oldArea.Width / 2, oldArea.Top + oldArea.Height / 2);
|
||||
var newpoint = new Point(newArea.Left + newArea.Width / 2, newArea.Top + newArea.Height / 2);
|
||||
var oldpoint = new PointBase(oldArea.Left + oldArea.Width / 2, oldArea.Top + oldArea.Height / 2);
|
||||
var newpoint = new PointBase(newArea.Left + newArea.Width / 2, newArea.Top + newArea.Height / 2);
|
||||
|
||||
text.Left = text.Left + newpoint.X - oldpoint.X;
|
||||
text.Top = text.Top + newpoint.Y - oldpoint.Y;
|
||||
}
|
||||
}
|
||||
|
||||
//private (PointInfoBase source, PointInfoBase target) FindConnectionPoints(PointInfoBase[] route)
|
||||
//{
|
||||
// if (IsPortless) // Portless
|
||||
// {
|
||||
// if (SourceConnectorInfo.DataItem == null || (IsFullConnection && SinkConnectorInfoFully.DataItem == null))
|
||||
// return (null, null);
|
||||
|
||||
// var sourceCenter = SourceConnectorInfo.DataItem.GetBounds().Center;
|
||||
// var targetCenter = SinkConnectorInfoFully?.DataItem?.GetBounds().Center ?? SinkConnectorInfoFully.Position;
|
||||
// var firstPt = route.Length > 0 ? route[0] : targetCenter;
|
||||
// var secondPt = route.Length > 0 ? route[0] : sourceCenter;
|
||||
// var sourceLine = new Line(firstPt, sourceCenter);
|
||||
// var targetLine = new Line(secondPt, targetCenter);
|
||||
// var sourceIntersections = Link.SourceNode.GetShape().GetIntersectionsWithLine(sourceLine);
|
||||
// var targetIntersections = Link.TargetNode.GetShape().GetIntersectionsWithLine(targetLine);
|
||||
// var sourceIntersection = GetClosestPointTo(sourceIntersections, firstPt);
|
||||
// var targetIntersection = GetClosestPointTo(targetIntersections, secondPt);
|
||||
// return (sourceIntersection ?? sourceCenter, targetIntersection ?? targetCenter);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (!Link.SourcePort.Initialized || Link.TargetPort?.Initialized == false)
|
||||
// return (null, null);
|
||||
|
||||
// var source = GetPortPositionBasedOnAlignment(Link.SourcePort, Link.SourceMarker);
|
||||
// var target = GetPortPositionBasedOnAlignment(Link.TargetPort, Link.TargetMarker);
|
||||
// return (source, target ?? Link.OnGoingPosition);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using System.Windows;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometry;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -85,6 +86,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get { return (connectors != null && connectors.Count >= 4) ? connectors[3] : null; }
|
||||
}
|
||||
|
||||
public ShapeDefiner ShapeDefiner
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
private string _icon;
|
||||
[CanDo]
|
||||
@@ -133,16 +138,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
[CanDo]
|
||||
public Point ItemWidthHeight
|
||||
public SizeBase Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Point(ItemWidth, ItemHeight);
|
||||
return new SizeBase(ItemWidth, ItemHeight);
|
||||
}
|
||||
set
|
||||
{
|
||||
ItemWidth = value.X;
|
||||
ItemHeight = value.Y;
|
||||
ItemWidth = value.Width;
|
||||
ItemHeight = value.Height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,14 +216,22 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SetProperty(ref _top, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CanDo]
|
||||
public Point TopLeft
|
||||
public PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Point(Left, Top);
|
||||
return new PointBase(Left, Top);
|
||||
}
|
||||
}
|
||||
|
||||
[CanDo]
|
||||
public PointBase TopLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PointBase(Left, Top);
|
||||
}
|
||||
set
|
||||
{
|
||||
@@ -386,17 +399,37 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void RaiseTopLeft()
|
||||
{
|
||||
this.RaisePropertyChanged(nameof(TopLeft), new Point(GetOldValue<double>(nameof(Left)), GetOldValue<double>(nameof(Top))), TopLeft);
|
||||
this.RaisePropertyChanged(nameof(TopLeft), new PointBase(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);
|
||||
this.RaisePropertyChanged(nameof(Size), new SizeBase(GetOldValue<double>(nameof(ItemWidth)), GetOldValue<double>(nameof(ItemHeight))), Size);
|
||||
}
|
||||
|
||||
public void RaiseAngle()
|
||||
{
|
||||
this.RaisePropertyChanged(nameof(Angle), GetOldValue<double>(nameof(Angle)), Angle);
|
||||
}
|
||||
|
||||
public RectangleBase GetBounds(bool includePorts = false)
|
||||
{
|
||||
if (!includePorts)
|
||||
return new RectangleBase(Left, Top, ItemWidth, ItemHeight);
|
||||
|
||||
var leftPort = LeftConnector;
|
||||
var topPort = TopConnector;
|
||||
var rightPort = RightConnector;
|
||||
var bottomPort = BottomConnector;
|
||||
|
||||
var left = leftPort == null ? Left: Math.Min(Left, leftPort.Position.X);
|
||||
var top = topPort == null ? Top : Math.Min(Left, topPort.Position.Y);
|
||||
var right = rightPort == null ? Left + ItemWidth :
|
||||
Math.Max(rightPort.Position.X + rightPort.ConnectorWidth, Left + ItemWidth);
|
||||
var bottom = bottomPort == null ? Top + ItemHeight :
|
||||
Math.Max(bottomPort.Position.Y + bottomPort.ConnectorHeight, Top + ItemHeight);
|
||||
|
||||
return new RectangleBase(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometry;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using Newtonsoft.Json;
|
||||
@@ -324,9 +325,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private Point _currentPoint;
|
||||
private System.Windows.Point _currentPoint;
|
||||
[Browsable(false)]
|
||||
public Point CurrentPoint
|
||||
public System.Windows.Point CurrentPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -1393,7 +1394,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
select item).FirstOrDefault();
|
||||
|
||||
DesignerItemViewModelBase sinkItem = (from item in selectedDesignerItems
|
||||
where item.Id == ((connection.SinkConnectorInfo as FullyCreatedConnectorInfo).DataItem).Id
|
||||
where item.Id == connection.SinkConnectorInfoFully?.DataItem?.Id
|
||||
select item).FirstOrDefault();
|
||||
|
||||
if (sourceItem != null &&
|
||||
@@ -1423,15 +1424,15 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
OffsetX = 10;
|
||||
OffsetY = 10;
|
||||
Clipboard.Clear();
|
||||
Clipboard.SetData(DataFormats.Serializable, json);
|
||||
System.Windows.Clipboard.Clear();
|
||||
System.Windows.Clipboard.SetData(System.Windows.DataFormats.Serializable, json);
|
||||
}
|
||||
|
||||
private void ExecutePasteCommand(object parameter)
|
||||
{
|
||||
if (Clipboard.ContainsData(DataFormats.Serializable))
|
||||
if (System.Windows.Clipboard.ContainsData(System.Windows.DataFormats.Serializable))
|
||||
{
|
||||
String clipboardData = Clipboard.GetData(DataFormats.Serializable) as String;
|
||||
String clipboardData = System.Windows.Clipboard.GetData(System.Windows.DataFormats.Serializable) as String;
|
||||
|
||||
if (String.IsNullOrEmpty(clipboardData))
|
||||
return;
|
||||
@@ -1512,7 +1513,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.StackTrace, e.Message, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
System.Windows.MessageBox.Show(e.StackTrace, e.Message, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1683,7 +1684,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
where item.ParentId == Guid.Empty
|
||||
select item;
|
||||
|
||||
Rect rect = GetBoundingRectangle(items);
|
||||
RectangleBase rect = GetBoundingRectangle(items);
|
||||
|
||||
GroupDesignerItemViewModel groupItem = new GroupDesignerItemViewModel();
|
||||
groupItem.IsGroup = true;
|
||||
@@ -1752,7 +1753,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public Rect GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items)
|
||||
public RectangleBase GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items)
|
||||
{
|
||||
double x1 = Double.MaxValue;
|
||||
double y1 = Double.MaxValue;
|
||||
@@ -1768,7 +1769,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
y2 = Math.Max(item.Top + item.ItemHeight, y2);
|
||||
}
|
||||
|
||||
return new Rect(new Point(x1, y1), new Point(x2, y2));
|
||||
return new RectangleBase(new PointBase(x1, y1), new PointBase(x2, y2));
|
||||
}
|
||||
|
||||
#region 用于wpf大小与物理像素之间转换
|
||||
@@ -3,11 +3,19 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometry;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class FullyCreatedConnectorInfo : ConnectorInfoBase
|
||||
{
|
||||
public override PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return PointHelper.GetPointForConnector(this);
|
||||
}
|
||||
}
|
||||
|
||||
private List<CinchMenuItem> menuOptions;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class LinkLabelModel : ConnectorPoint
|
||||
{
|
||||
public LinkLabelModel(ConnectorViewModel parent, string id, string content, double? distance = null, ConnectorPoint offset = null)
|
||||
{
|
||||
Parent = parent;
|
||||
Content = content;
|
||||
Distance = distance;
|
||||
Offset = offset;
|
||||
}
|
||||
|
||||
public LinkLabelModel(ConnectorViewModel parent, string content, double? distance = null, ConnectorPoint offset = null)
|
||||
{
|
||||
Parent = parent;
|
||||
Content = content;
|
||||
Distance = distance;
|
||||
Offset = offset;
|
||||
}
|
||||
|
||||
public ConnectorViewModel Parent { get; }
|
||||
public string Content { get; set; }
|
||||
/// <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 ConnectorPoint Offset { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometry;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class LinkVertexModel : ConnectorPoint
|
||||
{
|
||||
public LinkVertexModel(ConnectorViewModel parent, PointBase? position = null)
|
||||
{
|
||||
Parent = parent;
|
||||
X = position?.X ?? 0;
|
||||
Y = position?.Y ?? 0;
|
||||
}
|
||||
|
||||
public ConnectorViewModel Parent
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometry;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PartCreatedConnectionInfo : ConnectorInfoBase
|
||||
{
|
||||
private PointBase position;
|
||||
public override PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
public PartCreatedConnectionInfo(double X, double Y) : base(ConnectorOrientation.None)
|
||||
{
|
||||
this.position = new PointBase(X, Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,8 +188,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
void ClearSelectedItems();
|
||||
bool BelongToSameGroup(IGroupable item1, IGroupable item2);
|
||||
Rect GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items);
|
||||
//bool BelongToSameGroup(IGroupable item1, IGroupable item2);
|
||||
//Rectangle GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items);
|
||||
void UpdateZIndex();
|
||||
|
||||
bool IsReadOnly
|
||||
@@ -241,7 +241,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
Point CurrentPoint
|
||||
System.Windows.Point CurrentPoint
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PartCreatedConnectionInfo : ConnectorInfoBase
|
||||
{
|
||||
public Point CurrentLocation { get; private set; }
|
||||
|
||||
public PartCreatedConnectionInfo(Point currentLocation) : base(ConnectorOrientation.None)
|
||||
{
|
||||
this.CurrentLocation = currentLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user