MathgeomGLS

Форк
0
2205 строк · 56.9 Кб
1
unit faFunc1d;
2

3
interface
4

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

27
  Graf.Global1d,
28
  Graf.Parser1d;
29

30
type
31
  TFunctionsForm = class(TForm)
32
    MainMenu: TMainMenu;
33
    File1: TMenuItem;
34
    New1: TMenuItem;
35
    Label1: TLabel;
36
    Label2: TLabel;
37
    Label3: TLabel;
38
    Label4: TLabel;
39
    Label5: TLabel;
40
    Label6: TLabel;
41
    Label7: TLabel;
42
    Label8: TLabel;
43
    Label9: TLabel;
44
    Label10: TLabel;
45
    Label11: TLabel;
46
    Label12: TLabel;
47
    LabelPhi: TLabel;
48
    Labeldx: TLabel;
49
    Labelx: TLabel;
50
    Labely: TLabel;
51
    LabelRCos: TLabel;
52
    LabelRSin: TLabel;
53
    LabelFunc: TLabel;
54
    EditSegMin: TEdit;
55
    EditSegMax: TEdit;
56
    Editdx: TEdit;
57
    UpDown1: TUpDown;
58
    EditLocX: TEdit;
59
    EditLocY: TEdit;
60
    ShowLabelCheckBox: TCheckBox;
61
    ContinuousCheckBox: TCheckBox;
62
    EditPen: TEdit;
63
    UpDown2: TUpDown;
64
    EditCoordinate: TEdit;
65
    UpDown3: TUpDown;
66
    EditEvaluate: TEdit;
67
    Editfx: TEdit;
68
    SwitchButton: TSpeedButton;
69
    SegmentButton: TSpeedButton;
70
    sbPenColor: TSpeedButton;
71
    SpeedButton4: TSpeedButton;
72
    EvaluateButton: TSpeedButton;
73
    AddButton: TSpeedButton;
74
    DeleteButton: TSpeedButton;
75
    UpButton: TSpeedButton;
76
    DownButton: TSpeedButton;
77
    CheckListBox: TCheckListBox;
78
    BitBtn2: TBitBtn;
79
    ColorDialog: TColorDialog;
80
    Open1: TMenuItem;
81
    Save1: TMenuItem;
82
    Saveas1: TMenuItem;
83
    Derivatives1: TMenuItem;
84
    yfx1: TMenuItem;
85
    yfx2: TMenuItem;
86
    Integrate1: TMenuItem;
87
    Integrate2x: TMenuItem;
88
    Integrate2y: TMenuItem;
89
    Between1: TMenuItem;
90
    Volumex1: TMenuItem;
91
    Volumey1: TMenuItem;
92
    SaveDialog: TSaveDialog;
93
    OpenDialog: TOpenDialog;
94
    ImageList1: TImageList;
95
    Findx: TMenuItem;
96
    fxValue: TMenuItem;
97
    fx1Value: TMenuItem;
98
    fx2Value: TMenuItem;
99
    PenPanel: TPanel;
100
    CoordPanel: TPanel;
101
    N1: TMenuItem;
102
    Exit1: TMenuItem;
103
    CoordPointButton: TSpeedButton;
104
    procedure FormDestroy(Sender: TObject);
105
    procedure FormShow(Sender: TObject);
106
    procedure ParseKeyPress(Sender: TObject; var Key: Char);
107
    procedure IntKeyPress(Sender: TObject; var Key: Char);
108
    procedure fxKeyPress(Sender: TObject; var Key: Char);
109
    procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
110
    procedure EditSegMinKeyUp(Sender: TObject; var Key: Word;
111
      Shift: TShiftState);
112
    procedure EditSegMaxKeyUp(Sender: TObject; var Key: Word;
113
      Shift: TShiftState);
114
    procedure EditdxKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
115
    procedure EditdxChange(Sender: TObject);
116
    procedure EditLocXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
117
    procedure EditLocYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
118
    procedure EditPenKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
119
    procedure EditPenChange(Sender: TObject);
120
    procedure EvaluateKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
121
    procedure EditfxKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
122
    procedure NewClick(Sender: TObject);
123
    procedure OpenClick(Sender: TObject);
124
    procedure SaveClick(Sender: TObject);
125
    procedure SaveAsClick(Sender: TObject);
126
    procedure yfx1Click(Sender: TObject);
127
    procedure yfx2Click(Sender: TObject);
128
    procedure Integrate2xClick(Sender: TObject);
129
    procedure Integrate2yClick(Sender: TObject);
130
    procedure Between1Click(Sender: TObject);
131
    procedure Volumex1Click(Sender: TObject);
132
    procedure Volumey1Click(Sender: TObject);
133
    procedure fxValueClick(Sender: TObject);
134
    procedure fx1ValueClick(Sender: TObject);
135
    procedure fx2ValueClick(Sender: TObject);
136
    procedure SwitchClick(Sender: TObject);
137
    procedure SegmentClick(Sender: TObject);
138
    procedure ShowLabelClick(Sender: TObject);
139
    procedure ContinuousClick(Sender: TObject);
140
    procedure ColorClick(Sender: TObject);
141
    procedure EvaluateClick(Sender: TObject);
142
    procedure LabelyClick(Sender: TObject);
143
    procedure LabelRCosClick(Sender: TObject);
144
    procedure LabelRSinClick(Sender: TObject);
145
    procedure CheckListBoxClick(Sender: TObject);
146
    procedure AddButtonClick(Sender: TObject);
147
    procedure DeleteButtonClick(Sender: TObject);
148
    procedure BitBtn2Click(Sender: TObject);
149
    procedure BitBtn1Click(Sender: TObject);
150
    procedure UpButtonClick(Sender: TObject);
151
    procedure DownButtonClick(Sender: TObject);
152
    procedure CheckListBoxClickCheck(Sender: TObject);
153
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
154
    procedure Exit1Click(Sender: TObject);
155
    procedure CoordPointButtonClick(Sender: TObject);
156
    procedure FormCreate(Sender: TObject);
157
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
158
  private
159
    NewFile: Boolean;
160
    x1, x2: extended;
161
    function ReadData(const FName: TFileName): Boolean;
162
    procedure WriteData(const FName: TFileName);
163
    function DefaultData: TGraphData;
164
    procedure ShowData(Sender: TObject);
165
    procedure OpenSelectedFile(Sender: TObject; FName: TFileName);
166
    procedure ClosefxValueForm;
167
    procedure Closefx1ValueForm;
168
    procedure Closefx2ValueForm;
169
  public
170
    procedure ShowCartesianEvaluate;
171
    procedure ShowPolarEvaluate;
172
    procedure CloseIntegrateXForm;
173
    procedure CloseIntegrateYForm;
174
    procedure CloseBetweenForm;
175
    procedure CloseVolumeXForm;
176
    procedure CloseVolumeYForm;
177
  end;
178

179
var
180
  FunctionsForm: TFunctionsForm;
181

182
// =====================================================================
183
implementation
184
// =====================================================================
185

186
uses
187
  faGraf1D,
188
  faGridOpt1d,
189
  faDerivative,
190
  faIntegrateX,
191
  faIntegrateY,
192
  faBetween,
193
  faVolumeX,
194
  faVolumeY,
195
  faValueX,
196
  faValueX1,
197
  faValueX2,
198
  faTextBlocks,
199
  faNumeric;
200

201
{$R *.dfm}
202

203
procedure TFunctionsForm.FormClose(Sender: TObject; var Action: TCloseAction);
204
var
205
  i: integer;
206
begin
207
    for i := 0 to CheckListBox.Items.Count - 1 do
208
    CheckListBox.Items.Objects[i].Free;
209
  CheckListBox.Clear;
210
end;
211

212
procedure TFunctionsForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
213
begin
214
  MainForm.Close;
215
end;
216

217
procedure TFunctionsForm.FormCreate(Sender: TObject);
218
begin
219
  ReportMemoryLeaksOnShutdown := True;
220
end;
221

222
procedure TFunctionsForm.FormDestroy(Sender: TObject);
223
var
224
  i: integer;
225

226
begin
227
  with CheckListBox do
228
    for i := 0 to Count - 1 do
229
      Items.Objects[i].Free;
230
end;
231

232
procedure TFunctionsForm.FormShow(Sender: TObject);
233
begin
234
  if not ReadData(DataPath + GraphFName) then
235
  begin
236
    GraphFName := NewFName;
237
    NewFile := True;
238
    GraphData := DefaultData;
239

240
    with GraphData, CheckListBox do
241
    begin
242
      AddItem(PlotData.TextStr, TPlotDataObject.Create(PlotData));
243
      ItemIndex := Count - 1;
244
      Checked[ItemIndex] := True; // initially this item is checked
245
    end;
246
  end;
247

248
  Caption := GraphFName;
249
  ShowData(Sender);
250
  if GridOptionsForm.Visible then
251
    GridOptionsForm.ShowData;
252
end;
253

254
procedure TFunctionsForm.ParseKeyPress(Sender: TObject; var Key: Char);
255
begin
256
  with Sender as TEdit do
257
  begin
