Commit 44e474c2 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Drawing, pcbnew, and other minor fixes.

* Use wxDC to calculate screen center position.
* Minor grid drawing optimization.
* Remove an unnecessary use of global variable ActiveScreen.
* Doxygen warning fixes.
parent d657b430
Loading
Loading
Loading
Loading
+23 −8
Original line number Original line Diff line number Diff line
@@ -146,6 +146,7 @@ void EDA_DRAW_FRAME::EraseMsgBox()
void EDA_DRAW_FRAME::OnActivate( wxActivateEvent& event )
void EDA_DRAW_FRAME::OnActivate( wxActivateEvent& event )
{
{
    m_FrameIsActive = event.GetActive();
    m_FrameIsActive = event.GetActive();

    if( DrawPanel )
    if( DrawPanel )
        DrawPanel->m_CanStartBlock = -1;
        DrawPanel->m_CanStartBlock = -1;


@@ -157,6 +158,7 @@ void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event )
{
{
    if( DrawPanel )
    if( DrawPanel )
        DrawPanel->m_CanStartBlock = -1;
        DrawPanel->m_CanStartBlock = -1;

    event.Skip();
    event.Skip();
}
}


@@ -197,6 +199,7 @@ void EDA_DRAW_FRAME::PrintPage( wxDC* aDC,int aPrintMask,
    wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error"));
    wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error"));
}
}



// Virtual function
// Virtual function
void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
{
{
@@ -253,7 +256,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
     * index returned by GetSelection().
     * index returned by GetSelection().
     */
     */
    m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000;
    m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000;
    screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
    screen->m_Curseur = DrawPanel->GetScreenCenterLogicalPosition();
    screen->SetGrid( id );
    screen->SetGrid( id );
    Refresh();
    Refresh();
}
}
@@ -285,9 +288,11 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
    {
    {
        id--;
        id--;
        int selectedZoom = GetBaseScreen()->m_ZoomList[id];
        int selectedZoom = GetBaseScreen()->m_ZoomList[id];

        if( GetBaseScreen()->GetZoom() == selectedZoom )
        if( GetBaseScreen()->GetZoom() == selectedZoom )
            return;
            return;
        GetBaseScreen()->m_Curseur = DrawPanel->GetScreenCenterRealPosition();

        GetBaseScreen()->m_Curseur = DrawPanel->GetScreenCenterLogicalPosition();
        GetBaseScreen()->SetZoom( selectedZoom );
        GetBaseScreen()->SetZoom( selectedZoom );
        RedrawScreen( false );
        RedrawScreen( false );
    }
    }
@@ -382,12 +387,14 @@ void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
{
{
    // Keep default cursor in toolbars
    // Keep default cursor in toolbars
    SetCursor( wxNullCursor );
    SetCursor( wxNullCursor );

    // Change Cursor in DrawPanel only
    // Change Cursor in DrawPanel only
    if( DrawPanel )
    if( DrawPanel )
    {
    {
        DrawPanel->m_PanelDefaultCursor = aCursor;
        DrawPanel->m_PanelDefaultCursor = aCursor;
        DrawPanel->SetCursor( aCursor );
        DrawPanel->SetCursor( aCursor );
    }
    }

    DisplayToolMsg( aToolMsg );
    DisplayToolMsg( aToolMsg );


    if( aId < 0 )
    if( aId < 0 )
@@ -428,6 +435,7 @@ void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
        m_VToolBar->ToggleTool( ID_NO_SELECT_BUTT, TRUE );
        m_VToolBar->ToggleTool( ID_NO_SELECT_BUTT, TRUE );


    m_ID_current_state = aId;
    m_ID_current_state = aId;

    if( m_VToolBar )
    if( m_VToolBar )
        m_VToolBar->Refresh( );
        m_VToolBar->Refresh( );
}
}
@@ -527,6 +535,7 @@ void EDA_DRAW_FRAME::AdjustScrollBars()


    if( posX < 0 )
    if( posX < 0 )
        posX = 0;
        posX = 0;

    if( posY < 0 )
    if( posY < 0 )
        posY = 0;
        posY = 0;


@@ -562,6 +571,7 @@ void EDA_DRAW_FRAME::SetLanguage( wxCommandEvent& event )
    EDA_BASE_FRAME::SetLanguage( event );
    EDA_BASE_FRAME::SetLanguage( event );
}
}



