⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chartwnd.cpp

📁 PCI的一个测试程序,可以测试PCI driver和BOARD的功能.
💻 CPP
📖 第 1 页 / 共 2 页
字号:

        pDC->TextOut(rectFrame.left + i * m_AxresInfor[0].UnitValue / m_AxresInfor[0].Ratio - sizeTemp.cx / 2, rectFrame.bottom + 5, strLabel);
        
        if (i == m_AxresInfor[0].Layers)
        {
            break;
        }
        for(j=0; j<m_AxresInfor[0].SubLayers; ++j)
        {
            pDC->MoveTo(rectFrame.left + (i + j * 1.0 / m_AxresInfor[0].SubLayers) * m_AxresInfor[0].UnitValue / m_AxresInfor[0].Ratio, rectFrame.bottom + 2);
            pDC->LineTo(rectFrame.left + (i + j * 1.0 / m_AxresInfor[0].SubLayers) * m_AxresInfor[0].UnitValue / m_AxresInfor[0].Ratio, rectFrame.bottom - 2);

            pDC->MoveTo(rectFrame.left + (i + j * 1.0 / m_AxresInfor[0].SubLayers) * m_AxresInfor[0].UnitValue / m_AxresInfor[0].Ratio, rectFrame.top + 2);
            pDC->LineTo(rectFrame.left + (i + j * 1.0 / m_AxresInfor[0].SubLayers) * m_AxresInfor[0].UnitValue / m_AxresInfor[0].Ratio, rectFrame.top);
        }
    }
    pDC->SelectObject(pOldFont);

    // Y轴线
    m_AxresInfor[1].Ratio = (double)m_AxresInfor[1].Layers * m_AxresInfor[1].UnitValue * 1.0 / rectFrame.Height();
    // 使用字体YLabel
    pOldFont = pDC->SelectObject(&fontAxresLabel[1]);

    for(i=0; i<=m_AxresInfor[1].Layers; ++i)
    {
        // label and line
        pDC->MoveTo(rectFrame.left - 4, rectFrame.bottom - i * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio);
        pDC->LineTo(rectFrame.left + 4, rectFrame.bottom - i * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio);

        pDC->MoveTo(rectFrame.right - 4, rectFrame.bottom - i * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio);
        pDC->LineTo(rectFrame.right, rectFrame.bottom - i * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio);

        // label 
        CString     strLabel;
        if (m_AxresInfor[1].UnitValue > m_AxresInfor[1].Transformer && (m_AxresInfor[1].UnitValue % m_AxresInfor[1].Transformer == 0))
            strLabel.Format("%d", (int)((m_AxresInfor[1].BaseValue + i * m_AxresInfor[1].UnitValue) / (m_AxresInfor[1].Transformer)));
        else
            strLabel.Format("%.1f", (m_AxresInfor[1].BaseValue + i * m_AxresInfor[1].UnitValue * 1.0) / (m_AxresInfor[1].Transformer));

        pDC->TextOut(rectFrame.left - sizeYLabel.cx - 2, rectFrame.bottom - i * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio - sizeYLabel.cy / 2, strLabel);
        
        if (i == m_AxresInfor[1].Layers)
        {
            break;
        }
        for(j=0; j<m_AxresInfor[1].SubLayers; ++j)
        {
            pDC->MoveTo(rectFrame.left - 2, rectFrame.bottom - (i + j * 1.0 / m_AxresInfor[1].SubLayers) * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio);
            pDC->LineTo(rectFrame.left + 2, rectFrame.bottom - (i + j * 1.0 / m_AxresInfor[1].SubLayers) * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio);

            pDC->MoveTo(rectFrame.right - 2, rectFrame.bottom - (i + j * 1.0 / m_AxresInfor[1].SubLayers) * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio);
            pDC->LineTo(rectFrame.right,     rectFrame.bottom - (i + j * 1.0 / m_AxresInfor[1].SubLayers) * m_AxresInfor[1].UnitValue / m_AxresInfor[1].Ratio);
        }
    }
    pDC->SelectObject(pOldFont);
    pDC->SelectObject(pOldPen);


    // 显示每个曲线
    for(i=0; i<m_nChartCount; ++i)
    {
        CPen    penCurve(PS_SOLID, 1, m_pChartItem[i]->m_color);

        pOldPen = pDC->SelectObject(&penCurve);

        for(j=0; j<m_pChartItem[i]->m_count; ++j)
        {
            TCurvePoint *p = &(m_pChartItem[i]->m_pCurveData[j]);

            p->ViewX = rectFrame.left   + (p->x - m_AxresInfor[0].BaseValue) / m_AxresInfor[0].Ratio; 
            p->ViewY = rectFrame.bottom - (p->y - m_AxresInfor[1].BaseValue) / m_AxresInfor[1].Ratio; 

            if (j)
            {
                pDC->LineTo(p->ViewX, p->ViewY);
            }
            else
            {
                pDC->MoveTo(p->ViewX, p->ViewY);
            }

            // 画图形
            POINT   Point[5];
            Point[0].x = p->ViewX - 2;
            Point[0].y = p->ViewY - 2;
            Point[1].x = p->ViewX + 2;
            Point[1].y = p->ViewY - 2;
            Point[2].x = p->ViewX + 2;
            Point[2].y = p->ViewY + 2;
            Point[3].x = p->ViewX - 2;
            Point[3].y = p->ViewY + 2;
            Point[4].x = p->ViewX - 2;
            Point[4].y = p->ViewY - 2;

            pDC->Polyline(Point, 5);
        }

        pDC->SelectObject(pOldPen);
    }


    return TRUE;
    //return CWnd::OnEraseBkgnd(pDC);
}

