1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Windows.Forms;
|
---|
5 | using Netron.Diagramming.Core.Analysis;
|
---|
6 | namespace Netron.Diagramming.Core
|
---|
7 | {
|
---|
8 | /// <summary>
|
---|
9 | /// Base class for graph layout
|
---|
10 | /// </summary>
|
---|
11 | abstract class LayoutBase : ActionBase, ILayout
|
---|
12 | {
|
---|
13 | #region Fields
|
---|
14 | private IGraph graph;
|
---|
15 |
|
---|
16 | private string mName;
|
---|
17 | private Rectangle mBounds;
|
---|
18 | private PointF mCenter;
|
---|
19 | private const int defaultSpan = 400;
|
---|
20 | private IController mController = null;
|
---|
21 | #endregion
|
---|
22 |
|
---|
23 | #region Properties
|
---|
24 |
|
---|
25 | /// <summary>
|
---|
26 | /// Gets the nodes of the graph. This is another casting of the shapes collection of the model.
|
---|
27 | /// </summary>
|
---|
28 | /// <value>The nodes.</value>
|
---|
29 | public CollectionBase<INode> Nodes
|
---|
30 | {
|
---|
31 | get { return graph.Nodes; }
|
---|
32 | }
|
---|
33 |
|
---|
34 | /// <summary>
|
---|
35 | /// Gets the edges of the graph. This is just another casting of the connection collection of the model.
|
---|
36 | /// </summary>
|
---|
37 | /// <value>The edges.</value>
|
---|
38 | public CollectionBase<IEdge> Edges
|
---|
39 | {
|
---|
40 | get { return graph.Edges; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public IController Controller
|
---|
44 | {
|
---|
45 | get { return mController; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected int DefaultRunSpan
|
---|
49 | {
|
---|
50 | get { return defaultSpan; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | /// <summary>
|
---|
54 | /// Gets or sets the center of the layout. This can be the arithmetic middle
|
---|
55 | /// of the bounding area or can be set independently.
|
---|
56 | /// </summary>
|
---|
57 | public PointF Center
|
---|
58 | {
|
---|
59 | get { return mCenter; }
|
---|
60 | set { mCenter = value; }
|
---|
61 | }
|
---|
62 |
|
---|
63 | public IGraph Graph
|
---|
64 | {
|
---|
65 | get { return graph; }
|
---|
66 | set { graph = value; }
|
---|
67 | }
|
---|
68 | /// <summary>
|
---|
69 | /// Gets or sets the bounds of the layout surface.
|
---|
70 | /// </summary>
|
---|
71 | /// <value>The bounds.</value>
|
---|
72 | public Rectangle Bounds
|
---|
73 | {
|
---|
74 | get { return mBounds; }
|
---|
75 | set { mBounds = value; }
|
---|
76 |
|
---|
77 | }
|
---|
78 | public string LayoutName
|
---|
79 | {
|
---|
80 | get { return mName; }
|
---|
81 | }
|
---|
82 | #endregion
|
---|
83 |
|
---|
84 | #region Constructor
|
---|
85 | /// <summary>
|
---|
86 | /// Initializes a new instance of the <see cref="T:LayoutBase"/> class.
|
---|
87 | /// </summary>
|
---|
88 | /// <param name="name">The name.</param>
|
---|
89 | /// <param name="controller">The controller.</param>
|
---|
90 | protected LayoutBase(string name, IController controller ) : base(name)
|
---|
91 | {
|
---|
92 | mName = name;
|
---|
93 | mController = controller;
|
---|
94 | }
|
---|
95 |
|
---|
96 | #endregion
|
---|
97 |
|
---|
98 | #region Methods
|
---|
99 | protected void setX(INode item, INode referrer, double x)
|
---|
100 | {
|
---|
101 |
|
---|
102 | //float sx = item.Rectangle.X;
|
---|
103 | //if(float.IsNaN(sx))
|
---|
104 | // sx = (referrer != null ? referrer.Rectangle.X : x);
|
---|
105 |
|
---|
106 | item.MoveBy(new Point(Convert.ToInt32(x - item.Rectangle.X), 0));
|
---|
107 | //Trace.WriteLine("setX(" + x + ",0)");
|
---|
108 |
|
---|
109 | }
|
---|
110 | protected void setY(INode item, INode referrer, double y)
|
---|
111 | {
|
---|
112 |
|
---|
113 | //float sx = item.Rectangle.X;
|
---|
114 | //if(float.IsNaN(sx))
|
---|
115 | // sx = (referrer != null ? referrer.Rectangle.X : x);
|
---|
116 |
|
---|
117 | item.MoveBy(new Point(0, Convert.ToInt32(y - item.Rectangle.Y)));
|
---|
118 | //Trace.WriteLine("setY(0," + y +")");
|
---|
119 | }
|
---|
120 | #endregion
|
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 | }
|
---|
125 |
|
---|
126 | }
|
---|