BCB图表绘制工具代码
BCB 图表绘制工具代码
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Main.cpp", Form1);
//---------------------------------------------------------------------------
#include "Recognize/datatype.h"
#include "Recognize/Msgrecv.h"
#include "Recognize/Recognize.h"
int sfd;
int serverSocket;
HANDLE TcpRecvThread;
DWORD TcpRecvThreadID;
HANDLE ServerThread;
DWORD ServerThreadID;
LinkQueue Qu;
LinkQueue SQu;
CRITICAL_SECTION m_cs;
CRITICAL_SECTION Sm_cs;
MoveData PeerNet;
//---------------------------------------------------------------------------
// 初始化和识别器的连接
int InitConnect()
{
sfd = InitClientSocket("127.0.0.1", 6000);//192.168.1.106
if(sfd >0 )
{
// 建立临界区
InitializeCriticalSection( &m_cs );
InitializeCriticalSection( &Sm_cs );
// am建立识别与服务器线程
TcpRecvThread = CreateThread(NULL, 0, RecvNetEventThread, NULL, 0, &TcpRecvThreadID);
return 1;
}
else
{
ShowMessage("识别系统连接失败!请检查识别系统。");
return 1;
}
}
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->Title = "数据图表分析器";
if (InitConnect() == 0)
{
return 0;
}
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
#include <windows.h>
#include "Recognize/datatype.h"
#include "Recognize/Msgrecv.h"
#include "Recognize/Recognize.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner) ,
m_nCurrentLine(1) ,
m_bIsDrawing(false)
{
}
//---------------------------------------------------------------------------
// 计时器每秒处理
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
SYSTEMTIME tagSysTime;
GetLocalTime( &tagSysTime );
AnsiString szSysTime = AnsiString(tagSysTime.wYear) + "年"
+ AnsiString(tagSysTime.wMonth) + "月"
+ AnsiString(tagSysTime.wDay) + "日"
+ " "
+ AnsiString(tagSysTime.wHour) + ":"
+ AnsiString(tagSysTime.wMinute) + ":"
+ AnsiString(tagSysTime.wSecond);
StatusBar1->Panels->Items[2]->Text = szSysTime;
return;
}
//---------------------------------------------------------------------------
// 开始分析按钮按下
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//nCurrentX = 0;
Timer2->Enabled = true;
m_bIsDrawing = true;
Button1->Enabled = false;
Button3->Enabled = true;
Button4->Enabled = true;
return;
}
//---------------------------------------------------------------------------
// 仅观察X值
void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{
DBChart1->Hide();
DBChart2->Hide();
DBChart3->Hide();
DBChart4->Hide();
DBChart1->Height = 480;
DBChart1->Top = 0;
DBChart1->Show();
}
//---------------------------------------------------------------------------
// 仅观察Y值
void __fastcall TForm1::RadioButton2Click(TObject *Sender)
{
DBChart1->Hide();
DBChart2->Hide();
DBChart3->Hide();
DBChart4->Hide();
DBChart2->Height = 480;
DBChart2->Top = 0;
DBChart2->Show();
}
//---------------------------------------------------------------------------
// 仅观察Z值
void __fastcall TForm1::RadioButton3Click(TObject *Sender)
{
DBChart1->Hide();
DBChart2->Hide();
DBChart3->Hide();
DBChart4->Hide();
DBChart3->Height = 480;
DBChart3->Top = 0;
DBChart3->Show();
}
//---------------------------------------------------------------------------
// 观察多项
void __fastcall TForm1::Button2Click(TObject *Sender)
{
DBChart1->Hide();
DBChart2->Hide();
DBChart3->Hide();
DBChart4->Hide();
DBChart1->Height = 120;
DBChart2->Height = 120;
DBChart3->Height = 120;
DBChart4->Height = 120;
DBChart1->Top = 0;
DBChart2->Top = 120;
DBChart3->Top = 240;
DBChart4->Top = 360;
DBChart1->Show();
DBChart2->Show();
DBChart3->Show();
DBChart4->Show();
RadioButton1->Checked = false;
RadioButton2->Checked = false;
RadioButton3->Checked = false;
RadioButton4->Checked = false;
return;
}
//---------------------------------------------------------------------------
// 每10毫秒的一个计时器,在里面进行数据的接收
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
/*MoveData* pMoveData = NULL;
EnterCriticalSection(&m_cs);
nCurrentX = nCurrentX + 1;
if (nCurrentX == DBChart1->TopAxis->Maximum)
{
// 截取屏幕功能
if(CheckBox3->Checked)
{
SaveScreen();
}
nCurrentX = 0;
Series1->Clear();
FastLineSeries1->Clear();
FastLineSeries6->Clear();
}
//读取第一个包
if( !Qu.IsEmpty() )
{
nPackNum = nPackNum + 1;
pMoveData = Qu.DeQueue();
RackMove rack = pMoveData->rm;
DrawLineInfo(rack.x, rack.y, rack.z, nCurrentX, nPackNum, m_nCurrentLine);
Label1->Caption = AnsiString(rack.x);
AnsiString szInfo = "收到监视器消息,当前X值为" + AnsiString(rack.x) +
"---当前Y值为" + AnsiString(rack.y) +
"---当前Z值为" + AnsiString(rack.z) +
"---当前时间为" + AnsiString(nCurrentX) +
"---这是接到的第" + AnsiString(nPackNum) + "个包.";
StatusBar1->Panels->Items[0]->Text = szInfo;
}else
{
StatusBar1->Panels->Items[0]->Text = "当前未接收到消息!";
}
if (m_bIsNeedSaving)
{
SaveLog();
}
LeaveCriticalSection(&m_cs); */
}
//---------------------------------------------------------------------------
void TForm1::DrawLineInfo(float x, float y, float z, int nTime, int nPackNum, int nLineNum)
{
Series1->AddXY(nTime , x, "", clBlue);
FastLineSeries1->AddXY(nTime , y, "", clBlue);
FastLineSeries6->AddXY(nTime , z, "", clBlue);
Series6->AddXY(nTime , sqrt(y*y + z*z + x*x), "", clBlue);
}
//---------------------------------------------------------------------------
// 双击图表事件
void __fastcall TForm1::DBChart1DblClick(TObject *Sender)
{
if (m_bIsDrawing)
Button3Click(Sender);
else
Button1Click(Sender);
}
//---------------------------------------------------------------------------
// 停止分析
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Timer2->Enabled = false;
m_bIsDrawing = false;
Button3->Enabled = false;
Button1->Enabled = true;
Button4->Enabled = true;
Button1->Caption = "继续分析";
return;
}
//---------------------------------------------------------------------------
// 显示数值信息
void __fastcall TForm1::CheckBox1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (CheckBox1->Checked)
{
Series1->Marks->Visible = false;
Series6->Marks->Visible = false;
FastLineSeries1->Marks->Visible = false;
FastLineSeries6->Marks->Visible = false;
}
else
{
Series1->Marks->Visible = true;
Series6->Marks->Visible = true;
FastLineSeries1->Marks->Visible = true;
FastLineSeries6->Marks->Visible = true;
}
}
//---------------------------------------------------------------------------
// 拖拽X范围改变
void __fastcall TForm1::TrackBar2Change(TObject *Sender)
{
int nXValue1 = TrackBar2->Position;
int nXValue2 = TrackBar1->Position;
int nXMax = 15;
int nXMin = -15;
if (nXValue1 >= nXValue2)
{
nXMax = nXValue1;
nXMin = nXValue2;
}else
{
nXMax = nXValue2;
nXMin = nXValue1;
}
DBChart1->LeftAxis->Maximum = nXMax * 10;
DBChart1->LeftAxis->Minimum = nXMin * 10;
Label4->Caption = AnsiString(nXMin * 10);
Label5->Caption = AnsiString(nXMax * 10);
}
//---------------------------------------------------------------------------
// 拖拽X范围改变
void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
int nXValue1 = TrackBar2->Position;
int nXValue2 = TrackBar1->Position;
int nXMax = 15;
int nXMin = -15;
if (nXValue1 >= nXValue2)
{
nXMax = nXValue1;
nXMin = nXValue2;
}else
{
nXMax = nXValue2;
nXMin = nXValue1;
}
DBChart1->LeftAxis->Maximum = nXMax * 10;
DBChart1->LeftAxis->Minimum = nXMin * 10;
Label4->Caption = AnsiString(nXMin * 10);
Label5->Caption = AnsiString(nXMax * 10);
}
//---------------------------------------------------------------------------
// 拖拽Y范围改变
void __fastcall TForm1::TrackBar3Change(TObject *Sender)
{
int nYValue1 = TrackBar3->Position;
int nYValue2 = TrackBar4->Position;
int nYMax = 20;
int nYMin = 0;
if (nYValue1 >= nYValue2)
{
nYMax = nYValue1;
nYMin = nYValue2;
}else
{
nYMax = nYValue2;
nYMin = nYValue1;
}
DBChart2->LeftAxis->Maximum = nYMax * 10;
DBChart2->LeftAxis->Minimum = nYMin * 10;
Label6->Caption = AnsiString(nYMin * 10);
Label7->Caption = AnsiString(nYMax * 10);
}
//---------------------------------------------------------------------------
// 拖拽Y范围改变
void __fastcall TForm1::TrackBar4Change(TObject *Sender)
{
int nYValue1 = TrackBar3->Position;
int nYValue2 = TrackBar4->Position;
int nYMax = 20;
int nYMin = 0;
if (nYValue1 >= nYValue2)
{
nYMax = nYValue1;
nYMin = nYValue2;
}else
{
nYMax = nYValue2;
nYMin = nYValue1;
}
DBChart2->LeftAxis->Maximum = nYMax * 10;
DBChart2->LeftAxis->Minimum = nYMin * 10;
Label6->Caption = AnsiString(nYMin * 10);
Label7->Caption = AnsiString(nYMax * 10);
}
//---------------------------------------------------------------------------
// 拖拽Z范围改变
void __fastcall TForm1::TrackBar5Change(TObject *Sender)
{
int nZValue1 = TrackBar5->Position;
int nZValue2 = TrackBar6->Position;
int nZMax = 20;
int nZMin = -5;
if (nZValue1 >= nZValue2)
{
nZMax = nZValue1;
nZMin = nZValue2;
}else
{
nZMax = nZValue2;
nZMin = nZValue1;
}
DBChart3->LeftAxis->Maximum = nZMax * 10;
DBChart3->LeftAxis->Minimum = nZMin * 10;
Label8->Caption = AnsiString(nZMin * 10);
Label9->Caption = AnsiString(nZMax * 10);
}
//---------------------------------------------------------------------------
// 拖拽Z范围改变
void __fastcall TForm1::TrackBar6Change(TObject *Sender)
{
int nZValue1 = TrackBar5->Position;
int nZValue2 = TrackBar6->Position;
int nZMax = 20;
int nZMin = -5;
if (nZValue1 >= nZValue2)
{
nZMax = nZValue1;
nZMin = nZValue2;
}else
{
nZMax = nZValue2;
nZMin = nZValue1;
}
DBChart3->LeftAxis->Maximum = nZMax * 10;
DBChart3->LeftAxis->Minimum = nZMin * 10;
Label8->Caption = AnsiString(nZMin * 10);
Label9->Caption = AnsiString(nZMax * 10);
}
//---------------------------------------------------------------------------
// 重新开始分析
void __fastcall TForm1::Button4Click(TObject *Sender)
{
nCurrentX = 0;
Series1->Clear();
FastLineSeries1->Clear();
FastLineSeries6->Clear();
Timer2->Enabled = true;
m_bIsDrawing = true;
Button1->Enabled = false;
Button3->Enabled = true;
return;
}
//---------------------------------------------------------------------------
// 开始打印信息
void TForm1::StartLog()
{
AnsiString szFileName = "数据记录" + AnsiString(StatusBar1->Panels->Items[2]->Text) + ".ini" ;
pIni = new TIniFile(ExtractFilePath(Application->ExeName) + szFileName);
}
//---------------------------------------------------------------------------
// 打印信息
void TForm1::SaveLog()
{
pIni->WriteString("本次记录",AnsiString(StatusBar1->Panels->Items[2]->Text + " 信息编号:" + AnsiString(nCurrentX)),
AnsiString(StatusBar1->Panels->Items[0]->Text));
}
//---------------------------------------------------------------------------
// 停止打印
void TForm1::EndSave()
{
if (pIni)
{
delete pIni;
pIni = NULL;
}
}
//---------------------------------------------------------------------------
// 按下打印信息
void __fastcall TForm1::CheckBox2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (CheckBox2->Checked)
{
m_bIsNeedSaving = false;
EndSave();
}
else
{
StartLog();
m_bIsNeedSaving = true;
}
}
//---------------------------------------------------------------------------
// 短时间设置
void __fastcall TForm1::TrackBar7Change(TObject *Sender)
{
DBChart1->TopAxis->Maximum = TrackBar7->Position * 100;
DBChart2->TopAxis->Maximum = TrackBar7->Position * 100;
DBChart3->TopAxis->Maximum = TrackBar7->Position * 100;
DBChart4->TopAxis->Maximum = TrackBar7->Position * 100;
DBChart1->BottomAxis->Maximum = TrackBar7->Position * 100;
DBChart2->BottomAxis->Maximum = TrackBar7->Position * 100;
DBChart3->BottomAxis->Maximum = TrackBar7->Position * 100;
DBChart4->BottomAxis->Maximum = TrackBar7->Position * 100;
Label13->Enabled = false;
Label10->Enabled = true;
return;
}
//---------------------------------------------------------------------------
// 长时间设置
void __fastcall TForm1::TrackBar8Change(TObject *Sender)
{
DBChart1->TopAxis->Maximum = TrackBar8->Position * 1000;
DBChart2->TopAxis->Maximum = TrackBar8->Position * 1000;
DBChart3->TopAxis->Maximum = TrackBar8->Position * 1000;
DBChart4->TopAxis->Maximum = TrackBar8->Position * 1000;
DBChart1->BottomAxis->Maximum = TrackBar8->Position * 1000;
DBChart2->BottomAxis->Maximum = TrackBar8->Position * 1000;
DBChart3->BottomAxis->Maximum = TrackBar8->Position * 1000;
DBChart3->BottomAxis->Maximum = TrackBar8->Position * 1000;
Label10->Enabled = false;
Label13->Enabled = true;
return;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBChart2DblClick(TObject *Sender)
{
if (m_bIsDrawing)
Button3Click(Sender);
else
Button1Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBChart3DblClick(TObject *Sender)
{
if (m_bIsDrawing)
Button3Click(Sender);
else
Button1Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBChart4DblClick(TObject *Sender)
{
if (m_bIsDrawing)
Button3Click(Sender);
else
Button1Click(Sender);
}
//---------------------------------------------------------------------------
// 仅观察平方值
void __fastcall TForm1::RadioButton4Click(TObject *Sender)
{
DBChart1->Hide();
DBChart2->Hide();
DBChart3->Hide();
DBChart4->Hide();
DBChart4->Height = 480;
DBChart4->Top = 0;
DBChart4->Show();
}
//---------------------------------------------------------------------------
void TForm1::SaveScreen()
{
HDC screenDC=GetDC(0);
Graphics::TBitmap *Bitmap =Image1->Picture->Bitmap;
Bitmap->Handle =CreateCompatibleBitmap(screenDC, 500 , 500);
BitBlt(Bitmap->Canvas->Handle,0,0,
Bitmap->Width,Bitmap->Height,
screenDC,Form1->Left,Form1->Top + 50, SRCCOPY);
AnsiString szFileName = "数据图象记录" + AnsiString(StatusBar1->Panels->Items[2]->Text) + ".jpg" ;
Image1->Picture->SaveToFile(szFileName);
ReleaseDC(0,screenDC);
}
//---------------------------------------------------------------------------