MathgeomGLS

Форк
0
1131 строка · 31.9 Кб
1
unit faNumeric;
2

3
interface
4

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

21
  Vcl.Graphics,
22
  Forms,
23
  Graf.Global1d,
24
  faFunc1d;
25

26
type
27
  TNumericForm = class(TForm)
28
    AddButton: TSpeedButton;
29
    DeleteButton: TSpeedButton;
30
    UpButton: TSpeedButton;
31
    DownButton: TSpeedButton;
32
    CheckListBox: TCheckListBox;
33
    ApplyBitBtn: TBitBtn;
34
    Label4: TLabel;
35
    EditName: TEdit;
36
    Label2: TLabel;
37
    EditXCoord: TEdit;
38
    EditYCoord: TEdit;
39
    Label1: TLabel;
40
    CloseBitBtn: TBitBtn;
41
    Label3: TLabel;
42
    EditPen: TEdit;
43
    PenUpDown: TUpDown;
44
    PenSpeedButton: TSpeedButton;
45
    PenPanel: TPanel;
46
    DataListBox: TListBox;
47
    InputRG: TRadioGroup;
48
    PointsCheckBox: TCheckBox;
49
    SortCheckBox: TCheckBox;
50
    ColorDialog: TColorDialog;
51
    CoordsRG: TRadioGroup;
52
    PointsRG: TRadioGroup;
53
    PointSpeedButton: TSpeedButton;
54
    PointPanel: TPanel;
55
    GraphRG: TRadioGroup;
56
    Label5: TLabel;
57
    PointSizeTB: TTrackBar;
58
    ExtrapolateCB: TCheckBox;
59
    Label6: TLabel;
60
    CurveTB: TTrackBar;
61
    PointUpBtn: TSpeedButton;
62
    PointDownBtn: TSpeedButton;
63
    procedure FormShow(Sender: TObject);
64
    procedure FormDestroy(Sender: TObject);
65
    procedure EditNameKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
66
    procedure ParseKeyPress(Sender: TObject; var Key: Char);
67
    procedure EditNameKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
68
    procedure AddButtonClick(Sender: TObject);
69
    procedure IntKeyPress(Sender: TObject; var Key: Char);
70
    procedure EditPenKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
71
    procedure EditPenChange(Sender: TObject);
72
    procedure DeleteButtonClick(Sender: TObject);
73
    procedure EditXCoordKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
74
    procedure EditYCoordKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
75
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
76
    procedure DataListBoxClick(Sender: TObject);
77
    procedure InputRGClick(Sender: TObject);
78
    procedure DataListBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
79
    procedure CloseBitBtnClick(Sender: TObject);
80
    procedure CheckListBoxClick(Sender: TObject);
81
    procedure SortCheckBoxClick(Sender: TObject);
82
    procedure PointsCheckBoxClick(Sender: TObject);
83
    procedure ColorClick(Sender: TObject);
84
    procedure ApplyBitBtnClick(Sender: TObject);
85
    procedure UpButtonClick(Sender: TObject);
86
    procedure DownButtonClick(Sender: TObject);
87
    procedure CheckListBoxClickCheck(Sender: TObject);
88
    procedure CoordsRGClick(Sender: TObject);
89
    procedure PointColorClick(Sender: TObject);
90
    procedure ExtrapolateCBClick(Sender: TObject);
91
    procedure PointSizeTBChange(Sender: TObject);
92
    procedure PointsRGClick(Sender: TObject);
93
    procedure GraphRGClick(Sender: TObject);
94
    procedure CurveTBChange(Sender: TObject);
95
    procedure EditXCoordEnter(Sender: TObject);
96
    procedure EditCoordExit(Sender: TObject);
97
    procedure EditYCoordEnter(Sender: TObject);
98
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
99
    procedure PointUpBtnClick(Sender: TObject);
100
    procedure PointDownBtnClick(Sender: TObject);
101
  private
102
    xValue, yValue: extended;
103
    CurrentIndex: integer;
104
    function DefaultData: TNumericData;
105
    procedure UpdateNumericDataLists;
106
    procedure ConfirmDataOrder;
107
  public
108
    NumericData: TNumericData;
109
    procedure ShowData(Sender: TObject);
110
    procedure ClearCheckListBox;
111
    procedure UpdateDataListBox;
112
  end;
113

114
var
115
  NumericForm: TNumericForm;
116

117
//=====================================================================
118
implementation
119
//=====================================================================
120

121
uses
122
  Graf.Parser1d,
123
  faGraf1D;
124

125
{$R *.dfm}
126

127
procedure TNumericForm.FormShow(Sender: TObject);
128
begin
129
  Caption := GraphFName;
130
  if CheckListBox.Count = 0 then NumericData := DefaultData;
131
  ShowData(Sender);
132
end;
133

134
procedure TNumericForm.GraphRGClick(Sender: TObject);
135
begin
136
  if Active then
137
  begin
138
    case GraphRG.ItemIndex of
139
    0:GraphRG.Hint := 'Only coordinate points are displayed.';
140
    1:GraphRG.Hint := 'Lines point to point are displayed.';
141
    2:GraphRG.Hint := 'Function plotted using the Lagrange interpolation.';
142
    3:GraphRG.Hint := 'Function plotted using the Hermite interpolation.';
143
    end;
144
    with NumericData do
