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_dde.h>
38 #include <html_messagebox.h>
39 #include <fp_lib_table.h>
40 #include <netlist_reader.h>
41 #include <bitmaps.h>
43 
44 #include <cvpcb_mainframe.h>
45 #include <cvpcb.h>
46 #include <listboxes.h>
47 #include <invoke_pcb_dialog.h>
49 #include <cvpcb_id.h>
50 
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  bool tableChanged = false;
442  int r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs( Kiway() ) );
443 
444  if( r & 1 )
445  {
446  wxString fileName = FP_LIB_TABLE::GetGlobalTableFileName();
447 
448  try
449  {
450  GFootprintTable.Save( fileName );
451  tableChanged = true;
452  }
453  catch( const IO_ERROR& ioe )
454  {
455  wxString msg = wxString::Format(
456  _( "Error occurred saving the global footprint library table:\n\"%s\"\n%s" ),
457  GetChars( fileName ),
458  GetChars( ioe.What() )
459  );
460  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
461  }
462  }
463 
464  if( r & 2 )
465  {
466  wxString fileName = Prj().FootprintLibTblName();
467 
468  try
469  {
470  Prj().PcbFootprintLibs( Kiway() )->Save( fileName );
471  tableChanged = true;
472  }
473  catch( const IO_ERROR& ioe )
474  {
475  wxString msg = wxString::Format(
476  _( "Error occurred saving the project footprint library table:\n\"%s\"\n%s" ),
477  GetChars( fileName ),
478  GetChars( ioe.What() )
479  );
480  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
481  }
482  }
483 
484  if( tableChanged )
485  {
486  wxBusyCursor dummy;
488  m_FootprintsList->ReadFootprintFiles( Prj().PcbFootprintLibs( Kiway() ) );
489  }
490 }
491 
492 
493 void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event )
494 {
495  CreateScreenCmp();
496  GetFootprintViewerFrame()->RedrawScreen( wxPoint( 0, 0 ), false );
497 }
498 
499 
500 void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
501 {
503  return;
504 
505  wxString libraryName;
506  COMPONENT* component = GetSelectedComponent();
507  libraryName = m_libListBox->GetSelectedLibrary();
508 
509  m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
511 
512  refreshAfterComponentSearch (component);
513 }
514 
515 
517 {
518  // Tell AuiMgr that objects are changed !
519  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
520  // (could be not the case when starting CvPcb
521  m_auimgr.Update();
522 
523  if( component == NULL )
524  {
525  DisplayStatus();
526  return;
527  }
528 
529  // Preview of the already assigned footprint.
530  // Find the footprint that was already chosen for this component and select it,
531  // but only if the selection is made from the component list or the library list.
532  // If the selection is made from the footprint list, do not change the current
533  // selected footprint.
534  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
535  {
536  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
537 
538  bool found = false;
539 
540  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
541  {
542  wxString footprintName;
543  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
544  msg.Trim( true );
545  msg.Trim( false );
546  footprintName = msg.AfterFirst( wxChar( ' ' ) );
547 
548  if( module.Cmp( footprintName ) == 0 )
549  {
550  m_footprintListBox->SetSelection( ii, true );
551  found = true;
552  break;
553  }
554  }
555 
556  if( !found )
557  {
558  int ii = m_footprintListBox->GetSelection();
559 
560  if ( ii >= 0 )
561  m_footprintListBox->SetSelection( ii, false );
562 
564  {
565  CreateScreenCmp();
566  }
567  }
568  }
569 
571  DisplayStatus();
572 }
573 
574 void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
575 {
576  int option = 0;
577 
578  switch( event.GetId() )
579  {
580  case ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST:
582  break;
583 
584  case ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST:
586  break;
587 
588  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST:
590  break;
591 
592  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME:
595  break;
596  }
597 
598  if( event.IsChecked() )
599  m_filteringOptions |= option;
600  else
601  m_filteringOptions &= ~option;
602 
603  wxListEvent l_event;
604  OnSelectComponent( l_event );
605 }
606 
607 
608 void CVPCB_MAINFRAME::OnFilterFPbyKeywords( wxUpdateUIEvent& event )
609 {
611 }
612 
613 
614 void CVPCB_MAINFRAME::OnFilterFPbyPinCount( wxUpdateUIEvent& event )
615 {
617 }
618 
619 
620 void CVPCB_MAINFRAME::OnFilterFPbyLibrary( wxUpdateUIEvent& event )
621 {
623 }
624 
625 
626 void CVPCB_MAINFRAME::OnFilterFPbyKeyName( wxUpdateUIEvent& event )
627 {
629 }
630 
631 
632 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
633 {
634  // Called when changing the filter string in main toolbar.
635  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
636  // available footprints which match the filter
637 
639 
641  return;
642 
643  OnSelectFilteringFootprint( aEvent );
644 }
645 
646 
648 {
649  if( !m_initialized )
650  return;
651 
652  wxString filters, msg;
653  COMPONENT* component = GetSelectedComponent();
654 
656  {
657  msg.Empty();
658 
659  if( component )
660  {
661  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
662  {
663  if( msg.IsEmpty() )
664  msg += component->GetFootprintFilters()[ii];
665  else
666  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
667  }
668  }
669 
670  filters += _( "key words" ) + wxString::Format( wxT( " (%s)" ), msg );
671  }
672 
674  {
675  msg.Empty();
676 
677  if( component )
678  msg = wxString::Format( wxT( "%i" ), component->GetPinCount() );
679 
680  if( !filters.IsEmpty() )
681  filters += wxT( ", " );
682 
683  filters += _( "pin count" ) + wxString::Format( wxT( " (%s)" ), msg );
684  }
685 
687  {
689 
690  if( !filters.IsEmpty() )
691  filters += wxT( ", " );
692 
693  filters += _( "library" ) + wxString::Format( wxT( " (%s)" ), msg );
694  }
695 
697  {
698  if( !filters.IsEmpty() )
699  filters += wxT( ", " );
700 
701  filters += _( "search text" );
702  }
703 
704  if( filters.IsEmpty() )
705  msg = _( "No filtering" );
706  else
707  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
708 
709  msg << wxT( ": " ) << m_footprintListBox->GetCount();
710 
711  SetStatusText( msg );
712 
713 
714  msg.Empty();
715  wxString footprintName = GetSelectedFootprint();
716 
717  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
718 
719  if( module ) // can be NULL if no netlist loaded
720  {
721  msg = wxString::Format( _( "Description: %s; Key words: %s" ),
722  module->GetDoc(),
723  module->GetKeywords() );
724  }
725 
726  SetStatusText( msg, 1 );
727 }
728 
729 
731 {
732  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
733 
734  // Check if there are footprint libraries in the footprint library table.
735  if( !fptbl || !fptbl->GetLogicalLibs().size() )
736  {
737  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
738  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
739  return false;
740  }
741 
742  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
743 
744  m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
745 
747  {
749  }
750 
751  return true;
752 }
753 
754 
756 {
757  if( m_netlist.IsEmpty() )
758  return;
759 
760  int selection = m_compListBox->GetSelection();
761 
762  if ( selection < 0 )
763  selection = 0;
764 
765  if( m_netlist.GetComponent( selection ) == NULL )
766  return;
767 
768  COMPONENT* component = m_netlist.GetComponent( selection );
769 
770  std::string packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
771 
772  if( Kiface().IsSingle() )
773  SendCommand( MSG_TO_SCH, packet.c_str() );
774  else
775  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
776 }
777 
778 
779 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
780 {
781  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
782  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
783 
784  m_netlist.Clear();
785 
786  try
787  {
788  netrdr.LoadNetlist();
789  }
790  catch( const IO_ERROR& ioe )
791  {
792  wxString msg = wxString::Format( _( "Error loading schematic.\n%s" ), ioe.What().GetData() );
793  wxMessageBox( msg, _( "Load Error" ), wxOK | wxICON_ERROR );
794  return 1;
795  }
796 
797  // We also remove footprint name if it is "$noname" because this is a dummy name,
798  // not the actual name of the footprint.
799  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
800  {
801  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
802  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
803  }
804 
805  // Sort components by reference:
807 
808  return 0;
809 }
810 
811 
813 {
815 
816  if( !fpframe )
817  {
818  fpframe = new DISPLAY_FOOTPRINTS_FRAME( &Kiway(), this );
819  fpframe->Show( true );
820  }
821  else
822  {
823  if( fpframe->IsIconized() )
824  fpframe->Iconize( false );
825 
826  // The display footprint window might be buried under some other
827  // windows, so CreateScreenCmp() on an existing window would not
828  // show any difference, leaving the user confused.
829  // So we want to put it to front, second after our CVPCB_MAINFRAME.
830  // We do this by a little dance of bringing it to front then the main
831  // frame back.
832  fpframe->Raise(); // Make sure that is visible.
833  Raise(); // .. but still we want the focus.
834  }
835 
836  fpframe->InitDisplay();
837 }
838 
839 
841 {
842  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
843 
844  if( m_footprintListBox == NULL )
845  {
847  wxDefaultPosition, wxDefaultSize );
848  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(),
849  wxFONTFAMILY_MODERN,
850  wxFONTSTYLE_NORMAL,
851  wxFONTWEIGHT_NORMAL ) );
852  }
853 
854  m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL,
856  DisplayStatus();
857 }
858 
859 
861 {
862  wxString msg;
863  COMPONENT* component;
864  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
865 
866  if( m_compListBox == NULL )
867  {
869  wxDefaultPosition, wxDefaultSize );
870  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(),
871  wxFONTFAMILY_MODERN,
872  wxFONTSTYLE_NORMAL,
873  wxFONTWEIGHT_NORMAL ) );
874  }
875 
877 
878  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
879  {
880  component = m_netlist.GetComponent( i );
881 
882  msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1,
883  GetChars( component->GetReference() ),
884  GetChars( component->GetValue() ),
885  GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
886  m_compListBox->m_ComponentList.Add( msg );
887  }
888 
889  if( m_compListBox->m_ComponentList.Count() )
890  {
891  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
892  m_compListBox->SetSelection( 0, true );
893  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
895  }
896 }
897 
898 
900 {
901  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
902 
903  if( m_libListBox == NULL )
904  {
906  wxDefaultPosition, wxDefaultSize );
907  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(),
908  wxFONTFAMILY_MODERN,
909  wxFONTSTYLE_NORMAL,
910  wxFONTWEIGHT_NORMAL ) );
911  }
912 
913  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
914 
915  if( tbl )
916  {
917  wxArrayString libNames;
918 
919  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
920 
921  for( unsigned ii = 0; ii < libNickNames.size(); ii++ )
922  libNames.Add( libNickNames[ii] );
923 
924  m_libListBox->SetLibraryList( libNames );
925  }
926 }
927 
928 
930 {
931  int selection = m_compListBox->GetSelection();
932 
933  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
934  return m_netlist.GetComponent( selection );
935 
936  return NULL;
937 }
938 
939 
941 {
942  // returns the Footprint Viewer frame, if exists, or NULL
943  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
944  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
945 }
946 
947 
949 {
950  // returns the LIB_ID of the selected footprint in footprint listview
951  // or a empty string
953 }
954 
955 
956 void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
957 {
958  wxASSERT( aNumber < 2 );
959 
960  if( aNumber == 1 )
961  m_statusLine2->SetLabel( aText );
962  else
963  m_statusLine1->SetLabel( aText );
964 }
965 
966 
967 void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
968 {
969  Pgm().ConfigurePaths( this );
970 }
971 
972 
974 {
977  DisplayStatus();
978 }
979 
980 
982 {
983  const std::string& payload = mail.GetPayload();
984 
985  DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
986 
987  switch( mail.Command() )
988  {
990  ReadNetListAndFpFiles( payload );
991  /* @todo
992  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
993  */
994  break;
995 
996  case MAIL_STATUS:
997  SetStatusText( payload, 1 );
998  break;
999 
1000  default:
1001  ; // ignore most
1002  }
1003 }
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:173
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:65
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
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
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:305
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:912
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)
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 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)
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()
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...
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: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: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