/**
/**
 * Round to the nearest precision.
 * Round to the nearest precision.
 *
 *
@@ -575,6 +585,7 @@ double RoundTo0( double x, double precision )
    assert( precision != 0 );
    assert( precision != 0 );


    long long ix = wxRound( x * precision );
    long long ix = wxRound( x * precision );

    if ( x < 0.0 )
    if ( x < 0.0 )
        NEGATE( ix );
        NEGATE( ix );


@@ -613,15 +624,14 @@ void EDA_DRAW_FRAME::UpdateStatusBar()
    if ( (screen->GetZoom() % screen->m_ZoomScalar) == 0 )
    if ( (screen->GetZoom() % screen->m_ZoomScalar) == 0 )
        Line.Printf( wxT( "Z %d" ), screen->GetZoom() / screen->m_ZoomScalar );
        Line.Printf( wxT( "Z %d" ), screen->GetZoom() / screen->m_ZoomScalar );
    else
    else
        Line.Printf( wxT( "Z %.1f" ),
        Line.Printf( wxT( "Z %.1f" ), (float)screen->GetZoom() / screen->m_ZoomScalar );
                     (float)screen->GetZoom() / screen->m_ZoomScalar );

    SetStatusText( Line, 1 );
    SetStatusText( Line, 1 );


    /* Display absolute coordinates:  */
    /* Display absolute coordinates:  */
    double dXpos = To_User_Unit( g_UserUnit, screen->m_Curseur.x,
    double dXpos = To_User_Unit( g_UserUnit, screen->m_Curseur.x, m_InternalUnits );
                                 m_InternalUnits );
    double dYpos = To_User_Unit( g_UserUnit, screen->m_Curseur.y, m_InternalUnits );
    double dYpos = To_User_Unit( g_UserUnit, screen->m_Curseur.y,

                                 m_InternalUnits );
    /*
    /*
     * Converting from inches to mm can give some coordinates due to
     * Converting from inches to mm can give some coordinates due to
     * float point precision rounding errors, like 1.999 or 2.001 so
     * float point precision rounding errors, like 1.999 or 2.001 so
@@ -678,6 +688,7 @@ void EDA_DRAW_FRAME::UpdateStatusBar()
    dy = screen->m_Curseur.y - screen->m_O_Curseur.y;
    dy = screen->m_Curseur.y - screen->m_O_Curseur.y;
    dXpos = To_User_Unit( g_UserUnit, dx, m_InternalUnits );
    dXpos = To_User_Unit( g_UserUnit, dx, m_InternalUnits );
    dYpos = To_User_Unit( g_UserUnit, dy, m_InternalUnits );
    dYpos = To_User_Unit( g_UserUnit, dy, m_InternalUnits );

    if( g_UserUnit == MILLIMETRES )
    if( g_UserUnit == MILLIMETRES )
    {
    {
        dXpos = RoundTo0( dXpos, (double) ( m_InternalUnits / 10 ) );
        dXpos = RoundTo0( dXpos, (double) ( m_InternalUnits / 10 ) );
@@ -704,11 +715,15 @@ void EDA_DRAW_FRAME::LoadSettings()
    EDA_BASE_FRAME::LoadSettings();
    EDA_BASE_FRAME::LoadSettings();
    cfg->Read( m_FrameName + CursorShapeEntryKeyword, &m_CursorShape, ( long )0 );
    cfg->Read( m_FrameName + CursorShapeEntryKeyword, &m_CursorShape, ( long )0 );
    bool btmp;
    bool btmp;

    if ( cfg->Read( m_FrameName + ShowGridEntryKeyword, &btmp ) )
    if ( cfg->Read( m_FrameName + ShowGridEntryKeyword, &btmp ) )
        SetGridVisibility( btmp);
        SetGridVisibility( btmp);

    int itmp;
    int itmp;

    if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) )
    if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) )
        SetGridColor(itmp);
        SetGridColor(itmp);

    cfg->Read( m_FrameName + LastGridSizeId, &m_LastGridSizeId, 0L );
    cfg->Read( m_FrameName + LastGridSizeId, &m_LastGridSizeId, 0L );
}
}


+13 −18
Original line number Original line Diff line number Diff line
@@ -272,26 +272,12 @@ wxPoint EDA_DRAW_PANEL::CursorScreenPosition()
}
}




/**
wxPoint EDA_DRAW_PANEL::GetScreenCenterLogicalPosition()
 * Function GetScreenCenterRealPosition
 * @return position (in internal units) of the current area center showed
 *         on screen
 */
wxPoint EDA_DRAW_PANEL::GetScreenCenterRealPosition( void )
{
{
    int x, y, ppuX, ppuY;
    wxSize size = GetClientSize() / 2;
    wxPoint pos;
    INSTALL_UNBUFFERED_DC( dc, this );
    double  scalar = GetScreen()->GetScalingFactor();

    GetViewStart( &x, &y );
    GetScrollPixelsPerUnit( &ppuX, &ppuY );
    x *= ppuX;
    y *= ppuY;
    pos.x = wxRound( ( (double) GetClientSize().x / 2.0 + (double) x ) / scalar );
    pos.y = wxRound( ( (double) GetClientSize().y / 2.0 + (double) y ) / scalar );
    pos += GetScreen()->m_DrawOrg;


    return pos;
    return wxPoint( dc.DeviceToLogicalX( size.x ), dc.DeviceToLogicalY( size.y ) );
}
}




