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
|
2020-08-19 10:31:20 +00:00
|
|
|
* Copyright (C) 2020 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
|
|
|
|
*/
|
|
|
|
|
2020-08-08 20:52:57 +00:00
|
|
|
#include <kiface_i.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>
|
2020-05-06 01:45:48 +00:00
|
|
|
#include <pcbnew_settings.h>
|
|
|
|
#include <pgm_base.h>
|
2015-08-15 14:00:34 +00:00
|
|
|
#include <class_board.h>
|
2018-08-03 16:53:38 +00:00
|
|
|
#include "footprint_info_impl.h"
|
|
|
|
#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>
|
2018-10-10 09:48:16 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2020-06-14 15:08:47 +00:00
|
|
|
#include <dialogs/dialog_grid_settings.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>
|
|
|
|
#include <layer_widget.h>
|
2020-09-11 23:52:45 +00:00
|
|
|
#include <class_dimension.h>
|
2020-09-25 01:26:23 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
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 ),
|
2020-01-11 16:56:25 +00:00
|
|
|
m_rotationAngle( 900 ), 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
|
|
|
{
|
2018-08-04 23:07:25 +00:00
|
|
|
if( !GFootprintList.GetCount() )
|
2018-08-03 16:53:38 +00:00
|
|
|
{
|
|
|
|
wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
|
|
|
|
GFootprintList.ReadCacheFromFile( &footprintInfoCache );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( Prj().GetProjectPath() ) )
|
2019-12-25 20:53:22 +00:00
|
|
|
{
|
|
|
|
wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
|
|
|
|
GFootprintList.WriteCacheToFile( &footprintInfoCache );
|
|
|
|
}
|
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() )
|
|
|
|
mgr->UnloadProject( &Prj() );
|
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 )
|
|
|
|
{
|
|
|
|
static bool s_switcherShown = false;
|
|
|
|
|
|
|
|
if( !s_switcherShown && wxGetKeyState( WXK_RAW_CONTROL ) && wxGetKeyState( WXK_TAB ) )
|
|
|
|
{
|
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();
|
|
|
|
EDA_VIEW_SWITCHER switcher( this, mru );
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2020-08-19 22:46:57 +00:00
|
|
|
s_switcherShown = true;
|
|
|
|
switcher.ShowModal();
|
|
|
|
s_switcherShown = false;
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2020-08-19 22:46:57 +00:00
|
|
|
int idx = switcher.GetSelection();
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2020-08-19 22:46:57 +00:00
|
|
|
if( idx >= 0 && idx < (int) mru.size() )
|
|
|
|
m_appearancePanel->ApplyLayerPreset( mru[idx] );
|
2020-08-19 10:31:20 +00:00
|
|
|
|
2020-08-19 22:46:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-08-19 10:31:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return PCB_BASE_FRAME::TryBefore( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
|
|
|
|
{
|
|
|
|
wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
|
|
|
|
wxT( "Invalid rotation angle, defaulting to 90." ) );
|
|
|
|
|
|
|
|
m_rotationAngle = aRotationAngle;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard )
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_BASE_FRAME::SetBoard( aBoard );
|
|
|
|
|
2020-07-01 12:28:10 +00:00
|
|
|
GetCanvas()->GetGAL()->SetGridOrigin( VECTOR2D( aBoard->GetDesignSettings().m_GridOrigin ) );
|
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 )
|
|
|
|
{
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->DisplayBoard( aBoard );
|
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();
|
|
|
|
|
|
|
|
INSPECTOR_FUNC inspector =
|
|
|
|
[units, view]( EDA_ITEM* aItem, void* aTestData )
|
|
|
|
{
|
|
|
|
DIMENSION* dimension = static_cast<DIMENSION*>( aItem );
|
|
|
|
|
|
|
|
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();
|
|
|
|
view->Update( dimension );
|
|
|
|
}
|
|
|
|
|
|
|
|
return SEARCH_RESULT::CONTINUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
board->Visit( inspector, nullptr, GENERAL_COLLECTOR::Dimensions );
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-16 17:15:43 +00:00
|
|
|
COLOR_SETTINGS* PCB_BASE_EDIT_FRAME::GetColorSettings()
|
2020-05-06 01:45:48 +00:00
|
|
|
{
|
|
|
|
return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
|
|
|
|
}
|
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() );
|
|
|
|
}
|