KiCad PCB EDA Suite
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>
21 using 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  {
54  if( m_frame->ToolStackIsEmpty() )
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 {
102  CVPCB_ACTIONS::selectionActivate.MakeEvent() );
103 }
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
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.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
static TOOL_ACTION selectionActivate
Activation actions.
Definition: cvpcb_actions.h:41
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
int UpdateMenu(const TOOL_EVENT &aEvent)
Update the menu to reflect the current tool states.
void UpdateAll()
Run update handlers for the menu and its submenus.
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).
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.
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:432
Generic, UI-independent tool event.
Definition: tool_event.h:152
bool ToolStackIsEmpty()
Definition: tools_holder.h:116
static TOOL_ACTION updateMenu
Definition: actions.h:167
int Main(const TOOL_EVENT &aEvent)
The main loop.
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
SELECTION m_selection
Current state of selection (not really used: no selection in display footprints frame).
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59