KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_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
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
21
22#include <lib_symbol.h>
23#include <sch_screen.h>
25
26
28 m_symbol( aSymbol ),
29 m_screen( aScreen ),
30 m_frameOwns( false ),
31 m_unit( 1 ),
32 m_bodyStyle( 1 ),
34 m_sessionId( aSymbol->m_Uuid )
35{
36}
37
38
40 const KIID& aSchematicSymbolUUID,
41 const wxString& aReference ) :
42 m_symbol( aSymbol ),
43 m_screen( aScreen ),
44 m_frameOwns( false ),
45 m_unit( 1 ),
46 m_bodyStyle( 1 ),
48 m_schematicSymbolUUID( aSchematicSymbolUUID ),
49 m_reference( aReference )
50{
51}
52
53
54void SYMBOL_EDITOR_TAB_CONTEXT::PromoteToLibrary( const wxString& aLib, const wxString& aName )
55{
56 wxCHECK( m_kind == KIND::UNSAVED, /* void */ );
57
59 m_lib = aLib;
60 m_name = aName;
61}
62
63
64SYMBOL_EDITOR_TAB_CONTEXT::SYMBOL_EDITOR_TAB_CONTEXT( const wxString& aLib, const wxString& aName,
65 SYMBOL_BUFFER* aBuffer ) :
66 m_lib( aLib ),
67 m_name( aName ),
68 m_symbol( nullptr ),
69 m_screen( nullptr ),
70 m_frameOwns( false ),
71 m_unit( 1 ),
72 m_bodyStyle( 1 )
73{
74 // Edit a private clone; the buffer's symbol stays owned by the libMgr.
75 if( aBuffer )
76 m_symbol = new LIB_SYMBOL( aBuffer->GetSymbol() );
77
78 // Symbol geometry lives in the LIB_SYMBOL, so a fresh empty screen is correct.
79 m_screen = new SCH_SCREEN();
80
81 if( aBuffer && aBuffer->IsModified() )
82 m_screen->SetContentModified();
83}
84
85
87{
88 // Delete only when the context still owns the objects; an active tab's frame owns them.
89 if( !m_frameOwns )
90 {
91 delete m_symbol;
92 delete m_screen;
93 }
94}
95
96
98{
99 return m_screen && m_screen->IsContentModified();
100}
Definition kiid.h:46
Define a library symbol object.
Definition lib_symbol.h:114
LIB_SYMBOL & GetSymbol() const
LIB_SYMBOL * m_symbol
Working copy; owned by the context while detached.
wxString m_reference
Reference designator of the source instance, shown as the tab label.
SYMBOL_EDITOR_TAB_CONTEXT(const wxString &aLib, const wxString &aName, SYMBOL_BUFFER *aBuffer)
Construct a library tab over the buffer for aLibrary:aName.
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.
bool IsModified() const override
True when the working screen carries unsaved edits.
SCH_SCREEN * m_screen
Working screen; owned by the context while detached.
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.