KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_footprint_editor_tabs.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 <memory>
23
24#include <board.h>
25#include <footprint.h>
26#include <lib_id.h>
27
30
31
33static std::unique_ptr<BOARD> makeFpHolder( const wxString& aLib, const wxString& aName )
34{
35 auto board = std::make_unique<BOARD>();
36 board->SetBoardUse( BOARD_USE::FPHOLDER );
37
38 FOOTPRINT* fp = new FOOTPRINT( board.get() );
39 fp->SetFPID( LIB_ID( aLib, aName ) );
40 board->Add( fp );
41
42 return board;
43}
44
45
46BOOST_AUTO_TEST_SUITE( FootprintEditorTabs )
47
48
49BOOST_AUTO_TEST_CASE( ContextIdentityAndDirty )
50{
51 std::unique_ptr<BOARD> board = makeFpHolder( wxS( "Resistors" ), wxS( "R_0402" ) );
52 BOARD* raw = board.get();
53
54 FOOTPRINT_EDITOR_TAB_CONTEXT ctx( wxS( "Resistors" ), wxS( "R_0402" ), std::move( board ) );
55
56 BOOST_CHECK_EQUAL( ctx.GetTabKey(), wxS( "Resistors:R_0402" ) );
57 BOOST_CHECK_EQUAL( ctx.GetDisplayName(), wxS( "R_0402" ) );
58
59 BOOST_CHECK_EQUAL( ctx.GetBoard(), raw );
60
61 BOOST_CHECK( !ctx.IsModified() );
62
63 ctx.SetModified( true );
64 BOOST_CHECK( ctx.IsModified() );
65
66 ctx.SetModified( false );
67 BOOST_CHECK( !ctx.IsModified() );
68}
69
70
71BOOST_AUTO_TEST_CASE( ContextEmptyBoardIsNeverDirty )
72{
73 auto board = std::make_unique<BOARD>();
74 board->SetBoardUse( BOARD_USE::FPHOLDER );
75
76 FOOTPRINT_EDITOR_TAB_CONTEXT ctx( wxS( "Lib" ), wxS( "Empty" ), std::move( board ) );
77
78 ctx.SetModified( true );
79 BOOST_CHECK( !ctx.IsModified() );
80}
81
82
85BOOST_AUTO_TEST_CASE( InstanceTabContextIsTransientAndKeyedByUuid )
86{
87 KIID sourceUuid;
88 std::unique_ptr<BOARD> board = makeFpHolder( wxS( "Resistors" ), wxS( "R_0402" ) );
89 BOARD* raw = board.get();
90
91 FOOTPRINT_EDITOR_TAB_CONTEXT ctx( sourceUuid, wxS( "R5" ), std::move( board ) );
92
93 BOOST_CHECK( ctx.IsTransient() );
94 BOOST_CHECK( ctx.IsFromBoard() );
95 BOOST_CHECK_EQUAL( ctx.GetReference(), wxS( "R5" ) );
96 BOOST_CHECK_EQUAL( ctx.GetSourceUuid().AsString(), sourceUuid.AsString() );
97 BOOST_CHECK_EQUAL( ctx.GetBoard(), raw );
98 BOOST_CHECK_EQUAL( ctx.GetDisplayName(), wxS( "R5" ) );
99
102 BOOST_CHECK( ctx.GetTabKey() != wxS( "Resistors:R_0402" ) );
103 BOOST_CHECK( ctx.GetTabKey().StartsWith( wxString( wxT( "\x01" ) ) ) );
104
105 // The remap is mutable and survives on the context for save-back.
106 KIID editorId, boardId;
107 ctx.BoardFootprintUuids()[editorId] = boardId;
108 BOOST_REQUIRE_EQUAL( ctx.BoardFootprintUuids().count( editorId ), 1u );
109 BOOST_CHECK_EQUAL( ctx.BoardFootprintUuids()[editorId].AsString(), boardId.AsString() );
110}
111
112
113BOOST_AUTO_TEST_CASE( SettingsOpenTabsRoundTrip )
114{
116
117 settings.m_OpenTabs.clear();
118 settings.m_OpenTabs.push_back( { wxS( "Resistors" ), wxS( "R_0402" ) } );
119 settings.m_OpenTabs.push_back( { wxS( "Caps" ), wxS( "C_0603" ) } );
120 settings.m_ActiveTab = wxS( "Caps:C_0603" );
121
122 settings.Store();
123
124 settings.m_OpenTabs.clear();
125 settings.m_ActiveTab = wxEmptyString;
126
127 settings.Load();
128
129 BOOST_REQUIRE_EQUAL( settings.m_OpenTabs.size(), 2u );
130 BOOST_CHECK_EQUAL( settings.m_OpenTabs[0].m_lib, wxS( "Resistors" ) );
131 BOOST_CHECK_EQUAL( settings.m_OpenTabs[0].m_fpName, wxS( "R_0402" ) );
132 BOOST_CHECK_EQUAL( settings.m_OpenTabs[1].m_lib, wxS( "Caps" ) );
133 BOOST_CHECK_EQUAL( settings.m_OpenTabs[1].m_fpName, wxS( "C_0603" ) );
134 BOOST_CHECK_EQUAL( settings.m_ActiveTab, wxS( "Caps:C_0603" ) );
135}
136
137
@ FPHOLDER
Definition board.h:312
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:320
std::vector< OPEN_TAB > m_OpenTabs
wxString m_ActiveTab
Tab key ("lib:fpName") of the tab that was active when the editor last closed.
One open footprint tab owning its fp-holder board, lent to the frame by raw pointer while active.
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.
wxString GetDisplayName() const override
Short label shown on the tab.
static wxString MakeInstanceTabKey(const KIID &aSourceUuid)
De-duplication key for a placed board footprint, in a namespace disjoint from library keys.
bool IsModified() const override
True only when dirty and the board actually holds a footprint to edit.
wxString GetTabKey() const override
Stable identity for persistence and de-duplication.
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:442
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
Definition kiid.h:44
wxString AsString() const
Definition kiid.cpp:242
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(ContextIdentityAndDirty)
static std::unique_ptr< BOARD > makeFpHolder(const wxString &aLib, const wxString &aName)
Build an fp-holder BOARD carrying a single footprint with the given identity.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")