2017-02-19 02:39:55 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-07 04:26:33 +00:00
|
|
|
* Copyright (C) 2016-2019 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 <mutex>
|
|
|
|
#include <utility>
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
#include "pcbnew_settings.h"
|
2020-01-09 13:44:57 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#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>
|
|
|
|
#include <id.h>
|
|
|
|
#include <io_mgr.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>
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
/**
|
|
|
|
* Threadsafe interface class between loader thread and panel class.
|
|
|
|
*/
|
|
|
|
class FP_THREAD_IFACE
|
|
|
|
{
|
|
|
|
using CACHE_ENTRY = FOOTPRINT_PREVIEW_PANEL::CACHE_ENTRY;
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
public:
|
2020-01-09 14:18:41 +00:00
|
|
|
FP_THREAD_IFACE() : m_panel( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
/// Retrieve a cache entry by LIB_ID
|
2020-01-09 14:18:41 +00:00
|
|
|
OPT<CACHE_ENTRY> GetFromCache( const LIB_ID& aFPID )
|
2017-03-06 03:22:25 +00:00
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-10 19:11:41 +00:00
|
|
|
auto it = m_cachedFootprints.find( aFPID );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( it != m_cachedFootprints.end() )
|
|
|
|
return it->second;
|
|
|
|
else
|
2017-11-01 11:14:16 +00:00
|
|
|
return NULLOPT;
|
2017-03-10 19:11:41 +00:00
|
|
|
}
|
2017-03-06 03:22:25 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
/**
|
|
|
|
* Push an entry to the loading queue and a placeholder to the cache;
|
|
|
|
* return the placeholder.
|
|
|
|
*/
|
2020-01-09 14:18:41 +00:00
|
|
|
CACHE_ENTRY AddToQueue( const LIB_ID& aEntry )
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-06 03:22:25 +00:00
|
|
|
|
2020-01-09 13:44:57 +00:00
|
|
|
CACHE_ENTRY ent = { aEntry, nullptr, FPS_LOADING };
|
2017-03-10 19:11:41 +00:00
|
|
|
m_cachedFootprints[aEntry] = ent;
|
|
|
|
m_loaderQueue.push_back( ent );
|
2017-03-06 03:22:25 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
return ent;
|
|
|
|
}
|
2017-03-06 03:22:25 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
/// Pop an entry from the queue, or empty option if none is available.
|
2017-11-01 11:14:16 +00:00
|
|
|
OPT<CACHE_ENTRY> PopFromQueue()
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-06 03:22:25 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( m_loaderQueue.empty() )
|
|
|
|
{
|
2017-11-01 11:14:16 +00:00
|
|
|
return NULLOPT;
|
2017-03-10 19:11:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto ent = m_loaderQueue.front();
|
|
|
|
m_loaderQueue.pop_front();
|
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
}
|
2017-03-06 03:22:25 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
/// Add an entry to the cache.
|
2020-01-09 14:18:41 +00:00
|
|
|
void AddToCache( const CACHE_ENTRY& aEntry )
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-10 19:11:41 +00:00
|
|
|
m_cachedFootprints[aEntry.fpid] = aEntry;
|
|
|
|
}
|
2017-03-08 22:02:10 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
/**
|
|
|
|
* Threadsafe accessor to set the current footprint.
|
|
|
|
*/
|
|
|
|
void SetCurrentFootprint( LIB_ID aFp )
|
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-09-23 09:20:10 +00:00
|
|
|
m_current_fp = std::move( aFp );
|
2017-03-10 19:11:41 +00:00
|
|
|
}
|
2017-03-06 03:22:25 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
/**
|
|
|
|
* Threadsafe accessor to get the current footprint.
|
|
|
|
*/
|
|
|
|
LIB_ID GetCurrentFootprint()
|
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-10 19:11:41 +00:00
|
|
|
return m_current_fp;
|
2017-03-06 03:22:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 23:43:41 +00:00
|
|
|
/**
|
|
|
|
* Set the associated panel, for QueueEvent() and GetTable().
|
|
|
|
*/
|
|
|
|
void SetPanel( FOOTPRINT_PREVIEW_PANEL* aPanel )
|
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-26 23:43:41 +00:00
|
|
|
m_panel = aPanel;
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:23:03 +00:00
|
|
|
/**
|
|
|
|
* Get the associated panel.
|
|
|
|
*/
|
|
|
|
FOOTPRINT_PREVIEW_PANEL* GetPanel()
|
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-27 18:23:03 +00:00
|
|
|
return m_panel;
|
|
|
|
}
|
|
|
|
|
2017-03-26 23:43:41 +00:00
|
|
|
/**
|
|
|
|
* Post an event to the panel, if the panel still exists. Return whether
|
|
|
|
* the event was posted.
|
|
|
|
*/
|
2020-01-09 14:18:41 +00:00
|
|
|
bool QueueEvent( const wxEvent& aEvent )
|
2017-03-26 23:43:41 +00:00
|
|
|
{
|
2019-05-03 17:28:11 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-26 23:43:41 +00:00
|
|
|
|
|
|
|
if( m_panel )
|
|
|
|
{
|
|
|
|
m_panel->GetEventHandler()->QueueEvent( aEvent.Clone() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an FP_LIB_TABLE, or null if the panel is dead.
|
|
|
|
*/
|
|
|
|
FP_LIB_TABLE* GetTable()
|
|
|
|
{
|
2020-01-09 14:18:41 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_lock );
|
2017-03-26 23:43:41 +00:00
|
|
|
return m_panel ? m_panel->Prj().PcbFootprintLibs() : nullptr;
|
|
|
|
}
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
private:
|
2020-01-09 14:18:41 +00:00
|
|
|
std::deque<CACHE_ENTRY> m_loaderQueue;
|
2017-03-10 19:11:41 +00:00
|
|
|
std::map<LIB_ID, CACHE_ENTRY> m_cachedFootprints;
|
2020-01-09 14:18:41 +00:00
|
|
|
LIB_ID m_current_fp;
|
|
|
|
FOOTPRINT_PREVIEW_PANEL* m_panel;
|
|
|
|
std::mutex m_lock;
|
2017-03-06 03:22:25 +00:00
|
|
|
};
|
2017-02-19 02:39:55 +00:00
|
|
|
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
/**
|
|
|
|
* Footprint loader thread to prevent footprint loading from locking the UI.
|
|
|
|
* Interface is via a FP_THREAD_IFACE.
|
|
|
|
*/
|
2020-01-09 14:18:41 +00:00
|
|
|
class FP_LOADER_THREAD : public wxThread
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-10 19:11:41 +00:00
|
|
|
using CACHE_ENTRY = FOOTPRINT_PREVIEW_PANEL::CACHE_ENTRY;
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
std::shared_ptr<FP_THREAD_IFACE> m_iface;
|
|
|
|
|
|
|
|
public:
|
2020-01-09 14:18:41 +00:00
|
|
|
FP_LOADER_THREAD( const std::shared_ptr<FP_THREAD_IFACE>& aIface )
|
|
|
|
: wxThread( wxTHREAD_DETACHED ), m_iface( aIface )
|
|
|
|
{
|
|
|
|
}
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
~FP_LOADER_THREAD()
|
2020-01-09 14:18:41 +00:00
|
|
|
{
|
|
|
|
}
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ProcessEntry( CACHE_ENTRY& aEntry )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-26 23:43:41 +00:00
|
|
|
FP_LIB_TABLE* fptbl = m_iface->GetTable();
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( !fptbl )
|
|
|
|
return;
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2020-01-09 14:18:41 +00:00
|
|
|
try
|
|
|
|
{
|
2020-01-09 13:44:57 +00:00
|
|
|
aEntry.module.reset( fptbl->FootprintLoadWithOptionalNickname( aEntry.fpid ) );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( !aEntry.module )
|
|
|
|
aEntry.status = FPS_NOT_FOUND;
|
2020-01-09 14:18:41 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& )
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
|
|
|
aEntry.status = FPS_NOT_FOUND;
|
|
|
|
}
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( aEntry.status != FPS_NOT_FOUND )
|
|
|
|
aEntry.status = FPS_READY;
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
m_iface->AddToCache( aEntry );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( aEntry.fpid == m_iface->GetCurrentFootprint() )
|
|
|
|
{
|
2017-03-26 23:43:41 +00:00
|
|
|
wxCommandEvent evt( wxEVT_COMMAND_TEXT_UPDATED, 1 );
|
|
|
|
m_iface->QueueEvent( evt );
|
2017-03-10 19:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void* Entry() override
|
|
|
|
{
|
2017-03-27 18:23:03 +00:00
|
|
|
while( m_iface->GetPanel() )
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
|
|
|
auto ent = m_iface->PopFromQueue();
|
|
|
|
|
|
|
|
if( ent )
|
|
|
|
ProcessEntry( *ent );
|
|
|
|
else
|
|
|
|
wxMilliSleep( 100 );
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:23:03 +00:00
|
|
|
return nullptr;
|
2017-03-10 19:11:41 +00:00
|
|
|
}
|
|
|
|
};
|
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,
|
2020-01-09 13:44:57 +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 ),
|
2020-01-09 14:18:41 +00:00
|
|
|
m_displayOptions( std::move( aOpts ) ),
|
2020-01-09 13:44:57 +00:00
|
|
|
m_currentModule( nullptr ),
|
|
|
|
m_footprintDisplayed( true )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-10 19:11:41 +00:00
|
|
|
m_iface = std::make_shared<FP_THREAD_IFACE>();
|
2017-03-26 23:43:41 +00:00
|
|
|
m_iface->SetPanel( this );
|
|
|
|
m_loader = new FP_LOADER_THREAD( m_iface );
|
2017-02-19 02:39:55 +00:00
|
|
|
m_loader->Run();
|
|
|
|
|
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
|
|
|
|
|
|
|
|
m_dummyBoard = std::make_unique<BOARD>();
|
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();
|
|
|
|
|
2020-01-09 14:18:41 +00:00
|
|
|
Connect( wxEVT_COMMAND_TEXT_UPDATED,
|
|
|
|
wxCommandEventHandler( FOOTPRINT_PREVIEW_PANEL::OnLoaderThreadUpdate ), NULL, this );
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FOOTPRINT_PREVIEW_PANEL::~FOOTPRINT_PREVIEW_PANEL( )
|
|
|
|
{
|
2020-01-09 13:44:57 +00:00
|
|
|
if( m_currentModule )
|
|
|
|
{
|
|
|
|
GetView()->Remove( m_currentModule.get() );
|
|
|
|
GetView()->Clear();
|
|
|
|
m_currentModule->SetParent( nullptr );
|
|
|
|
}
|
|
|
|
|
2017-03-26 23:43:41 +00:00
|
|
|
m_iface->SetPanel( nullptr );
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-10 01:29:15 +00:00
|
|
|
const COLOR4D& FOOTPRINT_PREVIEW_PANEL::GetBackgroundColor()
|
|
|
|
{
|
|
|
|
KIGFX::PAINTER* painter = GetView()->GetPainter();
|
|
|
|
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
|
|
|
|
|
|
|
return settings->GetBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const COLOR4D& FOOTPRINT_PREVIEW_PANEL::GetForegroundColor()
|
|
|
|
{
|
|
|
|
KIGFX::PAINTER* painter = GetView()->GetPainter();
|
|
|
|
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
|
|
|
|
|
|
|
return settings->GetCursorColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
FOOTPRINT_PREVIEW_PANEL::CACHE_ENTRY FOOTPRINT_PREVIEW_PANEL::CacheAndReturn( const LIB_ID& aFPID )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-06 03:22:25 +00:00
|
|
|
auto opt_ent = m_iface->GetFromCache( aFPID );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
|
|
|
if( opt_ent )
|
|
|
|
return *opt_ent;
|
|
|
|
else
|
2017-03-06 03:22:25 +00:00
|
|
|
return m_iface->AddToQueue( aFPID );
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
// This is separate to avoid having to export CACHE_ENTRY to the global namespace
|
2020-01-09 14:18:41 +00:00
|
|
|
void FOOTPRINT_PREVIEW_PANEL::CacheFootprint( const LIB_ID& aFPID )
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
|
|
|
(void) CacheAndReturn( aFPID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-09 13:44:57 +00:00
|
|
|
void FOOTPRINT_PREVIEW_PANEL::renderFootprint( std::shared_ptr<MODULE> aModule )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2020-01-09 13:44:57 +00:00
|
|
|
if( m_currentModule )
|
|
|
|
{
|
|
|
|
GetView()->Remove( m_currentModule.get() );
|
|
|
|
GetView()->Clear();
|
|
|
|
m_currentModule->SetParent( nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
aModule->SetParent( m_dummyBoard.get() );
|
|
|
|
|
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() );
|
|
|
|
settings->SetContrastModeDisplay( HIGH_CONTRAST_MODE::NORMAL );
|
|
|
|
|
2020-01-09 13:44:57 +00:00
|
|
|
GetView()->Add( aModule.get() );
|
|
|
|
GetView()->SetVisible( aModule.get(), true );
|
|
|
|
GetView()->Update( aModule.get(), KIGFX::ALL );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2020-01-09 13:44:57 +00:00
|
|
|
// Save a reference to the module's shared pointer to say we are using it in the
|
|
|
|
// preview panel
|
|
|
|
m_currentModule = aModule;
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2020-01-09 13:44:57 +00:00
|
|
|
BOX2I bbox = aModule->ViewBBox();
|
|
|
|
bbox.Merge( aModule->Value().ViewBBox() );
|
|
|
|
bbox.Merge( aModule->Reference().ViewBBox() );
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_PREVIEW_PANEL::DisplayFootprint ( const LIB_ID& aFPID )
|
|
|
|
{
|
|
|
|
m_currentFPID = aFPID;
|
2017-03-10 19:11:41 +00:00
|
|
|
m_iface->SetCurrentFootprint( aFPID );
|
2017-02-19 02:39:55 +00:00
|
|
|
m_footprintDisplayed = false;
|
|
|
|
|
2020-01-09 14:18:41 +00:00
|
|
|
CACHE_ENTRY fpe = CacheAndReturn( m_currentFPID );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( m_handler )
|
|
|
|
m_handler( fpe.status );
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( fpe.status == FPS_READY )
|
|
|
|
{
|
2020-01-09 14:18:41 +00:00
|
|
|
if( !m_footprintDisplayed )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
|
|
|
renderFootprint( fpe.module );
|
|
|
|
m_footprintDisplayed = true;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-09 14:18:41 +00:00
|
|
|
void FOOTPRINT_PREVIEW_PANEL::OnLoaderThreadUpdate( wxCommandEvent& aEvent )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
|
|
|
DisplayFootprint( m_currentFPID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
void FOOTPRINT_PREVIEW_PANEL::SetStatusHandler( FOOTPRINT_STATUS_HANDLER aHandler )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-10 19:11:41 +00:00
|
|
|
m_handler = aHandler;
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::New( KIWAY* aKiway, wxWindow* aParent )
|
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
|
2018-11-03 12:35:17 +00:00
|
|
|
|
2020-06-17 18:00:58 +00:00
|
|
|
if( cfg->m_Window.grid.sizes.empty() )
|
2018-11-03 12:35:17 +00:00
|
|
|
{
|
2020-06-17 18:00:58 +00:00
|
|
|
cfg->m_Window.grid.sizes = { "1000 mil",
|
|
|
|
"500 mil",
|
|
|
|
"250 mil",
|
|
|
|
"200 mil",
|
|
|
|
"100 mil",
|
|
|
|
"50 mil",
|
|
|
|
"25 mil",
|
|
|
|
"20 mil",
|
|
|
|
"10 mil",
|
|
|
|
"5 mil",
|
|
|
|
"2 mil",
|
|
|
|
"1 mil",
|
|
|
|
"5.0 mm",
|
|
|
|
"2.5 mm",
|
|
|
|
"1.0 mm",
|
|
|
|
"0.5 mm",
|
|
|
|
"0.25 mm",
|
|
|
|
"0.2 mm",
|
|
|
|
"0.1 mm",
|
|
|
|
"0.05 mm",
|
|
|
|
"0.025 mm",
|
|
|
|
"0.01 mm" };
|
2018-11-03 12:35:17 +00:00
|
|
|
}
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-06-17 18:00:58 +00:00
|
|
|
if( cfg->m_Window.zoom_factors.empty() )
|
|
|
|
{
|
|
|
|
cfg->m_Window.zoom_factors = { 0.035,
|
|
|
|
0.05,
|
|
|
|
0.08,
|
|
|
|
0.13,
|
|
|
|
0.22,
|
|
|
|
0.35,
|
|
|
|
0.6,
|
|
|
|
1.0,
|
|
|
|
1.5,
|
|
|
|
2.2,
|
|
|
|
3.5,
|
|
|
|
5.0,
|
|
|
|
8.0,
|
|
|
|
13.0,
|
|
|
|
20.0,
|
|
|
|
35.0,
|
|
|
|
50.0,
|
|
|
|
80.0,
|
|
|
|
130.0,
|
|
|
|
220.0,
|
|
|
|
300.0 };
|
2018-11-03 12:35:17 +00:00
|
|
|
}
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2020-06-17 18:00:58 +00:00
|
|
|
for( double& factor : cfg->m_Window.zoom_factors )
|
|
|
|
factor = std::min( factor, MAX_ZOOM_FACTOR );
|
|
|
|
|
|
|
|
std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> gal_opts;
|
|
|
|
|
|
|
|
gal_opts = std::make_unique<KIGFX::GAL_DISPLAY_OPTIONS>();
|
|
|
|
gal_opts->ReadConfig( *Pgm().GetCommonSettings(), cfg->m_Window, aParent );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
auto canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
|
Pcbnew: FOOTPRINT_PREVIEW_PANEL passes reference to local
Previously, the GAL_DISPLAY_OPTIONS object in FOOTPRINT_PREVIEW_PANEL::New
was passed by reference in the ctor, down to EDA_DRAW_PANEL_GAL, which stored
it as a reference. The object in New() then goes out of scope, so the
referencing panel outlives the options.
Fix this by making a copy in a std::unique_ptr of the options, and giving
ownership to the panel.
There is another issue here: when the Pcbnew options are copies, the
OBSERVABLE subscriber list is copied too. This means if the panel called
NotifyChanged() on the options, Pcbnew would get updates, even though a copy
of the options changed. However, the panel doesn't change the options or
notify, so it's OK for now.
2019-04-11 11:06:50 +00:00
|
|
|
auto panel = new FOOTPRINT_PREVIEW_PANEL( aKiway, aParent, std::move( gal_opts ), canvasType );
|
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!
|
|
|
|
int gridIdx = std::max( 0, std::min( gridCfg.last_size_idx, (int) gridCfg.sizes.size() - 1 ) );
|
2020-10-02 22:04:16 +00:00
|
|
|
int gridSize = (int) ValueFromString( EDA_UNITS::MILS, gridCfg.sizes[ gridIdx ] );
|
2020-06-12 10:58:56 +00:00
|
|
|
panel->GetGAL()->SetGridSize( VECTOR2D( gridSize, gridSize ) );
|
2018-11-03 12:35:17 +00:00
|
|
|
|
|
|
|
return panel;
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|