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-12-17 16:43:46 +00:00
|
|
|
#include <dialogs/dialog_grid_settings.h>
|
2016-05-02 14:15:24 +00:00
|
|
|
#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>
|
2020-06-23 10:16:34 +00:00
|
|
|
#include <tool/common_tools.h>
|
2023-01-05 12:23:03 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
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 ),
|
2021-03-12 15:12:49 +00:00
|
|
|
m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits ),
|
|
|
|
m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits )
|
2013-07-09 05:48:26 +00:00
|
|
|
{
|
2020-07-06 14:41:29 +00:00
|
|
|
// Configure display origin transforms
|
|
|
|
m_gridOriginX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
|
|
|
|
m_gridOriginY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
|
|
|
|
|
2021-02-21 20:32:52 +00:00
|
|
|
RebuildGridSizes();
|
2011-09-09 11:02:03 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
if( m_parent->IsType( FRAME_SCH )
|
2020-10-31 01:27:16 +00:00
|
|
|
|| m_parent->IsType( FRAME_SCH_SYMBOL_EDITOR )
|
2020-06-14 15:08:47 +00:00
|
|
|
|| m_parent->IsType( FRAME_SCH_VIEWER )
|
|
|
|
|| m_parent->IsType( FRAME_SCH_VIEWER_MODAL )
|
|
|
|
|| m_parent->IsType( FRAME_SIMULATOR ) )
|
|
|
|
{
|
|
|
|
m_book->SetSelection( 1 );
|
2021-02-21 20:32:52 +00:00
|
|
|
m_buttonResetOrigin->Hide(); // Eeschema and friends don't use grid origin
|
2020-06-14 15:08:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_book->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
2022-04-10 22:40:59 +00:00
|
|
|
int hk1 = ACTIONS::gridFast1.GetHotKey();
|
|
|
|
int hk2 = ACTIONS::gridFast2.GetHotKey();
|
|
|
|
m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
|
|
|
|
m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
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
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2021-02-21 20:32:52 +00:00
|
|
|
|
|
|
|
m_buttonResetSizes->Bind( wxEVT_BUTTON,
|
2021-02-24 03:16:34 +00:00
|
|
|
[&]( wxCommandEvent& )
|
2021-02-21 20:32:52 +00:00
|
|
|
{
|
|
|
|
APP_SETTINGS_BASE* settings = m_parent->config();
|
|
|
|
settings->m_Window.grid.sizes = settings->DefaultGridSizeList();
|
|
|
|
RebuildGridSizes();
|
|
|
|
settings->m_Window.grid.last_size_idx = m_currentGridCtrl->GetSelection();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GRID_SETTINGS::RebuildGridSizes()
|
|
|
|
{
|
|
|
|
APP_SETTINGS_BASE* settings = m_parent->config();
|
|
|
|
|
|
|
|
wxString savedCurrentGrid = m_currentGridCtrl->GetStringSelection();
|
|
|
|
wxString savedGrid1 = m_grid1Ctrl->GetStringSelection();
|
|
|
|
wxString savedGrid2 = m_grid2Ctrl->GetStringSelection();
|
|
|
|
|
|
|
|
wxArrayString grids;
|
|
|
|
GRID_MENU::BuildChoiceList( &grids, settings, m_parent );
|
|
|
|
|
|
|
|
m_currentGridCtrl->Set( grids );
|
|
|
|
m_grid1Ctrl->Set( grids );
|
|
|
|
m_grid2Ctrl->Set( grids );
|
|
|
|
|
|
|
|
m_currentGridCtrl->SetStringSelection( savedCurrentGrid );
|
|
|
|
m_grid1Ctrl->SetStringSelection( savedGrid1 );
|
|
|
|
m_grid2Ctrl->SetStringSelection( savedGrid2 );
|
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
|
2023-01-05 12:23:03 +00:00
|
|
|
APP_SETTINGS_BASE* cfg = m_parent->config();
|
|
|
|
GRID_SETTINGS& gridCfg = cfg->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();
|
2023-02-19 03:40:07 +00:00
|
|
|
m_parent->SetGridOrigin( VECTOR2I( m_gridOriginX.GetValue(), m_gridOriginY.GetValue() ) );
|
2022-09-19 09:25:20 +00:00
|
|
|
gridCfg.user_grid_x = m_parent->StringFromValue( m_userGridX.GetValue(), true );
|
|
|
|
gridCfg.user_grid_y = m_parent->StringFromValue( m_userGridY.GetValue(), 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
|
|
|
|
2020-06-23 10:16:34 +00:00
|
|
|
// Notify TOOLS
|
2016-05-02 14:15:24 +00:00
|
|
|
TOOL_MANAGER* mgr = m_parent->GetToolManager();
|
2023-04-04 16:04:24 +00:00
|
|
|
mgr->ResetTools( TOOL_BASE::REDRAW );
|
2020-06-23 10:16:34 +00:00
|
|
|
|
|
|
|
// Notify GAL
|
2021-06-04 19:41:40 +00:00
|
|
|
mgr->RunAction( ACTIONS::gridPreset, true, static_cast<intptr_t>( 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
|
|
|
{
|
2021-02-21 20:32:52 +00:00
|
|
|
APP_SETTINGS_BASE* settings = m_parent->config();
|
|
|
|
|
|
|
|
GRID_SETTINGS& gridCfg = settings->m_Window.grid;
|
|
|
|
|
|
|
|
m_buttonResetSizes->Show( gridCfg.sizes != settings->DefaultGridSizeList() );
|
|
|
|
Layout();
|
2020-06-12 10:58:56 +00:00
|
|
|
|
2021-02-21 20:32:52 +00:00
|
|
|
m_currentGridCtrl->SetSelection( settings->m_Window.grid.last_size_idx );
|
2020-06-14 15:08:47 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
m_userGridX.SetValue( m_parent->ValueFromString( gridCfg.user_grid_x ) );
|
|
|
|
m_userGridY.SetValue( m_parent->ValueFromString( gridCfg.user_grid_y ) );
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|