145
    begin
146
      NumericStyle := TNumericStyle(GraphRG.ItemIndex);
147
      with CheckListBox do
148
      TNumericObject(Items.Objects[ItemIndex]).Data.NumericStyle := NumericStyle;
149
    end;
150
    CurveTB.Enabled := GraphRG.ItemIndex = 3;
151
    Label6.Enabled := CurveTB.Enabled;
152
    ExtrapolateCB.Enabled := GraphRG.ItemIndex = 2;
153
    MainForm.GLViewer.Invalidate;
154
    Altered := True;
155
    ApplyBitBtn.Visible := False;
156
  end;
157
end;
158

159
procedure TNumericForm.ParseKeyPress(Sender: TObject; var Key: Char);
160
begin
161
  with Sender as TEdit do
162
  begin
163
    if not CharInSet(UpCase(Key),
164
   [' ', '!', '(', ')', '*', '+', '-', '.', ',', '/', '0'..'9',
165
    'A'..'C', 'E', 'G'..'I', 'L', 'N'..'T', 'X', '^', '`', #8]) then
166
    begin
167
      Key := #0;
168
      Exit;
169
    end;
170
    if Key = '`' then Key := '�';
171
  end;
172
end;
173

174
procedure TNumericForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
175
begin
176
  if (DataListBox.Count = 0) and (CheckListBox.Count > 0)
177
  then DeleteButtonClick(Sender);
178
  FunctionsForm.CoordPointButton.Visible := False;
179

180
  if ApplyBitBtn.Visible then
181
  begin
182
    case MessageDlg('������� ������ ���� ��������.'+
183
              #13#10'��� ���������� ��������� ������� Apply Change Button.'+
184
              #13#10'��������� ��������� ?', mtConfirmation,
185
                    [mbYes, mbNo], 0) of
186
      mrYes: CanClose := False;
187
    end;
188
  end;
189
end;
190

191
procedure TNumericForm.FormDestroy(Sender: TObject);
192
begin
193
  ClearCheckListBox;
194
end;
195

196
procedure TNumericForm.FormKeyDown(Sender: TObject; var Key: Word;
197
                                    Shift: TShiftState);
198
begin
199
  if not(EditXCoord.Focused or EditYCoord.Focused) then
200
  case Key of
201
    VK_ADD: AddButtonClick(Sender);
202
    VK_SUBTRACT: DeleteButtonclick(Sender);
203
  end;
204
end;
205

206
procedure TNumericForm.EditNameKeyUp(Sender: TObject; var Key: Word;
207
                                      Shift: TShiftState);
208
begin
209
  with CheckListBox do if Count > 0 then
210
  begin
211
    if ItemIndex < 0 then ItemIndex := 0;
212
    TNumericObject(Items.Objects[ItemIndex]).Data.Name := EditName.Text;
213
    Items[ItemIndex] := EditName.Text;
214
    ApplyBitBtn.Visible := True;
215
  end;
216
end;
217

218
procedure TNumericForm.EditNameKeyDown(Sender: TObject; var Key: Word;
219
                                    Shift: TShiftState);
220
begin
221
  if (Key = VK_DELETE) or (Key = VK_BACK)
222
  then ApplyBitBtn.Visible := True;
223
end;
224

225
procedure TNumericForm.EditPenChange(Sender: TObject);
226
var
227
  k: word;
228

229
begin
230
  if Active then
231
  begin
232
    k := 0;
233
    EditPenKeyUp(Sender, k, []);
234
  end;
235
end;
236

237
procedure TNumericForm.EditPenKeyUp(Sender: TObject; var Key: Word;
238
                                     Shift: TShiftState);
239
var
240
  w: integer;
241

242
begin
243
  if Active then with Sender as TEdit do
244
  begin
245
    try
246
      w := StrToInt(Text);
247
    except
248
      w := 1;
249
    end;
250
    if w < 1 then w := 1;
251

252
    NumericData.PlotWidth := w;
253
    with CheckListBox do if Count > 0 then
254
    begin
255
      TNumericObject(Items.Objects[ItemIndex]).Data.PlotWidth := w;
256
      MainForm.GLViewer.Invalidate;
257
      Altered := True;
258
      ApplyBitBtn.Visible := False;
259
    end;
260
  end;
261
end;
262

263
procedure TNumericForm.EditXCoordEnter(Sender: TObject);
264
begin
265
  with MainForm.StatusBar.Panels[2] do
266
  case CoordsRG.ItemIndex of
267
  0:case InputRG.ItemIndex of
268
    0:Text := 'Enter an x Coordinate value then press Enter key.';
269
    1:Text := 'Enter a value then press Enter key to alter x Coordinate.';
270
    2:Text := 'Select an item from the coordinates list and press Delete Key.';
271
    end;
272
  1:case InputRG.ItemIndex of
273
    0:Text := 'Enter a value for polar angle ''�'' then press Enter key.';
274
    1:Text := 'Enter a value then press Enter key to alter ''�''.';
275
    2:Text := 'Select an item from the coordinates list and press Delete Key.';
276
    end;
277
  2:case InputRG.ItemIndex of
278
    0:Text := 'Enter a length for the vector then press Enter key.';
279
    1:Text := 'Enter a value then press Enter key to alter the vector length.';
280
    2:Text := 'Select an item from the coordinates list and press Delete Key.';
281
    end;
282
  end;
283
end;
284

285
procedure TNumericForm.EditCoordExit(Sender: TObject);
286
begin
287
  MainForm.StatusBar.Panels[2].Text := '';
288
end;
289

290
procedure TNumericForm.EditXCoordKeyUp(Sender: TObject; var Key: Word;
291
                                        Shift: TShiftState);
292
var
293
  s: string;
294
  e: byte;
295

296
begin
297
  if Active and (Key <> 9) then
298
  begin
299
    s := ScanText(EditXCoord.Text);
300
    xValue := ParseAndEvaluate(s, e);
301
    if isNAN(xValue) or isInfinite(xValue) or (e > 0) then xValue := 0;
302
    if Key = VK_RETURN then
303
    case InputRG.ItemIndex of
304
    0:begin      { Adding }
305
        EditYCoord.SetFocus;
306
      end;
307
    1:if DataListBox.Count > 0 then
308
      begin      { Editing }
309
        UpdateNumericDataLists;
310
        EditYCoord.SetFocus;
311
      end;
312
    end;
313
  end;
314
end;
315

316
procedure TNumericForm.EditYCoordEnter(Sender: TObject);
317
begin
318
  with MainForm.StatusBar.Panels[2] do
319
  case CoordsRG.ItemIndex of
320
  0:case InputRG.ItemIndex of
321
    0:Text := 'Enter a y Coordinate value then press Enter key.';
322
    1:Text := 'Enter a value then press Enter key to alter y Coordinate.';
323
    2:Text := 'Select an item from the coordinates list and press Delete Key.';
324
    end;
325
  1:case InputRG.ItemIndex of
326
    0:Text := 'Enter a value for the polar radial ''r'' then press Enter key.';
327
    1:Text := 'Enter a value then press Enter key to alter ''r''.';
328
    2:Text := 'Select an item from the coordinates list and press Delete Key.';
329
    end;
330
  2:case InputRG.ItemIndex of
331
    0:Text := 'Enter an angle for the vector then press Enter key.';
332
    1:Text := 'Enter a value then press Enter key to alter the vector angle.';
333
    2:Text := 'Select an item from the coordinates list and press Delete Key.';
334
    end;
335
  end;
336
end;
337

338
procedure TNumericForm.EditYCoordKeyUp(Sender: TObject; var Key: Word;
339
                                        Shift: TShiftState);
340
var
341
  j: integer;
342
  s: string;
343
  e: byte;
344

345
begin
346
  if Active and (Key <> 9) then
347
  begin
348
    s := ScanText(EditYCoord.Text);
349
    yValue := ParseAndEvaluate(s, e);
350
    if isNAN(yValue) or isInfinite(yValue) or (e > 0) then yValue := 0;
351
    if Key = VK_RETURN then
352
    begin
353
      case InputRG.ItemIndex of
354
      0:begin    { Adding }
355
          UpdateNumericDataLists;
356
          EditXCoord.SetFocus;
357
        end;
358
      1:if DataListBox.Count > 0 then
359
        begin    { Editing }
360
          j := DataListBox.ItemIndex;
361
          UpdateNumericDataLists;
362
          if j < DataListBox.Count -1 then
363
          begin
364
            DataListBox.ItemIndex := j +1;
365
            DataListBox.Selected[DataListbox.ItemIndex] := True;
366
            DataListBoxClick(Sender);
367
          end;
368
          EditXCoord.SetFocus;
369
        end;
370
      end;
371
    end;
372
    if DataListBox.Count > 0 then
373
    begin
374
      MainForm.GLViewer.Invalidate;
375
      Altered := True;
376
      ApplyBitBtn.Visible := False;
377
    end;
378
  end;
379
end;
380

381
procedure TNumericForm.ExtrapolateCBClick(Sender: TObject);
382
begin
383
  with NumericData do
384
  begin
385
    Extrapolate := ExtrapolateCB.Checked;
386
    with CheckListBox do
387
    TNumericObject(Items.Objects[ItemIndex]).Data.Extrapolate := Extrapolate;
388
  end;
389
  MainForm.GLViewer.Invalidate;
390
  Altered := True;
391
  ApplyBitBtn.Visible := False;
392
end;
393

394
procedure TNumericForm.InputRGClick(Sender: TObject);
395
begin
396
  if DataListBox.Count > 0 then
397
  case InputRG.ItemIndex of
398
  0:begin
399
      InputRG.Hint := 'Adding: Enter coordinates & press enter.';
400
      DataListBox.Hint := 'Adding data.';
401
      DataListBox.MultiSelect := False;
402
      EditXCoord.Text := '';
403
      EditYCoord.Text := '';
404
      SortCheckBox.Enabled := True;
405
      ConfirmDataOrder;
406
    end;
407
  1:begin
408
      InputRG.Hint := 'Select the item to edit then enter coordinates & press enter.';
409
      DataListBox.Hint := 'Editing data.';
410
      DataListBox.MultiSelect := False;
411
      SortCheckBox.Enabled := False;
412
      DataListBox.SetFocus;
413
      DataListBoxClick(Sender);
414
      MainForm.GLViewer.Invalidate;
415
    end;
416
  2:begin
417
      InputRG.Hint := 'Select the items to delete. Multiple items can be selected.';
418
      DataListBox.Hint := 'Deleting data: Press ''Del'' to delete. Two items must remain.';
419
      DataListBox.MultiSelect := True;
420
      SortCheckBox.Enabled := False;
421
      DataListBox.SetFocus;
422
      DataListBoxClick(Sender);
423
      MainForm.GLViewer.Invalidate;
424
    end;
425
  end;
426
end;
427

428
procedure TNumericForm.IntKeyPress(Sender: TObject; var Key: Char);
429
begin
430
  with Sender as TEdit do
431
  if not CharInSet(Key, ['0'..'9', #8]) then Key := #0;
432
end;
433

434
procedure TNumericForm.PointColorClick(Sender: TObject);
435
begin
436
  with NumericData do
437
  begin
438
    with CheckListBox do ColorDialog.Color :=
439
    TNumericObject(Items.Objects[ItemIndex]).Data.PointColor;
440
    if ColorDialog.Execute then
441
    begin
442
      NumericData.PointColor := ColorDialog.Color;
443
      with CheckListBox do
444
      TNumericObject(Items.Objects[ItemIndex]).Data.PointColor :=
445
      ColorDialog.Color;
446
      PointPanel.Color := ColorDialog.Color;
447
      MainForm.GLViewer.Invalidate;
448
      Altered := True;
449
      ApplyBitBtn.Visible := False;
450
    end;
451
  end;
452
end;
453

454
procedure TNumericForm.PointDownBtnClick(Sender: TObject);
455
var
456
  i: integer;
457

458
begin
459
  with DataListBox do
460
  begin
461
    i := ItemIndex;
462
    if i < Count -1 then Items.Move(i, i+1);
463
    ItemIndex := i+1;
464
  end;
465
  with CheckListBox do if i < DataListBox.Count -1
466
  then TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Move(i, i+1);
467

468
  MainForm.GLViewer.Invalidate;
469
  Altered := True;
470
end;
471

472
procedure TNumericForm.PointsCheckBoxClick(Sender: TObject);
473
begin
474
  if Active and (CheckListBox.Count > 0) then
475
  begin
476
    NumericData.ShowPoints := PointsCheckBox.Checked;
477
    with CheckListBox do
478
    TNumericObject(Items.Objects[ItemIndex]).Data.ShowPoints :=
479
                                             PointsCheckBox.Checked;
480
    MainForm.GLViewer.Invalidate;
481
    Altered := True;
482
    ApplyBitBtn.Visible := False;
483
  end;
484
end;
485

486
procedure TNumericForm.PointSizeTBChange(Sender: TObject);
487
begin
488
  if Active then with NumericData do
489
  begin
490
    PointSize := PointSizeTB.Position;
491
    with CheckListBox do
492
    TNumericObject(Items.Objects[ItemIndex]).Data.PointSize := PointSize;
493
  end;
494
  MainForm.GLViewer.Invalidate;
495
  Altered := True;
496
  ApplyBitBtn.Visible := False;
497
end;
498

499
procedure TNumericForm.PointsRGClick(Sender: TObject);
500
begin
501
  with NumericData do
502
  begin
503
    PointStyle := TPointStyle(PointsRG.ItemIndex);
504
    with CheckListBox do
505
    TNumericObject(Items.Objects[ItemIndex]).Data.PointStyle := PointStyle;
506
  end;
507
  MainForm.GLViewer.Invalidate;
508
  Altered := True;
509
  ApplyBitBtn.Visible := False;
510
end;
511

512
procedure TNumericForm.PointUpBtnClick(Sender: TObject);
513
var
514
  i: integer;
515

516
begin
517
  with DataListBox do
518
  begin
519
    i := ItemIndex;
520
    if i > 0 then Items.Move(i, i-1);
521
    if i > 1 then ItemIndex := i-1 else ItemIndex := 0;
522
  end;
523
  with CheckListBox do if i > 0
524
  then TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Move(i, i-1);
525

526
  MainForm.GLViewer.Invalidate;
527
  Altered := True;
528
end;
529

530
procedure TNumericForm.CoordsRGClick(Sender: TObject);
531
begin
532
  if Active and (CheckListBox.Count > 0) then
533
  begin
534
    case CoordsRG.ItemIndex of
535
    0:begin
536
        Label2.Caption := 'Plot Cartesian Coordinates {x, y}';
537
      end;
538
    1:begin
539
        Label2.Caption := 'Plot Polar Coordinates {�, r}';
540
      end;
541
    2:begin
542
        Label2.Caption := 'Enter a vector {length, angle}';
543
      end;
544
    end;
545
    DataListBoxClick(Sender);
546
    NumericData.CoordsIdx := CoordsRG.ItemIndex;
547
    with CheckListBox do
548
    TNumericObject(Items.Objects[ItemIndex]).Data.CoordsIdx :=
549
                                      NumericData.CoordsIdx;
550
    MainForm.GLViewer.Invalidate;
551
    Altered := True;
552
    ApplyBitBtn.Visible := False;
553
  end;
554
end;
555

556
procedure TNumericForm.ShowData(Sender: TObject);
557
var
558
  a, b: Boolean;
559

560
begin
561
  a := Altered;
562
  with CheckListBox do
563
  begin
564
    b := Count > 0;
565
    if b and (ItemIndex < 0) then ItemIndex := Count -1;
566
  end;
567
  DeleteButton.Enabled := b;
568
  UpButton.Enabled := b and (CheckListBox.Count > 1);
569
  DownButton.Enabled := b and (CheckListBox.Count > 1);
570
  DataListBox.Enabled := b;
571
  Label1.Enabled := b;
572
  Label4.Enabled := b;
573
  EditName.Enabled := b;
574
  Label3.Enabled := b;
575
  PointSpeedButton.Enabled := b;
576
  EditPen.Enabled := b;
577
  PenUpDown.Enabled := b;
578
  PenSpeedButton.Enabled := b;
579
  PointPanel.Enabled := b;
580
  PenPanel.Enabled := b;
581
  PointsCheckBox.Enabled := b;
582
  Label2.Enabled := b;
583
  EditXCoord.Enabled := b;
584
  EditYCoord.Enabled := b;
585
  SortCheckBox.Enabled := b;
586
  PointUpBtn.Enabled := not SortCheckBox.Checked;
587
  PointDownBtn.Enabled := not SortCheckBox.Checked;
588
  InputRG.Enabled := b;
589
  PointsRG.Enabled := b;
590
  GraphRG.Enabled := b;
591
  CoordsRG.Enabled := b;
592
  Label5.Enabled := b;
593
  PointSizeTB.Enabled := b;
594
  Label6.Enabled := b and (GraphRG.ItemIndex = 3);
595
  CurveTB.Enabled := b and (GraphRG.ItemIndex = 3);
596
  ExtrapolateCB.Enabled := b and (GraphRG.ItemIndex = 2);
597
  if b then
598
  begin
599
//  ConfirmDataOrder;??????
600
    SortCheckBox.Checked := NumericData.SortXValue;
601
    PointsCheckBox.Checked := NumericData.ShowPoints;
602
    EditPen.Text := IntToStr(NumericData.PlotWidth);
603
    PenPanel.Color := NumericData.PlotColor;
604
    EditName.Text := NumericData.Name;
605
    CoordsRG.ItemIndex := NumericData.CoordsIdx;
606
    PointsRG.ItemIndex := Ord(NumericData.PointStyle);
607
    PointSizeTB.Position := NumericData.PointSize;
608
    PointPanel.Color := NumericData.PointColor;
609
    GraphRG.ItemIndex := Ord(NumericData.NumericStyle);
610
    CurveTB.Position := NumericData.CurveRate;
611
    Label6.Caption := 'Curve Rate '+IntToStr(CurveTB.Position);
612
    ExtrapolateCB.Checked := NumericData.Extrapolate;
613
  end
614
  else DataListBox.Clear;
615
  Altered := a;
616
end;
617

618
procedure TNumericForm.SortCheckBoxClick(Sender: TObject);
619
begin
620
  PointUpBtn.Enabled := not SortCheckBox.Checked;
621
  PointDownBtn.Enabled := not SortCheckBox.Checked;
622
  if Active then with CheckListBox do if Count > 0 then
623
  begin
624
    TNumericObject(Items.Objects[ItemIndex]).Data.SortXValue := SortCheckBox.Checked;
625
    NumericData.SortXValue := SortCheckBox.Checked;
626
    ApplyBitBtn.Visible := DataListBox.Count > 0;
627
    if SortCheckBox.Checked then ConfirmDataOrder;
628
  end;
629
end;
630

631
procedure TNumericForm.AddButtonClick(Sender: TObject);
632
begin
633
  with CheckListBox do
634
  begin
635
    if Count = 0 then NumericData := DefaultData
636
    else NumericData := TNumericObject(Items.Objects[ItemIndex]).Data;
637
    AddItem(NumericData.Name, TNumericObject.Create(NumericData));
638
    ItemIndex := Count -1;
639
    Checked[ItemIndex] := True;
640
    DataListBox.Clear;
641
    CurrentIndex := ItemIndex;
642
  end;
643
  Altered := True;
644
  ShowData(Sender);
645
  InputRG.ItemIndex := 0;
646
  EditXCoord.SetFocus;
647
  ApplyBitBtn.Visible := True;
648
end;
649

650
procedure TNumericForm.DataListBoxClick(Sender: TObject);
651
  procedure PointToVector(x1, y1, x2, y2: extended; var l, a: extended);
652
  var
653
    dx, dy: extended;
654

655
  begin
656
    dx := x2 - x1;
657
    dy := y2 - y1;
658
    l := Sqrt(dx*dx + dy*dy);
659
    a := ArcTan(dy/dx);
660
  end;
661

662
var
663
  j: integer;
664
  l, a: extended;
665
  x, y: extended;
666

667
begin
668
  if InputRG.ItemIndex > 0 then
669
  begin        { Editing or Deleting }
670
    j := DataListBox.ItemIndex;
671
    with CheckListBox, TGraphPointObject(
672
         TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j]) do
673
    begin
674
      xValue := x_phi;
675
      yValue := y_r;
676

677
      case CoordsRG.ItemIndex of
678
      0:begin    { Cartesian option }
679
          EditXCoord.Text := FloatToStr(xValue);
680
          EditYCoord.Text := FloatToStr(yValue);
681
        end;
682
      1:begin    { Polar option }
683
          EditXCoord.Text := FloatToStrF(RadToDeg(xValue), ffNumber, 7, 5)+'�';
684
          EditYCoord.Text := FloatToStr(yValue);
685
        end;
686
      2:begin    { As a Vector option }
687
          l := 0;
688
          a := 0;
689
          if j > 0 then //PointToVector(0, 0, xValue, yValue, l, a)
690
          begin
691
            with CheckListBox, TGraphPointObject(
692
            TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j -1]) do
693
            begin
694
              x := x_phi;
695
              y := y_r;
696
            end;
697
            PointToVector(x, y, xValue, yValue, l, a);
698
          end;
699
          EditXCoord.Text := FloatToStr(l);
700
          EditYCoord.Text := FloatToStrF(RadToDeg(a), ffNumber, 7, 5)+'�';
701
        end;
702
      end;
703
    end;
704
    MainForm.GLViewer.Invalidate;
705
  end;
706
end;
707

708
procedure TNumericForm.DataListBoxKeyDown(Sender: TObject; var Key: Word;
709
                                          Shift: TShiftState);
710
var
711
  j, k: integer;
712

713
begin
714
  if (DataListBox.Count > 2) and (Key = VK_DELETE) then
715
  begin
716
    j := DataListBox.ItemIndex;        { free ControlPoint[j] }
717
    k := CheckListBox.ItemIndex;
718
    with CheckListBox, TGraphPointObject(
719
         TNumericObject(Items.Objects[k]).ControlPoints[j]) do Free;
720
    UpdateNumericDataLists;
721
    DataListBox.Selected[DataListBox.ItemIndex] := True;
722
    ApplyBitBtn.Visible := DataListBox.Count > 0;
723
  end;
724
end;
725

726
function TNumericForm.DefaultData: TNumericData;
727
begin
728
  with Result do
729
  begin
730
    Name := 'Numeric Plot';
731
    NumericStyle := nsLinear;
732
    ShowPoints := True;
733
    PointStyle := psSquare;
734
    PointSize := 1;         {  }
735
    PointColor := ClBlack;  {  }
736
    PlotWidth := 1;         { pen width for plot }
737
    PlotColor := ClBlack;   { pen color for plot }
738
    SortXValue := True;     { x values sorted if true }
739
    Extrapolate := False;   { extrapolate graph if true }
740
    CoordsIdx := 0;         { enter coords as x, y or phi, r or vector }
741
    CurveRate := 5;         { was k0 = 0.5; CurveRate/100 }
742
  end;
743
end;
744

745
procedure TNumericForm.ApplyBitBtnClick(Sender: TObject);
746
begin
747
  if EditXCoord.Focused or EditYCoord.Focused then Exit;
748

749
  if (DataListBox.Count = 0) and (CheckListBox.Count > 0)
750
  then DeleteButtonClick(Sender);
751

752
  MainForm.GLViewer.Invalidate;
753
  Altered := True;
754
  ApplyBitBtn.Visible := False;
755
end;
756

757
procedure TNumericForm.CheckListBoxClick(Sender: TObject);
758
begin
759
  if Active then
760
  begin
761
    UpdateDataListBox;
762
    ShowData(Sender);
763
  end;
764
end;
765

766
procedure TNumericForm.CheckListBoxClickCheck(Sender: TObject);
767
begin
768
  MainForm.GLViewer.Invalidate;
769
  Altered := True;
770
  ApplyBitBtn.Visible := False;
771
end;
772

773
procedure TNumericForm.ClearCheckListBox;
774
var
775
  i: integer;
776

777
begin
778
  with CheckListBox do
779
  begin
780
    for i := 0 to Count -1 do Items.Objects[i].Free;
781
    Clear;
782
  end;
783
end;
784

785
procedure TNumericForm.CloseBitBtnClick(Sender: TObject);
786
begin
787
  Close;
788
end;
789

790
procedure TNumericForm.ColorClick(Sender: TObject);
791
begin
792
  with NumericData do
793
  begin
794
    with CheckListBox do ColorDialog.Color :=
795
    TNumericObject(Items.Objects[ItemIndex]).Data.PlotColor;
796
    if ColorDialog.Execute then
797
    begin
798
      NumericData.PlotColor := ColorDialog.Color;
799
      with CheckListBox do
800
      TNumericObject(Items.Objects[ItemIndex]).Data.PlotColor :=
801
      ColorDialog.Color;
802
      PenPanel.Color := ColorDialog.Color;
803
      MainForm.GLViewer.Invalidate;
804
      Altered := True;
805
      ApplyBitBtn.Visible := False;
806
    end;
807
  end;
808
end;
809

810
procedure TNumericForm.CurveTBChange(Sender: TObject);
811
begin
812
  if Active then
813
  begin
814
    with NumericData do
815
    begin
816
      CurveRate := CurveTB.Position;
817
      Label6.Caption := 'Curve Rate '+IntToStr(CurveTB.Position);
818
      with CheckListBox do
819
      TNumericObject(Items.Objects[ItemIndex]).Data.CurveRate := CurveRate;
820
    end;
821
    MainForm.GLViewer.Invalidate;
822
    Altered := True;
823
    ApplyBitBtn.Visible := False;
824
  end;
825
end;
826

827
procedure TNumericForm.UpdateNumericDataLists;
828
  function InsertValuesAt: integer;
829
  var
830
    i: integer;
831

832
  begin
833
    Result := -1;
834
    with CheckListBox do
835
    if TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Count > 0 then
836
    begin
837
      if xValue < TGraphPointObject(
838
         TNumericObject(Items.Objects[ItemIndex]).ControlPoints[0]).x_phi
839
      then Result := 0
840
      else
841
      begin
842
        i := TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Count -1;
843
        if xValue < TGraphPointObject(
844
        TNumericObject(Items.Objects[ItemIndex]).ControlPoints[i]).x_phi then
845
        begin
846
          while (i > 0) and (xValue < TgraphPointObject(
847
          TNumericObject(Items.Objects[ItemIndex]).ControlPoints[i]).x_phi)
848
          do Dec(i);
849
          Result := i +1;
850
        end;
851
      end;
852
    end;
853
  end;
854

855
var
856
  s: string;
857
  j: integer;
858
  e: byte;
859
  x: extended;
860
  y: extended;
861

862
begin
863
  if CoordsRG.ItemIndex = 2 then   { As a Vector option }
864
  begin
865
    s := ScanText(EditXCoord.Text);
866
    xValue := ParseAndEvaluate(s, e);
867
//  if isNAN(xValue) then xValue := 0;
868
//  if e > 0 then xValue := 0;
869
    if isNAN(xValue) or isInfinite(xValue) or (e > 0) then xValue := 0;
870
    x := xValue*Cos(yValue);
871
    y := xValue*Sin(yValue);
872
    j := DataListBox.Count;
873

874
    if j > 0 then with CheckListBox, TGraphPointObject(
875
       TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j -1]) do
876
    begin
877
      x := x + x_phi;
878
      y := y + y_r;
879
    end;
880
    xValue := x;
881
    yValue := y;
882
  end;
883

884
  case InputRG.ItemIndex of
885
  0:begin       { Adding }
886
      if SortCheckBox.Checked then j := InsertValuesAt else j := -1;
887
      if j > -1 then
888
      begin    { insert added data }
889
        DataListBox.Items.Insert(j, Format('%18s,%18s', [FloatToStr(xValue),
890
                                                         FloatToStr(yValue)]));
891
        with CheckListBox do
892
        TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Insert(j,
893
                       TgraphPointObject.Create(xValue, yValue));
894
      end
895
      else
896
      begin    { append added data}
897
        DataListBox.Items.Add(Format('%18s,%18s', [FloatToStr(xValue),
898
                                                   FloatToStr(yValue)]));
899
        with CheckListBox do
900
        TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Add(
901
                       TGraphPointObject.Create(xValue, yValue));
902
        j := DataListBox.Count -1;
903
      end;
904
      DataListBox.ItemIndex := j;
905
      DataListBox.Selected[j] := True;
906
    end;
907
  1:begin       { Editing }
908
      j := DataListBox.ItemIndex;
909
      if CoordsRG.ItemIndex = 2 then
910
      begin
911
      end
912
      else DataListBox.Items[j] := Format('%18s,%18s', [FloatToStr(xValue),
913
                                                        FloatToStr(yValue)]);
914
      with CheckListBox, TGraphPointObject(
915
      TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j]) do
