-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolsPanel.cs
More file actions
268 lines (203 loc) · 7.53 KB
/
ToolsPanel.cs
File metadata and controls
268 lines (203 loc) · 7.53 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
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 ToolsPanel : UserControl
{
public ArrayList routes;// = Status.Routes;
ArrayList points;
//BindingSource bind = new BindingSource();
public GraphCreator graphcreator;
public ToolsPanel()
{
//graphcreator = g;
routes = Status.Routes;
points = Status.Points;
InitializeComponent();
routesListBox.DataSource = routes;
//routesListBox.DataSource = Status.myRoutes.routes;
//routesListBox.DisplayMember = "rs";
BindingContext bc1 = new BindingContext();
BindingContext bc2 = new BindingContext();
srcPoint.BindingContext = bc1;
srcPoint.DataSource = points;
destPoint.BindingContext = bc2;
destPoint.DataSource = points;
srcPoint.DisplayMember = "N";
destPoint.DisplayMember = "N";
}
private void pointBtn_Click(object sender, EventArgs e)
{
//gc.SetMode(Misc.Mode.Point);
Status.mode = Misc.Mode.Point;
}
public void RefreshRoutesAndPoints()
{
ListBox.SelectedIndexCollection selected = this.routesListBox.SelectedIndices;
this.BindingContext[routes].SuspendBinding();
this.BindingContext[routes].ResumeBinding();
this.BindingContext[points].SuspendBinding();
this.BindingContext[points].ResumeBinding();
srcPoint.BindingContext[points].SuspendBinding();
srcPoint.BindingContext[points].ResumeBinding();
destPoint.BindingContext[points].SuspendBinding();
destPoint.BindingContext[points].ResumeBinding();
for (int i = 0; i < routesListBox.Items.Count;i++ )
{
routesListBox.SetSelected(i, true);
}
}
private void ToolsPanel_Load(object sender, EventArgs e)
{
#if DEBUG
removeRouteBtn.Show();
selectAllRoutesBtn.Show();
#endif
}
private void routesListBox_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
Status.graphcreator.activeroutes.Clear();
ListBox.SelectedIndexCollection ic = routesListBox.SelectedIndices;
Status.graphcreator.Redraw(true);
//MessageBox.Show(n.ToString());
if (ic.Count > 0)
foreach (int i in ic)
{
if (i != -1) Status.graphcreator.DrawRoute((Route)routes[i], false);
Status.graphcreator.activeroutes.Add((Route)routes[i]);
}
}
catch (Exception ex){
Console.WriteLine(ex.Message);
}
}
private void routesListBox_SelectedValueChanged(object sender, EventArgs e)
{
}
private void srcPoint_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void destPoint_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void resultBtn_Click(object sender, EventArgs e)
{
try
{
Array a = routes.ToArray(typeof(Route));
graphcreator.tempdiredges.Clear();
Graph g = new Graph(points, a as Route[]);
string path;
resultLbl.Text = g.ShortestRoute(srcPoint.SelectedIndex, destPoint.SelectedIndex, out path).ToString();
Node c1 = null;
Node c2 = null;
//graphcreator.CreateGraphics().Clear(Color.White);
graphcreator.state = GraphCreator.GState.ResultPath;
graphcreator.Redraw(true);
graphcreator.DrawNodes(true);
while (g.nodestomove.Count >1)
{
/*
if (c != null)
{
graphcreator.DrawDirectEdge(c.point, ((Node)g.nodestomove.Peek()).point, ((Route)routes[((Node)g.nodestomove.Peek()).r]).color);
}
c = (Node)g.nodestomove.Dequeue();
*/
c1 = (Node)g.nodestomove.Dequeue();
c2 = (Node)g.nodestomove.Peek();
graphcreator.DrawDirectEdge(c1.point, c2.point, ((Route)routes[c1.r]).color);
graphcreator.tempdiredges.Add(new Edge(c1.point, c2.point, c1.r, 0, ((Route)routes[c1.r]).color));
}
MessageBox.Show(path);
//statusb
}
catch (Exception ex) { MessageBox.Show(ex.Message + "+" + ex.StackTrace); }
}
private void endRoute_Click(object sender, EventArgs e)
{
try
{
Route r = new Route(graphcreator.crs);
//routes.Add(r);
Status.Routes.Add(r);
Status.myRoutes.Add(r);
#if DEBUG
MessageBox.Show(graphcreator.crs);
#endif
graphcreator.ResetRouteInfo();
RefreshRoutesAndPoints();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public System.Windows.Forms.ListBox RoutesListBox{
get
{
return routesListBox;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void selectAllRoutesBtn_Click(object sender, EventArgs e)
{
for (int i = 0; i < routesListBox.Items.Count; i++)
{
routesListBox.SetSelected(i, true);
}
}
private void removeRouteBtn_Click(object sender, EventArgs e)
{
if (routesListBox.SelectedIndices.Count == 1){
Status.Routes[routesListBox.SelectedIndices[0]] = new Route("");
}
}
private void button1_Click(object sender, EventArgs e)
{
//Status.Routes;
}
private void lineBtn_Click(object sender, EventArgs e)
{
if (Status.mode != Misc.Mode.Line)
{
Status.mode = Misc.Mode.Line;
lineBtn.Image = Resource1.cross;
graphcreator.edges.Clear();
graphcreator.state = GraphCreator.GState.RouteDraw;
graphcreator.Invalidate();
}
else
{
endRoute_Click(sender, e);
lineBtn.Image = Resource1.layer_shape_polyline;
Status.mode = Misc.Mode.Select;
}
}
private void selectBtn_Click(object sender, EventArgs e)
{
Status.mode = Misc.Mode.Select;
}
private void pointBtn_Click_1(object sender, EventArgs e)
{
Status.mode = Misc.Mode.Point;
}
private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}