MathgeomGLS

Форк
0
/
faDerivativeOptions.pas 
566 строк · 15.3 Кб
1
unit faDerivativeOptions;
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.Forms,
15
  Vcl.Dialogs,
16
  Vcl.StdCtrls,
17
  Vcl.Buttons,
18
  Vcl.ExtCtrls,
19
  Vcl.ComCtrls,
20

21
  GLS.OpenGLTokens,
22
  GLS.VectorTypes,
23
  GLS.VectorGeometry,
24

25
  Graf.Global2d,
26
  Graf.Parser2d,
27
  faGridOptions;
28

29
type
30
  TDerivativesForm = class(TForm)
31
    GroupBox1: TGroupBox;
32
    Label1: TLabel;
33
    Label2: TLabel;
34
    Label3: TLabel;
35
    Label4: TLabel;
36
    Label5: TLabel;
37
    Label6: TLabel;
38
    Label8: TLabel;
39
    zCountLabel: TLabel;
40
    GridValues: TSpeedButton;
41
    PlotValues: TSpeedButton;
42
    EditMinX: TEdit;
43
    EditMaxX: TEdit;
44
    EditdX: TEdit;
45
    EditMinY: TEdit;
46
    EditMaxY: TEdit;
47
    EditdY: TEdit;
48
    EditMinZ: TEdit;
49
    EditMaxZ: TEdit;
50
    zLimitCB: TCheckBox;
51
    ModeComboBox: TComboBox;
52
    StyleComboBox: TComboBox;
53
    zCapCB: TCheckBox;
54
    ApplyBtn: TBitBtn;
55
    CloseBtn: TBitBtn;
56
    DerivXRB: TRadioButton;
57
    DerivYRB: TRadioButton;
58
    VolumeRB: TRadioButton;
59
    Label7: TLabel;
60
    EditAddLineWidth: TEdit;
61
    ColorButton: TSpeedButton;
62
    ColorDialog: TColorDialog;
63
    VolumeLabel: TLabel;
64
    PosVolLabel: TLabel;
65
    NegVolLabel: TLabel;
66
    TotalLabel: TLabel;
67
    procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
68
    procedure FloatKeyPress(Sender: TObject; var Key: Char);
69
    procedure IncKeyPress(Sender: TObject; var Key: Char);
70
    procedure EditMinXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
71
    procedure EditMaxXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
72
    procedure EditdXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
73
    procedure EditMinYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
74
    procedure EditMaxYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
75
    procedure EditdYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
76
    procedure EditMinZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
77
    procedure EditMaxZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
78
    procedure zLimitCBClick(Sender: TObject);
79
    procedure zCapCBClick(Sender: TObject);
80
    procedure ApplyBtnClick(Sender: TObject);
81
    procedure CloseBtnClick(Sender: TObject);
82
    procedure GridValuesClick(Sender: TObject);
83
    procedure PlotValuesClick(Sender: TObject);
84
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
85
    procedure StyleComboBoxChange(Sender: TObject);
86
    procedure ModeComboBoxChange(Sender: TObject);
87
    procedure DerivXRBClick(Sender: TObject);
88
    procedure DerivYRBClick(Sender: TObject);
89
    procedure VolumeRBClick(Sender: TObject);
90
    procedure FormShow(Sender: TObject);
91
    procedure EditAddLineWidthKeyPress(Sender: TObject; var Key: Char);
92
    procedure EditAddLineWidthKeyUp(Sender: TObject; var Key: Word;
93
                                  Shift: TShiftState);
94
    procedure ColorButtonClick(Sender: TObject);
95
    procedure PlotValuesMouseUp(Sender: TObject; Button: TMouseButton;
96
                                 Shift: TShiftState; X, Y: Integer);
97
    procedure GridValuesMouseUp(Sender: TObject; Button: TMouseButton;
98
                                 Shift: TShiftState; X, Y: Integer);
99
  private
100
    TooManyPoints: Boolean;
101
    procedure CountzPoints;
102
  public
103

104
  end;
105

106
var
107
  DerivativesForm: TDerivativesForm;
108

109
//==========================================================================
110
implementation
111
//==========================================================================
112

113
{$R *.dfm}
114
uses
115
  faGraf2d,