258
    if not CharInSet(UpCase(Key), [' ', '!', '(', ')', '*', '+', '-', '.', ',',
259
      '/', '0' .. '9', 'A' .. 'C', 'E', 'G' .. 'I', 'L', 'N' .. 'T', 'X', '^',
260
      '`', #8]) then
261
    begin
262
      Key := #0;
263
      Exit;
264
    end
265
    else if Active then
266
      BitBtn2.Visible := True;
267
    if Key = '`' then
268
      Key := '�';
269
  end;
270
  Altered := True;
271
end;
272

273
procedure TFunctionsForm.IntKeyPress(Sender: TObject; var Key: Char);
274
begin
275
  with Sender as TEdit do
276
    if not CharInSet(Key, ['0' .. '9', #8]) then
277
      Key := #0
278
end;
279

280
procedure TFunctionsForm.fxKeyPress(Sender: TObject; var Key: Char);
281
begin
282
  with Sender as TEdit do
283
  begin
284
    if not CharInSet(UpCase(Key), [' ', '!', '(', ')', '*', '+', '-', '.', ',',
285
      '/', '0' .. '9', 'A' .. 'C', 'E', 'G' .. 'I', 'L', 'N' .. 'T', 'X', '\',
286
      '^', '`', #8]) then
287
    begin
288
      Key := #0;
289
      Exit;
290
    end;
291

292
    if not GraphData.PlotData.PlotAsFx and
293
      ((Key = '\') or (Key = 'x') or (Key = 'X')) then
294
      Key := '�';
295
    if Key = '`' then
296
      Key := '�';
297
  end;
298
  Altered := True;
299
end;
300

301
procedure TFunctionsForm.EditKeyDown(Sender: TObject; var Key: Word;
302
  Shift: TShiftState);
303
begin
304
  if (Key = VK_DELETE) or (Key = VK_BACK) then
305
    Altered := True;
306
end;
307

308
procedure TFunctionsForm.EditSegMinKeyUp(Sender: TObject; var Key: Word;
309
  Shift: TShiftState);
310
var
311
  s: string;
312
  e: byte;
313

314
begin
315
  s := ScanText(EditSegMin.Text);
316
  x1 := ParseAndEvaluate(s, e);
317
  if isNAN(x1) or isInfinite(x1) or (e > 0) then
318
    x1 := -Pi;
319
  if Active then
320
    BitBtn2.Visible := True;
321
end;
322

323
procedure TFunctionsForm.EditSegMaxKeyUp(Sender: TObject; var Key: Word;
324
  Shift: TShiftState);
325
var
326
  s: string;
327
  e: byte;
328

329
begin
330
  s := ScanText(EditSegMax.Text);
331
  x2 := ParseAndEvaluate(s, e);
332
  if isNAN(x2) or isInfinite(x2) or (e > 0) then
333
    x2 := Pi;
334
  // if e > 0 then x2 := Pi;
335
  if Active then
336
    BitBtn2.Visible := True;
337
end;
338

339
procedure TFunctionsForm.EditdxKeyUp(Sender: TObject; var Key: Word;
340
  Shift: TShiftState);
341
var
342
  e: single;
343

344
begin
345
  if Active then
346
  begin
347
    with GraphData, PlotData do
348
    begin
349
      if PlotAsFx then
350
      begin
351
        try
352
          e := StrToFloat(Editdx.Text);
353
          if e = 0 then
354
            e := 1;
355
          xInc := e;
356
        except
357
          xInc := 1;
358
        end;
359
        TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data.xInc := xInc;
360
      end
361
      else { plotting r = f(�) }
362
      begin
363
        try
364
          e := StrToFloat(Editdx.Text);
365
          if e = 0 then
366
            e := 0.2;
367
          PhiInc := e;
368
        except
369
          PhiInc := 0.2;
370
        end;
371
        if PhiInc < PhiIncMin then
372
          PhiInc := PhiIncMin;
373
        TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data.PhiInc := PhiInc;
374
      end;
375
    end;
376
    MainForm.GLViewer.Invalidate;
377
  end;
378
end;
379

380
procedure TFunctionsForm.EditdxChange(Sender: TObject);
381
var
382
  k: Word;
383
begin
384
  if Active then
385
  begin
386
    k := 0;
387
    EditdxKeyUp(Sender, k, []);
388
  end;
389
end;
390

391
procedure TFunctionsForm.EditLocXKeyUp(Sender: TObject; var Key: Word;
392
  Shift: TShiftState);
393
var
394
  x: extended;
395
begin
396
  try
397
    x := StrToFloat(EditLocX.Text);
398
    with GraphData do
399
    begin
400
      if x > 0.95 * xMax then
401
        x := 0.95 * xMax;
402
      if x < xMin then
403
        x := xMin;
404
    end;
405
  except
406
    x := 0;
407
  end;
408
  TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data.xLabel := x;
409
  GraphData.PlotData.xLabel := x;
410
  MainForm.GLViewer.Invalidate;
411
end;
412

413
procedure TFunctionsForm.EditLocYKeyUp(Sender: TObject; var Key: Word;
414
  Shift: TShiftState);
415
var
416
  y: extended;
417
begin
418
  try
419
    y := StrToFloat(EditLocY.Text);
420
    with GraphData do
421
    begin
422
      if y > yMax then
423
        y := yMax;
424
      if y < 0.95 * yMin then
425
        y := 0.95 * yMin;
426
    end;
427
  except
428
    y := 0;
429
  end;
430
  TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data.yLabel := y;
431
  GraphData.PlotData.yLabel := y;
432
  MainForm.GLViewer.Invalidate;
433
end;
434

435
procedure TFunctionsForm.EditPenKeyUp(Sender: TObject; var Key: Word;
436
  Shift: TShiftState);
437
var
438
  w: integer;
439

440
begin
441
  if Active then
442
    with Sender as TEdit do
443
    begin
444
      try
445
        w := StrToInt(Text);
446
      except
447
        w := 1;
448
      end;
449
      if w < 1 then
450
        w := 1;
451
      with GraphData do
452
        case Tag of
453
          0:
454
            begin // sent from EditPen
455
              PlotData.PlotWidth := w;
456
              with CheckListBox do
457
                TPlotDataObject(Items.Objects[ItemIndex]).Data.PlotWidth := w;
458
            end;
459
          1:
460
            CoordWidth := w; // sent from EditCoordinate
461
        end;
462
      Altered := True;
463
      MainForm.GLViewer.Invalidate;
464
    end;
465
end;
466

467
procedure TFunctionsForm.EditPenChange(Sender: TObject);
468
var
469
  k: Word;
470

471
begin
472
  k := 0;
473
  EditPenKeyUp(Sender, k, []);
474
end;
475

476
procedure TFunctionsForm.EvaluateKeyUp(Sender: TObject; var Key: Word;
477
  Shift: TShiftState);
478
var
479
  s: string;
480
  e: byte;
481

482
begin
483
  if EditEvaluate.Text <> '' then
484
  begin
485
    s := ScanText(EditEvaluate.Text);
486
    xEvaluate := ParseAndEvaluate(s, e);
487
    if e = 0 then
488
      MainForm.GLViewer.Invalidate;
489
  end;
490
end;
491

492
procedure TFunctionsForm.Exit1Click(Sender: TObject);
493
begin
494
  Close;
495
end;
496

497
procedure TFunctionsForm.EditfxKeyUp(Sender: TObject; var Key: Word;
498
  Shift: TShiftState);
499
begin
500
  with TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data do
501
  begin
502
    TextStr := Editfx.Text;
503
    FunctStr := ScanText(TextStr);
504
    GraphData.PlotData.FunctStr := FunctStr;
505
    GraphData.PlotData.TextStr := TextStr;
506
  end;
507
  CheckListBox.Items[CheckListBox.ItemIndex] := Editfx.Text;
508
  MainForm.GLViewer.Invalidate;
509
end;
510

511
procedure TFunctionsForm.NewClick(Sender: TObject);
512
var
513
  i: integer;
514

515
begin
516
  if Altered then
517
    case MessageDlg('The current graph data has been altered.' +
518
      #13#10'Do you wish to save the alterations ?', mtConfirmation,
519
      [mbYes, mbNo, mbCancel], 0) of
520
      mrYes:
521
        SaveClick(Sender);
522
      mrCancel:
523
        Exit;
524
    end;
525

526
  for i := 0 to CheckListBox.Items.Count - 1 do
527
    CheckListBox.Items.Objects[i].Free;
528
  CheckListBox.Clear;
529

530
  GraphFName := NewFName;
531
  Caption := GraphFName;
532
  MainForm.Caption := GraphFName;
533
  GridOptionsForm.Caption := GraphFName;
534
  NumericForm.Caption := GraphFName;
535
  NumericForm.ClearCheckListBox;
536
  NumericForm.DataListBox.Clear;
537
  NumericForm.ShowData(Sender);
538
  TextBlocksForm.Caption := GraphFName;
539

540
  NewFile := True;
541
  Altered := True;
542
  GraphData := DefaultData;
543

544
  with GraphData do
545
    CheckListBox.AddItem(PlotData.TextStr, TPlotDataObject.Create(PlotData));
546

547
  CheckListBox.ItemIndex := 0;
548
  CheckListBox.Checked[CheckListBox.ItemIndex] := True;
549
  ShowData(Sender);
550
  GridOptionsForm.ShowData;
551
  GridOptionsForm.ApplyBitBtn.Visible := false;
552
  TextBlocksForm.ClearTextBlocks;
553
  (*
554
    NewFont needed to initialize GLWinFont.GetCharWidth
555
    if the font has been altered, which may or may not be the case,
556
    so do it anyway
557
  *)
558
  NewFont := True;
559
  MainForm.GLViewer.Invalidate;
560
end;
561

562
procedure TFunctionsForm.OpenClick(Sender: TObject);
563
begin
564
  if Altered then
565
    case MessageDlg('��������� ������� ���� ��������' +
566
      #13#10'��������� ��������� ?', mtConfirmation,
567
      [mbYes, mbNo, mbCancel], 0) of
568
      mrYes:
569
        SaveClick(Sender);
570
      mrCancel:
571
        Exit;
572
      mrNo:
573
        begin
574
          Altered := false;
575
          NewFile := false;
576
        end
577
    end;
578

579
  OpenDialog.InitialDir := DataPath;
580
  if OpenDialog.Execute then
581
  begin
582
    DataPath := ExtractFilePath(OpenDialog.FileName);
583
    DataPath := IncludeTrailingPathDelimiter(DataPath);
584
    MainForm.oMousex := -1;
585
    OpenSelectedFile(Sender, OpenDialog.FileName);
586
  end;
587
end;
588

589
procedure TFunctionsForm.SaveClick(Sender: TObject);
590
begin
591
  if NewFile then
592
    SaveAsClick(Sender)
593
  else
594
    WriteData(DataPath + GraphFName);
595
end;
596

597
procedure TFunctionsForm.SaveAsClick(Sender: TObject);
598
begin
599
  SaveDialog.InitialDir := DataPath;
600
  SaveDialog.FileName := GraphFName;
601
  if SaveDialog.Execute then
602
  begin
603
    GraphFName := ExtractFileName(SaveDialog.FileName);
604
    DataPath := ExtractFilePath(SaveDialog.FileName);
605
    DataPath := IncludeTrailingPathDelimiter(DataPath);
606
    WriteData(DataPath + GraphFName);
607
  end;
608
  Caption := GraphFName;
609
  MainForm.Caption := GraphFName;
610
  GridOptionsForm.Caption := GraphFName;
611
  NumericForm.Caption := GraphFName;
612
  TextBlocksForm.Caption := GraphFName;
613
end;
614

615
procedure TFunctionsForm.yfx1Click(Sender: TObject);
616
begin
617
  if yfx1.Checked then
618
  begin
619
    DerivativeForm.Show;
620
    yfx1.ImageIndex := -1;
621
    CheckListBoxClick(Sender);
622
  end
623
  else
624
  begin
625
    if yfx2.Checked then
626
      yfx2.Checked := false;
627
    yfx1.ImageIndex := 1;
628
    yfx2.ImageIndex := 2;
629
    with DerivativeForm do
630
      if Visible then
631
        Close;
632
  end;
633
  MainForm.GLViewer.Invalidate;
634
end;
635

636
procedure TFunctionsForm.yfx2Click(Sender: TObject);
637
begin
638
  if yfx2.Checked then
639
  begin
640
    if not yfx1.Checked then
641
      yfx1.Checked := True;
642
    with DerivativeForm do
643
      if not Visible then
644
        Show;
645
    yfx1.ImageIndex := -1;
646
    yfx2.ImageIndex := -1;
647
    CheckListBoxClick(Sender);
648
  end
649
  else
650
    yfx2.ImageIndex := 2;
651

652
  DerivativeForm.ShowData;
653
  MainForm.GLViewer.Invalidate;
654
end;
655

656
procedure TFunctionsForm.Integrate2xClick(Sender: TObject);
657
begin
658
  if Integrate2x.Checked then
659
  begin
660
    if Integrate2y.Checked then
661
      CloseIntegrateYForm;
662
    if Between1.Checked then
663
      CloseBetweenForm;
664
    if Volumex1.Checked then
665
      CloseVolumeXForm;
666
    if Volumey1.Checked then
667
      CloseVolumeYForm;
668
    CheckListBoxClick(Sender);
669
    IntegrateXForm.PlotIntegrated := piBoth;
670
    IntegrateXForm.Show;
671
    Integrate2x.ImageIndex := -1;
672
  end
673
  else
674
  begin
675
    Integrate2x.ImageIndex := 4;
676
    IntegrateXForm.Close;
677
    IntegrateXForm.PlotIntegrated := piCalc;
678
    MainForm.GLViewer.Invalidate;
679
  end;
680
end;
681

682
procedure TFunctionsForm.Integrate2yClick(Sender: TObject);
683
begin
684
  if Integrate2y.Checked then
685
  begin
686
    if Integrate2x.Checked then
687
      CloseIntegrateXForm;
688
    if Between1.Checked then
689
      CloseBetweenForm;
690
    if Volumex1.Checked then
691
      CloseVolumeXForm;
692
    if Volumey1.Checked then
693
      CloseVolumeYForm;
694
    CheckListBoxClick(Sender);
695
    IntegrateYForm.Show;
696
    Integrate2y.ImageIndex := -1;
697
  end
698
  else
699
  begin
700
    Integrate2y.ImageIndex := 4;
701
    IntegrateYForm.Close;
702
    MainForm.GLViewer.Invalidate;
703
  end;
704
end;
705

706
procedure TFunctionsForm.Between1Click(Sender: TObject);
707
begin
708
  if CheckListBox.Count < 2 then
709
    Exit;
710

711
  if Between1.Checked then
712
  begin
713
    if Integrate2x.Checked then
714
      CloseIntegrateXForm;
715
    if Integrate2y.Checked then
716
      CloseIntegrateYForm;
717
    if Volumex1.Checked then
718
      CloseVolumeXForm;
719
    if Volumey1.Checked then
720
      CloseVolumeYForm;
721
    with CheckListBox do
722
    begin
723
      ItemIndex := 0;
724
      Checked[0] := True;
725
      Checked[1] := True;
726
    end;
727
    CheckListBoxClick(Sender);
728
    BetweenForm.Show;
729
    Between1.ImageIndex := -1;
730
  end
731
  else
732
  begin
733
    Between1.ImageIndex := 5;
734
    BetweenForm.Close;
735
    MainForm.GLViewer.Invalidate;
736
  end;
737
end;
738

739
procedure TFunctionsForm.Volumex1Click(Sender: TObject);
740
begin
741
  if Volumex1.Checked then
742
  begin
743
    if Integrate2x.Checked then
744
      CloseIntegrateXForm;
745
    if Integrate2y.Checked then
746
      CloseIntegrateYForm;
747
    if Between1.Checked then
748
      CloseBetweenForm;
749
    if Volumey1.Checked then
750
      CloseVolumeYForm;
751
    CheckListBoxClick(Sender);
752
    Volumex1.ImageIndex := -1;
753
    VolumeXForm.Show;
754
  end
755
  else
756
  begin
757
    VolumeXForm.HideFunctionCheckBox.Checked := false;
758
    Volumex1.ImageIndex := 6;
759
    VolumeXForm.Close;
760
    MainForm.GLViewer.Invalidate;
761
  end;
762
end;
763

764
procedure TFunctionsForm.Volumey1Click(Sender: TObject);
765
begin
766
  if Volumey1.Checked then
767
  begin
768
    if Integrate2x.Checked then
769
      CloseIntegrateXForm;
770
    if Integrate2y.Checked then
771
      CloseIntegrateYForm;
772
    if Between1.Checked then
773
      CloseBetweenForm;
774
    if Volumex1.Checked then
775
      CloseVolumeXForm;
776
    CheckListBoxClick(Sender);
777
    Volumey1.ImageIndex := -1;
778
    VolumeYForm.Show;
779
  end
780
  else
781
  begin
782
    VolumeYForm.HideFunctionCheckBox.Checked := false;
783
    Volumey1.ImageIndex := 7;
784
    VolumeYForm.Close;
785
    MainForm.GLViewer.Invalidate;
786
  end;
787
end;
788

789
procedure TFunctionsForm.fxValueClick(Sender: TObject);
790
begin
791
  if fxValue.Checked then
792
  begin
793
    if fx1Value.Checked then
794
      Closefx1ValueForm;
795
    if fx2Value.Checked then
796
      Closefx2ValueForm;
797
    CheckListBoxClick(Sender);
798
    fxValue.ImageIndex := -1;
799
    fxValueForm.Show;
800
  end
801
  else
802
  begin
803
    fxValue.ImageIndex := 0;
804
    fxValueForm.Close;
805
  end;
806
end;
807

808
procedure TFunctionsForm.fx1ValueClick(Sender: TObject);
809
begin
810
  if fx1Value.Checked then
811
  begin
812
    if fxValue.Checked then
813
      ClosefxValueForm;
814
    if fx2Value.Checked then
815
      Closefx2ValueForm;
816
    CheckListBoxClick(Sender);
817
    fx1Value.ImageIndex := -1;
818
    fx1ValueForm.Show;
819
  end
820
  else
821
  begin
822
    fx1ValueForm.Close;
823
    fx1Value.ImageIndex := 1;
824
  end;
825
end;
826

827
procedure TFunctionsForm.fx2ValueClick(Sender: TObject);
828
begin
829
  if fx2Value.Checked then
830
  begin
831
    if fxValue.Checked then
832
      ClosefxValueForm;
833
    if fx1Value.Checked then
834
      Closefx1ValueForm;
835
    CheckListBoxClick(Sender);
836
    fx2Value.ImageIndex := -1;
837
    fx2ValueForm.Show;
838
  end
839
  else
840
  begin
841
    fx2ValueForm.Close;
842
    fx2Value.ImageIndex := 2;
843
  end;
844
end;
845

846
procedure TFunctionsForm.SwitchClick(Sender: TObject);
847
begin
848
  with CheckListBox do
849
    GraphData.PlotData := TPlotDataObject(Items.Objects[ItemIndex]).Data;
850

851
  with GraphData, PlotData do
852
  begin
853
    with SwitchButton do
854
    begin
855
      PlotAsFx := Tag = 1;
856
      Tag := (Tag + 1) mod 2;
857
    end;
858

859
    if not PlotAsFx and ((SegMax - SegMin) / PhiInc > 1E6) then
860
    begin
861
      MessageDlg('The current graph data'#13#10 +
862
        'can not be plotted as y = f(�).'#13#10 + 'The range is too large.',
863
        mtError, [mbOK], 0);
864
      SwitchButton.Tag := 0;
865
      PlotAsFx := True;
866
      Exit;
867
    end;
868

869
    with CheckListBox do
870
      TPlotDataObject(Items.Objects[ItemIndex]).Data.PlotAsFx := PlotAsFx;
871
  end;
872

873
  CheckListBoxClick(Sender);
874
  Altered := True;
875
end;
876

877
procedure TFunctionsForm.SegmentClick(Sender: TObject);
878
begin
879
  with GraphData.PlotData do
880
  begin
881
    with SegmentButton do
882
    begin
883
      IsSegment := Tag = 1;
884
      Tag := (Tag + 1) mod 2;
885
    end;
886
    with CheckListBox do
887
      TPlotDataObject(Items.Objects[ItemIndex]).Data.IsSegment := IsSegment;
888
  end;
889
  CheckListBoxClick(Sender);
890
end;
891

892
procedure TFunctionsForm.ShowLabelClick(Sender: TObject);
893
begin
894
  Label7.Visible := ShowLabelCheckBox.Checked;
895
  EditLocX.Visible := ShowLabelCheckBox.Checked;
896
  EditLocY.Visible := ShowLabelCheckBox.Checked;
897
  GraphData.PlotData.ShowLabel := ShowLabelCheckBox.Checked;
898
  with CheckListBox do
899
    TPlotDataObject(Items.Objects[ItemIndex]).Data.ShowLabel :=
900
      GraphData.PlotData.ShowLabel;
901
  Altered := True;
902
  MainForm.GLViewer.Invalidate;
903
end;
904

905
procedure TFunctionsForm.ContinuousClick(Sender: TObject);
906
begin
907
  GraphData.PlotData.IsContinuous := ContinuousCheckBox.Checked;
908
  with CheckListBox do
909
    TPlotDataObject(Items.Objects[ItemIndex]).Data.IsContinuous :=
910
      GraphData.PlotData.IsContinuous;
911
  Altered := True;
912
  MainForm.GLViewer.Invalidate;
913
end;
914

915
procedure TFunctionsForm.CoordPointButtonClick(Sender: TObject);
916
var
917
  k: Word;
918

919
begin
920
  if (NumericForm.CheckListBox.Count > 0) and
921
    (NumericForm.CheckListBox.ItemIndex > -1) and
922
    (NumericForm.CheckListBox.ItemIndex < NumericForm.CheckListBox.Count) and
923
    (NumericForm.InputRG.ItemIndex = 0) then
924
  begin
925
    if (Labely.Caption = 'y = Infinitely positive') or
926
      (Labely.Caption = 'y = Undefined') then
927
    begin
928
      Beep;
929
      Exit;
930
    end;
931
    k := VK_RETURN;
932
    if SwitchButton.Tag = 0 then
933
    begin
934
      NumericForm.EditXCoord.Text := EditEvaluate.Text;
935
      NumericForm.EditYCoord.Text :=
936
        Copy(Labely.Caption, pos('=', Labely.Caption) + 2,
937
        Length(Labely.Caption));
938
    end
939
    else
940
    begin
941
      if NumericForm.CoordsRG.ItemIndex = 1 then // .RadialCheckBox.Checked then
942
      begin
943
        NumericForm.EditXCoord.Text := EditEvaluate.Text;
944
        NumericForm.EditYCoord.Text :=
945
          Copy(Labely.Caption, pos('=', Labely.Caption) + 2,
946
          Length(Labely.Caption));
947
      end
948
      else
949
      begin
950
        NumericForm.EditXCoord.Text := Copy(LabelRCos.Caption,
951
          pos('=', LabelRCos.Caption) + 2, Length(LabelRCos.Caption));
952
        NumericForm.EditYCoord.Text := Copy(LabelRSin.Caption,
953
          pos('=', LabelRSin.Caption) + 2, Length(LabelRSin.Caption));
954
      end;
955
    end;
956
    NumericForm.EditXCoord.SetFocus;
957
    NumericForm.EditXCoordKeyUp(Sender, k, []);
958
    NumericForm.EditYCoordKeyUp(Sender, k, []);
959
  end
960
  else
961
    MessageDlg('The data for the coordinate can not' +
962
      #13#10'be entered in the Numeric data form' +
963
      #13#10'as the settings are not correct.' +
964
      #13#10'Select ''Adding'' for ''Input Options''.', mtInformation,
965
      [mbOK], 0);
966
end;
967

968
procedure TFunctionsForm.ColorClick(Sender: TObject);
969
var
970
  i: integer;
971

972
begin
973
  with GraphData do
974
  begin
975
    if Sender.ClassType = TPanel then
976
      i := TPanel(Sender).Tag
977
    else
978
      i := TSpeedButton(Sender).Tag;
979

980
    case i of
981
      0:
982
         ColorDialog.Color := TPlotDataObject(CheckListBox.Items.Objects[
983
           CheckListBox.ItemIndex]).Data.PlotColor;
984
      1:
985
        ColorDialog.Color := CoordColor;
986
    end;
987
    if ColorDialog.Execute then
988
    begin
989
      case TSpeedButton(Sender).Tag of
990
        0:
991
          begin
992
            PlotData.PlotColor := ColorDialog.Color;
993
            with CheckListBox do
994
              TPlotDataObject(Items.Objects[ItemIndex]).Data.PlotColor :=
995
                ColorDialog.Color;
996
            PenPanel.Color := ColorDialog.Color;
997
          end;
998
        1:
999
          begin
1000
            CoordColor := ColorDialog.Color;
1001
            CoordPanel.Color := ColorDialog.Color;
1002
          end;
1003
      end;
1004
      Altered := True;
1005
      MainForm.GLViewer.Invalidate;
1006
    end;
1007
  end;
1008
end;
1009

1010
procedure TFunctionsForm.EvaluateClick(Sender: TObject);
1011
var
1012
  k: Word;
1013

1014
begin
1015
  with EvaluateButton do
1016
    Tag := (Tag + 1) mod 2;
1017

1018
  CheckListBoxClick(Sender);
1019

1020
  CoordPointButton.Visible := EditEvaluate.Visible and NumericForm.Visible and
1021
    (NumericForm.CheckListBox.Count > 0) and
1022
    (NumericForm.CheckListBox.ItemIndex > -1) and
1023
    (NumericForm.CheckListBox.ItemIndex < NumericForm.CheckListBox.Count) and
1024
    (NumericForm.InputRG.ItemIndex = 0);
1025

1026
  if EditEvaluate.Visible then
1027
  begin
1028
    EditEvaluate.SetFocus;
1029
    if EditEvaluate.Text <> '' then
1030
    begin
1031
      k := 0;
1032
      EditEvaluate.SelStart := Length(EditEvaluate.Text);
1033
      EvaluateKeyUp(Sender, k, []);
1034
    end;
1035
  end
1036
  else
1037
    MainForm.GLViewer.Invalidate;
1038
end;
1039

1040
procedure TFunctionsForm.LabelyClick(Sender: TObject);
1041
begin
1042
  Clipboard.Clear;
1043
  Clipboard.AsText := Copy(Labely.Caption, pos('=', Labely.Caption) + 2,
1044
    Length(Labely.Caption));
1045
end;
1046

1047
procedure TFunctionsForm.LabelRCosClick(Sender: TObject);
1048
begin
1049
  Clipboard.Clear;
1050
  Clipboard.AsText := Copy(LabelRCos.Caption, pos('=', LabelRCos.Caption) + 2,
1051
    Length(LabelRCos.Caption));
1052
end;
1053

1054
procedure TFunctionsForm.LabelRSinClick(Sender: TObject);
1055
begin
1056
  Clipboard.Clear;
1057
  Clipboard.AsText := Copy(LabelRSin.Caption, pos('=', LabelRSin.Caption) + 2,
1058
    Length(LabelRSin.Caption));
1059
end;
1060

1061
procedure TFunctionsForm.CheckListBoxClick(Sender: TObject);
1062
begin
1063
  if BitBtn2.Visible then
1064
    BitBtn2Click(Sender);
1065
  with CheckListBox do
1066
    if Count > 0 then
1067
      with GraphData do
1068
      begin
1069
        PlotData := TPlotDataObject(Items.Objects[ItemIndex]).Data;
1070

1071
        EvaluateButton.Visible := Checked[ItemIndex];
1072
        if (EvaluateButton.Tag = 1) and not Checked[ItemIndex] then
1073
          EvaluateButton.Tag := 0;
1074
        CoordPointButton.Visible := EvaluateButton.Tag = 1;
1075

1076
        if PlotData.PlotAsFx then
1077
        begin
1078
          yfx1.Caption := 'y = f''(x)';
1079
          yfx2.Caption := 'y = f"(x)';
1080
        end
1081
        else
1082
        begin
1083
          yfx1.Caption := 'y = f''(�)';
1084
          yfx2.Caption := 'y = f"(�)';
1085

1086
          if Integrate2y.Checked then
1087
            CloseIntegrateYForm;
1088
          if Between1.Checked then
1089
            CloseBetweenForm;
1090
          if Volumex1.Checked then
1091
            CloseVolumeXForm;
1092
          if Volumey1.Checked then
1093
            CloseVolumeYForm;
1094
          if fxValue.Checked then
1095
            ClosefxValueForm;
1096
          if fx1Value.Checked then
1097
            Closefx1ValueForm;
1098
          if fx2Value.Checked then
1099
            Closefx2ValueForm;
1100
        end;
1101
      end;
1102

1103
  MainForm.GLViewer.Invalidate;
1104
  ShowData(Sender);
1105
  DerivativeForm.ShowData;
1106
  IntegrateXForm.ShowData;
1107
  IntegrateYForm.ShowData;
1108
  BetweenForm.ShowData;
1109
  VolumeXForm.ShowData;
1110
  VolumeYForm.ShowData;
1111
  with fxValueForm do
1112
    if Visible then
1113
    begin
1114
      ShowData;
1115
      SetFocus;
1116
      RecalcBtnClick(Sender);
1117
    end;
1118
  with fx1ValueForm do
1119
    if Visible then
1120
    begin
1121
      ShowData;
1122
      SetFocus;
1123
      RecalcBtnClick(Sender);
1124
    end;
1125
  with fx2ValueForm do
1126
    if Visible then
1127
    begin
1128
      ShowData;
1129
      SetFocus;
1130
      RecalcBtnClick(Sender);
1131
    end;
1132
end;
1133

1134
procedure TFunctionsForm.CheckListBoxClickCheck(Sender: TObject);
1135
begin
1136
  Altered := True;
1137
end;
1138

1139
procedure TFunctionsForm.BitBtn2Click(Sender: TObject);
1140
var
1141
  k: Word;
1142

1143
  procedure Swap(var N1, n2: extended);
1144
  var
1145
    n: extended;
1146

1147
  begin
1148
    n := N1;
1149
    N1 := n2;
1150
    n2 := n;
1151
  end;
1152

1153
begin
1154
  k := 0;
1155
  EditSegMinKeyUp(Sender, k, []);
1156
  EditSegMaxKeyUp(Sender, k, []);
1157

1158
  if x1 = x2 then
1159
    x2 := 1.1 * x1;
1160
  if x1 > x2 then
1161
    Swap(x1, x2);
1162

1163
  with GraphData.PlotData do
1164
  begin
1165
    SegMin := x1;
1166
    SegMax := x2;
1167
  end;
1168

1169
  with CheckListBox, TPlotDataObject(Items.Objects[ItemIndex]).Data do
1170
  begin
1171
    SegMin := x1;
1172
    SegMax := x2;
1173
  end;
1174
  Altered := True;
1175
  MainForm.GLViewer.Invalidate;
1176
  BitBtn2.Visible := false;
1177
end;
1178

1179
procedure TFunctionsForm.AddButtonClick(Sender: TObject);
1180
begin
1181
  with CheckListBox, GraphData do
1182
  begin
1183
    PlotData := TPlotDataObject(Items.Objects[ItemIndex]).Data;
1184
    AddItem(PlotData.TextStr, TPlotDataObject.Create(PlotData));
1185
    ItemIndex := Count - 1;
1186
    Checked[ItemIndex] := True;
1187
    DeleteButton.Enabled := True;
1188
    UpButton.Enabled := True;
1189
    DownButton.Enabled := True;
1190
  end;
1191
  Altered := True;
1192
  MainForm.GLViewer.Invalidate;
1193
  Editfx.SetFocus;
1194
  Editfx.SelStart := 0;
1195
end;
1196

1197
procedure TFunctionsForm.DeleteButtonClick(Sender: TObject);
1198
var
1199
  i: integer;
1200

1201
begin
1202
  if CheckListBox.Count > 1 then
1203
  begin
1204
    with CheckListBox do
1205
    begin
1206
      i := ItemIndex;
1207
      with Items.Objects[i] as TPlotDataObject do
1208
        Free;
1209
      Items.Delete(i);
1210
      if i > Count - 1 then
1211
        i := Count - 1;
1212
      ItemIndex := i;
1213
      DeleteButton.Enabled := Count > 1;
1214
    end;
1215
    Altered := True;
1216
    MainForm.GLViewer.Invalidate;
1217
  end
1218
end;
1219

1220
procedure TFunctionsForm.BitBtn1Click(Sender: TObject);
1221
begin
1222
  Close;
1223
end;
1224

1225
procedure TFunctionsForm.UpButtonClick(Sender: TObject);
1226
var
1227
  i: integer;
1228

1229
begin
1230
  with CheckListBox do
1231
  begin
1232
    i := ItemIndex;
1233
    if i > 0 then
1234
      Items.Move(i, i - 1);
1235
    if i > 1 then
1236
      ItemIndex := i - 1
1237
    else
1238
      ItemIndex := 0;
1239
  end;
1240
  CheckListBoxClick(Sender);
1241
  Altered := True;
1242
end;
1243

1244
procedure TFunctionsForm.DownButtonClick(Sender: TObject);
1245
var
1246
  i: integer;
1247

1248
begin
1249
  with CheckListBox do
1250
  begin
1251
    i := ItemIndex;
1252
    if i < Count - 1 then
1253
      Items.Move(i, i + 1);
1254
    ItemIndex := i + 1;
1255
  end;
1256
  CheckListBoxClick(Sender);
1257
  Altered := True;
1258
end;
1259

1260
function TFunctionsForm.ReadData(const FName: TFileName): Boolean;
1261
var
1262
  s, t: string;
1263
  f: TextFile;
1264
  i, j, k, l, m, n: integer;
1265
  c: TColor;
1266
  td: TTextData;
1267
  vx, vy: extended;
1268

1269
begin
1270
  Result := false;
1271
  if FileExists(FName) then
1272
  begin
1273
    AssignFile(f, FName);
1274
    try
1275
      Reset(f);
1276
      if FileSize(f) = 0 then
1277
      begin
1278
        CloseFile(f);
1279
        Result := false;
1280
        CheckListBox.ItemIndex := CheckListBox.Count - 1;
1281
        MessageDlg('File Error!'#13#10'The file '#13#10'"' + FName + '"' +
1282
          #13#10'is empty.', mtError, [mbOK], 0);
1283
        Exit;
1284
      end;
1285
      Readln(f, s);
1286
      j := 0;
1287
      i := pos(#9, s);
1288

1289
      while i > 0 do
1290
      begin
1291
        t := Copy(s, 1, i - 1);
1292
        s := Copy(s, i + 1, Length(s));
1293
        i := pos(#9, s);
1294
        Inc(j);
1295

1296
        case j of
1297
          1:
1298
            TryStrToFloat(t, GraphData.xMin);
1299
          2:
1300
            TryStrToFloat(t, GraphData.yMin);
1301
          3:
1302
            TryStrToFloat(t, GraphData.xMax);
1303
          4:
1304
            TryStrToFloat(t, GraphData.yMax);
1305
          5:
1306
            TryStrToFloat(t, GraphData.SavexMin);
1307
          6:
1308
            TryStrToFloat(t, GraphData.SaveyMin);
1309
          7:
1310
            TryStrToFloat(t, GraphData.SavexMax);
1311
          8:
1312
            TryStrToFloat(t, GraphData.SaveyMax);
1313
          9:
1314
            TryStrToFloat(t, GraphData.AreaAlpha);
1315
          10:
1316
            GraphData.FontName := t;
1317
          11:
1318
            begin
1319
              GraphData.FontStyle := [];
1320
              if pos('fsBold', t) > 0 then
1321
                Include(GraphData.FontStyle, fsBold);
1322
              if pos('fsItalic', t) > 0 then
1323
                Include(GraphData.FontStyle, fsItalic);
1324
              if pos('fsUnderline', t) > 0 then
1325
                Include(GraphData.FontStyle, fsUnderline);
1326
              if pos('fsStrikeOut', t) > 0 then
1327
                Include(GraphData.FontStyle, fsStrikeOut);
1328
            end;
1329
          12:
1330
            GraphData.FontSize := StrToInt(t);
1331
          13:
1332
            GraphData.AxisWidth := StrToInt(t);
1333
          14:
1334
            TryStrToInt(t, GraphData.xMinorGrad);
1335
          15:
1336
            TryStrToInt(t, GraphData.yMinorGrad);
1337
          16:
1338
            TryStrToInt(t, GraphData.xMajorGrad);
1339
          17:
1340
            TryStrToInt(t, GraphData.yMajorGrad);
1341
          18:
1342
            TryStrToInt(t, GraphData.MinorWidth);
1343
          19:
1344
            TryStrToInt(t, GraphData.MajorWidth);
1345
          20:
1346
            TryStrToInt(t, GraphData.CoordWidth);
1347
          21:
1348
            TryStrToInt(t, GraphData.dydxWidth);
1349
          22:
1350
            TryStrToInt(t, GraphData.d2ydx2Width);
1351
          23:
1352
            TryStrToInt(t, GraphData.IntegCount);
1353
          24:
1354
            TryStrToInt(t, GraphData.ydxWidth);
1355
          25:
1356
            GraphData.BackColor := StrToInt(t);
1357
          26:
1358
            GraphData.GridColor := StrToInt(t);
1359
          27:
1360
            GraphData.xAxisColor := StrToInt(t);
1361
          28:
1362
            GraphData.yAxisColor := StrToInt(t);
1363
          29:
1364
            GraphData.CoordColor := StrToInt(t);
1365
          30:
1366
            GraphData.dydxColor := StrToInt(t);
1367
          31:
1368
            GraphData.d2ydx2Color := StrToInt(t);
1369
          32:
1370
            GraphData.ydxColor := StrToInt(t);
1371
          33:
1372
            GraphData.PosAreaColor := StrToInt(t);
1373
          34:
1374
            GraphData.NegAreaColor := StrToInt(t);
1375
          35:
1376
            GraphData.Grid.xAxisStyle := TAxisStyle(StrToInt(t));
1377
          36:
1378
            GraphData.Grid.yAxisStyle := TAxisStyle(StrToInt(t));
1379
          37:
1380
            GraphData.Grid.GridStyle := TGridStyle(StrToInt(t));
1381
        end;
1382
      end;
1383
      // with GridOptionsForm
1384
      GridOptionsForm.xTrackBar.Position := GraphData.xMinorGrad;
1385
      GridOptionsForm.yTrackBar.Position := GraphData.yMinorGrad;
1386

1387
      n := StrToInt(s); // number of functions to plot
1388

1389
      for k := 0 to n - 1 do
1390
      begin // read each function's data
1391
        Readln(f, s);
1392
        j := 0;
1393
        i := pos(#9, s);
1394

1395
        while i > 0 do
1396
        begin
1397
          t := Copy(s, 1, i - 1);
1398
          s := Copy(s, i + 1, Length(s));
1399
          i := pos(#9, s);
1400
          Inc(j);
1401
          with GraphData.PlotData do
1402
            case j of
1403
              1:
1404
                FunctStr := t;
1405
              2:
1406
                TextStr := t;
1407
              3:
1408
                TryStrToFloat(t, xInc);
1409
              4:
1410
                PlotWidth := StrToInt(t);
1411
              5:
1412
                PlotColor := StrToInt(t);
1413
              6:
1414
                TryStrToFloat(t, PhiInc);
1415
              7:
1416
                TryStrToFloat(t, SegMin);
1417
              8:
1418
                TryStrToFloat(t, SegMax);
1419
              9:
1420
                TryStrToFloat(t, xLabel);
1421
              10:
1422
                TryStrToFloat(t, yLabel);
1423
              11:
1424
                ShowLabel := StrToBool(t);
1425
              12:
1426
                PlotAsFx := StrToBool(t);
1427
              13:
1428
                IsSegment := StrToBool(t);
1429
              14:
1430
                IsContinuous := StrToBool(t);
1431
            end;
1432
        end;
1433

1434
        CheckListBox.AddItem(GraphData.PlotData.TextStr,
1435
          TPlotDataObject.Create(GraphData.PlotData));
1436
        CheckListBox.Checked[CheckListBox.Count - 1] := StrToBool(s);
1437
      end;
1438

1439
      with NumericForm do
1440
      begin
1441
        ClearCheckListBox;
1442
        Readln(f, s);
1443
        n := StrToInt(s); // number of numeric graphs
1444
        m := 0;
1445
        vx := 0;
1446
        for k := 0 to n - 1 do
1447
        begin
1448
          Readln(f, s);
1449
          j := 0;
1450
          i := pos(#9, s);
1451

1452
          while i > 0 do
1453
          begin
1454
            t := Copy(s, 1, i - 1);
1455
            s := Copy(s, i + 1, Length(s));
1456
            i := pos(#9, s);
1457
            Inc(j);
1458

1459
            case j of
1460
              1:
1461
                NumericData.Name := t;
1462
              2:
1463
                NumericData.NumericStyle := TNumericStyle(StrToInt(t));
1464
              3:
1465
                NumericData.ShowPoints := StrToBool(t);
1466
              4:
1467
                NumericData.PointStyle := TPointStyle(StrToInt(t));
1468
              5:
1469
                NumericData.PointSize := StrToInt(t);
1470
              6:
1471
                NumericData.PointColor := StrToInt(t);
1472
              7:
1473
                NumericData.PlotWidth := StrToInt(t);
1474
              8:
1475
                NumericData.PlotColor := StrToInt(t);
1476
              9:
1477
                NumericData.SortXValue := StrToBool(t);
1478
              10:
1479
                NumericData.Extrapolate := StrToBool(t);
1480
              11:
1481
                TryStrToInt(t, NumericData.CoordsIdx);
1482
              12:
1483
                TryStrToInt(t, NumericData.CurveRate);
1484
              // was k0 = CurveRate/100
1485
              13:
1486
                m := StrToInt(t); // number of plot points
1487
            end;
1488
          end;
1489

1490
          with CheckListBox do
1491
          begin
1492
            AddItem(NumericData.Name, TNumericObject.Create(NumericData));
1493
            Checked[Count - 1] := StrToBool(s); // Checked
1494
          end;
1495

1496
          if m > 0 then
1497
          begin
1498
            Readln(f, s);
1499
            j := 0;
1500
            i := pos(#9, s);
1501

1502
            while i > 0 do
1503
            begin
1504
              t := Copy(s, 1, i - 1);
1505
              s := Copy(s, i + 1, Length(s));
1506
              i := pos(#9, s);
1507
              Inc(j);
1508
              if Odd(j) then
1509
                TryStrToFloat(t, vx)
1510
              else
1511
              begin
1512
                TryStrToFloat(t, vy);
1513
                with TNumericObject(CheckListBox.Items.Objects
1514
                  [CheckListBox.Count - 1]) do
1515
                  ControlPoints.Add(TGraphPointObject.Create(vx, vy));
1516
              end;
1517
            end;
1518
          end;
1519
        end;
1520
        ShowData(Self);
1521
        UpdateDataListBox;
1522
      end;
1523

1524
      TextBlocksForm.ClearTextBlocks;
1525
      Readln(f, s);
1526
      n := StrToInt(s); // number of TextBlocks
1527

1528
      for k := 0 to n - 1 do
1529
      begin // read each TextBlock's data
1530
        Readln(f, s);
1531
        j := 0;
1532
        i := pos(#9, s);
1533

1534
        while i > 0 do
1535
        begin
1536
          t := Copy(s, 1, i - 1);
1537
          s := Copy(s, i + 1, Length(s));
1538
          i := pos(#9, s);
1539
          Inc(j);
1540
          case j of
1541
            1:
1542
              Caption := t;
1543
            2:
1544
              TryStrToFloat(t, td.xLoc);
1545
            3:
1546
              TryStrToFloat(t, td.yLoc);
1547
            4:
1548
              TryStrToInt(t, td.yInc);
1549
            5:
1550
              td.FontName := t;
1551
            6:
1552
              begin
1553
                td.FontStyle := [];
1554
                if pos('fsBold', t) > 0 then
1555
                  Include(td.FontStyle, fsBold);
1556
                if pos('fsItalic', t) > 0 then
1557
                  Include(td.FontStyle, fsItalic);
1558
                if pos('fsUnderline', t) > 0 then
1559
                  Include(td.FontStyle, fsUnderline);
1560
                if pos('fsStrikeOut', t) > 0 then
1561
                  Include(td.FontStyle, fsStrikeOut);
1562
              end;
1563
            7:
1564
              td.FontSize := StrToInt(t);
1565
            8:
1566
              td.FontColor := StrToInt(t);
1567
          end;
1568
        end;
1569

1570
        with TextBlocksForm.BlockListBox do
1571
        begin
1572
          AddItem(td.Caption, TTextDataObject.Create(td));
1573
          ItemIndex := k;
1574
          Checked[k] := StrToBool(s);
1575
        end;
1576

1577
        Readln(f, s);
1578
        m := StrToInt(s); // number of TextLines
1579

1580
        for l := 0 to m - 1 do
1581
        begin // read each line
1582
          Readln(f, s);
1583
          i := pos(#9, s);
1584
          with TTextDataObject(TextBlocksForm.BlockListBox.Items.Objects[k]) do
1585
          begin
1586
            t := Copy(s, 1, i - 1);
1587
            c := StrToInt(Copy(s, i + 1, Length(s)));
1588
            TextLines.Add(TTextLineObject.Create(t, c));
1589
          end;
1590
        end;
1591
      end;
1592

1593
      with TextBlocksForm do
1594
        if Visible then
1595
        begin
1596
          ShowData(Self);
1597
          if BlockListBox.Count > 0 then
1598
            BlockListBoxClick(Self);
1599
        end;
1600

1601
    except
1602
      MessageDlg('File Error! An Error has occurred' +
1603
        #13#10'when attempting to read "' + FName + '".', mtError, [mbOK], 0);
1604
      CloseFile(f);
1605
      Exit;
1606
    end;
1607
    CloseFile(f);
1608
    Result := True;
1609
    MainForm.GLViewer.Buffer.BackgroundColor := GraphData.BackColor;
1610
    CheckListBox.ItemIndex := CheckListBox.Count - 1;
1611
  end;
1612
end;
1613

1614
procedure TFunctionsForm.WriteData(const FName: TFileName);
1615
var
1616
  f: TextFile;
1617
  s: string;
1618
  i, j, TextLineCount: integer;
1619

1620
begin
1621
  try
1622
    AssignFile(f, FName);
1623
    try
1624
      Rewrite(f); { write tab delimited data }
1625
      with GraphData do
1626
      begin
1627
        s := FloatToStr(xMin) + #9 + FloatToStr(yMin) + #9 + FloatToStr(xMax) +
1628
          #9 + FloatToStr(yMax) + #9 + FloatToStr(SavexMin) + #9 +
1629
          FloatToStr(SaveyMin) + #9 + FloatToStr(SavexMax) + #9 +
1630
          FloatToStr(SaveyMax) + #9 + FloatToStr(AreaAlpha) + #9 +
1631
          FontName + #9;
1632
        if fsBold in FontStyle then
1633
          s := s + 'fsBold';
1634
        if fsItalic in FontStyle then
1635
          s := s + 'fsItalic';
1636
        if fsUnderline in FontStyle then
1637
          s := s + 'fsUnderline';
1638
        if fsStrikeOut in FontStyle then
1639
          s := s + 'fsStrikeOut';
1640
        s := s + #9 + IntToStr(FontSize) + #9 + IntToStr(AxisWidth) + #9 +
1641
          IntToStr(xMinorGrad) + #9 + IntToStr(yMinorGrad) + #9 +
1642
          IntToStr(xMajorGrad) + #9 + IntToStr(yMajorGrad) + #9 +
1643
          IntToStr(MinorWidth) + #9 + IntToStr(MajorWidth) + #9 +
1644
          IntToStr(CoordWidth) + #9 + IntToStr(dydxWidth) + #9 +
1645
          IntToStr(d2ydx2Width) + #9 + IntToStr(IntegCount) + #9 +
1646
          IntToStr(ydxWidth) + #9 + IntToStr(BackColor) + #9 +
1647
          IntToStr(GridColor) + #9 + IntToStr(xAxisColor) + #9 +
1648
          IntToStr(yAxisColor) + #9 + IntToStr(CoordColor) + #9 +
1649
          IntToStr(dydxColor) + #9 + IntToStr(d2ydx2Color) + #9 +
1650
          IntToStr(ydxColor) + #9 + IntToStr(PosAreaColor) + #9 +
1651
          IntToStr(NegAreaColor) + #9 + IntToStr(Ord(Grid.xAxisStyle)) + #9 +
1652
          IntToStr(Ord(Grid.yAxisStyle)) + #9 + IntToStr(Ord(Grid.GridStyle)) +
1653
          #9 + IntToStr(CheckListBox.Count); { number of functions }
1654
      end;
1655
      writeln(f, s);
1656

1657
      for i := 0 to CheckListBox.Count - 1 do
1658
      begin { write each function's data }
1659
        with TPlotDataObject(CheckListBox.Items.Objects[i]).Data do
1660
        begin
1661
          FunctStr := Trim(FunctStr);
1662
          TextStr := Trim(TextStr);
1663
          s := FunctStr + #9 + TextStr + #9 + FloatToStr(xInc) + #9 +
1664
            IntToStr(PlotWidth) + #9 + IntToStr(PlotColor) + #9 +
1665
            FloatToStr(PhiInc) + #9 + FloatToStr(SegMin) + #9 +
1666
            FloatToStr(SegMax) + #9 + FloatToStr(xLabel) + #9 +
1667
            FloatToStr(yLabel) + #9 + BoolToStr(ShowLabel) + #9 +
1668
            BoolToStr(PlotAsFx) + #9 + BoolToStr(IsSegment) + #9 +
1669
            BoolToStr(IsContinuous) + #9 + BoolToStr(CheckListBox.Checked[i]);
1670
        end;
1671
        writeln(f, s);
1672
      end;
1673

1674
      with NumericForm do { write each Numeric plot }
1675
      begin
1676
        with CheckListBox do
1677
        begin
1678
          s := IntToStr(Count);
1679
          writeln(f, s); { number of numeric graphs }
1680
          for i := 0 to Count - 1 do
1681
          begin
1682
            with TNumericObject(Items.Objects[i]).Data do
1683
              s := Name + #9 + IntToStr(Ord(NumericStyle)) + #9 +
1684
                BoolToStr(ShowPoints) + #9 + IntToStr(Ord(PointStyle)) + #9 +
1685
                IntToStr(PointSize) + #9 + IntToStr(PointColor) + #9 +
1686
                IntToStr(PlotWidth) + #9 + IntToStr(PlotColor) + #9 +
1687
                BoolToStr(SortXValue) + #9 + BoolToStr(Extrapolate) + #9 +
1688
                IntToStr(CoordsIdx) + #9 + IntToStr(CurveRate) + #9;
1689
            { was k0 factor = CurveRate/100 }
1690
            s := s + IntToStr(TNumericObject(Items.Objects[i])
1691
              .ControlPoints.Count) + #9 + BoolToStr(Checked[i]);
1692
            writeln(f, s);
1693
            s := '';
1694
            with TNumericObject(Items.Objects[i]) do
1695
              for j := 0 to ControlPoints.Count - 1 do
1696
              begin
1697
                with TGraphPointObject(ControlPoints[j]) do
1698
                  s := s + FloatToStr(x_phi) + #9 + FloatToStr(y_r) + #9;
1699
              end;
1700
            writeln(f, s);
1701
          end;
1702
        end;
1703
      end;
1704

1705
      with TextBlocksForm do
1706
      begin
1707
        s := IntToStr(BlockListBox.Count);
1708
        writeln(f, s); { number of TextBlocks }
1709

1710
        for i := 0 to BlockListBox.Count - 1 do
1711
        begin { write each TextBlock's data }
1712
          with TTextDataObject(BlockListBox.Items.Objects[i]).Data do
1713
          begin
1714
            Caption := Trim(Caption);
1715
            s := Caption + #9 + FloatToStr(xLoc) + #9 + FloatToStr(yLoc) + #9 +
1716
              IntToStr(yInc) + #9 + FontName + #9;
1717
            if fsBold in FontStyle then
1718
              s := s + 'fsBold';
1719
            if fsItalic in FontStyle then
1720
              s := s + 'fsItalic';
1721
            if fsUnderline in FontStyle then
1722
              s := s + 'fsUnderline';
1723
            if fsStrikeOut in FontStyle then
1724
              s := s + 'fsStrikeOut';
1725
            s := s + #9 + IntToStr(FontSize) + #9 + IntToStr(FontColor) + #9 +
1726
              BoolToStr(BlockListBox.Checked[i]);
1727
          end;
1728
          writeln(f, s);
1729

1730
          with TTextDataObject(BlockListBox.Items.Objects[i]) do
1731
          begin
1732
            j := TextLines.Count - 1;
1733
            while (j >= 0) and (TTextLineObject(TextLines[j]).Text = '') do
1734
              Dec(j); { remove any traling empty lines }
1735

1736
            TextLineCount := j + 1;
1737
            s := IntToStr(TextLineCount);
1738
            writeln(f, s); { number of TextLines }
1739
            for j := 0 to TextLineCount - 1 do
1740
              with TTextLineObject(TextLines[j]) do
1741
              begin
1742
                s := Text + #9 + IntToStr(Color);
1743
                writeln(f, s);
1744
              end;
1745
          end;
1746
        end;
1747
      end;
1748
    finally
1749
      Flush(f);
1750
      CloseFile(f);
1751
    end;
1752
  except
1753
    MessageDlg('File Error! An Error has occurred' +
1754
      #13#10'when attempting to write to "' + GraphFName + '".', mtError,
1755
      [mbOK], 0);
1756
  end;
1757
  Altered := false;
1758
  NewFile := false;
1759
end;
1760

1761
function TFunctionsForm.DefaultData: TGraphData;
1762
begin
1763
  with Result do
1764
  begin
1765
    xMin := -10.2;
1766
    yMin := -10.2;
1767
    xMax := 10.75;
1768
    yMax := 10.95;
1769

1770
    SavexMin := 0;
1771
    SavexMax := 0;
1772
    SaveyMin := 0;
1773
    SaveyMax := 0;
1774

1775
    AreaAlpha := 0.25; { transparency of integration area }
1776

1777
    FontName := 'Tahoma';
1778
    FontStyle := [];
1779
    FontSize := 9;
1780

1781
    AxisWidth := 2; { axis line width }
1782

1783
    xMinorGrad := 5; { minor X axis graduation lengths }
1784
    yMinorGrad := 5; { minor Y axis graduation lengths }
1785
    xMajorGrad := 50; { major X axis graduation lengths }
1786
    yMajorGrad := 50; { major Y axis graduation lengths }
1787

1788
    MinorWidth := 1; { minor graduation & grid line width }
1789
    MajorWidth := 1; { major graduation & grid line width }
1790
    CoordWidth := 2; { coordinate line width }
1791

1792
    dydxWidth := 1; { derivative line width }
1793
    d2ydx2Width := 1; { 2nd derivative line width }
1794
    IntegCount := 64000; { number of integration intervals }
1795
    ydxWidth := 1; { integral line width }
1796

1797
    BackColor := clCream; { paper or background color }
1798
    GridColor := clSilver; { grid color }
1799
    xAxisColor := clRed; { xAxis color }
1800
    yAxisColor := clGreen; { yAxis color }
1801
    CoordColor := clGray; { coordinate line color }
1802
    dydxColor := clOlive; { derivative line color }
1803
    d2ydx2Color := clOlive; { 2nd derivative line color }
1804
    ydxColor := clTeal; { integral line color }
1805
    PosAreaColor := clSkyBlue; { positive integral area color }
1806
    NegAreaColor := clMaroon; { negative integral area color }
1807

1808
    with Grid do
1809
    begin
1810
      GridStyle := gsCartesian;
1811
      xAxisStyle := asLinear;
1812
      yAxisStyle := asLinear;
1813
    end;
1814

1815
    with PlotData do { each function has these individual values }
1816
    begin
1817
      FunctStr := '';
1818
      TextStr := FunctStr;
1819
      xInc := 1;
1820
      PlotWidth := 1;
1821
      PlotColor := clBlue;
1822
      PhiInc := 0.1;
1823
      SegMin := -Pi;
1824
      SegMax := Pi;
1825
      xLabel := -0.3;
1826
      yLabel := 0.1;
1827
      ShowLabel := True;
1828
      PlotAsFx := True;
1829
      IsSegment := false;
1830
      IsContinuous := false;
1831
    end;
1832
  end;
1833
end;
1834

1835
procedure TFunctionsForm.ShowData(Sender: TObject);
1836
var
1837
  i: integer;
1838
  fs, ts: string;
1839

1840
begin
1841
  with GraphData, PlotData do
1842
  begin
1843
    fs := FunctStr;
1844
    ts := TextStr;
1845

1846
    ShowLabelCheckBox.Checked := ShowLabel;
1847
    SegmentButton.Visible := PlotAsFx;
1848
    ContinuousCheckBox.Checked := IsContinuous;
1849
    UpButton.Enabled := CheckListBox.Count > 1;
1850
    DownButton.Enabled := UpButton.Enabled;
1851
    DeleteButton.Enabled := UpButton.Enabled;
1852

1853
    Labelx.Visible := EvaluateButton.Tag = 1;
1854
    Labely.Visible := Labelx.Visible;
1855
    EditEvaluate.Visible := Labelx.Visible;
1856
    EditCoordinate.Visible := Labelx.Visible;
1857
    UpDown3.Visible := Labelx.Visible;
1858
    SpeedButton4.Visible := Labelx.Visible;
1859
    PenPanel.Color := PlotColor;
1860
    CoordPanel.Color := CoordColor;
1861
    CoordPanel.Visible := Labelx.Visible;
1862

1863
    Label11.Visible := Labelx.Visible;
1864

1865
    SwitchButton.Visible := (Grid.xAxisStyle = asLinear) and
1866
      (Grid.yAxisStyle = asLinear);
1867

1868
    if PlotAsFx then
1869
    begin { plot as y = f(x) }
1870
      for i := 1 to Length(fs) do
1871
        if fs[i] = '�' then
1872
          fs[i] := 'x';
1873
      for i := 1 to Length(ts) do
1874
        if ts[i] = '�' then
1875
          ts[i] := 'x';
1876

1877
      LabelPhi.Caption := 'Plot x :';
1878
      with SwitchButton do
1879
      begin
1880
        Caption := 'Go to f(�)';
1881
        Hint := 'Switch to r = f(�)';
1882
        if not IsSegment then
1883
        begin
1884
          Label1.Visible := false;
1885
          Label2.Visible := false;
1886
          Label3.Visible := false;
1887
        end;
1888
        Tag := 0;
1889
      end;
1890

1891
      LabelFunc.Caption := 'y = f(x) = ';
1892
      Labelx.Caption := 'x =';
1893
      Labeldx.Caption := 'pixels';
1894

1895
      LabelRCos.Visible := false;
1896
      LabelRSin.Visible := false;
1897

1898
      Editdx.Text := FloatToStrF(xInc, ffGeneral, 7, 4);
1899
      UpDown1.Visible := True;
1900

1901
      yfx1.Caption := 'y = f''(x)';
1902
      yfx2.Caption := 'y = f"(x)';
1903
      Integrate1.Enabled := True;
1904
      Integrate2y.Enabled := True;
1905
      Findx.Enabled := True;
1906
      try
1907
        Between1.Enabled := (CheckListBox.Count > 1) and
1908
          (pos('�', CheckListBox.Items[0]) = 0) and
1909
          (pos('�', CheckListBox.Items[1]) = 0);
1910
      except
1911
      end;
1912

1913
      Volumex1.Enabled := True;
1914
      Volumey1.Enabled := True;
1915

1916
      with SegmentButton do
1917
      begin
1918
        if IsSegment then
1919
        begin
1920
          Caption := 'Go to Complete';
1921
          Hint := 'Click to plot whole range.';
1922
          Label1.Visible := True;
1923
          Label2.Visible := True;
1924
          Label3.Visible := True;
1925
          LabelPhi.Visible := True;
1926
          EditSegMin.Visible := True;
1927
          EditSegMax.Visible := True;
1928

1929
          EditSegMin.Text := FloatToStrF(SegMin, ffGeneral, 13, 4);
1930
          EditSegMax.Text := FloatToStrF(SegMax, ffGeneral, 13, 4);
1931
          Tag := 0;
1932
        end
1933
        else
1934
        begin
1935
          Caption := 'Go to Segment';
1936
          Hint := 'Click to limit plot range.';
1937
          Label1.Visible := false;
1938
          Label2.Visible := false;
1939
          Label3.Visible := false;
1940
          LabelPhi.Visible := false;
1941
          EditSegMin.Visible := false;
1942
          EditSegMax.Visible := false;
1943
          Tag := 1;
1944
        end;
1945
      end;
1946
    end { plot as y = f(x) }
1947
    else
1948
    begin { plot as r = f(�) }
1949
      for i := 1 to Length(fs) do
1950
        if (not CharInSet(fs[i - 1], ['e', 'E'])) and (UpCase(fs[i]) = 'X') then
1951
          fs[i] := '�';
1952

1953
      for i := 1 to Length(ts) do
1954
        if (not CharInSet(ts[i - 1], ['e', 'E'])) and (UpCase(ts[i]) = 'X') then
1955
          ts[i] := '�';
1956

1957
      LabelPhi.Visible := True;
1958
      EditSegMin.Visible := True;
1959
      EditSegMax.Visible := True;
1960

1961
      LabelRCos.Visible := Labely.Visible;
1962
      LabelRSin.Visible := Labely.Visible;
1963

1964
      LabelPhi.Caption := 'Plot � :';
1965
      with SwitchButton do
1966
      begin
1967
        Caption := 'Go to f(x)';
1968
        Hint := 'Switch to y = f(x)';
1969
        Label1.Visible := True;
1970
        Label2.Visible := True;
1971
        Label3.Visible := True;
1972
        Tag := 1;
1973
      end;
1974

1975
      LabelFunc.Caption := 'r = f(�) = ';
1976
      Labelx.Caption := '� =';
1977
      Labeldx.Caption := 'radians';
1978

1979
      yfx1.Caption := 'y = f''(�)';
1980
      yfx2.Caption := 'y = f"(�)';
1981

1982
      Integrate2y.Enabled := false;
1983
      Between1.Enabled := false;
1984
      Volumex1.Enabled := false;
1985
      Volumey1.Enabled := false;
1986
      Findx.Enabled := false;
1987

1988
      Editdx.Text := FloatToStrF(PhiInc, ffGeneral, 7, 4);
1989
      UpDown1.Visible := false;
1990

1991
      EditSegMin.Text := FloatToStrF(SegMin, ffGeneral, 13, 4);
1992
      EditSegMax.Text := FloatToStrF(SegMax, ffGeneral, 13, 4);
1993
    end; { plot as r = f(�) }
1994

1995
    FunctStr := fs;
1996
    TextStr := ts;
1997
    Editfx.Text := ts;
1998

1999
    EditLocX.Text := FloatToStrF(xLabel, ffGeneral, 4, 3);
2000
    EditLocY.Text := FloatToStrF(yLabel, ffGeneral, 4, 3);
2001

2002
    EditPen.Text := IntToStr(PlotWidth);
2003
    EditCoordinate.Text := IntToStr(CoordWidth);
2004

2005
    if Sender = SwitchButton then
2006
    begin
2007
      with CheckListBox do
2008
      begin
2009
        Items[ItemIndex] := ts;
2010
        with TPlotDataObject(Items.Objects[ItemIndex]).Data do
2011
        begin
2012
          FunctStr := fs;
2013
          TextStr := ts;
2014
        end;
2015
      end;
2016
      BitBtn2.Visible := false;
2017
    end;
2018
  end;
2019
end;
2020

2021
procedure TFunctionsForm.OpenSelectedFile(Sender: TObject; FName: TFileName);
2022
var
2023
  i: integer;
2024

2025
begin
2026
  if FileExists(FName) then
2027
  begin
2028
    Screen.Cursor := crHourglass;
2029
    CheckListBox.Clear;
2030
    GraphFName := ExtractFileName(FName);
2031

2032
    if ReadData(DataPath + GraphFName) then
2033
    begin
2034
      if Integrate2x.Checked then
2035
        CloseIntegrateXForm;
2036
      if Integrate2y.Checked then
2037
        CloseIntegrateYForm;
2038
      if Between1.Checked then
2039
        CloseBetweenForm;
2040
      if Volumex1.Checked then
2041
        CloseVolumeXForm;
2042
      if Volumey1.Checked then
2043
        CloseVolumeYForm;
2044

2045
      Caption := GraphFName;
2046
      MainForm.Caption := GraphFName;
2047
      GridOptionsForm.Caption := GraphFName;
2048
      NumericForm.Caption := GraphFName;
2049
      TextBlocksForm.Caption := GraphFName;
2050

2051
      ShowData(Sender);
2052
      BitBtn2.Visible := false;
2053
      NewFile := false;
2054
      Altered := false;
2055
      (*
2056
        NewFont needed to initialize GLWinFont.GetCharWidth
2057
        if the font has been altered, which may or may not be the case,
2058
        so do it anyway
2059
      *)
2060
      NewFont := True;
2061
      MainForm.GLViewer.Buffer.BackgroundColor := GraphData.BackColor;
2062
      MainForm.GLViewer.Invalidate;
2063
    end;
2064

2065
    GridOptionsForm.ShowData;
2066
    GridOptionsForm.ApplyBitBtn.Visible := false;
2067
    DerivativeForm.ShowData;
2068

2069
    with NumericForm do
2070
      if Visible then
2071
      begin
2072
        SetFocus;
2073
        ShowData(Sender);
2074
        CheckListBox.ItemIndex := CheckListBox.Count - 1;
2075
        if CheckListBox.ItemIndex > -1 then
2076
          CheckListBoxClick(Sender);
2077
      end;
2078

2079
    with TextBlocksForm do
2080
      if BlockListBox.Count > 0 then
2081
        UpdateRichLines;
2082
    Screen.Cursor := crDefault;
2083
  end
2084
  else
2085
  begin
2086
    MessageDlg('The file' + FName + #13#10'Could not be found.', mtError,
2087
      [mbOK], 0);
2088
    Screen.Cursor := crDefault;
2089
  end;
2090
end;
2091

2092
procedure TFunctionsForm.CloseIntegrateXForm;
2093
begin
2094
  Integrate2x.Checked := false;
2095
  Integrate2x.ImageIndex := 3;
2096
  IntegrateXForm.Close;
2097
  IntegrateXForm.PlotIntegrated := piCalc;
2098
end;
2099

2100
procedure TFunctionsForm.CloseIntegrateYForm;
2101
begin
2102
  Integrate2y.Checked := false;
2103
  Integrate2y.ImageIndex := 4;
2104
  IntegrateYForm.Close;
2105
end;
2106

2107
procedure TFunctionsForm.CloseBetweenForm;
2108
begin
2109
  Between1.Checked := false;
2110
  Between1.ImageIndex := 5;
2111
  BetweenForm.Close;
2112
end;
2113

2114
procedure TFunctionsForm.CloseVolumeXForm;
2115
begin
2116
  Volumex1.Checked := false;
2117
  Volumex1.ImageIndex := 6;
2118
  VolumeXForm.HideFunctionCheckBox.Checked := false;
2119
  VolumeXForm.Close;
2120
end;
2121

2122
procedure TFunctionsForm.CloseVolumeYForm;
2123
begin
2124
  Volumey1.Checked := false;
2125
  Volumey1.ImageIndex := 7;
2126
  VolumeYForm.HideFunctionCheckBox.Checked := false;
2127
  VolumeYForm.Close;
2128
end;
2129

2130
procedure TFunctionsForm.ClosefxValueForm;
2131
begin
2132
  fxValue.Checked := false;
2133
  fxValue.ImageIndex := 0;
2134
  fxValueForm.Close;
2135
end;
2136

2137
procedure TFunctionsForm.Closefx1ValueForm;
2138
begin
2139
  fx1Value.Checked := false;
2140
  fx1Value.ImageIndex := 1;
2141
  fx1ValueForm.Close;
2142
end;
2143

2144
procedure TFunctionsForm.Closefx2ValueForm;
2145
begin
2146
  fx2Value.Checked := false;
2147
  fx2Value.ImageIndex := 2;
2148
  fx2ValueForm.Close;
2149
end;
2150

2151
procedure TFunctionsForm.ShowCartesianEvaluate;
2152
var
2153
  s: string;
2154

2155
begin
2156
  if EditEvaluate.Text = '' then
2157
  begin
2158
    Labely.Caption := 'y = Undefined';
2159
    LabelRCos.Caption := '';
2160
    LabelRSin.Caption := '';
2161
  end
2162
  else
2163
  begin
2164
    s := FloatToStr(yEvaluate);
2165
    if s = '-INF' then
2166
      s := 'Infinitely negative';
2167
    if s = 'INF' then
2168
      s := 'Infinitely positive';
2169
    if s = 'NAN' then
2170
      s := 'Undefined';
2171
    Labely.Caption := 'y = ' + s;
2172
    Label12.Caption := '';
2173
  end;
2174
end;
2175

2176
procedure TFunctionsForm.ShowPolarEvaluate;
2177
var
2178
  s: string;
2179

2180
begin
2181
  if EditEvaluate.Text = '' then
2182
  begin
2183
    Labely.Caption := 'r = Undefined';
2184
    LabelRCos.Caption := 'x = Undefined';
2185
    LabelRSin.Caption := 'y = Undefined';
2186
  end
2187
  else
2188
  begin
2189
    s := FloatToStr(yEvaluate);
2190
    if s = '-INF' then
2191
      s := 'Infinitely negative';
2192
    if s = 'INF' then
2193
      s := 'Infinitely positive';
2194
    if s = 'NAN' then
2195
      s := 'Undefined';
2196
    Labely.Caption := 'r = ' + s;
2197
    yCosxEval := yEvaluate * Cos(xEvaluate);
2198
    ySinxEval := yEvaluate * Sin(xEvaluate);
2199
    LabelRCos.Caption := 'x = ' + FloatToStr(yCosxEval);
2200
    LabelRSin.Caption := 'y = ' + FloatToStr(ySinxEval);
2201
    Label12.Caption := 'Radians';
2202
  end;
2203
end;
2204

2205
end.
2206

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

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

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

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