KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pin_number_default_style_clearance.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
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, see <https://www.gnu.org/licenses/>.
18 */
19
28
30
31#include <sch_pin.h>
32#include <lib_symbol.h>
33#include <pin_layout_cache.h>
34#include <transform.h>
35
36#include <boost/test/unit_test.hpp>
37
38BOOST_AUTO_TEST_SUITE( PinNumberDefaultStyleClearance )
39
40BOOST_AUTO_TEST_CASE( NumberClearanceMatchesNameClearance )
41{
42 auto symbol = std::make_unique<LIB_SYMBOL>( wxT( "TestIC" ) );
43
44 // Name offset 0 puts both name and number outside the pin, on opposite sides
45 symbol->SetPinNameOffset( 0 );
46 symbol->SetShowPinNames( true );
47 symbol->SetShowPinNumbers( true );
48
49 auto pinOwner = std::make_unique<SCH_PIN>( symbol.get() );
50 pinOwner->SetPosition( VECTOR2I( 0, 0 ) );
51 pinOwner->SetOrientation( PIN_ORIENTATION::PIN_RIGHT );
52 pinOwner->SetLength( schIUScale.MilsToIU( 200 ) );
53 pinOwner->SetName( wxT( "SDI" ) );
54 pinOwner->SetNumber( wxT( "14" ) );
55 pinOwner->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
56 pinOwner->SetUnit( 1 );
57
58 SCH_PIN* pin = pinOwner.get();
59 symbol->AddDrawItem( pinOwner.release() );
60
61 PIN_LAYOUT_CACHE cache( *pin );
62
63 std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> nameInfo = cache.GetPinNameInfo( 0 );
64 std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> numberInfo = cache.GetPinNumberInfo( 0 );
65
66 BOOST_REQUIRE( nameInfo );
67 BOOST_REQUIRE( numberInfo );
68
69 int pinY = pin->GetPosition().y;
70 int nameClearance = std::abs( nameInfo->m_TextPosition.y - pinY );
71 int numberClearance = std::abs( numberInfo->m_TextPosition.y - pinY );
72
73 // Both use the same 50 mil default text size, so with the same layout formula they
74 // should sit at the same distance from the pin. A couple of IU covers int rounding.
75 const int tolerance = 2;
76
77 BOOST_CHECK_MESSAGE( std::abs( nameClearance - numberClearance ) <= tolerance,
78 "Pin number clearance (" << numberClearance
79 << " IU) does not match pin name clearance (" << nameClearance
80 << " IU) even though both use the default 50 mil text size" );
81}
82
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
A pin layout helper is a class that manages the layout of the parts of a pin on a schematic symbol:
std::optional< TEXT_INFO > GetPinNameInfo(int aShadowWidth)
Get the text info for the pin name.
std::optional< TEXT_INFO > GetPinNumberInfo(int aShadowWidth)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:411
@ PT_BIDI
input or output (like port for a microprocessor)
Definition pin_type.h:35
@ PIN_RIGHT
The pin extends rightwards from the connection point.
Definition pin_type.h:107
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
KIBIS_PIN * pin
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683