KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24972_sheet_pin_constrain.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
26
28
29#include <sch_sheet.h>
30#include <sch_sheet_pin.h>
31
32BOOST_AUTO_TEST_SUITE( Issue24972SheetPinConstrain )
33
34
35static bool onSheetBorder( const VECTOR2I& aPos, const SCH_SHEET& aSheet )
36{
37 int left = aSheet.GetPosition().x;
38 int right = aSheet.GetPosition().x + aSheet.GetSize().x;
39 int top = aSheet.GetPosition().y;
40 int bot = aSheet.GetPosition().y + aSheet.GetSize().y;
41
42 bool onVertical = ( aPos.x == left || aPos.x == right ) && aPos.y >= top && aPos.y <= bot;
43 bool onHorizontal = ( aPos.y == top || aPos.y == bot ) && aPos.x >= left && aPos.x <= right;
44
45 return onVertical || onHorizontal;
46}
47
48
49BOOST_AUTO_TEST_CASE( CalcEditClampsToBorder )
50{
51 SCH_SHEET sheet;
52 sheet.SetSize( VECTOR2I( 1000, 1000 ) );
53
54 SCH_SHEET_PIN* pin = new SCH_SHEET_PIN( &sheet, VECTOR2I( 0, 500 ), "P1" );
55 sheet.AddPin( pin );
56
57 pin->CalcEdit( VECTOR2I( 500, 5000 ) );
58 BOOST_CHECK( onSheetBorder( pin->GetPosition(), sheet ) );
59 BOOST_CHECK_EQUAL( pin->GetPosition(), VECTOR2I( 500, 1000 ) );
60
61 pin->CalcEdit( VECTOR2I( 5000, 300 ) );
62 BOOST_CHECK( onSheetBorder( pin->GetPosition(), sheet ) );
63 BOOST_CHECK_EQUAL( pin->GetPosition(), VECTOR2I( 1000, 300 ) );
64
65 pin->CalcEdit( VECTOR2I( -5000, -5000 ) );
66 BOOST_CHECK( onSheetBorder( pin->GetPosition(), sheet ) );
67}
68
69
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
void SetSize(const VECTOR2I &aSize)
Definition sch_sheet.h:142
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CalcEditClampsToBorder)
static bool onSheetBorder(const VECTOR2I &aPos, const SCH_SHEET &aSheet)
KIBIS top(path, &reporter)
KIBIS_PIN * pin
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683