PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/NM0.2.8 - stations!/?????????_v.2/Mapform.pas

http://naftometrou.googlecode.com/
Pascal | 523 lines | 485 code | 26 blank | 12 comment | 41 complexity | 7d04998ccf803c3fd453d15743a398b6 MD5 | raw file
  1. unit Mapform;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, ExtCtrls, StdCtrls, Math, Bomj, Spin;
  6. type
  7. TTunnel = record
  8. length:Real;
  9. nakl:Real;
  10. rad:Real;
  11. ug:Real;
  12. beg:Integer;
  13. en:Integer;
  14. idst:Integer;
  15. pov:Boolean;
  16. id1:Integer;
  17. id2:Integer;
  18. end;
  19. Tpoint = record
  20. x:Real;
  21. y:Real;
  22. z:Real;
  23. n1:Integer;
  24. n2:Integer;
  25. p1:Integer;
  26. p2:Integer;
  27. idst:Integer;
  28. np1:integer;
  29. np2:integer;
  30. pp1:integer;
  31. pp2:integer;
  32. ncs:Integer;
  33. pcs:Integer;
  34. ug:Real;
  35. end;
  36. TForm1 = class(TForm)
  37. Panel1: TPanel;
  38. pbM: TPaintBox;
  39. btn1: TButton;
  40. edt1: TEdit;
  41. lbl1: TLabel;
  42. lbl2: TLabel;
  43. btn2: TButton;
  44. edt3: TEdit;
  45. lbl3: TLabel;
  46. edt4: TEdit;
  47. lbl4: TLabel;
  48. btn3: TButton;
  49. btn4: TButton;
  50. se1: TSpinEdit;
  51. Edit1: TEdit;
  52. lbl5: TLabel;
  53. lbl6: TLabel;
  54. edt2: TEdit;
  55. btn5: TButton;
  56. se2: TSpinEdit;
  57. btn6: TButton;
  58. lbl7: TLabel;
  59. rb1: TRadioButton;
  60. rb2: TRadioButton;
  61. procedure FormCreate(Sender: TObject);
  62. procedure btn1Click(Sender: TObject);
  63. procedure btn2Click(Sender: TObject);
  64. procedure pbMPaint(Sender: TObject);
  65. procedure FormDestroy(Sender: TObject);
  66. procedure btn3Click(Sender: TObject);
  67. procedure btn4Click(Sender: TObject);
  68. procedure rb2Click(Sender: TObject);
  69. procedure btn6Click(Sender: TObject);
  70. procedure rb1Click(Sender: TObject);
  71. procedure btn5Click(Sender: TObject);
  72. private
  73. public
  74. { Public declarations }
  75. end;
  76. var
  77. Form1: TForm1;
  78. point: array [0..1000] of TPoint;
  79. Tunnel: array [0..1000] of TTunnel;
  80. now, allp, allt: Integer;
  81. napr: Boolean;
  82. outputer:TBlackbox;
  83. //ugol: Real;
  84. implementation
  85. {$R *.dfm}
  86. procedure TForm1.FormCreate(Sender: TObject);
  87. begin
  88. point[0].x := 200;
  89. point[0].y := 300;
  90. point[0].z := 0;
  91. point[0].ug := 0;
  92. point[0].idst := 0;
  93. point[0].n1 := -1;
  94. point[0].n2 := -1;
  95. point[0].p1 := -1;
  96. point[0].p2 := -1;
  97. point[0].ncs := 0;
  98. point[0].pcs := 0;
  99. allp:=1;
  100. allt:=0;
  101. now:=0;
  102. napr:=true;
  103. //ugol:=0;
  104. outputer := TBlackbox.lego;
  105. end;
  106. procedure TForm1.btn1Click(Sender: TObject);
  107. var ugol, l, n:Real;
  108. id:Integer;
  109. begin
  110. if ((napr and (point[now].n1 <> -1) and (point[now].n2 <> -1)) or ((not napr) and (point[now].p1 <> -1) and (point[now].p2 <> -1))) then
  111. ShowMessage('?? ????????!')
  112. else
  113. if (StrToFloat(edt1.Text) = 0) then
  114. ShowMessage('??????? ????. ????!')
  115. else
  116. begin
  117. ugol := point[now].ug;
  118. Tunnel[allt].pov := False;
  119. l := StrToFloat(edt1.Text);
  120. n := StrToFloat(se1.Text)*0.001;
  121. id := StrToInt(Edit1.Text);
  122. Edit1.Text := '0';
  123. if napr then
  124. begin
  125. Tunnel[allt].beg := now;
  126. Tunnel[allt].en := allp;
  127. if (point[now].n1 = -1) then
  128. point[now].n1 := allt
  129. else
  130. point[now].n2 := allt;
  131. point[allp].p1 := allt;
  132. point[allp].p2 := -1;
  133. point[allp].n1 := -1;
  134. point[allp].n2 := -1;
  135. point[allp].x := point[now].x + l*cos(ugol);
  136. point[allp].y := point[now].y + l*sin(ugol);
  137. point[allp].z := Point[now].z + l*n;
  138. end
  139. else
  140. begin
  141. Tunnel[allt].beg := allp;
  142. Tunnel[allt].en := now;
  143. if (point[now].p1 = -1) then
  144. point[now].p1 := allt
  145. else
  146. point[now].p2 := allt;
  147. point[allp].n1 := allt;
  148. point[allp].n2 := -1;
  149. point[allp].p1 := -1;
  150. point[allp].p2 := -1;
  151. point[allp].x := point[now].x - l*cos(ugol);
  152. point[allp].y := point[now].y - l*sin(ugol);
  153. point[allp].z := Point[now].z - l*n;
  154. end;
  155. point[now].idst := id;
  156. point[allp].idst := id;
  157. Tunnel[allt].idst := id;
  158. point[allp].ug := ugol;
  159. point[allp].ncs := 0;
  160. point[allp].pcs := 0;
  161. Tunnel[allt].length := l;
  162. Tunnel[allt].nakl := n;
  163. now:=allp;
  164. Inc(allp);
  165. Inc(allt);
  166. pbM.Repaint;
  167. end;
  168. end;
  169. procedure TForm1.btn2Click(Sender: TObject);
  170. var ugol, r, n:Real;
  171. id:Integer;
  172. begin
  173. if ((napr and (point[now].n1 <> -1) and (point[now].n2 <> -1)) or ((not napr) and (point[now].p1 <> -1) and (point[now].p2 <> -1))) then
  174. ShowMessage('?? ????????!')
  175. else
  176. if (StrToFloat(edt4.text) * StrToFloat(edt3.text) = 0) then
  177. ShowMessage('??????? ????. ????!')
  178. else
  179. begin
  180. Tunnel[allt].pov := True;
  181. ugol := StrToFloat(edt4.text)*3.141592654/180;
  182. r := StrToFloat(edt3.text);
  183. n := StrToFloat(se1.Text)*0.001;
  184. id := StrToInt(Edit1.Text);
  185. Edit1.Text := '0';
  186. if napr then
  187. begin
  188. Tunnel[allt].beg := now;
  189. Tunnel[allt].en := allp;
  190. if (point[now].n1 = -1) then
  191. point[now].n1 := allt
  192. else
  193. point[now].n2 := allt;
  194. point[allp].p1 := allt;
  195. point[allp].p2 := -1;
  196. point[allp].n1 := -1;
  197. point[allp].n2 := -1;
  198. point[allp].ug := Point[now].ug + ugol;
  199. point[allp].x := Point[now].x - Sign(ugol)*r*sin(Point[now].ug) + Sign(ugol)*r*sin(Point[allp].ug);
  200. point[allp].y := Point[now].y + Sign(ugol)*r*cos(Point[now].ug) - Sign(ugol)*r*cos(Point[allp].ug);
  201. point[allp].z := point[now].z + r*abs(ugol)*n;
  202. end
  203. else
  204. begin
  205. Tunnel[allt].en := now;
  206. Tunnel[allt].beg := allp;
  207. if (point[now].p1 = -1) then
  208. point[now].p1 := allt
  209. else
  210. point[now].p2 := allt;
  211. point[allp].n1 := allt;
  212. point[allp].n2 := -1;
  213. point[allp].p1 := -1;
  214. point[allp].p2 := -1;
  215. point[allp].ug := Point[now].ug - ugol;
  216. point[allp].x := Point[now].x + Sign(ugol)*r*sin(Point[now].ug) - Sign(ugol)*r*sin(Point[allp].ug);
  217. point[allp].y := Point[now].y - Sign(ugol)*r*cos(Point[now].ug) + Sign(ugol)*r*cos(Point[allp].ug);
  218. point[allp].z := point[now].z - r*abs(ugol)*n;
  219. end;
  220. point[now].idst := id;
  221. point[allp].idst := id;
  222. point[allp].ncs := 0;
  223. point[allp].pcs := 0;
  224. Tunnel[allt].idst := id;
  225. Tunnel[allt].rad := r;
  226. Tunnel[allt].ug := ugol;
  227. Tunnel[allt].length := r*abs(ugol);
  228. Tunnel[allt].nakl := n;
  229. now:=allp;
  230. Inc(allp);
  231. Inc(allt);
  232. pbM.Repaint;
  233. end;
  234. end;
  235. procedure TForm1.pbMPaint(Sender: TObject);
  236. var i, b, e:Integer;
  237. var cx, cy, r:Real;
  238. begin
  239. for i:= 0 to allt - 1 do
  240. begin
  241. if Tunnel[i].idst = 0 then
  242. begin
  243. pbM.Canvas.Pen.Width := 1;
  244. pbM.Canvas.Pen.Color := $000000;
  245. end
  246. else
  247. begin
  248. pbM.Canvas.Pen.Width := 3;
  249. pbM.Canvas.Pen.Color := $ff0000;
  250. end;
  251. if Tunnel[i].pov then
  252. begin
  253. r := tunnel[i].rad;
  254. b := tunnel[i].beg;
  255. e := tunnel[i].en;
  256. cx := Point[b].x - Sign(tunnel[i].ug)*r*sin(Point[b].ug);
  257. cy := pbM.Height - Point[b].y - Sign(tunnel[i].ug)*r*cos(Point[b].ug);
  258. if (tunnel[i].ug > 0) then
  259. pbM.Canvas.Arc(Round(cx-r),Round(cy-r),Round(cx+r),Round(cy+r),Round(Point[b].x),pbM.Height - Round(Point[b].y),Round(Point[e].x), pbM.Height - Round(Point[e].y))
  260. else
  261. pbM.Canvas.Arc(Round(cx-r),Round(cy-r),Round(cx+r),Round(cy+r),Round(Point[e].x),pbM.Height - Round(Point[e].y),Round(Point[b].x), pbM.Height - Round(Point[b].y));
  262. end
  263. else
  264. begin
  265. pbM.Canvas.MoveTo(Round(point[tunnel[i].beg].x), pbM.Height - Round(point[tunnel[i].beg].y));
  266. pbM.Canvas.LineTo(Round(point[tunnel[i].en].x), pbM.Height - Round(point[tunnel[i].en].y));
  267. end;
  268. end;
  269. pbM.Canvas.Pen.Width := 5;
  270. pbM.Canvas.Pen.Color := $0066ff;
  271. for i:= 0 to allp - 1 do
  272. begin
  273. pbM.Canvas.TextOut(Round(point[i].x), pbM.Height - Round(Point[i].y) + 1, IntToStr(i));
  274. pbM.Canvas.MoveTo(Round(point[i].x), pbM.Height - Round(Point[i].y));
  275. pbM.Canvas.LineTo(Round(point[i].x), pbM.Height - Round(Point[i].y));
  276. end;
  277. pbM.Canvas.Pen.Width := 5;
  278. if napr then
  279. pbM.Canvas.Pen.Color := $ffff00
  280. else
  281. pbM.Canvas.Pen.Color := $0000ff;
  282. pbM.Canvas.MoveTo(Round(point[now].x), pbM.Height - Round(Point[now].y));
  283. pbM.Canvas.LineTo(Round(point[now].x), pbM.Height - Round(Point[now].y));
  284. pbM.Canvas.Pen.Width := 3;
  285. if napr then
  286. pbM.Canvas.LineTo(Round(point[now].x) + Round(15*cos(point[now].ug)), pbM.Height - Round(Point[now].y) - Round(15*sin(point[now].ug)))
  287. else
  288. pbM.Canvas.LineTo(Round(point[now].x) - Round(15*cos(point[now].ug)), pbM.Height - Round(Point[now].y) + Round(15*sin(point[now].ug)));
  289. end;
  290. procedure TForm1.FormDestroy(Sender: TObject);
  291. begin
  292. outputer.Lesha;
  293. end;
  294. procedure TForm1.btn3Click(Sender: TObject);
  295. var freeid, i, j, amount:integer;
  296. cx, cy:Real;
  297. begin
  298. amount := allp;
  299. for i := 0 to allt - 1 do
  300. begin
  301. Tunnel[i].id1 := amount;
  302. amount := amount + Round (tunnel [i].length - 1);
  303. Tunnel[i].id2 := amount - 1;
  304. end;
  305. for i := 0 to allp - 1 do
  306. begin
  307. if (point[i].n1 <> -1) then
  308. point [i].np1 := tunnel[point[i].n1].id1
  309. else
  310. point [i].np1 := -1;
  311. if (point[i].n2 <> -1) then
  312. point [i].np2 := tunnel[point[i].n2].id1
  313. else
  314. point [i].np2 := point [i].np1;
  315. if (point[i].p1 <> -1) then
  316. point [i].pp1 := tunnel[point[i].p1].id2
  317. else
  318. point [i].pp1 := -1;
  319. if (point[i].p2 <> -1) then
  320. point [i].pp2 := tunnel[point[i].p2].id2
  321. else
  322. point [i].pp2 := point [i].pp1;
  323. end;
  324. outputer.sri2('amount=' + IntToStr(amount));
  325. outputer.hurktfu;
  326. outputer.sri2('idtrain=1');
  327. outputer.hurktfu;
  328. outputer.sri2('scb=newtest.naftoscb');
  329. outputer.hurktfu;
  330. outputer.sri2('!');
  331. outputer.hurktfu;
  332. for i := 0 to allt - 1 do
  333. if Tunnel [i].pov then
  334. begin
  335. cx:=Point[tunnel[i].beg].x - Sign(tunnel[i].ug)*tunnel[i].rad*sin(Point[tunnel[i].beg].ug);
  336. cy:=Point[tunnel[i].beg].y + Sign(tunnel[i].ug)*tunnel[i].rad*cos(Point[tunnel[i].beg].ug);
  337. {point [Tunnel [i].beg].np1 := freeid;
  338. point [Tunnel [i].beg].np2 := freeid;}
  339. for j := 1 to round (tunnel [i].length - 1) do
  340. begin
  341. outputer.sri(IntToStr(tunnel[i].id1 + j - 1));
  342. outputer.sreal(
  343. cx + Sign(tunnel[i].ug)*tunnel[i].rad*sin(Point[tunnel[i].beg].ug + tunnel[i].ug*j/Round(tunnel[i].length))
  344. );
  345. outputer.sreal(
  346. cy - Sign(tunnel[i].ug)*tunnel[i].rad*cos(Point[tunnel[i].beg].ug + tunnel[i].ug*j/Round(tunnel[i].length))
  347. );
  348. Outputer.sreal(Point [tunnel [i].beg].z + j * tunnel[i].nakl);
  349. if (j = round (abs (tunnel [i].length) - 1)) then
  350. begin
  351. outputer.sri(IntToStr(tunnel [i].en));
  352. outputer.sri(IntToStr(tunnel [i].en));
  353. end
  354. else
  355. begin
  356. outputer.sri(IntToStr(tunnel[i].id1 + j));
  357. outputer.sri(IntToStr(tunnel[i].id1 + j));
  358. end;
  359. if (j = 1) then
  360. begin
  361. outputer.sri(IntToStr(tunnel [i].beg));
  362. outputer.sri(IntToStr(tunnel [i].beg));
  363. end
  364. else
  365. begin
  366. outputer.sri(IntToStr(tunnel[i].id1 + j - 2));
  367. outputer.sri(IntToStr(tunnel[i].id1 + j - 2));
  368. end;
  369. if (j <= point[Tunnel[i].beg].ncs) then
  370. begin
  371. if (point[Tunnel[i].beg].n1 = i) then
  372. outputer.sri(IntToStr(point[Tunnel[i].beg].np2 + j - 1))
  373. else
  374. outputer.sri(IntToStr(point[Tunnel[i].beg].np1 + j - 1));
  375. end
  376. else
  377. if (j >= round (tunnel [i].length) - point[Tunnel[i].en].pcs) then
  378. begin
  379. if (point[Tunnel[i].en].p1 = i) then
  380. outputer.sri(IntToStr(point[Tunnel[i].beg].pp2 - (round (tunnel [i].length) - j) + 1))
  381. else
  382. outputer.sri(IntToStr(point[Tunnel[i].beg].pp1 - (round (tunnel [i].length) - j) + 1));
  383. end
  384. else
  385. outputer.sri(IntToStr(tunnel[i].id1 + j - 1));
  386. Outputer.sri(IntToStr(tunnel[i].idst));
  387. Outputer.sri('0');
  388. outputer.hurktfu;
  389. end;
  390. {point [Tunnel [i].en].pp1 := freeid - 1;
  391. point [Tunnel [i].en].pp2 := freeid - 1;}
  392. end
  393. else
  394. begin
  395. {point [Tunnel [i].beg].np1 := freeid;
  396. point [Tunnel [i].beg].np2 := freeid;}
  397. for j := 1 to round (tunnel [i].length - 1) do
  398. begin
  399. outputer.sri(IntToStr(tunnel[i].id1 + j - 1));
  400. outputer.sreal(
  401. (Point [tunnel [i].beg].x * (round (tunnel [i].length) - j) + Point [tunnel [i].en].x * j) / round (tunnel [i].length)
  402. );
  403. outputer.sreal(
  404. (Point [tunnel [i].beg].y * (round (tunnel [i].length) - j) + Point [tunnel [i].en].y * j) / round (tunnel [i].length)
  405. );
  406. Outputer.sreal(Point [tunnel [i].beg].z + j * tunnel[i].nakl);
  407. if (j = round (tunnel [i].length - 1)) then
  408. begin
  409. outputer.sri(IntToStr(tunnel [i].en));
  410. outputer.sri(IntToStr(tunnel [i].en));
  411. end
  412. else
  413. begin
  414. outputer.sri(IntToStr(tunnel[i].id1 + j));
  415. outputer.sri(IntToStr(tunnel[i].id1 + j));
  416. end;
  417. if (j = 1) then
  418. begin
  419. outputer.sri(IntToStr(tunnel [i].beg));
  420. outputer.sri(IntToStr(tunnel [i].beg));
  421. end
  422. else
  423. begin
  424. outputer.sri(IntToStr(tunnel[i].id1 + j - 2));
  425. outputer.sri(IntToStr(tunnel[i].id1 + j - 2));
  426. end;
  427. if (j <= point[Tunnel[i].beg].ncs) then
  428. begin
  429. if (point[Tunnel[i].beg].n1 = i) then
  430. outputer.sri(IntToStr(point[Tunnel[i].beg].np2 + j - 1))
  431. else
  432. outputer.sri(IntToStr(point[Tunnel[i].beg].np1 + j - 1));
  433. end
  434. else
  435. if (j >= round (tunnel [i].length) - point[Tunnel[i].en].pcs) then
  436. begin
  437. if (point[Tunnel[i].en].p1 = i) then
  438. outputer.sri(IntToStr(point[Tunnel[i].beg].pp2 - (round (tunnel [i].length) - j) + 1))
  439. else
  440. outputer.sri(IntToStr(point[Tunnel[i].beg].pp1 - (round (tunnel [i].length) - j) + 1));
  441. end
  442. else
  443. outputer.sri(IntToStr(tunnel[i].id1 + j - 1));
  444. Outputer.sri(IntToStr(tunnel[i].idst));
  445. Outputer.sri('0');
  446. outputer.hurktfu;
  447. end;
  448. {point [Tunnel [i].en].pp1 := freeid - 1;
  449. point [Tunnel [i].en].pp2 := freeid - 1;}
  450. end;
  451. for i := 0 to allp - 1 do
  452. begin
  453. outputer.sri(IntToStr(i));
  454. outputer.sreal(Point [i].x);
  455. outputer.sreal(Point [i].y);
  456. Outputer.sreal(Point [i].z);
  457. outputer.sri(IntToStr(point [i].np1));
  458. outputer.sri(IntToStr(point [i].np2));
  459. outputer.sri(IntToStr(point [i].pp1));
  460. outputer.sri(IntToStr(point [i].pp2));
  461. outputer.sri(IntToStr(i));
  462. Outputer.sri(IntToStr(point[i].idst));
  463. Outputer.sri('0');
  464. outputer.hurktfu;
  465. end;
  466. end;
  467. procedure TForm1.btn4Click(Sender: TObject);
  468. begin
  469. Dec(allt);
  470. Dec(allp);
  471. Dec(now);
  472. pbM.Repaint;
  473. end;
  474. procedure TForm1.rb2Click(Sender: TObject);
  475. begin
  476. napr := False;
  477. pbM.Repaint;
  478. end;
  479. procedure TForm1.btn6Click(Sender: TObject);
  480. begin
  481. now := se2.Value;
  482. pbM.Repaint;
  483. end;
  484. procedure TForm1.rb1Click(Sender: TObject);
  485. begin
  486. napr := True;
  487. pbM.Repaint;
  488. end;
  489. procedure TForm1.btn5Click(Sender: TObject);
  490. begin
  491. if napr then
  492. point[now].ncs := StrToInt(edt2.Text)
  493. else
  494. point[now].pcs := StrToInt(edt2.Text);
  495. pbM.Repaint;
  496. end;
  497. end.