#include "cctrlgraph_worktable_xy.h"
#include "logic.h"
#include <QPainter>
#include <QMutexLocker>
#include <QFontInfo>
#include <QApplication>
#include <QReadWriteLock>
#include "gui.h"
#include "cjig_driver.h"
CCtrlGraph_WorkTable_XY::CCtrlGraph_WorkTable_XY(QWidget *parent)
    : CCtrlGraph_WorkTable(parent)
{
	m_dAngleArrow = 0;
    m_MoveBtn.m_rect=QRect(0,0,50,35);
    m_MoveBtn.m_str=trUtf8("Move");
    m_bDrawButton=false;

}

void CCtrlGraph_WorkTable_XY::refreshPixmap(bool bupdate)
{
    if(!isVisible()) return;
    makeCurrent();
    m_Pixmap=QPixmap(size());
    m_Pixmap.fill(m_BKColor);
    QPainter painter(&m_Pixmap);
    painter.initFrom(this);

    if(!painter.isActive())return;
    draw_Background(painter);
    QRectF rectView=get_rectClip();
    painter.setClipRect(rectView);
    DrawTable(painter);
	DrawUserPanel(painter);
    DrawCell(painter);
    DrawLine(painter);
    DrawLevelPt(painter);
    DrawLocatePt(painter);
    DrawMsg( painter);
    DrawChannel(CAM2X,CH_RECT,QString("2"),Qt::green,painter);
    DrawChannel(CAM6X,CH_RECT,QString("6"),Qt::green,painter);
    DrawChannel(DistanceSensor, CH_RECT, QString("DS"), Qt::green, painter);
	#ifdef __USE_THIRD_CAMERA__
	DrawChannel(CAMKerf,CH_RECT,QString("4"),Qt::green,painter);
	#endif

    DrawChannel(LASERPATH_S_NARROW, CH_CIRCLE, GetLaserPathName(LASERPATH_S_NARROW), Qt::yellow, painter);
    DrawChannel(LASERPATH_D_NARROW, CH_CIRCLE, GetLaserPathName(LASERPATH_D_NARROW), Qt::yellow, painter);
    DrawChannel(LASERPATH_D_WIDE, CH_CIRCLE, GetLaserPathName(LASERPATH_D_WIDE), Qt::yellow, painter);
    DrawChannel(LASERPATH_L_NARROW, CH_CIRCLE, GetLaserPathName(LASERPATH_L_NARROW), Qt::yellow, painter);
    if (m_gSystem.m_iCurChID == LASERPATH_L_NARROW || m_gSystem.m_iCurChID == LASERPATH_D_WIDE
       || m_gSystem.m_iCurChID == LASERPATH_D_NARROW || m_gSystem.m_iCurChID == LASERPATH_S_NARROW)
    {
        DrawChannel(m_gSystem.m_iCurChID, CH_CIRCLE, GetLaserPathName(m_gSystem.m_iCurChID), Qt::yellow, painter);
        m_iLaserPathId = m_gSystem.m_iCurChID;
    }
    else
    {
        if (m_iLaserPathId != -1)
        {
            DrawChannel(m_iLaserPathId, CH_CIRCLE, GetLaserPathName(m_iLaserPathId), Qt::yellow, painter);
        }
    }

#ifdef __USE_JIG_MODULE__
	DrawLaserCheck(painter);
	DrawLaserCheckCell(painter);
#endif

	DrawPowerCheck(painter);

    DrawButton(painter);
    if(bupdate)
    {
        update();
    }
}

