KiCad PCB EDA Suite
footprint_wizard_frame.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) 2012-2015 Miguel Angel Ajo Pelayo <miguelangel@nbee.es>
5  * Copyright (C) 2012-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
31 #include <fctsys.h>
32 #include <kiface_i.h>
34 #include <class_drawpanel.h>
35 #include <pcb_draw_panel_gal.h>
36 #include <pcb_edit_frame.h>
37 #include <pcbnew.h>
39 #include <msgpanel.h>
40 #include <macros.h>
41 #include <bitmaps.h>
42 #include <grid_tricks.h>
43 #include <eda_dockart.h>
44 
45 #include <class_board.h>
46 #include <class_module.h>
47 #include <footprint_edit_frame.h>
48 
49 #include <pcbnew_id.h>
50 #include "footprint_wizard_frame.h"
51 #include <footprint_info.h>
52 #include <wx/grid.h>
53 #include <wx/tokenzr.h>
54 #include <wx/numformatter.h>
55 #include <wx/statline.h>
56 
57 #include <hotkeys.h>
59 #include <base_units.h>
60 
61 #include <tool/tool_manager.h>
62 #include <tool/tool_dispatcher.h>
63 #include <tool/common_tools.h>
64 #include "tools/selection_tool.h"
65 #include "tools/pcbnew_control.h"
66 #include "tools/pcb_actions.h"
67 
68 
69 BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
70 
71  // Window events
72  EVT_CLOSE( FOOTPRINT_WIZARD_FRAME::OnCloseWindow )
73  EVT_SIZE( FOOTPRINT_WIZARD_FRAME::OnSize )
74  EVT_ACTIVATE( FOOTPRINT_WIZARD_FRAME::OnActivate )
75 
76  // Toolbar events
78  FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard )
79 
81  FOOTPRINT_WIZARD_FRAME::DefaultParameters )
82 
84  FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
85 
87  FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
88 
90  FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint )
91 
93  FOOTPRINT_WIZARD_FRAME::Show3D_Frame )
94 
95  // listbox events
96 
97  EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
99  FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
100 
102 END_EVENT_TABLE()
103 
104 
105 /* Note: our FOOTPRINT_WIZARD_FRAME is always modal.
106  * Note:
107  * On windows, when the frame with type wxFRAME_FLOAT_ON_PARENT is displayed
108  * its parent frame is sometimes brought to the foreground when closing the
109  * LIB_VIEW_FRAME frame.
110  * If it still happens, it could be better to use wxSTAY_ON_TOP
111  * instead of wxFRAME_FLOAT_ON_PARENT
112  */
113 #ifdef __WINDOWS__
114 #define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT // could be wxSTAY_ON_TOP if issues
115 #else
116 #define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT
117 #endif
118 
120  wxWindow* aParent, FRAME_T aFrameType ) :
121  PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Wizard" ),
122  wxDefaultPosition, wxDefaultSize,
124  : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
125  FOOTPRINT_WIZARD_FRAME_NAME ), m_wizardListShown( false )
126 {
127  wxASSERT( aFrameType == FRAME_PCB_FOOTPRINT_WIZARD );
128 
129  // This frame is always show modal:
130  SetModal( true );
131 
132  m_showAxis = true; // true to draw axis.
133 
134  // Give an icon
135  wxIcon icon;
136  icon.CopyFromBitmap( KiBitmap( module_wizard_xpm) );
137  SetIcon( icon );
138 
139  m_hotkeysDescrList = g_Module_Viewer_Hotkeys_Descr;
140  m_wizardName.Empty();
141 
142  SetBoard( new BOARD() );
143 
144  // Ensure all layers and items are visible:
146  SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
147  GetScreen()->m_Center = true; // Center coordinate origins on screen.
148 
149  LoadSettings( config() );
150 
151  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
152 
153  // Set some display options here, because the FOOTPRINT_WIZARD_FRAME
154  // does not have a config menu to do that:
155 
156  // the footprint wizard frame has no config menu. so use some settings
157  // from the caller, or force some options:
158  PCB_BASE_FRAME* caller = dynamic_cast<PCB_BASE_FRAME*>( aParent );
159 
160  if( caller )
161  {
162  SetUserUnits( caller->GetUserUnits() );
163  }
164 
165  auto disp_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
166  // In viewer, the default net clearance is not known (it depends on the actual board).
167  // So we do not show the default clearance, by setting it to 0
168  // The footprint or pad specific clearance will be shown
169  GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0);
170 
171  disp_opts->m_DisplayPadIsol = true;
172  disp_opts->m_DisplayPadNum = true;
174 
175  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
176 
177  ReCreateHToolbar();
178  ReCreateVToolbar();
179 
180  // Create GAL canvas
181 #ifdef __WXMAC__
182  // Cairo renderer doesn't handle Retina displays
184 #else
186 #endif
187  PCB_DRAW_PANEL_GAL* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
188  GetGalDisplayOptions(), backend );
189  SetGalCanvas( gal_drawPanel );
190 
191  // Create the parameters panel
192  m_parametersPanel = new wxPanel( this, wxID_ANY );
193 
194  m_pageList = new wxListBox( m_parametersPanel, ID_FOOTPRINT_WIZARD_PAGE_LIST,
195  wxDefaultPosition, wxDefaultSize, 0, NULL,
196  wxLB_HSCROLL | wxNO_BORDER );
197 
198  auto divider = new wxStaticLine( m_parametersPanel, wxID_ANY,
199  wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
200 
201  m_parameterGrid = new wxGrid( m_parametersPanel, ID_FOOTPRINT_WIZARD_PARAMETER_LIST );
202  initParameterGrid();
203  m_parameterGrid->PushEventHandler( new GRID_TRICKS( m_parameterGrid ) );
204 
205  ReCreatePageList();
206 
207  wxBoxSizer* parametersSizer = new wxBoxSizer( wxHORIZONTAL );
208  parametersSizer->Add( m_pageList, 0, wxEXPAND, 5 );
209  parametersSizer->Add( divider, 0, wxEXPAND, 5 );
210  parametersSizer->Add( m_parameterGrid, 1, wxEXPAND, 5 );
211  m_parametersPanel->SetSizer( parametersSizer );
212  m_parametersPanel->Layout();
213 
214  // Create the build message box
215  m_buildMessageBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString,
216  wxDefaultPosition, wxDefaultSize,
217  wxTE_MULTILINE | wxTE_READONLY | wxNO_BORDER );
218 
219  DisplayWizardInfos();
220 
221  m_auimgr.SetManagedWindow( this );
222  m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );
223 
224  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
225  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
226 
227  m_auimgr.AddPane( m_parametersPanel, EDA_PANE().Palette().Name( "Params" ).Left().Position(0)
228  .Caption( _( "Parameters" ) ).MinSize( 360, 180 ) );
229  m_auimgr.AddPane( m_buildMessageBox, EDA_PANE().Palette().Name( "Output" ).Left().Position(1)
230  .CaptionVisible( false ).MinSize( 360, -1 ) );
231 
232  m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
233 
234  m_auimgr.AddPane( (wxWindow*) GetGalCanvas(),
235  wxAuiPaneInfo().Name( "DrawFrameGal" ).CentrePane().Hide() );
236 
237  // Create the manager and dispatcher & route draw panel events to the dispatcher
238  m_toolManager = new TOOL_MANAGER;
239  m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(),
240  gal_drawPanel->GetViewControls(), this );
241  m_actions = new PCB_ACTIONS();
242  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
243  gal_drawPanel->SetEventDispatcher( m_toolDispatcher );
244 
245  m_toolManager->RegisterTool( new PCBNEW_CONTROL );
246  m_toolManager->RegisterTool( new SELECTION_TOOL ); // for std context menus (zoom & grid)
247  m_toolManager->RegisterTool( new COMMON_TOOLS );
248  m_toolManager->InitTools();
249 
250  // Run the control tool, it is supposed to be always active
251  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
252 
253  auto& galOpts = GetGalDisplayOptions();
254  galOpts.m_fullscreenCursor = true;
255  galOpts.m_forceDisplayCursor = true;
256  galOpts.m_axesEnabled = true;
257 
258  UseGalCanvas( backend != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
259  updateView();
260 
261  SetActiveLayer( F_Cu );
262  // Now Drawpanel is sized, we can use BestZoom to show the component (if any)
263 #ifdef USE_WX_GRAPHICS_CONTEXT
264  GetScreen()->SetScalingFactor( BestZoom() );
265 #else
266  Zoom_Automatique( false );
267 #endif
268 
269  // Do not Run a dialog here: on some Window Managers, it creates issues.
270  // Reason: the FOOTPRINT_WIZARD_FRAME is run as modal;
271  // It means the call to FOOTPRINT_WIZARD_FRAME::ShowModal will change the
272  // Event Loop Manager, and stop the one created by the dialog.
273  // It does not happen on all W.M., perhaps due to the way the order events are called
274  // See the call in onActivate instead
275 }
276 
277 
279 {
280  // Delete the GRID_TRICKS.
281  m_parameterGrid->PopEventHandler( true );
282 
283  if( IsGalCanvasActive() )
284  {
286  // Be sure any event cannot be fired after frame deletion:
287  GetGalCanvas()->SetEvtHandlerEnabled( false );
288  }
289 
290  // Be sure a active tool (if exists) is desactivated:
291  if( m_toolManager )
293 
294  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
295 
296  if( draw3DFrame )
297  draw3DFrame->Destroy();
298 
299  // Now this frame can be deleted
300 }
301 
302 
303 void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event )
304 {
305  SaveSettings( config() );
306 
307  if( IsModal() )
308  {
309  // Only dismiss a modal frame once, so that the return values set by
310  // the prior DismissModal() are not bashed for ShowModal().
311  if( !IsDismissed() )
312  DismissModal( false );
313  }
314  else
315  {
316  Destroy();
317  }
318 }
319 
320 
322 {
323  DismissModal( true );
324  Close();
325 }
326 
327 
328 void FOOTPRINT_WIZARD_FRAME::OnGridSize( wxSizeEvent& aSizeEvent )
329 {
330  // Resize the parameter columns
332 
333  aSizeEvent.Skip();
334 }
335 
336 
337 void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
338 {
339  if( m_auimgr.GetManagedWindow() )
340  m_auimgr.Update();
341 
342  SizeEv.Skip();
343 }
344 
345 
346 void FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
347 {
349  UpdateStatusBar();
350 }
351 
352 
354 {
355  if( IsGalCanvasActive() )
356  {
357  auto dp = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
358  dp->UseColorScheme( &Settings().Colors() );
359  dp->DisplayBoard( GetBoard() );
362  UpdateMsgPanel();
363  }
364 }
365 
366 
368 {
369  BOARD_ITEM* footprint = GetBoard()->m_Modules;
370 
371  if( footprint )
372  {
373  MSG_PANEL_ITEMS items;
374 
375  footprint->GetMsgPanelInfo( m_UserUnits, items );
376  SetMsgPanel( items );
377  }
378  else
379  ClearMsgPanel();
380 }
381 
382 
384 {
385  m_parameterGridPage = -1;
386 
387  // Prepare the grid where parameters are displayed
388 
389  m_parameterGrid->CreateGrid( 0, 3 );
390 
391  m_parameterGrid->SetColLabelValue( WIZ_COL_NAME, _( "Parameter" ) );
392  m_parameterGrid->SetColLabelValue( WIZ_COL_VALUE, _( "Value" ) );
393  m_parameterGrid->SetColLabelValue( WIZ_COL_UNITS, _( "Units" ) );
394 
395  m_parameterGrid->SetColLabelSize( 22 );
396  m_parameterGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
397  m_parameterGrid->AutoSizeColumns();
398 
399  m_parameterGrid->AutoSizeRows();
400  m_parameterGrid->SetRowLabelSize( 0 );
401 
402  m_parameterGrid->DisableDragGridSize();
403  m_parameterGrid->DisableDragColSize();
404 
405  m_parameterGrid->Connect( wxEVT_SIZE,
406  wxSizeEventHandler( FOOTPRINT_WIZARD_FRAME::OnGridSize ),
407  NULL, this );
408 }
409 
410 
412 {
413  if( m_pageList == NULL )
414  return;
415 
416  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
417 
418  if( !footprintWizard )
419  return;
420 
421  m_pageList->Clear();
422  int max_page = footprintWizard->GetNumParameterPages();
423 
424  for( int i = 0; i<max_page; i++ )
425  {
426  wxString name = footprintWizard->GetParameterPageName( i );
427  m_pageList->Append( name );
428  }
429 
430  m_pageList->SetSelection( 0, true );
431 
435  m_canvas->Refresh();
436 }
437 
438 
440 {
441  if( m_parameterGrid == NULL )
442  return;
443 
444  FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
445 
446  if( footprintWizard == NULL )
447  return;
448 
449  m_parameterGrid->ClearGrid();
450  m_parameterGridPage = m_pageList->GetSelection();
451 
452  if( m_parameterGridPage < 0 ) // Should not happen
453  return;
454 
455  // Get the list of names, values, types, hints and designators
456  wxArrayString designatorsList = footprintWizard->GetParameterDesignators( m_parameterGridPage );
457  wxArrayString namesList = footprintWizard->GetParameterNames( m_parameterGridPage );
458  wxArrayString valuesList = footprintWizard->GetParameterValues( m_parameterGridPage );
459  wxArrayString typesList = footprintWizard->GetParameterTypes( m_parameterGridPage );
460  wxArrayString hintsList = footprintWizard->GetParameterHints( m_parameterGridPage );
461 
462  // Dimension the wxGrid
463  if( m_parameterGrid->GetNumberRows() > 0 )
464  m_parameterGrid->DeleteRows( 0, m_parameterGrid->GetNumberRows() );
465 
466  m_parameterGrid->AppendRows( namesList.size() );
467 
468  wxString designator, name, value, units, hint;
469 
470  for( unsigned int i = 0; i< namesList.size(); i++ )
471  {
472  designator = designatorsList[i];
473  name = namesList[i];
474  value = valuesList[i];
475  units = typesList[i];
476  hint = hintsList[i];
477 
478  m_parameterGrid->SetRowLabelValue( i, designator );
479 
480  // Set the 'Name'
481  m_parameterGrid->SetCellValue( i, WIZ_COL_NAME, name );
482  m_parameterGrid->SetReadOnly( i, WIZ_COL_NAME );
483 
484  // Boolean parameters are displayed using a checkbox
485  if( units == WIZARD_PARAM_UNITS_BOOL )
486  {
487  // Set to ReadOnly as we delegate interactivity to GRID_TRICKS
488  m_parameterGrid->SetReadOnly( i, WIZ_COL_VALUE );
489  m_parameterGrid->SetCellRenderer( i, WIZ_COL_VALUE, new wxGridCellBoolRenderer );
490  }
491  // Parameters that can be selected from a list of multiple options
492  else if( units.Contains( "," ) ) // Indicates list of available options
493  {
494  wxStringTokenizer tokenizer( units, "," );
495  wxArrayString options;
496 
497  while( tokenizer.HasMoreTokens() )
498  {
499  options.Add( tokenizer.GetNextToken() );
500  }
501 
502  m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellChoiceEditor( options ) );
503 
504  units = wxT( "" );
505  }
506  // Integer parameters
507  else if( units == WIZARD_PARAM_UNITS_INTEGER )
508  {
509  m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellNumberEditor );
510  }
511  // Non-integer numerical parameters
512  else if( ( units == WIZARD_PARAM_UNITS_MM ) ||
513  ( units == WIZARD_PARAM_UNITS_MILS ) ||
514  ( units == WIZARD_PARAM_UNITS_FLOAT ) ||
515  ( units == WIZARD_PARAM_UNITS_RADIANS ) ||
516  ( units == WIZARD_PARAM_UNITS_DEGREES ) ||
517  ( units == WIZARD_PARAM_UNITS_PERCENT ) )
518  {
519  m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellFloatEditor );
520 
521  // Convert separators to the locale-specific character
522  value.Replace( ",", wxNumberFormatter::GetDecimalSeparator() );
523  value.Replace( ".", wxNumberFormatter::GetDecimalSeparator() );
524  }
525 
526  // Set the 'Units'
527  m_parameterGrid->SetCellValue( i, WIZ_COL_UNITS, units );
528  m_parameterGrid->SetReadOnly( i, WIZ_COL_UNITS );
529 
530  // Set the 'Value'
531  m_parameterGrid->SetCellValue( i, WIZ_COL_VALUE, value );
532  }
533 
535 }
536 
538 {
539 
540  // Parameter grid is not yet configured
541  if( ( m_parameterGrid == NULL ) || ( m_parameterGrid->GetNumberCols() == 0 ) )
542  return;
543 
544  // first auto-size the columns to ensure enough space around text
545  m_parameterGrid->AutoSizeColumns();
546 
547  // Auto-size the value column
548  int width = m_parameterGrid->GetClientSize().GetWidth() -
549  m_parameterGrid->GetRowLabelSize() -
550  m_parameterGrid->GetColSize( WIZ_COL_NAME ) -
551  m_parameterGrid->GetColSize( WIZ_COL_UNITS );
552 
553  if( width > m_parameterGrid->GetColMinimalAcceptableWidth() )
554  {
555  m_parameterGrid->SetColSize( WIZ_COL_VALUE, width );
556  }
557 }
558 
559 
560 void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event )
561 {
562  int ii = m_pageList->GetSelection();
563 
564  if( ii < 0 )
565  return;
566 
568  m_canvas->Refresh();
570 }
571 
572 
573 #define AUI_PERSPECTIVE_KEY wxT( "Fpwizard_auiPerspective" )
574 
575 
576 void FOOTPRINT_WIZARD_FRAME::LoadSettings( wxConfigBase* aCfg )
577 {
579 
580  aCfg->Read( AUI_PERSPECTIVE_KEY, &m_auiPerspective );
581 }
582 
583 
584 void FOOTPRINT_WIZARD_FRAME::SaveSettings( wxConfigBase* aCfg )
585 {
587 
588  aCfg->Write( AUI_PERSPECTIVE_KEY, m_auimgr.SavePerspective() );
589 }
590 
591 
592 void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
593 {
595 
596  // Ensure we do not have old selection:
597  if( !event.GetActive() )
598  return;
599 
600  if( !m_wizardListShown )
601  {
602  m_wizardListShown = true;
604  }
605 #if 0
606  // Currently, we do not have a way to see if a Python wizard has changed,
607  // therefore the lists of parameters and option has to be rebuilt
608  // This code could be enabled when this way exists
609  bool footprintWizardsChanged = false;
610 
611  if( footprintWizardsChanged )
612  {
613  // If we are here, the library list has changed, rebuild it
616  }
617 #endif
618 }
619 
620 
621 bool FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
622 {
623  // Filter out the 'fake' mouse motion after a keyboard movement
624  if( !aHotKey && m_movingCursorWithKeyboard )
625  {
627  return false;
628  }
629 
630  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
631  cmd.SetEventObject( this );
632 
633  wxPoint pos = aPosition;
634  wxPoint oldpos = GetCrossHairPosition();
635  bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, true );
636 
637  switch( aHotKey )
638  {
639  case WXK_F1:
640  cmd.SetId( ID_KEY_ZOOM_IN );
641  GetEventHandler()->ProcessEvent( cmd );
642  keyHandled = true;
643  break;
644 
645  case WXK_F2:
646  cmd.SetId( ID_KEY_ZOOM_OUT );
647  GetEventHandler()->ProcessEvent( cmd );
648  keyHandled = true;
649  break;
650 
651  case WXK_F3:
652  cmd.SetId( ID_ZOOM_REDRAW );
653  GetEventHandler()->ProcessEvent( cmd );
654  keyHandled = true;
655  break;
656 
657  case WXK_F4:
658  cmd.SetId( ID_POPUP_ZOOM_CENTER );
659  GetEventHandler()->ProcessEvent( cmd );
660  keyHandled = true;
661  break;
662 
663  case WXK_HOME:
664  cmd.SetId( ID_ZOOM_PAGE );
665  GetEventHandler()->ProcessEvent( cmd );
666  keyHandled = true;
667  break;
668 
669  case ' ':
671  keyHandled = true;
672  break;
673 
674  default:
675  break;
676  }
677 
678  SetCrossHairPosition( pos );
679  RefreshCrossHair( oldpos, aPosition, aDC );
680 
681  UpdateStatusBar(); // Display new cursor coordinates
682 
683  return keyHandled;
684 }
685 
686 
687 void FOOTPRINT_WIZARD_FRAME::Show3D_Frame( wxCommandEvent& event )
688 {
689  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
690 
691  // We can probably remove this for 6.0, but just to be safe we'll stick to
692  // one 3DFrame at a time for 5.0
693  if( draw3DFrame )
694  draw3DFrame->Close( true );
695 
696  draw3DFrame = new EDA_3D_VIEWER( &Kiway(), this, _( "3D Viewer" ) );
697  Update3D_Frame( false );
698 
699 #ifdef __WXMAC__
700  // A stronger version of Raise() which promotes the window to its parent's level.
701  draw3DFrame->ReparentQuasiModal();
702 #else
703  draw3DFrame->Raise(); // Needed with some Window Managers
704 #endif
705 
706  draw3DFrame->Show( true );
707 }
708 
709 
715 void FOOTPRINT_WIZARD_FRAME::Update3D_Frame( bool aForceReloadFootprint )
716 {
717  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
718 
719  if( draw3DFrame == NULL )
720  return;
721 
722  wxString frm3Dtitle;
723  frm3Dtitle.Printf( _( "ModView: 3D Viewer [%s]" ), GetChars( m_wizardName ) );
724  draw3DFrame->SetTitle( frm3Dtitle );
725 
726  if( aForceReloadFootprint )
727  {
728  // Force 3D screen refresh immediately
729  draw3DFrame->NewDisplay( true );
730  }
731 }
732 
733 
735 {
736  wxString msg;
737 
738  if( !m_mainToolBar )
739  {
740  m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
741  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
742 
743  // Set up toolbar
744  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, wxEmptyString,
745  KiBitmap( module_wizard_xpm ),
746  _( "Select wizard script to run" ) );
747 
748  m_mainToolBar->AddSeparator();
749 
750  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, wxEmptyString,
751  KiBitmap( reload_xpm ),
752  _( "Reset wizard parameters to default") );
753 
754  m_mainToolBar->AddSeparator();
755 
756  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_PREVIOUS, wxEmptyString,
757  KiBitmap( lib_previous_xpm ),
758  _( "Select previous parameters page" ) );
759 
760  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_NEXT, wxEmptyString,
761  KiBitmap( lib_next_xpm ),
762  _( "Select next parameters page" ) );
763 
764  m_mainToolBar->AddSeparator();
765  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW, wxEmptyString,
766  KiBitmap( three_d_xpm ),
767  _( "Show footprint in 3D viewer" ) );
768 
769  m_mainToolBar->AddSeparator();
770  msg = AddHotkeyName( _( "Zoom in" ), g_Module_Editor_Hotkeys_Descr,
772  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString,
773  KiBitmap( zoom_in_xpm ), msg );
774 
775  msg = AddHotkeyName( _( "Zoom out" ), g_Module_Editor_Hotkeys_Descr,
777  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString,
778  KiBitmap( zoom_out_xpm ), msg );
779 
780  msg = AddHotkeyName( _( "Redraw view" ), g_Module_Editor_Hotkeys_Descr,
782  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
783  KiBitmap( zoom_redraw_xpm ), msg );
784 
785  msg = AddHotkeyName( _( "Zoom auto" ), g_Module_Editor_Hotkeys_Descr,
787  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
788  KiBitmap( zoom_fit_in_page_xpm ), msg );
789 
790  // The footprint wizard always can export the current footprint
791  m_mainToolBar->AddSeparator();
792  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_DONE,
793  wxEmptyString, KiBitmap( export_footprint_names_xpm ),
794  _( "Export footprint to editor" ) );
795 
796  // after adding the buttons to the toolbar, must call Realize() to
797  // reflect the changes
798  m_mainToolBar->Realize();
799  }
800 
801  m_mainToolBar->Refresh();
802 }
803 
804 
806 {
807  // Currently, there is no vertical toolbar
808 }
809 
810 #if defined(KICAD_SCRIPTING)
812 {
813  // Reload the Python plugins
814  // Because the board editor has also a plugin python menu,
815  // call PCB_EDIT_FRAME::PythonPluginsReload() if the board editor
816  // is running
817  PCB_EDIT_FRAME* brd_frame =
818  static_cast<PCB_EDIT_FRAME*>( Kiway().Player( FRAME_PCB, false ) );
819 
820  if( brd_frame )
821  brd_frame->PythonPluginsReload();
822  else
824 }
825 #endif
826 
827 
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:125
#define AUI_PERSPECTIVE_KEY
Class FOOTPRINT_WIZARD_FRAME.
struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hotkeys_Descr[]
show a marker on pads with no nets
wxString m_wizardName
name of the current wizard
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
NETCLASSPTR GetDefault() const
Function GetDefault.
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
void DisplayWizardInfos()
Function DisplayWizardInfos Shows all the details about the current wizard.
const wxString WIZARD_PARAM_UNITS_MM
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
Model changes (required full reload)
Definition: tool_base.h:83
Implementation of conversion functions that require both schematic and board internal units...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
wxString m_auiPerspective
Encoded string describing the AUI layout.
bool IsDismissed()
Function IsDismissed returns false only if both the frame is acting in modal mode and it has not been...
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
wxListBox * m_pageList
The list of pages.
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
Class SELECTION_TOOL.
struct EDA_HOTKEY_CONFIG g_Module_Editor_Hotkeys_Descr[]
Class BOARD to handle a board.
void ExportSelectedFootprint(wxCommandEvent &aEvent)
Function ExportSelectedFootprint(); will let the caller exit from the wait loop, and get the built fo...
virtual wxString GetParameterPageName(int aPage)=0
Function GetParameterPageName.
int m_parameterGridPage
the page currently displayed by m_parameterGrid it is most of time the m_pageList selection...
Definition: id.h:241
Class GRID_TRICKS is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance...
Definition: grid_tricks.h:51
static TOOL_ACTION zoomFitScreen
Definition: actions.h:56
virtual wxArrayString GetParameterTypes(int aPage)=0
Function GetParameterTypes.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
BOARD * GetBoard() const
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
void SetVisibleAlls()
Function SetVisibleAlls changes the bit-mask of visible element categories and layers.
#define FOOTPRINT_WIZARD_FRAME_NAME
Definition: draw_frame.h:52
void Update3D_Frame(bool aForceReloadFootprint=true)
Function Update3D_Frame must be called after a footprint selection Updates the 3D view and 3D frame t...
wxAuiManager m_auimgr
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
virtual wxArrayString GetParameterNames(int aPage)=0
Function GetParameterNames.
void initParameterGrid()
Function initParameterGrid Prepare the grid where parameters are displayed.
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
const wxString WIZARD_PARAM_UNITS_DEGREES
Definition of class FOOTPRINT_EDIT_FRAME.
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
void ClickOnPageList(wxCommandEvent &event)
void DeactivateTool()
Function DeactivateTool() Deactivates the currently active tool.
Pcbnew hotkeys.
Class PCBNEW_CONTROL.
This file contains miscellaneous commonly used macros and functions.
const wxString WIZARD_PARAM_UNITS_RADIANS
void ReCreateParameterList()
Function ReCreateParameterList Creates the list of parameters for the current page.
bool GeneralControlKeyMovement(int aHotKey, wxPoint *aPos, bool aSnapToGrid)
Handle the common part of GeneralControl dedicated to global cursor keys (i.e.
virtual void OnActivate(wxActivateEvent &event) override
Function OnActivate is called when the frame frame is activate to reload the libraries and component ...
FOOTPRINT_WIZARD_FRAME::DefaultParameters FOOTPRINT_WIZARD_FRAME::Process_Special_Functions FOOTPRINT_WIZARD_FRAME::Show3D_Frame EVT_GRID_CMD_CELL_CHANGED(ID_FOOTPRINT_WIZARD_PARAMETER_LIST, FOOTPRINT_WIZARD_FRAME::ParametersUpdated) FOOTPRINT_WIZARD_FRAME
Class TOOL_MANAGER.
Definition: tool_manager.h:49
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
const wxString WIZARD_PARAM_UNITS_INTEGER
wxGrid * m_parameterGrid
The list of parameters.
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
void ReCreatePageList()
Function ReCreatePageList Creates or recreates the list of parameter pages for the current wizard...
virtual wxArrayString GetParameterDesignators(int aPage)=0
Function GetParamaterDesignators.
void RefreshCrossHair(const wxPoint &aOldPos, const wxPoint &aEvtPos, wxDC *aDC)
Move and refresh the crosshair after movement and call the mouse capture function.
const wxString WIZARD_PARAM_UNITS_MILS
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:300
const wxString WIZARD_PARAM_UNITS_FLOAT
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, wxWindow *aFrame)
Sets the work environment (model, view, view controls and the parent window).
PCB_GENERAL_SETTINGS & Settings()
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:281
FOOTPRINT_WIZARD_FRAME(KIWAY *aKiway, wxWindow *parent, FRAME_T aFrameType)
Definition of file extensions used in Kicad.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets all tools (i.e.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
uint32_t EDA_KEY
Definition: common.h:74
const wxString WIZARD_PARAM_UNITS_PERCENT
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:918
#define KICAD_DEFAULT_DRAWFRAME_STYLE
EVT_TOOL(ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard) EVT_TOOL(ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
Definition: base_struct.h:297
bool IsModal()
Definition: kiway_player.h:226
FOOTPRINT_WIZARD * GetMyWizard()
Function GetMyWizard Reloads the wizard by name.
bool m_wizardListShown
A show-once flag for the wizard list.
Specialization of the wxAuiPaneInfo class for KiCad panels.
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
void PythonPluginsReload()
Reload the Python plugins if they are newer than the already loaded, and load new plugins if any Do n...
void Show3D_Frame(wxCommandEvent &event) override
Function Show3D_Frame (virtual) displays 3D view of the footprint (module) being edited.
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
void UseColorScheme(const COLORS_DESIGN_SETTINGS *aSettings)
Function UseColorScheme Applies layer color settings.
Class COMMON_TOOLS.
Definition: common_tools.h:38
Class TOOL_DISPATCHER.
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar EVT_MENU(ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, FOOTPRINT_EDIT_FRAME::ProcessPreferences) EVT_MENU(ID_PCB_LIB_TABLE_EDIT
BOARD * GetBoard()
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
void PythonPluginsReloadBase()
Helper function PythonPluginsReloadBase Reload Python plugins if they are newer than the already load...
Definition: pcbnew.cpp:311
virtual int GetNumParameterPages()=0
Function GetNumParameterPages.
virtual void UpdateStatusBar() override
Update the status bar information.
Class PCB_ACTIONS.
Definition: pcb_actions.h:42
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
Declaration of the eda_3d_viewer class.
const char * name
Definition: DXF_plotter.cpp:61
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools...
DLIST< MODULE > m_Modules
Definition: class_board.h:249
#define MODAL_MODE_EXTRASTYLE
bool GeneralControl(wxDC *aDC, const wxPoint &aPosition, EDA_KEY aHotKey=0) override
Perform application specific control using aDC at aPosition in logical units.
void SelectFootprintWizard()
Function SelectFootprintWizard Shows the list of footprint wizards available into the system...
size_t i
Definition: json11.cpp:597
void OnSetRelativeOffset(wxCommandEvent &event)
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void OnGridSize(wxSizeEvent &aSizeEvent)
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel...
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:925
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard. ...
Definition: eda_3d_viewer.h:49
virtual wxArrayString GetParameterValues(int aPage)=0
Function GetParameterValues.
Module description (excepted pads)
void OnCloseWindow(wxCloseEvent &Event) override
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
virtual wxArrayString GetParameterHints(int aPage)=0
Function GetParameterHints.
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Set the screen cross hair position to aPosition in logical (drawing) units.
const wxString WIZARD_PARAM_UNITS_BOOL
Message panel definition file.
void updateView()
rebuild the GAL view (reint tool manager, colors and drawings) must be run after any footprint change...
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:120
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
void UpdateMsgPanel() override
redraws the message panel.
void PythonPluginsReload()
Reload the Python plugins if they are newer than the already loaded, and load new plugins if any Do n...
void ResizeParamColumns()
Expand the &#39;Value&#39; column to fill available.
EDA_3D_VIEWER * Get3DViewerFrame()
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
virtual void OnActivate(wxActivateEvent &event)
Called when activating the frame.
bool m_movingCursorWithKeyboard
One-shot to avoid a recursive mouse event during hotkey movement.
Definition: draw_frame.h:173
void ClearMsgPanel(void)
Clear all messages from the message panel.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
void StopDrawing()
Function StopDrawing() Prevents the GAL canvas from further drawing till it is recreated or StartDraw...
Class FOOTPRINT_WIZARD This is the parent class from where any footprint wizard class must derive...