ArenaZ

Форк
0
/
Evaluate.pas 
508 строк · 16.1 Кб
1
unit Evaluate;
2

3
{$MODE Delphi}
4

5
interface
6

7
uses
8
  SysUtils, Variants, Classes, Graphics, Controls, Forms,
9
  Dialogs, StdCtrls, Buttons, OpenGL1x, OpenGLTokens, GLVectorGeometry,
10
  Menus, ComCtrls;
11

12
type
13
  TEvaluateForm = class(TForm)
14
    GroupBox1: TGroupBox;
15
    Labe1: TLabel;
16
    Label2: TLabel;
17
    Label3: TLabel;
18
    Label4: TLabel;
19
    Label5: TLabel;
20
    Label6: TLabel;
21
    EditX: TEdit;
22
    EditY: TEdit;
23
    EditZ: TEdit;
24
    Editdzdx: TEdit;
25
    Editdzdy: TEdit;
26
    Coordinates: TCheckBox;
27
    BitBtn1: TBitBtn;
28
    ToGrids: TCheckBox;
29
    EditCoordWidth: TEdit;
30
    ColorButton: TSpeedButton;
31
    ColorDialog: TColorDialog;
32
    dzdx_dzdy: TCheckBox;
33
    PopupMenu1: TPopupMenu;
34
    Slope1: TMenuItem;
35
    Degree1: TMenuItem;
36
    Radian1: TMenuItem;
37
    Label1: TLabel;
38
    EditArrow: TEdit;
39
    procedure FloatKeyPress(Sender: TObject; var Key: Char);
40
    procedure BitBtn1Click(Sender: TObject);
41
    procedure ColorButtonClick(Sender: TObject);
42
    procedure IntPress(Sender: TObject; var Key: Char);
43
    procedure EditXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
44
    procedure EditYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
45
    procedure EditCoordWidthKeyUp(Sender: TObject; var Key: Word;
46
                                   Shift: TShiftState);
47
    procedure CoordinatesClick(Sender: TObject);
48
    procedure ToGridsClick(Sender: TObject);
49
    procedure dzdx_dzdyClick(Sender: TObject);
50
    procedure MenuClick(Sender: TObject);
51
    procedure EditArrowKeyPress(Sender: TObject; var Key: Char);
52
    procedure EditArrowKeyUp(Sender: TObject; var Key: Word;
53
                              Shift: TShiftState);
54
  private
55
    { Private declarations }
56
    zValue: TGLFloat;
57
    dzdx, dzdy: TGLFloat;
58
    CurrentTag: integer;
59
    procedure ShowCoords(const x, y, z: TGLFloat; const c, t: Boolean);
60
  public
61
    { Public declarations }
62
    procedure UpdateEvaluate;
63
    procedure UpdateCoords;
64
    procedure DoEvaluate;
65
  end;
66

67
var
68
  EvaluateForm: TEvaluateForm;
69

70
implementation
71

72
uses
73
  Math, GLVectorTypes,
74
  IniFiles, uGlobal, Main, uParser, Functions, DerivativeOptions;
75

76
{$R *.lfm}
77

78
procedure TEvaluateForm.FloatKeyPress(Sender: TObject; var Key: Char);
79
begin
80
  with Sender as TEdit do
81
  if not CharInSet(Key, AnyFloat) then Key := #0;
82
end;
83

84
procedure TEvaluateForm.EditXKeyUp(Sender: TObject; var Key: Word;
85
                                    Shift: TShiftState);
86
var
87
  v: TGLFloat;
88

89
begin
90
  try
91
    v := StrToFloat(EditX.Text);
92
  except
93
    v := 0.0;
94
  end;
95
  ViewData.xEvaluate := v;
96
  DoEvaluate;
97
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
98
                              CoordChecked, ToGridsChecked);
99
  Altered := True;
100
end;
101

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

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

120
procedure TEvaluateForm.DoEvaluate;
121
var
122
  e: byte;
123
  x0, y0, x1, y1, z1, x2, y2, z2, dx, dy, dz, Sz: extended;
124
  VectorPos, VectorXDir, VectorYDir: TVector;
125

126
begin
127
  if Visible then
128
  begin
129
    with PlotData do                                //x1,y2---------------x2,y2
