KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_tool_prime.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_event.h>
23#include <tool/tool_manager.h>
24
30
31namespace
32{
33// Not the tool name: for TC_COMMAND events matching is by name alone, so a start event named
34// like the tool would also match the activation event Activate() sends and re-enter Main.
35const TOOL_EVENT START_EVENT( TC_COMMAND, TA_ACTION, std::string( "test.primeRecorder.start" ) );
36
37
38class PRIME_RECORDER_TOOL : public TOOL_INTERACTIVE
39{
40public:
41 PRIME_RECORDER_TOOL() :
42 TOOL_INTERACTIVE( "test.primeRecorder" ),
43 m_gotClick( false ),
44 m_hadPosition( false )
45 {
46 }
47
48 void Reset( RESET_REASON aReason ) override {}
49
50 int Main( const TOOL_EVENT& aEvent )
51 {
52 Activate();
53
54 while( TOOL_EVENT* evt = Wait() )
55 {
56 // The same test the router main loop uses to start routing from a click.
57 if( evt->IsClick( BUT_LEFT ) )
58 {
59 m_gotClick = true;
60 m_hadPosition = evt->HasPosition();
61
62 if( m_hadPosition )
63 m_clickPos = evt->Position();
64
65 break;
66 }
67 }
68
69 return 0;
70 }
71
72 bool m_gotClick;
73 bool m_hadPosition;
74 VECTOR2D m_clickPos;
75
76private:
77 void setTransitions() override { Go( &PRIME_RECORDER_TOOL::Main, START_EVENT ); }
78};
79} // namespace
80
81
82BOOST_AUTO_TEST_SUITE( ToolManagerPriming )
83
84BOOST_AUTO_TEST_CASE( PrimeActsAsPositionedLeftClick )
85{
86 TOOL_MANAGER mgr;
87 PRIME_RECORDER_TOOL* tool = new PRIME_RECORDER_TOOL();
88
89 mgr.SetEnvironment( nullptr, nullptr, nullptr, nullptr, nullptr );
90 mgr.RegisterTool( tool );
92
93 mgr.ProcessEvent( START_EVENT );
94 BOOST_REQUIRE( !tool->m_gotClick );
95
96 const VECTOR2D primePos( 1250000, -730000 );
97 mgr.PrimeTool( primePos );
98
99 // Priming only queues the click, so it arrives on the next processing pass.
100 BOOST_REQUIRE( !tool->m_gotClick );
102
103 BOOST_REQUIRE( tool->m_gotClick );
104 BOOST_CHECK( tool->m_hadPosition );
105 BOOST_CHECK_EQUAL( tool->m_clickPos.x, primePos.x );
106 BOOST_CHECK_EQUAL( tool->m_clickPos.y, primePos.y );
107}
108
@ RUN
Tool is invoked after being inactive.
Definition tool_base.h:75
Generic, UI-independent tool event.
Definition tool_event.h:167
Master controller class:
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void PrimeTool(const VECTOR2D &aPosition)
"Prime" a tool by sending a cursor left-click event with the mouse position set to the passed in posi...
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
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).
void Reset() override
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
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")
@ TA_MOUSE_MOTION
Definition tool_event.h:68
@ TA_ACTION
Tool action (allows one to control tools).
Definition tool_event.h:108
@ TC_COMMAND
Definition tool_event.h:53
@ TC_MOUSE
Definition tool_event.h:51
@ BUT_LEFT
Definition tool_event.h:128
VECTOR2< double > VECTOR2D
Definition vector2d.h:682