ArenaZ

Форк
0
/
Functions.pas 
1546 строк · 44.9 Кб
1
unit Functions;
2

3

4
interface
5

6
uses
7
  LCLType,
8
  SysUtils, Variants, Classes, Graphics, Controls, Forms,
9
  Dialogs, StdCtrls, CheckLst, Buttons, ComCtrls, Menus, uGlobal;
10

11
type
12
  TFunctionsForm = class(TForm)
13
    GroupBox1: TGroupBox;
14
    Label1: TLabel;
15
    Label2: TLabel;
16
    Label3: TLabel;
17
    Label4: TLabel;
18
    Label5: TLabel;
19
    Label6: TLabel;
20
    EditMinX: TEdit;
21
    EditMaxX: TEdit;
22
    EditdX: TEdit;
23
    EditMinY: TEdit;
24
    EditMaxY: TEdit;
25
    EditdY: TEdit;
26
    EditMinZ: TEdit;
27
    EditMaxZ: TEdit;
28
    zLimitCB: TCheckBox;
29
    LabelFunc: TLabel;
30
    Editfxy: TEdit;
31
    Label9: TLabel;
32
    AddButton: TSpeedButton;
33
    DeleteButton: TSpeedButton;
34
    CheckListBox: TCheckListBox;
35
    MainMenu: TMainMenu;
36
    File1: TMenuItem;
37
    New1: TMenuItem;
38
    Open1: TMenuItem;
39
    Save: TMenuItem;
40
    SaveAs: TMenuItem;
41
    N1: TMenuItem;
42
    Exit1: TMenuItem;
43
    SaveDialog: TSaveDialog;
44
    OpenDialog: TOpenDialog;
45
    Label17: TLabel;
46
    ModeComboBox: TComboBox;
47
    StyleComboBox: TComboBox;
48
    ApplyBtn: TBitBtn;
49
    zCountLabel: TLabel;
50
    Centre: TSpeedButton;
51
    UpButton: TSpeedButton;
52
    DownButton: TSpeedButton;
53
    zCapCB: TCheckBox;
54
    GridValues: TSpeedButton;
55
    Label7: TLabel;
56
    EditNote: TEdit;
57
    procedure FormDestroy(Sender: TObject);
58
    procedure FloatKeyPress(Sender: TObject; var Key: Char);
59
    procedure fxyKeyPress(Sender: TObject; var Key: Char);
60
    procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
61

62
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
63
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
64
    procedure AddButtonClick(Sender: TObject);
65
    procedure SaveClick(Sender: TObject);
66
    procedure SaveAsClick(Sender: TObject);
67
    procedure CheckListBoxClick(Sender: TObject);
68
    procedure DeleteButtonClick(Sender: TObject);
69
    procedure Open1Click(Sender: TObject);
70
    procedure Exit1Click(Sender: TObject);
71
    procedure New1Click(Sender: TObject);
72
    procedure zLimitCBClick(Sender: TObject);
73
    procedure ModeComboBoxChange(Sender: TObject);
74
    procedure StyleComboBoxChange(Sender: TObject);
75
    procedure ApplyBtnClick(Sender: TObject);
76
    procedure EditfxyClick(Sender: TObject);
77
    procedure CheckListBoxClickCheck(Sender: TObject);
78
    procedure EditdXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
79
    procedure EditdYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
80
    procedure EditMinXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
81
    procedure EditMaxXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
82
    procedure EditMinYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
83
    procedure EditMaxYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
84
    procedure EditMinZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
85
    procedure EditMaxZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
86
    procedure EditfxyKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
87
    procedure CentreClick(Sender: TObject);
88
    procedure UpButtonClick(Sender: TObject);
89
    procedure DownButtonClick(Sender: TObject);
90
    procedure FormCreate(Sender: TObject);
91
    procedure zCapCBClick(Sender: TObject);
92
    procedure GridValuesClick(Sender: TObject);
93
    procedure PositiveKeyPress(Sender: TObject; var Key: Char);
94
    procedure EditNoteClick(Sender: TObject);
95
    procedure EditNoteKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
96

97
    private
98
    { Private declarations }
99
    NewFile: Boolean;
100
    TooManyPoints: integer;
101
    function ReadData(const FName: TFileName): Boolean;
102
    procedure OpenSelectedFile(Sender: TObject; FName: TFileName);
103
    procedure WriteData(const FName: TFileName);
104
    function DefaultPlotData: TPlotData;
105
    function DefaultViewData: TViewData;
106
    function DefaultAddedData: TAddedData;
107
    procedure ShowData(Sender: TObject);
108
    procedure AddNewPlot;
109
    procedure CountzPoints;
110
    procedure UpdateTPlotDataObject;
111
    procedure AddRecent(const f: TFileName);
112
  public
113
    { Public declarations }
114
    procedure ReadAndShowInitialData;
115
    procedure OpenRecentFile(FName: TFileName);
116
  end;
117

118
var
119
  FunctionsForm: TFunctionsForm;
120

121
implementation
122

123
uses
124
  OpenGLTokens, Math, GLVectorGeometry, Main, uParser, GridOptions, GLColor,
125
  Evaluate, GLVectorTypes, CoordOptions, DerivativeOptions, GridColors,
126
  PlotColors;
127

128
{$R *.lfm}
129

130
procedure TFunctionsForm.AddButtonClick(Sender: TObject);
131
begin
132
  AddNewPlot;
133
end;
134

135
procedure TFunctionsForm.EditdXKeyUp(Sender: TObject; var Key: Word;
136
                                      Shift: TShiftState);
137
var
138
  x: TGlFloat;
139

140
begin
141
  try
142
    x := StrToFloat(EditdX.Text);
143
  except
144
    x := 1.0;
145
  end;
146
  PlotData.xInc := x;
147
  ApplyBtn.Visible := True;
148
  UpdateTPlotDataObject;
149
  CountzPoints;
150
end;
151

152
procedure TFunctionsForm.PositiveKeyPress(Sender: TObject; var Key: Char);
153
begin
154
  with Sender as TEdit do