916
      begin
917
        x_phi := xValue;
918
        y_r := yValue;
919
      end;
920
    end;
921
  2:with DataListBox do if SelCount > 0 then
922
    begin       { Deleting }
923
      j := 0;
924
      while (j < Count) and (Count > 2) do
925
      begin
926
        if Selected[j] then
927
        begin
928
          with CheckListBox do
929
          TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Delete(j);
930
          Items.Delete(j);
931
        end
932
        else Inc(j);
933
      end;
934
      MainForm.GLViewer.Invalidate;
935
      Altered := True;
936
      ApplyBitBtn.Visible := False;
937
    end;
938
  end;
939
end;
940

941
procedure TNumericForm.UpButtonClick(Sender: TObject);
942
var
943
  i: integer;
944

945
begin
946
  with CheckListBox do
947
  begin
948
    i := ItemIndex;
949
    if i > 0 then Items.Move(i, i-1);
950
    if i > 1 then ItemIndex := i-1 else ItemIndex := 0;
951
  end;
952
  CheckListBoxClick(Sender);
953
end;
954

955
procedure TNumericForm.UpdateDataListBox;
956
var
957
  j: integer;
958
  p: TGraphPointObject;
959

960
begin
961
  if Active then
962
  begin
963
    if CheckListBox.Count > 0 then
