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-2019 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 <bitmaps.h>
25 #include <tool/tool_event.h>
26 #include <tool/tool_manager.h>
27 #include <tools/cvpcb_actions.h>
29 #include <view/view.h>
30 #include <view/view_controls.h>
31 
33  TOOL_INTERACTIVE( "cvpcb.FootprintViewerInteractiveSelection" ),
34  m_frame( nullptr )
35 {
36 }
37 
38 
40 {
41  getEditFrame<DISPLAY_FOOTPRINTS_FRAME>()->AddStandardSubMenus( m_menu );
42  return true;
43 }
44 
45 
47 {
48  m_frame = getEditFrame<DISPLAY_FOOTPRINTS_FRAME>();
49 }
50 
51 
53 {
54  // Main loop: keep receiving events
55  while( TOOL_EVENT* evt = Wait() )
56  {
57  if( m_frame->ToolStackIsEmpty() )
59 
60  // single click? Select single object
61  if( evt->IsClick( BUT_LEFT ) )
62  {
64  }
65 
66  // right click? if there is any object - show the context menu
67  else if( evt->IsClick( BUT_RIGHT ) )
68  {
70  }
71 
72  // Middle double click? Do zoom to fit or zoom to objects
73  else if( evt->IsDblClick( BUT_MIDDLE ) )
74  {
76  }
77  else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE )
78  {
80  }
81 
82  else
83  evt->SetPassEvent();
84  }
85 
86  return 0;
87 }
88 
89 
91 {
92  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
93  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
94 
95  if( conditionalMenu )
96  conditionalMenu->Evaluate( m_selection );
97 
98  if( actionMenu )
99  actionMenu->UpdateAll();
100 
101  return 0;
102 }
103 
104 
106 {
109  CVPCB_ACTIONS::selectionActivate.MakeEvent() );
110 }
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.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:45
static TOOL_ACTION selectionActivate
Activation actions.
Definition: cvpcb_actions.h:44
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:215
static TOOL_ACTION zoomFitScreen
Definition: actions.h:99
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
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).
void SetCurrentCursor(KICURSOR cursor)
Set the current cursor shape for this panel.
DISPLAY_FOOTPRINTS_FRAME * m_frame
Pointer to the parent frame.
void setTransitions() override
Sets up handlers for various 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:426
Generic, UI-independent tool event.
Definition: tool_event.h:170
bool ToolStackIsEmpty()
Definition: tools_holder.h:117
static TOOL_ACTION updateMenu
Definition: actions.h:172
int Main(const TOOL_EVENT &aEvent)
Function Main()
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
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