MathgeomGLS
581 строка · 16.4 Кб
1unit uGlobal;
2
3interface
4
5uses
6Winapi.Windows,
7System.Classes,
8System.Types,
9System.SysUtils,
10Vcl.Graphics,
11Vcl.Printers;
12
13const
14piCalc = 0; // just calculate the integral area
15piShow = 1; // calculate area & plot the integral
16piArea = 2; // calculate & shade area
17piBoth = 3; // calculate area, plot the integral & shade area
18
19Pi: extended = 3.1415926535897932385;
20PiOn2: extended = 1.5707963267948966192;
21twoPi: extended = 6.2831853071795864769;
22
23NewFName: TFileName = 'New Graph';
24
25type
26TAxisStyle = (asLinear, asLog);
27TGridStyle = (gsNone, gsAxes, gsCartesian, gsPolar);
28
29TPrinterInfo = record
30Index: integer; // Printer.PrinterIndex
31PaperID: SmallInt; // default = DMPAPER_A4
32Orientation: TPrinterOrientation;
33xOffset: integer; // paper print area horizontal offset pixels
34yOffset: integer; // paper print area vertical offset pixels
35xRes: integer; // paper print area horizontal pixels
36yRes: integer; // paper print area vertical pixels
37xPixPerInch: integer; // these are equal
38yPixPerInch: integer;
39end;
40
41TPlotData = record
42FunctStr: string; // same font as grid except color = PlotColor
43TextStr: string; // edit field text
44xInc: single; // cartesian plot increment
45PlotWidth: integer; // pen width for function plot
46PlotColor: TColor; // pen color for function plot
47PhiInc: single; // polar plot increment
48SegMin: extended; // max and min for segment plot
49SegMax: extended;
50xLabel: extended; // plot label location
51yLabel: extended;
52ShowLabel: Boolean;
53PlotAsFx: Boolean; // true if cartesian plot
54IsSegment: Boolean; // true for segment plot
55IsContinuous: Boolean; // when false app looks for discontinuities
56end;
57
58TGrid = record
59xAxisStyle: TAxisStyle;
60yAxisStyle: TAxisStyle;
61GridStyle: TGridStyle;
62end;
63
64TGraphData = record
65xMin: extended; // plot area view
66yMin: extended;
67xMax: extended;
68yMax: extended;
69
70SavexMin: extended; // saved plot area view
71SaveyMin: extended;
72SavexMax: extended;
73SaveyMax: extended;
74
75AreaAlpha: single; // transparency of integration area
76
77FontName: string;
78FontStyle: TFontStyles;
79FontSize: integer;
80AxisWidth: integer; { axes line pen width }
81xMinorGrad: integer; { minor X axis graduation lengths }
82yMinorGrad: integer; { minor Y axis graduation lengths }
83xMajorGrad: integer; { major X axis graduation lengths }
84yMajorGrad: integer; { major Y axis graduation lengths }
85MinorWidth: integer; { minor graduation & grid line width }
86MajorWidth: integer; { major graduation & grid line width }
87CoordWidth: integer; { coordinate line width }
88dydxWidth: integer; { derivative line width }
89d2ydx2Width: integer; { 2ndderivative line width }
90IntegCount: integer; { number of integration intervals }
91ydxWidth: integer; { integral line width }
92
93BackColor: TColor; { paper or background color }
94GridColor: TColor; { grid color }
95xAxisColor: TColor; { xAxis color }
96yAxisColor: TColor; { yAxis color}
97CoordColor: TColor; { coordinate line color }
98dydxColor: TColor; { derivative line color }
99d2ydx2Color: TColor; { 2ndderivative line color }
100ydxColor: TColor; { integral line color }
101PosAreaColor: TColor; { positive integral area color }
102NegAreaColor: TColor; { negative integral area color }
103
104Grid: TGrid;
105PlotData: TPlotData;
106end;
107
108TPlotDataObject = class(TObject)
109constructor Create(D: TPlotData);
110destructor Destroy; override;
111private
112public
113Data: TPlotData;
114end;
115
116TGraphPoint = record
117PlotPoint: TPoint;
118x, y: extended;
119end;
120
121TGraphPointObject = class(TObject) { in uCanvas; drawing differenttial etc. }
122constructor Create(vx_phi, vy_r: extended);
123destructor Destroy; override;
124private
125public
126PlotPoint: TPoint;
127x_phi: extended;
128y_r: extended;
129DrawLine: Boolean;
130end;
131
132TGraphLine = record { in uCanvas; drawing integral etc. }
133P1, P2: TPoint;
134x, y1, y2: extended;
135end;
136
137TGraphLineObject = class(TObject)
138constructor Create(vx, vy: extended);
139destructor Destroy; override;
140private
141public
142GraphLine: TGraphLine;
143end;
144
145TPenStyle = record
146PenWidth: integer; { pen width for function plot }
147PenColor: TColor; { pen color for function plot }
148end;
149
150TPlotStyle = record
151AreaAlpha: single; { transparency of integration area }
152
153StyleName: string[30];
154FontName: string[100];
155FontStyle: TFontStyles;
156FontSize: integer;
157AxisWidth: integer; { axes line pen width }
158xMinorGrad: integer; { minor X axis graduation lengths }
159yMinorGrad: integer; { minor Y axis graduation lengths }
160xMajorGrad: integer; { major X axis graduation lengths }
161yMajorGrad: integer; { major Y axis graduation lengths }
162MinorWidth: integer; { minor graduation & grid line width }
163MajorWidth: integer; { major graduation & grid line width }
164CoordWidth: integer; { coordinate line width }
165dydxWidth: integer; { derivative line width }
166d2ydx2Width: integer; { 2ndderivative line width }
167IntegCount: integer; { number of integration intervals }
168ydxWidth: integer; { integral line width }
169
170BackColor: TColor; { paper or background color }
171GridColor: TColor; { grid color }
172xAxisColor: TColor; { xAxis color }
173yAxisColor: TColor; { yAxis color}
174CoordColor: TColor; { coordinate line color }
175dydxColor: TColor; { derivative line color }
176d2ydx2Color: TColor; { 2ndderivative line color }
177ydxColor: TColor; { integral line color }
178PosAreaColor: TColor; { positive integral area color }
179NegAreaColor: TColor; { negative integral area color }
180
181Grid: TGrid;
182Pens: Array[0..11] of TPenStyle;
183
184NumLines: Array[0..11] of TPenStyle; { PlotWidth, PlotColor }
185NumPoints: Array[0..11] of TPenStyle; { PointSize, PointColor }
186end;
187
188TPlotStyleObject = class(TObject)
189constructor Create(S: TPlotStyle);
190destructor Destroy; override;
191private
192public
193Style: TPlotStyle;
194end;
195
196TFoundPointObject = class(TObject) { used by Interpolate procedure }
197constructor Create(x, m, y: extended; c, mc: TColor);
198destructor Destroy; override;
199private
200public
201xValue, mValue, yValue: extended;
202Color, mColor: TColor;
203end;
204
205TTextData = record
206Caption: string; { in CheckListBox }
207xLoc, yLoc: extended; { text block left, top }
208yInc: integer; { default, wbf.CharHeight }
209FontName: string; { wbf font }
210FontStyle: TFontStyles; { style }
211FontSize: integer; { size }
212FontColor: TColor; { color }
213end;
214
215TTextLineObject = class(TObject)
216constructor Create(T: string; C: TColor);
217destructor Destroy; override;
218private
219public
220Text: string;
221Color: TColor;
222end;
223
224TTextDataObject = class(TObject)
225constructor Create(D: TTextData);
226destructor Destroy; override;
227private
228public
229Data: TTextData;
230TextLines: TList; // TTextLineObject list
231end;
232
233TNumericStyle = (nsNone, nsLinear, nsLagrange, nsHermite);
234TPointStyle = (psSquare, psPlus, psCross, psCircle);
235
236TNumericData = record
237Name: string; { descriptive name }
238NumericStyle: TNumericStyle; { nsNone, nsLinear, nsLagrange, nsHermite }
239ShowPoints: Boolean; { points visible if true }
240PointStyle: TPointStyle; { psSquare, psPlus, psCross, psCircle }
241PointSize: integer; { }
242PointColor: TColor; { }
243PlotWidth: integer; { pen width for plot }
244PlotColor: TColor; { pen color for plot }
245SortXValue: Boolean; { x values sorted if true }
246Extrapolate: Boolean; { extrapolate graph if true }
247CoordsIdx: integer; { enter coords as x, y or phi, r or vector }
248CurveRate: integer; { was k0 factor k0 = CurveRate/100 }
249end;
250
251TNumericObject = class(TObject)
252constructor Create(D: TNumericData);
253destructor Destroy; override;
254private
255public
256Data: TNumericData;
257ControlPoints: TList; // list of TGraphPointObject
258end;
259
260TLayout = record
261IsMaximize: Boolean; // is true if MainForm.WindowState = wsMaximized
262MainLeft: integer;
263MainTop: integer;
264MainWidth: integer;
265MainHeight: integer;
266CurrentGraphFName: ShortString;
267CurrentDataPath: ShortString;
268CurrentImagePath: ShortString;
269CurrentPrinterInfo: TPrinterInfo;
270GridsVisible: Boolean;
271GridsLeft: integer;
272GridsTop: integer;
273NumericVisible: Boolean;
274NumericLeft: integer;
275NumericTop: integer;
276TextVisible: Boolean;
277TextLeft: integer;
278TextTop: integer;
279TextWidth: integer;
280TextHeight: integer;
281FuncLeft: integer;
282FuncTop: integer;
283DerivLeft: integer;
284DerivTop: integer;
285IntegXLeft: integer;
286IntegXTop: integer;
287IntegYLeft: integer;
288IntegYTop: integer;
289BetweenLeft: integer;
290BetweenTop: integer;
291VolumeXLeft: integer;
292VolumeXTop: integer;
293VolumeYLeft: integer;
294VolumeYTop: integer;
295fxLeft: integer;
296fxTop: integer;
297fx1Left: integer;
298fx1Top: integer;
299fx2Left: integer;
300fX2Top: integer;
301PrintLeft: integer;
302PrintTop: integer;
303PrintScale: double;
304PrintBorderColor: integer;
305PrintBorderWidth: integer;
306PrintUnit: integer;
307BitmapLeft: integer;
308BitmapTop: integer;
309BitmapScale: double;
310BitmapBorderColor: integer;
311BitmapBorderWidth: integer;
312BitmapUnit: integer;
313StyleLeft: integer;
314StyleTop: integer;
315end;
316
317var
318GraphData: TGraphData;
319Altered: Boolean; // any alteration to the plot
320LabelRect: TRect;
321BinPath: TFileName;
322/// PlotPath: TFileName; // now the same as for Plot1d.dproj
323DataPath: TFileName;
324ImagePath: TFileName;
325GraphFName: TFileName;
326StyleFName: TFileName;
327LayoutFName: TFileName;
328
329// Miscellaneous Parameters
330PhiIncMin: single = 0.00001;
331xEvaluate: extended = 0;
332yEvaluate: extended = 0;
333yCosxEval: extended = 0;
334ySinxEval: extended = 0;
335
336IntegCountMax: integer = 256000;
337IntegMin: extended;
338IntegMax: extended;
339KeptMin: extended;
340KeptMax: extended;
341KeepRange: Boolean;
342IntegConst: extended;
343IntegCountPos: integer;
344
345PrinterInfo: TPrinterInfo;
346Layout: TLayout;
347
348procedure GetPrinterInfo(var Info: TPrinterInfo);
349procedure SetPrinterInfo(const Info: TPrinterInfo);
350function GetPaperType: string;
351
352//========================================================================
353implementation
354//========================================================================
355
356constructor TPlotDataObject.Create(D: TPlotData);
357begin
358inherited Create;
359Data := D;
360end;
361
362destructor TPlotDataObject.Destroy;
363begin
364inherited Destroy;
365end;
366
367constructor TGraphPointObject.Create(vx_phi, vy_r: extended);
368begin
369inherited Create;
370x_phi := vx_phi;
371y_r := vy_r;
372end;
373
374destructor TGraphPointObject.Destroy;
375begin
376inherited Destroy;
377end;
378
379constructor TGraphLineObject.Create(vx, vy: extended);
380begin
381inherited Create;
382with GraphLine do
383begin
384x := vx;
385y1 := vy;
386end;
387end;
388
389destructor TGraphLineObject.Destroy;
390begin
391inherited Destroy;
392end;
393
394constructor TPlotStyleObject.Create(S: TPlotStyle);
395begin
396inherited Create;
397Style := S;
398end;
399
400destructor TPlotStyleObject.Destroy;
401begin
402inherited Destroy;
403end;
404
405constructor TFoundPointObject.Create(x, m, y: extended; c, mc: TColor);
406begin
407inherited Create;
408xValue := x;
409mValue := m;
410yValue := y;
411Color := c;
412mColor := mc;
413end;
414
415destructor TFoundPointObject.Destroy;
416begin
417inherited Destroy;
418end;
419
420constructor TTextLineObject.Create(T: string; C: TColor);
421begin
422inherited Create;
423Text := T;
424Color := C;
425end;
426
427destructor TTextLineObject.Destroy;
428begin
429inherited Destroy;
430end;
431
432constructor TTextDataObject.Create(D: TTextData);
433begin
434inherited Create;
435Data := D;
436TextLines := TList.Create;
437end;
438
439destructor TTextDataObject.Destroy;
440var
441i: integer;
442
443begin
444for i := 0 to TextLines.Count -1 do TTextLineObject(TextLines.Items[i]).Free;
445TextLines.Free;
446inherited Destroy;
447end;
448
449constructor TNumericObject.Create(D: TNumericData);
450begin
451inherited Create;
452Data := D;
453ControlPoints := TList.Create;
454end;
455
456destructor TNumericObject.Destroy;
457var
458i: integer;
459
460begin
461for i := 0 to ControlPoints.Count -1 do TObject(ControlPoints.Items[i]).Free;
462ControlPoints.Free;
463inherited Destroy;
464end;
465
466procedure GetPrinterInfo(var Info: TPrinterInfo);
467var
468Device: array [0..255] of char;
469Driver: array [0..255] of char;
470Port: array [0..255] of char;
471hDMode: THandle;
472pDMode: PDevMode;
473
474begin
475Printer.GetPrinter(Device, Driver, Port, hDMode);
476if hDMode <> 0 then
477begin
478pDMode := GlobalLock(hDMode);
479if pDMode <> nil then
480begin
481with Info do PaperID := pDMode.dmPaperSize; // default = DMPAPER_A4
482GlobalUnlock(hDMode);
483with Info do
484begin
485Index := Printer.PrinterIndex;
486xPixPerInch := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
487yPixPerInch := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
488xOffset := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
489yOffset := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
490xRes := GetDeviceCaps(Printer.Handle, HORZRES);
491yRes := GetDeviceCaps(Printer.Handle, VERTRES);
492Orientation := Printer.Orientation;
493end;
494end;
495end;
496end;
497
498procedure SetPrinterInfo(const Info: TPrinterInfo);
499var
500Device: array [0..255] of char;
501Driver: array [0..255] of char;
502Port: array [0..255] of char;
503hDMode: THandle;
504pDMode: PDevMode;
505
506begin
507Printer.GetPrinter(Device, Driver, Port, hDMode);
508if (PrinterInfo.Index < -1) or
509(PrinterInfo.Index > Printer.Printers.Count -1)
510then PrinterInfo.Index := -1;
511
512Printer.PrinterIndex := PrinterInfo.Index;
513Printer.Orientation := PrinterInfo.Orientation;
514if hDMode <> 0 then
515begin
516pDMode := GlobalLock(hDMode);
517if pDMode <> nil then
518begin
519pDMode.dmPaperSize := PrinterInfo.PaperID; { default = DMPAPER_A4 }
520pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE;
521pDMode^.dmFields := pDMode^.dmFields or DM_ORIENTATION;
522pDMode^.dmFields := pDMode^.dmFields or DM_DEFAULTSOURCE;
523GlobalUnlock(hDMode);
524end;
525end;
526end;
527
528function GetPaperType: string;
529var
530s: string;
531begin
532case PrinterInfo.PaperID of
533DMPAPER_LETTER: s := 'Letter, 8�" x 11"';
534DMPAPER_LEGAL: s := 'Legal, 8�" x 14"';
535DMPAPER_A4: s := 'A4, 210mm x 297mm';
536DMPAPER_CSHEET: s := 'C, 17" x 22"';
537DMPAPER_DSHEET: s := 'D, 22" x 34"';
538DMPAPER_ESHEET: s := 'E, 34" x 44"';
539DMPAPER_LETTERSMALL: s := 'Letter, 8�" x 11"';
540DMPAPER_TABLOID: s := 'Tabloid, 11" x 17"';
541DMPAPER_LEDGER: s := 'Ledger, 17" x 11"';
542DMPAPER_STATEMENT: s := 'Statement, 5�" x 8�"';
543DMPAPER_EXECUTIVE: s := 'Executive, 7�" x 10�"';
544DMPAPER_A3: s := 'A3, 297mm x 420mm';
545DMPAPER_A4SMALL: s := 'A4, 210mm x 297mm';
546DMPAPER_A5: s := 'A5, 148mm x 210mm';
547DMPAPER_B4: s := 'B4, 250mm x 354mm';
548DMPAPER_B5: s := 'B5, 182mm x 257mm';
549DMPAPER_FOLIO: s := 'Folio, 8�" x 13"';
550DMPAPER_QUARTO: s := 'Quarto, 215mm x 275mm';
551DMPAPER_10X14: s := 'Sheet, 10" x 14"';
552DMPAPER_11X17: s := 'Sheet, 11" x 17"';
553DMPAPER_NOTE: s := 'Note, 8�" x 11"';
554DMPAPER_ENV_9: s := 'Envelope 3 7/8" x 8 7/8"';
555DMPAPER_ENV_10: s := 'Envelope 4 1/8" x 9�"';
556DMPAPER_ENV_11: s := 'Envelope 4�" x 10 3/8"';
557DMPAPER_ENV_12: s := 'Envelope 4�" x 11"';
558DMPAPER_ENV_14: s := 'Envelope 5" x 11�"';
559DMPAPER_ENV_DL: s := 'Envelope 110mm x 220mm';
560DMPAPER_ENV_C5: s := 'Envelope 162mm x 229mm';
561DMPAPER_ENV_C3: s := 'Envelope 324mm x 458mm';
562DMPAPER_ENV_C4: s := 'Envelope 229mm x 324mm';
563DMPAPER_ENV_C6: s := 'Envelope 114mm x 162mm';
564DMPAPER_ENV_C65: s := 'Envelope 114mm x 229mm';
565DMPAPER_ENV_B4: s := 'Envelope 250mm x 353mm';
566DMPAPER_ENV_B5: s := 'Envelope 176mm x 250mm';
567DMPAPER_ENV_B6: s := 'Envelope 176mm x 125mm';
568DMPAPER_ENV_ITALY: s := 'Envelope 110mm x 230mm';
569DMPAPER_ENV_MONARCH: s := 'Envelope 3 7/8" x 7�"';
570DMPAPER_ENV_PERSONAL:s := 'Envelope 3 5/8" x 6�"';
571DMPAPER_FANFOLD_US: s := 'Fanfold, 14 7/8" x 11"';
572DMPAPER_FANFOLD_STD_GERMAN:s := 'Fanfold, 8�" x 12"';
573DMPAPER_FANFOLD_LGL_GERMAN:s := 'Fanfold, 8�" x 13"';
574260: s := '8" x 6"';
575262: s := 'Fanfold, 210mm x 12"';
576else s := 'Custom ';
577end;
578Result := s;
579end;
580
581end.
582