KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sheet_suffix_properties.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
21
22#include <fields_grid_table.h>
23#include <sch_sheet.h>
24
25
26BOOST_AUTO_TEST_SUITE( SheetSuffixProperties )
27
28
29BOOST_AUTO_TEST_CASE( MissingSuffixIsEditableWithoutChangingTheSheet )
30{
31 SCH_SHEET sheet;
32 const SCH_SHEET& original = sheet;
33 const size_t originalCount = original.GetFields().size();
34
36
37 std::vector<SCH_FIELD> fields = GetSheetFieldsForEditing( sheet );
38
39 BOOST_REQUIRE_EQUAL( fields.size(), originalCount + 1 );
40 BOOST_REQUIRE( fields[2].GetId() == FIELD_T::SHEET_REF_SUFFIX );
41 BOOST_CHECK_EQUAL( fields[2].GetUntranslatedName(), wxS( "Reference Suffix" ) );
42 BOOST_CHECK( fields[2].GetText().IsEmpty() );
43 BOOST_CHECK( !fields[2].IsVisible() );
44
45 fields[2].SetText( wxS( "_M1" ) );
46 fields.clear();
47
48 BOOST_CHECK_EQUAL( original.GetFields().size(), originalCount );
50}
51
52
53BOOST_AUTO_TEST_CASE( ExistingSuffixRetainsItsValueAndAppearance )
54{
55 SCH_SHEET sheet;
56 SCH_FIELD custom( &sheet, FIELD_T::SHEET_USER, wxS( "Description" ) );
58 sheet.AddField( custom );
59
60 SCH_FIELD suffix( &sheet, FIELD_T::SHEET_REF_SUFFIX, wxS( "Reference Suffix" ) );
62 suffix.SetText( wxS( "_${CH}" ) );
63 suffix.SetVisible( true );
64 suffix.SetBold( true );
65 suffix.SetPosition( VECTOR2I( 1500, 2000 ) );
66 sheet.AddField( suffix );
67
68 std::vector<SCH_FIELD> fields = GetSheetFieldsForEditing( sheet );
69
70 BOOST_REQUIRE_EQUAL( fields.size(), sheet.GetFields().size() );
71 BOOST_REQUIRE( fields[2].GetId() == FIELD_T::SHEET_REF_SUFFIX );
72 BOOST_CHECK_EQUAL( fields[2].GetText(), wxS( "_${CH}" ) );
73 BOOST_CHECK( fields[2].IsVisible() );
74 BOOST_CHECK( fields[2].IsBold() );
75 BOOST_CHECK( fields[2].GetPosition() == VECTOR2I( 1500, 2000 ) );
76 BOOST_CHECK_EQUAL( fields[3].GetName(), wxS( "Description" ) );
77
78 fields[2].SetText( wxS( "_M2" ) );
79
80 const SCH_SHEET& original = sheet;
81
82 BOOST_CHECK_EQUAL( original.GetField( FIELD_T::SHEET_REF_SUFFIX )->GetText(), wxS( "_${CH}" ) );
83}
84
85
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
Definition eda_text.cpp:311
void SetOrdinal(int aOrdinal, FIELD_T aType)
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
void SetPosition(const VECTOR2I &aPosition) override
void SetText(const wxString &aText) override
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
Definition sch_sheet.h:93
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add aFieldName to the list of fields.
std::vector< SCH_FIELD > GetSheetFieldsForEditing(const SCH_SHEET &aSheet)
bool IsBold(TEXT_STYLE_FLAGS aFlags)
Definition font.h:64
@ SHEET_REF_SUFFIX
Optional sheet field appended to the references of the sheet's symbols.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(MissingSuffixIsEditableWithoutChangingTheSheet)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708