KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_footprint_item_equality.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 3
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, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26
27#include <footprint.h>
28#include <pad.h>
30#include <pcb_shape.h>
31#include <pcb_textbox.h>
32#include <zone.h>
33
34
35namespace
36{
37
38std::unique_ptr<FOOTPRINT> loadFootprint( const std::string& aPath )
39{
41 wxString name;
42
43 return io.ImportFootprint( wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + aPath ), name );
44}
45
46} // namespace
47
48
49BOOST_AUTO_TEST_SUITE( FootprintItemEquality )
50
51
52BOOST_AUTO_TEST_CASE( CustomPadPrimitiveGeometryCounts )
53{
54 const std::string path = "plugins/cadstar/lib/footprint-with-thermal-pad.pretty/CP_32_7.kicad_mod";
55
56 std::unique_ptr<FOOTPRINT> before = loadFootprint( path );
57 std::unique_ptr<FOOTPRINT> after = loadFootprint( path );
58
59 BOOST_REQUIRE( before && after );
60
61 auto customPad = []( FOOTPRINT& aFootprint ) -> PAD*
62 {
63 for( PAD* pad : aFootprint.Pads() )
64 {
65 if( !pad->GetPrimitives( F_Cu ).empty() )
66 return pad;
67 }
68
69 return nullptr;
70 };
71
72 PAD* padBefore = customPad( *before );
73 PAD* padAfter = customPad( *after );
74
75 BOOST_REQUIRE( padBefore && padAfter );
76 BOOST_REQUIRE( *padBefore == *padAfter );
77
78 padAfter->GetPrimitives( F_Cu ).front()->Move( VECTOR2I( 50000, 0 ) );
79
80 BOOST_CHECK( !( *padBefore == *padAfter ) );
81}
82
83
84BOOST_AUTO_TEST_CASE( TextBoxSizeCounts )
85{
86 const std::string path = "../downgrade/golden/current/metadata.pretty/metadata.kicad_mod";
87
88 std::unique_ptr<FOOTPRINT> before = loadFootprint( path );
89 std::unique_ptr<FOOTPRINT> after = loadFootprint( path );
90
91 BOOST_REQUIRE( before && after );
92
93 auto textBox = []( FOOTPRINT& aFootprint ) -> PCB_TEXTBOX*
94 {
95 for( BOARD_ITEM* item : aFootprint.GraphicalItems() )
96 {
97 if( item->Type() == PCB_TEXTBOX_T )
98 return static_cast<PCB_TEXTBOX*>( item );
99 }
100
101 return nullptr;
102 };
103
104 PCB_TEXTBOX* boxBefore = textBox( *before );
105 PCB_TEXTBOX* boxAfter = textBox( *after );
106
107 BOOST_REQUIRE( boxBefore && boxAfter );
108 BOOST_REQUIRE( *boxBefore == *boxAfter );
109
110 boxAfter->SetEnd( boxAfter->GetEnd() + VECTOR2I( 500000, 0 ) );
111
112 BOOST_CHECK( !( *boxBefore == *boxAfter ) );
113}
114
115
116BOOST_AUTO_TEST_CASE( ZoneLayersCount )
117{
118 const std::string path = "plugins/altium/pcblib/Tracks.pretty/KEEPOUT.kicad_mod";
119
120 std::unique_ptr<FOOTPRINT> before = loadFootprint( path );
121 std::unique_ptr<FOOTPRINT> after = loadFootprint( path );
122
123 BOOST_REQUIRE( before && after && !before->Zones().empty() && !after->Zones().empty() );
124
125 ZONE* zoneBefore = before->Zones().front();
126 ZONE* zoneAfter = after->Zones().front();
127
128 BOOST_REQUIRE( *zoneBefore == *zoneAfter );
129
130 zoneAfter->SetLayerSet( zoneAfter->GetLayerSet().Contains( B_Cu ) ? LSET{ F_Cu } : LSET{ B_Cu } );
131
132 BOOST_CHECK( !( *zoneBefore == *zoneAfter ) );
133}
134
135
136BOOST_AUTO_TEST_CASE( PadNumberCounts )
137{
138 const std::string path = "plugins/cadstar/lib/footprint-with-thermal-pad.pretty/CP_32_7.kicad_mod";
139
140 std::unique_ptr<FOOTPRINT> before = loadFootprint( path );
141 std::unique_ptr<FOOTPRINT> after = loadFootprint( path );
142
143 BOOST_REQUIRE( before && after && !after->Pads().empty() );
144 BOOST_REQUIRE( *before == *after );
145
146 after->Pads().front()->SetNumber( after->Pads().front()->GetNumber() + wxS( "0" ) );
147
148 BOOST_CHECK( !( *before == *after ) );
149}
150
151
const char * name
General utilities for PCB file IO for QA programs.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
Definition pad.h:61
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives(PCB_LAYER_ID aLayer) const
Accessor to the basic shape list for custom-shaped pads.
Definition pad.h:375
A PCB_IO derivation for saving and loading Pcbnew s-expression formatted files.
std::unique_ptr< FOOTPRINT > ImportFootprint(const wxString &aFootprintPath, wxString &aFootprintNameOut, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a single footprint from aFootprintPath and put its name in aFootprintNameOut.
void SetEnd(const VECTOR2I &aEnd) override
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetLayerSet(const LSET &aLayerSet) override
Definition zone.cpp:702
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:133
@ B_Cu
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:60
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_CASE(CustomPadPrimitiveGeometryCounts)
BOOST_AUTO_TEST_SUITE_END()
std::string path
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708