📄 unitmain.~cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UnitMain.h"
#include "UnitCommSet.h"
#include "UnitOptions.h"
#include "UnitAbout.h"
#include "TestSetData.h"
#include "math.h"
//#include "yb_base.h" //串口控件带的头文件,有获取路径功能
#include <fstream.h> //文件流"fstream.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "YbCommDevice"
#pragma resource "*.dfm"
TForm1 *Form1;
ofstream SaveFile; //文件流
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
AppCfg.Load(YbCommDevice1); //如果配置文件TestSettings.cfg存在,从配置文件载入信息
InitCtrls(); //初始化控件信息
PostMessage(Handle,WM_USERCMD,UC_LOGIN,0);
}
//---------------------------------------------------------------------------
void TForm1::AddPoint(const double x, const double y, TColor AColor)
{
if (CBVertical->Checked) // if VERTICAL SCROLL
{
LineSeries1->AddXY(y,x,"",AColor);
Series1->AddXY(y+2,x,"", AColor);
Series2->AddXY(y-6,x,"", clBlack);
Series3->AddXY(y+8,x,"", clBlack);
}
else
{ LineSeries1->AddXY(x,y,"",AColor);
Series1->AddXY(x,y+2,"", AColor);
Series2->AddXY(x,y-6,"", clBlack);
Series3->AddXY(x,y+8,"", clBlack);
}
}
//---------------------------------------------------------------------------
void TForm1::FillDemoPoints()
{
// fill the LineSeries with some random data }
LineSeries1->Clear(); // <-- this removes all points from LineSeries1
Series1->Clear(); // <-- this removes all points from LineSeries1
Series2->Clear(); // <-- this removes all points from LineSeries1
// let"s add 60 minutes from 12:00 to 12:59
for (Word t = 0;t<60;t++)
AddPoint( EncodeTime( 12, t, 0,0),random(10),clRed );
// let"s add 60 more minutes from 13:00 to 13:59
for (Word t = 0;t<60;t++)
AddPoint( EncodeTime( 13, t, 0,0),random(10),clRed);
}
//---------------------------------------------------------------------------
void TForm1::CalcScrollBarPos()
{
double Difer;
ChangingBars = true;
/* if (Chart1->BottomAxis->Automatic)
;//ScrollBar1->Enabled = false;
else {
//ScrollBar1->Enabled = true;
Difer = Chart1->MaxXValue(Chart1->BottomAxis) -
Chart1->MinXValue(Chart1->BottomAxis);
if (Difer>0)
;// ScrollBar1->Position = floor(100.0*(
// Chart1->BottomAxis->Minimum-Chart1->MinXValue(Chart1->BottomAxis))/Difer);
}
*/ if (Chart1->LeftAxis->Automatic)
ScrollBar2->Enabled = false;
else {
ScrollBar2->Enabled = true;
Difer = Chart1->MaxYValue(Chart1->LeftAxis) -
Chart1->MinYValue(Chart1->LeftAxis);
if (Difer>0)
ScrollBar2->Position = floor(100.0*(
Chart1->LeftAxis->Minimum-Chart1->MinYValue(Chart1->LeftAxis))/Difer);
}
ChangingBars = false;
}
//---------------------------------------------------------------------------
// This is the event we need to arrange Axis scale as new points are added->
void __fastcall TForm1::LineSeries1AfterAdd(TChartSeries *Sender,
int ValueIndex)
{
// if (VERTICAL SCROLL
if (CBVertical->Checked) {
Sender->GetVertAxis->Automatic = false; // <-- we dont want automatic scaling
Sender->GetVertAxis->AutomaticMaximum = false; // <-- we dont want automatic scaling
Sender->GetVertAxis->AutomaticMinimum = false; // <-- we dont want automatic scaling
// In this example, we will set the Axis Minimum and Maximum values to
// show One Hour of data}ing at last point Time plus 5 minutes
Sender->GetVertAxis->Minimum = 0;
Sender->GetVertAxis->Maximum = Sender->YValues->MaxValue + DateTimeStep[ dtFiveMinutes ];
Sender->GetVertAxis->Minimum = Sender->GetVertAxis->Maximum - DateTimeStep[ dtOneHour ];
}
else {
Sender->GetHorizAxis->Automatic = false; // <-- we dont want automatic scaling
Sender->GetHorizAxis->AutomaticMaximum = false; // <-- we dont want automatic scaling
Sender->GetHorizAxis->AutomaticMinimum = false; // <-- we dont want automatic scaling
// In this example, we will set the Axis Minimum and Maximum values to
// show One Hour of data}ing at last point Time plus 5 minutes
Sender->GetHorizAxis->Minimum = 0;
Sender->GetHorizAxis->Maximum = Sender->XValues->MaxValue + DateTimeStep[ dtFiveMinutes ];
Sender->GetHorizAxis->Minimum = Sender->GetHorizAxis->Maximum - DateTimeStep[ dtOneHour ];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Series1AfterAdd(TChartSeries *Sender,
int ValueIndex)
{
// if (VERTICAL SCROLL
if (CBVertical->Checked) {
Sender->GetVertAxis->Automatic = false; // <-- we dont want automatic scaling
Sender->GetVertAxis->AutomaticMaximum = false; // <-- we dont want automatic scaling
Sender->GetVertAxis->AutomaticMinimum = false; // <-- we dont want automatic scaling
// In this example, we will set the Axis Minimum and Maximum values to
// show One Hour of data}ing at last point Time plus 5 minutes
Sender->GetVertAxis->Minimum = 0;
Sender->GetVertAxis->Maximum = Sender->YValues->MaxValue + DateTimeStep[ dtFiveMinutes ];
Sender->GetVertAxis->Minimum = Sender->GetVertAxis->Maximum - DateTimeStep[ dtOneHour ];
}
else {
Sender->GetHorizAxis->Automatic = false; // <-- we dont want automatic scaling
Sender->GetHorizAxis->AutomaticMaximum = false; // <-- we dont want automatic scaling
Sender->GetHorizAxis->AutomaticMinimum = false; // <-- we dont want automatic scaling
// In this example, we will set the Axis Minimum and Maximum values to
// show One Hour of data}ing at last point Time plus 5 minutes
Sender->GetHorizAxis->Minimum = 0;
Sender->GetHorizAxis->Maximum = Sender->XValues->MaxValue + DateTimeStep[ dtFiveMinutes ];
Sender->GetHorizAxis->Minimum = Sender->GetHorizAxis->Maximum - DateTimeStep[ dtOneHour ];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Series2AfterAdd(TChartSeries *Sender,
int ValueIndex)
{
// if (VERTICAL SCROLL
if (CBVertical->Checked) {
Sender->GetVertAxis->Automatic = false; // <-- we dont want automatic scaling
Sender->GetVertAxis->AutomaticMaximum = false; // <-- we dont want automatic scaling
Sender->GetVertAxis->AutomaticMinimum = false; // <-- we dont want automatic scaling
// In this example, we will set the Axis Minimum and Maximum values to
// show One Hour of data}ing at last point Time plus 5 minutes
Sender->GetVertAxis->Minimum = 0;
Sender->GetVertAxis->Maximum = Sender->YValues->MaxValue + DateTimeStep[ dtFiveMinutes ];
Sender->GetVertAxis->Minimum = Sender->GetVertAxis->Maximum - DateTimeStep[ dtOneHour ];
}
else {
Sender->GetHorizAxis->Automatic = false; // <-- we dont want automatic scaling
Sender->GetHorizAxis->AutomaticMaximum = false; // <-- we dont want automatic scaling
Sender->GetHorizAxis->AutomaticMinimum = false; // <-- we dont want automatic scaling
// In this example, we will set the Axis Minimum and Maximum values to
// show One Hour of data}ing at last point Time plus 5 minutes
Sender->GetHorizAxis->Minimum = 0;
Sender->GetHorizAxis->Maximum = Sender->XValues->MaxValue + DateTimeStep[ dtFiveMinutes ];
Sender->GetHorizAxis->Minimum = Sender->GetHorizAxis->Maximum - DateTimeStep[ dtOneHour ];
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Series3AfterAdd(TChartSeries *Sender,
int ValueIndex)
{
// if (VERTICAL SCROLL
if (CBVertical->Checked) {
Sender->GetVertAxis->Automatic = false; // <-- we dont want automatic scaling
Sender->GetVertAxis->AutomaticMaximum = false; // <-- we dont want automatic scaling
Sender->GetVertAxis->AutomaticMinimum = false; // <-- we dont want automatic scaling
// In this example, we will set the Axis Minimum and Maximum values to
// show One Hour of data}ing at last point Time plus 5 minutes
Sender->GetVertAxis->Minimum = 0;
Sender->GetVertAxis->Maximum = Sender->YValues->MaxValue + DateTimeStep[ dtFiveMinutes ];
Sender->GetVertAxis->Minimum = Sender->GetVertAxis->Maximum - DateTimeStep[ dtOneHour ];
}
else {
Sender->GetHorizAxis->Automatic = false; // <-- we dont want automatic scaling
Sender->GetHorizAxis->AutomaticMaximum = false; // <-- we dont want automatic scaling
Sender->GetHorizAxis->AutomaticMinimum = false; // <-- we dont want automatic scaling
// In this example, we will set the Axis Minimum and Maximum values to
// show One Hour of data}ing at last point Time plus 5 minutes
Sender->GetHorizAxis->Minimum = 0;
Sender->GetHorizAxis->Maximum = Sender->XValues->MaxValue + DateTimeStep[ dtFiveMinutes ];
Sender->GetHorizAxis->Minimum = Sender->GetHorizAxis->Maximum - DateTimeStep[ dtOneHour ];
}
}
void __fastcall TForm1::InitCtrls(void) //初始化控件信息
{
Font->Name = AppLang.FontName;
Font->Charset = AppLang.Charset;
Font->Size = AppLang.FontSize;
TAppStrings Msg;
Application->Title = Msg.Str_AppTitle;
Caption = Msg.Str_AppTitle;
MenuFile->Caption = Msg.Mnu_File;
MenuData->Caption = Msg.Mnu_Data;
MenuHelp->Caption = Msg.Mnu_Help;
ActionCommSet->Caption = Msg.Mnu_CommSet ;
ActionLanguage->Caption = Msg.Mnu_Language;
ActionExit->Caption = Msg.Mnu_Exit ;
ActionHelp->Caption = Msg.Mnu_Help ;
ActionAbout->Caption = Msg.Mnu_About ;
ActionSend->Caption = Msg.Mnu_Send ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::UserLogin(int iParam) //当主窗体第一次显示出来时产生的事件
{
try
{
YbCommDevice1->Active = true;
}
catch(Exception &e)
{
if(!CommSet())
Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
if(Message.Msg==WM_USERCMD)
{
if(Message.WParam == UC_LOGIN)
{
UserLogin(Message.LParam);
}
}
TForm::WndProc(Message);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -