MathgeomGLS

Форк
0
/
fIntegrateY.pas 
329 строк · 7.9 Кб
1
unit fIntegrateY;
2

3
interface
4

5
uses
6
  Winapi.Windows,
7
  Winapi.Messages,
8
  System.SysUtils,
9
  System.Variants,
10
  System.Classes,
11
  System.Math,
12
  Vcl.Graphics,
13
  Vcl.Controls,
14
  Vcl.Clipbrd,
15
  Vcl.Forms,
16
  Vcl.Dialogs,
17
  Vcl.StdCtrls,
18
  Vcl.Buttons,
19
  Vcl.ComCtrls,
20
  Vcl.Menus,
21
  Vcl.ExtCtrls,
22

23
  uParser,
24
  uGlobal;
25

26
type
27
  TIntegrateYForm = class(TForm)
28
    Label3: TLabel;
29
    Label4: TLabel;
30
    Label5: TLabel;
31
    Label6: TLabel;
32
    Label1: TLabel;
33
    Label2: TLabel;
34
    Label7: TLabel;
35
    Label8: TLabel;
36
    PositiveButton: TSpeedButton;
37
    NegativeButton: TSpeedButton;
38
    NegAreaLabel: TLabel;
39
    PosAreaLabel: TLabel;
40
    TotalAreaLabel: TLabel;
41
    EditIntegMin: TEdit;
42
    EditIntegMax: TEdit;
43
    EditCount: TEdit;
44
    UpDown1: TUpDown;
45
    EditOpacity: TEdit;
46
    UpDown2: TUpDown;
47
    RecalcBtn: TBitBtn;
48
    CloseBtn: TBitBtn;
49
    ColorDialog: TColorDialog;
50
    KeepRangeCheckBox: TCheckBox;
51
    PositivePanel: TPanel;
52
    NegativePanel: TPanel;
53
    SumAreaLabel: TLabel;
54
    procedure FormShow(Sender: TObject);
55
    procedure FormActivate(Sender: TObject);
56
    procedure FormKeyPress(Sender: TObject; var Key: Char);
57
    procedure FormDeactivate(Sender: TObject);
58

59
    procedure ParseKeyPress(Sender: TObject; var Key: Char);
60
    procedure IntKeyPress(Sender: TObject; var Key: Char);
61
    procedure EditIntegMinKeyUp(Sender: TObject; var Key: Word;
62
                                 Shift: TShiftState);
63
    procedure EditIntegMaxKeyUp(Sender: TObject; var Key: Word;
64
                                 Shift: TShiftState);
65
    procedure EditCountKeyUp(Sender: TObject; var Key: Word;
66
                              Shift: TShiftState);
67
    procedure EditOpacityKeyUp(Sender: TObject; var Key: Word;
68
                                Shift: TShiftState);
69
    procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
70
    procedure UpDown2Click(Sender: TObject; Button: TUDBtnType);
71
    procedure UpDown1MouseUp(Sender: TObject; Button: TMouseButton;
72
                              Shift: TShiftState; X, Y: Integer);
73
    procedure PositiveButtonClick(Sender: TObject);
74
    procedure NegativeButtonClick(Sender: TObject);
75
    procedure RecalcBtnClick(Sender: TObject);
76
    procedure CloseBtnClick(Sender: TObject);
77
    procedure IntegLabelClick(Sender: TObject);
78
    procedure KeepRangeCheckBoxClick(Sender: TObject);
79
  private
80
    procedure UpdateRangeData;
81
  public
82
    procedure ShowData;
83
  end;
84

85
var
86
  IntegrateYForm: TIntegrateYForm;
87

88
//====================================================================
89
implementation
90
//====================================================================
91

92
uses
93
  fFuncts,
94
  fPlot1D;
95

96
{$R *.dfm}
97

98
procedure TIntegrateYForm.FormShow(Sender: TObject);
99
begin
100
  KeepRangeCheckBox.Checked := KeepRange;
