2023-08-26 12:29:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2024-02-02 17:47:34 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2023-08-26 12:29:24 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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-10-25 12:59:12 +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
|
|
|
{
|
2024-02-05 05:52:11 +00:00
|
|
|
m_currentGridCtrl->SetMinSize( FromDIP( m_currentGridCtrl->GetMinSize() ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
RebuildGridSizes();
|
|
|
|
|
|
|
|
if( m_frameType == FRAME_PCB_EDITOR || m_frameType == FRAME_FOOTPRINT_EDITOR )
|
|
|
|
{
|
2024-02-03 16:31:37 +00:00
|
|
|
m_checkGridOverrideConnected->SetLabel( _( "Footprints/pads:" ) );
|
|
|
|
m_checkGridOverrideWires->SetLabel( _( "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
|
|
|
}
|
2024-03-10 18:21:29 +00:00
|
|
|
|
|
|
|
if( m_frameType == FRAME_GERBER )
|
|
|
|
{
|
|
|
|
m_overridesLabel->Show( false );
|
|
|
|
m_staticline3->Show( false );
|
|
|
|
|
|
|
|
m_checkGridOverrideText->Show( false );
|
|
|
|
m_gridOverrideTextChoice->Show( false );
|
|
|
|
|
|
|
|
m_checkGridOverrideGraphics->Show( false );
|
|
|
|
m_gridOverrideGraphicsChoice->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 ) ) );
|
|
|
|
|
2023-10-21 18:56:19 +00:00
|
|
|
m_addGridButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_removeGridButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
|
|
|
m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
|
|
|
|
m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
|
|
|
|
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, "", "" };
|
2024-02-02 17:47:34 +00:00
|
|
|
DIALOG_GRID_SETTINGS dlg( wxGetTopLevelParent( this ), 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
|
|
|
{
|
2024-02-02 17:47:34 +00:00
|
|
|
wxWindow* topLevelParent = wxGetTopLevelParent( this );
|
|
|
|
|
|
|
|
DisplayError( topLevelParent,
|
|
|
|
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
|
|
|
{
|
2024-02-02 17:47:34 +00:00
|
|
|
wxWindow* topLevelParent = wxGetTopLevelParent( this );
|
|
|
|
|
|
|
|
DisplayError( topLevelParent,
|
|
|
|
wxString::Format( _( "At least one grid size is required." ) ) );
|
2023-08-26 12:29:24 +00:00
|
|
|
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 );
|
|
|
|
}
|