void CCtrlGraph_WorkTable_XY::DrawChannel(int32_t iChid, int32_t chshape,QString& chname, Qt::GlobalColor ecolor, QPainter &painter)
{

    CMWorkTableDriver* pWorktableDriver=GET_CARD(WORKTABLE_DRIVER,CMWorkTableDriver);
    Q_ASSERT(pWorktableDriver);
    CMPointd wt;
    pWorktableDriver->CurAxisToWt(iChid,wt,false);

    //旋转镜像
    wt = ConvertToLogicAixs(wt);

    DrawPoint( MPT_mmToQPT_mm(wt),   chshape,chname,   ecolor, painter);
    if(m_gSystem.m_iCurChID==iChid)
    {
        DrawCurPoint( MPT_mmToQPT_mm(wt),painter);
    }
}
void CCtrlGraph_WorkTable_XY::MTimeFresh()
{
    if(!isVisible()) return;
    refreshPixmap();

    int iSMID=SM_IO;
    VS_Thread* m_pState=(VS_Thread*)m_gSystem.FindSM(iSMID)->GetIdleState();
    if(m_pState->QueueSize()<100)
    {
        m_pState->pushback_Msg(VarMsg_Driver_ID,QObject::trUtf8("Fresh Pos"),
                               QVariantList()
                               <<MOTOR_DRIVER<<CMotorDriver::FRESHPOS
                               <<MOTORX,0);
        m_pState->pushback_Msg(VarMsg_Driver_ID,QObject::trUtf8("Fresh Pos"),
                               QVariantList()
                               <<MOTOR_DRIVER<<CMotorDriver::FRESHPOS
                               <<MOTORY,0);

    }
}

void CCtrlGraph_WorkTable_XY::MInit()
{

    m_dRangeXMin=0.5;
    m_dRangeXMax=200;

    lUnitsX.push_back(50.0);
    lUnitsX.push_back(20.0);
    lUnitsX.push_back(10.0);
    lUnitsX.push_back(5.0);
    lUnitsX.push_back(2.0);
    lUnitsX.push_back(1.0);
    m_dCurUnitX=0.1;
    m_strUnitX="mm";

    m_dRangeYMin=0.5;
    m_dRangeYMax=200;

    lUnitsY.push_back(50.0);
    lUnitsY.push_back(20.0);
    lUnitsY.push_back(10.0);
    lUnitsY.push_back(5.0);
    lUnitsY.push_back(2.0);
    lUnitsY.push_back(1.0);
    m_dCurUnitY=0.1;
    m_strUnitY="mm";

    CMWorkTable* pWorkTable=GET_CHDIRECT(WORKTABLE,CMWorkTable);

    int iwidth= pWorkTable-> m_Variants.get_VData(Var_WorkTable_Width_ID)
            ->toDouble();
    int iheight= pWorkTable->m_Variants.get_VData(Var_WorkTable_Height_ID)
            ->toDouble();

    m_dRangeXMax=iwidth;
    if(m_dRangeXMax<300)m_dRangeXMax=300;
    m_dRangeYMax=iheight;
    if(m_dRangeYMax<300)m_dRangeYMax=300;

    CCtrlGraph_WorkTable::MInit();
}

void CCtrlGraph_WorkTable_XY::mouseReleaseEvent(QMouseEvent *pEvent)
{
    CCtrlGraphOpenGL::mouseReleaseEvent(pEvent);
    if(pEvent->button()==Qt::LeftButton)
    {
        if(m_MoveBtn.m_rect.contains(pEvent->pos()))
        {
            m_MoveBtn.m_bChecked=!m_MoveBtn.m_bChecked;
        }
        else if(m_MoveBtn.m_bChecked&&
        m_gSystem.IsAllSMIdle()&&
        get_rectClip().contains(pEvent->pos()))
        {
            CMWorkTableDriver* pWorkTableDriver=GET_CARD(WORKTABLE_DRIVER,
                                                         CMWorkTableDriver);
            CMPointd wt,axis;
            QPointF pt=pEvent->pos();
            pt=m_trans_DP2LP.map(pt);
            wt.tX=pt.x();
            wt.tY=pt.y();

            int iPosState=m_gSystem.CheckWtPos(wt);
            if(iPosState==1)
            {
                m_gSystem.m_SysMsg.SetMsg(QObject::trUtf8("Target X pos out of work table"));
            }
            else if(iPosState==2)
            {
                m_gSystem.m_SysMsg.SetMsg(QObject::trUtf8("Target Y pos out of work table"));
            }
            if(iPosState)
            {
                return;
            }
            wt = ConvertToRealAxis(wt);

            pWorkTableDriver->WtToAxis(m_gSystem.m_iCurChID, wt,axis);
            V_MsgQueue msgqueue;
            m_gSystem.absmove_xy_msg(axis.tX,axis.tY,msgqueue);
            m_gSystem.start_test(SM_MAIN, msgqueue,true);
        }
    }
}

