KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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 SYMBOL_EDITOR_TAB_CONTEXT_H
21#define SYMBOL_EDITOR_TAB_CONTEXT_H
22
23#include <wx/string.h>
24#include <wx/translation.h>
25
26#include <kiid.h>
28
29class LIB_SYMBOL;
30class SCH_SCREEN;
31class SYMBOL_BUFFER;
32
33
45{
46public:
56
57
64 SYMBOL_EDITOR_TAB_CONTEXT( const wxString& aLib, const wxString& aName, SYMBOL_BUFFER* aBuffer );
65
73
82 const KIID& aSchematicSymbolUUID, const wxString& aReference );
83
85
89 static wxString MakeTabKey( const wxString& aLib, const wxString& aName )
90 {
91 return aLib + wxT( ":" ) + aName;
92 }
93
100 static wxString MakeInstanceTabKey( const KIID& aSchematicSymbolUUID )
101 {
102 return wxString( wxT( "\x01@sym:" ) ) + aSchematicSymbolUUID.AsString();
103 }
104
108 static wxString MakeUnsavedTabKey( const KIID& aSessionId )
109 {
110 return wxString( wxT( "\x01@unsaved:" ) ) + aSessionId.AsString();
111 }
112
113 wxString GetTabKey() const override
114 {
115 switch( m_kind )
116 {
119 default: return MakeTabKey( m_lib, m_name );
120 }
121 }
122
123 wxString GetDisplayName( bool aShortForm = false ) const override
124 {
125 switch( m_kind )
126 {
128 if( aShortForm )
129 return m_reference;
130 else
131 return m_reference + wxS( " " ) + _( "[from schematic]" );
132
133 case KIND::UNSAVED:
134 return _( "<unnamed>" );
135
136 default:
137 return m_name;
138 }
139 }
140
144 bool IsTransient() const { return m_kind != KIND::LIBRARY; }
145
147 bool IsUnsaved() const { return m_kind == KIND::UNSAVED; }
149 const wxString& GetReference() const { return m_reference; }
150
154 bool IsModified() const override;
155
156 const wxString& GetLibrary() const { return m_lib; }
157 const wxString& GetName() const { return m_name; }
158 void SetName( const wxString& aName ) { m_name = aName; }
159
163 void PromoteToLibrary( const wxString& aLib, const wxString& aName );
164
168 LIB_SYMBOL* GetSymbol() const { return m_symbol; }
169 SCH_SCREEN* GetScreen() const { return m_screen; }
170
176 void ReleaseToFrame() { m_frameOwns = true; }
177
181 void AdoptWorkingObjects( LIB_SYMBOL* aSymbol, SCH_SCREEN* aScreen )
182 {
183 m_symbol = aSymbol;
184 m_screen = aScreen;
185 m_frameOwns = false;
186 }
187
192 {
193 m_symbol = aSymbol;
194 m_screen = aScreen;
195 }
196
197 int GetUnit() const { return m_unit; }
198 void SetUnit( int aUnit ) { m_unit = aUnit; }
199
200 int GetBodyStyle() const { return m_bodyStyle; }
201 void SetBodyStyle( int aBodyStyle ) { m_bodyStyle = aBodyStyle; }
202
203private:
204 wxString m_lib;
205 wxString m_name;
211
213
216
218 wxString m_reference;
219
222};
223
224#endif // SYMBOL_EDITOR_TAB_CONTEXT_H
Definition kiid.h:46
wxString AsString() const
Definition kiid.cpp:264
Define a library symbol object.
Definition lib_symbol.h:114
void RefreshFrameOwnedObjects(LIB_SYMBOL *aSymbol, SCH_SCREEN *aScreen)
Track the frame's new working symbol after undo/redo replaces it, while staying frame-owned.
void ReleaseToFrame()
Hand the working symbol/screen to the frame as the tab becomes active.
LIB_SYMBOL * GetSymbol() const
Observe the working symbol/screen.
LIB_SYMBOL * m_symbol
Working copy; owned by the context while detached.
const wxString & GetReference() const
static wxString MakeTabKey(const wxString &aLib, const wxString &aName)
De-duplication key for a library:symbol pair.
wxString m_reference
Reference designator of the source instance, shown as the tab label.
static wxString MakeInstanceTabKey(const KIID &aSchematicSymbolUUID)
De-duplication key for a placed schematic instance, in a namespace disjoint from library keys.
SYMBOL_EDITOR_TAB_CONTEXT(const wxString &aLib, const wxString &aName, SYMBOL_BUFFER *aBuffer)
Construct a library tab over the buffer for aLibrary:aName.
wxString GetTabKey() const override
Stable identity for persistence and de-duplication.
wxString GetDisplayName(bool aShortForm=false) const override
Short label shown on the tab.
const KIID & GetSchematicSymbolUUID() const
bool m_frameOwns
True while the tab is active and the frame owns the symbol/screen.
void PromoteToLibrary(const wxString &aLib, const wxString &aName)
Gives an unsaved new symbol a library identity.
KIID m_sessionId
Identity of an unsaved new symbol, which has no library:name pair to key on.
static wxString MakeUnsavedTabKey(const KIID &aSessionId)
De-duplication key for an unsaved new symbol.
bool IsModified() const override
True when the working screen carries unsaved edits.
SCH_SCREEN * m_screen
Working screen; owned by the context while detached.
void AdoptWorkingObjects(LIB_SYMBOL *aSymbol, SCH_SCREEN *aScreen)
Take ownership back on detach, capturing whatever the frame's symbol now points at.
void SetName(const wxString &aName)
const wxString & GetLibrary() const
bool IsTransient() const
True for a tab that is session-only and not persisted.
KIID m_schematicSymbolUUID
Source instance UUID, used as both the de-dup key and the save-back target.
KIND
What the tab edits, which decides its key, its label and whether it is persisted.
@ UNSAVED
A brand-new symbol with no library home yet, session-only.
@ SCHEMATIC_INSTANCE
A symbol pulled off a placed schematic symbol, session-only.
@ LIBRARY
A library symbol, keyed library:name and persisted across sessions.
#define _(s)