MathgeomGLS
1131 строка · 31.9 Кб
1unit fNumeric;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.UITypes,
9System.SysUtils,
10System.Variants,
11System.Classes,
12System.Math,
13Vcl.Dialogs,
14Vcl.ComCtrls,
15Vcl.StdCtrls,
16Vcl.ExtCtrls,
17Vcl.Controls,
18Vcl.Buttons,
19Vcl.CheckLst,
20
21Vcl.Graphics,
22Forms,
23uGlobal,
24fFuncts;
25
26type
27TNumericForm = class(TForm)
28AddButton: TSpeedButton;
29DeleteButton: TSpeedButton;
30UpButton: TSpeedButton;
31DownButton: TSpeedButton;
32CheckListBox: TCheckListBox;
33ApplyBitBtn: TBitBtn;
34Label4: TLabel;
35EditName: TEdit;
36Label2: TLabel;
37EditXCoord: TEdit;
38EditYCoord: TEdit;
39Label1: TLabel;
40CloseBitBtn: TBitBtn;
41Label3: TLabel;
42EditPen: TEdit;
43PenUpDown: TUpDown;
44PenSpeedButton: TSpeedButton;
45PenPanel: TPanel;
46DataListBox: TListBox;
47InputRG: TRadioGroup;
48PointsCheckBox: TCheckBox;
49SortCheckBox: TCheckBox;
50ColorDialog: TColorDialog;
51CoordsRG: TRadioGroup;
52PointsRG: TRadioGroup;
53PointSpeedButton: TSpeedButton;
54PointPanel: TPanel;
55GraphRG: TRadioGroup;
56Label5: TLabel;
57PointSizeTB: TTrackBar;
58ExtrapolateCB: TCheckBox;
59Label6: TLabel;
60CurveTB: TTrackBar;
61PointUpBtn: TSpeedButton;
62PointDownBtn: TSpeedButton;
63procedure FormShow(Sender: TObject);
64procedure FormDestroy(Sender: TObject);
65procedure EditNameKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
66procedure ParseKeyPress(Sender: TObject; var Key: Char);
67procedure EditNameKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
68procedure AddButtonClick(Sender: TObject);
69procedure IntKeyPress(Sender: TObject; var Key: Char);
70procedure EditPenKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
71procedure EditPenChange(Sender: TObject);
72procedure DeleteButtonClick(Sender: TObject);
73procedure EditXCoordKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
74procedure EditYCoordKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
75procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
76procedure DataListBoxClick(Sender: TObject);
77procedure InputRGClick(Sender: TObject);
78procedure DataListBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
79procedure CloseBitBtnClick(Sender: TObject);
80procedure CheckListBoxClick(Sender: TObject);
81procedure SortCheckBoxClick(Sender: TObject);
82procedure PointsCheckBoxClick(Sender: TObject);
83procedure ColorClick(Sender: TObject);
84procedure ApplyBitBtnClick(Sender: TObject);
85procedure UpButtonClick(Sender: TObject);
86procedure DownButtonClick(Sender: TObject);
87procedure CheckListBoxClickCheck(Sender: TObject);
88procedure CoordsRGClick(Sender: TObject);
89procedure PointColorClick(Sender: TObject);
90procedure ExtrapolateCBClick(Sender: TObject);
91procedure PointSizeTBChange(Sender: TObject);
92procedure PointsRGClick(Sender: TObject);
93procedure GraphRGClick(Sender: TObject);
94procedure CurveTBChange(Sender: TObject);
95procedure EditXCoordEnter(Sender: TObject);
96procedure EditCoordExit(Sender: TObject);
97procedure EditYCoordEnter(Sender: TObject);
98procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
99procedure PointUpBtnClick(Sender: TObject);
100procedure PointDownBtnClick(Sender: TObject);
101private
102xValue, yValue: extended;
103CurrentIndex: integer;
104function DefaultData: TNumericData;
105procedure UpdateNumericDataLists;
106procedure ConfirmDataOrder;
107public
108NumericData: TNumericData;
109procedure ShowData(Sender: TObject);
110procedure ClearCheckListBox;
111procedure UpdateDataListBox;
112end;
113
114var
115NumericForm: TNumericForm;
116
117//=====================================================================
118implementation
119//=====================================================================
120
121uses
122uParser,
123fPlot1D;
124
125{$R *.dfm}
126
127procedure TNumericForm.FormShow(Sender: TObject);
128begin
129Caption := GraphFName;
130if CheckListBox.Count = 0 then NumericData := DefaultData;
131ShowData(Sender);
132end;
133
134procedure TNumericForm.GraphRGClick(Sender: TObject);
135begin
136if Active then
137begin
138case GraphRG.ItemIndex of
1390:GraphRG.Hint := 'Only coordinate points are displayed.';
1401:GraphRG.Hint := 'Lines point to point are displayed.';
1412:GraphRG.Hint := 'Function plotted using the Lagrange interpolation.';
1423:GraphRG.Hint := 'Function plotted using the Hermite interpolation.';
143end;
144with NumericData do
145begin
146NumericStyle := TNumericStyle(GraphRG.ItemIndex);
147with CheckListBox do
148TNumericObject(Items.Objects[ItemIndex]).Data.NumericStyle := NumericStyle;
149end;
150CurveTB.Enabled := GraphRG.ItemIndex = 3;
151Label6.Enabled := CurveTB.Enabled;
152ExtrapolateCB.Enabled := GraphRG.ItemIndex = 2;
153MainForm.GLViewer.Invalidate;
154Altered := True;
155ApplyBitBtn.Visible := False;
156end;
157end;
158
159procedure TNumericForm.ParseKeyPress(Sender: TObject; var Key: Char);
160begin
161with Sender as TEdit do
162begin
163if not CharInSet(UpCase(Key),
164[' ', '!', '(', ')', '*', '+', '-', '.', ',', '/', '0'..'9',
165'A'..'C', 'E', 'G'..'I', 'L', 'N'..'T', 'X', '^', '`', #8]) then
166begin
167Key := #0;
168Exit;
169end;
170if Key = '`' then Key := '�';
171end;
172end;
173
174procedure TNumericForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
175begin
176if (DataListBox.Count = 0) and (CheckListBox.Count > 0)
177then DeleteButtonClick(Sender);
178FunctionsForm.CoordPointButton.Visible := False;
179
180if ApplyBitBtn.Visible then
181begin
182case MessageDlg('The current data has been altered.'+
183#13#10'To save the change press the Apply Change Button.'+
184#13#10'Do you wish to save the alterations ?', mtConfirmation,
185[mbYes, mbNo], 0) of
186mrYes: CanClose := False;
187end;
188end;
189end;
190
191procedure TNumericForm.FormDestroy(Sender: TObject);
192begin
193ClearCheckListBox;
194end;
195
196procedure TNumericForm.FormKeyDown(Sender: TObject; var Key: Word;
197Shift: TShiftState);
198begin
199if not(EditXCoord.Focused or EditYCoord.Focused) then
200case Key of
201VK_ADD: AddButtonClick(Sender);
202VK_SUBTRACT: DeleteButtonclick(Sender);
203end;
204end;
205
206procedure TNumericForm.EditNameKeyUp(Sender: TObject; var Key: Word;
207Shift: TShiftState);
208begin
209with CheckListBox do if Count > 0 then
210begin
211if ItemIndex < 0 then ItemIndex := 0;
212TNumericObject(Items.Objects[ItemIndex]).Data.Name := EditName.Text;
213Items[ItemIndex] := EditName.Text;
214ApplyBitBtn.Visible := True;
215end;
216end;
217
218procedure TNumericForm.EditNameKeyDown(Sender: TObject; var Key: Word;
219Shift: TShiftState);
220begin
221if (Key = VK_DELETE) or (Key = VK_BACK)
222then ApplyBitBtn.Visible := True;
223end;
224
225procedure TNumericForm.EditPenChange(Sender: TObject);
226var
227k: word;
228
229begin
230if Active then
231begin
232k := 0;
233EditPenKeyUp(Sender, k, []);
234end;
235end;
236
237procedure TNumericForm.EditPenKeyUp(Sender: TObject; var Key: Word;
238Shift: TShiftState);
239var
240w: integer;
241
242begin
243if Active then with Sender as TEdit do
244begin
245try
246w := StrToInt(Text);
247except
248w := 1;
249end;
250if w < 1 then w := 1;
251
252NumericData.PlotWidth := w;
253with CheckListBox do if Count > 0 then
254begin
255TNumericObject(Items.Objects[ItemIndex]).Data.PlotWidth := w;
256MainForm.GLViewer.Invalidate;
257Altered := True;
258ApplyBitBtn.Visible := False;
259end;
260end;
261end;
262
263procedure TNumericForm.EditXCoordEnter(Sender: TObject);
264begin
265with MainForm.StatusBar.Panels[2] do
266case CoordsRG.ItemIndex of
2670:case InputRG.ItemIndex of
2680:Text := 'Enter an x Coordinate value then press Enter key.';
2691:Text := 'Enter a value then press Enter key to alter x Coordinate.';
2702:Text := 'Select an item from the coordinates list and press Delete Key.';
271end;
2721:case InputRG.ItemIndex of
2730:Text := 'Enter a value for polar angle ''�'' then press Enter key.';
2741:Text := 'Enter a value then press Enter key to alter ''�''.';
2752:Text := 'Select an item from the coordinates list and press Delete Key.';
276end;
2772:case InputRG.ItemIndex of
2780:Text := 'Enter a length for the vector then press Enter key.';
2791:Text := 'Enter a value then press Enter key to alter the vector length.';
2802:Text := 'Select an item from the coordinates list and press Delete Key.';
281end;
282end;
283end;
284
285procedure TNumericForm.EditCoordExit(Sender: TObject);
286begin
287MainForm.StatusBar.Panels[2].Text := '';
288end;
289
290procedure TNumericForm.EditXCoordKeyUp(Sender: TObject; var Key: Word;
291Shift: TShiftState);
292var
293s: string;
294e: byte;
295
296begin
297if Active and (Key <> 9) then
298begin
299s := ScanText(EditXCoord.Text);
300xValue := ParseAndEvaluate(s, e);
301if isNAN(xValue) or isInfinite(xValue) or (e > 0) then xValue := 0;
302if Key = VK_RETURN then
303case InputRG.ItemIndex of
3040:begin { Adding }
305EditYCoord.SetFocus;
306end;
3071:if DataListBox.Count > 0 then
308begin { Editing }
309UpdateNumericDataLists;
310EditYCoord.SetFocus;
311end;
312end;
313end;
314end;
315
316procedure TNumericForm.EditYCoordEnter(Sender: TObject);
317begin
318with MainForm.StatusBar.Panels[2] do
319case CoordsRG.ItemIndex of
3200:case InputRG.ItemIndex of
3210:Text := 'Enter a y Coordinate value then press Enter key.';
3221:Text := 'Enter a value then press Enter key to alter y Coordinate.';
3232:Text := 'Select an item from the coordinates list and press Delete Key.';
324end;
3251:case InputRG.ItemIndex of
3260:Text := 'Enter a value for the polar radial ''r'' then press Enter key.';
3271:Text := 'Enter a value then press Enter key to alter ''r''.';
3282:Text := 'Select an item from the coordinates list and press Delete Key.';
329end;
3302:case InputRG.ItemIndex of
3310:Text := 'Enter an angle for the vector then press Enter key.';
3321:Text := 'Enter a value then press Enter key to alter the vector angle.';
3332:Text := 'Select an item from the coordinates list and press Delete Key.';
334end;
335end;
336end;
337
338procedure TNumericForm.EditYCoordKeyUp(Sender: TObject; var Key: Word;
339Shift: TShiftState);
340var
341j: integer;
342s: string;
343e: byte;
344
345begin
346if Active and (Key <> 9) then
347begin
348s := ScanText(EditYCoord.Text);
349yValue := ParseAndEvaluate(s, e);
350if isNAN(yValue) or isInfinite(yValue) or (e > 0) then yValue := 0;
351if Key = VK_RETURN then
352begin
353case InputRG.ItemIndex of
3540:begin { Adding }
355UpdateNumericDataLists;
356EditXCoord.SetFocus;
357end;
3581:if DataListBox.Count > 0 then
359begin { Editing }
360j := DataListBox.ItemIndex;
361UpdateNumericDataLists;
362if j < DataListBox.Count -1 then
363begin
364DataListBox.ItemIndex := j +1;
365DataListBox.Selected[DataListbox.ItemIndex] := True;
366DataListBoxClick(Sender);
367end;
368EditXCoord.SetFocus;
369end;
370end;
371end;
372if DataListBox.Count > 0 then
373begin
374MainForm.GLViewer.Invalidate;
375Altered := True;
376ApplyBitBtn.Visible := False;
377end;
378end;
379end;
380
381procedure TNumericForm.ExtrapolateCBClick(Sender: TObject);
382begin
383with NumericData do
384begin
385Extrapolate := ExtrapolateCB.Checked;
386with CheckListBox do
387TNumericObject(Items.Objects[ItemIndex]).Data.Extrapolate := Extrapolate;
388end;
389MainForm.GLViewer.Invalidate;
390Altered := True;
391ApplyBitBtn.Visible := False;
392end;
393
394procedure TNumericForm.InputRGClick(Sender: TObject);
395begin
396if DataListBox.Count > 0 then
397case InputRG.ItemIndex of
3980:begin
399InputRG.Hint := 'Adding: Enter coordinates & press enter.';
400DataListBox.Hint := 'Adding data.';
401DataListBox.MultiSelect := False;
402EditXCoord.Text := '';
403EditYCoord.Text := '';
404SortCheckBox.Enabled := True;
405ConfirmDataOrder;
406end;
4071:begin
408InputRG.Hint := 'Select the item to edit then enter coordinates & press enter.';
409DataListBox.Hint := 'Editing data.';
410DataListBox.MultiSelect := False;
411SortCheckBox.Enabled := False;
412DataListBox.SetFocus;
413DataListBoxClick(Sender);
414MainForm.GLViewer.Invalidate;
415end;
4162:begin
417InputRG.Hint := 'Select the items to delete. Multiple items can be selected.';
418DataListBox.Hint := 'Deleting data: Press ''Del'' to delete. Two items must remain.';
419DataListBox.MultiSelect := True;
420SortCheckBox.Enabled := False;
421DataListBox.SetFocus;
422DataListBoxClick(Sender);
423MainForm.GLViewer.Invalidate;
424end;
425end;
426end;
427
428procedure TNumericForm.IntKeyPress(Sender: TObject; var Key: Char);
429begin
430with Sender as TEdit do
431if not CharInSet(Key, ['0'..'9', #8]) then Key := #0;
432end;
433
434procedure TNumericForm.PointColorClick(Sender: TObject);
435begin
436with NumericData do
437begin
438with CheckListBox do ColorDialog.Color :=
439TNumericObject(Items.Objects[ItemIndex]).Data.PointColor;
440if ColorDialog.Execute then
441begin
442NumericData.PointColor := ColorDialog.Color;
443with CheckListBox do
444TNumericObject(Items.Objects[ItemIndex]).Data.PointColor :=
445ColorDialog.Color;
446PointPanel.Color := ColorDialog.Color;
447MainForm.GLViewer.Invalidate;
448Altered := True;
449ApplyBitBtn.Visible := False;
450end;
451end;
452end;
453
454procedure TNumericForm.PointDownBtnClick(Sender: TObject);
455var
456i: integer;
457
458begin
459with DataListBox do
460begin
461i := ItemIndex;
462if i < Count -1 then Items.Move(i, i+1);
463ItemIndex := i+1;
464end;
465with CheckListBox do if i < DataListBox.Count -1
466then TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Move(i, i+1);
467
468MainForm.GLViewer.Invalidate;
469Altered := True;
470end;
471
472procedure TNumericForm.PointsCheckBoxClick(Sender: TObject);
473begin
474if Active and (CheckListBox.Count > 0) then
475begin
476NumericData.ShowPoints := PointsCheckBox.Checked;
477with CheckListBox do
478TNumericObject(Items.Objects[ItemIndex]).Data.ShowPoints :=
479PointsCheckBox.Checked;
480MainForm.GLViewer.Invalidate;
481Altered := True;
482ApplyBitBtn.Visible := False;
483end;
484end;
485
486procedure TNumericForm.PointSizeTBChange(Sender: TObject);
487begin
488if Active then with NumericData do
489begin
490PointSize := PointSizeTB.Position;
491with CheckListBox do
492TNumericObject(Items.Objects[ItemIndex]).Data.PointSize := PointSize;
493end;
494MainForm.GLViewer.Invalidate;
495Altered := True;
496ApplyBitBtn.Visible := False;
497end;
498
499procedure TNumericForm.PointsRGClick(Sender: TObject);
500begin
501with NumericData do
502begin
503PointStyle := TPointStyle(PointsRG.ItemIndex);
504with CheckListBox do
505TNumericObject(Items.Objects[ItemIndex]).Data.PointStyle := PointStyle;
506end;
507MainForm.GLViewer.Invalidate;
508Altered := True;
509ApplyBitBtn.Visible := False;
510end;
511
512procedure TNumericForm.PointUpBtnClick(Sender: TObject);
513var
514i: integer;
515
516begin
517with DataListBox do
518begin
519i := ItemIndex;
520if i > 0 then Items.Move(i, i-1);
521if i > 1 then ItemIndex := i-1 else ItemIndex := 0;
522end;
523with CheckListBox do if i > 0
524then TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Move(i, i-1);
525
526MainForm.GLViewer.Invalidate;
527Altered := True;
528end;
529
530procedure TNumericForm.CoordsRGClick(Sender: TObject);
531begin
532if Active and (CheckListBox.Count > 0) then
533begin
534case CoordsRG.ItemIndex of
5350:begin
536Label2.Caption := 'Plot Cartesian Coordinates {x, y}';
537end;
5381:begin
539Label2.Caption := 'Plot Polar Coordinates {�, r}';
540end;
5412:begin
542Label2.Caption := 'Enter a vector {length, angle}';
543end;
544end;
545DataListBoxClick(Sender);
546NumericData.CoordsIdx := CoordsRG.ItemIndex;
547with CheckListBox do
548TNumericObject(Items.Objects[ItemIndex]).Data.CoordsIdx :=
549NumericData.CoordsIdx;
550MainForm.GLViewer.Invalidate;
551Altered := True;
552ApplyBitBtn.Visible := False;
553end;
554end;
555
556procedure TNumericForm.ShowData(Sender: TObject);
557var
558a, b: Boolean;
559
560begin
561a := Altered;
562with CheckListBox do
563begin
564b := Count > 0;
565if b and (ItemIndex < 0) then ItemIndex := Count -1;
566end;
567DeleteButton.Enabled := b;
568UpButton.Enabled := b and (CheckListBox.Count > 1);
569DownButton.Enabled := b and (CheckListBox.Count > 1);
570DataListBox.Enabled := b;
571Label1.Enabled := b;
572Label4.Enabled := b;
573EditName.Enabled := b;
574Label3.Enabled := b;
575PointSpeedButton.Enabled := b;
576EditPen.Enabled := b;
577PenUpDown.Enabled := b;
578PenSpeedButton.Enabled := b;
579PointPanel.Enabled := b;
580PenPanel.Enabled := b;
581PointsCheckBox.Enabled := b;
582Label2.Enabled := b;
583EditXCoord.Enabled := b;
584EditYCoord.Enabled := b;
585SortCheckBox.Enabled := b;
586PointUpBtn.Enabled := not SortCheckBox.Checked;
587PointDownBtn.Enabled := not SortCheckBox.Checked;
588InputRG.Enabled := b;
589PointsRG.Enabled := b;
590GraphRG.Enabled := b;
591CoordsRG.Enabled := b;
592Label5.Enabled := b;
593PointSizeTB.Enabled := b;
594Label6.Enabled := b and (GraphRG.ItemIndex = 3);
595CurveTB.Enabled := b and (GraphRG.ItemIndex = 3);
596ExtrapolateCB.Enabled := b and (GraphRG.ItemIndex = 2);
597if b then
598begin
599// ConfirmDataOrder;??????
600SortCheckBox.Checked := NumericData.SortXValue;
601PointsCheckBox.Checked := NumericData.ShowPoints;
602EditPen.Text := IntToStr(NumericData.PlotWidth);
603PenPanel.Color := NumericData.PlotColor;
604EditName.Text := NumericData.Name;
605CoordsRG.ItemIndex := NumericData.CoordsIdx;
606PointsRG.ItemIndex := Ord(NumericData.PointStyle);
607PointSizeTB.Position := NumericData.PointSize;
608PointPanel.Color := NumericData.PointColor;
609GraphRG.ItemIndex := Ord(NumericData.NumericStyle);
610CurveTB.Position := NumericData.CurveRate;
611Label6.Caption := 'Curve Rate '+IntToStr(CurveTB.Position);
612ExtrapolateCB.Checked := NumericData.Extrapolate;
613end
614else DataListBox.Clear;
615Altered := a;
616end;
617
618procedure TNumericForm.SortCheckBoxClick(Sender: TObject);
619begin
620PointUpBtn.Enabled := not SortCheckBox.Checked;
621PointDownBtn.Enabled := not SortCheckBox.Checked;
622if Active then with CheckListBox do if Count > 0 then
623begin
624TNumericObject(Items.Objects[ItemIndex]).Data.SortXValue := SortCheckBox.Checked;
625NumericData.SortXValue := SortCheckBox.Checked;
626ApplyBitBtn.Visible := DataListBox.Count > 0;
627if SortCheckBox.Checked then ConfirmDataOrder;
628end;
629end;
630
631procedure TNumericForm.AddButtonClick(Sender: TObject);
632begin
633with CheckListBox do
634begin
635if Count = 0 then NumericData := DefaultData
636else NumericData := TNumericObject(Items.Objects[ItemIndex]).Data;
637AddItem(NumericData.Name, TNumericObject.Create(NumericData));
638ItemIndex := Count -1;
639Checked[ItemIndex] := True;
640DataListBox.Clear;
641CurrentIndex := ItemIndex;
642end;
643Altered := True;
644ShowData(Sender);
645InputRG.ItemIndex := 0;
646EditXCoord.SetFocus;
647ApplyBitBtn.Visible := True;
648end;
649
650procedure TNumericForm.DataListBoxClick(Sender: TObject);
651procedure PointToVector(x1, y1, x2, y2: extended; var l, a: extended);
652var
653dx, dy: extended;
654
655begin
656dx := x2 - x1;
657dy := y2 - y1;
658l := Sqrt(dx*dx + dy*dy);
659a := ArcTan(dy/dx);
660end;
661
662var
663j: integer;
664l, a: extended;
665x, y: extended;
666
667begin
668if InputRG.ItemIndex > 0 then
669begin { Editing or Deleting }
670j := DataListBox.ItemIndex;
671with CheckListBox, TGraphPointObject(
672TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j]) do
673begin
674xValue := x_phi;
675yValue := y_r;
676
677case CoordsRG.ItemIndex of
6780:begin { Cartesian option }
679EditXCoord.Text := FloatToStr(xValue);
680EditYCoord.Text := FloatToStr(yValue);
681end;
6821:begin { Polar option }
683EditXCoord.Text := FloatToStrF(RadToDeg(xValue), ffNumber, 7, 5)+'�';
684EditYCoord.Text := FloatToStr(yValue);
685end;
6862:begin { As a Vector option }
687l := 0;
688a := 0;
689if j > 0 then //PointToVector(0, 0, xValue, yValue, l, a)
690begin
691with CheckListBox, TGraphPointObject(
692TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j -1]) do
693begin
694x := x_phi;
695y := y_r;
696end;
697PointToVector(x, y, xValue, yValue, l, a);
698end;
699EditXCoord.Text := FloatToStr(l);
700EditYCoord.Text := FloatToStrF(RadToDeg(a), ffNumber, 7, 5)+'�';
701end;
702end;
703end;
704MainForm.GLViewer.Invalidate;
705end;
706end;
707
708procedure TNumericForm.DataListBoxKeyDown(Sender: TObject; var Key: Word;
709Shift: TShiftState);
710var
711j, k: integer;
712
713begin
714if (DataListBox.Count > 2) and (Key = VK_DELETE) then
715begin
716j := DataListBox.ItemIndex; { free ControlPoint[j] }
717k := CheckListBox.ItemIndex;
718with CheckListBox, TGraphPointObject(
719TNumericObject(Items.Objects[k]).ControlPoints[j]) do Free;
720UpdateNumericDataLists;
721DataListBox.Selected[DataListBox.ItemIndex] := True;
722ApplyBitBtn.Visible := DataListBox.Count > 0;
723end;
724end;
725
726function TNumericForm.DefaultData: TNumericData;
727begin
728with Result do
729begin
730Name := 'Numeric Plot';
731NumericStyle := nsLinear;
732ShowPoints := True;
733PointStyle := psSquare;
734PointSize := 1; { }
735PointColor := ClBlack; { }
736PlotWidth := 1; { pen width for plot }
737PlotColor := ClBlack; { pen color for plot }
738SortXValue := True; { x values sorted if true }
739Extrapolate := False; { extrapolate graph if true }
740CoordsIdx := 0; { enter coords as x, y or phi, r or vector }
741CurveRate := 5; { was k0 = 0.5; CurveRate/100 }
742end;
743end;
744
745procedure TNumericForm.ApplyBitBtnClick(Sender: TObject);
746begin
747if EditXCoord.Focused or EditYCoord.Focused then Exit;
748
749if (DataListBox.Count = 0) and (CheckListBox.Count > 0)
750then DeleteButtonClick(Sender);
751
752MainForm.GLViewer.Invalidate;
753Altered := True;
754ApplyBitBtn.Visible := False;
755end;
756
757procedure TNumericForm.CheckListBoxClick(Sender: TObject);
758begin
759if Active then
760begin
761UpdateDataListBox;
762ShowData(Sender);
763end;
764end;
765
766procedure TNumericForm.CheckListBoxClickCheck(Sender: TObject);
767begin
768MainForm.GLViewer.Invalidate;
769Altered := True;
770ApplyBitBtn.Visible := False;
771end;
772
773procedure TNumericForm.ClearCheckListBox;
774var
775i: integer;
776
777begin
778with CheckListBox do
779begin
780for i := 0 to Count -1 do Items.Objects[i].Free;
781Clear;
782end;
783end;
784
785procedure TNumericForm.CloseBitBtnClick(Sender: TObject);
786begin
787Close;
788end;
789
790procedure TNumericForm.ColorClick(Sender: TObject);
791begin
792with NumericData do
793begin
794with CheckListBox do ColorDialog.Color :=
795TNumericObject(Items.Objects[ItemIndex]).Data.PlotColor;
796if ColorDialog.Execute then
797begin
798NumericData.PlotColor := ColorDialog.Color;
799with CheckListBox do
800TNumericObject(Items.Objects[ItemIndex]).Data.PlotColor :=
801ColorDialog.Color;
802PenPanel.Color := ColorDialog.Color;
803MainForm.GLViewer.Invalidate;
804Altered := True;
805ApplyBitBtn.Visible := False;
806end;
807end;
808end;
809
810procedure TNumericForm.CurveTBChange(Sender: TObject);
811begin
812if Active then
813begin
814with NumericData do
815begin
816CurveRate := CurveTB.Position;
817Label6.Caption := 'Curve Rate '+IntToStr(CurveTB.Position);
818with CheckListBox do
819TNumericObject(Items.Objects[ItemIndex]).Data.CurveRate := CurveRate;
820end;
821MainForm.GLViewer.Invalidate;
822Altered := True;
823ApplyBitBtn.Visible := False;
824end;
825end;
826
827procedure TNumericForm.UpdateNumericDataLists;
828function InsertValuesAt: integer;
829var
830i: integer;
831
832begin
833Result := -1;
834with CheckListBox do
835if TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Count > 0 then
836begin
837if xValue < TGraphPointObject(
838TNumericObject(Items.Objects[ItemIndex]).ControlPoints[0]).x_phi
839then Result := 0
840else
841begin
842i := TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Count -1;
843if xValue < TGraphPointObject(
844TNumericObject(Items.Objects[ItemIndex]).ControlPoints[i]).x_phi then
845begin
846while (i > 0) and (xValue < TgraphPointObject(
847TNumericObject(Items.Objects[ItemIndex]).ControlPoints[i]).x_phi)
848do Dec(i);
849Result := i +1;
850end;
851end;
852end;
853end;
854
855var
856s: string;
857j: integer;
858e: byte;
859x: extended;
860y: extended;
861
862begin
863if CoordsRG.ItemIndex = 2 then { As a Vector option }
864begin
865s := ScanText(EditXCoord.Text);
866xValue := ParseAndEvaluate(s, e);
867// if isNAN(xValue) then xValue := 0;
868// if e > 0 then xValue := 0;
869if isNAN(xValue) or isInfinite(xValue) or (e > 0) then xValue := 0;
870x := xValue*Cos(yValue);
871y := xValue*Sin(yValue);
872j := DataListBox.Count;
873
874if j > 0 then with CheckListBox, TGraphPointObject(
875TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j -1]) do
876begin
877x := x + x_phi;
878y := y + y_r;
879end;
880xValue := x;
881yValue := y;
882end;
883
884case InputRG.ItemIndex of
8850:begin { Adding }
886if SortCheckBox.Checked then j := InsertValuesAt else j := -1;
887if j > -1 then
888begin { insert added data }
889DataListBox.Items.Insert(j, Format('%18s,%18s', [FloatToStr(xValue),
890FloatToStr(yValue)]));
891with CheckListBox do
892TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Insert(j,
893TgraphPointObject.Create(xValue, yValue));
894end
895else
896begin { append added data}
897DataListBox.Items.Add(Format('%18s,%18s', [FloatToStr(xValue),
898FloatToStr(yValue)]));
899with CheckListBox do
900TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Add(
901TGraphPointObject.Create(xValue, yValue));
902j := DataListBox.Count -1;
903end;
904DataListBox.ItemIndex := j;
905DataListBox.Selected[j] := True;
906end;
9071:begin { Editing }
908j := DataListBox.ItemIndex;
909if CoordsRG.ItemIndex = 2 then
910begin
911end
912else DataListBox.Items[j] := Format('%18s,%18s', [FloatToStr(xValue),
913FloatToStr(yValue)]);
914with CheckListBox, TGraphPointObject(
915TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j]) do
916begin
917x_phi := xValue;
918y_r := yValue;
919end;
920end;
9212:with DataListBox do if SelCount > 0 then
922begin { Deleting }
923j := 0;
924while (j < Count) and (Count > 2) do
925begin
926if Selected[j] then
927begin
928with CheckListBox do
929TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Delete(j);
930Items.Delete(j);
931end
932else Inc(j);
933end;
934MainForm.GLViewer.Invalidate;
935Altered := True;
936ApplyBitBtn.Visible := False;
937end;
938end;
939end;
940
941procedure TNumericForm.UpButtonClick(Sender: TObject);
942var
943i: integer;
944
945begin
946with CheckListBox do
947begin
948i := ItemIndex;
949if i > 0 then Items.Move(i, i-1);
950if i > 1 then ItemIndex := i-1 else ItemIndex := 0;
951end;
952CheckListBoxClick(Sender);
953end;
954
955procedure TNumericForm.UpdateDataListBox;
956var
957j: integer;
958p: TGraphPointObject;
959
960begin
961if Active then
962begin
963if CheckListBox.Count > 0 then
964begin
965DataListBox.Clear;
966with CheckListBox do
967begin
968NumericData := TNumericObject(Items.Objects[ItemIndex]).Data;
969CurrentIndex := ItemIndex;
970for j := 0 to TNumericObject(
971Items.Objects[ItemIndex]).ControlPoints.Count -1 do
972begin
973p := TNumericObject(Items.Objects[ItemIndex]).ControlPoints[j];
974DataListBox.Items.Add(Format('%18s,%18s', [FloatToStr(p.x_phi),
975FloatToStr(p.y_r)]));
976end;
977end;
978with DataListBox do if Count > 0 then
979begin
980ItemIndex := Count -1;
981Selected[ItemIndex] := True;
982end;
983
984if InputRG.ItemIndex = 0 then
985begin
986EditXCoord.Text := '';
987EditYCoord.Text := '';
988end
989else DataListBoxClick(Self);
990ShowData(Self);
991end;
992end;
993end;
994
995procedure TNumericForm.DeleteButtonClick(Sender: TObject);
996var
997i: integer;
998
999begin
1000if CheckListBox.Count > 0 then
1001begin
1002with CheckListBox do
1003begin
1004i := ItemIndex;
1005with Items.Objects[i] as TNumericObject do Free;
1006Items.Delete(i);
1007if i > Count -1 then i := Count -1;
1008ItemIndex := i;
1009DeleteButton.Enabled := Count > 0;
1010end;
1011end;
1012Altered := True;
1013ApplyBitBtn.Visible := True;
1014if CheckListBox.Count > 0 then CheckListBoxClick(Sender);
1015if CheckListBox.Count < 2 then ShowData(Sender);
1016end;
1017
1018procedure TNumericForm.DownButtonClick(Sender: TObject);
1019var
1020i: integer;
1021
1022begin
1023with CheckListBox do
1024begin
1025i := ItemIndex;
1026if i < Count -1 then Items.Move(i, i+1);
1027ItemIndex := i+1;
1028end;
1029CheckListBoxClick(Sender);
1030end;
1031
1032procedure TNumericForm.ConfirmDataOrder;
1033var
1034x, y: extended;
1035
1036function InsertValuesAt: integer;
1037var
1038i: integer;
1039
1040begin
1041Result := -1;
1042with CheckListBox do
1043if TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Count > 0 then
1044begin
1045if x < TGraphPointObject(
1046TNumericObject(Items.Objects[ItemIndex]).ControlPoints[0]).x_phi
1047then Result := 0
1048else
1049begin
1050i := TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Count -1;
1051if x < TGraphPointObject(
1052TNumericObject(Items.Objects[ItemIndex]).ControlPoints[i]).x_phi then
1053begin
1054while (i > 0) and (x < TgraphPointObject(
1055TNumericObject(Items.Objects[ItemIndex]).ControlPoints[i]).x_phi)
1056do Dec(i);
1057Result := i +1;
1058end;
1059end;
1060end;
1061end;
1062
1063var
1064i, j: integer;
1065IsOrdered: Boolean;
1066Temp: TList; { list of TGraphPointObject }
1067
1068begin
1069if SortCheckBox.Checked and (DataListBox.Count > 1) then
1070with CheckListBox do if Count > 0 then
1071with TNumericObject(Items.Objects[ItemIndex]) do
1072begin
1073IsOrdered := ControlPoints.Count > 1;
1074i := 1;
1075while IsOrdered and (i < ControlPoints.Count) do
1076begin
1077IsOrdered := (TGraphPointObject(ControlPoints[i]).x_phi >
1078TGraphPointObject(ControlPoints[i -1]).x_phi);
1079Inc(i);
1080end;
1081if not IsOrdered and (MessageDlg('The current data is not sorted!'+
1082#13#10'Should the data be sorted?',
1083mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
1084begin
1085Temp := TList.Create;
1086try
1087Temp.Assign(ControlPoints);
1088ControlPoints.Clear;
1089DataListBox.Clear;
1090x := TGraphPointObject(Temp[0]).x_phi;
1091y := TGraphPointObject(Temp[0]).y_r;
1092DataListBox.Items.Add(Format('%18s,%18s', [FloatToStr(x), FloatToStr(y)]));
1093ControlPoints.Add(TGraphPointObject.Create(x, y));
1094j := InsertValuesAt;
1095for i := 1 to Temp.Count -1 do
1096begin
1097x := TGraphPointObject(Temp[i]).x_phi;
1098y := TGraphPointObject(Temp[i]).y_r;
1099j := InsertValuesAt;
1100if j > -1 then
1101begin { insert added data }
1102DataListBox.Items.Insert(j, Format('%18s,%18s', [FloatToStr(x),
1103FloatToStr(y)]));
1104with CheckListBox do
1105TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Insert(j,
1106TGraphPointObject.Create(x, y));
1107end
1108else
1109begin { append added data}
1110DataListBox.Items.Add(Format('%18s,%18s', [FloatToStr(x),
1111FloatToStr(y)]));
1112with CheckListBox do
1113TNumericObject(Items.Objects[ItemIndex]).ControlPoints.Add(
1114TGraphPointObject.Create(x, y));
1115j := DataListBox.Count -1;
1116end;
1117end;
1118DataListBox.ItemIndex := j;
1119DataListBox.Selected[j] := True;
1120finally
1121for i := 0 to Temp.Count -1 do TObject(Temp.Items[i]).Free;
1122Temp.Free;
1123MainForm.GLViewer.Invalidate;
1124Altered := True;
1125ApplyBitBtn.Visible := False;
1126end;
1127end;
1128end;
1129end;
1130
1131end.
1132