void CCtrlGraph_WorkTable_XY::mousePressEvent(QMouseEvent *pEvent)
{
    CCtrlGraph_WorkTable::mousePressEvent(pEvent);
    if(pEvent->button()==Qt::LeftButton)
    {m_bCapture=!m_MoveBtn.m_bChecked;}
}

void CCtrlGraph_WorkTable_XY::DrawTable(QPainter &painter)
{
    CMWorkTable* pWTTable=GET_CHDIRECT(WORKTABLE,CMWorkTable);
    double dWidth= pWTTable->m_Variants.get_VData(Var_WorkTable_Width_ID)->toDouble();
    double dHeight= pWTTable->m_Variants.get_VData(Var_WorkTable_Height_ID)->toDouble();


    painter.setTransform(m_trans_LP2DP);

    QRectF rectf=QRectF(-dWidth/2,-dHeight/2,dWidth,dHeight);
    painter.setPen(QPen(Qt::blue,0));
    painter.drawRect(rectf);
}

void CCtrlGraph_WorkTable_XY::DrawLaserCheck(QPainter& painter)
{
	
	CMWorkTableDriver* pWorktableDriver=GET_CARD(WORKTABLE_DRIVER,CMWorkTableDriver);
	Q_ASSERT(pWorktableDriver);

	CProcess_LaserKerf* pLaserKerf = GET_PROCESS(PROCESS_LASERKERF, SM_MAIN, CProcess_LaserKerf);
    CJigDriver* pJigDriver = GET_CARD(JigDriver, CJigDriver);
	double dCenterX = pJigDriver->m_Variants.get_VData(Var_Process_LaserKerf_AreaCenterX)->toDouble();
	double dCenterY = pJigDriver->m_Variants.get_VData(Var_Process_LaserKerf_AreaCenterY)->toDouble();
	CMPointd axis(dCenterX, dCenterY);
	CMPointd wt;
	pWorktableDriver->AxisToWt(CAM6X, axis, wt);
	QPointF pt = MPT_mmToQPT_mm(wt);
	painter.setPen(QPen(Qt::blue,0));
	int isize=75;
	painter.setTransform(m_trans_LP2DP);

	QRectF rectf(pt.x()-isize/2.0, pt.y()-isize/2.0, isize, isize);
	painter.drawRect(rectf);

	QLine line1(pt.x()-isize/2.0,pt.y(),
		pt.x()+isize/2.0,pt.y());
	QLine line2(pt.x(),pt.y()-isize/2.0,
		pt.x(),pt.y()+isize/2.0);
	painter.setPen(Qt::black);
	painter.drawLine(line1);
	painter.drawLine(line2);

	painter.setPen(Qt::yellow);
	uint areaType = pJigDriver->m_Variants.get_VData(Var_Process_LaserKerf_AreaType)->toUInt();
	isize = pJigDriver->m_Variants.get_VData(Var_Process_LaserKerf_AreaValidWidth)->toDouble();
	double dOuterErision = pJigDriver->m_Variants.get_VData(Var_Process_LaserKerf_OuterErosionDistance)->toDouble()*2;
	if(0 == areaType)
	{
		painter.drawEllipse(pt.x()-isize/2.0, pt.y()-isize/2.0, isize, isize);
	}
	else
	{
		painter.drawRect(pt.x()-isize/2, pt.y()-isize/2.0, isize, isize);
	}
}

