MathgeomGLS

Форк
0
/
uGlobal.pas 
581 строка · 16.4 Кб
1
unit uGlobal;
2

3
interface
4

5
uses
6
  Winapi.Windows,
7
  System.Classes,
8
  System.Types,
9
  System.SysUtils,
10
  Vcl.Graphics,
11
  Vcl.Printers;
12

13
const
14
  piCalc = 0;  // just calculate the integral area
15
  piShow = 1;  // calculate area & plot the integral
16
  piArea = 2;  // calculate & shade area
17
  piBoth = 3;  // calculate area, plot the integral & shade area
18

19
  Pi: extended = 3.1415926535897932385;
20
  PiOn2: extended = 1.5707963267948966192;
21
  twoPi: extended = 6.2831853071795864769;
22

23
  NewFName: TFileName = 'New Graph';
24

25
type
26
  TAxisStyle = (asLinear, asLog);
27
  TGridStyle = (gsNone, gsAxes, gsCartesian, gsPolar);
28

29
  TPrinterInfo = record
30
    Index: integer;          // Printer.PrinterIndex
31
    PaperID: SmallInt;       // default = DMPAPER_A4
32
    Orientation: TPrinterOrientation;
33
    xOffset: integer;        // paper print area horizontal offset pixels
34
    yOffset: integer;        // paper print area vertical offset pixels
35
    xRes: integer;           // paper print area horizontal pixels
36
    yRes: integer;           // paper print area vertical pixels
37
    xPixPerInch: integer;    // these are equal
38
    yPixPerInch: integer;
39
  end;
40

41
  TPlotData = record
42
    FunctStr: string;      // same font as grid except color = PlotColor
43
    TextStr: string;       // edit field text
44
    xInc: single;          // cartesian plot increment
45
    PlotWidth: integer;    // pen width for function plot
46
    PlotColor: TColor;     // pen color for function plot
47
    PhiInc: single;        // polar plot increment
48
    SegMin: extended;      // max and min for segment plot
49
    SegMax: extended;
50
    xLabel: extended;      // plot label location
51
    yLabel: extended;
52
    ShowLabel: Boolean;
53
    PlotAsFx: Boolean;     // true if cartesian plot
54
    IsSegment: Boolean;    // true for segment plot
55
    IsContinuous: Boolean; // when false app looks for discontinuities
56
  end;
57

58
  TGrid = record
59
    xAxisStyle: TAxisStyle;
60
    yAxisStyle: TAxisStyle;
61
    GridStyle: TGridStyle;
62
  end;
63

64
  TGraphData = record
65
    xMin: extended;        // plot area view
66
    yMin: extended;
67
    xMax: extended;
68
    yMax: extended;
69

70
    SavexMin: extended;    // saved plot area view
71
    SaveyMin: extended;
72
    SavexMax: extended;
73
    SaveyMax: extended;
74

75
    AreaAlpha: single;     // transparency of integration area
76

77
    FontName: string;
78
    FontStyle: TFontStyles;
79
    FontSize: integer;
80
    AxisWidth: integer;    { axes line pen width }
81
    xMinorGrad: integer;   { minor X axis graduation lengths }
82
    yMinorGrad: integer;   { minor Y axis graduation lengths }
83
    xMajorGrad: integer;   { major X axis graduation lengths }
84
    yMajorGrad: integer;   { major Y axis graduation lengths }
85
    MinorWidth: integer;   { minor graduation & grid line width }
86
    MajorWidth: integer;   { major graduation & grid line width }
87
    CoordWidth: integer;   { coordinate line width }
88
    dydxWidth: integer;    { derivative line width }
89
    d2ydx2Width: integer;  { 2ndderivative line width }
90
    IntegCount: integer;   { number of integration intervals }
91
    ydxWidth: integer;     { integral line width }
92

93
    BackColor: TColor;     { paper or background color }
94
    GridColor: TColor;     { grid color }
95
    xAxisColor: TColor;    { xAxis color }
96
    yAxisColor: TColor;    { yAxis color}
97
    CoordColor: TColor;    { coordinate line color }
98
    dydxColor: TColor;     { derivative line color }
99
    d2ydx2Color: TColor;   { 2ndderivative line color }
100
    ydxColor: TColor;      { integral line color }
101
    PosAreaColor: TColor;  { positive integral area color }
102
    NegAreaColor: TColor;  { negative integral area color }
103

104
    Grid: TGrid;
105
    PlotData: TPlotData;
106
  end;
107

108
  TPlotDataObject = class(TObject)
109
    constructor Create(D: TPlotData);
110
    destructor Destroy; override;
