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
68 FOOTPRINT_EDITOR_TAB_CONTEXT( const KIID& aSourceUuid, const wxString& aReference,
69 std::unique_ptr<BOARD> aBoard );
70
72
79 static std::unique_ptr<FOOTPRINT_EDITOR_TAB_CONTEXT> MakeUnsaved( std::unique_ptr<BOARD> aBoard );
80
87 static wxString MakeInstanceTabKey( const KIID& aSourceUuid )
88 {
89 return wxString( wxT( "\x01@fp:" ) ) + aSourceUuid.AsString();
90 }
91
96 static wxString MakeUnsavedTabKey( const KIID& aSessionId )
97 {
98 return wxString( wxT( "\x01@import:" ) ) + aSessionId.AsString();
99 }
100
101 wxString GetTabKey() const override
102 {
103 switch( m_kind )
104 {
107 default: return m_lib + wxT( ":" ) + m_name;
108 }
109 }
110
111 wxString GetDisplayName() const override;
112
119 void PromoteToLibrary( const wxString& aLib, const wxString& aName );
120
124 bool IsTransient() const { return m_kind != KIND::LIBRARY; }
125
126 bool IsFromBoard() const { return m_kind == KIND::BOARD_INSTANCE; }
127 bool IsUnsaved() const { return m_kind == KIND::UNSAVED; }
128 const KIID& GetSourceUuid() const { return m_sourceUuid; }
129 const wxString& GetReference() const { return m_reference; }
130
135 std::map<KIID, KIID>& BoardFootprintUuids() { return m_boardFootprintUuids; }
136
140 bool IsModified() const override;
141
142 void SetModified( bool aModified ) { m_modified = aModified; }
143
147 BOARD* GetBoard() const { return m_board.get(); }
148
149 const wxString& GetLib() const { return m_lib; }
150 const wxString& GetName() const { return m_name; }
151 void SetName( const wxString& aName ) { m_name = aName; }
152
157 void SetOriginalFootprintCopy( std::unique_ptr<FOOTPRINT> aCopy );
158
159 const wxString& GetFootprintNameWhenLoaded() const { return m_footprintNameWhenLoaded; }
160 void SetFootprintNameWhenLoaded( const wxString& aName ) { m_footprintNameWhenLoaded = aName; }
161
162private:
163 FOOTPRINT_EDITOR_TAB_CONTEXT( KIND aKind, std::unique_ptr<BOARD> aBoard );
164
165 wxString m_lib;
166 wxString m_name;
167 std::unique_ptr<BOARD> m_board;
168 std::unique_ptr<FOOTPRINT> m_originalFootprintCopy;
170 bool m_modified = false;
171
173
176
179
181 wxString m_reference;
182
184 std::map<KIID, KIID> m_boardFootprintUuids;
185};
186
187#endif // FOOTPRINT_EDITOR_TAB_CONTEXT_H
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
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 never persisted.
BOARD * GetBoard() const
The fp-holder board owned by this context.
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.
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
static wxString MakeInstanceTabKey(const KIID &aSourceUuid)
De-duplication key for a placed board footprint, in a namespace disjoint from library keys.
KIID m_sessionId
Reference designator of the source footprint, shown as the tab label.
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)
KIND m_kind
Source board footprint UUID, used as the de-dup key and save-back target.
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
Editor-to-board UUID remap used to save instance edits back to the original board items.
Definition kiid.h:46
wxString AsString() const
Definition kiid.cpp:264