MathgeomGLS

Форк
0
/
faFunctions.pas 
1681 строка · 47.3 Кб
1
unit faFunctions;
2

3
interface
4

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

27
  GLS.OpenGLTokens,
28
  GLS.VectorGeometry,
29
  GLS.Coordinates,
30
  GLS.Color,
31
  GLS.VectorTypes,
32

33
  Graf.Global2d,
34
  Graf.Parser2d;
35

36
type
37
  TFunctionsForm = class(TForm)
38
    GroupBox1: TGroupBox;
39
    Label1: TLabel;
40
    Label2: TLabel;
41
    Label3: TLabel;
42
    Label4: TLabel;
43
    Label5: TLabel;
44
    Label6: TLabel;
45
    EditMinX: TEdit;
46
    EditMaxX: TEdit;
47
    EditdX: TEdit;
48
    EditMinY: TEdit;
49
    EditMaxY: TEdit;
50
    EditdY: TEdit;
51
    EditMinZ: TEdit;
52
    EditMaxZ: TEdit;
53
    cbZLimit: TCheckBox;
54
    LabelFunc: TLabel;
55
    Editfxy: TEdit;
56
    Label9: TLabel;
57
    AddButton: TSpeedButton;
58
    DeleteButton: TSpeedButton;
59
    CheckListBox: TCheckListBox;
60
    MainMenu: TMainMenu;
61
    File1: TMenuItem;
62
    miNew: TMenuItem;
63
    miOpenFile: TMenuItem;
64
    miSave: TMenuItem;
65
    miSaveAs: TMenuItem;
66
    N1: TMenuItem;
67
    miExit: TMenuItem;
68
    SaveDialog: TSaveDialog;
69
    OpenDialog: TOpenDialog;
70
    Label17: TLabel;
71
    ModeComboBox: TComboBox;
72
    StyleComboBox: TComboBox;
73
    ApplyBtn: TBitBtn;
74
    zCountLabel: TLabel;
75
    Centre: TSpeedButton;
76
    UpButton: TSpeedButton;
77
    DownButton: TSpeedButton;
78
    cbZCap: TCheckBox;
79
    GridValues: TSpeedButton;
80
    Label7: TLabel;
81
    EditNote: TEdit;
82
    procedure FormDestroy(Sender: TObject);
83
    procedure FloatKeyPress(Sender: TObject; var Key: Char);
84
    procedure fxyKeyPress(Sender: TObject; var Key: Char);
85
    procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
86
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
87
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
88
    procedure AddButtonClick(Sender: TObject);
89
    procedure miSaveClick(Sender: TObject);
90
    procedure miSaveAsClick(Sender: TObject);
91
    procedure CheckListBoxClick(Sender: TObject);
92
    procedure DeleteButtonClick(Sender: TObject);
93
    procedure miOpenFileClick(Sender: TObject);
94
    procedure miExitClick(Sender: TObject);
95
    procedure miNewClick(Sender: TObject);
96
    procedure cbZLimitClick(Sender: TObject);
97
    procedure ModeComboBoxChange(Sender: TObject);
98
    procedure StyleComboBoxChange(Sender: TObject);
99
    procedure ApplyBtnClick(Sender: TObject);
100
    procedure EditfxyClick(Sender: TObject);
101
    procedure CheckListBoxClickCheck(Sender: TObject);
102
    procedure EditdXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
103
    procedure EditdYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
104
    procedure EditMinXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
105
    procedure EditMaxXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
106
    procedure EditMinYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
107
    procedure EditMaxYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
108
    procedure EditMinZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
109
    procedure EditMaxZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
110
    procedure EditfxyKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
111
    procedure CentreClick(Sender: TObject);
112
    procedure UpButtonClick(Sender: TObject);
113
    procedure DownButtonClick(Sender: TObject);
114
    procedure FormCreate(Sender: TObject);
115
    procedure cbZCapClick(Sender: TObject);
116
    procedure GridValuesClick(Sender: TObject);
117
    procedure PositiveKeyPress(Sender: TObject; var Key: Char);
118
    procedure EditNoteClick(Sender: TObject);
119
    procedure EditNoteKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
120
  private
121
    NewFile: Boolean;
122
    TooManyPoints: integer;
123
    function ReadData(const FName: TFileName): Boolean;
124
    procedure OpenSelectedFile(Sender: TObject; FName: TFileName);
125
    procedure WriteData(const FName: TFileName);
126
    function DefaultPlotData: TPlotData;
127
    function DefaultViewData: TViewData;
128
    function DefaultAddedData: TAddedData;
129
    procedure ShowData(Sender: TObject);
130
    procedure AddNewPlot;
131
    procedure CountzPoints;
132
    procedure UpdateTPlotDataObject;
133
    procedure AddRecent(const f: TFileName);
134
  public
135
    procedure ReadAndShowInitialData;
136
    procedure OpenRecentFile(FName: TFileName);
137
  end;
138

139
var
140
  FunctionsForm: TFunctionsForm;
141

142
// ========================================================================
143
implementation
144
// ========================================================================
145

146
uses
147
  faGraf2d,
148
  faPlotColors,
149
  faEvaluate,
150
  faCoordOptions,
151
  faGridColors,
152
  faGridOptions,
153
  faDerivativeOptions;
154

155
{$R *.dfm}
156

157
procedure TFunctionsForm.AddButtonClick(Sender: TObject);
158
begin
159
  AddNewPlot;
160
end;
161

162
procedure TFunctionsForm.EditdXKeyUp(Sender: TObject; var Key: Word;
163
  Shift: TShiftState);
164
var
165
  x: TGLFloat;
166

167
begin
168
  try
169
    x := StrToFloat(EditdX.Text);
170
  except
171
    x := 1.0;
172
  end;
173
  PlotData.xInc := x;
174
  ApplyBtn.Visible := True;
175
  UpdateTPlotDataObject;
176
  CountzPoints;
177
end;
178

179
procedure TFunctionsForm.PositiveKeyPress(Sender: TObject; var Key: Char);
180
begin
181
  with Sender as TEdit do