111
  private
112
  public
113
    Data: TPlotData;
114
  end;
115

116
  TGraphPoint = record
117
    PlotPoint: TPoint;
118
    x, y: extended;
119
  end;
120

121
  TGraphPointObject = class(TObject) { in uCanvas; drawing differenttial etc. }
122
    constructor Create(vx_phi, vy_r: extended);
123
    destructor Destroy; override;
124
  private
125
  public
126
    PlotPoint: TPoint;
127
    x_phi: extended;
128
    y_r: extended;
129
    DrawLine: Boolean;
130
  end;
131

132
  TGraphLine = record    { in uCanvas; drawing integral etc. }
133
    P1, P2: TPoint;
134
    x, y1, y2: extended;
135
  end;
136

137
  TGraphLineObject = class(TObject)
138
    constructor Create(vx, vy: extended);
139
    destructor Destroy; override;
140
  private
141
  public
142
    GraphLine: TGraphLine;
143
  end;
144

145
  TPenStyle = record
146
    PenWidth: integer;    { pen width for function plot }
147
    PenColor: TColor;     { pen color for function plot }
148
  end;
149

150
  TPlotStyle = record
151
    AreaAlpha: single;     { transparency of integration area }
152

153
    StyleName: string[30];
154
    FontName: string[100];
155
    FontStyle: TFontStyles;
156
    FontSize: integer;
157
    AxisWidth: integer;    { axes line pen width }
158
    xMinorGrad: integer;   { minor X axis graduation lengths }
159
    yMinorGrad: integer;   { minor Y axis graduation lengths }
160
    xMajorGrad: integer;   { major X axis graduation lengths }
161
    yMajorGrad: integer;   { major Y axis graduation lengths }
162
    MinorWidth: integer;   { minor graduation & grid line width }
163
    MajorWidth: integer;   { major graduation & grid line width }
164
    CoordWidth: integer;   { coordinate line width }
165
    dydxWidth: integer;    { derivative line width }
166
    d2ydx2Width: integer;  { 2ndderivative line width }
167
    IntegCount: integer;   { number of integration intervals }
168
    ydxWidth: integer;     { integral line width }
169

170
    BackColor: TColor;     { paper or background color }
171
    GridColor: TColor;     { grid color }
172
    xAxisColor: TColor;    { xAxis color }
173
    yAxisColor: TColor;    { yAxis color}
174
    CoordColor: TColor;    { coordinate line color }
175
    dydxColor: TColor;     { derivative line color }
176
    d2ydx2Color: TColor;   { 2ndderivative line color }
177
    ydxColor: TColor;      { integral line color }
178
    PosAreaColor: TColor;  { positive integral area color }
179
    NegAreaColor: TColor;  { negative integral area color }
180

181
    Grid: TGrid;
182
    Pens: Array[0..11] of TPenStyle;
183

184
    NumLines: Array[0..11] of TPenStyle;  { PlotWidth,  PlotColor }
185
    NumPoints: Array[0..11] of TPenStyle; { PointSize,  PointColor }
186
  end;
187

188
  TPlotStyleObject = class(TObject)
189
    constructor Create(S: TPlotStyle);
190
    destructor Destroy; override;
191
  private
192
  public
193
    Style: TPlotStyle;
194
  end;
195

196
  TFoundPointObject = class(TObject)   { used by Interpolate procedure }
197
    constructor Create(x, m, y: extended; c, mc: TColor);
198
    destructor Destroy; override;
199
  private
200
  public
201
    xValue, mValue, yValue: extended;
202
    Color, mColor: TColor;
203
  end;
204

205
  TTextData = record
206
    Caption: string;        { in CheckListBox }
207
    xLoc, yLoc: extended;   { text block left, top }
208
    yInc: integer;          { default, wbf.CharHeight }
209
    FontName: string;       { wbf font }
210
    FontStyle: TFontStyles; { style }
211
    FontSize: integer;      { size }
212
    FontColor: TColor;      { color }
213
  end;
214

215
  TTextLineObject = class(TObject)
216
    constructor Create(T: string; C: TColor);
217
    destructor Destroy; override;
218
  private
219
  public
220
    Text: string;
221
    Color: TColor;
222
  end;
223

224
  TTextDataObject = class(TObject)
225
    constructor Create(D: TTextData);
226
    destructor Destroy; override;
227
  private
228
  public
229
    Data: TTextData;
230
    TextLines: TList;       // TTextLineObject list
231
  end;
232

233
  TNumericStyle = (nsNone, nsLinear, nsLagrange, nsHermite);
234
  TPointStyle = (psSquare, psPlus, psCross, psCircle);
