KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright The 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <confirm.h>
22#include <cstdint>
23#include <functional>
24#include <kiface_base.h>
25#include <kiway_mail.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#include <wx/settings.h>
37#include <wx/msgdlg.h>
38
39using namespace std::placeholders;
40
41
43 TOOL_INTERACTIVE( "cvpcb.Control" ),
44 m_frame( nullptr )
45{
46}
47
48
53
54
55int CVPCB_CONTROL::Main( const TOOL_EVENT& aEvent )
56{
57 // Main loop: keep receiving events
58 while( TOOL_EVENT* evt = Wait() )
59 {
60 bool handled = false;
61
62 // The escape key maps to the cancel event, which is used to close the window
63 if( evt->IsCancel() )
64 {
65 m_frame->Close( false );
66 handled = true;
67 }
68 else if( evt->IsKeyPressed() )
69 {
70 switch( evt->KeyCode() )
71 {
72 // The right arrow moves focus to the focusable object to the right
73 case WXK_RIGHT:
75 handled = true;
76 break;
77
78 // The left arrow moves focus to the focusable object to the left
79 case WXK_LEFT:
81 handled = true;
82 break;
83
84 default:
85 // Let every other key continue processing to the controls of the window
86 break;
87 }
88 }
89
90 if( !handled )
91 evt->SetPassEvent();
92 }
93
94 return 0;
95}
96
97
99{
101
102 switch( dir )
103 {
105 switch( m_frame->GetFocusedControl() )
106 {
108 m_frame->SetFocusedControl( CVPCB_MAINFRAME::CONTROL_COMPONENT );
109 break;
110
112 m_frame->SetFocusedControl( CVPCB_MAINFRAME::CONTROL_FOOTPRINT );
113 break;
114
116 m_frame->SetFocusedControl( CVPCB_MAINFRAME::CONTROL_LIBRARY );
117 break;
118
120 default:
121 break;
122 }
123
124 break;
125
127 switch( m_frame->GetFocusedControl() )
128 {
130 m_frame->SetFocusedControl( CVPCB_MAINFRAME::CONTROL_FOOTPRINT );
131 break;
132
134 m_frame->SetFocusedControl( CVPCB_MAINFRAME::CONTROL_LIBRARY );
135 break;
136
138 m_frame->SetFocusedControl( CVPCB_MAINFRAME::CONTROL_COMPONENT );
139 break;
140
142 default:
143 break;
144 }
145
146 break;
147
148 default:
149 break;
150 }
151
152 return 0;
153}
154
155
157{
158
159 DISPLAY_FOOTPRINTS_FRAME* fpframe = m_frame->GetFootprintViewerFrame();
160
161 if( !fpframe )
162 {
163 // DISPLAY_FOOTPRINTS_FRAME needs a PCBNEW_SETTINGS because most of its settings
164 // come from it, and needs _pcbnew.dll/so code. So load it if the dll is not yet loaded
165 // (for instance if the board editor was never loaded)
166 m_frame->Kiway().KiFACE( KIWAY::FACE_PCB );
167
168 fpframe = (DISPLAY_FOOTPRINTS_FRAME*) m_frame->Kiway().Player( FRAME_CVPCB_DISPLAY, true,
169 m_frame );
170
171 // If Kiway() cannot create the Eeschema frame, it shows a error message, and
172 // frame is null
173 if( !fpframe )
174 return 0;
175
176 fpframe->Show( true );
177 }
178 else
179 {
180 if( wxWindow* blocking_win = fpframe->Kiway().GetBlockingDialog() )
181 blocking_win->Close( true );
182
183 if( fpframe->IsIconized() )
184 fpframe->Iconize( false );
185
186 // The display footprint window might be buried under some other
187 // windows, so CreateScreenCmp() on an existing window would not
188 // show any difference, leaving the user confused.
189 // So we want to put it to front, second after our CVPCB_MAINFRAME.
190 // We do this by a little dance of bringing it to front then the main
191 // frame back.
192 wxWindow* focus = m_frame->FindFocus();
193
194 fpframe->Raise(); // Make sure that is visible.
195 m_frame->Raise(); // .. but still we want the focus.
196
197 if( focus )
198 focus->SetFocus();
199 }
200
201 fpframe->InitDisplay();
202
203 return 0;
204}
205
206
208{
209 m_frame->SetFootprintFilter( aEvent.Parameter<FOOTPRINTS_LISTBOX::FP_FILTER_T>(),
211 return 0;
212}
213
214
216{
218 dlg.ShowModal();
219
220 return 0;
221}
222
223
225{
226 m_frame->SaveFootprintAssociation( true );
227 return 0;
228}
229
230
232{
233 m_frame->SaveFootprintAssociation( false );
234 return 0;
235}
236
237
238int CVPCB_CONTROL::ToNA( const TOOL_EVENT& aEvent )
239{
241
242 std::vector<unsigned int> naComp =
243 m_frame->GetComponentIndices( CVPCB_MAINFRAME::NA_COMPONENTS );
244 std::vector<unsigned int> tempSel =
245 m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
246
247 // No unassociated components
248 if( naComp.empty() )
249 return 0;
250
251 // Extract the current selection
252 bool changeSel = false;
253 unsigned int newSel = UINT_MAX;
254
255 switch( dir )
256 {
258 if( !tempSel.empty() )
259 newSel = tempSel.front();
260
261 // Find the next index in the component list
262 for( unsigned int idx : naComp )
263 {
264 if( idx > newSel )
265 {
266 changeSel = true;
267 newSel = idx;
268 break;
269 }
270 }
271
272 break;
273
275 if( !tempSel.empty() )
276 {
277 newSel = tempSel.front();
278
279 // Find the previous index in the component list
280 for( int jj = naComp.size()-1; jj >= 0; jj-- )
281 {
282 unsigned idx = naComp[jj];
283
284 if( idx < newSel )
285 {
286 changeSel = true;
287 newSel = idx;
288 break;
289 }
290 }
291 }
292
293 break;
294
295 default:
296 wxASSERT_MSG( false, "Invalid direction" );
297 }
298
299 // Set the new component selection
300 if( changeSel )
301 m_frame->SetSelectedComponent( newSel );
302
303 return 0;
304}
305
306
308{
309 ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
310 CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
311 SELECTION dummySel;
312
313 if( conditionalMenu )
314 conditionalMenu->Evaluate( dummySel );
315
316 if( actionMenu )
317 actionMenu->UpdateAll();
318
319 return 0;
320}
321
322
static TOOL_ACTION updateMenu
Definition actions.h:268
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
void UpdateAll()
Run update handlers for the menu and its submenus.
static TOOL_ACTION showEquFileTable
static TOOL_ACTION gotoPreviousNA
Navigate the component tree.
static TOOL_ACTION changeFocusLeft
static TOOL_ACTION gotoNextNA
static TOOL_ACTION saveAssociationsToFile
static TOOL_ACTION FilterFPbyLibrary
static TOOL_ACTION filterFPbyPin
static TOOL_ACTION changeFocusRight
Window control actions.
static TOOL_ACTION controlActivate
Activation actions.
static TOOL_ACTION FilterFPbyFPFilters
Footprint Filtering actions.
static TOOL_ACTION saveAssociationsToSchematic
Management actions.
static TOOL_ACTION showFootprintViewer
Open the footprint viewer.
CVPCB_MAINFRAME * m_frame
int SaveAssociationsToFile(const TOOL_EVENT &aEvent)
Save the associations to the schematic and save schematic to file.
int Main(const TOOL_EVENT &aEvent)
Main processing loop for the CvPcb window.
void setTransitions() override
Set up handlers for various events.
int SaveAssociationsToSchematic(const TOOL_EVENT &aEvent)
Save the associations to the schematic.
int UpdateMenu(const TOOL_EVENT &aEvent)
Update the menu to reflect the current tool states.
int ShowFootprintViewer(const TOOL_EVENT &aEvent)
Create or Update the frame showing the current highlighted footprint and (if showed) the 3D display f...
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int ChangeFocus(const TOOL_EVENT &aEvent)
Rotate focus in the CVPCB window.
int ShowEquFileTable(const TOOL_EVENT &aEvent)
Show the dialog to modify the included footprint association files (.equ).
int ToNA(const TOOL_EVENT &aEvent)
Move the selected component to the not associated one in the specified direction.
int ToggleFootprintFilter(const TOOL_EVENT &aEvent)
Filter the footprint list by toggling the given filter type.
ITEM_DIR
Directions to move when selecting items.
@ ITEM_NEXT
The next item.
@ ITEM_PREV
The previous item.
@ FILTER_TOGGLE
Toggle the filter state.
@ CONTROL_NONE
No controls have focus.
@ CONTROL_LIBRARY
Library listbox.
@ CONTROL_FOOTPRINT
Footprint listbox.
@ CONTROL_COMPONENT
Component listbox.
@ NA_COMPONENTS
Not associated components.
@ SEL_COMPONENTS
Selected components.
FOCUS_DIR
Directions to rotate the focus through the listboxes is.
int ShowModal() override
void InitDisplay()
Refresh the full display for this frame.
FP_FILTER_T
Filter setting constants.
Definition listboxes.h:95
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition kiway.cpp:705
@ FACE_PCB
pcbnew DSO
Definition kiway.h:356
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:484
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_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
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.
This file is part of the common library.
@ FRAME_CVPCB_DISPLAY
Definition frame_type.h:49