void CCtrlGraph_WorkTable_XY::DrawLaserCheckCell(QPainter& painter)
{
	CProcess_LaserKerf* pProcessLaserKerf = GET_PROCESS(PROCESS_LASERKERF, SM_MAIN, CProcess_LaserKerf);
	Q_ASSERT(pProcessLaserKerf);

	CMWorkTableDriver* pWorktableDriver=GET_CARD(WORKTABLE_DRIVER,CMWorkTableDriver);
	Q_ASSERT(pWorktableDriver);
	
    CJigDriver* pJigDriver = GET_CARD(JigDriver, CJigDriver);
    double dCenterX = pJigDriver->m_Variants.get_VData(Var_Process_LaserKerf_AreaCenterX)->toDouble();
    double dCenterY = pJigDriver->m_Variants.get_VData(Var_Process_LaserKerf_AreaCenterY)->toDouble();

	QColor color = Qt::blue;
	QReadLocker l(&pJigDriver->m_Lock);
	for(auto iter= pJigDriver->m_MarkListTopLeft.crbegin();iter!= pJigDriver->m_MarkListTopLeft.crend();iter++)
	{
		const _Mark_Area& markArea = (*iter);
		
		if(markArea.iCellIndex == pJigDriver->m_iCurPosIdx){
			color = Qt::green;
		}else if(markArea.iLineIndex+1 == markArea.iSize){
			color = Qt::red;
		}else {
			color = Qt::blue;
		}
		
		CMPointd wt;
        CMPointd areaPt(dCenterX+ markArea.ptLeftTop.tX, dCenterY+ markArea.ptLeftTop.tY);
		pWorktableDriver->AxisToWt(CAM6X, areaPt, wt);
		QPointF pt = MPT_mmToQPT_mm(wt);
		painter.setPen(QPen(color,0));
		painter.setTransform(m_trans_LP2DP);

		painter.drawRect(pt.x(), pt.y()-markArea.dHeight, markArea.dWidth, markArea.dHeight);
	}

}

void CCtrlGraph_WorkTable_XY::DrawPowerCheck(QPainter& painter)
{
	CMWorkTableDriver* pWorktableDriver=GET_CARD(WORKTABLE_DRIVER,CMWorkTableDriver);
	Q_ASSERT(pWorktableDriver);
	CMPointd axis(559, 76);

    CProcess_LaserPowerCali* pPowerCali = GET_PROCESS(PROCESS_POWERCALI_D_NARROW,
                                    SM_MAIN,
                                    CProcess_LaserPowerCali);

    axis.tX = pPowerCali->m_Variants.get_VData(Var_Process_LaserPowerCali_XPos)->toDouble();
    axis.tY = pPowerCali->m_Variants.get_VData(Var_Process_LaserPowerCali_YPos)->toDouble();

	CMPointd wt;
	pWorktableDriver->AxisToWt(LASERPATH_D_NARROW, axis, wt);
	QPointF pt = MPT_mmToQPT_mm(wt);

	painter.setPen(QPen(Qt::blue,0));
	painter.resetTransform();
	int isize= 15;
	painter.setTransform(m_trans_LP2DP);
	//pt=m_trans_LP2DP.map(pt);
	/*QRectF rectf(pt.x()-isize/2.0, pt.y()-isize/2.0, isize, isize);
	painter.drawRect(rectf);
	QLine line1(pt.x()-isize,pt.y(),
	pt.x()+isize,pt.y());
	QLine line2(pt.x(),pt.y()-isize,
	pt.x(),pt.y()+isize);
	painter.setPen(Qt::black);
	painter.drawLine(line1);
	painter.drawLine(line2);*/
	painter.drawEllipse(pt.x()-isize/2.0, pt.y()-isize/2.0, isize, isize);
}

