KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_editor_tab_context.h
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
20#ifndef FOOTPRINT_EDITOR_TAB_CONTEXT_H
21#define FOOTPRINT_EDITOR_TAB_CONTEXT_H
22
23#include <map>
24#include <memory>
25
26#include <wx/string.h>
27
28#include <kiid.h>
30
31class BOARD;
32class FOOTPRINT;
33
34
46{
47public:
57
58 FOOTPRINT_EDITOR_TAB_CONTEXT( const wxString& aLib, const wxString& aName,
59 std::unique_ptr<BOARD> aBoard );
60
69 FOOTPRINT_EDITOR_TAB_CONTEXT( const KIID& aSourceUuid, const wxString& aReference,
70 std::unique_ptr<BOARD> aBoard );
71
73
80 static std::unique_ptr<FOOTPRINT_EDITOR_TAB_CONTEXT> MakeUnsaved( std::unique_ptr<BOARD> aBoard );
81
88 static wxString MakeInstanceTabKey( const KIID& aSourceUuid )
89 {
90 return wxString( wxT( "\x01@fp:" ) ) + aSourceUuid.AsString();
91 }
92
97 static wxString MakeUnsavedTabKey( const KIID& aSessionId )
98 {
99 return wxString( wxT( "\x01@import:" ) ) + aSessionId.AsString();
100 }
101
102 wxString GetTabKey() const override
103 {
104 switch( m_kind )
105 {
108 default: return m_lib + wxT( ":" ) + m_name;
109 }
110 }
111
112 wxString GetDisplayName( bool aShortForm = false ) const override;
113
120 void PromoteToLibrary( const wxString& aLib, const wxString& aName );
121
125 bool IsTransient() const { return m_kind != KIND::LIBRARY; }
126
127 bool IsFromBoard() const { return m_kind == KIND::BOARD_INSTANCE; }
128 bool IsUnsaved() const { return m_kind == KIND::UNSAVED; }
129 const KIID& GetSourceUuid() const { return m_sourceUuid; }
130 const wxString& GetReference() const { return m_reference; }
131
136 std::map<KIID, KIID>& BoardFootprintUuids() { return m_boardFootprintUuids; }
137
141 bool IsModified() const override;
142
143 void SetModified( bool aModified ) { m_modified = aModified; }
144
148 BOARD* GetBoard() const { return m_board.get(); }
149
150 const wxString& GetLib() const { return m_lib; }
151 const wxString& GetName() const { return m_name; }
152 void SetName( const wxString& aName ) { m_name = aName; }
153
158 void SetOriginalFootprintCopy( std::unique_ptr<FOOTPRINT> aCopy );
159
160 const wxString& GetFootprintNameWhenLoaded() const { return m_footprintNameWhenLoaded; }
161 void SetFootprintNameWhenLoaded( const wxString& aName ) { m_footprintNameWhenLoaded = aName; }
162
163private:
164 FOOTPRINT_EDITOR_TAB_CONTEXT( KIND aKind, std::unique_ptr<BOARD> aBoard );
165
166 wxString m_lib;
167 wxString m_name;
168 std::unique_ptr<BOARD> m_board;
169 std::unique_ptr<FOOTPRINT> m_originalFootprintCopy;
171 bool m_modified = false;
172
174
177
180
182 wxString m_reference;
183
185 std::map<KIID, KIID> m_boardFootprintUuids;
186};
187
188#endif // FOOTPRINT_EDITOR_TAB_CONTEXT_H
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
std::map< KIID, KIID > & BoardFootprintUuids()
Editor-to-board UUID remap captured at load, used by SaveFootprintToBoard to restore the original boa...
bool IsTransient() const
True for a tab that is session-only and not yet saved.
BOARD * GetBoard() const
The fp-holder board owned by this context.
KIID m_sourceUuid
Source board footprint UUID, used as the de-dup key and save-back target.
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.
void PromoteToLibrary(const wxString &aLib, const wxString &aName)
Give an imported footprint the library identity a save-as just assigned it.
std::map< KIID, KIID > m_boardFootprintUuids
Editor-to-board UUID remap used to save instance edits back to the original board items.
static wxString MakeUnsavedTabKey(const KIID &aSessionId)
De-duplication key for an imported footprint, in a namespace disjoint from the library and instance k...
~FOOTPRINT_EDITOR_TAB_CONTEXT() override
wxString GetDisplayName(bool aShortForm=false) const override
Short label shown on the tab.
static wxString MakeInstanceTabKey(const KIID &aSourceUuid)
De-duplication key for a placed board footprint, in a namespace disjoint from library keys.
KIID m_sessionId
Identity of an unsaved import, which has no library:name pair to key on.
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.
void SetFootprintNameWhenLoaded(const wxString &aName)
void SetOriginalFootprintCopy(std::unique_ptr< FOOTPRINT > aCopy)
const wxString & GetFootprintNameWhenLoaded() const
bool IsModified() const override
True only when dirty and the board actually holds a footprint to edit.
FOOTPRINT * GetOriginalFootprintCopy() const
Baseline clone captured at load, used to detect edits and to revert.
wxString GetTabKey() const override
Stable identity for persistence and de-duplication.
FOOTPRINT_EDITOR_TAB_CONTEXT(const wxString &aLib, const wxString &aName, std::unique_ptr< BOARD > aBoard)
wxString m_reference
Reference designator of the source footprint, shown as the tab label.
Definition kiid.h:46
wxString AsString() const
Definition kiid.cpp:264