130
    begin                                           //  |                   |
131
      x0 := ViewData.xEvaluate;                     //  |                   |
132
      y0 := ViewData.yEvaluate;                     //  |        zValue     |
133
      dx := xInc;                                   //  |         .         |
134
      dy := yInc;                                   //  |       x0,y0       |
135
      x1 := x0 - dx;                                //  |                   |
136
      y1 := y0 - dy;                                //  |                   |
137
      x2 := x0 + dx;                                //  |                   |
138
      y2 := y0 + dy;                                //x1,y1---------------x2,y1
139
    end;
140

141
    zValue := ParseEvaluateFxy(x0, y0, PlotData.fxyStr, e);{ evaluate z, x0,y0 }
142
    EditZ.Text := FloatTostr(zValue);
143
    VectorPos := VectorMake(x0, y0, zValue*ViewData.xyGrid.zScale);
144

145
    z1 := ParseEvaluateFxy(x1, y0, PlotData.fxyStr, e);   { evaluate z1, x1,y0 }
146
    z2 := ParseEvaluateFxy(x2, y0, PlotData.fxyStr, e);   { evaluate z2, x2,y0 }
147
    dz := z2 - z1;
148
    dzdx := dz/(x2 - x1);                            { dzdx = slope wrt x axis }
149

150
    VectorXDir := VectorMake(x2 - x1, 0, dz*ViewData.xyGrid.zScale);
151
    case CurrentTag of
152
    0:Editdzdx.Text := FloatToStrF(dzdx, ffNumber, 12, 8);
153
    1:Editdzdx.Text := FloatToStrF(RadToDeg(ArcTan(dzdx)), ffNumber, 12, 8)+'°';
154
    2:Editdzdx.Text := FloatToStrF(ArcTan(dzdx), ffNumber, 12, 8)+' Rad.';
155
    end;
156

157
    z1 := ParseEvaluateFxy(x0, y1, PlotData.fxyStr, e);   { evaluate z1, x0,y1 }
158
    z2 := ParseEvaluateFxy(x0, y2, PlotData.fxyStr, e);   { evaluate z2, x0,y2 }
159
    dz := z2 - z1;
160
    dzdy := dz/(y2 - y1);                            { dzdy = slope wrt y axis }
161

162
    VectorYDir := VectorMake(0, y2 - y1, dz*ViewData.xyGrid.zScale);
163
    case CurrentTag of
164
    0:Editdzdy.Text := FloatToStrF(dzdy, ffNumber, 12, 8);
165
    1:Editdzdy.Text := FloatToStrF(RadToDeg(ArcTan(dzdy)), ffNumber, 12, 8)+'°';
166
    2:Editdzdy.Text := FloatToStrF(ArcTan(dzdy), ffNumber, 12, 8)+' Rad.';
167
    end;
168

169
    if dzdx_dzdy.Checked then
170
    begin
171
      with ViewData.xyGrid do if xRange.Step < yRange.Step
172
      then Sz := xRange.Step else Sz := yRange.Step;
173
      with ViewForm.xArrow do
174
      begin
175
        with ViewData do
176
        begin
177
          Scale.AsVector := VectorMake(ArrowSize*Sz/2, ArrowSize*Sz/2, ArrowSize*Sz);
178
          Material.FrontProperties.Diffuse.AsWinColor := xTextColor;
179
        end;
180
        Direction.AsVector := VectorXDir;
181
        Position.AsVector := VectorPos;
182
      end;
183

184
      with ViewForm.yArrow do
185
      begin
186
        with ViewData do
187
        begin
188
          Scale.AsVector := VectorMake(ArrowSize*Sz/2, ArrowSize*Sz/2, ArrowSize*Sz);
189
          Material.FrontProperties.Diffuse.AsWinColor := yTextColor;
190
        end;
191
        Direction.AsVector := VectorYDir;
192
        Position.AsVector := VectorPos;
193
      end;
194
    end;
195
  end;
196
end;
197

198
procedure TEvaluateForm.dzdx_dzdyClick(Sender: TObject);
199
begin
200
  ViewData.dzdx_dyChecked := dzdx_dzdy.Checked;
201
  ViewForm.xArrow.Visible := dzdx_dzdy.Checked;
