KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew/test_shape_corner_radius.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 (C) 2024 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 * or you may search the http://www.gnu.org website for the version 2 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
25#include <boost/test/unit_test.hpp>
26
27#include <pcb_shape.h>
29#include <properties/property.h>
30#include <i18n_utility.h>
31
32BOOST_AUTO_TEST_CASE( PCBShapeCornerRadius )
33{
34 PCB_SHAPE shape( nullptr, SHAPE_T::RECTANGLE );
35 shape.SetStart( VECTOR2I( 0, 0 ) );
36 shape.SetEnd( VECTOR2I( 1000, 600 ) );
37 shape.SetCornerRadius( 200 );
38 BOOST_CHECK_EQUAL( shape.GetCornerRadius(), 200 );
39
40 shape.SetCornerRadius( 400 );
41 BOOST_CHECK_EQUAL( shape.GetCornerRadius(), 300 );
42
43 shape.SetCornerRadius( -10 );
45}
46
47BOOST_AUTO_TEST_CASE( PCBShapeCornerRadiusValidation )
48{
49 PCB_SHAPE shape( nullptr, SHAPE_T::RECTANGLE );
50 shape.SetStart( VECTOR2I( 0, 0 ) );
51 shape.SetEnd( VECTOR2I( 1000, 500 ) );
52
54 propMgr.Rebuild();
55
56 PROPERTY_BASE* prop = propMgr.GetProperty( TYPE_HASH( EDA_SHAPE ), _HKI( "Corner Radius" ) );
57
58 auto resultTooLarge = prop->Validate( wxAny( 400 ), &shape );
59 BOOST_CHECK( resultTooLarge.has_value() );
60
61 auto resultOK = prop->Validate( wxAny( 200 ), &shape );
62 BOOST_CHECK( !resultOK.has_value() );
63}
void SetCornerRadius(int aRadius)
void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:177
void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:219
int GetCornerRadius() const
VALIDATOR_RESULT Validate(const wxAny &&aValue, EDA_ITEM *aItem)
Definition property.h:352
Provide class metadata.Helper macro to map type hashes to names.
static PROPERTY_MANAGER & Instance()
void Rebuild()
Rebuild the list of all registered properties.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:46
Some functions to handle hotkeys in KiCad.
#define _HKI(x)
Definition page_info.cpp:44
BOOST_AUTO_TEST_CASE(PCBShapeCornerRadius)
#define TYPE_HASH(x)
Definition property.h:73
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695