-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphCreator.cs
More file actions
335 lines (267 loc) · 9.89 KB
/
GraphCreator.cs
File metadata and controls
335 lines (267 loc) · 9.89 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace GBusManager
{
public partial class GraphCreator : GraphViewer
{
#region vars
int c;
bool drawLine;
bool movePoint;
int x1, y1;
public string crs = "";
int lpn = -1;
Point s,f;
bool newPointBlock; // не позволяет добавлять новые точки, пока не подтверждено добавление предыдущей
#endregion
public ArrayList tempedges = new ArrayList();
public ArrayList tempdiredges = new ArrayList();
public ArrayList activeroutes = new ArrayList();
public GraphCreator()
{
points = Status.Points;
this.g = this.CreateGraphics();
c = Status.Points.Count;
//activeroutes = SaveLoad.Routes;
InitializeComponent();
Status.myPoints.PointAdded += new PointHandler(myPoints_PointAdded);
Status.myPoints.PointDeleted += new PointHandler(myPoints_PointDeleted);
Status.myRoutes.RouteAdded += new RouteHandler(myRoutes_RouteAdded);
}
void myRoutes_RouteAdded(object sender, RoutesEventArgs e)
{
Console.WriteLine("GraphCreator должен нарисовать новый маршрут {0}", e.route);
}
void myPoints_PointDeleted(object sender, PointsEventArgs e)
{
Console.WriteLine("GraphCreator должен стереть точку {0}", e.point);
}
void myPoints_PointAdded(object sender, PointsEventArgs e)
{
Console.WriteLine("GraphCreator должен нарисовать новую точку {0}",e.point);
}
public void ResetRouteInfo()
{
lpn = -1;
crs = "";
tempedges.Clear();
state = GState.NodesAndRoutes;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void GraphCreator_Load(object sender, EventArgs e)
{
}
public override void GraphView_MouseClick(object sender, MouseEventArgs e)
{
if (Status.mode == Misc.Mode.Point)
{
#region Point
if (!newPointBlock)
{
newPointBlock = true;
g.FillEllipse(new SolidBrush(Color.Black), e.X - Settings1.Default.NodeSize / 2, e.Y - Settings1.Default.NodeSize / 2, Settings1.Default.NodeSize, Settings1.Default.NodeSize);
TextBox tb = new TextBox();
this.Controls.Add(tb);
tb.Left = e.X;
tb.Top = e.Y - tb.Height;
tb.Width = 20;
tb.Text = Status.Points.Count.ToString();
Button addBtn = new Button();
addBtn.Left = e.X + tb.Width;
addBtn.Top = e.Y - addBtn.Height;
addBtn.Width = 20;
addBtn.Click += delegate
{
c++;
this.Controls.Remove(addBtn);
this.Controls.Remove(tb);
/*
Label lbl = new Label();
lbl.Text = tb.Text;
Font f = new Font(FontFamily.GenericMonospace, 8);
lbl.Font = f;
lbl.AutoSize = true;
Pen p = new Pen(Color.Black);
this.Controls.Add(lbl);
lbl.BorderStyle = BorderStyle.None;
lbl.Top = e.Y + lbl.Height / 2;
lbl.Left = e.X + lbl.Width / 2;
*/
//g.DrawString(n.ToString(), new Font("Arial", 10), new SolidBrush(Color.Black), new PointF(x, y));
Node n = new Node(int.Parse(tb.Text), e.X, e.Y);
Point pp = new Point(e.X, e.Y, int.Parse(tb.Text));
Status.myPoints.Add(pp);
points.Add(pp);
Status.tp.RefreshRoutesAndPoints();
newPointBlock = false;
};
this.Controls.Add(addBtn);
}
#endregion
}
if (Status.mode == Misc.Mode.Select)
{
#region Select
Point p;
if ((Control.ModifierKeys & Keys.Control) != 0) multiSelect = true; else { multiSelect = false; foreach (Point pnt in points) pnt.selected = false;}
if ((p = FindNear(e.X, e.Y, 10)) != null)
{
selectedPoint = p;
p.selected = true;
}
Redraw(true);
#endregion
}
}
private void GraphCreator_MouseMove(object sender, MouseEventArgs e)
{
if (movePoint)
{
selectedPoint.X = e.X;
selectedPoint.Y = e.Y;
Console.WriteLine(selectedPoint);
//OnPaint(new PaintEventArgs(this.CreateGraphics(),new Rectangle(this.Left,this.Top, this.Width, this.Height)));
Invalidate();
}
}
private void GraphCreator_MouseUp(object sender, MouseEventArgs e)
{
if (drawLine) {
Point p = FindNear(e.X,e.Y,10);
if (p!=null) {
f = p;
drawLine = false;
//state = GState.RouteDraw;
if (Status.DEBUG) MessageBox.Show("("+x1+","+y1+") -> ("+p.X+","+p.Y+")");
//DrawNodes(true);
tempedges.Add(new Edge(s, p, 0, 0));
g.DrawLine(new Pen(Color.Black), x1, y1, p.X, p.Y);
lpn = p.N;
crs +=" "+ p.N;
}
}
if (movePoint) {
movePoint = false;
Console.WriteLine("movePoint false");
}
}
private void GraphCreator_MouseDown(object sender, MouseEventArgs e)
{
if (Status.mode == Misc.Mode.Line)
{
Point p = FindNear(e.X, e.Y, 10);
if (p != null && (p.N == lpn || lpn == -1))
{
drawLine = true;
GState prevstate = state;
state = GState.RouteDraw;
s = p;
x1 = p.X;
y1 = p.Y;
if (crs == "") { crs += "" + p.N; }
}
}
if (Status.mode == Misc.Mode.Select)
{
Point p = FindNear(e.X, e.Y, 10);
selectedPoint = p;
if (selectedPoint != null)
{
movePoint = true;
Console.WriteLine("movePoint true");
//MouseMove+=//OnPaint(new PaintEventArgs(this.CreateGraphics(),new Rectangle(this.Left,this.Top, this.Width, this.Height)));
}
}
}
private void GraphCreator_Paint(object sender, PaintEventArgs e)
{
//this.DrawAll();
Console.WriteLine("GraphCreator_Paint");
switch (state){
case GState.OnlyNodes:
{
Console.WriteLine("OnlyNodes");
DrawNodes(true);
break;
}
case GState.NodesAndRoutes:
{
try
{
Console.WriteLine("NodesAndRoutes");
DrawNodes(true);
edges.Clear();
DrawRoutes((Route[])activeroutes.ToArray(typeof(Route)));
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}
break;
}
case GState.RouteDraw:
{
Console.WriteLine("RouteDraw");
DrawNodes(true);
DrawTempEdges(tempedges);
break;
}
case GState.ResultPath:
{
DrawNodes(true);
foreach (object o in tempdiredges){
Edge ed = (Edge)o;
DrawDirectEdge(ed.P1, ed.P2, ed.c);
}
break;
}
case GState.SelectPoints:
{
DrawNodes(true);
//SelectPoint
break;
}
}
}
public void DrawExisting()
{
}
public enum GState
{
OnlyNodes,
NodesAndRoutes,
RouteDraw,
ResultPath,
SelectPoints
}
public GState state = GState.NodesAndRoutes;
/*
public State State
{
get
{
return state;
}
set
{
state = value;
ViewEventArgs vea = new ViewEventArgs();
vea.State = value;
if (value == GState.NodesAndRoutes)
{
OnViewEvent(vea);
}
}
}
*/
}
}