KiCad PCB EDA Suite
Loading...
Searching...
No Matches
cvpcb_fpviewer_selection_tool.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 <functional>
21
using namespace
std::placeholders;
22
23
#include <
tool/tool_event.h
>
24
#include <
tool/tool_manager.h
>
25
#include <
tools/cvpcb_actions.h
>
26
#include <
tools/cvpcb_fpviewer_selection_tool.h
>
27
28
29
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL
() :
30
TOOL_INTERACTIVE
(
"common.InteractiveSelection"
),
31
m_frame
( nullptr )
32
{
33
}
34
35
36
bool
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Init
()
37
{
38
getEditFrame<DISPLAY_FOOTPRINTS_FRAME>
()->AddStandardSubMenus( *
m_menu
.get() );
39
return
true
;
40
}
41
42
43
void
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Reset
(
RESET_REASON
aReason )
44
{
45
m_frame
=
getEditFrame<DISPLAY_FOOTPRINTS_FRAME>
();
46
}
47
48
49
int
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main
(
const
TOOL_EVENT
& aEvent )
50
{
51
// Main loop: keep receiving events
52
while
(
TOOL_EVENT
* evt =
Wait
() )
53
{
54
if
(
m_frame
->ToolStackIsEmpty() )
55
m_frame
->GetCanvas()->SetCurrentCursor(
KICURSOR::ARROW
);
56
57
if
( evt->IsClick(
BUT_LEFT
) )
58
{
59
clearSelection
();
60
}
61
else
if
( evt->IsClick(
BUT_RIGHT
) )
62
{
63
m_menu
->ShowContextMenu(
m_selection
);
64
}
65
else
if
( evt->IsDblClick(
BUT_MIDDLE
) )
66
{
67
m_toolMgr
->RunAction(
ACTIONS::zoomFitScreen
);
68
}
69
else
if
( evt->IsCancel() || evt->Action() ==
TA_UNDO_REDO_PRE
)
70
{
71
clearSelection
();
72
}
73
else
74
{
75
evt->SetPassEvent();
76
}
77
}
78
79
return
0;
80
}
81
82
83
int
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu
(
const
TOOL_EVENT
& aEvent )
84
{
85
ACTION_MENU
* actionMenu = aEvent.
Parameter
<
ACTION_MENU
*>();
86
CONDITIONAL_MENU
* conditionalMenu =
dynamic_cast<
CONDITIONAL_MENU
*
>
( actionMenu );
87
88
if
( conditionalMenu )
89
conditionalMenu->
Evaluate
(
m_selection
);
90
91
if
( actionMenu )
92
actionMenu->
UpdateAll
();
93
94
return
0;
95
}
96
97
98
void
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions
()
99
{
100
Go
( &
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu
,
ACTIONS::updateMenu
.MakeEvent() );
101
Go
( &
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main
,
ACTIONS::selectionActivate
.MakeEvent() );
102
}
ACTIONS::selectionActivate
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition
actions.h:213
ACTIONS::updateMenu
static TOOL_ACTION updateMenu
Definition
actions.h:271
ACTIONS::zoomFitScreen
static TOOL_ACTION zoomFitScreen
Definition
actions.h:141
ACTION_MENU
Define the structure of a menu based on ACTIONs.
Definition
action_menu.h:47
ACTION_MENU::UpdateAll
void UpdateAll()
Run update handlers for the menu and its submenus.
Definition
action_menu.cpp:291
CONDITIONAL_MENU
Definition
conditional_menu.h:42
CONDITIONAL_MENU::Evaluate
void Evaluate(const SELECTION &aSelection)
Update the contents of the menu based on the supplied conditions.
Definition
conditional_menu.cpp:128
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL()
Definition
cvpcb_fpviewer_selection_tool.cpp:29
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::m_frame
DISPLAY_FOOTPRINTS_FRAME * m_frame
Pointer to the parent frame.
Definition
cvpcb_fpviewer_selection_tool.h:73
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions
void setTransitions() override
Set up handlers for various events.
Definition
cvpcb_fpviewer_selection_tool.cpp:98
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Init
bool Init() override
Init() is called once upon a registration of the tool.
Definition
cvpcb_fpviewer_selection_tool.cpp:36
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Reset
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Definition
cvpcb_fpviewer_selection_tool.cpp:43
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::m_selection
SELECTION m_selection
Current state of selection (not really used: no selection in display footprints frame).
Definition
cvpcb_fpviewer_selection_tool.h:76
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu
int UpdateMenu(const TOOL_EVENT &aEvent)
Update the menu to reflect the current tool states.
Definition
cvpcb_fpviewer_selection_tool.cpp:83
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main
int Main(const TOOL_EVENT &aEvent)
The main loop.
Definition
cvpcb_fpviewer_selection_tool.cpp:49
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::clearSelection
void clearSelection()
Definition
cvpcb_fpviewer_selection_tool.h:59
TOOL_BASE::getEditFrame
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition
tool_base.h:186
TOOL_BASE::m_toolMgr
TOOL_MANAGER * m_toolMgr
Definition
tool_base.h:220
TOOL_BASE::RESET_REASON
RESET_REASON
Determine the reason of reset for a tool.
Definition
tool_base.h:78
TOOL_EVENT
Generic, UI-independent tool event.
Definition
tool_event.h:171
TOOL_EVENT::Parameter
T Parameter() const
Return a parameter assigned to the event.
Definition
tool_event.h:473
TOOL_INTERACTIVE::Go
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
Definition
tool_interactive.h:147
TOOL_INTERACTIVE::m_menu
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
Definition
tool_interactive.h:125
TOOL_INTERACTIVE::TOOL_INTERACTIVE
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
Definition
tool_interactive.cpp:39
TOOL_INTERACTIVE::Wait
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
Definition
tool_interactive.cpp:71
KICURSOR::ARROW
@ ARROW
Definition
cursors.h:46
cvpcb_actions.h
cvpcb_fpviewer_selection_tool.h
tool_event.h
TA_UNDO_REDO_PRE
@ TA_UNDO_REDO_PRE
This event is sent before undo/redo command is performed.
Definition
tool_event.h:106
BUT_MIDDLE
@ BUT_MIDDLE
Definition
tool_event.h:134
BUT_LEFT
@ BUT_LEFT
Definition
tool_event.h:132
BUT_RIGHT
@ BUT_RIGHT
Definition
tool_event.h:133
tool_manager.h
src
cvpcb
tools
cvpcb_fpviewer_selection_tool.cpp
Generated on Sun Sep 21 2025 01:05:22 for KiCad PCB EDA Suite by
1.13.2