CUDA.EditorFm.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. //
  2. // The graphics platform GLScene https://github.com/glscene
  3. //
  4. unit CUDA.EditorFm;
  5. (* Editor of TGLCUDA *)
  6. interface
  7. {$I GLScene.inc}
  8. uses
  9. Winapi.Windows,
  10. Winapi.Messages,
  11. System.SysUtils,
  12. System.Variants,
  13. System.Classes,
  14. System.Win.Registry,
  15. System.ImageList,
  16. Vcl.Graphics,
  17. Vcl.Controls,
  18. Vcl.Forms,
  19. Vcl.Dialogs,
  20. Vcl.ImgList,
  21. Vcl.StdCtrls,
  22. Vcl.ComCtrls,
  23. Vcl.ToolWin,
  24. DesignIntf,
  25. VCLEditors,
  26. GLS.Strings,
  27. CUDA.APIComps,
  28. CUDA.FFTPlan,
  29. CUDA.Graphics;
  30. type
  31. TGLCUDAEditorForm = class(TForm)
  32. ToolBar1: TToolBar;
  33. AddModuleButton: TToolButton;
  34. DeleteButton: TToolButton;
  35. ListBox1: TListBox;
  36. ImageList1: TImageList;
  37. AddMemDataButton: TToolButton;
  38. AddFFTPlanButton: TToolButton;
  39. AddGeometryResButton: TToolButton;
  40. AddImageResButton: TToolButton;
  41. procedure AddItemButtonClick(Sender: TObject);
  42. procedure DeleteButtonClick(Sender: TObject);
  43. procedure FormCreate(Sender: TObject);
  44. procedure ListBox1Click(Sender: TObject);
  45. procedure FormDestroy(Sender: TObject);
  46. private
  47. FClassList: TList;
  48. FCUDA: TGLCUDA;
  49. FCurrentDesigner: IDesigner;
  50. protected
  51. procedure Notification(AComponent: TComponent; Operation: TOperation);
  52. override;
  53. procedure OnCUDAComponentNameChanged(Sender : TObject);
  54. public
  55. procedure SetCUDAEditorClient(Client: TGLCUDA; Designer: IDesigner);
  56. end;
  57. function GLCUDAEditorForm: TGLCUDAEditorForm;
  58. procedure ReleaseGLCUDAEditorForm;
  59. //--------------------------------------------------------
  60. implementation
  61. //--------------------------------------------------------
  62. {$R *.dfm}
  63. const
  64. cRegistryKey = 'Software\GLScene\CUDAEditor';
  65. var
  66. vGLCUDAEditorForm: TGLCUDAEditorForm;
  67. function GLCUDAEditorForm: TGLCUDAEditorForm;
  68. begin
  69. if not Assigned(vGLCUDAEditorForm) then
  70. vGLCUDAEditorForm := TGLCUDAEditorForm.Create(nil);
  71. Result := vGLCUDAEditorForm;
  72. end;
  73. procedure ReleaseGLCUDAEditorForm;
  74. begin
  75. if Assigned(vGLCUDAEditorForm) then
  76. begin
  77. vGLCUDAEditorForm.Free;
  78. vGLCUDAEditorForm := nil;
  79. end;
  80. end;
  81. function ReadRegistryInteger(reg: TRegistry; const name: string;
  82. defaultValue: Integer): Integer;
  83. begin
  84. if reg.ValueExists(name) then
  85. Result := reg.ReadInteger(name)
  86. else
  87. Result := defaultValue;
  88. end;
  89. procedure TGLCUDAEditorForm.AddItemButtonClick(Sender: TObject);
  90. var
  91. LClass: TCUDAComponentClass;
  92. obj: TCUDAComponent;
  93. begin
  94. if Assigned(FCurrentDesigner) then
  95. begin
  96. LClass := TCUDAComponentClass(FClassList[TToolButton(Sender).Tag]);
  97. obj := TCUDAComponent(FCurrentDesigner.CreateComponent(LClass, FCUDA, 0, 0, 0, 0));
  98. obj.Master := FCUDA;
  99. ListBox1.AddItem(obj.Name, obj);
  100. FCurrentDesigner.Modified;
  101. end;
  102. end;
  103. procedure TGLCUDAEditorForm.DeleteButtonClick(Sender: TObject);
  104. var
  105. obj: TCUDAComponent;
  106. i: Integer;
  107. begin
  108. if ListBox1.SelCount = 0 then
  109. exit;
  110. for i := 0 to ListBox1.Count - 1 do
  111. begin
  112. if ListBox1.Selected[i] then
  113. begin
  114. obj := TCUDAComponent(ListBox1.Items.Objects[i]);
  115. obj.Destroy;
  116. end;
  117. end;
  118. ListBox1.DeleteSelected;
  119. FCurrentDesigner.Modified;
  120. end;
  121. procedure TGLCUDAEditorForm.FormCreate(Sender: TObject);
  122. var
  123. reg: TRegistry;
  124. begin
  125. RegisterCUDAComponentNameChangeEvent(OnCUDAComponentNameChanged);
  126. reg := TRegistry.Create;
  127. try
  128. if reg.OpenKey(cRegistryKey, True) then
  129. begin
  130. Left := ReadRegistryInteger(reg, 'Left', Left);
  131. Top := ReadRegistryInteger(reg, 'Top', Top);
  132. Width := ReadRegistryInteger(reg, 'Width', 250);
  133. Height := ReadRegistryInteger(reg, 'Height', Height);
  134. end;
  135. finally
  136. reg.Free;
  137. end;
  138. FClassList := TList.Create;
  139. AddModuleButton.Tag := FClassList.Add(TCUDAModule);
  140. AddMemDataButton.Tag := FClassList.Add(TCUDAMemData);
  141. AddFFTPlanButton.Tag := FClassList.Add(TCUDAFFTPlan);
  142. AddGeometryResButton.Tag := FClassList.Add(TCUDAGeometryResource);
  143. AddImageResButton.Tag := FClassList.Add(TCUDAImageResource);
  144. end;
  145. procedure TGLCUDAEditorForm.FormDestroy(Sender: TObject);
  146. var
  147. reg: TRegistry;
  148. begin
  149. DeRegisterCUDAComponentNameChangeEvent;
  150. FClassList.Destroy;
  151. reg := TRegistry.Create;
  152. try
  153. if reg.OpenKey(cRegistryKey, True) then
  154. begin
  155. reg.WriteInteger('Left', Left);
  156. reg.WriteInteger('Top', Top);
  157. reg.WriteInteger('Width', Width);
  158. reg.WriteInteger('Height', Height);
  159. end;
  160. finally
  161. reg.Free;
  162. end;
  163. end;
  164. procedure TGLCUDAEditorForm.ListBox1Click(Sender: TObject);
  165. var
  166. obj: TCUDAComponent;
  167. i: Integer;
  168. begin
  169. if not Assigned(FCurrentDesigner) then
  170. exit;
  171. obj := nil;
  172. if ListBox1.SelCount = 1 then
  173. for i := 0 to ListBox1.Count - 1 do
  174. begin
  175. if ListBox1.Selected[i] then
  176. begin
  177. obj := TCUDAComponent(ListBox1.Items.Objects[i]);
  178. break;
  179. end;
  180. end;
  181. if Assigned(obj) then
  182. FCurrentDesigner.SelectComponent(obj);
  183. end;
  184. procedure TGLCUDAEditorForm.SetCUDAEditorClient(Client: TGLCUDA; Designer: IDesigner);
  185. var
  186. i: Integer;
  187. child: TCUDAComponent;
  188. begin
  189. if Assigned(FCUDA) then
  190. FCUDA.RemoveFreeNotification(Self);
  191. FCUDA := Client;
  192. FCurrentDesigner := Designer;
  193. ListBox1.Clear;
  194. if Assigned(FCUDA) then
  195. begin
  196. FCUDA.FreeNotification(Self);
  197. Caption := strCUDAEditor + ' : ' + FCUDA.Name;
  198. for i := 0 to FCUDA.ItemsCount - 1 do
  199. begin
  200. child := FCUDA.Items[i];
  201. ListBox1.AddItem(child.Name, child);
  202. end;
  203. end
  204. else
  205. Caption := strCUDAEditor;
  206. end;
  207. procedure TGLCUDAEditorForm.Notification(AComponent: TComponent; Operation:
  208. TOperation);
  209. begin
  210. if (FCUDA = AComponent) and (Operation = opRemove) then
  211. begin
  212. FCUDA := nil;
  213. SetCUDAEditorClient(nil, nil);
  214. end;
  215. inherited;
  216. end;
  217. procedure TGLCUDAEditorForm.OnCUDAComponentNameChanged(Sender: TObject);
  218. var
  219. i: Integer;
  220. obj: TCUDAComponent;
  221. begin
  222. for i := 0 to ListBox1.Count - 1 do
  223. begin
  224. obj := TCUDAComponent(ListBox1.Items.Objects[i]);
  225. if Sender = obj then
  226. begin
  227. ListBox1.Items[I]:= obj.Name;
  228. break;
  229. end;
  230. end;
  231. end;
  232. //-----------------------------------------------
  233. initialization
  234. //-----------------------------------------------
  235. finalization
  236. ReleaseGLCUDAEditorForm;
  237. end.