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
67  EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit )
72 
73  // Toolbar events
89 
90  // Button events
91  EVT_BUTTON( wxID_OK, CVPCB_MAINFRAME::OnOK )
92  EVT_BUTTON( wxID_CANCEL, CVPCB_MAINFRAME::OnCancel )
93 
94  // Frame events
96  EVT_SIZE( CVPCB_MAINFRAME::OnSize )
97 
98  // UI event handlers
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, ID_SAVE_PROJECT,
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  // clear highlight symbol in schematic:
278  SendMessageToEESCHEMA( true );
279 
280  // Delete window
281  Destroy();
282 }
283 
284 
285 void CVPCB_MAINFRAME::ChangeFocus( bool aMoveRight )
286 {
287  wxWindow* hasFocus = wxWindow::FindFocus();
288 
289  if( aMoveRight )
290  {
291  if( hasFocus == m_libListBox )
292  m_compListBox->SetFocus();
293  else if( hasFocus == m_compListBox )
294  m_footprintListBox->SetFocus();
295  else if( hasFocus == m_footprintListBox )
296  m_libListBox->SetFocus();
297  }
298  else
299  {
300  if( hasFocus == m_libListBox )
301  m_footprintListBox->SetFocus();
302  else if( hasFocus == m_compListBox )
303  m_libListBox->SetFocus();
304  else if( hasFocus == m_footprintListBox )
305  m_compListBox->SetFocus();
306  }
307 }
308 
309 
310 void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event )
311 {
312  if( m_netlist.IsEmpty() )
313  return;
314 
315  int first_selected = m_compListBox->GetFirstSelected();
316 
317  if( first_selected < 0 )
318  first_selected = -1; // We will start to 0 for the first search , if no item selected
319 
320  int candidate = -1;
321 
322  for( int jj = first_selected+1; jj < (int)m_netlist.GetCount(); jj++ )
323  {
324  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
325  {
326  candidate = jj;
327  break;
328  }
329  }
330 
331  if( candidate >= 0 )
332  {
334  m_compListBox->SetSelection( candidate );
336  }
337 }
338 
339 
340 void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
341 {
342  if( m_netlist.IsEmpty() )
343  return;
344 
345  int first_selected = m_compListBox->GetFirstSelected();
346 
347  if( first_selected < 0 )
348  first_selected = m_compListBox->GetCount();
349 
350  int candidate = -1;
351 
352  for( int jj = first_selected-1; jj >= 0; jj-- )
353  {
354  if( m_netlist.GetComponent( jj )->GetFPID().empty() )
355  {
356  candidate = jj;
357  break;
358  }
359  }
360 
361  if( candidate >= 0 )
362  {
364  m_compListBox->SetSelection( candidate );
366  }
367 }
368 
369 
370 void CVPCB_MAINFRAME::OnOK( wxCommandEvent& aEvent )
371 {
372  SaveFootprintAssociation( false );
373 
374  m_modified = false;
375 
376  Close( true );
377 }
378 
379 
380 void CVPCB_MAINFRAME::OnSaveAndContinue( wxCommandEvent& aEvent )
381 {
382  SaveFootprintAssociation( true );
383 
384  m_modified = false;
385 }
386 
387 
388 void CVPCB_MAINFRAME::OnCancel( wxCommandEvent& event )
389 {
390  // Throw away modifications on a Cancel
391  m_modified = false;
392 
393  Close( false );
394 }
395 
396 
397 void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event )
398 {
399  Close( false );
400 }
401 
402 
403 void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event )
404 {
405  if( IsOK( this, _( "Delete selections" ) ) )
406  {
407  m_skipComponentSelect = true;
408 
409  // Remove all selections to avoid issues when setting the fpids
411 
412  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
413  {
414  LIB_ID fpid;
415 
416  m_netlist.GetComponent( i )->SetFPID( fpid );
417  SetNewPkg( wxEmptyString );
418  }
419 
420  // Remove all selections after setting the fpids
422 
423  m_skipComponentSelect = false;
425  }
426 
427  DisplayStatus();
428 }
429 
430 
431 bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
432 {
433  return true;
434 }
435 
436 
437 void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent )
438 {
440  kiface->CreateWindow( this, DIALOG_PCB_LIBRARY_TABLE, &Kiway() );
441 
442  wxBusyCursor dummy;
444  m_FootprintsList->ReadFootprintFiles( Prj().PcbFootprintLibs( Kiway() ) );
445 }
446 
447 
448 void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event )
449 {
450  CreateScreenCmp();
451  GetFootprintViewerFrame()->RedrawScreen( wxPoint( 0, 0 ), false );
452 }
453 
454 
455 void CVPCB_MAINFRAME::OnComponentRightClick( wxMouseEvent& event )
456 {
457  wxMenu menu;
458 
459  menu.Append( ID_CVPCB_CREATE_SCREENCMP, _( "View Footprint" ), _( "Show the assigned footprint in the footprint viewer" ) );
460 
461  PopupMenu( &menu );
462 }
463 
464 
465 void CVPCB_MAINFRAME::OnFootprintRightClick( wxMouseEvent& event )
466 {
467  wxMenu menu;
468 
469  menu.Append( ID_CVPCB_CREATE_SCREENCMP, _( "View Footprint" ), _( "Show the current footprint in the footprint viewer" ) );
470 
471  PopupMenu( &menu );
472 }
473 
474 
475 void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
476 {
478  return;
479 
480  wxString libraryName;
481  COMPONENT* component = GetSelectedComponent();
482  libraryName = m_libListBox->GetSelectedLibrary();
483 
484  m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
486 
487  if( component && component->GetFPID().IsValid() )
489  else
491 
492  refreshAfterComponentSearch (component);
493 }
494 
495 
497 {
498  // Tell AuiMgr that objects are changed !
499  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
500  // (could be not the case when starting CvPcb
501  m_auimgr.Update();
502 
503  if( component == NULL )
504  {
505  DisplayStatus();
506  return;
507  }
508 
509  // Preview of the already assigned footprint.
510  // Find the footprint that was already chosen for this component and select it,
511  // but only if the selection is made from the component list or the library list.
512  // If the selection is made from the footprint list, do not change the current
513  // selected footprint.
514  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
515  {
516  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
517 
519 
520  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
521  {
522  wxString footprintName;
523  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
524  msg.Trim( true );
525  msg.Trim( false );
526  footprintName = msg.AfterFirst( wxChar( ' ' ) );
527 
528  if( module.Cmp( footprintName ) == 0 )
529  {
530  m_footprintListBox->SetSelection( ii, true );
531  break;
532  }
533  }
534 
536  CreateScreenCmp();
537  }
538 
540  DisplayStatus();
541 }
542 
543 void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
544 {
545  int option = 0;
546 
547  switch( event.GetId() )
548  {
551  break;
552 
555  break;
556 
559  break;
560 
564  break;
565  }
566 
567  if( event.IsChecked() )
568  m_filteringOptions |= option;
569  else
570  m_filteringOptions &= ~option;
571 
572  wxListEvent l_event;
573  OnSelectComponent( l_event );
574 }
575 
576 
577 void CVPCB_MAINFRAME::OnFilterFPbyKeywords( wxUpdateUIEvent& event )
578 {
580 }
581 
582 
583 void CVPCB_MAINFRAME::OnFilterFPbyPinCount( wxUpdateUIEvent& event )
584 {
586 }
587 
588 
589 void CVPCB_MAINFRAME::OnFilterFPbyLibrary( wxUpdateUIEvent& event )
590 {
592 }
593 
594 
595 void CVPCB_MAINFRAME::OnFilterFPbyKeyName( wxUpdateUIEvent& event )
596 {
598 }
599 
600 
601 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
602 {
603  // Called when changing the filter string in main toolbar.
604  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
605  // available footprints which match the filter
606 
608 
610  return;
611 
612  OnSelectFilteringFootprint( aEvent );
613 }
614 
615 
617 {
618  if( !m_initialized )
619  return;
620 
621  wxString filters, msg;
622  COMPONENT* component = GetSelectedComponent();
623 
625  {
626  msg.Empty();
627 
628  if( component )
629  {
630  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
631  {
632  if( msg.IsEmpty() )
633  msg += component->GetFootprintFilters()[ii];
634  else
635  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
636  }
637  }
638 
639  filters += _( "key words" ) + wxString::Format( wxT( " (%s)" ), msg );
640  }
641 
643  {
644  msg.Empty();
645 
646  if( component )
647  msg = wxString::Format( wxT( "%i" ), component->GetPinCount() );
648 
649  if( !filters.IsEmpty() )
650  filters += wxT( ", " );
651 
652  filters += _( "pin count" ) + wxString::Format( wxT( " (%s)" ), msg );
653  }
654 
656  {
658 
659  if( !filters.IsEmpty() )
660  filters += wxT( ", " );
661 
662  filters += _( "library" ) + wxString::Format( wxT( " (%s)" ), msg );
663  }
664 
666  {
667  if( !filters.IsEmpty() )
668  filters += wxT( ", " );
669 
670  filters += _( "search text" );
671  }
672 
673  if( filters.IsEmpty() )
674  msg = _( "No filtering" );
675  else
676  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
677 
678  msg << wxT( ": " ) << m_footprintListBox->GetCount();
679 
680  SetStatusText( msg );
681 
682 
683  msg.Empty();
684  wxString footprintName = GetSelectedFootprint();
685 
686  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
687 
688  if( module ) // can be NULL if no netlist loaded
689  {
690  msg = wxString::Format( _( "Description: %s; Key words: %s" ),
691  module->GetDescription(),
692  module->GetKeywords() );
693  }
694 
695  SetStatusText( msg, 1 );
696 }
697 
698 
700 {
701  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
702 
703  // Check if there are footprint libraries in the footprint library table.
704  if( !fptbl || !fptbl->GetLogicalLibs().size() )
705  {
706  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
707  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
708  return false;
709  }
710 
711  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
712 
713  m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
714 
716  {
718  }
719 
720  return true;
721 }
722 
723 
724 void CVPCB_MAINFRAME::SendMessageToEESCHEMA( bool aClearHighligntOnly )
725 {
726  if( m_netlist.IsEmpty() )
727  return;
728 
729  // clear highlight of previously selected components (if any):
730  // Selecting a non existing symbol clears any previously highlighted symbols
731  std::string packet = "$CLEAR: \"HIGHLIGHTED\"";
732 
733  if( Kiface().IsSingle() )
734  SendCommand( MSG_TO_SCH, packet.c_str() );
735  else
736  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
737 
738  if( aClearHighligntOnly )
739  return;
740 
741  int selection = m_compListBox->GetSelection();
742 
743  if ( selection < 0 ) // Nothing selected
744  return;
745 
746  if( m_netlist.GetComponent( selection ) == NULL )
747  return;
748 
749  // Now highlight the selected component:
750  COMPONENT* component = m_netlist.GetComponent( selection );
751 
752  packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
753 
754  if( Kiface().IsSingle() )
755  SendCommand( MSG_TO_SCH, packet.c_str() );
756  else
757  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
758 }
759 
760 
761 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
762 {
763  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
764  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
765 
766  m_netlist.Clear();
767 
768  try
769  {
770  netrdr.LoadNetlist();
771  }
772  catch( const IO_ERROR& ioe )
773  {
774  wxString msg = wxString::Format( _( "Error loading schematic.\n%s" ), ioe.What().GetData() );
775  wxMessageBox( msg, _( "Load Error" ), wxOK | wxICON_ERROR );
776  return 1;
777  }
778 
779  // We also remove footprint name if it is "$noname" because this is a dummy name,
780  // not the actual name of the footprint.
781  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
782  {
783  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
784  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
785  }
786 
787  // Sort components by reference:
789 
790  return 0;
791 }
792 
793 
795 {
797 
798  if( !fpframe )
799  {
800  fpframe = (DISPLAY_FOOTPRINTS_FRAME*) Kiway().Player( FRAME_CVPCB_DISPLAY, true, this );
801  fpframe->Show( true );
802  }
803  else
804  {
805  if( fpframe->IsIconized() )
806  fpframe->Iconize( false );
807 
808  // The display footprint window might be buried under some other
809  // windows, so CreateScreenCmp() on an existing window would not
810  // show any difference, leaving the user confused.
811  // So we want to put it to front, second after our CVPCB_MAINFRAME.
812  // We do this by a little dance of bringing it to front then the main
813  // frame back.
814  fpframe->Raise(); // Make sure that is visible.
815  Raise(); // .. but still we want the focus.
816  }
817 
818  fpframe->InitDisplay();
819 }
820 
821 
823 {
824  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
825 
826  if( m_footprintListBox == NULL )
827  {
829  wxDefaultPosition, wxDefaultSize );
830  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(),
831  wxFONTFAMILY_MODERN,
832  wxFONTSTYLE_NORMAL,
833  wxFONTWEIGHT_NORMAL ) );
834  }
835 
836  m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL,
838  DisplayStatus();
839 }
840 
841 
843 {
844  wxString msg;
845  COMPONENT* component;
846  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
847 
848  if( m_compListBox == NULL )
849  {
851  wxDefaultPosition, wxDefaultSize );
852  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(),
853  wxFONTFAMILY_MODERN,
854  wxFONTSTYLE_NORMAL,
855  wxFONTWEIGHT_NORMAL ) );
856  }
857 
859 
860  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
861  {
862  component = m_netlist.GetComponent( i );
863 
864  msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1,
865  GetChars( component->GetReference() ),
866  GetChars( component->GetValue() ),
867  GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
868  m_compListBox->m_ComponentList.Add( msg );
869  }
870 
871  if( m_compListBox->m_ComponentList.Count() )
872  {
873  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
874  m_compListBox->SetSelection( 0, true );
875  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
877  }
878 }
879 
880 
882 {
883  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
884 
885  if( m_libListBox == NULL )
886  {
888  wxDefaultPosition, wxDefaultSize );
889  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(),
890  wxFONTFAMILY_MODERN,
891  wxFONTSTYLE_NORMAL,
892  wxFONTWEIGHT_NORMAL ) );
893  }
894 
895  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
896 
897  if( tbl )
898  {
899  wxArrayString libNames;
900 
901  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
902 
903  for( unsigned ii = 0; ii < libNickNames.size(); ii++ )
904  libNames.Add( libNickNames[ii] );
905 
906  m_libListBox->SetLibraryList( libNames );
907  }
908 }
909 
910 
912 {
913  int selection = m_compListBox->GetSelection();
914 
915  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
916  return m_netlist.GetComponent( selection );
917 
918  return NULL;
919 }
920 
921 
923 {
924  // returns the Footprint Viewer frame, if exists, or NULL
925  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
926  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
927 }
928 
929 
931 {
932  // returns the LIB_ID of the selected footprint in footprint listview
933  // or a empty string
935 }
936 
937 
938 void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
939 {
940  wxASSERT( aNumber < 2 );
941 
942  if( aNumber == 1 )
943  m_statusLine2->SetLabel( aText );
944  else
945  m_statusLine1->SetLabel( aText );
946 }
947 
948 
949 void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
950 {
951  DIALOG_CONFIGURE_PATHS dlg( this, Prj().Get3DCacheManager()->GetResolver() );
952  dlg.ShowModal();
953 }
954 
955 
957 {
960  DisplayStatus();
961 }
962 
963 
965 {
966  const std::string& payload = mail.GetPayload();
967 
968  //DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
969 
970  switch( mail.Command() )
971  {
973  ReadNetListAndFpFiles( payload );
974  /* @todo
975  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
976  */
977  break;
978 
979  case MAIL_STATUS:
980  SetStatusText( payload, 1 );
981  break;
982 
983  default:
984  ; // ignore most
985  }
986 }
void ToFirstNA(wxCommandEvent &event)
void SetLibraryList(const wxArrayString &aList)
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:211
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
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
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
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
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)
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:155
void SetSelectedFootprint(const LIB_ID &aFPID)
This file is part of the common library.
COMPONENTS_LISTBOX * m_compListBox
void SendMessageToEESCHEMA(bool aClearHighligntOnly=false)
Function SendMessageToEESCHEMA Send a remote command to Eeschema via a socket, Commands are $PART: "r...
#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...
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:256
bool SendCommand(int service, const char *cmdline)
Definition: eda_dde.cpp:132
wxAuiManager m_auimgr
#define FOOTPRINTVIEWER_FRAME_NAME
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 IsValid() const
Definition: lib_id.h:171
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
bool empty() const
Definition: lib_id.h:186
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)
void AutomaticFootprintMatching(wxCommandEvent &event)
Called by the automatic association button Read *.equ files to try to find corresponding footprint fo...
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 GetKicadHelp(wxCommandEvent &event)
const char * c_str() const
Definition: utf8.h:107
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 LIB_ID & GetFPID() const
Definition: pcb_netlist.h:166
#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
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
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.
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.
bool IsSingle() const
Function IsSingle is this KIFACE_I running under single_top?
Definition: kiface_i.h:115
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
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
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.
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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.
const wxString & GetReference() const
Definition: pcb_netlist.h:151
void KiwayMailIn(KIWAY_EXPRESS &aEvent) override
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
wxString GetSelectedLibrary()
void GetKicadAbout(wxCommandEvent &event)
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
UTF8 Format() const
Definition: lib_id.cpp:237
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:200
wxString GetSelectedFootprint()
virtual void RedrawScreen(const wxPoint &aCenterPoint, bool aWarpPointer)
Redraw the entire screen area by updating the scroll bars and mouse pointer in order to have aCenterP...
void InitDisplay()
Function InitDisplay Refresh the full display for this frame: Set the title, the status line and redr...
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()
void OnEditEquFilesList(wxCommandEvent &aEvent)
Function OnEditEquFilesList envokes the equ files list edit dialog.
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)
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
int GetPinCount() const
Definition: pcb_netlist.h:184
defines the display data cache manager for 3D models
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:244
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:212
const wxString & GetValue() const
Definition: pcb_netlist.h:153
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:177
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
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:293
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...