155
  if not CharInSet(Key, ['+', '0'..'9', '.', #8]) then Key := #0;
156
end;
157

158
procedure TFunctionsForm.EditdYKeyUp(Sender: TObject; var Key: Word;
159
                                      Shift: TShiftState);
160
var
161
  y: TGLFloat;
162

163
begin
164
  try
165
    y := StrToFloat(EditdY.Text);
166
  except
167
    y := 1.0;
168
  end;
169
  PlotData.yInc := y;
170
  ApplyBtn.Visible := True;
171
  UpdateTPlotDataObject;
172
  CountzPoints;
173
end;
174

175
procedure TFunctionsForm.EditfxyClick(Sender: TObject);
176
begin
177
  ViewForm.MousePoint.X := Maxint;
178
end;
179

180
procedure TFunctionsForm.EditfxyKeyUp(Sender: TObject; var Key: Word;
181
                                       Shift: TShiftState);
182
var
183
  e: byte;
184

185
begin
186
  if Key <> 13 then
187
  begin
188
    PlotData.txtStr := Editfxy.Text;
189
    PlotData.fxyStr := ScanText(Editfxy.Text);
190
    ParseAndEvaluate(PlotData.fxyStr, e);
191

192
    with CheckListBox do if (Count > 0) and (ItemIndex > -1)
193
    then Items[ItemIndex] := PlotData.txtStr;
194
    ApplyBtn.Visible := e = 0;
195
    UpdateTPlotDataObject;
196
  end;
197
end;
198

199
procedure TFunctionsForm.EditKeyDown(Sender: TObject; var Key: Word;
200
                                      Shift: TShiftState);
201
begin
202
  if (Key = VK_DELETE) or (Key = VK_BACK) then ApplyBtn.Visible := True;
203
end;
204

205
procedure TFunctionsForm.fxyKeyPress(Sender: TObject; var Key: Char);
206
begin
207
  with Sender as TEdit do
208
  begin
209
    if not CharInSet(UpCase(Key), ParseSet) then
210
    begin
211
      Key := #0;
212
      Exit;
213
    end;
214
    if Key = '`' then Key := #176;
215
  end;
216
end;
217

218
procedure TFunctionsForm.GridValuesClick(Sender: TObject);
219
var
220
  DoApply: Boolean;
221

222
begin
223
  with GridOptionsForm do
224
  DoApply := xyLock.Checked and zLock.Checked and MinLock.Checked;
225

226
  if DoApply then
227
  begin
228
    with ViewData.xyGrid.xRange do
229
    begin
230
      EditMinX.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
231
      PlotData.xMin := Minimum;
232
      EditMaxX.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
233
      PlotData.xMax := Maximum;
234
    end;
235

236
    with ViewData.xyGrid.yRange do
237
    begin
238
      EditMinY.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
239
      PlotData.yMin := Minimum;
240
      EditMaxY.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
241
      PlotData.yMax := Maximum;
242
    end;
243

244
    with ViewData.xzGrid.zRange do
245
    begin
246
      EditMinZ.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
247
      PlotData.zMin := Minimum;
248
      EditMaxZ.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
249
      PlotData.zMax := Maximum;
250
    end;
251
    ApplyBtnClick(Sender);
252
  end;
253
end;
254

255
procedure TFunctionsForm.ModeComboBoxChange(Sender: TObject);
256
begin
257
  PlotData.ViewMode := TViewMode(ModeComboBox.ItemIndex);
258
  UpdateTPlotDataObject;
259
  ApplyBtnClick(Sender);
260
end;
261

262
procedure TFunctionsForm.New1Click(Sender: TObject);
263
var
264
  i: integer;
265
  s: string;
266

267
begin
268
  if Altered or GridColorsAltered or DerivativeAltered then
269
  case MessageDlg('The current graph''s data has been altered.'+
270
            #13#10'Do you wish to save the alterations ?', mtConfirmation,
271
                    [mbYes, mbNo, mbCancel], 0) of
272
    mrYes:SaveClick(Sender);
273
 mrCancel:Exit;
274
  end;
275
  s := DataPath + GraphFName; { save original FName }
276
  if s <> GraphFName then AddRecent(s);
277
  with CheckListBox do
278
  begin
279
    for i := 0 to Items.Count -1 do Items.Objects[i].Free;
280
    Clear;
281
  end;
282

283
  GraphFName := NewFName;
284
  Caption := GraphFName;
285
  ViewForm.Caption := GraphFName;
286
  GridOptionsForm.Caption := GraphFName;
287
  EvaluateForm.Caption := GraphFName;
288
  CoordsForm.Caption := GraphFName;
289

290
  NewFile := True;
291
  Altered := False;
292
  ViewData := DefaultViewData;
293
  PlotData := DefaultPlotData;
294
  AddedData := DefaultAddedData;
295

296
  if GridColorsForm.Visible then GridColorsForm.Close;
297
  if PlotColorsForm.Visible then PlotColorsForm.Close;
298
  if DerivativesForm.Visible then DerivativesForm.Close;
299
  ApplyBtnClick(Sender);
300
  with CheckListBox do
301
  begin
302
    AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
303
    ItemIndex := Count -1;
304
    Checked[ItemIndex] := True;
305
  end;
306
  ViewForm.TargetCube.Position.SetPoint(0, 0, 0);
307
  ShowData(Sender);
308
end;
309

310
procedure TFunctionsForm.Open1Click(Sender: TObject);
311
var
312
  i: integer;
313
  s: string;
314

315
begin
316
  if DerivativesForm.Visible then DerivativesForm.Close;
317
  if GridColorsForm.Visible then GridColorsForm.ShowGridColorData;
318
  if PlotColorsForm.Visible then PlotColorsForm.ShowPlotColorData;
319
  if Altered or GridColorsAltered or DerivativeAltered then
320
  case MessageDlg('The current graph''s data has been altered.'+
321
            #13#10'Do you wish to save the alterations ?', mtConfirmation,
322
                    [mbYes, mbNo, mbCancel], 0) of
323
    mrYes: SaveClick(Sender);
324
 mrCancel:Exit;
325
    mrNo:
326
    begin
327
      Altered := False;
328
      GridColorsAltered := False;
329
      DerivativeAltered := False;
330
      NewFile := False;
331
    end
332
  end;
333

334
  with OpenDialog do
335
  begin
336
    InitialDir := DataPath;
337
    if Execute then
338
    begin
339
      s := DataPath + GraphFName; { save original FName }
340
      DataPath := ExtractFilePath(FileName);
341
      DataPath := IncludeTrailingPathDelimiter(DataPath);
342
      ViewForm.MousePoint.X := Maxint;
343
      GraphFName := ExtractFileName(FileName);
344
      if s <> GraphFName then AddRecent(s);
345
      with CheckListBox do
346
      begin
347
        for i := 0 to Items.Count -1 do Items.Objects[i].Free;
348
        Clear;
349
      end;
350
      if ReadData(DataPath + GraphFName) then ShowData(Sender);
351
      ApplyBtnClick(Sender);
352
      Altered := False;
353
      GridColorsAltered := False;
354
      DerivativeAltered := False;
355
      if GridColorsForm.Visible then GridColorsForm.ShowGridColorData;
356
      if PlotColorsForm.Visible then PlotColorsForm.ShowPlotColorData;
357
    end;
358
  end;
359
end;
360

361
procedure TFunctionsForm.EditMaxXKeyUp(Sender: TObject; var Key: Word;
362
                                        Shift: TShiftState);
363
var
364
  x: TGLFloat;
365

366
begin
367
  try
368
    x := StrToFloat(EditMaxX.Text);
369
  except
370
    x := 1.0;
371
  end;
372
  PlotData.xMax := x;
373
  ApplyBtn.Visible := True;
374
  UpdateTPlotDataObject;
375
  CountzPoints;
376
end;
377

378
procedure TFunctionsForm.EditMaxYKeyUp(Sender: TObject; var Key: Word;
379
                                        Shift: TShiftState);
380
var
381
  y: TGLFloat;
382

383
begin
384
  try
385
    y := StrToFloat(EditMaxY.Text);
386
  except
387
    y := 1.0;
388
  end;
389
  PlotData.yMax := y;
390
  ApplyBtn.Visible := True;
391
  UpdateTPlotDataObject;
392
  CountzPoints;
393
end;
394

395
procedure TFunctionsForm.EditMaxZKeyUp(Sender: TObject; var Key: Word;
396
                                        Shift: TShiftState);
397
var
398
  z: TGLFloat;
399

400
begin
401
  try
402
    z := StrToFloat(EditMaxZ.Text);
403
  except
404
    z := 1.0;
405
  end;
406
  PlotData.zMax := z;
407
  ApplyBtn.Visible := True;
408
  UpdateTPlotDataObject;
409
  CountzPoints;
410
end;
411

412
procedure TFunctionsForm.EditMinXKeyUp(Sender: TObject; var Key: Word;
413
                                        Shift: TShiftState);
414
var
415
  x: TGLFloat;
416

417
begin
418
  try
419
    x := StrToFloat(EditMinX.Text);
420
  except
421
    x := -1.0;
422
  end;
423
  PlotData.xMin := x;
424
  ApplyBtn.Visible := True;
425
  UpdateTPlotDataObject;
426
  CountzPoints;
427
end;
428

429
procedure TFunctionsForm.EditMinYKeyUp(Sender: TObject; var Key: Word;
430
                                        Shift: TShiftState);
431
var
432
  y: TGLFloat;
433

434
begin
435
  try
436
    y := StrToFloat(EditMinY.Text);
437
  except
438
    y := -1.0;
439
  end;
440
  PlotData.yMin := y;
441
  ApplyBtn.Visible := True;
442
  UpdateTPlotDataObject;
443
  CountzPoints;
444
end;
445

446
procedure TFunctionsForm.EditMinZKeyUp(Sender: TObject; var Key: Word;
447
                                        Shift: TShiftState);
448
var
449
  z: TGLFloat;
450

451
begin
452
  try
453
    z := StrToFloat(EditMinZ.Text);
454
  except
455
    z := -1.0;
456
  end;
457
  PlotData.zMin := z;
458
  ApplyBtn.Visible := True;
459
  UpdateTPlotDataObject;
460
  CountzPoints;
461
end;
462

463
procedure TFunctionsForm.EditNoteClick(Sender: TObject);
464
begin
465
  ViewForm.MousePoint.X := Maxint;
466
end;
467

468
procedure TFunctionsForm.EditNoteKeyUp(Sender: TObject; var Key: Word;
469
                                        Shift: TShiftState);
470
begin
471
  if Key <> 13 then
472
  begin
473
    PlotData.NoteStr := EditNote.Text;
474
    with CheckListBox do if (Count > 0) and (ItemIndex > -1)
475
    then TPlotDataObject(Items.Objects[ItemIndex]).Data := PlotData;
476
    Altered := True;
477
  end;
478
end;
479

480
procedure TFunctionsForm.Exit1Click(Sender: TObject);
481
begin
482
  ViewForm.Exit1Click(Sender);
483
end;
484

485
procedure TFunctionsForm.FloatKeyPress(Sender: TObject; var Key: Char);
486
begin
487
  with Sender as TEdit do
488
  if not CharInSet(Key, AnyFloat) then Key := #0;
489
end;
490

491
procedure TFunctionsForm.FormClose(Sender: TObject; var Action: TCloseAction);
492
var
493
  i: integer;
494

495
begin
496
  for i := 0 to CheckListBox.Items.Count -1 do
497
                CheckListBox.Items.Objects[i].Free;
498
  CheckListBox.Clear;
499
end;
500

501
procedure TFunctionsForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
502
begin
503
  ViewForm.Close;
504
  CanClose := not ViewForm.Visible;
505
end;
506

507
procedure TFunctionsForm.FormCreate(Sender: TObject);
508
begin
509

510
end;
511

512
procedure TFunctionsForm.FormDestroy(Sender: TObject);
513
var
514
  i: integer;
515

516
begin
517
  with CheckListBox do for i := 0 to Count -1 do Items.Objects[i].Free;
518
end;
519

520
function TFunctionsForm.DefaultPlotData: TPlotData;
521
begin
522
  with Result do
523
  begin
524
    fxyStr := '';                { function string }
525
    txtStr := '';                { txt -> fxy when scanned }
526
    NoteStr := '';               { describe function }
527
    xMin := -10.0;               { x limits and increment }
528
    xMax :=  10.0;
529
    xInc :=   1.0;
530
    yMin := -10.0;               { y limits and increment }
531
    yMax :=  10.0;
532
    yInc :=   1.0;
533
    zMin := -10.0;               { z limits }
534
    zMax :=  10.0;
535
    zLim := False;               { false = z limits do not apply }
536
    zCap := False;               { above zLim values := NAN }
537

538
    UpperColor := VectorMake(255, 0, 0, 1000);
539
    LowerColor := VectorMake(0, 0, 255, 1000);
540

541
    ColorBlend := 0.5;
542
    ColorMove := 0.0;
543
    ViewMode := vmAmbient;
544
    fxyMode := fxyFill;
545
  end;
546
end;
547

548
function TFunctionsForm.DefaultViewData: TViewData;
549
begin
550
  with Result do
551
  begin
552
    CameraCubeAt := VectorMake(0, 0, 0);
553
    CameraAt := VectorMake(50, 50, 30);
554
    fLength := 200;
555
    LightAt := VectorMake(50, 50, 50);
556
    ViewDepth := 1000;
557
    BackColor := clActiveCaption;
558
    with xyGrid do
559
    begin
560
      Color := clrBlue;
561
      with xRange do
562
      begin
563
        Maximum :=  10;
564
        Minimum := -10;
565
        Step := 1;
566
      end;
567
      with yRange do
568
      begin
569
        Maximum :=  10;
570
        Minimum := -10;
571
        Step := 1;
572
      end;
573
      zPosition := -10;
574
      zScale := 1;
575
      IsVisible := True;
576
      IsChecked := True;
577
    end;
578

579
    with xzGrid do
580
    begin
581
      Color := clrGreen;
582
      with xRange do
583
      begin
584
        Maximum :=  10;
585
        Minimum := -10;
586
        Step := 1;
587
      end;
588
      with zRange do
589
      begin
590
        Maximum :=  10;
591
        Minimum := -10;
592
        Step := 1;
593
      end;
594
      yPosition := -10;
595
      IsVisible := True;
596
      IsChecked := True;
597
    end;
598

599
    with yzGrid do
600
    begin
601
      Color := clrRed;
602
      with yRange do
603
      begin
604
        Maximum :=  10;
605
        Minimum := -10;
606
        Step := 1;
607
      end;
608
      with zRange do
609
      begin
610
        Maximum :=  10;
611
        Minimum := -10;
612
        Step := 1;
613
      end;
614
      xPosition := -10;
615
      IsVisible := True;
616
      IsChecked := True;
617
    end;
618

619
    xEvaluate := 0.0;
620
    yEvaluate := 0.0;
621
    CoordChecked := False;
622
    ToGridsChecked := False;
623
    dzdx_dyChecked := False;
624
    BoxChecked := False;
625
    CoordWidth := 1;
626
    CoordColor := clBlack;
627
    BoxLnWidth := 1;
628
    BoxLnColor := clrBlack;
629

630
    TextVisible := False;
631
    TextFontN := 'Tahoma';
632
    TextFontSz := 10;
633
    xPosYMax := False;
634
    xPosZMax := False;
635
    xTextColor := clBlack;
636

637
    yPosXMax := False;
638
    yPosZMax := False;
639
    yTextColor := clBlack;
640

641
    TextVisible := True;
642
    TextFontN := 'Tahoma';    { ViewForm.GLWinBitmapFont }
643
    TextFontSz := 20;
644

645
    xPosYMax := False;
646
    xPosZMax := False;
647
    xTextColor := clRed;
648

649
    yPosXMax := False;
650
    yPosZMax := False;
651
    yTextColor := clGreen;
652

653
    zPosXMax := False;
654
    zPosYMax := False;
655
    zTextColor := clBlue;
656
    ArrowSize := 1.0;
657
  end;
658
end;
659

660
function TFunctionsForm.DefaultAddedData: TAddedData;
661
begin
662
  with Result do
663
  begin
664
    xMin := -10.0;               { x limits and increment }
665
    xMax :=  10.0;
666
    xInc :=   1.0;
667
    yMin := -10.0;               { y limits and increment }
668
    yMax :=  10.0;
669
    yInc :=   1.0;
670
    zMin := -10.0;               { z limits }
671
    zMax :=  10.0;
672
    zLim := False;               { false = z limits do not apply }
673
    zCap := False;               { above zLim values := NAN }
674

675
    UpperColor := VectorMake(255, 0, 0, 1000);
676
    LowerColor := VectorMake(0, 0, 255, 1000);
677

678
    ColorBlend := 0.5;
679
    ColorMove := 0.0;
680
    ViewMode := vmAmbient;
681
    fxyMode := fxyFill;
682

683
    AddLineWidth := 1;
684
    AddLineColor := clBlack;
685
    AddedAs := AddNone;
686
  end;
687
end;
688

689
procedure TFunctionsForm.CountzPoints;
690
var
691
  n: integer;
692

693
begin
694
  with PlotData do
695
  n := round((xMax - xMin + xInc)/xInc)*round((yMax - yMin + yInc)/yInc);
696
  TooManyPoints := round(Log10(n));
697
  case TooManyPoints of
698
  0..2:ZCountLabel.Font.Color := clLime;
699
     3:ZCountLabel.Font.Color := clTeal;
700
     4:ZCountLabel.Font.Color := clGreen;
701
     5:ZCountLabel.Font.Color := clBlue;
702
  else ZCountLabel.Font.Color := clRed;
703
  end;
704
  if TooManyPoints > 6
705
  then ZCountLabel.Caption := 'Too many Points: ' + FloatToStrF(n, ffnumber, 8, 0)+' !'
706
  else ZCountLabel.Caption := 'N° Points = ' + FloatToStrF(n, ffnumber, 8, 0);
707
end;
708

709
procedure TFunctionsForm.UpdateTPlotDataObject;
710
begin
711
  with CheckListBox do
712
  TPlotDataObject(Items.Objects[ItemIndex]).Data := PlotData;
713
end;
714

715
procedure TFunctionsForm.DeleteButtonClick(Sender: TObject);
716
var
717
  i: integer;
718

719
begin
720
  if CheckListBox.Count > 1 then
721
  begin
722
    with CheckListBox do
723
    begin
724
      i := ItemIndex;
725
      with Items.Objects[i] as TPlotDataObject do Free;
726
      Items.Delete(i);
727
      if i > Count -1 then i := Count -1;
728
      ItemIndex := i;
729
      PlotData := TPlotDataObject(Items.Objects[ItemIndex]).Data;
730
      DeleteButton.Enabled := Count > 1;
731
    end;
732
    ApplyBtnClick(Sender);
733
  end
734
end;
735

736
procedure TFunctionsForm.DownButtonClick(Sender: TObject);
737
var
738
  i: integer;
739

740
begin
741
  with CheckListBox do
742
  begin
743
    i := ItemIndex;
744
    if i < Count -1 then Items.Move(i, i+1);
745
    ItemIndex := i+1;
746
  end;
747
  CheckListBoxClick(Sender);
748
  Altered := True;
749
end;
750

751
function TFunctionsForm.ReadData(const FName: TFileName): Boolean;
752
  function StrToVector(s: string): TVector;
753
  var
754
    t: string;
755
    i: integer;
756

757
  begin
758
    i := Pos(',', s);
759
    t := Copy(s, 1, i -1);
760
    Result.X := StrToFloat(t);
761

762
    s := Copy(s, i +1, Length(s));
763
    i := Pos(',', s);
764
    t := Copy(s, 1, i -1);
765
    Result.Y := StrToFloat(t);
766

767
    s := Copy(s, i +1, Length(s));
768
    Result.Z := StrToFloat(s);
769
  end;
770

771
  function StrToColor(s: string): TColorVector;
772
  var
773
    t: string;
774
    i: integer;
775

776
  begin
777
    i := Pos(',', s);
778
    t := Copy(s, 1, i -1);
779
    Result.X := StrToFloat(t);
780

781
    s := Copy(s, i +1, Length(s));
782
    i := Pos(',', s);
783
    t := Copy(s, 1, i -1);
784
    Result.Y := StrToFloat(t);
785

786
    s := Copy(s, i +1, Length(s));
787
    i := Pos(',', s);
788
    t := Copy(s, 1, i -1);
789
    Result.Z := StrToFloat(t);
790

791
    s := Copy(s, i +1, Length(s));
792
    Result.W := StrToFloat(s);
793
  end;
794

795
  function StrToRange(s: string): TRange;
796
  var
797
    t: string;
798
    i: integer;
799

800
  begin
801
    i := Pos(',', s);
802
    t := Copy(s, 1, i -1);
803
    Result.Maximum := StrToFloat(t);
804

805
    s := Copy(s, i +1, Length(s));
806
    i := Pos(',', s);
807
    t := Copy(s, 1, i -1);
808
    Result.Minimum := StrToFloat(t);
809

810
    s := Copy(s, i +1, Length(s));
811
    Result.Step := StrToFloat(s);
812
  end;
813

814
var
815
  s, t: string;
816
  f: TextFile;
817
  i, j, k, n: integer;
818

819
begin
820
  Result := False;
821
  if FileExists(FName) then
822
  begin
823
    AssignFile(f, FName);
824
    try
825
      Reset(f);
826
      Readln(f, s);
827
      j := 0;
828
      i := Pos(#9, s);
829

830
      while i > 0 do
831
      begin
832
        t := Copy(s, 1, i -1);
833
        s := Copy(s, i +1, Length(s));
834
        i := Pos(#9, s);
835
        Inc(j);
836

837
        with ViewData do
838
        case j of
839
        1:CameraCubeAt := StrToVector(t);
840
        2:CameraAt := StrToVector(t);
841
        3:fLength := StrToFloat(t);
842
        4:LightAt := StrToVector(t);
843
        5:ViewDepth := StrToFloat(t);
844
        6:BackColor := StrToInt(t);
845

846
        7:xyGrid.Color := StrToColor(t);
847
        8:xyGrid.xRange := StrToRange(t);
848
        9:xyGrid.yRange := StrToRange(t);
849
       10:xyGrid.zPosition := StrToFloat(t);
850
       11:xyGrid.zScale := StrToFloat(t);
851
       12:xyGrid.IsVisible := StrToBool(t);
852
       13:xyGrid.IsChecked := StrToBool(t);
853

854
       14:xzGrid.Color := StrToColor(t);
855
       15:xzGrid.xRange := StrToRange(t);
856
       16:xzGrid.zRange := StrToRange(t);
857
       17:xzGrid.yPosition := StrToFloat(t);
858
       18:xzGrid.IsVisible := StrToBool(t);
859
       19:xzGrid.IsChecked := StrToBool(t);
860

861
       20:yzGrid.Color := StrToColor(t);
862
       21:yzGrid.yRange := StrToRange(t);
863
       22:yzGrid.zRange := StrToRange(t);
864
       23:yzGrid.xPosition := StrToFloat(t);
865
       24:yzGrid.IsVisible := StrToBool(t);
866
       25:yzGrid.IsChecked := StrToBool(t);
867
       26:ViewForm.TargetCube.Position.AsVector := StrToVector(t);
868

869
       27:xEvaluate := StrToFloat(t);
870
       28:yEvaluate := StrToFloat(t);
871
       29:CoordChecked := StrToBool(t);
872
       30:ToGridsChecked := StrToBool(t);
873
       31:dzdx_dyChecked := StrToBool(t);
874
       32:BoxChecked := StrToBool(t);
875
       33:CoordWidth := StrToInt(t);
876
       34:CoordColor := StrToInt(t);
877
       35:BoxLnWidth := StrToInt(t);
878
       36:BoxLnColor := StrToColor(t);
879
       37:TextVisible := StrToBool(t);
880
       38:TextFontN := t;
881
       39:TextFontSz := StrToInt(t);
882
       40:xPosYMax := StrToBool(t);
883
       41:xPosZMax := StrToBool(t);
884
       42:xTextColor := StrToInt(t);
885
       43:yPosXMax := StrToBool(t);
886
       44:yPosZMax := StrToBool(t);
887
       45:yTextColor := StrToInt(t);
888
       46:zPosXMax := StrToBool(t);
889
       47:zPosYMax := StrToBool(t);
890
       48:zTextColor := StrToInt(t);
891
       49:ArrowSize := StrTofloat(t);
892
        end;
893
      end;
894
      n := StrToInt(s);  { number of functions }
895
      for k := 0 to n -1 do
896
      begin{ read each function's data }
897
        Readln(f, s);
898
        j := 0;
899
        i := Pos(#9, s);
900

901
        while i > 0 do
902
        begin
903
          t := Copy(s, 1, i -1);
904
          s := Copy(s, i +1, Length(s));
905
          i := Pos(#9, s);
906
          Inc(j);
907

908
          with PlotData do
909
          case j of
910
          1:fxyStr := t;
911
          2:txtStr := t;
912
          3:NoteStr := t;
913
          4:xMin := StrToFloat(t);
914
          5:xMax := StrToFloat(t);
915
          6:xInc := StrToFloat(t);
916
          7:yMin := StrToFloat(t);
917
          8:yMax := StrToFloat(t);
918
          9:yInc := StrToFloat(t);
919
         10:zMin := StrToFloat(t);
920
         11:zMax := StrToFloat(t);
921
         12:zLim := StrToBool(t);
922
         13:zcap := StrToBool(t);
923
         14:UpperColor := StrToColor(t);
924
         15:LowerColor := StrToColor(t);
925
         16:ColorBlend := StrToFloat(t);
926
         17:ColorMove := StrToFloat(t);
927
         18:ViewMode := TViewMode(StrToInt(t));
928
         19:fxyMode := TfxyMode(StrToInt(t));
929
          end;
930
        end;
931
        with CheckListBox do
932
        begin
933
          AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
934
          Checked[Count -1] := StrToBool(s);
935
        end;
936
      end;
937

938
      Readln(f, s);
939
      j := 0;
940
      i := Pos(#9, s);
941

942
      while i > 0 do
943
      begin
944
        t := Copy(s, 1, i -1);
945
        s := Copy(s, i +1, Length(s));
946
        i := Pos(#9, s);
947
        Inc(j);
948
        with AddedData do
949
        case j of
950
        1:xMin := StrToFloat(t);
951
        2:xMax := StrToFloat(t);
952
        3:xInc := StrToFloat(t);
953
        4:yMin := StrToFloat(t);
954
        5:yMax := StrToFloat(t);
955
        6:yInc := StrToFloat(t);
956
        7:zMin := StrToFloat(t);
957
        8:zMax := StrToFloat(t);
958
        9:zLim := StrToBool(t);
959
       10:zcap := StrToBool(t);
960
       11:UpperColor := StrToColor(t);
961
       12:LowerColor := StrToColor(t);
962
       13:ColorBlend := StrToFloat(t);
963
       14:ColorMove := StrToFloat(t);
964
       15:ViewMode := TViewMode(StrToInt(t));
965
       16:fxyMode := TfxyMode(StrToInt(t));
966
       17:AddLineWidth := StrToInt(t);
967
       18:AddLineColor := StrToInt(t);
968
       19:AddedAs := TAddedType(StrToInt(t));
969
        end;
970
      end;
971

972
    except
973
      MessageDlg('File Error! An Error has occurred'+
974
           #13#10'when attempting to read "'+FName+'".',
975
      mtError, [mbOK], 0);
976
      CloseFile(f);
977
      Exit;
978
    end;
979
    CloseFile(f);
980
    Result := True;
981
    CheckListBox.ItemIndex := CheckListBox.Count -1;
982
    NewFile := not Result;
983
  end;
984
end;
985

986
procedure TFunctionsForm.SaveClick(Sender: TObject);
987
begin
988
  if NewFile then SaveAsClick(Sender) else WriteData(DataPath + GraphFName);
989
end;
990

991
procedure TFunctionsForm.SaveAsClick(Sender: TObject);
992
begin
993
  with SaveDialog do
994
  begin
995
    InitialDir := DataPath;
996
    FileName := GraphFName;
997
    if Execute then
998
    begin
999
      GraphFName := ExtractFileName(FileName);
1000
      DataPath := ExtractFilePath(FileName);
1001
      DataPath := IncludeTrailingPathDelimiter(DataPath);
1002
      WriteData(DataPath + GraphFName);
1003
    end;
1004
  end;
1005
  Caption := GraphFName;
1006
  ViewForm.Caption := GraphFName;
1007
  GridOptionsForm.Caption := GraphFName;
1008
  EvaluateForm.Caption := GraphFName;
1009
  CoordsForm.Caption := GraphFName;
1010
end;
1011

1012
procedure TFunctionsForm.WriteData(const FName: TFileName);
1013
  function VectorToStr(v: TVector): string;
1014
  begin
1015
    Result := FloatToStr(v.X)+','+FloatToStr(v.Y)+','+FloatToStr(v.Z);
1016
  end;
1017

1018
  function ColorToStr(c: TColorVector): string;
1019
  begin
1020
    Result :=
1021
    FloatToStr(c.X)+','+FloatToStr(c.Y)+','+FloatToStr(c.Z)+','+FloatToStr(c.W);
1022
  end;
1023

1024
  function RangetoStr(r: TRange): string;
1025
  begin
1026
    Result :=
1027
    FloatToStr(r.Maximum)+','+FloatToStr(r.Minimum)+','+FloatTostr(r.Step);
1028
  end;
1029

1030
var
1031
  f: TextFile;
1032
  s: string;
1033
  i: integer;
1034

1035
begin
1036
  try
1037
    AssignFile(f, FName);
1038
    try
1039
      Rewrite(f);   { write tab delimited data }
1040
      with ViewData do
1041
      begin
1042
        CameraCubeAt := ViewForm.CameraCube.Position.AsVector;
1043
        CameraAt := ViewForm.Camera.Position.AsVector;
1044
        fLength := ViewForm.Camera.FocalLength;
1045
        LightAt := ViewForm.GLLight.Position.AsVector;
1046
        ViewDepth := ViewForm.Camera.DepthOfView;
1047
        BackColor := ViewForm.GLSViewer.Buffer.BackgroundColor;
1048

1049
        s := VectorToStr(CameraCubeAt)+#9+VectorToStr(CameraAt)+#9+
1050
        FloatToStr(fLength)+#9+VectorToStr(LightAt)+#9+
1051
        FloatToStr(ViewDepth)+#9+IntToStr(BackColor)+#9+
1052
                            {xy}
1053
        ColorToStr(xyGrid.Color)+#9+
1054
        RangeToStr(xyGrid.xRange)+#9+RangeToStr(xyGrid.yRange)+#9+
1055
        FloatToStr(xyGrid.zPosition)+#9+FloatToStr(xyGrid.zScale)+#9+
1056
        BoolToStr(xyGrid.IsVisible)+#9+BoolToStr(xyGrid.IsChecked)+#9+
1057
                            {xz}
1058
        ColorToStr(xzGrid.Color)+#9+
1059
        RangeToStr(xzGrid.xRange)+#9+RangeToStr(xzGrid.zRange)+#9+
1060
        FloatToStr(xzGrid.yPosition)+#9+BoolToStr(xzGrid.IsVisible)+#9+
1061
        BoolToStr(xzGrid.IsChecked)+#9+
1062
                            {yz}
1063
        ColorToStr(yzGrid.Color)+#9+
1064
        RangeToStr(yzGrid.yRange)+#9+RangeToStr(yzGrid.zRange)+#9+
1065
        FloatToStr(yzGrid.xPosition)+#9+BoolToStr(yzGrid.IsVisible)+#9+
1066
        BoolToStr(yzGrid.IsChecked)+#9+
1067
                            { Target}
1068
        VectorToStr(ViewForm.TargetCube.Position.AsVector)+#9+
1069

1070
        FloatToStr(xEvaluate)+#9+FloatToStr(yEvaluate)+#9+
1071
        BoolToStr(CoordChecked)+#9+BoolToStr(ToGridsChecked)+#9+
1072
        BoolToStr(dzdx_dyChecked)+#9+BoolToStr(BoxChecked)+#9+
1073
        IntToStr(CoordWidth)+#9+IntToStr(CoordColor)+#9+
1074
        IntToStr(BoxLnWidth)+#9+ColorToStr(BoxLnColor)+#9+
1075
        BoolToStr(TextVisible)+#9+TextFontN+#9+IntToStr(TextFontSz)+#9+
1076
        BoolToStr(xPosYMax)+#9+BoolToStr(xPosZMax)+#9+IntToStr(xTextColor)+#9+
1077
        BoolToStr(yPosXMax)+#9+BoolToStr(yPosZMax)+#9+IntToStr(yTextColor)+#9+
1078
        BoolToStr(zPosXMax)+#9+BoolToStr(zPosYMax)+#9+IntToStr(zTextColor)+#9+
1079
        FloatToStr(ArrowSize)+#9+
1080
        IntToStr(CheckListBox.Count);  { number of functions }
1081
      end;
1082
      writeln(f, s);
1083

1084
      for i := 0 to CheckListBox.Count -1 do { each function }
1085
      begin
1086
        PlotData := TPlotDataObject(CheckListBox.Items.Objects[i]).Data;
1087
        with PlotData do
1088
        begin
1089
          s := fxyStr+#9+txtStr+#9+NoteStr+#9+
1090
          FloatToStr(xMin)+#9+FloatToStr(xMax)+#9+FloatToStr(xInc)+#9+
1091
          FloatToStr(yMin)+#9+FloatToStr(yMax)+#9+FloatToStr(yInc)+#9+
1092
          FloatToStr(zMin)+#9+FloatToStr(zMax)+#9+BoolToStr(zLim)+#9+
1093
          BoolToStr(zCap)+#9+ColorToStr(UpperColor)+#9+ColorToStr(LowerColor)+#9+
1094
          FloatToStr(ColorBlend)+#9+FloatToStr(ColorMove)+#9+IntToStr(Ord(ViewMode))+#9+
1095
          IntToStr(Ord(fxyMode))+#9+BoolToStr(CheckListBox.Checked[i]);
1096
        end;
1097
        writeln(f, s);
1098
      end;
1099

1100
      with AddedData do
1101
      begin
1102
        s := FloatToStr(xMin)+#9+FloatToStr(xMax)+#9+FloatToStr(xInc)+#9+
1103
        FloatToStr(yMin)+#9+FloatToStr(yMax)+#9+FloatToStr(yInc)+#9+
1104
        FloatToStr(zMin)+#9+FloatToStr(zMax)+#9+BoolToStr(zLim)+#9+
1105
        BoolToStr(zCap)+#9+ColorToStr(UpperColor)+#9+ColorToStr(LowerColor)+#9+
1106
        FloatToStr(ColorBlend)+#9+FloatToStr(ColorMove)+#9+IntToStr(Ord(ViewMode))+#9+
1107
        IntToStr(Ord(fxyMode))+#9+IntToStr(AddLineWidth)+#9+IntToStr(AddLineColor)+#9+
1108
        IntToStr(Ord(AddedAs));
1109
      end;
1110
      writeln(f, s);
1111
    finally
1112
      Flush(f);
1113
      CloseFile(f);
1114
    end;
1115
  except
1116
    MessageDlg('File Error! An Error has occurred'+
1117
         #13#10'when attempting to write to "'+GraphFName+'".',
1118
    mtError, [mbOK], 0);
1119
  end;
1120
  NewFile := False;
1121
  Altered := False;
1122
  Layout.CurrentGraphFName := GraphFName;
1123
end;
1124

1125
procedure TFunctionsForm.zCapCBClick(Sender: TObject);
1126
begin
1127
  PlotData.zCap := zCapCB.Checked;
1128
  UpdateTPlotDataObject;
1129
  Applybtn.Visible := True;
1130
end;
1131

1132
procedure TFunctionsForm.zLimitCBClick(Sender: TObject);
1133
begin
1134
  PlotData.zLim := zLimitCB.Checked;
1135
  UpdateTPlotDataObject;
1136
  Applybtn.Visible := True;
1137
end;
1138

1139
procedure TFunctionsForm.ShowData(Sender: TObject);
1140
begin
1141
  with ViewData do
1142
  begin
1143
    if not(Sender is TCheckListBox) then
1144
    begin
1145
      ViewForm.CameraCube.Position.AsVector := CameraCubeAt;
1146
      ViewForm.Camera.Position.AsVector := CameraAt;
1147
      ViewForm.Camera.FocalLength := fLength;
1148
      ViewForm.GLLight.Position.AsVector := LightAt;
1149
      ViewForm.Camera.DepthOfView := ViewDepth;
1150
      ViewForm.GLSViewer.Buffer.BackgroundColor := BackColor;
1151
    end;
1152

1153
    GridOptionsForm.EditViewDepth.Text := FloatToStrF(ViewDepth, ffGeneral, 7, 4);
1154

1155
                            {xy}
1156
    GridOptionsForm.EditxyGridMinx.Text := FloatToStrF(xyGrid.xRange.Minimum, ffGeneral, 7, 4);
1157
    ViewForm.GLxyGrid.XSamplingScale.Min := xyGrid.xRange.Minimum;
1158
    GridOptionsForm.EditxyGridMiny.Text := FloatToStrF(xyGrid.yRange.Minimum, ffGeneral, 7, 4);
1159
    ViewForm.GLxyGrid.YSamplingScale.Min := xyGrid.yRange.Minimum;
1160

1161
    GridOptionsForm.EditxyGridMaxx.Text := FloatToStrF(xyGrid.xRange.Maximum, ffGeneral, 7, 4);
1162
    ViewForm.GLxyGrid.XSamplingScale.Max := xyGrid.xRange.Maximum;
1163
    GridOptionsForm.EditxyGridMaxy.Text := FloatToStrF(xyGrid.yRange.Maximum, ffGeneral, 7, 4);
1164
    ViewForm.GLxyGrid.YSamplingScale.Max := xyGrid.yRange.Maximum;
1165

1166
    GridOptionsForm.EditxyGridStpx.Text := FloatToStrF(xyGrid.xRange.Step, ffGeneral, 7, 4);
1167
    ViewForm.GLxyGrid.XSamplingScale.Step := xyGrid.xRange.Step;
1168
    GridOptionsForm.EditxyGridStpy.Text := FloatToStrF(xyGrid.yRange.Step, ffGeneral, 7, 4);
1169
    ViewForm.GLxyGrid.YSamplingScale.Step := xyGrid.yRange.Step;
1170

1171
    GridOptionsForm.EditxyGridPosz.Text := FloatToStrF(xyGrid.zPosition, ffGeneral, 7, 4);
1172
    ViewForm.GLxyGrid.Position.Z := xyGrid.zPosition*xyGrid.zScale;
1173

1174
    GridOptionsForm.EditzScale.Text := FloatToStrF(xyGrid.zScale, ffGeneral, 7, 4);
1175
    ViewForm.GLxzGrid.Scale.Z := xyGrid.zScale;
1176
    ViewForm.GLyzGrid.Scale.Z := xyGrid.zScale;
1177

1178
    ViewForm.GLxyGrid.LineColor.SetColor(xyGrid.Color.X, xyGrid.Color.Y,
1179
                                         xyGrid.Color.Z, xyGrid.Color.W);
1180

1181
                            {xz}
1182
    GridOptionsForm.EditxzGridMinx.Text := FloatToStrF(xzGrid.xRange.Minimum, ffGeneral, 7, 4);
1183
    ViewForm.GLxzGrid.XSamplingScale.Min := xzGrid.xRange.Minimum;
1184
    GridOptionsForm.EditxzGridMinz.Text := FloatToStrF(xzGrid.zRange.Minimum, ffGeneral, 7, 4);
1185
    ViewForm.GLxzGrid.ZSamplingScale.Min := xzGrid.zRange.Minimum;
1186

1187
    GridOptionsForm.EditxzGridMaxx.Text := FloatToStrF(xzGrid.xRange.Maximum, ffGeneral, 7, 4);
1188
    ViewForm.GLxzGrid.XSamplingScale.Max := xzGrid.xRange.Maximum;
1189
    GridOptionsForm.EditxzGridMaxz.Text := FloatToStrF(xzGrid.zRange.Maximum, ffGeneral, 7, 4);
1190
    ViewForm.GLxzGrid.ZSamplingScale.Max := xzGrid.zRange.Maximum;
1191

1192
    GridOptionsForm.EditxzGridStpx.Text := FloatToStrF(xzGrid.xRange.Step, ffGeneral, 7, 4);
1193
    ViewForm.GLxzGrid.XSamplingScale.Step := xzGrid.xRange.Step;
1194
    GridOptionsForm.EditxzGridStpz.Text := FloatToStrF(xzGrid.zRange.Step, ffGeneral, 7, 4);
1195
    ViewForm.GLxzGrid.ZSamplingScale.Step := xzGrid.zRange.Step;
1196

1197
    GridOptionsForm.EditxzGridPosy.Text := FloatToStrF(xzGrid.yPosition, ffGeneral, 7, 4);
1198
    ViewForm.GLxzGrid.Position.Y := xzGrid.yPosition;
1199

1200
    ViewForm.GLxzGrid.LineColor.SetColor(xzGrid.Color.X, xzGrid.Color.Y,
1201
                                         xzGrid.Color.Z, xzGrid.Color.W);
1202

1203
                            {yz}
1204
    GridOptionsForm.EdityzGridMiny.Text := FloatToStrF(yzGrid.yRange.Minimum, ffGeneral, 7, 4);
1205
    ViewForm.GLyzGrid.YSamplingScale.Min := yzGrid.yRange.Minimum;
1206
    GridOptionsForm.EdityzGridMinz.Text := FloatToStrF(yzGrid.zRange.Minimum, ffGeneral, 7, 4);
1207
    ViewForm.GLyzGrid.ZSamplingScale.Min := yzGrid.zRange.Minimum;
1208

1209
    GridOptionsForm.EdityzGridMaxy.Text := FloatToStrF(yzGrid.yRange.Maximum, ffGeneral, 7, 4);
1210
    ViewForm.GLyzGrid.YSamplingScale.Max := yzGrid.yRange.Maximum;
1211
    GridOptionsForm.EdityzGridMaxz.Text := FloatToStrF(yzGrid.zRange.Maximum, ffGeneral, 7, 4);
1212
    ViewForm.GLyzGrid.ZSamplingScale.Max := yzGrid.zRange.Maximum;
1213

1214
    GridOptionsForm.EdityzGridStpy.Text := FloatToStrF(yzGrid.yRange.Step, ffGeneral, 7, 4);
1215
    ViewForm.GLyzGrid.YSamplingScale.Step := yzGrid.yRange.Step;
1216
    GridOptionsForm.EdityzGridStpz.Text := FloatToStrF(yzGrid.zRange.Step, ffGeneral, 7, 4);
1217
    ViewForm.GLyzGrid.ZSamplingScale.Step := yzGrid.zRange.Step;
1218

1219
    GridOptionsForm.EdityzGridPosx.Text := FloatToStrF(yzGrid.xPosition, ffGeneral, 7, 4);
1220
    ViewForm.GLyzGrid.Position.X := yzGrid.xPosition;
1221

1222
    ViewForm.GLyzGrid.LineColor.SetColor(yzGrid.Color.X, yzGrid.Color.Y,
1223
                                         yzGrid.Color.Z, yzGrid.Color.W);
1224

1225
    ViewForm.BoxLine1.LineColor.SetColor(BoxLnColor.X, BoxLnColor.Y,
1226
                                         BoxLnColor.Z, BoxLnColor.W);
1227
    ViewForm.BoxLine2.LineColor := ViewForm.BoxLine1.LineColor;
1228
    ViewForm.BoxLine3.LineColor := ViewForm.BoxLine1.LineColor;
1229
    ViewForm.BoxLine4.LineColor := ViewForm.BoxLine1.LineColor;
1230

1231
    GridOptionsForm.xyGridCB.Checked := xyGrid.IsVisible;
1232
    GridOptionsForm.xyLock.Checked := xyGrid.IsChecked;
1233
    ViewForm.GLxyGrid.Visible := xyGrid.IsVisible;
1234

1235
    GridOptionsForm.xzGridCB.Checked := xzGrid.IsVisible;
1236
    GridOptionsForm.zLock.Checked := xzGrid.IsChecked;
1237
    ViewForm.GLxzGrid.Visible := xzGrid.IsVisible;
1238

1239
    GridOptionsForm.yzGridCB.Checked := yzGrid.IsVisible;
1240
    GridOptionsForm.MinLock.Checked := yzGrid.IsChecked;
1241
    ViewForm.GLyzGrid.Visible := yzGrid.IsVisible;
1242

1243
    GridOptionsForm.EditzScale.Text := FloatToStrF(xyGrid.zScale, ffGeneral, 7, 4);
1244
    ViewForm.GLxzGrid.Scale.Z := xyGrid.zScale;
1245
    ViewForm.GLyzGrid.Scale.Z := xyGrid.zScale;
1246

1247
    GridOptionsForm.BoxOutlineCB.Checked := BoxChecked;
1248
    GridOptionsForm.EditBoxLnWidth.Text := IntToStr(BoxLnWidth);
1249
    GridOptionsForm.DrawOutline(BoxChecked);
1250

1251
    EvaluateForm.EditX.Text := FloatToStrF(xEvaluate, ffGeneral, 7, 4);
1252
    EvaluateForm.EditY.Text := FloatToStrF(yEvaluate, ffGeneral, 7, 4);
1253
    EvaluateForm.EditZ.Text := '';
1254
    EvaluateForm.EditCoordWidth.Text := IntToStr(CoordWidth);
1255
    EvaluateForm.Coordinates.Checked := CoordChecked;
1256
    EvaluateForm.ToGrids.Checked := ToGridsChecked;
1257
    EValuateForm.dzdx_dzdy.Checked := dzdx_dyChecked;
1258
    EvaluateForm.ColorDialog.Color := CoordColor;
1259
    EvaluateForm.UpdateCoords;
1260
    EvaluateForm.UpdateEvaluate;
1261

1262
    CoordsForm.ShowCoordsCB.Checked := TextVisible;
1263
    CoordsForm.FontButton.Caption := 'Font:'+' '+TextFontN+' '+IntToStr(TextFontSz);
1264
    ViewForm.GLWinBmpFont.Font.Name := TextFontN;
1265
    ViewForm.GLWinBmpFont.Font.Size := TextFontSz;
1266
    CoordsForm.xMaxYCB.Checked := xPosYMax;
1267
    CoordsForm.xMaxZCB.Checked := xPosZMax;
1268

1269
    CoordsForm.yMaxXCB.Checked := yPosXMax;
1270
    CoordsForm.yMaxZCB.Checked := yPosZMax;
1271

1272
    CoordsForm.zMaxYCB.Checked := zPosYMax;
1273
    CoordsForm.zMaxXCB.Checked := zPosXMax;
1274

1275
    CoordsForm.UpdateCoordText;
1276
  end;
1277

1278
  with PlotData do
1279
  begin
1280
    Editfxy.Text := txtStr;
1281
    EditNote.Text := NoteStr;
1282

1283
    EditMinX.Text := FloatToStrF(xMin, ffGeneral, 7, 4);
1284
    EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 7, 4);
1285
    EditdX.Text := FloatToStrF(xInc, ffGeneral, 7, 4);
1286

1287
    EditMinY.Text := FloatToStrF(yMin, ffGeneral, 7, 4);
1288
    EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 7, 4);
1289
    EditdY.Text := FloatToStrF(yInc, ffGeneral, 7, 4);
1290

1291
    EditMinZ.Text := FloatToStrF(zMin, ffGeneral, 7, 4);
1292
    EditMaxZ.Text := FloatToStrF(zMax, ffGeneral, 7, 4);
1293
    zLimitCB.Checked := zLim;
1294
    zCapCB.Checked := zCap;
1295

1296
    ModeComboBox.ItemIndex := Ord(ViewMode);
1297
    StyleComboBox.ItemIndex := Ord(fxyMode);
1298
  end;
1299
  Caption := GraphFName;
1300
  ViewForm.Caption := GraphFName;
1301
  GridOptionsForm.Caption := GraphFName;
1302
  EvaluateForm.Caption := GraphFName;
1303
  CoordsForm.Caption := GraphFName;
1304
  CountzPoints;
1305
end;
1306

1307
procedure TFunctionsForm.StyleComboBoxChange(Sender: TObject);
1308
begin
1309
  PlotData.fxyMode := TfxyMode(StyleComboBox.ItemIndex);
1310
  UpdateTPlotDataObject;
1311
  ApplyBtnClick(Sender);
1312
end;
1313

1314
procedure TFunctionsForm.UpButtonClick(Sender: TObject);
1315
var
1316
  i: integer;
1317

1318
begin
1319
  with CheckListBox do
1320
  begin
1321
    i := ItemIndex;
1322
    if i > 0 then Items.Move(i, i-1);
1323
    if i > 1 then ItemIndex := i-1 else ItemIndex := 0;
1324
  end;
1325
  CheckListBoxClick(Sender);
1326
  Altered := True;
1327
end;
1328

1329
procedure TFunctionsForm.AddNewPlot;
1330
begin
1331
  with CheckListBox do
1332
  begin
1333
    AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
1334
    ItemIndex := Count -1;
1335
    Checked[ItemIndex] := True;  { initially this item is checked }
1336
  end;
1337
  Editfxy.SetFocus;
1338
  Editfxy.SelLength := 0;
1339
end;
1340

1341
procedure TFunctionsForm.ApplyBtnClick(Sender: TObject);
1342
var
1343
  v: TGLFloat;
1344
  s: string;
1345

1346
begin
1347
  if TooManyPoints > 6 then Exit;
1348

1349
  with PlotData do
1350
  begin
1351
    if xMin > xMax then  { swap }
1352
    begin
1353
      v := xMin;
1354
      xMin := xMax;
1355
      xMax := v;
1356
      s := EditMinX.Text;
1357
      EditMinX.Text := EditMaxX.Text;
1358
      EditMaxX.Text := s;
1359
      UpdateTPlotDataObject;
1360
    end;
1361
    if yMin > yMax then  { swap }
1362
    begin
1363
      v := yMin;
1364
      yMin := yMax;
1365
      yMax := v;
1366
      s := EditMinY.Text;
1367
      EditMinY.Text := EditMaxY.Text;
1368
      EditMaxY.Text := s;
1369
      UpdateTPlotDataObject;
1370
    end;
1371
  end;
1372

1373
  AddedData.AddedAs := AddNone;
1374

1375
  ViewForm.UpdatePlot;
1376
  EvaluateForm.UpdateEvaluate;
1377
  ApplyBtn.Visible := False;
1378
  Altered := True;
1379
end;
1380

1381
procedure TFunctionsForm.CentreClick(Sender: TObject);
1382
var
1383
  x, y, z: TGLFloat;
1384

1385
begin
1386
  with ViewForm do
1387
  begin
1388
    MousePoint.X := Maxint;
1389
    x := PlotData.xMax + PlotData.xMin;
1390
    y := PlotData.yMax + PlotData.yMin;
1391
    z := PlotData.zMax + PlotData.zMin;
1392
    TargetCube.Position.SetPoint(x/2, y/2, z/2);
1393
  end;
1394
  Altered := True;
1395
  ViewForm.ShowDisplacement;
1396
end;
1397

1398
procedure TFunctionsForm.CheckListBoxClick(Sender: TObject);
1399
begin
1400
  with CheckListBox do
1401
  begin
1402
    PlotData := TPlotDataObject(Items.Objects[ItemIndex]).Data;
1403
    if Checked[ItemIndex] then EvaluateForm.UpdateEvaluate;
1404
  end;
1405
  ShowData(Sender);
1406
  if PlotColorsForm.Visible then PlotColorsForm.ShowPlotColorData;
1407
  if DerivativesForm.Visible then DerivativesForm.ApplyBtn.Visible := True;
1408
end;
1409

1410
procedure TFunctionsForm.CheckListBoxClickCheck(Sender: TObject);
1411
begin
1412
  ApplyBtn.Visible := True;
1413
end;
1414

1415
procedure TFunctionsForm.ReadAndShowInitialData;
1416
begin
1417
  if not ReadData(DataPath + GraphFName) then
1418
  begin
1419
    GraphFName := NewFName;
1420
    NewFile := True;
1421
    ViewData := DefaultViewData;
1422
    PlotData := DefaultPlotData;
1423
    AddedData := DefaultAddedData;
1424
    with CheckListBox do
1425
    begin
1426
      AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
1427
      ItemIndex := Count -1;
1428
      Checked[ItemIndex] := True;  { initially this item is checked }
1429
    end;
1430
    ViewForm.TargetCube.Position.SetPoint(0, 0, 0);
1431
  end;
1432

1433
  Caption := GraphFName;
1434
  ShowData(Self);
1435
end;
1436

1437
procedure TFunctionsForm.OpenRecentFile(FName: TFileName);
1438
var
1439
  i: integer;
1440

1441
begin
1442
  if DerivativesForm.Visible then DerivativesForm.Close;
1443
  if FileExists(FName) then
1444
  begin
1445
    if Altered or GridColorsAltered then
1446
    case MessageDlg('The current graph''s data has been altered.'+
1447
              #13#10'Do you wish to save the alterations ?', mtConfirmation,
1448
                      [mbYes, mbNo, mbCancel], 0) of
1449
      mrYes:SaveClick(Self);
1450
   mrCancel:Exit;
1451
      mrNo:
1452
      begin
1453
        Altered := False;
1454
        GridColorsAltered := False;
1455
        DerivativeAltered := False;
1456
        NewFile := False;
1457
      end;
1458
    end;
1459
    AddRecent(FName);
1460
    DataPath := ExtractFilePath(FName);
1461
    DataPath := IncludeTrailingPathDelimiter(DataPath);
1462
    ViewForm.MousePoint.X := Maxint;
1463
    GraphFName := ExtractFileName(FName);
1464

1465
    with CheckListBox do
1466
    begin
1467
      for i := 0 to Items.Count -1 do Items.Objects[i].Free;
1468
      Clear;
1469
    end;
1470

1471
    if ReadData(FName) then ShowData(Self);
1472
    if GridColorsForm.Visible then GridColorsForm.ShowGridColorData;
1473
    if PlotColorsForm.Visible then PlotColorsForm.ShowPlotColorData;
1474

1475
    ApplyBtnClick(Self);
1476
    Altered := False;
1477
    GridColorsAltered := False;
1478
    DerivativeAltered := False;
1479
  end
1480
  else MessageDlg('The file '+FName+' does not exist!', mtError, [mbOK], 0);
1481
end;
1482

1483
procedure TFunctionsForm.AddRecent(const f: TFileName);
1484
var
1485
  i: integer;
1486
  Found: Boolean;
1487

1488
begin
1489
  with ViewForm.Recent1 do
1490
  begin
1491
    Found := False;
1492
    i := 0;
1493
    while (i < Count) and not Found do
1494
    begin
1495
      Found := Items[i].Caption = DataPath + GraphFName;
1496
      Inc(i);
1497
    end;
1498
    if Found then Delete(i -1);
1499
    Insert(0, TMenuItem.Create(Self));
1500
    Items[0].Caption := DataPath + GraphFName;
1501
    Items[0].OnClick := ViewForm.RecentFilesClick;
1502
    if Count > 16 then Delete(Count -1);
1503
  end;
1504
end;
1505

1506
procedure TFunctionsForm.OpenSelectedFile(Sender: TObject; FName: TFileName);
1507
var
1508
  i: integer;
1509

1510
begin
1511
  if FileExists(FName) then
1512
  begin
1513
    Screen.Cursor := crHourglass;
1514
    with CheckListBox do
1515
    begin
1516
      for i := 0 to Items.Count -1 do Items.Objects[i].Free;
1517
      Clear;
1518
    end;
1519

1520
    GraphFName := ExtractFileName(FName);
1521

1522
    if ReadData(DataPath + GraphFName) then
1523
    begin
1524
      Caption := GraphFName;
1525
      ViewForm.Caption := GraphFName;
1526
      GridOptionsForm.Caption := GraphFName;
1527
      ShowData(Sender);
1528
      NewFile := False;
1529
      Altered := False;
1530
    { NewFont needed to initialize GLWinFont.GetCharWidth
1531
      if the font has been altered, which may or may not be the case,
1532
      so do it anyway }
1533
      ViewForm.GLSViewer.Buffer.BackgroundColor := ViewData.BackColor;
1534
      ViewForm.GLSViewer.Invalidate;
1535
    end;
1536
    Screen.Cursor := crDefault;
1537
  end
1538
  else
1539
  begin
1540
    MessageDlg('The file'+FName+
1541
         #13#10'Could not be found.', mtError, [mbOK], 0);
1542
    Screen.Cursor := crDefault;
1543
  end;
1544
end;
1545

1546
end.
1547

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

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

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

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