2007-08-20 01:49:24 +00:00
|
|
|
/************/
|
|
|
|
/* 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
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "macros.h"
|
|
|
|
#include "bitmaps.h"
|
|
|
|
#include "id.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "class_base_screen.h"
|
|
|
|
#include "wxstruct.h"
|
2010-01-17 16:22:31 +00:00
|
|
|
#include "kicad_device_context.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-29 10:05:07 +00:00
|
|
|
/** Compute draw offset (scroll bars and draw parameters)
|
|
|
|
* in order to have the current graphic cursor position at the screen center
|
|
|
|
* @param ToMouse if TRUE, the mouse cursor is moved
|
|
|
|
* to the graphic cursor position (which is usually on grid)
|
2008-04-17 16:25:29 +00:00
|
|
|
*
|
2007-08-20 01:49:24 +00:00
|
|
|
* Note: Mac OS ** does not ** allow moving mouse cursor by program.
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawFrame::Recadre_Trace( bool ToMouse )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
PutOnGrid( &(GetBaseScreen()->m_Curseur) );
|
2007-08-20 01:49:24 +00:00
|
|
|
AdjustScrollBars();
|
2010-01-15 10:02:47 +00:00
|
|
|
|
|
|
|
|
2010-01-17 16:22:31 +00:00
|
|
|
/* We do not use here DrawPanel->Refresh() because
|
|
|
|
* the redraw is delayed and the mouse events (from MouseToCursorSchema ot others)
|
|
|
|
* during this delay create problems: the mouse cursor position is false in calculations.
|
|
|
|
* TODO: see exactly how the mouse creates problems when moving during refresh
|
|
|
|
* use Refresh() and update() do not change problems
|
|
|
|
*/
|
|
|
|
INSTALL_DC(dc,DrawPanel);
|
|
|
|
DrawPanel->ReDraw( &dc );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2007-10-29 10:05:07 +00:00
|
|
|
/* Move the mouse cursor to the on grid graphic cursor position */
|
2007-08-20 01:49:24 +00:00
|
|
|
if( ToMouse == TRUE )
|
|
|
|
DrawPanel->MouseToCursorSchema();
|
2010-01-15 10:02:47 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2007-10-29 15:51:48 +00:00
|
|
|
/** Adjust the coordinate to the nearest grid value
|
2010-01-12 13:15:13 +00:00
|
|
|
* @param coord = coordinate to adjust
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawFrame::PutOnGrid( wxPoint* coord )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-14 19:43:31 +00:00
|
|
|
wxRealPoint grid_size = GetBaseScreen()->GetGridSize();
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
if( !GetBaseScreen()->m_UserGridIsON )
|
2007-08-20 01:49:24 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
int tmp = wxRound( coord->x / grid_size.x );
|
|
|
|
coord->x = wxRound( tmp * grid_size.x );
|
2009-02-11 15:49:28 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
tmp = wxRound( coord->y / grid_size.y );
|
2010-01-12 13:15:13 +00:00
|
|
|
coord->y = wxRound( tmp * grid_size.y );
|
2007-08-20 01:49:24 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2009-12-19 19:24:49 +00:00
|
|
|
/** Redraw the screen with best zoom level and the best centering
|
|
|
|
* that shows all the page or the board
|
2007-08-20 01:49:24 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawFrame::Zoom_Automatique( bool move_mouse_cursor )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-19 19:24:49 +00:00
|
|
|
GetBaseScreen()->SetZoom( BestZoom() ); // Set the best zoom
|
|
|
|
Recadre_Trace( move_mouse_cursor ); // Set the best centering and refresh the screen
|
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
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawFrame::Window_Zoom( EDA_Rect& Rect )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-01-12 13:15:13 +00:00
|
|
|
double scalex, bestscale;
|
2007-08-20 01:49:24 +00:00
|
|
|
wxSize size;
|
|
|
|
|
|
|
|
/* Compute the best zoom */
|
|
|
|
Rect.Normalize();
|
2010-01-12 13:15:13 +00:00
|
|
|
size = DrawPanel->GetClientSize();
|
|
|
|
|
2008-04-03 19:38:24 +00:00
|
|
|
// Use ceil to at least show the full rect
|
2010-01-12 13:15:13 +00:00
|
|
|
scalex = (double) Rect.GetSize().x / size.x;
|
|
|
|
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
|
|
|
|
2009-02-02 12:12:18 +00:00
|
|
|
GetBaseScreen()->SetScalingFactor( bestscale );
|
2008-04-17 16:25:29 +00:00
|
|
|
GetBaseScreen()->m_Curseur = Rect.Centre();
|
2007-08-20 01:49:24 +00:00
|
|
|
Recadre_Trace( TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/** Function OnZoom
|
2009-03-14 16:26:49 +00:00
|
|
|
* Called from any zoom event (toolbar , hotkey or popup )
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawFrame::OnZoom( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
if( DrawPanel == NULL )
|
2010-01-12 13:15:13 +00:00
|
|
|
return;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
int i;
|
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;
|
2009-01-07 15:59:49 +00:00
|
|
|
BASE_SCREEN* screen = GetBaseScreen();
|
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;
|
2010-01-12 13:15:13 +00:00
|
|
|
|
|
|
|
// fall thru
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
case ID_ZOOM_IN:
|
|
|
|
if( id == ID_ZOOM_IN )
|
|
|
|
screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
|
2009-02-11 19:39:55 +00:00
|
|
|
if( screen->SetPreviousZoom() )
|
|
|
|
Recadre_Trace( 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;
|
2010-01-12 13:15:13 +00:00
|
|
|
|
|
|
|
// fall thru
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
case ID_ZOOM_OUT:
|
|
|
|
if( id == ID_ZOOM_OUT )
|
|
|
|
screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
|
2009-02-11 19:39:55 +00:00
|
|
|
if( screen->SetNextZoom() )
|
|
|
|
Recadre_Trace( zoom_at_cursor );
|
2009-01-07 15:59:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_ZOOM_REDRAW:
|
2010-01-12 13:15:13 +00:00
|
|
|
DrawPanel->Refresh();
|
2009-01-07 15:59:49 +00:00
|
|
|
break;
|
|
|
|
|
2007-08-20 01:49:24 +00:00
|
|
|
case ID_POPUP_ZOOM_CENTER:
|
2009-01-07 15:59:49 +00:00
|
|
|
Recadre_Trace( true );
|
|
|
|
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:
|
2009-01-07 15:59:49 +00:00
|
|
|
DrawPanel->MouseToCursorSchema();
|
2007-08-20 01:49:24 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
default:
|
|
|
|
i = id - ID_POPUP_ZOOM_LEVEL_START;
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
if( ( i < 0 ) || ( (size_t) i >= screen->m_ZoomList.GetCount() ) )
|
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] ) )
|
|
|
|
Recadre_Trace( 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)
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawPanel::AddMenuZoom( wxMenu* MasterMenu )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
size_t i;
|
|
|
|
int maxZoomIds;
|
|
|
|
int zoom;
|
2009-10-14 19:43:31 +00:00
|
|
|
wxRealPoint grid;
|
2009-01-29 14:26:20 +00:00
|
|
|
wxString msg;
|
|
|
|
GRID_TYPE tmp;
|
|
|
|
wxMenu* gridMenu;
|
|
|
|
double gridValue;
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
ADD_MENUITEM( MasterMenu, ID_POPUP_ZOOM_CENTER, _( "Center" ),
|
|
|
|
zoom_center_xpm );
|
2008-02-17 21:19:13 +00:00
|
|
|
ADD_MENUITEM( MasterMenu, ID_POPUP_ZOOM_IN, _( "Zoom in" ), zoom_in_xpm );
|
|
|
|
ADD_MENUITEM( MasterMenu, ID_POPUP_ZOOM_OUT, _( "Zoom out" ), zoom_out_xpm );
|
2009-01-07 15:59:49 +00:00
|
|
|
ADD_MENUITEM( MasterMenu, ID_ZOOM_PAGE, _( "Zoom auto" ), zoom_auto_xpm );
|
2007-08-20 01:49:24 +00:00
|
|
|
|
|
|
|
wxMenu* zoom_choice = new wxMenu;
|
|
|
|
ADD_MENUITEM_WITH_SUBMENU( MasterMenu, zoom_choice,
|
2008-12-05 16:03:05 +00:00
|
|
|
ID_POPUP_ZOOM_SELECT, _( "Zoom select" ),
|
|
|
|
zoom_select_xpm );
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
ADD_MENUITEM( MasterMenu, ID_ZOOM_REDRAW, _( "Redraw view" ),
|
2008-12-05 16:03:05 +00:00
|
|
|
zoom_redraw_xpm );
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
zoom = GetScreen()->GetZoom();
|
2009-01-29 14:26:20 +00:00
|
|
|
maxZoomIds = ID_POPUP_ZOOM_LEVEL_END - ID_POPUP_ZOOM_LEVEL_START;
|
|
|
|
maxZoomIds = ( (size_t) maxZoomIds < GetScreen()->m_ZoomList.GetCount() ) ?
|
2010-01-12 13:15:13 +00:00
|
|
|
maxZoomIds : GetScreen()->m_ZoomList.GetCount();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
/* Populate zoom submenu. */
|
|
|
|
for( i = 0; i < (size_t) maxZoomIds; i++ )
|
2007-08-20 01:49:24 +00:00
|
|
|
{
|
2010-01-12 13:15:13 +00:00
|
|
|
if( ( GetScreen()->m_ZoomList[i] % GetScreen()->m_ZoomScalar ) == 0 )
|
2009-10-14 19:43:31 +00:00
|
|
|
msg.Printf( wxT( "%u" ),
|
|
|
|
GetScreen()->m_ZoomList[i] / GetScreen()->m_ZoomScalar );
|
2009-01-31 10:05:16 +00:00
|
|
|
else
|
2009-10-14 19:43:31 +00:00
|
|
|
msg.Printf( wxT( "%.1f" ),
|
2009-11-23 15:16:50 +00:00
|
|
|
(float) GetScreen()->m_ZoomList[i] /
|
|
|
|
GetScreen()->m_ZoomScalar );
|
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 );
|
|
|
|
if( zoom == GetScreen()->m_ZoomList[i] )
|
|
|
|
zoom_choice->Check( ID_POPUP_ZOOM_LEVEL_START + i, true );
|
2007-08-20 01:49:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
/* Create grid submenu as required. */
|
|
|
|
if( !GetScreen()->m_GridList.IsEmpty() )
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
gridMenu = new wxMenu;
|
|
|
|
ADD_MENUITEM_WITH_SUBMENU( MasterMenu, gridMenu,
|
2008-12-05 16:03:05 +00:00
|
|
|
ID_POPUP_GRID_SELECT, _( "Grid Select" ),
|
|
|
|
grid_select_xpm );
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
grid = GetScreen()->GetGridSize();
|
2007-08-20 01:49:24 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
for( i = 0; i < GetScreen()->m_GridList.GetCount(); i++ )
|
2007-08-20 01:49:24 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
tmp = GetScreen()->m_GridList[i];
|
2009-03-12 15:24:52 +00:00
|
|
|
gridValue = To_User_Unit( g_UnitMetric, tmp.m_Size.x,
|
2009-05-21 17:42:42 +00:00
|
|
|
m_Parent->m_InternalUnits );
|
|
|
|
|
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-01-12 13:15:13 +00:00
|
|
|
if( g_UnitMetric == 0 ) // inches
|
2009-03-12 15:24:52 +00:00
|
|
|
msg.Printf( wxT( "%.1f mils" ), gridValue * 1000 );
|
2008-12-05 16:03:05 +00:00
|
|
|
else
|
2009-03-12 15:24:52 +00:00
|
|
|
msg.Printf( wxT( "%.3f mm" ), gridValue );
|
2009-01-29 14:26:20 +00:00
|
|
|
msg = _( "Grid: " ) + msg;
|
2007-08-20 01:49:24 +00:00
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
gridMenu->Append( tmp.m_Id, msg, wxEmptyString, true );
|
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();
|
|
|
|
ADD_MENUITEM( MasterMenu, ID_POPUP_CANCEL, _( "Close" ), cancel_xpm );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|