KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_connectivity_revision.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
22
23#include <advanced_config.h>
26#include <lib_symbol.h>
27#include <sch_commit.h>
28#include <sch_pin.h>
29#include <sch_screen.h>
30#include <sch_sheet.h>
31#include <sch_symbol.h>
32#include <schematic.h>
34#include <tool/tool_manager.h>
35#include <scoped_set_reset.h>
36
37
39{
41 std::unique_ptr<SCHEMATIC> schematic;
42};
43
44
45BOOST_FIXTURE_TEST_SUITE( ConnectivityRevision, CONNECTIVITY_REVISION_FIXTURE )
46
47BOOST_AUTO_TEST_CASE( ScreenIndexTracksSymbolPinReplacementAndUndo )
48{
50 SCOPED_SET_RESET restoreEngine( config.m_ConnectivityEngine, config.m_ConnectivityEngine );
51 SCOPED_SET_RESET restoreIncremental( config.m_IncrementalConnectivity, config.m_IncrementalConnectivity );
52 config.m_ConnectivityEngine = true;
53 config.m_IncrementalConnectivity = true;
54
55 KI_TEST::LoadSchematic( settings, "issue7203", schematic );
56 SCH_SCREEN* screen = schematic->GetTopLevelSheets().front()->GetScreen();
57 SCH_SYMBOL* symbol = nullptr;
58
59 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
60 {
61 SCH_SYMBOL* candidate = static_cast<SCH_SYMBOL*>( item );
62
63 if( candidate->GetLibSymbolRef() && candidate->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ).size() >= 2 )
64 {
65 symbol = candidate;
66 break;
67 }
68 }
69
70 BOOST_REQUIRE( symbol );
71 TOOL_MANAGER manager;
72 manager.SetEnvironment( schematic.get(), nullptr, nullptr, nullptr, nullptr );
73 schematic->RebuildConnectivity();
75
76 const auto verify =
77 [&]()
78 {
79 const std::string incremental = SCH_CONNECTIVITY::Dump( *schematic, schematic->Connectivity() );
80 rebuilt.Update( *schematic, true );
81 BOOST_CHECK_EQUAL( incremental, SCH_CONNECTIVITY::Dump( *schematic, rebuilt ) );
82 };
83
84 verify();
85
87 const KIID id = pin->m_Uuid;
88 const wxString number = pin->GetNumber();
89 const KIID_PATH path = schematic->Hierarchy().front().Path();
90
91 BOOST_REQUIRE( schematic->Connectivity().Connection( id, path ) );
92 BOOST_REQUIRE( screen->GetConnectivityItem( id ) == pin );
93 std::unique_ptr<SCH_ITEM> undo( static_cast<SCH_ITEM*>( symbol->Clone() ) );
94 std::unique_ptr<LIB_SYMBOL> updated = symbol->GetLibSymbolRef()->Flatten();
95
96 for( SCH_PIN* libPin : updated->GetPinsByNumber( number ) )
97 updated->RemoveDrawItem( libPin );
98
99 SCH_COMMIT replacement( &manager );
100 replacement.Modify( symbol, screen );
101 symbol->SetLibSymbol( updated.release() );
102 BOOST_CHECK( !screen->GetConnectivityItem( id ) );
103 replacement.Push( "Replace native symbol pin set", SKIP_UNDO );
104 BOOST_CHECK( !schematic->Connectivity().Connection( id, path ) );
105 verify();
106
107 SCH_COMMIT restoration( &manager );
108 restoration.Modify( symbol, screen );
109 symbol->SwapItemData( undo.get() );
110 SCH_ITEM* restored = screen->GetConnectivityItem( id );
111 BOOST_REQUIRE( restored );
112 BOOST_CHECK( restored->GetParent() == symbol );
113 BOOST_CHECK( restored == symbol->GetPin( number ) );
114 restoration.Push( "Restore native symbol pin set", SKIP_UNDO );
115 BOOST_REQUIRE( schematic->Connectivity().Connection( id, path ) );
116 verify();
117}
118
119
120BOOST_AUTO_TEST_CASE( AssigningSymbolPreservesAlternatePinDefinitions )
121{
122 KI_TEST::LoadSchematic( settings, "issue22286/bugtest", schematic );
123 SCH_SCREEN* screen = schematic->GetTopLevelSheets().front()->GetScreen();
124 SCH_SYMBOL* symbol = nullptr;
125 SCH_PIN* pin = nullptr;
126
127 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
128 {
129 auto* candidate = static_cast<SCH_SYMBOL*>( item );
130
131 for( SCH_PIN* candidatePin : candidate->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES ) )
132 {
133 if( !candidatePin->GetAlt().IsEmpty() )
134 {
135 symbol = candidate;
136 pin = candidatePin;
137 break;
138 }
139 }
140
141 if( symbol )
142 break;
143 }
144
145 BOOST_REQUIRE( symbol );
146 const KIID id = pin->m_Uuid;
147 const wxString alternate = pin->GetAlt();
148 const auto type = pin->GetType();
149 BOOST_REQUIRE( screen->GetConnectivityItem( id ) == pin );
150 auto copy = std::make_unique<SCH_SYMBOL>( *symbol );
151 *symbol = *copy;
152 auto* updated = dynamic_cast<SCH_PIN*>( screen->GetConnectivityItem( id ) );
153 BOOST_REQUIRE( updated );
154 BOOST_REQUIRE( updated->GetLibPin() );
155 BOOST_CHECK_EQUAL( updated->GetAlt(), alternate );
156 BOOST_CHECK( updated->GetType() == type );
157 BOOST_CHECK( updated->GetLibPin()->GetParent() == symbol->GetLibSymbolRef().get() );
158}
159
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
EDA_ITEM * GetParent() const
Definition eda_item.h:112
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
Definition kiid.h:46
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Model-owned source resolver.
void Update(SCHEMATIC &aSchematic, bool aRebuild=false)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
void SwapItemData(SCH_ITEM *aImage)
Swap data between aItem and aImage.
Definition sch_item.cpp:840
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
SCH_ITEM * GetConnectivityItem(const KIID &aId) const
Resolve a drawing item or a connectable child on this screen; ambiguous IDs return null.
Schematic symbol object.
Definition sch_symbol.h:73
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit, int aBodyStyle) const override
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:182
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
RAII class that sets an value at construction and resets it to the original value at destruction.
Master controller class:
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::string Dump(SCHEMATIC &aSchematic)
Canonical, pointer-free connectivity rows for migration and rebuild comparisons.
#define SKIP_UNDO
Definition sch_commit.h:38
std::unique_ptr< SCHEMATIC > schematic
#define ALL_UNITS
Definition symbol.h:150
#define ALL_BODY_STYLES
Definition symbol.h:151
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(ScreenIndexTracksSymbolPinReplacementAndUndo)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
KIBIS_PIN * pin
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_SYMBOL_T
Definition typeinfo.h:168