MathgeomGLS

Форк
0
/
fEvaluate.pas 
522 строки · 15.8 Кб
1
unit fEvaluate;
2

3
interface
4

5
uses
6
  Winapi.Windows,
7
  Winapi.Messages,
8
  System.SysUtils,
9
  System.Variants,
10
  System.Classes,
11
  System.Math,
12
  System.IniFiles,
13
  Vcl.Graphics,
14
  Vcl.Controls,
15
  Vcl.Forms,
16
  Vcl.Dialogs,
17
  Vcl.StdCtrls,
18
  Vcl.Buttons,
19
  Vcl.Menus,
20
  Vcl.ComCtrls,
21

22
  GLS.OpenGLTokens,
23
  GLS.Coordinates,
24
  GLS.VectorTypes,
25
  GLS.VectorGeometry,
26
  fDerivativeOptions,
27

28
  uGlobal,
29
  uParser;
30

31
type
32
  TFormEvaluate = class(TForm)
33
    GroupBox1: TGroupBox;
34
    Labe1: TLabel;
35
    Label2: TLabel;
36
    Label3: TLabel;
37
    Label4: TLabel;
38
    Label5: TLabel;
39
    Label6: TLabel;
40
    EditX: TEdit;
41
    EditY: TEdit;
42
    EditZ: TEdit;
43
    Editdzdx: TEdit;
44
    Editdzdy: TEdit;
45
    Coordinates: TCheckBox;
46
    BitBtn1: TBitBtn;
47
    ToGrids: TCheckBox;
48
    EditCoordWidth: TEdit;
49
    ColorButton: TSpeedButton;
50
    ColorDialog: TColorDialog;
51
    dzdx_dzdy: TCheckBox;
52
    PopupMenu1: TPopupMenu;
53
    Slope1: TMenuItem;
54
    Degree1: TMenuItem;
55
    Radian1: TMenuItem;
56
    Label1: TLabel;
57
    EditArrow: TEdit;
58
    procedure FloatKeyPress(Sender: TObject; var Key: Char);
59
    procedure BitBtn1Click(Sender: TObject);
60
    procedure ColorButtonClick(Sender: TObject);
61
    procedure IntPress(Sender: TObject; var Key: Char);
62
    procedure EditXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
63
    procedure EditYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
64
    procedure EditCoordWidthKeyUp(Sender: TObject; var Key: Word;
65
                                   Shift: TShiftState);
66
    procedure CoordinatesClick(Sender: TObject);
67
    procedure ToGridsClick(Sender: TObject);
68
    procedure dzdx_dzdyClick(Sender: TObject);
69
    procedure MenuClick(Sender: TObject);
70
    procedure EditArrowKeyPress(Sender: TObject; var Key: Char);
71
    procedure EditArrowKeyUp(Sender: TObject; var Key: Word;
72
                              Shift: TShiftState);
73
  private
74
    zValue: TGLFloat;
75
    dzdx, dzdy: TGLFloat;
76
    CurrentTag: integer;
77
    procedure ShowCoords(const x, y, z: TGLFloat; const c, t: Boolean);
78
  public
79
    procedure UpdateEvaluate;
80
    procedure UpdateCoords;
81
    procedure DoEvaluate;
82
  end;
83

84
var
85
  FormEvaluate: TFormEvaluate;
86

87
//=======================================================================
88
implementation
89
//=======================================================================
90

91
uses
92
  fPlot2D;
93

94
{$R *.dfm}
95

96
procedure TFormEvaluate.FloatKeyPress(Sender: TObject; var Key: Char);
97
begin
98
  with Sender as TEdit do
99
  if not CharInSet(Key, AnyFloat) then Key := #0;
100
end;
101

102
procedure TFormEvaluate.EditXKeyUp(Sender: TObject; var Key: Word;
103
                                    Shift: TShiftState);
104
var
105
  v: TGLFloat;
106

107
begin
108
  try
109
    v := StrToFloat(EditX.Text);
110
  except
111
    v := 0.0;
112
  end;
113
  ViewData.xEvaluate := v;
114
  DoEvaluate;
