2023-08-26 12:29:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2023 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wx/textdlg.h>
|
|
|
|
#include <dialogs/panel_grid_settings.h>
|
2023-08-30 15:21:56 +00:00
|
|
|
#include <dialogs/dialog_grid_settings.h>
|
2023-08-26 12:29:24 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <settings/app_settings.h>
|
|
|
|
#include <eda_draw_frame.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/actions.h>
|
|
|
|
#include <tool/grid_menu.h>
|
|
|
|
#include <tool/common_tools.h>
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
|
|
|
|
PANEL_GRID_SETTINGS::PANEL_GRID_SETTINGS( wxWindow* aParent, UNITS_PROVIDER* aUnitsProvider,
|
|
|
|
wxWindow* aEventSource, APP_SETTINGS_BASE* aCfg,
|
|
|
|
FRAME_T aFrameType ) :
|
|
|
|
PANEL_GRID_SETTINGS_BASE( aParent ),
|
2023-08-30 15:21:56 +00:00
|
|
|
m_unitsProvider( aUnitsProvider ), m_cfg( aCfg ), m_frameType( aFrameType ),
|
2023-08-30 17:33:04 +00:00
|
|
|
m_eventSource( aEventSource )
|
2023-08-26 12:29:24 +00:00
|
|
|
{
|
|
|
|
RebuildGridSizes();
|
|
|
|
|
|
|
|
if( m_frameType == FRAME_PCB_EDITOR || m_frameType == FRAME_FOOTPRINT_EDITOR )
|
|
|
|
{
|
2023-08-30 17:33:04 +00:00
|
|
|
m_checkGridOverrideConnected->SetLabel( wxT( "Footprints/pads:" ) );
|
|
|
|
m_checkGridOverrideWires->SetLabel( wxT( "Tracks:" ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-30 17:33:04 +00:00
|
|
|
m_gridOverrideViasChoice->SetSelection( 0 );
|
|
|
|
m_gridOverrideViasChoice->Show( false );
|
2023-08-26 12:29:24 +00:00
|
|
|
m_checkGridOverrideVias->Show( false );
|
|
|
|
|
|
|
|
if( m_frameType != FRAME_SCH
|
|
|
|
&& m_frameType != FRAME_SCH_SYMBOL_EDITOR
|
|
|
|
&& m_frameType != FRAME_SCH_VIEWER
|
|
|
|
&& m_frameType != FRAME_SIMULATOR )
|
|
|
|
{
|
|
|
|
m_checkGridOverrideConnected->Show( false );
|
2023-08-30 17:33:04 +00:00
|
|
|
m_gridOverrideConnectedChoice->Show( false );
|
2023-08-26 12:29:24 +00:00
|
|
|
|
|
|
|
m_checkGridOverrideWires->Show( false );
|
2023-08-30 17:33:04 +00:00
|
|
|
m_gridOverrideWiresChoice->Show( false );
|
2023-08-26 12:29:24 +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 ) ) );
|
|
|
|
|
|
|
|
m_addGridButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_removeGridButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
|
|
|
m_moveUpButton->SetBitmap( KiBitmap( BITMAPS::small_up ) );
|
|
|
|
m_moveDownButton->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
|
|
|
|
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_GRID_SETTINGS::ResetPanel()
|
|
|
|
{
|
2023-08-30 15:21:56 +00:00
|
|
|
m_cfg->m_Window.grid.grids = m_cfg->DefaultGridSizeList();
|
2023-08-26 12:29:24 +00:00
|
|
|
RebuildGridSizes();
|
|
|
|
m_cfg->m_Window.grid.last_size_idx = m_currentGridCtrl->GetSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_GRID_SETTINGS::RebuildGridSizes()
|
|
|
|
{
|
|
|
|
wxString savedCurrentGrid = m_currentGridCtrl->GetStringSelection();
|
2023-08-30 17:33:04 +00:00
|
|
|
|
2023-08-26 12:29:24 +00:00
|
|
|
wxString savedGrid1 = m_grid1Ctrl->GetStringSelection();
|
|
|
|
wxString savedGrid2 = m_grid2Ctrl->GetStringSelection();
|
|
|
|
|
2023-08-30 17:33:04 +00:00
|
|
|
wxString savedConnectables = m_gridOverrideConnectedChoice->GetStringSelection();
|
|
|
|
wxString savedWires = m_gridOverrideWiresChoice->GetStringSelection();
|
|
|
|
wxString savedVias = m_gridOverrideViasChoice->GetStringSelection();
|
|
|
|
wxString savedText = m_gridOverrideTextChoice->GetStringSelection();
|
|
|
|
wxString savedGraphics = m_gridOverrideGraphicsChoice->GetStringSelection();
|
|
|
|
|
2023-08-26 12:29:24 +00:00
|
|
|
wxArrayString grids;
|
|
|
|
wxString msg;
|
|
|
|
EDA_IU_SCALE scale = m_unitsProvider->GetIuScale();
|
|
|
|
EDA_UNITS primaryUnit;
|
|
|
|
EDA_UNITS secondaryUnit;
|
|
|
|
|
|
|
|
m_unitsProvider->GetUnitPair( primaryUnit, secondaryUnit );
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
for( const struct GRID& grid : m_cfg->m_Window.grid.grids )
|
2023-08-26 12:29:24 +00:00
|
|
|
{
|
2023-08-30 15:21:56 +00:00
|
|
|
wxString name = grid.name;
|
2023-08-26 12:29:24 +00:00
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
if( !name.IsEmpty() )
|
|
|
|
name += wxT( ": " );
|
|
|
|
|
|
|
|
msg.Printf( _( "%s%s (%s)" ), name, grid.MessageText( scale, primaryUnit, true ),
|
|
|
|
grid.MessageText( scale, secondaryUnit, true ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
|
|
|
|
grids.Add( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentGridCtrl->Set( grids );
|
2023-08-30 17:33:04 +00:00
|
|
|
|
2023-08-26 12:29:24 +00:00
|
|
|
m_grid1Ctrl->Set( grids );
|
|
|
|
m_grid2Ctrl->Set( grids );
|
|
|
|
|
2023-08-30 17:33:04 +00:00
|
|
|
m_gridOverrideConnectedChoice->Set( grids );
|
|
|
|
m_gridOverrideWiresChoice->Set( grids );
|
|
|
|
m_gridOverrideViasChoice->Set( grids );
|
|
|
|
m_gridOverrideTextChoice->Set( grids );
|
|
|
|
m_gridOverrideGraphicsChoice->Set( grids );
|
|
|
|
|
2023-08-26 12:29:24 +00:00
|
|
|
if( !m_currentGridCtrl->SetStringSelection( savedCurrentGrid ) )
|
|
|
|
m_currentGridCtrl->SetStringSelection( grids.front() );
|
|
|
|
|
|
|
|
if( !m_grid1Ctrl->SetStringSelection( savedGrid1 ) )
|
|
|
|
m_grid1Ctrl->SetStringSelection( grids.front() );
|
|
|
|
|
|
|
|
if( !m_grid2Ctrl->SetStringSelection( savedGrid2 ) )
|
|
|
|
m_grid2Ctrl->SetStringSelection( grids.back() );
|
2023-08-30 17:33:04 +00:00
|
|
|
|
|
|
|
if( !m_gridOverrideConnectedChoice->SetStringSelection( savedConnectables ) )
|
|
|
|
m_gridOverrideConnectedChoice->SetStringSelection( grids.front() );
|
|
|
|
|
|
|
|
if( !m_gridOverrideWiresChoice->SetStringSelection( savedWires ) )
|
|
|
|
m_gridOverrideWiresChoice->SetStringSelection( grids.front() );
|
|
|
|
|
|
|
|
if( !m_gridOverrideViasChoice->SetStringSelection( savedVias ) )
|
|
|
|
m_gridOverrideViasChoice->SetStringSelection( grids.front() );
|
|
|
|
|
|
|
|
if( !m_gridOverrideTextChoice->SetStringSelection( savedText ) )
|
|
|
|
m_gridOverrideTextChoice->SetStringSelection( grids.front() );
|
|
|
|
|
|
|
|
if( !m_gridOverrideGraphicsChoice->SetStringSelection( savedGraphics ) )
|
|
|
|
m_gridOverrideGraphicsChoice->SetStringSelection( grids.front() );
|
2023-08-26 12:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_GRID_SETTINGS::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
// Apply the new settings
|
|
|
|
GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
|
|
|
|
|
|
|
|
gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
|
2023-08-30 17:33:04 +00:00
|
|
|
|
2023-08-26 12:29:24 +00:00
|
|
|
gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
|
|
|
|
gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
|
|
|
|
|
|
|
|
gridCfg.override_connected = m_checkGridOverrideConnected->GetValue();
|
2023-08-30 17:33:04 +00:00
|
|
|
gridCfg.override_connected_idx = m_gridOverrideConnectedChoice->GetSelection();
|
2023-08-26 12:29:24 +00:00
|
|
|
gridCfg.override_wires = m_checkGridOverrideWires->GetValue();
|
2023-08-30 17:33:04 +00:00
|
|
|
gridCfg.override_wires_idx = m_gridOverrideWiresChoice->GetSelection();
|
2023-08-26 12:29:24 +00:00
|
|
|
gridCfg.override_vias = m_checkGridOverrideVias->GetValue();
|
2023-08-30 17:33:04 +00:00
|
|
|
gridCfg.override_vias_idx = m_gridOverrideViasChoice->GetSelection();
|
2023-08-26 12:29:24 +00:00
|
|
|
gridCfg.override_text = m_checkGridOverrideText->GetValue();
|
2023-08-30 17:33:04 +00:00
|
|
|
gridCfg.override_text_idx = m_gridOverrideTextChoice->GetSelection();
|
2023-08-26 12:29:24 +00:00
|
|
|
gridCfg.override_graphics = m_checkGridOverrideGraphics->GetValue();
|
2023-08-30 17:33:04 +00:00
|
|
|
gridCfg.override_graphics_idx = m_gridOverrideGraphicsChoice->GetSelection();
|
2023-08-26 12:29:24 +00:00
|
|
|
|
|
|
|
return RESETTABLE_PANEL::TransferDataFromWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_GRID_SETTINGS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
|
|
|
|
|
2023-08-30 17:33:04 +00:00
|
|
|
// lambda that gives us a safe index into grids regardless of config idx
|
|
|
|
auto safeGrid = [&gridCfg]( int idx ) -> int
|
|
|
|
{
|
|
|
|
if( idx < 0 || idx >= (int) gridCfg.grids.size() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return idx;
|
|
|
|
};
|
|
|
|
|
2023-08-26 12:29:24 +00:00
|
|
|
Layout();
|
|
|
|
|
2023-08-30 17:33:04 +00:00
|
|
|
m_currentGridCtrl->SetSelection( safeGrid( gridCfg.last_size_idx ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
|
2023-08-30 17:33:04 +00:00
|
|
|
m_grid1Ctrl->SetSelection( safeGrid( gridCfg.fast_grid_1 ) );
|
|
|
|
m_grid2Ctrl->SetSelection( safeGrid( gridCfg.fast_grid_2 ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
|
2023-08-30 17:33:04 +00:00
|
|
|
m_gridOverrideConnectedChoice->SetSelection( safeGrid( gridCfg.override_connected_idx ) );
|
|
|
|
m_gridOverrideWiresChoice->SetSelection( safeGrid( gridCfg.override_wires_idx ) );
|
|
|
|
m_gridOverrideViasChoice->SetSelection( safeGrid( gridCfg.override_vias_idx ) );
|
|
|
|
m_gridOverrideTextChoice->SetSelection( safeGrid( gridCfg.override_text_idx ) );
|
|
|
|
m_gridOverrideGraphicsChoice->SetSelection( safeGrid( gridCfg.override_graphics_idx ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
|
2023-08-30 17:33:04 +00:00
|
|
|
m_checkGridOverrideConnected->SetValue( safeGrid( gridCfg.override_connected ) );
|
|
|
|
m_checkGridOverrideWires->SetValue( safeGrid( gridCfg.override_wires ) );
|
|
|
|
m_checkGridOverrideVias->SetValue( safeGrid( gridCfg.override_vias ) );
|
|
|
|
m_checkGridOverrideText->SetValue( safeGrid( gridCfg.override_text ) );
|
|
|
|
m_checkGridOverrideGraphics->SetValue( safeGrid( gridCfg.override_graphics ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
|
|
|
|
return RESETTABLE_PANEL::TransferDataToWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_GRID_SETTINGS::OnAddGrid( wxCommandEvent& event )
|
|
|
|
{
|
2023-08-30 15:21:56 +00:00
|
|
|
GRID newGrid = GRID{ wxEmptyString, "", "" };
|
|
|
|
DIALOG_GRID_SETTINGS dlg( this->GetParent(), m_eventSource, m_unitsProvider, newGrid );
|
2023-08-26 12:29:24 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int row = m_currentGridCtrl->GetSelection();
|
|
|
|
GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
for( GRID& g : gridCfg.grids )
|
2023-08-26 12:29:24 +00:00
|
|
|
{
|
2023-08-30 15:21:56 +00:00
|
|
|
if( newGrid == g )
|
2023-08-26 12:29:24 +00:00
|
|
|
{
|
2023-08-30 15:21:56 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "Grid size '%s' already exists." ),
|
|
|
|
g.UserUnitsMessageText( m_unitsProvider ) ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
gridCfg.grids.insert( gridCfg.grids.begin() + row, newGrid );
|
2023-08-26 12:29:24 +00:00
|
|
|
RebuildGridSizes();
|
|
|
|
m_currentGridCtrl->SetSelection( row );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_GRID_SETTINGS::OnRemoveGrid( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
|
|
|
|
int row = m_currentGridCtrl->GetSelection();
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
if( gridCfg.grids.size() <= 1 )
|
2023-08-26 12:29:24 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "At least one grid size is required." ) ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
gridCfg.grids.erase( gridCfg.grids.begin() + row );
|
2023-08-26 12:29:24 +00:00
|
|
|
RebuildGridSizes();
|
|
|
|
|
|
|
|
if( row != 0 )
|
|
|
|
m_currentGridCtrl->SetSelection( row - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_GRID_SETTINGS::OnMoveGridUp( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
|
|
|
|
int row = m_currentGridCtrl->GetSelection();
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
if( gridCfg.grids.size() <= 1 || row == 0 )
|
2023-08-26 12:29:24 +00:00
|
|
|
return;
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
std::swap( gridCfg.grids[row], gridCfg.grids[row - 1] );
|
2023-08-26 12:29:24 +00:00
|
|
|
RebuildGridSizes();
|
|
|
|
|
|
|
|
if( row != 0 )
|
|
|
|
m_currentGridCtrl->SetSelection( row - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_GRID_SETTINGS::OnMoveGridDown( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
|
|
|
|
int row = m_currentGridCtrl->GetSelection();
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
if( gridCfg.grids.size() <= 1 || row == ( (int) gridCfg.grids.size() - 1 ) )
|
2023-08-26 12:29:24 +00:00
|
|
|
return;
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
std::swap( gridCfg.grids[row], gridCfg.grids[row + 1] );
|
2023-08-26 12:29:24 +00:00
|
|
|
RebuildGridSizes();
|
|
|
|
|
|
|
|
if( row != 0 )
|
|
|
|
m_currentGridCtrl->SetSelection( row + 1 );
|
|
|
|
}
|