MathgeomGLS
332 строки · 7.9 Кб
1unit fVolumeY;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11System.Math,
12Vcl.Clipbrd,
13Vcl.Graphics,
14Vcl.Controls,
15Vcl.Forms,
16Vcl.Dialogs,
17Vcl.Menus,
18Vcl.StdCtrls,
19Vcl.Buttons,
20Vcl.ComCtrls,
21Vcl.ExtCtrls;
22
23type
24TVolumeYForm = class(TForm)
25Label3: TLabel;
26Label4: TLabel;
27Label5: TLabel;
28Label6: TLabel;
29Label1: TLabel;
30Label2: TLabel;
31Label7: TLabel;
32Label8: TLabel;
33PositiveButton: TSpeedButton;
34NegativeButton: TSpeedButton;
35TotalVolumeLabel: TLabel;
36EditIntegMin: TEdit;
37EditIntegMax: TEdit;
38EditCount: TEdit;
39UpDown1: TUpDown;
40EditOpacity: TEdit;
41UpDown2: TUpDown;
42RecalcBtn: TBitBtn;
43CloseBtn: TBitBtn;
44KeepRangeCheckBox: TCheckBox;
45ColorDialog: TColorDialog;
46HideFunctionCheckBox: TCheckBox;
47PositivePanel: TPanel;
48NegativePanel: TPanel;
49SurfaceAreaLabel: TLabel;
50procedure FormShow(Sender: TObject);
51procedure FormActivate(Sender: TObject);
52procedure FormKeyPress(Sender: TObject; var Key: Char);
53procedure FormDeactivate(Sender: TObject);
54procedure ParseKeyPress(Sender: TObject; var Key: Char);
55procedure IntKeyPress(Sender: TObject; var Key: Char);
56procedure EditIntegMinKeyUp(Sender: TObject; var Key: Word;
57Shift: TShiftState);
58procedure EditIntegMaxKeyUp(Sender: TObject; var Key: Word;
59Shift: TShiftState);
60procedure EditCountKeyUp(Sender: TObject; var Key: Word;
61Shift: TShiftState);
62procedure EditOpacityKeyUp(Sender: TObject; var Key: Word;
63Shift: TShiftState);
64procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
65procedure UpDown2Click(Sender: TObject; Button: TUDBtnType);
66procedure UpDown1MouseUp(Sender: TObject; Button: TMouseButton;
67Shift: TShiftState; X, Y: Integer);
68procedure PositiveButtonClick(Sender: TObject);
69procedure NegativeButtonClick(Sender: TObject);
70procedure RecalcBtnClick(Sender: TObject);
71procedure IntegLabelClick(Sender: TObject);
72procedure KeepRangeCheckBoxClick(Sender: TObject);
73procedure CloseBtnClick(Sender: TObject);
74procedure HideFunctionCheckBoxClick(Sender: TObject);
75private
76procedure UpdateRangeData;
77public
78procedure ShowData;
79end;
80
81var
82VolumeYForm: TVolumeYForm;
83
84//=================================================================
85implementation
86//=================================================================
87
88uses
89uParser,
90uGlobal,
91fFuncts,
92fPlot1D;
93
94{$R *.dfm}
95
96procedure TVolumeYForm.FormShow(Sender: TObject);
97begin
98KeepRangeCheckBox.Checked := KeepRange;
99ShowData;
100end;
101
102procedure TVolumeYForm.HideFunctionCheckBoxClick(Sender: TObject);
103begin
104MainForm.GLViewer.Invalidate;
105end;
106
107procedure TVolumeYForm.FormActivate(Sender: TObject);
108begin
109EditIntegMin.SetFocus;
110EditIntegMin.SelText;
111end;
112
113procedure TVolumeYForm.FormKeyPress(Sender: TObject; var Key: Char);
114begin
115case Key of
116#13:begin
117RecalcBtnClick(Sender);
118Key := #0;
119end;
120#27:begin
121Key := #0;
122Close;
123end;
124end;
125end;
126
127procedure TVolumeYForm.FormDeactivate(Sender: TObject);
128begin
129if KeepRange then UpdateRangeData;
130end;
131
132procedure TVolumeYForm.ParseKeyPress(Sender: TObject; var Key: Char);
133begin
134with Sender as TEdit do
135begin
136if not CharInSet(UpCase(Key),
137[' ', '!', '(', ')', '*', '+', '-', '.', ',', '/', '0'..'9',
138'A'..'C', 'E', 'G'..'I', 'L', 'N'..'T', 'X', '^', '`', #8]) then
139begin
140Key := #0;
141Exit;
142end;
143if Key = '`' then Key := '�';
144end;
145end;
146
147procedure TVolumeYForm.RecalcBtnClick(Sender: TObject);
148begin
149MainForm.GLViewer.Invalidate;
150end;
151
152procedure TVolumeYForm.IntegLabelClick(Sender: TObject);
153begin
154Clipboard.Clear;
155with Sender as TLabel do
156Clipboard.AsText := Copy(Caption, pos('=', Caption)+2, Length(Caption));
157end;
158
159procedure TVolumeYForm.IntKeyPress(Sender: TObject; var Key: Char);
160begin
161with Sender as TEdit do
162if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
163end;
164
165procedure TVolumeYForm.KeepRangeCheckBoxClick(Sender: TObject);
166begin
167KeepRange := KeepRangeCheckBox.Checked;
168end;
169
170procedure TVolumeYForm.NegativeButtonClick(Sender: TObject);
171begin
172ColorDialog.Color := GraphData.NegAreaColor;
173if ColorDialog.Execute then
174begin
175GraphData.NegAreaColor := ColorDialog.Color;
176NegativePanel.Color := GraphData.NegAreaColor;
177MainForm.GLViewer.Invalidate;
178Altered := TRUE
179end;
180end;
181
182procedure TVolumeYForm.PositiveButtonClick(Sender: TObject);
183begin
184ColorDialog.Color := GraphData.PosAreaColor;
185if ColorDialog.Execute then
186begin
187GraphData.PosAreaColor := ColorDialog.Color;
188PositivePanel.Color := GraphData.PosAreaColor;
189MainForm.GLViewer.Invalidate;
190Altered := TRUE
191end;
192end;
193
194procedure TVolumeYForm.UpDown1Click(Sender: TObject; Button: TUDBtnType);
195var
196k: word;
197
198begin
199k := 0;
200EditCountKeyUp(Sender, k, []);
201end;
202
203procedure TVolumeYForm.UpDown1MouseUp(Sender: TObject; Button: TMouseButton;
204Shift: TShiftState; X, Y: Integer);
205begin
206RecalcBtnClick(Sender);
207end;
208
209procedure TVolumeYForm.UpDown2Click(Sender: TObject; Button: TUDBtnType);
210var
211k: word;
212
213begin
214k := 0;
215EditOpacityKeyUp(Sender, k, []);
216end;
217
218procedure TVolumeYForm.EditIntegMinKeyUp(Sender: TObject; var Key: Word;
219Shift: TShiftState);
220var
221s: string;
222e: byte;
223
224begin
225s := ScanText(EditIntegMin.Text);
226IntegMin := ParseAndEvaluate(s, e);
227//if isNAN(IntegMin) then IntegMin := 0;
228//if e > 0 then IntegMin := 0;
229if isNAN(IntegMin) or isInfinite(IntegMin) or (e > 0) then IntegMin := 0;
230end;
231
232procedure TVolumeYForm.EditIntegMaxKeyUp(Sender: TObject; var Key: Word;
233Shift: TShiftState);
234var
235s: string;
236e: byte;
237
238begin
239s := ScanText(EditIntegMax.Text);
240IntegMax := ParseAndEvaluate(s, e);
241//if isNAN(IntegMax) then IntegMax := 0;
242//if e > 0 then IntegMax := 0;
243if isNAN(IntegMax) or isInfinite(IntegMax) or (e > 0) then IntegMax := 0;
244end;
245
246procedure TVolumeYForm.CloseBtnClick(Sender: TObject);
247begin
248Close;
249end;
250
251procedure TVolumeYForm.EditCountKeyUp(Sender: TObject; var Key: Word;
252Shift: TShiftState);
253begin
254with GraphData do
255begin
256try
257IntegCount := StrToInt(EditCount.Text);
258if IntegCount = 0 then IntegCount := IntegCountPos;
259except
260IntegCount := IntegCountPos;
261end;
262if IntegCount > IntegCountMax then IntegCount := IntegCountMax;
263end;
264Altered := true;
265end;
266
267procedure TVolumeYForm.EditOpacityKeyUp(Sender: TObject; var Key: Word;
268Shift: TShiftState);
269var
270n: integer;
271
272begin
273try
274n := StrToInt(EditOpacity.Text);
275except
276n := 1;
277end;
278GraphData.AreaAlpha := n/100;
279Altered := true;
280MainForm.GLViewer.Invalidate;
281end;
282
283procedure TVolumeYForm.UpdateRangeData;
284begin
285KeptMin := IntegMin;
286KeptMax := IntegMax;
287end;
288
289procedure TVolumeYForm.ShowData;
290begin
291with GraphData, PlotData do
292begin
293EditCount.Text := IntToStr(IntegCount);
294UpDown2.Position := round(AreaAlpha*100);
295if TextStr = '' then Caption := '' else Caption := 'y = '+TextStr;
296
297KeepRangeCheckBox.Checked := KeepRange;
298PositivePanel.Color := PosAreaColor;
299NegativePanel.Color := NegAreaColor;
300
301if IsSegment then
302begin
303if KeepRange then
304begin
305IntegMin := KeptMin;
306IntegMax := KeptMax;
307end
308else
309begin
310IntegMin := SegMin;
311IntegMax := SegMax;
312end;
313end
314else
315begin
316if KeepRange then
317begin
318IntegMin := KeptMin;
319IntegMax := KeptMax;
320end
321else
322begin
323IntegMin := xMin;
324IntegMax := xMax;
325end;
326end;
327end;
328EditIntegMin.Text := FloatToStrF(IntegMin, ffGeneral, 13, 4);
329EditIntegMax.Text := FloatToStrF(IntegMax, ffGeneral, 13, 4);
330end;
331
332end.
333