115
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
116
                              CoordChecked, ToGridsChecked);
117
  Altered := True;
118
end;
119

120
procedure TFormEvaluate.EditYKeyUp(Sender: TObject; var Key: Word;
121
                                    Shift: TShiftState);
122
var
123
  v: TGLFloat;
124

125
begin
126
  try
127
    v := StrToFloat(EditY.Text);
128
  except
129
    v := 0.0;
130
  end;
131
  ViewData.yEvaluate := v;
132
  DoEvaluate;
133
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
134
                              CoordChecked, ToGridsChecked);
135
  Altered := True;
136
end;
137

138
procedure TFormEvaluate.DoEvaluate;
139
var
140
  e: byte;
141
  x0, y0, x1, y1, z1, x2, y2, z2, dx, dy, dz, Sz: extended;
142
  VectorPos, VectorXDir, VectorYDir: TGLVector;
143

144
begin
145
  if Visible then
146
  begin
147
    with PlotData do                                //x1,y2---------------x2,y2
148
    begin                                           //  |                   |
149
      x0 := ViewData.xEvaluate;                     //  |                   |
150
      y0 := ViewData.yEvaluate;                     //  |        zValue     |
151
      dx := xInc;                                   //  |         .         |
152
      dy := yInc;                                   //  |       x0,y0       |
153
      x1 := x0 - dx;                                //  |                   |
154
      y1 := y0 - dy;                                //  |                   |
155
      x2 := x0 + dx;                                //  |                   |
156
      y2 := y0 + dy;                                //x1,y1---------------x2,y1
157
    end;
158

159
    zValue := ParseEvaluateFxy(x0, y0, PlotData.fxyStr, e);{ evaluate z, x0,y0 }
160
    EditZ.Text := FloatTostr(zValue);
161
    VectorPos := VectorMake(x0, y0, zValue*ViewData.xyGrid.zScale);
162

163
    z1 := ParseEvaluateFxy(x1, y0, PlotData.fxyStr, e);   { evaluate z1, x1,y0 }
164
    z2 := ParseEvaluateFxy(x2, y0, PlotData.fxyStr, e);   { evaluate z2, x2,y0 }
165
    dz := z2 - z1;
166
    dzdx := dz/(x2 - x1);                            { dzdx = slope wrt x axis }
167

168
    VectorXDir := VectorMake(x2 - x1, 0, dz*ViewData.xyGrid.zScale);
169
    case CurrentTag of
170
    0:Editdzdx.Text := FloatToStrF(dzdx, ffNumber, 12, 8);
171
    1:Editdzdx.Text := FloatToStrF(RadianToDeg(ArcTan(dzdx)), ffNumber, 12, 8)+'�';
172
    2:Editdzdx.Text := FloatToStrF(ArcTan(dzdx), ffNumber, 12, 8)+' Rad.';
173
    end;
174

175
    z1 := ParseEvaluateFxy(x0, y1, PlotData.fxyStr, e);   { evaluate z1, x0,y1 }
176
    z2 := ParseEvaluateFxy(x0, y2, PlotData.fxyStr, e);   { evaluate z2, x0,y2 }
177
    dz := z2 - z1;
178
    dzdy := dz/(y2 - y1);                            { dzdy = slope wrt y axis }
179

180
    VectorYDir := VectorMake(0, y2 - y1, dz*ViewData.xyGrid.zScale);
181
    case CurrentTag of
182
    0:Editdzdy.Text := FloatToStrF(dzdy, ffNumber, 12, 8);
183
    1:Editdzdy.Text := FloatToStrF(RadianToDeg(ArcTan(dzdy)), ffNumber, 12, 8)+'�';
184
    2:Editdzdy.Text := FloatToStrF(ArcTan(dzdy), ffNumber, 12, 8)+' Rad.';
185
    end;
186

187
    if dzdx_dzdy.Checked then
188
    begin
189
      with ViewData.xyGrid do if xRange.Step < yRange.Step
190
      then Sz := xRange.Step else Sz := yRange.Step;
191
      with FormPlot2D.xArrow do
192
      begin