235

236
  TNumericData = record
237
    Name: string;                  { descriptive name }
238
    NumericStyle: TNumericStyle;   { nsNone, nsLinear, nsLagrange, nsHermite }
239
    ShowPoints: Boolean;           { points visible if true }
240
    PointStyle: TPointStyle;       { psSquare, psPlus, psCross, psCircle }
241
    PointSize: integer;            {  }
242
    PointColor: TColor;            {  }
243
    PlotWidth: integer;            { pen width for plot }
244
    PlotColor: TColor;             { pen color for plot }
245
    SortXValue: Boolean;           { x values sorted if true }
246
    Extrapolate: Boolean;          { extrapolate graph if true }
247
    CoordsIdx: integer;            { enter coords as x, y or phi, r or vector }
248
    CurveRate: integer;            { was k0 factor k0 = CurveRate/100 }
249
  end;
250

251
  TNumericObject = class(TObject)
252
    constructor Create(D: TNumericData);
253
    destructor Destroy; override;
254
  private
255
  public
256
    Data: TNumericData;
257
    ControlPoints: TList;         // list of TGraphPointObject
258
  end;
259

260
  TLayout = record
261
    IsMaximize: Boolean;  // is true if MainForm.WindowState = wsMaximized
262
    MainLeft: integer;
263
    MainTop: integer;
264
    MainWidth: integer;
265
    MainHeight: integer;
266
    CurrentGraphFName: ShortString;
267
    CurrentDataPath: ShortString;
268
    CurrentImagePath: ShortString;
269
    CurrentPrinterInfo: TPrinterInfo;
270
    GridsVisible: Boolean;
271
    GridsLeft: integer;
272
    GridsTop: integer;
273
    NumericVisible: Boolean;
274
    NumericLeft: integer;
275
    NumericTop: integer;
276
    TextVisible: Boolean;
277
    TextLeft: integer;
278
    TextTop: integer;
279
    TextWidth: integer;
280
    TextHeight: integer;
281
    FuncLeft: integer;
282
    FuncTop: integer;
283
    DerivLeft: integer;
284
    DerivTop: integer;
285
    IntegXLeft: integer;
286
    IntegXTop: integer;
287
    IntegYLeft: integer;
288
    IntegYTop: integer;
289
    BetweenLeft: integer;
290
    BetweenTop: integer;
291
    VolumeXLeft: integer;
292
    VolumeXTop: integer;
293
    VolumeYLeft: integer;
294
    VolumeYTop: integer;
295
    fxLeft: integer;
296
    fxTop: integer;
297
    fx1Left: integer;
298
    fx1Top: integer;
299
    fx2Left: integer;
300
    fX2Top: integer;
301
    PrintLeft: integer;
302
    PrintTop: integer;
303
    PrintScale: double;
304
    PrintBorderColor: integer;
305
    PrintBorderWidth: integer;
306
    PrintUnit: integer;
307
    BitmapLeft: integer;
308
    BitmapTop: integer;
309
    BitmapScale: double;
310
    BitmapBorderColor: integer;
311
    BitmapBorderWidth: integer;
312
    BitmapUnit: integer;
313
    StyleLeft: integer;
314
    StyleTop: integer;
315
  end;
316

317
var
318
  GraphData: TGraphData;
319
  Altered: Boolean;   // any alteration to the plot
320
  LabelRect: TRect;
321
  BinPath: TFileName;
322
///  PlotPath: TFileName;  // now the same as for Plot1d.dproj
323
  DataPath: TFileName;
324
  ImagePath: TFileName;
325
  GraphFName: TFileName;
326
  StyleFName: TFileName;
327
  LayoutFName: TFileName;
328

329
// Miscellaneous Parameters
330
  PhiIncMin: single = 0.00001;
331
  xEvaluate: extended = 0;
332
  yEvaluate: extended = 0;
333
  yCosxEval: extended = 0;
334
  ySinxEval: extended = 0;
335

336
  IntegCountMax: integer = 256000;
337
  IntegMin: extended;
338
  IntegMax: extended;
339
  KeptMin: extended;
340
  KeptMax: extended;
341
  KeepRange: Boolean;
342
  IntegConst: extended;
343
  IntegCountPos: integer;
344

345
  PrinterInfo: TPrinterInfo;
346
  Layout: TLayout;
347

348
  procedure GetPrinterInfo(var Info: TPrinterInfo);
349
  procedure SetPrinterInfo(const Info: TPrinterInfo);
350
  function GetPaperType: string;
351

352
//========================================================================
353
implementation
354
//========================================================================
355

