2013-02-26 11:25:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-06-14 15:08:47 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-02-26 11:25:30 +00:00
|
|
|
*
|
|
|
|
* 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-06-05 12:10:51 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
#include <dialog_grid_settings.h>
|
2016-05-02 14:15:24 +00:00
|
|
|
#include <base_units.h>
|
|
|
|
#include <common.h>
|
2020-06-12 10:58:56 +00:00
|
|
|
#include <settings/app_settings.h>
|
2020-06-14 15:08:47 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2016-05-02 14:15:24 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-06-14 15:08:47 +00:00
|
|
|
#include <tool/actions.h>
|
2020-06-12 10:58:56 +00:00
|
|
|
#include <tool/grid_menu.h>
|
2019-05-25 19:39:42 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( EDA_DRAW_FRAME* aParent ):
|
|
|
|
DIALOG_GRID_SETTINGS_BASE( aParent ),
|
2016-05-02 14:15:24 +00:00
|
|
|
m_parent( aParent ),
|
2018-02-03 09:09:53 +00:00
|
|
|
m_gridOriginX( aParent, m_staticTextGridPosX, m_GridOriginXCtrl, m_TextPosXUnits ),
|
|
|
|
m_gridOriginY( aParent, m_staticTextGridPosY, m_GridOriginYCtrl, m_TextPosYUnits ),
|
2020-06-12 10:58:56 +00:00
|
|
|
m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits, true ),
|
|
|
|
m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits, true )
|
2013-07-09 05:48:26 +00:00
|
|
|
{
|
2020-06-12 10:58:56 +00:00
|
|
|
wxArrayString grids;
|
|
|
|
GRID_MENU::BuildChoiceList( &grids, m_parent->config(), GetUserUnits() != EDA_UNITS::INCHES );
|
2020-06-14 15:08:47 +00:00
|
|
|
m_currentGridCtrl->Append( grids );
|
2020-06-12 10:58:56 +00:00
|
|
|
m_grid1Ctrl->Append( grids );
|
|
|
|
m_grid2Ctrl->Append( grids );
|
2011-09-09 11:02:03 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
if( m_parent->IsType( FRAME_SCH )
|
|
|
|
|| m_parent->IsType( FRAME_SCH_LIB_EDITOR )
|
|
|
|
|| m_parent->IsType( FRAME_SCH_VIEWER )
|
|
|
|
|| m_parent->IsType( FRAME_SCH_VIEWER_MODAL )
|
|
|
|
|| m_parent->IsType( FRAME_SIMULATOR ) )
|
|
|
|
{
|
|
|
|
m_book->SetSelection( 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_book->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
|
2018-03-06 05:33:04 +00:00
|
|
|
SetInitialFocus( m_GridOriginXCtrl );
|
2018-02-02 15:44:53 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
Layout();
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
bool DIALOG_GRID_SETTINGS::TransferDataFromWindow()
|
2016-05-02 14:15:24 +00:00
|
|
|
{
|
|
|
|
// Validate new settings
|
2020-06-14 15:08:47 +00:00
|
|
|
if( !m_userGridX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
|
2018-02-03 09:09:53 +00:00
|
|
|
return false;
|
2017-07-10 13:16:57 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
if( !m_userGridY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
|
2018-02-15 15:12:10 +00:00
|
|
|
return false;
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
// Apply the new settings
|
2020-06-12 10:58:56 +00:00
|
|
|
GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid;
|
2016-05-02 14:15:24 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
|
2018-02-03 09:09:53 +00:00
|
|
|
m_parent->SetGridOrigin( wxPoint( m_gridOriginX.GetValue(), m_gridOriginY.GetValue() ) );
|
2020-06-12 10:58:56 +00:00
|
|
|
gridCfg.user_grid_x = StringFromValue( GetUserUnits(), m_userGridX.GetValue(), true, true );
|
|
|
|
gridCfg.user_grid_y = StringFromValue( GetUserUnits(), m_userGridY.GetValue(), true, true );
|
2020-06-14 15:08:47 +00:00
|
|
|
gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
|
|
|
|
gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
|
2016-05-02 14:15:24 +00:00
|
|
|
|
|
|
|
// Notify GAL
|
|
|
|
TOOL_MANAGER* mgr = m_parent->GetToolManager();
|
2020-06-12 10:58:56 +00:00
|
|
|
mgr->RunAction( ACTIONS::gridPreset, true, gridCfg.last_size_idx );
|
2019-06-19 17:34:02 +00:00
|
|
|
mgr->RunAction( ACTIONS::gridSetOrigin, true, new VECTOR2D( m_parent->GetGridOrigin() ) );
|
2016-05-02 14:15:24 +00:00
|
|
|
|
2018-11-23 23:33:02 +00:00
|
|
|
m_parent->UpdateGridSelectBox();
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
return wxDialog::TransferDataFromWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
bool DIALOG_GRID_SETTINGS::TransferDataToWindow()
|
2016-05-02 14:15:24 +00:00
|
|
|
{
|
2020-06-14 15:08:47 +00:00
|
|
|
GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid;
|
2020-06-12 10:58:56 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
m_currentGridCtrl->SetSelection( m_parent->config()->m_Window.grid.last_size_idx );
|
|
|
|
|
|
|
|
m_userGridX.SetValue( ValueFromString( GetUserUnits(), gridCfg.user_grid_x, true ) );
|
|
|
|
m_userGridY.SetValue( ValueFromString( GetUserUnits(), gridCfg.user_grid_y, true ) );
|
2016-05-02 14:15:24 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
m_gridOriginX.SetValue( m_parent->GetGridOrigin().x );
|
|
|
|
m_gridOriginY.SetValue( m_parent->GetGridOrigin().y );
|
2016-05-02 14:15:24 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
m_grid1Ctrl->SetSelection( gridCfg.fast_grid_1 );
|
|
|
|
m_grid2Ctrl->SetSelection( gridCfg.fast_grid_2 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
int hk1 = ACTIONS::gridFast1.GetHotKey();
|
2019-08-08 10:23:13 +00:00
|
|
|
int hk2 = ACTIONS::gridFast2.GetHotKey();
|
2018-08-26 17:57:28 +00:00
|
|
|
m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
|
|
|
|
m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
|
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
return wxDialog::TransferDataToWindow();
|
2010-07-13 10:42:32 +00:00
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
void DIALOG_GRID_SETTINGS::OnResetGridOriginClick( wxCommandEvent& event )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2018-02-03 09:09:53 +00:00
|
|
|
m_gridOriginX.SetValue( 0 );
|
|
|
|
m_gridOriginY.SetValue( 0 );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2013-07-09 05:48:26 +00:00
|
|
|
|
|
|
|
|