KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_autoplace_fields.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 * 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
29
31#include "eeschema_test_utils.h"
32
33#include <sch_symbol.h>
34#include <sch_field.h>
35#include <sch_item.h>
36#include <geometry/eda_angle.h>
37
38
40{
41public:
42 SCH_SYMBOL* GetSymbolByRef( const wxString& aRef )
43 {
44 if( !m_schematic )
45 return nullptr;
46
47 SCH_SCREEN* screen = m_schematic->RootScreen();
48
49 if( !screen )
50 return nullptr;
51
52 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
53 {
54 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
55
56 if( symbol && symbol->GetRef( &m_schematic->Hierarchy()[0], false ) == aRef )
57 return symbol;
58 }
59
60 return nullptr;
61 }
62};
63
64
65BOOST_FIXTURE_TEST_SUITE( AutoplaceFields, TEST_AUTOPLACE_FIELDS_FIXTURE )
66
67
68
82BOOST_AUTO_TEST_CASE( RotatedSymbolFieldBoundingBox )
83{
84 wxFileName fn;
85 fn.SetPath( KI_TEST::GetEeschemaTestDataDir() );
86 fn.AppendDir( wxS( "issue16538" ) );
87 fn.SetName( wxS( "issue16538" ) );
89
90 LoadSchematic( fn.GetFullPath() );
91
92 SCH_SYMBOL* symbol = GetSymbolByRef( wxS( "C1" ) );
93 BOOST_REQUIRE( symbol );
94
95 // Verify the symbol is rotated 90 degrees (y1 != 0)
96 TRANSFORM transform = symbol->GetTransform();
97 BOOST_CHECK( transform.y1 != 0 );
98
99 // Get the reference field
100 SCH_FIELD* refField = symbol->GetField( FIELD_T::REFERENCE );
101 BOOST_REQUIRE( refField );
102
103 // Set the field to horizontal angle (as the fix does)
104 refField->SetTextAngle( ANGLE_HORIZONTAL );
105
106 // Get the bounding box after setting horizontal angle
107 BOX2I bbox = refField->GetBoundingBox();
108
109 // For a 90-degree rotated symbol with horizontal field angle:
110 // The bounding box should be tall and narrow (text displays vertically)
111 // Height should be greater than width for short text like "C1"
112 BOOST_CHECK_MESSAGE( bbox.GetHeight() > bbox.GetWidth(),
113 wxString::Format( "Expected vertical bounding box (height > width) "
114 "for rotated symbol. Got width=%lld, height=%lld",
115 static_cast<long long>( bbox.GetWidth() ),
116 static_cast<long long>( bbox.GetHeight() ) ) );
117}
118
119
123BOOST_AUTO_TEST_CASE( FieldDrawRotationForRotatedSymbol )
124{
125 wxFileName fn;
126 fn.SetPath( KI_TEST::GetEeschemaTestDataDir() );
127 fn.AppendDir( wxS( "issue16538" ) );
128 fn.SetName( wxS( "issue16538" ) );
130
131 LoadSchematic( fn.GetFullPath() );
132
133 SCH_SYMBOL* symbol = GetSymbolByRef( wxS( "C1" ) );
134 BOOST_REQUIRE( symbol );
135
136 SCH_FIELD* refField = symbol->GetField( FIELD_T::REFERENCE );
137 BOOST_REQUIRE( refField );
138
139 // Set field to horizontal angle (as the fix does for autoplace)
140 refField->SetTextAngle( ANGLE_HORIZONTAL );
141
142 // For a 90-degree rotated symbol with horizontal field angle,
143 // GetDrawRotation should return vertical (the visual orientation)
144 EDA_ANGLE drawRotation = refField->GetDrawRotation();
145 BOOST_CHECK_MESSAGE( drawRotation.IsVertical(),
146 wxString::Format( "Expected vertical draw rotation for 90-degree "
147 "rotated symbol with horizontal field angle. "
148 "Got %f degrees", drawRotation.AsDegrees() ) );
149}
150
151
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr size_type GetWidth() const
Definition box2.h:214
constexpr size_type GetHeight() const
Definition box2.h:215
double AsDegrees() const
Definition eda_angle.h:116
bool IsVertical() const
Definition eda_angle.h:148
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:311
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:241
A generic fixture for loading schematics and associated settings for qa tests.
std::unique_ptr< SCHEMATIC > m_schematic
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:118
Schematic symbol object.
Definition sch_symbol.h:76
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
const TRANSFORM & GetTransform() const
Definition symbol.h:247
SCH_SYMBOL * GetSymbolByRef(const wxString &aRef)
for transforming drawing coordinates for a wxDC device context.
Definition transform.h:46
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:407
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName)
@ REFERENCE
Field Reference of part, i.e. "IC21".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(RotatedSymbolFieldBoundingBox)
Test that field bounding boxes for rotated symbols have correct dimensions.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
@ SCH_SYMBOL_T
Definition typeinfo.h:176