MathgeomGLS

Форк
0
/
fGridOpts.pas 
677 строк · 16.6 Кб
1
unit fGridOpts;
2

3
interface
4

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

23
  uParser,
24
  uGlobal;
25

26
type
27
  TGridOptionsForm = class(TForm)
28
    Label1: TLabel;
29
    Label2: TLabel;
30
    Label3: TLabel;
31
    Label4: TLabel;
32
    Label5: TLabel;
33
    Label6: TLabel;
34
    Label7: TLabel;
35
    Label8: TLabel;
36
    Label9: TLabel;
37
    Label10: TLabel;
38

39
    EditMinY: TEdit;
40
    EditMinX: TEdit;
41
    EditMaxX: TEdit;
42
    EditMaxY: TEdit;
43

44
    SpeedButton1: TSpeedButton;
45
    SpeedButton2: TSpeedButton;
46
    SpeedButton3: TSpeedButton;
47
    SpeedButton4: TSpeedButton;
48
    SpeedButton5: TSpeedButton;
49
    SpeedButton6: TSpeedButton;
50
    SpeedButton7: TSpeedButton;
51
    SpeedButton8: TSpeedButton;
52

53
    EditAxesPen: TEdit;
54
    UpDown1: TUpDown;
55
    EditMajorGrid: TEdit;
56
    UpDown2: TUpDown;
57
    EditMinorGrid: TEdit;
58
    UpDown3: TUpDown;
59

60
    GridStyles: TRadioGroup;
61
    xTrackBar: TTrackBar;
62
    yTrackBar: TTrackBar;
63

64
    BitBtn1: TBitBtn;
65
    ApplyBitBtn: TBitBtn;
66
    ColorDialog: TColorDialog;
67
    FontDialog: TFontDialog;
68
    LogXCheck: TCheckBox;
69
    LogYCheck: TCheckBox;
70
    SaveSpeedButton: TSpeedButton;
71
    RestoreSpeedButton: TSpeedButton;
72
    procedure FormShow(Sender: TObject);
73
    procedure BitBtn1Click(Sender: TObject);
74
    procedure ApplyBitBtnClick(Sender: TObject);
75

76
    procedure EditMinXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
77
    procedure EditMaxXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
78
    procedure EditMinYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
79
    procedure EditMaxYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
80
    procedure EditPenKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
81
    procedure EditPenChange(Sender: TObject);
82

83
    procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
84

85
    procedure ParseKeyPress(Sender: TObject; var Key: Char);
86
    procedure IntKeyPress(Sender: TObject; var Key: Char);
87

88
    procedure GridStylesClick(Sender: TObject);
89
    procedure ColorClick(Sender: TObject);
90
    procedure FontClick(Sender: TObject);
91
    procedure LogXCheckClick(Sender: TObject);
92
    procedure LogYCheckClick(Sender: TObject);
93

94
    procedure Centre(Sender: TObject);
95
    procedure EqualGrad(Sender: TObject);
96
    procedure EqualRange(Sender: TObject);
97
    procedure xTrackBarChange(Sender: TObject);
98
    procedure yTrackBarChange(Sender: TObject);
99
    procedure SaveSpeedButtonClick(Sender: TObject);
100
    procedure RestoreSpeedButtonClick(Sender: TObject);
101
  private
102
     
103
    function AnyPolar: Boolean;
104
  public
105
     
106
    procedure ShowData;
107
  end;
108

109
var
110
  GridOptionsForm: TGridOptionsForm;
111

112
//========================================================================
113
implementation
114
//========================================================================
115

116
uses
117
  fPlot1D,
118
  fTextBlocks,
119
  fFuncts;
120

121
{$R *.dfm}
122

123
procedure TGridOptionsForm.FormShow(Sender: TObject);
124
begin
125
  Caption := GraphFName;
126
  ShowData;
127
end;
128

129
procedure TGridOptionsForm.BitBtn1Click(Sender: TObject);
130
begin
131
  Close;
132
end;
133

134
procedure TGridOptionsForm.ApplyBitBtnClick(Sender: TObject);
135
  procedure Swap(var n1, n2: extended);
136
  var
137
    n: extended;
138

139
  begin
140
    n := n1;
141
    n1 := n2;
142
    n2 := n;
143
  end;
144

145
begin
146
  with GraphData do
147
  begin
148
    if xMin = xMax then xMax := 1.1*xMin;
149
    if yMin = yMax then yMax := 1.1*yMin;
150
    if xMin > xMax then Swap(xMin, xMax);
