home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 September
/
Chip_2002-09_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d6
/
YPPARSER.ZIP
/
Graph
/
MainForm.pas
< prev
Wrap
Pascal/Delphi Source File
|
2002-06-14
|
19KB
|
612 lines
{********************************************************}
{ }
{ Graph }
{ IMPORTANT-READ CAREFULLY: }
{ }
{ This End-User License Agreement is a legal }
{ agreement between you (either an individual }
{ or a single entity) and Pisarev Yuriy for }
{ the software product identified above, which }
{ includes computer software and may include }
{ associated media, printed materials, and "online" }
{ or electronic documentation ("SOFTWARE PRODUCT"). }
{ By installing, copying, or otherwise using the }
{ SOFTWARE PRODUCT, you agree to be bound by the }
{ terms of this LICENSE AGREEMENT. }
{ }
{ If you do not agree to the terms of this }
{ LICENSE AGREEMENT, do not install or use }
{ the SOFTWARE PRODUCT. }
{ }
{ License conditions }
{ }
{ No part of the software or the manual may be }
{ multiplied, disseminated or processed in any }
{ way without the written consent of Pisarev }
{ Yuriy. Violations of these conditions will be }
{ prosecuted in every case. }
{ }
{ The use of the software is done at your own }
{ risk. The manufacturer and developer accepts }
{ no liability for any damages, either as direct }
{ or indirect consequence of the use of this }
{ product or software. }
{ }
{ Only observance of these conditions allows you }
{ to use the hardware and software in your computer }
{ system. }
{ }
{ All rights reserved. }
{ Copyright 2002 Pisarev Yuriy }
{ }
{ yuriy_mbox@hotmail.com }
{ }
{********************************************************}
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms, Dialogs, ImgList, ActnList, ActnMan, ComCtrls, StdCtrls, ExtCtrls,
ToolWin, GraphBldr, ActnCtrls, ActnMenus, StdActns, Menus, AppEvnts,
ClipBrd, Printers, Registry;
type
TMain = class(TForm)
ControlBar1: TControlBar;
StandardToolBar: TToolBar;
Panel1: TPanel;
tbCalculate: TToolButton;
tbDelete: TToolButton;
tbShowGrid: TToolButton;
tbTrace: TToolButton;
tbCopy: TToolButton;
ToolButton1: TToolButton;
tbDetailLevel: TTrackBar;
ToolButton2: TToolButton;
tbGraphColor: TToolButton;
tbAxisColor: TToolButton;
ActionManager1: TActionManager;
ServiceCalculate: TAction;
ServiceShowGrid: TAction;
ServiceTracing: TAction;
ServiceCopy: TAction;
ServiceDelete: TAction;
ServiceGraphColor: TAction;
ServiceShowAxis: TAction;
HelpAbout: TAction;
ImageList1: TImageList;
ColorDialog: TColorDialog;
StatusBar: TStatusBar;
RichEdit: TRichEdit;
ActionMainMenuBar1: TActionMainMenuBar;
FileOpen: TFileOpen;
FileSaveAs: TFileSaveAs;
FileExit: TFileExit;
EditCut: TEditCut;
EditCopy: TEditCopy;
EditPaste: TEditPaste;
EditSelectAll: TEditSelectAll;
EditUndo: TEditUndo;
EditDelete: TEditDelete;
FileSave: TAction;
FilePrint: TAction;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
ViewStandard: TAction;
ViewFormat: TAction;
PopupMenu2: TPopupMenu;
N9: TMenuItem;
N10: TMenuItem;
PrintDialog: TPrintDialog;
FormatToolBar: TToolBar;
Panel2: TPanel;
edXMaxValue: TEdit;
udXMaxValue: TUpDown;
ToolButton3: TToolButton;
Panel3: TPanel;
edYMaxValue: TEdit;
udYMaxValue: TUpDown;
ToolButton4: TToolButton;
Panel4: TPanel;
edPenWidth: TEdit;
udPenWidth: TUpDown;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
Panel6: TPanel;
edHorzSpacing: TEdit;
udHorzSpacing: TUpDown;
Panel7: TPanel;
edVertSpacing: TEdit;
udVertSpacing: TUpDown;
PopupMenu3: TPopupMenu;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
N15: TMenuItem;
N16: TMenuItem;
N17: TMenuItem;
N18: TMenuItem;
N19: TMenuItem;
N20: TMenuItem;
ApplicationEvents1: TApplicationEvents;
GraphBldr: TGraphBldr;
ServiceRefresh: TAction;
Refresh1: TMenuItem;
procedure ViewStandardExecute(Sender: TObject);
procedure ViewStandardUpdate(Sender: TObject);
procedure ViewFormatExecute(Sender: TObject);
procedure ViewFormatUpdate(Sender: TObject);
procedure HelpAboutExecute(Sender: TObject);
procedure ServiceCalculateExecute(Sender: TObject);
procedure ServiceCalculateUpdate(Sender: TObject);
procedure ServiceShowGridExecute(Sender: TObject);
procedure ServiceShowGridUpdate(Sender: TObject);
procedure ServiceShowAxisExecute(Sender: TObject);
procedure ServiceShowAxisUpdate(Sender: TObject);
procedure ServiceTracingExecute(Sender: TObject);
procedure ServiceTracingUpdate(Sender: TObject);
procedure ServiceCopyExecute(Sender: TObject);
procedure ServiceDeleteExecute(Sender: TObject);
procedure ServiceRefreshExecute(Sender: TObject);
procedure ServiceGraphColorExecute(Sender: TObject);
procedure FileOpenAccept(Sender: TObject);
procedure FileSaveExecute(Sender: TObject);
procedure FileSaveUpdate(Sender: TObject);
procedure FileSaveAsAccept(Sender: TObject);
procedure FilePrintExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure ApplicationEvents1Hint(Sender: TObject);
procedure RichEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure tbDetailLevelChange(Sender: TObject);
procedure edXMaxValueChange(Sender: TObject);
procedure edXMaxValueExit(Sender: TObject);
procedure edYMaxValueChange(Sender: TObject);
procedure edYMaxValueExit(Sender: TObject);
procedure edPenWidthChange(Sender: TObject);
procedure edPenWidthExit(Sender: TObject);
procedure edHorzSpacingChange(Sender: TObject);
procedure edHorzSpacingExit(Sender: TObject);
procedure edVertSpacingChange(Sender: TObject);
procedure edVertSpacingExit(Sender: TObject);
procedure EditKeyPress(Sender: TObject; var Key: Char);
procedure GraphBldrMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure GraphBldrTrace(Sender: TObject; X, Y: Double);
private
FFileName: string;
public
property FileName: string read FFileName write FFileName;
end;
resourcestring
MenuFileName = 'Menu.dat';
const
WheelDelta = 1;
var
Main: TMain;
implementation
uses AboutForm;
{$R *.dfm}
procedure TMain.ViewStandardExecute(Sender: TObject);
begin
ViewStandard.Checked := not ViewStandard.Checked;
StandardToolBar.Visible := ViewStandard.Checked;
end;
procedure TMain.ViewStandardUpdate(Sender: TObject);
begin
ViewStandard.Checked := StandardToolBar.Visible;
end;
procedure TMain.ViewFormatExecute(Sender: TObject);
begin
ViewFormat.Checked := not ViewFormat.Checked;
FormatToolBar.Visible := ViewFormat.Checked;
end;
procedure TMain.ViewFormatUpdate(Sender: TObject);
begin
ViewFormat.Checked := FormatToolBar.Visible;
end;
procedure TMain.HelpAboutExecute(Sender: TObject);
begin
with TAboutDlg.Create(nil) do
try
ShowModal;
finally
Free;
end;
end;
procedure TMain.ServiceCalculateExecute(Sender: TObject);
var
I: Integer;
begin
Screen.Cursor := crHourGlass;
try
with GraphBldr do begin
Text := RichEdit.Text;
try
Calculate;
for I := 0 to StatusBar.Panels.Count - 1 do
StatusBar.Panels[I].Text := '';
except
on E: Exception do begin
Clear;
StatusBar.Panels[2].Text := E.Message;
end;
end;
Draw;
end;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TMain.ServiceCalculateUpdate(Sender: TObject);
begin
ServiceCalculate.Enabled := RichEdit.Text <> '';
end;
procedure TMain.ServiceShowGridExecute(Sender: TObject);
begin
ServiceShowGrid.Checked := not ServiceShowGrid.Checked;
with GraphBldr do begin
ShowGrid := ServiceShowGrid.Checked;
Draw;
end;
end;
procedure TMain.ServiceShowGridUpdate(Sender: TObject);
begin
ServiceShowGrid.Checked := GraphBldr.ShowGrid;
end;
procedure TMain.ServiceShowAxisExecute(Sender: TObject);
begin
ServiceShowAxis.Checked := not ServiceShowAxis.Checked;
with GraphBldr do begin
ShowAxis := ServiceShowAxis.Checked;
Draw;
end;
end;
procedure TMain.ServiceShowAxisUpdate(Sender: TObject);
begin
ServiceShowAxis.Checked := GraphBldr.ShowAxis;
end;
procedure TMain.ServiceTracingExecute(Sender: TObject);
begin
ServiceTracing.Checked := not ServiceTracing.Checked;
with GraphBldr do begin
StatusBar.Panels[1].Text := '';
Tracing := ServiceTracing.Checked;
Draw;
end;
end;
procedure TMain.ServiceTracingUpdate(Sender: TObject);
begin
ServiceTracing.Checked := GraphBldr.Tracing;
end;
procedure TMain.ServiceCopyExecute(Sender: TObject);
begin
ClipBoard.Assign(GraphBldr.Picture);
end;
procedure TMain.ServiceDeleteExecute(Sender: TObject);
var
I: Integer;
begin
with GraphBldr do begin
Clear;
for I := 0 to StatusBar.Panels.Count - 1 do
StatusBar.Panels[I].Text := '';
Draw;
end;
end;
procedure TMain.ServiceRefreshExecute(Sender: TObject);
begin
GraphBldr.Draw;
end;
procedure TMain.ServiceGraphColorExecute(Sender: TObject);
begin
ColorDialog.Color := GraphBldr.GraphPen.Color;
if ColorDialog.Execute then with GraphBldr do begin
GraphPen.Color := ColorDialog.Color;
Draw;
end;
end;
procedure TMain.FileOpenAccept(Sender: TObject);
begin
FFileName := FileOpen.Dialog.FileName;
with TStringList.Create do
try
LoadFromFile(FFileName);
RichEdit.Text := StringReplace(Text, #13#10, ' ', [rfReplaceAll]);
ServiceCalculate.Execute;
finally
Free;
end;
end;
procedure TMain.FileSaveExecute(Sender: TObject);
begin
with TStringList.Create do
try
Add(RichEdit.Text);
SaveToFile(FFileName);
finally
Free;
end;
end;
procedure TMain.FileSaveUpdate(Sender: TObject);
begin
FileSave.Enabled := FFileName <> '';
end;
procedure TMain.FileSaveAsAccept(Sender: TObject);
begin
FFileName := FileSaveAs.Dialog.FileName;
FileSave.Execute;
end;
procedure TMain.FilePrintExecute(Sender: TObject);
var
I: Integer;
begin
with PrintDialog do if Execute then for I := 0 to Copies do
with Printer do begin
BeginDoc;
Canvas.Draw(0, 0, GraphBldr.Picture);
EndDoc;
end;
end;
procedure TMain.FormCreate(Sender: TObject);
begin
GraphBldr.DataEditor.AttrsManager.Add(RichEdit);
with ActionManager1 do begin
FileName := ExtractFilePath(Application.ExeName) + MenuFileName;
if FileExists(FileName) then LoadFromFile(FileName);
end;
end;
procedure TMain.FormActivate(Sender: TObject);
begin
OnActivate := nil;
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
if KeyExists('Software\Graph\Settings') and
OpenKey('Software\Graph\Settings', False) then
begin
GraphBldr.ShowGrid := ReadBool('ShowGrid');
GraphBldr.ShowAxis := ReadBool('ShowAxis');
GraphBldr.Tracing := ReadBool('Tracing');
GraphBldr.DetailLevel := ReadInteger('DetailLevel');
tbDetailLevel.Position := GraphBldr.DetailLevel;
GraphBldr.GraphPen.Color := ReadInteger('GraphColor');
GraphBldr.XMaxValue := ReadInteger('XMaxValue');
udXMaxValue.Position := GraphBldr.XMaxValue;
GraphBldr.YMaxValue := ReadInteger('YMaxValue');
udYMaxValue.Position := GraphBldr.YMaxValue;
GraphBldr.GraphPen.Width := ReadInteger('PenWidth');
udPenWidth.Position := GraphBldr.GraphPen.Width;
GraphBldr.HorzSpacing := ReadFloat('HorzSpacing');
udHorzSpacing.Position := Round(GraphBldr.HorzSpacing);
GraphBldr.VertSpacing := ReadFloat('VertSpacing');
udVertSpacing.Position := Round(GraphBldr.VertSpacing);
StandardToolBar.Visible := ReadBool('StandardToolBar');
FormatToolBar.Visible := ReadBool('FormatToolBar');
end;
finally
Free;
end;
end;
procedure TMain.FormDestroy(Sender: TObject);
begin
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software\Graph\Settings', True);
WriteBool('ShowGrid', GraphBldr.ShowGrid);
WriteBool('ShowAxis', GraphBldr.ShowAxis);
WriteBool('Tracing', GraphBldr.Tracing);
WriteInteger('DetailLevel', GraphBldr.DetailLevel);
WriteInteger('GraphColor', GraphBldr.GraphPen.Color);
WriteInteger('XMaxValue', GraphBldr.XMaxValue);
WriteInteger('YMaxValue', GraphBldr.YMaxValue);
WriteInteger('PenWidth', GraphBldr.GraphPen.Width);
WriteFloat('HorzSpacing', GraphBldr.HorzSpacing);
WriteFloat('VertSpacing', GraphBldr.VertSpacing);
WriteBool('StandardToolBar', StandardToolBar.Visible);
WriteBool('FormatToolBar', FormatToolBar.Visible);
finally
Free;
end;
end;
procedure TMain.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
var
Point: TPoint;
begin
Point.X := MousePos.X - ClientOrigin.X;
Point.Y := MousePos.Y - ClientOrigin.Y;
with GraphBldr do if (Point.X >= Left) and (Point.Y >= Top) and
(Point.X < Left + Width) and (Point.Y < Top + Height) then
with GraphBldr do begin
if XMaxValue > udXMaxValue.Min then begin
XMaxValue := XMaxValue - WheelDelta;
udXMaxValue.Position := XMaxValue;
end;
if YMaxValue > udYMaxValue.Min then begin
YMaxValue := YMaxValue - WheelDelta;
udYMaxValue.Position := YMaxValue;
end;
if Trim(Text) <> '' then Calculate;
Draw;
end;
end;
procedure TMain.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
var
Point: TPoint;
begin
Point.X := MousePos.X - ClientOrigin.X;
Point.Y := MousePos.Y - ClientOrigin.Y;
with GraphBldr do if (Point.X >= Left) and (Point.Y >= Top) and
(Point.X < Left + Width) and (Point.Y < Top + Height) then
with GraphBldr do begin
if XMaxValue < udXMaxValue.Max then begin
XMaxValue := XMaxValue + WheelDelta;
udXMaxValue.Position := XMaxValue;
end;
if YMaxValue < udYMaxValue.Max then begin
YMaxValue := YMaxValue + WheelDelta;
udYMaxValue.Position := YMaxValue;
end;
if Trim(Text) <> '' then Calculate;
Draw;
end;
end;
procedure TMain.ApplicationEvents1Hint(Sender: TObject);
begin
if Length(Application.Hint) > 0 then begin
StatusBar.SimplePanel := True;
StatusBar.SimpleText := Application.Hint
end else StatusBar.SimplePanel := False;
end;
procedure TMain.RichEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then ServiceCalculate.Execute;
end;
procedure TMain.tbDetailLevelChange(Sender: TObject);
begin
GraphBldr.DetailLevel := tbDetailLevel.Position;
end;
procedure TMain.edXMaxValueChange(Sender: TObject);
begin
with GraphBldr do begin
XMaxValue := udXMaxValue.Position;
if Trim(Text) <> '' then Calculate;
Draw;
end;
end;
procedure TMain.edXMaxValueExit(Sender: TObject);
begin
edXMaxValue.Text := IntToStr(GraphBldr.XMaxValue);
end;
procedure TMain.edYMaxValueChange(Sender: TObject);
begin
with GraphBldr do begin
YMaxValue := udYMaxValue.Position;
if Trim(Text) <> '' then Calculate;
Draw;
end;
end;
procedure TMain.edYMaxValueExit(Sender: TObject);
begin
edYMaxValue.Text := IntToStr(GraphBldr.YMaxValue);
end;
procedure TMain.edPenWidthChange(Sender: TObject);
begin
with GraphBldr do begin
GraphPen.Width := udPenWidth.Position;
Draw;
end;
end;
procedure TMain.edPenWidthExit(Sender: TObject);
begin
edPenWidth.Text := IntToStr(GraphBldr.GraphPen.Width);
end;
procedure TMain.edHorzSpacingChange(Sender: TObject);
begin
with GraphBldr do begin
HorzSpacing := udHorzSpacing.Position;
Draw;
end;
end;
procedure TMain.edHorzSpacingExit(Sender: TObject);
begin
edHorzSpacing.Text := FloatToStr(GraphBldr.HorzSpacing);
end;
procedure TMain.edVertSpacingChange(Sender: TObject);
begin
with GraphBldr do begin
VertSpacing := udVertSpacing.Position;
Draw;
end;
end;
procedure TMain.edVertSpacingExit(Sender: TObject);
begin
edVertSpacing.Text := FloatToStr(GraphBldr.VertSpacing);
end;
procedure TMain.EditKeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0;
end;
procedure TMain.GraphBldrMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
StatusBar.Panels[0].Text := Format('%f: %f',
[GraphBldr.XCoord(X), GraphBldr.YCoord(Y)]);
end;
procedure TMain.GraphBldrTrace(Sender: TObject; X, Y: Double);
begin
StatusBar.Panels[1].Text := Format('Tracing: %f: %f', [X, Y]);
end;
end.