-
Notifications
You must be signed in to change notification settings - Fork 0
/
Path.cs
281 lines (234 loc) · 8.69 KB
/
Path.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*****************************************************************************
* *
* Path.cs *
* 25 November 2006 *
* Project: Crystalline *
* Written by: Richard Sartor *
* Copyright © 2006 Metaphysics Industries, Inc. *
* *
* Converted from C++ to C# on 10 November 2007 *
* *
* A class that represents a connection from one element to another. *
* *
*****************************************************************************/
using System;
using System.Collections.Generic;
using MetaphysicsIndustries.Collections;
using System.Drawing;
using MetaphysicsIndustries.Utilities;
namespace MetaphysicsIndustries.Crystalline
{
[Serializable]
public abstract class Path : Entity, IConnectionConduit<Element, Element, Path>
{
public Path()
{
}
public override RectangleV GetBoundingBox()
{
if (PathJoints.Count < 1) { return new RectangleV(); }
return RectangleV.BoundingBoxFromPoints(PathJoints.ToArray());
}
public override void Render(Graphics g, Pen pen, Brush brush, Font font)
{
Render(g, pen, brush, font, true, true);
}
public virtual void Render(Graphics g, Pen pen, Brush brush, Font font, bool renderPathJoints, bool renderArrow)
{
if (PathJoints.Count >= 2)
{
int n = PathJoints.Count;
int i;
for (i = 0; i < n - 1; i++)
{
//if (renderPathJoints)
//{
// PathJoints[i].Render(g, pen, brush, font);
//}
g.DrawLine(Pens.Black, PathJoints[i], PathJoints[i + 1]);
}
if (n > 1 && To != null)
{
if (renderArrow)
{
RenderArrow(g, pen, brush, font, PathJoints[n - 2], PathJoints[n - 1]);
}
}
else if (n > 0)
{
//if (renderPathJoints)
//{
// PathJoints[j - 1].Render(g, pen, brush, font);
//}
}
}
else if (From != null && To != null)
{
Vector from = From.GetOutboundConnectionPoint(this);
Vector to = To.GetInboundConnectionPoint(this);
g.DrawLine(pen, from, to);
if (renderArrow)
{
RenderArrow(g, pen, brush, font, from, to);
}
}
else if (From != null)
{
Vector from = From.GetOutboundConnectionPoint(this);
Vector center = From.GetCenterOfBox();
g.DrawLine(pen, from, 10 * (from - center).Normalized());
}
else if (To != null)
{
Vector to = To.GetInboundConnectionPoint(this);
Vector center = To.GetCenterOfBox();
g.DrawLine(pen, 10 * (to - center).Normalized(), to);
}
//else if (PathJoints.Count == 1)
//{
// PathJoints[0].Render(g, pen, brush, font);
//}
else
{
//no from, no to, no pathjoints
//don't render anything
}
}
public virtual void RenderArrow(Graphics g, Pen pen, Brush brush, Font font, Vector startLocation, Vector tipLocation)
{
Vector[] r = { new Vector(), new Vector(), new Vector() };
Vector p;
float angle;
float size;
size = ArrowSize;
p = tipLocation - startLocation;
angle = p.CalcTheta();
r[0] = tipLocation;
r[1] = Vector.FromPolar(angle + (float)(Math.PI * 5.0 / 6.0), size) + r[0];
r[2] = Vector.FromPolar(angle - (float)(Math.PI * 5.0 / 6.0), size) + r[0];
g.FillPolygon(pen.Brush, Vector.ConvertArray(r));
}
//private float _arrowSize;
public float ArrowSize
{
get { return 10; }
protected set { }
}
public virtual List<Vector> PathJoints
{
get { return _pathJoints; }
}
public virtual Element To
{
get { return _to; }
set
{
if (_to != value)
{
//this.OnToChanging(new EventArgs());
if (_to != null)
{
_to.Inbound.Remove(this);
}
_to = value;
if (_to != null)
{
_to.Inbound.Add(this);
}
if (ParentCrystallineControl != null)
{
ParentCrystallineControl.RoutePath(this);
}
this.OnToChanged(new EventArgs());
}
}
}
public virtual Element From
{
get { return _from; }
set
{
if (_from != value)
{
//this.OnFromChanging(new EventArgs());
if (_from != null)
{
_from.Outbound.Remove(this);
}
_from = value;
if (_from != null)
{
_from.Outbound.Add(this);
}
if (ParentCrystallineControl != null)
{
ParentCrystallineControl.RoutePath(this);
}
this.OnFromChanged(new EventArgs());
}
}
}
//[MetaphysicsIndustries.Serialization.Serializable(false)]
//CrystallineControl _parentCrystallineControl;
public override CrystallineControl ParentCrystallineControl
{
get { return base.ParentCrystallineControl; }
set
{
if (ParentCrystallineControl != value)
{
if (ParentCrystallineControl != null)
{
ParentCrystallineControl.Entities.Remove(this);
}
SetParentCrystallineControl(value);
if (ParentCrystallineControl != null)
{
ParentCrystallineControl.Entities.Add(this);
}
}
}
}
//public event EventHandler ToChanging;
//public event EventHandler ToChanged;
//public event EventHandler FromChanged;
//public event EventHandler FromChanging;
protected virtual void OnFromChanged(EventArgs e)
{
//if (FromChanged != null)
//{
// this.FromChanged(this, e);
//}
}
protected virtual void OnToChanged(EventArgs e)
{
//if (ToChanged != null)
//{
// this.ToChanged(this, e);
//}
}
//protected virtual void OnFromChanging(EventArgs e)
//{
// if (FromChanging != null)
// {
// this.FromChanging(this, e);
// }
//}
//protected virtual void OnToChanging(EventArgs e)
//{
// if (ToChanging != null)
// {
// this.ToChanging(this, e);
// }
//}
public override void Disconnect(out Entity[] entitiesToRemove)
{
From = null;
To = null;
entitiesToRemove = null;
}
private List<Vector> _pathJoints = new List<Vector>();
private Element _to;
private Element _from;
}
}