964
    begin
965
      DataListBox.Clear;
966
      with CheckListBox do
967
      begin
968
        NumericData := TNumericObject(Items.Objects[ItemIndex]).Data;
969
        CurrentIndex := ItemIndex;
970
        for j := 0 to TNumericObject(
971
            Items.Objects[ItemIndex]).ControlPoints.Count -1 do
972
        begin
973
          p := TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j];
974
          DataListBox.Items.Add(Format('%18s,%18s', [FloatToStr(p.x_phi),
975
                                                     FloatToStr(p.y_r)]));
976
        end;
977
      end;
978
      with DataListBox do if Count > 0 then
979
      begin
980
        ItemIndex := Count -1;
981
        Selected[ItemIndex] := True;
982
      end;
983

984
      if InputRG.ItemIndex = 0 then
985
      begin
986
        EditXCoord.Text := '';
987
        EditYCoord.Text := '';
988
      end
989
      else DataListBoxClick(Self);
990
      ShowData(Self);
991
    end;
992
  end;
993
end;
994

995
procedure TNumericForm.DeleteButtonClick(Sender: TObject);
996
var
997
  i: integer;
998

999
begin
1000
  if CheckListBox.Count > 0 then
1001
  begin
1002
    with CheckListBox do
1003
    begin
1004
      i := ItemIndex;
