Commit 86e04b4f authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

more nanometer work, see comment at line 66 of pcbnew/classpcb.cpp

parent fda7bbff
Loading
Loading
Loading
Loading
+16 −47
Original line number Original line Diff line number Diff line
@@ -98,16 +98,8 @@ double BASE_SCREEN::GetScalingFactor() const


void BASE_SCREEN::SetScalingFactor( double aScale )
void BASE_SCREEN::SetScalingFactor( double aScale )
{
{
    double zoom = aScale;

    // Limit zoom to max and min allowed values:
    // Limit zoom to max and min allowed values:
    if( zoom < m_ZoomList[0] )
    double zoom = Clamp( GetMinAllowedZoom(), aScale, GetMaxAllowedZoom() );
        zoom = m_ZoomList[0];

    int idxmax = m_ZoomList.GetCount() - 1;

    if( zoom > m_ZoomList[idxmax] )
        zoom = m_ZoomList[idxmax];


    SetZoom( zoom );
    SetZoom( zoom );
}
}
@@ -115,38 +107,30 @@ void BASE_SCREEN::SetScalingFactor( double aScale )


bool BASE_SCREEN::SetFirstZoom()
bool BASE_SCREEN::SetFirstZoom()
{
{
    if( m_ZoomList.IsEmpty() )
    return SetZoom( GetMinAllowedZoom() );
    {
        if( m_Zoom != 1.0 )
        {
            SetZoom( 1.0 );
            return true;
        }
    }
    else if( m_Zoom != m_ZoomList[0] )
    {
        SetZoom( m_ZoomList[0] );
        return true;
}
}


    return false;
}



bool BASE_SCREEN::SetLastZoom()
double BASE_SCREEN::GetZoom() const
{
{
    return m_Zoom;
    return SetZoom( GetMaxAllowedZoom() );
}
}




bool BASE_SCREEN::SetZoom( double coeff )
bool BASE_SCREEN::SetZoom( double iu_per_du )
{
{
    if( coeff == m_Zoom )
    if( iu_per_du == m_Zoom )
        return false;
        return false;


    wxLogDebug( "Zoom:%16g  1/Zoom:%16g", coeff, 1/coeff );
    wxLogDebug( "Zoom:%16g  1/Zoom:%16g", iu_per_du, 1/iu_per_du );


    m_Zoom = coeff;
    if( iu_per_du < GetMinAllowedZoom() )
        return false;

    if( iu_per_du > GetMaxAllowedZoom() )
        return false;

    m_Zoom = iu_per_du;


    return true;
    return true;
}
}
@@ -154,10 +138,7 @@ bool BASE_SCREEN::SetZoom( double coeff )


