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 <kiface_ids.h>
36 #include <macros.h>
37 #include <confirm.h>
38 #include <eda_dde.h>
39 #include <html_messagebox.h>
40 #include <fp_lib_table.h>
41 #include <netlist_reader.h>
42 #include <bitmaps.h>
44 
45 #include <cvpcb_mainframe.h>
46 #include <cvpcb.h>
47 #include <listboxes.h>
48 #include <invoke_pcb_dialog.h>
50 #include <cvpcb_id.h>
51 
52 wxSize const FRAME_MIN_SIZE_DU( 350, 250 );
53 wxSize const FRAME_DEFAULT_SIZE_DU( 450, 300 );
54 
57 
58 static const wxString FilterFootprintEntry = "FilterFootprint";
60 
61 BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER )
62 
63  // Menu events
64  EVT_MENU( wxID_SAVE, CVPCB_MAINFRAME::OnSaveAndContinue )
65  EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit )
66  EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp )
67  EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout )
70 
71  // Toolbar events
72  EVT_TOOL( ID_CVPCB_LIB_TABLE_EDIT, CVPCB_MAINFRAME::OnEditFootprintLibraryTable )
77  EVT_TOOL( ID_CVPCB_AUTO_ASSOCIE, CVPCB_MAINFRAME::AutomaticFootprintMatching )
79  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
81  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
83  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
85  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
86  EVT_TEXT( ID_CVPCB_FILTER_TEXT_EDIT, CVPCB_MAINFRAME::OnEnterFilteringText )
87 
88  // Button events
89  EVT_BUTTON( wxID_OK, CVPCB_MAINFRAME::OnOK )
90  EVT_BUTTON( wxID_CANCEL, CVPCB_MAINFRAME::OnCancel )
91 
92  // Frame events
93  EVT_CLOSE( CVPCB_MAINFRAME::OnCloseWindow )
94  EVT_SIZE( CVPCB_MAINFRAME::OnSize )
95 
96  // UI event handlers
97  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyKeywords)
98  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyPinCount )
99  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, CVPCB_MAINFRAME::OnFilterFPbyLibrary )
100  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, CVPCB_MAINFRAME::OnFilterFPbyKeyName )
101 
102 END_EVENT_TABLE()
103 
104 
105 #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
106 
107 
108 CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
109  KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, _( "Assign Footprints" ), wxDefaultPosition,
111 {
112  m_compListBox = NULL;
113  m_footprintListBox = NULL;
114  m_libListBox = NULL;
115  m_mainToolBar = NULL;
116  m_modified = false;
117  m_skipComponentSelect = false;
118  m_filteringOptions = 0;
119  m_tcFilterString = NULL;
121  m_initialized = false;
122 
123  // Give an icon
124  wxIcon icon;
125  icon.CopyFromBitmap( KiBitmap( icon_cvpcb_xpm ) );
126  SetIcon( icon );
127 
128  SetAutoLayout( true );
129 
130  LoadSettings( config() );
131 
132  wxSize const frame_min( ConvertDialogToPixels( FRAME_MIN_SIZE_DU ) );
133 
134  SetSizeHints( frame_min );
135 
136  // Frame size and position
137  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
138 
139  ReCreateMenuBar();
141 
142  // Create list of available modules and components of the schematic
143  BuildCmpListBox();
146 
147  m_auimgr.SetManagedWindow( this );
148 
149  EDA_PANEINFO horiz;
150  horiz.HorizontalToolbarPane();
151 
152  EDA_PANEINFO info;
153  info.InfoToolbarPane();
154 
155  if( m_mainToolBar )
156  m_auimgr.AddPane( m_mainToolBar,
157  wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top() );
158 
159  if( m_compListBox )
160  m_auimgr.AddPane( m_compListBox,
161  wxAuiPaneInfo( horiz ).Name( wxT( "m_compListBox" ) ).CentrePane() );
162 
163  if( m_libListBox)
164  m_auimgr.AddPane( m_libListBox,
165  wxAuiPaneInfo( info ).Name( wxT( "m_libListBox" ) ).
166  Left().BestSize( (int) ( m_FrameSize.x * 0.20 ), m_FrameSize.y ) );
167 
168  if( m_footprintListBox )
169  m_auimgr.AddPane( m_footprintListBox,
170  wxAuiPaneInfo( info ).Name( wxT( "m_footprintListBox" ) ).
171  Right().BestSize( (int) ( m_FrameSize.x * 0.30 ), m_FrameSize.y ) );
172 
173  // Build the bottom panel, to display 2 status texts and the buttons:
174  auto bottomPanel = new wxPanel( this );
175  auto panelSizer = new wxBoxSizer( wxVERTICAL );
176  wxFont statusFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
177  statusFont.SetSymbolicSize( wxFONTSIZE_SMALL );
178 
179  m_statusLine1 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
180  m_statusLine1->SetFont( statusFont );
181  panelSizer->Add( m_statusLine1, 0, wxTOP, 4 );
182 
183  m_statusLine2 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
184  m_statusLine2->SetFont( statusFont );
185  panelSizer->Add( m_statusLine2, 0, 0, 4 );
186 
187  // Add buttons:
188  auto buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
189  auto sdbSizer = new wxStdDialogButtonSizer();
190 
191  m_saveAndContinue = new wxButton( bottomPanel, wxID_SAVE,
192  _( "Apply, Save Schematic && Continue" ) );
193  buttonsSizer->Add( m_saveAndContinue, 0, wxALIGN_BOTTOM | wxBOTTOM | wxRIGHT, 10 );
194 
195  auto sdbSizerOK = new wxButton( bottomPanel, wxID_OK );
196  sdbSizer->AddButton( sdbSizerOK );
197  auto sdbSizerCancel = new wxButton( bottomPanel, wxID_CANCEL );
198  sdbSizer->AddButton( sdbSizerCancel );
199  sdbSizer->Realize();
200 
201  buttonsSizer->Add( sdbSizer, 0, 0, 5 );
202  panelSizer->Add( buttonsSizer, 0, wxALIGN_RIGHT, 5 );
203 
204  bottomPanel->SetSizer( panelSizer );
205  bottomPanel->Fit();
206 
207  sdbSizerOK->SetDefault();
208 
209  m_auimgr.AddPane( bottomPanel, wxAuiPaneInfo( horiz ).Name( wxT( "buttons" ) ).Bottom() );
210 
211  m_auimgr.Update();
212  m_initialized = true;
213 
214  // Connect Events
215  m_saveAndContinue->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CVPCB_MAINFRAME::OnSaveAndContinue ), NULL, this );
216 }
217 
218 
220 {
221  // Disconnect Events
222  m_saveAndContinue->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CVPCB_MAINFRAME::OnSaveAndContinue ), NULL, this );
223 
224  m_auimgr.UnInit();
225 }
226 
227 
228 void CVPCB_MAINFRAME::LoadSettings( wxConfigBase* aCfg )
229 {
231 
232  wxSize const frame_default( ConvertDialogToPixels( FRAME_DEFAULT_SIZE_DU ) );
233 
234  if( m_FrameSize == wxDefaultSize )
235  m_FrameSize = frame_default;
236 
238 }
239 
240 
241 void CVPCB_MAINFRAME::SaveSettings( wxConfigBase* aCfg )
242 {
244 
246 }
247 
248 
249 void CVPCB_MAINFRAME::OnSize( wxSizeEvent& event )
250 {
251  event.Skip();
252 }
253 
254 
255 void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
256 {
257  if( m_modified )
258  {
259  wxString msg = _( "Component to Footprint links modified.\nSave before exit?" );
260  int ii = DisplayExitDialog( this, msg );
261 
262  switch( ii )
263  {
264  case wxID_CANCEL:
265  Event.Veto();
266  return;
267 
268  case wxID_NO:
269  break;
270 
271  case wxID_YES:
272  SaveFootprintAssociation( false );
273  break;
274  }
275  }
276 
277  // Close module display frame
279  GetFootprintViewerFrame()->Close( true );
280 
281  m_modified = false;
282 
283  Destroy();
284 }
285 
286 
287 void CVPCB_MAINFRAME::ChangeFocus( bool aMoveRight )
288 {
289  wxWindow* hasFocus = wxWindow::FindFocus();
290 
291  if( aMoveRight )
292  {
293  if( hasFocus == m_libListBox )
294  m_compListBox->SetFocus();
295  else if( hasFocus == m_compListBox )
296  m_footprintListBox->SetFocus();
297  else if( hasFocus == m_footprintListBox )
298  m_libListBox->SetFocus();
299  }
300  else
301  {
302  if( hasFocus == m_libListBox )
303  m_footprintListBox->SetFocus();
304  else if( hasFocus == m_compListBox )
305  m_libListBox->SetFocus();
306  else if( hasFocus == m_footprintListBox )
307  m_compListBox->SetFocus();
308  }
309 }
310 
311 
312 void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event )
313 {
314  if( m_netlist.IsEmpty() )
315  return;
316 
317  int first_selected = m_compListBox->GetFirstSelected();
318 
319  if( first_selected < 0 )
320  first_selected = -1; // We will start to 0 for the first search , if no item selected
321 
322  int candidate = -1;
323 
324  for( int jj = first_selected+1; jj < (int)m_netlist.GetCount(); jj++ )
325  {
326  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
327  {
328  candidate = jj;
329  break;
330  }
331  }
332 
333  if( candidate >= 0 )
334  {
336  m_compListBox->SetSelection( candidate );
338  }
339 }
340 
341 
342 void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
343 {
344  if( m_netlist.IsEmpty() )
345  return;
346 
347  int first_selected = m_compListBox->GetFirstSelected();
348 
349  if( first_selected < 0 )
350  first_selected = m_compListBox->GetCount();
351 
352  int candidate = -1;
353 
354  for( int jj = first_selected-1; jj >= 0; jj-- )
355  {
356  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
357  {
358  candidate = jj;
359  break;
360  }
361  }
362 
363  if( candidate >= 0 )
364  {
366  m_compListBox->SetSelection( candidate );
368  }
369 }
370 
371 
372 void CVPCB_MAINFRAME::OnOK( wxCommandEvent& aEvent )
373 {
374  SaveFootprintAssociation( false );
375 
376  m_modified = false;
377 
378  Close( true );
379 }
380 
381 
382 void CVPCB_MAINFRAME::OnSaveAndContinue( wxCommandEvent& aEvent )
383 {
384  SaveFootprintAssociation( true );
385 
386  m_modified = false;
387 }
388 
389 
390 void CVPCB_MAINFRAME::OnCancel( wxCommandEvent& event )
391 {
392  // Throw away modifications on a Cancel
393  m_modified = false;
394 
395  Close( false );
396 }
397 
398 
399 void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event )
400 {
401  Close( false );
402 }
403 
404 
405 void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event )
406 {
407  if( IsOK( this, _( "Delete selections" ) ) )
408  {
409  m_skipComponentSelect = true;
410 
411  // Remove all selections to avoid issues when setting the fpids
413 
414  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
415  {
416  LIB_ID fpid;
417 
418  m_netlist.GetComponent( i )->SetFPID( fpid );
419  SetNewPkg( wxEmptyString );
420  }
421 
422  // Remove all selections after setting the fpids
424 
425  m_skipComponentSelect = false;
427  }
428 
429  DisplayStatus();
430 }
431 
432 
433 bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
434 {
435  return true;
436 }
437 
438 
439 void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent )
440 {
441  FP_LIB_TABLE* globalTable;
442  bool tableChanged = false;
444 
445  if( kiface )
446  globalTable = (FP_LIB_TABLE*) kiface->IfaceOrAddress( KIFACE_GLOBAL_FOOTPRINT_TABLE );
447  else
448  globalTable = &GFootprintTable; // Shouldn't happen now that Cvpcb is integrated
449 
450  int r = InvokePcbLibTableEditor( this, globalTable, Prj().PcbFootprintLibs( Kiway() ) );
451 
452  if( r & 1 )
453  {
454  wxString fileName = FP_LIB_TABLE::GetGlobalTableFileName();
455 
456  try
457  {
458  globalTable->Save( fileName );
459  tableChanged = true;
460  }
461  catch( const IO_ERROR& ioe )
462  {
463  wxString msg = wxString::Format(
464  _( "Error occurred saving the global footprint library table:\n\"%s\"\n%s" ),
465  GetChars( fileName ),
466  GetChars( ioe.What() )
467  );
468  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
469  }
470  }
471 
472  if( r & 2 )
473  {
474  wxString fileName = Prj().FootprintLibTblName();
475 
476  try
477  {
478  Prj().PcbFootprintLibs( Kiway() )->Save( fileName );
479  tableChanged = true;
480  }
481  catch( const IO_ERROR& ioe )
482  {
483  wxString msg = wxString::Format(
484  _( "Error occurred saving the project footprint library table:\n\"%s\"\n%s" ),
485  GetChars( fileName ),
486  GetChars( ioe.What() )
487  );
488  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
489  }
490  }
491 
492  if( tableChanged )
493  {
494  wxBusyCursor dummy;
496  m_FootprintsList->ReadFootprintFiles( Prj().PcbFootprintLibs( Kiway() ) );
497  }
498 }
499 
500 
501 void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event )
502 {
503  CreateScreenCmp();
504  GetFootprintViewerFrame()->RedrawScreen( wxPoint( 0, 0 ), false );
505 }
506 
507 
508 void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
509 {
511  return;
512 
513  wxString libraryName;
514  COMPONENT* component = GetSelectedComponent();
515  libraryName = m_libListBox->GetSelectedLibrary();
516 
517  m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
519 
520  refreshAfterComponentSearch (component);
521 }
522 
523 
525 {
526  // Tell AuiMgr that objects are changed !
527  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
528  // (could be not the case when starting CvPcb
529  m_auimgr.Update();
530 
531  if( component == NULL )
532  {
533  DisplayStatus();
534  return;
535  }
536 
537  // Preview of the already assigned footprint.
538  // Find the footprint that was already chosen for this component and select it,
539  // but only if the selection is made from the component list or the library list.
540  // If the selection is made from the footprint list, do not change the current
541  // selected footprint.
542  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
543  {
544  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
545 
546  bool found = false;
547 
548  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
549  {
550  wxString footprintName;
551  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
552  msg.Trim( true );
553  msg.Trim( false );
554  footprintName = msg.AfterFirst( wxChar( ' ' ) );
555 
556  if( module.Cmp( footprintName ) == 0 )
557  {
558  m_footprintListBox->SetSelection( ii, true );
559  found = true;
560  break;
561  }
562  }
563 
564  if( !found )
565  {
566  int ii = m_footprintListBox->GetSelection();
567 
568  if ( ii >= 0 )
569  m_footprintListBox->SetSelection( ii, false );
570 
572  {
573  CreateScreenCmp();
574  }
575  }
576  }
577 
579  DisplayStatus();
580 }
581 
582 void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
583 {
584  int option = 0;
585 
586  switch( event.GetId() )
587  {
588  case ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST:
590  break;
591 
592  case ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST:
594  break;
595 
596  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST:
598  break;
599 
600  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME:
603  break;
604  }
605 
606  if( event.IsChecked() )
607  m_filteringOptions |= option;
608  else
609  m_filteringOptions &= ~option;
610 
611  wxListEvent l_event;
612  OnSelectComponent( l_event );
613 }
614 
615 
616 void CVPCB_MAINFRAME::OnFilterFPbyKeywords( wxUpdateUIEvent& event )
617 {
619 }
620 
621 
622 void CVPCB_MAINFRAME::OnFilterFPbyPinCount( wxUpdateUIEvent& event )
623 {
625 }
626 
627 
628 void CVPCB_MAINFRAME::OnFilterFPbyLibrary( wxUpdateUIEvent& event )
629 {
631 }
632 
633 
634 void CVPCB_MAINFRAME::OnFilterFPbyKeyName( wxUpdateUIEvent& event )
635 {
637 }
638 
639 
640 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
641 {
642  // Called when changing the filter string in main toolbar.
643  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
644  // available footprints which match the filter
645 
647 
649  return;
650 
651  OnSelectFilteringFootprint( aEvent );
652 }
653 
654 
656 {
657  if( !m_initialized )
658  return;
659 
660  wxString filters, msg;
661  COMPONENT* component = GetSelectedComponent();
662 
664  {
665  msg.Empty();
666 
667  if( component )
668  {
669  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
670  {
671  if( msg.IsEmpty() )
672  msg += component->GetFootprintFilters()[ii];
673  else
674  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
675  }
676  }
677 
678  filters += _( "key words" ) + wxString::Format( wxT( " (%s)" ), msg );
679  }
680 
682  {
683  msg.Empty();
684 
685  if( component )
686  msg = wxString::Format( wxT( "%i" ), component->GetPinCount() );
687 
688  if( !filters.IsEmpty() )
689  filters += wxT( ", " );
690 
691  filters += _( "pin count" ) + wxString::Format( wxT( " (%s)" ), msg );
692  }
693 
695  {
697 
698  if( !filters.IsEmpty() )
699  filters += wxT( ", " );
700 
701  filters += _( "library" ) + wxString::Format( wxT( " (%s)" ), msg );
702  }
703 
705  {
706  if( !filters.IsEmpty() )
707  filters += wxT( ", " );
708 
709  filters += _( "search text" );
710  }
711 
712  if( filters.IsEmpty() )
713  msg = _( "No filtering" );
714  else
715  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
716 
717  msg << wxT( ": " ) << m_footprintListBox->GetCount();
718 
719  SetStatusText( msg );
720 
721 
722  msg.Empty();
723  wxString footprintName = GetSelectedFootprint();
724 
725  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
726 
727  if( module ) // can be NULL if no netlist loaded
728  {
729  msg = wxString::Format( _( "Description: %s; Key words: %s" ),
730  module->GetDoc(),
731  module->GetKeywords() );
732  }
733 
734  SetStatusText( msg, 1 );
735 }
736 
737 
739 {
740  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
741 
742  // Check if there are footprint libraries in the footprint library table.
743  if( !fptbl || !fptbl->GetLogicalLibs().size() )
744  {
745  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
746  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
747  return false;
748  }
749 
750  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
751 
752  m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
753 
755  {
757  }
758 
759  return true;
760 }
761 
762 
764 {
765  if( m_netlist.IsEmpty() )
766  return;
767 
768  int selection = m_compListBox->GetSelection();
769 
770  if ( selection < 0 )
771  selection = 0;
772 
773  if( m_netlist.GetComponent( selection ) == NULL )
774  return;
775 
776  COMPONENT* component = m_netlist.GetComponent( selection );
777 
778  std::string packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
779 
780  if( Kiface().IsSingle() )
781  SendCommand( MSG_TO_SCH, packet.c_str() );
782  else
783  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
784 }
785 
786 
787 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
788 {
789  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
790  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
791 
792  m_netlist.Clear();
793 
794  try
795  {
796  netrdr.LoadNetlist();
797  }
798  catch( const IO_ERROR& ioe )
799  {
800  wxString msg = wxString::Format( _( "Error loading schematic.\n%s" ), ioe.What().GetData() );
801  wxMessageBox( msg, _( "Load Error" ), wxOK | wxICON_ERROR );
802  return 1;
803  }
804 
805  // We also remove footprint name if it is "$noname" because this is a dummy name,
806  // not the actual name of the footprint.
807  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
808  {
809  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
810  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
811  }
812 
813  // Sort components by reference:
815 
816  return 0;
817 }
818 
819 
821 {
823 
824  if( !fpframe )
825  {
826  fpframe = new DISPLAY_FOOTPRINTS_FRAME( &Kiway(), this );
827  fpframe->Show( true );
828  }
829  else
830  {
831  if( fpframe->IsIconized() )
832  fpframe->Iconize( false );
833 
834  // The display footprint window might be buried under some other
835  // windows, so CreateScreenCmp() on an existing window would not
836  // show any difference, leaving the user confused.
837  // So we want to put it to front, second after our CVPCB_MAINFRAME.
838  // We do this by a little dance of bringing it to front then the main
839  // frame back.
840  fpframe->Raise(); // Make sure that is visible.
841  Raise(); // .. but still we want the focus.
842  }
843 
844  fpframe->InitDisplay();
845 }
846 
847 
849 {
850  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
851 
852  if( m_footprintListBox == NULL )
853  {
855  wxDefaultPosition, wxDefaultSize );
856  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(),
857  wxFONTFAMILY_MODERN,
858  wxFONTSTYLE_NORMAL,
859  wxFONTWEIGHT_NORMAL ) );
860  }
861 
862  m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL,
864  DisplayStatus();
865 }
866 
867 
869 {
870  wxString msg;
871  COMPONENT* component;
872  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
873 
874  if( m_compListBox == NULL )
875  {
877  wxDefaultPosition, wxDefaultSize );
878  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(),
879  wxFONTFAMILY_MODERN,
880  wxFONTSTYLE_NORMAL,
881  wxFONTWEIGHT_NORMAL ) );
882  }
883 
885 
886  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
887  {
888  component = m_netlist.GetComponent( i );
889 
890  msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1,
891  GetChars( component->GetReference() ),
892  GetChars( component->GetValue() ),
893  GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
894  m_compListBox->m_ComponentList.Add( msg );
895  }
896 
897  if( m_compListBox->m_ComponentList.Count() )
898  {
899  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
900  m_compListBox->SetSelection( 0, true );
901  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
903  }
904 }
905 
906 
908 {
909  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
910 
911  if( m_libListBox == NULL )
912  {
914  wxDefaultPosition, wxDefaultSize );
915  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(),
916  wxFONTFAMILY_MODERN,
917  wxFONTSTYLE_NORMAL,
918  wxFONTWEIGHT_NORMAL ) );
919  }
920 
921  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
922 
923  if( tbl )
924  {
925  wxArrayString libNames;
926 
927  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
928 
929  for( unsigned ii = 0; ii < libNickNames.size(); ii++ )
930  libNames.Add( libNickNames[ii] );
931 
932  m_libListBox->SetLibraryList( libNames );
933  }
934 }
935 
936 
938 {
939  int selection = m_compListBox->GetSelection();
940 
941  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
942  return m_netlist.GetComponent( selection );
943 
944  return NULL;
945 }
946 
947 
949 {
950  // returns the Footprint Viewer frame, if exists, or NULL
951  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
952  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
953 }
954 
955 
957 {
958  // returns the LIB_ID of the selected footprint in footprint listview
959  // or a empty string
961 }
962 
963 
964 void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
965 {
966  wxASSERT( aNumber < 2 );
967 
968  if( aNumber == 1 )
969  m_statusLine2->SetLabel( aText );
970  else
971  m_statusLine1->SetLabel( aText );
972 }
973 
974 
975 void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
976 {
977  Pgm().ConfigurePaths( this );
978 }
979 
980 
982 {
985  DisplayStatus();
986 }
987 
988 
990 {
991  const std::string& payload = mail.GetPayload();
992 
993  DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
994 
995  switch( mail.Command() )
996  {
998  ReadNetListAndFpFiles( payload );
999  /* @todo
1000  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
1001  */
1002  break;
1003 
1004  case MAIL_STATUS:
1005  SetStatusText( payload, 1 );
1006  break;
1007 
1008  default:
1009  ; // ignore most
1010  }
1011 }
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:190
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:166
DDE server & client.
FOOTPRINT_LIST * m_FootprintsList
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.
void OnCancel(wxCommandEvent &aEvent)
int GetPinCount() const
Definition: pcb_netlist.h:184
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:155
This file is part of the common library.
COMPONENTS_LISTBOX * m_compListBox
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:177
#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 DisplayErrors(wxTopLevelWindow *aCaller=NULL)
void SetNewPkg(const wxString &aFootprintName)
Function SetNewPkg set the footprint name for all selected components in component list and selects t...
void OnFilterFPbyKeywords(wxUpdateUIEvent &event)
void ReCreateHToolbar()
Definition: tool_cvpcb.cpp:35
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:66
bool SendCommand(int service, const char *cmdline)
Definition: eda_dde.cpp:132
wxAuiManager m_auimgr
#define FOOTPRINTVIEWER_FRAME_NAME
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:244
Return the global FP_LIB_TABLE.
Definition: kiface_ids.h:53
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
VTBL_ENTRY void * IfaceOrAddress(int aDataId)=0
Function IfaceOrAddress returns a pointer to the requested object.
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: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 ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string aPayload, wxWindow *aSource=NULL)
Function ExpressMail send aPayload to aDestination from aSource.
Definition: kiway.cpp:386
VTBL_ENTRY void ConfigurePaths(wxWindow *aParent=NULL)
Function ConfigurePaths.
Definition: pgm_base.cpp:970
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:151
const wxString & GetValue() const
Definition: pcb_netlist.h:153
#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
void ShowChangedLanguage() override
Function ShowChangedLanguage redraws the menus and what not in current language.
wxTextCtrl * m_tcFilterString
void OnSelectComponent(wxListEvent &event)
Function OnSelectComponent Called when clicking on a component in component list window.
static FOOTPRINT_LIST * GetInstance(KIWAY &aKiway)
Factory function to return a FOOTPRINT_LIST via Kiway.
FOOTPRINT_INFO * GetModuleInfo(const wxString &aFootprintName)
Get info for a module by name.
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. ...
const wxString & GetDoc()
void UpdateWidth(int aLine=-1)
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
void OnOK(wxCommandEvent &aEvent)
virtual bool ReadFootprintFiles(FP_LIB_TABLE *aTable, const wxString *aNickname=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)=0
Read all the footprints provided by the combination of aTable and aNickname.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
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 ...
wxAuiToolBar * m_mainToolBar
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
void SetStatusText(const wxString &aText, int aNumber=0) override
void OnFilterFPbyPinCount(wxUpdateUIEvent &event)
pcbnew DSO
Definition: kiway.h:267
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()
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 KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Function KiFACE returns the KIFACE* given a FACE_T.
Definition: kiway.cpp:148
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:120
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)
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
wxStaticText * m_statusLine2
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:265
void OnCloseWindow(wxCloseEvent &Event)
#define CMP_FORMAT
Definition: cvpcb.h:30
wxArrayString m_ComponentList
Definition: listboxes.h:199
wxString GetSelectedFootprint()
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:250
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:173
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...
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
size_t i
Definition: json11.cpp:597
COMPONENT * GetSelectedComponent()
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:151
FOOTPRINTS_LISTBOX * m_footprintListBox
unsigned GetErrorCount() const
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...
return & kiface
Definition: pcbnew.cpp:197
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
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:256
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)
virtual void ShowChangedLanguage()
Function ShowChangedLanguage redraws the menus and what not in current language.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:233
void DisplayStatus()
Function DisplayStatus updates the information displayed on the status bar at bottom of the main fram...
void OnSaveAndContinue(wxCommandEvent &aEvent)
wxButton * m_saveAndContinue
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
void SaveFootprintAssociation(bool doSaveSchematic)
Function SaveFootprintAssociation saves the edits that the user has done by sending them back to eesc...
The CvPcb application main window.
wxStaticText * m_statusLine1
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)
SCH->CVPCB netlist immediately after launching CVPCB.
Definition: mail_type.h:42