1005
      with Items.Objects[i] as TNumericObject do Free;
1006
      Items.Delete(i);
1007
      if i > Count -1 then i := Count -1;
1008
      ItemIndex := i;
1009
      DeleteButton.Enabled := Count > 0;
1010
    end;
1011
  end;
1012
  Altered := True;
1013
  ApplyBitBtn.Visible := True;
1014
  if CheckListBox.Count > 0 then CheckListBoxClick(Sender);
1015
  if CheckListBox.Count < 2  then ShowData(Sender);
1016
end;
1017

1018
procedure TNumericForm.DownButtonClick(Sender: TObject);
1019
var
1020
  i: integer;
1021

1022
begin
1023
  with CheckListBox do
1024
  begin
1025
    i := ItemIndex;
1026
    if i < Count -1 then Items.Move(i, i+1);
1027
    ItemIndex := i+1;
1028
  end;
1029
  CheckListBoxClick(Sender);
1030
end;
1031

1032
procedure TNumericForm.ConfirmDataOrder;
1033
var
1034
  x, y: extended;
1035

1036
  function InsertValuesAt: integer;
1037
  var
1038
    i: integer;
1039

1040
  begin
1041
    Result := -1;
1042
    with CheckListBox do
1043
    if TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Count > 0 then
1044
    begin