// ChartPoint: x is transfer size in byte, y is transfer rate in Bps
void    CChartWnd::AddChart(COLORREF color, const char *name, int count, TPOINT *pChartData)
{
    if (count <= 0)
        return;

    if (m_nChartCount >= MAX_CHART_COUNT)
        return;

    int     i = m_nChartCount++;

    m_pChartItem[i] = new CChartItem();

    m_pChartItem[i]->SetId(color, name);
    m_pChartItem[i]->SetChartData(count, pChartData);

}

void    CChartWnd::CalcChart()
{
    // 输入数据:
    //     显示区域位置
    //     各线数据(x、y)
    // 输出数据的定义:
    //     Title显示位置
    //     X、YAresName显示位置
    //     X、YAres起始、终止位置
    //     X、YAres刻度显示(如何表达)
    //     各线、各点的位置(包含数据以及显示点位置)
    int     i;
    int     j;

    int     MinX = 0x7fffffff;
    int     MinY = 0x7fffffff;
    int     MaxX = 0;
    int     MaxY = 0;

    for(i=0; i<m_nChartCount; ++i)
    {
        for(j=0; j<m_pChartItem[i]->m_count; ++j)
        {
            if (m_pChartItem[i]->m_pCurveData[j].x < MinX)
                MinX = m_pChartItem[i]->m_pCurveData[j].x;
            if (m_pChartItem[i]->m_pCurveData[j].x > MaxX)
                MaxX = m_pChartItem[i]->m_pCurveData[j].x;
            if (m_pChartItem[i]->m_pCurveData[j].y < MinY)
                MinY = m_pChartItem[i]->m_pCurveData[j].y;
            if (m_pChartItem[i]->m_pCurveData[j].y > MaxY)
                MaxY = m_pChartItem[i]->m_pCurveData[j].y;
        }
    }

    if (m_nChartCount == 0)
    {
        MinX = 0;
        MinY = 0;
        MaxX = 10 * 1024;
        MaxY = 10 * 1000 * 1000;
    }


    ULONG   XDegree[] = {1024, 2*1024, 5*1024, 10*1024, 20*1024, 50*1024, 100*1024, 200*1024, 500*1024, 1000*1024};
    ULONG   YDegree[] = {105*1000, 210*1000, 512*1000, 1*1000*1000, 2*1000*1000, 5*1000*1000, 10*1000*1000, 20*1000*1000, 50*1000*1000, 
		100*1000*1000, 200*1000*1000, 300*1000*1000, 400*1000*1000, 500*1000*1000,
		600*1000*1000, 700*1000*1000, 800*1000*1000, 900*1000*1000, 1000*1000*1000};

    int     dx = MaxX - MinX;
    int     dy = MaxY - MinY;

    // 计算X轴
    for(i=0; i<sizeof(XDegree)/sizeof(XDegree[0]); ++i)
    {
        if (dx < m_AxresInfor[0].Layers * XDegree[i])
        {
            if (MaxX > (MinX / XDegree[i] + m_AxresInfor[0].Layers) * XDegree[i])
                continue;

            break;
        }
    }

    if (i >= sizeof(XDegree)/sizeof(XDegree[0]))
        i = sizeof(XDegree)/sizeof(XDegree[0]) - 1;

    m_AxresInfor[0].UnitValue = XDegree[i];
    m_AxresInfor[0].BaseValue = MinX / m_AxresInfor[0].UnitValue * m_AxresInfor[0].UnitValue;


    // 计算Y轴
    for(i=0; i<sizeof(YDegree)/sizeof(YDegree[0]); ++i)
    {
        if (dy < m_AxresInfor[1].Layers * YDegree[i])
        {
            if (MaxY > (MinY / YDegree[i] + m_AxresInfor[1].Layers) * YDegree[i])
                continue;

            break;
        }
    }

    if (i >= sizeof(YDegree)/sizeof(YDegree[0]))
        i = sizeof(YDegree)/sizeof(YDegree[0]) - 1;

    m_AxresInfor[1].UnitValue = YDegree[i];
    m_AxresInfor[1].BaseValue = MinY / m_AxresInfor[1].UnitValue * m_AxresInfor[1].UnitValue;
    


}

