2014-07-09 11:50:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 CERN
|
2022-01-20 09:43:40 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-07-09 11:50:27 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2014-07-09 11:50:27 +00:00
|
|
|
#include <pcb_base_edit_frame.h>
|
2015-08-15 14:00:34 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2021-04-12 10:10:22 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tools/pcb_selection_tool.h>
|
2020-05-06 01:45:48 +00:00
|
|
|
#include <pcbnew_settings.h>
|
|
|
|
#include <pgm_base.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-06-11 16:59:28 +00:00
|
|
|
#include <pcb_dimension.h>
|
2021-04-12 10:10:22 +00:00
|
|
|
#include <footprint_info_impl.h>
|
2018-08-03 16:53:38 +00:00
|
|
|
#include <project.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/color_settings.h>
|
2020-05-06 01:45:48 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2020-07-11 17:42:00 +00:00
|
|
|
#include <widgets/appearance_controls.h>
|
2020-08-19 10:31:20 +00:00
|
|
|
#include <dialogs/eda_view_switcher.h>
|
2020-09-25 01:26:23 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <collectors.h>
|
2020-09-25 01:26:23 +00:00
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
|
|
|
|
PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
|
|
|
|
FRAME_T aFrameType, const wxString& aTitle,
|
|
|
|
const wxPoint& aPos, const wxSize& aSize, long aStyle,
|
|
|
|
const wxString& aFrameName ) :
|
|
|
|
PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
|
2022-01-13 20:04:14 +00:00
|
|
|
m_undoRedoBlocked( false ),
|
2020-08-19 22:46:57 +00:00
|
|
|
m_selectionFilterPanel( nullptr ),
|
|
|
|
m_appearancePanel( nullptr )
|
2018-08-03 16:53:38 +00:00
|
|
|
{
|
2021-04-12 10:10:22 +00:00
|
|
|
Bind( wxEVT_IDLE,
|
|
|
|
[this]( wxIdleEvent& aEvent )
|
|
|
|
{
|
|
|
|
// Handle cursor adjustments. While we can get motion and key events through
|
|
|
|
// wxWidgets, we can't get modifier-key-up events.
|
|
|
|
if( m_toolManager )
|
|
|
|
{
|
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
|
|
|
|
if( selTool )
|
|
|
|
selTool->OnIdle( aEvent );
|
|
|
|
}
|
|
|
|
} );
|
2018-08-03 16:53:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-09 15:13:42 +00:00
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
PCB_BASE_EDIT_FRAME::~PCB_BASE_EDIT_FRAME()
|
|
|
|
{
|
2020-08-09 15:13:42 +00:00
|
|
|
GetCanvas()->GetView()->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-24 02:01:14 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::doCloseWindow()
|
2020-08-09 15:13:42 +00:00
|
|
|
{
|
|
|
|
SETTINGS_MANAGER* mgr = GetSettingsManager();
|
2021-02-04 00:05:46 +00:00
|
|
|
wxFileName projectName( Prj().GetProjectFullName() );
|
2020-08-09 15:13:42 +00:00
|
|
|
|
2021-02-04 00:05:46 +00:00
|
|
|
if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( projectName.GetPath() )
|
|
|
|
&& projectName.Exists() )
|
2019-12-25 20:53:22 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
GFootprintList.WriteCacheToFile( Prj().GetProjectPath() + wxT( "fp-info-cache" ) );
|
2019-12-25 20:53:22 +00:00
|
|
|
}
|
2019-09-23 13:41:44 +00:00
|
|
|
|
2020-08-08 20:52:57 +00:00
|
|
|
// Close the project if we are standalone, so it gets cleaned up properly
|
2020-08-09 15:13:42 +00:00
|
|
|
if( mgr->IsProjectOpen() && Kiface().IsSingle() )
|
2021-02-04 00:05:46 +00:00
|
|
|
mgr->UnloadProject( &Prj(), false );
|
2018-08-03 16:53:38 +00:00
|
|
|
}
|
2018-07-23 11:37:01 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
|
2020-08-19 10:31:20 +00:00
|
|
|
bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
|
|
|
|
{
|
2021-10-24 22:07:06 +00:00
|
|
|
static bool s_presetSwitcherShown = false;
|
|
|
|
static bool s_viewportSwitcherShown = false;
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2022-01-08 22:23:44 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
wxKeyCode presetSwitchKey = WXK_RAW_CONTROL;
|
|
|
|
wxKeyCode viewSwitchKey = WXK_ALT;
|
|
|
|
#else
|
|
|
|
wxKeyCode presetSwitchKey = WXK_RAW_CONTROL;
|
|
|
|
wxKeyCode viewSwitchKey = WXK_WINDOWS_LEFT;
|
|
|
|
#endif
|
|
|
|
|
2022-01-14 03:28:45 +00:00
|
|
|
if( aEvent.GetEventType() != wxEVT_CHAR && aEvent.GetEventType() != wxEVT_CHAR_HOOK )
|
|
|
|
return PCB_BASE_FRAME::TryBefore( aEvent );
|
|
|
|
|
2022-01-08 22:23:44 +00:00
|
|
|
if( !s_presetSwitcherShown && wxGetKeyState( presetSwitchKey ) && wxGetKeyState( WXK_TAB ) )
|
2020-08-19 10:31:20 +00:00
|
|
|
{
|
2020-08-19 23:43:35 +00:00
|
|
|
if( m_appearancePanel && this->IsActive() )
|
2020-08-19 22:46:57 +00:00
|
|
|
{
|
|
|
|
const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2022-01-07 23:33:19 +00:00
|
|
|
if( mru.size() > 1 )
|
|
|
|
{
|
2022-01-08 22:23:44 +00:00
|
|
|
EDA_VIEW_SWITCHER switcher( this, mru, presetSwitchKey );
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2022-01-07 23:33:19 +00:00
|
|
|
s_presetSwitcherShown = true;
|
|
|
|
switcher.ShowModal();
|
|
|
|
s_presetSwitcherShown = false;
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2022-01-07 23:33:19 +00:00
|
|
|
int idx = switcher.GetSelection();
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2022-01-07 23:33:19 +00:00
|
|
|
if( idx >= 0 && idx < (int) mru.size() )
|
|
|
|
m_appearancePanel->ApplyLayerPreset( mru[idx] );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-19 22:46:57 +00:00
|
|
|
}
|
2020-08-19 10:31:20 +00:00
|
|
|
}
|
2022-01-08 22:23:44 +00:00
|
|
|
else if( !s_viewportSwitcherShown && wxGetKeyState( viewSwitchKey ) && wxGetKeyState( WXK_TAB ) )
|
2021-10-24 22:07:06 +00:00
|
|
|
{
|
|
|
|
if( m_appearancePanel && this->IsActive() )
|
|
|
|
{
|
|
|
|
const wxArrayString& mru = m_appearancePanel->GetViewportsMRU();
|
|
|
|
|
2022-01-07 23:33:19 +00:00
|
|
|
if( mru.size() > 1 )
|
|
|
|
{
|
2022-01-08 22:23:44 +00:00
|
|
|
EDA_VIEW_SWITCHER switcher( this, mru, viewSwitchKey );
|
2022-01-07 23:33:19 +00:00
|
|
|
|
|
|
|
s_viewportSwitcherShown = true;
|
|
|
|
switcher.ShowModal();
|
|
|
|
s_viewportSwitcherShown = false;
|
2021-10-24 22:07:06 +00:00
|
|
|
|
2022-01-07 23:33:19 +00:00
|
|
|
int idx = switcher.GetSelection();
|
2021-10-24 22:07:06 +00:00
|
|
|
|
2022-01-07 23:33:19 +00:00
|
|
|
if( idx >= 0 && idx < (int) mru.size() )
|
|
|
|
m_appearancePanel->ApplyViewport( mru[idx] );
|
2021-10-24 22:07:06 +00:00
|
|
|
|
2022-01-07 23:33:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-24 22:07:06 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-19 10:31:20 +00:00
|
|
|
|
|
|
|
return PCB_BASE_FRAME::TryBefore( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-20 09:43:40 +00:00
|
|
|
EDA_ANGLE PCB_BASE_EDIT_FRAME::GetRotationAngle() const
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
2022-01-20 09:43:40 +00:00
|
|
|
// Return a default angle (90 degrees) used for rotate operations.
|
|
|
|
return ANGLE_90;
|
2014-07-09 11:50:27 +00:00
|
|
|
}
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2015-02-18 19:27:00 +00:00
|
|
|
|
2019-05-30 12:25:08 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::ActivateGalCanvas()
|
2015-08-07 17:15:36 +00:00
|
|
|
{
|
2019-05-30 12:25:08 +00:00
|
|
|
PCB_BASE_FRAME::ActivateGalCanvas();
|
2015-08-07 17:15:36 +00:00
|
|
|
|
2020-09-30 22:02:05 +00:00
|
|
|
GetCanvas()->SyncLayersVisibility( m_pcb );
|
2015-08-07 17:15:36 +00:00
|
|
|
}
|
2015-08-15 14:00:34 +00:00
|
|
|
|
|
|
|
|
2021-11-25 16:19:03 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
|
2015-08-15 14:00:34 +00:00
|
|
|
{
|
2020-09-30 22:02:05 +00:00
|
|
|
bool new_board = ( aBoard != m_pcb );
|
2015-08-15 14:00:34 +00:00
|
|
|
|
2020-09-25 01:26:23 +00:00
|
|
|
if( new_board )
|
|
|
|
{
|
|
|
|
if( m_toolManager )
|
|
|
|
m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
|
|
|
|
|
|
|
|
GetCanvas()->GetView()->Clear();
|
|
|
|
GetCanvas()->GetView()->InitPreview();
|
|
|
|
}
|
|
|
|
|
2021-11-25 16:19:03 +00:00
|
|
|
PCB_BASE_FRAME::SetBoard( aBoard, aReporter );
|
2020-09-25 01:26:23 +00:00
|
|
|
|
2021-11-09 03:36:40 +00:00
|
|
|
GetCanvas()->GetGAL()->SetGridOrigin( VECTOR2D( aBoard->GetDesignSettings().GetGridOrigin() ) );
|
2016-01-13 18:37:52 +00:00
|
|
|
|
2020-09-30 23:04:31 +00:00
|
|
|
if( new_board )
|
|
|
|
{
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
|
|
|
|
bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
|
|
|
|
}
|
|
|
|
|
2015-08-15 14:00:34 +00:00
|
|
|
// update the tool manager with the new board and its view.
|
|
|
|
if( m_toolManager )
|
|
|
|
{
|
2021-11-25 16:19:03 +00:00
|
|
|
GetCanvas()->DisplayBoard( aBoard, aReporter );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
GetCanvas()->UpdateColors();
|
2019-06-13 17:28:55 +00:00
|
|
|
m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
|
2020-06-12 10:58:56 +00:00
|
|
|
GetCanvas()->GetViewControls(), config(), this );
|
2015-08-15 14:00:34 +00:00
|
|
|
|
|
|
|
if( new_board )
|
2020-09-26 16:06:32 +00:00
|
|
|
m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
|
2015-08-15 14:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-10 09:48:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_EDIT_FRAME::unitsChangeRefresh()
|
|
|
|
{
|
|
|
|
PCB_BASE_FRAME::unitsChangeRefresh();
|
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
if( BOARD* board = GetBoard() )
|
|
|
|
{
|
|
|
|
EDA_UNITS units = GetUserUnits();
|
|
|
|
KIGFX::VIEW* view = GetCanvas()->GetView();
|
2022-04-17 13:02:19 +00:00
|
|
|
bool selectedItemModified = false;
|
2020-09-11 23:52:45 +00:00
|
|
|
|
|
|
|
INSPECTOR_FUNC inspector =
|
2022-04-17 13:02:19 +00:00
|
|
|
[units, view, &selectedItemModified]( EDA_ITEM* aItem, void* aTestData )
|
2020-09-11 23:52:45 +00:00
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
|
2020-09-11 23:52:45 +00:00
|
|
|
|
|
|
|
if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
|
|
|
|
{
|
2020-10-02 20:51:24 +00:00
|
|
|
dimension->SetUnits( units );
|
2020-09-11 23:52:45 +00:00
|
|
|
dimension->Update();
|
2022-04-17 13:02:19 +00:00
|
|
|
|
|
|
|
if( dimension->IsSelected() )
|
|
|
|
selectedItemModified = true;
|
|
|
|
|
2020-09-11 23:52:45 +00:00
|
|
|
view->Update( dimension );
|
|
|
|
}
|
|
|
|
|
|
|
|
return SEARCH_RESULT::CONTINUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
board->Visit( inspector, nullptr, GENERAL_COLLECTOR::Dimensions );
|
2022-04-17 13:02:19 +00:00
|
|
|
|
|
|
|
if( selectedItemModified )
|
|
|
|
m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
|
2020-09-11 23:52:45 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 09:48:16 +00:00
|
|
|
ReCreateAuxiliaryToolbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-23 22:43:54 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::SetGridVisibility( bool aVisible )
|
|
|
|
{
|
|
|
|
PCB_BASE_FRAME::SetGridVisibility( aVisible );
|
|
|
|
|
2019-11-24 00:51:54 +00:00
|
|
|
// Update the grid checkbox in the layer widget
|
2020-07-11 17:42:00 +00:00
|
|
|
if( m_appearancePanel )
|
|
|
|
m_appearancePanel->SetObjectVisible( LAYER_GRID, aVisible );
|
2019-11-23 22:43:54 +00:00
|
|
|
}
|
2020-05-06 01:45:48 +00:00
|
|
|
|
|
|
|
|
2020-10-17 19:52:51 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::SetObjectVisible( GAL_LAYER_ID aLayer, bool aVisible )
|
|
|
|
{
|
|
|
|
if( m_appearancePanel )
|
|
|
|
m_appearancePanel->SetObjectVisible( aLayer, aVisible );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-07 20:34:10 +00:00
|
|
|
COLOR_SETTINGS* PCB_BASE_EDIT_FRAME::GetColorSettings( bool aForceRefresh ) const
|
2020-05-06 01:45:48 +00:00
|
|
|
{
|
2021-12-26 00:36:12 +00:00
|
|
|
return Pgm().GetSettingsManager().GetColorSettings( Settings().m_ColorTheme );
|
2020-05-06 01:45:48 +00:00
|
|
|
}
|
2020-07-13 11:21:40 +00:00
|
|
|
|
|
|
|
|
2020-09-25 01:26:23 +00:00
|
|
|
wxString PCB_BASE_EDIT_FRAME::GetDesignRulesPath()
|
|
|
|
{
|
|
|
|
if( !GetBoard() )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
wxFileName fn = GetBoard()->GetFileName();
|
|
|
|
fn.SetExt( DesignRulesFileExtension );
|
|
|
|
return Prj().AbsolutePath( fn.GetFullName() );
|
|
|
|
}
|
2021-03-26 01:24:12 +00:00
|
|
|
|
2021-04-07 15:53:43 +00:00
|
|
|
|
2021-03-26 01:24:12 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
|
|
|
|
{
|
2021-10-25 12:02:00 +00:00
|
|
|
PCB_BASE_FRAME::handleActivateEvent( aEvent );
|
2021-03-26 01:24:12 +00:00
|
|
|
|
|
|
|
// The text in the collapsible pane headers need to be updated
|
2021-03-28 03:48:07 +00:00
|
|
|
if( m_appearancePanel )
|
|
|
|
m_appearancePanel->RefreshCollapsiblePanes();
|
2021-03-26 01:24:12 +00:00
|
|
|
}
|
2021-04-07 15:53:43 +00:00
|
|
|
|
|
|
|
|