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
44{
45public:
46 FOOTPRINT_EDITOR_TAB_CONTEXT( const wxString& aLib, const wxString& aName,
47 std::unique_ptr<BOARD> aBoard );
48
56 FOOTPRINT_EDITOR_TAB_CONTEXT( const KIID& aSourceUuid, const wxString& aReference,
57 std::unique_ptr<BOARD> aBoard );
58
60
67 static wxString MakeInstanceTabKey( const KIID& aSourceUuid )
68 {
69 return wxString( wxT( "\x01@fp:" ) ) + aSourceUuid.AsString();
70 }
71
72 wxString GetTabKey() const override
73 {
74 return m_fromBoard ? MakeInstanceTabKey( m_sourceUuid ) : m_lib + wxT( ":" ) + m_name;
75 }
76
77 wxString GetDisplayName() const override { return m_fromBoard ? m_reference : m_name; }
78
82 bool IsTransient() const { return m_fromBoard; }
83
84 bool IsFromBoard() const { return m_fromBoard; }
85 const KIID& GetSourceUuid() const { return m_sourceUuid; }
86 const wxString& GetReference() const { return m_reference; }
87
92 std::map<KIID, KIID>& BoardFootprintUuids() { return m_boardFootprintUuids; }
93
97 bool IsModified() const override;
98
99 void SetModified( bool aModified ) { m_modified = aModified; }
100
104 BOARD* GetBoard() const { return m_board.get(); }
105
106 const wxString& GetLib() const { return m_lib; }
107 const wxString& GetName() const { return m_name; }
108 void SetName( const wxString& aName ) { m_name = aName; }
109
114 void SetOriginalFootprintCopy( std::unique_ptr<FOOTPRINT> aCopy );
115
116 const wxString& GetFootprintNameWhenLoaded() const { return m_footprintNameWhenLoaded; }
117 void SetFootprintNameWhenLoaded( const wxString& aName ) { m_footprintNameWhenLoaded = aName; }
118
119private:
120 wxString m_lib;
121 wxString m_name;
122 std::unique_ptr<BOARD> m_board;
123 std::unique_ptr<FOOTPRINT> m_originalFootprintCopy;
125 bool m_modified = false;
126
128 bool m_fromBoard = false;
129
132
134 wxString m_reference;
135
137 std::map<KIID, KIID> m_boardFootprintUuids;
138};
139
140#endif // FOOTPRINT_EDITOR_TAB_CONTEXT_H
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:320
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 an instance (board) tab, which is session-only and never persisted.
BOARD * GetBoard() const
The fp-holder board owned by this context.
KIID m_sourceUuid
Reference designator of the source footprint, shown as the tab label.
std::unique_ptr< FOOTPRINT > m_originalFootprintCopy
wxString GetDisplayName() const override
Short label shown on the tab.
~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.
bool m_modified
True for an instance tab edited in place from a placed board footprint.
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)
bool m_fromBoard
Source board footprint UUID, used as the de-dup key and save-back target.
wxString m_reference
Editor-to-board UUID remap used to save instance edits back to the original board items.
Definition kiid.h:44
wxString AsString() const
Definition kiid.cpp:242