193
        Scale.AsVector := VectorMake(ViewData.ArrowSize*Sz/2,
194
          ViewData.ArrowSize*Sz/2, ViewData.ArrowSize*Sz);
195
        Material.FrontProperties.Diffuse.AsWinColor := ViewData.xTextColor;
196
        Direction.AsVector := VectorXDir;
197
        Position.AsVector := VectorPos;
198
      end;
199

200
      with FormPlot2D.yArrow do
201
      begin
202
        Scale.AsVector := VectorMake(ViewData.ArrowSize*Sz/2,
203
          ViewData.ArrowSize*Sz/2, ViewData.ArrowSize*Sz);
204
        Material.FrontProperties.Diffuse.AsWinColor := ViewData.yTextColor;
205
        Direction.AsVector := VectorYDir;
206
        Position.AsVector := VectorPos;
207
      end;
208
    end;
209
  end;
210
end;
211

212
procedure TFormEvaluate.dzdx_dzdyClick(Sender: TObject);
213
begin
214
  ViewData.dzdx_dyChecked := dzdx_dzdy.Checked;
215
  FormPlot2D.xArrow.Visible := dzdx_dzdy.Checked;
216
  FormPlot2D.yArrow.Visible := dzdx_dzdy.Checked;
217
  DoEvaluate;
218
  Altered := True;
219
end;
220

221
procedure TFormEvaluate.BitBtn1Click(Sender: TObject);
222
begin
223
  Close;
224
end;
225

226
procedure TFormEvaluate.EditArrowKeyPress(Sender: TObject; var Key: Char);
227
begin
228
  with Sender as TEdit do
229
  if not CharInSet(Key, PosFloat) then Key := #0;
230
end;
231

232
procedure TFormEvaluate.EditArrowKeyUp(Sender: TObject; var Key: Word;
233
                                        Shift: TShiftState);
234
var
235
  w: TGLFloat;
236

237
begin
238
  try
239
    w := StrToFloat(EditArrow.Text);
240
  except
241
    w := 1;
242
  end;
243
  ViewData.ArrowSize := w;
244
  Altered := True;
245
  DoEvaluate;
246
end;
247

248
procedure TFormEvaluate.EditCoordWidthKeyUp(Sender: TObject; var Key: Word;
249
                                             Shift: TShiftState);
250
var
251
  w: integer;
252

253
begin
254
  try
255
    w := StrToInt(EditCoordWidth.Text);
256
  except
257
    w := 3;
258
  end;
259
  ViewData.CoordWidth := w;
260
  FormPlot2D.xCoordLine.LineWidth := w;
261
  FormPlot2D.yCoordLine.LineWidth := w;
262
  FormPlot2D.zCoordLine.LineWidth := w;
263
  Altered := True;
264
end;
265

266
procedure TFormEvaluate.IntPress(Sender: TObject; var Key: Char);
267
begin
268
  with Sender as TEdit do
269
  if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
270
end;
271

272
procedure TFormEvaluate.ColorButtonClick(Sender: TObject);
273
begin
274
  if ColorDialog.Execute then
275
  begin
276
    ViewData.CoordColor := ColorDialog.Color;
277
    UpdateCoords;
278
    Altered := True;
279
  end;
280
end;
281

282
procedure TFormEvaluate.CoordinatesClick(Sender: TObject);
283
begin
284
  ViewData.CoordChecked := Coordinates.Checked;
285
  DoEvaluate;
286
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
287
                              CoordChecked, ToGridsChecked);
288
  if FormDerivatives.Visible and not Coordinates.Checked then
289
  begin
290
    FormPlot2D.AddXLine.Visible := False;
291
    FormPlot2D.AddYLine.Visible := False;
292
    FormPlot2D.AddZLine.Visible := False;
293
  end;
294

295
  Altered := True;
296
end;
297

298
procedure TFormEvaluate.ToGridsClick(Sender: TObject);
299
begin
300
  ViewData.ToGridsChecked := ToGrids.Checked;
301
  DoEvaluate;
302
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
303
                              CoordChecked, ToGridsChecked);
304
  Altered := True;
305
end;
306