@@ -650,6 +636,15 @@ void EDA_DRAW_PANEL::DrawGrid( wxDC* DC )


    m_Parent->PutOnGrid( &org, &gridSize );
    m_Parent->PutOnGrid( &org, &gridSize );


    // Setting the nearest grid position can select grid points outside the clip box.
    // Incrementing the start point by one grid step should prevent drawing grid points
    // outside the clip box.
    if( org.x < m_ClipBox.GetX() )
        org.x += wxRound( gridSize.x );

    if( org.y < m_ClipBox.GetY() )
        org.y += wxRound( gridSize.y );

#if ( defined( __WXMAC__ ) || defined( __WXGTK__ ) || 1 )
#if ( defined( __WXMAC__ ) || defined( __WXGTK__ ) || 1 )
    // Use a pixel based draw to display grid.  There are a lot of calls, so the cost is high
    // Use a pixel based draw to display grid.  There are a lot of calls, so the cost is high
    // and grid is slowly drawn on some platforms.  Please note that this should always be
    // and grid is slowly drawn on some platforms.  Please note that this should always be
+1 −1
Original line number Original line Diff line number Diff line
@@ -93,7 +93,7 @@ static wxDC* s_DC_lastDC = NULL;
 *
 *
 * Please note that this is only accurate for lines that are one pixel wide.
 * Please note that this is only accurate for lines that are one pixel wide.
 *
 *
 * @param aRect - The rectangle to test.
 * @param aClipBox - The rectangle to test.
 * @param x1 - X coordinate of one end of a line.
 * @param x1 - X coordinate of one end of a line.
 * @param y1 - Y coordinate of one end of a line.
 * @param y1 - Y coordinate of one end of a line.
 * @param x2 - X coordinate of the other end of a line.
 * @param x2 - X coordinate of the other end of a line.
+2 −2
Original line number Original line Diff line number Diff line
@@ -125,7 +125,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )


    case ID_ZOOM_IN:
    case ID_ZOOM_IN:
        if( id == ID_ZOOM_IN )
        if( id == ID_ZOOM_IN )
            screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
            screen->m_Curseur = DrawPanel->GetScreenCenterLogicalPosition();
        if( screen->SetPreviousZoom() )
        if( screen->SetPreviousZoom() )
            RedrawScreen( zoom_at_cursor );
            RedrawScreen( zoom_at_cursor );
        break;
        break;
@@ -137,7 +137,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )


    case ID_ZOOM_OUT:
    case ID_ZOOM_OUT:
        if( id == ID_ZOOM_OUT )
        if( id == ID_ZOOM_OUT )
            screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
            screen->m_Curseur = DrawPanel->GetScreenCenterLogicalPosition();
        if( screen->SetNextZoom() )
        if( screen->SetNextZoom() )
            RedrawScreen( zoom_at_cursor );
            RedrawScreen( zoom_at_cursor );
        break;
        break;
+9 −4
Original line number Original line Diff line number Diff line
@@ -154,7 +154,7 @@ public:
     * converts \a aRect from device to drawing (logical) coordinates.
     * converts \a aRect from device to drawing (logical) coordinates.
     * <p>
     * <p>
     * \a aRect must be in scrolled device units.
     * \a aRect must be in scrolled device units.
     * <\p>
     * </p>
     * @param aRect The rectangle to convert.
     * @param aRect The rectangle to convert.
     * @param aDC The device context used for the conversion.
     * @param aDC The device context used for the conversion.
     * @return A rectangle converted to drawing units.
     * @return A rectangle converted to drawing units.
@@ -191,12 +191,12 @@ public:
     * area.  The clip box is used when drawing to determine which objects are not visible
     * area.  The clip box is used when drawing to determine which objects are not visible
     * and do not need to be drawn.
     * and do not need to be drawn.
     * </p>
     * </p>
     * @param aDc The device context use for drawing with the correct scale and
     * @param aDC The device context use for drawing with the correct scale and
     *            offsets already configured.  See DoPrepareDC().
     *            offsets already configured.  See DoPrepareDC().
     * @param aRect The clip rectangle in device units or NULL for the entire visible area
     * @param aRect The clip rectangle in device units or NULL for the entire visible area
     *              of the screen.
     *              of the screen.
     */
     */
    void         SetClipBox( wxDC& dc, const wxRect* aRect = NULL );
    void         SetClipBox( wxDC& aDC, const wxRect* aRect = NULL );


    void         ReDraw( wxDC* DC, bool erasebg = TRUE );
    void         ReDraw( wxDC* DC, bool erasebg = TRUE );


@@ -222,7 +222,12 @@ public:
     */
     */
    void         RefreshDrawingRect( const EDA_Rect& aRect, bool aEraseBackground = true );
    void         RefreshDrawingRect( const EDA_Rect& aRect, bool aEraseBackground = true );


    wxPoint      GetScreenCenterRealPosition( void );
    /**
     * Function GetScreenCenterLogicalPosition
     * @return The current screen center position in logical (drawing) units.
     */
    wxPoint      GetScreenCenterLogicalPosition();

    void         MouseToCursorSchema();
    void         MouseToCursorSchema();
    void         MouseTo( const wxPoint& Mouse );
    void         MouseTo( const wxPoint& Mouse );


Loading