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 <tools/cvpcb_actions.h>
28 #include <view/view.h>
29 #include <view/view_controls.h>
30 
32  TOOL_INTERACTIVE( "cvpcb.FootprintViewerInteractiveSelection" ),
33  m_frame( nullptr )
34 {
35 }
36 
37 
39 {
40  getEditFrame<DISPLAY_FOOTPRINTS_FRAME>()->AddStandardSubMenus( m_menu );
41  return true;
42 }
43 
44 
46 {
47  m_frame = getEditFrame<DISPLAY_FOOTPRINTS_FRAME>();
48 }
49 
50 
52 {
53  // Main loop: keep receiving events
54  while( TOOL_EVENT* evt = Wait() )
55  {
56  if( m_frame->ToolStackIsEmpty() )
57  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
58 
59  // single click? Select single object
60  if( evt->IsClick( BUT_LEFT ) )
61  {
63  }
64 
65  // right click? if there is any object - show the context menu
66  else if( evt->IsClick( BUT_RIGHT ) )
67  {
69  }
70 
71  else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE )
72  {
74  }
75 
76  else
77  evt->SetPassEvent();
78  }
79 
80  return 0;
81 }
82 
83 
85 {
86  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
87  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
88 
89  if( conditionalMenu )
90  conditionalMenu->Evaluate( m_selection );
91 
92  if( actionMenu )
93  actionMenu->UpdateAll();
94 
95  return 0;
96 }
97 
98 
100 {
103  CVPCB_ACTIONS::selectionActivate.MakeEvent() );
104 }
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
ACTION_MENU.
Definition: action_menu.h:44
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
VIEW_CONTROLS class definition.
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.
int UpdateMenu(const TOOL_EVENT &aEvent)
Update the menu to reflect the current tool states.
void UpdateAll()
Function UpdateAll() Runs 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))
Function Go()
DISPLAY_FOOTPRINTS_FRAME * m_frame
Pointer to the parent frame.
void setTransitions() override
Sets up handlers for various events.
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
TOOL_EVENT.
Definition: tool_event.h:171
bool ToolStackIsEmpty()
Definition: tools_holder.h:84
static TOOL_ACTION updateMenu
Definition: actions.h:163
int Main(const TOOL_EVENT &aEvent)
Function Main()
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
SELECTION m_selection
Current state of selection (not really used: no selection in display footprints frame).
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59