void CCtrlGraph_WorkTable_XY::DrawCell(QPainter& painter)
{
    CMProduct* pProduct=GET_CHDIRECT(PRODUCT,CMProduct);

    double dDiameter=pProduct->m_Variants.get_VData(Var_Product_Diameter_ID)
            ->toDouble();
    if(DEQUAL0(dDiameter))return;
    painter.setTransform(m_trans_LP2DP);
    double dFlatLength=pProduct->m_Variants.get_VData(Var_MProduct_FlatLength_ID)
            ->toDouble();
    double dRadius=fabs(dDiameter/2);
    double  dHalfLine=fabs(dFlatLength/2);
    if (dHalfLine>=dRadius)
    {
        dHalfLine=dRadius*0.999;
    }
    QPointF CenterPt;
    QPointF StartPt;
    QPointF EndPt;
    if (m_gSystem.m_iCurSideID==SIDE_A||
            m_gSystem.m_iCurSideID==SIDE_B)
    {
        CProductSide* pSide=GET_CHDIRECT(m_gSystem.m_iCurSideID,
                                         CProductSide);

        CenterPt.rx()=pSide->m_realCenter.tX;
        CenterPt.ry()=pSide->m_realCenter.tY;
    }
    else
    {
        CenterPt.rx()=pProduct->m_RealCenter.tX;
        CenterPt.ry()=pProduct->m_RealCenter.tY;
    }

    double dFlatAngle=0;
    int iLineDirect=pProduct->m_Variants.get_VData(Var_MProduct_FlatPos_ID)
            ->toUInt();
    if (m_gSystem.m_iCurSideID==SIDE_B)
    {
        if (iLineDirect==MYRIGHT) { dFlatAngle=270; }
        else if (iLineDirect==MYTOP) { dFlatAngle=0; }
        else if (iLineDirect==MYLEFT) { dFlatAngle=90; }
        else if (iLineDirect==MYBOTTOM) { dFlatAngle=180; }
    }
    else
    {
        if (iLineDirect==MYRIGHT) { dFlatAngle=0; }
        else if (iLineDirect==MYTOP) { dFlatAngle=90; }
        else if (iLineDirect==MYLEFT) { dFlatAngle=180; }
        else if (iLineDirect==MYBOTTOM) { dFlatAngle=270; }
    }
    double angleStep=DEG(asin(dHalfLine/dRadius));

    StartPt.rx()=cos(RAD(dFlatAngle-angleStep))*dRadius;
    StartPt.ry()=sin(RAD(dFlatAngle-angleStep))*dRadius;


    EndPt.rx()=cos(RAD(dFlatAngle+angleStep))*dRadius;
    EndPt.ry()=sin(RAD(dFlatAngle+angleStep))*dRadius;

    StartPt=StartPt+CenterPt;
    EndPt=EndPt+CenterPt;

    double dStartAngle=-dFlatAngle-angleStep;
    double dAngleSwap=-(360-angleStep*2);
    QRectF rectf(CenterPt.x()-dRadius,
                 CenterPt.y()-dRadius,
                 dRadius*2,
                 dRadius*2);

    QBrush bhnormal(QColor(0,0,255));
    QRectF rectView=get_rectClip();
    int penwidth=(m_rectWindow.m_width/rectView.width())*m_iPenWidth;
    painter.setPen(QPen(bhnormal,penwidth));
    painter.drawArc(rectf,dStartAngle*16,dAngleSwap*16);
    painter.drawLine(StartPt,EndPt);

	//根据角度划箭头
	//double x1=cos(RAD(m_dAngleArrow-6))*dRadius;
 //   double y1=sin(RAD(m_dAngleArrow-6))*dRadius;
	//double x2=cos(RAD(m_dAngleArrow+6))*dRadius;
 //   double y2=sin(RAD(m_dAngleArrow+6))*dRadius;
	//double x3=cos(RAD(m_dAngleArrow))*(dRadius-10);
 //   double y3=sin(RAD(m_dAngleArrow))*(dRadius-10);
	//painter.drawLine(QPoint(x1,y1),QPoint(x3,y3));
	//painter.drawLine(QPoint(x2,y2),QPoint(x3,y3));

	QPointF pt;
	if(m_gSystem.m_iCurSideID == SIDE_B){
		pt.setX(0);
		pt.setY(dRadius);
		DrawPoint(pt, CH_TRIANGLE, QString(""), Qt::blue, painter);
	}else{
		pt.setX(-dRadius);
		pt.setY(0);
		DrawPoint(pt, CH_TRIANGLE_CLIP, QString(""), Qt::blue, painter);
	}
	/*pt.setX(dRadius);
	pt.setY(0);
	DrawPoint(pt, CH_TRIANGLE, QString(""), Qt::blue, painter);*/

    DrawPoint( CenterPt,  CH_RECT, QString::fromUtf8(""),Qt::red, painter);
}