116
  faAddPlotColors,
117
  faEvaluate;
118

119
procedure TDerivativesForm.EditdXKeyUp(Sender: TObject; var Key: Word;
120
                                        Shift: TShiftState);
121
var
122
  x: TGlFloat;
123

124
begin
125
  try
126
    x := StrToFloat(EditdX.Text);
127
  except
128
    x := 1.0;
129
  end;
130
  AddedData.xInc := x;
131
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
132
  DerivativeAltered := True;
133
  CountzPoints;
134
end;
135

136
procedure TDerivativesForm.EditdYKeyUp(Sender: TObject; var Key: Word;
137
                                        Shift: TShiftState);
138
var
139
  y: TGLFloat;
140

141
begin
142
  try
143
    y := StrToFloat(EditdY.Text);
144
  except
145
    y := 1.0;
146
  end;
147
  AddedData.yInc := y;
148
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
149
  DerivativeAltered := True;
150
  CountzPoints;
151
end;
152

153
procedure TDerivativesForm.EditKeyDown(Sender: TObject; var Key: Word;
154
                                        Shift: TShiftState);
155
begin
156
//if (Key = VK_DELETE) or (Key = VK_BACK)
157
//then ApplyBtn.Visible := AddedData.AddedAs > AddNone;
158
end;
159

160
procedure TDerivativesForm.EditAddLineWidthKeyPress(Sender: TObject;
161
                                                var Key: Char);
162
begin
163
  with Sender as TEdit do
164
  if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
165
end;
166

167
procedure TDerivativesForm.EditAddLineWidthKeyUp(Sender: TObject; var Key: Word;
168
                                               Shift: TShiftState);
169
var
170
  w: integer;
171

172
begin
173
  try
174
    w := StrToInt(EditAddLineWidth.Text);
175
  except
176
    w := 3;
177
  end;
178

179
  AddedData.AddLineWidth := w;
180
  FormPlotStars.AddXLine.LineWidth := w;
181
  FormPlotStars.AddYLine.LineWidth := w;
182
  FormPlotStars.AddZLine.LineWidth := w;
183
  DerivativeAltered := True;
184
//ApplyBtn.Visible := AddedData.AddedAs = AddVolume;
185
end;
186

187
procedure TDerivativesForm.EditMaxXKeyUp(Sender: TObject; var Key: Word;
188
                                          Shift: TShiftState);
189
var
190
  x: TGLFloat;
191

192
begin
193
  try
194
    x := StrToFloat(EditMaxX.Text);
195
  except
196
    x := 1.0;
197
  end;
198
  AddedData.xMax := x;
199
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
200
  DerivativeAltered := True;
201
  CountzPoints;
202
end;
203

204
procedure TDerivativesForm.EditMaxYKeyUp(Sender: TObject; var Key: Word;
205
                                          Shift: TShiftState);
206
var
207
  y: TGLFloat;
208

209
begin
210
  try
211
    y := StrToFloat(EditMaxY.Text);
212
  except
213
    y := 1.0;
214
  end;
215
  AddedData.yMax := y;
216
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
217
  DerivativeAltered := True;
218
  CountzPoints;
219
end;
220

221
procedure TDerivativesForm.EditMaxZKeyUp(Sender: TObject; var Key: Word;
222
                                          Shift: TShiftState);
223
var
224
  z: TGLFloat;
225

226
begin
227
  try
228
    z := StrToFloat(EditMaxZ.Text);
229
  except
230
    z := 1.0;
231
  end;
232
  AddedData.zMax := z;
233
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
234
  DerivativeAltered := True;
235
  CountzPoints;
236
end;
237

238
procedure TDerivativesForm.EditMinXKeyUp(Sender: TObject; var Key: Word;
239
                                          Shift: TShiftState);
240
var
241
  x: TGLFloat;
242

243
begin
244
  try
245
    x := StrToFloat(EditMinX.Text);
246
  except
247
    x := -1.0;
248
  end;
249
  AddedData.xMin := x;
250
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
251
  DerivativeAltered := True;
252
  CountzPoints;
253
end;
254

255
procedure TDerivativesForm.EditMinYKeyUp(Sender: TObject; var Key: Word;
256
                                          Shift: TShiftState);