202
  ViewForm.yArrow.Visible := dzdx_dzdy.Checked;
203
  DoEvaluate;
204
  Altered := True;
205
end;
206

207
procedure TEvaluateForm.BitBtn1Click(Sender: TObject);
208
begin
209
  Close;
210
end;
211

212
procedure TEvaluateForm.EditArrowKeyPress(Sender: TObject; var Key: Char);
213
begin
214
  with Sender as TEdit do
215
  if not CharInSet(Key, PosFloat) then Key := #0;
216
end;
217

218
procedure TEvaluateForm.EditArrowKeyUp(Sender: TObject; var Key: Word;
219
                                        Shift: TShiftState);
220
var
221
  w: TGLFloat;
222

223
begin
224
  try
225
    w := StrToFloat(EditArrow.Text);
226
  except
227
    w := 1;
228
  end;
229
  ViewData.ArrowSize := w;
230
  Altered := True;
231
  DoEvaluate;
232
end;
233

234
procedure TEvaluateForm.EditCoordWidthKeyUp(Sender: TObject; var Key: Word;
235
                                             Shift: TShiftState);
236
var
237
  w: integer;
238

239
begin
240
  try
241
    w := StrToInt(EditCoordWidth.Text);
242
  except
243
    w := 3;
244
  end;
245
  ViewData.CoordWidth := w;
246
  ViewForm.xCoordLine.LineWidth := w;
247
  ViewForm.yCoordLine.LineWidth := w;
248
  ViewForm.zCoordLine.LineWidth := w;
249
  Altered := True;
250
end;
251

252
procedure TEvaluateForm.IntPress(Sender: TObject; var Key: Char);
253
begin
254
  with Sender as TEdit do
255
  if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
256
end;
257

258
procedure TEvaluateForm.ColorButtonClick(Sender: TObject);
259
begin
260
  if ColorDialog.Execute then
261
  begin
262
    ViewData.CoordColor := ColorDialog.Color;
263
    UpdateCoords;
264
    Altered := True;
265
  end;
266
end;
267

268
procedure TEvaluateForm.CoordinatesClick(Sender: TObject);
269
begin
270
  ViewData.CoordChecked := Coordinates.Checked;
271
  DoEvaluate;
272
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
273
                              CoordChecked, ToGridsChecked);
274
  if DerivativesForm.Visible and not Coordinates.Checked then
275
  begin
276
    ViewForm.AddXLine.Visible := False;
277
    ViewForm.AddYLine.Visible := False;
278
    ViewForm.AddZLine.Visible := False;
279
  end;
280

281
  Altered := True;
282
end;
283

284
procedure TEvaluateForm.ToGridsClick(Sender: TObject);
285
begin
286
  ViewData.ToGridsChecked := ToGrids.Checked;
287
  DoEvaluate;
288
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
289
                              CoordChecked, ToGridsChecked);
290
  Altered := True;
291
end;
292

293
procedure TEvaluateForm.ShowCoords(const x, y, z: TGLFloat; const c, t: Boolean);
294
begin
295
  with ViewForm do
296
  begin
297
    if c then                  { show coords }
298
    begin
299
      with xCoordLine do
300
      begin
301
        if t then              { to grids }
302
        begin
303
          Position.SetPoint(GLyzGrid.Position.x, y, z);
304
          Nodes[0].X := x - GLyzGrid.Position.x;
305
        end
306
        else                   { +- step }
307
        begin
308
          Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, z);
309
          Nodes[0].X := 2*GLxyGrid.XSamplingScale.Step;
310
        end;
311
        Visible := True;
312
      end;
313

314
      with yCoordLine do
315
      begin
316
        if t then              { to grids }
317
        begin
318
          Position.SetPoint(x, GLxzGrid.Position.y, z);
319
          Nodes[0].Y := y - GLxzGrid.Position.y;
320
        end
321
        else                   { +- step }
322
        begin
323
          Position.SetPoint(x, y - GLxyGrid.YSamplingScale.Step, z);
324
          Nodes[0].Y := 2*GLxyGrid.YSamplingScale.Step;
325
        end;
326
        Visible := True;
327
      end;
328

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

344
    { only after DerivativesForm.ApplyBtnClick if AddedAs.AddedAs = AddVolume }
345
      if DerivativesForm.Visible then
