KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_commit.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
20#include <boost/test/unit_test.hpp>
21#include <tool/tool_manager.h>
22#include <sch_commit.h>
23#include <sch_group.h>
24#include <sch_text.h>
25#include <sch_line.h>
26#include <sch_screen.h>
27#include <sch_label.h>
28#include <schematic.h>
29#include <connection_graph.h>
32
33BOOST_AUTO_TEST_SUITE( SchCommit )
34
35BOOST_AUTO_TEST_CASE( RecursesThroughGroups )
36{
37 TOOL_MANAGER mgr;
38 SCH_COMMIT commit( &mgr );
39
40 SCH_TEXT t1;
41 SCH_TEXT t2;
43 group.AddItem( &t1 );
44 group.AddItem( &t2 );
45
46 commit.Stage( &group, CHT_MODIFY, nullptr, RECURSE_MODE::RECURSE );
47
48 BOOST_CHECK_EQUAL( commit.GetStatus( &t1 ), CHT_MODIFY );
49 BOOST_CHECK_EQUAL( commit.GetStatus( &t2 ), CHT_MODIFY );
50}
51
52BOOST_AUTO_TEST_CASE( ClearsSelectedByDragFlag )
53{
54 TOOL_MANAGER mgr;
55 SCH_COMMIT commit( &mgr );
56
58 text.SetFlags( SELECTED_BY_DRAG );
59 text.SetSelected();
60
61 commit.Stage( &text, CHT_MODIFY );
62
63 BOOST_CHECK( text.IsSelected() );
65}
66
67BOOST_AUTO_TEST_CASE( CommitCanDeferConnectivityUntilExplicitRebuild )
68{
69 SETTINGS_MANAGER settings;
70 std::unique_ptr<SCHEMATIC> schematic;
71 KI_TEST::LoadSchematic( settings, "netlists/multinetclasses/multinetclasses", schematic );
72 const SCH_SHEET_PATH path = schematic->Hierarchy().front();
73 SCH_SCREEN* screen = path.LastScreen();
74 SCH_LABEL* label = nullptr;
75
76 for( SCH_ITEM* item : screen->Items().OfType( SCH_LABEL_T ) )
77 {
78 auto* candidate = static_cast<SCH_LABEL*>( item );
79
80 if( candidate->GetText() == "NET_2" )
81 label = candidate;
82 }
83
84 BOOST_REQUIRE( label );
85 schematic->ConnectionGraph()->Reset();
86 TOOL_MANAGER manager;
87 manager.SetEnvironment( schematic.get(), nullptr, nullptr, nullptr, nullptr );
88 SCH_COMMIT commit( &manager );
89 commit.Modify( label, screen );
90 label->SetText( "DEFERRED_CONNECTIVITY" );
91 commit.Push( "Rename label", SKIP_UNDO | SKIP_CONNECTIVITY );
92 BOOST_CHECK( commit.Empty() );
93 BOOST_CHECK_EQUAL( label->GetText(), "DEFERRED_CONNECTIVITY" );
94 BOOST_CHECK( schematic->ConnectionGraph()->GetNetMap().empty() );
95 schematic->RecalculateConnections( nullptr, GLOBAL_CLEANUP, &manager );
96 const auto name = label->GetConnectionName( &path );
98 BOOST_CHECK_EQUAL( *name, "/DEFERRED_CONNECTIVITY" );
99}
100
101BOOST_AUTO_TEST_CASE( RevertingCleanupRestoresMergedWireBeforeItsMove )
102{
103 SETTINGS_MANAGER settings;
104 std::unique_ptr<SCHEMATIC> schematic;
105 KI_TEST::LoadSchematic( settings, "issue12505", schematic );
106 SCH_SCREEN* screen = schematic->GetCurrentScreen();
107 auto* wire = dynamic_cast<SCH_LINE*>(
108 screen->GetConnectivityItem( KIID( "8d2c5f9b-5bc9-4d6f-9ddd-e2fce9531195" ) ) );
109 auto* other = dynamic_cast<SCH_LINE*>(
110 screen->GetConnectivityItem( KIID( "06af46a6-6f60-4f17-95ae-2a85a89f02a6" ) ) );
111 BOOST_REQUIRE( wire && other );
112 const VECTOR2I start = wire->GetStartPoint();
113 const VECTOR2I end = wire->GetEndPoint();
114 TOOL_MANAGER manager;
115 manager.SetEnvironment( schematic.get(), nullptr, nullptr, nullptr, nullptr );
116 SCH_COMMIT move( &manager );
117 move.Modify( wire, screen );
118 wire->Move( other->GetStartPoint() - start );
119 screen->Update( wire );
120 schematic->CleanUp( &move, screen );
121 BOOST_REQUIRE( !screen->CheckIfOnDrawList( wire ) );
122
123 move.Revert();
124 BOOST_CHECK( screen->CheckIfOnDrawList( wire ) );
125 BOOST_CHECK( wire->GetStartPoint() == start );
126 BOOST_CHECK( wire->GetEndPoint() == end );
127 BOOST_CHECK( !wire->HasFlag( STRUCT_DELETED ) );
128 BOOST_CHECK( screen->GetConnectivityItem( wire->m_Uuid ) == wire );
129}
130
132
const char * name
bool Empty() const
Definition commit.h:142
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
int GetStatus(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Returns status of an item.
Definition commit.cpp:232
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:231
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
Definition kiid.h:46
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE) override
Add a change of the item aItem of type aChangeType to the change list.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
std::optional< wxString > GetConnectionName(const SCH_SHEET_PATH *aSheet=nullptr, bool aLocal=false, bool aIgnoreSheet=false) const
Return the connection name for this sheet instance, if connected.
Definition sch_item.cpp:539
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:118
SCH_ITEM * GetConnectivityItem(const KIID &aId) const
Resolve a drawing item or a connectable child on this screen; ambiguous IDs return null.
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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).
@ CHT_MODIFY
Definition commit.h:40
@ RECURSE
Definition eda_item.h:51
#define SELECTED_BY_DRAG
Item was algorithmically selected as a dragged item.
#define STRUCT_DELETED
flag indication structures to be erased
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
#define SKIP_CONNECTIVITY
Definition sch_commit.h:41
#define SKIP_UNDO
Definition sch_commit.h:38
Class to handle a set of SCH_ITEMs.
@ GLOBAL_CLEANUP
Definition schematic.h:94
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_AUTO_TEST_CASE(RecursesThroughGroups)
VECTOR2I end
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_LABEL_T
Definition typeinfo.h:163
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683