2011-11-07 19:04: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) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.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
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
/**
|
|
|
|
* @file drawframe.cpp
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <id.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <class_base_screen.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_device_context.h>
|
|
|
|
#include <dialog_helpers.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-19 13:51:48 +00:00
|
|
|
#include <wx/fontdlg.h>
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
/**
|
|
|
|
* Definition for enabling and disabling scroll bar setting trace output. See the
|
|
|
|
* wxWidgets documentation on useing the WXTRACE environment variable.
|
2010-02-22 16:45:35 +00:00
|
|
|
*/
|
2011-11-07 19:04:24 +00:00
|
|
|
static const wxString traceScrollSettings( wxT( "KicadScrollSettings" ) );
|
2010-02-22 16:45:35 +00:00
|
|
|
|
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Configuration entry names.
|
2010-02-01 21:23:27 +00:00
|
|
|
static const wxString CursorShapeEntryKeyword( wxT( "CursorShape" ) );
|
|
|
|
static const wxString ShowGridEntryKeyword( wxT( "ShowGrid" ) );
|
|
|
|
static const wxString GridColorEntryKeyword( wxT( "GridColor" ) );
|
2009-10-14 19:43:31 +00:00
|
|
|
static const wxString LastGridSizeId( wxT( "_LastGridSize" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, EDA_BASE_FRAME )
|
|
|
|
EVT_MOUSEWHEEL( EDA_DRAW_FRAME::OnMouseEvent )
|
|
|
|
EVT_MENU_OPEN( EDA_DRAW_FRAME::OnMenuOpen )
|
|
|
|
EVT_ACTIVATE( EDA_DRAW_FRAME::OnActivate )
|
2011-02-21 21:07:00 +00:00
|
|
|
EVT_MENU_RANGE( ID_ZOOM_IN, ID_ZOOM_REDRAW, EDA_DRAW_FRAME::OnZoom )
|
2009-01-07 15:59:49 +00:00
|
|
|
EVT_MENU_RANGE( ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE,
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_FRAME::OnZoom )
|
2009-10-14 19:43:31 +00:00
|
|
|
EVT_MENU_RANGE( ID_POPUP_GRID_LEVEL_1000, ID_POPUP_GRID_USER,
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_FRAME::OnSelectGrid )
|
2011-02-21 13:54:29 +00:00
|
|
|
|
|
|
|
EVT_TOOL( ID_TB_OPTIONS_SHOW_GRID, EDA_DRAW_FRAME::OnToggleGridState )
|
|
|
|
EVT_TOOL_RANGE( ID_TB_OPTIONS_SELECT_UNIT_MM, ID_TB_OPTIONS_SELECT_UNIT_INCH,
|
|
|
|
EDA_DRAW_FRAME::OnSelectUnits )
|
|
|
|
EVT_TOOL( ID_TB_OPTIONS_SELECT_CURSOR, EDA_DRAW_FRAME::OnToggleCrossHairStyle )
|
|
|
|
|
|
|
|
EVT_UPDATE_UI( wxID_UNDO, EDA_DRAW_FRAME::OnUpdateUndo )
|
|
|
|
EVT_UPDATE_UI( wxID_REDO, EDA_DRAW_FRAME::OnUpdateRedo )
|
|
|
|
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_GRID, EDA_DRAW_FRAME::OnUpdateGrid )
|
|
|
|
EVT_UPDATE_UI( ID_TB_OPTIONS_SELECT_CURSOR, EDA_DRAW_FRAME::OnUpdateCrossHairStyle )
|
|
|
|
EVT_UPDATE_UI_RANGE( ID_TB_OPTIONS_SELECT_UNIT_MM, ID_TB_OPTIONS_SELECT_UNIT_INCH,
|
|
|
|
EDA_DRAW_FRAME::OnUpdateUnits )
|
2009-01-07 15:59:49 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype, const wxString& title,
|
|
|
|
const wxPoint& pos, const wxSize& size, long style ) :
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_BASE_FRAME( father, idtype, title, pos, size, style )
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
|
|
|
wxSize minsize;
|
|
|
|
|
2011-12-14 20:03:15 +00:00
|
|
|
m_drawToolBar = NULL;
|
|
|
|
m_optionsToolBar = NULL;
|
|
|
|
m_gridSelectBox = NULL;
|
|
|
|
m_zoomSelectBox = NULL;
|
2010-02-14 18:14:33 +00:00
|
|
|
m_HotkeysZoomAndGridList = NULL;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas = NULL;
|
2011-12-12 14:02:37 +00:00
|
|
|
m_messagePanel = NULL;
|
2011-02-05 02:21:11 +00:00
|
|
|
m_currentScreen = NULL;
|
2011-02-24 20:22:12 +00:00
|
|
|
m_toolId = ID_NO_TOOL_SELECTED;
|
2011-12-14 20:03:15 +00:00
|
|
|
m_lastDrawToolId = ID_NO_TOOL_SELECTED;
|
|
|
|
m_showAxis = false; // true to draw axis.
|
|
|
|
m_showBorderAndTitleBlock = false; // true to display reference sheet.
|
|
|
|
m_showGridAxis = false; // true to draw the grid axis
|
|
|
|
m_cursorShape = 0;
|
2009-10-14 19:43:31 +00:00
|
|
|
m_LastGridSizeId = 0;
|
2011-12-14 20:03:15 +00:00
|
|
|
m_DrawGrid = true; // hide/Show grid. default = show
|
2010-02-01 21:23:27 +00:00
|
|
|
m_GridColor = DARKGRAY; // Grid color
|
2011-02-03 19:27:28 +00:00
|
|
|
m_snapToGrid = true;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
// Internal units per inch: = 1000 for schema, = 10000 for PCB
|
2011-12-16 13:32:23 +00:00
|
|
|
m_internalUnits = EESCHEMA_INTERNAL_UNIT;
|
2009-01-29 14:26:20 +00:00
|
|
|
minsize.x = 470;
|
|
|
|
minsize.y = 350 + m_MsgFrameHeight;
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
SetSizeHints( minsize.x, minsize.y, -1, -1, -1, -1 );
|
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Make sure window has a sane minimum size.
|
2008-12-19 13:51:48 +00:00
|
|
|
if( ( size.x < minsize.x ) || ( size.y < minsize.y ) )
|
2007-08-15 02:43:57 +00:00
|
|
|
SetSize( 0, 0, minsize.x, minsize.y );
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Pane sizes for status bar.
|
2011-08-09 03:35:54 +00:00
|
|
|
// @todo these should be sized based on typical text content, like
|
|
|
|
// "dx -10.123 -10.123 dy -10.123 -10.123" using the system font which is
|
|
|
|
// in play on a particular platform, and should not be constants.
|
|
|
|
// Please do not reduce these constant values, and please use dynamic
|
|
|
|
// system font specific sizing in the future.
|
2009-04-09 18:23:28 +00:00
|
|
|
#define ZOOM_DISPLAY_SIZE 60
|
2011-08-09 03:35:54 +00:00
|
|
|
#define COORD_DISPLAY_SIZE 165
|
|
|
|
#define DELTA_DISPLAY_SIZE 190
|
|
|
|
#define UNITS_DISPLAY_SIZE 65
|
|
|
|
#define FUNCTION_DISPLAY_SIZE 110
|
2007-10-31 17:47:44 +00:00
|
|
|
static const int dims[6] = { -1, ZOOM_DISPLAY_SIZE,
|
2011-08-09 03:35:54 +00:00
|
|
|
COORD_DISPLAY_SIZE, DELTA_DISPLAY_SIZE,
|
2008-04-17 16:25:29 +00:00
|
|
|
UNITS_DISPLAY_SIZE, FUNCTION_DISPLAY_SIZE };
|
2007-08-15 02:43:57 +00:00
|
|
|
|
|
|
|
CreateStatusBar( 6 );
|
|
|
|
SetStatusWidths( 6, dims );
|
|
|
|
|
|
|
|
// Create child subwindows.
|
2009-11-23 15:16:50 +00:00
|
|
|
GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
|
2007-08-15 02:43:57 +00:00
|
|
|
m_FramePos.x = m_FramePos.y = 0;
|
|
|
|
m_FrameSize.y -= m_MsgFrameHeight;
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas = new EDA_DRAW_PANEL( this, -1, wxPoint( 0, 0 ), m_FrameSize );
|
2011-12-12 14:02:37 +00:00
|
|
|
m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
|
|
|
|
wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
|
2009-04-09 18:23:28 +00:00
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
m_messagePanel->SetBackgroundColour( wxColour( ColorRefs[LIGHTGRAY].m_Red,
|
|
|
|
ColorRefs[LIGHTGRAY].m_Green,
|
|
|
|
ColorRefs[LIGHTGRAY].m_Blue ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
SAFE_DELETE( m_currentScreen );
|
2009-11-05 08:52:41 +00:00
|
|
|
|
2009-11-02 22:24:55 +00:00
|
|
|
m_auimgr.UnInit();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-11 15:53:28 +00:00
|
|
|
void EDA_DRAW_FRAME::unitsChangeRefresh()
|
|
|
|
{
|
|
|
|
UpdateStatusBar();
|
|
|
|
|
|
|
|
EDA_ITEM* item = GetScreen()->GetCurItem();
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
item->DisplayInfo( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::EraseMsgBox()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-12 14:02:37 +00:00
|
|
|
if( m_messagePanel )
|
|
|
|
m_messagePanel->EraseMsgBox();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnActivate( wxActivateEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-15 02:43:57 +00:00
|
|
|
m_FrameIsActive = event.GetActive();
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetCanStartBlock( -1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
event.Skip(); // required under wxMAC
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetCanStartBlock( -1 );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
SetGridVisibility( !IsGridVisible() );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2011-02-21 13:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_FRAME::OnSelectUnits( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_MM && g_UserUnit != MILLIMETRES )
|
|
|
|
{
|
|
|
|
g_UserUnit = MILLIMETRES;
|
2011-03-01 19:26:17 +00:00
|
|
|
unitsChangeRefresh();
|
2011-02-21 13:54:29 +00:00
|
|
|
}
|
|
|
|
else if( aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_INCH && g_UserUnit != INCHES )
|
|
|
|
{
|
|
|
|
g_UserUnit = INCHES;
|
2011-03-01 19:26:17 +00:00
|
|
|
unitsChangeRefresh();
|
2011-02-21 13:54:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent )
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
|
|
|
m_canvas->CrossHairOff( &dc );
|
2011-12-14 20:03:15 +00:00
|
|
|
m_cursorShape = !m_cursorShape;
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOn( &dc );
|
2011-02-21 13:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_FRAME::OnUpdateUndo( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( GetScreen() )
|
|
|
|
aEvent.Enable( GetScreen()->GetUndoCommandCount() > 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_FRAME::OnUpdateRedo( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( GetScreen() )
|
|
|
|
aEvent.Enable( GetScreen()->GetRedoCommandCount() > 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_FRAME::OnUpdateUnits( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
bool enable;
|
|
|
|
|
|
|
|
enable = ( ((aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_MM) && (g_UserUnit == MILLIMETRES))
|
|
|
|
|| ((aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_INCH) && (g_UserUnit == INCHES)) );
|
|
|
|
|
|
|
|
aEvent.Check( enable );
|
|
|
|
DisplayUnitsMsg();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_FRAME::OnUpdateGrid( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxString tool_tip = IsGridVisible() ? _( "Hide grid" ) : _( "Show grid" );
|
|
|
|
|
|
|
|
aEvent.Check( IsGridVisible() );
|
2011-12-14 20:03:15 +00:00
|
|
|
m_optionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_GRID, tool_tip );
|
2011-02-21 13:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_DRAW_FRAME::OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
2011-12-14 20:03:15 +00:00
|
|
|
aEvent.Check( m_cursorShape );
|
2011-02-21 13:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::ReCreateAuxiliaryToolbar()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::ReCreateMenuBar()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-02-02 19:01:21 +00:00
|
|
|
void EDA_DRAW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::ToolOnRightClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
void EDA_DRAW_FRAME::PrintPage( wxDC* aDC,int aPrintMask, bool aPrintMirrorMode, void* aData )
|
2010-03-18 20:35:29 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-10-14 19:43:31 +00:00
|
|
|
int* clientData;
|
|
|
|
int id = ID_POPUP_GRID_LEVEL_100;
|
|
|
|
|
|
|
|
if( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED )
|
|
|
|
{
|
2011-12-14 20:03:15 +00:00
|
|
|
if( m_gridSelectBox == NULL )
|
2009-10-14 19:43:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't use wxCommandEvent::GetClientData() here. It always
|
|
|
|
* returns NULL in GTK. This solution is not as elegant but
|
|
|
|
* it works.
|
|
|
|
*/
|
2011-12-14 20:03:15 +00:00
|
|
|
int index = m_gridSelectBox->GetSelection();
|
2009-10-14 19:43:31 +00:00
|
|
|
wxASSERT( index != wxNOT_FOUND );
|
2011-12-14 20:03:15 +00:00
|
|
|
clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( index );
|
2009-10-14 19:43:31 +00:00
|
|
|
|
|
|
|
if( clientData != NULL )
|
|
|
|
id = *clientData;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id = event.GetId();
|
|
|
|
|
|
|
|
/* Update the grid select combobox if the grid size was changed
|
|
|
|
* by menu event.
|
|
|
|
*/
|
2011-12-14 20:03:15 +00:00
|
|
|
if( m_gridSelectBox != NULL )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2011-12-14 20:03:15 +00:00
|
|
|
for( size_t i = 0; i < m_gridSelectBox->GetCount(); i++ )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2011-12-14 20:03:15 +00:00
|
|
|
clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( i );
|
2009-10-14 19:43:31 +00:00
|
|
|
|
|
|
|
if( clientData && id == *clientData )
|
|
|
|
{
|
2011-12-14 20:03:15 +00:00
|
|
|
m_gridSelectBox->SetSelection( i );
|
2009-10-14 19:43:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
if( screen->GetGridId() == id )
|
|
|
|
return;
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
/*
|
|
|
|
* This allows for saving non-sequential command ID offsets used that
|
|
|
|
* may be used in the grid size combobox. Do not use the selection
|
|
|
|
* index returned by GetSelection().
|
|
|
|
*/
|
|
|
|
m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000;
|
2009-10-15 11:35:53 +00:00
|
|
|
screen->SetGrid( id );
|
2011-09-09 11:02:03 +00:00
|
|
|
screen->SetCrossHairPosition( screen->RefPos( true ) );
|
2009-10-14 19:43:31 +00:00
|
|
|
Refresh();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
2011-12-14 20:03:15 +00:00
|
|
|
if( m_zoomSelectBox == NULL )
|
2009-11-23 15:16:50 +00:00
|
|
|
return; // Should not happen!
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-12-14 20:03:15 +00:00
|
|
|
int id = m_zoomSelectBox->GetCurrentSelection();
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-12-14 20:03:15 +00:00
|
|
|
if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
|
2009-01-29 14:26:20 +00:00
|
|
|
return;
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( id == 0 ) // Auto zoom (Fit in Page)
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
Zoom_Automatique( true );
|
2007-08-15 02:43:57 +00:00
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
else
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
|
|
|
id--;
|
2011-02-05 02:21:11 +00:00
|
|
|
int selectedZoom = GetScreen()->m_ZoomList[id];
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( GetScreen()->GetZoom() == selectedZoom )
|
2007-08-15 02:43:57 +00:00
|
|
|
return;
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
GetScreen()->SetZoom( selectedZoom );
|
2011-02-11 20:48:13 +00:00
|
|
|
RedrawScreen( GetScreen()->GetScrollCenterPosition(), false );
|
2007-08-15 02:43:57 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-07-05 12:46:14 +00:00
|
|
|
double EDA_DRAW_FRAME::GetZoom( void )
|
2007-10-26 06:08:19 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
return GetScreen()->GetZoom();
|
2007-10-26 06:08:19 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnMouseEvent( wxMouseEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-15 02:43:57 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-15 02:43:57 +00:00
|
|
|
SetStatusText( msg, 5 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::DisplayUnitsMsg()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-15 02:43:57 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
switch( g_UserUnit )
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
|
|
|
case INCHES:
|
2010-07-12 14:07:09 +00:00
|
|
|
msg = _( "Inches" );
|
2007-08-15 02:43:57 +00:00
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
case MILLIMETRES:
|
2007-08-15 02:43:57 +00:00
|
|
|
msg += _( "mm" );
|
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
default:
|
2010-07-12 14:07:09 +00:00
|
|
|
msg += _( "Units" );
|
2007-08-15 02:43:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetStatusText( msg, 4 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
2010-01-14 20:20:59 +00:00
|
|
|
m_FrameSize = GetClientSize( );
|
2007-08-15 02:43:57 +00:00
|
|
|
|
|
|
|
SizeEv.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
2010-07-27 09:01:26 +00:00
|
|
|
// Keep default cursor in toolbars
|
|
|
|
SetCursor( wxNullCursor );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
// Change m_canvas cursor if requested.
|
|
|
|
if( m_canvas && aCursor >= 0 )
|
|
|
|
m_canvas->SetCurrentCursor( aCursor );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2010-07-27 16:49:38 +00:00
|
|
|
DisplayToolMsg( aToolMsg );
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2010-07-27 16:49:38 +00:00
|
|
|
if( aId < 0 )
|
2007-08-15 02:43:57 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-24 20:22:12 +00:00
|
|
|
wxCHECK2_MSG( aId >= ID_NO_TOOL_SELECTED, aId = ID_NO_TOOL_SELECTED,
|
|
|
|
wxString::Format( wxT( "Current tool ID cannot be set to %d." ), aId ) );
|
|
|
|
|
|
|
|
m_toolId = aId;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::OnGrid( int grid_type )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition )
|
|
|
|
{
|
|
|
|
wxPoint pos = aPosition;
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
if( m_currentScreen != NULL && m_snapToGrid )
|
|
|
|
pos = m_currentScreen->GetNearestGridPosition( aPosition );
|
2011-02-03 19:27:28 +00:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
int EDA_DRAW_FRAME::ReturnBlockCommand( int key )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-15 02:43:57 +00:00
|
|
|
return 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::InitBlockPasteInfos()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-05 02:21:11 +00:00
|
|
|
GetScreen()->m_BlockLocate.ClearItemsList();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetMouseCaptureCallback( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::HandleBlockPlace( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
bool EDA_DRAW_FRAME::HandleBlockEnd( wxDC* DC )
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
2010-11-13 11:02:24 +00:00
|
|
|
return false;
|
2007-08-15 02:43:57 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPosition )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-02-14 18:14:33 +00:00
|
|
|
int unitsX, unitsY, posX, posY;
|
2011-11-07 19:04:24 +00:00
|
|
|
wxSize clientSize, logicalClientSize, virtualSize;
|
2011-02-05 02:21:11 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
2010-02-22 16:45:35 +00:00
|
|
|
bool noRefresh = true;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
if( screen == NULL || m_canvas == NULL )
|
2007-08-15 02:43:57 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
double scalar = screen->GetScalingFactor();
|
|
|
|
|
|
|
|
wxLogTrace( traceScrollSettings, wxT( "Center Position = ( %d, %d ), scalar = %0.5f." ),
|
|
|
|
aCenterPosition.x, aCenterPosition.y, scalar );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Calculate the portion of the drawing that can be displayed in the
|
|
|
|
// client area at the current zoom level.
|
2011-12-22 13:28:11 +00:00
|
|
|
clientSize = m_canvas->GetClientSize();
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
// The logical size of the client window.
|
|
|
|
logicalClientSize.x = wxRound( (double) clientSize.x / scalar );
|
|
|
|
logicalClientSize.y = wxRound( (double) clientSize.y / scalar );
|
|
|
|
|
2011-12-22 21:57:50 +00:00
|
|
|
// A corner of the drawing in internal units.
|
|
|
|
wxSize corner = GetPageSizeIU();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
// The drawing rectangle logical units
|
2011-12-22 21:57:50 +00:00
|
|
|
wxRect drawingRect( wxPoint( 0, 0 ), corner );
|
2009-02-11 19:39:55 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
wxLogTrace( traceScrollSettings, wxT( "Logical drawing rect = ( %d, %d, %d, %d )." ),
|
|
|
|
drawingRect.x, drawingRect.y, drawingRect.width, drawingRect.height );
|
|
|
|
wxLogTrace( traceScrollSettings, wxT( " left %d, right %d, top %d, bottome %d" ),
|
|
|
|
drawingRect.GetLeft(), drawingRect.GetRight(),
|
|
|
|
drawingRect.GetTop(), drawingRect.GetBottom() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
// The size of the client rectangle in logical units.
|
|
|
|
int x = wxRound( (double) aCenterPosition.x - ( (double) logicalClientSize.x / 2.0 ) );
|
|
|
|
int y = wxRound( (double) aCenterPosition.y - ( (double) logicalClientSize.y / 2.0 ) );
|
|
|
|
|
|
|
|
// If drawn around the center, adjust the client rectangle accordingly.
|
2008-04-17 16:25:29 +00:00
|
|
|
if( screen->m_Center )
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
2011-11-07 19:04:24 +00:00
|
|
|
x += wxRound( (double) drawingRect.width / 2.0 );
|
|
|
|
y += wxRound( (double) drawingRect.height / 2.0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxRect logicalClientRect( wxPoint( x, y ), logicalClientSize );
|
|
|
|
|
|
|
|
wxLogTrace( traceScrollSettings, wxT( "Logical client rect = ( %d, %d, %d, %d )." ),
|
|
|
|
logicalClientRect.x, logicalClientRect.y,
|
|
|
|
logicalClientRect.width, logicalClientRect.height );
|
|
|
|
wxLogTrace( traceScrollSettings, wxT( " left %d, right %d, top %d, bottome %d" ),
|
|
|
|
logicalClientRect.GetLeft(), logicalClientRect.GetRight(),
|
|
|
|
logicalClientRect.GetTop(), logicalClientRect.GetBottom() );
|
|
|
|
|
|
|
|
if( drawingRect == logicalClientRect )
|
|
|
|
{
|
|
|
|
virtualSize = drawingRect.GetSize();
|
|
|
|
}
|
|
|
|
else if( drawingRect.Contains( logicalClientRect ) )
|
|
|
|
{
|
|
|
|
virtualSize = drawingRect.GetSize();
|
2007-08-15 02:43:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-07 19:04:24 +00:00
|
|
|
int drawingCenterX = drawingRect.x + ( drawingRect.width / 2 );
|
|
|
|
int clientCenterX = logicalClientRect.x + ( logicalClientRect.width / 2 );
|
|
|
|
int drawingCenterY = drawingRect.y + ( drawingRect.height / 2 );
|
|
|
|
int clientCenterY = logicalClientRect.y + ( logicalClientRect.height / 2 );
|
|
|
|
|
|
|
|
if( logicalClientRect.width > drawingRect.width )
|
|
|
|
{
|
|
|
|
if( drawingCenterX > clientCenterX )
|
|
|
|
virtualSize.x = ( drawingCenterX - logicalClientRect.GetLeft() ) * 2;
|
|
|
|
else if( drawingCenterX < clientCenterX )
|
|
|
|
virtualSize.x = ( logicalClientRect.GetRight() - drawingCenterX ) * 2;
|
|
|
|
else
|
|
|
|
virtualSize.x = logicalClientRect.width;
|
|
|
|
}
|
|
|
|
else if( logicalClientRect.width < drawingRect.width )
|
|
|
|
{
|
|
|
|
if( drawingCenterX > clientCenterX )
|
|
|
|
virtualSize.x = drawingRect.width +
|
|
|
|
( (drawingRect.GetLeft() - logicalClientRect.GetLeft() ) * 2 );
|
|
|
|
else if( drawingCenterX < clientCenterX )
|
|
|
|
virtualSize.x = drawingRect.width +
|
|
|
|
( (logicalClientRect.GetRight() - drawingRect.GetRight() ) * 2 );
|
|
|
|
else
|
|
|
|
virtualSize.x = drawingRect.width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
virtualSize.x = drawingRect.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( logicalClientRect.height > drawingRect.height )
|
|
|
|
{
|
|
|
|
if( drawingCenterY > clientCenterY )
|
|
|
|
virtualSize.y = ( drawingCenterY - logicalClientRect.GetTop() ) * 2;
|
|
|
|
else if( drawingCenterY < clientCenterY )
|
|
|
|
virtualSize.y = ( logicalClientRect.GetBottom() - drawingCenterY ) * 2;
|
|
|
|
else
|
|
|
|
virtualSize.y = logicalClientRect.height;
|
|
|
|
}
|
|
|
|
else if( logicalClientRect.height < drawingRect.height )
|
|
|
|
{
|
|
|
|
if( drawingCenterY > clientCenterY )
|
|
|
|
virtualSize.y = drawingRect.height +
|
|
|
|
( ( drawingRect.GetTop() - logicalClientRect.GetTop() ) * 2 );
|
|
|
|
else if( drawingCenterY < clientCenterY )
|
|
|
|
virtualSize.y = drawingRect.height +
|
|
|
|
( ( logicalClientRect.GetBottom() - drawingRect.GetBottom() ) * 2 );
|
|
|
|
else
|
|
|
|
virtualSize.y = drawingRect.height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
virtualSize.y = drawingRect.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( screen->m_Center )
|
|
|
|
{
|
|
|
|
screen->m_DrawOrg.x = -( wxRound( (double) virtualSize.x / 2.0 ) );
|
|
|
|
screen->m_DrawOrg.y = -( wxRound( (double) virtualSize.y / 2.0 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
screen->m_DrawOrg.x = -( wxRound( (double) (virtualSize.x - drawingRect.width) / 2.0 ) );
|
|
|
|
screen->m_DrawOrg.y = -( wxRound( (double) (virtualSize.y - drawingRect.height) / 2.0 ) );
|
2007-08-15 02:43:57 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
/* Always set scrollbar pixels per unit to 1 unless you want the zoom
|
|
|
|
* around cursor to jump around. This reported problem occurs when the
|
|
|
|
* zoom point is not on a pixel per unit increment. If you set the
|
|
|
|
* pixels per unit to 10, you have potential for the zoom point to
|
|
|
|
* jump around +/-5 pixels from the nearest grid point.
|
|
|
|
*/
|
2010-02-14 18:14:33 +00:00
|
|
|
screen->m_ScrollPixelsPerUnitX = screen->m_ScrollPixelsPerUnitY = 1;
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
// Calculate the number of scroll bar units for the given zoom level in device units.
|
|
|
|
unitsX = wxRound( (double) virtualSize.x * scalar );
|
|
|
|
unitsY = wxRound( (double) virtualSize.y * scalar );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
// Calculate the scroll bar position in logical units to place the center position at
|
|
|
|
// the center of client rectangle.
|
2011-02-11 20:48:13 +00:00
|
|
|
screen->SetScrollCenterPosition( aCenterPosition );
|
2011-11-07 19:04:24 +00:00
|
|
|
posX = aCenterPosition.x - wxRound( (double) logicalClientRect.width / 2.0 ) -
|
|
|
|
screen->m_DrawOrg.x;
|
|
|
|
posY = aCenterPosition.y - wxRound( (double) logicalClientRect.height / 2.0 ) -
|
|
|
|
screen->m_DrawOrg.y;
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
// Convert scroll bar position to device units.
|
|
|
|
posX = wxRound( (double) posX * scalar );
|
|
|
|
posY = wxRound( (double) posY * scalar );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( posX < 0 )
|
2011-11-07 19:04:24 +00:00
|
|
|
{
|
|
|
|
wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %d" ), posX );
|
2010-02-08 18:15:42 +00:00
|
|
|
posX = 0;
|
2011-11-07 19:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( posX > unitsX )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %d" ), posX );
|
|
|
|
posX = unitsX;
|
|
|
|
}
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( posY < 0 )
|
2011-11-07 19:04:24 +00:00
|
|
|
{
|
|
|
|
wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %d" ), posY );
|
2010-02-08 18:15:42 +00:00
|
|
|
posY = 0;
|
2011-11-07 19:04:24 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
if( posY > unitsY )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %d" ), posY );
|
|
|
|
posY = unitsY;
|
|
|
|
}
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
screen->m_ScrollbarPos = wxPoint( posX, posY );
|
|
|
|
screen->m_ScrollbarNumber = wxSize( unitsX, unitsY );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-07 19:04:24 +00:00
|
|
|
wxLogTrace( traceScrollSettings,
|
|
|
|
wxT( "Drawing = (%d, %d), Client = (%d, %d), Offset = (%d, %d), \
|
|
|
|
SetScrollbars(%d, %d, %d, %d, %d, %d)" ),
|
|
|
|
virtualSize.x, virtualSize.y, logicalClientSize.x, logicalClientSize.y,
|
|
|
|
screen->m_DrawOrg.x, screen->m_DrawOrg.y,
|
2010-02-22 16:45:35 +00:00
|
|
|
screen->m_ScrollPixelsPerUnitX, screen->m_ScrollPixelsPerUnitY,
|
|
|
|
screen->m_ScrollbarNumber.x, screen->m_ScrollbarNumber.y,
|
|
|
|
screen->m_ScrollbarPos.x, screen->m_ScrollbarPos.y );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetScrollbars( screen->m_ScrollPixelsPerUnitX,
|
|
|
|
screen->m_ScrollPixelsPerUnitY,
|
|
|
|
screen->m_ScrollbarNumber.x,
|
|
|
|
screen->m_ScrollbarNumber.y,
|
|
|
|
screen->m_ScrollbarPos.x,
|
|
|
|
screen->m_ScrollbarPos.y, noRefresh );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::SetLanguage( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_BASE_FRAME::SetLanguage( event );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
/**
|
|
|
|
* Round to the nearest precision.
|
|
|
|
*
|
|
|
|
* Try to approximate a coordinate using a given precision to prevent
|
|
|
|
* rounding errors when converting from inches to mm.
|
|
|
|
*
|
2009-07-25 04:53:39 +00:00
|
|
|
* ie round the unit value to 0 if unit is 1 or 2, or 8 or 9
|
|
|
|
*/
|
2009-10-14 19:43:31 +00:00
|
|
|
double RoundTo0( double x, double precision )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
2009-10-14 19:43:31 +00:00
|
|
|
assert( precision != 0 );
|
|
|
|
|
|
|
|
long long ix = wxRound( x * precision );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
if ( x < 0.0 )
|
|
|
|
NEGATE( ix );
|
|
|
|
|
|
|
|
int remainder = ix % 10; // remainder is in precision mm
|
2009-07-25 04:53:39 +00:00
|
|
|
|
|
|
|
if ( remainder <= 2 )
|
2009-10-14 19:43:31 +00:00
|
|
|
ix -= remainder; // truncate to the near number
|
2009-07-25 04:53:39 +00:00
|
|
|
else if (remainder >= 8 )
|
2009-10-14 19:43:31 +00:00
|
|
|
ix += 10 - remainder; // round to near number
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
if ( x < 0 )
|
|
|
|
NEGATE( ix );
|
|
|
|
|
|
|
|
return (double) ix / precision;
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::UpdateStatusBar()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
wxString Line;
|
|
|
|
int dx, dy;
|
2011-02-05 02:21:11 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
if( !screen )
|
2007-08-15 02:43:57 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Display Zoom level: zoom = zoom_coeff/ZoomScalar
|
2011-07-05 12:46:14 +00:00
|
|
|
Line.Printf( wxT( "Z %g" ), screen->GetZoom() );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
SetStatusText( Line, 1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Display absolute coordinates:
|
2011-12-16 13:32:23 +00:00
|
|
|
double dXpos = To_User_Unit( g_UserUnit, screen->GetCrossHairPosition().x, m_internalUnits );
|
|
|
|
double dYpos = To_User_Unit( g_UserUnit, screen->GetCrossHairPosition().y, m_internalUnits );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
/*
|
|
|
|
* Converting from inches to mm can give some coordinates due to
|
|
|
|
* float point precision rounding errors, like 1.999 or 2.001 so
|
|
|
|
* round to the nearest drawing precision required by the application.
|
2011-09-30 18:15:37 +00:00
|
|
|
*/
|
2010-07-12 14:07:09 +00:00
|
|
|
if ( g_UserUnit == MILLIMETRES )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
2011-12-16 13:32:23 +00:00
|
|
|
dXpos = RoundTo0( dXpos, (double)( m_internalUnits / 10 ) );
|
|
|
|
dYpos = RoundTo0( dYpos, (double)( m_internalUnits / 10 ) );
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
2010-07-12 14:07:09 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// The following sadly is an if Eeschema/if Pcbnew
|
2010-10-30 10:03:41 +00:00
|
|
|
wxString absformatter;
|
|
|
|
wxString locformatter;
|
2010-07-12 14:07:09 +00:00
|
|
|
switch( g_UserUnit )
|
|
|
|
{
|
|
|
|
case INCHES:
|
2011-12-16 13:32:23 +00:00
|
|
|
if( m_internalUnits == EESCHEMA_INTERNAL_UNIT )
|
2010-07-12 14:07:09 +00:00
|
|
|
{
|
2010-10-30 10:03:41 +00:00
|
|
|
absformatter = wxT( "X %.3f Y %.3f" );
|
|
|
|
locformatter = wxT( "dx %.3f dy %.3f" );
|
2010-07-12 14:07:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-30 10:03:41 +00:00
|
|
|
absformatter = wxT( "X %.4f Y %.4f" );
|
|
|
|
locformatter = wxT( "dx %.4f dy %.4f" );
|
2010-07-12 14:07:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MILLIMETRES:
|
2011-12-16 13:32:23 +00:00
|
|
|
if( m_internalUnits == EESCHEMA_INTERNAL_UNIT )
|
2010-07-12 14:07:09 +00:00
|
|
|
{
|
2010-10-30 10:03:41 +00:00
|
|
|
absformatter = wxT( "X %.2f Y %.2f" );
|
|
|
|
locformatter = wxT( "dx %.2f dy %.2f" );
|
2010-07-12 14:07:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-30 10:03:41 +00:00
|
|
|
absformatter = wxT( "X %.3f Y %.3f" );
|
|
|
|
locformatter = wxT( "dx %.3f dy %.3f" );
|
2010-07-12 14:07:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNSCALED_UNITS:
|
2010-10-30 10:03:41 +00:00
|
|
|
absformatter = wxT( "X %f Y %f" );
|
|
|
|
locformatter = wxT( "dx %f dy %f" );
|
2010-07-12 14:07:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-10-30 10:03:41 +00:00
|
|
|
Line.Printf( absformatter, dXpos, dYpos );
|
2007-08-15 02:43:57 +00:00
|
|
|
SetStatusText( Line, 2 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Display relative coordinates:
|
2011-02-11 20:48:13 +00:00
|
|
|
dx = screen->GetCrossHairPosition().x - screen->m_O_Curseur.x;
|
|
|
|
dy = screen->GetCrossHairPosition().y - screen->m_O_Curseur.y;
|
2011-12-16 13:32:23 +00:00
|
|
|
dXpos = To_User_Unit( g_UserUnit, dx, m_internalUnits );
|
|
|
|
dYpos = To_User_Unit( g_UserUnit, dy, m_internalUnits );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
if( g_UserUnit == MILLIMETRES )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
2011-12-16 13:32:23 +00:00
|
|
|
dXpos = RoundTo0( dXpos, (double) ( m_internalUnits / 10 ) );
|
|
|
|
dYpos = RoundTo0( dYpos, (double) ( m_internalUnits / 10 ) );
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// We already decided the formatter above
|
2010-10-30 10:03:41 +00:00
|
|
|
Line.Printf( locformatter, dXpos, dYpos );
|
2007-08-15 02:43:57 +00:00
|
|
|
SetStatusText( Line, 3 );
|
2012-02-17 19:43:43 +00:00
|
|
|
|
|
|
|
// refresh units display
|
|
|
|
DisplayUnitsMsg();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::LoadSettings()
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-12-16 20:12:49 +00:00
|
|
|
wxASSERT( wxGetApp().GetSettings() != NULL );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
wxConfig* cfg = wxGetApp().GetSettings();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_BASE_FRAME::LoadSettings();
|
2011-12-14 20:03:15 +00:00
|
|
|
cfg->Read( m_FrameName + CursorShapeEntryKeyword, &m_cursorShape, ( long )0 );
|
2010-02-01 21:23:27 +00:00
|
|
|
bool btmp;
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2010-02-01 21:23:27 +00:00
|
|
|
if ( cfg->Read( m_FrameName + ShowGridEntryKeyword, &btmp ) )
|
2011-02-09 19:47:33 +00:00
|
|
|
SetGridVisibility( btmp );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2010-02-01 21:23:27 +00:00
|
|
|
int itmp;
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2010-02-01 21:23:27 +00:00
|
|
|
if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) )
|
2011-02-09 19:47:33 +00:00
|
|
|
SetGridColor( itmp );
|
2011-01-31 18:26:12 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
cfg->Read( m_FrameName + LastGridSizeId, &m_LastGridSizeId, 0L );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::SaveSettings()
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-12-16 20:12:49 +00:00
|
|
|
wxASSERT( wxGetApp().GetSettings() != NULL );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-12-16 20:12:49 +00:00
|
|
|
wxConfig* cfg = wxGetApp().GetSettings();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
EDA_BASE_FRAME::SaveSettings();
|
2011-12-14 20:03:15 +00:00
|
|
|
cfg->Write( m_FrameName + CursorShapeEntryKeyword, m_cursorShape );
|
2010-02-01 21:23:27 +00:00
|
|
|
cfg->Write( m_FrameName + ShowGridEntryKeyword, IsGridVisible() );
|
|
|
|
cfg->Write( m_FrameName + GridColorEntryKeyword, GetGridColor() );
|
2009-10-14 19:43:31 +00:00
|
|
|
cfg->Write( m_FrameName + LastGridSizeId, ( long ) m_LastGridSizeId );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper,
|
|
|
|
const wxString& textLower,
|
|
|
|
int color, int pad )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2011-12-12 14:02:37 +00:00
|
|
|
if( m_messagePanel == NULL )
|
2009-10-14 19:43:31 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
|
2009-10-14 19:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void EDA_DRAW_FRAME::ClearMsgPanel( void )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2011-12-12 14:02:37 +00:00
|
|
|
if( m_messagePanel == NULL )
|
2009-10-14 19:43:31 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
m_messagePanel->EraseMsgBox();
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2011-03-11 15:53:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxString EDA_DRAW_FRAME::CoordinateToString( int aValue, bool aConvertToMils )
|
|
|
|
{
|
2011-12-16 13:32:23 +00:00
|
|
|
return ::CoordinateToString( aValue, m_internalUnits, aConvertToMils );
|
2011-03-11 15:53:28 +00:00
|
|
|
}
|