2017-03-10 19:11:41 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __FOOTPRINT_PREVIEW_PANEL_H
|
|
|
|
#define __FOOTPRINT_PREVIEW_PANEL_H
|
|
|
|
|
|
|
|
#include <wx/wx.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <deque>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#include <pcb_draw_panel_gal.h>
|
|
|
|
#include <gal/gal_display_options.h>
|
|
|
|
#include <lib_id.h>
|
|
|
|
#include <kiway_player.h>
|
2017-11-01 11:14:16 +00:00
|
|
|
#include <core/optional.h>
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
#include <widgets/footprint_preview_widget.h>
|
|
|
|
|
|
|
|
class MODULE;
|
|
|
|
class KIWAY;
|
|
|
|
class IO_MGR;
|
|
|
|
class BOARD;
|
|
|
|
class FP_LOADER_THREAD;
|
|
|
|
class FP_THREAD_IFACE;
|
2017-08-04 12:43:02 +00:00
|
|
|
class COLORS_DESIGN_SETTINGS;
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Panel that renders a single footprint via Cairo GAL, meant to be exported
|
|
|
|
* through Kiface.
|
|
|
|
*/
|
|
|
|
class FOOTPRINT_PREVIEW_PANEL :
|
|
|
|
public PCB_DRAW_PANEL_GAL, public KIWAY_HOLDER, public FOOTPRINT_PREVIEW_PANEL_BASE
|
|
|
|
{
|
|
|
|
friend class FP_THREAD_IFACE;
|
|
|
|
friend class FP_LOADER_THREAD;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~FOOTPRINT_PREVIEW_PANEL( );
|
|
|
|
|
2020-01-09 14:18:41 +00:00
|
|
|
virtual void CacheFootprint( const LIB_ID& aFPID ) override;
|
2017-03-10 19:11:41 +00:00
|
|
|
|
2020-01-09 14:18:41 +00:00
|
|
|
virtual void DisplayFootprint( const LIB_ID& aFPID ) override;
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
virtual void SetStatusHandler( FOOTPRINT_STATUS_HANDLER aHandler ) override;
|
|
|
|
|
|
|
|
virtual wxWindow* GetWindow() override;
|
|
|
|
|
|
|
|
static FOOTPRINT_PREVIEW_PANEL* New( KIWAY* aKiway, wxWindow* aParent );
|
|
|
|
|
|
|
|
private:
|
2020-01-09 14:18:41 +00:00
|
|
|
struct CACHE_ENTRY
|
|
|
|
{
|
|
|
|
LIB_ID fpid;
|
2020-01-09 13:44:57 +00:00
|
|
|
std::shared_ptr<MODULE> module;
|
2020-01-09 14:18:41 +00:00
|
|
|
FOOTPRINT_STATUS status;
|
2017-03-10 19:11:41 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Create a new panel
|
|
|
|
*
|
|
|
|
* @param aKiway the connected KIWAY
|
|
|
|
* @param aParent the owning WX window
|
|
|
|
* @param aOpts the GAL options (ownership is assumed)
|
|
|
|
* @param aGalType the displayed GAL type
|
|
|
|
*/
|
|
|
|
FOOTPRINT_PREVIEW_PANEL( KIWAY* aKiway, wxWindow* aParent,
|
|
|
|
std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> aOpts, GAL_TYPE aGalType );
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
|
2020-01-09 14:18:41 +00:00
|
|
|
virtual CACHE_ENTRY CacheAndReturn( const LIB_ID& aFPID );
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
void OnLoaderThreadUpdate( wxCommandEvent& aEvent );
|
|
|
|
|
2020-01-09 13:44:57 +00:00
|
|
|
void renderFootprint( std::shared_ptr<MODULE> aModule );
|
2017-03-10 19:11:41 +00:00
|
|
|
|
2020-01-09 14:18:41 +00:00
|
|
|
FP_LOADER_THREAD* m_loader;
|
|
|
|
std::shared_ptr<FP_THREAD_IFACE> m_iface;
|
|
|
|
FOOTPRINT_STATUS_HANDLER m_handler;
|
|
|
|
|
|
|
|
std::unique_ptr<BOARD> m_dummyBoard;
|
|
|
|
std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> m_displayOptions;
|
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
|
|
|
std::unique_ptr<COLORS_DESIGN_SETTINGS> m_colorsSettings;
|
2017-03-10 19:11:41 +00:00
|
|
|
|
2020-01-09 13:44:57 +00:00
|
|
|
std::shared_ptr<MODULE> m_currentModule;
|
|
|
|
LIB_ID m_currentFPID;
|
|
|
|
bool m_footprintDisplayed;
|
2017-03-10 19:11:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|