257
var
258
  y: TGLFloat;
259

260
begin
261
  try
262
    y := StrToFloat(EditMinY.Text);
263
  except
264
    y := -1.0;
265
  end;
266
  AddedData.yMin := y;
267
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
268
  DerivativeAltered := True;
269
  CountzPoints;
270
end;
271

272
procedure TDerivativesForm.EditMinZKeyUp(Sender: TObject; var Key: Word;
273
                                          Shift: TShiftState);
274
var
275
  z: TGLFloat;
276

277
begin
278
  try
279
    z := StrToFloat(EditMinZ.Text);
280
  except
281
    z := -1.0;
282
  end;
283
  AddedData.zMin := z;
284
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
285
  DerivativeAltered := True;
286
  CountzPoints;
287
end;
288

289
procedure TDerivativesForm.FormCloseQuery(Sender: TObject;
290
                                    var CanClose: Boolean);
291
begin
292
  AddedData.AddedAs := AddNone;
293
  FormPlotStars.ClearAddedField;
294
  FormPlotStars.ClearAddedLines;
295
  FormPlotStars.AddXLine.Visible := False;
296
  FormPlotStars.AddYLine.Visible := False;
297
  FormPlotStars.AddZLine.Visible := False;
298
  FormPlotStars.miPlotColours.Enabled := True;
299
  FormPlotStars.miDerivativePlotColours.Enabled := False;
300
  if AddPlotColorsForm.Visible then AddPlotColorsForm.Close;
301
  Altered := Altered or DerivativeAltered;
302
end;
303

304
procedure TDerivativesForm.FormShow(Sender: TObject);
305
begin
306
  Caption := GraphFName;
307
  with AddedData do
308
  begin
309
    EditMinX.Text := FloatToStrF(xMin, ffGeneral, 7, 4);
310
    EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 7, 4);
311
    Editdx.Text := FloatToStrF(xInc, ffGeneral, 7, 4);
312
    EditMinY.Text := FloatToStrF(yMin, ffGeneral, 7, 4);
313
    EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 7, 4);
314
    Editdy.Text := FloatToStrF(yInc, ffGeneral, 7, 4);
315
    EditMinZ.Text := FloatToStrF(zMin, ffGeneral, 7, 4);
316
    EditMaxZ.Text := FloatToStrF(zMax, ffGeneral, 7, 4);
317
    zLimitCB.Checked := zLim;
318
    zCapCB.Checked := zCap;
319
    ModeComboBox.ItemIndex := Ord(ViewMode);
320
    StyleComboBox.ItemIndex := Ord(fxyMode);
321
    if AddLineWidth < 1 then AddLineWidth := 1;
322
    EditAddLineWidth.Text := IntToStr(AddLineWidth);
323
    ModeComboBox.ItemIndex := Ord(ViewMode);
324
    StyleComboBox.ItemIndex := Ord(fxyMode);
325
  end;
326
  AddPlotColorsForm.ShowPlotColorData;
327
//ApplyBtn.Visible := VolumeRB.Checked;
328
  if DerivXRB.Checked or DerivyRB.Checked then ApplyBtnClick(Sender);
329
  DerivativeAltered := False;
330
  CountzPoints;
331
end;
332

333
procedure TDerivativesForm.GridValuesClick(Sender: TObject);
334
begin
335
  with ViewData.xyGrid.xRange do
336
  begin
337
    EditMinX.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
338
    AddedData.xMin := Minimum;
339
    EditMaxX.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
340
    AddedData.xMax := Maximum;
341
    EditdX.Text := FloatToStrF(Step, ffGeneral, 7, 4);
342
    AddedData.xInc := Step;
343
  end;
344

345
  with ViewData.xyGrid.yRange do
346
  begin
347
    EditMinY.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
348
    AddedData.yMin := Minimum;
349
    EditMaxY.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
350
    AddedData.yMax := Maximum;
351
    EditdY.Text := FloatToStrF(Step, ffGeneral, 7, 4);
352
    AddedData.yInc := Step;
353
  end;
354

355
  with ViewData.xzGrid.zRange do
356
  begin
357
    EditMinZ.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
358
    AddedData.zMin := Minimum;
