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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2017 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>
45 
46 #include <cvpcb_mainframe.h>
47 #include <cvpcb.h>
48 #include <listview_classes.h>
49 #include <invoke_pcb_dialog.h>
51 #include <cvpcb_id.h>
52 
53 
54 #define FRAME_MIN_SIZE_X 450
55 #define FRAME_MIN_SIZE_Y 300
56 
57 
60 
62 static const wxString KeepCvpcbOpenEntry = "KeepCvpcbOpen";
63 
64 static const wxString FootprintDocFileEntry = "footprints_doc_file";
65 
66 static const wxString FilterFootprintEntry = "FilterFootprint";
68 
69 BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER )
70 
71  // Menu events
72  EVT_MENU( wxID_SAVE, CVPCB_MAINFRAME::SaveQuitCvpcb )
73  EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit )
74  EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp )
75  EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout )
79 
80  // Toolbar events
82 
83  EVT_TOOL( ID_CVPCB_LIB_TABLE_EDIT, CVPCB_MAINFRAME::OnEditFootprintLibraryTable )
88  EVT_TOOL( ID_CVPCB_AUTO_ASSOCIE, CVPCB_MAINFRAME::AutomaticFootprintMatching )
90  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
92  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
94  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
96  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
97  EVT_TEXT( ID_CVPCB_FILTER_TEXT_EDIT, CVPCB_MAINFRAME::OnEnterFilteringText )
98 
99  // Frame events
100  EVT_CLOSE( CVPCB_MAINFRAME::OnCloseWindow )
101  EVT_SIZE( CVPCB_MAINFRAME::OnSize )
102 
103  // UI event handlers
104  EVT_UPDATE_UI( ID_CVPCB_CONFIG_KEEP_OPEN_ON_SAVE, CVPCB_MAINFRAME::OnUpdateKeepOpenOnSave )
105  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyKeywords)
106  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyPinCount )
107  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, CVPCB_MAINFRAME::OnFilterFPbyLibrary )
108  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, CVPCB_MAINFRAME::OnFilterFPbyKeyName )
109 
110 END_EVENT_TABLE()
111 
112 
113 #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
114 
115 
116 CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
117  KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, wxT( "CvPCB" ), wxDefaultPosition,
119 {
120  m_compListBox = NULL;
121  m_footprintListBox = NULL;
122  m_libListBox = NULL;
123  m_mainToolBar = NULL;
124  m_modified = false;
125  m_keepCvpcbOpen = false;
127  m_skipComponentSelect = false;
128  m_filteringOptions = 0;
129  m_tcFilterString = NULL;
131 
132  /* Name of the document footprint list
133  * usually located in share/modules/footprints_doc
134  * this is of the responsibility to users to create this file
135  * if they want to have a list of footprints
136  */
138 
139  // Give an icon
140  wxIcon icon;
141  icon.CopyFromBitmap( KiBitmap( icon_cvpcb_xpm ) );
142  SetIcon( icon );
143 
144  SetAutoLayout( true );
145 
146  LoadSettings( config() );
147 
148  if( m_FrameSize.x < FRAME_MIN_SIZE_X )
150 
151  if( m_FrameSize.y < FRAME_MIN_SIZE_Y )
153 
154  // Set minimal frame width and height
155  SetSizeHints( FRAME_MIN_SIZE_X, FRAME_MIN_SIZE_Y, -1, -1, -1, -1 );
156 
157  // Frame size and position
158  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
159 
160  // create the status bar
161  static const int dims[3] = { -1, -1, 250 };
162 
163  CreateStatusBar( 3 );
164  SetStatusWidths( 3, dims );
165 
166  ReCreateMenuBar();
168 
169  // Create list of available modules and components of the schematic
170  BuildCmpListBox();
173 
174  m_auimgr.SetManagedWindow( this );
175 
176  UpdateTitle();
177 
178  EDA_PANEINFO horiz;
179  horiz.HorizontalToolbarPane();
180 
181  EDA_PANEINFO info;
182  info.InfoToolbarPane();
183 
184 
185  if( m_mainToolBar )
186  m_auimgr.AddPane( m_mainToolBar,
187  wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top() );
188 
189  if( m_compListBox )
190  m_auimgr.AddPane( m_compListBox,
191  wxAuiPaneInfo( horiz ).Name( wxT( "m_compListBox" ) ).CentrePane() );
192 
193  if( m_libListBox)
194  m_auimgr.AddPane( m_libListBox,
195  wxAuiPaneInfo( info ).Name( wxT( "m_libListBox" ) ).
196  Left().BestSize( (int) ( m_FrameSize.x * 0.20 ), m_FrameSize.y ) );
197 
198  if( m_footprintListBox )
199  m_auimgr.AddPane( m_footprintListBox,
200  wxAuiPaneInfo( info ).Name( wxT( "m_footprintListBox" ) ).
201  Right().BestSize( (int) ( m_FrameSize.x * 0.30 ), m_FrameSize.y ) );
202 
203  m_auimgr.Update();
204 }
205 
206 
208 {
209  m_auimgr.UnInit();
210 }
211 
212 
213 void CVPCB_MAINFRAME::LoadSettings( wxConfigBase* aCfg )
214 {
216 
217  aCfg->Read( KeepCvpcbOpenEntry, &m_keepCvpcbOpen, true );
221 }
222 
223 
224 void CVPCB_MAINFRAME::SaveSettings( wxConfigBase* aCfg )
225 {
227 
228  aCfg->Write( KeepCvpcbOpenEntry, m_keepCvpcbOpen );
231 }
232 
233 
234 void CVPCB_MAINFRAME::OnSize( wxSizeEvent& event )
235 {
236  event.Skip();
237 }
238 
239 
240 void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event )
241 {
242  Close( false );
243 }
244 
245 
246 void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
247 {
248  if( m_modified )
249  {
250  wxString msg = _( "Component to Footprint links modified.\nSave before exit ?" );
251  int ii = DisplayExitDialog( this, msg );
252 
253  switch( ii )
254  {
255  case wxID_CANCEL:
256  Event.Veto();
257  return;
258 
259  case wxID_NO:
260  break;
261 
262  case wxID_YES:
264  break;
265  }
266  }
267 
268  // Close module display frame
270  GetFootprintViewerFrame()->Close( true );
271 
272  m_modified = false;
273 
274  Destroy();
275  return;
276 }
277 
278 
279 void CVPCB_MAINFRAME::ChangeFocus( bool aMoveRight )
280 {
281  wxWindow* hasFocus = wxWindow::FindFocus();
282 
283  if( aMoveRight )
284  {
285  if( hasFocus == m_libListBox )
286  m_compListBox->SetFocus();
287  else if( hasFocus == m_compListBox )
288  m_footprintListBox->SetFocus();
289  else if( hasFocus == m_footprintListBox )
290  m_libListBox->SetFocus();
291  }
292  else
293  {
294  if( hasFocus == m_libListBox )
295  m_footprintListBox->SetFocus();
296  else if( hasFocus == m_compListBox )
297  m_libListBox->SetFocus();
298  else if( hasFocus == m_footprintListBox )
299  m_compListBox->SetFocus();
300  }
301 }
302 
303 
304 void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event )
305 {
306  if( m_netlist.IsEmpty() )
307  return;
308 
309  long first_selected = m_compListBox->GetFirstSelected();
310 
311  if( first_selected < 0 )
312  first_selected = -1; // We will start to 0 for the first search , if no item selected
313 
314  int candidate = -1;
315 
316  for( unsigned jj = first_selected+1; jj < m_netlist.GetCount(); jj++ )
317  {
318  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
319  {
320  candidate = jj;
321  break;
322  }
323  }
324 
325  if( candidate >= 0 )
326  {
328  m_compListBox->SetSelection( candidate );
330  }
331 }
332 
333 
334 void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
335 {
336  if( m_netlist.IsEmpty() )
337  return;
338 
339  int first_selected = m_compListBox->GetFirstSelected();
340 
341  if( first_selected < 0 )
342  first_selected = m_compListBox->GetCount();
343 
344  int candidate = -1;
345 
346  for( int jj = first_selected-1; jj >= 0; jj-- )
347  {
348  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
349  {
350  candidate = jj;
351  break;
352  }
353  }
354 
355  if( candidate >= 0 )
356  {
358  m_compListBox->SetSelection( candidate );
360  }
361 }
362 
363 
364 void CVPCB_MAINFRAME::SaveQuitCvpcb( wxCommandEvent& aEvent )
365 {
367 
368  m_modified = false;
369 
370  if( !m_keepCvpcbOpen )
371  Close( true );
372 }
373 
374 
375 void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event )
376 {
377  if( IsOK( this, _( "Delete selections" ) ) )
378  {
379  m_skipComponentSelect = true;
380 
381  // Remove all selections to avoid issues when setting the fpids
383 
384  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
385  {
386  LIB_ID fpid;
387 
388  m_netlist.GetComponent( i )->SetFPID( fpid );
389  SetNewPkg( wxEmptyString );
390  }
391 
392  // Remove all selections after setting the fpids
394 
395  m_skipComponentSelect = false;
398  }
399 
400  DisplayStatus();
401 }
402 
403 
404 bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
405 {
406  return true;
407 }
408 
409 
410 void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent )
411 {
412  bool tableChanged = false;
413  int r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs( Kiway() ) );
414 
415  if( r & 1 )
416  {
417  wxString fileName = FP_LIB_TABLE::GetGlobalTableFileName();
418 
419  try
420  {
421  GFootprintTable.Save( fileName );
422  tableChanged = true;
423  }
424  catch( const IO_ERROR& ioe )
425  {
426  wxString msg = wxString::Format(
427  _( "Error occurred saving the global footprint library table:\n'%s'\n%s" ),
428  GetChars( fileName ),
429  GetChars( ioe.What() )
430  );
431  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
432  }
433  }
434 
435  if( r & 2 )
436  {
437  wxString fileName = Prj().FootprintLibTblName();
438 
439  try
440  {
441  Prj().PcbFootprintLibs( Kiway() )->Save( fileName );
442  tableChanged = true;
443  }
444  catch( const IO_ERROR& ioe )
445  {
446  wxString msg = wxString::Format(
447  _( "Error occurred saving the project footprint library table:\n'%s'\n%s" ),
448  GetChars( fileName ),
449  GetChars( ioe.What() )
450  );
451  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
452  }
453  }
454 
455  if( tableChanged )
456  {
457  wxBusyCursor dummy;
459  m_FootprintsList->ReadFootprintFiles( Prj().PcbFootprintLibs( Kiway() ) );
460  }
461 }
462 
463 
464 void CVPCB_MAINFRAME::OnKeepOpenOnSave( wxCommandEvent& event )
465 {
466  m_keepCvpcbOpen = event.IsChecked();
467 }
468 
469 
470 void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event )
471 {
472  CreateScreenCmp();
473  GetFootprintViewerFrame()->RedrawScreen( wxPoint( 0, 0 ), false );
474 }
475 
476 
477 void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
478 {
480  return;
481 
482  wxString libraryName;
483  COMPONENT* component = GetSelectedComponent();
484  libraryName = m_libListBox->GetSelectedLibrary();
485 
486  m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
488 
489  refreshAfterComponentSearch (component);
490 }
491 
492 
494 {
495  // Tell AuiMgr that objects are changed !
496  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
497  // (could be not the case when starting CvPcb
498  m_auimgr.Update();
499 
500  if( component == NULL )
501  return;
502 
503  // Preview of the already assigned footprint.
504  // Find the footprint that was already chosen for this component and select it,
505  // but only if the selection is made from the component list or the library list.
506  // If the selection is made from the footprint list, do not change the current
507  // selected footprint.
508  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
509  {
510  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
511 
512  bool found = false;
513 
514  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
515  {
516  wxString footprintName;
517  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
518  msg.Trim( true );
519  msg.Trim( false );
520  footprintName = msg.AfterFirst( wxChar( ' ' ) );
521 
522  if( module.Cmp( footprintName ) == 0 )
523  {
524  m_footprintListBox->SetSelection( ii, true );
525  found = true;
526  break;
527  }
528  }
529 
530  if( !found )
531  {
532  int ii = m_footprintListBox->GetSelection();
533 
534  if ( ii >= 0 )
535  m_footprintListBox->SetSelection( ii, false );
536 
538  {
539  CreateScreenCmp();
540  }
541  }
542  }
543 
545  DisplayStatus();
546 }
547 
548 void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
549 {
550  int option = 0;
551 
552  switch( event.GetId() )
553  {
554  case ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST:
556  break;
557 
558  case ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST:
560  break;
561 
562  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST:
564  break;
565 
566  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME:
569  break;
570  }
571 
572  if( event.IsChecked() )
573  m_filteringOptions |= option;
574  else
575  m_filteringOptions &= ~option;
576 
577  wxListEvent l_event;
578  OnSelectComponent( l_event );
579 }
580 
581 
582 void CVPCB_MAINFRAME::OnUpdateKeepOpenOnSave( wxUpdateUIEvent& event )
583 {
584  event.Check( m_keepCvpcbOpen );
585 }
586 
587 
588 void CVPCB_MAINFRAME::OnFilterFPbyKeywords( wxUpdateUIEvent& event )
589 {
591 }
592 
593 
594 void CVPCB_MAINFRAME::OnFilterFPbyPinCount( wxUpdateUIEvent& event )
595 {
597 }
598 
599 
600 void CVPCB_MAINFRAME::OnFilterFPbyLibrary( wxUpdateUIEvent& event )
601 {
603 }
604 
605 
606 void CVPCB_MAINFRAME::OnFilterFPbyKeyName( wxUpdateUIEvent& event )
607 {
609 }
610 
611 
612 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
613 {
614  // Called when changing the filter string in main toolbar.
615  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
616  // available footprints which match the filter
617 
619 
621  return;
622 
623  OnSelectFilteringFootprint( aEvent );
624 }
625 
626 
628 {
629  wxString msg;
630  COMPONENT* component;
631 
632  if( wxWindow::FindFocus() == m_compListBox || wxWindow::FindFocus() == m_libListBox )
633  {
634  msg.Printf( _( "Components: %d, unassigned: %d" ), (int) m_netlist.GetCount(),
636  SetStatusText( msg, 0 );
637 
638  msg.Empty();
639 
640  component = GetSelectedComponent();
641 
642  if( component )
643  {
644  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
645  {
646  if( msg.IsEmpty() )
647  msg += component->GetFootprintFilters()[ii];
648  else
649  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
650  }
651 
652  msg = _( "Filter list: " ) + msg;
653  }
654 
655  SetStatusText( msg, 1 );
656  }
657  else
658  {
659  wxString footprintName = GetSelectedFootprint();
660 
661  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
662 
663  if( module ) // can be NULL if no netlist loaded
664  {
665  msg = _( "Description: " ) + module->GetDoc();
666  SetStatusText( msg, 0 );
667 
668  msg = _( "Key words: " ) + module->GetKeywords();
669  SetStatusText( msg, 1 );
670  }
671  }
672 
673  msg.Empty();
674  wxString filters;
675 
676  if( m_footprintListBox )
677  {
679  filters = _( "key words" );
680 
682  {
683  if( !filters.IsEmpty() )
684  filters += wxT( "+" );
685 
686  filters += _( "pin count" );
687  }
688 
690  {
691  if( !filters.IsEmpty() )
692  filters += wxT( "+" );
693 
694  filters += _( "library" );
695  }
696 
698  {
699  if( !filters.IsEmpty() )
700  filters += wxT( "+" );
701 
702  filters += _( "name" );
703  }
704 
705  if( filters.IsEmpty() )
706  msg = _( "No filtering" );
707  else
708  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
709 
710  msg << wxT( ": " ) << m_footprintListBox->GetCount();
711 
712  SetStatusText( msg, 2 );
713  }
714 }
715 
716 
718 {
719  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
720 
721  // Check if there are footprint libraries in the footprint library table.
722  if( !fptbl || !fptbl->GetLogicalLibs().size() )
723  {
724  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
725  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
726  return false;
727  }
728 
729  {
730  wxBusyCursor dummy; // Let the user know something is happening.
731 
732  m_FootprintsList->ReadFootprintFiles( fptbl );
733  }
734 
735  if( m_FootprintsList->GetErrorCount() )
736  {
737  m_FootprintsList->DisplayErrors( this );
738  }
739 
740  return true;
741 }
742 
743 
745 {
746  wxString title;
747  PROJECT& prj = Prj();
748  wxFileName fn = prj.GetProjectFullName();
749 
750  if( fn.IsOk() && !prj.GetProjectFullName().IsEmpty() && fn.FileExists() )
751  {
752  title.Printf( L"Cvpcb \u2014 %s%s",
753  fn.GetFullPath(),
754  fn.IsFileWritable()
755  ? wxString( wxEmptyString )
756  : _( " [Read Only]" ) );
757  }
758  else
759  {
760  title = "Cvpcb";
761  }
762 
763  SetTitle( title );
764 }
765 
766 
768 {
769  if( m_netlist.IsEmpty() )
770  return;
771 
772  int selection = m_compListBox->GetSelection();
773 
774  if ( selection < 0 )
775  selection = 0;
776 
777  if( m_netlist.GetComponent( selection ) == NULL )
778  return;
779 
780  COMPONENT* component = m_netlist.GetComponent( selection );
781 
782  std::string packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
783 
784  if( Kiface().IsSingle() )
785  SendCommand( MSG_TO_SCH, packet.c_str() );
786  else
787  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
788 }
789 
790 
791 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
792 {
793  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
794  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
795 
796  m_netlist.Clear();
797 
798  try
799  {
800  netrdr.LoadNetlist();
801  }
802  catch( const IO_ERROR& ioe )
803  {
804  wxString msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.What().GetData() );
805  wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
806  return 1;
807  }
808 
809  // We also remove footprint name if it is "$noname" because this is a dummy name,
810  // not the actual name of the footprint.
811  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
812  {
813  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
814  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
815  }
816 
817  // Sort components by reference:
819 
820  return 0;
821 }
822 
823 
825 {
827 
828  if( !fpframe )
829  {
830  fpframe = new DISPLAY_FOOTPRINTS_FRAME( &Kiway(), this );
831  fpframe->Show( true );
832  }
833  else
834  {
835  if( fpframe->IsIconized() )
836  fpframe->Iconize( false );
837 
838  // The display footprint window might be buried under some other
839  // windows, so CreateScreenCmp() on an existing window would not
840  // show any difference, leaving the user confused.
841  // So we want to put it to front, second after our CVPCB_MAINFRAME.
842  // We do this by a little dance of bringing it to front then the main
843  // frame back.
844  fpframe->Raise(); // Make sure that is visible.
845  Raise(); // .. but still we want the focus.
846  }
847 
848  fpframe->InitDisplay();
849 }
850 
851 
853 {
854  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
855 
856  if( m_footprintListBox == NULL )
857  {
859  wxDefaultPosition, wxDefaultSize );
860  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(),
861  wxFONTFAMILY_MODERN,
862  wxFONTSTYLE_NORMAL,
863  wxFONTWEIGHT_NORMAL ) );
864  }
865 
866  m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL,
868  DisplayStatus();
869 }
870 
871 
873 {
874  wxString msg;
875  COMPONENT* component;
876  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
877 
878  if( m_compListBox == NULL )
879  {
881  wxDefaultPosition, wxDefaultSize );
882  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(),
883  wxFONTFAMILY_MODERN,
884  wxFONTSTYLE_NORMAL,
885  wxFONTWEIGHT_NORMAL ) );
886  }
887 
889 
890  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
891  {
892  component = m_netlist.GetComponent( i );
893 
894  msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1,
895  GetChars( component->GetReference() ),
896  GetChars( component->GetValue() ),
897  GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
898  m_compListBox->m_ComponentList.Add( msg );
899  }
900 
901  if( m_compListBox->m_ComponentList.Count() )
902  {
903  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
904  m_compListBox->SetSelection( 0, true );
905  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
907  }
908 }
909 
910 
912 {
913  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
914 
915  if( m_libListBox == NULL )
916  {
918  wxDefaultPosition, wxDefaultSize );
919  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(),
920  wxFONTFAMILY_MODERN,
921  wxFONTSTYLE_NORMAL,
922  wxFONTWEIGHT_NORMAL ) );
923  }
924 
925  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
926 
927  if( tbl )
928  {
929  wxArrayString libNames;
930 
931  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
932 
933  for( unsigned ii = 0; ii < libNickNames.size(); ii++ )
934  libNames.Add( libNickNames[ii] );
935 
936  m_libListBox->SetLibraryList( libNames );
937  }
938 }
939 
940 
942 {
943  int selection = m_compListBox->GetSelection();
944 
945  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
946  return m_netlist.GetComponent( selection );
947 
948  return NULL;
949 }
950 
951 
953 {
954  // returns the Footprint Viewer frame, if exists, or NULL
955  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
956  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
957 }
958 
960 {
961  // returns the LIB_ID of the selected footprint in footprint listview
962  // or a empty string
964 }
965 
966 
967 void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
968 {
969  Pgm().ConfigurePaths( this );
970 }
971 
972 
974 {
975  const std::string& payload = mail.GetPayload();
976 
977  DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
978 
979  switch( mail.Command() )
980  {
982  ReadNetListAndFpFiles( payload );
983  /* @todo
984  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
985  */
986  break;
987 
988  default:
989  ; // ignore most
990  }
991 }
void OnUpdateKeepOpenOnSave(wxUpdateUIEvent &event)
EDA_PANEINFO & HorizontalToolbarPane()
Function HorizontalToolbarPane Change *this to a horizontal toolbar for KiCad.
Definition: wxstruct.h:487
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...
#define KICAD_DEFAULT_DRAWFRAME_STYLE
Definition: wxstruct.h:55
wxString m_DocModulesFileName
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
Function empty.
Definition: lib_id.h:198
#define FRAME_MIN_SIZE_Y
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.
#define FOOTPRINTVIEWER_FRAME_NAME
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.
Definition: listboxes.cpp:112
#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. ...
Definition: basicframe.cpp:335
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...
static const wxString FootprintDocFileEntry
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
void OnFilterFPbyKeywords(wxUpdateUIEvent &event)
void UpdateTitle()
Function UpdateTitle sets the main window title bar text.
void ReCreateHToolbar()
Definition: tool_cvpcb.cpp:42
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...
Definition: basicframe.cpp:380
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
Definition: wxstruct.h:149
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:235
Class LIB_ID.
Definition: lib_id.h:56
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.
Definition: wxstruct.h:478
void CreateScreenCmp()
Create or Update the frame showing the current highlighted footprint and (if showed) the 3D display f...
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:311
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:75
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:36
wxTextCtrl * m_tcFilterString
void OnSelectComponent(wxListEvent &event)
Function OnSelectComponent Called when clicking on a component in component list window.
#define DEFAULT_FOOTPRINTS_LIST_FILENAME
Definition: cvpcb.h:29
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 iff cvpcb should be kept open after saving files.
const wxString & GetDoc()
void UpdateWidth(int aLine=-1)
Definition: listboxes.cpp:58
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
virtual void LoadSettings(wxConfigBase *aCfg)
Function LoadSettings loads common frame parameters from a configuration file.
Definition: basicframe.cpp:275
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.
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:257
void OnFilterFPbyPinCount(wxUpdateUIEvent &event)
void Save(const wxString &aFileName) const
Function Save.
wxPoint m_FramePos
Definition: wxstruct.h:139
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's fp-lib-table, i.e.
Definition: project.cpp:114
EDA_PANEINFO & InfoToolbarPane()
Function InfoToolbarPane Change *this to a information panel for for KiCad.
Definition: wxstruct.h:552
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:32
wxArrayString m_ComponentList
#define FRAME_MIN_SIZE_X
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:59
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:387
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
Function Format.
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...
wxSize m_FrameSize
Definition: wxstruct.h:140
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:129
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()
Function GetLogicalLibs.
void DisplayModule(wxCommandEvent &event)
EESCHEMA->CVPCB netlist immediately after launching CVPCB.
Definition: mail_type.h:41
std::unique_ptr< FOOTPRINT_LIST > m_FootprintsList