KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_altium_custom_pad_issue23933.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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 */
20
25
28
30
31#include <footprint.h>
32#include <pad.h>
33#include <padstack.h>
34#include <base_units.h>
36
37#include <map>
38#include <memory>
39
40
47
48
49BOOST_FIXTURE_TEST_SUITE( AltiumCustomPadIssue23933, ALTIUM_CUSTOM_PAD_FIXTURE )
50
51
52BOOST_AUTO_TEST_CASE( CustomShapePadIsSinglePad )
53{
54 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/altium/pcblib/";
55 wxString libraryPath = dataPath + "GW_JTLMS1_CM.PcbLib";
56
57 std::unique_ptr<FOOTPRINT> footprint(
58 altiumPlugin.FootprintLoad( libraryPath, wxT( "GW JTLMS1_CM" ), false, nullptr ) );
59 BOOST_REQUIRE( footprint );
60
61 std::map<wxString, std::vector<PAD*>> padsByNumber;
62
63 for( PAD* pad : footprint->Pads() )
64 {
65 if( !pad->GetNumber().IsEmpty() )
66 padsByNumber[pad->GetNumber()].push_back( pad );
67 }
68
69 // Anchors from the Altium source: pad 1 at (1.31mm, 0), pad 2 at (-0.69mm, 0)
70 std::map<wxString, VECTOR2I> expectedAnchors = {
71 { wxT( "1" ), VECTOR2I( pcbIUScale.mmToIU( 1.31 ), 0 ) },
72 { wxT( "2" ), VECTOR2I( pcbIUScale.mmToIU( -0.69 ), 0 ) }
73 };
74
75 for( const auto& [number, anchor] : expectedAnchors )
76 {
77 BOOST_TEST_CONTEXT( wxString::Format( wxT( "Pad number '%s'" ), number ) )
78 {
79 BOOST_REQUIRE_EQUAL( padsByNumber[number].size(), 1u );
80
81 PAD* pad = padsByNumber[number].front();
82
83 BOOST_CHECK_EQUAL( static_cast<int>( pad->GetShape( PADSTACK::ALL_LAYERS ) ),
84 static_cast<int>( PAD_SHAPE::CUSTOM ) );
85 BOOST_CHECK_EQUAL( pad->GetPosition().x, anchor.x );
86 BOOST_CHECK_EQUAL( pad->GetPosition().y, anchor.y );
87
88 bool hasPrimitive = false;
89
90 for( PCB_LAYER_ID layer : { PADSTACK::ALL_LAYERS, F_Cu, B_Cu } )
91 {
92 if( !pad->GetPrimitives( layer ).empty() )
93 {
94 hasPrimitive = true;
95 break;
96 }
97 }
98
99 BOOST_CHECK( hasPrimitive );
100
101 // Pre-fix the outline was anchored at a polygon corner, ~1mm from the pad anchor
102 std::shared_ptr<SHAPE_POLY_SET> poly =
103 pad->GetEffectivePolygon( PADSTACK::ALL_LAYERS, ERROR_INSIDE );
104 BOOST_REQUIRE( poly && poly->OutlineCount() > 0 );
105
106 VECTOR2I outlineCenter = poly->BBox().GetCenter();
107 int tol = pcbIUScale.mmToIU( 0.5 );
108
109 BOOST_CHECK_LE( std::abs( outlineCenter.x - anchor.x ), tol );
110 BOOST_CHECK_LE( std::abs( outlineCenter.y - anchor.y ), tol );
111 }
112 }
113}
114
115
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
Definition pad.h:61
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ 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.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:437
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708