UI.PAS 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. Uses Win2K2,CoolKey,Graph,ccontr,Core;
  2. TYPE
  3. EStatus = (ST_WAITING,ST_RUNNING,ST_FINISHED);
  4. const
  5. AStatus : array [EStatus] of string[15] = ('Waiting','Running', 'Finished');
  6. var
  7. TextOut : Text;
  8. RunNum : Integer;
  9. gCol : Integer;
  10. Parent : hWNd;
  11. Stat : EStatus;
  12. OCButtons : Array [1..2] of hWnd;
  13. Edits : array [1..9] of hWnd;
  14. Traces : array [0..5] of boolean;
  15. Checks : array [0..5] of hWnd;
  16. Plot : hWnd;
  17. Model : ^CModel;
  18. Buffer : PBuffer;
  19. Device : PDevice;
  20. Srcs1, Srcs2,Srcs3 : PSource;
  21. BegVal,
  22. LastVal : Real;
  23. Steps,CurStep : integer;
  24. BufferSize : integer;
  25. S1,S2,S3 : Real;
  26. Delta, DovInt : real;
  27. Function GetFloat(aH:hWND):real;
  28. var
  29. st : string;
  30. ret : real;
  31. i : integer;
  32. begin
  33. GetWindowText(AH,@st,255);
  34. Val(st,ret,i);
  35. GetFloat := ret;
  36. end;
  37. Procedure GetParams;
  38. var
  39. st : string[50];
  40. i : integer;
  41. v : real;
  42. begin
  43. BegVal := GetFloat(Edits[3]);
  44. LastVal := GetFloat(Edits[4]);
  45. DovInt := GetFloat(Edits[2]);
  46. Steps := Round(GetFloat(Edits[5]));
  47. BufferSize := Round(GetFloat(Edits[6]));
  48. S1 := Getfloat(Edits[7]);
  49. S2 := Getfloat(Edits[8]);
  50. S3 := Getfloat(Edits[9]);
  51. GetWindowText(Edits[1],@st,50);
  52. if st[ord(st[0])] = '%' then
  53. begin
  54. Val(copy(st,1,ord(st[0])-1),v,i);
  55. Delta := v/100.0;
  56. end
  57. else
  58. Val(st,Delta,i);
  59. end;
  60. Procedure InitModel;
  61. begin
  62. Delta := 0.1;
  63. DovInt := 1.64;
  64. BegVal := 1.0;
  65. LastVal := 4.0;
  66. Steps := 20;
  67. BufferSize := 5;
  68. S1 := 2.0;
  69. S2 := 1.0;
  70. S3 := 5.0;
  71. New(Buffer, Init(BufferSize));
  72. New(Device, Init(BegVal));
  73. New(Model, Init(3,Device,Buffer,Delta,DovInt));
  74. New(Srcs1,Init(0,S1));
  75. Model^.AddNewSource(Srcs1);
  76. New(Srcs2,Init(1,S2));
  77. Model^.AddNewSource(Srcs2);
  78. New(Srcs3,Init(2,S3));
  79. Model^.AddNewSource(Srcs3);
  80. end;
  81. Procedure StartModel;
  82. var
  83. XY : TRPoint;
  84. nm : string;
  85. i : UINT8;
  86. begin
  87. Buffer^.SetBufferSize(BufferSize);
  88. Device^.Lambda := BegVal;
  89. Model^.Delta := Delta;
  90. Model^.DovInt := DovInt;
  91. Srcs1^.Lambda := S1;
  92. Srcs2^.Lambda := S2;
  93. Srcs3^.Lambda := S3;
  94. { for i := 0 to 5 do
  95. Traces[i] := boolean(SendMessage(Checks[i],CB_GETCHECK,0,0));}
  96. XY.X:=0;
  97. XY.Y:=Steps;
  98. SendMessage(Plot,XP_DELALLPOINTS,0,0);
  99. SendMessage(Plot,XP_DELALLPOINTS,1,0);
  100. SendMessage(Plot,XP_DELALLPOINTS,2,0);
  101. SendMessage(Plot,XP_DELALLPOINTS,3,0);
  102. SendMessage(Plot,XP_DELALLPOINTS,4,0);
  103. SendMessage(Plot,XP_DELALLPOINTS,5,0);
  104. SendMessage(Plot,XP_SETXRANGE,0,UINT32(@XY));
  105. SendMessage(Plot,XP_SETXRANGE,1,UINT32(@XY));
  106. SendMessage(Plot,XP_SETXRANGE,2,UINT32(@XY));
  107. SendMessage(Plot,XP_SETXRANGE,3,UINT32(@XY));
  108. SendMessage(Plot,XP_SETXRANGE,4,UINT32(@XY));
  109. SendMessage(Plot,XP_SETXRANGE,5,UINT32(@XY));
  110. str(RunNum,nm);
  111. Inc(RunNum);
  112. nm := 'result.'+nm;
  113. Assign(TextOut,nm);
  114. Rewrite(TextOut);
  115. Model^.Start;
  116. CurStep := 0;
  117. end;
  118. Function WindowProc(ahWnd:HWND;aMsg,wParam,lParam:UINT32):UINT32;far;
  119. var
  120. ps : LPPAINTSTRUCT;
  121. XY,Max : TRPoint;
  122. i : UINT8;
  123. rt : RECT;
  124. begin
  125. case aMsg of
  126. WM_CREATE:
  127. begin
  128. OCButtons[1] := CreateWindow('OK','BUTTON',WS_CHILD,
  129. 66,350,50,30,ahWnd,NULL);
  130. PostMessage(OCButtons[1],CB_SETID,1,0);
  131. OCButtons[2] := CreateWindow('Cancel','BUTTON',WS_CHILD,
  132. 152,350,60,30,ahWnd,NULL);
  133. PostMessage(OCButtons[2],CB_SETID,2,0);
  134. CreateWindow('Veroyatn','LABEL',WS_CHILD,
  135. 10,10,140,15,ahWnd,NULL);
  136. Edits[1]:=CreateWindow('10%','EDIT',WS_CHILD,
  137. 150,10,140,15,ahWnd,NULL);
  138. CreateWindow('Dov. Int','LABEL',WS_CHILD,
  139. 10,30,140,15,ahWnd,NULL);
  140. Edits[2]:=CreateWindow('1.64','EDIT',WS_CHILD,
  141. 150,30,140,15,ahWnd,NULL);
  142. CreateWindow('Beg. Lam ist','LABEL',WS_CHILD,
  143. 10,50,140,15,ahWnd,NULL);
  144. Edits[3]:=CreateWindow('1.0','EDIT',WS_CHILD,
  145. 150,50,140,15,ahWnd,NULL);
  146. CreateWindow('End Lam ist','LABEL',WS_CHILD,
  147. 10,70,140,15,ahWnd,NULL);
  148. Edits[4]:=CreateWindow('4.0','EDIT',WS_CHILD,
  149. 150,70,140,15,ahWnd,NULL);
  150. CreateWindow('Steps','LABEL',WS_CHILD,
  151. 10,90,140,15,ahWnd,NULL);
  152. Edits[5]:=CreateWindow('20','EDIT',WS_CHILD,
  153. 150,90,140,15,ahWnd,NULL);
  154. CreateWindow('Buf size','LABEL',WS_CHILD,
  155. 10,110,140,15,ahWnd,NULL);
  156. Edits[6]:=CreateWindow('5','EDIT',WS_CHILD,
  157. 150,110,140,15,ahWnd,NULL);
  158. CreateWindow('Lambda 1','LABEL',WS_CHILD,
  159. 10,130,140,15,ahWnd,NULL);
  160. Edits[7]:=CreateWindow('2.0','EDIT',WS_CHILD,
  161. 150,130,140,15,ahWnd,NULL);
  162. CreateWindow('Lambda 2','LABEL',WS_CHILD,
  163. 10,150,140,15,ahWnd,NULL);
  164. Edits[8]:=CreateWindow('1.0','EDIT',WS_CHILD,
  165. 150,150,140,15,ahWnd,NULL);
  166. CreateWindow('Lambda 3','LABEL',WS_CHILD,
  167. 10,170,140,15,ahWnd,NULL);
  168. Edits[9]:=CreateWindow('5.0','EDIT',WS_CHILD,
  169. 150,170,140,15,ahWnd,NULL);
  170. Plot := CreateWindow('Test plot','XYPLOT',WS_CHILD,310,10,300,300,ahWnd,NULL);
  171. SendMessage(Plot,XP_SETPLOTCOUNT,6,0);
  172. SendMessage(Plot,XP_SETCOLOR,0,Red);
  173. SendMessage(Plot,XP_SETCOLOR,1,Green);
  174. SendMessage(Plot,XP_SETCOLOR,2,Blue);
  175. SendMessage(Plot,XP_SETCOLOR,3,Magenta);
  176. SendMessage(Plot,XP_SETCOLOR,4,Yellow);
  177. SendMessage(Plot,XP_SETCOLOR,5,White);
  178. XY.X:=0;
  179. XY.Y:=100;
  180. SendMessage(Plot,XP_SETYRANGE,0,UINT32(@XY));
  181. SendMessage(Plot,XP_SETYRANGE,1,UINT32(@XY));
  182. SendMessage(Plot,XP_SETYRANGE,2,UINT32(@XY));
  183. Checks[0] := CreateWindow('Ist1 Potk (Red)','CHECKBOX',WS_CHILD,
  184. 10,200,200,15,ahWnd,NULL);
  185. SendMessage(Checks[0],CB_SETCHECK,0,0);
  186. Checks[1] := CreateWindow('Ist2 Potk (Green)','CHECKBOX',WS_CHILD,
  187. 10,220,200,15,ahWnd,NULL);
  188. SendMessage(Checks[1],CB_SETCHECK,1,0);
  189. Checks[2] := CreateWindow('Ist3 Potk (Blue)','CHECKBOX',WS_CHILD,
  190. 10,240,200,15,ahWnd,NULL);
  191. SendMessage(Checks[2],CB_SETCHECK,0,0);
  192. Checks[3] := CreateWindow('Ist1 MatO (Magenta)','CHECKBOX',WS_CHILD,
  193. 10,260,200,15,ahWnd,NULL);
  194. SendMessage(Checks[3],CB_SETCHECK,0,0);
  195. Checks[4] := CreateWindow('Ist2 MatO (Yellow)','CHECKBOX',WS_CHILD,
  196. 10,280,200,15,ahWnd,NULL);
  197. SendMessage(Checks[4],CB_SETCHECK,1,0);
  198. Checks[5] := CreateWindow('Ist3 MatO (White)','CHECKBOX',WS_CHILD,
  199. 10,300,200,15,ahWnd,NULL);
  200. SendMessage(Checks[5],CB_SETCHECK,0,0);
  201. Randomize;
  202. Stat := ST_WAITING;
  203. for i := 0 to 5 do SendMessage(Checks[i],CB_SETID,i+100,0);
  204. { fillchar(Traces,sizeof(Traces),0);}
  205. InitModel;
  206. RunNum := 0;
  207. PostMessage(ahWnd,WM_PAINT,0,0);
  208. AddOnFrameMessage(ahWnd);
  209. end;
  210. WM_COMMAND:
  211. begin
  212. case wParam of
  213. 1: if (lParam = 0) and (Stat <> ST_RUNNING) then begin {OK button pressed}
  214. GetParams;
  215. StartModel;
  216. Stat := ST_RUNNING;
  217. PostMessage(ahWnd,WM_PAINT,0,0);
  218. end;
  219. 2: if lParam = 0 then
  220. begin
  221. if Stat = ST_RUNNING then
  222. begin
  223. Close(TextOut);
  224. Stat := ST_WAITING;
  225. PostMessage(ahWnd,WM_PAINT,0,0);
  226. end
  227. else
  228. PostMessage(ahWnd,WM_DESTROY,0,0);
  229. end;
  230. end;
  231. if (wParam >= 100) and (wParam <=105) and (lParam = 1) then
  232. begin
  233. SendMessage(Plot,WM_SETVISIBLE,i-100,SendMessage(Checks[i-100],CB_GETCHECK,0,0));
  234. end;
  235. end;
  236. WM_ONFRAME:
  237. begin
  238. if Stat = ST_RUNNING then
  239. begin
  240. if Not Model^.Step then
  241. begin
  242. XY.X := CurStep;
  243. if Traces[0] then begin
  244. XY.Y := 100*Srcs1^.RefusedReq/Srcs1^.TotalReq;
  245. SendMessage(Plot,XP_ADDPOINT,0,UINT32(@XY));
  246. end;
  247. if Traces[1] then begin
  248. XY.Y := 100*Srcs2^.RefusedReq/Srcs2^.TotalReq;
  249. SendMessage(Plot,XP_ADDPOINT,1,UINT32(@XY));
  250. end;
  251. if Traces[2] then begin
  252. XY.Y := 100*Srcs3^.RefusedReq/Srcs3^.TotalReq;
  253. SendMessage(Plot,XP_ADDPOINT,2,UINT32(@XY));
  254. end;
  255. if (Srcs1^.DoneReq <> 0) AND Traces[3] then
  256. begin
  257. XY.Y := Srcs1^.MatWait/Srcs1^.DoneReq;
  258. SendMessage(Plot,XP_ADDPOINT,3,UINT32(@XY));
  259. end;
  260. if (Srcs2^.DoneReq <> 0) AND Traces[4] then
  261. begin
  262. XY.Y := Srcs2^.MatWait/Srcs2^.DoneReq;
  263. SendMessage(Plot,XP_ADDPOINT,4,UINT32(@XY));
  264. end;
  265. if (Srcs3^.DoneReq <> 0) AND Traces[5] then
  266. begin
  267. XY.Y := Srcs3^.MatWait/Srcs3^.DoneReq;
  268. SendMessage(Plot,XP_ADDPOINT,5,UINT32(@XY));
  269. end;
  270. Max.X := 0;
  271. Max.Y := 0;
  272. for i := 3 to 5 do if Traces[i] then
  273. begin
  274. SendMessage(Plot,XP_GETYRANGE,i,UINT32(@XY));
  275. if XY.Y > Max.Y then Max.Y := XY.Y;
  276. end;
  277. for i := 3 to 5 do if Traces[i] then
  278. SendMessage(Plot,XP_SETYRANGE,i,UINT32(@Max));
  279. PostMessage(Plot,WM_PAINT,0,0);
  280. Model^.PrintValues(TextOut);
  281. inc(CurStep);
  282. Device^.Lambda := BegVal + (LAstVal-BegVal)/Steps*Curstep;
  283. if CurStep = Steps+1 then
  284. begin
  285. Stat := ST_FINISHED;
  286. Close(TextOut);
  287. PostMessage(ahWnd,WM_PAINT,0,0);
  288. end
  289. else
  290. Model^.Start;
  291. end
  292. end;
  293. end;
  294. WM_DESTROY:
  295. begin
  296. if Stat <> ST_WAITING then begin
  297. Dispose(Model,Done);
  298. Dispose(Buffer,Done);
  299. Dispose(Device,Done);
  300. end;
  301. DelOnFrameMessage(ahWnd);
  302. PostQuitMessage(ahwnd);
  303. end;
  304. WM_KEYDOWN:
  305. if wParam = ord(SC_ESCAPE) then PostMessage(ahWnd,WM_DESTROY,0,0);
  306. WM_PAINT:
  307. begin
  308. ps := BeginPaint(ahWNd);
  309. wSetColor(ps,GlobalPalette.WindowFontColor);
  310. wSetBgColor(ps,GlobalPalette.ThreeDColor1);
  311. wSetStyle(ps,SolidFill);
  312. wSetFontJustify(ps,CenterText,BottomText);
  313. GetClientRect(ahWnd,@rt);
  314. wBar(ps,0,rt.b.y - 20, rt.b.x,rt.b.y);
  315. wTextOut(ps,rt.b.x shr 1, rt.b.y-1, @AStatus[Stat]);
  316. EndPaint(ps);
  317. end;
  318. end;
  319. end;
  320. var
  321. bA : longint;
  322. begin
  323. ba := MemAvail;
  324. if InitWin2K2 = ERR_OK then
  325. if RegisterClass('MSMO',WindowProc) = ERR_OK then
  326. begin
  327. InitCommonControls;
  328. Parent:=CreateWindow('Configuration','MSMO',
  329. WS_TITLE OR WS_SIZEABLE OR WS_MINMAX,
  330. 10,10,620,420,
  331. NULL,NULL);
  332. MainRunLoop;
  333. end;
  334. DoneWin2K2;
  335. WriteLn(ba-MemAvail);
  336. end.