346
      begin
347
        case AddedData.AddedAs of
348
          AddDerivX:
349
          begin
350
            with AddXLine do        { xCoord }
351
            begin
352
              if t then             { to grids }
353
              begin
354
                Position.SetPoint(GLyzGrid.Position.x, y, dzdx*ViewData.xyGrid.zScale);
355
                Nodes[0].AsVector := VectorMake(x - GLyzGrid.Position.x, 0, 0);
356
              end
357
              else                  { +- step }
358
              begin
359
                Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, dzdx*ViewData.xyGrid.zScale);
360
                Nodes[0].AsVector := VectorMake(2*GLxyGrid.XSamplingScale.Step, 0, 0);
361
              end;
362
              Visible := True;
363
            end;
364

365
            with AddYLine do         { yCoord }
366
            begin
367
              if t then              { to grids }
368
              begin
369
                Position.SetPoint(x, GLxzGrid.Position.y, dzdx*ViewData.xyGrid.zScale);
370
                Nodes[0].AsVector := VectorMake(0, y - GLxzGrid.Position.y, 0);
371
              end
372
              else                   { +- step }
373
              begin
374
                Position.SetPoint(x, y - GLxyGrid.YSamplingScale.Step, dzdx*ViewData.xyGrid.zScale);
375
                Nodes[0].AsVector := VectorMake(0, 2*GLxyGrid.YSamplingScale.Step, 0);
376
              end;
377
              Visible := True;
378
            end;
379

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

395
          end;  { AddDerivX }
396

397
          AddDerivY:
398
          begin
399
            with AddXLine do        { xCoord }
400
            begin
401
              if t then             { to grids }
402
              begin
403
                Position.SetPoint(GLyzGrid.Position.x, y, dzdy*ViewData.xyGrid.zScale);
404
                Nodes[0].AsVector := VectorMake(x - GLyzGrid.Position.x, 0, 0);
405
              end
406
              else                  { +- step }
407
              begin
408
                Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, dzdy*ViewData.xyGrid.zScale);
409
                Nodes[0].AsVector := VectorMake(2*GLxyGrid.XSamplingScale.Step, 0, 0);
410
              end;
411
              Visible := True;
412
            end;
413

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

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

444
          end;  { AddDerivY }
445

446
          AddVolume:
447
          begin
448
            AddXLine.Visible := False;
449
            AddYLine.Visible := False;
450
            AddZLine.Visible := False;
451
          end;  { AddVolume }
452
        end;  { case AddedData.AddedAs of... }
453
      end;  { if DerivativesForm.Visible then... }
454
    end   { if c then show coords }
455
    else
456
    begin { coordinate lines not visible }
457
      xCoordLine.Visible := False;
458
      yCoordLine.Visible := False;
459
      zCoordLine.Visible := False;
460
    end;
461
  end;
462

463
  with ViewData do
464
  begin
465
    EditArrow.Text := FloatToStr(ArrowSize);
466
    EditCoordWidth.Text := IntToStr(CoordWidth);
467
    ViewForm.xCoordLine.LineWidth := CoordWidth;
468
    ViewForm.yCoordLine.LineWidth := CoordWidth;
469
    ViewForm.zCoordLine.LineWidth := CoordWidth;
470
  end;
471
end;
472

473
procedure TEvaluateForm.MenuClick(Sender: TObject);
474
begin
475
  if CurrentTag <> TMenuItem(Sender).Tag then
476
  begin
477
    case CurrentTag of
478
      0:Slope1.Checked  := False;
479
      1:Degree1.Checked := False;
480
      2:Radian1.Checked := False;
481
    end;
482
    with Sender as TMenuItem do
483
    begin
484
      Checked := True;
485
      CurrentTag := Tag;
486
    end;
487
    DoEvaluate;
488
  end;
489
end;
490

491
procedure TEvaluateForm.UpdateEvaluate;
492
begin
493
  DoEvaluate;
494
  with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
495
                              CoordChecked, ToGridsChecked);
496
end;
497

498
procedure TEvaluateForm.UpdateCoords;
499
begin
500
  with ViewForm do
501
  begin
502
    with xCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
503
    with yCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
504
    with zCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
505
  end;
506
end;
507

508
end.
509

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

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

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

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