151
    if yMin > yMax then Swap(yMin, yMax);
152
  end;
153

154
  Altered := True;
155
  MainForm.GLViewer.Invalidate;
156
  ApplyBitBtn.Visible := False;
157
end;
158

159
procedure TGridOptionsForm.EditMinXKeyUp(Sender: TObject; var Key: Word;
160
                                          Shift: TShiftState);
161
var
162
  x: extended;
163
  s: string;
164
  e: byte;
165

166
begin
167
  with GraphData do
168
  begin
169
    s := ScanText(EditMinX.Text);
170
    x := ParseAndEvaluate(s, e);
171
    if isNAN(x) or isInfinite(x) then x := 0;
172
    if (e = 0) and((Grid.xAxisStyle <> asLog) or (x > 0)) then xMin := x
173
    else if Grid.xAxisStyle = asLog then xMin :=  0.1 else xMin := -0.1;
174
  end;
175
end;
176

177
procedure TGridOptionsForm.EditMinYKeyUp(Sender: TObject; var Key: Word;
178
                                          Shift: TShiftState);
179
var
180
  y: extended;
181
  s: string;
182
  e: byte;
183

184
begin
185
  with GraphData do
186
  begin
187
    s := ScanText(EditMinY.Text);
188
    y := ParseAndEvaluate(s, e);
189
    if isNAN(y) or isInfinite(y) then y := 0;
190
    if (e = 0) and((Grid.yAxisStyle <> asLog) or (y > 0)) then yMin := y
191
    else if Grid.yAxisStyle = asLog then yMin :=  0.1 else yMin := -0.1;
192
  end;
193
end;
194

195
procedure TGridOptionsForm.EditMaxXKeyUp(Sender: TObject; var Key: Word;
196
                                          Shift: TShiftState);
197
var
198
  x: extended;
199
  s: string;
200
  e: byte;
201

202
begin
203
  with GraphData do
204
  begin
205
    s := ScanText(EditMaxX.Text);
206
    x := ParseAndEvaluate(s, e);
207
    if isNAN(x) or isInfinite(x) then x := 0;
208
    if (e = 0) and((Grid.xAxisStyle <> asLog) or (x > 0)) then xMax := x
209
    else xMax := 0.1;
210
  end;
211
end;
212

213
procedure TGridOptionsForm.EditMaxYKeyUp(Sender: TObject; var Key: Word;
214
                                          Shift: TShiftState);
215
var
216
  y: extended;
217
  s: string;
218
  e: byte;
219

220
begin
221
  with GraphData do
222
  begin
223
    s := ScanText(EditMaxY.Text);
224
    y := ParseAndEvaluate(s, e);
225
    if isNAN(y) or isInfinite(y) then y := 0;
226
    if (e = 0) and((Grid.yAxisStyle <> asLog) or (y > 0)) then yMax := y
227
    else yMax := 0.1;
228
  end;
229
end;
230

231
procedure TGridOptionsForm.EditPenKeyUp(Sender: TObject; var Key: Word;
232
                                         Shift: TShiftState);
233
var
234
  w: integer;
235

236
begin
237
  if Active then
238
  with Sender as TEdit do
239
  begin
240
    try
241
      w := StrToInt(Text);
242
    except
243
      w := 1;
244
    end;
245
    if w < 1 then w := 1;
246

247
    with GraphData do
248
    case Tag of
249
    0:AxisWidth := w;
250
    1:MajorWidth := w;
251
    2:MinorWidth := w;
252
    end;
253
    Altered := True;
254
    MainForm.GLViewer.Invalidate;
255
  end;
256
end;
257

258
procedure TGridOptionsForm.EditPenChange(Sender: TObject);
259
var
260
  k: word;
261

262
begin
263
  k := 0;
264
  EditPenKeyUp(Sender, k, []);
265
end;
266

267
procedure TGridOptionsForm.EditKeyDown(Sender: TObject; var Key: Word;
268
                                       Shift: TShiftState);
269
begin
270
  if Active and ((Key = VK_DELETE) or (Key = VK_BACK))
271
  then ApplyBitBtn.Visible := True;
272
end;
273

274
procedure TGridOptionsForm.ParseKeyPress(Sender: TObject; var Key: Char);
275
begin
276
  with Sender as TEdit do
277
  begin
