2012-04-13 18:51:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file zoom.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-11-23 15:16:50 +00:00
|
|
|
* Manage zoom, grid step, and auto crop.
|
2007-08-20 01:49:24 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <id.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <class_base_screen.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <kicad_device_context.h>
|
|
|
|
#include <hotkeys_basic.h>
|
2012-04-09 09:16:47 +00:00
|
|
|
#include <menus_helpers.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
AdjustScrollBars( aCenterPoint );
|
2010-01-15 10:02:47 +00:00
|
|
|
|
2011-07-09 06:41:32 +00:00
|
|
|
// Move the mouse cursor to the on grid graphic cursor position
|
2011-01-30 22:22:38 +00:00
|
|
|
if( aWarpPointer )
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-07-09 06:41:32 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
|
|
|
m_canvas->Update();
|
2012-04-23 21:56:26 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-04-23 21:56:26 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
|
|
|
|
2012-05-06 20:10:43 +00:00
|
|
|
// Set the best zoom and get center point.
|
|
|
|
|
2012-05-07 21:47:25 +00:00
|
|
|
// BestZoom() can compute an illegal zoom if the client window size
|
|
|
|
// is small, say because frame is not maximized. So use the clamping form
|
|
|
|
// of SetZoom():
|
|
|
|
double bestzoom = BestZoom();
|
2012-05-06 20:10:43 +00:00
|
|
|
screen->SetScalingFactor( bestzoom );
|
2011-07-09 06:41:32 +00:00
|
|
|
|
2011-03-01 18:45:21 +00:00
|
|
|
if( screen->m_FirstRedraw )
|
|
|
|
screen->SetCrossHairPosition( screen->GetScrollCenterPosition() );
|
2011-07-09 06:41:32 +00:00
|
|
|
|
2011-03-01 18:45:21 +00:00
|
|
|
RedrawScreen( screen->GetScrollCenterPosition(), aWarpPointer );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2007-10-29 10:05:07 +00:00
|
|
|
/** Compute the zoom factor and the new draw offset to draw the
|
2007-08-20 01:49:24 +00:00
|
|
|
* selected area (Rect) in full window screen
|
2008-04-03 19:38:24 +00:00
|
|
|
* @param Rect = selected area to show after zooming
|
2007-08-20 01:49:24 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
void EDA_DRAW_FRAME::Window_Zoom( EDA_RECT& Rect )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-04-23 21:56:26 +00:00
|
|
|
// Compute the best zoom
|
2007-08-20 01:49:24 +00:00
|
|
|
Rect.Normalize();
|
2012-04-23 21:56:26 +00:00
|
|
|
|
|
|
|
wxSize size = m_canvas->GetClientSize();
|
2010-01-12 13:15:13 +00:00
|
|
|
|
2008-04-03 19:38:24 +00:00
|
|
|
// Use ceil to at least show the full rect
|
2012-04-23 21:56:26 +00:00
|
|
|
double scalex = (double) Rect.GetSize().x / size.x;
|
|
|
|
double bestscale = (double) Rect.GetSize().y / size.y;
|
|
|
|
|
2009-02-02 12:12:18 +00:00
|
|
|
bestscale = MAX( bestscale, scalex );
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
GetScreen()->SetScalingFactor( bestscale );
|
2011-02-11 20:48:13 +00:00
|
|
|
RedrawScreen( Rect.Centre(), true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function OnZoom
|
2009-03-14 16:26:49 +00:00
|
|
|
* Called from any zoom event (toolbar , hotkey or popup )
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas == NULL )
|
2010-01-12 13:15:13 +00:00
|
|
|
return;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
int id = event.GetId();
|
2009-01-29 14:26:20 +00:00
|
|
|
bool zoom_at_cursor = false;
|
2011-02-05 02:21:11 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
2011-02-11 20:48:13 +00:00
|
|
|
wxPoint center = screen->GetScrollCenterPosition();
|
2007-08-20 01:49:24 +00:00
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
2008-02-17 21:19:13 +00:00
|
|
|
case ID_POPUP_ZOOM_IN:
|
2009-01-07 15:59:49 +00:00
|
|
|
zoom_at_cursor = true;
|
2012-05-06 20:10:43 +00:00
|
|
|
center = screen->GetCrossHairPosition();
|
2010-01-12 13:15:13 +00:00
|
|
|
|
|
|
|
// fall thru
|
2009-01-07 15:59:49 +00:00
|
|
|
case ID_ZOOM_IN:
|
2012-05-06 20:10:43 +00:00
|
|
|
if( screen->SetPreviousZoom() )
|
|
|
|
RedrawScreen( center, zoom_at_cursor );
|
2009-01-07 15:59:49 +00:00
|
|
|
break;
|
|
|
|
|
2008-02-17 21:19:13 +00:00
|
|
|
case ID_POPUP_ZOOM_OUT:
|
2009-01-07 15:59:49 +00:00
|
|
|
zoom_at_cursor = true;
|
2012-05-06 20:10:43 +00:00
|
|
|
center = screen->GetCrossHairPosition();
|
2010-01-12 13:15:13 +00:00
|
|
|
|
|
|
|
// fall thru
|
2009-01-07 15:59:49 +00:00
|
|
|
case ID_ZOOM_OUT:
|
2012-05-06 20:10:43 +00:00
|
|
|
if( screen->SetNextZoom() )
|
|
|
|
RedrawScreen( center, zoom_at_cursor );
|
2009-01-07 15:59:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_ZOOM_REDRAW:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2009-01-07 15:59:49 +00:00
|
|
|
break;
|
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
case ID_POPUP_ZOOM_CENTER:
|
2011-02-17 18:34:27 +00:00
|
|
|
center = screen->GetCrossHairPosition();
|
2011-02-11 20:48:13 +00:00
|
|
|
RedrawScreen( center, true );
|
2009-01-07 15:59:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_ZOOM_PAGE:
|
2009-12-19 19:24:49 +00:00
|
|
|
Zoom_Automatique( false );
|
2007-08-20 01:49:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_ZOOM_SELECT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_CANCEL:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:49:24 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
default:
|
2012-04-23 21:56:26 +00:00
|
|
|
unsigned i;
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
i = id - ID_POPUP_ZOOM_LEVEL_START;
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2012-05-06 20:10:43 +00:00
|
|
|
if( i >= screen->m_ZoomList.size() )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
2009-12-02 13:06:55 +00:00
|
|
|
wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
|
2009-05-21 17:42:42 +00:00
|
|
|
__TFILE__, __LINE__, i );
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-02-11 19:39:55 +00:00
|
|
|
if( screen->SetZoom( screen->m_ZoomList[i] ) )
|
2011-02-11 20:48:13 +00:00
|
|
|
RedrawScreen( center, true );
|
2007-08-20 01:49:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
UpdateStatusBar();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
/* add the zoom list menu the the MasterMenu.
|
|
|
|
* used in OnRightClick(wxMouseEvent& event)
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
int maxZoomIds;
|
|
|
|
int zoom;
|
|
|
|
wxString msg;
|
2012-04-23 21:56:26 +00:00
|
|
|
BASE_SCREEN* screen = m_canvas->GetScreen();
|
2010-02-14 18:14:33 +00:00
|
|
|
|
|
|
|
msg = AddHotkeyName( _( "Center" ), m_HotkeysZoomAndGridList, HK_ZOOM_CENTER );
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, ID_POPUP_ZOOM_CENTER, msg, KiBitmap( zoom_center_on_screen_xpm ) );
|
2010-02-14 18:14:33 +00:00
|
|
|
msg = AddHotkeyName( _( "Zoom in" ), m_HotkeysZoomAndGridList, HK_ZOOM_IN );
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, ID_POPUP_ZOOM_IN, msg, KiBitmap( zoom_in_xpm ) );
|
2010-02-14 18:14:33 +00:00
|
|
|
msg = AddHotkeyName( _( "Zoom out" ), m_HotkeysZoomAndGridList, HK_ZOOM_OUT );
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, ID_POPUP_ZOOM_OUT, msg, KiBitmap( zoom_out_xpm ) );
|
2010-02-14 18:14:33 +00:00
|
|
|
msg = AddHotkeyName( _( "Redraw view" ), m_HotkeysZoomAndGridList, HK_ZOOM_REDRAW );
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, ID_ZOOM_REDRAW, msg, KiBitmap( zoom_redraw_xpm ) );
|
2010-02-14 18:14:33 +00:00
|
|
|
msg = AddHotkeyName( _( "Zoom auto" ), m_HotkeysZoomAndGridList, HK_ZOOM_AUTO );
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, ID_ZOOM_PAGE, msg, KiBitmap( zoom_fit_in_page_xpm ) );
|
2007-08-20 01:49:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxMenu* zoom_choice = new wxMenu;
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, zoom_choice,
|
|
|
|
ID_POPUP_ZOOM_SELECT, _( "Zoom select" ),
|
|
|
|
KiBitmap( zoom_selection_xpm ) );
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2010-02-14 18:14:33 +00:00
|
|
|
zoom = screen->GetZoom();
|
2009-01-29 14:26:20 +00:00
|
|
|
maxZoomIds = ID_POPUP_ZOOM_LEVEL_END - ID_POPUP_ZOOM_LEVEL_START;
|
2012-05-06 20:10:43 +00:00
|
|
|
maxZoomIds = ( (size_t) maxZoomIds < screen->m_ZoomList.size() ) ?
|
|
|
|
maxZoomIds : screen->m_ZoomList.size();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2012-04-23 21:56:26 +00:00
|
|
|
// Populate zoom submenu.
|
2010-02-15 08:23:05 +00:00
|
|
|
for( int i = 0; i < maxZoomIds; i++ )
|
2007-08-20 01:49:24 +00:00
|
|
|
{
|
2011-07-05 12:46:14 +00:00
|
|
|
msg.Printf( wxT( "%g" ), screen->m_ZoomList[i] );
|
2009-01-31 10:05:16 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
zoom_choice->Append( ID_POPUP_ZOOM_LEVEL_START + i, _( "Zoom: " ) + msg,
|
|
|
|
wxEmptyString, wxITEM_CHECK );
|
2010-02-14 18:14:33 +00:00
|
|
|
if( zoom == screen->m_ZoomList[i] )
|
2009-01-29 14:26:20 +00:00
|
|
|
zoom_choice->Check( ID_POPUP_ZOOM_LEVEL_START + i, true );
|
2007-08-20 01:49:24 +00:00
|
|
|
}
|
|
|
|
|
2012-04-23 21:56:26 +00:00
|
|
|
// Create grid submenu as required.
|
2010-12-08 20:12:46 +00:00
|
|
|
if( screen->GetGridCount() )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
2010-02-15 08:23:05 +00:00
|
|
|
wxMenu* gridMenu = new wxMenu;
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, gridMenu, ID_POPUP_GRID_SELECT,
|
|
|
|
_( "Grid Select" ), KiBitmap( grid_select_xpm ) );
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2010-02-15 08:23:05 +00:00
|
|
|
GRID_TYPE tmp;
|
|
|
|
wxRealPoint grid = screen->GetGridSize();
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( size_t i = 0; i < screen->GetGridCount(); i++ )
|
2007-08-20 01:49:24 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
tmp = screen->GetGrid( i );
|
2012-04-13 18:51:24 +00:00
|
|
|
double gridValueInch = To_User_Unit( INCHES, tmp.m_Size.x );
|
|
|
|
double gridValue_mm = To_User_Unit( MILLIMETRES, tmp.m_Size.x );
|
2009-05-21 17:42:42 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
if( tmp.m_Id == ID_POPUP_GRID_USER )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
msg = _( "User Grid" );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
2008-12-05 16:03:05 +00:00
|
|
|
else
|
2007-08-20 01:49:24 +00:00
|
|
|
{
|
2010-07-12 14:07:09 +00:00
|
|
|
switch( g_UserUnit )
|
|
|
|
{
|
|
|
|
case INCHES:
|
2010-03-22 16:44:22 +00:00
|
|
|
msg.Printf( wxT( "%.1f mils, (%.3f mm)" ),
|
2010-02-15 08:23:05 +00:00
|
|
|
gridValueInch * 1000, gridValue_mm );
|
2010-07-12 14:07:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MILLIMETRES:
|
2010-03-22 16:44:22 +00:00
|
|
|
msg.Printf( wxT( "%.3f mm, (%.1f mils)" ),
|
2010-02-15 08:23:05 +00:00
|
|
|
gridValue_mm, gridValueInch * 1000 );
|
2010-07-12 14:07:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNSCALED_UNITS:
|
|
|
|
msg = wxT( "???" );
|
|
|
|
break;
|
|
|
|
}
|
2007-08-20 01:49:24 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
gridMenu->Append( tmp.m_Id, msg, wxEmptyString, true );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
if( grid == tmp.m_Size )
|
2009-01-29 14:26:20 +00:00
|
|
|
gridMenu->Check( tmp.m_Id, true );
|
2007-08-20 01:49:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MasterMenu->AppendSeparator();
|
2011-09-01 12:54:34 +00:00
|
|
|
AddMenuItem( MasterMenu, ID_POPUP_CANCEL, _( "Close" ), KiBitmap( cancel_xpm ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|