FmCUDAEditor.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //
  2. // The graphics engine GLScene
  3. //
  4. unit FmCUDAEditor;
  5. (* Editor of TGLCUDA *)
  6. interface
  7. {$I Stage.Defines.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. Stage.Strings,
  27. GLS.CUDA.APIComps,
  28. GLS.CUDA.FFTPlan,
  29. GLS.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. implementation //--------------------------------------------------------
  60. {$R *.dfm}
  61. const
  62. cRegistryKey = 'Software\GLScene\CUDAEditor';
  63. var
  64. vGLCUDAEditorForm: TGLCUDAEditorForm;
  65. function GLCUDAEditorForm: TGLCUDAEditorForm;
  66. begin
  67. if not Assigned(vGLCUDAEditorForm) then
  68. vGLCUDAEditorForm := TGLCUDAEditorForm.Create(nil);
  69. Result := vGLCUDAEditorForm;
  70. end;
  71. procedure ReleaseGLCUDAEditorForm;
  72. begin
  73. if Assigned(vGLCUDAEditorForm) then
  74. begin
  75. vGLCUDAEditorForm.Free;
  76. vGLCUDAEditorForm := nil;
  77. end;
  78. end;
  79. function ReadRegistryInteger(reg: TRegistry; const name: string;
  80. defaultValue: Integer): Integer;
  81. begin
  82. if reg.ValueExists(name) then
  83. Result := reg.ReadInteger(name)
  84. else
  85. Result := defaultValue;
  86. end;
  87. procedure TGLCUDAEditorForm.AddItemButtonClick(Sender: TObject);
  88. var
  89. LClass: TCUDAComponentClass;
  90. obj: TCUDAComponent;
  91. begin
  92. if Assigned(FCurrentDesigner) then
  93. begin
  94. LClass := TCUDAComponentClass(FClassList[TToolButton(Sender).Tag]);
  95. obj := TCUDAComponent(FCurrentDesigner.CreateComponent(LClass, FCUDA, 0, 0, 0, 0));
  96. obj.Master := FCUDA;
  97. ListBox1.AddItem(obj.Name, obj);
  98. FCurrentDesigner.Modified;
  99. end;
  100. end;
  101. procedure TGLCUDAEditorForm.DeleteButtonClick(Sender: TObject);
  102. var
  103. obj: TCUDAComponent;
  104. i: Integer;
  105. begin
  106. if ListBox1.SelCount = 0 then
  107. exit;
  108. for i := 0 to ListBox1.Count - 1 do
  109. begin
  110. if ListBox1.Selected[i] then
  111. begin
  112. obj := TCUDAComponent(ListBox1.Items.Objects[i]);
  113. obj.Destroy;
  114. end;
  115. end;
  116. ListBox1.DeleteSelected;
  117. FCurrentDesigner.Modified;
  118. end;
  119. procedure TGLCUDAEditorForm.FormCreate(Sender: TObject);
  120. var
  121. reg: TRegistry;
  122. begin
  123. RegisterCUDAComponentNameChangeEvent(OnCUDAComponentNameChanged);
  124. reg := TRegistry.Create;
  125. try
  126. if reg.OpenKey(cRegistryKey, True) then
  127. begin
  128. Left := ReadRegistryInteger(reg, 'Left', Left);
  129. Top := ReadRegistryInteger(reg, 'Top', Top);
  130. Width := ReadRegistryInteger(reg, 'Width', 250);
  131. Height := ReadRegistryInteger(reg, 'Height', Height);
  132. end;
  133. finally
  134. reg.Free;
  135. end;
  136. FClassList := TList.Create;
  137. AddModuleButton.Tag := FClassList.Add(TCUDAModule);
  138. AddMemDataButton.Tag := FClassList.Add(TCUDAMemData);
  139. AddFFTPlanButton.Tag := FClassList.Add(TCUDAFFTPlan);
  140. AddGeometryResButton.Tag := FClassList.Add(TCUDAGeometryResource);
  141. AddImageResButton.Tag := FClassList.Add(TCUDAImageResource);
  142. end;
  143. procedure TGLCUDAEditorForm.FormDestroy(Sender: TObject);
  144. var
  145. reg: TRegistry;
  146. begin
  147. DeRegisterCUDAComponentNameChangeEvent;
  148. FClassList.Destroy;
  149. reg := TRegistry.Create;
  150. try
  151. if reg.OpenKey(cRegistryKey, True) then
  152. begin
  153. reg.WriteInteger('Left', Left);
  154. reg.WriteInteger('Top', Top);
  155. reg.WriteInteger('Width', Width);
  156. reg.WriteInteger('Height', Height);
  157. end;
  158. finally
  159. reg.Free;
  160. end;
  161. end;
  162. procedure TGLCUDAEditorForm.ListBox1Click(Sender: TObject);
  163. var
  164. obj: TCUDAComponent;
  165. i: Integer;
  166. begin
  167. if not Assigned(FCurrentDesigner) then
  168. exit;
  169. obj := nil;
  170. if ListBox1.SelCount = 1 then
  171. for i := 0 to ListBox1.Count - 1 do
  172. begin
  173. if ListBox1.Selected[i] then
  174. begin
  175. obj := TCUDAComponent(ListBox1.Items.Objects[i]);
  176. break;
  177. end;
  178. end;
  179. if Assigned(obj) then
  180. FCurrentDesigner.SelectComponent(obj);
  181. end;
  182. procedure TGLCUDAEditorForm.SetCUDAEditorClient(Client: TGLCUDA; Designer: IDesigner);
  183. var
  184. i: Integer;
  185. child: TCUDAComponent;
  186. begin
  187. if Assigned(FCUDA) then
  188. FCUDA.RemoveFreeNotification(Self);
  189. FCUDA := Client;
  190. FCurrentDesigner := Designer;
  191. ListBox1.Clear;
  192. if Assigned(FCUDA) then
  193. begin
  194. FCUDA.FreeNotification(Self);
  195. Caption := strCUDAEditor + ' : ' + FCUDA.Name;
  196. for i := 0 to FCUDA.ItemsCount - 1 do
  197. begin
  198. child := FCUDA.Items[i];
  199. ListBox1.AddItem(child.Name, child);
  200. end;
  201. end
  202. else
  203. Caption := strCUDAEditor;
  204. end;
  205. procedure TGLCUDAEditorForm.Notification(AComponent: TComponent; Operation:
  206. TOperation);
  207. begin
  208. if (FCUDA = AComponent) and (Operation = opRemove) then
  209. begin
  210. FCUDA := nil;
  211. SetCUDAEditorClient(nil, nil);
  212. end;
  213. inherited;
  214. end;
  215. procedure TGLCUDAEditorForm.OnCUDAComponentNameChanged(Sender: TObject);
  216. var
  217. i: Integer;
  218. obj: TCUDAComponent;
  219. begin
  220. for i := 0 to ListBox1.Count - 1 do
  221. begin
  222. obj := TCUDAComponent(ListBox1.Items.Objects[i]);
  223. if Sender = obj then
  224. begin
  225. ListBox1.Items[I]:= obj.Name;
  226. break;
  227. end;
  228. end;
  229. end;
  230. //-----------------------------------------------
  231. initialization
  232. //-----------------------------------------------
  233. finalization
  234. ReleaseGLCUDAEditorForm;
  235. end.