356
constructor TPlotDataObject.Create(D: TPlotData);
357
begin
358
  inherited Create;
359
  Data := D;
360
end;
361

362
destructor TPlotDataObject.Destroy;
363
begin
364
  inherited Destroy;
365
end;
366

367
constructor TGraphPointObject.Create(vx_phi, vy_r: extended);
368
begin
369
  inherited Create;
370
  x_phi := vx_phi;
371
  y_r := vy_r;
372
end;
373

374
destructor TGraphPointObject.Destroy;
375
begin
376
  inherited Destroy;
377
end;
378

379
constructor TGraphLineObject.Create(vx, vy: extended);
380
begin
381
  inherited Create;
382
  with GraphLine do
383
  begin
384
    x := vx;
385
    y1 := vy;
386
  end;
387
end;
388

389
destructor TGraphLineObject.Destroy;
390
begin
391
  inherited Destroy;
392
end;
393

394
constructor TPlotStyleObject.Create(S: TPlotStyle);
395
begin
396
  inherited Create;
397
  Style := S;
398
end;
399

400
destructor TPlotStyleObject.Destroy;
401
begin
402
  inherited Destroy;
403
end;
404

405
constructor TFoundPointObject.Create(x, m, y: extended; c, mc: TColor);
406
begin
407
  inherited Create;
408
  xValue := x;
409
  mValue := m;
410
  yValue := y;
411
  Color := c;
412
  mColor := mc;
413
end;
414

415
destructor TFoundPointObject.Destroy;
416
begin
417
  inherited Destroy;
418
end;
419

420
constructor TTextLineObject.Create(T: string; C: TColor);
421
begin
422
  inherited Create;
423
  Text := T;
424
  Color := C;
425
end;
426

427
destructor TTextLineObject.Destroy;
428
begin
429
  inherited Destroy;
430
end;
431

432
constructor TTextDataObject.Create(D: TTextData);
433
begin
434
  inherited Create;
435
  Data := D;
436
  TextLines := TList.Create;
437
end;
438

439
destructor TTextDataObject.Destroy;
440
  var
441
    i: integer;
442

443
begin
444
  for i := 0 to TextLines.Count -1 do TTextLineObject(TextLines.Items[i]).Free;
445
  TextLines.Free;
446
  inherited Destroy;
447
end;
448

449
constructor TNumericObject.Create(D: TNumericData);
450
begin
451
  inherited Create;
452
  Data := D;
453
  ControlPoints := TList.Create;
454
end;
455

456
destructor TNumericObject.Destroy;
457
  var
458
    i: integer;
459

460
begin
461
  for i := 0 to ControlPoints.Count -1 do TObject(ControlPoints.Items[i]).Free;
462
  ControlPoints.Free;
463
  inherited Destroy;
464
end;
465

466
procedure GetPrinterInfo(var Info: TPrinterInfo);
467
var
468
  Device: array [0..255] of char;
469
  Driver: array [0..255] of char;
470
  Port: array [0..255] of char;
471
  hDMode: THandle;
472
  pDMode: PDevMode;
473

474
begin
475
  Printer.GetPrinter(Device, Driver, Port, hDMode);
476
  if hDMode <> 0 then
477
  begin
478
    pDMode := GlobalLock(hDMode);
479
    if pDMode <> nil then
480
    begin
481
      with Info do PaperID := pDMode.dmPaperSize;  // default = DMPAPER_A4
482
      GlobalUnlock(hDMode);
483
      with Info do
484
      begin
485
        Index := Printer.PrinterIndex;
486
        xPixPerInch := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
487
        yPixPerInch := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
488
        xOffset := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
489
        yOffset := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
490
        xRes := GetDeviceCaps(Printer.Handle, HORZRES);
491
        yRes := GetDeviceCaps(Printer.Handle, VERTRES);
492
        Orientation := Printer.Orientation;
493
      end;
494
    end;
495
  end;
496
end;
497

498
procedure SetPrinterInfo(const Info: TPrinterInfo);
499
var
500
  Device: array [0..255] of char;
501
  Driver: array [0..255] of char;
502
  Port: array [0..255] of char;
503
  hDMode: THandle;
504
  pDMode: PDevMode;
505

506
begin
507
  Printer.GetPrinter(Device, Driver, Port, hDMode);
508
  if (PrinterInfo.Index < -1) or
509
     (PrinterInfo.Index > Printer.Printers.Count -1)
510
  then PrinterInfo.Index := -1;
511

512
  Printer.PrinterIndex := PrinterInfo.Index;
513
  Printer.Orientation := PrinterInfo.Orientation;
