MathgeomGLS
461 строка · 11.7 Кб
1unit faIntegrateX;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11System.Math,
12Vcl.Graphics,
13Vcl.Controls,
14Vcl.Forms,
15Vcl.Dialogs,
16Vcl.StdCtrls,
17Vcl.Buttons,
18Vcl.ComCtrls,
19Vcl.Menus,
20Vcl.ExtCtrls;
21
22type
23TIntegrateXForm = class(TForm)
24Label3: TLabel;
25Label1: TLabel;
26Label4: TLabel;
27MinIntegXLabel: TLabel;
28Label6: TLabel;
29ColorButton: TSpeedButton;
30Label5: TLabel;
31AreaLabel: TLabel;
32Label7: TLabel;
33PositiveButton: TSpeedButton;
34NegativeButton: TSpeedButton;
35MaxIntegXLabel: TLabel;
36NegAreaLabel: TLabel;
37PosAreaLabel: TLabel;
38MinIntegYLabel: TLabel;
39MaxIntegYLabel: TLabel;
40TotalAreaLabel: TLabel;
41CentreButton: TSpeedButton;
42EditIntegMin: TEdit;
43EditIntegMax: TEdit;
44EditCount: TEdit;
45UpDown1: TUpDown;
46RecalcBtn: TBitBtn;
47CloseBtn: TBitBtn;
48EditPenWidth: TEdit;
49UpDown2: TUpDown;
50EditConst: TEdit;
51IntegCheckBox: TCheckBox;
52ShadeCheckBox: TCheckBox;
53EditOpacity: TEdit;
54UpDown3: TUpDown;
55ColorDialog: TColorDialog;
56Label2: TLabel;
57KeepRangeCheckBox: TCheckBox;
58ColorPanel: TPanel;
59NegativePanel: TPanel;
60PositivePanel: TPanel;
61SumAreaLabel: TLabel;
62procedure FormShow(Sender: TObject);
63procedure FormActivate(Sender: TObject);
64procedure FormKeyPress(Sender: TObject; var Key: Char);
65procedure FormDeactivate(Sender: TObject);
66
67procedure ParseKeyPress(Sender: TObject; var Key: Char);
68procedure IntKeyPress(Sender: TObject; var Key: Char);
69procedure EditIntegMinKeyUp(Sender: TObject; var Key: Word;
70Shift: TShiftState);
71procedure EditIntegMaxKeyUp(Sender: TObject; var Key: Word;
72Shift: TShiftState);
73procedure EditCountKeyUp(Sender: TObject; var Key: Word;
74Shift: TShiftState);
75procedure EditConstKeyUp(Sender: TObject; var Key: Word;
76Shift: TShiftState);
77procedure EditPenWidthKeyUp(Sender: TObject; var Key: Word;
78Shift: TShiftState);
79procedure EditOpacityKeyUp(Sender: TObject; var Key: Word;
80Shift: TShiftState);
81procedure EditCountExit(Sender: TObject);
82
83procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
84procedure UpDown2Click(Sender: TObject; Button: TUDBtnType);
85procedure UpDown3Click(Sender: TObject; Button: TUDBtnType);
86procedure UpDown1MouseUp(Sender: TObject; Button: TMouseButton;
87Shift: TShiftState; X, Y: Integer);
88
89procedure CheckBoxClick(Sender: TObject);
90procedure CentreButtonClick(Sender: TObject);
91procedure ColorButtonClick(Sender: TObject);
92procedure PositiveButtonClick(Sender: TObject);
93procedure NegativeButtonClick(Sender: TObject);
94procedure RecalcBtnClick(Sender: TObject);
95procedure CloseBtnClick(Sender: TObject);
96procedure IntegLabelClick(Sender: TObject);
97procedure KeepRangeCheckBoxClick(Sender: TObject);
98private
99
100procedure UpdateRangeData;
101public
102
103PlotIntegrated: byte; { piCalc = 0; piShow = 1; piArea = 2; piBoth = 3 }
104procedure ShowData;
105end;
106
107var
108IntegrateXForm: TIntegrateXForm;
109
110//======================================================================
111implementation
112//======================================================================
113
114uses
115Graf.Parser1d,
116Graf.Global1d,
117faFunc1d,
118faGraf1D,
119Clipbrd;
120
121{$R *.dfm}
122
123procedure TIntegrateXForm.FormShow(Sender: TObject);
124begin
125KeepRangeCheckBox.Checked := KeepRange;
126ShowData;
127end;
128
129procedure TIntegrateXForm.FormActivate(Sender: TObject);
130begin
131EditIntegMin.SetFocus;
132EditIntegMin.SelText;
133end;
134
135procedure TIntegrateXForm.FormKeyPress(Sender: TObject; var Key: Char);
136begin
137case Key of
138#13:begin
139RecalcBtnClick(Sender);
140Key := #0;
141end;
142#27:begin
143Key := #0;
144Close;
145end;
146end;
147end;
148
149procedure TIntegrateXForm.FormDeactivate(Sender: TObject);
150begin
151if KeepRange then UpdateRangeData;
152end;
153
154procedure TIntegrateXForm.ParseKeyPress(Sender: TObject; var Key: Char);
155begin
156with Sender as TEdit do
157begin
158if not CharInSet(UpCase(Key),
159[' ', '!', '(', ')', '*', '+', '-', '.', ',', '/', '0'..'9',
160'A'..'C', 'E', 'G'..'I', 'L', 'N'..'T', 'X', '^', '`', #8]) then
161begin
162Key := #0;
163Exit;
164end;
165if Key = '`' then Key := '�';
166end;
167end;
168
169procedure TIntegrateXForm.IntKeyPress(Sender: TObject; var Key: Char);
170begin
171with Sender as TEdit do
172if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
173end;
174
175procedure TIntegrateXForm.EditIntegMinKeyUp(Sender: TObject; var Key: Word;
176Shift: TShiftState);
177var
178s: string;
179e: byte;
180
181begin
182s := ScanText(EditIntegMin.Text);
183IntegMin := ParseAndEvaluate(s, e);
184//if isNAN(IntegMin) then IntegMin := 0;
185//if e > 0 then IntegMin := 0;
186if isNAN(IntegMin) or isInfinite(IntegMin) or (e > 0) then IntegMin := 0;
187end;
188
189procedure TIntegrateXForm.EditIntegMaxKeyUp(Sender: TObject; var Key: Word;
190Shift: TShiftState);
191var
192s: string;
193e: byte;
194
195begin
196s := ScanText(EditIntegMax.Text);
197IntegMax := ParseAndEvaluate(s, e);
198// if isNAN(IntegMax) then IntegMax := 0;
199// if e > 0 then IntegMax := 0;
200if isNAN(IntegMax) or isInfinite(IntegMax) or (e > 0) then IntegMax := 0;
201end;
202
203procedure TIntegrateXForm.EditCountKeyUp(Sender: TObject; var Key: Word;
204Shift: TShiftState);
205begin
206with GraphData do
207begin
208try
209IntegCount := StrToInt(EditCount.Text);
210if IntegCount = 0 then IntegCount := IntegCountPos;
211except
212IntegCount := IntegCountPos;
213end;
214if IntegCount > IntegCountMax then IntegCount := IntegCountMax;
215end;
216Altered := true;
217end;
218
219procedure TIntegrateXForm.EditConstKeyUp(Sender: TObject; var Key: Word;
220Shift: TShiftState);
221begin
222try
223IntegConst := StrToFloat(EditConst.Text);
224except
225IntegConst := 0;
226end;
227end;
228
229procedure TIntegrateXForm.EditPenWidthKeyUp(Sender: TObject; var Key: Word;
230Shift: TShiftState);
231begin
232try
233GraphData.ydxWidth := StrToInt(EditPenWidth.Text);
234if Graphdata.ydxWidth = 0 then GraphData.ydxWidth := 1;
235except
236GraphData.ydxWidth := 1;
237end;
238Altered := true;
239MainForm.GLViewer.Invalidate;
240end;
241
242procedure TIntegrateXForm.EditOpacityKeyUp(Sender: TObject; var Key: Word;
243Shift: TShiftState);
244var
245n: integer;
246
247begin
248try
249n := StrToInt(EditOpacity.Text);
250except
251n := 1;
252end;
253GraphData.AreaAlpha := n/100;
254Altered := true;
255MainForm.GLViewer.Invalidate;
256end;
257
258procedure TIntegrateXForm.EditCountExit(Sender: TObject);
259begin
260EditCount.Text := IntToStr(GraphData.IntegCount);
261end;
262
263procedure TIntegrateXForm.UpDown1Click(Sender: TObject; Button: TUDBtnType);
264var
265k: word;
266
267begin
268k := 0;
269EditCountKeyUp(Sender, k, []);
270end;
271
272procedure TIntegrateXForm.UpDown2Click(Sender: TObject; Button: TUDBtnType);
273var
274k: word;
275
276begin
277k := 0;
278EditPenWidthKeyUp(Sender, k, []);
279end;
280
281procedure TIntegrateXForm.UpDown3Click(Sender: TObject; Button: TUDBtnType);
282var
283k: word;
284
285begin
286k := 0;
287EditOpacityKeyUp(Sender, k, []);
288end;
289
290procedure TIntegrateXForm.UpDown1MouseUp(Sender: TObject; Button: TMouseButton;
291Shift: TShiftState; X, Y: Integer);
292begin
293RecalcBtnClick(Sender);
294end;
295
296procedure TIntegrateXForm.CheckBoxClick(Sender: TObject);
297begin
298with Sender as TCheckBox do
299if Checked then
300begin { tag = piShow for IntegCheckBox; piArea for ShadeCheckBox }
301if not Ord(PlotIntegrated) and Tag = Tag
302then Inc(PlotIntegrated, Tag); { now selected }
303end
304else
305if Ord(PlotIntegrated) and Tag = Tag
306then Dec(PlotIntegrated, Tag); { now de-selected }
307RecalcBtnClick(Sender);
308end;
309
310procedure TIntegrateXForm.CentreButtonClick(Sender: TObject);
311var
312y1, y2: extended;
313
314begin
315y1 := StrToFloat(Copy(MinIntegYLabel.Caption,
316pos('=', MinIntegYLabel.Caption)+2,
317Length(MinIntegYLabel.Caption)));
318y2 := StrToFloat(Copy(MaxIntegYLabel.Caption,
319pos('=', MaxIntegYLabel.Caption)+2,
320Length(MaxIntegYLabel.Caption)));
321IntegConst := IntegConst-(y1 + y2)/2;
322EditConst.Text := FloatToStr(IntegConst);
323RecalcBtnclick(Sender);
324end;
325
326procedure TIntegrateXForm.ColorButtonClick(Sender: TObject);
327begin
328ColorDialog.Color := GraphData.ydxColor;
329if ColorDialog.Execute then
330begin
331GraphData.ydxColor := ColorDialog.Color;
332ColorPanel.Color := GraphData.ydxColor;
333MainForm.GLViewer.Invalidate;
334Altered := TRUE
335end;
336end;
337
338procedure TIntegrateXForm.PositiveButtonClick(Sender: TObject);
339begin
340ColorDialog.Color := GraphData.PosAreaColor;
341if ColorDialog.Execute then
342begin
343GraphData.PosAreaColor := ColorDialog.Color;
344PositivePanel.Color := GraphData.PosAreaColor;
345MainForm.GLViewer.Invalidate;
346Altered := TRUE
347end;
348end;
349
350procedure TIntegrateXForm.NegativeButtonClick(Sender: TObject);
351begin
352ColorDialog.Color := GraphData.NegAreaColor;
353if ColorDialog.Execute then
354begin
355GraphData.NegAreaColor := ColorDialog.Color;
356NegativePanel.Color := GraphData.NegAreaColor;
357MainForm.GLViewer.Invalidate;
358Altered := TRUE
359end;
360end;
361
362procedure TIntegrateXForm.RecalcBtnClick(Sender: TObject);
363begin
364MainForm.GLViewer.Invalidate;
365end;
366
367procedure TIntegrateXForm.IntegLabelClick(Sender: TObject);
368begin
369Clipboard.Clear;
370with Sender as TLabel do
371Clipboard.AsText := Copy(Caption, pos('=', Caption)+2, Length(Caption));
372end;
373
374procedure TIntegrateXForm.KeepRangeCheckBoxClick(Sender: TObject);
375begin
376KeepRange := KeepRangeCheckBox.Checked;
377end;
378
379procedure TIntegrateXForm.CloseBtnClick(Sender: TObject);
380begin
381Close;
382end;
383
384procedure TIntegrateXForm.UpdateRangeData;
385begin
386KeptMin := IntegMin;
387KeptMax := IntegMax;
388end;
389
390procedure TIntegrateXForm.ShowData;
391begin
392with GraphData, PlotData do
393begin
394EditCount.Text := IntToStr(IntegCount);
395UpDown2.Position := ydxWidth;
396UpDown3.Position := round(AreaAlpha*100);
397KeepRangeCheckBox.Checked := KeepRange;
398ColorPanel.Color := ydxColor;
399PositivePanel.Color := PosAreaColor;
400NegativePanel.Color := NegAreaColor;
401
402if PlotAsFx then
403begin
404if TextStr = '' then Caption := '' else Caption := 'y = '+TextStr;
405if IsSegment then
406begin
407if KeepRange then
408begin
409IntegMin := KeptMin;
410IntegMax := KeptMax;
411end
412else
413begin
414IntegMin := SegMin;
415IntegMax := SegMax;
416end;
417end
418else
419begin
420if KeepRange then
421begin
422IntegMin := KeptMin;
423IntegMax := KeptMax;
424end
425else
426begin
427IntegMin := xMin;
428IntegMax := xMax;
429end;
430end;
431
432Label1.Caption := 'where a = x1';
433Label2.Caption := 'and b = x2';
434Label5.Caption := 'Integral y at a = x1:';
435CentreButton.Caption := 'Centre to x a&xis';
436end
437else
438begin
439Caption := 'r = '+TextStr;
440if KeepRange then
441begin
442IntegMin := KeptMin;
443IntegMax := KeptMax;
444end
445else
446begin
447IntegMin := SegMin;
448IntegMax := SegMax;
449end;
450Label1.Caption := 'For a = �1';
451Label2.Caption := 'b = �2 (radians)';
452Label5.Caption := 'Integral r at (a = �1):';
453CentreButton.Caption := 'Centre to x a&xis';
454end;
455end;
456EditIntegMin.Text := FloatToStrF(IntegMin, ffGeneral, 13, 4);
457EditIntegMax.Text := FloatToStrF(IntegMax, ffGeneral, 13, 4);
458EditConst.Text := FloatToStrF(IntegConst, ffGeneral, 13, 4);
459end;
460
461end.
462