278
    if not CharInSet(UpCase(Key),
279
   [' ', '!', '(', ')', '*', '+', '-', '.', ',', '/', '0'..'9',
280
    'A'..'C', 'E', 'G'..'I', 'L', 'N'..'T', 'X', '^', '`', #8]) then
281
    begin
282
      Key := #0;
283
      Exit;
284
    end
285
    else if Active then ApplyBitBtn.Visible := True;
286
    if Key = '`' then Key := '�';
287
  end;
288
end;
289

290
procedure TGridOptionsForm.IntKeyPress(Sender: TObject; var Key: Char);
291
begin
292
  with Sender as TEdit do
293
  if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
294
end;
295

296
procedure TGridOptionsForm.xTrackBarChange(Sender: TObject);
297
begin
298
  if Active then with GraphData do
299
  begin
300
    if xTrackBar.Position > 10
301
    then xMinorGrad := 10*(xTrackBar.Position - 10)
302
    else xMinorGrad := xTrackBar.Position;
303
    xMajorGrad := 10*xMinorGrad;
304
    Altered := True;
305
    MainForm.GLViewer.Invalidate;
306
  end;
307
end;
308

309
procedure TGridOptionsForm.yTrackBarChange(Sender: TObject);
310
begin
311
  if Active then with GraphData do
312
  begin
313
    if yTrackBar.Position > 10
314
    then yMinorGrad := 10*(yTrackBar.Position - 10)
315
    else yMinorGrad := yTrackBar.Position;
316
    yMajorGrad := 10*yMinorGrad;
317
    Altered := True;
318
    MainForm.GLViewer.Invalidate;
319
  end;
320
end;
321

322
procedure TGridOptionsForm.GridStylesClick(Sender: TObject);
323
begin
324
  if Active then
325
  begin
326
    with GridStyles, GraphData do Grid.GridStyle := TGridStyle(ItemIndex);
327
    Altered := True;
328
    MainForm.GLViewer.Invalidate;
329
  end;
330
end;
331

332
procedure TGridOptionsForm.ColorClick(Sender: TObject);
333
begin
334
  with GraphData do
335
  begin
336
    case TSpeedButton(Sender).Tag of
337
    0:ColorDialog.Color := BackColor;
338
    1:ColorDialog.Color := GridColor;
339
    2:ColorDialog.Color := xAxisColor;
340
    3:ColorDialog.Color := yAxisColor;
341
    end;
342
    if ColorDialog.Execute then
343
    begin
344
      case TSpeedButton(Sender).Tag of
345
      0:begin
346
          BackColor := ColorDialog.Color;
347
          MainForm.GLViewer.Buffer.BackgroundColor := BackColor;
348
          with TextBlocksForm
349
          do if BlockListBox.Count > 0 then RichEdit.Color := BackColor;
350
        end;
351
      1:GridColor := ColorDialog.Color;
352
      2:xAxisColor := ColorDialog.Color;
353
      3:yAxisColor := ColorDialog.Color;
354
      end;
355
      Altered := True;
356
      MainForm.GLViewer.Invalidate;
357
    end;
358
  end;
359
end;
360

361
procedure TGridOptionsForm.FontClick(Sender: TObject);
362
begin
363
  with FontDialog, GraphData do
364
  begin
365
    case TSpeedButton(Sender).Tag of
366
    0:begin
367
        Font.Name := FontName;
368
        Font.Style := FontStyle;
369
        Font.Size := FontSize;
370
      end;
371
    end;
372
    if Execute then
373
    begin
374
      case TSpeedButton(Sender).Tag of
375
      0:begin
376
          FontName := Font.Name;
377
          FontStyle := Font.Style;
378
          FontSize := Font.Size;
379
        end;
380
      end;
381
      Altered := True;
382
      NewFont := True;
383
      MainForm.GLViewer.Invalidate;
384
    end;
385
  end;
386
end;
387

388
procedure TGridOptionsForm.LogXCheckClick(Sender: TObject);
389
var
390
  d: extended;
391

392
begin
393
  if AnyPolar then  { can not use log axes }
394
  begin
395
    LogXCheck.Checked := False;
396
    MainForm.StatusBar.Panels[2].Text := 'One or more Functions are Polar';
397
  end
398
  else
399
  begin
400
    with GraphData do
401
    begin
402
      if LogXCheck.Checked then
403
      begin
404
        with FunctionsForm do
405
        begin
406
          if Integrate2x.Checked then CloseIntegrateXForm;
407
          if Integrate2y.Checked then CloseIntegrateYForm;
408
          if Between1.Checked then CloseBetweenForm;
409
          if Volumex1.Checked then CloseVolumeXForm;
410
          if Volumey1.Checked then CloseVolumeYForm;
411
        end;
412

413
        Grid.xAxisStyle := asLog;
414
        if xMin <= 0 then  { xMin must be +ve }
415
        begin
416
          d := xMax - xMin;
417
          xMin := (xMax - xMin)/MainForm.GLViewer.Width;
418
          xMax := xMin + d;
419
          EditMinX.Text := FloatToStr(xMin);
420
          EditMaxX.Text := FloatToStr(xMax);
421
        end;
422
      end
423
      else Grid.xAxisStyle := asLinear;
424

425
      SpeedButton6.Enabled := (Grid.xAxisStyle = asLinear) and
426
                              (Grid.yAxisStyle = asLinear);
427
      SpeedButton7.Enabled := SpeedButton6.Enabled or
428
                             ((Grid.xAxisStyle = asLog) and
429
                              (Grid.yAxisStyle = asLog));
430
      SpeedButton8.Enabled := SpeedButton6.Enabled or
431
                             ((Grid.xAxisStyle = asLog) and
432
                              (Grid.yAxisStyle = asLog));
433

434
      with FunctionsForm do
435
      begin
436
        SwitchButton.Visible := SpeedButton6.Enabled;
437
        Integrate1.Enabled := SpeedButton6.Enabled;
438
      end;
439
    end;
440
    Altered := True;
441
    MainForm.GLViewer.Invalidate;
442
  end;
443
end;
444

445
procedure TGridOptionsForm.LogYCheckClick(Sender: TObject);
446
var
447
  d: extended;
448

449
begin
450
  if AnyPolar then  { can not use log axes }
451
  begin
452
    LogYCheck.Checked := False;
453
    MainForm.StatusBar.Panels[2].Text := 'One or more Functions are Polar';
454
  end
455
  else
456
  begin
457
    with GraphData do
458
    begin
459
      if LogYCheck.Checked then
460
      begin
461
        with FunctionsForm do
462
        begin
463
          if Integrate2x.Checked then CloseIntegrateXForm;
464
          if Integrate2y.Checked then CloseIntegrateYForm;
465
          if Between1.Checked then CloseBetweenForm;
466
          if Volumex1.Checked then CloseVolumeXForm;
467
          if Volumey1.Checked then CloseVolumeYForm;
468
        end;
469

470
        Grid.yAxisStyle := asLog;
471
        if yMin <= 0 then  { yMin must be +ve }
472
        begin
473
          d := yMax - yMin;
474
          yMin := (yMax - yMin)/MainForm.GLViewer.Height;
475
          yMax := yMin + d;
476
          EditMinY.Text := FloatToStr(yMin);
477
          EditMaxY.Text := FloatToStr(yMax);
478
        end;
479
      end
480
      else Grid.yAxisStyle := asLinear;
481

482
      SpeedButton6.Enabled := (Grid.xAxisStyle = asLinear) and
483
                              (Grid.yAxisStyle = asLinear);
484
      SpeedButton7.Enabled := SpeedButton6.Enabled or
485
                             ((Grid.xAxisStyle = asLog) and
486
                              (Grid.yAxisStyle = asLog));
487
      SpeedButton8.Enabled := SpeedButton6.Enabled or
488
                             ((Grid.xAxisStyle = asLog) and
489
                              (Grid.yAxisStyle = asLog));
490

491
      with FunctionsForm do
492
      begin
493
        SwitchButton.Visible := SpeedButton6.Enabled;
494
        Integrate1.Enabled := SpeedButton6.Enabled;
495
      end;
496
    end;
497
    Altered := True;
498
    MainForm.GLViewer.Invalidate;
499
  end;
500
end;
501

502
procedure TGridOptionsForm.RestoreSpeedButtonClick(Sender: TObject);
503
begin
504
  with GraphData do
505
  begin
506
    if (SavexMin > 0) or (Grid.xAxisStyle = asLinear)
507
    then xMin := SavexMin;
508
    xMax := SavexMax;
509
    if (SaveyMin > 0) or (Grid.yAxisStyle = asLinear)
510
    then yMin := SaveyMin;
511
    yMax := SaveyMax;
512

513
    EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
514
    EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
515
    EditMinY.Text := FloatToStrF(yMin, ffGeneral, 13, 4);
516
    EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 13, 4);
517
  end;
518
  Altered := True;
519
  MainForm.GLViewer.Invalidate;
520
end;
521

522
procedure TGridOptionsForm.Centre(Sender: TObject);
523
var
524
  x, y: extended;
525

526
begin
527
  with GraphData do
528
  begin
529
    x := (xMax - xMin)/2;
530
    xMin := -x;
531
    xMax :=  x;
532

533
    y := (yMax - yMin)/2;
534
    yMin := -y;
535
    yMax :=  y;
536

537
    EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
538
    EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
539
  end;
540

541
  Altered := True;
542
  MainForm.GLViewer.Invalidate;
543
end;
544

545
procedure TGridOptionsForm.EqualGrad(Sender: TObject);
546
var
547
  x, y, r: extended;
548

549
begin
550
  with GraphData do
551
  begin
552
    x := xMax - xMin;
553
    y := yMax - yMin;
554
    r := (x*MainForm.GLViewer.Height)/(y*Mainform.GLViewer.Width);
555

556
    if x > y then
557
    begin
558
      yMax := yMax*r;
559
      yMin := yMin*r;
560
    end
561
    else
562
    begin
563
      xMax := xMax/r;
564
      xMin := xMin/r;
565
    end;
566
    EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
567
    EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
568
  end;
569
  Altered := True;
570
  MainForm.GLViewer.Invalidate;
571
end;
572

573
procedure TGridOptionsForm.EqualRange(Sender: TObject);
574
var
575
  x, y: extended;
576

577
begin
578
  with GraphData do
579
  begin
580
    x := xMax - xMin;
581
    y := yMax - yMin;
582

583
    if x > y then
584
    begin
585
      xMax := yMax;
586
      xMin := yMin;
587
    end
588
    else
589
    begin
590
      yMax := xMax;
591
      yMin := xMin;
592
    end;
593
    EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
594
    EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
595
    EditMinY.Text := FloatToStrF(yMin, ffGeneral, 13, 4);
596
    EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 13, 4);
