1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
7
using System.Collections.Generic;
10
using System.Globalization;
11
using System.Windows.Data;
12
using ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.Relations;
13
using System.Windows.Media;
17
namespace ICSharpCode.Data.EDMDesigner.Core.UI.Converters
19
public class ComplexPropertyRelationToXYConverter : RelationToXYConverterBase
21
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
23
var complexPropertyRelation = (ComplexPropertyRelation)value;
24
var fromX = -((MatrixTransform)complexPropertyRelation.Canvas.TransformToVisual(complexPropertyRelation.FromTypeDesigner)).Matrix.OffsetX;
25
var toMiddleWidth = complexPropertyRelation.ToTypeDesigner.ActualWidth / 2.0;
26
var toX = -((MatrixTransform)complexPropertyRelation.Canvas.TransformToVisual(complexPropertyRelation.ToTypeDesigner)).Matrix.OffsetX + toMiddleWidth;
27
var xDiff = toX - fromX;
28
double x1, x2, x3, x4, x1Arrow, x2Arrow, xCanvas;
29
var fromByLeft = true;
35
if (xDiff > complexPropertyRelation.FromTypeDesigner.ActualWidth / 2.0)
37
double moreX = complexPropertyRelation.FromTypeDesigner.ActualWidth;
50
var fromItem = complexPropertyRelation.FromTypeDesigner.IsExpanded ? complexPropertyRelation.FromItem : complexPropertyRelation.FromTypeDesigner;
51
var fromY = -((MatrixTransform)complexPropertyRelation.Canvas.TransformToVisual(fromItem)).Matrix.OffsetY;
52
var toY = -((MatrixTransform)complexPropertyRelation.Canvas.TransformToVisual(complexPropertyRelation.ToTypeDesigner)).Matrix.OffsetY;
53
var yDiff = toY - fromY;
54
var itemMiddleHeight = fromItem.ActualHeight / 2.0;
55
var y1 = itemMiddleHeight;
56
double y2, y3, y4, y1Arrow, y2Arrow, yCanvas;
69
if (yDiff < -complexPropertyRelation.ToTypeDesigner.ActualHeight / 2.0 || toY < MIN_SIZE)
71
double moreY = complexPropertyRelation.ToTypeDesigner.ActualHeight;
78
var angle = GetAngle(x1, x2, y1, y2);
79
var angleAbs = Math.Abs(angle);
82
bool twoPoints, threePoints, fivePoints, fivePointsV, fivePointsH;
83
if (angleAbs >= ARROW_LINE_MIN_ANGLE && angleAbs <= ARROW_LINE_MAX_ANGLE && (toByTop ? angle > 0 : angle < 0))
86
threePoints = fivePoints = fivePointsH = fivePointsV = false;
90
threePoints = ((y2 > y1) ? toByTop && yDiff > MIN_SIZE : !toByTop && yDiff < -MIN_SIZE) && (xDiff > MIN_SIZE ? !fromByLeft && x2 - x1 > MIN_SIZE : fromByLeft && x2 - x1 < -MIN_SIZE);
99
fromY += fromItem.ActualHeight / 2.0;
100
fivePointsV = fromX - MIN_SIZE * 2.0 < toX && fromX + complexPropertyRelation.ToTypeDesigner.ActualWidth + MIN_SIZE * (double)2 > toX && (fromY > toY + complexPropertyRelation.ToTypeDesigner.ActualHeight + MIN_SIZE || fromY < toY + complexPropertyRelation.ToTypeDesigner.ActualHeight + MIN_SIZE);
101
fivePointsH = (toByTop ? toY - MIN_SIZE <= fromY : toY + complexPropertyRelation.ToTypeDesigner.ActualHeight + MIN_SIZE > fromY) && (fromX - MIN_SIZE * 2.0 > toX || fromX + complexPropertyRelation.FromTypeDesigner.ActualWidth + MIN_SIZE * (double)2 < toX);
102
fivePoints = fivePointsH || fivePointsV;
104
twoPoints = !(fivePoints || threePoints);
109
x3 = y3 = x4 = y4 = 0;
110
FillArrow(angle, x1, x2, y1, y2, out x1Arrow, out x2Arrow, out y1Arrow, out y2Arrow);
111
var translateXCanvas = Math.Min(x1Arrow, x2Arrow);
112
if (translateXCanvas < 0)
114
x1 -= translateXCanvas;
115
x2 -= translateXCanvas;
116
x1Arrow -= translateXCanvas;
117
x2Arrow -= translateXCanvas;
118
xCanvas += translateXCanvas;
120
var translateYCanvas = Math.Min(y1Arrow, y2Arrow);
121
if (translateYCanvas < 0)
123
y1 -= translateYCanvas;
124
y2 -= translateYCanvas;
125
y1Arrow -= translateYCanvas;
126
y2Arrow -= translateYCanvas;
127
yCanvas += translateYCanvas;
132
var xTranslate = x2 - ARROW_WIDTH;
135
xCanvas += xTranslate;
139
x1Arrow = x2 - ARROW_WIDTH;
140
x2Arrow = x2 + ARROW_WIDTH;
148
y1Arrow = y3 - ARROW_HEIGHT;
150
y1Arrow = y3 + ARROW_HEIGHT;
158
x2 = Math.Abs(fromByLeft ? x1 - x2 + toMiddleWidth : x2 - toMiddleWidth - x1 ) / 2.0;
161
x3 = x1 + MIN_SIZE + (double)complexPropertyRelation.FromItemIndex * MORE_SIZE_PER_ITEM;
162
if (x3 < x4 - MIN_SIZE)
163
x2 = Math.Max(x2, x3);
167
x3 = x1 - MIN_SIZE - (double)complexPropertyRelation.FromItemIndex * MORE_SIZE_PER_ITEM;
168
if (x3 > x4 + MIN_SIZE)
169
x2 = Math.Min(x2, x3);
172
else if (fivePointsV)
174
var fromTypeY = -((MatrixTransform)complexPropertyRelation.Canvas.TransformToVisual(complexPropertyRelation.FromTypeDesigner)).Matrix.OffsetY;
176
y2 = Math.Abs(y2 - fromTypeY + yCanvas) / 2.0;
179
fromTypeY += complexPropertyRelation.FromTypeDesigner.ActualHeight;
180
y2 = Math.Abs(y2 - fromTypeY + yCanvas) / 2.0;
183
x2 = x1 - MIN_SIZE - (double)complexPropertyRelation.FromItemIndex * MORE_SIZE_PER_ITEM;
185
x2 = x1 + MIN_SIZE + (double)complexPropertyRelation.FromItemIndex * MORE_SIZE_PER_ITEM;
188
throw new NotImplementedException();
194
y1Arrow = y4 - ARROW_HEIGHT;
199
y1Arrow = y4 + ARROW_HEIGHT;
203
throw new InvalidOperationException();
207
return new double[][] { new[] { xCanvas, yCanvas }, new[] { x1, y1 }, new[] { x2, y2 }, new[] { x3, y3 }, new[] { x4, y3 }, new[] { x4, y4 }, new[] { x1Arrow, y1Arrow }, new[] { x2Arrow, y2Arrow } };