182
    if not CharInSet(Key, ['+', '0' .. '9', '.', #8]) then
183
      Key := #0;
184
end;
185

186
procedure TFunctionsForm.EditdYKeyUp(Sender: TObject; var Key: Word;
187
  Shift: TShiftState);
188
var
189
  y: TGlFloat;
190

191
begin
192
  try
193
    y := StrToFloat(EditdY.Text);
194
  except
195
    y := 1.0;
196
  end;
197
  PlotData.yInc := y;
198
  ApplyBtn.Visible := True;
199
  UpdateTPlotDataObject;
200
  CountzPoints;
201
end;
202

203
procedure TFunctionsForm.EditfxyClick(Sender: TObject);
204
begin
205
  FormPlotStars.MousePoint.x := Maxint;
206
end;
207

208
procedure TFunctionsForm.EditfxyKeyUp(Sender: TObject; var Key: Word;
209
  Shift: TShiftState);
210
var
211
  e: byte;
212

213
begin
214
  if Key <> 13 then
215
  begin
216
    PlotData.txtStr := Editfxy.Text;
217
    PlotData.fxyStr := ScanText(Editfxy.Text);
218
    ParseAndEvaluate(PlotData.fxyStr, e);
219

220
    with CheckListBox do
221
      if (Count > 0) and (ItemIndex > -1) then
222
        Items[ItemIndex] := PlotData.txtStr;
223
    ApplyBtn.Visible := e = 0;
224
    UpdateTPlotDataObject;
225
  end;
226
end;
227

228
procedure TFunctionsForm.EditKeyDown(Sender: TObject; var Key: Word;
229
  Shift: TShiftState);
230
begin
231
  if (Key = VK_DELETE) or (Key = VK_BACK) then
232
    ApplyBtn.Visible := True;
233
end;
234

235
procedure TFunctionsForm.fxyKeyPress(Sender: TObject; var Key: Char);
236
begin
237
  with (Sender as TEdit) do
238
  begin
239
    if not CharInSet(UpCase(Key), ParseSet) then
240
    begin
241
      Key := #0;
242
      Exit;
243
    end;
244
    if Key = '`' then
245
      Key := '°';
246
  end;
247
end;
248

249
procedure TFunctionsForm.GridValuesClick(Sender: TObject);
250
var
251
  DoApply: Boolean;
252

253
begin
254
  with FormGridOptions do
255
    DoApply := xyLock.Checked and zLock.Checked and MinLock.Checked;
256

257
  if DoApply then
258
  begin
259
    with ViewData.xyGrid.xRange do
260
    begin
261
      EditMinX.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
262
      PlotData.xMin := Minimum;
263
      EditMaxX.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
264
      PlotData.xMax := Maximum;
265
    end;
266

267
    with ViewData.xyGrid.yRange do
268
    begin
269
      EditMinY.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
270
      PlotData.yMin := Minimum;
271
      EditMaxY.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
272
      PlotData.yMax := Maximum;
273
    end;
274

275
    with ViewData.xzGrid.zRange do
276
    begin
277
      EditMinZ.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
278
      PlotData.zMin := Minimum;
279
      EditMaxZ.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
280
      PlotData.zMax := Maximum;
281
    end;
282
    ApplyBtnClick(Sender);
283
  end;
284
end;
285

286
procedure TFunctionsForm.ModeComboBoxChange(Sender: TObject);
287
begin
288
  PlotData.ViewMode := TViewMode(ModeComboBox.ItemIndex);
289
  UpdateTPlotDataObject;
290
  ApplyBtnClick(Sender);
291
end;
292

293
procedure TFunctionsForm.miNewClick(Sender: TObject);
294
var
295
  i: integer;
296
  s: string;
297

298
begin
299
  if Altered or GridColorsAltered or DerivativeAltered then
300
    case MessageDlg('Параметры графика изменены.' +
301
      #13#10'Сохранить изменения?', mtConfirmation,
302
      [mbYes, mbNo, mbCancel], 0) of
303
      mrYes:
304
        miSaveClick(Sender);
305
      mrCancel:
306
        Exit;
307
    end;
308
  s := DataPath + GraphFName; // save original FName
309
  if s <> GraphFName then
310
    AddRecent(s);
311
  with CheckListBox do
312
  begin
313
    for i := 0 to Items.Count - 1 do
314
      Items.Objects[i].Free;
315
    Clear;
316
  end;
317

318
  GraphFName := NewFName;
319
  Caption := GraphFName;
320
  FormPlotStars.Caption := GraphFName;
321
  FormGridOptions.Caption := GraphFName;
322
  EvaluateForm.Caption := GraphFName;
323
  CoordsForm.Caption := GraphFName;
324

325
  NewFile := True;
326
  Altered := False;
327
  ViewData := DefaultViewData;
328
  PlotData := DefaultPlotData;
329
  AddedData := DefaultAddedData;
330

331
  if GridColorsForm.Visible then
332
    GridColorsForm.Close;
333
  if PlotColorsForm.Visible then
334
    PlotColorsForm.Close;
335
  if DerivativesForm.Visible then
336
    DerivativesForm.Close;
337
  ApplyBtnClick(Sender);
338

339
  CheckListBox.AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
340
  CheckListBox.ItemIndex := CheckListBox.Count - 1;
341
  CheckListBox.Checked[CheckListBox.ItemIndex] := True;
342

343
  FormPlotStars.TargetCube.Position.SetPoint(0, 0, 0);
344
  ShowData(Sender);
345
end;
346

347
procedure TFunctionsForm.miOpenFileClick(Sender: TObject);
348
var
349
  i: integer;
350
  s: string;
351

352
begin
353
  if DerivativesForm.Visible then
354
    DerivativesForm.Close;
355
  if GridColorsForm.Visible then
356
    GridColorsForm.ShowGridColorData;
357
  if PlotColorsForm.Visible then
358
    PlotColorsForm.ShowPlotColorData;
359
  if Altered or GridColorsAltered or DerivativeAltered then
360
    case MessageDlg('Параметры графика изменены.' +
361
      #13#10'Сохранить изменения?', mtConfirmation,
362
      [mbYes, mbNo, mbCancel], 0) of
363
      mrYes:
364
        miSaveClick(Sender);
365
      mrCancel:
366
        Exit;
367
      mrNo:
368
        begin
369
          Altered := False;
370
          GridColorsAltered := False;
371
          DerivativeAltered := False;
372
          NewFile := False;
373
        end
374
    end;
375

376
  OpenDialog.InitialDir := DataPath;
377
  if OpenDialog.Execute then
378
  begin
379
    s := DataPath + GraphFName; // save original FName
380
    DataPath := ExtractFilePath(OpenDialog.FileName);
381
    DataPath := IncludeTrailingPathDelimiter(DataPath);
382
    FormPlotStars.MousePoint.x := Maxint;
383
    GraphFName := ExtractFileName(OpenDialog.FileName);
384
    if s <> GraphFName then
385
      AddRecent(s);
386

387
    for i := 0 to CheckListBox.Items.Count - 1 do
388
      CheckListBox.Items.Objects[i].Free;
389
    CheckListBox.Clear;
390

391
    if ReadData(DataPath + GraphFName) then
392
      ShowData(Sender);
393
    ApplyBtnClick(Sender);
394
    Altered := False;
395
    GridColorsAltered := False;
396
    DerivativeAltered := False;
397
    if GridColorsForm.Visible then
398
      GridColorsForm.ShowGridColorData;
399
    if PlotColorsForm.Visible then
400
      PlotColorsForm.ShowPlotColorData;
401
  end;
402
end;
403

404
procedure TFunctionsForm.EditMaxXKeyUp(Sender: TObject; var Key: Word;
405
  Shift: TShiftState);
406
var
407
  x: TGlFloat;
408

409
begin
410
  try
411
    x := StrToFloat(EditMaxX.Text);
412
  except
413
    x := 1.0;
414
  end;
415
  PlotData.xMax := x;
416
  ApplyBtn.Visible := True;
417
  UpdateTPlotDataObject;
418
  CountzPoints;
419
end;
420

421
procedure TFunctionsForm.EditMaxYKeyUp(Sender: TObject; var Key: Word;
422
  Shift: TShiftState);
423
var
424
  y: TGlFloat;
425

426
begin
427
  try
428
    y := StrToFloat(EditMaxY.Text);
429
  except
430
    y := 1.0;
431
  end;
432
  PlotData.yMax := y;
433
  ApplyBtn.Visible := True;
434
  UpdateTPlotDataObject;
435
  CountzPoints;
436
end;
437

438
procedure TFunctionsForm.EditMaxZKeyUp(Sender: TObject; var Key: Word;
439
  Shift: TShiftState);
440
var
441
  z: TGLFloat;
442

443
begin
444
  try
445
    z := StrToFloat(EditMaxZ.Text);
446
  except
447
    z := 1.0;
448
  end;
449
  PlotData.zMax := z;
450
  ApplyBtn.Visible := True;
451
  UpdateTPlotDataObject;
452
  CountzPoints;
453
end;
454

455
procedure TFunctionsForm.EditMinXKeyUp(Sender: TObject; var Key: Word;
456
  Shift: TShiftState);
457
var
458
  x: TGlFloat;
459

460
begin
461
  try
462
    x := StrToFloat(EditMinX.Text);
463
  except
464
    x := -1.0;
465
  end;
466
  PlotData.xMin := x;
467
  ApplyBtn.Visible := True;
468
  UpdateTPlotDataObject;
469
  CountzPoints;
470
end;
471

472
procedure TFunctionsForm.EditMinYKeyUp(Sender: TObject; var Key: Word;
473
  Shift: TShiftState);
474
var
475
  y: TGlFloat;
476

477
begin
478
  try
479
    y := StrToFloat(EditMinY.Text);
480
  except
481
    y := -1.0;
482
  end;
483
  PlotData.yMin := y;
484
  ApplyBtn.Visible := True;
485
  UpdateTPlotDataObject;
486
  CountzPoints;
487
end;
488

489
procedure TFunctionsForm.EditMinZKeyUp(Sender: TObject; var Key: Word;
490
  Shift: TShiftState);
491
var
492
  z: TGlFloat;
493

494
begin
495
  try
496
    z := StrToFloat(EditMinZ.Text);
497
  except
498
    z := -1.0;
499
  end;
500
  PlotData.zMin := z;
501
  ApplyBtn.Visible := True;
502
  UpdateTPlotDataObject;
503
  CountzPoints;
504
end;
505

506
procedure TFunctionsForm.EditNoteClick(Sender: TObject);
507
begin
508
  FormPlotStars.MousePoint.x := Maxint;
509
end;
510

511
procedure TFunctionsForm.EditNoteKeyUp(Sender: TObject; var Key: Word;
512
  Shift: TShiftState);
513
begin
514
  if Key <> 13 then
515
  begin
516
    PlotData.NoteStr := EditNote.Text;
517
    with CheckListBox do
518
      if (Count > 0) and (ItemIndex > -1) then
519
        TPlotDataObject(Items.Objects[ItemIndex]).Data := PlotData;
520
    Altered := True;
521
  end;
522
end;
523

524
procedure TFunctionsForm.miExitClick(Sender: TObject);
525
begin
526
  FormPlotStars.miExitClick(Sender);
527
end;
528

529
procedure TFunctionsForm.FloatKeyPress(Sender: TObject; var Key: Char);
530
begin
531
  with Sender as TEdit do
532
    if not CharInSet(Key, AnyFloat) then
533
      Key := #0;
534
end;
535

536
procedure TFunctionsForm.FormClose(Sender: TObject; var Action: TCloseAction);
537
var
538
  i: integer;
539

540
begin
541
  for i := 0 to CheckListBox.Items.Count - 1 do
542
    CheckListBox.Items.Objects[i].Free;
543
  CheckListBox.Clear;
544
end;
545

546
procedure TFunctionsForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
547
begin
548
  FormPlotStars.Close;
549
  CanClose := not FormPlotStars.Visible;
550
end;
551

552
procedure TFunctionsForm.FormCreate(Sender: TObject);
553
begin
554
  ReportMemoryLeaksOnShutdown := True;
555
end;
556

557
procedure TFunctionsForm.FormDestroy(Sender: TObject);
558
var
559
  i: integer;
560

561
begin
562
  with CheckListBox do
563
    for i := 0 to Count - 1 do
564
      Items.Objects[i].Free;
565
end;
566

567
function TFunctionsForm.DefaultPlotData: TPlotData;
568
begin
569
  with Result do
570
  begin
571
    fxyStr := ''; // function string
572
    txtStr := ''; // txt -> fxy when scanned
573
    NoteStr := ''; // describe function
574
    xMin := -10.0; // x limits and increment
575
    xMax := 10.0;
576
    xInc := 1.0;
577
    yMin := -10.0; // y limits and increment
578
    yMax := 10.0;
579
    yInc := 1.0;
580
    zMin := -10.0; // z limits
581
    zMax := 10.0;
582
    zLim := False; // false = z limits do not apply
583
    zCap := False; // above zLim values := NAN
584

585
    UpperColor := VectorMake(255, 0, 0, 1000);
586
    LowerColor := VectorMake(0, 0, 255, 1000);
587

588
    ColorBlend := 0.5;
589
    ColorMove := 0.0;
590
    ViewMode := vmAmbient;
591
    fxyMode := fxyFill;
592
  end;
593
end;
594

595
function TFunctionsForm.DefaultViewData: TViewData;
596
begin
597
  Result.CameraCubeAt := VectorMake(0, 0, 0);
598
  Result.CameraAt := VectorMake(50, 50, 30);
599
  Result.fLength := 200;
600
  Result.LightAt := VectorMake(50, 50, 50);
601
  Result.ViewDepth := 1000;
602
  Result.BackColor := clActiveCaption;
603
  with Result.xyGrid do
604
  begin
605
    Color := clrBlue;
606
    xRange.Maximum := 10;
607
    xRange.Minimum := -10;
608
    xRange.Step := 1;
609
    yRange.Maximum := 10;
610
    yRange.Minimum := -10;
611
    yRange.Step := 1;
612
    zPosition := -10;
613
    zScale := 1;
614
    IsVisible := True;
615
    IsChecked := True;
616
  end;
617

618
  with Result.xzGrid do
619
  begin
620
    Color := clrGreen;
621
    xRange.Maximum := 10;
622
    xRange.Minimum := -10;
623
    xRange.Step := 1;
624
    zRange.Maximum := 10;
625
    zRange.Minimum := -10;
626
    zRange.Step := 1;
627
    yPosition := -10;
628
    IsVisible := True;
629
    IsChecked := True;
630
  end;
631

632
  with Result.yzGrid do
633
  begin
634
    Color := clrRed;
635
    yRange.Maximum := 10;
636
    yRange.Minimum := -10;
637
    yRange.Step := 1;
638
    zRange.Maximum := 10;
639
    zRange.Minimum := -10;
640
    zRange.Step := 1;
641
    xPosition := -10;
642
    IsVisible := True;
643
    IsChecked := True;
644
  end;
645

646
  Result.xEvaluate := 0.0;
647
  Result.yEvaluate := 0.0;
648
  Result.CoordChecked := False;
649
  Result.ToGridsChecked := False;
650
  Result.dzdx_dyChecked := False;
651
  Result.BoxChecked := False;
652
  Result.CoordWidth := 1;
653
  Result.CoordColor := clBlack;
654
  Result.BoxLnWidth := 1;
655
  Result.BoxLnColor := clrBlack;
656

657
  Result.TextVisible := False;
658
  Result.TextFontN := 'Tahoma';
659
  Result.TextFontSz := 10;
660
  Result.xPosYMax := False;
661
  Result.xPosZMax := False;
662
  Result.xTextColor := clBlack;
663

664
  Result.yPosXMax := False;
665
  Result.yPosZMax := False;
666
  Result.yTextColor := clBlack;
667

668
  Result.TextVisible := True;
669
  Result.TextFontN := 'Tahoma'; // FormPlotStars.GLWinBitmapFont
670
  Result.TextFontSz := 20;
671

672
  Result.xPosYMax := False;
673
  Result.xPosZMax := False;
674
  Result.xTextColor := clRed;
675

676
  Result.yPosXMax := False;
677
  Result.yPosZMax := False;
678
  Result.yTextColor := clGreen;
679

680
  Result.zPosXMax := False;
681
  Result.zPosYMax := False;
682
  Result.zTextColor := clBlue;
683
  Result.ArrowSize := 1.0;
684
end;
685

686
function TFunctionsForm.DefaultAddedData: TAddedData;
687
begin
688
  Result.xMin := -10.0; // x limits and increment
689
  Result.xMax := 10.0;
690
  Result.xInc := 1.0;
691
  Result.yMin := -10.0; // y limits and increment
692
  Result.yMax := 10.0;
693
  Result.yInc := 1.0;
694
  Result.zMin := -10.0; // z limits
695
  Result.zMax := 10.0;
696
  Result.zLim := False; // false = z limits do not apply
697
  Result.zCap := False; // above zLim values := NAN
698

699
  Result.UpperColor := VectorMake(255, 0, 0, 1000);
700
  Result.LowerColor := VectorMake(0, 0, 255, 1000);
701

702
  Result.ColorBlend := 0.5;
703
  Result.ColorMove := 0.0;
704
  Result.ViewMode := vmAmbient;
705
  Result.fxyMode := fxyFill;
706

707
  Result.AddLineWidth := 1;
708
  Result.AddLineColor := clBlack;
709
  Result.AddedAs := AddNone;
710
end;
711

712
procedure TFunctionsForm.CountzPoints;
713
var
714
  n: integer;
715

716
begin
717
  n := round((PlotData.xMax - PlotData.xMin + PlotData.xInc) / PlotData.xInc) *
718
    round((PlotData.yMax - PlotData.yMin + PlotData.yInc) / PlotData.yInc);
719
  TooManyPoints := round(Log10(n));
720
  case TooManyPoints of
721
    0 .. 2:
722
      zCountLabel.Font.Color := clLime;
723
    3:
724
      zCountLabel.Font.Color := clTeal;
725
    4:
726
      zCountLabel.Font.Color := clGreen;
727
    5:
728
      zCountLabel.Font.Color := clBlue;
729
  else
730
    zCountLabel.Font.Color := clRed;
731
  end;
732
  if TooManyPoints > 6 then
733
    zCountLabel.Caption := 'Too many Points: ' + FloatToStrF(n, ffnumber,
734
      8, 0) + ' !'
735
  else
736
    zCountLabel.Caption := 'N° точек = ' + FloatToStrF(n, ffnumber, 8, 0);
737
end;
738

739
procedure TFunctionsForm.UpdateTPlotDataObject;
740
begin
741
  TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data := PlotData;
742
end;
743

744
procedure TFunctionsForm.DeleteButtonClick(Sender: TObject);
745
var
746
  i: integer;
747

748
begin
749
  if CheckListBox.Count > 1 then
750
  begin
751
    i := CheckListBox.ItemIndex;
752
    with CheckListBox.Items.Objects[i] as TPlotDataObject do
753
      Free;
754
    CheckListBox.Items.Delete(i);
755
    if i > CheckListBox.Count - 1 then
756
      i := CheckListBox.Count - 1;
757
    CheckListBox.ItemIndex := i;
758
    PlotData := TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data;
759
    DeleteButton.Enabled := CheckListBox.Count > 1;
760
    ApplyBtnClick(Sender);
761
  end
762
end;
763

764
procedure TFunctionsForm.DownButtonClick(Sender: TObject);
765
var
766
  i: integer;
767

768
begin
769
  i := CheckListBox.ItemIndex;
770
  if i < CheckListBox.Count - 1 then
771
    CheckListBox.Items.Move(i, i + 1);
772
  CheckListBox.ItemIndex := i + 1;
773
  CheckListBoxClick(Sender);
774
  Altered := True;
775
end;
776

777
function TFunctionsForm.ReadData(const FName: TFileName): Boolean;
778

779
  function StrToVector(s: string): TGLVector;
780
  var
781
    t: string;
782
    i: integer;
783

784
  begin
785
    i := Pos(',', s);
786
    t := Copy(s, 1, i - 1);
787
    TryStrToFloat(t, Result.x);
788

789
    s := Copy(s, i + 1, Length(s));
790
    i := Pos(',', s);
791
    t := Copy(s, 1, i - 1);
792
    TryStrToFloat(t, Result.y);
793

794
    s := Copy(s, i + 1, Length(s));
795
    TryStrToFloat(t, Result.z);
796
  end;
797

798
  function StrToColor(s: string): TGLColorVector;
799
  var
800
    t: string;
801
    i: integer;
802

803
  begin
804
    i := Pos(',', s);
805
    t := Copy(s, 1, i - 1);
806
    TryStrToFloat(t, Result.x);
807

808
    s := Copy(s, i + 1, Length(s));
809
    i := Pos(',', s);
810
    t := Copy(s, 1, i - 1);
811
    TryStrToFloat(t, Result.y);
812

813
    s := Copy(s, i + 1, Length(s));
814
    i := Pos(',', s);
815
    t := Copy(s, 1, i - 1);
816
    TryStrToFloat(t, Result.z);
817

818
    s := Copy(s, i + 1, Length(s));
819
    TryStrToFloat(t, Result.W);
820
  end;
821

822
  function StrToRange(s: string): TRange;
823
  var
824
    t: string;
825
    i: integer;
826

827
  begin
828
    i := Pos(',', s);
829
    t := Copy(s, 1, i - 1);
830
    TryStrToFloat(t, Result.Maximum);
831

832
    s := Copy(s, i + 1, Length(s));
833
    i := Pos(',', s);
834
    t := Copy(s, 1, i - 1);
835
    TryStrToFloat(t, Result.Minimum);
836

837
    s := Copy(s, i + 1, Length(s));
838
    TryStrToFloat(t, Result.Step);
839
  end;
840

841
var
842
  s, t: string;
843
  f: TextFile;
844
  i, j, k, n: integer;
845

846
begin
847
  Result := False;
848
  if FileExists(FName) then
849
  begin
850
    AssignFile(f, FName);
851
    try
852
      Reset(f);
853
      Readln(f, s);
854
      j := 0;
855
      i := Pos(#9, s);
856

857
      while i > 0 do
858
      begin
859
        t := Copy(s, 1, i - 1);
860
        s := Copy(s, i + 1, Length(s));
861
        i := Pos(#9, s);
862
        Inc(j);
863

864
          case j of
865
            1:
866
              ViewData.CameraCubeAt := StrToVector(t);
867
            2:
868
              ViewData.CameraAt := StrToVector(t);
869
            3:
870
              TryStrToFloat(t, ViewData.fLength);
871
            4:
872
              ViewData.LightAt := StrToVector(t);
873
            5:
874
              TryStrToFloat(t, ViewData.ViewDepth);
875
            6:
876
              ViewData.BackColor := StrToInt(t);
877
            7:
878
              ViewData.xyGrid.Color := StrToColor(t);
879
            8:
880
              ViewData.xyGrid.xRange := StrToRange(t);
881
            9:
882
              ViewData.xyGrid.yRange := StrToRange(t);
883
            10:
884
              TryStrToFloat(t, ViewData.xyGrid.zPosition);
885
            11:
886
              TryStrToFloat(t, ViewData.xyGrid.zScale);
887
            12:
888
              ViewData.xyGrid.IsVisible := StrToBool(t);
889
            13:
890
              ViewData.xyGrid.IsChecked := StrToBool(t);
891
            14:
892
              ViewData.xzGrid.Color := StrToColor(t);
893
            15:
894
              ViewData.xzGrid.xRange := StrToRange(t);
895
            16:
896
              ViewData.xzGrid.zRange := StrToRange(t);
897
            17:
898
              TryStrToFloat(t, ViewData.xzGrid.yPosition);
899
            18:
900
              ViewData.xzGrid.IsVisible := StrToBool(t);
901
            19:
902
              ViewData.xzGrid.IsChecked := StrToBool(t);
903
            20:
904
              ViewData.yzGrid.Color := StrToColor(t);
905
            21:
906
              ViewData.yzGrid.yRange := StrToRange(t);
907
            22:
908
              ViewData.yzGrid.zRange := StrToRange(t);
909
            23:
910
              TryStrToFloat(t, ViewData.yzGrid.xPosition);
911
            24:
912
              ViewData.yzGrid.IsVisible := StrToBool(t);
913
            25:
914
              ViewData.yzGrid.IsChecked := StrToBool(t);
915
            26:
916
              FormPlotStars.TargetCube.Position.AsVector := StrToVector(t);
917
            27:
918
              TryStrToFloat(t, ViewData.xEvaluate);
919
            28:
920
              TryStrToFloat(t, ViewData.yEvaluate);
921
            29:
922
              ViewData.CoordChecked := StrToBool(t);
923
            30:
924
              ViewData.ToGridsChecked := StrToBool(t);
925
            31:
926
              ViewData.dzdx_dyChecked := StrToBool(t);
927
            32:
928
              ViewData.BoxChecked := StrToBool(t);
929
            33:
930
              ViewData.CoordWidth := StrToInt(t);
931
            34:
932
              ViewData.CoordColor := StrToInt(t);
933
            35:
934
              ViewData.BoxLnWidth := StrToInt(t);
935
            36:
936
              ViewData.BoxLnColor := StrToColor(t);
937
            37:
938
              ViewData.TextVisible := StrToBool(t);
939
            38:
940
              ViewData.TextFontN := t;
941
            39:
942
              ViewData.TextFontSz := StrToInt(t);
943
            40:
944
              ViewData.xPosYMax := StrToBool(t);
945
            41:
946
              ViewData.xPosZMax := StrToBool(t);
947
            42:
948
              ViewData.xTextColor := StrToInt(t);
949
            43:
950
              ViewData.yPosXMax := StrToBool(t);
951
            44:
952
              ViewData.yPosZMax := StrToBool(t);
953
            45:
954
              ViewData.yTextColor := StrToInt(t);
955
            46:
956
              ViewData.zPosXMax := StrToBool(t);
957
            47:
958
              ViewData.zPosYMax := StrToBool(t);
959
            48:
960
              ViewData.zTextColor := StrToInt(t);
961
            49:
962
              TryStrToFloat(t, ViewData.ArrowSize);
963
          end;
964
      end;
965
      n := StrToInt(s); // number of functions
966
      for k := 0 to n - 1 do
967
      begin // read each function's data
968
        Readln(f, s);
969
        j := 0;
970
        i := Pos(#9, s);
971
        while i > 0 do
972
        begin
973
          t := Copy(s, 1, i - 1);
974
          s := Copy(s, i + 1, Length(s));
975
          i := Pos(#9, s);
976
          Inc(j);
977
          with PlotData do
978
            case j of
979
              1:
980
                fxyStr := t;
981
              2:
982
                txtStr := t;
983
              3:
984
                NoteStr := t;
985
              4:
986
                TryStrToFloat(t, xMin);
987
              5:
988
                TryStrToFloat(t, xMax);
989
              6:
990
                TryStrToFloat(t, xInc);
991
              7:
992
                TryStrToFloat(t, yMin);
993
              8:
994
                TryStrToFloat(t, yMax);
995
              9:
996
                TryStrToFloat(t, yInc);
997
              10:
998
                TryStrToFloat(t, zMin);
999
              11:
1000
                TryStrToFloat(t, zMax);
1001
              12:
1002
                zLim := StrToBool(t);
1003
              13:
1004
                zCap := StrToBool(t);
1005
              14:
1006
                UpperColor := StrToColor(t);
1007
              15:
1008
                LowerColor := StrToColor(t);
1009
              16:
1010
                ColorBlend := StrToFloat(t); // TryStrToFloat(t, ColorBlend);
1011
              17:
1012
                ColorMove := StrToFloat(t); // TryStrToFloat(t, ColorMove);
1013
              18:
1014
                ViewMode := TViewMode(StrToInt(t));
1015
              19:
1016
                fxyMode := TfxyMode(StrToInt(t));
1017
            end;
1018
        end;
1019
        CheckListBox.AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
1020
        CheckListBox.Checked[CheckListBox.Count - 1] := StrToBool(s);
1021
      end;
1022
      Readln(f, s);
1023
      j := 0;
1024
      i := Pos(#9, s);
1025
      while i > 0 do
1026
      begin
1027
        t := Copy(s, 1, i - 1);
1028
        s := Copy(s, i + 1, Length(s));
1029
        i := Pos(#9, s);
1030
        Inc(j);
1031
        with AddedData do
1032
          case j of
1033
            1:
1034
              TryStrToFloat(t, xMin);
1035
            2:
1036
              TryStrToFloat(t, xMax);
1037
            3:
1038
              TryStrToFloat(t, xInc);
1039
            4:
1040
              TryStrToFloat(t, yMin);
1041
            5:
1042
              TryStrToFloat(t, yMax);
1043
            6:
1044
              TryStrToFloat(t, yInc);
1045
            7:
1046
              TryStrToFloat(t, zMin);
1047
            8:
1048
              TryStrToFloat(t, zMax);
1049
            9:
1050
              zLim := StrToBool(t);
1051
            10:
1052
              zCap := StrToBool(t);
1053
            11:
1054
              UpperColor := StrToColor(t);
1055
            12:
1056
              LowerColor := StrToColor(t);
1057
            13:
1058
              TryStrToFloat(t, ColorBlend);
1059
            14:
1060
              TryStrToFloat(t, ColorMove);
1061
            15:
1062
              ViewMode := TViewMode(StrToInt(t));
1063
            16:
1064
              fxyMode := TfxyMode(StrToInt(t));
1065
            17:
1066
              TryStrToInt(t, AddLineWidth);
1067
            18:
1068
              TryStrToInt(t, AddLineColor);
1069
            19:
1070
              AddedAs := TAddedType(StrToInt(t));
1071
          end;
1072
      end;
1073

1074
    except
1075
      MessageDlg('Ошибка!' +
1076
        #13#10'при попытке считывания "' + FName + '".', mtError, [mbOK], 0);
1077
      CloseFile(f);
1078
      Exit;
1079
    end;
1080
    CloseFile(f);
1081
    Result := True;
1082
    CheckListBox.ItemIndex := CheckListBox.Count - 1;
1083
    NewFile := not Result;
1084
  end;
1085
end;
1086

1087
procedure TFunctionsForm.miSaveClick(Sender: TObject);
1088
begin
1089
  if NewFile then
1090
    miSaveAsClick(Sender)
1091
  else
1092
    WriteData(DataPath + GraphFName);
1093
end;
1094

1095
procedure TFunctionsForm.miSaveAsClick(Sender: TObject);
1096
begin
1097
  SaveDialog.InitialDir := DataPath;
1098
  SaveDialog.FileName := GraphFName;
1099
  if SaveDialog.Execute then
1100
  begin
1101
    GraphFName := ExtractFileName(SaveDialog.FileName);
1102
    DataPath := ExtractFilePath(SaveDialog.FileName);
1103
    DataPath := IncludeTrailingPathDelimiter(DataPath);
1104
    WriteData(DataPath + GraphFName);
1105
  end;
1106
  Caption := GraphFName;
1107
  FormPlotStars.Caption := GraphFName;
1108
  FormGridOptions.Caption := GraphFName;
1109
  EvaluateForm.Caption := GraphFName;
1110
  CoordsForm.Caption := GraphFName;
1111
end;
1112

1113
procedure TFunctionsForm.WriteData(const FName: TFileName);
1114
  function VectorToStr(v: TGLVector): string;
1115
  begin
1116
    Result := FloatToStr(v.x) + ',' + FloatToStr(v.y) + ',' + FloatToStr(v.z);
1117
  end;
1118

1119
  function ColorToStr(c: TGLColorVector): string;
1120
  begin
1121
    Result := FloatToStr(c.x) + ',' + FloatToStr(c.y) + ',' + FloatToStr(c.z) +
1122
      ',' + FloatToStr(c.W);
1123
  end;
1124

1125
  function RangetoStr(r: TRange): string;
1126
  begin
1127
    Result := FloatToStr(r.Maximum) + ',' + FloatToStr(r.Minimum) + ',' +
1128
      FloatToStr(r.Step);
1129
  end;
1130

1131
var
1132
  f: TextFile;
1133
  s: string;
1134
  i: integer;
1135

1136
begin
1137
  try
1138
    AssignFile(f, FName);
1139
    try
1140
      Rewrite(f); // write tab delimited data
1141
      with ViewData do
1142
      begin
1143
        CameraCubeAt := FormPlotStars.CameraCube.Position.AsVector;
1144
        CameraAt := FormPlotStars.Camera.Position.AsVector;
1145
        fLength := FormPlotStars.Camera.FocalLength;
1146
        LightAt := FormPlotStars.GLLight.Position.AsVector;
1147
        ViewDepth := FormPlotStars.Camera.DepthOfView;
1148
        BackColor := FormPlotStars.GLSViewer.Buffer.BackgroundColor;
1149

1150
        s := VectorToStr(CameraCubeAt) + #9 + VectorToStr(CameraAt) + #9 +
1151
          FloatToStr(fLength) + #9 + VectorToStr(LightAt) + #9 +
1152
          FloatToStr(ViewDepth) + #9 + IntToStr(BackColor) + #9 +
1153
        { xy }
1154
          ColorToStr(xyGrid.Color) + #9 + RangetoStr(xyGrid.xRange) + #9 +
1155
          RangetoStr(xyGrid.yRange) + #9 + FloatToStr(xyGrid.zPosition) + #9 +
1156
          FloatToStr(xyGrid.zScale) + #9 + BoolToStr(xyGrid.IsVisible) + #9 +
1157
          BoolToStr(xyGrid.IsChecked) + #9 +
1158
        { xz }
1159
          ColorToStr(xzGrid.Color) + #9 + RangetoStr(xzGrid.xRange) + #9 +
1160
          RangetoStr(xzGrid.zRange) + #9 + FloatToStr(xzGrid.yPosition) + #9 +
1161
          BoolToStr(xzGrid.IsVisible) + #9 + BoolToStr(xzGrid.IsChecked) + #9 +
1162
        { yz }
1163
          ColorToStr(yzGrid.Color) + #9 + RangetoStr(yzGrid.yRange) + #9 +
1164
          RangetoStr(yzGrid.zRange) + #9 + FloatToStr(yzGrid.xPosition) + #9 +
1165
          BoolToStr(yzGrid.IsVisible) + #9 + BoolToStr(yzGrid.IsChecked) + #9 +
1166
        { Target }
1167
          VectorToStr(FormPlotStars.TargetCube.Position.AsVector) + #9 +
1168

1169
          FloatToStr(xEvaluate) + #9 + FloatToStr(yEvaluate) + #9 +
1170
          BoolToStr(CoordChecked) + #9 + BoolToStr(ToGridsChecked) + #9 +
1171
          BoolToStr(dzdx_dyChecked) + #9 + BoolToStr(BoxChecked) + #9 +
1172
          IntToStr(CoordWidth) + #9 + IntToStr(CoordColor) + #9 +
1173
          IntToStr(BoxLnWidth) + #9 + ColorToStr(BoxLnColor) + #9 +
1174
          BoolToStr(TextVisible) + #9 + TextFontN + #9 + IntToStr(TextFontSz) +
1175
          #9 + BoolToStr(xPosYMax) + #9 + BoolToStr(xPosZMax) + #9 +
1176
          IntToStr(xTextColor) + #9 + BoolToStr(yPosXMax) + #9 +
1177
          BoolToStr(yPosZMax) + #9 + IntToStr(yTextColor) + #9 +
1178
          BoolToStr(zPosXMax) + #9 + BoolToStr(zPosYMax) + #9 +
1179
          IntToStr(zTextColor) + #9 + FloatToStr(ArrowSize) + #9 +
1180
          IntToStr(CheckListBox.Count); { number of functions }
1181
      end;
1182
      writeln(f, s);
1183

1184
      for i := 0 to CheckListBox.Count - 1 do { each function }
1185
      begin
1186
        PlotData := TPlotDataObject(CheckListBox.Items.Objects[i]).Data;
1187
        with PlotData do
1188
        begin
1189
          s := fxyStr + #9 + txtStr + #9 + NoteStr + #9 + FloatToStr(xMin) + #9
1190
            + FloatToStr(xMax) + #9 + FloatToStr(xInc) + #9 + FloatToStr(yMin) +
1191
            #9 + FloatToStr(yMax) + #9 + FloatToStr(yInc) + #9 +
1192
            FloatToStr(zMin) + #9 + FloatToStr(zMax) + #9 + BoolToStr(zLim) + #9
1193
            + BoolToStr(zCap) + #9 + ColorToStr(UpperColor) + #9 +
1194
            ColorToStr(LowerColor) + #9 + FloatToStr(ColorBlend) + #9 +
1195
            FloatToStr(ColorMove) + #9 + IntToStr(Ord(ViewMode)) + #9 +
1196
            IntToStr(Ord(fxyMode)) + #9 + BoolToStr(CheckListBox.Checked[i]);
1197
        end;
1198
        writeln(f, s);
1199
      end;
1200

1201
      with AddedData do
1202
      begin
1203
        s := FloatToStr(xMin) + #9 + FloatToStr(xMax) + #9 + FloatToStr(xInc) +
1204
          #9 + FloatToStr(yMin) + #9 + FloatToStr(yMax) + #9 + FloatToStr(yInc)
1205
          + #9 + FloatToStr(zMin) + #9 + FloatToStr(zMax) + #9 + BoolToStr(zLim)
1206
          + #9 + BoolToStr(zCap) + #9 + ColorToStr(UpperColor) + #9 +
1207
          ColorToStr(LowerColor) + #9 + FloatToStr(ColorBlend) + #9 +
1208
          FloatToStr(ColorMove) + #9 + IntToStr(Ord(ViewMode)) + #9 +
1209
          IntToStr(Ord(fxyMode)) + #9 + IntToStr(AddLineWidth) + #9 +
1210
          IntToStr(AddLineColor) + #9 + IntToStr(Ord(AddedAs));
1211
      end;
1212
      writeln(f, s);
1213
    finally
1214
      Flush(f);
1215
      CloseFile(f);
1216
    end;
1217
  except
1218
    MessageDlg('Ошибка!' +
1219
      #13#10'при попытке записи в "' + GraphFName + '".', mtError,
1220
      [mbOK], 0);
1221
  end;
1222
  NewFile := False;
1223
  Altered := False;
1224
  Layout.CurrentGraphFName := GraphFName;
1225
end;
1226

1227
procedure TFunctionsForm.cbZCapClick(Sender: TObject);
1228
begin
1229
  PlotData.zCap := cbZCap.Checked;
1230
  UpdateTPlotDataObject;
1231
  ApplyBtn.Visible := True;
1232
end;
1233

1234
procedure TFunctionsForm.cbZLimitClick(Sender: TObject);
1235
begin
1236
  PlotData.zLim := cbZLimit.Checked;
1237
  UpdateTPlotDataObject;
1238
  ApplyBtn.Visible := True;
1239
end;
1240

1241
procedure TFunctionsForm.ShowData(Sender: TObject);
1242
begin
1243
  if not(Sender is TCheckListBox) then
1244
  begin
1245
    FormPlotStars.CameraCube.Position.AsVector := ViewData.CameraCubeAt;
1246
    FormPlotStars.Camera.Position.AsVector := ViewData.CameraAt;
1247
    FormPlotStars.Camera.FocalLength := ViewData.fLength;
1248
    FormPlotStars.GLLight.Position.AsVector := ViewData.LightAt;
1249
    FormPlotStars.Camera.DepthOfView := ViewData.ViewDepth;
1250
    FormPlotStars.GLSViewer.Buffer.BackgroundColor := ViewData.BackColor;
1251
  end;
1252

1253
  FormGridOptions.EditViewDepth.Text :=
1254
    FloatToStrF(ViewData.ViewDepth, ffGeneral, 7, 4);
1255

1256
  // xy
1257
  FormGridOptions.EditxyGridMinx.Text := FloatToStrF(ViewData.xyGrid.xRange.Minimum,
1258
    ffGeneral, 7, 4);
1259
  FormPlotStars.GLxyGrid.XSamplingScale.Min := ViewData.xyGrid.xRange.Minimum;
1260
  FormGridOptions.EditxyGridMiny.Text := FloatToStrF(ViewData.xyGrid.yRange.Minimum,
1261
    ffGeneral, 7, 4);
1262
  FormPlotStars.GLxyGrid.YSamplingScale.Min := ViewData.xyGrid.yRange.Minimum;
1263

1264
  FormGridOptions.EditxyGridMaxx.Text := FloatToStrF(ViewData.xyGrid.xRange.Maximum,
1265
    ffGeneral, 7, 4);
1266
  FormPlotStars.GLxyGrid.XSamplingScale.Max := ViewData.xyGrid.xRange.Maximum;
1267
  FormGridOptions.EditxyGridMaxy.Text := FloatToStrF(ViewData.xyGrid.yRange.Maximum,
1268
    ffGeneral, 7, 4);
1269
  FormPlotStars.GLxyGrid.YSamplingScale.Max := ViewData.xyGrid.yRange.Maximum;
1270

1271
  FormGridOptions.EditxyGridStpx.Text := FloatToStrF(ViewData.xyGrid.xRange.Step,
1272
    ffGeneral, 7, 4);
1273
  FormPlotStars.GLxyGrid.XSamplingScale.Step := ViewData.xyGrid.xRange.Step;
1274
  FormGridOptions.EditxyGridStpy.Text := FloatToStrF(ViewData.xyGrid.yRange.Step,
1275
    ffGeneral, 7, 4);
1276
  FormPlotStars.GLxyGrid.YSamplingScale.Step := ViewData.xyGrid.yRange.Step;
1277

1278
  FormGridOptions.EditxyGridPosz.Text := FloatToStrF(ViewData.xyGrid.zPosition,
1279
    ffGeneral, 7, 4);
1280
  FormPlotStars.GLxyGrid.Position.z := ViewData.xyGrid.zPosition * ViewData.xyGrid.zScale;
1281

1282
  FormGridOptions.EditzScale.Text := FloatToStrF(ViewData.xyGrid.zScale,
1283
    ffGeneral, 7, 4);
1284
  FormPlotStars.GLxzGrid.Scale.z := ViewData.xyGrid.zScale;
1285
  FormPlotStars.GLyzGrid.Scale.z := ViewData.xyGrid.zScale;
1286

1287
  FormPlotStars.GLxyGrid.LineColor.SetColor(ViewData.xyGrid.Color.x, ViewData.xyGrid.Color.y,
1288
    ViewData.xyGrid.Color.z, ViewData.xyGrid.Color.W);
1289

1290
  // xz
1291
  FormGridOptions.EditxzGridMinx.Text := FloatToStrF(ViewData.xzGrid.xRange.Minimum,
1292
    ffGeneral, 7, 4);
1293
  FormPlotStars.GLxzGrid.XSamplingScale.Min := ViewData.xzGrid.xRange.Minimum;
1294
  FormGridOptions.EditxzGridMinz.Text := FloatToStrF(ViewData.xzGrid.zRange.Minimum,
1295
    ffGeneral, 7, 4);
1296
  FormPlotStars.GLxzGrid.ZSamplingScale.Min := ViewData.xzGrid.zRange.Minimum;
1297

1298
  FormGridOptions.EditxzGridMaxx.Text := FloatToStrF(ViewData.xzGrid.xRange.Maximum,
1299
    ffGeneral, 7, 4);
1300
  FormPlotStars.GLxzGrid.XSamplingScale.Max := ViewData.xzGrid.xRange.Maximum;
1301
  FormGridOptions.EditxzGridMaxz.Text := FloatToStrF(ViewData.xzGrid.zRange.Maximum,
1302
    ffGeneral, 7, 4);
1303
  FormPlotStars.GLxzGrid.ZSamplingScale.Max := ViewData.xzGrid.zRange.Maximum;
1304

1305
  FormGridOptions.EditxzGridStpx.Text := FloatToStrF(ViewData.xzGrid.xRange.Step,
1306
    ffGeneral, 7, 4);
1307
  FormPlotStars.GLxzGrid.XSamplingScale.Step := ViewData.xzGrid.xRange.Step;
1308
  FormGridOptions.EditxzGridStpz.Text := FloatToStrF(ViewData.xzGrid.zRange.Step,
1309
    ffGeneral, 7, 4);
1310
  FormPlotStars.GLxzGrid.ZSamplingScale.Step := ViewData.xzGrid.zRange.Step;
1311

1312
  FormGridOptions.EditxzGridPosy.Text := FloatToStrF(ViewData.xzGrid.yPosition,
1313
    ffGeneral, 7, 4);
1314
  FormPlotStars.GLxzGrid.Position.y := ViewData.xzGrid.yPosition;
1315

1316
  FormPlotStars.GLxzGrid.LineColor.SetColor(ViewData.xzGrid.Color.x, ViewData.xzGrid.Color.y,
1317
    ViewData.xzGrid.Color.z, ViewData.xzGrid.Color.W);
1318

1319
  // yz
1320
  FormGridOptions.EdityzGridMiny.Text := FloatToStrF(ViewData.yzGrid.yRange.Minimum,
1321
    ffGeneral, 7, 4);
1322
  FormPlotStars.GLyzGrid.YSamplingScale.Min := ViewData.yzGrid.yRange.Minimum;
1323
  FormGridOptions.EdityzGridMinz.Text := FloatToStrF(ViewData.yzGrid.zRange.Minimum,
1324
    ffGeneral, 7, 4);
1325
  FormPlotStars.GLyzGrid.ZSamplingScale.Min := ViewData.yzGrid.zRange.Minimum;
1326

1327
  FormGridOptions.EdityzGridMaxy.Text := FloatToStrF(ViewData.yzGrid.yRange.Maximum,
1328
    ffGeneral, 7, 4);
1329
  FormPlotStars.GLyzGrid.YSamplingScale.Max := ViewData.yzGrid.yRange.Maximum;
1330
  FormGridOptions.EdityzGridMaxz.Text := FloatToStrF(ViewData.yzGrid.zRange.Maximum,
1331
    ffGeneral, 7, 4);
1332
  FormPlotStars.GLyzGrid.ZSamplingScale.Max := ViewData.yzGrid.zRange.Maximum;
1333

1334
  FormGridOptions.EdityzGridStpy.Text := FloatToStrF(ViewData.yzGrid.yRange.Step,
1335
    ffGeneral, 7, 4);
1336
  FormPlotStars.GLyzGrid.YSamplingScale.Step := ViewData.yzGrid.yRange.Step;
1337
  FormGridOptions.EdityzGridStpz.Text := FloatToStrF(ViewData.yzGrid.zRange.Step,
1338
    ffGeneral, 7, 4);
1339
  FormPlotStars.GLyzGrid.ZSamplingScale.Step := ViewData.yzGrid.zRange.Step;
1340
  FormGridOptions.EdityzGridPosx.Text := FloatToStrF(ViewData.yzGrid.xPosition,
1341
    ffGeneral, 7, 4);
1342
  FormPlotStars.GLyzGrid.Position.x := ViewData.yzGrid.xPosition;
1343
  FormPlotStars.GLyzGrid.LineColor.SetColor(ViewData.yzGrid.Color.x, ViewData.yzGrid.Color.y,
1344
    ViewData.yzGrid.Color.z, ViewData.yzGrid.Color.W);
1345
  FormPlotStars.BoxLine1.LineColor.SetColor(ViewData.BoxLnColor.x, ViewData.BoxLnColor.y,
1346
    ViewData.BoxLnColor.z, ViewData.BoxLnColor.W);
1347

1348
  FormPlotStars.BoxLine2.LineColor := FormPlotStars.BoxLine1.LineColor;
1349
  FormPlotStars.BoxLine3.LineColor := FormPlotStars.BoxLine1.LineColor;
1350
  FormPlotStars.BoxLine4.LineColor := FormPlotStars.BoxLine1.LineColor;
1351

1352
  FormGridOptions.xyGridCB.Checked := ViewData.xyGrid.IsVisible;
1353
  FormGridOptions.xyLock.Checked := ViewData.xyGrid.IsChecked;
1354
  FormPlotStars.GLxyGrid.Visible := ViewData.xyGrid.IsVisible;
1355

1356
  FormGridOptions.xzGridCB.Checked := ViewData.xzGrid.IsVisible;
1357
  FormGridOptions.zLock.Checked := ViewData.xzGrid.IsChecked;
1358
  FormPlotStars.GLxzGrid.Visible := ViewData.xzGrid.IsVisible;
1359

1360
  FormGridOptions.yzGridCB.Checked := ViewData.yzGrid.IsVisible;
1361
  FormGridOptions.MinLock.Checked := ViewData.yzGrid.IsChecked;
1362
  FormPlotStars.GLyzGrid.Visible := ViewData.yzGrid.IsVisible;
1363

1364
  FormGridOptions.EditzScale.Text := FloatToStrF(ViewData.xyGrid.zScale,
1365
    ffGeneral, 7, 4);
1366
  FormPlotStars.GLxzGrid.Scale.z := ViewData.xyGrid.zScale;
1367
  FormPlotStars.GLyzGrid.Scale.z := ViewData.xyGrid.zScale;
1368

1369
  FormGridOptions.BoxOutlineCB.Checked := ViewData.BoxChecked;
1370
  FormGridOptions.EditBoxLnWidth.Text := IntToStr(ViewData.BoxLnWidth);
1371
  FormGridOptions.DrawOutline(ViewData.BoxChecked);
1372

1373
  EvaluateForm.EditX.Text := FloatToStrF(ViewData.xEvaluate, ffGeneral, 7, 4);
1374
  EvaluateForm.EditY.Text := FloatToStrF(ViewData.yEvaluate, ffGeneral, 7, 4);
1375
  EvaluateForm.EditZ.Text := '';
1376
  EvaluateForm.EditCoordWidth.Text := IntToStr(ViewData.CoordWidth);
1377
  EvaluateForm.Coordinates.Checked := ViewData.CoordChecked;
1378
  EvaluateForm.ToGrids.Checked := ViewData.ToGridsChecked;
1379
  EvaluateForm.dzdx_dzdy.Checked := ViewData.dzdx_dyChecked;
1380
  EvaluateForm.ColorDialog.Color := ViewData.CoordColor;
1381
  EvaluateForm.UpdateCoords;
1382
  EvaluateForm.UpdateEvaluate;
1383

1384
  CoordsForm.cbShowCoords.Checked := ViewData.TextVisible;
1385
  CoordsForm.FontButton.Caption := 'Шрифт:' + ' ' + ViewData.TextFontN + ' ' +
1386
    IntToStr(ViewData.TextFontSz);
1387
  FormPlotStars.GLWinBmpFont.Font.Name := ViewData.TextFontN;
1388
  FormPlotStars.GLWinBmpFont.Font.Size := ViewData.TextFontSz;
1389
  CoordsForm.cbXmaxY.Checked := ViewData.xPosYMax;
1390
  CoordsForm.cbXmaxZ.Checked := ViewData.xPosZMax;
1391

1392
  CoordsForm.cbYmaxX.Checked := ViewData.yPosXMax;
1393
  CoordsForm.cbYmaxZ.Checked := ViewData.yPosZMax;
1394

1395
  CoordsForm.cbZmaxY.Checked := ViewData.zPosYMax;
1396
  CoordsForm.cbZmaxX.Checked := ViewData.zPosXMax;
1397

1398
  CoordsForm.UpdateCoordText;
1399

1400
  Editfxy.Text := PlotData.txtStr;
1401
  EditNote.Text := PlotData.NoteStr;
1402

1403
  EditMinX.Text := FloatToStrF(PlotData.xMin, ffGeneral, 7, 4);
1404
  EditMaxX.Text := FloatToStrF(PlotData.xMax, ffGeneral, 7, 4);
1405
  EditdX.Text := FloatToStrF(PlotData.xInc, ffGeneral, 7, 4);
1406

1407
  EditMinY.Text := FloatToStrF(PlotData.yMin, ffGeneral, 7, 4);
1408
  EditMaxY.Text := FloatToStrF(PlotData.yMax, ffGeneral, 7, 4);
1409
  EditdY.Text := FloatToStrF(PlotData.yInc, ffGeneral, 7, 4);
1410

1411
  EditMinZ.Text := FloatToStrF(PlotData.zMin, ffGeneral, 7, 4);
1412
  EditMaxZ.Text := FloatToStrF(PlotData.zMax, ffGeneral, 7, 4);
1413
  cbZLimit.Checked := PlotData.zLim;
1414
  cbZCap.Checked := PlotData.zCap;
1415

1416
  ModeComboBox.ItemIndex := Ord(PlotData.ViewMode);
1417
  StyleComboBox.ItemIndex := Ord(PlotData.fxyMode);
1418

1419
  Caption := GraphFName;
1420
  FormPlotStars.Caption := GraphFName;
1421
  FormGridOptions.Caption := GraphFName;
1422
  EvaluateForm.Caption := GraphFName;
1423
  CoordsForm.Caption := GraphFName;
1424
  CountzPoints;
1425
end;
1426

1427
procedure TFunctionsForm.StyleComboBoxChange(Sender: TObject);
1428
begin
1429
  PlotData.fxyMode := TfxyMode(StyleComboBox.ItemIndex);
1430
  UpdateTPlotDataObject;
1431
  ApplyBtnClick(Sender);
1432
end;
1433

1434
procedure TFunctionsForm.UpButtonClick(Sender: TObject);
1435
var
1436
  i: integer;
1437

1438
begin
1439
  with CheckListBox do
1440
  begin
1441
    i := ItemIndex;
1442
    if i > 0 then
1443
      Items.Move(i, i - 1);
1444
    if i > 1 then
1445
      ItemIndex := i - 1
1446
    else
1447
      ItemIndex := 0;
1448
  end;
1449
  CheckListBoxClick(Sender);
1450
  Altered := True;
1451
end;
1452

1453
procedure TFunctionsForm.AddNewPlot;
1454
begin
1455
  with CheckListBox do
1456
  begin
1457
    AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
1458
    ItemIndex := Count - 1;
1459
    Checked[ItemIndex] := True; // initially this item is checked
1460
  end;
1461
  Editfxy.SetFocus;
1462
  Editfxy.SelLength := 0;
1463
end;
1464

1465
procedure TFunctionsForm.ApplyBtnClick(Sender: TObject);
1466
var
1467
  v: TGlFloat;
1468
  s: string;
1469

1470
begin
1471
  if TooManyPoints > 6 then
1472
    Exit;
1473

1474
  with PlotData do
1475
  begin
1476
    if xMin > xMax then // swap
1477
    begin
1478
      v := xMin;
1479
      xMin := xMax;
1480
      xMax := v;
1481
      s := EditMinX.Text;
1482
      EditMinX.Text := EditMaxX.Text;
1483
      EditMaxX.Text := s;
1484
      UpdateTPlotDataObject;
1485
    end;
1486
    if yMin > yMax then // swap
1487
    begin
1488
      v := yMin;
1489
      yMin := yMax;
1490
      yMax := v;
1491
      s := EditMinY.Text;
1492
      EditMinY.Text := EditMaxY.Text;
1493
      EditMaxY.Text := s;
1494
      UpdateTPlotDataObject;
1495
    end;
1496
  end;
1497

1498
  AddedData.AddedAs := AddNone;
1499

1500
  FormPlotStars.UpdatePlot;
1501
  EvaluateForm.UpdateEvaluate;
1502
  ApplyBtn.Visible := False;
1503
  Altered := True;
1504
end;
1505

1506
procedure TFunctionsForm.CentreClick(Sender: TObject);
1507
var
1508
  x, y, z: TGlFloat;
1509

1510
begin
1511
  with FormPlotStars do
1512
  begin
1513
    MousePoint.x := Maxint;
1514
    x := PlotData.xMax + PlotData.xMin;
1515
    y := PlotData.yMax + PlotData.yMin;
1516
    z := PlotData.zMax + PlotData.zMin;
1517
    TargetCube.Position.SetPoint(x / 2, y / 2, z / 2);
1518
  end;
1519
  Altered := True;
1520
  FormPlotStars.ShowDisplacement;
1521
end;
1522

1523
procedure TFunctionsForm.CheckListBoxClick(Sender: TObject);
1524
begin
1525
  PlotData := TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data;
1526
  if CheckListBox.Checked[CheckListBox.ItemIndex] then
1527
    EvaluateForm.UpdateEvaluate;
1528

1529
  ShowData(Sender);
1530
  if PlotColorsForm.Visible then
1531
    PlotColorsForm.ShowPlotColorData;
1532
  if DerivativesForm.Visible then
1533
    DerivativesForm.ApplyBtn.Visible := True;
1534
end;
1535

1536
procedure TFunctionsForm.CheckListBoxClickCheck(Sender: TObject);
1537
begin
1538
  ApplyBtn.Visible := True;
1539
end;
1540

1541
procedure TFunctionsForm.ReadAndShowInitialData;
1542
begin
1543
  if not ReadData(DataPath + GraphFName) then
1544
  begin
1545
    GraphFName := NewFName;
1546
    NewFile := True;
1547
    ViewData := DefaultViewData;
1548
    PlotData := DefaultPlotData;
1549
    AddedData := DefaultAddedData;
1550
    with CheckListBox do
1551
    begin
1552
      AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
1553
      ItemIndex := Count - 1;
1554
      Checked[ItemIndex] := True; // initially this item is checked
1555
    end;
1556
    FormPlotStars.TargetCube.Position.SetPoint(0, 0, 0);
1557
  end;
1558

1559
  Caption := GraphFName;
1560
  ShowData(Self);
1561
end;
1562

1563
procedure TFunctionsForm.OpenRecentFile(FName: TFileName);
1564
var
1565
  i: integer;
1566

1567
begin
1568
  if DerivativesForm.Visible then
1569
    DerivativesForm.Close;
1570
  if FileExists(FName) then
1571
  begin
1572
    if Altered or GridColorsAltered then
1573
      case MessageDlg('Параметры графика были изменены.' +
1574
        #13#10'Сохранить изменения ?', mtConfirmation,
1575
        [mbYes, mbNo, mbCancel], 0) of
1576
        mrYes:
1577
          miSaveClick(Self);
1578
        mrCancel:
1579
          Exit;
1580
        mrNo:
1581
          begin
1582
            Altered := False;
1583
            GridColorsAltered := False;
1584
            DerivativeAltered := False;
1585
            NewFile := False;
1586
          end;
1587
      end;
1588
    AddRecent(FName);
1589
    DataPath := ExtractFilePath(FName);
1590
    DataPath := IncludeTrailingPathDelimiter(DataPath);
1591
    FormPlotStars.MousePoint.x := Maxint;
1592
    GraphFName := ExtractFileName(FName);
1593

1594
    with CheckListBox do
1595
    begin
1596
      for i := 0 to Items.Count - 1 do
1597
        Items.Objects[i].Free;
1598
      Clear;
1599
    end;
1600

1601
    if ReadData(FName) then
1602
      ShowData(Self);
1603
    if GridColorsForm.Visible then
1604
      GridColorsForm.ShowGridColorData;
1605
    if PlotColorsForm.Visible then
1606
      PlotColorsForm.ShowPlotColorData;
1607

1608
    ApplyBtnClick(Self);
1609
    Altered := False;
1610
    GridColorsAltered := False;
1611
    DerivativeAltered := False;
1612
  end
1613
  else
1614
    MessageDlg('Файл ' + FName + ' не найден', mtError, [mbOK], 0);
1615
end;
1616

1617
procedure TFunctionsForm.AddRecent(const f: TFileName);
1618
var
1619
  i: integer;
1620
  Found: Boolean;
1621

1622
begin
1623
  with FormPlotStars.miRecent do
1624
  begin
1625
    Found := False;
1626
    i := 0;
1627
    while (i < Count) and not Found do
1628
    begin
1629
      Found := Items[i].Caption = DataPath + GraphFName;
1630
      Inc(i);
1631
    end;
1632
    if Found then
1633
      Delete(i - 1);
1634
    Insert(0, TMenuItem.Create(Self));
1635
    Items[0].Caption := DataPath + GraphFName;
1636
    Items[0].OnClick := FormPlotStars.RecentFilesClick;
1637
    if Count > 16 then
1638
      Delete(Count - 1);
1639
  end;
1640
end;
1641

1642
procedure TFunctionsForm.OpenSelectedFile(Sender: TObject; FName: TFileName);
1643
var
1644
  i: integer;
1645

1646
begin
1647
  if FileExists(FName) then
1648
  begin
1649
    Screen.Cursor := crHourglass;
1650
    with CheckListBox do
1651
    begin
1652
      for i := 0 to Items.Count - 1 do
1653
        Items.Objects[i].Free;
1654
      Clear;
1655
    end;
1656
    GraphFName := ExtractFileName(FName);
1657
    if ReadData(DataPath + GraphFName) then
1658
    begin
1659
      Caption := GraphFName;
1660
      FormPlotStars.Caption := GraphFName;
1661
      FormGridOptions.Caption := GraphFName;
1662
      ShowData(Sender);
1663
      NewFile := False;
1664
      Altered := False;
1665
      (* NewFont needed to initialize GLWinFont.GetCharWidth
1666
        if the font has been altered, which may or may not be the case,
1667
        so do it anyway *)
1668
      FormPlotStars.GLSViewer.Buffer.BackgroundColor := ViewData.BackColor;
1669
      FormPlotStars.GLSViewer.Invalidate;
1670
    end;
1671
    Screen.Cursor := crDefault;
1672
  end
1673
  else
1674
  begin
1675
    MessageDlg('Файл' + FName + #13#10'не найден', mtError,
1676
      [mbOK], 0);
1677
    Screen.Cursor := crDefault;
1678
  end;
1679
end;
1680

1681
end.
1682

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

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

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

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