KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_ref_suffix_split.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 <board.h>
23#include <footprint.h>
24#include <mail_type.h>
25#include <ref_suffix_split.h>
26
27
28BOOST_AUTO_TEST_SUITE( RefSuffixSplit )
29
30
31BOOST_AUTO_TEST_CASE( CopiesShareTheFirstPagesBase )
32{
33 const std::string id = "00000000-0000-0000-0000-0000000000";
34 const std::string a = "/" + id + "b1/";
35 const std::string b = "/" + id + "b2/";
36 const std::string c = "/" + id + "b3/";
37
38 BOARD board;
39
40 auto add =
41 [&]( const std::string& aSheet, const char* aSymbol, const wxString& aRef )
42 {
43 FOOTPRINT* footprint = new FOOTPRINT( &board );
44 footprint->SetPath( KIID_PATH( wxString( aSheet + id + aSymbol ) ) );
45 footprint->SetReference( aRef );
46 board.Add( footprint, ADD_MODE::APPEND );
47 return footprint->m_Uuid;
48 };
49
50 // Sheet C comes first in page order, so its unsuffixed copy numbers the shared base
51 std::optional<SHEET_REF_SUFFIXES> suffixes = ParseRefSuffixes( std::string( MAIL_SCH_REF_SUFFIXES_TAG ) + "\n"
52 + c + "\t\n" + b + "\t_M2\n" + a + "\t_M1\n/\t\n"
53 + b + id + "a5\t_M1\n" );
54 BOOST_REQUIRE( suffixes );
55
56 KIID first = add( a, "a1", wxS( "R4_M1" ) );
57 KIID second = add( b, "a1", wxS( "R4_M2" ) );
58 KIID stale = add( a, "a3", wxS( "R6" ) );
59 KIID bare = add( c, "a1", wxS( "R4" ) );
60 KIID twin = add( "/", "a4", wxS( "R8" ) );
61 add( c, "a4", wxS( "R8" ) );
62 KIID package = add( b, "a5", wxS( "U9_M1" ) );
63
64 std::map<KIID, FOOTPRINT_REF_SPLIT> splits = SplitRefSuffixes( board.Footprints(), &*suffixes, true );
65
66 BOOST_CHECK( splits[first].Representative == bare && splits[second].Representative == bare );
67 BOOST_CHECK( splits[stale].Unknown );
68 BOOST_CHECK( splits[twin].Representative == twin );
69
70 // A package on another sheet's suffix keeps that suffix
71 BOOST_CHECK_EQUAL( splits[package].Base, wxS( "U9" ) );
72
73 // Without a schematic, a suffix cannot be told from part of the reference
74 BOOST_CHECK( SplitRefSuffixes( board.Footprints(), nullptr, true )[first].Unknown );
75}
76
77
78BOOST_AUTO_TEST_CASE( NumericSuffixNeedsTheSchematic )
79{
80 BOARD board;
81 FOOTPRINT* child = new FOOTPRINT( &board );
82 child->SetPath( KIID_PATH( wxS( "/11111111-1111-1111-1111-111111111111/"
83 "22222222-2222-2222-2222-222222222222" ) ) );
84 child->SetReference( wxS( "R72" ) );
85 board.Add( child, ADD_MODE::APPEND );
86
87 BOOST_CHECK( SplitRefSuffixes( board.Footprints(), nullptr, true )[child->m_Uuid].Unknown );
88 BOOST_CHECK( !SplitRefSuffixes( board.Footprints(), nullptr, false )[child->m_Uuid].Unknown );
89
90 KIID_PATH sheet = child->GetPath();
91 sheet.pop_back();
92 SHEET_REF_SUFFIXES suffixes;
93 suffixes[sheet.AsString() + wxS( "/" )].Suffix = wxS( "2" );
94
95 FOOTPRINT_REF_SPLIT split = SplitRefSuffixes( board.Footprints(), &suffixes, true )[child->m_Uuid];
96 BOOST_CHECK( !split.Unknown );
97 BOOST_CHECK_EQUAL( split.Base, wxS( "R7" ) );
98 BOOST_CHECK_EQUAL( split.Suffix, wxS( "2" ) );
99}
100
101
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1548
const FOOTPRINTS & Footprints() const
Definition board.h:465
const KIID m_Uuid
Definition eda_item.h:599
void SetPath(const KIID_PATH &aPath)
Definition footprint.h:456
void SetReference(const wxString &aReference)
Definition footprint.h:799
const KIID_PATH & GetPath() const
Definition footprint.h:455
wxString AsString() const
Definition kiid.cpp:423
Definition kiid.h:46
#define MAIL_SCH_REF_SUFFIXES_TAG
First line of a MAIL_SCH_GET_REF_SUFFIXES reply, so a schematic with no sheets still answers.
Definition mail_type.h:85
std::optional< SHEET_REF_SUFFIXES > ParseRefSuffixes(const std::string &aPayload)
std::map< KIID, FOOTPRINT_REF_SPLIT > SplitRefSuffixes(const FOOTPRINTS &aFootprints, const SHEET_REF_SUFFIXES *aSuffixes, bool aSuffixMode)
Split each footprint reference into its base and sheet suffix.
std::map< wxString, SHEET_REF_SUFFIX > SHEET_REF_SUFFIXES
Sheet suffixes keyed by the sheet path string that starts the paths of its footprints,...
static std::vector< std::string > split(const std::string &aStr, const std::string &aDelim)
Split the input string into a vector of output strings.
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_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CopiesShareTheFirstPagesBase)