1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Windows.Forms;
|
---|
4 | namespace Netron.Diagramming.Core
|
---|
5 | {
|
---|
6 | /// <summary>
|
---|
7 | /// Abstract base class for a connection
|
---|
8 | /// </summary>
|
---|
9 | public abstract partial class ConnectionBase : DiagramEntityBase, IConnection
|
---|
10 | {
|
---|
11 | // ------------------------------------------------------------------
|
---|
12 | /// <summary>
|
---|
13 | /// Specifies the minimum length a connection can be. This is used
|
---|
14 | /// by the ConnectionTool to determine if the connection start and
|
---|
15 | /// stop points are far enough apart to create a connection.
|
---|
16 | /// </summary>
|
---|
17 | // ------------------------------------------------------------------
|
---|
18 | public const int MinLength = 5;
|
---|
19 |
|
---|
20 | #region Fields
|
---|
21 |
|
---|
22 | // ------------------------------------------------------------------
|
---|
23 | /// <summary>
|
---|
24 | /// Implementation of IVersion - the current version of
|
---|
25 | /// ConnectionBase.
|
---|
26 | /// </summary>
|
---|
27 | // ------------------------------------------------------------------
|
---|
28 | protected const double connectionBaseVersion = 1.0;
|
---|
29 |
|
---|
30 | /// <summary>
|
---|
31 | /// the start connector
|
---|
32 | /// </summary>
|
---|
33 | private IConnector mFrom;
|
---|
34 | /// <summary>
|
---|
35 | /// the end connector
|
---|
36 | /// </summary>
|
---|
37 | private IConnector mTo;
|
---|
38 |
|
---|
39 | #endregion
|
---|
40 |
|
---|
41 | #region Properties
|
---|
42 |
|
---|
43 | // ------------------------------------------------------------------
|
---|
44 | /// <summary>
|
---|
45 | /// Gets the current version.
|
---|
46 | /// </summary>
|
---|
47 | // ------------------------------------------------------------------
|
---|
48 | public override double Version
|
---|
49 | {
|
---|
50 | get
|
---|
51 | {
|
---|
52 | return connectionBaseVersion;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | /// <summary>
|
---|
57 | /// The initial or start connector
|
---|
58 | /// </summary>
|
---|
59 | public IConnector From
|
---|
60 | {
|
---|
61 | get{return mFrom;}
|
---|
62 | set{mFrom = value;}
|
---|
63 | }
|
---|
64 | /// <summary>
|
---|
65 | /// The final or end connector
|
---|
66 | /// </summary>
|
---|
67 | /// <example>
|
---|
68 | /// <code>
|
---|
69 | /// Connection connection
|
---|
70 | /// </code>
|
---|
71 | /// </example>
|
---|
72 | public IConnector To
|
---|
73 | {
|
---|
74 | get{return mTo;}
|
---|
75 | set{mTo = value;}
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 | #endregion
|
---|
82 |
|
---|
83 | #region Constructor
|
---|
84 | /// <summary>
|
---|
85 | /// Default constructor
|
---|
86 | /// </summary>
|
---|
87 | /// <param name="site"></param>
|
---|
88 | protected ConnectionBase(IModel site) : base(site)
|
---|
89 | {
|
---|
90 | PenStyle = ArtPalette.GetDefaultPenStyle();
|
---|
91 |
|
---|
92 | }
|
---|
93 |
|
---|
94 | /// <summary>
|
---|
95 | /// Initializes a new instance of the <see cref="T:ConnectionBase"/> class.
|
---|
96 | /// </summary>
|
---|
97 | /// <param name="from">From.</param>
|
---|
98 | /// <param name="to">To.</param>
|
---|
99 | protected ConnectionBase(Point from, Point to) : base()
|
---|
100 | {
|
---|
101 | this.mFrom = new Connector(from);
|
---|
102 | this.mFrom.Parent = this;
|
---|
103 | this.mTo = new Connector(to);
|
---|
104 | this.mTo.Parent = this;
|
---|
105 | PenStyle = ArtPalette.GetDefaultPenStyle();
|
---|
106 | }
|
---|
107 |
|
---|
108 | public ConnectionBase() : base() { }
|
---|
109 |
|
---|
110 | #endregion
|
---|
111 |
|
---|
112 | #region Methods
|
---|
113 | /// <summary>
|
---|
114 | /// Paints the entity on the control
|
---|
115 | /// </summary>
|
---|
116 | /// <param name="g"></param>
|
---|
117 | public override void Paint(Graphics g)
|
---|
118 | {
|
---|
119 | if (g == null)
|
---|
120 | throw new ArgumentNullException("The Graphics object is 'null'");
|
---|
121 | From.Paint(g);
|
---|
122 | To.Paint(g);
|
---|
123 | }
|
---|
124 | /// <summary>
|
---|
125 | /// The custom menu to be added to the base menu of this entity
|
---|
126 | /// </summary>
|
---|
127 | /// <returns>ToolStripItem[]</returns>
|
---|
128 | public override ToolStripItem[] Menu()
|
---|
129 | {
|
---|
130 | return null;
|
---|
131 | }
|
---|
132 | /// <summary>
|
---|
133 | /// Invalidates the entity
|
---|
134 | /// </summary>
|
---|
135 | public override void Invalidate()
|
---|
136 | {
|
---|
137 |
|
---|
138 |
|
---|
139 | Rectangle r = Rectangle;
|
---|
140 | r.Offset(-10, -10);
|
---|
141 | r.Inflate(40, 40);
|
---|
142 | if (Model != null)
|
---|
143 | Model.RaiseOnInvalidateRectangle(r);
|
---|
144 | }
|
---|
145 |
|
---|
146 | #endregion
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 | }
|
---|
152 | }
|
---|