MathgeomGLS
1681 строка · 47.0 Кб
1unit fFunctions;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11System.ImageList,
12System.UITypes,
13System.Math,
14Vcl.ClipBrd,
15Vcl.Graphics,
16Vcl.Controls,
17Vcl.Forms,
18Vcl.Dialogs,
19Vcl.StdCtrls,
20Vcl.CheckLst,
21Vcl.Buttons,
22Vcl.ComCtrls,
23Vcl.Menus,
24Vcl.ImgList,
25Vcl.ExtCtrls,
26
27GLS.OpenGLTokens,
28GLS.VectorGeometry,
29GLS.Coordinates,
30GLS.Color,
31GLS.VectorTypes,
32
33uGlobal,
34uParser;
35
36type
37TFormFunctions = class(TForm)
38GroupBox1: TGroupBox;
39Label1: TLabel;
40Label2: TLabel;
41Label3: TLabel;
42Label4: TLabel;
43Label5: TLabel;
44Label6: TLabel;
45EditMinX: TEdit;
46EditMaxX: TEdit;
47EditdX: TEdit;
48EditMinY: TEdit;
49EditMaxY: TEdit;
50EditdY: TEdit;
51EditMinZ: TEdit;
52EditMaxZ: TEdit;
53cbZLimit: TCheckBox;
54LabelFunc: TLabel;
55Editfxy: TEdit;
56Label9: TLabel;
57AddButton: TSpeedButton;
58DeleteButton: TSpeedButton;
59CheckListBox: TCheckListBox;
60MainMenu: TMainMenu;
61File1: TMenuItem;
62New1: TMenuItem;
63OpenFile: TMenuItem;
64Save: TMenuItem;
65SaveAs: TMenuItem;
66N1: TMenuItem;
67Exit1: TMenuItem;
68SaveDialog: TSaveDialog;
69OpenDialog: TOpenDialog;
70Label17: TLabel;
71ModeComboBox: TComboBox;
72StyleComboBox: TComboBox;
73ApplyBtn: TBitBtn;
74zCountLabel: TLabel;
75Centre: TSpeedButton;
76UpButton: TSpeedButton;
77DownButton: TSpeedButton;
78cbZCap: TCheckBox;
79GridValues: TSpeedButton;
80Label7: TLabel;
81EditNote: TEdit;
82procedure FormDestroy(Sender: TObject);
83procedure FloatKeyPress(Sender: TObject; var Key: Char);
84procedure fxyKeyPress(Sender: TObject; var Key: Char);
85procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
86procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
87procedure FormClose(Sender: TObject; var Action: TCloseAction);
88procedure AddButtonClick(Sender: TObject);
89procedure SaveClick(Sender: TObject);
90procedure SaveAsClick(Sender: TObject);
91procedure CheckListBoxClick(Sender: TObject);
92procedure DeleteButtonClick(Sender: TObject);
93procedure OpenFileClick(Sender: TObject);
94procedure Exit1Click(Sender: TObject);
95procedure New1Click(Sender: TObject);
96procedure cbZLimitClick(Sender: TObject);
97procedure ModeComboBoxChange(Sender: TObject);
98procedure StyleComboBoxChange(Sender: TObject);
99procedure ApplyBtnClick(Sender: TObject);
100procedure EditfxyClick(Sender: TObject);
101procedure CheckListBoxClickCheck(Sender: TObject);
102procedure EditdXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
103procedure EditdYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
104procedure EditMinXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
105procedure EditMaxXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
106procedure EditMinYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
107procedure EditMaxYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
108procedure EditMinZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
109procedure EditMaxZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
110procedure EditfxyKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
111procedure CentreClick(Sender: TObject);
112procedure UpButtonClick(Sender: TObject);
113procedure DownButtonClick(Sender: TObject);
114procedure FormCreate(Sender: TObject);
115procedure cbZCapClick(Sender: TObject);
116procedure GridValuesClick(Sender: TObject);
117procedure PositiveKeyPress(Sender: TObject; var Key: Char);
118procedure EditNoteClick(Sender: TObject);
119procedure EditNoteKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
120private
121NewFile: Boolean;
122TooManyPoints: integer;
123function ReadData(const FName: TFileName): Boolean;
124procedure OpenSelectedFile(Sender: TObject; FName: TFileName);
125procedure WriteData(const FName: TFileName);
126function DefaultPlotData: TPlotData;
127function DefaultViewData: TViewData;
128function DefaultAddedData: TAddedData;
129procedure ShowData(Sender: TObject);
130procedure AddNewPlot;
131procedure CountzPoints;
132procedure UpdateTPlotDataObject;
133procedure AddRecent(const f: TFileName);
134public
135procedure ReadAndShowInitialData;
136procedure OpenRecentFile(FName: TFileName);
137end;
138
139var
140FormFunctions: TFormFunctions;
141
142// ========================================================================
143implementation
144// ========================================================================
145
146uses
147fPlot2D,
148fPlotColors,
149fEvaluate,
150fCoordOptions,
151fGridColors,
152fGridOptions,
153fDerivativeOptions;
154
155{$R *.dfm}
156
157procedure TFormFunctions.AddButtonClick(Sender: TObject);
158begin
159AddNewPlot;
160end;
161
162procedure TFormFunctions.EditdXKeyUp(Sender: TObject; var Key: Word;
163Shift: TShiftState);
164var
165x: TGLFloat;
166
167begin
168try
169x := StrToFloat(EditdX.Text);
170except
171x := 1.0;
172end;
173PlotData.xInc := x;
174ApplyBtn.Visible := True;
175UpdateTPlotDataObject;
176CountzPoints;
177end;
178
179procedure TFormFunctions.PositiveKeyPress(Sender: TObject; var Key: Char);
180begin
181with Sender as TEdit do
182if not CharInSet(Key, ['+', '0' .. '9', '.', #8]) then
183Key := #0;
184end;
185
186procedure TFormFunctions.EditdYKeyUp(Sender: TObject; var Key: Word;
187Shift: TShiftState);
188var
189y: TGlFloat;
190
191begin
192try
193y := StrToFloat(EditdY.Text);
194except
195y := 1.0;
196end;
197PlotData.yInc := y;
198ApplyBtn.Visible := True;
199UpdateTPlotDataObject;
200CountzPoints;
201end;
202
203procedure TFormFunctions.EditfxyClick(Sender: TObject);
204begin
205FormPlot2D.MousePoint.x := Maxint;
206end;
207
208procedure TFormFunctions.EditfxyKeyUp(Sender: TObject; var Key: Word;
209Shift: TShiftState);
210var
211e: byte;
212
213begin
214if Key <> 13 then
215begin
216PlotData.txtStr := Editfxy.Text;
217PlotData.fxyStr := ScanText(Editfxy.Text);
218ParseAndEvaluate(PlotData.fxyStr, e);
219
220with CheckListBox do
221if (Count > 0) and (ItemIndex > -1) then
222Items[ItemIndex] := PlotData.txtStr;
223ApplyBtn.Visible := e = 0;
224UpdateTPlotDataObject;
225end;
226end;
227
228procedure TFormFunctions.EditKeyDown(Sender: TObject; var Key: Word;
229Shift: TShiftState);
230begin
231if (Key = VK_DELETE) or (Key = VK_BACK) then
232ApplyBtn.Visible := True;
233end;
234
235procedure TFormFunctions.fxyKeyPress(Sender: TObject; var Key: Char);
236begin
237with (Sender as TEdit) do
238begin
239if not CharInSet(UpCase(Key), ParseSet) then
240begin
241Key := #0;
242Exit;
243end;
244if Key = '`' then
245Key := '°';
246end;
247end;
248
249procedure TFormFunctions.GridValuesClick(Sender: TObject);
250var
251DoApply: Boolean;
252
253begin
254with FormGridOptions do
255DoApply := xyLock.Checked and zLock.Checked and MinLock.Checked;
256
257if DoApply then
258begin
259with ViewData.xyGrid.xRange do
260begin
261EditMinX.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
262PlotData.xMin := Minimum;
263EditMaxX.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
264PlotData.xMax := Maximum;
265end;
266
267with ViewData.xyGrid.yRange do
268begin
269EditMinY.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
270PlotData.yMin := Minimum;
271EditMaxY.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
272PlotData.yMax := Maximum;
273end;
274
275with ViewData.xzGrid.zRange do
276begin
277EditMinZ.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
278PlotData.zMin := Minimum;
279EditMaxZ.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
280PlotData.zMax := Maximum;
281end;
282ApplyBtnClick(Sender);
283end;
284end;
285
286procedure TFormFunctions.ModeComboBoxChange(Sender: TObject);
287begin
288PlotData.ViewMode := TViewMode(ModeComboBox.ItemIndex);
289UpdateTPlotDataObject;
290ApplyBtnClick(Sender);
291end;
292
293procedure TFormFunctions.New1Click(Sender: TObject);
294var
295i: integer;
296s: string;
297
298begin
299if Altered or GridColorsAltered or DerivativeAltered then
300case MessageDlg('The current graph''s data has been altered.' +
301#13#10'Do you wish to save the alterations ?', mtConfirmation,
302[mbYes, mbNo, mbCancel], 0) of
303mrYes:
304SaveClick(Sender);
305mrCancel:
306Exit;
307end;
308s := DataPath + GraphFName; // save original FName
309if s <> GraphFName then
310AddRecent(s);
311with CheckListBox do
312begin
313for i := 0 to Items.Count - 1 do
314Items.Objects[i].Free;
315Clear;
316end;
317
318GraphFName := NewFName;
319Caption := GraphFName;
320FormPlot2D.Caption := GraphFName;
321FormGridOptions.Caption := GraphFName;
322FormEvaluate.Caption := GraphFName;
323FormCoords.Caption := GraphFName;
324
325NewFile := True;
326Altered := False;
327ViewData := DefaultViewData;
328PlotData := DefaultPlotData;
329AddedData := DefaultAddedData;
330
331if FormGridColors.Visible then
332FormGridColors.Close;
333if FormPlotColors.Visible then
334FormPlotColors.Close;
335if FormDerivatives.Visible then
336FormDerivatives.Close;
337ApplyBtnClick(Sender);
338
339CheckListBox.AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
340CheckListBox.ItemIndex := CheckListBox.Count - 1;
341CheckListBox.Checked[CheckListBox.ItemIndex] := True;
342
343FormPlot2D.TargetCube.Position.SetPoint(0, 0, 0);
344ShowData(Sender);
345end;
346
347procedure TFormFunctions.OpenFileClick(Sender: TObject);
348var
349i: integer;
350s: string;
351
352begin
353if FormDerivatives.Visible then
354FormDerivatives.Close;
355if FormGridColors.Visible then
356FormGridColors.ShowGridColorData;
357if FormPlotColors.Visible then
358FormPlotColors.ShowPlotColorData;
359if Altered or GridColorsAltered or DerivativeAltered then
360case MessageDlg('The current graph''s data has been altered.' +
361#13#10'Do you wish to save the alterations ?', mtConfirmation,
362[mbYes, mbNo, mbCancel], 0) of
363mrYes:
364SaveClick(Sender);
365mrCancel:
366Exit;
367mrNo:
368begin
369Altered := False;
370GridColorsAltered := False;
371DerivativeAltered := False;
372NewFile := False;
373end
374end;
375
376OpenDialog.InitialDir := DataPath;
377if OpenDialog.Execute then
378begin
379s := DataPath + GraphFName; // save original FName
380DataPath := ExtractFilePath(OpenDialog.FileName);
381DataPath := IncludeTrailingPathDelimiter(DataPath);
382FormPlot2D.MousePoint.x := Maxint;
383GraphFName := ExtractFileName(OpenDialog.FileName);
384if s <> GraphFName then
385AddRecent(s);
386
387for i := 0 to CheckListBox.Items.Count - 1 do
388CheckListBox.Items.Objects[i].Free;
389CheckListBox.Clear;
390
391if ReadData(DataPath + GraphFName) then
392ShowData(Sender);
393ApplyBtnClick(Sender);
394Altered := False;
395GridColorsAltered := False;
396DerivativeAltered := False;
397if FormGridColors.Visible then
398FormGridColors.ShowGridColorData;
399if FormPlotColors.Visible then
400FormPlotColors.ShowPlotColorData;
401end;
402end;
403
404procedure TFormFunctions.EditMaxXKeyUp(Sender: TObject; var Key: Word;
405Shift: TShiftState);
406var
407x: TGlFloat;
408
409begin
410try
411x := StrToFloat(EditMaxX.Text);
412except
413x := 1.0;
414end;
415PlotData.xMax := x;
416ApplyBtn.Visible := True;
417UpdateTPlotDataObject;
418CountzPoints;
419end;
420
421procedure TFormFunctions.EditMaxYKeyUp(Sender: TObject; var Key: Word;
422Shift: TShiftState);
423var
424y: TGlFloat;
425
426begin
427try
428y := StrToFloat(EditMaxY.Text);
429except
430y := 1.0;
431end;
432PlotData.yMax := y;
433ApplyBtn.Visible := True;
434UpdateTPlotDataObject;
435CountzPoints;
436end;
437
438procedure TFormFunctions.EditMaxZKeyUp(Sender: TObject; var Key: Word;
439Shift: TShiftState);
440var
441z: TGLFloat;
442
443begin
444try
445z := StrToFloat(EditMaxZ.Text);
446except
447z := 1.0;
448end;
449PlotData.zMax := z;
450ApplyBtn.Visible := True;
451UpdateTPlotDataObject;
452CountzPoints;
453end;
454
455procedure TFormFunctions.EditMinXKeyUp(Sender: TObject; var Key: Word;
456Shift: TShiftState);
457var
458x: TGlFloat;
459
460begin
461try
462x := StrToFloat(EditMinX.Text);
463except
464x := -1.0;
465end;
466PlotData.xMin := x;
467ApplyBtn.Visible := True;
468UpdateTPlotDataObject;
469CountzPoints;
470end;
471
472procedure TFormFunctions.EditMinYKeyUp(Sender: TObject; var Key: Word;
473Shift: TShiftState);
474var
475y: TGlFloat;
476
477begin
478try
479y := StrToFloat(EditMinY.Text);
480except
481y := -1.0;
482end;
483PlotData.yMin := y;
484ApplyBtn.Visible := True;
485UpdateTPlotDataObject;
486CountzPoints;
487end;
488
489procedure TFormFunctions.EditMinZKeyUp(Sender: TObject; var Key: Word;
490Shift: TShiftState);
491var
492z: TGlFloat;
493
494begin
495try
496z := StrToFloat(EditMinZ.Text);
497except
498z := -1.0;
499end;
500PlotData.zMin := z;
501ApplyBtn.Visible := True;
502UpdateTPlotDataObject;
503CountzPoints;
504end;
505
506procedure TFormFunctions.EditNoteClick(Sender: TObject);
507begin
508FormPlot2D.MousePoint.x := Maxint;
509end;
510
511procedure TFormFunctions.EditNoteKeyUp(Sender: TObject; var Key: Word;
512Shift: TShiftState);
513begin
514if Key <> 13 then
515begin
516PlotData.NoteStr := EditNote.Text;
517with CheckListBox do
518if (Count > 0) and (ItemIndex > -1) then
519TPlotDataObject(Items.Objects[ItemIndex]).Data := PlotData;
520Altered := True;
521end;
522end;
523
524procedure TFormFunctions.Exit1Click(Sender: TObject);
525begin
526FormPlot2D.Exit1Click(Sender);
527end;
528
529procedure TFormFunctions.FloatKeyPress(Sender: TObject; var Key: Char);
530begin
531with Sender as TEdit do
532if not CharInSet(Key, AnyFloat) then
533Key := #0;
534end;
535
536procedure TFormFunctions.FormClose(Sender: TObject; var Action: TCloseAction);
537var
538i: integer;
539
540begin
541for i := 0 to CheckListBox.Items.Count - 1 do
542CheckListBox.Items.Objects[i].Free;
543CheckListBox.Clear;
544end;
545
546procedure TFormFunctions.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
547begin
548FormPlot2D.Close;
549CanClose := not FormPlot2D.Visible;
550end;
551
552procedure TFormFunctions.FormCreate(Sender: TObject);
553begin
554ReportMemoryLeaksOnShutdown := True;
555end;
556
557procedure TFormFunctions.FormDestroy(Sender: TObject);
558var
559i: integer;
560
561begin
562with CheckListBox do
563for i := 0 to Count - 1 do
564Items.Objects[i].Free;
565end;
566
567function TFormFunctions.DefaultPlotData: TPlotData;
568begin
569with Result do
570begin
571fxyStr := ''; // function string
572txtStr := ''; // txt -> fxy when scanned
573NoteStr := ''; // describe function
574xMin := -10.0; // x limits and increment
575xMax := 10.0;
576xInc := 1.0;
577yMin := -10.0; // y limits and increment
578yMax := 10.0;
579yInc := 1.0;
580zMin := -10.0; // z limits
581zMax := 10.0;
582zLim := False; // false = z limits do not apply
583zCap := False; // above zLim values := NAN
584
585UpperColor := VectorMake(255, 0, 0, 1000);
586LowerColor := VectorMake(0, 0, 255, 1000);
587
588ColorBlend := 0.5;
589ColorMove := 0.0;
590ViewMode := vmAmbient;
591fxyMode := fxyFill;
592end;
593end;
594
595function TFormFunctions.DefaultViewData: TViewData;
596begin
597Result.CameraCubeAt := VectorMake(0, 0, 0);
598Result.CameraAt := VectorMake(50, 50, 30);
599Result.fLength := 200;
600Result.LightAt := VectorMake(50, 50, 50);
601Result.ViewDepth := 1000;
602Result.BackColor := clActiveCaption;
603with Result.xyGrid do
604begin
605Color := clrBlue;
606xRange.Maximum := 10;
607xRange.Minimum := -10;
608xRange.Step := 1;
609yRange.Maximum := 10;
610yRange.Minimum := -10;
611yRange.Step := 1;
612zPosition := -10;
613zScale := 1;
614IsVisible := True;
615IsChecked := True;
616end;
617
618with Result.xzGrid do
619begin
620Color := clrGreen;
621xRange.Maximum := 10;
622xRange.Minimum := -10;
623xRange.Step := 1;
624zRange.Maximum := 10;
625zRange.Minimum := -10;
626zRange.Step := 1;
627yPosition := -10;
628IsVisible := True;
629IsChecked := True;
630end;
631
632with Result.yzGrid do
633begin
634Color := clrRed;
635yRange.Maximum := 10;
636yRange.Minimum := -10;
637yRange.Step := 1;
638zRange.Maximum := 10;
639zRange.Minimum := -10;
640zRange.Step := 1;
641xPosition := -10;
642IsVisible := True;
643IsChecked := True;
644end;
645
646Result.xEvaluate := 0.0;
647Result.yEvaluate := 0.0;
648Result.CoordChecked := False;
649Result.ToGridsChecked := False;
650Result.dzdx_dyChecked := False;
651Result.BoxChecked := False;
652Result.CoordWidth := 1;
653Result.CoordColor := clBlack;
654Result.BoxLnWidth := 1;
655Result.BoxLnColor := clrBlack;
656
657Result.TextVisible := False;
658Result.TextFontN := 'Tahoma';
659Result.TextFontSz := 10;
660Result.xPosYMax := False;
661Result.xPosZMax := False;
662Result.xTextColor := clBlack;
663
664Result.yPosXMax := False;
665Result.yPosZMax := False;
666Result.yTextColor := clBlack;
667
668Result.TextVisible := True;
669Result.TextFontN := 'Tahoma'; // FormPlot2D.GLWinBitmapFont
670Result.TextFontSz := 20;
671
672Result.xPosYMax := False;
673Result.xPosZMax := False;
674Result.xTextColor := clRed;
675
676Result.yPosXMax := False;
677Result.yPosZMax := False;
678Result.yTextColor := clGreen;
679
680Result.zPosXMax := False;
681Result.zPosYMax := False;
682Result.zTextColor := clBlue;
683Result.ArrowSize := 1.0;
684end;
685
686function TFormFunctions.DefaultAddedData: TAddedData;
687begin
688Result.xMin := -10.0; // x limits and increment
689Result.xMax := 10.0;
690Result.xInc := 1.0;
691Result.yMin := -10.0; // y limits and increment
692Result.yMax := 10.0;
693Result.yInc := 1.0;
694Result.zMin := -10.0; // z limits
695Result.zMax := 10.0;
696Result.zLim := False; // false = z limits do not apply
697Result.zCap := False; // above zLim values := NAN
698
699Result.UpperColor := VectorMake(255, 0, 0, 1000);
700Result.LowerColor := VectorMake(0, 0, 255, 1000);
701
702Result.ColorBlend := 0.5;
703Result.ColorMove := 0.0;
704Result.ViewMode := vmAmbient;
705Result.fxyMode := fxyFill;
706
707Result.AddLineWidth := 1;
708Result.AddLineColor := clBlack;
709Result.AddedAs := AddNone;
710end;
711
712procedure TFormFunctions.CountzPoints;
713var
714n: integer;
715
716begin
717n := round((PlotData.xMax - PlotData.xMin + PlotData.xInc) / PlotData.xInc) *
718round((PlotData.yMax - PlotData.yMin + PlotData.yInc) / PlotData.yInc);
719TooManyPoints := round(Log10(n));
720case TooManyPoints of
7210 .. 2:
722zCountLabel.Font.Color := clLime;
7233:
724zCountLabel.Font.Color := clTeal;
7254:
726zCountLabel.Font.Color := clGreen;
7275:
728zCountLabel.Font.Color := clBlue;
729else
730zCountLabel.Font.Color := clRed;
731end;
732if TooManyPoints > 6 then
733zCountLabel.Caption := 'Too many Points: ' + FloatToStrF(n, ffnumber,
7348, 0) + ' !'
735else
736zCountLabel.Caption := 'N° Points = ' + FloatToStrF(n, ffnumber, 8, 0);
737end;
738
739procedure TFormFunctions.UpdateTPlotDataObject;
740begin
741TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data := PlotData;
742end;
743
744procedure TFormFunctions.DeleteButtonClick(Sender: TObject);
745var
746i: integer;
747
748begin
749if CheckListBox.Count > 1 then
750begin
751i := CheckListBox.ItemIndex;
752with CheckListBox.Items.Objects[i] as TPlotDataObject do
753Free;
754CheckListBox.Items.Delete(i);
755if i > CheckListBox.Count - 1 then
756i := CheckListBox.Count - 1;
757CheckListBox.ItemIndex := i;
758PlotData := TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data;
759DeleteButton.Enabled := CheckListBox.Count > 1;
760ApplyBtnClick(Sender);
761end
762end;
763
764procedure TFormFunctions.DownButtonClick(Sender: TObject);
765var
766i: integer;
767
768begin
769i := CheckListBox.ItemIndex;
770if i < CheckListBox.Count - 1 then
771CheckListBox.Items.Move(i, i + 1);
772CheckListBox.ItemIndex := i + 1;
773CheckListBoxClick(Sender);
774Altered := True;
775end;
776
777function TFormFunctions.ReadData(const FName: TFileName): Boolean;
778
779function StrToVector(s: string): TGLVector;
780var
781t: string;
782i: integer;
783
784begin
785i := Pos(',', s);
786t := Copy(s, 1, i - 1);
787TryStrToFloat(t, Result.x);
788
789s := Copy(s, i + 1, Length(s));
790i := Pos(',', s);
791t := Copy(s, 1, i - 1);
792TryStrToFloat(t, Result.y);
793
794s := Copy(s, i + 1, Length(s));
795TryStrToFloat(t, Result.z);
796end;
797
798function StrToColor(s: string): TGLColorVector;
799var
800t: string;
801i: integer;
802
803begin
804i := Pos(',', s);
805t := Copy(s, 1, i - 1);
806TryStrToFloat(t, Result.x);
807
808s := Copy(s, i + 1, Length(s));
809i := Pos(',', s);
810t := Copy(s, 1, i - 1);
811TryStrToFloat(t, Result.y);
812
813s := Copy(s, i + 1, Length(s));
814i := Pos(',', s);
815t := Copy(s, 1, i - 1);
816TryStrToFloat(t, Result.z);
817
818s := Copy(s, i + 1, Length(s));
819TryStrToFloat(t, Result.W);
820end;
821
822function StrToRange(s: string): TRange;
823var
824t: string;
825i: integer;
826
827begin
828i := Pos(',', s);
829t := Copy(s, 1, i - 1);
830TryStrToFloat(t, Result.Maximum);
831
832s := Copy(s, i + 1, Length(s));
833i := Pos(',', s);
834t := Copy(s, 1, i - 1);
835TryStrToFloat(t, Result.Minimum);
836
837s := Copy(s, i + 1, Length(s));
838TryStrToFloat(t, Result.Step);
839end;
840
841var
842s, t: string;
843f: TextFile;
844i, j, k, n: integer;
845
846begin
847Result := False;
848if FileExists(FName) then
849begin
850AssignFile(f, FName);
851try
852Reset(f);
853Readln(f, s);
854j := 0;
855i := Pos(#9, s);
856
857while i > 0 do
858begin
859t := Copy(s, 1, i - 1);
860s := Copy(s, i + 1, Length(s));
861i := Pos(#9, s);
862Inc(j);
863
864case j of
8651:
866ViewData.CameraCubeAt := StrToVector(t);
8672:
868ViewData.CameraAt := StrToVector(t);
8693:
870TryStrToFloat(t, ViewData.fLength);
8714:
872ViewData.LightAt := StrToVector(t);
8735:
874TryStrToFloat(t, ViewData.ViewDepth);
8756:
876ViewData.BackColor := StrToInt(t);
8777:
878ViewData.xyGrid.Color := StrToColor(t);
8798:
880ViewData.xyGrid.xRange := StrToRange(t);
8819:
882ViewData.xyGrid.yRange := StrToRange(t);
88310:
884TryStrToFloat(t, ViewData.xyGrid.zPosition);
88511:
886TryStrToFloat(t, ViewData.xyGrid.zScale);
88712:
888ViewData.xyGrid.IsVisible := StrToBool(t);
88913:
890ViewData.xyGrid.IsChecked := StrToBool(t);
89114:
892ViewData.xzGrid.Color := StrToColor(t);
89315:
894ViewData.xzGrid.xRange := StrToRange(t);
89516:
896ViewData.xzGrid.zRange := StrToRange(t);
89717:
898TryStrToFloat(t, ViewData.xzGrid.yPosition);
89918:
900ViewData.xzGrid.IsVisible := StrToBool(t);
90119:
902ViewData.xzGrid.IsChecked := StrToBool(t);
90320:
904ViewData.yzGrid.Color := StrToColor(t);
90521:
906ViewData.yzGrid.yRange := StrToRange(t);
90722:
908ViewData.yzGrid.zRange := StrToRange(t);
90923:
910TryStrToFloat(t, ViewData.yzGrid.xPosition);
91124:
912ViewData.yzGrid.IsVisible := StrToBool(t);
91325:
914ViewData.yzGrid.IsChecked := StrToBool(t);
91526:
916FormPlot2D.TargetCube.Position.AsVector := StrToVector(t);
91727:
918TryStrToFloat(t, ViewData.xEvaluate);
91928:
920TryStrToFloat(t, ViewData.yEvaluate);
92129:
922ViewData.CoordChecked := StrToBool(t);
92330:
924ViewData.ToGridsChecked := StrToBool(t);
92531:
926ViewData.dzdx_dyChecked := StrToBool(t);
92732:
928ViewData.BoxChecked := StrToBool(t);
92933:
930ViewData.CoordWidth := StrToInt(t);
93134:
932ViewData.CoordColor := StrToInt(t);
93335:
934ViewData.BoxLnWidth := StrToInt(t);
93536:
936ViewData.BoxLnColor := StrToColor(t);
93737:
938ViewData.TextVisible := StrToBool(t);
93938:
940ViewData.TextFontN := t;
94139:
942ViewData.TextFontSz := StrToInt(t);
94340:
944ViewData.xPosYMax := StrToBool(t);
94541:
946ViewData.xPosZMax := StrToBool(t);
94742:
948ViewData.xTextColor := StrToInt(t);
94943:
950ViewData.yPosXMax := StrToBool(t);
95144:
952ViewData.yPosZMax := StrToBool(t);
95345:
954ViewData.yTextColor := StrToInt(t);
95546:
956ViewData.zPosXMax := StrToBool(t);
95747:
958ViewData.zPosYMax := StrToBool(t);
95948:
960ViewData.zTextColor := StrToInt(t);
96149:
962TryStrToFloat(t, ViewData.ArrowSize);
963end;
964end;
965n := StrToInt(s); // number of functions
966for k := 0 to n - 1 do
967begin // read each function's data
968Readln(f, s);
969j := 0;
970i := Pos(#9, s);
971while i > 0 do
972begin
973t := Copy(s, 1, i - 1);
974s := Copy(s, i + 1, Length(s));
975i := Pos(#9, s);
976Inc(j);
977with PlotData do
978case j of
9791:
980fxyStr := t;
9812:
982txtStr := t;
9833:
984NoteStr := t;
9854:
986TryStrToFloat(t, xMin);
9875:
988TryStrToFloat(t, xMax);
9896:
990TryStrToFloat(t, xInc);
9917:
992TryStrToFloat(t, yMin);
9938:
994TryStrToFloat(t, yMax);
9959:
996TryStrToFloat(t, yInc);
99710:
998TryStrToFloat(t, zMin);
99911:
1000TryStrToFloat(t, zMax);
100112:
1002zLim := StrToBool(t);
100313:
1004zCap := StrToBool(t);
100514:
1006UpperColor := StrToColor(t);
100715:
1008LowerColor := StrToColor(t);
100916:
1010ColorBlend := StrToFloat(t); // TryStrToFloat(t, ColorBlend);
101117:
1012ColorMove := StrToFloat(t); // TryStrToFloat(t, ColorMove);
101318:
1014ViewMode := TViewMode(StrToInt(t));
101519:
1016fxyMode := TfxyMode(StrToInt(t));
1017end;
1018end;
1019CheckListBox.AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
1020CheckListBox.Checked[CheckListBox.Count - 1] := StrToBool(s);
1021end;
1022Readln(f, s);
1023j := 0;
1024i := Pos(#9, s);
1025while i > 0 do
1026begin
1027t := Copy(s, 1, i - 1);
1028s := Copy(s, i + 1, Length(s));
1029i := Pos(#9, s);
1030Inc(j);
1031with AddedData do
1032case j of
10331:
1034TryStrToFloat(t, xMin);
10352:
1036TryStrToFloat(t, xMax);
10373:
1038TryStrToFloat(t, xInc);
10394:
1040TryStrToFloat(t, yMin);
10415:
1042TryStrToFloat(t, yMax);
10436:
1044TryStrToFloat(t, yInc);
10457:
1046TryStrToFloat(t, zMin);
10478:
1048TryStrToFloat(t, zMax);
10499:
1050zLim := StrToBool(t);
105110:
1052zCap := StrToBool(t);
105311:
1054UpperColor := StrToColor(t);
105512:
1056LowerColor := StrToColor(t);
105713:
1058TryStrToFloat(t, ColorBlend);
105914:
1060TryStrToFloat(t, ColorMove);
106115:
1062ViewMode := TViewMode(StrToInt(t));
106316:
1064fxyMode := TfxyMode(StrToInt(t));
106517:
1066TryStrToInt(t, AddLineWidth);
106718:
1068TryStrToInt(t, AddLineColor);
106919:
1070AddedAs := TAddedType(StrToInt(t));
1071end;
1072end;
1073
1074except
1075MessageDlg('File Error! An Error has occurred' +
1076#13#10'when attempting to read "' + FName + '".', mtError, [mbOK], 0);
1077CloseFile(f);
1078Exit;
1079end;
1080CloseFile(f);
1081Result := True;
1082CheckListBox.ItemIndex := CheckListBox.Count - 1;
1083NewFile := not Result;
1084end;
1085end;
1086
1087procedure TFormFunctions.SaveClick(Sender: TObject);
1088begin
1089if NewFile then
1090SaveAsClick(Sender)
1091else
1092WriteData(DataPath + GraphFName);
1093end;
1094
1095procedure TFormFunctions.SaveAsClick(Sender: TObject);
1096begin
1097SaveDialog.InitialDir := DataPath;
1098SaveDialog.FileName := GraphFName;
1099if SaveDialog.Execute then
1100begin
1101GraphFName := ExtractFileName(SaveDialog.FileName);
1102DataPath := ExtractFilePath(SaveDialog.FileName);
1103DataPath := IncludeTrailingPathDelimiter(DataPath);
1104WriteData(DataPath + GraphFName);
1105end;
1106Caption := GraphFName;
1107FormPlot2D.Caption := GraphFName;
1108FormGridOptions.Caption := GraphFName;
1109FormEvaluate.Caption := GraphFName;
1110FormCoords.Caption := GraphFName;
1111end;
1112
1113procedure TFormFunctions.WriteData(const FName: TFileName);
1114function VectorToStr(v: TGLVector): string;
1115begin
1116Result := FloatToStr(v.x) + ',' + FloatToStr(v.y) + ',' + FloatToStr(v.z);
1117end;
1118
1119function ColorToStr(c: TGLColorVector): string;
1120begin
1121Result := FloatToStr(c.x) + ',' + FloatToStr(c.y) + ',' + FloatToStr(c.z) +
1122',' + FloatToStr(c.W);
1123end;
1124
1125function RangetoStr(r: TRange): string;
1126begin
1127Result := FloatToStr(r.Maximum) + ',' + FloatToStr(r.Minimum) + ',' +
1128FloatToStr(r.Step);
1129end;
1130
1131var
1132f: TextFile;
1133s: string;
1134i: integer;
1135
1136begin
1137try
1138AssignFile(f, FName);
1139try
1140Rewrite(f); { write tab delimited data }
1141with ViewData do
1142begin
1143CameraCubeAt := FormPlot2D.CameraCube.Position.AsVector;
1144CameraAt := FormPlot2D.Camera.Position.AsVector;
1145fLength := FormPlot2D.Camera.FocalLength;
1146LightAt := FormPlot2D.GLLight.Position.AsVector;
1147ViewDepth := FormPlot2D.Camera.DepthOfView;
1148BackColor := FormPlot2D.GLSViewer.Buffer.BackgroundColor;
1149
1150s := VectorToStr(CameraCubeAt) + #9 + VectorToStr(CameraAt) + #9 +
1151FloatToStr(fLength) + #9 + VectorToStr(LightAt) + #9 +
1152FloatToStr(ViewDepth) + #9 + IntToStr(BackColor) + #9 +
1153{ xy }
1154ColorToStr(xyGrid.Color) + #9 + RangetoStr(xyGrid.xRange) + #9 +
1155RangetoStr(xyGrid.yRange) + #9 + FloatToStr(xyGrid.zPosition) + #9 +
1156FloatToStr(xyGrid.zScale) + #9 + BoolToStr(xyGrid.IsVisible) + #9 +
1157BoolToStr(xyGrid.IsChecked) + #9 +
1158{ xz }
1159ColorToStr(xzGrid.Color) + #9 + RangetoStr(xzGrid.xRange) + #9 +
1160RangetoStr(xzGrid.zRange) + #9 + FloatToStr(xzGrid.yPosition) + #9 +
1161BoolToStr(xzGrid.IsVisible) + #9 + BoolToStr(xzGrid.IsChecked) + #9 +
1162{ yz }
1163ColorToStr(yzGrid.Color) + #9 + RangetoStr(yzGrid.yRange) + #9 +
1164RangetoStr(yzGrid.zRange) + #9 + FloatToStr(yzGrid.xPosition) + #9 +
1165BoolToStr(yzGrid.IsVisible) + #9 + BoolToStr(yzGrid.IsChecked) + #9 +
1166{ Target }
1167VectorToStr(FormPlot2D.TargetCube.Position.AsVector) + #9 +
1168
1169FloatToStr(xEvaluate) + #9 + FloatToStr(yEvaluate) + #9 +
1170BoolToStr(CoordChecked) + #9 + BoolToStr(ToGridsChecked) + #9 +
1171BoolToStr(dzdx_dyChecked) + #9 + BoolToStr(BoxChecked) + #9 +
1172IntToStr(CoordWidth) + #9 + IntToStr(CoordColor) + #9 +
1173IntToStr(BoxLnWidth) + #9 + ColorToStr(BoxLnColor) + #9 +
1174BoolToStr(TextVisible) + #9 + TextFontN + #9 + IntToStr(TextFontSz) +
1175#9 + BoolToStr(xPosYMax) + #9 + BoolToStr(xPosZMax) + #9 +
1176IntToStr(xTextColor) + #9 + BoolToStr(yPosXMax) + #9 +
1177BoolToStr(yPosZMax) + #9 + IntToStr(yTextColor) + #9 +
1178BoolToStr(zPosXMax) + #9 + BoolToStr(zPosYMax) + #9 +
1179IntToStr(zTextColor) + #9 + FloatToStr(ArrowSize) + #9 +
1180IntToStr(CheckListBox.Count); { number of functions }
1181end;
1182writeln(f, s);
1183
1184for i := 0 to CheckListBox.Count - 1 do { each function }
1185begin
1186PlotData := TPlotDataObject(CheckListBox.Items.Objects[i]).Data;
1187with PlotData do
1188begin
1189s := fxyStr + #9 + txtStr + #9 + NoteStr + #9 + FloatToStr(xMin) + #9
1190+ FloatToStr(xMax) + #9 + FloatToStr(xInc) + #9 + FloatToStr(yMin) +
1191#9 + FloatToStr(yMax) + #9 + FloatToStr(yInc) + #9 +
1192FloatToStr(zMin) + #9 + FloatToStr(zMax) + #9 + BoolToStr(zLim) + #9
1193+ BoolToStr(zCap) + #9 + ColorToStr(UpperColor) + #9 +
1194ColorToStr(LowerColor) + #9 + FloatToStr(ColorBlend) + #9 +
1195FloatToStr(ColorMove) + #9 + IntToStr(Ord(ViewMode)) + #9 +
1196IntToStr(Ord(fxyMode)) + #9 + BoolToStr(CheckListBox.Checked[i]);
1197end;
1198writeln(f, s);
1199end;
1200
1201with AddedData do
1202begin
1203s := FloatToStr(xMin) + #9 + FloatToStr(xMax) + #9 + FloatToStr(xInc) +
1204#9 + FloatToStr(yMin) + #9 + FloatToStr(yMax) + #9 + FloatToStr(yInc)
1205+ #9 + FloatToStr(zMin) + #9 + FloatToStr(zMax) + #9 + BoolToStr(zLim)
1206+ #9 + BoolToStr(zCap) + #9 + ColorToStr(UpperColor) + #9 +
1207ColorToStr(LowerColor) + #9 + FloatToStr(ColorBlend) + #9 +
1208FloatToStr(ColorMove) + #9 + IntToStr(Ord(ViewMode)) + #9 +
1209IntToStr(Ord(fxyMode)) + #9 + IntToStr(AddLineWidth) + #9 +
1210IntToStr(AddLineColor) + #9 + IntToStr(Ord(AddedAs));
1211end;
1212writeln(f, s);
1213finally
1214Flush(f);
1215CloseFile(f);
1216end;
1217except
1218MessageDlg('File Error! An Error has occurred' +
1219#13#10'when attempting to write to "' + GraphFName + '".', mtError,
1220[mbOK], 0);
1221end;
1222NewFile := False;
1223Altered := False;
1224Layout.CurrentGraphFName := GraphFName;
1225end;
1226
1227procedure TFormFunctions.cbZCapClick(Sender: TObject);
1228begin
1229PlotData.zCap := cbZCap.Checked;
1230UpdateTPlotDataObject;
1231ApplyBtn.Visible := True;
1232end;
1233
1234procedure TFormFunctions.cbZLimitClick(Sender: TObject);
1235begin
1236PlotData.zLim := cbZLimit.Checked;
1237UpdateTPlotDataObject;
1238ApplyBtn.Visible := True;
1239end;
1240
1241procedure TFormFunctions.ShowData(Sender: TObject);
1242begin
1243if not(Sender is TCheckListBox) then
1244begin
1245FormPlot2D.CameraCube.Position.AsVector := ViewData.CameraCubeAt;
1246FormPlot2D.Camera.Position.AsVector := ViewData.CameraAt;
1247FormPlot2D.Camera.FocalLength := ViewData.fLength;
1248FormPlot2D.GLLight.Position.AsVector := ViewData.LightAt;
1249FormPlot2D.Camera.DepthOfView := ViewData.ViewDepth;
1250FormPlot2D.GLSViewer.Buffer.BackgroundColor := ViewData.BackColor;
1251end;
1252
1253FormGridOptions.EditViewDepth.Text :=
1254FloatToStrF(ViewData.ViewDepth, ffGeneral, 7, 4);
1255
1256// xy
1257FormGridOptions.EditxyGridMinx.Text := FloatToStrF(ViewData.xyGrid.xRange.Minimum,
1258ffGeneral, 7, 4);
1259FormPlot2D.GLxyGrid.XSamplingScale.Min := ViewData.xyGrid.xRange.Minimum;
1260FormGridOptions.EditxyGridMiny.Text := FloatToStrF(ViewData.xyGrid.yRange.Minimum,
1261ffGeneral, 7, 4);
1262FormPlot2D.GLxyGrid.YSamplingScale.Min := ViewData.xyGrid.yRange.Minimum;
1263
1264FormGridOptions.EditxyGridMaxx.Text := FloatToStrF(ViewData.xyGrid.xRange.Maximum,
1265ffGeneral, 7, 4);
1266FormPlot2D.GLxyGrid.XSamplingScale.Max := ViewData.xyGrid.xRange.Maximum;
1267FormGridOptions.EditxyGridMaxy.Text := FloatToStrF(ViewData.xyGrid.yRange.Maximum,
1268ffGeneral, 7, 4);
1269FormPlot2D.GLxyGrid.YSamplingScale.Max := ViewData.xyGrid.yRange.Maximum;
1270
1271FormGridOptions.EditxyGridStpx.Text := FloatToStrF(ViewData.xyGrid.xRange.Step,
1272ffGeneral, 7, 4);
1273FormPlot2D.GLxyGrid.XSamplingScale.Step := ViewData.xyGrid.xRange.Step;
1274FormGridOptions.EditxyGridStpy.Text := FloatToStrF(ViewData.xyGrid.yRange.Step,
1275ffGeneral, 7, 4);
1276FormPlot2D.GLxyGrid.YSamplingScale.Step := ViewData.xyGrid.yRange.Step;
1277
1278FormGridOptions.EditxyGridPosz.Text := FloatToStrF(ViewData.xyGrid.zPosition,
1279ffGeneral, 7, 4);
1280FormPlot2D.GLxyGrid.Position.z := ViewData.xyGrid.zPosition * ViewData.xyGrid.zScale;
1281
1282FormGridOptions.EditzScale.Text := FloatToStrF(ViewData.xyGrid.zScale,
1283ffGeneral, 7, 4);
1284FormPlot2D.GLxzGrid.Scale.z := ViewData.xyGrid.zScale;
1285FormPlot2D.GLyzGrid.Scale.z := ViewData.xyGrid.zScale;
1286
1287FormPlot2D.GLxyGrid.LineColor.SetColor(ViewData.xyGrid.Color.x, ViewData.xyGrid.Color.y,
1288ViewData.xyGrid.Color.z, ViewData.xyGrid.Color.W);
1289
1290// xz
1291FormGridOptions.EditxzGridMinx.Text := FloatToStrF(ViewData.xzGrid.xRange.Minimum,
1292ffGeneral, 7, 4);
1293FormPlot2D.GLxzGrid.XSamplingScale.Min := ViewData.xzGrid.xRange.Minimum;
1294FormGridOptions.EditxzGridMinz.Text := FloatToStrF(ViewData.xzGrid.zRange.Minimum,
1295ffGeneral, 7, 4);
1296FormPlot2D.GLxzGrid.ZSamplingScale.Min := ViewData.xzGrid.zRange.Minimum;
1297
1298FormGridOptions.EditxzGridMaxx.Text := FloatToStrF(ViewData.xzGrid.xRange.Maximum,
1299ffGeneral, 7, 4);
1300FormPlot2D.GLxzGrid.XSamplingScale.Max := ViewData.xzGrid.xRange.Maximum;
1301FormGridOptions.EditxzGridMaxz.Text := FloatToStrF(ViewData.xzGrid.zRange.Maximum,
1302ffGeneral, 7, 4);
1303FormPlot2D.GLxzGrid.ZSamplingScale.Max := ViewData.xzGrid.zRange.Maximum;
1304
1305FormGridOptions.EditxzGridStpx.Text := FloatToStrF(ViewData.xzGrid.xRange.Step,
1306ffGeneral, 7, 4);
1307FormPlot2D.GLxzGrid.XSamplingScale.Step := ViewData.xzGrid.xRange.Step;
1308FormGridOptions.EditxzGridStpz.Text := FloatToStrF(ViewData.xzGrid.zRange.Step,
1309ffGeneral, 7, 4);
1310FormPlot2D.GLxzGrid.ZSamplingScale.Step := ViewData.xzGrid.zRange.Step;
1311
1312FormGridOptions.EditxzGridPosy.Text := FloatToStrF(ViewData.xzGrid.yPosition,
1313ffGeneral, 7, 4);
1314FormPlot2D.GLxzGrid.Position.y := ViewData.xzGrid.yPosition;
1315
1316FormPlot2D.GLxzGrid.LineColor.SetColor(ViewData.xzGrid.Color.x, ViewData.xzGrid.Color.y,
1317ViewData.xzGrid.Color.z, ViewData.xzGrid.Color.W);
1318
1319// yz
1320FormGridOptions.EdityzGridMiny.Text := FloatToStrF(ViewData.yzGrid.yRange.Minimum,
1321ffGeneral, 7, 4);
1322FormPlot2D.GLyzGrid.YSamplingScale.Min := ViewData.yzGrid.yRange.Minimum;
1323FormGridOptions.EdityzGridMinz.Text := FloatToStrF(ViewData.yzGrid.zRange.Minimum,
1324ffGeneral, 7, 4);
1325FormPlot2D.GLyzGrid.ZSamplingScale.Min := ViewData.yzGrid.zRange.Minimum;
1326
1327FormGridOptions.EdityzGridMaxy.Text := FloatToStrF(ViewData.yzGrid.yRange.Maximum,
1328ffGeneral, 7, 4);
1329FormPlot2D.GLyzGrid.YSamplingScale.Max := ViewData.yzGrid.yRange.Maximum;
1330FormGridOptions.EdityzGridMaxz.Text := FloatToStrF(ViewData.yzGrid.zRange.Maximum,
1331ffGeneral, 7, 4);
1332FormPlot2D.GLyzGrid.ZSamplingScale.Max := ViewData.yzGrid.zRange.Maximum;
1333
1334FormGridOptions.EdityzGridStpy.Text := FloatToStrF(ViewData.yzGrid.yRange.Step,
1335ffGeneral, 7, 4);
1336FormPlot2D.GLyzGrid.YSamplingScale.Step := ViewData.yzGrid.yRange.Step;
1337FormGridOptions.EdityzGridStpz.Text := FloatToStrF(ViewData.yzGrid.zRange.Step,
1338ffGeneral, 7, 4);
1339FormPlot2D.GLyzGrid.ZSamplingScale.Step := ViewData.yzGrid.zRange.Step;
1340FormGridOptions.EdityzGridPosx.Text := FloatToStrF(ViewData.yzGrid.xPosition,
1341ffGeneral, 7, 4);
1342FormPlot2D.GLyzGrid.Position.x := ViewData.yzGrid.xPosition;
1343FormPlot2D.GLyzGrid.LineColor.SetColor(ViewData.yzGrid.Color.x, ViewData.yzGrid.Color.y,
1344ViewData.yzGrid.Color.z, ViewData.yzGrid.Color.W);
1345FormPlot2D.BoxLine1.LineColor.SetColor(ViewData.BoxLnColor.x, ViewData.BoxLnColor.y,
1346ViewData.BoxLnColor.z, ViewData.BoxLnColor.W);
1347
1348FormPlot2D.BoxLine2.LineColor := FormPlot2D.BoxLine1.LineColor;
1349FormPlot2D.BoxLine3.LineColor := FormPlot2D.BoxLine1.LineColor;
1350FormPlot2D.BoxLine4.LineColor := FormPlot2D.BoxLine1.LineColor;
1351
1352FormGridOptions.xyGridCB.Checked := ViewData.xyGrid.IsVisible;
1353FormGridOptions.xyLock.Checked := ViewData.xyGrid.IsChecked;
1354FormPlot2D.GLxyGrid.Visible := ViewData.xyGrid.IsVisible;
1355
1356FormGridOptions.xzGridCB.Checked := ViewData.xzGrid.IsVisible;
1357FormGridOptions.zLock.Checked := ViewData.xzGrid.IsChecked;
1358FormPlot2D.GLxzGrid.Visible := ViewData.xzGrid.IsVisible;
1359
1360FormGridOptions.yzGridCB.Checked := ViewData.yzGrid.IsVisible;
1361FormGridOptions.MinLock.Checked := ViewData.yzGrid.IsChecked;
1362FormPlot2D.GLyzGrid.Visible := ViewData.yzGrid.IsVisible;
1363
1364FormGridOptions.EditzScale.Text := FloatToStrF(ViewData.xyGrid.zScale,
1365ffGeneral, 7, 4);
1366FormPlot2D.GLxzGrid.Scale.z := ViewData.xyGrid.zScale;
1367FormPlot2D.GLyzGrid.Scale.z := ViewData.xyGrid.zScale;
1368
1369FormGridOptions.BoxOutlineCB.Checked := ViewData.BoxChecked;
1370FormGridOptions.EditBoxLnWidth.Text := IntToStr(ViewData.BoxLnWidth);
1371FormGridOptions.DrawOutline(ViewData.BoxChecked);
1372
1373FormEvaluate.EditX.Text := FloatToStrF(ViewData.xEvaluate, ffGeneral, 7, 4);
1374FormEvaluate.EditY.Text := FloatToStrF(ViewData.yEvaluate, ffGeneral, 7, 4);
1375FormEvaluate.EditZ.Text := '';
1376FormEvaluate.EditCoordWidth.Text := IntToStr(ViewData.CoordWidth);
1377FormEvaluate.Coordinates.Checked := ViewData.CoordChecked;
1378FormEvaluate.ToGrids.Checked := ViewData.ToGridsChecked;
1379FormEvaluate.dzdx_dzdy.Checked := ViewData.dzdx_dyChecked;
1380FormEvaluate.ColorDialog.Color := ViewData.CoordColor;
1381FormEvaluate.UpdateCoords;
1382FormEvaluate.UpdateEvaluate;
1383
1384FormCoords.cbShowCoords.Checked := ViewData.TextVisible;
1385FormCoords.FontButton.Caption := 'Font:' + ' ' + ViewData.TextFontN + ' ' +
1386IntToStr(ViewData.TextFontSz);
1387FormPlot2D.GLWinBmpFont.Font.Name := ViewData.TextFontN;
1388FormPlot2D.GLWinBmpFont.Font.Size := ViewData.TextFontSz;
1389FormCoords.cbXmaxY.Checked := ViewData.xPosYMax;
1390FormCoords.cbXmaxZ.Checked := ViewData.xPosZMax;
1391
1392FormCoords.cbYmaxX.Checked := ViewData.yPosXMax;
1393FormCoords.cbYmaxZ.Checked := ViewData.yPosZMax;
1394
1395FormCoords.cbZmaxY.Checked := ViewData.zPosYMax;
1396FormCoords.cbZmaxX.Checked := ViewData.zPosXMax;
1397
1398FormCoords.UpdateCoordText;
1399
1400Editfxy.Text := PlotData.txtStr;
1401EditNote.Text := PlotData.NoteStr;
1402
1403EditMinX.Text := FloatToStrF(PlotData.xMin, ffGeneral, 7, 4);
1404EditMaxX.Text := FloatToStrF(PlotData.xMax, ffGeneral, 7, 4);
1405EditdX.Text := FloatToStrF(PlotData.xInc, ffGeneral, 7, 4);
1406
1407EditMinY.Text := FloatToStrF(PlotData.yMin, ffGeneral, 7, 4);
1408EditMaxY.Text := FloatToStrF(PlotData.yMax, ffGeneral, 7, 4);
1409EditdY.Text := FloatToStrF(PlotData.yInc, ffGeneral, 7, 4);
1410
1411EditMinZ.Text := FloatToStrF(PlotData.zMin, ffGeneral, 7, 4);
1412EditMaxZ.Text := FloatToStrF(PlotData.zMax, ffGeneral, 7, 4);
1413cbZLimit.Checked := PlotData.zLim;
1414cbZCap.Checked := PlotData.zCap;
1415
1416ModeComboBox.ItemIndex := Ord(PlotData.ViewMode);
1417StyleComboBox.ItemIndex := Ord(PlotData.fxyMode);
1418
1419Caption := GraphFName;
1420FormPlot2D.Caption := GraphFName;
1421FormGridOptions.Caption := GraphFName;
1422FormEvaluate.Caption := GraphFName;
1423FormCoords.Caption := GraphFName;
1424CountzPoints;
1425end;
1426
1427procedure TFormFunctions.StyleComboBoxChange(Sender: TObject);
1428begin
1429PlotData.fxyMode := TfxyMode(StyleComboBox.ItemIndex);
1430UpdateTPlotDataObject;
1431ApplyBtnClick(Sender);
1432end;
1433
1434procedure TFormFunctions.UpButtonClick(Sender: TObject);
1435var
1436i: integer;
1437
1438begin
1439with CheckListBox do
1440begin
1441i := ItemIndex;
1442if i > 0 then
1443Items.Move(i, i - 1);
1444if i > 1 then
1445ItemIndex := i - 1
1446else
1447ItemIndex := 0;
1448end;
1449CheckListBoxClick(Sender);
1450Altered := True;
1451end;
1452
1453procedure TFormFunctions.AddNewPlot;
1454begin
1455with CheckListBox do
1456begin
1457AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
1458ItemIndex := Count - 1;
1459Checked[ItemIndex] := True; { initially this item is checked }
1460end;
1461Editfxy.SetFocus;
1462Editfxy.SelLength := 0;
1463end;
1464
1465procedure TFormFunctions.ApplyBtnClick(Sender: TObject);
1466var
1467v: TGlFloat;
1468s: string;
1469
1470begin
1471if TooManyPoints > 6 then
1472Exit;
1473
1474with PlotData do
1475begin
1476if xMin > xMax then { swap }
1477begin
1478v := xMin;
1479xMin := xMax;
1480xMax := v;
1481s := EditMinX.Text;
1482EditMinX.Text := EditMaxX.Text;
1483EditMaxX.Text := s;
1484UpdateTPlotDataObject;
1485end;
1486if yMin > yMax then { swap }
1487begin
1488v := yMin;
1489yMin := yMax;
1490yMax := v;
1491s := EditMinY.Text;
1492EditMinY.Text := EditMaxY.Text;
1493EditMaxY.Text := s;
1494UpdateTPlotDataObject;
1495end;
1496end;
1497
1498AddedData.AddedAs := AddNone;
1499
1500FormPlot2D.UpdatePlot;
1501FormEvaluate.UpdateEvaluate;
1502ApplyBtn.Visible := False;
1503Altered := True;
1504end;
1505
1506procedure TFormFunctions.CentreClick(Sender: TObject);
1507var
1508x, y, z: TGlFloat;
1509
1510begin
1511with FormPlot2D do
1512begin
1513MousePoint.x := Maxint;
1514x := PlotData.xMax + PlotData.xMin;
1515y := PlotData.yMax + PlotData.yMin;
1516z := PlotData.zMax + PlotData.zMin;
1517TargetCube.Position.SetPoint(x / 2, y / 2, z / 2);
1518end;
1519Altered := True;
1520FormPlot2D.ShowDisplacement;
1521end;
1522
1523procedure TFormFunctions.CheckListBoxClick(Sender: TObject);
1524begin
1525PlotData := TPlotDataObject(CheckListBox.Items.Objects[CheckListBox.ItemIndex]).Data;
1526if CheckListBox.Checked[CheckListBox.ItemIndex] then
1527FormEvaluate.UpdateEvaluate;
1528
1529ShowData(Sender);
1530if FormPlotColors.Visible then
1531FormPlotColors.ShowPlotColorData;
1532if FormDerivatives.Visible then
1533FormDerivatives.ApplyBtn.Visible := True;
1534end;
1535
1536procedure TFormFunctions.CheckListBoxClickCheck(Sender: TObject);
1537begin
1538ApplyBtn.Visible := True;
1539end;
1540
1541procedure TFormFunctions.ReadAndShowInitialData;
1542begin
1543if not ReadData(DataPath + GraphFName) then
1544begin
1545GraphFName := NewFName;
1546NewFile := True;
1547ViewData := DefaultViewData;
1548PlotData := DefaultPlotData;
1549AddedData := DefaultAddedData;
1550with CheckListBox do
1551begin
1552AddItem(PlotData.txtStr, TPlotDataObject.Create(PlotData));
1553ItemIndex := Count - 1;
1554Checked[ItemIndex] := True; // initially this item is checked
1555end;
1556FormPlot2D.TargetCube.Position.SetPoint(0, 0, 0);
1557end;
1558
1559Caption := GraphFName;
1560ShowData(Self);
1561end;
1562
1563procedure TFormFunctions.OpenRecentFile(FName: TFileName);
1564var
1565i: integer;
1566
1567begin
1568if FormDerivatives.Visible then
1569FormDerivatives.Close;
1570if FileExists(FName) then
1571begin
1572if Altered or GridColorsAltered then
1573case MessageDlg('The current graph''s data has been altered.' +
1574#13#10'Do you wish to save the alterations ?', mtConfirmation,
1575[mbYes, mbNo, mbCancel], 0) of
1576mrYes:
1577SaveClick(Self);
1578mrCancel:
1579Exit;
1580mrNo:
1581begin
1582Altered := False;
1583GridColorsAltered := False;
1584DerivativeAltered := False;
1585NewFile := False;
1586end;
1587end;
1588AddRecent(FName);
1589DataPath := ExtractFilePath(FName);
1590DataPath := IncludeTrailingPathDelimiter(DataPath);
1591FormPlot2D.MousePoint.x := Maxint;
1592GraphFName := ExtractFileName(FName);
1593
1594with CheckListBox do
1595begin
1596for i := 0 to Items.Count - 1 do
1597Items.Objects[i].Free;
1598Clear;
1599end;
1600
1601if ReadData(FName) then
1602ShowData(Self);
1603if FormGridColors.Visible then
1604FormGridColors.ShowGridColorData;
1605if FormPlotColors.Visible then
1606FormPlotColors.ShowPlotColorData;
1607
1608ApplyBtnClick(Self);
1609Altered := False;
1610GridColorsAltered := False;
1611DerivativeAltered := False;
1612end
1613else
1614MessageDlg('The file ' + FName + ' does not exist!', mtError, [mbOK], 0);
1615end;
1616
1617procedure TFormFunctions.AddRecent(const f: TFileName);
1618var
1619i: integer;
1620Found: Boolean;
1621
1622begin
1623with FormPlot2D.Recent1 do
1624begin
1625Found := False;
1626i := 0;
1627while (i < Count) and not Found do
1628begin
1629Found := Items[i].Caption = DataPath + GraphFName;
1630Inc(i);
1631end;
1632if Found then
1633Delete(i - 1);
1634Insert(0, TMenuItem.Create(Self));
1635Items[0].Caption := DataPath + GraphFName;
1636Items[0].OnClick := FormPlot2D.RecentFilesClick;
1637if Count > 16 then
1638Delete(Count - 1);
1639end;
1640end;
1641
1642procedure TFormFunctions.OpenSelectedFile(Sender: TObject; FName: TFileName);
1643var
1644i: integer;
1645
1646begin
1647if FileExists(FName) then
1648begin
1649Screen.Cursor := crHourglass;
1650with CheckListBox do
1651begin
1652for i := 0 to Items.Count - 1 do
1653Items.Objects[i].Free;
1654Clear;
1655end;
1656GraphFName := ExtractFileName(FName);
1657if ReadData(DataPath + GraphFName) then
1658begin
1659Caption := GraphFName;
1660FormPlot2D.Caption := GraphFName;
1661FormGridOptions.Caption := GraphFName;
1662ShowData(Sender);
1663NewFile := False;
1664Altered := False;
1665(* NewFont needed to initialize GLWinFont.GetCharWidth
1666if the font has been altered, which may or may not be the case,
1667so do it anyway *)
1668FormPlot2D.GLSViewer.Buffer.BackgroundColor := ViewData.BackColor;
1669FormPlot2D.GLSViewer.Invalidate;
1670end;
1671Screen.Cursor := crDefault;
1672end
1673else
1674begin
1675MessageDlg('The file' + FName + #13#10'Could not be found.', mtError,
1676[mbOK], 0);
1677Screen.Cursor := crDefault;
1678end;
1679end;
1680
1681end.
1682