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,
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 // SelectFootprintWizard();
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 0
601  // Currently, we do not have a way to see if a Python wizard has changed,
602  // therefore the lists of parameters and option has to be rebuilt
603  // This code could be enabled when this way exists
604  bool footprintWizardsChanged = false;
605 
606  if( footprintWizardsChanged )
607  {
608  // If we are here, the library list has changed, rebuild it
611  }
612 #endif
613 }
614 
615 
616 bool FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
617 {
618  // Filter out the 'fake' mouse motion after a keyboard movement
619  if( !aHotKey && m_movingCursorWithKeyboard )
620  {
622  return false;
623  }
624 
625  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
626  cmd.SetEventObject( this );
627 
628  wxPoint pos = aPosition;
629  wxPoint oldpos = GetCrossHairPosition();
630  bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, true );
631 
632  switch( aHotKey )
633  {
634  case WXK_F1:
635  cmd.SetId( ID_KEY_ZOOM_IN );
636  GetEventHandler()->ProcessEvent( cmd );
637  keyHandled = true;
638  break;
639 
640  case WXK_F2:
641  cmd.SetId( ID_KEY_ZOOM_OUT );
642  GetEventHandler()->ProcessEvent( cmd );
643  keyHandled = true;
644  break;
645 
646  case WXK_F3:
647  cmd.SetId( ID_ZOOM_REDRAW );
648  GetEventHandler()->ProcessEvent( cmd );
649  keyHandled = true;
650  break;
651 
652  case WXK_F4:
653  cmd.SetId( ID_POPUP_ZOOM_CENTER );
654  GetEventHandler()->ProcessEvent( cmd );
655  keyHandled = true;
656  break;
657 
658  case WXK_HOME:
659  cmd.SetId( ID_ZOOM_PAGE );
660  GetEventHandler()->ProcessEvent( cmd );
661  keyHandled = true;
662  break;
663 
664  case ' ':
666  keyHandled = true;
667  break;
668 
669  default:
670  break;
671  }
672 
673  SetCrossHairPosition( pos );
674  RefreshCrossHair( oldpos, aPosition, aDC );
675 
676  UpdateStatusBar(); // Display new cursor coordinates
677 
678  return keyHandled;
679 }
680 
681 
682 void FOOTPRINT_WIZARD_FRAME::Show3D_Frame( wxCommandEvent& event )
683 {
684  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
685 
686  // We can probably remove this for 6.0, but just to be safe we'll stick to
687  // one 3DFrame at a time for 5.0
688  if( draw3DFrame )
689  draw3DFrame->Close( true );
690 
691  draw3DFrame = new EDA_3D_VIEWER( &Kiway(), this, _( "3D Viewer" ) );
692  Update3D_Frame( false );
693 
694 #ifdef __WXMAC__
695  // A stronger version of Raise() which promotes the window to its parent's level.
696  draw3DFrame->ReparentQuasiModal();
697 #else
698  draw3DFrame->Raise(); // Needed with some Window Managers
699 #endif
700 
701  draw3DFrame->Show( true );
702 }
703 
704 
710 void FOOTPRINT_WIZARD_FRAME::Update3D_Frame( bool aForceReloadFootprint )
711 {
712  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
713 
714  if( draw3DFrame == NULL )
715  return;
716 
717  wxString frm3Dtitle;
718  frm3Dtitle.Printf( _( "ModView: 3D Viewer [%s]" ), GetChars( m_wizardName ) );
719  draw3DFrame->SetTitle( frm3Dtitle );
720 
721  if( aForceReloadFootprint )
722  {
723  // Force 3D screen refresh immediately
724  draw3DFrame->NewDisplay( true );
725  }
726 }
727 
728 
730 {
731  wxString msg;
732 
733  if( !m_mainToolBar )
734  {
735  m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
736  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
737 
738  // Set up toolbar
739  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, wxEmptyString,
740  KiBitmap( module_wizard_xpm ),
741  _( "Select wizard script to run" ) );
742 
743  m_mainToolBar->AddSeparator();
744 
745  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, wxEmptyString,
746  KiBitmap( reload_xpm ),
747  _( "Reset wizard parameters to default") );
748 
749  m_mainToolBar->AddSeparator();
750 
751  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_PREVIOUS, wxEmptyString,
752  KiBitmap( lib_previous_xpm ),
753  _( "Select previous parameters page" ) );
754 
755  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_NEXT, wxEmptyString,
756  KiBitmap( lib_next_xpm ),
757  _( "Select next parameters page" ) );
758 
759  m_mainToolBar->AddSeparator();
760  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW, wxEmptyString,
761  KiBitmap( three_d_xpm ),
762  _( "Show footprint in 3D viewer" ) );
763 
764  m_mainToolBar->AddSeparator();
765  msg = AddHotkeyName( _( "Zoom in" ), g_Module_Editor_Hotkeys_Descr,
767  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString,
768  KiBitmap( zoom_in_xpm ), msg );
769 
770  msg = AddHotkeyName( _( "Zoom out" ), g_Module_Editor_Hotkeys_Descr,
772  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString,
773  KiBitmap( zoom_out_xpm ), msg );
774 
775  msg = AddHotkeyName( _( "Redraw view" ), g_Module_Editor_Hotkeys_Descr,
777  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
778  KiBitmap( zoom_redraw_xpm ), msg );
779 
780  msg = AddHotkeyName( _( "Zoom auto" ), g_Module_Editor_Hotkeys_Descr,
782  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
783  KiBitmap( zoom_fit_in_page_xpm ), msg );
784 
785  // The footprint wizard always can export the current footprint
786  m_mainToolBar->AddSeparator();
787  m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_DONE,
788  wxEmptyString, KiBitmap( export_footprint_names_xpm ),
789  _( "Export footprint to editor" ) );
790 
791  // after adding the buttons to the toolbar, must call Realize() to
792  // reflect the changes
793  m_mainToolBar->Realize();
794  }
795 
796  m_mainToolBar->Refresh();
797 }
798 
799 
801 {
802  // Currently, there is no vertical toolbar
803 }
804 
805 #if defined(KICAD_SCRIPTING)
807 {
808  // Reload the Python plugins
809  // Because the board editor has also a plugin python menu,
810  // call PCB_EDIT_FRAME::PythonPluginsReload() if the board editor
811  // is running
812  PCB_EDIT_FRAME* brd_frame =
813  static_cast<PCB_EDIT_FRAME*>( Kiway().Player( FRAME_PCB, false ) );
814 
815  if( brd_frame )
816  brd_frame->PythonPluginsReload();
817  else
819 }
820 #endif
821 
822 
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:284
FOOTPRINT_WIZARD_FRAME(KIWAY *aKiway, wxWindow *parent, FRAME_T aFrameType)
The common library.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:538
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:73
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:921
#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.
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:170
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:248
#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.
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:928
Class EDA_3D_VIEWER Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard...
Definition: eda_3d_viewer.h:50
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...