unit20.cpp

来自「光学仪器的控制系统 用于教学和科研的仪器」· C++ 代码 · 共 2,372 行 · 第 1/5 页

CPP
2,372
字号
    {
        m_StdParaCount = m_AllParaCount;
        XL = 999999; XH = -999999;
        YL = 999999; YH = -999999;
        for(i = 0; i < m_StdParaCount; i++)
        {
            if(m_pXGDParas[i].Abs < XL) XL = m_pXGDParas[i].Abs;
            if(m_pXGDParas[i].Abs > XH) XH = m_pXGDParas[i].Abs;
            if(m_pXGDParas[i].C1 < YL) YL = m_pXGDParas[i].C1;
            if(m_pXGDParas[i].C1 > YH) YH = m_pXGDParas[i].C1;
        }

        hg1(&Ra,&Rb,&Rc);

        Str = "C=";
        sprintf(gs, "%4.5f", Ra);
        Str += gs;
        Str += "×A";
        Str += "+";
        sprintf(gs,"%4.5f",Rb);
        Str += gs;
        labelC_A->Caption = Str;

        Str = "R=";
        sprintf(gs,"%4.5f",Rc);
        Str += gs;
        labelR->Caption = Str;

        //m_StdX[0] = XL;  m_StdX[1] = XH;
        //m_StdY[0] = (Ra*XL + Rb);
        //m_StdY[1] = (Ra*XH + Rb);

        btnBuildStd->Enabled = false;

        m_bStdCompl = true;
        DrawWorkQX();

        UpdatePara();
        NewItem();
        //StringGrid1->FixedRows = StringGrid1->FixedRows + m_StdParaCount;
        //StringGrid1->Repaint();

        btnCeLiang->Enabled = true;
        SelectGridCell(StringGrid1, 0, StringGrid1->RowCount - 1);
        m_bAmend = true;
    }
