📄 unit20.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "math.h "
#include "stdio.h"
#include "Unit20.h"
#include "Unit21.h"
#include "Unit1.h"
#include "workcurvetype.h"
#include "IsNumber.h"
#include "IO.h"
#include "Fram.h"
#include "dir.h"
#include "Unit5.h"
#include "Unit22.h"
#include "Unit23.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormXGD *FormXGD;
//---------------------------------------------------------------------------
__fastcall TFormXGD::TFormXGD(TComponent* Owner)
: TForm(Owner)
{
int i;
//char gs[80];
bshowsapoint=true;
bshowexpoint=true;
bshowworkline=true;
m_bReadData = false;
m_Rdi = 0;
m_RX = 0; m_RY = 0;
DrawPutuBK();
m_WntoGo = Form1->wns0;
m_bStop = false;
m_CanCloseed = false;
m_bRunFirst = true;
m_bFirstActive = false;
m_SelectRow = -1;
m_VER = 101; //版本1.01
m_NDJD = 6;
m_XGDJD = 6;
m_MaxParaCount = 500;
m_pXGDParas = new XGDPARA[m_MaxParaCount];
m_StdParaCount = 0;; //标准样品个数
m_AllParaCount = 0; //所有测量个数
m_bStdCompl = false; //标准样品未建立
m_CurNDUnit = 0;
m_UnitK = 1.0;
m_bAmend = false;
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------
__fastcall TFormXGD::~TFormXGD()
{
if(m_pXGDParas != NULL)
{
delete []m_pXGDParas;
m_pXGDParas = NULL;
}
}
//---------------------------------------------------------------------------
void TFormXGD::DrawQX(void)
{
int i,wx,wy;
if(calcs<2) return;
if(Rb>YH) YH=Rb;
if((Ra*XH+Rb)>YH) YH=Ra*XH+Rb;
DrawBK();
wx=Left+(Right-Left)*(calca[0][1]-0.0)/(XH-XL);
wy=Top+(Bottom-Top)*(YH-calca[0][0])/(YH-YL);
Image1->Canvas->Pen->Style=psSolid;
Image1->Canvas->MoveTo(wx,wy);
if(bshowsapoint)
{
Image1->Canvas->Pen->Color=clBlue;
for(i=0;i<calcs;i++)
{
wx=Left+(Right-Left)*(calca[i][1]-0.0)/(XH-XL);
if(wx<Left) wx=Left;
else if(wx>Right) wx=Right;
wy=Top+(Bottom-Top)*(YH-calca[i][0])/(YH-YL);
if(wy<Top) wy=Top;
else if(wy>Bottom) wy=Bottom;
Image1->Canvas->Ellipse(wx-2,wy-2,wx+2,wy+2);
Image1->Canvas->LineTo(wx,wy);
Image1->Canvas->MoveTo(wx,wy);
}
Image1->Canvas->Pen->Color=clBlack;
}
if(bshowworkline)
{wx=Left;
wy=Top+(Bottom-Top)*(YH-Rb)/(YH-YL);
Image1->Canvas->Pen->Style=psSolid;
Image1->Canvas->Pen->Color=clBlack;
Image1->Canvas->MoveTo(wx,wy);
wx=Right;
wy=Top+(Bottom-Top)*(YH-(Ra*XH+Rb))/(YH-YL);
if(wy<Top) wy=Top;
else if(wy>Bottom) wy=Bottom;
Image1->Canvas->LineTo(wx,wy);
}
String Str;
char ts[80];
Str="C=";
sprintf(ts,"%4.5f",Ra);
Str+=ts;
Str+="×A";
if(Rb>=0) Str+="+";
sprintf(ts,"%4.5f",Rb);
Str+=ts;
labelC_A->Caption=Str;
Str="R=";
Str+=FloatToStr(Rc);
labelR->Caption=Str;
}
//---------------------------------------------------------------------------
void TFormXGD::DrawBK(void)
{
//int Wx00, Wx11, Wy00, Wy11;
//int Wx0, Wx1, Wy0, Wy1;
CommonDrawBK(Image1->Canvas,
0, Image1->Width, 0, Image1->Height,
XL, XH, YL, YH,
Wx00, Wx11, Wy00, Wy11,
Wx0, Wx1, Wy0, Wy1);
return;
Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height);
Image1->Canvas->Rectangle(Left,Top-5,Right,Bottom+5);
//画两条虚线
Image1->Canvas->Pen->Style=psDot;
Image1->Canvas->MoveTo(Left,Top);
Image1->Canvas->LineTo(Right,Top);
Image1->Canvas->MoveTo(Left,Bottom);
Image1->Canvas->LineTo(Right,Bottom);
Image1->Canvas->Pen->Style=psSolid;
//画坐标刻度
int x,y;
for(int i=1;i<10;i++)
{ x=Left+((Right-Left)*i)/10;
y=Top-5;
Image1->Canvas->MoveTo(x,y);
Image1->Canvas->LineTo(x,y+3);
y=Bottom+5;
Image1->Canvas->MoveTo(x,y-1);
Image1->Canvas->LineTo(x,y-4);
x=Left;
y=Top+((Bottom-Top-10)*i)/10;
Image1->Canvas->MoveTo(x,y);
Image1->Canvas->LineTo(x+3,y);
x=Right;
Image1->Canvas->MoveTo(x-1,y);
Image1->Canvas->LineTo(x-4,y);
}
//画间隔点
for(int i=1;i<20;i++)
for(int j=1;j<20;j++)
{ x=Left+(Right-Left)*i/20;
y=Top+(Bottom-Top)*j/20;
Image1->Canvas->Pixels[x][y]=clBlack;
}
char ts[80];
sprintf(ts,"%4.2f",YH);
Form1->Peak_write(Image1,Left-15,Top+15,ts);
sprintf(ts,"%4.2f",YL);
Form1->Peak_write(Image1,Left-15,Bottom+5,ts);
sprintf(ts,"%4.2f",XL);
Image1->Canvas->TextOut(Left,Bottom+5,ts);
sprintf(ts,"%4.2f",XH);
Image1->Canvas->TextOut(Right-20,Bottom+5,ts);
Image1->Canvas->TextOut((Left+Right)/2-10,Bottom+5,"吸光度");
Form1->Peak_write(Image1,Left-15,(Top+Bottom)/2+10,"浓度");
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::FormCreate(TObject *Sender)
{
TSize sz;
Left=20;Right=Image1->Width-20;
Top=20; Bottom=Image1->Height-20;
XL=0.0; XH=0.0; YL=0.0; YH=0.0;
bCeLiang=false;
DrawBK();
StringGrid1->Cells[0][0] = "序号";
StringGrid1->Cells[1][0] = "名称";
StringGrid1->Cells[2][0] = "编号";
StringGrid1->Cells[3][0] = "ABS";
StringGrid1->Cells[4][0] = "C1";
StringGrid1->Cells[5][0] = "C";
StringGrid1->Cells[6][0] = "C1-C";
StringGrid1->Cells[7][0] = "测量次数";
StringGrid1->Cells[8][0] = "日期";
StringGrid1->Cells[9][0] = "备注";
sz = StringGrid1->Canvas->TextExtent("2004-7-19 17:20:23");
StringGrid1->ColWidths[8] = sz.cx + 1;
UpdatePara();
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::btnReturnClick(TObject *Sender)
{
this->ActiveControl = NULL;
m_CanCloseed = true;
Close();
}
//---------------------------------------------------------------------------
void TFormXGD::manudraw()
{
FormInData->ShowModal();
if(FormInData->bOK==true)
{
this->GetData();
if(calcs==0) return;
hg1(&Ra,&Rb,&Rc);
DrawQX();
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void TFormXGD::hg(float *a,float *b,float *c)
{
int i;
float xn=0.0,yn=0.0,a1=0.0,a2=0.0,a3=0.0,a4=0.0;
*a=0.0;*b=0.0;*c=0.0;
for(i=0;i<calcs;i++)
{ xn=xn+calca[i][0];
yn=yn+calca[i][1];
}
xn=xn/(float)calcs;
yn=yn/(float)calcs;
for(i=0;i<calcs;i++)
{ a1=a1+(calca[i][0]-xn)*(calca[i][1]-yn);
a2=a2+(calca[i][0]-xn)*(calca[i][0]-xn);
a3=a3+(calca[i][1]-yn)*(calca[i][1]-yn);
}
if(a2!=0)*a=a1/a2;
*b=yn-*a*xn;
a4=sqrt(a2*a3);
if(a4!=0)*c=a1/a4;
}
//---------------------------------------------------------------------------
void TFormXGD::hg1(float *a,float *b,float *c)
{
int i;
int calcs;
float xn=0.0,yn=0.0,a1=0.0,a2=0.0,a3=0.0,a4=0.0;
*a=0.0;*b=0.0;*c=0.0;
calcs = m_StdParaCount;
for(i = 0; i < calcs; i++)
{
strcpy(m_pXGDParas[i].Name, StringGrid1->Cells[1][i+1].c_str());
strcpy(m_pXGDParas[i].Num, StringGrid1->Cells[2][i+1].c_str());
if(IsFloat(StringGrid1->Cells[3][i + 1]))
m_pXGDParas[i].Abs = StringGrid1->Cells[3][i + 1].ToDouble();
if(IsFloat(StringGrid1->Cells[4][i + 1]))
{
m_pXGDParas[i].C1 = StringGrid1->Cells[4][i + 1].ToDouble();
m_pXGDParas[i].C = m_pXGDParas[i].C1;
}
if(IsFloat(StringGrid1->Cells[7][i + 1]))
m_pXGDParas[i].TasCount = StringGrid1->Cells[7][i + 1].ToDouble();
DateTimeToSystemTime(StrToDateTime(StringGrid1->Cells[8][i+1]), m_pXGDParas[i].Time);
strcpy(m_pXGDParas[i].BeiZhu, StringGrid1->Cells[9][i+1].c_str());
m_pXGDParas[i].bValid = true;
xn=xn + m_pXGDParas[i].Abs;
yn=yn + m_pXGDParas[i].C1;
}
xn = xn / (float)calcs;
yn = yn / (float)calcs;
for(i = 0; i < calcs; i++)
{
a1 = a1 + (m_pXGDParas[i].Abs - xn) * (m_pXGDParas[i].C1 - yn);
a2 = a2 + (m_pXGDParas[i].Abs - xn) * (m_pXGDParas[i].Abs - xn);
a3 = a3 + (m_pXGDParas[i].C1 - yn) * (m_pXGDParas[i].C1 - yn);
}
if(a2!=0)*a=a1/a2;
*b=yn-*a*xn;
a4=sqrt(a2*a3);
if(a4!=0)*c=a1/a4;
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::FormShow(TObject *Sender)
{
float wx, val;
bool br;
int xt, yt;
int wi;
char gs[80];
//int Wx00, Wx11, Wy00, Wy11;
//int Wx0, Wx1, Wy0, Wy1;
this->ActiveControl = NULL;
m_CanCloseed = false;
m_bFirstActive = true;
FNFloatToStr(gs, 1, 3, (float)Form1->mcs/(float)Form1->wnd0);
labelCurBC->Caption = gs;
labelCurBC->Caption = labelCurBC->Caption + " nm";
labelCurBC->Repaint();
DrawPutuBK();
DrawPutuQX();
wi = 0;
br = Form1->GetData1(wi, m_Wx0, m_Wx1, m_Wy0, m_Wy1, xt, yt, wx, val);
if(br)
{
m_bReadData = true;
m_Rdi= wi;
m_RX = xt; m_RY = yt;
RSRect=Rect(0,0,IMTemp->Width,IMTemp->Height);
RDRect=Rect(m_RX-5,m_RY-5,m_RX+5,m_RY+5);
IMTemp->Canvas->CopyRect(RSRect,imgPutu->Canvas,RDRect);//Get
GetDataPutu(m_Rdi);
}
else
{
m_bReadData = false;
}
/*
StringGrid1->Cells[0][1] = 1;
sprintf(gs, "未命名%d", 1);
StringGrid1->Cells[1][1] = gs;
sprintf(gs, "编号%4.0d", 1);
StringGrid1->Cells[2][1] = gs;
StringGrid1->Cells[3][1] = "";
StringGrid1->Cells[4][1] = "";
StringGrid1->Cells[5][1] = "";
StringGrid1->Cells[6][1] = "";
StringGrid1->Cells[7][1] = "1";
GetLocalTime(&m_pXGDParas[0].Time); //日期时间
StringGrid1->Cells[8][1] = DateTimeToStr(SystemTimeToDateTime(m_pXGDParas[0].Time));
StringGrid1->Cells[9][1] = "(无)";
*/
Timer1->Enabled = true;
//StringGrid1->Row = 1;
//StringGrid1->Col = 1;
//UpdatePara();
}
//---------------------------------------------------------------------------
void TFormXGD::DrawPutuBK(void)
{
Form1->DrawBK1(imgPutu->Canvas, imgPutu->Width, imgPutu->Height,
m_Wx00, m_Wx11, m_Wy00, m_Wy11,
m_Wx0, m_Wx1, m_Wy0, m_Wy1);
}
//---------------------------------------------------------------------------
void TFormXGD::DrawPutuQX(void)
{
Form1->DrawQX1(imgPutu->Canvas,
m_Wx00, m_Wx11, m_Wy00, m_Wy11,
m_Wx0, m_Wx1, m_Wy0, m_Wy1);
if(m_bReadData)
{
RSRect=Rect(0,0,IMTemp->Width,IMTemp->Height);
RDRect=Rect(m_RX-5,m_RY-5,m_RX+5,m_RY+5);
IMTemp->Canvas->CopyRect(RSRect,imgPutu->Canvas,RDRect);//Get
GetDataPutu(m_Rdi);
}
}
//---------------------------------------------------------------------------
void TFormXGD::GetDataPutu(int wi)
{
float wx, val;
bool br;
char gs[80];
int xt, yt;
br = Form1->GetData1(wi, m_Wx0, m_Wx1, m_Wy0, m_Wy1, xt, yt, wx, val);
if(br)
{
m_Rdi = wi;
RSRect=Rect(0,0,IMTemp->Width,IMTemp->Height);
RDRect=Rect(m_RX-5,m_RY-5,m_RX+5,m_RY+5);
imgPutu->Canvas->CopyRect(RDRect,IMTemp->Canvas,RSRect);//Put
m_RX = xt; m_RY = yt;
RDRect=Rect(m_RX-5,m_RY-5,m_RX+5,m_RY+5);
IMTemp->Canvas->CopyRect(RSRect,imgPutu->Canvas,RDRect);//Get
//DrawCross
imgPutu->Canvas->Pen->Color=clRed;
imgPutu->Canvas->MoveTo(m_RX-5,m_RY-5);
imgPutu->Canvas->LineTo(m_RX+5,m_RY+5);
imgPutu->Canvas->MoveTo(m_RX-5,m_RY+4);//
imgPutu->Canvas->LineTo(m_RX+5,m_RY-5);
//sprintf(gs, "%1.3f", wx);
FNFloatToStr(gs, 1, 3, wx);
lbWx->Caption = gs;
//sprintf(gs, "%1.1f", val);
FNFloatToStr(gs, 1, m_XGDJD, val);
lbVal->Caption = gs;
}
}
//---------------------------------------------------------------------------
void TFormXGD::GetData(void)
{
float maxx=0.0,maxy=0.0;
float minx=0.0,miny=0.0;
calcs=0;
for(int i=1;i<=21;i++)
{
if(FormInData->StringGrid1->Cells[1][i]=="") break;
if(FormInData->StringGrid1->Cells[2][i]=="") break;
calca[i-1][0]=StrToFloat(FormInData->StringGrid1->Cells[1][i]);
if(calca[i-1][0]>maxy) maxy=calca[i-1][0];
if(calca[i-1][0]<miny) minx=calca[i-1][0];
calca[i-1][1]=StrToFloat(FormInData->StringGrid1->Cells[2][i]);
if(calca[i-1][1]>maxx) maxx=calca[i-1][1];
if(calca[i-1][1]<minx) minx=calca[i-1][1];
calcs++;
}
YH=maxy;
YL=miny;
XH=maxx;
XL=minx;
}
void __fastcall TFormXGD::btnCeLiangClick(TObject *Sender)
{
float xgd, nd;
char gs[80];
int row;
this->ActiveControl = NULL;
if(m_bStdCompl && m_SelectRow > 0)
{
row = m_SelectRow;
// Form1->set_tmode();
xgd = Form1->tas(1);
if(Form1->csd[1] != 3)
xgd = Form1->pp2 * xgd * Form1->tbb() * 100.0;
xgd = Form1->toa(xgd);
nd = Ra * xgd + Rb;
if(XL > xgd) XL = xgd;
if(XH < xgd) XH = xgd;
if(YL > nd) YL = nd;
if(YH < nd) YH = nd;
m_pXGDParas[row - 1].Abs = xgd;
m_pXGDParas[row - 1].C1 = nd;
//StringGrid1->Col = 2;
//StringGrid1->Options >> goRowSelect;
//StringGrid1->Options << goEditing;
//StringGrid1->Options << goAlwaysShowEditor;
//sprintf(gs, "%1.3f", xgd);
FNFloatToStr(gs, 1, m_XGDJD, xgd);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -