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 (C) 2023 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_base.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#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
50{
51 m_frame = getEditFrame<CVPCB_MAINFRAME>();
52}
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 {
109 break;
110
113 break;
114
117 break;
118
120 default:
121 break;
122 }
123
124 break;
125
127 switch( m_frame->GetFocusedControl() )
128 {
131 break;
132
135 break;
136
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
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 if( !m_frame->Kiway().KiFACE( KIWAY::FACE_PCB, false ) )
167 {
168 try
169 {
171 }
172 catch( ... )
173 {
174 // _pcbnew.dll/so is not available (install problem).
175 }
176 }
177
179 m_frame );
180
181 // If Kiway() cannot create the eeschema frame, it shows a error message, and
182 // frame is null
183 if( !fpframe )
184 return 0;
185
186 fpframe->Show( true );
187 }
188 else
189 {
190 if( wxWindow* blocking_win = fpframe->Kiway().GetBlockingDialog() )
191 blocking_win->Close( true );
192
193 if( fpframe->IsIconized() )
194 fpframe->Iconize( false );
195
196 // The display footprint window might be buried under some other
197 // windows, so CreateScreenCmp() on an existing window would not
198 // show any difference, leaving the user confused.
199 // So we want to put it to front, second after our CVPCB_MAINFRAME.
200 // We do this by a little dance of bringing it to front then the main
201 // frame back.
202 wxWindow* focus = m_frame->FindFocus();
203
204 fpframe->Raise(); // Make sure that is visible.
205 m_frame->Raise(); // .. but still we want the focus.
206
207 if( focus )
208 focus->SetFocus();
209 }
210
211 fpframe->InitDisplay();
212
213 return 0;
214}
215
216
218{
221 return 0;
222}
223
224
226{
228 dlg.ShowModal();
229
230 return 0;
231}
232
233
235{
237 return 0;
238}
239
240
242{
244 return 0;
245}
246
247
248int CVPCB_CONTROL::ToNA( const TOOL_EVENT& aEvent )
249{
251
252 std::vector<unsigned int> naComp = m_frame->GetComponentIndices( CVPCB_MAINFRAME::NA_COMPONENTS );
253 std::vector<unsigned int> tempSel = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
254
255 // No unassociated components
256 if( naComp.empty() )
257 return 0;
258
259 // Extract the current selection
260 bool changeSel = false;
261 unsigned int newSel = UINT_MAX;
262
263 switch( dir )
264 {
266 if( !tempSel.empty() )
267 newSel = tempSel.front();
268
269 // Find the next index in the component list
270 for( unsigned int idx : naComp )
271 {
272 if( idx > newSel )
273 {
274 changeSel = true;
275 newSel = idx;
276 break;
277 }
278 }
279
280 break;
281
283 if( !tempSel.empty() )
284 {
285 newSel = tempSel.front();
286
287 // Find the previous index in the component list
288 for( int jj = naComp.size()-1; jj >= 0; jj-- )
289 {
290 unsigned idx = naComp[jj];
291
292 if( idx < newSel )
293 {
294 changeSel = true;
295 newSel = idx;
296 break;
297 }
298 }
299 }
300
301 break;
302
303 default:
304 wxASSERT_MSG( false, "Invalid direction" );
305 }
306
307 // Set the new component selection
308 if( changeSel )
309 m_frame->SetSelectedComponent( newSel );
310
311 return 0;
312}
313
314
316{
317 ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
318 CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
319 SELECTION dummySel;
320
321 if( conditionalMenu )
322 conditionalMenu->Evaluate( dummySel );
323
324 if( actionMenu )
325 actionMenu->UpdateAll();
326
327 return 0;
328}
329
330
332{
333 // Control actions
338
339 // Run the footprint viewer
341
342 // Management actions
346
347 // Navigation actions
350
351 // Filter the footprints
355}
static TOOL_ACTION updateMenu
Definition: actions.h:218
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void UpdateAll()
Run update handlers for the menu and its submenus.
static TOOL_ACTION showEquFileTable
Definition: cvpcb_actions.h:58
static TOOL_ACTION gotoPreviousNA
Navigate the component tree.
Definition: cvpcb_actions.h:52
static TOOL_ACTION changeFocusLeft
Definition: cvpcb_actions.h:46
static TOOL_ACTION gotoNextNA
Definition: cvpcb_actions.h:53
static TOOL_ACTION saveAssociationsToFile
Definition: cvpcb_actions.h:57
static TOOL_ACTION FilterFPbyLibrary
Definition: cvpcb_actions.h:69
static TOOL_ACTION filterFPbyPin
Definition: cvpcb_actions.h:68
static TOOL_ACTION changeFocusRight
Window control actions.
Definition: cvpcb_actions.h:45
static TOOL_ACTION controlActivate
Definition: cvpcb_actions.h:42
static TOOL_ACTION FilterFPbyFPFilters
Footprint Filtering actions.
Definition: cvpcb_actions.h:67
static TOOL_ACTION saveAssociationsToSchematic
Management actions.
Definition: cvpcb_actions.h:56
static TOOL_ACTION showFootprintViewer
Open the footprint viewer.
Definition: cvpcb_actions.h:49
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
This method is meant to be overridden in order to specify handlers for 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.
CVPCB_MAINFRAME::CONTROL_TYPE GetFocusedControl() const
Find out which control currently has focus.
@ FILTER_TOGGLE
Toggle the filter state.
DISPLAY_FOOTPRINTS_FRAME * GetFootprintViewerFrame() const
void SetFootprintFilter(FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction)
Set a filter criteria to either on/off or toggle the criteria.
void SetSelectedComponent(int aIndex, bool aSkipUpdate=false)
Set the currently selected component in the components listbox.
@ CONTROL_NONE
No controls have focus.
@ CONTROL_LIBRARY
Library listbox.
@ CONTROL_FOOTPRINT
Footprint listbox.
@ CONTROL_COMPONENT
Component listbox.
void SetFocusedControl(CVPCB_MAINFRAME::CONTROL_TYPE aControl)
Set the focus to a specific control.
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.
@ NA_COMPONENTS
Not associated components.
@ SEL_COMPONENTS
Selected components.
bool SaveFootprintAssociation(bool doSaveSchematic)
Save the edits that the user has done by sending them back to Eeschema via the kiway.
FOCUS_DIR
Directions to rotate the focus through the listboxes is.
int ShowModal() override
void InitDisplay()
Refresh the full display for this frame: Set the title, the status line and redraw the canvas Must be...
FP_FILTER_T
Filter setting constants.
Definition: listboxes.h:93
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:406
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:669
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:202
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:292
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
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_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.
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
This file is part of the common library.
@ FRAME_CVPCB_DISPLAY
Definition: frame_type.h:53