MathgeomGLS
677 строк · 16.6 Кб
1unit fGridOpts;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.UITypes,
9System.SysUtils,
10System.Variants,
11System.Classes,
12System.Math,
13Vcl.Graphics,
14Vcl.Controls,
15Vcl.Forms,
16Vcl.Dialogs,
17Vcl.StdCtrls,
18Vcl.ExtCtrls,
19Vcl.Buttons,
20Vcl.ComCtrls,
21Vcl.Menus,
22
23uParser,
24uGlobal;
25
26type
27TGridOptionsForm = class(TForm)
28Label1: TLabel;
29Label2: TLabel;
30Label3: TLabel;
31Label4: TLabel;
32Label5: TLabel;
33Label6: TLabel;
34Label7: TLabel;
35Label8: TLabel;
36Label9: TLabel;
37Label10: TLabel;
38
39EditMinY: TEdit;
40EditMinX: TEdit;
41EditMaxX: TEdit;
42EditMaxY: TEdit;
43
44SpeedButton1: TSpeedButton;
45SpeedButton2: TSpeedButton;
46SpeedButton3: TSpeedButton;
47SpeedButton4: TSpeedButton;
48SpeedButton5: TSpeedButton;
49SpeedButton6: TSpeedButton;
50SpeedButton7: TSpeedButton;
51SpeedButton8: TSpeedButton;
52
53EditAxesPen: TEdit;
54UpDown1: TUpDown;
55EditMajorGrid: TEdit;
56UpDown2: TUpDown;
57EditMinorGrid: TEdit;
58UpDown3: TUpDown;
59
60GridStyles: TRadioGroup;
61xTrackBar: TTrackBar;
62yTrackBar: TTrackBar;
63
64BitBtn1: TBitBtn;
65ApplyBitBtn: TBitBtn;
66ColorDialog: TColorDialog;
67FontDialog: TFontDialog;
68LogXCheck: TCheckBox;
69LogYCheck: TCheckBox;
70SaveSpeedButton: TSpeedButton;
71RestoreSpeedButton: TSpeedButton;
72procedure FormShow(Sender: TObject);
73procedure BitBtn1Click(Sender: TObject);
74procedure ApplyBitBtnClick(Sender: TObject);
75
76procedure EditMinXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
77procedure EditMaxXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
78procedure EditMinYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
79procedure EditMaxYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
80procedure EditPenKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
81procedure EditPenChange(Sender: TObject);
82
83procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
84
85procedure ParseKeyPress(Sender: TObject; var Key: Char);
86procedure IntKeyPress(Sender: TObject; var Key: Char);
87
88procedure GridStylesClick(Sender: TObject);
89procedure ColorClick(Sender: TObject);
90procedure FontClick(Sender: TObject);
91procedure LogXCheckClick(Sender: TObject);
92procedure LogYCheckClick(Sender: TObject);
93
94procedure Centre(Sender: TObject);
95procedure EqualGrad(Sender: TObject);
96procedure EqualRange(Sender: TObject);
97procedure xTrackBarChange(Sender: TObject);
98procedure yTrackBarChange(Sender: TObject);
99procedure SaveSpeedButtonClick(Sender: TObject);
100procedure RestoreSpeedButtonClick(Sender: TObject);
101private
102
103function AnyPolar: Boolean;
104public
105
106procedure ShowData;
107end;
108
109var
110GridOptionsForm: TGridOptionsForm;
111
112//========================================================================
113implementation
114//========================================================================
115
116uses
117fPlot1D,
118fTextBlocks,
119fFuncts;
120
121{$R *.dfm}
122
123procedure TGridOptionsForm.FormShow(Sender: TObject);
124begin
125Caption := GraphFName;
126ShowData;
127end;
128
129procedure TGridOptionsForm.BitBtn1Click(Sender: TObject);
130begin
131Close;
132end;
133
134procedure TGridOptionsForm.ApplyBitBtnClick(Sender: TObject);
135procedure Swap(var n1, n2: extended);
136var
137n: extended;
138
139begin
140n := n1;
141n1 := n2;
142n2 := n;
143end;
144
145begin
146with GraphData do
147begin
148if xMin = xMax then xMax := 1.1*xMin;
149if yMin = yMax then yMax := 1.1*yMin;
150if xMin > xMax then Swap(xMin, xMax);
151if yMin > yMax then Swap(yMin, yMax);
152end;
153
154Altered := True;
155MainForm.GLViewer.Invalidate;
156ApplyBitBtn.Visible := False;
157end;
158
159procedure TGridOptionsForm.EditMinXKeyUp(Sender: TObject; var Key: Word;
160Shift: TShiftState);
161var
162x: extended;
163s: string;
164e: byte;
165
166begin
167with GraphData do
168begin
169s := ScanText(EditMinX.Text);
170x := ParseAndEvaluate(s, e);
171if isNAN(x) or isInfinite(x) then x := 0;
172if (e = 0) and((Grid.xAxisStyle <> asLog) or (x > 0)) then xMin := x
173else if Grid.xAxisStyle = asLog then xMin := 0.1 else xMin := -0.1;
174end;
175end;
176
177procedure TGridOptionsForm.EditMinYKeyUp(Sender: TObject; var Key: Word;
178Shift: TShiftState);
179var
180y: extended;
181s: string;
182e: byte;
183
184begin
185with GraphData do
186begin
187s := ScanText(EditMinY.Text);
188y := ParseAndEvaluate(s, e);
189if isNAN(y) or isInfinite(y) then y := 0;
190if (e = 0) and((Grid.yAxisStyle <> asLog) or (y > 0)) then yMin := y
191else if Grid.yAxisStyle = asLog then yMin := 0.1 else yMin := -0.1;
192end;
193end;
194
195procedure TGridOptionsForm.EditMaxXKeyUp(Sender: TObject; var Key: Word;
196Shift: TShiftState);
197var
198x: extended;
199s: string;
200e: byte;
201
202begin
203with GraphData do
204begin
205s := ScanText(EditMaxX.Text);
206x := ParseAndEvaluate(s, e);
207if isNAN(x) or isInfinite(x) then x := 0;
208if (e = 0) and((Grid.xAxisStyle <> asLog) or (x > 0)) then xMax := x
209else xMax := 0.1;
210end;
211end;
212
213procedure TGridOptionsForm.EditMaxYKeyUp(Sender: TObject; var Key: Word;
214Shift: TShiftState);
215var
216y: extended;
217s: string;
218e: byte;
219
220begin
221with GraphData do
222begin
223s := ScanText(EditMaxY.Text);
224y := ParseAndEvaluate(s, e);
225if isNAN(y) or isInfinite(y) then y := 0;
226if (e = 0) and((Grid.yAxisStyle <> asLog) or (y > 0)) then yMax := y
227else yMax := 0.1;
228end;
229end;
230
231procedure TGridOptionsForm.EditPenKeyUp(Sender: TObject; var Key: Word;
232Shift: TShiftState);
233var
234w: integer;
235
236begin
237if Active then
238with Sender as TEdit do
239begin
240try
241w := StrToInt(Text);
242except
243w := 1;
244end;
245if w < 1 then w := 1;
246
247with GraphData do
248case Tag of
2490:AxisWidth := w;
2501:MajorWidth := w;
2512:MinorWidth := w;
252end;
253Altered := True;
254MainForm.GLViewer.Invalidate;
255end;
256end;
257
258procedure TGridOptionsForm.EditPenChange(Sender: TObject);
259var
260k: word;
261
262begin
263k := 0;
264EditPenKeyUp(Sender, k, []);
265end;
266
267procedure TGridOptionsForm.EditKeyDown(Sender: TObject; var Key: Word;
268Shift: TShiftState);
269begin
270if Active and ((Key = VK_DELETE) or (Key = VK_BACK))
271then ApplyBitBtn.Visible := True;
272end;
273
274procedure TGridOptionsForm.ParseKeyPress(Sender: TObject; var Key: Char);
275begin
276with Sender as TEdit do
277begin
278if not CharInSet(UpCase(Key),
279[' ', '!', '(', ')', '*', '+', '-', '.', ',', '/', '0'..'9',
280'A'..'C', 'E', 'G'..'I', 'L', 'N'..'T', 'X', '^', '`', #8]) then
281begin
282Key := #0;
283Exit;
284end
285else if Active then ApplyBitBtn.Visible := True;
286if Key = '`' then Key := '�';
287end;
288end;
289
290procedure TGridOptionsForm.IntKeyPress(Sender: TObject; var Key: Char);
291begin
292with Sender as TEdit do
293if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
294end;
295
296procedure TGridOptionsForm.xTrackBarChange(Sender: TObject);
297begin
298if Active then with GraphData do
299begin
300if xTrackBar.Position > 10
301then xMinorGrad := 10*(xTrackBar.Position - 10)
302else xMinorGrad := xTrackBar.Position;
303xMajorGrad := 10*xMinorGrad;
304Altered := True;
305MainForm.GLViewer.Invalidate;
306end;
307end;
308
309procedure TGridOptionsForm.yTrackBarChange(Sender: TObject);
310begin
311if Active then with GraphData do
312begin
313if yTrackBar.Position > 10
314then yMinorGrad := 10*(yTrackBar.Position - 10)
315else yMinorGrad := yTrackBar.Position;
316yMajorGrad := 10*yMinorGrad;
317Altered := True;
318MainForm.GLViewer.Invalidate;
319end;
320end;
321
322procedure TGridOptionsForm.GridStylesClick(Sender: TObject);
323begin
324if Active then
325begin
326with GridStyles, GraphData do Grid.GridStyle := TGridStyle(ItemIndex);
327Altered := True;
328MainForm.GLViewer.Invalidate;
329end;
330end;
331
332procedure TGridOptionsForm.ColorClick(Sender: TObject);
333begin
334with GraphData do
335begin
336case TSpeedButton(Sender).Tag of
3370:ColorDialog.Color := BackColor;
3381:ColorDialog.Color := GridColor;
3392:ColorDialog.Color := xAxisColor;
3403:ColorDialog.Color := yAxisColor;
341end;
342if ColorDialog.Execute then
343begin
344case TSpeedButton(Sender).Tag of
3450:begin
346BackColor := ColorDialog.Color;
347MainForm.GLViewer.Buffer.BackgroundColor := BackColor;
348with TextBlocksForm
349do if BlockListBox.Count > 0 then RichEdit.Color := BackColor;
350end;
3511:GridColor := ColorDialog.Color;
3522:xAxisColor := ColorDialog.Color;
3533:yAxisColor := ColorDialog.Color;
354end;
355Altered := True;
356MainForm.GLViewer.Invalidate;
357end;
358end;
359end;
360
361procedure TGridOptionsForm.FontClick(Sender: TObject);
362begin
363with FontDialog, GraphData do
364begin
365case TSpeedButton(Sender).Tag of
3660:begin
367Font.Name := FontName;
368Font.Style := FontStyle;
369Font.Size := FontSize;
370end;
371end;
372if Execute then
373begin
374case TSpeedButton(Sender).Tag of
3750:begin
376FontName := Font.Name;
377FontStyle := Font.Style;
378FontSize := Font.Size;
379end;
380end;
381Altered := True;
382NewFont := True;
383MainForm.GLViewer.Invalidate;
384end;
385end;
386end;
387
388procedure TGridOptionsForm.LogXCheckClick(Sender: TObject);
389var
390d: extended;
391
392begin
393if AnyPolar then { can not use log axes }
394begin
395LogXCheck.Checked := False;
396MainForm.StatusBar.Panels[2].Text := 'One or more Functions are Polar';
397end
398else
399begin
400with GraphData do
401begin
402if LogXCheck.Checked then
403begin
404with FunctionsForm do
405begin
406if Integrate2x.Checked then CloseIntegrateXForm;
407if Integrate2y.Checked then CloseIntegrateYForm;
408if Between1.Checked then CloseBetweenForm;
409if Volumex1.Checked then CloseVolumeXForm;
410if Volumey1.Checked then CloseVolumeYForm;
411end;
412
413Grid.xAxisStyle := asLog;
414if xMin <= 0 then { xMin must be +ve }
415begin
416d := xMax - xMin;
417xMin := (xMax - xMin)/MainForm.GLViewer.Width;
418xMax := xMin + d;
419EditMinX.Text := FloatToStr(xMin);
420EditMaxX.Text := FloatToStr(xMax);
421end;
422end
423else Grid.xAxisStyle := asLinear;
424
425SpeedButton6.Enabled := (Grid.xAxisStyle = asLinear) and
426(Grid.yAxisStyle = asLinear);
427SpeedButton7.Enabled := SpeedButton6.Enabled or
428((Grid.xAxisStyle = asLog) and
429(Grid.yAxisStyle = asLog));
430SpeedButton8.Enabled := SpeedButton6.Enabled or
431((Grid.xAxisStyle = asLog) and
432(Grid.yAxisStyle = asLog));
433
434with FunctionsForm do
435begin
436SwitchButton.Visible := SpeedButton6.Enabled;
437Integrate1.Enabled := SpeedButton6.Enabled;
438end;
439end;
440Altered := True;
441MainForm.GLViewer.Invalidate;
442end;
443end;
444
445procedure TGridOptionsForm.LogYCheckClick(Sender: TObject);
446var
447d: extended;
448
449begin
450if AnyPolar then { can not use log axes }
451begin
452LogYCheck.Checked := False;
453MainForm.StatusBar.Panels[2].Text := 'One or more Functions are Polar';
454end
455else
456begin
457with GraphData do
458begin
459if LogYCheck.Checked then
460begin
461with FunctionsForm do
462begin
463if Integrate2x.Checked then CloseIntegrateXForm;
464if Integrate2y.Checked then CloseIntegrateYForm;
465if Between1.Checked then CloseBetweenForm;
466if Volumex1.Checked then CloseVolumeXForm;
467if Volumey1.Checked then CloseVolumeYForm;
468end;
469
470Grid.yAxisStyle := asLog;
471if yMin <= 0 then { yMin must be +ve }
472begin
473d := yMax - yMin;
474yMin := (yMax - yMin)/MainForm.GLViewer.Height;
475yMax := yMin + d;
476EditMinY.Text := FloatToStr(yMin);
477EditMaxY.Text := FloatToStr(yMax);
478end;
479end
480else Grid.yAxisStyle := asLinear;
481
482SpeedButton6.Enabled := (Grid.xAxisStyle = asLinear) and
483(Grid.yAxisStyle = asLinear);
484SpeedButton7.Enabled := SpeedButton6.Enabled or
485((Grid.xAxisStyle = asLog) and
486(Grid.yAxisStyle = asLog));
487SpeedButton8.Enabled := SpeedButton6.Enabled or
488((Grid.xAxisStyle = asLog) and
489(Grid.yAxisStyle = asLog));
490
491with FunctionsForm do
492begin
493SwitchButton.Visible := SpeedButton6.Enabled;
494Integrate1.Enabled := SpeedButton6.Enabled;
495end;
496end;
497Altered := True;
498MainForm.GLViewer.Invalidate;
499end;
500end;
501
502procedure TGridOptionsForm.RestoreSpeedButtonClick(Sender: TObject);
503begin
504with GraphData do
505begin
506if (SavexMin > 0) or (Grid.xAxisStyle = asLinear)
507then xMin := SavexMin;
508xMax := SavexMax;
509if (SaveyMin > 0) or (Grid.yAxisStyle = asLinear)
510then yMin := SaveyMin;
511yMax := SaveyMax;
512
513EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
514EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
515EditMinY.Text := FloatToStrF(yMin, ffGeneral, 13, 4);
516EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 13, 4);
517end;
518Altered := True;
519MainForm.GLViewer.Invalidate;
520end;
521
522procedure TGridOptionsForm.Centre(Sender: TObject);
523var
524x, y: extended;
525
526begin
527with GraphData do
528begin
529x := (xMax - xMin)/2;
530xMin := -x;
531xMax := x;
532
533y := (yMax - yMin)/2;
534yMin := -y;
535yMax := y;
536
537EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
538EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
539end;
540
541Altered := True;
542MainForm.GLViewer.Invalidate;
543end;
544
545procedure TGridOptionsForm.EqualGrad(Sender: TObject);
546var
547x, y, r: extended;
548
549begin
550with GraphData do
551begin
552x := xMax - xMin;
553y := yMax - yMin;
554r := (x*MainForm.GLViewer.Height)/(y*Mainform.GLViewer.Width);
555
556if x > y then
557begin
558yMax := yMax*r;
559yMin := yMin*r;
560end
561else
562begin
563xMax := xMax/r;
564xMin := xMin/r;
565end;
566EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
567EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
568end;
569Altered := True;
570MainForm.GLViewer.Invalidate;
571end;
572
573procedure TGridOptionsForm.EqualRange(Sender: TObject);
574var
575x, y: extended;
576
577begin
578with GraphData do
579begin
580x := xMax - xMin;
581y := yMax - yMin;
582
583if x > y then
584begin
585xMax := yMax;
586xMin := yMin;
587end
588else
589begin
590yMax := xMax;
591yMin := xMin;
592end;
593EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
594EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
595EditMinY.Text := FloatToStrF(yMin, ffGeneral, 13, 4);
596EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 13, 4);
597end;
598Altered := True;
599MainForm.GLViewer.Invalidate;
600end;
601
602function TGridOptionsForm.AnyPolar: Boolean;
603var
604i: integer;
605Found: Boolean;
606
607begin
608with FunctionsForm.CheckListBox do
609begin
610i := 0;
611Found := False;
612while not Found and (i < Count) do
613begin
614Found := not TPlotDataObject(Items.Objects[i]).Data.PlotAsFx
615and Checked[i];
616Inc(i);
617end;
618Result := Found;
619end;
620end;
621
622procedure TGridOptionsForm.SaveSpeedButtonClick(Sender: TObject);
623begin
624with GraphData do
625begin
626SavexMin := xMin;
627SavexMax := xMax;
628SaveyMin := yMin;
629SaveyMax := yMax;
630RestoreSpeedButton.Visible := (SavexMin <> SavexMax) and
631(SaveyMin <> SaveyMax);
632end;
633end;
634
635procedure TGridOptionsForm.ShowData;
636var
637b: boolean;
638
639begin
640b := Altered;
641
642with GraphData do
643begin
644RestoreSpeedButton.Visible := (SavexMin <> SavexMax) and
645(SaveyMin <> SaveyMax);
646EditMinX.Text := FloatToStrF(xMin, ffGeneral, 13, 4);
647EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 13, 4);
648EditMinY.Text := FloatToStrF(yMin, ffGeneral, 13, 4);
649EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 13, 4);
650if Active then
651ApplyBitBtn.Visible := False;
652
653UpDown1.Position := AxisWidth;
654UpDown2.Position := MajorWidth;
655UpDown3.Position := MinorWidth;
656GridStyles.ItemIndex := Ord(Grid.GridStyle);
657
658LogXCheck.Checked := Grid.xAxisStyle = asLog;
659LogYCheck.Checked := Grid.yAxisStyle = asLog;
660
661SpeedButton6.Enabled := not(LogXCheck.Checked or LogYCheck.Checked);
662SpeedButton7.Enabled := SpeedButton6.Enabled or
663((Grid.xAxisStyle = asLog) and
664(Grid.yAxisStyle = asLog));
665SpeedButton8.Enabled := SpeedButton6.Enabled or
666((Grid.xAxisStyle = asLog) and
667(Grid.yAxisStyle = asLog));
668
669Label9.Font.Color := xAxisColor;
670Label10.Font.Color := yAxisColor;
671xTrackBar.Position := xMinorGrad;
672yTrackBar.Position := yMinorGrad;
673end;
674Altered := b;
675end;
676
677end.
678