void    CChartWnd::SetTitle(LPCTSTR p_szTitle)
{
    m_strTitle = p_szTitle;
}

void    CChartWnd::SetAxresName(LPCTSTR p_szXAxresName, LPCTSTR p_szYAxresName)
{
    m_strAxresName[0] = p_szXAxresName;
    m_strAxresName[1] = p_szYAxresName;
}

CString CChartWnd::GetTitle()
{
    return m_strTitle;
}

CString CChartWnd::GetAxresName_X()
{
    return m_strAxresName[0];
}

CString CChartWnd::GetAxresName_Y()
{
    return m_strAxresName[1];
}

void    CChartWnd::SetLayers(int XLayer, int YLayer, int XSubLayer, int YSubLayer)
{
    m_AxresInfor[0].Layers    = XLayer;
    m_AxresInfor[0].SubLayers = XSubLayer;
    m_AxresInfor[1].Layers    = YLayer;
    m_AxresInfor[1].SubLayers = YSubLayer;
}

void    CChartWnd::ClearChart()
{
    for(int i=0; i<m_nChartCount; ++i)
    {
        if (m_pChartItem[i])
        {
            delete m_pChartItem[i];
            m_pChartItem[i] = NULL;
        }
    }

    m_nChartCount = 0;
}

int CChartWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  在此添加您专用的创建代码
    m_wndTips.Create(NULL, NULL, WS_CHILD, CRect(0, 0, 1, 1), this, 0);

    return 0;
}

const int TIP_POS = 5;

void CChartWnd::OnMouseMove(UINT nFlags, CPoint point)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    CString     strTips;

    m_wndTips.ClearTips();

    // collect tips
    for(int i=0; i<m_nChartCount; ++i)
    {
        for (int j=0; j<m_pChartItem[i]->m_count; ++j)
        {
            if (m_pChartItem[i]->m_pCurveData[j].ViewX - point.x > -TIP_POS
                && m_pChartItem[i]->m_pCurveData[j].ViewX - point.x < TIP_POS
                && m_pChartItem[i]->m_pCurveData[j].ViewY - point.y > -TIP_POS
                && m_pChartItem[i]->m_pCurveData[j].ViewY - point.y < TIP_POS)
            {
                CString strTemp;
                
                strTemp = m_pChartItem[i]->m_name;
                strTemp += ":";

                m_wndTips.AddTips(strTemp);

                strTemp.Format("Size    %.2f %s", 
                    m_pChartItem[i]->m_pCurveData[j].DispX, GetUnitStr(m_pChartItem[i]->m_pCurveData[j].UnitX, 1));

                m_wndTips.AddTips(strTemp);

                strTemp.Format("Bps     %.2f %s", 
                    m_pChartItem[i]->m_pCurveData[j].DispY, GetUnitStr(m_pChartItem[i]->m_pCurveData[j].UnitY));

                m_wndTips.AddTips(strTemp);
            }
        }
    }

    m_wndTips.ShowTips(point.x, point.y);

    CWnd::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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