bool BASE_SCREEN::SetNextZoom()
bool BASE_SCREEN::SetNextZoom()
{
{
    if( m_ZoomList.IsEmpty() || m_Zoom >= m_ZoomList.Last() )
    for( unsigned i=0; i < m_ZoomList.size();  ++i )
        return false;

    for( unsigned i = 0; i < m_ZoomList.GetCount(); i++ )
    {
    {
        if( m_Zoom < m_ZoomList[i] )
        if( m_Zoom < m_ZoomList[i] )
        {
        {
@@ -172,10 +153,7 @@ bool BASE_SCREEN::SetNextZoom()


bool BASE_SCREEN::SetPreviousZoom()
bool BASE_SCREEN::SetPreviousZoom()
{
{
    if( m_ZoomList.IsEmpty() || m_Zoom <= m_ZoomList[0] )
    for( unsigned i = m_ZoomList.size(); i != 0;  --i )
        return false;

    for( unsigned i = m_ZoomList.GetCount(); i != 0; i-- )
    {
    {
        if( m_Zoom > m_ZoomList[i - 1] )
        if( m_Zoom > m_ZoomList[i - 1] )
        {
        {
@@ -188,15 +166,6 @@ bool BASE_SCREEN::SetPreviousZoom()
}
}




bool BASE_SCREEN::SetLastZoom()
{
    if( m_ZoomList.IsEmpty() || m_Zoom == m_ZoomList.Last() )
        return false;

    return SetZoom( m_ZoomList.Last() );
}


void BASE_SCREEN::SetGridList( GRIDS& gridlist )
void BASE_SCREEN::SetGridList( GRIDS& gridlist )
{
{
    if( !m_grids.empty() )
    if( !m_grids.empty() )
+2 −1
Original line number Original line Diff line number Diff line
@@ -425,7 +425,8 @@ void PDF_PLOTTER::closePdfStream()
    workFile = 0;
    workFile = 0;
    ::wxRemoveFile( workFilename );
    ::wxRemoveFile( workFilename );


    wxMemoryOutputStream    memos;
    // NULL means memos owns the memory, but provide a hint on optimum size needed.
    wxMemoryOutputStream    memos( NULL, std::max( 2000, stream_len ) ) ;


    {
    {
        /* Somewhat standard parameters to compress in DEFLATE. The PDF spec is
        /* Somewhat standard parameters to compress in DEFLATE. The PDF spec is
+25 −22
Original line number Original line Diff line number Diff line
@@ -660,9 +660,13 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosi
    return true;
    return true;
}
}


#define SAFETY_MARGIN   100


#define VIRT_MIN    double(INT_MIN+100)
// see comment in classpcb.cpp near line 66
#define VIRT_MAX    double(INT_MAX-100)
static const double MAX_AXIS = 1518500251 - SAFETY_MARGIN;

#define VIRT_MIN    (-MAX_AXIS/2.0)     ///< min X or Y coordinate in virtual space
#define VIRT_MAX    (MAX_AXIS/2.0)      ///< max X or Y coordinate in virtual space




void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
@@ -707,8 +711,8 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
    DBOX    clientRectIU( xIU, yIU, clientSizeIU.x, clientSizeIU.y );
    DBOX    clientRectIU( xIU, yIU, clientSizeIU.x, clientSizeIU.y );
    wxPoint centerPositionIU;
    wxPoint centerPositionIU;


#if 1 || defined( USE_PCBNEW_NANOMETRES )
    // put "int" limits on the clientRect
    // put "int" limits on the clientRect
    {
    if( clientRectIU.GetLeft() < VIRT_MIN )
    if( clientRectIU.GetLeft() < VIRT_MIN )
        clientRectIU.MoveLeftTo( VIRT_MIN );
        clientRectIU.MoveLeftTo( VIRT_MIN );
    if( clientRectIU.GetTop() < VIRT_MIN )
    if( clientRectIU.GetTop() < VIRT_MIN )
@@ -717,10 +721,10 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
        clientRectIU.MoveRightTo( VIRT_MAX );
        clientRectIU.MoveRightTo( VIRT_MAX );
    if( clientRectIU.GetBottom() > VIRT_MAX )
    if( clientRectIU.GetBottom() > VIRT_MAX )
        clientRectIU.MoveBottomTo( VIRT_MAX );
        clientRectIU.MoveBottomTo( VIRT_MAX );
#endif


    centerPositionIU.x = KiROUND( clientRectIU.x + clientRectIU.width/2 );
    centerPositionIU.x = KiROUND( clientRectIU.x + clientRectIU.width/2 );
    centerPositionIU.y = KiROUND( clientRectIU.y + clientRectIU.height/2 );
    centerPositionIU.y = KiROUND( clientRectIU.y + clientRectIU.height/2 );
    }


    DSIZE   virtualSizeIU;
    DSIZE   virtualSizeIU;


@@ -784,19 +788,19 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
        }
        }
    }
    }


#if 1 || defined( USE_PCBNEW_NANOMETRES )
    // put "int" limits on the virtualSizeIU
    virtualSizeIU.x = std::min( virtualSizeIU.x, MAX_AXIS );
    virtualSizeIU.y = std::min( virtualSizeIU.y, MAX_AXIS );
#endif

    if( screen->m_Center )
    if( screen->m_Center )
    {
    {
        virtualSizeIU.x = std::min( virtualSizeIU.x, VIRT_MAX );
        virtualSizeIU.y = std::min( virtualSizeIU.y, VIRT_MAX );

        screen->m_DrawOrg.x = -KiROUND( virtualSizeIU.x / 2.0 );
        screen->m_DrawOrg.x = -KiROUND( virtualSizeIU.x / 2.0 );
        screen->m_DrawOrg.y = -KiROUND( virtualSizeIU.y / 2.0 );
        screen->m_DrawOrg.y = -KiROUND( virtualSizeIU.y / 2.0 );
    }
    }
    else
    else
    {
    {
        virtualSizeIU.x = std::min( virtualSizeIU.x, VIRT_MAX );
        virtualSizeIU.y = std::min( virtualSizeIU.y, VIRT_MAX );

        screen->m_DrawOrg.x = -KiROUND( ( virtualSizeIU.x - pageRectIU.width )  / 2.0 );
        screen->m_DrawOrg.x = -KiROUND( ( virtualSizeIU.x - pageRectIU.width )  / 2.0 );
        screen->m_DrawOrg.y = -KiROUND( ( virtualSizeIU.y - pageRectIU.height ) / 2.0 );
        screen->m_DrawOrg.y = -KiROUND( ( virtualSizeIU.y - pageRectIU.height ) / 2.0 );
    }
    }
@@ -868,4 +872,3 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
                             screen->m_ScrollbarPos.x,
                             screen->m_ScrollbarPos.x,
                             screen->m_ScrollbarPos.y, noRefresh );
                             screen->m_ScrollbarPos.y, noRefresh );
}
}
+13 −30
Original line number Original line Diff line number Diff line
@@ -59,7 +59,10 @@ void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
{
{
    BASE_SCREEN* screen = GetScreen();
    BASE_SCREEN* screen = GetScreen();


    screen->SetZoom( BestZoom() ); // Set the best zoom and get center point.
    // Set the best zoom and get center point.
    double bestzoom = BestZoom();

    screen->SetScalingFactor( bestzoom );


    if( screen->m_FirstRedraw )
    if( screen->m_FirstRedraw )
        screen->SetCrossHairPosition( screen->GetScrollCenterPosition() );
        screen->SetCrossHairPosition( screen->GetScrollCenterPosition() );
@@ -103,47 +106,27 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
    bool         zoom_at_cursor = false;
    bool         zoom_at_cursor = false;
    BASE_SCREEN* screen = GetScreen();
    BASE_SCREEN* screen = GetScreen();
    wxPoint      center = screen->GetScrollCenterPosition();
    wxPoint      center = screen->GetScrollCenterPosition();
    wxPoint      zoom_center = center;
    double	 zoom = screen->GetZoom();


    switch( id )
    switch( id )
    {
    {
    case ID_POPUP_ZOOM_IN:
    case ID_POPUP_ZOOM_IN:
        zoom_at_cursor = true;
        zoom_at_cursor = true;
        zoom_center = screen->GetCrossHairPosition();
        center = screen->GetCrossHairPosition();


    // fall thru
    // fall thru
    case ID_ZOOM_IN:
    case ID_ZOOM_IN:
        if( screen->SetPreviousZoom() ) {
        if( screen->SetPreviousZoom() )
	    if( zoom_at_cursor ) {
            RedrawScreen( center, zoom_at_cursor );
		double new_zoom = screen->GetZoom();
		double factor = new_zoom / zoom;
		wxPoint delta = center - zoom_center;
		center = wxPoint(
		    zoom_center.x + delta.x * factor,
		    zoom_center.y + delta.y * factor);
	    }
            RedrawScreen( center, false );
	}
        break;
        break;


    case ID_POPUP_ZOOM_OUT:
    case ID_POPUP_ZOOM_OUT:
        zoom_at_cursor = true;
        zoom_at_cursor = true;
        zoom_center = screen->GetCrossHairPosition();
        center = screen->GetCrossHairPosition();


    // fall thru
    // fall thru
    case ID_ZOOM_OUT:
    case ID_ZOOM_OUT:
        if( screen->SetNextZoom() ) {
        if( screen->SetNextZoom() )
	    if( zoom_at_cursor ) {
            RedrawScreen( center, zoom_at_cursor );
		double new_zoom = screen->GetZoom();
		double factor = new_zoom / zoom;
		wxPoint delta = center - zoom_center;
		center = wxPoint(
		    zoom_center.x + delta.x * factor,
		    zoom_center.y + delta.y * factor);
	    }
            RedrawScreen( center, false );
	}
        break;
        break;


    case ID_ZOOM_REDRAW:
    case ID_ZOOM_REDRAW:
@@ -171,7 +154,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )


        i = id - ID_POPUP_ZOOM_LEVEL_START;
        i = id - ID_POPUP_ZOOM_LEVEL_START;


        if( i >= screen->m_ZoomList.GetCount() )
        if( i >= screen->m_ZoomList.size() )
        {
        {
            wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
            wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
                        __TFILE__, __LINE__, i );
                        __TFILE__, __LINE__, i );
@@ -214,8 +197,8 @@ void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )


    zoom = screen->GetZoom();
    zoom = screen->GetZoom();
    maxZoomIds = ID_POPUP_ZOOM_LEVEL_END - ID_POPUP_ZOOM_LEVEL_START;
    maxZoomIds = ID_POPUP_ZOOM_LEVEL_END - ID_POPUP_ZOOM_LEVEL_START;
    maxZoomIds = ( (size_t) maxZoomIds < screen->m_ZoomList.GetCount() ) ?
    maxZoomIds = ( (size_t) maxZoomIds < screen->m_ZoomList.size() ) ?
                 maxZoomIds : screen->m_ZoomList.GetCount();
                 maxZoomIds : screen->m_ZoomList.size();


    // Populate zoom submenu.
    // Populate zoom submenu.
    for( int i = 0; i < maxZoomIds; i++ )
    for( int i = 0; i < maxZoomIds; i++ )
+1 −1
Original line number Original line Diff line number Diff line
@@ -106,7 +106,7 @@ SCH_SCREEN::SCH_SCREEN() :
    SetZoom( 32 );
    SetZoom( 32 );


    for( i = 0; i < SCHEMATIC_ZOOM_LIST_CNT; i++ )
    for( i = 0; i < SCHEMATIC_ZOOM_LIST_CNT; i++ )
        m_ZoomList.Add( SchematicZoomList[i] );
        m_ZoomList.push_back( SchematicZoomList[i] );


    for( i = 0; i < SCHEMATIC_GRID_LIST_CNT; i++ )
    for( i = 0; i < SCHEMATIC_GRID_LIST_CNT; i++ )
        AddGrid( SchematicGridList[i] );
        AddGrid( SchematicGridList[i] );
Loading