Вiзуальний облiк вхiдних даних iнтерфейсу RS-232
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
Diagram1.Invalidate;
end;
end;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
Form3.Showmodal;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
//form2.Show;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
form3.Show;
end;
procedure TForm1.N6Click(Sender: TObject);
begin
// form4.show;
end;
procedure TForm1.AboutClick(Sender: TObject);
begin
aboutbox.showmodal;
end;
procedure TForm1.newGraphicExecute(Sender: TObject);
begin
form1.ItemNewClick(self);
end;
procedure TForm1.ExitPrExecute(Sender: TObject);
begin
close;
end;
procedure TForm1.StartGrExecute(Sender: TObject);
begin
ScrollBar1.Enabled:=false;
Fileitem.Enabled:=false;
// Interpolation.Enabled:=false;
Options.Enabled:=false;
SpeedButton1.Enabled:=false;
SpeedButton2.Enabled:=false;
SpeedButton3.Enabled:=false;
Timer1.Interval:=GraphicDiagram1.NumMiliSec;
Timer1.Enabled:=True;
Pause.Enabled:=true;
SpeedButton5.Enabled:=true;
end;
procedure TForm1.StopGrExecute(Sender: TObject);
begin
GraphicDiagram1.DrawCountthen">if GraphicDiagram1.GetPointsCount>GraphicDiagram1.DrawCount then
begin
ScrollBar1.Enabled:=true;
ScrollBar1.SetParams(GraphicDiagram1.GetPointsCount,0,GraphicDiagram1.GetPointsCount);
end;
Fileitem.Enabled:=true;
// Interpolation.Enabled:=true;
Options.Enabled:=true;
SpeedButton1.Enabled:=true;
SpeedButton2.Enabled:=true;
SpeedButton3.Enabled:=true;
Timer1.Enabled:=false;
Pause.Enabled:=false;
end;
procedure TForm1.SaveGraphExecute(Sender: TObject);
begin
SavePictureClick(Sender);
end;
procedure TForm1.saveDataGrExecute(Sender: TObject);
begin
if SaveDialog1.Execute then
GraphicDiagram1.SaveData(SaveDialog1.FileName);
end;
procedure TForm1.HelpPrExecute(Sender: TObject);
begin
aboutBox.ShowModal;
end;
procedure TForm1.LoadDataGRExecute(Sender: TObject);
begin
if openDialog1.Execute then
begin
if fileExists (openDialog1.FileName) then
GraphicDiagram1.LoadData(openDialog1.FileName)
else messageDlg(НемаСФ такого файлу!!,mtError,[mbOk],0);
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
try
GraphicDiagram1.NumMiliSec:=StrToInt(Edit16.Text);
except MessageDlg(Число повинне бути цiлим та додатнiм!!!,mtError,[mbOk],0); end
end;
procedure TForm1.GeneratorOptionClick(Sender: TObject);
begin
Form4.showmodal;
end;
end.
Текст компонента GraphicDiagram
unit GraphicDiagram;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const WM_MYMessage = WM_USER+1000;
const MAX_COUNT = 10000;
type
TTypeDiagram = (tdLine,tdColumn,tdUser);
TPoint = ^Longint;
TPointArray = TList;
TCount = 0..MAX_COUNT;
TnewMouseMoveEvent = procedure (Sender:TObject;Shift:TShiftState;x,y:integer;
var DoDefault:boolean) of Object;
TGraphicDiagram = class(TGraphicControl)
private
FTypeDiagram:TTypeDiagram;
FpointStart:Longint;//початок вiдображення точок на графiку
FPointDrawCount:Longint; //Кiнець вiдображення точок на графiку
FNumSeccond,FNumMSeccond:word; // кiлькiсть мiлiсекунд, пiсля яких добавляСФться точка
FPointYMax:Longint; //максимальна точка по РЖгрик
FDrawX:Boolean;
FDrawY:Boolean;
FDRAWColor:TColor;
FDrawGridX:Boolean;
FDrawGridY:Boolean;
FDrawGridColor:TColor;
FPointsValue:TPointArray; // тiльки додатнi елементи
FDataStart,FDataStop:TDateTime;//початок вiдображення точок на графiку
FEnabled:Boolean;
FOnMouseMove:TnewMouseMoveEvent;
OurTime:longint;
MashtabX:real;
MashtabY:real;
FMashTab:Boolean; //маштаб якщо вiн змiнився то true
// function GetValue(index:Longint): Longint; //читаСФ точку
Procedure SetValue(index,value:Longint); //добавляСФ точку
procedure SetTypeDiagram(typeD:TTypeDiagram);
procedure SetMashtabX;
procedure SetMashtabY;
protected
procedure paint;override;
procedure WritePoints(stream:TStream);virtual;
procedure ReadPoints(stream:TStream);virtual;
procedure DefineProperties(Filer:TFiler);override;
procedure WMMouseMove(var Mes:TWMMouse); message WM_MOUSEMOVE;
procedure MyMouseMove(Shift:TShiftState;x,y:integer);dynamic;
Procedure WMMyMessage(var Mes:TMessage); message WM_MyMessage;
public
{ Public declarations }
constructor create(AOwner:TComponent);override;
destructor Destroy; override;
procedure AddValue(value:TPoint);overload;
function GetPointsCount:Longint; //читаСФ точку
function getList:TPointArray;
function SaveData(filename:String):integer;
function LoadData(filename:String):integer;
function SavePicture(filename:String):integer;
procedure Start;
procedure Stop;
procedure Clear;
procedure Resize(Sender:TControl);
function GetValue(index:Longint): Longint; //читаСФ точку
// procedure AddValue(value:longint);overload;
published
{ Published declarations }
property TypeDiagram:TTypeDiagram read FTypeDiagram write FTypeDiagram;
property DrawCount:integer read FPointDrawCount Write FPointDrawCount;
property DrawX:Boolean read FDrawX Write FDrawX;
property DrawY:Boolean read FDrawY Write FDrawY;
property DrawGridX:Boolean read FDrawGridX Write FDrawGridX;
property DrawGridY:Boolean read FDrawGridY Write FDrawGridY;
property DrawColor:TColor read FDrawColor Write FDrawColor;
property DrawGridColor:TColor read FDrawGridColor Write FDrawGridColor;
property DrawStart:integer read FPointStart Write FPointStart;
property NumSeccondShow:word read FNumSeccond write FNumSeccond stored false;
property NumMiliSec:word read FNumMSeccond write FNumMSeccond stored false;
property OnMouseMove:TnewMouseMoveEvent read FOnMouseMove write FOnMouseMove;
end;
procedure Register;
implementation
procedure TGraphicDiagram.Resize;
begin
Height:=Sender.Height-30;
Width:=Sender.Width-15;
invalidate;
end;
function TGraphicDiagram.getList:TPointArray;
begin
result:=FPointsValue;
end;
procedure TGraphicDiagram.Start;
begin
FDataStart:=now;
end;
procedure TGraphicDiagram.Stop;
begin
FDataStop:=now;
end;
destructor TGraphicDiagram.destroy;
begin
Self.clear;
inherited;
end;
procedure TGraphicDiagram.Clear;
var l:^Longint;
i:TPoint;
n:Longint;
begin
n:=FPointsValue.Count-1;
FPointsValue.clear;
FpointStart:=0;
new (i);
i^:=0;
AddValue(i);
invalidate;
end;
function TGraphicDiagram.LoadData;
var i:Longint;
n:^Longint;
f:textFile;
st:String;
begin
result:=-1;
FpointsValue.Clear;
FpointStart:=0;
if not FileExists(filename) then exit;
assignFile(f,filename);
reset(f);
while not eof(f) do
begin
readln(f,st);
i:=pos(|,st);
if i=0 then Exception.create(Неправильний формат файлу +filename);
FDataStart:=StrToDateTime(copy(st,1,i-1));
new (n);
n^:= StrToInt(copy(st,i+1,10));
FpointsValue.add(n);
end;
closeFile(f);
invalidate;
result:=0;
end;
function TGraphicDiagram.SavePicture;
var tp:TBitMap;
st:TStream;
p:pointer;
rin:TRect;
begin
rin:=Rect(0,0,width,height);
//TCanvas
tp:= TBitmap.Create;
// p:=addr(self.canvas.pixels[0,0])
tp.width:=width;
tp.height:=height;
tp.canvas.CopyRect (rin, self.canvas,rin);
tp.SaveToFile (filename);
tp.free;
end;
function TGraphicDiagram.SaveData;
var i:Longint;
n:^Longint;
f:textFile;
begin
result:=-1;
assignFile(f,filename);
rewrite(f);
for i:=0 to FPointsValue.count-1 do
begin
n:=FpointsValue.items[i];
writeln(f,DateTimeToStr(FDataStart+(FDataStart-FDataStop)/FPointsValue.count),|,n^);
end;
closeFile(f);
result:=0;
end;
function TGraphicDiagram.GetPointsCount:Longint; //
begin
resu