KiCad PCB EDA Suite
cvpcb_control.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) 2019 Ian McInerney <Ian.S.McInerney@ieee.org>
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <confirm.h>
22 #include <cstdint>
23 #include <functional>
24 #include <kiface_i.h>
25 #include <kiway_express.h>
26 #include <lib_id.h>
27 #include <tool/actions.h>
28 #include <tool/tool_manager.h>
29 
30 #include <cvpcb_mainframe.h>
33 #include <listboxes.h>
34 #include <tools/cvpcb_actions.h>
35 #include <tools/cvpcb_control.h>
36 
37 using namespace std::placeholders;
38 
39 
41  TOOL_INTERACTIVE( "cvpcb.Control" ),
42  m_frame( nullptr )
43 {
44 }
45 
46 
48 {
49  m_frame = getEditFrame<CVPCB_MAINFRAME>();
50 }
51 
52 
53 int CVPCB_CONTROL::Main( const TOOL_EVENT& aEvent )
54 {
55  // Main loop: keep receiving events
56  while( TOOL_EVENT* evt = Wait() )
57  {
58  bool handled = false;
59 
60  // The escape key maps to the cancel event, which is used to close the window
61  if( evt->IsCancel() )
62  {
63  m_frame->Close( false );
64  handled = true;
65  }
66  else if( evt->IsKeyPressed() )
67  {
68  switch( evt->KeyCode() )
69  {
70  // The right arrow moves focus to the focusable object to the right
71  case WXK_RIGHT:
73  handled = true;
74  break;
75 
76  // The left arrow moves focus to the focusable object to the left
77  case WXK_LEFT:
79  handled = true;
80  break;
81 
82  default:
83  // Let every other key continue processing to the controls of the window
84  break;
85  }
86  }
87 
88  if( !handled )
89  evt->SetPassEvent();
90  }
91 
92  // This tool is supposed to be active forever
93  wxASSERT( false );
94 
95  return 0;
96 }
97 
98 
100 {
101  int tmp = aEvent.Parameter<intptr_t>();
103  static_cast<CVPCB_MAINFRAME::FOCUS_DIR>( tmp );
104 
105  switch( dir )
106  {
108  switch( m_frame->GetFocusedControl() )
109  {
112  break;
113 
116  break;
117 
120  break;
121 
123  default:
124  break;
125  }
126 
127  break;
128 
130  switch( m_frame->GetFocusedControl() )
131  {
134  break;
135 
138  break;
139 
142  break;
143 
145  default:
146  break;
147  }
148 
149  break;
150 
151  default:
152  break;
153  }
154 
155  return 0;
156 }
157 
158 
160 {
161 
163 
164  if( !fpframe )
165  {
167  FRAME_CVPCB_DISPLAY, true, m_frame );
168  fpframe->Show( true );
169  }
170  else
171  {
172  if( fpframe->IsIconized() )
173  fpframe->Iconize( false );
174 
175  // The display footprint window might be buried under some other
176  // windows, so CreateScreenCmp() on an existing window would not
177  // show any difference, leaving the user confused.
178  // So we want to put it to front, second after our CVPCB_MAINFRAME.
179  // We do this by a little dance of bringing it to front then the main
180  // frame back.
181  wxWindow* focus = m_frame->FindFocus();
182 
183  fpframe->Raise(); // Make sure that is visible.
184  m_frame->Raise(); // .. but still we want the focus.
185 
186  if( focus )
187  focus->SetFocus();
188  }
189 
190  fpframe->InitDisplay();
191 
192  return 0;
193 }
194 
195 
197 {
199  static_cast<FOOTPRINTS_LISTBOX::FP_FILTER_T>( aEvent.Parameter<intptr_t>() ),
201 
202  return 0;
203 }
204 
205 
207 {
209  dlg.ShowModal();
210 
211  return 0;
212 }
213 
214 
216 {
218  return 0;
219 }
220 
221 
222 int CVPCB_CONTROL::ToNA( const TOOL_EVENT& aEvent )
223 {
224  int tmp = aEvent.Parameter<intptr_t>();
226  static_cast<CVPCB_MAINFRAME::ITEM_DIR>( tmp );
227 
228  std::vector<unsigned int> naComp = m_frame->GetComponentIndices( CVPCB_MAINFRAME::NA_COMPONENTS );
229  std::vector<unsigned int> tempSel = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
230 
231  // No unassociated components
232  if( naComp.empty() )
233  return 0;
234 
235  // Extract the current selection
236  unsigned int curSel = -1;
237  unsigned int newSel = -1;
238  switch( dir )
239  {
241  if( !tempSel.empty() )
242  newSel = tempSel.front();
243 
244  // Find the next index in the component list
245  for( unsigned int i : naComp )
246  {
247  if( i > newSel )
248  {
249  newSel = i;
250  break;
251  }
252  }
253 
254  break;
255 
257  if( !tempSel.empty() )
258  {
259  newSel = tempSel.front();
260  curSel = newSel - 1; // Break one before the current selection
261  }
262 
263  break;
264 
265  default:
266  wxASSERT_MSG( false, "Invalid direction" );
267  }
268 
269  // Find the next index in the component list
270  for( unsigned int i : naComp )
271  {
272  if( i >= curSel )
273  {
274  newSel = i;
275  break;
276  }
277  }
278 
279  // Set the component selection
280  m_frame->SetSelectedComponent( newSel );
281 
282  return 0;
283 }
284 
285 
287 {
288  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
289  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
290  SELECTION dummySel;
291 
292  if( conditionalMenu )
293  conditionalMenu->Evaluate( dummySel );
294 
295  if( actionMenu )
296  actionMenu->UpdateAll();
297 
298  return 0;
299 }
300 
301 
303 {
304  // Control actions
309 
310  // Run the footprint viewer
312 
313  // Management actions
316 
317  // Navigation actions
320 
321  // Filter the footprints
326 }
int ShowEquFileTable(const TOOL_EVENT &aEvent)
Show the dialog to modify the included footprint association files (.equ)
static TOOL_ACTION showFootprintViewer
Open the footprint viewer.
Definition: cvpcb_actions.h:52
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
static TOOL_ACTION FilterFPbyFPFilters
Footprint Filtering actions.
Definition: cvpcb_actions.h:69
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
static TOOL_ACTION showEquFileTable
Definition: cvpcb_actions.h:60
static TOOL_ACTION gotoNextNA
Definition: cvpcb_actions.h:56
Class ACTION_MENU.
Definition: action_menu.h:43
This file is part of the common library.
static TOOL_ACTION gotoPreviousNA
Navigate the component tree.
Definition: cvpcb_actions.h:55
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
CVPCB_MAINFRAME * m_frame
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
static TOOL_ACTION changeFocusLeft
Definition: cvpcb_actions.h:49
void SetFocusedControl(CVPCB_MAINFRAME::CONTROL_TYPE aControl)
Set the focus to a specific control.
static TOOL_ACTION changeFocusRight
Window control actions.
Definition: cvpcb_actions.h:48
int SaveAssociations(const TOOL_EVENT &aEvent)
Save the associations to the schematic.
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()
Class DISPLAY_FOOTPRINTS_FRAME is used to display footprints.
int ToNA(const TOOL_EVENT &aEvent)
Move the selected component to the not associated one in the specified direction.
static TOOL_ACTION FilterFPbyLibrary
Definition: cvpcb_actions.h:71
int ChangeFocus(const TOOL_EVENT &aEvent)
Rotate focus in the CVPCB window.
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:328
void SetSelectedComponent(int aIndex, bool aSkipUpdate=false)
Set the currently selected component in the components listbox.
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
Class TOOL_EVENT.
Definition: tool_event.h:171
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
No controls have focus.
int ToggleFootprintFilter(const TOOL_EVENT &aEvent)
Filter the footprint list by toggling the given filter type.
static TOOL_ACTION updateMenu
Definition: actions.h:158
static TOOL_ACTION saveAssociations
Management actions.
Definition: cvpcb_actions.h:59
FOCUS_DIR
Directions to rotate the focus through the listboxes is.
static TOOL_ACTION FilterFPbyTextPattern
Definition: cvpcb_actions.h:72
void InitDisplay()
Function InitDisplay Refresh the full display for this frame: Set the title, the status line and redr...
DISPLAY_FOOTPRINTS_FRAME * GetFootprintViewerFrame()
static TOOL_ACTION filterFPbyPin
Definition: cvpcb_actions.h:70
static TOOL_ACTION controlActivate
Definition: cvpcb_actions.h:45
size_t i
Definition: json11.cpp:649
ITEM_DIR
Directions to move when selecting items.
Toggle the filter state.
int ShowFootprintViewer(const TOOL_EVENT &aEvent)
Create or Update the frame showing the current highlighted footprint and (if showed) the 3D display f...
int Main(const TOOL_EVENT &aEvent)
Main processing loop for the CVPCB window.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
CVPCB_MAINFRAME::CONTROL_TYPE GetFocusedControl()
Find out which control currently has focus.
void SetFootprintFilter(FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction)
Function SetFootprintFilter Set a filter criteria to either on/off or toggle the criteria.
std::vector< unsigned int > GetComponentIndices(CVPCB_MAINFRAME::CRITERIA aCriteria=CVPCB_MAINFRAME::ALL_COMPONENTS)
Get the indices for all the components meeting the specified criteria in the components listbox.
Not associated components.
int UpdateMenu(const TOOL_EVENT &aEvent)
Update the menu to reflect the current tool states.
bool SaveFootprintAssociation(bool doSaveSchematic)
Function SaveFootprintAssociation saves the edits that the user has done by sending them back to eesc...