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