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 <kiface_i.h>
34 #include <kiface_ids.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 #include <3d_cache/3d_cache.h>
44 #include <dialog_configure_paths.h>
45 #include <cvpcb.h>
46 #include <listboxes.h>
47 #include <wx/statline.h>
48 #include <invoke_pcb_dialog.h>
50 #include <cvpcb_id.h>
51 
52 #include <cvpcb_mainframe.h>
53 
54 wxSize const FRAME_MIN_SIZE_DU( 350, 250 );
55 wxSize const FRAME_DEFAULT_SIZE_DU( 450, 300 );
56 
59 
60 static const wxString FilterFootprintEntry = "FilterFootprint";
62 
63 BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER )
64 
65  // Menu events
66  EVT_MENU( wxID_SAVE, CVPCB_MAINFRAME::OnSaveAndContinue )
67  EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit )
68  EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp )
69  EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout )
72 
73  // Toolbar events
74  EVT_TOOL( ID_CVPCB_LIB_TABLE_EDIT, CVPCB_MAINFRAME::OnEditFootprintLibraryTable )
79  EVT_TOOL( ID_CVPCB_AUTO_ASSOCIE, CVPCB_MAINFRAME::AutomaticFootprintMatching )
81  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
83  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
85  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
87  CVPCB_MAINFRAME::OnSelectFilteringFootprint )
88  EVT_TEXT( ID_CVPCB_FILTER_TEXT_EDIT, CVPCB_MAINFRAME::OnEnterFilteringText )
89 
90  // Button events
91  EVT_BUTTON( wxID_OK, CVPCB_MAINFRAME::OnOK )
92  EVT_BUTTON( wxID_CANCEL, CVPCB_MAINFRAME::OnCancel )
93 
94  // Frame events
95  EVT_CLOSE( CVPCB_MAINFRAME::OnCloseWindow )
96  EVT_SIZE( CVPCB_MAINFRAME::OnSize )
97 
98  // UI event handlers
99  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyKeywords)
100  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyPinCount )
101  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, CVPCB_MAINFRAME::OnFilterFPbyLibrary )
102  EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, CVPCB_MAINFRAME::OnFilterFPbyKeyName )
103 
104 END_EVENT_TABLE()
105 
106 
107 #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
108 
109 
110 CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
111  KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, _( "Assign Footprints" ), wxDefaultPosition,
113 {
114  m_compListBox = NULL;
115  m_footprintListBox = NULL;
116  m_libListBox = NULL;
117  m_mainToolBar = NULL;
118  m_modified = false;
119  m_skipComponentSelect = false;
120  m_filteringOptions = 0;
121  m_tcFilterString = NULL;
123  m_initialized = false;
124 
125  // Give an icon
126  wxIcon icon;
127  icon.CopyFromBitmap( KiBitmap( icon_cvpcb_xpm ) );
128  SetIcon( icon );
129 
130  SetAutoLayout( true );
131 
132  LoadSettings( config() );
133 
134  wxSize const frame_min( ConvertDialogToPixels( FRAME_MIN_SIZE_DU ) );
135 
136  SetSizeHints( frame_min );
137 
138  // Frame size and position
139  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
140 
141  ReCreateMenuBar();
143 
144  // Create list of available modules and components of the schematic
145  BuildCmpListBox();
148 
149  m_auimgr.SetManagedWindow( this );
150 
151  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
152 
153  m_auimgr.AddPane( m_libListBox, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(1)
154  .Caption( _( "Footprint Libraries" ) )
155  .BestSize( (int) ( m_FrameSize.x * 0.20 ), m_FrameSize.y ) );
156 
157  m_auimgr.AddPane( m_compListBox, EDA_PANE().Palette().Name( "Components" ).Center().Layer(0)
158  .Caption( _( "Symbol : Footprint Assignments" ) ) );
159 
160  m_auimgr.AddPane( m_footprintListBox, EDA_PANE().Palette().Name( "Footprints" ).Right().Layer(1)
161  .Caption( _( "Filtered Footprints" ) )
162  .BestSize( (int) ( m_FrameSize.x * 0.30 ), m_FrameSize.y ) );
163 
164  // Build the bottom panel, to display 2 status texts and the buttons:
165  auto bottomPanel = new wxPanel( this );
166  auto panelSizer = new wxBoxSizer( wxVERTICAL );
167 
168  wxFlexGridSizer* fgSizerStatus = new wxFlexGridSizer( 2, 1, 0, 0 );
169  fgSizerStatus->SetFlexibleDirection( wxBOTH );
170  fgSizerStatus->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
171 
172  m_statusLine1 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
173  fgSizerStatus->Add( m_statusLine1, 0, 0, 5 );
174 
175  m_statusLine2 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
176  fgSizerStatus->Add( m_statusLine2, 0, wxBOTTOM, 3 );
177 
178  panelSizer->Add( fgSizerStatus, 1, wxEXPAND|wxLEFT, 2 );
179 
180  wxStaticLine* staticline1 = new wxStaticLine( bottomPanel );
181  panelSizer->Add( staticline1, 0, wxEXPAND, 5 );
182 
183  wxFont statusFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
184  statusFont.SetSymbolicSize( wxFONTSIZE_SMALL );
185  m_statusLine1->SetFont( statusFont );
186  m_statusLine2->SetFont( statusFont );
187 
188  // Add buttons:
189  auto buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
190  auto sdbSizer = new wxStdDialogButtonSizer();
191 
192  m_saveAndContinue = new wxButton( bottomPanel, wxID_SAVE,
193  _( "Apply, Save Schematic && Continue" ) );
194  buttonsSizer->Add( m_saveAndContinue, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 20 );
195 
196  auto sdbSizerOK = new wxButton( bottomPanel, wxID_OK );
197  sdbSizer->AddButton( sdbSizerOK );
198  auto sdbSizerCancel = new wxButton( bottomPanel, wxID_CANCEL );
199  sdbSizer->AddButton( sdbSizerCancel );
200  sdbSizer->Realize();
201 
202  buttonsSizer->Add( sdbSizer, 0, 0, 5 );
203  panelSizer->Add( buttonsSizer, 0, wxALIGN_RIGHT|wxALL, 5 );
204 
205  bottomPanel->SetSizer( panelSizer );
206  bottomPanel->Fit();
207 
208  sdbSizerOK->SetDefault();
209 
210  m_auimgr.AddPane( bottomPanel, EDA_PANE().HToolbar().Name( "Buttons" ).Bottom().Layer(6) );
211 
212  m_auimgr.Update();
213  m_initialized = true;
214 
215  // Connect Events
216  m_saveAndContinue->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CVPCB_MAINFRAME::OnSaveAndContinue ), NULL, this );
217  m_footprintListBox->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CVPCB_MAINFRAME::OnFootprintRightClick ), NULL, this );
218  m_compListBox->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CVPCB_MAINFRAME::OnComponentRightClick ), NULL, this );
219 }
220 
221 
223 {
224  // Disconnect Events
225  m_saveAndContinue->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CVPCB_MAINFRAME::OnSaveAndContinue ), NULL, this );
226  m_footprintListBox->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CVPCB_MAINFRAME::OnFootprintRightClick ), NULL, this );
227 
228  m_auimgr.UnInit();
229 }
230 
231 
232 void CVPCB_MAINFRAME::LoadSettings( wxConfigBase* aCfg )
233 {
235 
236  wxSize const frame_default( ConvertDialogToPixels( FRAME_DEFAULT_SIZE_DU ) );
237 
238  if( m_FrameSize == wxDefaultSize )
239  m_FrameSize = frame_default;
240 
242 }
243 
244 
245 void CVPCB_MAINFRAME::SaveSettings( wxConfigBase* aCfg )
246 {
248 
250 }
251 
252 
253 void CVPCB_MAINFRAME::OnSize( wxSizeEvent& event )
254 {
255  event.Skip();
256 }
257 
258 
259 void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
260 {
261  if( m_modified )
262  {
263  if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified.\nSave before exit?" ),
264  [&]()->bool { return SaveFootprintAssociation( false ); } ) )
265  {
266  Event.Veto();
267  return;
268  }
269  }
270 
271  // Close module display frame
273  GetFootprintViewerFrame()->Close( true );
274 
275  m_modified = false;
276 
277  Destroy();
278 }
279 
280 
281 void CVPCB_MAINFRAME::ChangeFocus( bool aMoveRight )
282 {
283  wxWindow* hasFocus = wxWindow::FindFocus();
284 
285  if( aMoveRight )
286  {
287  if( hasFocus == m_libListBox )
288  m_compListBox->SetFocus();
289  else if( hasFocus == m_compListBox )
290  m_footprintListBox->SetFocus();
291  else if( hasFocus == m_footprintListBox )
292  m_libListBox->SetFocus();
293  }
294  else
295  {
296  if( hasFocus == m_libListBox )
297  m_footprintListBox->SetFocus();
298  else if( hasFocus == m_compListBox )
299  m_libListBox->SetFocus();
300  else if( hasFocus == m_footprintListBox )
301  m_compListBox->SetFocus();
302  }
303 }
304 
305 
306 void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event )
307 {
308  if( m_netlist.IsEmpty() )
309  return;
310 
311  int first_selected = m_compListBox->GetFirstSelected();
312 
313  if( first_selected < 0 )
314  first_selected = -1; // We will start to 0 for the first search , if no item selected
315 
316  int candidate = -1;
317 
318  for( int jj = first_selected+1; jj < (int)m_netlist.GetCount(); jj++ )
319  {
320  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
321  {
322  candidate = jj;
323  break;
324  }
325  }
326 
327  if( candidate >= 0 )
328  {
330  m_compListBox->SetSelection( candidate );
332  }
333 }
334 
335 
336 void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
337 {
338  if( m_netlist.IsEmpty() )
339  return;
340 
341  int first_selected = m_compListBox->GetFirstSelected();
342 
343  if( first_selected < 0 )
344  first_selected = m_compListBox->GetCount();
345 
346  int candidate = -1;
347 
348  for( int jj = first_selected-1; jj >= 0; jj-- )
349  {
350  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
351  {
352  candidate = jj;
353  break;
354  }
355  }
356 
357  if( candidate >= 0 )
358  {
360  m_compListBox->SetSelection( candidate );
362  }
363 }
364 
365 
366 void CVPCB_MAINFRAME::OnOK( wxCommandEvent& aEvent )
367 {
368  SaveFootprintAssociation( false );
369 
370  m_modified = false;
371 
372  Close( true );
373 }
374 
375 
376 void CVPCB_MAINFRAME::OnSaveAndContinue( wxCommandEvent& aEvent )
377 {
378  SaveFootprintAssociation( true );
379 
380  m_modified = false;
381 }
382 
383 
384 void CVPCB_MAINFRAME::OnCancel( wxCommandEvent& event )
385 {
386  // Throw away modifications on a Cancel
387  m_modified = false;
388 
389  Close( false );
390 }
391 
392 
393 void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event )
394 {
395  Close( false );
396 }
397 
398 
399 void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event )
400 {
401  if( IsOK( this, _( "Delete selections" ) ) )
402  {
403  m_skipComponentSelect = true;
404 
405  // Remove all selections to avoid issues when setting the fpids
407 
408  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
409  {
410  LIB_ID fpid;
411 
412  m_netlist.GetComponent( i )->SetFPID( fpid );
413  SetNewPkg( wxEmptyString );
414  }
415 
416  // Remove all selections after setting the fpids
418 
419  m_skipComponentSelect = false;
421  }
422 
423  DisplayStatus();
424 }
425 
426 
427 bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
428 {
429  return true;
430 }
431 
432 
433 void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent )
434 {
436  kiface->CreateWindow( this, DIALOG_PCB_LIBRARY_TABLE, &Kiway() );
437 
438  wxBusyCursor dummy;
440  m_FootprintsList->ReadFootprintFiles( Prj().PcbFootprintLibs( Kiway() ) );
441 }
442 
443 
444 void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event )
445 {
446  CreateScreenCmp();
447  GetFootprintViewerFrame()->RedrawScreen( wxPoint( 0, 0 ), false );
448 }
449 
450 
451 void CVPCB_MAINFRAME::OnComponentRightClick( wxMouseEvent& event )
452 {
453  wxMenu menu;
454 
455  menu.Append( ID_CVPCB_CREATE_SCREENCMP, _( "View Footprint" ), _( "Show the assigned footprint in the footprint viewer" ) );
456 
457  PopupMenu( &menu );
458 }
459 
460 
461 void CVPCB_MAINFRAME::OnFootprintRightClick( wxMouseEvent& event )
462 {
463  wxMenu menu;
464 
465  menu.Append( ID_CVPCB_CREATE_SCREENCMP, _( "View Footprint" ), _( "Show the current footprint in the footprint viewer" ) );
466 
467  PopupMenu( &menu );
468 }
469 
470 
471 void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
472 {
474  return;
475 
476  wxString libraryName;
477  COMPONENT* component = GetSelectedComponent();
478  libraryName = m_libListBox->GetSelectedLibrary();
479 
480  m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
482 
484 
485  refreshAfterComponentSearch (component);
486 }
487 
488 
490 {
491  // Tell AuiMgr that objects are changed !
492  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
493  // (could be not the case when starting CvPcb
494  m_auimgr.Update();
495 
496  if( component == NULL )
497  {
498  DisplayStatus();
499  return;
500  }
501 
502  // Preview of the already assigned footprint.
503  // Find the footprint that was already chosen for this component and select it,
504  // but only if the selection is made from the component list or the library list.
505  // If the selection is made from the footprint list, do not change the current
506  // selected footprint.
507  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
508  {
509  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
510 
512 
513  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
514  {
515  wxString footprintName;
516  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
517  msg.Trim( true );
518  msg.Trim( false );
519  footprintName = msg.AfterFirst( wxChar( ' ' ) );
520 
521  if( module.Cmp( footprintName ) == 0 )
522  {
523  m_footprintListBox->SetSelection( ii, true );
524  break;
525  }
526  }
527 
529  CreateScreenCmp();
530  }
531 
533  DisplayStatus();
534 }
535 
536 void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
537 {
538  int option = 0;
539 
540  switch( event.GetId() )
541  {
542  case ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST:
544  break;
545 
546  case ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST:
548  break;
549 
550  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST:
552  break;
553 
554  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME:
557  break;
558  }
559 
560  if( event.IsChecked() )
561  m_filteringOptions |= option;
562  else
563  m_filteringOptions &= ~option;
564 
565  wxListEvent l_event;
566  OnSelectComponent( l_event );
567 }
568 
569 
570 void CVPCB_MAINFRAME::OnFilterFPbyKeywords( wxUpdateUIEvent& event )
571 {
573 }
574 
575 
576 void CVPCB_MAINFRAME::OnFilterFPbyPinCount( wxUpdateUIEvent& event )
577 {
579 }
580 
581 
582 void CVPCB_MAINFRAME::OnFilterFPbyLibrary( wxUpdateUIEvent& event )
583 {
585 }
586 
587 
588 void CVPCB_MAINFRAME::OnFilterFPbyKeyName( wxUpdateUIEvent& event )
589 {
591 }
592 
593 
594 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
595 {
596  // Called when changing the filter string in main toolbar.
597  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
598  // available footprints which match the filter
599 
601 
603  return;
604 
605  OnSelectFilteringFootprint( aEvent );
606 }
607 
608 
610 {
611  if( !m_initialized )
612  return;
613 
614  wxString filters, msg;
615  COMPONENT* component = GetSelectedComponent();
616 
618  {
619  msg.Empty();
620 
621  if( component )
622  {
623  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
624  {
625  if( msg.IsEmpty() )
626  msg += component->GetFootprintFilters()[ii];
627  else
628  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
629  }
630  }
631 
632  filters += _( "key words" ) + wxString::Format( wxT( " (%s)" ), msg );
633  }
634 
636  {
637  msg.Empty();
638 
639  if( component )
640  msg = wxString::Format( wxT( "%i" ), component->GetPinCount() );
641 
642  if( !filters.IsEmpty() )
643  filters += wxT( ", " );
644 
645  filters += _( "pin count" ) + wxString::Format( wxT( " (%s)" ), msg );
646  }
647 
649  {
651 
652  if( !filters.IsEmpty() )
653  filters += wxT( ", " );
654 
655  filters += _( "library" ) + wxString::Format( wxT( " (%s)" ), msg );
656  }
657 
659  {
660  if( !filters.IsEmpty() )
661  filters += wxT( ", " );
662 
663  filters += _( "search text" );
664  }
665 
666  if( filters.IsEmpty() )
667  msg = _( "No filtering" );
668  else
669  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
670 
671  msg << wxT( ": " ) << m_footprintListBox->GetCount();
672 
673  SetStatusText( msg );
674 
675 
676  msg.Empty();
677  wxString footprintName = GetSelectedFootprint();
678 
679  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
680 
681  if( module ) // can be NULL if no netlist loaded
682  {
683  msg = wxString::Format( _( "Description: %s; Key words: %s" ),
684  module->GetDescription(),
685  module->GetKeywords() );
686  }
687 
688  SetStatusText( msg, 1 );
689 }
690 
691 
693 {
694  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
695 
696  // Check if there are footprint libraries in the footprint library table.
697  if( !fptbl || !fptbl->GetLogicalLibs().size() )
698  {
699  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
700  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
701  return false;
702  }
703 
704  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
705 
706  m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
707 
709  {
711  }
712 
713  return true;
714 }
715 
716 
718 {
719  if( m_netlist.IsEmpty() )
720  return;
721 
722  int selection = m_compListBox->GetSelection();
723 
724  if ( selection < 0 )
725  selection = 0;
726 
727  if( m_netlist.GetComponent( selection ) == NULL )
728  return;
729 
730  COMPONENT* component = m_netlist.GetComponent( selection );
731 
732  std::string packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
733 
734  if( Kiface().IsSingle() )
735  SendCommand( MSG_TO_SCH, packet.c_str() );
736  else
737  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
738 }
739 
740 
741 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
742 {
743  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
744  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
745 
746  m_netlist.Clear();
747 
748  try
749  {
750  netrdr.LoadNetlist();
751  }
752  catch( const IO_ERROR& ioe )
753  {
754  wxString msg = wxString::Format( _( "Error loading schematic.\n%s" ), ioe.What().GetData() );
755  wxMessageBox( msg, _( "Load Error" ), wxOK | wxICON_ERROR );
756  return 1;
757  }
758 
759  // We also remove footprint name if it is "$noname" because this is a dummy name,
760  // not the actual name of the footprint.
761  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
762  {
763  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
764  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
765  }
766 
767  // Sort components by reference:
769 
770  return 0;
771 }
772 
773 
775 {
777 
778  if( !fpframe )
779  {
780  fpframe = (DISPLAY_FOOTPRINTS_FRAME*) Kiway().Player( FRAME_CVPCB_DISPLAY, true, this );
781  fpframe->Show( true );
782  }
783  else
784  {
785  if( fpframe->IsIconized() )
786  fpframe->Iconize( false );
787 
788  // The display footprint window might be buried under some other
789  // windows, so CreateScreenCmp() on an existing window would not
790  // show any difference, leaving the user confused.
791  // So we want to put it to front, second after our CVPCB_MAINFRAME.
792  // We do this by a little dance of bringing it to front then the main
793  // frame back.
794  fpframe->Raise(); // Make sure that is visible.
795  Raise(); // .. but still we want the focus.
796  }
797 
798  fpframe->InitDisplay();
799 }
800 
801 
803 {
804  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
805 
806  if( m_footprintListBox == NULL )
807  {
809  wxDefaultPosition, wxDefaultSize );
810  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(),
811  wxFONTFAMILY_MODERN,
812  wxFONTSTYLE_NORMAL,
813  wxFONTWEIGHT_NORMAL ) );
814  }
815 
816  m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL,
818  DisplayStatus();
819 }
820 
821 
823 {
824  wxString msg;
825  COMPONENT* component;
826  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
827 
828  if( m_compListBox == NULL )
829  {
831  wxDefaultPosition, wxDefaultSize );
832  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(),
833  wxFONTFAMILY_MODERN,
834  wxFONTSTYLE_NORMAL,
835  wxFONTWEIGHT_NORMAL ) );
836  }
837 
839 
840  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
841  {
842  component = m_netlist.GetComponent( i );
843 
844  msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1,
845  GetChars( component->GetReference() ),
846  GetChars( component->GetValue() ),
847  GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
848  m_compListBox->m_ComponentList.Add( msg );
849  }
850 
851  if( m_compListBox->m_ComponentList.Count() )
852  {
853  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
854  m_compListBox->SetSelection( 0, true );
855  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
857  }
858 }
859 
860 
862 {
863  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
864 
865  if( m_libListBox == NULL )
866  {
868  wxDefaultPosition, wxDefaultSize );
869  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(),
870  wxFONTFAMILY_MODERN,
871  wxFONTSTYLE_NORMAL,
872  wxFONTWEIGHT_NORMAL ) );
873  }
874 
875  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
876 
877  if( tbl )
878  {
879  wxArrayString libNames;
880 
881  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
882 
883  for( unsigned ii = 0; ii < libNickNames.size(); ii++ )
884  libNames.Add( libNickNames[ii] );
885 
886  m_libListBox->SetLibraryList( libNames );
887  }
888 }
889 
890 
892 {
893  int selection = m_compListBox->GetSelection();
894 
895  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
896  return m_netlist.GetComponent( selection );
897 
898  return NULL;
899 }
900 
901 
903 {
904  // returns the Footprint Viewer frame, if exists, or NULL
905  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
906  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
907 }
908 
909 
911 {
912  // returns the LIB_ID of the selected footprint in footprint listview
913  // or a empty string
915 }
916 
917 
918 void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
919 {
920  wxASSERT( aNumber < 2 );
921 
922  if( aNumber == 1 )
923  m_statusLine2->SetLabel( aText );
924  else
925  m_statusLine1->SetLabel( aText );
926 }
927 
928 
929 void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
930 {
931  DIALOG_CONFIGURE_PATHS dlg( this, Prj().Get3DCacheManager()->GetResolver() );
932  dlg.ShowModal();
933 }
934 
935 
937 {
940  DisplayStatus();
941 }
942 
943 
945 {
946  const std::string& payload = mail.GetPayload();
947 
948  //DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
949 
950  switch( mail.Command() )
951  {
953  ReadNetListAndFpFiles( payload );
954  /* @todo
955  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
956  */
957  break;
958 
959  case MAIL_STATUS:
960  SetStatusText( payload, 1 );
961  break;
962 
963  default:
964  ; // ignore most
965  }
966 }
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...
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Function HandleUnsavedChanges displays a dialog with Save, Cancel and Discard Changes buttons...
Definition: confirm.cpp:201
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:120
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:186
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions EVT_UPDATE_UI(ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard) EVT_UPDATE_UI(ID_MODEDIT_INSERT_MODULE_IN_BOARD
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
int StrPrintf(std::string *aResult, const char *aFormat,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
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.
FOOTPRINT_INFO * GetModuleInfo(const wxString &aFootprintId)
Get info for a module by id.
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)
const wxString & GetDescription() override
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...
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)
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.
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
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.
VTBL_ENTRY wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKIWAY, int aCtlBits=0)=0
Function CreateWindow creates a wxWindow for the current project.
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.
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. ...
void UpdateWidth(int aLine=-1)
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:300
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:114
virtual void LoadSettings(wxConfigBase *aCfg)
Function LoadSettings loads common frame parameters from a configuration file.
void OnComponentRightClick(wxMouseEvent &event)
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()
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
#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)
void OnFootprintRightClick(wxMouseEvent &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
Specialization of the wxAuiPaneInfo class for KiCad panels.
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)
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar EVT_MENU(ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, FOOTPRINT_EDIT_FRAME::ProcessPreferences) EVT_MENU(ID_PCB_LIB_TABLE_EDIT
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
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
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...
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
defines the display data cache manager for 3D models
unsigned GetErrorCount() const
UTF8 Format() const
Definition: lib_id.cpp:237
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:219
PCB<->SCH, CVPCB->SCH cross-probing.
Definition: mail_type.h:39
void OnConfigurePaths(wxCommandEvent &aEvent)
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:281
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
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
bool SaveFootprintAssociation(bool doSaveSchematic)
Function SaveFootprintAssociation saves the edits that the user has done by sending them back to eesc...