void CCtrlGraph_WorkTable_XY::DrawLine(QPainter &painter)
{
    painter.setTransform(m_trans_LP2DP);
    if (m_gSystem.m_iCurSideID==SIDE_A||
            m_gSystem.m_iCurSideID==SIDE_B)
    {
        CProductSide* pSide=GET_CHDIRECT(m_gSystem.m_iCurSideID,
                                         CProductSide);
        int iSizeParam=pSide->m_vCutParam.size();
        QRectF rectView=get_rectClip();
        int penwidth=(m_rectWindow.m_width/rectView.width())*m_iPenWidth;

        int iSize=pSide->m_CutLineVector.size();
        for(int i=0;i<iSize;i++)
        {
            QMutexLocker locker(&pSide->m_CutLineVector.mutex);
            CUTLINE* pLine=pSide->GetCutLine(i);
            if(pLine)
            {
                int iLayer=pLine->m_bHasCut-1;
                QBrush bhnormal(QColor(0,0,255));
                if (pLine->m_bSUB) {
                    bhnormal = Qt::darkBlue;
                }
                if(iLayer>=0&&iSizeParam)
                {
                    int iStepColor=255/iSizeParam*(iLayer+1);
                    //bhnormal=QColor(iStepColor,0,255-iStepColor);
					bhnormal=QColor(0,iStepColor,0);
                }
                if(m_gSystem.m_iCurLine==i)
                {
                    bhnormal=QColor(255,255,0);
                }
                painter.setPen(QPen(bhnormal,penwidth));

                CMPointd ptPositive = ConvertToLogicAixs(pLine->m_WPPair.ptPostive);
                CMPointd ptNegative = ConvertToLogicAixs(pLine->m_WPPair.ptNegative);
                QPointF ptStart=MPT_mmToQPT_mm(ptPositive);
                QPointF ptEnd=MPT_mmToQPT_mm(ptNegative);
                painter.drawLine(ptStart,ptEnd);
            }
        }

    }
}

void CCtrlGraph_WorkTable_XY::DrawUserPanel(QPainter& painter)
{
	CMWorkTable* pWTTable=GET_CHDIRECT(WORKTABLE,CMWorkTable);
	double dWidth= pWTTable->m_Variants.get_VData(Var_WorkTable_Width_ID)->toDouble();
	double dHeight= pWTTable->m_Variants.get_VData(Var_WorkTable_Height_ID)->toDouble();

	painter.setTransform(m_trans_LP2DP);

	QRectF rectf=QRectF(dWidth/2+50, -dHeight/2+50, 10, 100);
	painter.setPen(QPen(Qt::green,2));
	painter.fillRect(rectf, QBrush(Qt::blue));
	//painter.drawRect(rectf);
}

void CCtrlGraph_WorkTable_XY::DrawLevelPt(QPainter &painter)
{
    painter.setTransform(m_trans_LP2DP);
    if (m_gSystem.m_iCurSideID==SIDE_A||
            m_gSystem.m_iCurSideID==SIDE_B)
    {
        CProcess_Level* pLevel=GET_PROCESS(PROCESS_LEVELING,
                                           SM_MAIN,
                                           CProcess_Level);
        Q_ASSERT(pLevel);
        DrawPoint(MPT_mmToQPT_mm(ConvertToLogicAixs(pLevel->m_AlignPt1.Pt)),CH_RECT,QString::fromUtf8(""),Qt::red,painter);
        DrawPoint(MPT_mmToQPT_mm(ConvertToLogicAixs(pLevel->m_AlignPt2.Pt)),CH_RECT,QString::fromUtf8(""),Qt::red,painter);
        DrawPoint(MPT_mmToQPT_mm(ConvertToLogicAixs(pLevel->m_AlignPtMid.Pt)),CH_RECT,QString::fromUtf8(""),Qt::red,painter);
        DrawPoint(MPT_mmToQPT_mm(ConvertToLogicAixs(pLevel->m_AlignPtBase.Pt)),CH_RECT,QString::fromUtf8(""),Qt::red,painter);
    }

}

void CCtrlGraph_WorkTable_XY::DrawLocatePt(QPainter &painter)
{
    painter.setTransform(m_trans_LP2DP);
    if (m_gSystem.m_iCurSideID!=SIDE_A&&
            m_gSystem.m_iCurSideID!=SIDE_B)
    {
        CProcess_Locate* pLocate=GET_PROCESS(PROCESS_LOCATE,
                                             SM_MAIN,
                                             CProcess_Locate);
        Q_ASSERT(pLocate);

        int isize=pLocate->m_LocateVector.size();
        for(int i=0;i<isize;i++)
        {
            QMutexLocker locker(&pLocate->m_LocateVector.mutex);
            LOCATEPOS *pos=pLocate->m_LocateVector.mget(i);
            if(pos)
            {
                DrawPoint(MPT_mmToQPT_mm(ConvertToLogicAixs(pos->WPDP)),CH_RECT,
                          QString::fromUtf8(""),Qt::red,painter);
            }
        }
    }
}