*/
}
//---------------------------------------------------------------------------
void TFormXGD::DrawWorkQX(void)
{
    int i;
    AnsiString Str;
    char gs[80];
    float xgd, nd;

    CommonDrawBK(Image1->Canvas,
                    0, Image1->Width, 0, Image1->Height,
                    XL, XH, YL, YH,
                    Wx00, Wx11, Wy00, Wy11,
                    Wx0,  Wx1,  Wy0,  Wy1);
    if(m_bStdCompl)
    {
        m_StdX[0] = XL;  m_StdX[1] = XH;
        m_StdY[0] = (Ra*XL + Rb);
        m_StdY[1] = (Ra*XH + Rb);

        if(m_StdY[0] < YL) YL = m_StdY[0];
        if(m_StdY[0] > YH) YH = m_StdY[0];
        if(m_StdY[1] < YL) YL = m_StdY[1];
        if(m_StdY[1] > YH) YH = m_StdY[1];
        
        CommonDrawQX(Image1->Canvas,
                    XL, XH, YL, YH,
                    m_StdX, m_StdY, 2,
                    Wx00, Wx11, Wy00, Wy11,
                    Wx0,  Wx1,  Wy0,  Wy1,
                    clGreen, true);

        for(i = 0; i < m_StdParaCount; i++)
        {
            if(!IsFloat(StringGrid1->Cells[3][i + 1]) || !IsFloat(StringGrid1->Cells[4][i + 1]))
                  continue;

            xgd = StringGrid1->Cells[3][i + 1].ToDouble();
            nd = StringGrid1->Cells[4][i + 1].ToDouble();
            
            CommonDrawPoint(Image1->Canvas,
                    XL, XH, YL, YH,
                    //m_pXGDParas[i].Abs, m_pXGDParas[i].C1, i+1,
                    xgd, nd, i+1,
                    Wx00, Wx11, Wy00, Wy11,
                    Wx0,  Wx1,  Wy0,  Wy1,
                    clRed, false);
        }
        for(; i < m_AllParaCount; i++)
        {
            if(!IsFloat(StringGrid1->Cells[3][i + 1]) || !IsFloat(StringGrid1->Cells[4][i + 1]))
                  continue;

            xgd = StringGrid1->Cells[3][i + 1].ToDouble();
            nd = StringGrid1->Cells[4][i + 1].ToDouble();

            CommonDrawPoint(Image1->Canvas,
                    XL, XH, YL, YH,
                    xgd, nd, i - m_StdParaCount + 1,
                    Wx00, Wx11, Wy00, Wy11,
                    Wx0,  Wx1,  Wy0,  Wy1,
                    clBlue, true);
        }

        Str = "C=";
        sprintf(gs, "%4.5f", Ra);
        Str += gs;
        Str += "×A";
        if(Rb >= 0)
            Str += " + ";
        else
            Str += " - ";
        //sprintf(gs,"%4.5f",Rb);
        FNFloatToStr(gs, 1, m_NDJD, fabs(Rb));
        Str += gs;

        switch(m_CurNDUnit)
        {
            case 0: Str += " (ug/ml)"; break;
            case 1: Str += " (ng/ml)"; break;
            case 2: Str += " (pg/ml)"; break;
        }
        labelC_A->Caption = Str;

        Str = "R=";
        sprintf(gs,"%4.5f",Rc);
        Str += gs;
        labelR->Caption = Str;
    }
}
//---------------------------------------------------------------------------
void  TFormXGD::MouseClikAt(UINT  x,UINT  y)
{
    CursorAt(x, y);
    ButtonD(1);
    ButtonU(1);
}
//---------------------------------------------------------------------------
void  TFormXGD::CursorAt(UINT  x,UINT  y)
{
       INPUT  input[1];
       x=(UINT)(65535.0*x/GetSystemMetrics(SM_CXSCREEN));
       y=(UINT)(65535.0*y/GetSystemMetrics(SM_CYSCREEN));

       memset(input,0,sizeof(input));
       input[0].type  =  INPUT_MOUSE;
       input[0].mi.dx=x;
       input[0].mi.dy=y;
       input[0].mi.dwFlags  =  MOUSEEVENTF_ABSOLUTE  |MOUSEEVENTF_MOVE;
       input[0].ki.time  =  GetTickCount();
       SendInput(1,  input,  sizeof(INPUT));
}
//---------------------------------------------------------------------------
void  TFormXGD::ButtonD(UINT  button)
{
       INPUT  input[1];  
       memset(input,0,sizeof(input));  
       input[0].type  =  INPUT_MOUSE;
       switch  (button)  
       {  
       case  3:  
               input[0].mi.dwFlags  =  MOUSEEVENTF_MIDDLEDOWN;  
               break;  
       case  2:  
               input[0].mi.dwFlags  =  MOUSEEVENTF_RIGHTDOWN;  
               break;  
       default:  
               input[0].mi.dwFlags  =  MOUSEEVENTF_LEFTDOWN;  
       }  
       input[0].ki.time  =  GetTickCount();  
       SendInput(1,  input,  sizeof(INPUT));  
}  
//---------------------------------------------------------------------------
void  TFormXGD::ButtonU(UINT  button)
{
       INPUT  input[1];
       memset(input,0,sizeof(input));
       input[0].type  =  INPUT_MOUSE;
       switch  (button)
       {
       case  3:
               input[0].mi.dwFlags  =  MOUSEEVENTF_MIDDLEUP;
               break;
       case  2:
               input[0].mi.dwFlags  =  MOUSEEVENTF_RIGHTUP;
               break;
       default:
               input[0].mi.dwFlags  =  MOUSEEVENTF_LEFTUP;
       }
       input[0].ki.time  =  GetTickCount();
       SendInput(1,  input,  sizeof(INPUT));
}