307
procedure TFormEvaluate.ShowCoords(const x, y, z: TGLFloat; const c, t: Boolean);
308
begin
309
  with FormPlot2D do
310
  begin
311
    if c then                  { show coords }
312
    begin
313
      with xCoordLine do
314
      begin
315
        if t then              { to grids }
316
        begin
317
          Position.SetPoint(GLyzGrid.Position.x, y, z);
318
          Nodes[0].X := x - GLyzGrid.Position.x;
319
        end
320
        else                   { +- step }
321
        begin
322
          Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, z);
323
          Nodes[0].X := 2*GLxyGrid.XSamplingScale.Step;
324
        end;
325
        Visible := True;
326
      end;
327

328
      with yCoordLine do
329
      begin
330
        if t then              { to grids }
331
        begin
332
          Position.SetPoint(x, GLxzGrid.Position.y, z);
333
          Nodes[0].Y := y - GLxzGrid.Position.y;
334
        end
335
        else                   { +- step }
336
        begin
337
          Position.SetPoint(x, y - GLxyGrid.YSamplingScale.Step, z);
338
          Nodes[0].Y := 2*GLxyGrid.YSamplingScale.Step;
339
        end;
340
        Visible := True;
341
      end;
342

343
      with zCoordLine do
344
      begin
345
        if t then              { to grids }
346
        begin
347
          Position.SetPoint(x, y, GLxyGrid.Position.z);
348
          Nodes[0].Z := z - GLxyGrid.Position.z;
349
        end
350
        else                   { +- step }
351
        begin
352
          Position.SetPoint(x, y, z - GLxzGrid.ZSamplingScale.Step);
353
          Nodes[0].Z := 2*GLxzGrid.ZSamplingScale.Step;
354
        end;
355
        Visible := True;
356
      end;
357

358
    { only after FormDerivatives.ApplyBtnClick if AddedAs.AddedAs = AddVolume }
359
      if FormDerivatives.Visible then
360
      begin
361
        case AddedData.AddedAs of
362
          AddDerivX:
363
          begin
364
            with AddXLine do        { xCoord }
365
            begin
366
              if t then             { to grids }
367
              begin
368
                Position.SetPoint(GLyzGrid.Position.x, y, dzdx*ViewData.xyGrid.zScale);
369
                Nodes[0].AsVector := VectorMake(x - GLyzGrid.Position.x, 0, 0);
370
              end
371
              else                  { +- step }
372
              begin
373
                Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, dzdx*ViewData.xyGrid.zScale);
374
                Nodes[0].AsVector := VectorMake(2*GLxyGrid.XSamplingScale.Step, 0, 0);
375
              end;
376
              Visible := True;
377
            end;
378

379
            with AddYLine do         { yCoord }
380
            begin
381
              if t then              { to grids }
382
              begin
383
                Position.SetPoint(x, GLxzGrid.Position.y, dzdx*ViewData.xyGrid.zScale);
384
                Nodes[0].AsVector := VectorMake(0, y - GLxzGrid.Position.y, 0);
385
              end
386
              else                   { +- step }
387
              begin
388
                Position.SetPoint(x, y - GLxyGrid.YSamplingScale.Step, dzdx*ViewData.xyGrid.zScale);
389
                Nodes[0].AsVector := VectorMake(0, 2*GLxyGrid.YSamplingScale.Step, 0);
390
              end;
391
              Visible := True;
392
            end;
393

394
            with AddZLine do         { zCoord }
395
            begin
396
              if t then              { to grids }
397
              begin
398
                Position.SetPoint(x, y, GLxyGrid.Position.z);
399
                Nodes[0].AsVector := VectorMake(0, 0, dzdx*ViewData.xyGrid.zScale - GLxyGrid.Position.z);
400
              end
401
              else                   { +- step }
402
              begin
403
                Position.SetPoint(x, y, dzdx*ViewData.xyGrid.zScale - GLxzGrid.ZSamplingScale.Step);
404
                Nodes[0].AsVector := VectorMake(0, 0, 2*GLxzGrid.ZSamplingScale.Step);
405
              end;
406
              Visible := True;
407
            end;
408

409
          end;  { AddDerivX }
410

411
          AddDerivY:
