KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24943_variant_unit_sync.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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
28
30
31#include <memory>
32
33#include <lib_symbol.h>
34#include <sch_commit.h>
35#include <sch_pin.h>
36#include <sch_symbol.h>
37#include <sch_screen.h>
38#include <sch_sheet.h>
39#include <sch_sheet_path.h>
40#include <schematic.h>
42#include <tool/tool_manager.h>
43
44#include <wx/filename.h>
45#include <wx/stdpaths.h>
46
47
49{
51 {
52 wxString tempDir = wxStandardPaths::Get().GetTempDir();
53 wxString projectPath = tempDir + wxFileName::GetPathSeparator() + wxT( "test_issue24943.kicad_pro" );
54
55 m_settingsManager.LoadProject( projectPath.ToStdString() );
56 m_schematic = std::make_unique<SCHEMATIC>( nullptr );
57 m_schematic->SetProject( &m_settingsManager.Prj() );
58 m_schematic->CreateDefaultScreens();
59
60 m_sheet = m_schematic->GetTopLevelSheets()[0];
61 SCH_SCREEN* screen = m_sheet->GetScreen();
62 screen->SetFileName( "issue24943.kicad_sch" );
63
64 m_path.clear();
65 m_path.push_back( m_sheet );
66
67 m_libSym = std::make_unique<LIB_SYMBOL>( "OPAMP", nullptr );
68
69 SCH_PIN* pin = new SCH_PIN( m_libSym.get() );
70 pin->SetNumber( "1" );
72 m_libSym->AddDrawItem( pin );
73
74 m_libSym->SetUnitCount( 2, true );
75
76 m_unitA = new SCH_SYMBOL( *m_libSym, m_libSym->GetLibId(), &m_path, 1, 0, VECTOR2I( 0, 0 ) );
77 m_unitA->UpdatePins();
78 screen->Append( m_unitA );
79
80 m_unitB = new SCH_SYMBOL( *m_libSym, m_libSym->GetLibId(), &m_path, 2, 0, VECTOR2I( 2540000, 0 ) );
81 m_unitB->UpdatePins();
82 screen->Append( m_unitB );
83
84 m_unitA->SetRef( &m_path, wxS( "U1" ) );
85 m_unitB->SetRef( &m_path, wxS( "U1" ) );
86
87 m_baseValue = wxS( "OPAMP" );
88 m_unitA->GetField( FIELD_T::VALUE )->SetText( m_baseValue );
89 m_unitB->GetField( FIELD_T::VALUE )->SetText( m_baseValue );
90 }
91
92 void sync( SCH_SYMBOL* aSource, const wxString& aVariant )
93 {
94 TOOL_MANAGER mgr;
95 SCH_COMMIT commit( &mgr );
96
97 aSource->SyncOtherUnits( m_path, commit, nullptr, aVariant );
98 }
99
101 std::unique_ptr<SCHEMATIC> m_schematic;
102 std::unique_ptr<LIB_SYMBOL> m_libSym;
103 SCH_SHEET* m_sheet = nullptr;
105 SCH_SYMBOL* m_unitA = nullptr;
106 SCH_SYMBOL* m_unitB = nullptr;
107 wxString m_baseValue;
108};
109
110
111BOOST_FIXTURE_TEST_SUITE( Issue24943VariantUnitSync, ISSUE24943_FIXTURE )
112
113
114
118BOOST_AUTO_TEST_CASE( ValueSyncUnderVariant )
119{
120 m_unitA->SetValueFieldText( wxS( "AAA" ), &m_path, wxS( "V1" ) );
121 sync( m_unitA, wxS( "V1" ) );
122
123 BOOST_CHECK_EQUAL( m_unitB->GetValue( false, &m_path, false, wxS( "V1" ) ), wxS( "AAA" ) );
124
125 BOOST_CHECK_EQUAL( m_unitA->GetValue( false, &m_path, false ), m_baseValue );
126 BOOST_CHECK_EQUAL( m_unitB->GetValue( false, &m_path, false ), m_baseValue );
127}
128
129
133BOOST_AUTO_TEST_CASE( UserFieldSyncUnderVariant )
134{
135 for( SCH_SYMBOL* unit : { m_unitA, m_unitB } )
136 {
137 SCH_FIELD mpn( unit, FIELD_T::USER, wxS( "MPN" ) );
138 mpn.SetText( wxS( "111" ) );
139 unit->AddField( mpn );
140 }
141
142 m_unitA->SetFieldText( wxS( "MPN" ), wxS( "222" ), &m_path, wxS( "V1" ) );
143 sync( m_unitA, wxS( "V1" ) );
144
145 BOOST_CHECK_EQUAL( m_unitB->GetFieldText( wxS( "MPN" ), &m_path, wxS( "V1" ) ), wxS( "222" ) );
146 BOOST_CHECK_EQUAL( m_unitB->GetField( wxS( "MPN" ) )->GetText(), wxS( "111" ) );
147}
148
149
154BOOST_AUTO_TEST_CASE( ExcludeFlagSyncUnderVariant )
155{
156 m_unitA->SetExcludedFromBOM( true, &m_path, wxS( "V1" ) );
157 sync( m_unitA, wxS( "V1" ) );
158
159 BOOST_CHECK( m_unitB->GetExcludedFromBOM( &m_path, wxS( "V1" ) ) );
160 BOOST_CHECK( !m_unitB->GetExcludedFromBOM( &m_path ) );
161}
162
163
167BOOST_AUTO_TEST_CASE( DnpSyncUnderVariantControl )
168{
169 m_unitA->SetDNP( true, &m_path, wxS( "V1" ) );
170 sync( m_unitA, wxS( "V1" ) );
171
172 BOOST_CHECK( m_unitB->GetDNP( &m_path, wxS( "V1" ) ) );
173 BOOST_CHECK( !m_unitB->GetDNP( &m_path ) );
174}
175
176
180BOOST_AUTO_TEST_CASE( ValueSyncWithoutVariant )
181{
182 m_unitA->SetValueFieldText( wxS( "BBB" ), &m_path, wxEmptyString );
183 sync( m_unitA, wxEmptyString );
184
185 BOOST_CHECK_EQUAL( m_unitB->GetValue( false, &m_path, false ), wxS( "BBB" ) );
186}
187
188
void SetText(const wxString &aText) override
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
Schematic symbol object.
Definition sch_symbol.h:69
void SyncOtherUnits(const SCH_SHEET_PATH &aSourceSheet, SCH_COMMIT &aCommit, PROPERTY_BASE *aProperty, const wxString &aVariantName=wxEmptyString)
Keep fields other than the reference, include/exclude flags, and alternate pin assignments in sync in...
Master controller class:
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Regression tests for issue 24943, design variant edits on multi-unit symbols.
void sync(SCH_SYMBOL *aSource, const wxString &aVariant)
std::unique_ptr< LIB_SYMBOL > m_libSym
std::unique_ptr< SCHEMATIC > m_schematic
@ USER
The field ID hasn't been set yet; field is invalid.
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ValueSyncUnderVariant)
A value assigned under a variant must reach the sibling unit as the same variant differential,...
KIBIS_PIN * pin
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683