1045
      if x < TGraphPointObject(
1046
         TNumericObject(Items.Objects[ItemIndex]).ControlPoints[0]).x_phi
1047
      then Result := 0
1048
      else
1049
      begin
1050
        i := TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Count -1;
1051
        if x < TGraphPointObject(
1052
        TNumericObject(Items.Objects[ItemIndex]).ControlPoints[i]).x_phi then
1053
        begin
1054
          while (i > 0) and (x < TgraphPointObject(
1055
          TNumericObject(Items.Objects[ItemIndex]).ControlPoints[i]).x_phi)
1056
          do Dec(i);
1057
          Result := i +1;
1058
        end;
1059
      end;
1060
    end;
1061
  end;
1062

1063
var
1064
  i, j: integer;
1065
  IsOrdered: Boolean;
1066
  Temp: TList;         { list of TGraphPointObject }
1067

1068
begin
1069
  if SortCheckBox.Checked and (DataListBox.Count > 1) then
1070
  with CheckListBox do if Count > 0 then
1071
  with TNumericObject(Items.Objects[ItemIndex]) do
1072
  begin
1073
    IsOrdered := ControlPoints.Count > 1;
1074
    i := 1;
1075
    while IsOrdered and (i < ControlPoints.Count) do
1076
    begin
1077
      IsOrdered := (TGraphPointObject(ControlPoints[i]).x_phi >
1078
                    TGraphPointObject(ControlPoints[i -1]).x_phi);