359
    EditMaxZ.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
360
    AddedData.zMax := Maximum;
361
  end;
362
  DerivativeAltered := True;
363
  CountzPoints;
364
end;
365

366
procedure TDerivativesForm.GridValuesMouseUp(Sender: TObject;
367
          Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
368
begin
369
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
370
end;
371

372
procedure TDerivativesForm.IncKeyPress(Sender: TObject; var Key: Char);
373
begin
374
  with Sender as TEdit do
375
  if not CharInSet(Key, PosFloat) then Key := #0;
376
end;
377

378
procedure TDerivativesForm.ModeComboBoxChange(Sender: TObject);
379
begin
380
  AddedData.ViewMode := TViewMode(ModeComboBox.ItemIndex);
381
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
382
  ApplyBtnClick(Sender);
383
end;
384

385
procedure TDerivativesForm.FloatKeyPress(Sender: TObject; var Key: Char);
386
begin
387
  with Sender as TEdit do
388
  if not CharInSet(Key, AnyFloat) then Key := #0;
389
end;
390

391
procedure TDerivativesForm.PlotValuesClick(Sender: TObject);
392
begin
393
  EditMinx.Text := FloatToStrF(PlotData.xMin, ffGeneral, 7, 4);
394
  AddedData.xMin := PlotData.xMin;
395
  EditMaxx.Text := FloatToStrF(PlotData.xMax, ffGeneral, 7, 4);
396
  AddedData.xMax := PlotData.xMax;
397
  EditdX.Text := FloatToStrF(PlotData.xInc, ffGeneral, 7, 4);
398
  AddedData.xInc := PlotData.xInc;
399
  EditMiny.Text := FloatToStrF(PlotData.yMin, ffGeneral, 7, 4);
400
  AddedData.yMin := PlotData.yMin;
401
  EditMaxy.Text := FloatToStrF(PlotData.yMax, ffGeneral, 7, 4);
402
  AddedData.yMax := PlotData.yMax;
403
  EditdY.Text := FloatToStrF(PlotData.yInc, ffGeneral, 7, 4);
404
  AddedData.yInc := PlotData.yInc;
405
  EditMinz.Text := FloatToStrF(PlotData.zMin, ffGeneral, 7, 4);
406
  AddedData.zMin := PlotData.zMin;
407
  EditMaxz.Text := FloatToStrF(PlotData.zMax, ffGeneral, 7, 4);
408
  AddedData.zMax := PlotData.zMax;
409
  zLimitCB.Checked := PlotData.zLim;
410
  AddedData.zLim := PlotData.zLim;
411
  zCapCB.Checked := PlotData.zCap;
412
  AddedData.zCap := PlotData.zCap;
413
  CountzPoints;
414
end;
415

416
procedure TDerivativesForm.PlotValuesMouseUp(Sender: TObject;
417
          Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
418
begin
419
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
420
end;
421

422
procedure TDerivativesForm.StyleComboBoxChange(Sender: TObject);
423
begin
424
  AddedData.fxyMode := TfxyMode(StyleComboBox.ItemIndex);
425
//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
426
  ApplyBtnClick(Sender);
427
end;
428

429
procedure TDerivativesForm.VolumeRBClick(Sender: TObject);
430
begin
431
  AddedData.AddedAs := AddVolume;
432
//ApplyBtn.Visible := not TooManyPoints;
433
  ApplyBtnClick(Sender);
434
end;
435

436
procedure TDerivativesForm.DerivXRBClick(Sender: TObject);
437
begin
438
  FormPlotStars.ClearAddedLines;
439
  AddedData.AddedAs := AddDerivX;
440
  DerivXRB.Checked := False;
441
  ApplyBtnClick(Sender);
442
end;
443

444
procedure TDerivativesForm.DerivYRBClick(Sender: TObject);
445
begin
446
  FormPlotStars.ClearAddedLines;
447
  AddedData.AddedAs := AddDerivY;
448
  DerivYRB.Checked := False;
449
  ApplyBtnClick(Sender);
450
end;
451

452
procedure TDerivativesForm.zCapCBClick(Sender: TObject);
453
begin
454
  FormPlotStars.ClearAddedLines;
455
  AddedData.zCap := zCapCB.Checked;
456
//ApplyBtn.Visible := AddedData.AddedAs = AddVolume;
457
end;
458

459
procedure TDerivativesForm.zLimitCBClick(Sender: TObject);
460
begin
461
  AddedData.zLim := zLimitCB.Checked;
462
//ApplyBtn.Visible := AddedData.AddedAs = AddVolume;
463
end;
464

465
procedure TDerivativesForm.ApplyBtnClick(Sender: TObject);
466
var
467
  v: TGLFloat;
468
  s: string;
469

470
begin
471
  if TooManyPoints then Exit;
472

473
  Screen.Cursor := crHourGlass;
474
  with AddedData do
475
  begin
476
    if xMin > xMax then  { swap }
477
    begin
478
      v := xMin;
479
      xMin := xMax;
480
      xMax := v;
481
      s := EditMinX.Text;
482
      EditMinX.Text := EditMaxX.Text;
483
      EditMaxX.Text := s;
484
    end;
485
    if yMin > yMax then  { swap }
486
    begin
487
      v := yMin;
488
      yMin := yMax;
489
      yMax := v;
490
      s := EditMinY.Text;
491
      EditMinY.Text := EditMaxY.Text;
492
      EditMaxY.Text := s;
493
    end;
494
    if zMin > zMax then  { swap }
495
    begin
496
      v := zMin;
497
      zMin := zMax;
498
      zMax := v;
499
      s := EditMinZ.Text;
500
      EditMinZ.Text := EditMaxZ.Text;
501
      EditMaxZ.Text := s;
502
    end;
503

504
    if DerivXRB.Checked then AddedAs := AddDerivX else
505
    if DerivYRB.Checked then AddedAs := AddDerivY else
506
    if VolumeRB.Checked then AddedAs := AddVolume;
507
  end;
508

509
  PosVolLabel.Caption := '';
510
  NegVolLabel.Caption := '';
511
  TotalLabel.Caption := '';
512
  VolumeLabel.Caption := '';
513
  FormPlotStars.ClearAddedField;
514
  FormPlotStars.ClearAddedLines;
515
  FormPlotStars.UpdateAdded;
516
  EvaluateForm.UpdateEvaluate;
517
  ApplyBtn.Visible := False;
518
  Screen.Cursor := crDefault;
519
end;
520

521
procedure TDerivativesForm.CloseBtnClick(Sender: TObject);
522
begin
523
  Close;
524
end;
525

526
procedure TDerivativesForm.ColorButtonClick(Sender: TObject);
527
begin
528
  ColorDialog.Color := AddedData.AddLineColor;
529
  if ColorDialog.Execute then
530
  begin
531
    AddedData.AddLineColor := ColorDialog.Color;
532

533
    with FormPlotStars do
534
    begin
535
      with AddXLine do LineColor.AsWinColor := AddedData.AddLineColor;
536
      with AddYLine do LineColor.AsWinColor := AddedData.AddLineColor;
537
      with AddZLine do LineColor.AsWinColor := AddedData.AddLineColor;
538
    end;
539

540
    DerivativeAltered := True;
541
    ApplyBtnClick(Sender);
542
  end;
543
end;
544

545
procedure TDerivativesForm.CountzPoints;
546
var
547
  n, c: integer;
548

549
begin
550
  with AddedData do
551
  n := round((xMax - xMin)/xInc +1)*round((yMax - yMin)/yInc +1);
552
  c := round(Log10(n));
553
  case c of
554
  0..1:ZCountLabel.Font.Color := clLime;
555
     2:ZCountLabel.Font.Color := clTeal;
556
     3:ZCountLabel.Font.Color := clGreen;
557
     4:ZCountLabel.Font.Color := clBlue;
558
  else ZCountLabel.Font.Color := clRed;
559
  end;
560
  TooManyPoints := c > 4;
561
  if TooManyPoints then
562
  ZCountLabel.Caption := 'Too many Points: ' + FloatToStrF(n, ffnumber, 8, 0)+' !'
563
  else ZCountLabel.Caption := 'N� Points = ' + FloatToStrF(n, ffnumber, 8, 0);
564
end;
565

566
end.
567

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

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

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

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