KiCad PCB EDA Suite
cvpcb_mainframe.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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #include <fctsys.h>
31 #include <build_version.h>
32 #include <kiway_express.h>
33 #include <pgm_base.h>
34 #include <kiface_i.h>
35 #include <macros.h>
36 #include <confirm.h>
37 #include <eda_doc.h>
38 #include <eda_dde.h>
39 #include <gestfich.h>
40 #include <html_messagebox.h>
42 #include <fp_lib_table.h>
43 #include <netlist_reader.h>
44 #include <bitmaps.h>
46 
47 #include <cvpcb_mainframe.h>
48 #include <cvpcb.h>
49 #include <listboxes.h>
50 #include <invoke_pcb_dialog.h>
52 #include <cvpcb_id.h>
53 
54 
55 wxSize const FRAME_MIN_SIZE_DU( 350, 250 );
56 wxSize const FRAME_DEFAULT_SIZE_DU( 450, 300 );
57 
60 
62 static const wxString KeepCvpcbOpenEntry = "KeepCvpcbOpen";
63 
64 static const wxString FilterFootprintEntry = "FilterFootprint";
66 
67 BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER )
68 
69  // Menu events
70  EVT_MENU( wxID_SAVE, CVPCB_MAINFRAME::SaveQuitCvpcb )
71  EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit )
72  EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp )
73  EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout )
77 
78  // Toolbar events
80 
81  EVT_TOOL( ID_CVPCB_LIB_TABLE_EDIT, CVPCB_MAINFRAME::OnEditFootprintLibraryTable )
86  EVT_TOOL( ID_CVPCB_AUTO_ASSOCIE, CVPCB_MAINFRAME::AutomaticFootprintMatching )
88  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
90  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
92  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
94  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
95  EVT_TEXT( ID_CVPCB_FILTER_TEXT_EDIT, CVPCB_MAINFRAME::OnEnterFilteringText )
96 
97  // Frame events
98  EVT_CLOSE( CVPCB_MAINFRAME::OnCloseWindow )
99  EVT_SIZE( CVPCB_MAINFRAME::OnSize )
100 
101  // UI event handlers
102  EVT_UPDATE_UI( ID_CVPCB_CONFIG_KEEP_OPEN_ON_SAVE, CVPCB_MAINFRAME::OnUpdateKeepOpenOnSave )
103  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyKeywords)
104  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyPinCount )
105  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, CVPCB_MAINFRAME::OnFilterFPbyLibrary )
106  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, CVPCB_MAINFRAME::OnFilterFPbyKeyName )
107 
108 END_EVENT_TABLE()
109 
110 
111 #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
112 
113 
114 CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
115  KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, wxT( "CvPCB" ), wxDefaultPosition,
117 {
118  m_compListBox = NULL;
119  m_footprintListBox = NULL;
120  m_libListBox = NULL;
121  m_mainToolBar = NULL;
122  m_modified = false;
123  m_keepCvpcbOpen = false;
125  m_skipComponentSelect = false;
126  m_filteringOptions = 0;
127  m_tcFilterString = NULL;
129 
130  // Give an icon
131  wxIcon icon;
132  icon.CopyFromBitmap( KiBitmap( icon_cvpcb_xpm ) );
133  SetIcon( icon );
134 
135  SetAutoLayout( true );
136 
137  LoadSettings( config() );
138 
139  wxSize const frame_min( ConvertDialogToPixels( FRAME_MIN_SIZE_DU ) );
140 
141  SetSizeHints( frame_min );
142 
143  // Frame size and position
144  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
145 
146  // create the status bar
147  static const int dims[3] = { -1, -1, 250 };
148 
149  CreateStatusBar( 3 );
150  SetStatusWidths( 3, dims );
151 
152  ReCreateMenuBar();
154 
155  // Create list of available modules and components of the schematic
156  BuildCmpListBox();
159 
160  m_auimgr.SetManagedWindow( this );
161 
162  UpdateTitle();
163 
164  EDA_PANEINFO horiz;
165  horiz.HorizontalToolbarPane();
166 
167  EDA_PANEINFO info;
168  info.InfoToolbarPane();
169 
170 
171  if( m_mainToolBar )
172  m_auimgr.AddPane( m_mainToolBar,
173  wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top() );
174 
175  if( m_compListBox )
176  m_auimgr.AddPane( m_compListBox,
177  wxAuiPaneInfo( horiz ).Name( wxT( "m_compListBox" ) ).CentrePane() );
178 
179  if( m_libListBox)
180  m_auimgr.AddPane( m_libListBox,
181  wxAuiPaneInfo( info ).Name( wxT( "m_libListBox" ) ).
182  Left().BestSize( (int) ( m_FrameSize.x * 0.20 ), m_FrameSize.y ) );
183 
184  if( m_footprintListBox )
185  m_auimgr.AddPane( m_footprintListBox,
186  wxAuiPaneInfo( info ).Name( wxT( "m_footprintListBox" ) ).
187  Right().BestSize( (int) ( m_FrameSize.x * 0.30 ), m_FrameSize.y ) );
188 
189  m_auimgr.Update();
190 }
191 
192 
194 {
195  m_auimgr.UnInit();
196 }
197 
198 
199 void CVPCB_MAINFRAME::LoadSettings( wxConfigBase* aCfg )
200 {
202 
203  wxSize const frame_default( ConvertDialogToPixels( FRAME_DEFAULT_SIZE_DU ) );
204 
205  if( m_FrameSize == wxDefaultSize )
206  m_FrameSize = frame_default;
207 
208  aCfg->Read( KeepCvpcbOpenEntry, &m_keepCvpcbOpen, true );
210 }
211 
212 
213 void CVPCB_MAINFRAME::SaveSettings( wxConfigBase* aCfg )
214 {
216 
217  aCfg->Write( KeepCvpcbOpenEntry, m_keepCvpcbOpen );
219 }
220 
221 
222 void CVPCB_MAINFRAME::OnSize( wxSizeEvent& event )
223 {
224  event.Skip();
225 }
226 
227 
228 void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event )
229 {
230  Close( false );
231 }
232 
233 
234 void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
235 {
236  if( m_modified )
237  {
238  wxString msg = _( "Component to Footprint links modified.\nSave before exit ?" );
239  int ii = DisplayExitDialog( this, msg );
240 
241  switch( ii )
242  {
243  case wxID_CANCEL:
244  Event.Veto();
245  return;
246 
247  case wxID_NO:
248  break;
249 
250  case wxID_YES:
252  break;
253  }
254  }
255 
256  // Close module display frame
258  GetFootprintViewerFrame()->Close( true );
259 
260  m_modified = false;
261 
262  Destroy();
263  return;
264 }
265 
266 
267 void CVPCB_MAINFRAME::ChangeFocus( bool aMoveRight )
268 {
269  wxWindow* hasFocus = wxWindow::FindFocus();
270 
271  if( aMoveRight )
272  {
273  if( hasFocus == m_libListBox )
274  m_compListBox->SetFocus();
275  else if( hasFocus == m_compListBox )
276  m_footprintListBox->SetFocus();
277  else if( hasFocus == m_footprintListBox )
278  m_libListBox->SetFocus();
279  }
280  else
281  {
282  if( hasFocus == m_libListBox )
283  m_footprintListBox->SetFocus();
284  else if( hasFocus == m_compListBox )
285  m_libListBox->SetFocus();
286  else if( hasFocus == m_footprintListBox )
287  m_compListBox->SetFocus();
288  }
289 }
290 
291 
292 void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event )
293 {
294  if( m_netlist.IsEmpty() )
295  return;
296 
297  long first_selected = m_compListBox->GetFirstSelected();
298 
299  if( first_selected < 0 )
300  first_selected = -1; // We will start to 0 for the first search , if no item selected
301 
302  int candidate = -1;
303 
304  for( unsigned jj = first_selected+1; jj < m_netlist.GetCount(); jj++ )
305  {
306  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
307  {
308  candidate = jj;
309  break;
310  }
311  }
312 
313  if( candidate >= 0 )
314  {
316  m_compListBox->SetSelection( candidate );
318  }
319 }
320 
321 
322 void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
323 {
324  if( m_netlist.IsEmpty() )
325  return;
326 
327  int first_selected = m_compListBox->GetFirstSelected();
328 
329  if( first_selected < 0 )
330  first_selected = m_compListBox->GetCount();
331 
332  int candidate = -1;
333 
334  for( int jj = first_selected-1; jj >= 0; jj-- )
335  {
336  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
337  {
338  candidate = jj;
339  break;
340  }
341  }
342 
343  if( candidate >= 0 )
344  {
346  m_compListBox->SetSelection( candidate );
348  }
349 }
350 
351 
352 void CVPCB_MAINFRAME::SaveQuitCvpcb( wxCommandEvent& aEvent )
353 {
355 
356  m_modified = false;
357 
358  if( !m_keepCvpcbOpen )
359  Close( true );
360 }
361 
362 
363 void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event )
364 {
365  if( IsOK( this, _( "Delete selections" ) ) )
366  {
367  m_skipComponentSelect = true;
368 
369  // Remove all selections to avoid issues when setting the fpids
371 
372  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
373  {
374  LIB_ID fpid;
375 
376  m_netlist.GetComponent( i )->SetFPID( fpid );
377  SetNewPkg( wxEmptyString );
378  }
379 
380  // Remove all selections after setting the fpids
382 
383  m_skipComponentSelect = false;
386  }
387 
388  DisplayStatus();
389 }
390 
391 
392 bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
393 {
394  return true;
395 }
396 
397 
398 void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent )
399 {
400  bool tableChanged = false;
401  int r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs( Kiway() ) );
402 
403  if( r & 1 )
404  {
405  wxString fileName = FP_LIB_TABLE::GetGlobalTableFileName();
406 
407  try
408  {
409  GFootprintTable.Save( fileName );
410  tableChanged = true;
411  }
412  catch( const IO_ERROR& ioe )
413  {
414  wxString msg = wxString::Format(
415  _( "Error occurred saving the global footprint library table:\n\"%s\"\n%s" ),
416  GetChars( fileName ),
417  GetChars( ioe.What() )
418  );
419  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
420  }
421  }
422 
423  if( r & 2 )
424  {
425  wxString fileName = Prj().FootprintLibTblName();
426 
427  try
428  {
429  Prj().PcbFootprintLibs( Kiway() )->Save( fileName );
430  tableChanged = true;
431  }
432  catch( const IO_ERROR& ioe )
433  {
434  wxString msg = wxString::Format(
435  _( "Error occurred saving the project footprint library table:\n\"%s\"\n%s" ),
436  GetChars( fileName ),
437  GetChars( ioe.What() )
438  );
439  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
440  }
441  }
442 
443  if( tableChanged )
444  {
445  wxBusyCursor dummy;
447  m_FootprintsList->ReadFootprintFiles( Prj().PcbFootprintLibs( Kiway() ) );
448  }
449 }
450 
451 
452 void CVPCB_MAINFRAME::OnKeepOpenOnSave( wxCommandEvent& event )
453 {
454  m_keepCvpcbOpen = event.IsChecked();
455 }
456 
457 
458 void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event )
459 {
460  CreateScreenCmp();
461  GetFootprintViewerFrame()->RedrawScreen( wxPoint( 0, 0 ), false );
462 }
463 
464 
465 void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
466 {
468  return;
469 
470  wxString libraryName;
471  COMPONENT* component = GetSelectedComponent();
472  libraryName = m_libListBox->GetSelectedLibrary();
473 
474  m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
476 
477  refreshAfterComponentSearch (component);
478 }
479 
480 
482 {
483  // Tell AuiMgr that objects are changed !
484  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
485  // (could be not the case when starting CvPcb
486  m_auimgr.Update();
487 
488  if( component == NULL )
489  return;
490 
491  // Preview of the already assigned footprint.
492  // Find the footprint that was already chosen for this component and select it,
493  // but only if the selection is made from the component list or the library list.
494  // If the selection is made from the footprint list, do not change the current
495  // selected footprint.
496  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
497  {
498  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
499 
500  bool found = false;
501 
502  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
503  {
504  wxString footprintName;
505  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
506  msg.Trim( true );
507  msg.Trim( false );
508  footprintName = msg.AfterFirst( wxChar( ' ' ) );
509 
510  if( module.Cmp( footprintName ) == 0 )
511  {
512  m_footprintListBox->SetSelection( ii, true );
513  found = true;
514  break;
515  }
516  }
517 
518  if( !found )
519  {
520  int ii = m_footprintListBox->GetSelection();
521 
522  if ( ii >= 0 )
523  m_footprintListBox->SetSelection( ii, false );
524 
526  {
527  CreateScreenCmp();
528  }
529  }
530  }
531 
533  DisplayStatus();
534 }
535 
536 void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
537 {
538  int option = 0;
539 
540  switch( event.GetId() )
541  {
542  case ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST:
544  break;
545 
546  case ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST:
548  break;
549 
550  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST:
552  break;
553 
554  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME:
557  break;
558  }
559 
560  if( event.IsChecked() )
561  m_filteringOptions |= option;
562  else
563  m_filteringOptions &= ~option;
564 
565  wxListEvent l_event;
566  OnSelectComponent( l_event );
567 }
568 
569 
570 void CVPCB_MAINFRAME::OnUpdateKeepOpenOnSave( wxUpdateUIEvent& event )
571 {
572  event.Check( m_keepCvpcbOpen );
573 }
574 
575 
576 void CVPCB_MAINFRAME::OnFilterFPbyKeywords( wxUpdateUIEvent& event )
577 {
579 }
580 
581 
582 void CVPCB_MAINFRAME::OnFilterFPbyPinCount( wxUpdateUIEvent& event )
583 {
585 }
586 
587 
588 void CVPCB_MAINFRAME::OnFilterFPbyLibrary( wxUpdateUIEvent& event )
589 {
591 }
592 
593 
594 void CVPCB_MAINFRAME::OnFilterFPbyKeyName( wxUpdateUIEvent& event )
595 {
597 }
598 
599 
600 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
601 {
602  // Called when changing the filter string in main toolbar.
603  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
604  // available footprints which match the filter
605 
607 
609  return;
610 
611  OnSelectFilteringFootprint( aEvent );
612 }
613 
614 
616 {
617  wxString msg;
618  COMPONENT* component;
619 
620  if( wxWindow::FindFocus() == m_compListBox || wxWindow::FindFocus() == m_libListBox )
621  {
622  msg.Printf( _( "Components: %d, unassigned: %d" ), (int) m_netlist.GetCount(),
624  SetStatusText( msg, 0 );
625 
626  msg.Empty();
627 
628  component = GetSelectedComponent();
629 
630  if( component )
631  {
632  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
633  {
634  if( msg.IsEmpty() )
635  msg += component->GetFootprintFilters()[ii];
636  else
637  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
638  }
639 
640  msg = _( "Filter list: " ) + msg;
641  }
642 
643  SetStatusText( msg, 1 );
644  }
645  else
646  {
647  wxString footprintName = GetSelectedFootprint();
648 
649  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
650 
651  if( module ) // can be NULL if no netlist loaded
652  {
653  msg = _( "Description: " ) + module->GetDoc();
654  SetStatusText( msg, 0 );
655 
656  msg = _( "Key words: " ) + module->GetKeywords();
657  SetStatusText( msg, 1 );
658  }
659  }
660 
661  msg.Empty();
662  wxString filters;
663 
664  if( m_footprintListBox )
665  {
667  filters = _( "key words" );
668 
670  {
671  if( !filters.IsEmpty() )
672  filters += wxT( "+" );
673 
674  filters += _( "pin count" );
675  }
676 
678  {
679  if( !filters.IsEmpty() )
680  filters += wxT( "+" );
681 
682  filters += _( "library" );
683  }
684 
686  {
687  if( !filters.IsEmpty() )
688  filters += wxT( "+" );
689 
690  filters += _( "name" );
691  }
692 
693  if( filters.IsEmpty() )
694  msg = _( "No filtering" );
695  else
696  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
697 
698  msg << wxT( ": " ) << m_footprintListBox->GetCount();
699 
700  SetStatusText( msg, 2 );
701  }
702 }
703 
704 
706 {
707  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
708 
709  // Check if there are footprint libraries in the footprint library table.
710  if( !fptbl || !fptbl->GetLogicalLibs().size() )
711  {
712  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
713  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
714  return false;
715  }
716 
717  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
718 
719  m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
720 
721  if( m_FootprintsList->GetErrorCount() )
722  {
723  m_FootprintsList->DisplayErrors( this );
724  }
725 
726  return true;
727 }
728 
729 
731 {
732  wxString title;
733  PROJECT& prj = Prj();
734  wxFileName fn = prj.GetProjectFullName();
735 
736  if( fn.IsOk() && !prj.GetProjectFullName().IsEmpty() && fn.FileExists() )
737  {
738  title.Printf( L"Cvpcb \u2014 %s%s",
739  fn.GetFullPath(),
740  fn.IsFileWritable()
741  ? wxString( wxEmptyString )
742  : _( " [Read Only]" ) );
743  }
744  else
745  {
746  title = "Cvpcb";
747  }
748 
749  SetTitle( title );
750 }
751 
752 
754 {
755  if( m_netlist.IsEmpty() )
756  return;
757 
758  int selection = m_compListBox->GetSelection();
759 
760  if ( selection < 0 )
761  selection = 0;
762 
763  if( m_netlist.GetComponent( selection ) == NULL )
764  return;
765 
766  COMPONENT* component = m_netlist.GetComponent( selection );
767 
768  std::string packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
769 
770  if( Kiface().IsSingle() )
771  SendCommand( MSG_TO_SCH, packet.c_str() );
772  else
773  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
774 }
775 
776 
777 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
778 {
779  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
780  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
781 
782  m_netlist.Clear();
783 
784  try
785  {
786  netrdr.LoadNetlist();
787  }
788  catch( const IO_ERROR& ioe )
789  {
790  wxString msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.What().GetData() );
791  wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
792  return 1;
793  }
794 
795  // We also remove footprint name if it is "$noname" because this is a dummy name,
796  // not the actual name of the footprint.
797  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
798  {
799  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
800  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
801  }
802 
803  // Sort components by reference:
805 
806  return 0;
807 }
808 
809 
811 {
813 
814  if( !fpframe )
815  {
816  fpframe = new DISPLAY_FOOTPRINTS_FRAME( &Kiway(), this );
817  fpframe->Show( true );
818  }
819  else
820  {
821  if( fpframe->IsIconized() )
822  fpframe->Iconize( false );
823 
824  // The display footprint window might be buried under some other
825  // windows, so CreateScreenCmp() on an existing window would not
826  // show any difference, leaving the user confused.
827  // So we want to put it to front, second after our CVPCB_MAINFRAME.
828  // We do this by a little dance of bringing it to front then the main
829  // frame back.
830  fpframe->Raise(); // Make sure that is visible.
831  Raise(); // .. but still we want the focus.
832  }
833 
834  fpframe->InitDisplay();
835 }
836 
837 
839 {
840  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
841 
842  if( m_footprintListBox == NULL )
843  {
845  wxDefaultPosition, wxDefaultSize );
846  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(),
847  wxFONTFAMILY_MODERN,
848  wxFONTSTYLE_NORMAL,
849  wxFONTWEIGHT_NORMAL ) );
850  }
851 
852  m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL,
854  DisplayStatus();
855 }
856 
857 
859 {
860  wxString msg;
861  COMPONENT* component;
862  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
863 
864  if( m_compListBox == NULL )
865  {
867  wxDefaultPosition, wxDefaultSize );
868  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(),
869  wxFONTFAMILY_MODERN,
870  wxFONTSTYLE_NORMAL,
871  wxFONTWEIGHT_NORMAL ) );
872  }
873 
875 
876  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
877  {
878  component = m_netlist.GetComponent( i );
879 
880  msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1,
881  GetChars( component->GetReference() ),
882  GetChars( component->GetValue() ),
883  GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
884  m_compListBox->m_ComponentList.Add( msg );
885  }
886 
887  if( m_compListBox->m_ComponentList.Count() )
888  {
889  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
890  m_compListBox->SetSelection( 0, true );
891  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
893  }
894 }
895 
896 
898 {
899  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
900 
901  if( m_libListBox == NULL )
902  {
904  wxDefaultPosition, wxDefaultSize );
905  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(),
906  wxFONTFAMILY_MODERN,
907  wxFONTSTYLE_NORMAL,
908  wxFONTWEIGHT_NORMAL ) );
909  }
910 
911  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
912 
913  if( tbl )
914  {
915  wxArrayString libNames;
916 
917  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
918 
919  for( unsigned ii = 0; ii < libNickNames.size(); ii++ )
920  libNames.Add( libNickNames[ii] );
921 
922  m_libListBox->SetLibraryList( libNames );
923  }
924 }
925 
926 
928 {
929  int selection = m_compListBox->GetSelection();
930 
931  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
932  return m_netlist.GetComponent( selection );
933 
934  return NULL;
935 }
936 
937 
939 {
940  // returns the Footprint Viewer frame, if exists, or NULL
941  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
942  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
943 }
944 
946 {
947  // returns the LIB_ID of the selected footprint in footprint listview
948  // or a empty string
950 }
951 
952 
953 void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
954 {
955  Pgm().ConfigurePaths( this );
956 }
957 
958 
960 {
961  const std::string& payload = mail.GetPayload();
962 
963  DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
964 
965  switch( mail.Command() )
966  {
968  ReadNetListAndFpFiles( payload );
969  /* @todo
970  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
971  */
972  break;
973 
974  default:
975  ; // ignore most
976  }
977 }
void OnUpdateKeepOpenOnSave(wxUpdateUIEvent &event)
EDA_PANEINFO & HorizontalToolbarPane()
Function HorizontalToolbarPane Change *this to a horizontal toolbar for KiCad.
void ToFirstNA(wxCommandEvent &event)
void SetLibraryList(const wxArrayString &aList)
void SendMessageToEESCHEMA()
Function SendMessageToEESCHEMA Send a remote command to Eeschema via a socket, Commands are $PART: "r...
void OnEditFootprintLibraryTable(wxCommandEvent &event)
Function OnEditFootprintLibraryTable displays the footprint library table editing dialog and updates ...
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:111
Class KIWAY_EXPRESS carries a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
bool empty() const
Definition: lib_id.h:170
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
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
DDE server & client.
Class PROJECT holds project specific data.
Definition: project.h:56
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void OnSelectFilteringFootprint(wxCommandEvent &event)
Function OnSelectFilteringFootprint is the command event handler for enabling and disabling footprint...
Class KICAD_NETLIST_READER read the new s-expression based KiCad netlist format.
This file is part of the common library TODO brief description.
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:153
This file is part of the common library.
COMPONENTS_LISTBOX * m_compListBox
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:175
This file is part of the common library.
#define CVPCB_MAINFRAME_NAME
void DeselectAll()
Removes all selection in lists which can have more than one item selected.
#define MSG_TO_SCH
Definition: eda_dde.h:46
wxString m_currentSearchPattern
virtual void SaveSettings(wxConfigBase *aCfg)
Function SaveSettings saves common frame parameters to a configuration data file. ...
void SetSelection(int index, bool State=true)
void SetNewPkg(const wxString &aFootprintName)
Function SetNewPkg set the footprint name for all selected components in component list and selects t...
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:94
void OnFilterFPbyKeywords(wxUpdateUIEvent &event)
void UpdateTitle()
Function UpdateTitle sets the main window title bar text.
void ReCreateHToolbar()
Definition: tool_cvpcb.cpp:38
int ReadSchematicNetlist(const std::string &aNetlist)
Function ReadSchematicNetlist read the netlist (.net) file built on the fly by Eeschema.
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
void SaveQuitCvpcb(wxCommandEvent &event)
bool SendCommand(int service, const char *cmdline)
Definition: eda_dde.cpp:134
wxAuiManager m_auimgr
#define FOOTPRINTVIEWER_FRAME_NAME
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:235
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
wxSize const FRAME_MIN_SIZE_DU(350, 250)
bool LoadFootprintFiles()
Function LoadFootprintFiles reads the list of footprint (*.mod files) and generate the list of footpr...
void ChangeFocus(bool aMoveRight)
static const wxString FilterFootprintEntry
static std::unique_ptr< FOOTPRINT_LIST > GetInstance(KIWAY &aKiway)
Factory function to return a new FOOTPRINT_LIST via Kiway.
void ToPreviousNA(wxCommandEvent &event)
Specialization of the wxAuiPaneInfo class for KiCad panels.
void CreateScreenCmp()
Create or Update the frame showing the current highlighted footprint and (if showed) the 3D display f...
wxSize const FRAME_DEFAULT_SIZE_DU(450, 300)
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
EVT_TOOL(ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, CVPCB_MAINFRAME::OnSelectFilteringFootprint) EVT_TOOL(ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST
Class DISPLAY_FOOTPRINTS_FRAME is used to display footprints.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:312
This file contains miscellaneous commonly used macros and functions.
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
void SortByReference()
void OnSize(wxSizeEvent &SizeEvent)
VTBL_ENTRY void ConfigurePaths(wxWindow *aParent=NULL)
Function ConfigurePaths.
Definition: pgm_base.cpp:905
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
const wxString & GetReference() const
Definition: pcb_netlist.h:149
const wxString & GetValue() const
Definition: pcb_netlist.h:151
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
wxTextCtrl * m_tcFilterString
void OnSelectComponent(wxListEvent &event)
Function OnSelectComponent Called when clicking on a component in component list window.
void DelAssociations(wxCommandEvent &event)
Function DelAssociations removes all component footprint associations already made.
virtual void LoadNetlist() override
Function LoadNetlist loads the contents of the netlist file into aNetlist.
void refreshAfterComponentSearch(COMPONENT *component)
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
static const wxString KeepCvpcbOpenEntry
Nonzero if cvpcb should be kept open after saving association in schematic.
const wxString & GetDoc()
void UpdateWidth(int aLine=-1)
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
virtual void LoadSettings(wxConfigBase *aCfg)
Function LoadSettings loads common frame parameters from a configuration file.
EVT_MENU(ID_SELECT_PREFERED_PDF_BROWSER_NAME, KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser) EVT_MENU_RANGE(ID_LANGUAGE_CHOICE
Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder.
void KiwayMailIn(KIWAY_EXPRESS &aEvent) override
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
wxString GetSelectedLibrary()
int InvokePcbLibTableEditor(wxTopLevelWindow *aCaller, FP_LIB_TABLE *aGlobal, FP_LIB_TABLE *aProject)
Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing two lib ...
The common library.
wxAuiToolBar * m_mainToolBar
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
void OnFilterFPbyPinCount(wxUpdateUIEvent &event)
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
const wxString & GetKeywords()
virtual void ReCreateMenuBar() override
(Re)Create the menubar for the CvPcb mainframe
void BuildFOOTPRINTS_LISTBOX()
const wxString GetSelectedFootprint()
void OnQuit(wxCommandEvent &event)
wxString OnGetItemText(long item, long column) const override
Function OnGetItemText this overloaded function MUST be provided for the wxLC_VIRTUAL mode because re...
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project&#39;s fp-lib-table, i.e.
Definition: project.cpp:118
EDA_PANEINFO & InfoToolbarPane()
Function InfoToolbarPane Change *this to a information panel for for KiCad.
LIBRARY_LISTBOX * m_libListBox
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
void SetSelection(int index, bool State=true)
void OnKeepOpenOnSave(wxCommandEvent &event)
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
const std::string & GetPayload()
Function Payload returns the payload, which can be any text but it typicall self identifying s-expres...
Definition: kiway_express.h:62
void OnFilterFPbyKeyName(wxUpdateUIEvent &event)
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:256
void OnCloseWindow(wxCloseEvent &Event)
#define CMP_FORMAT
Definition: cvpcb.h:30
wxArrayString m_ComponentList
Definition: listboxes.h:199
void RedrawScreen(const wxPoint &aCenterPoint, bool aWarpPointer)
Function RedrawScreen redraws the entire screen area by updating the scroll bars and mouse pointer in...
Definition: zoom.cpp:46
void InitDisplay()
Function InitDisplay Refresh the full display for this frame: Set the title, the status line and redr...
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:241
int DisplayExitDialog(wxWindow *parent, const wxString &aMessage)
Function DisplayExitDialog displays a dialog with 3 buttons: Save and Exit Cancel Exit without save...
Definition: confirm.cpp:229
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
see class PGM_BASE
DISPLAY_FOOTPRINTS_FRAME * GetFootprintViewerFrame()
bool ReadNetListAndFpFiles(const std::string &aNetlist)
Function ReadNetListAndFpFiles loads the netlist file built on the fly by Eeschema and loads footprin...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
VTBL_ENTRY void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, const std::string &aPayload, wxWindow *aSource=NULL)
Function ExpressMail send aPayload to aDestination from aSource.
Definition: kiway.cpp:386
KICAD_MANAGER_FRAME::language_change KICAD_MANAGER_FRAME::OnChangeIconsOptions EVT_UPDATE_UI(ID_SELECT_PREFERED_PDF_BROWSER, KICAD_MANAGER_FRAME::OnUpdatePreferredPdfBrowser) EVT_UPDATE_UI_RANGE(ID_TO_SCH
CVPCB_MAINFRAME(KIWAY *aKiway, wxWindow *aParent)
const char * c_str() const
Definition: utf8.h:107
COMPONENT * GetSelectedComponent()
FOOTPRINTS_LISTBOX * m_footprintListBox
UTF8 Format() const
Definition: lib_id.cpp:263
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void SetFootprints(FOOTPRINT_LIST &aList, const wxString &aLibName, COMPONENT *aComponent, const wxString &aFootPrintFilterPattern, int aFilterType)
Function SetFootprints populates the wxListCtrl with the footprints from aList that meet the filter c...
PCB<->SCH, CVPCB->SCH cross-probing.
Definition: mail_type.h:39
void OnConfigurePaths(wxCommandEvent &aEvent)
#define DBG(x)
Definition: fctsys.h:33
void OnEnterFilteringText(wxCommandEvent &event)
Function OnEnterFilteringText Is called each time the text of m_tcFilterString is changed...
MAIL_T Command()
Function Command returns the MAIL_T associated with this mail.
Definition: kiway_express.h:52
void SaveFootprintAssociation()
Function SaveFootprintAssociation saves the edits that the user has done by sending them back to eesc...
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:247
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
void OnFilterFPbyLibrary(wxUpdateUIEvent &event)
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:289
void DisplayStatus()
Function DisplayStatus updates the information displayed on the status bar at bottom of the main fram...
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
The CvPcb application main window.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE...
void DisplayModule(wxCommandEvent &event)
EESCHEMA->CVPCB netlist immediately after launching CVPCB.
Definition: mail_type.h:41
std::unique_ptr< FOOTPRINT_LIST > m_FootprintsList