KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_board_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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21#include <tool/tool_manager.h>
23#include <board.h>
24#include <board_commit.h>
25#include <footprint.h>
26#include <pcb_shape.h>
27#include <pcb_text.h>
28#include <pcb_group.h>
29
30BOOST_AUTO_TEST_SUITE( BoardCommit )
31
32BOOST_AUTO_TEST_CASE( RecursesThroughGroups )
33{
34 BOARD board;
35 TOOL_MANAGER mgr;
36 mgr.SetEnvironment( &board, nullptr, nullptr, nullptr, nullptr );
38 mgr.RegisterTool( dummyTool );
39 BOARD_COMMIT commit( dummyTool );
40
41 PCB_SHAPE s1( nullptr, SHAPE_T::SEGMENT );
42 PCB_SHAPE s2( nullptr, SHAPE_T::SEGMENT );
43 PCB_GROUP group( nullptr );
44 group.AddItem( &s1 );
45 group.AddItem( &s2 );
46
47 commit.Stage( &group, CHT_MODIFY, nullptr, RECURSE_MODE::RECURSE );
48
49 BOOST_CHECK_EQUAL( commit.GetStatus( &s1 ), CHT_MODIFY );
50 BOOST_CHECK_EQUAL( commit.GetStatus( &s2 ), CHT_MODIFY );
51}
52
53BOOST_AUTO_TEST_CASE( MakeImageCreatesTransientCopy )
54{
55 PCB_SHAPE shape( nullptr, SHAPE_T::SEGMENT );
57
59 BOOST_CHECK( copy != &shape );
60 BOOST_CHECK( copy->HasFlag( UR_TRANSIENT ) );
61
62 delete copy;
63}
64
65BOOST_AUTO_TEST_CASE( ReturnsBoardFromManager )
66{
67 BOARD board;
68 TOOL_MANAGER mgr;
69 mgr.SetEnvironment( &board, nullptr, nullptr, nullptr, nullptr );
71 mgr.RegisterTool( dummyTool );
72
73 BOARD_COMMIT commit( dummyTool );
74
75 BOOST_CHECK_EQUAL( commit.GetBoard(), &board );
76}
77
78BOOST_AUTO_TEST_CASE( RemoveFootprintTextFromBoardEditor )
79{
80 BOARD board;
81 TOOL_MANAGER mgr;
82 mgr.SetEnvironment( &board, nullptr, nullptr, nullptr, nullptr );
84 mgr.RegisterTool( dummyTool );
85
86 FOOTPRINT* fp = new FOOTPRINT( &board );
87 PCB_TEXT* text = new PCB_TEXT( fp );
88 text->SetText( wxT( "${REFERENCE}" ) );
89 text->SetLayer( F_Fab );
90 fp->Add( text );
91 board.Add( fp );
92
93 BOOST_REQUIRE_EQUAL( fp->GraphicalItems().size(), 1 );
94
95 {
96 BOARD_COMMIT commit( &mgr, true, false );
97 commit.Remove( text );
98 commit.Push( wxT( "Delete" ), SKIP_UNDO );
99 }
100
101 BOOST_CHECK_EQUAL( fp->GraphicalItems().size(), 0 );
102}
103
105
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
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.
BOARD * GetBoard() const
static EDA_ITEM * MakeImage(EDA_ITEM *aItem)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1247
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:90
int GetStatus(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Returns status of an item.
Definition commit.cpp:171
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:100
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
DRAWINGS & GraphicalItems()
Definition footprint.h:380
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:53
Master controller class:
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
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:44
@ RECURSE
Definition eda_item.h:53
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack
@ SEGMENT
Definition eda_shape.h:50
@ F_Fab
Definition layer_ids.h:119
Class to handle a set of BOARD_ITEMs.
#define SKIP_UNDO
Definition sch_commit.h:40
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(RecursesThroughGroups)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")