2017-02-19 02:39:55 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-03-10 17:15:40 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-02-19 02:39:55 +00:00
|
|
|
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
|
|
|
|
* Copyright (C) 2016 Tomasz Wlostowski <tomasz.wlostowski@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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-01-09 13:44:57 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
#include "pcbnew_settings.h"
|
2023-06-20 13:15:56 +00:00
|
|
|
#include <advanced_config.h>
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <base_units.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2023-01-02 22:11:44 +00:00
|
|
|
#include <pcb_dimension.h>
|
2023-09-23 03:17:53 +00:00
|
|
|
#include <dpi_scaling_common.h>
|
2020-01-09 13:44:57 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2017-03-10 19:11:41 +00:00
|
|
|
#include <footprint_preview_panel.h>
|
2020-01-09 13:44:57 +00:00
|
|
|
#include <fp_lib_table.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2017-02-19 02:39:55 +00:00
|
|
|
#include <kiway.h>
|
|
|
|
#include <math/box2.h>
|
2020-07-26 11:17:38 +00:00
|
|
|
#include <pcb_painter.h>
|
2020-01-09 13:44:57 +00:00
|
|
|
#include <pcb_draw_panel_gal.h>
|
2018-11-03 12:35:17 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <pgm_base.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2020-01-09 13:44:57 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
#include <wx/stattext.h>
|
2020-12-01 19:27:42 +00:00
|
|
|
#include <zoom_defines.h>
|
2023-06-10 12:34:54 +00:00
|
|
|
#include <dialog_shim.h>
|
2023-09-28 03:15:54 +00:00
|
|
|
#include <project_pcb.h>
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2018-09-11 15:28:57 +00:00
|
|
|
FOOTPRINT_PREVIEW_PANEL::FOOTPRINT_PREVIEW_PANEL( KIWAY* aKiway, wxWindow* aParent,
|
2023-09-02 21:13:48 +00:00
|
|
|
UNITS_PROVIDER* aUnitsProvider,
|
2020-12-21 22:02:13 +00:00
|
|
|
std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> aOpts,
|
|
|
|
GAL_TYPE aGalType ) :
|
|
|
|
PCB_DRAW_PANEL_GAL( aParent, -1, wxPoint( 0, 0 ), wxSize( 200, 200 ), *aOpts, aGalType ),
|
|
|
|
KIWAY_HOLDER( aKiway, KIWAY_HOLDER::PANEL ),
|
|
|
|
m_displayOptions( std::move( aOpts ) ),
|
|
|
|
m_currentFootprint( nullptr )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-03 21:05:13 +00:00
|
|
|
SetStealsFocus( false );
|
2017-02-19 02:39:55 +00:00
|
|
|
ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
|
|
|
|
EnableScrolling( false, false ); // otherwise Zoom Auto disables GAL canvas
|
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
m_userUnits = aUnitsProvider->GetUserUnits();
|
2023-06-10 12:34:54 +00:00
|
|
|
|
2017-02-19 02:39:55 +00:00
|
|
|
m_dummyBoard = std::make_unique<BOARD>();
|
2023-03-05 13:27:22 +00:00
|
|
|
m_dummyBoard->SetUserUnits( m_userUnits );
|
2023-06-10 12:34:54 +00:00
|
|
|
m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
|
2020-01-13 01:44:19 +00:00
|
|
|
UpdateColors();
|
2020-01-09 14:18:41 +00:00
|
|
|
SyncLayersVisibility( m_dummyBoard.get() );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
|
|
|
Raise();
|
2018-09-11 15:28:57 +00:00
|
|
|
Show( true );
|
2017-02-19 02:39:55 +00:00
|
|
|
StartDrawing();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FOOTPRINT_PREVIEW_PANEL::~FOOTPRINT_PREVIEW_PANEL( )
|
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
if( m_currentFootprint )
|
2020-01-09 13:44:57 +00:00
|
|
|
{
|
2020-10-14 23:37:26 +00:00
|
|
|
GetView()->Remove( m_currentFootprint.get() );
|
2020-01-09 13:44:57 +00:00
|
|
|
GetView()->Clear();
|
2020-10-14 23:37:26 +00:00
|
|
|
m_currentFootprint->SetParent( nullptr );
|
2020-01-09 13:44:57 +00:00
|
|
|
}
|
2023-03-10 17:15:40 +00:00
|
|
|
|
|
|
|
if( m_otherFootprint )
|
|
|
|
{
|
|
|
|
GetView()->Remove( m_otherFootprint.get() );
|
|
|
|
GetView()->Clear();
|
|
|
|
m_otherFootprint->SetParent( nullptr );
|
|
|
|
}
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
const COLOR4D& FOOTPRINT_PREVIEW_PANEL::GetBackgroundColor() const
|
2020-08-10 01:29:15 +00:00
|
|
|
{
|
|
|
|
KIGFX::PAINTER* painter = GetView()->GetPainter();
|
|
|
|
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
|
|
|
|
|
|
|
return settings->GetBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
const COLOR4D& FOOTPRINT_PREVIEW_PANEL::GetForegroundColor() const
|
2020-08-10 01:29:15 +00:00
|
|
|
{
|
|
|
|
KIGFX::PAINTER* painter = GetView()->GetPainter();
|
|
|
|
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
|
|
|
|
2022-06-05 17:58:27 +00:00
|
|
|
return settings->GetLayerColor( F_Fab );
|
2020-08-10 01:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FOOTPRINT_PREVIEW_PANEL::renderFootprint( std::shared_ptr<FOOTPRINT> aFootprint )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2023-03-10 17:15:40 +00:00
|
|
|
aFootprint->SetParent( m_dummyBoard.get() );
|
2020-01-09 13:44:57 +00:00
|
|
|
|
2023-01-02 22:11:44 +00:00
|
|
|
INSPECTOR_FUNC inspector =
|
|
|
|
[&]( EDA_ITEM* descendant, void* aTestData )
|
|
|
|
{
|
2023-03-05 13:27:22 +00:00
|
|
|
static_cast<PCB_DIMENSION_BASE*>( descendant )->UpdateUnits();
|
2023-01-02 22:11:44 +00:00
|
|
|
return INSPECT_RESULT::CONTINUE;
|
|
|
|
};
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
aFootprint->Visit( inspector, nullptr, { PCB_DIM_LEADER_T,
|
|
|
|
PCB_DIM_ALIGNED_T,
|
|
|
|
PCB_DIM_ORTHOGONAL_T,
|
|
|
|
PCB_DIM_CENTER_T,
|
|
|
|
PCB_DIM_RADIAL_T } );
|
2023-01-02 22:11:44 +00:00
|
|
|
|
2020-07-26 11:17:38 +00:00
|
|
|
// Ensure we are not using the high contrast mode to display the selected footprint
|
|
|
|
KIGFX::PAINTER* painter = GetView()->GetPainter();
|
|
|
|
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
2021-12-26 00:36:12 +00:00
|
|
|
settings->m_ContrastModeDisplay = HIGH_CONTRAST_MODE::NORMAL;
|
2020-07-26 11:17:38 +00:00
|
|
|
|
2023-03-10 17:15:40 +00:00
|
|
|
GetView()->Add( aFootprint.get() );
|
|
|
|
GetView()->SetVisible( aFootprint.get(), true );
|
|
|
|
GetView()->Update( aFootprint.get(), KIGFX::ALL );
|
|
|
|
}
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2023-03-10 17:15:40 +00:00
|
|
|
|
|
|
|
void FOOTPRINT_PREVIEW_PANEL::fitToCurrentFootprint()
|
|
|
|
{
|
2024-01-28 14:34:10 +00:00
|
|
|
BOX2I bbox = m_currentFootprint->GetBoundingBox( false, false );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
|
|
|
if( bbox.GetSize().x > 0 && bbox.GetSize().y > 0 )
|
|
|
|
{
|
|
|
|
// Autozoom
|
|
|
|
GetView()->SetViewport( BOX2D( bbox.GetOrigin(), bbox.GetSize() ) );
|
|
|
|
|
|
|
|
// Add a margin
|
|
|
|
GetView()->SetScale( GetView()->GetScale() * 0.7 );
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
bool FOOTPRINT_PREVIEW_PANEL::DisplayFootprint( const LIB_ID& aFPID )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2023-03-10 17:15:40 +00:00
|
|
|
if( m_currentFootprint )
|
|
|
|
{
|
|
|
|
GetView()->Remove( m_currentFootprint.get() );
|
|
|
|
GetView()->Clear();
|
|
|
|
m_currentFootprint->SetParent( nullptr );
|
|
|
|
}
|
|
|
|
|
2023-09-28 03:15:54 +00:00
|
|
|
FP_LIB_TABLE* fptbl = PROJECT_PCB::PcbFootprintLibs( &Prj() );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
try
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
2023-01-02 22:11:44 +00:00
|
|
|
const FOOTPRINT* fp = fptbl->GetEnumeratedFootprint( aFPID.GetLibNickname(),
|
|
|
|
aFPID.GetLibItemName() );
|
2021-02-25 23:42:12 +00:00
|
|
|
|
|
|
|
if( fp )
|
|
|
|
m_currentFootprint.reset( static_cast<FOOTPRINT*>( fp->Duplicate() ) );
|
|
|
|
else
|
|
|
|
m_currentFootprint.reset();
|
2020-12-21 22:02:13 +00:00
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
m_currentFootprint.reset();
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
2023-03-10 17:15:40 +00:00
|
|
|
if( m_currentFootprint )
|
|
|
|
{
|
|
|
|
renderFootprint( m_currentFootprint );
|
|
|
|
fitToCurrentFootprint();
|
|
|
|
}
|
|
|
|
|
2023-09-04 10:12:20 +00:00
|
|
|
ForceRefresh();
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
return m_currentFootprint != nullptr;
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-10 17:15:40 +00:00
|
|
|
void FOOTPRINT_PREVIEW_PANEL::DisplayFootprints( std::shared_ptr<FOOTPRINT> aFootprintA,
|
|
|
|
std::shared_ptr<FOOTPRINT> aFootprintB )
|
|
|
|
{
|
|
|
|
if( m_currentFootprint )
|
|
|
|
{
|
|
|
|
GetView()->Remove( m_currentFootprint.get() );
|
|
|
|
m_currentFootprint->SetParent( nullptr );
|
|
|
|
|
|
|
|
wxASSERT( m_otherFootprint );
|
|
|
|
|
|
|
|
GetView()->Remove( m_otherFootprint.get() );
|
|
|
|
m_otherFootprint->SetParent( nullptr );
|
|
|
|
|
|
|
|
GetView()->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentFootprint = aFootprintA;
|
|
|
|
m_otherFootprint = aFootprintB;
|
|
|
|
|
|
|
|
if( m_currentFootprint )
|
|
|
|
{
|
|
|
|
wxASSERT( m_otherFootprint );
|
|
|
|
|
|
|
|
renderFootprint( m_currentFootprint );
|
|
|
|
renderFootprint( m_otherFootprint );
|
|
|
|
fitToCurrentFootprint();
|
|
|
|
}
|
|
|
|
|
|
|
|
Layout();
|
2023-03-11 12:42:58 +00:00
|
|
|
Show();
|
2023-03-10 17:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_PREVIEW_PANEL::RefreshAll()
|
|
|
|
{
|
|
|
|
GetView()->UpdateAllItems( KIGFX::REPAINT );
|
|
|
|
ForceRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
wxWindow* FOOTPRINT_PREVIEW_PANEL::GetWindow()
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-10 19:11:41 +00:00
|
|
|
return static_cast<wxWindow*>( this );
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::New( KIWAY* aKiway, wxWindow* aParent,
|
|
|
|
UNITS_PROVIDER* aUnitsProvider )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
|
2018-11-03 12:35:17 +00:00
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
if( cfg->m_Window.grid.grids.empty() )
|
|
|
|
cfg->m_Window.grid.grids = cfg->DefaultGridSizeList();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-12-01 19:27:42 +00:00
|
|
|
// Currently values read from config file are not used because the user cannot
|
|
|
|
// change this config
|
|
|
|
//if( cfg->m_Window.zoom_factors.empty() )
|
2020-06-17 18:00:58 +00:00
|
|
|
{
|
2023-06-20 13:15:56 +00:00
|
|
|
if( ADVANCED_CFG::GetCfg().m_HyperZoom )
|
|
|
|
cfg->m_Window.zoom_factors = { ZOOM_LIST_PCBNEW_HYPER };
|
|
|
|
else
|
|
|
|
cfg->m_Window.zoom_factors = { ZOOM_LIST_PCBNEW };
|
2018-11-03 12:35:17 +00:00
|
|
|
}
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2023-09-23 03:17:53 +00:00
|
|
|
std::unique_ptr<GAL_DISPLAY_OPTIONS_IMPL> gal_opts;
|
2020-06-17 18:00:58 +00:00
|
|
|
|
2023-09-23 03:17:53 +00:00
|
|
|
gal_opts = std::make_unique<GAL_DISPLAY_OPTIONS_IMPL>();
|
2020-06-17 18:00:58 +00:00
|
|
|
gal_opts->ReadConfig( *Pgm().GetCommonSettings(), cfg->m_Window, aParent );
|
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
auto galType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
|
|
|
|
FOOTPRINT_PREVIEW_PANEL* panel = new FOOTPRINT_PREVIEW_PANEL( aKiway, aParent, aUnitsProvider,
|
|
|
|
std::move( gal_opts ), galType );
|
2018-11-03 12:35:17 +00:00
|
|
|
|
2020-06-17 18:00:58 +00:00
|
|
|
panel->UpdateColors();
|
2018-11-03 12:35:17 +00:00
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
const GRID_SETTINGS& gridCfg = cfg->m_Window.grid;
|
2020-05-06 01:45:48 +00:00
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
panel->GetGAL()->SetGridVisibility( gridCfg.show );
|
|
|
|
|
2020-07-07 14:53:04 +00:00
|
|
|
//Bounds checking cannot include number of elements as an index!
|
2023-08-30 15:21:56 +00:00
|
|
|
int gridIdx = alg::clamp( 0, gridCfg.last_size_idx, (int) gridCfg.grids.size() - 1 );
|
|
|
|
double gridSizeX = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILS,
|
|
|
|
gridCfg.grids[gridIdx].x );
|
|
|
|
double gridSizeY = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILS,
|
|
|
|
gridCfg.grids[gridIdx].y );
|
|
|
|
panel->GetGAL()->SetGridSize( VECTOR2D( gridSizeX, gridSizeY ) );
|
2018-11-03 12:35:17 +00:00
|
|
|
|
2023-03-10 17:15:40 +00:00
|
|
|
auto painter = static_cast<KIGFX::PCB_PAINTER*>( panel->GetView()->GetPainter() );
|
|
|
|
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
|
|
|
settings->SetHighlight( false );
|
|
|
|
settings->SetNetColorMode( NET_COLOR_MODE::OFF );
|
|
|
|
|
2018-11-03 12:35:17 +00:00
|
|
|
return panel;
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|