KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24335_group_move_ancestor.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, see <https://www.gnu.org/licenses/>.
18 */
19
35
36#include <boost/test/unit_test.hpp>
37
38#include <eda_item.h>
39#include <sch_field.h>
40#include <sch_group.h>
41#include <sch_line.h>
42#include <sch_screen.h>
43#include <sch_symbol.h>
44#include <schematic.h>
46
48
49#include <wx/filename.h>
50#include <wx/stdpaths.h>
51
52
54{
57 {
58 wxString tempDir = wxStandardPaths::Get().GetTempDir();
59 wxString projectPath = tempDir + wxFileName::GetPathSeparator()
60 + wxT( "test_issue24335.kicad_pro" );
61 m_tempFiles.push_back( projectPath );
62
63 m_settingsManager.LoadProject( projectPath.ToStdString() );
64 m_schematic = std::make_unique<SCHEMATIC>( nullptr );
65 m_schematic->SetProject( &m_settingsManager.Prj() );
66 m_schematic->CreateDefaultScreens();
67 }
68
70 {
71 m_schematic.reset();
72
73 for( const wxString& file : m_tempFiles )
74 {
75 if( wxFileExists( file ) )
76 wxRemoveFile( file );
77 }
78 }
79
81 std::unique_ptr<SCHEMATIC> m_schematic;
82 std::vector<wxString> m_tempFiles;
83};
84
85
86BOOST_FIXTURE_TEST_SUITE( Issue24335GroupMoveAncestor, GROUP_MOVE_ANCESTOR_FIXTURE )
87
88
89BOOST_AUTO_TEST_CASE( SymbolInsideSelectedGroupReportsAncestor )
90{
91 SCH_SCREEN* screen = m_schematic->GetTopLevelSheets()[0]->GetScreen();
92 BOOST_REQUIRE( screen );
93
94 SCH_SYMBOL* symbol = new SCH_SYMBOL();
95 symbol->SetPosition( VECTOR2I( 0, 0 ) );
96 screen->Append( symbol );
97
98 SCH_GROUP* group = new SCH_GROUP( screen );
99 group->AddItem( symbol );
100 screen->Append( group );
101
102 // Baseline: nothing is selected.
103 BOOST_CHECK( !symbol->IsSelected() );
104 BOOST_CHECK( !symbol->HasSelectedAncestorGroup() );
105
106 // Selecting the group must propagate to "ancestor is selected" for the symbol even though the
107 // symbol itself does not carry the SELECTED flag (group selection replaces members in the
108 // collector).
109 group->SetSelected();
110
111 BOOST_CHECK( !symbol->IsSelected() );
112 BOOST_CHECK( symbol->HasSelectedAncestorGroup() );
113
114 group->ClearSelected();
115 BOOST_CHECK( !symbol->HasSelectedAncestorGroup() );
116}
117
118
119BOOST_AUTO_TEST_CASE( NestedGroupAncestorIsDetected )
120{
121 SCH_SCREEN* screen = m_schematic->GetTopLevelSheets()[0]->GetScreen();
122 BOOST_REQUIRE( screen );
123
124 SCH_SYMBOL* symbol = new SCH_SYMBOL();
125 symbol->SetPosition( VECTOR2I( 0, 0 ) );
126 screen->Append( symbol );
127
128 SCH_GROUP* inner = new SCH_GROUP( screen );
129 inner->AddItem( symbol );
130 screen->Append( inner );
131
132 SCH_GROUP* outer = new SCH_GROUP( screen );
133 outer->AddItem( inner );
134 screen->Append( outer );
135
136 BOOST_REQUIRE( symbol->GetParentGroup() == inner );
137 BOOST_REQUIRE( inner->GetParentGroup() == outer );
138
139 // Selecting only the outer group must still be picked up by the symbol's ancestor walk.
140 outer->SetSelected();
141 BOOST_CHECK( symbol->HasSelectedAncestorGroup() );
142 BOOST_CHECK( inner->HasSelectedAncestorGroup() );
143
144 outer->ClearSelected();
145 inner->SetSelected();
146 BOOST_CHECK( symbol->HasSelectedAncestorGroup() );
147 BOOST_CHECK( !inner->HasSelectedAncestorGroup() );
148}
149
150
151BOOST_AUTO_TEST_CASE( SymbolFieldInheritsAncestorGroupViaParent )
152{
153 SCH_SCREEN* screen = m_schematic->GetTopLevelSheets()[0]->GetScreen();
154 BOOST_REQUIRE( screen );
155
156 // Symbol fields are children of the symbol (GetParent() == symbol). When the symbol's group
157 // is selected, the field must also be recognised as moving with the group via the parent walk.
158 SCH_SYMBOL* symbol = new SCH_SYMBOL();
159 symbol->SetPosition( VECTOR2I( 0, 0 ) );
160 screen->Append( symbol );
161
162 SCH_GROUP* group = new SCH_GROUP( screen );
163 group->AddItem( symbol );
164 screen->Append( group );
165
166 SCH_FIELD* field = symbol->GetField( FIELD_T::REFERENCE );
167 BOOST_REQUIRE( field );
168 BOOST_REQUIRE( field->GetParent() == symbol );
169 BOOST_REQUIRE( field->GetParentGroup() == nullptr );
170
171 group->SetSelected();
172
173 BOOST_CHECK( field->HasSelectedAncestorGroup() );
174}
175
176
177BOOST_AUTO_TEST_CASE( WireInsideSelectedGroupReportsAncestor )
178{
179 SCH_SCREEN* screen = m_schematic->GetTopLevelSheets()[0]->GetScreen();
180 BOOST_REQUIRE( screen );
181
182 SCH_LINE* wire = new SCH_LINE( VECTOR2I( 0, 0 ), LAYER_WIRE );
183 wire->SetEndPoint( VECTOR2I( 100000, 0 ) );
184 screen->Append( wire );
185
186 SCH_GROUP* group = new SCH_GROUP( screen );
187 group->AddItem( wire );
188 screen->Append( group );
189
190 group->SetSelected();
191
192 // The connectivity walker relies on this signal to avoid double-moving in-group wires.
193 BOOST_CHECK( wire->HasSelectedAncestorGroup() );
194}
195
196
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:58
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:114
void ClearSelected()
Definition eda_item.h:147
bool IsSelected() const
Definition eda_item.h:132
void SetSelected()
Definition eda_item.h:144
EDA_ITEM * GetParent() const
Definition eda_item.h:110
bool HasSelectedAncestorGroup() const
Definition eda_item.cpp:106
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:145
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Schematic symbol object.
Definition sch_symbol.h:69
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_symbol.h:886
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
@ LAYER_WIRE
Definition layer_ids.h:450
Class to handle a set of SCH_ITEMs.
@ REFERENCE
Field Reference of part, i.e. "IC21".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(SymbolInsideSelectedGroupReportsAncestor)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683