597
  end;
598
  Altered := True;
599
  MainForm.GLViewer.Invalidate;
600
end;
601

602
function TGridOptionsForm.AnyPolar: Boolean;
603
var
604
  i: integer;
605
  Found: Boolean;
606

607
begin
608
  with FunctionsForm.CheckListBox do
609
  begin
610
    i := 0;
611
    Found := False;
612
    while not Found and (i < Count) do
613
    begin
614
      Found := not TPlotDataObject(Items.Objects[i]).Data.PlotAsFx
615
               and Checked[i];
616
      Inc(i);
617
    end;
618
    Result := Found;
619
  end;
620
end;
621

622
procedure TGridOptionsForm.SaveSpeedButtonClick(Sender: TObject);
623
begin
624
  with GraphData do
625
  begin
626
    SavexMin := xMin;
627
    SavexMax := xMax;
628
    SaveyMin := yMin;
629
    SaveyMax := yMax;
630
    RestoreSpeedButton.Visible := (SavexMin <> SavexMax) and
631
                                  (SaveyMin <> SaveyMax);
632
  end;
633
end;
634

635
procedure TGridOptionsForm.ShowData;
636
var
637
  b: boolean;
638

639
begin
640
  b := Altered;
641

642
  with GraphData do
643
  begin
644
    RestoreSpeedButton.Visible := (SavexMin <> SavexMax) and
