-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
264 lines (227 loc) · 7.44 KB
/
MainForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text; //нужно избавиться от длишних классов
using System.Threading;
using System.Windows.Forms;
using BitmapProcessing;
namespace VisualizationElementOfTurning
{
public partial class MainForm : Form
{
Tool tool = null;
Bitmap bitmap = null;
FastBitmap fast_bmp = null;
WorkPiece workPiece = null;
ReadWay readWay = null;
// MyWay way = null;
int width;
int height;
int toolWidth;
int toolHeight;
Thread t;
delegate void myDelegate();
myDelegate de;
myDelegate FTW;
public MainForm()
{
InitializeComponent();
// way = new FirstWay();
bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
fast_bmp = new FastBitmap(bitmap);
if(textBox1.Text.Contains("."))
{
width = (int)Convert.ToDouble(textBox1.Text);
}
else width = Convert.ToInt32(textBox1.Text);
if(textBox2.Text.Contains("."))
{
height = (int)Convert.ToDouble(textBox2.Text);
}
else height = Convert.ToInt32(textBox2.Text);
if(textBox3.Text.Contains("."))
{
toolWidth = (int) Convert.ToDouble(textBox3.Text);
}
else toolWidth = Convert.ToInt32(textBox3.Text);
if(textBox4.Text.Contains("."))
{
toolHeight = (int)Convert.ToDouble(textBox4.Text);
}
else toolHeight = Convert.ToInt32(textBox4.Text);
tool = new Scoring(toolWidth, toolHeight);
workPiece = new WorkPiece(width, height);
FTW = new myDelegate(Repaint);
DoubleBuffered = true;
}
private void pictureBox_Paint(object sender, PaintEventArgs e)
{
Graphics g_bmp = Graphics.FromImage(bitmap);
g_bmp.Clear(Color.White);
workPiece.PaintFigure(fast_bmp);
tool.PaintFigure(g_bmp);
e.Graphics.DrawImageUnscaled(bitmap, new Point(0, 0));
}
private void timer_Tick(object sender, EventArgs e)
{
if(!radioButton3.Checked )
{
if (openFileDialog1.FileName != null)
{
readWay.Moving(tool);
}
else
{
//way.Moving(tool);
}
}
FTW();
}
private void buttonStart_Click(object sender, EventArgs e)
{
if(timer1.Enabled)
{
timer1.Enabled = false;
button1.Text = "Stop";
}
else
{
if (!radioButton3.Checked && openFileDialog1.FileName != openFileDialog1.InitialDirectory)
{
readWay = new ReadWay(openFileDialog1.FileName);
readWay.ReadFile();
}
timer1.Enabled = true;
button1.Text = "Start";
}
}
private void buttonInit_Click(object sender, EventArgs e)
{
bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
fast_bmp = new FastBitmap(bitmap);
if (textBox1.Text.Contains(","))
{
width = (int)Convert.ToDouble(textBox1.Text);
}
else width = Convert.ToInt32(textBox1.Text);
if (textBox2.Text.Contains(","))
{
height = (int)Convert.ToDouble(textBox2.Text);
}
else height = Convert.ToInt32(textBox2.Text);
if (textBox3.Text.Contains(","))
{
toolWidth = (int)Convert.ToDouble(textBox3.Text);
}
else toolWidth = Convert.ToInt32(textBox3.Text);
if (textBox4.Text.Contains(","))
{
toolHeight = (int)Convert.ToDouble(textBox4.Text);
}
else toolHeight = Convert.ToInt32(textBox4.Text);
/*width = Convert.ToInt32(textBox1.Text);
height = Convert.ToInt32(textBox2.Text);
toolWidth = Convert.ToInt32(textBox3.Text);
toolHeight = Convert.ToInt32(textBox4.Text);*/
if(radioButton1.Checked == true)
{
tool = new Scoring(toolWidth, toolHeight);
}
else
{
tool = new Cutter(toolWidth, toolHeight);
}
workPiece = new WorkPiece(width, height);
pictureBox1.Invalidate();
}
private void buttonUp_MouseDown(object sender, MouseEventArgs e)
{
de = new myDelegate(GoUp);
ThreadStart del = new ThreadStart(de);
t = new Thread(del);
t.Start();
}
private void buttonUp_MouseUp(object sender, MouseEventArgs e)
{
t.Abort();
}
public void GoUp()
{
while(true)
{
tool.MoveUp();
FTW();
}
}
public void GoLeft()
{
while (true)
{
tool.MoveLeft();
FTW();
}
}
public void GoDown()
{
while (true)
{
tool.MoveDown();
FTW();
}
}
public void GoRight()
{
while (true)
{
tool.MoveRight();
FTW();
}
}
private void buttonLeft_MouseDown(object sender, MouseEventArgs e)
{
de = new myDelegate(GoLeft);
ThreadStart del = new ThreadStart(de);
t = new Thread(del);
t.Start();
}
private void buttonLeft_MouseUp(object sender, MouseEventArgs e)
{
t.Abort();
}
private void buttonDown_MouseDown(object sender, MouseEventArgs e)
{
de = new myDelegate(GoDown);
ThreadStart del = new ThreadStart(de);
t = new Thread(del);
t.Start();
}
private void buttonDown_MouseUp(object sender, MouseEventArgs e)
{
t.Abort();
}
private void buttonRight_MouseDown(object sender, MouseEventArgs e)
{
de = new myDelegate(GoRight);
ThreadStart del = new ThreadStart(de);
t = new Thread(del);
t.Start();
}
private void buttonRight_MouseUp(object sender, MouseEventArgs e)
{
t.Abort();
}
public void Repaint()
{
workPiece.Interaction(tool);
workPiece.Check();
pictureBox1.Invalidate();
}
private void opebFileDialog_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
}
}