MathgeomGLS
566 строк · 15.2 Кб
1unit fDerivativeOptions;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11System.Math,
12Vcl.Graphics,
13Vcl.Controls,
14Vcl.Forms,
15Vcl.Dialogs,
16Vcl.StdCtrls,
17Vcl.Buttons,
18Vcl.ExtCtrls,
19Vcl.ComCtrls,
20
21GLS.OpenGLTokens,
22GLS.VectorTypes,
23GLS.VectorGeometry,
24
25uGlobal,
26uParser,
27fGridOptions;
28
29type
30TDerivativesForm = class(TForm)
31GroupBox1: TGroupBox;
32Label1: TLabel;
33Label2: TLabel;
34Label3: TLabel;
35Label4: TLabel;
36Label5: TLabel;
37Label6: TLabel;
38Label8: TLabel;
39zCountLabel: TLabel;
40GridValues: TSpeedButton;
41PlotValues: TSpeedButton;
42EditMinX: TEdit;
43EditMaxX: TEdit;
44EditdX: TEdit;
45EditMinY: TEdit;
46EditMaxY: TEdit;
47EditdY: TEdit;
48EditMinZ: TEdit;
49EditMaxZ: TEdit;
50zLimitCB: TCheckBox;
51ModeComboBox: TComboBox;
52StyleComboBox: TComboBox;
53zCapCB: TCheckBox;
54ApplyBtn: TBitBtn;
55CloseBtn: TBitBtn;
56DerivXRB: TRadioButton;
57DerivYRB: TRadioButton;
58VolumeRB: TRadioButton;
59Label7: TLabel;
60EditAddLineWidth: TEdit;
61ColorButton: TSpeedButton;
62ColorDialog: TColorDialog;
63VolumeLabel: TLabel;
64PosVolLabel: TLabel;
65NegVolLabel: TLabel;
66TotalLabel: TLabel;
67procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
68procedure FloatKeyPress(Sender: TObject; var Key: Char);
69procedure IncKeyPress(Sender: TObject; var Key: Char);
70procedure EditMinXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
71procedure EditMaxXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
72procedure EditdXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
73procedure EditMinYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
74procedure EditMaxYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
75procedure EditdYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
76procedure EditMinZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
77procedure EditMaxZKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
78procedure zLimitCBClick(Sender: TObject);
79procedure zCapCBClick(Sender: TObject);
80procedure ApplyBtnClick(Sender: TObject);
81procedure CloseBtnClick(Sender: TObject);
82procedure GridValuesClick(Sender: TObject);
83procedure PlotValuesClick(Sender: TObject);
84procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
85procedure StyleComboBoxChange(Sender: TObject);
86procedure ModeComboBoxChange(Sender: TObject);
87procedure DerivXRBClick(Sender: TObject);
88procedure DerivYRBClick(Sender: TObject);
89procedure VolumeRBClick(Sender: TObject);
90procedure FormShow(Sender: TObject);
91procedure EditAddLineWidthKeyPress(Sender: TObject; var Key: Char);
92procedure EditAddLineWidthKeyUp(Sender: TObject; var Key: Word;
93Shift: TShiftState);
94procedure ColorButtonClick(Sender: TObject);
95procedure PlotValuesMouseUp(Sender: TObject; Button: TMouseButton;
96Shift: TShiftState; X, Y: Integer);
97procedure GridValuesMouseUp(Sender: TObject; Button: TMouseButton;
98Shift: TShiftState; X, Y: Integer);
99private
100TooManyPoints: Boolean;
101procedure CountzPoints;
102public
103{ Public declarations }
104end;
105
106var
107DerivativesForm: TDerivativesForm;
108
109//==========================================================================
110implementation
111//==========================================================================
112
113{$R *.dfm}
114uses
115fPlot3D,
116fAddPlotColors,
117fEvaluate;
118
119procedure TDerivativesForm.EditdXKeyUp(Sender: TObject; var Key: Word;
120Shift: TShiftState);
121var
122x: TGlFloat;
123
124begin
125try
126x := StrToFloat(EditdX.Text);
127except
128x := 1.0;
129end;
130AddedData.xInc := x;
131//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
132DerivativeAltered := True;
133CountzPoints;
134end;
135
136procedure TDerivativesForm.EditdYKeyUp(Sender: TObject; var Key: Word;
137Shift: TShiftState);
138var
139y: TGLFloat;
140
141begin
142try
143y := StrToFloat(EditdY.Text);
144except
145y := 1.0;
146end;
147AddedData.yInc := y;
148//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
149DerivativeAltered := True;
150CountzPoints;
151end;
152
153procedure TDerivativesForm.EditKeyDown(Sender: TObject; var Key: Word;
154Shift: TShiftState);
155begin
156//if (Key = VK_DELETE) or (Key = VK_BACK)
157//then ApplyBtn.Visible := AddedData.AddedAs > AddNone;
158end;
159
160procedure TDerivativesForm.EditAddLineWidthKeyPress(Sender: TObject;
161var Key: Char);
162begin
163with Sender as TEdit do
164if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
165end;
166
167procedure TDerivativesForm.EditAddLineWidthKeyUp(Sender: TObject; var Key: Word;
168Shift: TShiftState);
169var
170w: integer;
171
172begin
173try
174w := StrToInt(EditAddLineWidth.Text);
175except
176w := 3;
177end;
178
179AddedData.AddLineWidth := w;
180ViewForm.AddXLine.LineWidth := w;
181ViewForm.AddYLine.LineWidth := w;
182ViewForm.AddZLine.LineWidth := w;
183DerivativeAltered := True;
184//ApplyBtn.Visible := AddedData.AddedAs = AddVolume;
185end;
186
187procedure TDerivativesForm.EditMaxXKeyUp(Sender: TObject; var Key: Word;
188Shift: TShiftState);
189var
190x: TGLFloat;
191
192begin
193try
194x := StrToFloat(EditMaxX.Text);
195except
196x := 1.0;
197end;
198AddedData.xMax := x;
199//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
200DerivativeAltered := True;
201CountzPoints;
202end;
203
204procedure TDerivativesForm.EditMaxYKeyUp(Sender: TObject; var Key: Word;
205Shift: TShiftState);
206var
207y: TGLFloat;
208
209begin
210try
211y := StrToFloat(EditMaxY.Text);
212except
213y := 1.0;
214end;
215AddedData.yMax := y;
216//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
217DerivativeAltered := True;
218CountzPoints;
219end;
220
221procedure TDerivativesForm.EditMaxZKeyUp(Sender: TObject; var Key: Word;
222Shift: TShiftState);
223var
224z: TGLFloat;
225
226begin
227try
228z := StrToFloat(EditMaxZ.Text);
229except
230z := 1.0;
231end;
232AddedData.zMax := z;
233//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
234DerivativeAltered := True;
235CountzPoints;
236end;
237
238procedure TDerivativesForm.EditMinXKeyUp(Sender: TObject; var Key: Word;
239Shift: TShiftState);
240var
241x: TGLFloat;
242
243begin
244try
245x := StrToFloat(EditMinX.Text);
246except
247x := -1.0;
248end;
249AddedData.xMin := x;
250//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
251DerivativeAltered := True;
252CountzPoints;
253end;
254
255procedure TDerivativesForm.EditMinYKeyUp(Sender: TObject; var Key: Word;
256Shift: TShiftState);
257var
258y: TGLFloat;
259
260begin
261try
262y := StrToFloat(EditMinY.Text);
263except
264y := -1.0;
265end;
266AddedData.yMin := y;
267//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
268DerivativeAltered := True;
269CountzPoints;
270end;
271
272procedure TDerivativesForm.EditMinZKeyUp(Sender: TObject; var Key: Word;
273Shift: TShiftState);
274var
275z: TGLFloat;
276
277begin
278try
279z := StrToFloat(EditMinZ.Text);
280except
281z := -1.0;
282end;
283AddedData.zMin := z;
284//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
285DerivativeAltered := True;
286CountzPoints;
287end;
288
289procedure TDerivativesForm.FormCloseQuery(Sender: TObject;
290var CanClose: Boolean);
291begin
292AddedData.AddedAs := AddNone;
293ViewForm.ClearAddedField;
294ViewForm.ClearAddedLines;
295ViewForm.AddXLine.Visible := False;
296ViewForm.AddYLine.Visible := False;
297ViewForm.AddZLine.Visible := False;
298ViewForm.PlotColours1.Enabled := True;
299ViewForm.DerivativePlotColours1.Enabled := False;
300if AddPlotColorsForm.Visible then AddPlotColorsForm.Close;
301Altered := Altered or DerivativeAltered;
302end;
303
304procedure TDerivativesForm.FormShow(Sender: TObject);
305begin
306Caption := GraphFName;
307with AddedData do
308begin
309EditMinX.Text := FloatToStrF(xMin, ffGeneral, 7, 4);
310EditMaxX.Text := FloatToStrF(xMax, ffGeneral, 7, 4);
311Editdx.Text := FloatToStrF(xInc, ffGeneral, 7, 4);
312EditMinY.Text := FloatToStrF(yMin, ffGeneral, 7, 4);
313EditMaxY.Text := FloatToStrF(yMax, ffGeneral, 7, 4);
314Editdy.Text := FloatToStrF(yInc, ffGeneral, 7, 4);
315EditMinZ.Text := FloatToStrF(zMin, ffGeneral, 7, 4);
316EditMaxZ.Text := FloatToStrF(zMax, ffGeneral, 7, 4);
317zLimitCB.Checked := zLim;
318zCapCB.Checked := zCap;
319ModeComboBox.ItemIndex := Ord(ViewMode);
320StyleComboBox.ItemIndex := Ord(fxyMode);
321if AddLineWidth < 1 then AddLineWidth := 1;
322EditAddLineWidth.Text := IntToStr(AddLineWidth);
323ModeComboBox.ItemIndex := Ord(ViewMode);
324StyleComboBox.ItemIndex := Ord(fxyMode);
325end;
326AddPlotColorsForm.ShowPlotColorData;
327//ApplyBtn.Visible := VolumeRB.Checked;
328if DerivXRB.Checked or DerivyRB.Checked then ApplyBtnClick(Sender);
329DerivativeAltered := False;
330CountzPoints;
331end;
332
333procedure TDerivativesForm.GridValuesClick(Sender: TObject);
334begin
335with ViewData.xyGrid.xRange do
336begin
337EditMinX.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
338AddedData.xMin := Minimum;
339EditMaxX.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
340AddedData.xMax := Maximum;
341EditdX.Text := FloatToStrF(Step, ffGeneral, 7, 4);
342AddedData.xInc := Step;
343end;
344
345with ViewData.xyGrid.yRange do
346begin
347EditMinY.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
348AddedData.yMin := Minimum;
349EditMaxY.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
350AddedData.yMax := Maximum;
351EditdY.Text := FloatToStrF(Step, ffGeneral, 7, 4);
352AddedData.yInc := Step;
353end;
354
355with ViewData.xzGrid.zRange do
356begin
357EditMinZ.Text := FloatToStrF(Minimum, ffGeneral, 7, 4);
358AddedData.zMin := Minimum;
359EditMaxZ.Text := FloatToStrF(Maximum, ffGeneral, 7, 4);
360AddedData.zMax := Maximum;
361end;
362DerivativeAltered := True;
363CountzPoints;
364end;
365
366procedure TDerivativesForm.GridValuesMouseUp(Sender: TObject;
367Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
368begin
369//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
370end;
371
372procedure TDerivativesForm.IncKeyPress(Sender: TObject; var Key: Char);
373begin
374with Sender as TEdit do
375if not CharInSet(Key, PosFloat) then Key := #0;
376end;
377
378procedure TDerivativesForm.ModeComboBoxChange(Sender: TObject);
379begin
380AddedData.ViewMode := TViewMode(ModeComboBox.ItemIndex);
381//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
382ApplyBtnClick(Sender);
383end;
384
385procedure TDerivativesForm.FloatKeyPress(Sender: TObject; var Key: Char);
386begin
387with Sender as TEdit do
388if not CharInSet(Key, AnyFloat) then Key := #0;
389end;
390
391procedure TDerivativesForm.PlotValuesClick(Sender: TObject);
392begin
393EditMinx.Text := FloatToStrF(PlotData.xMin, ffGeneral, 7, 4);
394AddedData.xMin := PlotData.xMin;
395EditMaxx.Text := FloatToStrF(PlotData.xMax, ffGeneral, 7, 4);
396AddedData.xMax := PlotData.xMax;
397EditdX.Text := FloatToStrF(PlotData.xInc, ffGeneral, 7, 4);
398AddedData.xInc := PlotData.xInc;
399EditMiny.Text := FloatToStrF(PlotData.yMin, ffGeneral, 7, 4);
400AddedData.yMin := PlotData.yMin;
401EditMaxy.Text := FloatToStrF(PlotData.yMax, ffGeneral, 7, 4);
402AddedData.yMax := PlotData.yMax;
403EditdY.Text := FloatToStrF(PlotData.yInc, ffGeneral, 7, 4);
404AddedData.yInc := PlotData.yInc;
405EditMinz.Text := FloatToStrF(PlotData.zMin, ffGeneral, 7, 4);
406AddedData.zMin := PlotData.zMin;
407EditMaxz.Text := FloatToStrF(PlotData.zMax, ffGeneral, 7, 4);
408AddedData.zMax := PlotData.zMax;
409zLimitCB.Checked := PlotData.zLim;
410AddedData.zLim := PlotData.zLim;
411zCapCB.Checked := PlotData.zCap;
412AddedData.zCap := PlotData.zCap;
413CountzPoints;
414end;
415
416procedure TDerivativesForm.PlotValuesMouseUp(Sender: TObject;
417Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
418begin
419//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
420end;
421
422procedure TDerivativesForm.StyleComboBoxChange(Sender: TObject);
423begin
424AddedData.fxyMode := TfxyMode(StyleComboBox.ItemIndex);
425//ApplyBtn.Visible := AddedData.AddedAs > AddNone;
426ApplyBtnClick(Sender);
427end;
428
429procedure TDerivativesForm.VolumeRBClick(Sender: TObject);
430begin
431AddedData.AddedAs := AddVolume;
432//ApplyBtn.Visible := not TooManyPoints;
433ApplyBtnClick(Sender);
434end;
435
436procedure TDerivativesForm.DerivXRBClick(Sender: TObject);
437begin
438ViewForm.ClearAddedLines;
439AddedData.AddedAs := AddDerivX;
440DerivXRB.Checked := False;
441ApplyBtnClick(Sender);
442end;
443
444procedure TDerivativesForm.DerivYRBClick(Sender: TObject);
445begin
446ViewForm.ClearAddedLines;
447AddedData.AddedAs := AddDerivY;
448DerivYRB.Checked := False;
449ApplyBtnClick(Sender);
450end;
451
452procedure TDerivativesForm.zCapCBClick(Sender: TObject);
453begin
454ViewForm.ClearAddedLines;
455AddedData.zCap := zCapCB.Checked;
456//ApplyBtn.Visible := AddedData.AddedAs = AddVolume;
457end;
458
459procedure TDerivativesForm.zLimitCBClick(Sender: TObject);
460begin
461AddedData.zLim := zLimitCB.Checked;
462//ApplyBtn.Visible := AddedData.AddedAs = AddVolume;
463end;
464
465procedure TDerivativesForm.ApplyBtnClick(Sender: TObject);
466var
467v: TGLFloat;
468s: string;
469
470begin
471if TooManyPoints then Exit;
472
473Screen.Cursor := crHourGlass;
474with AddedData do
475begin
476if xMin > xMax then { swap }
477begin
478v := xMin;
479xMin := xMax;
480xMax := v;
481s := EditMinX.Text;
482EditMinX.Text := EditMaxX.Text;
483EditMaxX.Text := s;
484end;
485if yMin > yMax then { swap }
486begin
487v := yMin;
488yMin := yMax;
489yMax := v;
490s := EditMinY.Text;
491EditMinY.Text := EditMaxY.Text;
492EditMaxY.Text := s;
493end;
494if zMin > zMax then { swap }
495begin
496v := zMin;
497zMin := zMax;
498zMax := v;
499s := EditMinZ.Text;
500EditMinZ.Text := EditMaxZ.Text;
501EditMaxZ.Text := s;
502end;
503
504if DerivXRB.Checked then AddedAs := AddDerivX else
505if DerivYRB.Checked then AddedAs := AddDerivY else
506if VolumeRB.Checked then AddedAs := AddVolume;
507end;
508
509PosVolLabel.Caption := '';
510NegVolLabel.Caption := '';
511TotalLabel.Caption := '';
512VolumeLabel.Caption := '';
513ViewForm.ClearAddedField;
514ViewForm.ClearAddedLines;
515ViewForm.UpdateAdded;
516EvaluateForm.UpdateEvaluate;
517ApplyBtn.Visible := False;
518Screen.Cursor := crDefault;
519end;
520
521procedure TDerivativesForm.CloseBtnClick(Sender: TObject);
522begin
523Close;
524end;
525
526procedure TDerivativesForm.ColorButtonClick(Sender: TObject);
527begin
528ColorDialog.Color := AddedData.AddLineColor;
529if ColorDialog.Execute then
530begin
531AddedData.AddLineColor := ColorDialog.Color;
532
533with ViewForm do
534begin
535with AddXLine do LineColor.AsWinColor := AddedData.AddLineColor;
536with AddYLine do LineColor.AsWinColor := AddedData.AddLineColor;
537with AddZLine do LineColor.AsWinColor := AddedData.AddLineColor;
538end;
539
540DerivativeAltered := True;
541ApplyBtnClick(Sender);
542end;
543end;
544
545procedure TDerivativesForm.CountzPoints;
546var
547n, c: integer;
548
549begin
550with AddedData do
551n := round((xMax - xMin)/xInc +1)*round((yMax - yMin)/yInc +1);
552c := round(Log10(n));
553case c of
5540..1:ZCountLabel.Font.Color := clLime;
5552:ZCountLabel.Font.Color := clTeal;
5563:ZCountLabel.Font.Color := clGreen;
5574:ZCountLabel.Font.Color := clBlue;
558else ZCountLabel.Font.Color := clRed;
559end;
560TooManyPoints := c > 4;
561if TooManyPoints then
562ZCountLabel.Caption := 'Too many Points: ' + FloatToStrF(n, ffnumber, 8, 0)+' !'
563else ZCountLabel.Caption := 'N� Points = ' + FloatToStrF(n, ffnumber, 8, 0);
564end;
565
566end.
567