-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnit1.cpp
419 lines (340 loc) · 15.6 KB
/
Unit1.cpp
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CGAUGES"
#pragma link "CGRID"
#pragma link "Unit3"
#pragma resource "*.dfm"
int a;
TForm1 *Form1;
TStringList *dane = new TStringList;
TStringList *dane2= new TStringList;
TStringList *loco= new TStringList;
bool RouteOpen=0;
bool VehicleOpen=0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::ZaladujLinie1Click(TObject *Sender)
{
try
{ char myPath[_MAX_PATH+1];
GetModuleFileName(NULL,myPath,_MAX_PATH);
String path = AnsiString(myPath);
path = path.SubString(0,path.Length()-7)+"\\Routes\\";
OpenDialog1->InitialDir = path;
if(OpenDialog1->Execute())
{
OpenDialog1->Title = "ζdowanie linii kolejowej";
dane -> LoadFromFile(OpenDialog1->FileName);
if(RouteOpen==0)
{
Linia = new Route(dane);
RouteOpen=1;
}
else
{
Linia -> ~Route();
Linia = new Route(dane);
}
Form4->Caption=OpenDialog1->FileName;
if(Linia->ShowLength()==0){throw 20;}
Label33->Caption="Zaladowano linie o dlugosci "+CurrToStr(Linia->ShowLength())+" m.";
Form1->EdytujLinie1->Enabled="TRUE";
Form1->W1->Enabled="TRUE";
Form4->Wykres2=0;
profilstatyczny.erase(profilstatyczny.begin(),profilstatyczny.end());
jazda.erase(jazda.begin(),jazda.end());
}
}
catch(...)
{
Application->MessageBoxA("Nie udalo sie otworzyc pliku","B章d",MB_ICONWARNING);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EdytujLinie1Click(TObject *Sender)
{
if(Form2->Visible==0)
{
Form2->ListBox1->Clear();
for(int i=0; i<Linia->Size(); i++){
AnsiString s=Linia->ShowSection(i);
Form2->ListBox1->Items->Add(s);}
Form2->ListBox2->Clear();
for(int i=0; i<Linia->DescriptionCount(); i++){
AnsiString s=Linia->ShowDescribe(i);
Form2->ListBox2->Items->Add(s);}
if(Linia->DescriptionCount()==0){Form2->ListBox2->Items->Add(" ");}
Form2->Visible="TRUE";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::W1Click(TObject *Sender)
{
Form4->RouteLength=Linia->ShowLength();
Form4->Visible="TRUE";
Form4->SetWindowSize(Linia->TheHighestSpeed());
profilstatyczny=staticprofile(Linia,NULL);
Form4->SetScale(Linia->ShowLength());
Form4->RysujWykres(profilstatyczny,Form4->start,Form4->skala,0,Linia->TheHighestSpeed());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NowaLinia1Click(TObject *Sender)
{
if(RouteOpen==0)
{
Linia = new Route(dane,1);
RouteOpen=1;
}
else
{
Linia -> ~Route();
Linia = new Route(dane,1);
}
Form1->EdytujLinie1->Enabled="TRUE";
Form1->W1->Enabled="TRUE";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ZaladujPojazd1Click(TObject *Sender)
{
try
{
char myPath[_MAX_PATH+1];
GetModuleFileName(NULL,myPath,_MAX_PATH);
String path = AnsiString(myPath);
path = path.SubString(0,path.Length()-7)+"\\Vehicles\\";
OpenDialog2->InitialDir = path;
if(OpenDialog2->Execute())
{
if(VehicleOpen==1){
Pojazd -> ~Vehicle();
}
else {VehicleOpen=1;}
dane2 -> LoadFromFile(OpenDialog2->FileName);
Pojazd = new Vehicle(dane2);
Form1-> E1 -> Enabled = "TRUE";
Form1->Label1->Caption = "Za豉dowano pojazd z pliku: "+OpenDialog2->FileName;
VehicleOpen=1;
Edit2->Text = Pojazd ->ShowName();
Edit3->Text = Pojazd ->ShowLength();
Edit6->Text = Pojazd ->ShowWeight();
Edit10->Text = Pojazd ->ShowWheels();
Edit13->Text = CurrToStr(Pojazd -> Vmax());
Edit7->Text = "100";
GroupBox1->Enabled="TRUE";
StatusBar1->Panels->Items[0]->Text="Karta poci鉚u odblokowana";
Form4->Wykres2=0;
}
}
catch(...)
{
ShowMessage("Nie udalo sie otworzyc pliku");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::E1Click(TObject *Sender)
{
Form3->Show();
Form3->Edit1->Text = Pojazd->ShowName();
Form3->Edit2->Text = Pojazd->ShowWheels();
Form3->Edit3->Text = Pojazd->ShowWeight();
Form3->Edit4->Text = Pojazd->ShowLength();
for (int i=0; i<Pojazd->CharSize(); i++){ Form3->ListBox1->Items->Add(Pojazd->ShowChar(i,0));}
Form3->RysujWykres();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Nowy1Click(TObject *Sender)
{
GroupBox1->Enabled="TRUE";
StatusBar1->Panels->Items[0]->Text="Karta poci鉚u odblokowana";
if(VehicleOpen==1){
int msgboxID = Application->MessageBox("Czy chcesz utworzyc nowy pojazd trakcyjny?","UWAGA!",MB_YESNO | MB_ICONWARNING);
if(msgboxID == IDYES){
Pojazd -> ~Vehicle();
TStringList *empty = new TStringList;
Pojazd = new Vehicle(empty);
Form1-> E1 -> Enabled = "TRUE";
Form3-> Visible = "TRUE";
Form3-> RysujWykres();
Form1-> Label1 -> Caption ="Utworzono nowy pojazd trakcyjny";
}
}
else {
VehicleOpen=1;
TStringList *empty = new TStringList;
Pojazd = new Vehicle(empty);
Form1-> E1 -> Enabled = "TRUE";
Form3-> Visible = "TRUE";
Form3-> RysujWykres();
Form1-> Label1 -> Caption ="Utworzono nowy pojazd trakcyjny";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GroupBox1Click(TObject *Sender)
{
Edit2->Text = Pojazd -> ShowName();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
locomotives=1;
ComboBox1->Items->Add("1");
ComboBox1->Items->Add("2");
ComboBox1->Items->Add("3");
hamulce = new TStringList;
StatusBar1->Panels->Add();
StatusBar1->Panels->Items[0]->Text="Karta poci鉚u zablokowana";
StatusBar1->Panels->Items[0]->Alignment=2;
try {
hamulce->LoadFromFile("hamowanie.dat");
Hamulec = new Brake(hamulce);
}
catch(...){
Application->MessageBox("Brak pliku z krzywymi hamowania","BㄔD",MB_ICONERROR);
Application->Terminate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(Pojazd->ReadyToGo()==1){
try{
Pociag = new Train(Pojazd,locomotives,atoi(Edit11->Text.c_str()),atof(Edit8->Text.c_str()),atoi(Edit4->Text.c_str()),atoi(Edit7->Text.c_str()),atoi(Edit13->Text.c_str()));
Edit5->Text=CurrToStr(Pociag->TrainLength());
Edit9->Text=CurrToStr(Pociag->TrainWeight());
Edit12->Text=CurrToStr(Pociag->LWheels() + Pociag->CWheels() );
if(atoi(Edit7->Text.c_str())<30){ Application->MessageBoxA("Minimalny % masy hamuj鉍ej wynosi 30%","Masa hamuj鉍a",MB_ICONWARNING);}
else if(atoi(Edit13->Text.c_str())>Pojazd->Vmax()){ Application->MessageBoxA(("Maksymalna pr璠kosc pociagu wynosi "+CurrToStr(Pojazd->Vmax())+" km/h. \n Wpisz nizsza wartosc").c_str(),"Pr璠kosc",MB_ICONWARNING);}
else {
jazda = trainride(Pociag,Linia,Hamulec);
Form4->SetWindowSize(atoi(Form1->Edit13->Text.c_str()));
Form4->Label5->Caption = "Pocz靖ek wykresu: 0";
Form4->Label6->Caption = "Maksymalna pr璠kosc: "+ CurrToStr(Form1->Linia->Vmax(0,Pociag->TrainLength(),atoi(Form1->Edit13->Text.c_str())));
Form4->Show();
Form4->Refresh();
Form4->Wykres2=1;
Form4->SetScale(Linia->ShowLength());
Form4->start=0;
Form4->RysujWykres(profilstatyczny,Form4->start,Form4->skala,Pociag->TrainLength(),atoi(Form1->Edit13->Text.c_str()));
Form4->RysujWykres2(jazda,Form4->skala,Pociag->TrainMaxSpeed(),Form4->start);
Form4->TrainMaxSpeed=atoi(Form1->Edit13->Text.c_str());
Form4->RouteLength=Linia->ShowLength();
}
}
catch(...)
{
Application->MessageBoxA("Nieprawid這we dane wejsciowe","B章d procedury",MB_ICONERROR);
}
}
else { Application->MessageBoxA("Niekompletne dane pojazdu trakcynego","Pojazd trakcyjny",MB_ICONWARNING);}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
locomotives=atoi(ComboBox1->Text.c_str());
Form4->Wykres2=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Pociag = new Train(Pojazd,locomotives,atoi(Edit11->Text.c_str()),atof(Edit8->Text.c_str()),atoi(Edit4->Text.c_str()),atoi(Edit7->Text.c_str()),atoi(Edit13->Text.c_str()));
Edit5->Text=CurrToStr(Pociag->TrainLength());
Edit9->Text=CurrToStr(Pociag->TrainWeight());
Edit12->Text=CurrToStr(Pociag->LWheels() + Pociag->CWheels() );
if(atoi(Edit7->Text.c_str())<30){
Application->MessageBoxA("Minimalny % masy hamuj鉍ej wynosi 30%","Masa hamuj鉍a",MB_ICONWARNING);
}
else if(atoi(Edit13->Text.c_str())>Pojazd->Vmax()){
Application->MessageBoxA(("Maksymalna pr璠kosc pociagu wynosi "+CurrToStr(Pojazd->Vmax())+" km/h. \n Wpisz nizsza wartosc").c_str(),"Pr璠kosc",MB_ICONWARNING);
}
// Form4->Visible="TRUE";
Form4->Show();
Form4->RouteLength=Linia->ShowLength();
Form4->TrainLength=Pociag->TrainLength();
Form4->SetWindowSize(atoi(Form1->Edit13->Text.c_str()));
profilstatyczny=staticprofile(Linia,Pociag);
Form4->SetScale(Linia->ShowLength());
Form4->RysujWykres(profilstatyczny,Form4->start,Form4->skala,Pociag->TrainLength(),atoi(Form1->Edit13->Text.c_str()));
Form4->Label5->Caption = "Pocz靖ek wykresu: 0";
Form4->Label6->Caption = "Maksymalna pr璠kosc: "+ CurrToStr(Form1->Linia->Vmax(0,Pociag->TrainLength(),atoi(Form1->Edit13->Text.c_str())));
// Form4->Label7->Caption = "Nastepna predkosc (obnizenie): "+ CurrToStr(Form1->Linia->NextSpeed(0,Pociag->TrainLength(),atoi(Form1->Edit13->Text.c_str())));
// Form4->Label8->Caption = "Dystans do obnizenia predkosci: "+ CurrToStr(Form1->Linia->DistanceToSpeedChange(0,Pociag->TrainLength(),atoi(Form1->Edit13->Text.c_str())));
// Form4->Label9->Caption = "Droga hamowania: "+ CurrToStr(Form1->Hamulec->DistanceOfBraking(Form1->Linia->Vmax(0,Pociag->TrainLength(),atoi(Form1->Edit13->Text.c_str())),Form1->Linia->NextSpeed(0,Pociag->TrainLength(),atoi(Form1->Edit13->Text.c_str())),atoi(Edit7->Text.c_str())));
// Form4->Label10->Caption = "Najblizszy pkt hamowania: "+CurrToStr(Form1->Hamulec->BrakeLaunch(0,Form1->Linia,Form1->Pociag));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit13Change(TObject *Sender)
{
Form4->Wykres2=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit7Change(TObject *Sender)
{
Form4->Wykres2=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit4Change(TObject *Sender)
{
Form4->Wykres2=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit8Change(TObject *Sender)
{
Form4->Wykres2=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit11Change(TObject *Sender)
{
Form4->Wykres2=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Zakocz1Click(TObject *Sender)
{
int ID = Application->MessageBoxA("Czy chcesz zako鎍zyc program?","Koniec",MB_YESNO | MB_ICONQUESTION);
if(ID==IDYES){
Application->Terminate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Oprogramie2Click(TObject *Sender)
{
Form5->Visible="TRUE";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Zaadujodcinek1Click(TObject *Sender)
{
ZaladujLinie1Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Zaadujpojazd1Click(TObject *Sender)
{
ZaladujPojazd1Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(Form4->Wykres2==1){
//std::map<int,int> TimeTable = GetTimetable(jazda);
Rozklad = new TimeTable(jazda,Linia,*Pociag);
Form7->Show();
Form7->CreateTemplate(Rozklad);
Form7->ShowTimeTable(Rozklad,Form7->pt);
Form7->ComboBox2->Items->Add("Przyjazd");
Form7->ComboBox2->Items->Add("Odjazd");
Form7->ComboBox2->Enabled=0;
Form7->ComboBox1->ItemIndex=0;
Form7->ComboBox2->ItemIndex=1;
// ShowMessage("Rozmiar = "+CurrToStr(Rozklad.CountSection()));
}
else {
Application->MessageBoxA("Brak profilu dynamicznego","B章d",MB_ICONERROR);
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------