home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 October
/
Chip_2001-10_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d123456
/
CHEMPLOT.ZIP
/
TPlot
/
Demo
/
Normal1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2001-07-26
|
15KB
|
510 lines
unit Normal1;
{$I Chemware.inc}
{.$ DEFINE JUST_THE_GRAPH}
interface
uses
SysUtils, Classes, TypInfo,
{$IFDEF WIN32}
Windows, Messages, Graphics, Controls, Forms, Dialogs,
ImgList, Menus, Grids, ExtCtrls, StdCtrls,
Buttons, ToolWin, ComCtrls,
{$ENDIF}
{$IFDEF LINUX}
Types, //Untranslated,
Qt, QTypes,
QGraphics, QControls, QForms, QDialogs,
QImgList, QMenus, QGrids, QExtCtrls, QStdCtrls,
QButtons, QComCtrls,
{$ENDIF}
Plot, Plotdefs, Plotmenu, Plotimagelist, Data, Plottoolbar, Nedit, Misc;
type
TMainForm = class(TForm)
Panel1: TPanel;
StringGrid1: TStringGrid;
MinNEdit: TNEdit;
Label1: TLabel;
Label2: TLabel;
MaxNEdit: TNEdit;
Label3: TLabel;
StepSizeNEdit: TNEdit;
Label4: TLabel;
MeanNEdit: TNEdit;
Label5: TLabel;
StdDevNEdit: TNEdit;
GoBitBtn: TBitBtn;
GoCrazyBitBtn: TBitBtn;
ClearAllBitBtn: TBitBtn;
NoisyBitBtn: TBitBtn;
TraceBitBtn: TBitBtn;
TypeBitBtn: TBitBtn;
StatusBar1: TStatusBar;
procedure ClearAllBitBtnClick(Sender: TObject);
procedure GoBitBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PlotMenu1ExitMenuItemClick(Sender: TObject);
procedure NoisyBitBtnClick(Sender: TObject);
procedure GoCrazyBitBtnClick(Sender: TObject);
procedure CrazyTimerTimer(Sender: TObject);
procedure MyPlotFileOpen(Sender: TObject; TheFile: String);
procedure TraceBitBtnClick(Sender: TObject);
procedure TypeBitBtnClick(Sender: TObject);
procedure Plot1AfterPaint(Sender: TObject; ACanvas: TCanvas);
procedure MyPlotBeforeDraw(Sender: TObject; ACanvas: TCanvas);
private
MyPlot: TPlot;
{$IFNDEF JUST_THE_GRAPH}
MyPlotMenu: TPlotMenu;
MyPlotImageList: TPlotImageList;
MyPlotToolBar: TPlotToolBar;
{$ENDIF}
Revolutions,
StartWidth,
StartHeight: Integer;
Angle,
AngleInc: Single;
StartTime: TDateTime;
TypeClicked: Boolean;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
{$R Penguin.res}
{Kylix seems to have a versioninfo resource already.
Unfortunately, it is empty.}
{.$ R version.res}
const
RADIUS = 50.0;
{$IFDEF WIN32}
MYCAPTION = 'TPlot demo for Delphi';
{$ENDIF}
{$IFDEF LINUX}
MYCAPTION = 'TPlot demo for Kylix';
{$ENDIF}
procedure TMainForm.FormCreate(Sender: TObject);
begin
TypeClicked := FALSE;
Height := 516;
Width := 712;
MyPlot := TPlot.Create(Self);
MyPlot.Parent := Self;
MyPlot.Align := alClient;
MyPlot.PlotType := ptXY;
MyPlot.NoSeries := 2;
MyPlot.MakeDummyData(20);
{$IFNDEF JUST_THE_GRAPH}
MyPlotImageList := TPlotImageList.Create(Self);
MyPlot.Images := MyPlotImageList;
MyPlotMenu := TPlotMenu.Create(Self);
MyPlotMenu.Images := MyPlotImageList;
MyPlotMenu.Plot := MyPlot;
MyPlotMenu.SetUpOnClicks;
MyPlotToolBar := TPlotToolBar.Create(Self);
MyPlotToolBar.Parent := Self;
MyPlotToolBar.Images := MyPlotImageList;
MyPlotToolBar.Plot := MyPlot;
{$ENDIF}
MyPlot.OnFileOpen := MyPlotFileOpen;
MyPlot.OnBeforeDraw := MyPlotBeforeDraw;
MyPlot.Instructions.Add('');
MyPlot.Instructions.Add('Click on the "Type" button to see different Plot Types.');
StringGrid1.Cells[0, 0] := 'Test:';
StringGrid1.Cells[0, 1] := 'Score:';
StringGrid1.ColWidths[0] := 60;
Self.Caption := MYCAPTION;
end;
procedure TMainForm.ClearAllBitBtnClick(Sender: TObject);
var
i: Integer;
begin
MyPlot.SeriesList.ClearSeries;
for i := 1 to StringGrid1.ColCount-1 do
begin
StringGrid1.Cells[i, 0] := '';
StringGrid1.Cells[i, 1] := '';
end;
end;
procedure TMainForm.GoBitBtnClick(Sender: TObject);
var
X, Y: Single;
Mean: Single;
StdDev: Single;
Min: Single;
Max: Single;
StepSize: Single;
begin
MyPlot.NoSeries := 1;
MyPlot.Series[0].DelData;
Screen.Cursor := crHourGlass;
Mean := MeanNEdit.AsReal;
StdDev := StdDevNEdit.AsReal;
Min := MinNEdit.AsReal;
Max := MaxNEdit.AsReal;
StepSize := StepSizeNEdit.AsReal;
{Set the axes:}
MyPlot.XAxis.Max := Max;
MyPlot.XAxis.Min := Min;
MyPlot.YAxis.Min := 0;
MyPlot.XAxis.Intercept := 0;
X := Min;
while (X <= Max) do
begin
Y := Exp(-Sqr((X-Mean)/(2*StdDev))) /
Sqrt(2*Pi*StdDev);
{Don't fire any events, and don't adjust axes:}
MyPlot[0].AddPoint(X, Y, FALSE, FALSE);
X := X + StepSize;
end;
MyPlot[0].Visible := TRUE;
{MyPlot.YAxis.Min := MyPlot.Series[0].YMin;}
MyPlot.YAxis.Max := MyPlot.Series[0].YMax;
{for i := 1 to StringGrid1.ColCount-1 do
begin
if (Length(StringGrid1.Cells[i, 0]) > 0) then
begin
if (Length(StringGrid1.Cells[i, 1]) > 0) then
begin
try
TheScore := StrToFloat(StringGrid1.Cells[i, 1]);
TheSeries := MyPlot.Add(-1);
MyPlot[TheSeries].Name := StringGrid1.Cells[i, 0];
MyPlot[TheSeries].AddPoint(TheScore, MyPlot.YAxis.Min, TRUE, TRUE);
MyPlot[TheSeries].AddPoint(TheScore, MyPlot.YAxis.Max, TRUE, TRUE);
MyPlot[TheSeries].Visible := TRUE;
MyPlot[TheSeries].Symbol := TSymbol(i mod (1+Ord(sDownTriangle)));
finally
end;
end;
end;
end;}
{get the finishing time:}
Screen.Cursor := crDefault;
Self.Caption := Format(MYCAPTION + ' - %d points', [MyPlot.Series[0].NoPts]);
end;
procedure TMainForm.PlotMenu1ExitMenuItemClick(Sender: TObject);
begin
Close;
end;
procedure TMainForm.NoisyBitBtnClick(Sender: TObject);
begin
MyPlot.MakeDummyData(100);
end;
procedure TMainForm.GoCrazyBitBtnClick(Sender: TObject);
begin
if (Assigned(MyPlot.OnAfterPaint)) then
begin
GoCrazyBitBtn.Caption := 'Go Crazy';
TraceBitBtn.Enabled := TRUE;
MyPlot.OnAfterPaint := nil;
end
else
begin
Revolutions := 0;
StartTime := Now;
StartWidth := Width;
StartHeight := Height;
Angle := 0;
AngleInc := 4 * Pi / 180;
GoCrazyBitBtn.Caption := 'Enough !';
TraceBitBtn.Enabled := FALSE;
MyPlot.OnAfterPaint := Plot1AfterPaint;
MyPlot.Invalidate;
end;
end;
procedure TMainForm.CrazyTimerTimer(Sender: TObject);
var
fpm: Single;
ElapsedTime: TDateTime;
begin
if (MyPlot.PlotType >= pt3DContour) then
begin
MyPlot.ZAngle := MyPlot.ZAngle + 1;
end
else
begin
Width := StartWidth + Round(RADIUS * Sin(Angle));
Height := StartHeight + Round(RADIUS * Cos(Angle));
Angle := Angle + AngleInc;
end;
Inc(Revolutions);
ElapsedTime := Now - StartTime;
fpm := Revolutions / ((24 * 3600)*ElapsedTime);
StatusBar1.SimpleText := Format(
'%d frames, %8.2f frames per second',
[Revolutions, fpm]);
end;
procedure TMainForm.MyPlotFileOpen(Sender: TObject; TheFile: String);
var
TheTitle: String;
begin
TheTitle := ExtractFileName(Application.ExeName);
TheTitle := Copy(TheTitle, 1, Length(TheTitle)-4);
TheTitle := TheTitle + ' - ' + ExtractFileName(TheFile);
Application.Title := TheTitle;
MainForm.Caption := TheTitle;
end;
procedure TMainForm.TraceBitBtnClick(Sender: TObject);
begin
MyPlot.Trace;
end;
procedure TMainForm.TypeBitBtnClick(Sender: TObject);
var
ThePlotType: Integer;
TheXStringData: TStringList;
procedure DoXY;
begin
MyPlot.SetInstructionText('Please wait while I add some symbols ...');
Wait(2000, TRUE);
MyPlot.Series[0].Symbol := sySquare;
Wait(2000, TRUE);
MyPlot.Series[1].Symbol := syCircle;
MyPlot.SetInstructionText('Done !');
end;
begin
if (not TypeClicked) then
begin
DoXY;
TypeClicked := TRUE;
exit;
end;
ThePlotType := Ord(MyPlot.PlotType);
ThePlotType := (ThePlotType+1) mod (Ord(High(TPlotType))+1);
{Initialise properties that can change:}
MyPlot.SeriesList.ClearSeries;
MyPlot.YAxis.LimitsVisible := FALSE;
MyPlot.ContourInterval := 1;
MyPlot.ContourDetail := cdLow;
MyPlot.ContourWireFrame := FALSE;
MyPlot.YAxis.TickDirection := orLeft;
MyPlot.YAxis.Title.Orientation := orLeft;
MyPlot.YAxis.Min := 0;
MyPlot.PlotType := TPlotType(ThePlotType);
MyPlot.Title.Caption := 'TPlot - ' + #10 +
MyPlot.GetPlotTypeAsString;
case MyPlot.PlotType of
ptXY:
begin
MyPlot.MakeDummyData(100);
MyPlot.Border.Left := 70;
MyPlot.Border.BottomGap := 80;
DoXY;
end;
ptError:
begin
MyPlot.MakeDummyData(20);
MyPlot.Series[0].Symbol := syCircle;
MyPlot.SetInstructionText('This is boring !');
end;
ptMultiple:
begin
MyPlot.NoSeries := 4;
MyPlot.Multiplicity := 4;
MyPlot.MakeDummyData(20);
MyPlot.Series[0].Pen.Width := 0;
MyPlot.Series[1].Pen.Width := 0;
MyPlot.Series[2].Pen.Width := 0;
MyPlot.Series[3].Pen.Width := 0;
MyPlot.Series[0].Name := 'High';
MyPlot.Series[1].Name := 'Low';
MyPlot.Series[2].Name := 'Open';
MyPlot.Series[3].Name := 'Close';
MyPlot.Series[0].Symbol := syLeftDash;
MyPlot.Series[1].Symbol := syRightDash;
MyPlot.MultiJoin := '2,3';
MyPlot.SetInstructionText('Please wait while I add some Limits ...');
Misc.Wait(2000, FALSE);
MyPlot.YAxis.LimitLower := 2;
MyPlot.YAxis.LimitUpper := 9;
MyPlot.YAxis.LimitsVisible := TRUE;
MyPlot.Series[3].ShadeLimits := TRUE;
MyPlot.SetInstructionText('Done !');
end;
ptBubble:
begin
MyPlot.MakeDummyData(20);
MyPlot.SetInstructionText('This is boring !');
end;
ptColumn, ptStack, ptNormStack:
begin
MyPlot.Grid := gtNone;
MyPlot.MakeDummyData(10);
MyPlot.SetInstructionText('This is boring !');
end;
ptPie:
begin
MyPlot.MakeDummyData(10);
TheXStringData := TStringList.Create;
TheXStringData.Add('Alpha');
TheXStringData.Add('Bravo');
TheXStringData.Add('Charlie');
TheXStringData.Add('Delta');
TheXStringData.Add('Echo');
TheXStringData.Add('Foxtrot');
TheXStringData.Add('Golf');
TheXStringData.Add('Hotel');
TheXStringData.Add('India');
TheXStringData.Add('Juliet');
TheXStringData.Add('Kilo');
MyPlot.Series[0].XStringData := TheXStringData;
MyPlot.Series[1].XStringData := TheXStringData;
TheXStringData.Free;
MyPlot.SetInstructionText('This is very boring !');
end;
ptPolar:
begin
MyPlot.XAxis.Min := -10;
MyPlot.XAxis.Max := 10;
MyPlot.YAxis.Min := -10;
MyPlot.YAxis.Max := 10;
MyPlot.MakeDummyData(20);
MyPlot.XAxis.Intercept := 0;
MyPlot.YAxis.Intercept := 0;
MyPlot.SetInstructionText('This is extremely boring !');
end;
ptLineContour, ptContour, pt3DContour, pt3DWire, pt3DColumn:
begin
if (MyPlot.PlotType > ptContour) then
begin
MyPlot.Border.Left := 120;
MyPlot.Border.BottomGap := 130;
end;
MyPlot.XAxis.Min := 0;
MyPlot.XAxis.Max := 10;
MyPlot.YAxis.Min := 0;
MyPlot.YAxis.Max := 10;
MyPlot.NoSeries := 10;
MyPlot.MakeDummyData(20);
end;
else ;
end;
case MyPlot.PlotType of
ptLineContour:
begin
MyPlot.SetInstructionText('Please wait while I increase the ContourDetail ...');
Misc.Wait(2000, FALSE);
MyPlot.ContourDetail := cdMedium;
MyPlot.ContourInterval := MyPlot.ContourInterval / 2;
Misc.Wait(2000, FALSE);
MyPlot.ContourDetail := cdHigh;
MyPlot.SetInstructionText('Done !');
end;
ptContour:
begin
MyPlot.SetInstructionText('Please wait while I increase the ContourDetail ...');
Misc.Wait(2000, FALSE);
MyPlot.ContourDetail := cdMedium;
Misc.Wait(2000, FALSE);
MyPlot.ContourDetail := cdHigh;
MyPlot.SetInstructionText('Done !');
end;
pt3DContour:
begin
MyPlot.SetInstructionText('Please wait while I increase the ContourDetail ...');
Misc.Wait(2000, FALSE);
MyPlot.ContourDetail := cdMedium;
Misc.Wait(2000, FALSE);
MyPlot.ContourDetail := cdHigh;
Misc.Wait(2000, FALSE);
MyPlot.SetInstructionText('... add a wireframe ...');
Misc.Wait(2000, FALSE);
MyPlot.ContourWireFrame := TRUE;
MyPlot.SetInstructionText('... add some walls and grids ...');
Misc.Wait(2000, FALSE);
MyPlot.Grid := gtBoth;
MyPlot.SetInstructionText('... move the axes to render them more visible ...');
Misc.Wait(2000, FALSE);
MyPlot.XAxis.Intercept := MyPlot.YAxis.Max;
Misc.Wait(2000, FALSE);
MyPlot.YAxis.Intercept := MyPlot.XAxis.Max;
MyPlot.SetInstructionText('... re-arrange the Y Axis Title and Labels');
Misc.Wait(2000, FALSE);
MyPlot.YAxis.TickDirection := orRight;
MyPlot.YAxis.Title.Orientation := orRight;
MyPlot.SetInstructionText('... move the Z Axis ...');
Misc.Wait(2000, FALSE);
MyPlot.ZAxis.ZInterceptY := MyPlot.YAxis.Max;
MyPlot.SetInstructionText('Done !');
MyPlot.Refresh;
end;
pt3DWire, pt3DColumn:
begin
MyPlot.SetInstructionText('Please wait while I move the axes to render them more visible ...');
Misc.Wait(2000, FALSE);
MyPlot.XAxis.Intercept := MyPlot.YAxis.Max;
MyPlot.YAxis.Intercept := MyPlot.XAxis.Max;
MyPlot.YAxis.TickDirection := orRight;
MyPlot.YAxis.Title.Orientation := orRight;
MyPlot.SetInstructionText('Done !');
end;
end;
end;
procedure TMainForm.Plot1AfterPaint(Sender: TObject; ACanvas: TCanvas);
begin
Application.ProcessMessages;
CrazyTimerTimer(Sender);
end;
procedure TMainForm.MyPlotBeforeDraw(Sender: TObject; ACanvas: TCanvas);
var
ABitmap: TBitmap;
ARect: TRect;
begin
if (MyPlot.PlotType = ptLineContour) then
begin
ABitmap := TBitmap.Create;
ABitmap.LoadFromResourceName(hInstance, 'PENGUIN');
ARect.Left := MyPlot.Border.Left;
ARect.Top := MyPlot.Border.Top;
ARect.Right := MyPlot.Border.Right;
ARect.Bottom := MyPlot.Border.Bottom;
ACanvas.StretchDraw(ARect, ABitmap);
ABitmap.Free;
end;
end;
end.