//---------------------------------------------------------------------------
void TFormXGD::SelectGridCell(TStringGrid *sgrid, int Col, int Row)
{
/*
    TGridRect gridrect;
    gridrect.Left = Col;
    gridrect.Top = Row;
    gridrect.Right = Col;
    gridrect.Bottom = Row;
    sgrid->Selection = gridrect;
*/

    TRect cellrect;
    TPoint oldpt, pt;

    GetCursorPos(&oldpt);
    cellrect = sgrid->CellRect(Col, Row);
    pt.x = (cellrect.Left + cellrect.Right) / 2;
    pt.y = (cellrect.Top  + cellrect.Bottom) / 2;
    pt = sgrid->ClientToScreen(pt);
    MouseClikAt(pt.x, pt.y);
    CursorAt(oldpt.x, oldpt.y);

}
//---------------------------------------------------------------------------
void TFormXGD::InitPara(void)
{
  int i;
  char gs[80];

  StringGrid1->RowCount = 2;
  m_StdParaCount = 0;;  //标准样品个数
  m_AllParaCount = 0;   //所有测量个数
  m_bStdCompl = false;  //标准样品未建立
  m_CurNDUnit = 0;

  SetNDUnit(m_CurNDUnit);

  for(i = 0; i < StringGrid1->ColCount; i++)
           StringGrid1->Cells[i][1] = "";

    for(i = 0; i < m_MaxParaCount; i++)
    {
        sprintf(gs, "未命名%d", i+1);
        strcpy(m_pXGDParas[i].Name, gs);
        sprintf(gs, "编号%d", i+1);
        strcpy(m_pXGDParas[i].Num, gs);
        m_pXGDParas[i].Abs = 0.123;
        m_pXGDParas[i].C1 = 0.456;
        m_pXGDParas[i].C = 0.345;
        m_pXGDParas[i].TasCount = 1;       //测量次数
        GetLocalTime(&m_pXGDParas[i].Time);    //日期时间
        strcpy(m_pXGDParas[i].BeiZhu, "(无)");      //备注
        m_pXGDParas[i].bValid = false;
    }

  XL = 0; XH = 0;
  YL = 0; YH = 0;
  CommonDrawBK(Image1->Canvas,
                    0, Image1->Width, 0, Image1->Height,
                    XL, XH, YL, YH,
                    Wx00, Wx11, Wy00, Wy11,
                    Wx0,  Wx1,  Wy0,  Wy1);

  NewItem();
  StringGrid1->Repaint();

    btnAddItem->Enabled = CheckForNewItem();
    if(!m_bStdCompl)
    {
        if(btnAddItem->Enabled && StringGrid1->RowCount >= 3)
        {
            btnBuildStd->Enabled = true;
        }
        else
        {
            btnBuildStd->Enabled = false;
        }
    }
    else
    {
        btnBuildStd->Enabled = true;
    }

  m_bAmend = false;
  m_UnitK = 1.0;
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::tbSaveClick(TObject *Sender)
{
    DoSave();
}
//---------------------------------------------------------------------------
int TFormXGD::SaveNDFile(AnsiString strFName)
{
  int iFileHandle;
  char fileflag[10], stdcomp;
  int len;
  int r;
  int i;

  strcpy(fileflag, "wfz-26uvc");
  iFileHandle = FileCreate(strFName);
  if(iFileHandle == -1)
  {
      r = -1;
  }
  else
  {
      stdcomp = m_bStdCompl;

      FileWrite(iFileHandle, fileflag, 10);
      FileWrite(iFileHandle, &m_VER, sizeof(m_VER));
      FileWrite(iFileHandle, &m_AllParaCount, sizeof(m_AllParaCount));
      FileWrite(iFileHandle, &m_StdParaCount, sizeof(m_StdParaCount));
      FileWrite(iFileHandle, &stdcomp, sizeof(stdcomp));
      //ver 1.01
      if(m_VER >= 101)
          FileWrite(iFileHandle, &m_CurNDUnit, sizeof(m_CurNDUnit));
      
      FileWrite(iFileHandle, &XL, sizeof(XL));
      FileWrite(iFileHandle, &XH, sizeof(XH));
      FileWrite(iFileHandle, &YL, sizeof(YL));
      FileWrite(iFileHandle, &YH, sizeof(YH));

      FileWrite(iFileHandle, &Ra, sizeof(Ra));
      FileWrite(iFileHandle, &Rb, sizeof(Rb));
      FileWrite(iFileHandle, &Rc, sizeof(Rc));

      for(i = 0; i < m_AllParaCount; i++)
      {
          len = sizeof(m_pXGDParas[i]);
          FileWrite(iFileHandle, &m_pXGDParas[i], len);
      }

      FileClose(iFileHandle);
      r = 0;
  }

  return r;
}
//---------------------------------------------------------------------------
int TFormXGD::LoadNDFile(AnsiString strFName)
{
  int iFileHandle;
  char fileflag[10], stdcomp;
  int ver;
  int allcount, stdcount;
  int len;
  int r;

  int i;

  strcpy(fileflag, "wfz-26uvc");
  iFileHandle = FileOpen(strFName, fmOpenRead);
  if(iFileHandle == -1)
  {
      r = -1;
  }
  else
  {

      r = -1;

      FileRead(iFileHandle, fileflag, 10);
      if(strcmp(fileflag, "wfz-26uvc") == 0)
      {
          FileRead(iFileHandle, &ver, sizeof(m_VER));
          FileRead(iFileHandle, &allcount, sizeof(allcount));
          FileRead(iFileHandle, &stdcount, sizeof(stdcount));
          FileRead(iFileHandle, &stdcomp, sizeof(stdcomp));
          //ver 1.01
          if(ver >= 101)
              FileRead(iFileHandle, &m_CurNDUnit, sizeof(m_CurNDUnit));
          else
              m_CurNDUnit = 0;

          if(ver <= m_VER && allcount <= m_MaxParaCount)
          {
              m_AllParaCount = allcount;
              m_StdParaCount = stdcount;
              m_bStdCompl = stdcomp;

              FileRead(iFileHandle, &XL, sizeof(XL));
              FileRead(iFileHandle, &XH, sizeof(XH));
              FileRead(iFileHandle, &YL, sizeof(YL));
              FileRead(iFileHandle, &YH, sizeof(YH));

              FileRead(iFileHandle, &Ra, sizeof(Ra));
              FileRead(iFileHandle, &Rb, sizeof(Rb));
              FileRead(iFileHandle, &Rc, sizeof(Rc));

              for(i = 0; i < m_AllParaCount; i++)
              {
                  len = sizeof(m_pXGDParas[i]);
                  FileRead(iFileHandle, &m_pXGDParas[i], len);
              }
              r = 0;
          }
          else
          {
              if(ver > m_VER) r = -2;
              else if(allcount > m_MaxParaCount) r = -3;
          }

      }

      FileClose(iFileHandle);
  }

  return r;
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::tbOpenClick(TObject *Sender)
{
    int iFileHandle;
    int r;
    AnsiString strHint;

    if(CheckAmended())
    {
        r = Application->MessageBox("测量内容已经改变,是否保存?","提示",MB_YESNO|MB_ICONWARNING);
        if(r == IDYES)
        {
            r = DoSave();
            if(r != 1) return ;
        }
    }

    if(OpenDialog1->Execute())
    {
        if(FileExists(OpenDialog1->FileName))
        {
            r = LoadNDFile(OpenDialog1->FileName);
            if(r >= 0)
            {
                StringGrid1->RowCount = m_AllParaCount + 1;
                UpdatePara();
                SetNDUnit(m_CurNDUnit);
                DrawWorkQX();
                StringGrid1->Repaint();

    btnAddItem->Enabled = CheckForNewItem();
    if(!m_bStdCompl)
    {
        if(btnAddItem->Enabled && StringGrid1->RowCount >= 3)
        {
            btnBuildStd->Enabled = true;
        }
        else
        {
            btnBuildStd->Enabled = false;
        }
    }
    else
    {
        btnBuildStd->Enabled = true;
    }

                m_bAmend = false;
            }
            else
            {
                switch(r)
                {
                    case -1: strHint = "无法打开文件!"; break;
                    case -2: strHint = "文件版本不对,无法打开!"; break;
                    case -3: strHint = "测量项过多,可能文件已损坏,无法打开"; break;
                    case -4: strHint = "未知错误,无法打开文件!"; break;
                }
                Application->MessageBox(strHint.c_str(), "提示",
     

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?