forked from JasonLautzenheiser/trizbort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnection.cs
969 lines (877 loc) · 26.7 KB
/
Connection.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
/*
Copyright (c) 2010-2015 by Genstein and Jason Lautzenheiser.
This file is (or was originally) part of Trizbort, the Interactive Fiction Mapper.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using PdfSharp.Drawing;
namespace Trizbort
{
/// <summary>
/// A connection between elements or points in space.
/// </summary>
/// <remarks>
/// Connections are multi-segment lines between vertices.
/// Each vertex is fixed either to a point in space or
/// to an element's port.
/// </remarks>
internal class Connection : Element
{
public const string Up = "up";
public const string Down = "down";
public const string In = "in";
public const string Out = "out";
private static readonly ConnectionStyle DefaultStyle = ConnectionStyle.Solid;
private static readonly ConnectionFlow DefaultFlow = ConnectionFlow.TwoWay;
private readonly TextBlock m_endText = new TextBlock();
private readonly TextBlock m_midText = new TextBlock();
private readonly List<LineSegment> m_smartSegments = new List<LineSegment>();
private readonly TextBlock m_startText = new TextBlock();
private readonly BoundList<Vertex> m_vertexList = new BoundList<Vertex>();
private ConnectionFlow m_flow = DefaultFlow;
private ConnectionStyle m_style = DefaultStyle;
private Color m_ConnectionColor = Color.Transparent;
public Connection(Project project)
: base(project)
{
m_vertexList.Added += OnVertexAdded;
m_vertexList.Removed += OnVertexRemoved;
}
// Added this second constructor to be used when loading a room
// This constructor is significantly faster as it doesn't look for gap in the element IDs
public Connection(Project project, int TotalIDs)
: base(project, TotalIDs)
{
m_vertexList.Added += OnVertexAdded;
m_vertexList.Removed += OnVertexRemoved;
}
public Connection(Project project, Vertex a, Vertex b)
: this(project)
{
VertexList.Add(a);
VertexList.Add(b);
}
// Added to ignore ID gaps
public Connection(Project project, Vertex a, Vertex b, int TotalIDs)
: this(project, TotalIDs)
{
VertexList.Add(a);
VertexList.Add(b);
}
public Connection(Project project, Vertex a, Vertex b, params Vertex[] args)
: this(project, a, b)
{
foreach (var vertex in args)
{
VertexList.Add(vertex);
}
}
// Added to ignore ID gaps
public Connection(Project project, Vertex a, Vertex b, int TotalIDs, params Vertex[] args)
: this(project, a, b, TotalIDs)
{
foreach (var vertex in args)
{
VertexList.Add(vertex);
}
}
public Color ConnectionColor
{
get { return m_ConnectionColor; }
set
{
if (m_ConnectionColor != value)
{
m_ConnectionColor = value;
RaiseChanged();
}
}
}
public ConnectionStyle Style
{
get { return m_style; }
set
{
if (m_style != value)
{
m_style = value;
RaiseChanged();
}
}
}
public ConnectionFlow Flow
{
get { return m_flow; }
set
{
if (m_flow != value)
{
m_flow = value;
RaiseChanged();
}
}
}
public string StartText
{
get { return m_startText.Text; }
set
{
if (m_startText.Text != value)
{
m_startText.Text = value;
RaiseChanged();
}
}
}
public string MidText
{
get { return m_midText.Text; }
set
{
if (m_midText.Text != value)
{
m_midText.Text = value;
RaiseChanged();
}
}
}
public string EndText
{
get { return m_endText.Text; }
set
{
if (m_endText.Text != value)
{
m_endText.Text = value;
RaiseChanged();
}
}
}
public BoundList<Vertex> VertexList
{
get { return m_vertexList; }
}
public override Depth Depth
{
get { return Depth.Low; }
}
public override bool HasDialog
{
get { return true; }
}
private void OnVertexAdded(object sender, ItemEventArgs<Vertex> e)
{
e.Item.Connection = this;
e.Item.Changed += OnVertexChanged;
PortList.Add(new VertexPort(e.Item, this));
}
private void OnVertexRemoved(object sender, ItemEventArgs<Vertex> e)
{
e.Item.Connection = null;
e.Item.Changed -= OnVertexChanged;
foreach (VertexPort port in PortList)
{
if (port.Vertex == e.Item)
{
PortList.Remove(port);
break;
}
}
}
private void OnVertexChanged(object sender, EventArgs e)
{
RaiseChanged();
}
public void SetText(string start, string mid, string end)
{
StartText = start;
MidText = mid ?? MidText;
EndText = end;
}
public static void GetText(ConnectionLabel label, out string start, out string end)
{
start = string.Empty;
end = string.Empty;
switch (label)
{
case ConnectionLabel.None:
start = string.Empty;
end = string.Empty;
break;
case ConnectionLabel.Up:
start = Up;
end = Down;
break;
case ConnectionLabel.Down:
start = Down;
end = Up;
break;
case ConnectionLabel.In:
start = In;
end = Out;
break;
case ConnectionLabel.Out:
start = Out;
end = In;
break;
}
}
public void SetText(ConnectionLabel label)
{
string start, end;
GetText(label, out start, out end);
SetText(start, null, end);
}
private List<LineSegment> GetSegments()
{
var list = new List<LineSegment>();
if (VertexList.Count > 0)
{
var first = VertexList[0];
var last = VertexList[VertexList.Count - 1];
var index = 0;
var a = VertexList[index++].Position;
if (first.Port != null && first.Port.HasStalk)
{
var stalkPos = first.Port.StalkPosition;
list.Add(new LineSegment(a, stalkPos));
a = stalkPos;
}
while (index < VertexList.Count)
{
var v = VertexList[index++];
var b = v.Position;
if (index == VertexList.Count && v.Port != null && v.Port.HasStalk)
{
var stalkPos = v.Port.StalkPosition;
list.Add(new LineSegment(a, stalkPos));
a = stalkPos;
}
list.Add(new LineSegment(a, b));
a = b;
}
}
return list;
}
/// <summary>
/// Split the given line segment if it crosses line segments we've already drawn.
/// </summary>
/// <param name="lineSegment">The line segment to consider.</param>
/// <param name="context">The context in which we've been drawing line segments.</param>
/// <param name="newSegments">
/// The results of splitting the given line segment, if any. Call with a reference to a null
/// list.
/// </param>
/// <returns>True if the line segment was split and newSegments now exists and contains line segments; false otherwise.</returns>
private bool Split(LineSegment lineSegment, DrawingContext context, ref List<LineSegment> newSegments)
{
foreach (var previousSegment in context.LinesDrawn)
{
var amount = Math.Max(1, Settings.LineWidth)*3;
List<LineSegmentIntersect> intersects;
if (lineSegment.Intersect(previousSegment, true, out intersects))
{
foreach (var intersect in intersects)
{
switch (intersect.Type)
{
case LineSegmentIntersectType.MidPointA:
var one = new LineSegment(lineSegment.Start, intersect.Position);
if (one.Shorten(amount))
{
if (!Split(one, context, ref newSegments))
{
if (newSegments == null)
{
newSegments = new List<LineSegment>();
}
newSegments.Add(one);
}
}
var two = new LineSegment(intersect.Position, lineSegment.End);
if (two.Forshorten(amount))
{
if (!Split(two, context, ref newSegments))
{
if (newSegments == null)
{
newSegments = new List<LineSegment>();
}
newSegments.Add(two);
}
}
break;
case LineSegmentIntersectType.StartA:
if (lineSegment.Forshorten(amount))
{
if (!Split(lineSegment, context, ref newSegments))
{
if (newSegments == null)
{
newSegments = new List<LineSegment>();
}
newSegments.Add(lineSegment);
}
}
break;
case LineSegmentIntersectType.EndA:
if (lineSegment.Shorten(amount))
{
if (!Split(lineSegment, context, ref newSegments))
{
if (newSegments == null)
{
newSegments = new List<LineSegment>();
}
newSegments.Add(lineSegment);
}
}
break;
}
// don't check other intersects;
// we've already split this line, and tested the parts for further intersects.
return newSegments != null;
}
}
}
return false;
}
public override void RecomputeSmartLineSegments(DrawingContext context)
{
m_smartSegments.Clear();
foreach (var lineSegment in GetSegments())
{
List<LineSegment> newSegments = null;
if (Split(lineSegment, context, ref newSegments))
{
foreach (var newSegment in newSegments)
{
m_smartSegments.Add(newSegment);
}
}
else
{
m_smartSegments.Add(lineSegment);
}
}
foreach (var segment in m_smartSegments)
{
context.LinesDrawn.Add(segment);
}
}
public override void Draw(XGraphics graphics, Palette palette, DrawingContext context)
{
var lineSegments = context.UseSmartLineSegments ? m_smartSegments : GetSegments();
foreach (var lineSegment in lineSegments)
{
var pen = palette.GetLinePen(context.Selected, context.Hover, Style == ConnectionStyle.Dashed);
Pen specialPen = null;
if (!context.Hover)
if ((ConnectionColor != Color.Transparent) && !context.Selected)
{
specialPen = (Pen) pen.Clone();
specialPen.Color = ConnectionColor;
}
if (!Settings.DebugDisableLineRendering)
{
graphics.DrawLine(specialPen ?? pen, lineSegment.Start.ToPointF(), lineSegment.End.ToPointF());
}
var delta = lineSegment.Delta;
if (Flow == ConnectionFlow.OneWay && delta.Length > Settings.ConnectionArrowSize)
{
SolidBrush brush = (SolidBrush) palette.GetLineBrush(context.Selected, context.Hover);
SolidBrush specialBrush = null;
if (!context.Hover)
if ((ConnectionColor != Color.Transparent) && !context.Selected)
{
specialBrush = (SolidBrush) brush.Clone();
specialBrush.Color = ConnectionColor;
}
Drawing.DrawChevron(graphics, lineSegment.Mid.ToPointF(), (float) (Math.Atan2(delta.Y, delta.X)/Math.PI*180), Settings.ConnectionArrowSize, specialBrush ?? brush);
}
context.LinesDrawn.Add(lineSegment);
}
Annotate(graphics, palette, lineSegments);
}
private void Annotate(XGraphics graphics, Palette palette, List<LineSegment> lineSegments)
{
if (lineSegments.Count == 0)
return;
if (!string.IsNullOrEmpty(StartText))
{
Annotate(graphics, palette, lineSegments[0], m_startText, StringAlignment.Near);
}
if (!string.IsNullOrEmpty(EndText))
{
Annotate(graphics, palette, lineSegments[lineSegments.Count - 1], m_endText, StringAlignment.Far);
}
if (!string.IsNullOrEmpty(MidText))
{
var totalLength = lineSegments.Sum(lineSegment => lineSegment.Length);
var middle = totalLength/2;
foreach (var lineSegment in lineSegments)
{
var length = lineSegment.Length;
if (middle > length)
{
middle -= length;
}
else
{
middle /= length;
var pos = lineSegment.Start + lineSegment.Delta*middle;
var fakeSegment = new LineSegment(pos - lineSegment.Delta*Numeric.Small, pos + lineSegment.Delta*Numeric.Small);
Annotate(graphics, palette, fakeSegment, m_midText, StringAlignment.Center);
break;
}
}
}
}
private static void Annotate(XGraphics graphics, Palette palette, LineSegment lineSegment, TextBlock text, StringAlignment alignment)
{
Vector point;
var delta = lineSegment.Delta;
switch (alignment)
{
case StringAlignment.Near:
default:
point = lineSegment.Start;
delta.Negate();
break;
case StringAlignment.Center:
point = lineSegment.Mid;
break;
case StringAlignment.Far:
point = lineSegment.End;
break;
}
var bounds = new Rect(point, Vector.Zero);
bounds.Inflate(Settings.TextOffsetFromConnection);
var angle = (float) -(Math.Atan2(delta.Y, delta.X)/Math.PI*180.0);
var compassPoint = CompassPoint.East;
if (Numeric.InRange(angle, 0, 45))
{
compassPoint = CompassPoint.NorthWest;
}
else if (Numeric.InRange(angle, 45, 90))
{
compassPoint = CompassPoint.SouthEast;
}
else if (Numeric.InRange(angle, 90, 135))
{
compassPoint = CompassPoint.SouthWest;
}
else if (Numeric.InRange(angle, 135, 180))
{
compassPoint = CompassPoint.NorthEast;
}
else if (Numeric.InRange(angle, 0, -45))
{
compassPoint = CompassPoint.NorthEast;
}
else if (Numeric.InRange(angle, -45, -90))
{
compassPoint = CompassPoint.NorthEast;
}
else if (Numeric.InRange(angle, -90, -135))
{
compassPoint = CompassPoint.NorthWest;
}
else if (Numeric.InRange(angle, -135, -180))
{
compassPoint = CompassPoint.SouthEast;
}
var pos = bounds.GetCorner(compassPoint);
var format = new XStringFormat();
Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, compassPoint);
if (alignment == StringAlignment.Center && Numeric.InRange(angle, -10, 10))
{
// HACK: if the line segment is pretty horizontal and we're drawing mid-line text,
// move text below the line to get it out of the way of any labels at the ends,
// and center the text so it fits onto a line between two proximal rooms.
pos = bounds.GetCorner(CompassPoint.South);
format.Alignment = XStringAlignment.Center;
format.LineAlignment = XLineAlignment.Near;
}
if (!Settings.DebugDisableTextRendering)
text.Draw(graphics, Settings.LineFont, palette.LineBrush, pos, Vector.Zero, format);
}
public override Rect UnionBoundsWith(Rect rect, bool includeMargins)
{
foreach (var vertex in VertexList)
{
rect = rect.Union(vertex.Position);
}
return rect;
}
public override Vector GetPortPosition(Port port)
{
var vertexPort = (VertexPort) port;
return vertexPort.Vertex.Position;
}
public override Vector GetPortStalkPosition(Port port)
{
return GetPortPosition(port);
}
public override string GetToolTipText()
{
return "Connection ToolTip Text";
}
public override eTooltipColor GetToolTipColor()
{
return eTooltipColor.Apple;
}
public override string GetToolTipFooter()
{
return string.Empty;
}
public override string GetToolTipHeader()
{
return string.Empty;
}
public override bool HasTooltip()
{
return false;
}
public override float Distance(Vector pos, bool includeMargins)
{
var distance = float.MaxValue;
foreach (var segment in GetSegments())
{
distance = Math.Min(distance, pos.DistanceFromLineSegment(segment));
}
return distance;
}
public override bool Intersects(Rect rect)
{
foreach (var segment in GetSegments())
{
if (segment.IntersectsWith(rect))
{
return true;
}
}
return false;
}
public override void ShowDialog()
{
using (var dialog = new ConnectionPropertiesDialog())
{
dialog.IsDotted = Style == ConnectionStyle.Dashed;
dialog.IsDirectional = Flow == ConnectionFlow.OneWay;
dialog.StartText = StartText;
dialog.MidText = MidText;
dialog.EndText = EndText;
dialog.ConnectionColor = ConnectionColor;
if (dialog.ShowDialog() == DialogResult.OK)
{
Style = dialog.IsDotted ? ConnectionStyle.Dashed : ConnectionStyle.Solid;
Flow = dialog.IsDirectional ? ConnectionFlow.OneWay : ConnectionFlow.TwoWay;
ConnectionColor = dialog.ConnectionColor;
StartText = dialog.StartText;
MidText = dialog.MidText;
EndText = dialog.EndText;
}
}
}
public void Save(XmlScribe scribe)
{
if (ConnectionColor != Color.Transparent)
scribe.Attribute("color",Colors.SaveColor(ConnectionColor));
if (Style != DefaultStyle)
{
switch (Style)
{
case ConnectionStyle.Solid:
scribe.Attribute("style", "solid");
break;
case ConnectionStyle.Dashed:
scribe.Attribute("style", "dashed");
break;
}
}
if (Flow != DefaultFlow)
{
switch (Flow)
{
case ConnectionFlow.OneWay:
scribe.Attribute("flow", "oneWay");
break;
case ConnectionFlow.TwoWay:
scribe.Attribute("flow", "twoWay");
break;
}
}
if (!string.IsNullOrEmpty(StartText))
{
scribe.Attribute("startText", StartText);
}
if (!string.IsNullOrEmpty(MidText))
{
scribe.Attribute("midText", MidText);
}
if (!string.IsNullOrEmpty(EndText))
{
scribe.Attribute("endText", EndText);
}
var index = 0;
foreach (var vertex in VertexList)
{
if (vertex.Port != null)
{
scribe.StartElement("dock");
scribe.Attribute("index", index);
scribe.Attribute("id", vertex.Port.Owner.ID);
scribe.Attribute("port", vertex.Port.ID);
scribe.EndElement();
}
else
{
scribe.StartElement("point");
scribe.Attribute("index", index);
scribe.Attribute("x", vertex.Position.X);
scribe.Attribute("y", vertex.Position.Y);
scribe.EndElement();
}
++index;
}
}
public object BeginLoad(XmlElementReader element)
{
switch (element.Attribute("style").Text)
{
case "solid":
default:
Style = ConnectionStyle.Solid;
break;
case "dashed":
Style = ConnectionStyle.Dashed;
break;
}
switch (element.Attribute("flow").Text)
{
case "twoWay":
default:
Flow = ConnectionFlow.TwoWay;
break;
case "oneWay":
Flow = ConnectionFlow.OneWay;
break;
}
StartText = element.Attribute("startText").Text;
MidText = element.Attribute("midText").Text;
EndText = element.Attribute("endText").Text;
if (element.Attribute("color").Text != "") { ConnectionColor = ColorTranslator.FromHtml(element.Attribute("color").Text); }
var vertexElementList = new List<XmlElementReader>();
vertexElementList.AddRange(element.Children);
vertexElementList.Sort((a, b) => a.Attribute("index").ToInt().CompareTo(b.Attribute("index").ToInt()));
foreach (var vertexElement in vertexElementList)
{
if (vertexElement.HasName("point"))
{
var vertex = new Vertex();
vertex.Position = new Vector(vertexElement.Attribute("x").ToFloat(), vertexElement.Attribute("y").ToFloat());
VertexList.Add(vertex);
}
else if (vertexElement.HasName("dock"))
{
var vertex = new Vertex();
// temporarily leave this vertex as a positional vertex;
// we can't safely dock it to a port until EndLoad().
VertexList.Add(vertex);
}
}
return vertexElementList;
}
public void EndLoad(object state)
{
var elements = (List<XmlElementReader>) (state);
for (var index = 0; index < elements.Count; ++index)
{
var element = elements[index];
if (element.HasName("dock"))
{
Element target;
if (Project.FindElement(element.Attribute("id").ToInt(), out target))
{
var portID = element.Attribute("port").Text;
foreach (var port in target.Ports)
{
if (StringComparer.InvariantCultureIgnoreCase.Compare(portID, port.ID) == 0)
{
var vertex = VertexList[index];
vertex.Port = port;
break;
}
}
}
}
}
}
public void Reverse()
{
VertexList.Reverse();
RaiseChanged();
}
public Room GetSourceRoom(out CompassPoint sourceCompassPoint)
{
if (m_vertexList.Count > 0)
{
var port = m_vertexList[0].Port;
if (port is Room.CompassPort)
{
var compassPort = (Room.CompassPort) port;
sourceCompassPoint = compassPort.CompassPoint;
return port.Owner as Room;
}
}
sourceCompassPoint = CompassPoint.North;
return null;
}
public Room GetTargetRoom(out CompassPoint targetCompassPoint)
{
if (m_vertexList.Count > 1)
{
var port = m_vertexList[m_vertexList.Count - 1].Port;
if (port is Room.CompassPort)
{
var compassPort = (Room.CompassPort) port;
targetCompassPoint = compassPort.CompassPoint;
return compassPort.Owner as Room;
}
}
targetCompassPoint = CompassPoint.North;
return null;
}
public String ClipboardPrint()
{
var clipboardText = "";
switch (Style)
{
case ConnectionStyle.Solid:
clipboardText += "solid" + ":";
break;
case ConnectionStyle.Dashed:
clipboardText += "dashed" + ":";
break;
default:
clipboardText += "default" + ":";
break;
}
switch (Flow)
{
case ConnectionFlow.OneWay:
clipboardText += "oneWay" + ":";
break;
case ConnectionFlow.TwoWay:
clipboardText += "twoWay" + ":";
break;
default:
clipboardText += "default" + ":";
break;
}
clipboardText += StartText + ":";
clipboardText += MidText + ":";
clipboardText += EndText;
var index = 0;
foreach (var vertex in VertexList)
{
clipboardText += ":";
if (vertex.Port != null)
{
clipboardText += "dock" + ":";
clipboardText += index + ":";
clipboardText += vertex.Port.Owner.ID + ":";
clipboardText += vertex.Port.ID;
}
else
{
clipboardText += "point" + ":";
clipboardText += index + ":";
clipboardText += vertex.Position.X + ":";
clipboardText += vertex.Position.Y;
}
++index;
}
clipboardText += "";
return clipboardText;
}
internal class VertexPort : MoveablePort
{
public VertexPort(Vertex vertex, Connection connection)
: base(connection)
{
Vertex = vertex;
Connection = connection;
}
public override string ID
{
get { return Connection.VertexList.IndexOf(Vertex).ToString(CultureInfo.InvariantCulture); }
}
public override Port DockedAt
{
get { return Vertex.Port; }
}
public Vertex Vertex { get; private set; }
public Connection Connection { get; private set; }
public override void SetPosition(Vector pos)
{
Vertex.Position = pos;
Connection.RaiseChanged();
}
public override void DockAt(Port port)
{
Vertex.Port = port;
Connection.RaiseChanged();
}
}
}
/// <summary>
/// The visual style of a connection.
/// </summary>
internal enum ConnectionStyle
{
Solid,
Dashed
}
/// <summary>
/// The direction in which a connection flows.
/// </summary>
internal enum ConnectionFlow
{
TwoWay,
OneWay
}
/// <summary>
/// The style of label to display on a line.
/// This is a simple set of defaults; lines may have entirely custom labels.
/// </summary>
internal enum ConnectionLabel
{
None,
Up,
Down,
In,
Out
}
}