KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_editor_tab_context.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <wx/translation.h>
23
24#include <board.h>
25#include <footprint.h>
26
27
29 const wxString& aName,
30 std::unique_ptr<BOARD> aBoard ) :
31 m_lib( aLib ),
32 m_name( aName ),
33 m_board( std::move( aBoard ) ),
35{
36}
37
38
40 const wxString& aReference,
41 std::unique_ptr<BOARD> aBoard ) :
42 m_board( std::move( aBoard ) ),
44 m_sourceUuid( aSourceUuid ),
45 m_reference( aReference )
46{
47}
48
49
51 m_board( std::move( aBoard ) ),
52 m_kind( aKind )
53{
54}
55
56
58
59
60std::unique_ptr<FOOTPRINT_EDITOR_TAB_CONTEXT>
61FOOTPRINT_EDITOR_TAB_CONTEXT::MakeUnsaved( std::unique_ptr<BOARD> aBoard )
62{
63 return std::unique_ptr<FOOTPRINT_EDITOR_TAB_CONTEXT>(
64 new FOOTPRINT_EDITOR_TAB_CONTEXT( KIND::UNSAVED, std::move( aBoard ) ) );
65}
66
67
69{
70 switch( m_kind )
71 {
73
74 // The imported name is not an identity the editor can save to, so the tab reads as unnamed
75 case KIND::UNSAVED: return _( "<unnamed>" );
76
77 default: return m_name;
78 }
79}
80
81
82void FOOTPRINT_EDITOR_TAB_CONTEXT::PromoteToLibrary( const wxString& aLib, const wxString& aName )
83{
84 wxCHECK( m_kind == KIND::UNSAVED, /* void */ );
85
87 m_lib = aLib;
88 m_name = aName;
90}
91
92
94{
95 return m_modified && m_board && m_board->GetFirstFootprint();
96}
97
98
99void FOOTPRINT_EDITOR_TAB_CONTEXT::SetOriginalFootprintCopy( std::unique_ptr<FOOTPRINT> aCopy )
100{
101 m_originalFootprintCopy = std::move( aCopy );
102}
KIID m_sourceUuid
Identity of an unsaved import, which has no library:name pair to key on.
std::unique_ptr< FOOTPRINT > m_originalFootprintCopy
KIND
What the tab edits, which decides its key, its label and whether it is persisted.
@ UNSAVED
An imported footprint with no library home yet, session-only.
@ BOARD_INSTANCE
A footprint pulled off a placed board footprint, session-only.
@ LIBRARY
A library footprint, keyed library:name and persisted across sessions.
wxString GetDisplayName() const override
Short label shown on the tab.
void PromoteToLibrary(const wxString &aLib, const wxString &aName)
Give an imported footprint the library identity a save-as just assigned it.
~FOOTPRINT_EDITOR_TAB_CONTEXT() override
static std::unique_ptr< FOOTPRINT_EDITOR_TAB_CONTEXT > MakeUnsaved(std::unique_ptr< BOARD > aBoard)
Construct a tab for an imported footprint that has no library identity yet.
KIND m_kind
Source board footprint UUID, used as the de-dup key and save-back target.
void SetOriginalFootprintCopy(std::unique_ptr< FOOTPRINT > aCopy)
bool IsModified() const override
True only when dirty and the board actually holds a footprint to edit.
FOOTPRINT_EDITOR_TAB_CONTEXT(const wxString &aLib, const wxString &aName, std::unique_ptr< BOARD > aBoard)
wxString m_reference
Editor-to-board UUID remap used to save instance edits back to the original board items.
Definition kiid.h:46
#define _(s)
STL namespace.