514
  if hDMode <> 0 then
515
  begin
516
    pDMode := GlobalLock(hDMode);
517
    if pDMode <> nil then
518
    begin
519
      pDMode.dmPaperSize := PrinterInfo.PaperID;    { default = DMPAPER_A4 }
520
      pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE;
521
      pDMode^.dmFields := pDMode^.dmFields or DM_ORIENTATION;
522
      pDMode^.dmFields := pDMode^.dmFields or DM_DEFAULTSOURCE;
523
      GlobalUnlock(hDMode);
524
    end;
525
  end;
526
end;
527

528
function GetPaperType: string;
529
var
530
  s: string;
531
begin
532
  case PrinterInfo.PaperID of
533
DMPAPER_LETTER:      s := 'Letter, 8�" x 11"';
534
DMPAPER_LEGAL:       s := 'Legal, 8�" x 14"';
535
DMPAPER_A4:          s := 'A4, 210mm x 297mm';
536
DMPAPER_CSHEET:      s := 'C, 17" x 22"';
537
DMPAPER_DSHEET:      s := 'D, 22" x 34"';
538
DMPAPER_ESHEET:      s := 'E, 34" x 44"';
539
DMPAPER_LETTERSMALL: s := 'Letter, 8�" x 11"';
540
DMPAPER_TABLOID:     s := 'Tabloid, 11" x 17"';
541
DMPAPER_LEDGER:      s := 'Ledger, 17" x 11"';
542
DMPAPER_STATEMENT:   s := 'Statement, 5�" x 8�"';
543
DMPAPER_EXECUTIVE:   s := 'Executive, 7�" x 10�"';
544
DMPAPER_A3:          s := 'A3, 297mm x 420mm';
545
DMPAPER_A4SMALL:     s := 'A4, 210mm x 297mm';
546
DMPAPER_A5:          s := 'A5, 148mm x 210mm';
547
DMPAPER_B4:          s := 'B4, 250mm x 354mm';
548
DMPAPER_B5:          s := 'B5, 182mm x 257mm';
549
DMPAPER_FOLIO:       s := 'Folio, 8�" x 13"';
550
DMPAPER_QUARTO:      s := 'Quarto, 215mm x 275mm';
551
DMPAPER_10X14:       s := 'Sheet, 10" x 14"';
552
DMPAPER_11X17:       s := 'Sheet, 11" x 17"';
553
DMPAPER_NOTE:        s := 'Note, 8�" x 11"';
554
DMPAPER_ENV_9:       s := 'Envelope 3 7/8" x 8 7/8"';
555
DMPAPER_ENV_10:      s := 'Envelope 4 1/8" x 9�"';
556
DMPAPER_ENV_11:      s := 'Envelope 4�" x 10 3/8"';
557
DMPAPER_ENV_12:      s := 'Envelope 4�" x 11"';
558
DMPAPER_ENV_14:      s := 'Envelope 5" x 11�"';
559
DMPAPER_ENV_DL:      s := 'Envelope 110mm x 220mm';
560
DMPAPER_ENV_C5:      s := 'Envelope 162mm x 229mm';
561
DMPAPER_ENV_C3:      s := 'Envelope 324mm x 458mm';
562
DMPAPER_ENV_C4:      s := 'Envelope 229mm x 324mm';
563
DMPAPER_ENV_C6:      s := 'Envelope 114mm x 162mm';
564
DMPAPER_ENV_C65:     s := 'Envelope 114mm x 229mm';
565
DMPAPER_ENV_B4:      s := 'Envelope 250mm x 353mm';
566
DMPAPER_ENV_B5:      s := 'Envelope 176mm x 250mm';
567
DMPAPER_ENV_B6:      s := 'Envelope 176mm x 125mm';
568
DMPAPER_ENV_ITALY:   s := 'Envelope 110mm x 230mm';
569
DMPAPER_ENV_MONARCH: s := 'Envelope 3 7/8" x 7�"';
570
DMPAPER_ENV_PERSONAL:s := 'Envelope 3 5/8" x 6�"';
571
DMPAPER_FANFOLD_US:  s := 'Fanfold, 14 7/8" x 11"';
572
DMPAPER_FANFOLD_STD_GERMAN:s := 'Fanfold, 8�" x 12"';
573
DMPAPER_FANFOLD_LGL_GERMAN:s := 'Fanfold, 8�" x 13"';
574
260: s := '8" x 6"';
575
262: s := 'Fanfold, 210mm x 12"';
576
else s := 'Custom ';
577
  end;
578
  Result := s;
579
end;
580

581
end.
582

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

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

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

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