示例#1
0
void mpMarker::Plot(wxDC & dc, mpWindow & w) {
wxCoord     cx, cy, tw, th;
wxColour    cc;
wxString    ss;

// setup

    dc.SetPen(m_pen);
    dc.SetFont(m_font);

// part of setup is setting the text color

    cc = m_pen.GetColour();
    dc.SetTextForeground(cc);

// what to draw

    ss = GetName();

// where to draw

    dc.GetTextExtent(ss, &tw, &th);
    cx = (wxCoord) ((mX - w.GetPosX()) * w.GetScaleX()) - (tw / 2);
    cy = (wxCoord) ((w.GetPosY() - mY) * w.GetScaleY()) - (th / 2);

// do it

    dc.DrawText( ss, cx, cy);
}
示例#2
0
void c_mtf_layer::Plot(wxDC & dc, mpWindow & w)
{
    if (m_visible)
    {
        dc.SetPen(m_pen); 

        wxCoord start_px = m_drawOutsideMargins? 0 : w.GetMarginLeft();
        wxCoord end_px = m_drawOutsideMargins? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
        wxCoord min_y_px = m_drawOutsideMargins ? 0 : w.GetMarginTop();
        wxCoord max_y_px = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();

        wxCoord y0 = w.y2p(0); 
        wxCoord ix = 0;
        wxCoord iy = w.y2p(GetY(w.p2x(0)));
        
        for (wxCoord i = start_px + 1; i < end_px; ++i) 
        {
            wxCoord y = w.y2p(GetY(w.p2x(i)));
            if (m_drawOutsideMargins || (iy >= min_y_px) && (iy <= max_y_px))
                dc.DrawLine(i-1, iy, i, y);
            
            iy = y; 
        }

        if (!m_name.IsEmpty() && m_showName)
        {
            dc.SetFont(m_font);

            wxCoord tx, ty;
            dc.GetTextExtent(m_name, &tx, &ty);
			
            if ((m_flags & mpALIGNMASK) == mpALIGN_RIGHT) 
                tx = (w.GetScrX() - tx) - w.GetMarginRight() - 8; 
            else if ((m_flags & mpALIGNMASK) == mpALIGN_CENTER) 
                tx = ((w.GetScrX() - w.GetMarginRight() - w.GetMarginLeft() - tx) / 2) + w.GetMarginLeft(); 
            else 
                tx = w.GetMarginLeft() + 8;
            dc.DrawText( m_name, tx, w.y2p(GetY(w.p2x(tx))) ); // (wxCoord) ((w.GetPosY() - GetY( (double)tx / w.GetScaleX() + w.GetPosX())) * w.GetScaleY()) );
        }
    }
}
void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow )
{
    if( !m_window )
        m_window = &aWindow;

    if( !m_visible )
        return;

    const auto& dataX = m_trace->GetDataX();
    const auto& dataY = m_trace->GetDataY();

    if( dataX.size() <= 1 )
        return;

    if( m_updateRequired )
    {
        m_coords.x = m_trace->s2x( aWindow.p2x( m_dim.x ) );

        // Find the closest point coordinates
        auto maxXIt = std::upper_bound( dataX.begin(), dataX.end(), m_coords.x );
        int maxIdx = maxXIt - dataX.begin();
        int minIdx = maxIdx - 1;

        // Out of bounds checks
        if( minIdx < 0 )
        {
            minIdx = 0;
            maxIdx = 1;
            m_coords.x = dataX[0];
        }
        else if( maxIdx >= (int) dataX.size() )
        {
            maxIdx = dataX.size() - 1;
            minIdx = maxIdx - 1;
            m_coords.x = dataX[maxIdx];
        }

        const double leftX = dataX[minIdx];
        const double rightX = dataX[maxIdx];
        const double leftY = dataY[minIdx];
        const double rightY = dataY[maxIdx];

        // Linear interpolation
        m_coords.y = leftY + ( rightY - leftY ) / ( rightX - leftX ) * ( m_coords.x - leftX );
        m_updateRequired = false;

        // Notify the parent window about the changes
        wxQueueEvent( aWindow.GetParent(), new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
    }
    else
    {
        m_updateRef = true;
    }

    if( m_updateRef )
    {
        UpdateReference();
        m_updateRef = false;
    }

    // Line length in horizontal and vertical dimensions
    const wxPoint cursorPos( aWindow.x2p( m_trace->x2s( m_coords.x ) ),
                             aWindow.y2p( m_trace->y2s( m_coords.y ) ) );

    wxCoord leftPx   = m_drawOutsideMargins ? 0 : aWindow.GetMarginLeft();
    wxCoord rightPx  = m_drawOutsideMargins ? aWindow.GetScrX() : aWindow.GetScrX() - aWindow.GetMarginRight();
    wxCoord topPx    = m_drawOutsideMargins ? 0 : aWindow.GetMarginTop();
    wxCoord bottomPx = m_drawOutsideMargins ? aWindow.GetScrY() : aWindow.GetScrY() - aWindow.GetMarginBottom();

    aDC.SetPen( wxPen( *wxWHITE, 1, m_continuous ? wxPENSTYLE_SOLID : wxPENSTYLE_LONG_DASH ) );

    if( topPx < cursorPos.y && cursorPos.y < bottomPx )
        aDC.DrawLine( leftPx, cursorPos.y, rightPx, cursorPos.y );

    if( leftPx < cursorPos.x && cursorPos.x < rightPx )
        aDC.DrawLine( cursorPos.x, topPx, cursorPos.x, bottomPx );
}