1079
      Inc(i);
1080
    end;
1081
    if not IsOrdered and (MessageDlg('The current data is not sorted!'+
1082
                               #13#10'Should the data be sorted?',
1083
           mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
1084
    begin
1085
      Temp := TList.Create;
1086
      try
1087
        Temp.Assign(ControlPoints);
1088
        ControlPoints.Clear;
1089
        DataListBox.Clear;
1090
        x := TGraphPointObject(Temp[0]).x_phi;
1091
        y := TGraphPointObject(Temp[0]).y_r;
1092
        DataListBox.Items.Add(Format('%18s,%18s', [FloatToStr(x), FloatToStr(y)]));
1093
        ControlPoints.Add(TGraphPointObject.Create(x, y));
1094
        j := InsertValuesAt;
1095
        for i := 1 to Temp.Count -1 do
1096
        begin
1097
          x := TGraphPointObject(Temp[i]).x_phi;
1098
          y := TGraphPointObject(Temp[i]).y_r;
1099
          j := InsertValuesAt;
1100
          if j > -1 then
1101
          begin    { insert added data }
1102
            DataListBox.Items.Insert(j, Format('%18s,%18s', [FloatToStr(x),
1103
                                                             FloatToStr(y)]));
1104
            with CheckListBox do
1105
            TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Insert(j,
1106
                           TGraphPointObject.Create(x, y));
1107
          end
1108
          else
1109
          begin    { append added data}
1110
            DataListBox.Items.Add(Format('%18s,%18s', [FloatToStr(x),
1111
                                                       FloatToStr(y)]));
1112
            with CheckListBox do
1113
            TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Add(
1114
                           TGraphPointObject.Create(x, y));
1115
            j := DataListBox.Count -1;
1116
          end;
1117
        end;
1118
        DataListBox.ItemIndex := j;
1119
        DataListBox.Selected[j] := True;
1120
      finally
1121
        for i := 0 to Temp.Count -1 do TObject(Temp.Items[i]).Free;
1122
        Temp.Free;
1123
        MainForm.GLViewer.Invalidate;
1124
        Altered := True;
1125
        ApplyBitBtn.Visible := False;
1126
      end;
1127
    end;
1128
  end;
1129
end;
1130

1131
end.
1132

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

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

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

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