KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_constraint_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
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
21#include <tool/tool_manager.h>
23
24#include <board.h>
25#include <board_commit.h>
27
28
29BOOST_AUTO_TEST_SUITE( ConstraintSolverCommit )
30
31
33{
37
38 COMMIT_FIXTURE() : tool( new KI_TEST::DUMMY_TOOL() )
39 {
40 mgr.SetEnvironment( &board, nullptr, nullptr, nullptr, nullptr );
41 mgr.RegisterTool( tool );
42 }
43};
44
45
46BOOST_FIXTURE_TEST_CASE( AddPushThenRemovePush, COMMIT_FIXTURE )
47{
49 KIID id = c->m_Uuid;
50
51 BOARD_COMMIT addCommit( tool );
52 addCommit.Add( c );
53 addCommit.Push( wxT( "add constraint" ) );
54
55 BOOST_CHECK_EQUAL( board.Constraints().size(), 1 );
56 BOOST_CHECK( board.ResolveItem( id, true ) == c );
57
58 // Removing must not trip the CHT_REMOVE wxASSERT(false) default for an unhandled type.
59 BOARD_COMMIT removeCommit( tool );
60 removeCommit.Remove( c );
61 removeCommit.Push( wxT( "remove constraint" ) );
62
63 BOOST_CHECK( board.Constraints().empty() );
64 BOOST_CHECK( board.ResolveItem( id, true ) == nullptr );
65}
66
67
68BOOST_FIXTURE_TEST_CASE( AddRevertLeavesNothing, COMMIT_FIXTURE )
69{
71
72 BOARD_COMMIT commit( tool );
73 commit.Add( c );
74
75 // Revert before Push undoes the staged add and frees the constraint.
76 commit.Revert();
77
78 BOOST_CHECK( board.Constraints().empty() );
79}
80
81
82BOOST_FIXTURE_TEST_CASE( ModifyRevertRestoresValue, COMMIT_FIXTURE )
83{
85 c->SetValue( 1.0 );
86
87 BOARD_COMMIT addCommit( tool );
88 addCommit.Add( c );
89 addCommit.Push( wxT( "add" ) );
90
91 BOARD_COMMIT modifyCommit( tool );
92 modifyCommit.Modify( c );
93 c->SetValue( 2.0 );
94 modifyCommit.Revert();
95
96 BOOST_REQUIRE( c->HasValue() );
97 BOOST_CHECK_CLOSE( *c->GetValue(), 1.0, 1e-9 );
98}
99
100
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
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
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:74
const KIID m_Uuid
Definition eda_item.h:531
Definition kiid.h:44
A geometric constraint between board items (issue #2329).
std::optional< double > GetValue() const
bool HasValue() const
void SetValue(std::optional< double > aValue)
Master controller class:
@ HORIZONTAL
A segment (or two points) is horizontal.
@ FIXED_LENGTH
A segment has a driving length value.
@ PARALLEL
Two segments are parallel.
KI_TEST::DUMMY_TOOL * tool
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_FIXTURE_TEST_CASE(AddPushThenRemovePush, COMMIT_FIXTURE)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")