MathgeomGLS
2205 строк · 56.9 Кб
1unit faFunc1d;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11System.UITypes,
12System.Math,
13System.ImageList,
14Vcl.ImgList,
15Vcl.ClipBrd,
16Vcl.Graphics,
17Vcl.Controls,
18Vcl.Forms,
19Vcl.Dialogs,
20Vcl.StdCtrls,
21Vcl.CheckLst,
22Vcl.Buttons,
23Vcl.ComCtrls,
24Vcl.Menus,
25Vcl.ExtCtrls,
26
27Graf.Global1d,
28Graf.Parser1d;
29
30type
31TFunctionsForm = class(TForm)
32MainMenu: TMainMenu;
33File1: TMenuItem;
34New1: TMenuItem;
35Label1: TLabel;
36Label2: TLabel;
37Label3: TLabel;
38Label4: TLabel;
39Label5: TLabel;
40Label6: TLabel;
41Label7: TLabel;
42Label8: TLabel;
43Label9: TLabel;
44Label10: TLabel;
45Label11: TLabel;
46Label12: TLabel;
47LabelPhi: TLabel;
48Labeldx: TLabel;
49Labelx: TLabel;
50Labely: TLabel;
51LabelRCos: TLabel;
52LabelRSin: TLabel;
53LabelFunc: TLabel;
54EditSegMin: TEdit;
55EditSegMax: TEdit;
56Editdx: TEdit;
57UpDown1: TUpDown;
58EditLocX: TEdit;
59EditLocY: TEdit;
60ShowLabelCheckBox: TCheckBox;
61ContinuousCheckBox: TCheckBox;
62EditPen: TEdit;
63UpDown2: TUpDown;
64EditCoordinate: TEdit;
65UpDown3: TUpDown;
66EditEvaluate: TEdit;
67Editfx: TEdit;
68SwitchButton: TSpeedButton;
69SegmentButton: TSpeedButton;
70sbPenColor: TSpeedButton;
71SpeedButton4: TSpeedButton;
72EvaluateButton: TSpeedButton;
73AddButton: TSpeedButton;
74DeleteButton: TSpeedButton;
75UpButton: TSpeedButton;
76DownButton: TSpeedButton;
77CheckListBox: TCheckListBox;
78BitBtn2: TBitBtn;
79ColorDialog: TColorDialog;
80Open1: TMenuItem;
81Save1: TMenuItem;
82Saveas1: TMenuItem;
83Derivatives1: TMenuItem;
84yfx1: TMenuItem;
85yfx2: TMenuItem;
86Integrate1: TMenuItem;
87Integrate2x: TMenuItem;
88Integrate2y: TMenuItem;
89Between1: TMenuItem;
90Volumex1: TMenuItem;
91Volumey1: TMenuItem;
92SaveDialog: TSaveDialog;
93OpenDialog: TOpenDialog;
94ImageList1: TImageList;
95Findx: TMenuItem;
96fxValue: TMenuItem;
97fx1Value: TMenuItem;
98fx2Value: TMenuItem;
99PenPanel: TPanel;
100CoordPanel: TPanel;
101N1: TMenuItem;
102Exit1: TMenuItem;
103CoordPointButton: TSpeedButton;
104procedure FormDestroy(Sender: TObject);
105procedure FormShow(Sender: TObject);
106procedure ParseKeyPress(Sender: TObject; var Key: Char);
107procedure IntKeyPress(Sender: TObject; var Key: Char);
108procedure fxKeyPress(Sender: TObject; var Key: Char);
109procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
110procedure EditSegMinKeyUp(Sender: TObject; var Key: Word;
111Shift: TShiftState);
112procedure EditSegMaxKeyUp(Sender: TObject; var Key: Word;
113Shift: TShiftState);
114procedure EditdxKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
115procedure EditdxChange(Sender: TObject);
116procedure EditLocXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
117procedure EditLocYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
118procedure EditPenKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
119procedure EditPenChange(Sender: TObject);
120procedure EvaluateKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
121procedure EditfxKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
122procedure NewClick(Sender: TObject);
123procedure OpenClick(Sender: TObject);
124procedure SaveClick(Sender: TObject);
125procedure SaveAsClick(Sender: TObject);
126procedure yfx1Click(Sender: TObject);
127procedure yfx2Click(Sender: TObject);
128procedure Integrate2xClick(Sender: TObject);
129procedure Integrate2yClick(Sender: TObject);
130procedure Between1Click(Sender: TObject);
131procedure Volumex1Click(Sender: TObject);
132procedure Volumey1Click(Sender: TObject);
133procedure fxValueClick(Sender: TObject);
134procedure fx1ValueClick(Sender: TObject);
135procedure fx2ValueClick(Sender: TObject);
136procedure SwitchClick(Sender: TObject);
137procedure SegmentClick(Sender: TObject);
138procedure ShowLabelClick(Sender: TObject);
139procedure ContinuousClick(Sender: TObject);
140procedure ColorClick(Sender: TObject);
141procedure EvaluateClick(Sender: TObject);
142procedure LabelyClick(Sender: TObject);
143procedure LabelRCosClick(Sender: TObject);
144procedure LabelRSinClick(Sender: TObject);
145procedure CheckListBoxClick(Sender: TObject);
146procedure AddButtonClick(Sender: TObject);
147procedure DeleteButtonClick(Sender: TObject);
148procedure BitBtn2Click(Sender: TObject);
149procedure BitBtn1Click(Sender: TObject);
150procedure UpButtonClick(Sender: TObject);
151procedure DownButtonClick(Sender: TObject);
152procedure CheckListBoxClickCheck(Sender: TObject);
153procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
154procedure Exit1Click(Sender: TObject);
155procedure CoordPointButtonClick(Sender: TObject);
156procedure FormCreate(Sender: TObject);
157procedure FormClose(Sender: TObject; var Action: TCloseAction);
158private
159NewFile: Boolean;
160x1, x2: extended;
161function ReadData(const FName: TFileName): Boolean;
162procedure WriteData(const FName: TFileName);
163function DefaultData: TGraphData;
164procedure ShowData(Sender: TObject);
165procedure OpenSelectedFile(Sender: TObject; FName: TFileName);
166procedure ClosefxValueForm;
167procedure Closefx1ValueForm;
168procedure Closefx2ValueForm;
169public
170procedure ShowCartesianEvaluate;
171procedure ShowPolarEvaluate;
172procedure CloseIntegrateXForm;
173procedure CloseIntegrateYForm;
174procedure CloseBetweenForm;
175procedure CloseVolumeXForm;
176procedure CloseVolumeYForm;
177end;
178
179var
180FunctionsForm: TFunctionsForm;
181
182// =====================================================================
183implementation
184// =====================================================================
185
186uses
187faGraf1D,
188faGridOpt1d,
189faDerivative,
190faIntegrateX,
191faIntegrateY,
192faBetween,
193faVolumeX,
194faVolumeY,
195faValueX,
196faValueX1,
197faValueX2,
198faTextBlocks,
199faNumeric;
200
201{$R *.dfm}
202
203procedure TFunctionsForm.FormClose(Sender: TObject; var Action: TCloseAction);
204var
205i: integer;
206begin
207for i := 0 to CheckListBox.Items.Count - 1 do
208CheckListBox.Items.Objects[i].Free;
209CheckListBox.Clear;
210end;
211
212procedure TFunctionsForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
213begin
214MainForm.Close;
215end;
216
217procedure TFunctionsForm.FormCreate(Sender: TObject);
218begin
219ReportMemoryLeaksOnShutdown := True;
220end;
221
222procedure TFunctionsForm.FormDestroy(Sender: TObject);
223var
224i: integer;
225
226begin
227with CheckListBox do
228for i := 0 to Count - 1 do
229Items.Objects[i].Free;
230end;
231
232procedure TFunctionsForm.FormShow(Sender: TObject);
233begin
234if not ReadData(DataPath + GraphFName) then
235begin
236GraphFName := NewFName;
237NewFile := True;
238GraphData := DefaultData;
239
240with GraphData, CheckListBox do
241begin
242AddItem(PlotData.TextStr, TPlotDataObject.Create(PlotData));
243ItemIndex := Count - 1;
244Checked[ItemIndex] := True; // initially this item is checked
245end;
246end;
247
248Caption := GraphFName;
249ShowData(Sender);
250if GridOptionsForm.Visible then
251GridOptionsForm.ShowData;
252end;
253
254procedure TFunctionsForm.ParseKeyPress(Sender: TObject; var Key: Char);
255begin
256with Sender as TEdit do
257begin
258if not CharInSet(UpCase(Key), [' ', '!', '(', ')', '*', '+', '-', '.', ',',
259'/', '0' .. '9', 'A' .. 'C', 'E', 'G' .. 'I', 'L', 'N' .. 'T', 'X', '^',
260'`', #8]) then
261begin
262Key := #0;
263Exit;
264end
265else if Active then
266BitBtn2.Visible := True;
267if Key = '`' then
268Key := '�';
269end;
270Altered := True;
271end;
272
273procedure TFunctionsForm.IntKeyPress(Sender: TObject; var Key: Char);
274begin
275with Sender as TEdit do
276if not CharInSet(Key, ['0' .. '9', #8]) then
277Key := #0
278end;
279
280procedure TFunctionsForm.fxKeyPress(Sender: TObject; var Key: Char);
281begin
282with Sender as TEdit do
283begin
284if not CharInSet(UpCase(Key), [' ', '!', '(', ')', '*', '+', '-', '.', ',',
285'/', '0' .. '9', 'A' .. 'C', 'E', 'G' .. 'I', 'L', 'N' .. 'T', 'X', '\',
286'^', '`', #8]) then
287begin
288Key := #0;
289Exit;
290end;
291
292if not GraphData.PlotData.PlotAsFx and
293((Key = '\') or (Key = 'x') or (Key = 'X')) then
294Key := '�';
295if Key = '`' then
296Key := '�';
297end;
298Altered := True;
299end;
300
301procedure TFunctionsForm.EditKeyDown(Sender: TObject; var Key: Word;
302Shift: TShiftState);
303begin
304if (Key = VK_DELETE) or (Key = VK_BACK) then
305Altered := True;
306end;
307
308procedure TFunctionsForm.EditSegMinKeyUp(Sender: TObject; var Key: Word;
309Shift: TShiftState);
310var
311s: string;
312e: byte;
313
314begin
315s := ScanText(EditSegMin.Text);
316x1 := ParseAndEvaluate(s, e);
317if isNAN(x1) or isInfinite(x1) or (e > 0) then
318x1 := -Pi;
319if Active then
320BitBtn2.Visible := True;
321end;
322
323procedure TFunctionsForm.EditSegMaxKeyUp(Sender: TObject; var Key: Word;
324Shift: TShiftState);
325var
326s: string;
327e: byte;
328
329begin
330s := ScanText(EditSegMax.Text);
331x2 := ParseAndEvaluate(s, e);
332if isNAN(x2) or isInfinite(x2) or (e > 0) then
333x2 := Pi;
334// if e > 0 then x2 := Pi;
335if Active then
336BitBtn2.Visible := True;
337end;
338
339procedure TFunctionsForm.EditdxKeyUp(Sender: TObject; var Key: Word;
340Shift: TShiftState);
341var
342e: single;
343
344begin
345if Active then
346begin
347with GraphData, PlotData do
348begin
349if PlotAsFx then
350begin
351try
352e := StrToFloat(Editdx.Text);
353if e = 0 then
354e := 1;
355xInc := e;
356except
357xInc := 1;
358end;
359TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data.xInc := xInc;
360end
361else { plotting r = f(�) }
362begin
363try
364e := StrToFloat(Editdx.Text);
365if e = 0 then
366e := 0.2;
367PhiInc := e;
368except
369PhiInc := 0.2;
370end;
371if PhiInc < PhiIncMin then
372PhiInc := PhiIncMin;
373TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data.PhiInc := PhiInc;
374end;
375end;
376MainForm.GLViewer.Invalidate;
377end;
378end;
379
380procedure TFunctionsForm.EditdxChange(Sender: TObject);
381var
382k: Word;
383begin
384if Active then
385begin
386k := 0;
387EditdxKeyUp(Sender, k, []);
388end;
389end;
390
391procedure TFunctionsForm.EditLocXKeyUp(Sender: TObject; var Key: Word;
392Shift: TShiftState);
393var
394x: extended;
395begin
396try
397x := StrToFloat(EditLocX.Text);
398with GraphData do
399begin
400if x > 0.95 * xMax then
401x := 0.95 * xMax;
402if x < xMin then
403x := xMin;
404end;
405except
406x := 0;
407end;
408TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data.xLabel := x;
409GraphData.PlotData.xLabel := x;
410MainForm.GLViewer.Invalidate;
411end;
412
413procedure TFunctionsForm.EditLocYKeyUp(Sender: TObject; var Key: Word;
414Shift: TShiftState);
415var
416y: extended;
417begin
418try
419y := StrToFloat(EditLocY.Text);
420with GraphData do
421begin
422if y > yMax then
423y := yMax;
424if y < 0.95 * yMin then
425y := 0.95 * yMin;
426end;
427except
428y := 0;
429end;
430TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data.yLabel := y;
431GraphData.PlotData.yLabel := y;
432MainForm.GLViewer.Invalidate;
433end;
434
435procedure TFunctionsForm.EditPenKeyUp(Sender: TObject; var Key: Word;
436Shift: TShiftState);
437var
438w: integer;
439
440begin
441if Active then
442with Sender as TEdit do
443begin
444try
445w := StrToInt(Text);
446except
447w := 1;
448end;
449if w < 1 then
450w := 1;
451with GraphData do
452case Tag of
4530:
454begin // sent from EditPen
455PlotData.PlotWidth := w;
456with CheckListBox do
457TPlotDataObject(Items.Objects[ItemIndex]).Data.PlotWidth := w;
458end;
4591:
460CoordWidth := w; // sent from EditCoordinate
461end;
462Altered := True;
463MainForm.GLViewer.Invalidate;
464end;
465end;
466
467procedure TFunctionsForm.EditPenChange(Sender: TObject);
468var
469k: Word;
470
471begin
472k := 0;
473EditPenKeyUp(Sender, k, []);
474end;
475
476procedure TFunctionsForm.EvaluateKeyUp(Sender: TObject; var Key: Word;
477Shift: TShiftState);
478var
479s: string;
480e: byte;
481
482begin
483if EditEvaluate.Text <> '' then
484begin
485s := ScanText(EditEvaluate.Text);
486xEvaluate := ParseAndEvaluate(s, e);
487if e = 0 then
488MainForm.GLViewer.Invalidate;
489end;
490end;
491
492procedure TFunctionsForm.Exit1Click(Sender: TObject);
493begin
494Close;
495end;
496
497procedure TFunctionsForm.EditfxKeyUp(Sender: TObject; var Key: Word;
498Shift: TShiftState);
499begin
500with TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data do
501begin
502TextStr := Editfx.Text;
503FunctStr := ScanText(TextStr);
504GraphData.PlotData.FunctStr := FunctStr;
505GraphData.PlotData.TextStr := TextStr;
506end;
507CheckListBox.Items[CheckListBox.ItemIndex] := Editfx.Text;
508MainForm.GLViewer.Invalidate;
509end;
510
511procedure TFunctionsForm.NewClick(Sender: TObject);
512var
513i: integer;
514
515begin
516if Altered then
517case MessageDlg('The current graph data has been altered.' +
518#13#10'Do you wish to save the alterations ?', mtConfirmation,
519[mbYes, mbNo, mbCancel], 0) of
520mrYes:
521SaveClick(Sender);
522mrCancel:
523Exit;
524end;
525
526for i := 0 to CheckListBox.Items.Count - 1 do
527CheckListBox.Items.Objects[i].Free;
528CheckListBox.Clear;
529
530GraphFName := NewFName;
531Caption := GraphFName;
532MainForm.Caption := GraphFName;
533GridOptionsForm.Caption := GraphFName;
534NumericForm.Caption := GraphFName;
535NumericForm.ClearCheckListBox;
536NumericForm.DataListBox.Clear;
537NumericForm.ShowData(Sender);
538TextBlocksForm.Caption := GraphFName;
539
540NewFile := True;
541Altered := True;
542GraphData := DefaultData;
543
544with GraphData do
545CheckListBox.AddItem(PlotData.TextStr, TPlotDataObject.Create(PlotData));
546
547CheckListBox.ItemIndex := 0;
548CheckListBox.Checked[CheckListBox.ItemIndex] := True;
549ShowData(Sender);
550GridOptionsForm.ShowData;
551GridOptionsForm.ApplyBitBtn.Visible := false;
552TextBlocksForm.ClearTextBlocks;
553(*
554NewFont needed to initialize GLWinFont.GetCharWidth
555if the font has been altered, which may or may not be the case,
556so do it anyway
557*)
558NewFont := True;
559MainForm.GLViewer.Invalidate;
560end;
561
562procedure TFunctionsForm.OpenClick(Sender: TObject);
563begin
564if Altered then
565case MessageDlg('��������� ������� ���� ��������' +
566#13#10'��������� ��������� ?', mtConfirmation,
567[mbYes, mbNo, mbCancel], 0) of
568mrYes:
569SaveClick(Sender);
570mrCancel:
571Exit;
572mrNo:
573begin
574Altered := false;
575NewFile := false;
576end
577end;
578
579OpenDialog.InitialDir := DataPath;
580if OpenDialog.Execute then
581begin
582DataPath := ExtractFilePath(OpenDialog.FileName);
583DataPath := IncludeTrailingPathDelimiter(DataPath);
584MainForm.oMousex := -1;
585OpenSelectedFile(Sender, OpenDialog.FileName);
586end;
587end;
588
589procedure TFunctionsForm.SaveClick(Sender: TObject);
590begin
591if NewFile then
592SaveAsClick(Sender)
593else
594WriteData(DataPath + GraphFName);
595end;
596
597procedure TFunctionsForm.SaveAsClick(Sender: TObject);
598begin
599SaveDialog.InitialDir := DataPath;
600SaveDialog.FileName := GraphFName;
601if SaveDialog.Execute then
602begin
603GraphFName := ExtractFileName(SaveDialog.FileName);
604DataPath := ExtractFilePath(SaveDialog.FileName);
605DataPath := IncludeTrailingPathDelimiter(DataPath);
606WriteData(DataPath + GraphFName);
607end;
608Caption := GraphFName;
609MainForm.Caption := GraphFName;
610GridOptionsForm.Caption := GraphFName;
611NumericForm.Caption := GraphFName;
612TextBlocksForm.Caption := GraphFName;
613end;
614
615procedure TFunctionsForm.yfx1Click(Sender: TObject);
616begin
617if yfx1.Checked then
618begin
619DerivativeForm.Show;
620yfx1.ImageIndex := -1;
621CheckListBoxClick(Sender);
622end
623else
624begin
625if yfx2.Checked then
626yfx2.Checked := false;
627yfx1.ImageIndex := 1;
628yfx2.ImageIndex := 2;
629with DerivativeForm do
630if Visible then
631Close;
632end;
633MainForm.GLViewer.Invalidate;
634end;
635
636procedure TFunctionsForm.yfx2Click(Sender: TObject);
637begin
638if yfx2.Checked then
639begin
640if not yfx1.Checked then
641yfx1.Checked := True;
642with DerivativeForm do
643if not Visible then
644Show;
645yfx1.ImageIndex := -1;
646yfx2.ImageIndex := -1;
647CheckListBoxClick(Sender);
648end
649else
650yfx2.ImageIndex := 2;
651
652DerivativeForm.ShowData;
653MainForm.GLViewer.Invalidate;
654end;
655
656procedure TFunctionsForm.Integrate2xClick(Sender: TObject);
657begin
658if Integrate2x.Checked then
659begin
660if Integrate2y.Checked then
661CloseIntegrateYForm;
662if Between1.Checked then
663CloseBetweenForm;
664if Volumex1.Checked then
665CloseVolumeXForm;
666if Volumey1.Checked then
667CloseVolumeYForm;
668CheckListBoxClick(Sender);
669IntegrateXForm.PlotIntegrated := piBoth;
670IntegrateXForm.Show;
671Integrate2x.ImageIndex := -1;
672end
673else
674begin
675Integrate2x.ImageIndex := 4;
676IntegrateXForm.Close;
677IntegrateXForm.PlotIntegrated := piCalc;
678MainForm.GLViewer.Invalidate;
679end;
680end;
681
682procedure TFunctionsForm.Integrate2yClick(Sender: TObject);
683begin
684if Integrate2y.Checked then
685begin
686if Integrate2x.Checked then
687CloseIntegrateXForm;
688if Between1.Checked then
689CloseBetweenForm;
690if Volumex1.Checked then
691CloseVolumeXForm;
692if Volumey1.Checked then
693CloseVolumeYForm;
694CheckListBoxClick(Sender);
695IntegrateYForm.Show;
696Integrate2y.ImageIndex := -1;
697end
698else
699begin
700Integrate2y.ImageIndex := 4;
701IntegrateYForm.Close;
702MainForm.GLViewer.Invalidate;
703end;
704end;
705
706procedure TFunctionsForm.Between1Click(Sender: TObject);
707begin
708if CheckListBox.Count < 2 then
709Exit;
710
711if Between1.Checked then
712begin
713if Integrate2x.Checked then
714CloseIntegrateXForm;
715if Integrate2y.Checked then
716CloseIntegrateYForm;
717if Volumex1.Checked then
718CloseVolumeXForm;
719if Volumey1.Checked then
720CloseVolumeYForm;
721with CheckListBox do
722begin
723ItemIndex := 0;
724Checked[0] := True;
725Checked[1] := True;
726end;
727CheckListBoxClick(Sender);
728BetweenForm.Show;
729Between1.ImageIndex := -1;
730end
731else
732begin
733Between1.ImageIndex := 5;
734BetweenForm.Close;
735MainForm.GLViewer.Invalidate;
736end;
737end;
738
739procedure TFunctionsForm.Volumex1Click(Sender: TObject);
740begin
741if Volumex1.Checked then
742begin
743if Integrate2x.Checked then
744CloseIntegrateXForm;
745if Integrate2y.Checked then
746CloseIntegrateYForm;
747if Between1.Checked then
748CloseBetweenForm;
749if Volumey1.Checked then
750CloseVolumeYForm;
751CheckListBoxClick(Sender);
752Volumex1.ImageIndex := -1;
753VolumeXForm.Show;
754end
755else
756begin
757VolumeXForm.HideFunctionCheckBox.Checked := false;
758Volumex1.ImageIndex := 6;
759VolumeXForm.Close;
760MainForm.GLViewer.Invalidate;
761end;
762end;
763
764procedure TFunctionsForm.Volumey1Click(Sender: TObject);
765begin
766if Volumey1.Checked then
767begin
768if Integrate2x.Checked then
769CloseIntegrateXForm;
770if Integrate2y.Checked then
771CloseIntegrateYForm;
772if Between1.Checked then
773CloseBetweenForm;
774if Volumex1.Checked then
775CloseVolumeXForm;
776CheckListBoxClick(Sender);
777Volumey1.ImageIndex := -1;
778VolumeYForm.Show;
779end
780else
781begin
782VolumeYForm.HideFunctionCheckBox.Checked := false;
783Volumey1.ImageIndex := 7;
784VolumeYForm.Close;
785MainForm.GLViewer.Invalidate;
786end;
787end;
788
789procedure TFunctionsForm.fxValueClick(Sender: TObject);
790begin
791if fxValue.Checked then
792begin
793if fx1Value.Checked then
794Closefx1ValueForm;
795if fx2Value.Checked then
796Closefx2ValueForm;
797CheckListBoxClick(Sender);
798fxValue.ImageIndex := -1;
799fxValueForm.Show;
800end
801else
802begin
803fxValue.ImageIndex := 0;
804fxValueForm.Close;
805end;
806end;
807
808procedure TFunctionsForm.fx1ValueClick(Sender: TObject);
809begin
810if fx1Value.Checked then
811begin
812if fxValue.Checked then
813ClosefxValueForm;
814if fx2Value.Checked then
815Closefx2ValueForm;
816CheckListBoxClick(Sender);
817fx1Value.ImageIndex := -1;
818fx1ValueForm.Show;
819end
820else
821begin
822fx1ValueForm.Close;
823fx1Value.ImageIndex := 1;
824end;
825end;
826
827procedure TFunctionsForm.fx2ValueClick(Sender: TObject);
828begin
829if fx2Value.Checked then
830begin
831if fxValue.Checked then
832ClosefxValueForm;
833if fx1Value.Checked then
834Closefx1ValueForm;
835CheckListBoxClick(Sender);
836fx2Value.ImageIndex := -1;
837fx2ValueForm.Show;
838end
839else
840begin
841fx2ValueForm.Close;
842fx2Value.ImageIndex := 2;
843end;
844end;
845
846procedure TFunctionsForm.SwitchClick(Sender: TObject);
847begin
848with CheckListBox do
849GraphData.PlotData := TPlotDataObject(Items.Objects[ItemIndex]).Data;
850
851with GraphData, PlotData do
852begin
853with SwitchButton do
854begin
855PlotAsFx := Tag = 1;
856Tag := (Tag + 1) mod 2;
857end;
858
859if not PlotAsFx and ((SegMax - SegMin) / PhiInc > 1E6) then
860begin
861MessageDlg('The current graph data'#13#10 +
862'can not be plotted as y = f(�).'#13#10 + 'The range is too large.',
863mtError, [mbOK], 0);
864SwitchButton.Tag := 0;
865PlotAsFx := True;
866Exit;
867end;
868
869with CheckListBox do
870TPlotDataObject(Items.Objects[ItemIndex]).Data.PlotAsFx := PlotAsFx;
871end;
872
873CheckListBoxClick(Sender);
874Altered := True;
875end;
876
877procedure TFunctionsForm.SegmentClick(Sender: TObject);
878begin
879with GraphData.PlotData do
880begin
881with SegmentButton do
882begin
883IsSegment := Tag = 1;
884Tag := (Tag + 1) mod 2;
885end;
886with CheckListBox do
887TPlotDataObject(Items.Objects[ItemIndex]).Data.IsSegment := IsSegment;
888end;
889CheckListBoxClick(Sender);
890end;
891
892procedure TFunctionsForm.ShowLabelClick(Sender: TObject);
893begin
894Label7.Visible := ShowLabelCheckBox.Checked;
895EditLocX.Visible := ShowLabelCheckBox.Checked;
896EditLocY.Visible := ShowLabelCheckBox.Checked;
897GraphData.PlotData.ShowLabel := ShowLabelCheckBox.Checked;
898with CheckListBox do
899TPlotDataObject(Items.Objects[ItemIndex]).Data.ShowLabel :=
900GraphData.PlotData.ShowLabel;
901Altered := True;
902MainForm.GLViewer.Invalidate;
903end;
904
905procedure TFunctionsForm.ContinuousClick(Sender: TObject);
906begin
907GraphData.PlotData.IsContinuous := ContinuousCheckBox.Checked;
908with CheckListBox do
909TPlotDataObject(Items.Objects[ItemIndex]).Data.IsContinuous :=
910GraphData.PlotData.IsContinuous;
911Altered := True;
912MainForm.GLViewer.Invalidate;
913end;
914
915procedure TFunctionsForm.CoordPointButtonClick(Sender: TObject);
916var
917k: Word;
918
919begin
920if (NumericForm.CheckListBox.Count > 0) and
921(NumericForm.CheckListBox.ItemIndex > -1) and
922(NumericForm.CheckListBox.ItemIndex < NumericForm.CheckListBox.Count) and
923(NumericForm.InputRG.ItemIndex = 0) then
924begin
925if (Labely.Caption = 'y = Infinitely positive') or
926(Labely.Caption = 'y = Undefined') then
927begin
928Beep;
929Exit;
930end;
931k := VK_RETURN;
932if SwitchButton.Tag = 0 then
933begin
934NumericForm.EditXCoord.Text := EditEvaluate.Text;
935NumericForm.EditYCoord.Text :=
936Copy(Labely.Caption, pos('=', Labely.Caption) + 2,
937Length(Labely.Caption));
938end
939else
940begin
941if NumericForm.CoordsRG.ItemIndex = 1 then // .RadialCheckBox.Checked then
942begin
943NumericForm.EditXCoord.Text := EditEvaluate.Text;
944NumericForm.EditYCoord.Text :=
945Copy(Labely.Caption, pos('=', Labely.Caption) + 2,
946Length(Labely.Caption));
947end
948else
949begin
950NumericForm.EditXCoord.Text := Copy(LabelRCos.Caption,
951pos('=', LabelRCos.Caption) + 2, Length(LabelRCos.Caption));
952NumericForm.EditYCoord.Text := Copy(LabelRSin.Caption,
953pos('=', LabelRSin.Caption) + 2, Length(LabelRSin.Caption));
954end;
955end;
956NumericForm.EditXCoord.SetFocus;
957NumericForm.EditXCoordKeyUp(Sender, k, []);
958NumericForm.EditYCoordKeyUp(Sender, k, []);
959end
960else
961MessageDlg('The data for the coordinate can not' +
962#13#10'be entered in the Numeric data form' +
963#13#10'as the settings are not correct.' +
964#13#10'Select ''Adding'' for ''Input Options''.', mtInformation,
965[mbOK], 0);
966end;
967
968procedure TFunctionsForm.ColorClick(Sender: TObject);
969var
970i: integer;
971
972begin
973with GraphData do
974begin
975if Sender.ClassType = TPanel then
976i := TPanel(Sender).Tag
977else
978i := TSpeedButton(Sender).Tag;
979
980case i of
9810:
982ColorDialog.Color := TPlotDataObject(CheckListBox.Items.Objects[
983CheckListBox.ItemIndex]).Data.PlotColor;
9841:
985ColorDialog.Color := CoordColor;
986end;
987if ColorDialog.Execute then
988begin
989case TSpeedButton(Sender).Tag of
9900:
991begin
992PlotData.PlotColor := ColorDialog.Color;
993with CheckListBox do
994TPlotDataObject(Items.Objects[ItemIndex]).Data.PlotColor :=
995ColorDialog.Color;
996PenPanel.Color := ColorDialog.Color;
997end;
9981:
999begin
1000CoordColor := ColorDialog.Color;
1001CoordPanel.Color := ColorDialog.Color;
1002end;
1003end;
1004Altered := True;
1005MainForm.GLViewer.Invalidate;
1006end;
1007end;
1008end;
1009
1010procedure TFunctionsForm.EvaluateClick(Sender: TObject);
1011var
1012k: Word;
1013
1014begin
1015with EvaluateButton do
1016Tag := (Tag + 1) mod 2;
1017
1018CheckListBoxClick(Sender);
1019
1020CoordPointButton.Visible := EditEvaluate.Visible and NumericForm.Visible and
1021(NumericForm.CheckListBox.Count > 0) and
1022(NumericForm.CheckListBox.ItemIndex > -1) and
1023(NumericForm.CheckListBox.ItemIndex < NumericForm.CheckListBox.Count) and
1024(NumericForm.InputRG.ItemIndex = 0);
1025
1026if EditEvaluate.Visible then
1027begin
1028EditEvaluate.SetFocus;
1029if EditEvaluate.Text <> '' then
1030begin
1031k := 0;
1032EditEvaluate.SelStart := Length(EditEvaluate.Text);
1033EvaluateKeyUp(Sender, k, []);
1034end;
1035end
1036else
1037MainForm.GLViewer.Invalidate;
1038end;
1039
1040procedure TFunctionsForm.LabelyClick(Sender: TObject);
1041begin
1042Clipboard.Clear;
1043Clipboard.AsText := Copy(Labely.Caption, pos('=', Labely.Caption) + 2,
1044Length(Labely.Caption));
1045end;
1046
1047procedure TFunctionsForm.LabelRCosClick(Sender: TObject);
1048begin
1049Clipboard.Clear;
1050Clipboard.AsText := Copy(LabelRCos.Caption, pos('=', LabelRCos.Caption) + 2,
1051Length(LabelRCos.Caption));
1052end;
1053
1054procedure TFunctionsForm.LabelRSinClick(Sender: TObject);
1055begin
1056Clipboard.Clear;
1057Clipboard.AsText := Copy(LabelRSin.Caption, pos('=', LabelRSin.Caption) + 2,
1058Length(LabelRSin.Caption));
1059end;
1060
1061procedure TFunctionsForm.CheckListBoxClick(Sender: TObject);
1062begin
1063if BitBtn2.Visible then
1064BitBtn2Click(Sender);
1065with CheckListBox do
1066if Count > 0 then
1067with GraphData do
1068begin
1069PlotData := TPlotDataObject(Items.Objects[ItemIndex]).Data;
1070
1071EvaluateButton.Visible := Checked[ItemIndex];
1072if (EvaluateButton.Tag = 1) and not Checked[ItemIndex] then
1073EvaluateButton.Tag := 0;
1074CoordPointButton.Visible := EvaluateButton.Tag = 1;
1075
1076if PlotData.PlotAsFx then
1077begin
1078yfx1.Caption := 'y = f''(x)';
1079yfx2.Caption := 'y = f"(x)';
1080end
1081else
1082begin
1083yfx1.Caption := 'y = f''(�)';
1084yfx2.Caption := 'y = f"(�)';
1085
1086if Integrate2y.Checked then
1087CloseIntegrateYForm;
1088if Between1.Checked then
1089CloseBetweenForm;
1090if Volumex1.Checked then
1091CloseVolumeXForm;
1092if Volumey1.Checked then
1093CloseVolumeYForm;
1094if fxValue.Checked then
1095ClosefxValueForm;
1096if fx1Value.Checked then
1097Closefx1ValueForm;
1098if fx2Value.Checked then
1099Closefx2ValueForm;
1100end;
1101end;
1102
1103MainForm.GLViewer.Invalidate;
1104ShowData(Sender);
1105DerivativeForm.ShowData;
1106IntegrateXForm.ShowData;
1107IntegrateYForm.ShowData;
1108BetweenForm.ShowData;
1109VolumeXForm.ShowData;
1110VolumeYForm.ShowData;
1111with fxValueForm do
1112if Visible then
1113begin
1114ShowData;
1115SetFocus;
1116RecalcBtnClick(Sender);
1117end;
1118with fx1ValueForm do
1119if Visible then
1120begin
1121ShowData;
1122SetFocus;
1123RecalcBtnClick(Sender);
1124end;
1125with fx2ValueForm do
1126if Visible then
1127begin
1128ShowData;
1129SetFocus;
1130RecalcBtnClick(Sender);
1131end;
1132end;
1133
1134procedure TFunctionsForm.CheckListBoxClickCheck(Sender: TObject);
1135begin
1136Altered := True;
1137end;
1138
1139procedure TFunctionsForm.BitBtn2Click(Sender: TObject);
1140var
1141k: Word;
1142
1143procedure Swap(var N1, n2: extended);
1144var
1145n: extended;
1146
1147begin
1148n := N1;
1149N1 := n2;
1150n2 := n;
1151end;
1152
1153begin
1154k := 0;
1155EditSegMinKeyUp(Sender, k, []);
1156EditSegMaxKeyUp(Sender, k, []);
1157
1158if x1 = x2 then
1159x2 := 1.1 * x1;
1160if x1 > x2 then
1161Swap(x1, x2);
1162
1163with GraphData.PlotData do
1164begin
1165SegMin := x1;
1166SegMax := x2;
1167end;
1168
1169with CheckListBox, TPlotDataObject(Items.Objects[ItemIndex]).Data do
1170begin
1171SegMin := x1;
1172SegMax := x2;
1173end;
1174Altered := True;
1175MainForm.GLViewer.Invalidate;
1176BitBtn2.Visible := false;
1177end;
1178
1179procedure TFunctionsForm.AddButtonClick(Sender: TObject);
1180begin
1181with CheckListBox, GraphData do
1182begin
1183PlotData := TPlotDataObject(Items.Objects[ItemIndex]).Data;
1184AddItem(PlotData.TextStr, TPlotDataObject.Create(PlotData));
1185ItemIndex := Count - 1;
1186Checked[ItemIndex] := True;
1187DeleteButton.Enabled := True;
1188UpButton.Enabled := True;
1189DownButton.Enabled := True;
1190end;
1191Altered := True;
1192MainForm.GLViewer.Invalidate;
1193Editfx.SetFocus;
1194Editfx.SelStart := 0;
1195end;
1196
1197procedure TFunctionsForm.DeleteButtonClick(Sender: TObject);
1198var
1199i: integer;
1200
1201begin
1202if CheckListBox.Count > 1 then
1203begin
1204with CheckListBox do
1205begin
1206i := ItemIndex;
1207with Items.Objects[i] as TPlotDataObject do
1208Free;
1209Items.Delete(i);
1210if i > Count - 1 then
1211i := Count - 1;
1212ItemIndex := i;
1213DeleteButton.Enabled := Count > 1;
1214end;
1215Altered := True;
1216MainForm.GLViewer.Invalidate;
1217end
1218end;
1219
1220procedure TFunctionsForm.BitBtn1Click(Sender: TObject);
1221begin
1222Close;
1223end;
1224
1225procedure TFunctionsForm.UpButtonClick(Sender: TObject);
1226var
1227i: integer;
1228
1229begin
1230with CheckListBox do
1231begin
1232i := ItemIndex;
1233if i > 0 then
1234Items.Move(i, i - 1);
1235if i > 1 then
1236ItemIndex := i - 1
1237else
1238ItemIndex := 0;
1239end;
1240CheckListBoxClick(Sender);
1241Altered := True;
1242end;
1243
1244procedure TFunctionsForm.DownButtonClick(Sender: TObject);
1245var
1246i: integer;
1247
1248begin
1249with CheckListBox do
1250begin
1251i := ItemIndex;
1252if i < Count - 1 then
1253Items.Move(i, i + 1);
1254ItemIndex := i + 1;
1255end;
1256CheckListBoxClick(Sender);
1257Altered := True;
1258end;
1259
1260function TFunctionsForm.ReadData(const FName: TFileName): Boolean;
1261var
1262s, t: string;
1263f: TextFile;
1264i, j, k, l, m, n: integer;
1265c: TColor;
1266td: TTextData;
1267vx, vy: extended;
1268
1269begin
1270Result := false;
1271if FileExists(FName) then
1272begin
1273AssignFile(f, FName);
1274try
1275Reset(f);
1276if FileSize(f) = 0 then
1277begin
1278CloseFile(f);
1279Result := false;
1280CheckListBox.ItemIndex := CheckListBox.Count - 1;
1281MessageDlg('File Error!'#13#10'The file '#13#10'"' + FName + '"' +
1282#13#10'is empty.', mtError, [mbOK], 0);
1283Exit;
1284end;
1285Readln(f, s);
1286j := 0;
1287i := pos(#9, s);
1288
1289while i > 0 do
1290begin
1291t := Copy(s, 1, i - 1);
1292s := Copy(s, i + 1, Length(s));
1293i := pos(#9, s);
1294Inc(j);
1295
1296case j of
12971:
1298TryStrToFloat(t, GraphData.xMin);
12992:
1300TryStrToFloat(t, GraphData.yMin);
13013:
1302TryStrToFloat(t, GraphData.xMax);
13034:
1304TryStrToFloat(t, GraphData.yMax);
13055:
1306TryStrToFloat(t, GraphData.SavexMin);
13076:
1308TryStrToFloat(t, GraphData.SaveyMin);
13097:
1310TryStrToFloat(t, GraphData.SavexMax);
13118:
1312TryStrToFloat(t, GraphData.SaveyMax);
13139:
1314TryStrToFloat(t, GraphData.AreaAlpha);
131510:
1316GraphData.FontName := t;
131711:
1318begin
1319GraphData.FontStyle := [];
1320if pos('fsBold', t) > 0 then
1321Include(GraphData.FontStyle, fsBold);
1322if pos('fsItalic', t) > 0 then
1323Include(GraphData.FontStyle, fsItalic);
1324if pos('fsUnderline', t) > 0 then
1325Include(GraphData.FontStyle, fsUnderline);
1326if pos('fsStrikeOut', t) > 0 then
1327Include(GraphData.FontStyle, fsStrikeOut);
1328end;
132912:
1330GraphData.FontSize := StrToInt(t);
133113:
1332GraphData.AxisWidth := StrToInt(t);
133314:
1334TryStrToInt(t, GraphData.xMinorGrad);
133515:
1336TryStrToInt(t, GraphData.yMinorGrad);
133716:
1338TryStrToInt(t, GraphData.xMajorGrad);
133917:
1340TryStrToInt(t, GraphData.yMajorGrad);
134118:
1342TryStrToInt(t, GraphData.MinorWidth);
134319:
1344TryStrToInt(t, GraphData.MajorWidth);
134520:
1346TryStrToInt(t, GraphData.CoordWidth);
134721:
1348TryStrToInt(t, GraphData.dydxWidth);
134922:
1350TryStrToInt(t, GraphData.d2ydx2Width);
135123:
1352TryStrToInt(t, GraphData.IntegCount);
135324:
1354TryStrToInt(t, GraphData.ydxWidth);
135525:
1356GraphData.BackColor := StrToInt(t);
135726:
1358GraphData.GridColor := StrToInt(t);
135927:
1360GraphData.xAxisColor := StrToInt(t);
136128:
1362GraphData.yAxisColor := StrToInt(t);
136329:
1364GraphData.CoordColor := StrToInt(t);
136530:
1366GraphData.dydxColor := StrToInt(t);
136731:
1368GraphData.d2ydx2Color := StrToInt(t);
136932:
1370GraphData.ydxColor := StrToInt(t);
137133:
1372GraphData.PosAreaColor := StrToInt(t);
137334:
1374GraphData.NegAreaColor := StrToInt(t);
137535:
1376GraphData.Grid.xAxisStyle := TAxisStyle(StrToInt(t));
137736:
1378GraphData.Grid.yAxisStyle := TAxisStyle(StrToInt(t));
137937:
1380GraphData.Grid.GridStyle := TGridStyle(StrToInt(t));
1381end;
1382end;
1383// with GridOptionsForm
1384GridOptionsForm.xTrackBar.Position := GraphData.xMinorGrad;
1385GridOptionsForm.yTrackBar.Position := GraphData.yMinorGrad;
1386
1387n := StrToInt(s); // number of functions to plot
1388
1389for k := 0 to n - 1 do
1390begin // read each function's data
1391Readln(f, s);
1392j := 0;
1393i := pos(#9, s);
1394
1395while i > 0 do
1396begin
1397t := Copy(s, 1, i - 1);
1398s := Copy(s, i + 1, Length(s));
1399i := pos(#9, s);
1400Inc(j);
1401with GraphData.PlotData do
1402case j of
14031:
1404FunctStr := t;
14052:
1406TextStr := t;
14073:
1408TryStrToFloat(t, xInc);
14094:
1410PlotWidth := StrToInt(t);
14115:
1412PlotColor := StrToInt(t);
14136:
1414TryStrToFloat(t, PhiInc);
14157:
1416TryStrToFloat(t, SegMin);
14178:
1418TryStrToFloat(t, SegMax);
14199:
1420TryStrToFloat(t, xLabel);
142110:
1422TryStrToFloat(t, yLabel);
142311:
1424ShowLabel := StrToBool(t);
142512:
1426PlotAsFx := StrToBool(t);
142713:
1428IsSegment := StrToBool(t);
142914:
1430IsContinuous := StrToBool(t);
1431end;
1432end;
1433
1434CheckListBox.AddItem(GraphData.PlotData.TextStr,
1435TPlotDataObject.Create(GraphData.PlotData));
1436CheckListBox.Checked[CheckListBox.Count - 1] := StrToBool(s);
1437end;
1438
1439with NumericForm do
1440begin
1441ClearCheckListBox;
1442Readln(f, s);
1443n := StrToInt(s); // number of numeric graphs
1444m := 0;
1445vx := 0;
1446for k := 0 to n - 1 do
1447begin
1448Readln(f, s);
1449j := 0;
1450i := pos(#9, s);
1451
1452while i > 0 do
1453begin
1454t := Copy(s, 1, i - 1);
1455s := Copy(s, i + 1, Length(s));
1456i := pos(#9, s);
1457Inc(j);
1458
1459case j of
14601:
1461NumericData.Name := t;
14622:
1463NumericData.NumericStyle := TNumericStyle(StrToInt(t));
14643:
1465NumericData.ShowPoints := StrToBool(t);
14664:
1467NumericData.PointStyle := TPointStyle(StrToInt(t));
14685:
1469NumericData.PointSize := StrToInt(t);
14706:
1471NumericData.PointColor := StrToInt(t);
14727:
1473NumericData.PlotWidth := StrToInt(t);
14748:
1475NumericData.PlotColor := StrToInt(t);
14769:
1477NumericData.SortXValue := StrToBool(t);
147810:
1479NumericData.Extrapolate := StrToBool(t);
148011:
1481TryStrToInt(t, NumericData.CoordsIdx);
148212:
1483TryStrToInt(t, NumericData.CurveRate);
1484// was k0 = CurveRate/100
148513:
1486m := StrToInt(t); // number of plot points
1487end;
1488end;
1489
1490with CheckListBox do
1491begin
1492AddItem(NumericData.Name, TNumericObject.Create(NumericData));
1493Checked[Count - 1] := StrToBool(s); // Checked
1494end;
1495
1496if m > 0 then
1497begin
1498Readln(f, s);
1499j := 0;
1500i := pos(#9, s);
1501
1502while i > 0 do
1503begin
1504t := Copy(s, 1, i - 1);
1505s := Copy(s, i + 1, Length(s));
1506i := pos(#9, s);
1507Inc(j);
1508if Odd(j) then
1509TryStrToFloat(t, vx)
1510else
1511begin
1512TryStrToFloat(t, vy);
1513with TNumericObject(CheckListBox.Items.Objects
1514[CheckListBox.Count - 1]) do
1515ControlPoints.Add(TGraphPointObject.Create(vx, vy));
1516end;
1517end;
1518end;
1519end;
1520ShowData(Self);
1521UpdateDataListBox;
1522end;
1523
1524TextBlocksForm.ClearTextBlocks;
1525Readln(f, s);
1526n := StrToInt(s); // number of TextBlocks
1527
1528for k := 0 to n - 1 do
1529begin // read each TextBlock's data
1530Readln(f, s);
1531j := 0;
1532i := pos(#9, s);
1533
1534while i > 0 do
1535begin
1536t := Copy(s, 1, i - 1);
1537s := Copy(s, i + 1, Length(s));
1538i := pos(#9, s);
1539Inc(j);
1540case j of
15411:
1542Caption := t;
15432:
1544TryStrToFloat(t, td.xLoc);
15453:
1546TryStrToFloat(t, td.yLoc);
15474:
1548TryStrToInt(t, td.yInc);
15495:
1550td.FontName := t;
15516:
1552begin
1553td.FontStyle := [];
1554if pos('fsBold', t) > 0 then
1555Include(td.FontStyle, fsBold);
1556if pos('fsItalic', t) > 0 then
1557Include(td.FontStyle, fsItalic);
1558if pos('fsUnderline', t) > 0 then
1559Include(td.FontStyle, fsUnderline);
1560if pos('fsStrikeOut', t) > 0 then
1561Include(td.FontStyle, fsStrikeOut);
1562end;
15637:
1564td.FontSize := StrToInt(t);
15658:
1566td.FontColor := StrToInt(t);
1567end;
1568end;
1569
1570with TextBlocksForm.BlockListBox do
1571begin
1572AddItem(td.Caption, TTextDataObject.Create(td));
1573ItemIndex := k;
1574Checked[k] := StrToBool(s);
1575end;
1576
1577Readln(f, s);
1578m := StrToInt(s); // number of TextLines
1579
1580for l := 0 to m - 1 do
1581begin // read each line
1582Readln(f, s);
1583i := pos(#9, s);
1584with TTextDataObject(TextBlocksForm.BlockListBox.Items.Objects[k]) do
1585begin
1586t := Copy(s, 1, i - 1);
1587c := StrToInt(Copy(s, i + 1, Length(s)));
1588TextLines.Add(TTextLineObject.Create(t, c));
1589end;
1590end;
1591end;
1592
1593with TextBlocksForm do
1594if Visible then
1595begin
1596ShowData(Self);
1597if BlockListBox.Count > 0 then
1598BlockListBoxClick(Self);
1599end;
1600
1601except
1602MessageDlg('File Error! An Error has occurred' +
1603#13#10'when attempting to read "' + FName + '".', mtError, [mbOK], 0);
1604CloseFile(f);
1605Exit;
1606end;
1607CloseFile(f);
1608Result := True;
1609MainForm.GLViewer.Buffer.BackgroundColor := GraphData.BackColor;
1610CheckListBox.ItemIndex := CheckListBox.Count - 1;
1611end;
1612end;
1613
1614procedure TFunctionsForm.WriteData(const FName: TFileName);
1615var
1616f: TextFile;
1617s: string;
1618i, j, TextLineCount: integer;
1619
1620begin
1621try
1622AssignFile(f, FName);
1623try
1624Rewrite(f); { write tab delimited data }
1625with GraphData do
1626begin
1627s := FloatToStr(xMin) + #9 + FloatToStr(yMin) + #9 + FloatToStr(xMax) +
1628#9 + FloatToStr(yMax) + #9 + FloatToStr(SavexMin) + #9 +
1629FloatToStr(SaveyMin) + #9 + FloatToStr(SavexMax) + #9 +
1630FloatToStr(SaveyMax) + #9 + FloatToStr(AreaAlpha) + #9 +
1631FontName + #9;
1632if fsBold in FontStyle then
1633s := s + 'fsBold';
1634if fsItalic in FontStyle then
1635s := s + 'fsItalic';
1636if fsUnderline in FontStyle then
1637s := s + 'fsUnderline';
1638if fsStrikeOut in FontStyle then
1639s := s + 'fsStrikeOut';
1640s := s + #9 + IntToStr(FontSize) + #9 + IntToStr(AxisWidth) + #9 +
1641IntToStr(xMinorGrad) + #9 + IntToStr(yMinorGrad) + #9 +
1642IntToStr(xMajorGrad) + #9 + IntToStr(yMajorGrad) + #9 +
1643IntToStr(MinorWidth) + #9 + IntToStr(MajorWidth) + #9 +
1644IntToStr(CoordWidth) + #9 + IntToStr(dydxWidth) + #9 +
1645IntToStr(d2ydx2Width) + #9 + IntToStr(IntegCount) + #9 +
1646IntToStr(ydxWidth) + #9 + IntToStr(BackColor) + #9 +
1647IntToStr(GridColor) + #9 + IntToStr(xAxisColor) + #9 +
1648IntToStr(yAxisColor) + #9 + IntToStr(CoordColor) + #9 +
1649IntToStr(dydxColor) + #9 + IntToStr(d2ydx2Color) + #9 +
1650IntToStr(ydxColor) + #9 + IntToStr(PosAreaColor) + #9 +
1651IntToStr(NegAreaColor) + #9 + IntToStr(Ord(Grid.xAxisStyle)) + #9 +
1652IntToStr(Ord(Grid.yAxisStyle)) + #9 + IntToStr(Ord(Grid.GridStyle)) +
1653#9 + IntToStr(CheckListBox.Count); { number of functions }
1654end;
1655writeln(f, s);
1656
1657for i := 0 to CheckListBox.Count - 1 do
1658begin { write each function's data }
1659with TPlotDataObject(CheckListBox.Items.Objects[i]).Data do
1660begin
1661FunctStr := Trim(FunctStr);
1662TextStr := Trim(TextStr);
1663s := FunctStr + #9 + TextStr + #9 + FloatToStr(xInc) + #9 +
1664IntToStr(PlotWidth) + #9 + IntToStr(PlotColor) + #9 +
1665FloatToStr(PhiInc) + #9 + FloatToStr(SegMin) + #9 +
1666FloatToStr(SegMax) + #9 + FloatToStr(xLabel) + #9 +
1667FloatToStr(yLabel) + #9 + BoolToStr(ShowLabel) + #9 +
1668BoolToStr(PlotAsFx) + #9 + BoolToStr(IsSegment) + #9 +
1669BoolToStr(IsContinuous) + #9 + BoolToStr(CheckListBox.Checked[i]);
1670end;
1671writeln(f, s);
1672end;
1673
1674with NumericForm do { write each Numeric plot }
1675begin
1676with CheckListBox do
1677begin
1678s := IntToStr(Count);
1679writeln(f, s); { number of numeric graphs }
1680for i := 0 to Count - 1 do
1681begin
1682with TNumericObject(Items.Objects[i]).Data do
1683s := Name + #9 + IntToStr(Ord(NumericStyle)) + #9 +
1684BoolToStr(ShowPoints) + #9 + IntToStr(Ord(PointStyle)) + #9 +
1685IntToStr(PointSize) + #9 + IntToStr(PointColor) + #9 +
1686IntToStr(PlotWidth) + #9 + IntToStr(PlotColor) + #9 +
1687BoolToStr(SortXValue) + #9 + BoolToStr(Extrapolate) + #9 +
1688IntToStr(CoordsIdx) + #9 + IntToStr(CurveRate) + #9;
1689{ was k0 factor = CurveRate/100 }
1690s := s + IntToStr(TNumericObject(Items.Objects[i])
1691.ControlPoints.Count) + #9 + BoolToStr(Checked[i]);
1692writeln(f, s);
1693s := '';
1694with TNumericObject(Items.Objects[i]) do
1695for j := 0 to ControlPoints.Count - 1 do
1696begin
1697with TGraphPointObject(ControlPoints[j]) do
1698s := s + FloatToStr(x_phi) + #9 + FloatToStr(y_r) + #9;
1699end;
1700writeln(f, s);
1701end;
1702end;
1703end;
1704
1705with TextBlocksForm do
1706begin
1707s := IntToStr(BlockListBox.Count);
1708writeln(f, s); { number of TextBlocks }
1709
1710for i := 0 to BlockListBox.Count - 1 do
1711begin { write each TextBlock's data }
1712with TTextDataObject(BlockListBox.Items.Objects[i]).Data do
1713begin
1714Caption := Trim(Caption);
1715s := Caption + #9 + FloatToStr(xLoc) + #9 + FloatToStr(yLoc) + #9 +
1716IntToStr(yInc) + #9 + FontName + #9;
1717if fsBold in FontStyle then
1718s := s + 'fsBold';
1719if fsItalic in FontStyle then
1720s := s + 'fsItalic';
1721if fsUnderline in FontStyle then
1722s := s + 'fsUnderline';
1723if fsStrikeOut in FontStyle then
1724s := s + 'fsStrikeOut';
1725s := s + #9 + IntToStr(FontSize) + #9 + IntToStr(FontColor) + #9 +
1726BoolToStr(BlockListBox.Checked[i]);
1727end;
1728writeln(f, s);
1729
1730with TTextDataObject(BlockListBox.Items.Objects[i]) do
1731begin
1732j := TextLines.Count - 1;
1733while (j >= 0) and (TTextLineObject(TextLines[j]).Text = '') do
1734Dec(j); { remove any traling empty lines }
1735
1736TextLineCount := j + 1;
1737s := IntToStr(TextLineCount);
1738writeln(f, s); { number of TextLines }
1739for j := 0 to TextLineCount - 1 do
1740with TTextLineObject(TextLines[j]) do
1741begin
1742s := Text + #9 + IntToStr(Color);
1743writeln(f, s);
1744end;
1745end;
1746end;
1747end;
1748finally
1749Flush(f);
1750CloseFile(f);
1751end;
1752except
1753MessageDlg('File Error! An Error has occurred' +
1754#13#10'when attempting to write to "' + GraphFName + '".', mtError,
1755[mbOK], 0);
1756end;
1757Altered := false;
1758NewFile := false;
1759end;
1760
1761function TFunctionsForm.DefaultData: TGraphData;
1762begin
1763with Result do
1764begin
1765xMin := -10.2;
1766yMin := -10.2;
1767xMax := 10.75;
1768yMax := 10.95;
1769
1770SavexMin := 0;
1771SavexMax := 0;
1772SaveyMin := 0;
1773SaveyMax := 0;
1774
1775AreaAlpha := 0.25; { transparency of integration area }
1776
1777FontName := 'Tahoma';
1778FontStyle := [];
1779FontSize := 9;
1780
1781AxisWidth := 2; { axis line width }
1782
1783xMinorGrad := 5; { minor X axis graduation lengths }
1784yMinorGrad := 5; { minor Y axis graduation lengths }
1785xMajorGrad := 50; { major X axis graduation lengths }
1786yMajorGrad := 50; { major Y axis graduation lengths }
1787
1788MinorWidth := 1; { minor graduation & grid line width }
1789MajorWidth := 1; { major graduation & grid line width }
1790CoordWidth := 2; { coordinate line width }
1791
1792dydxWidth := 1; { derivative line width }
1793d2ydx2Width := 1; { 2nd derivative line width }
1794IntegCount := 64000; { number of integration intervals }
1795ydxWidth := 1; { integral line width }
1796
1797BackColor := clCream; { paper or background color }
1798GridColor := clSilver; { grid color }
1799xAxisColor := clRed; { xAxis color }
1800yAxisColor := clGreen; { yAxis color }
1801CoordColor := clGray; { coordinate line color }
1802dydxColor := clOlive; { derivative line color }
1803d2ydx2Color := clOlive; { 2nd derivative line color }
1804ydxColor := clTeal; { integral line color }
1805PosAreaColor := clSkyBlue; { positive integral area color }
1806NegAreaColor := clMaroon; { negative integral area color }
1807
1808with Grid do
1809begin
1810GridStyle := gsCartesian;
1811xAxisStyle := asLinear;
1812yAxisStyle := asLinear;
1813end;
1814
1815with PlotData do { each function has these individual values }
1816begin
1817FunctStr := '';
1818TextStr := FunctStr;
1819xInc := 1;
1820PlotWidth := 1;
1821PlotColor := clBlue;
1822PhiInc := 0.1;
1823SegMin := -Pi;
1824SegMax := Pi;
1825xLabel := -0.3;
1826yLabel := 0.1;
1827ShowLabel := True;
1828PlotAsFx := True;
1829IsSegment := false;
1830IsContinuous := false;
1831end;
1832end;
1833end;
1834
1835procedure TFunctionsForm.ShowData(Sender: TObject);
1836var
1837i: integer;
1838fs, ts: string;
1839
1840begin
1841with GraphData, PlotData do
1842begin
1843fs := FunctStr;
1844ts := TextStr;
1845
1846ShowLabelCheckBox.Checked := ShowLabel;
1847SegmentButton.Visible := PlotAsFx;
1848ContinuousCheckBox.Checked := IsContinuous;
1849UpButton.Enabled := CheckListBox.Count > 1;
1850DownButton.Enabled := UpButton.Enabled;
1851DeleteButton.Enabled := UpButton.Enabled;
1852
1853Labelx.Visible := EvaluateButton.Tag = 1;
1854Labely.Visible := Labelx.Visible;
1855EditEvaluate.Visible := Labelx.Visible;
1856EditCoordinate.Visible := Labelx.Visible;
1857UpDown3.Visible := Labelx.Visible;
1858SpeedButton4.Visible := Labelx.Visible;
1859PenPanel.Color := PlotColor;
1860CoordPanel.Color := CoordColor;
1861CoordPanel.Visible := Labelx.Visible;
1862
1863Label11.Visible := Labelx.Visible;
1864
1865SwitchButton.Visible := (Grid.xAxisStyle = asLinear) and
1866(Grid.yAxisStyle = asLinear);
1867
1868if PlotAsFx then
1869begin { plot as y = f(x) }
1870for i := 1 to Length(fs) do
1871if fs[i] = '�' then
1872fs[i] := 'x';
1873for i := 1 to Length(ts) do
1874if ts[i] = '�' then
1875ts[i] := 'x';
1876
1877LabelPhi.Caption := 'Plot x :';
1878with SwitchButton do
1879begin
1880Caption := 'Go to f(�)';
1881Hint := 'Switch to r = f(�)';
1882if not IsSegment then
1883begin
1884Label1.Visible := false;
1885Label2.Visible := false;
1886Label3.Visible := false;
1887end;
1888Tag := 0;
1889end;
1890
1891LabelFunc.Caption := 'y = f(x) = ';
1892Labelx.Caption := 'x =';
1893Labeldx.Caption := 'pixels';
1894
1895LabelRCos.Visible := false;
1896LabelRSin.Visible := false;
1897
1898Editdx.Text := FloatToStrF(xInc, ffGeneral, 7, 4);
1899UpDown1.Visible := True;
1900
1901yfx1.Caption := 'y = f''(x)';
1902yfx2.Caption := 'y = f"(x)';
1903Integrate1.Enabled := True;
1904Integrate2y.Enabled := True;
1905Findx.Enabled := True;
1906try
1907Between1.Enabled := (CheckListBox.Count > 1) and
1908(pos('�', CheckListBox.Items[0]) = 0) and
1909(pos('�', CheckListBox.Items[1]) = 0);
1910except
1911end;
1912
1913Volumex1.Enabled := True;
1914Volumey1.Enabled := True;
1915
1916with SegmentButton do
1917begin
1918if IsSegment then
1919begin
1920Caption := 'Go to Complete';
1921Hint := 'Click to plot whole range.';
1922Label1.Visible := True;
1923Label2.Visible := True;
1924Label3.Visible := True;
1925LabelPhi.Visible := True;
1926EditSegMin.Visible := True;
1927EditSegMax.Visible := True;
1928
1929EditSegMin.Text := FloatToStrF(SegMin, ffGeneral, 13, 4);
1930EditSegMax.Text := FloatToStrF(SegMax, ffGeneral, 13, 4);
1931Tag := 0;
1932end
1933else
1934begin
1935Caption := 'Go to Segment';
1936Hint := 'Click to limit plot range.';
1937Label1.Visible := false;
1938Label2.Visible := false;
1939Label3.Visible := false;
1940LabelPhi.Visible := false;
1941EditSegMin.Visible := false;
1942EditSegMax.Visible := false;
1943Tag := 1;
1944end;
1945end;
1946end { plot as y = f(x) }
1947else
1948begin { plot as r = f(�) }
1949for i := 1 to Length(fs) do
1950if (not CharInSet(fs[i - 1], ['e', 'E'])) and (UpCase(fs[i]) = 'X') then
1951fs[i] := '�';
1952
1953for i := 1 to Length(ts) do
1954if (not CharInSet(ts[i - 1], ['e', 'E'])) and (UpCase(ts[i]) = 'X') then
1955ts[i] := '�';
1956
1957LabelPhi.Visible := True;
1958EditSegMin.Visible := True;
1959EditSegMax.Visible := True;
1960
1961LabelRCos.Visible := Labely.Visible;
1962LabelRSin.Visible := Labely.Visible;
1963
1964LabelPhi.Caption := 'Plot � :';
1965with SwitchButton do
1966begin
1967Caption := 'Go to f(x)';
1968Hint := 'Switch to y = f(x)';
1969Label1.Visible := True;
1970Label2.Visible := True;
1971Label3.Visible := True;
1972Tag := 1;
1973end;
1974
1975LabelFunc.Caption := 'r = f(�) = ';
1976Labelx.Caption := '� =';
1977Labeldx.Caption := 'radians';
1978
1979yfx1.Caption := 'y = f''(�)';
1980yfx2.Caption := 'y = f"(�)';
1981
1982Integrate2y.Enabled := false;
1983Between1.Enabled := false;
1984Volumex1.Enabled := false;
1985Volumey1.Enabled := false;
1986Findx.Enabled := false;
1987
1988Editdx.Text := FloatToStrF(PhiInc, ffGeneral, 7, 4);
1989UpDown1.Visible := false;
1990
1991EditSegMin.Text := FloatToStrF(SegMin, ffGeneral, 13, 4);
1992EditSegMax.Text := FloatToStrF(SegMax, ffGeneral, 13, 4);
1993end; { plot as r = f(�) }
1994
1995FunctStr := fs;
1996TextStr := ts;
1997Editfx.Text := ts;
1998
1999EditLocX.Text := FloatToStrF(xLabel, ffGeneral, 4, 3);
2000EditLocY.Text := FloatToStrF(yLabel, ffGeneral, 4, 3);
2001
2002EditPen.Text := IntToStr(PlotWidth);
2003EditCoordinate.Text := IntToStr(CoordWidth);
2004
2005if Sender = SwitchButton then
2006begin
2007with CheckListBox do
2008begin
2009Items[ItemIndex] := ts;
2010with TPlotDataObject(Items.Objects[ItemIndex]).Data do
2011begin
2012FunctStr := fs;
2013TextStr := ts;
2014end;
2015end;
2016BitBtn2.Visible := false;
2017end;
2018end;
2019end;
2020
2021procedure TFunctionsForm.OpenSelectedFile(Sender: TObject; FName: TFileName);
2022var
2023i: integer;
2024
2025begin
2026if FileExists(FName) then
2027begin
2028Screen.Cursor := crHourglass;
2029CheckListBox.Clear;
2030GraphFName := ExtractFileName(FName);
2031
2032if ReadData(DataPath + GraphFName) then
2033begin
2034if Integrate2x.Checked then
2035CloseIntegrateXForm;
2036if Integrate2y.Checked then
2037CloseIntegrateYForm;
2038if Between1.Checked then
2039CloseBetweenForm;
2040if Volumex1.Checked then
2041CloseVolumeXForm;
2042if Volumey1.Checked then
2043CloseVolumeYForm;
2044
2045Caption := GraphFName;
2046MainForm.Caption := GraphFName;
2047GridOptionsForm.Caption := GraphFName;
2048NumericForm.Caption := GraphFName;
2049TextBlocksForm.Caption := GraphFName;
2050
2051ShowData(Sender);
2052BitBtn2.Visible := false;
2053NewFile := false;
2054Altered := false;
2055(*
2056NewFont needed to initialize GLWinFont.GetCharWidth
2057if the font has been altered, which may or may not be the case,
2058so do it anyway
2059*)
2060NewFont := True;
2061MainForm.GLViewer.Buffer.BackgroundColor := GraphData.BackColor;
2062MainForm.GLViewer.Invalidate;
2063end;
2064
2065GridOptionsForm.ShowData;
2066GridOptionsForm.ApplyBitBtn.Visible := false;
2067DerivativeForm.ShowData;
2068
2069with NumericForm do
2070if Visible then
2071begin
2072SetFocus;
2073ShowData(Sender);
2074CheckListBox.ItemIndex := CheckListBox.Count - 1;
2075if CheckListBox.ItemIndex > -1 then
2076CheckListBoxClick(Sender);
2077end;
2078
2079with TextBlocksForm do
2080if BlockListBox.Count > 0 then
2081UpdateRichLines;
2082Screen.Cursor := crDefault;
2083end
2084else
2085begin
2086MessageDlg('The file' + FName + #13#10'Could not be found.', mtError,
2087[mbOK], 0);
2088Screen.Cursor := crDefault;
2089end;
2090end;
2091
2092procedure TFunctionsForm.CloseIntegrateXForm;
2093begin
2094Integrate2x.Checked := false;
2095Integrate2x.ImageIndex := 3;
2096IntegrateXForm.Close;
2097IntegrateXForm.PlotIntegrated := piCalc;
2098end;
2099
2100procedure TFunctionsForm.CloseIntegrateYForm;
2101begin
2102Integrate2y.Checked := false;
2103Integrate2y.ImageIndex := 4;
2104IntegrateYForm.Close;
2105end;
2106
2107procedure TFunctionsForm.CloseBetweenForm;
2108begin
2109Between1.Checked := false;
2110Between1.ImageIndex := 5;
2111BetweenForm.Close;
2112end;
2113
2114procedure TFunctionsForm.CloseVolumeXForm;
2115begin
2116Volumex1.Checked := false;
2117Volumex1.ImageIndex := 6;
2118VolumeXForm.HideFunctionCheckBox.Checked := false;
2119VolumeXForm.Close;
2120end;
2121
2122procedure TFunctionsForm.CloseVolumeYForm;
2123begin
2124Volumey1.Checked := false;
2125Volumey1.ImageIndex := 7;
2126VolumeYForm.HideFunctionCheckBox.Checked := false;
2127VolumeYForm.Close;
2128end;
2129
2130procedure TFunctionsForm.ClosefxValueForm;
2131begin
2132fxValue.Checked := false;
2133fxValue.ImageIndex := 0;
2134fxValueForm.Close;
2135end;
2136
2137procedure TFunctionsForm.Closefx1ValueForm;
2138begin
2139fx1Value.Checked := false;
2140fx1Value.ImageIndex := 1;
2141fx1ValueForm.Close;
2142end;
2143
2144procedure TFunctionsForm.Closefx2ValueForm;
2145begin
2146fx2Value.Checked := false;
2147fx2Value.ImageIndex := 2;
2148fx2ValueForm.Close;
2149end;
2150
2151procedure TFunctionsForm.ShowCartesianEvaluate;
2152var
2153s: string;
2154
2155begin
2156if EditEvaluate.Text = '' then
2157begin
2158Labely.Caption := 'y = Undefined';
2159LabelRCos.Caption := '';
2160LabelRSin.Caption := '';
2161end
2162else
2163begin
2164s := FloatToStr(yEvaluate);
2165if s = '-INF' then
2166s := 'Infinitely negative';
2167if s = 'INF' then
2168s := 'Infinitely positive';
2169if s = 'NAN' then
2170s := 'Undefined';
2171Labely.Caption := 'y = ' + s;
2172Label12.Caption := '';
2173end;
2174end;
2175
2176procedure TFunctionsForm.ShowPolarEvaluate;
2177var
2178s: string;
2179
2180begin
2181if EditEvaluate.Text = '' then
2182begin
2183Labely.Caption := 'r = Undefined';
2184LabelRCos.Caption := 'x = Undefined';
2185LabelRSin.Caption := 'y = Undefined';
2186end
2187else
2188begin
2189s := FloatToStr(yEvaluate);
2190if s = '-INF' then
2191s := 'Infinitely negative';
2192if s = 'INF' then
2193s := 'Infinitely positive';
2194if s = 'NAN' then
2195s := 'Undefined';
2196Labely.Caption := 'r = ' + s;
2197yCosxEval := yEvaluate * Cos(xEvaluate);
2198ySinxEval := yEvaluate * Sin(xEvaluate);
2199LabelRCos.Caption := 'x = ' + FloatToStr(yCosxEval);
2200LabelRSin.Caption := 'y = ' + FloatToStr(ySinxEval);
2201Label12.Caption := 'Radians';
2202end;
2203end;
2204
2205end.
2206