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
27SYMBOL_EDITOR_TAB_CONTEXT::SYMBOL_EDITOR_TAB_CONTEXT( const wxString& aLib, const wxString& aName,
28 SYMBOL_BUFFER* aBuffer ) :
29 m_lib( aLib ),
30 m_name( aName ),
31 m_symbol( nullptr ),
32 m_screen( nullptr ),
33 m_frameOwns( false ),
34 m_unit( 1 ),
35 m_bodyStyle( 1 ),
36 m_fromSchematic( false )
37{
38 // Edit a private clone; the buffer's symbol stays owned by the libMgr.
39 if( aBuffer )
40 m_symbol = new LIB_SYMBOL( aBuffer->GetSymbol() );
41
42 // Symbol geometry lives in the LIB_SYMBOL, so a fresh empty screen is correct.
43 m_screen = new SCH_SCREEN();
44
45 if( aBuffer && aBuffer->IsModified() )
46 m_screen->SetContentModified();
47}
48
49
51 const KIID& aSchematicSymbolUUID,
52 const wxString& aReference ) :
53 m_symbol( aSymbol ),
54 m_screen( aScreen ),
55 m_frameOwns( false ),
56 m_unit( 1 ),
57 m_bodyStyle( 1 ),
58 m_fromSchematic( true ),
59 m_schematicSymbolUUID( aSchematicSymbolUUID ),
60 m_reference( aReference )
61{
62}
63
64
66{
67 // Delete only when the context still owns the objects; an active tab's frame owns them.
68 if( !m_frameOwns )
69 {
70 delete m_symbol;
71 delete m_screen;
72 }
73}
74
75
77{
78 return m_screen && m_screen->IsContentModified();
79}
Definition kiid.h:44
Define a library symbol object.
Definition lib_symbol.h:79
LIB_SYMBOL & GetSymbol() const
int m_bodyStyle
True for an instance tab edited in place from a placed schematic symbol.
bool m_fromSchematic
Source instance UUID, used as both the de-dup key and the save-back target.
LIB_SYMBOL * m_symbol
Working copy; owned by the context while detached.
SYMBOL_EDITOR_TAB_CONTEXT(const wxString &aLib, const wxString &aName, SYMBOL_BUFFER *aBuffer)
bool m_frameOwns
True while the tab is active and the frame owns the symbol/screen.
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
Reference designator of the source instance, shown as the tab label.