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 (C) 2018-2021 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>
21using namespace std::placeholders;
22
23#include <tool/tool_event.h>
24#include <tool/tool_manager.h>
25#include <tools/cvpcb_actions.h>
27
28
30 TOOL_INTERACTIVE( "cvpcb.FootprintViewerInteractiveSelection" ),
31 m_frame( nullptr )
32{
33}
34
35
37{
38 getEditFrame<DISPLAY_FOOTPRINTS_FRAME>()->AddStandardSubMenus( m_menu );
39 return true;
40}
41
42
44{
45 m_frame = getEditFrame<DISPLAY_FOOTPRINTS_FRAME>();
46}
47
48
50{
51 // Main loop: keep receiving events
52 while( TOOL_EVENT* evt = Wait() )
53 {
55 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
56
57 if( evt->IsClick( BUT_LEFT ) )
58 {
60 }
61 else if( evt->IsClick( BUT_RIGHT ) )
62 {
64 }
65 else if( evt->IsDblClick( BUT_MIDDLE ) )
66 {
68 }
69 else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE )
70 {
72 }
73 else
74 {
75 evt->SetPassEvent();
76 }
77 }
78
79 return 0;
80}
81
82
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
99{
103}
static TOOL_ACTION updateMenu
Definition: actions.h:204
static TOOL_ACTION zoomFitScreen
Definition: actions.h:124
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void UpdateAll()
Run update handlers for the menu and its submenus.
void Evaluate(const SELECTION &aSelection)
Update the contents of the menu based on the supplied conditions.
static TOOL_ACTION selectionActivate
Activation actions.
Definition: cvpcb_actions.h:41
DISPLAY_FOOTPRINTS_FRAME * m_frame
Pointer to the parent frame.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
bool Init() override
Init() is called once upon a registration of the tool.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
SELECTION m_selection
Current state of selection (not really used: no selection in display footprints frame).
int UpdateMenu(const TOOL_EVENT &aEvent)
Update the menu to reflect the current tool states.
int Main(const TOOL_EVENT &aEvent)
The main loop.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
bool ToolStackIsEmpty()
Definition: tools_holder.h:125
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
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).
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
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.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:145
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:57
@ TA_UNDO_REDO_PRE
Definition: tool_event.h:105
@ BUT_MIDDLE
Definition: tool_event.h:133
@ BUT_LEFT
Definition: tool_event.h:131
@ BUT_RIGHT
Definition: tool_event.h:132