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
20
#include <
qa_utils/wx_utils/unit_test_utils.h
>
21
22
#include <memory>
23
24
#include <
board.h
>
25
#include <
footprint.h
>
26
#include <
lib_id.h
>
27
28
#include <
footprint_editor_settings.h
>
29
#include <
footprint_editor_tab_context.h
>
30
31
33
static
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
46
BOOST_AUTO_TEST_SUITE
( FootprintEditorTabs )
47
48
49
BOOST_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
71
BOOST_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
85
BOOST_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
100
BOOST_CHECK_EQUAL
( ctx.
GetTabKey
(),
101
FOOTPRINT_EDITOR_TAB_CONTEXT::MakeInstanceTabKey
( sourceUuid ) );
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
113
BOOST_AUTO_TEST_CASE
( SettingsOpenTabsRoundTrip )
114
{
115
FOOTPRINT_EDITOR_SETTINGS
settings;
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
138
BOOST_AUTO_TEST_SUITE_END
()
board.h
BOARD_USE::FPHOLDER
@ FPHOLDER
Definition
board.h:312
BOARD
Information pertinent to a Pcbnew printed circuit board.
Definition
board.h:320
FOOTPRINT_EDITOR_SETTINGS
Definition
footprint_editor_settings.h:31
FOOTPRINT_EDITOR_SETTINGS::m_OpenTabs
std::vector< OPEN_TAB > m_OpenTabs
Definition
footprint_editor_settings.h:99
FOOTPRINT_EDITOR_SETTINGS::m_ActiveTab
wxString m_ActiveTab
Tab key ("lib:fpName") of the tab that was active when the editor last closed.
Definition
footprint_editor_settings.h:102
FOOTPRINT_EDITOR_TAB_CONTEXT
One open footprint tab owning its fp-holder board, lent to the frame by raw pointer while active.
Definition
footprint_editor_tab_context.h:44
FOOTPRINT_EDITOR_TAB_CONTEXT::BoardFootprintUuids
std::map< KIID, KIID > & BoardFootprintUuids()
Editor-to-board UUID remap captured at load, used by SaveFootprintToBoard to restore the original boa...
Definition
footprint_editor_tab_context.h:92
FOOTPRINT_EDITOR_TAB_CONTEXT::IsTransient
bool IsTransient() const
True for an instance (board) tab, which is session-only and never persisted.
Definition
footprint_editor_tab_context.h:82
FOOTPRINT_EDITOR_TAB_CONTEXT::GetBoard
BOARD * GetBoard() const
The fp-holder board owned by this context.
Definition
footprint_editor_tab_context.h:104
FOOTPRINT_EDITOR_TAB_CONTEXT::GetDisplayName
wxString GetDisplayName() const override
Short label shown on the tab.
Definition
footprint_editor_tab_context.h:77
FOOTPRINT_EDITOR_TAB_CONTEXT::GetSourceUuid
const KIID & GetSourceUuid() const
Definition
footprint_editor_tab_context.h:85
FOOTPRINT_EDITOR_TAB_CONTEXT::MakeInstanceTabKey
static wxString MakeInstanceTabKey(const KIID &aSourceUuid)
De-duplication key for a placed board footprint, in a namespace disjoint from library keys.
Definition
footprint_editor_tab_context.h:67
FOOTPRINT_EDITOR_TAB_CONTEXT::SetModified
void SetModified(bool aModified)
Definition
footprint_editor_tab_context.h:99
FOOTPRINT_EDITOR_TAB_CONTEXT::IsModified
bool IsModified() const override
True only when dirty and the board actually holds a footprint to edit.
Definition
footprint_editor_tab_context.cpp:51
FOOTPRINT_EDITOR_TAB_CONTEXT::GetTabKey
wxString GetTabKey() const override
Stable identity for persistence and de-duplication.
Definition
footprint_editor_tab_context.h:72
FOOTPRINT_EDITOR_TAB_CONTEXT::GetReference
const wxString & GetReference() const
Definition
footprint_editor_tab_context.h:86
FOOTPRINT_EDITOR_TAB_CONTEXT::IsFromBoard
bool IsFromBoard() const
Definition
footprint_editor_tab_context.h:84
FOOTPRINT
Definition
footprint.h:288
FOOTPRINT::SetFPID
void SetFPID(const LIB_ID &aFPID)
Definition
footprint.h:442
JSON_SETTINGS::Load
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
Definition
json_settings.cpp:138
JSON_SETTINGS::Store
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
Definition
json_settings.cpp:391
KIID
Definition
kiid.h:44
KIID::AsString
wxString AsString() const
Definition
kiid.cpp:242
LIB_ID
A logical library item identifier and consists of various portions much like a URI.
Definition
lib_id.h:45
footprint.h
footprint_editor_settings.h
footprint_editor_tab_context.h
lib_id.h
PLUGIN_ACTION_SCOPE::FOOTPRINT
@ FOOTPRINT
Definition
plugin_action_scope.h:30
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(ContextIdentityAndDirty)
Definition
test_footprint_editor_tabs.cpp:49
makeFpHolder
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.
Definition
test_footprint_editor_tabs.cpp:33
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
pcbnew
test_footprint_editor_tabs.cpp
Generated on Fri Jun 19 2026 00:06:52 for KiCad PCB EDA Suite by
1.13.2