void CCtrlGraph_WorkTable_XY::DrawMsg(QPainter &painter)
{

    CMProduct* pProduct=GET_CHDIRECT(PRODUCT,CMProduct);
    QString str=tr("Load");
    QString str1;
    double dDiameter=pProduct->m_Variants.get_VData(Var_Product_Diameter_ID)
            ->toDouble();
	QString sLine= "";
    CMPointd center=pProduct->m_RealCenter;
    if (m_gSystem.m_iCurSideID==SIDE_A||
            m_gSystem.m_iCurSideID==SIDE_B)
    {

        CProductSide* pSide=GET_CHDIRECT(m_gSystem.m_iCurSideID,
                                         CProductSide);
        str=m_gSystem.m_mapNameList[m_gSystem.m_iCurSideID];
        center=pSide->m_realCenter;
		int iLineSize = pSide->m_CutLineVector.size();
		if(iLineSize<=0){
			iLineSize = (int)(dDiameter / pSide->m_Variants.get_VData(Var_ProductSide_SideStep)->toDouble());
		}
		sLine = QString("Line: %1/%2\n").arg(m_gSystem.m_iCurLine+1).arg(iLineSize);
		
    }else{
		//LOAD面
		CProductSide* pSideA=GET_CHDIRECT(SIDE_A,
			CProductSide);
		CProductSide* pSideB=GET_CHDIRECT(SIDE_A,
			CProductSide);
		int iLineSizeA = (int)(dDiameter / pSideA->m_Variants.get_VData(Var_ProductSide_SideStep)->toDouble());
		int iLineSizeB = (int)(dDiameter / pSideA->m_Variants.get_VData(Var_ProductSide_SideStep)->toDouble());

		sLine = QString("Line: %1X%2\n").arg(iLineSizeA).arg(iLineSizeB);
	}
    str1=tr("%1.\nDiameter:%2mm.\n"
            "Diameter Real:%3mm.\n"
            "Center X:%4mm.\n"
            "Center Y:%5mm.\n")
            .arg(str)
            .arg(dDiameter,0,'f',3)
            .arg(pProduct->m_dRealDiameter,0,'f',3)
            .arg(center.tX,0,'f',3)
            .arg(center.tY,0,'f',3);
	str1 += sLine;

    DrawString(painter, str1);
}

void CCtrlGraph_WorkTable_XY::DrawButton(QPainter& painter)
{
    painter.resetTransform();
    QRectF rectFrame=rect();
    painter.setClipRect(rectFrame);
    QRect m_rectBtn=m_MoveBtn.m_rect;
    m_MoveBtn.m_rect.moveCenter(QPoint( rectFrame.width()-m_rectBtn.width()/2-2,
                              m_rectBtn.height()/2-2));
    m_MoveBtn.DrawButton(painter);
}

CMPointd CCtrlGraph_WorkTable_XY::ConvertToLogicAixs(CMPointd wt)
{
    //Y 轴取反再与X轴交换
    /*CMPointd wtTmp = wt;
    wtTmp.tX = -wt.tY;
    wtTmp.tY = wt.tX;*/
    //return wtTmp;
    return wt;
}

CMPointd CCtrlGraph_WorkTable_XY::ConvertToRealAxis(CMPointd wt)
{
    //先交换再取反
    /*CMPointd wtTmp = wt;
    wtTmp.tX = wt.tY;
    wtTmp.tY = wt.tX;
    wtTmp.tY *= -1;
    return wtTmp;*/
    return wt;
}

QString CCtrlGraph_WorkTable_XY::GetLaserPathName(int32_t iPathId)
{
    if (iPathId == LASERPATH_D_NARROW)
    {
        return QObject::tr("D");
    }
    else if (iPathId == LASERPATH_S_NARROW)
    {
        return QObject::tr("S");
    }
    else if (iPathId == LASERPATH_L_NARROW)
    {
        return QObject::tr("L");
    }
    else if (iPathId == LASERPATH_D_WIDE)
    {
        return QObject::tr("W");
    }
    else
    {
        return QObject::tr("E");
    }
}