101
  ShowData;
102
end;
103

104
procedure TIntegrateYForm.FormActivate(Sender: TObject);
105
begin
106
  EditIntegMin.SetFocus;
107
  EditIntegMin.SelText;
108
end;
109

110
procedure TIntegrateYForm.FormKeyPress(Sender: TObject; var Key: Char);
111
begin
112
  case Key of
113
#13:begin
114
      RecalcBtnClick(Sender);
115
      Key := #0;
116
    end;
117
#27:begin
118
      Key := #0;
119
      Close;
120
    end;
121
  end;
122
end;
123

124
procedure TIntegrateYForm.FormDeactivate(Sender: TObject);
125
begin
126
  if KeepRange then UpdateRangeData;
127
end;
128

129
procedure TIntegrateYForm.ParseKeyPress(Sender: TObject; var Key: Char);
130
begin
131
  with Sender as TEdit do
132
  begin
133
    if not CharInSet(UpCase(Key),
134
   [' ', '!', '(', ')', '*', '+', '-', '.', ',', '/', '0'..'9',
135
    'A'..'C', 'E', 'G'..'I', 'L', 'N'..'T', 'X', '^', '`', #8]) then
136
    begin
137
      Key := #0;
138
      Exit;
139
    end;
140
    if Key = '`' then Key := '�';
141
  end;
142
end;
143

144
procedure TIntegrateYForm.IntKeyPress(Sender: TObject; var Key: Char);
145
begin
146
  with Sender as TEdit do
147
  if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
148
end;
149

150
procedure TIntegrateYForm.EditIntegMinKeyUp(Sender: TObject; var Key: Word;
151
                                             Shift: TShiftState);
152
var
153
  s: string;
154
  e: byte;
155

156
begin
157
  s := ScanText(EditIntegMin.Text);
158
  IntegMin := ParseAndEvaluate(s, e);
159
//  if isNAN(IntegMin) then IntegMin := 0;
160
//  if e > 0 then IntegMin := 0;
161
  if isNAN(IntegMin) or isInfinite(IntegMin) or (e > 0) then IntegMin := 0;
162
end;
163

164
procedure TIntegrateYForm.EditIntegMaxKeyUp(Sender: TObject; var Key: Word;
165
                                             Shift: TShiftState);
166
var
167
  s: string;
168
  e: byte;
169

170
begin
171
  s := ScanText(EditIntegMax.Text);
172
  IntegMax := ParseAndEvaluate(s, e);
173
//  if isNAN(IntegMax) then IntegMax := 0;
174
//  if e > 0 then IntegMax := 0;
175
  if isNAN(IntegMax) or isInfinite(IntegMax) or (e > 0) then IntegMax := 0;
176
end;
177

178
procedure TIntegrateYForm.EditCountKeyUp(Sender: TObject; var Key: Word;
179
                                          Shift: TShiftState);
180
begin
181
  with GraphData do
182
  begin
183
    try
184
      IntegCount := StrToInt(EditCount.Text);
185
      if IntegCount = 0 then IntegCount := IntegCountPos;
186
    except
187
      IntegCount := IntegCountPos;
188
    end;
189
    if IntegCount > IntegCountMax then IntegCount := IntegCountMax;
190
  end;
191
  Altered := true;
192
end;
193

194
procedure TIntegrateYForm.EditOpacityKeyUp(Sender: TObject; var Key: Word;
195
                                            Shift: TShiftState);
196
var
197
  n: integer;
198

199
begin
200
  try
201
    n := StrToInt(EditOpacity.Text);
202
  except
203
    n := 1;
204
  end;
205
  GraphData.AreaAlpha := n/100;
206
  Altered := true;
207
  MainForm.GLViewer.Invalidate;
208
end;
209

210
procedure TIntegrateYForm.UpDown1Click(Sender: TObject; Button: TUDBtnType);
211
var
212
  k: word;
213

214
begin
215
  k := 0;
216
  EditCountKeyUp(Sender, k, []);
217
end;
218

219
procedure TIntegrateYForm.UpDown2Click(Sender: TObject; Button: TUDBtnType);
220
var
221
  k: word;
222

223
begin
224
  k := 0;
225
  EditOpacityKeyUp(Sender, k, []);
226
end;
227

228
procedure TIntegrateYForm.UpDown1MouseUp(Sender: TObject; Button: TMouseButton;
229
                                          Shift: TShiftState; X, Y: Integer);
230
begin
231
  RecalcBtnClick(Sender);
232
end;
233

234
procedure TIntegrateYForm.PositiveButtonClick(Sender: TObject);
235
begin
236
  ColorDialog.Color := GraphData.PosAreaColor;
237
  if ColorDialog.Execute then
238
  begin
239
    GraphData.PosAreaColor := ColorDialog.Color;
240
    PositivePanel.Color := GraphData.PosAreaColor;
241
    MainForm.GLViewer.Invalidate;
242
    Altered := TRUE
243
  end;
244
end;
245

246
procedure TIntegrateYForm.NegativeButtonClick(Sender: TObject);
247
begin
248
  ColorDialog.Color := GraphData.NegAreaColor;
249
  if ColorDialog.Execute then
250
  begin
251
    GraphData.NegAreaColor := ColorDialog.Color;
252
    NegativePanel.Color := GraphData.NegAreaColor;
253
    MainForm.GLViewer.Invalidate;
254
    Altered := TRUE
255
  end;
256
end;
257

258
procedure TIntegrateYForm.RecalcBtnClick(Sender: TObject);
259
begin
260
  MainForm.GLViewer.Invalidate;
261
end;
262

263
procedure TIntegrateYForm.IntegLabelClick(Sender: TObject);
264
begin
265
  Clipboard.Clear;
266
  with Sender as TLabel do
267
  Clipboard.AsText := Copy(Caption,  pos('=', Caption)+2, Length(Caption));
268
end;
269

270
procedure TIntegrateYForm.KeepRangeCheckBoxClick(Sender: TObject);
271
begin
272
  KeepRange := KeepRangeCheckBox.Checked;
273
end;
274

275
procedure TIntegrateYForm.CloseBtnClick(Sender: TObject);
276
begin
277
  Close;
278
end;
279

280
procedure TIntegrateYForm.UpdateRangeData;
281
begin
282
  KeptMin := IntegMin;
283
  KeptMax := IntegMax;
284
end;
285

286
procedure TIntegrateYForm.ShowData;
287
begin
288
  with GraphData, PlotData do
289
  begin
290
    EditCount.Text := IntToStr(IntegCount);
291
    UpDown2.Position := round(AreaAlpha*100);
292
    if TextStr = '' then Caption := '' else Caption := 'y = '+TextStr;
293

294
    KeepRangeCheckBox.Checked := KeepRange;
295
    PositivePanel.Color := PosAreaColor;
296
    NegativePanel.Color := NegAreaColor;
297

298
    if IsSegment then
299
    begin
300
      if KeepRange then
301
      begin
302
        IntegMin := KeptMin;
303
        IntegMax := KeptMax;
304
      end
305
      else
306
      begin
307
        IntegMin := SegMin;
308
        IntegMax := SegMax;
309
      end;
310
    end
311
    else
312
    begin
313
      if KeepRange then
314
      begin
315
        IntegMin := KeptMin;
316
        IntegMax := KeptMax;
317
      end
318
      else
319
      begin
320
        IntegMin := xMin;
321
        IntegMax := xMax;
322
      end;
323
    end;
324
  end;
325
  EditIntegMin.Text := FloatToStrF(IntegMin, ffGeneral, 13, 4);
326
  EditIntegMax.Text := FloatToStrF(IntegMax, ffGeneral, 13, 4);
327
end;
328

329
end.
330

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.