ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JDesigner/ufExportJ.pas
Revision: 1.1.1.1 (vendor branch)
Committed: Mon Dec 10 19:29:12 2001 UTC (14 years, 6 months ago) by hsauro
Branch: MAIN, hsauro
CVS Tags: V10, HEAD_NEW, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
no message

Line File contents
1 unit ufExportJ;
2
3 // Export network to a file. Format decided by user, currently supported:
4 // Jaranc, SBML, CellML
5
6 interface
7
8 uses
9 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
10 ExtCtrls, StdCtrls, uNetPanel, ClipBrd, ComCtrls, Buttons;
11
12 type
13 TfrmExportJarnac = class(TForm)
14 pnlBase: TPanel;
15 BtnClose: TButton;
16 PageControl: TPageControl;
17 tsJarnac: TTabSheet;
18 tsSBML: TTabSheet;
19 pnlMain: TPanel;
20 grpModule: TGroupBox;
21 Label1: TLabel;
22 Label3: TLabel;
23 EdtModuleName: TEdit;
24 rdoDefaultModel: TRadioButton;
25 rdoNamedModel: TRadioButton;
26 EdtModelName: TEdit;
27 EdtModuleTitle: TEdit;
28 grpSimple: TGroupBox;
29 Label2: TLabel;
30 rdoDefaultSimpl: TRadioButton;
31 rdoNamedSimple: TRadioButton;
32 EdtSimpleModelName: TEdit;
33 EdtSimpleTitle: TEdit;
34 rdoExportModule: TRadioButton;
35 rdoSimpleExport: TRadioButton;
36 mJCheck: TMemo;
37 Label4: TLabel;
38 Label5: TLabel;
39 mSCheck: TMemo;
40 Label6: TLabel;
41 cboSBMLVersion: TComboBox;
42 BtnCopySBMLToClipboard: TBitBtn;
43 BtnCopySBMLToFile: TBitBtn;
44 BtnLookAtSBML: TBitBtn;
45 BtnLookAtJarnacScript: TBitBtn;
46 BtnCopyJarnacToClipBoard: TBitBtn;
47 BtnCopyJarnacToFile: TBitBtn;
48 SaveToFileDialog: TSaveDialog;
49 Label8: TLabel;
50 edtSBMLName: TEdit;
51 procedure rdoSimpleExportClick(Sender: TObject);
52 procedure FormShow(Sender: TObject);
53 procedure FormCreate(Sender: TObject);
54 procedure tsSBMLShow(Sender: TObject);
55 procedure BtnLookAtSBMLClick(Sender: TObject);
56 procedure BtnCopySBMLToClipboardClick(Sender: TObject);
57 procedure BtnCopyJarnacToClipBoardClick(Sender: TObject);
58 procedure BtnCopySBMLToFileClick(Sender: TObject);
59 procedure BtnCopyJarnacToFileClick(Sender: TObject);
60 procedure BtnLookAtJarnacScriptClick(Sender: TObject);
61 procedure mSCheckKeyDown(Sender: TObject; var Key: Word;
62 Shift: TShiftState);
63 procedure mJCheckKeyDown(Sender: TObject; var Key: Word;
64 Shift: TShiftState);
65 private
66 { Private declarations }
67 procedure DisableGroupBox (grp : TGroupBox);
68 procedure EnableGroupBox (grp : TGroupBox);
69 public
70 { Public declarations }
71 ModuleName, ModelName, ModelTitle : string;
72 NetPanel : TNetPanel;
73 end;
74
75 var
76 frmExportJarnac: TfrmExportJarnac;
77
78 implementation
79
80 {$R *.DFM}
81
82
83 procedure TfrmExportJarnac.DisableGroupBox (grp : TGroupBox);
84 var i : integer;
85 begin
86 for i := 0 to grp.ControlCount - 1 do
87 grp.Controls[i].Enabled := False;
88 grp.Enabled := False;
89 end;
90
91
92 procedure TfrmExportJarnac.EnableGroupBox (grp : TGroupBox);
93 var i : integer;
94 begin
95 grp.Enabled := True;
96 for i := 0 to grp.ControlCount - 1 do
97 grp.Controls[i].Enabled := True;
98 end;
99
100
101 procedure TfrmExportJarnac.rdoSimpleExportClick(Sender: TObject);
102 begin
103 if rdoSimpleExport.Checked then
104 begin
105 DisableGroupBox (grpModule);
106 EnableGroupBox (grpSimple);
107 end
108 else
109 begin
110 DisableGroupBox (grpSimple);
111 EnableGroupBox (grpModule);
112 end;
113 end;
114
115 procedure TfrmExportJarnac.FormShow(Sender: TObject);
116 begin
117 rdoSimpleExportClick (Sender);
118 end;
119
120 procedure TfrmExportJarnac.FormCreate(Sender: TObject);
121 begin
122 // Initial values for Jarnac export
123 ModuleName := '';
124 ModelName := '';
125 ModelTitle := 'untitled';
126 end;
127
128 // When the user tabs to the SBML page, initialise the combo box entry
129 procedure TfrmExportJarnac.tsSBMLShow(Sender: TObject);
130 begin
131 cboSBMLVersion.ItemIndex := 0;
132 edtSBMLName.Text := ModelTitle;
133 end;
134
135
136 procedure TfrmExportJarnac.BtnLookAtSBMLClick(Sender: TObject);
137 var Buf : PChar;
138 begin
139 ModelTitle := edtSBMLName.Text;
140 NetPanel.Network.NetworkName := ModelTitle;
141 NetPanel.Network.GetSBML (Buf);
142
143 // Copy the buffer to the clipboard and to the memo component
144 ClipBoard.SetTextBuf (Buf);
145 mSCheck.Clear;
146 mSCheck.PasteFromClipboard;
147 mSCheck.SetFocus;
148 mSCheck.SelStart := 0;
149 // No need to free Buf coz' it's handled by GetSBML automatically
150 end;
151
152
153 procedure TfrmExportJarnac.BtnCopySBMLToClipboardClick(Sender: TObject);
154 var Buf : PChar;
155 begin
156 NetPanel.Network.GetSBML (Buf);
157 // Copy the buffer to the clipboard
158 ClipBoard.SetTextBuf (Buf);
159 end;
160
161
162 procedure TfrmExportJarnac.BtnCopyJarnacToClipBoardClick(Sender: TObject);
163 var f : TFileStream; m : TMemoryStream; Buf : PChar;
164 begin
165 if rdoSimpleExport.Checked then
166 begin
167 ModuleName := '';
168 if rdoNamedSimple.Checked then
169 ModelName := EdtSimpleModelName.Text
170 else ModelName := '';
171 ModelTitle := EdtSimpleTitle.Text;
172 end
173 else
174 begin
175 ModuleName := EdtModuleName.Text;
176 if rdoNamedModel.Checked then
177 ModelName := EdtModelName.Text
178 else ModelName := '';
179 ModelTitle := EdtModuleTitle.Text;
180 end;
181
182 f := TFileStream.Create ('tmp$$$.jan', fmCreate);
183 try
184 NetPanel.Network.GetJarnacScript (f, ModuleName, ModelName, ModelTitle);
185 finally
186 f.Free;
187 end;
188
189 // Prepare to copy the file to the clipboard
190 m := TMemoryStream.Create;
191 try
192 // Load the file into a memory stream then dump it to a PChar buffer
193 m.LoadFromFile ('tmp$$$.jan');
194 GetMem (Buf, m.Size+1);
195 m.Position := 0;
196 m.Read (Buf^, m.Size);
197 Buf[m.Size] := #0;
198 ClipBoard.SetTextBuf (Buf);
199 finally
200 m.Free;
201 FreeMem (Buf);
202 DeleteFile ('tmp$$$.jan');
203 end;
204 end;
205
206
207 procedure TfrmExportJarnac.BtnCopySBMLToFileClick(Sender: TObject);
208 var Buf : PChar; f : TFileStream; i : integer;
209 begin
210 NetPanel.Network.GetSBML (Buf);
211
212 SaveToFileDialog.DefaultExt := 'sbml';
213 SaveToFileDialog.Filter := 'SBML files (*.xml)|*.xml';
214 if SaveToFileDialog.Execute then
215 begin
216 f := TFileStream.Create (SaveToFileDialog.FileName, fmCreate);
217 try
218 //for i := 1 to length (Buf) do
219 // f.Write (Buf[i], 1);
220 f.Write (Buf^, Length (Buf));
221 finally
222 f.free;
223 end;
224 end;
225 end;
226
227
228 procedure TfrmExportJarnac.BtnCopyJarnacToFileClick(Sender: TObject);
229 var Buf : PChar; f : TFileStream;
230 begin
231 if rdoSimpleExport.Checked then
232 begin
233 ModuleName := '';
234 if rdoNamedSimple.Checked then
235 ModelName := EdtSimpleModelName.Text
236 else ModelName := '';
237 ModelTitle := EdtSimpleTitle.Text;
238 end
239 else
240 begin
241 ModuleName := EdtModuleName.Text;
242 if rdoNamedModel.Checked then
243 ModelName := EdtModelName.Text
244 else ModelName := '';
245 ModelTitle := EdtModuleTitle.Text;
246 end;
247
248 SaveToFileDialog.DefaultExt := 'jan';
249 SaveToFileDialog.Filter := 'Jarnac files (*.jan)|*.jan';
250
251 if SaveToFileDialog.Execute then
252 begin
253 f := TFileStream.Create ('tmp$$$.jan', fmCreate);
254 try
255 NetPanel.Network.GetJarnacScript (f, ModuleName, ModelName, ModelTitle);
256 finally
257 f.Free;
258 end;
259 end;
260 end;
261
262 procedure TfrmExportJarnac.BtnLookAtJarnacScriptClick(Sender: TObject);
263 var f : TFileStream; m : TMemoryStream; Buf : PChar;
264 begin
265 if rdoSimpleExport.Checked then
266 begin
267 ModuleName := '';
268 if rdoNamedSimple.Checked then
269 ModelName := EdtSimpleModelName.Text
270 else ModelName := '';
271 ModelTitle := EdtSimpleTitle.Text;
272 end
273 else
274 begin
275 ModuleName := EdtModuleName.Text;
276 if rdoNamedModel.Checked then
277 ModelName := EdtModelName.Text
278 else ModelName := '';
279 ModelTitle := EdtModuleTitle.Text;
280 end;
281
282 f := TFileStream.Create ('tmp$$$.jan', fmCreate);
283 try
284 NetPanel.Network.GetJarnacScript (f, ModuleName, ModelName, ModelTitle);
285 finally
286 f.Free;
287 end;
288
289 // Prepare to copy the file to the clipboard
290 m := TMemoryStream.Create;
291 try
292 // Load the file into a memory stream then dump it to a PChar buffer
293 m.LoadFromFile ('tmp$$$.jan');
294 GetMem (Buf, m.Size+1);
295 m.Position := 0;
296 m.Read (Buf^, m.Size);
297 Buf[m.Size] := #0;
298 ClipBoard.SetTextBuf (Buf);
299 mJCheck.Clear;
300 mJCheck.PasteFromClipboard;
301 mJCheck.SetFocus;
302 finally
303 m.Free;
304 FreeMem (Buf);
305 DeleteFile ('tmp$$$.jan');
306 end;
307 end;
308
309 procedure TfrmExportJarnac.mSCheckKeyDown(Sender: TObject; var Key: Word;
310 Shift: TShiftState);
311 begin
312 if (Key = Ord('C')) and (ssCtrl in Shift) then
313 mSCheck.CopyToClipboard;
314 end;
315
316 procedure TfrmExportJarnac.mJCheckKeyDown(Sender: TObject; var Key: Word;
317 Shift: TShiftState);
318 begin
319 if (Key = Ord('C')) and (ssCtrl in Shift) then
320 mJCheck.CopyToClipboard;
321 end;
322
323 end.