645
                                  (SaveyMin <> SaveyMax);
646
    EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
647
    EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
648
    EditMinY.Text := FloatToStrF(yMin, ffGeneral, 13, 4);
649
    EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 13, 4);
650
    if Active then
651
    ApplyBitBtn.Visible := False;
652

653
    UpDown1.Position := AxisWidth;
654
    UpDown2.Position := MajorWidth;
655
    UpDown3.Position := MinorWidth;
656
    GridStyles.ItemIndex := Ord(Grid.GridStyle);
657

658
    LogXCheck.Checked := Grid.xAxisStyle = asLog;
659
    LogYCheck.Checked := Grid.yAxisStyle = asLog;
660

661
    SpeedButton6.Enabled := not(LogXCheck.Checked or LogYCheck.Checked);
662
    SpeedButton7.Enabled := SpeedButton6.Enabled or
663
                          ((Grid.xAxisStyle = asLog) and
664
                           (Grid.yAxisStyle = asLog));
665
    SpeedButton8.Enabled := SpeedButton6.Enabled or
666
                          ((Grid.xAxisStyle = asLog) and
667
                           (Grid.yAxisStyle = asLog));
668

669
    Label9.Font.Color := xAxisColor;
670
    Label10.Font.Color := yAxisColor;
671
    xTrackBar.Position := xMinorGrad;
672
    yTrackBar.Position := yMinorGrad;
673
  end;
674
  Altered := b;
675
end;
676

677
end.
678

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

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

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

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