412
          begin
413
            with AddXLine do        { xCoord }
414
            begin
415
              if t then             { to grids }
416
              begin
417
                Position.SetPoint(GLyzGrid.Position.x, y, dzdy*ViewData.xyGrid.zScale);
418
                Nodes[0].AsVector := VectorMake(x - GLyzGrid.Position.x, 0, 0);
419
              end
420
              else                  { +- step }
421
              begin
422
                Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, dzdy*ViewData.xyGrid.zScale);
423
                Nodes[0].AsVector := VectorMake(2*GLxyGrid.XSamplingScale.Step, 0, 0);
424
              end;
425
              Visible := True;
426
            end;
427

428
            with AddYLine do         { yCoord }
429
            begin
430
              if t then              { to grids }
431
              begin
432
                Position.SetPoint(x, GLxzGrid.Position.y, dzdy*ViewData.xyGrid.zScale);
433
                Nodes[0].AsVector := VectorMake(0, y - GLxzGrid.Position.y, 0);
434
              end
435
              else                   { +- step }
436
              begin
437
                Position.SetPoint(x, y - GLxyGrid.YSamplingScale.Step, dzdy*ViewData.xyGrid.zScale);
438
                Nodes[0].AsVector := VectorMake(0, 2*GLxyGrid.YSamplingScale.Step, 0);
439
              end;
440
              Visible := True;
441
            end;
442

443
            with AddZLine do         { zCoord }
444
            begin
445
              if t then              { to grids }
446
              begin
447
                Position.SetPoint(x, y, GLxyGrid.Position.z);
448
                Nodes[0].AsVector := VectorMake(0, 0, dzdy*ViewData.xyGrid.zScale - GLxyGrid.Position.z);
449
              end
450
              else                   // +- step
451
              begin
452
                Position.SetPoint(x, y, dzdy*ViewData.xyGrid.zScale - GLxzGrid.ZSamplingScale.Step);
453
                Nodes[0].AsVector := VectorMake(0, 0, 2*GLxzGrid.ZSamplingScale.Step);
454
              end;
455
              Visible := True;
456
            end;
457

458
          end;  // AddDerivY
459

460
          AddVolume:
461
          begin
462
            AddXLine.Visible := False;
463
            AddYLine.Visible := False;
464
            AddZLine.Visible := False;
465
          end;  // AddVolume
466
        end;  // case AddedData.AddedAs of...
467
      end;  // if FormDerivatives.Visible then...
468
    end   // if c then show coords
469
    else
470
    begin // coordinate lines not visible
471
      xCoordLine.Visible := False;
472
      yCoordLine.Visible := False;
473
      zCoordLine.Visible := False;
474
    end;
475
  end;
476

477
  with ViewData do
478
  begin
479
    EditArrow.Text := FloatToStr(ArrowSize);
480
    EditCoordWidth.Text := IntToStr(CoordWidth);
481
    FormPlot2D.xCoordLine.LineWidth := CoordWidth;
482
    FormPlot2D.yCoordLine.LineWidth := CoordWidth;
483
    FormPlot2D.zCoordLine.LineWidth := CoordWidth;
484
  end;
485
end;
486

487
procedure TFormEvaluate.MenuClick(Sender: TObject);
488
begin
489
  if CurrentTag <> TMenuItem(Sender).Tag then
490
  begin
491
    case CurrentTag of
492
      0:Slope1.Checked  := False;
493
      1:Degree1.Checked := False;
494
      2:Radian1.Checked := False;
495
    end;
496
    with Sender as TMenuItem do
497
    begin
498
      Checked := True;
499
      CurrentTag := Tag;
500
    end;
501
    DoEvaluate;
502
  end;
503
end;
504

505
procedure TFormEvaluate.UpdateEvaluate;
506
begin
507
  DoEvaluate;
508
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
509
                              CoordChecked, ToGridsChecked);
510
end;
511

512
procedure TFormEvaluate.UpdateCoords;
513
begin
514
  with FormPlot2D do
515
  begin
516
    with xCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
517
    with yCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
518
    with zCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
519
  end;
520
end;
521

522
end.
523

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.