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 
483  if( component && component->GetFPID().IsValid() )
485  else
487 
488  refreshAfterComponentSearch (component);
489 }
490 
491 
493 {
494  // Tell AuiMgr that objects are changed !
495  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
496  // (could be not the case when starting CvPcb
497  m_auimgr.Update();
498 
499  if( component == NULL )
500  {
501  DisplayStatus();
502  return;
503  }
504 
505  // Preview of the already assigned footprint.
506  // Find the footprint that was already chosen for this component and select it,
507  // but only if the selection is made from the component list or the library list.
508  // If the selection is made from the footprint list, do not change the current
509  // selected footprint.
510  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
511  {
512  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
513 
515 
516  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
517  {
518  wxString footprintName;
519  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
520  msg.Trim( true );
521  msg.Trim( false );
522  footprintName = msg.AfterFirst( wxChar( ' ' ) );
523 
524  if( module.Cmp( footprintName ) == 0 )
525  {
526  m_footprintListBox->SetSelection( ii, true );
527  break;
528  }
529  }
530 
532  CreateScreenCmp();
533  }
534 
536  DisplayStatus();
537 }
538 
539 void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
540 {
541  int option = 0;
542 
543  switch( event.GetId() )
544  {
545  case ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST:
547  break;
548 
549  case ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST:
551  break;
552 
553  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST:
555  break;
556 
557  case ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME:
560  break;
561  }
562 
563  if( event.IsChecked() )
564  m_filteringOptions |= option;
565  else
566  m_filteringOptions &= ~option;
567 
568  wxListEvent l_event;
569  OnSelectComponent( l_event );
570 }
571 
572 
573 void CVPCB_MAINFRAME::OnFilterFPbyKeywords( wxUpdateUIEvent& event )
574 {
576 }
577 
578 
579 void CVPCB_MAINFRAME::OnFilterFPbyPinCount( wxUpdateUIEvent& event )
580 {
582 }
583 
584 
585 void CVPCB_MAINFRAME::OnFilterFPbyLibrary( wxUpdateUIEvent& event )
586 {
588 }
589 
590 
591 void CVPCB_MAINFRAME::OnFilterFPbyKeyName( wxUpdateUIEvent& event )
592 {
594 }
595 
596 
597 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
598 {
599  // Called when changing the filter string in main toolbar.
600  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
601  // available footprints which match the filter
602 
604 
606  return;
607 
608  OnSelectFilteringFootprint( aEvent );
609 }
610 
611 
613 {
614  if( !m_initialized )
615  return;
616 
617  wxString filters, msg;
618  COMPONENT* component = GetSelectedComponent();
619 
621  {
622  msg.Empty();
623 
624  if( component )
625  {
626  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
627  {
628  if( msg.IsEmpty() )
629  msg += component->GetFootprintFilters()[ii];
630  else
631  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
632  }
633  }
634 
635  filters += _( "key words" ) + wxString::Format( wxT( " (%s)" ), msg );
636  }
637 
639  {
640  msg.Empty();
641 
642  if( component )
643  msg = wxString::Format( wxT( "%i" ), component->GetPinCount() );
644 
645  if( !filters.IsEmpty() )
646  filters += wxT( ", " );
647 
648  filters += _( "pin count" ) + wxString::Format( wxT( " (%s)" ), msg );
649  }
650 
652  {
654 
655  if( !filters.IsEmpty() )
656  filters += wxT( ", " );
657 
658  filters += _( "library" ) + wxString::Format( wxT( " (%s)" ), msg );
659  }
660 
662  {
663  if( !filters.IsEmpty() )
664  filters += wxT( ", " );
665 
666  filters += _( "search text" );
667  }
668 
669  if( filters.IsEmpty() )
670  msg = _( "No filtering" );
671  else
672  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
673 
674  msg << wxT( ": " ) << m_footprintListBox->GetCount();
675 
676  SetStatusText( msg );
677 
678 
679  msg.Empty();
680  wxString footprintName = GetSelectedFootprint();
681 
682  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
683 
684  if( module ) // can be NULL if no netlist loaded
685  {
686  msg = wxString::Format( _( "Description: %s; Key words: %s" ),
687  module->GetDescription(),
688  module->GetKeywords() );
689  }
690 
691  SetStatusText( msg, 1 );
692 }
693 
694 
696 {
697  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
698 
699  // Check if there are footprint libraries in the footprint library table.
700  if( !fptbl || !fptbl->GetLogicalLibs().size() )
701  {
702  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
703  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
704  return false;
705  }
706 
707  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
708 
709  m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
710 
712  {
714  }
715 
716  return true;
717 }
718 
719 
721 {
722  if( m_netlist.IsEmpty() )
723  return;
724 
725  int selection = m_compListBox->GetSelection();
726 
727  if ( selection < 0 )
728  selection = 0;
729 
730  if( m_netlist.GetComponent( selection ) == NULL )
731  return;
732 
733  COMPONENT* component = m_netlist.GetComponent( selection );
734 
735  std::string packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
736 
737  if( Kiface().IsSingle() )
738  SendCommand( MSG_TO_SCH, packet.c_str() );
739  else
740  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
741 }
742 
743 
744 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
745 {
746  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
747  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
748 
749  m_netlist.Clear();
750 
751  try
752  {
753  netrdr.LoadNetlist();
754  }
755  catch( const IO_ERROR& ioe )
756  {
757  wxString msg = wxString::Format( _( "Error loading schematic.\n%s" ), ioe.What().GetData() );
758  wxMessageBox( msg, _( "Load Error" ), wxOK | wxICON_ERROR );
759  return 1;
760  }
761 
762  // We also remove footprint name if it is "$noname" because this is a dummy name,
763  // not the actual name of the footprint.
764  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
765  {
766  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
767  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
768  }
769 
770  // Sort components by reference:
772 
773  return 0;
774 }
775 
776 
778 {
780 
781  if( !fpframe )
782  {
783  fpframe = (DISPLAY_FOOTPRINTS_FRAME*) Kiway().Player( FRAME_CVPCB_DISPLAY, true, this );
784  fpframe->Show( true );
785  }
786  else
787  {
788  if( fpframe->IsIconized() )
789  fpframe->Iconize( false );
790 
791  // The display footprint window might be buried under some other
792  // windows, so CreateScreenCmp() on an existing window would not
793  // show any difference, leaving the user confused.
794  // So we want to put it to front, second after our CVPCB_MAINFRAME.
795  // We do this by a little dance of bringing it to front then the main
796  // frame back.
797  fpframe->Raise(); // Make sure that is visible.
798  Raise(); // .. but still we want the focus.
799  }
800 
801  fpframe->InitDisplay();
802 }
803 
804 
806 {
807  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
808 
809  if( m_footprintListBox == NULL )
810  {
812  wxDefaultPosition, wxDefaultSize );
813  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(),
814  wxFONTFAMILY_MODERN,
815  wxFONTSTYLE_NORMAL,
816  wxFONTWEIGHT_NORMAL ) );
817  }
818 
819  m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL,
821  DisplayStatus();
822 }
823 
824 
826 {
827  wxString msg;
828  COMPONENT* component;
829  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
830 
831  if( m_compListBox == NULL )
832  {
834  wxDefaultPosition, wxDefaultSize );
835  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(),
836  wxFONTFAMILY_MODERN,
837  wxFONTSTYLE_NORMAL,
838  wxFONTWEIGHT_NORMAL ) );
839  }
840 
842 
843  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
844  {
845  component = m_netlist.GetComponent( i );
846 
847  msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1,
848  GetChars( component->GetReference() ),
849  GetChars( component->GetValue() ),
850  GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
851  m_compListBox->m_ComponentList.Add( msg );
852  }
853 
854  if( m_compListBox->m_ComponentList.Count() )
855  {
856  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
857  m_compListBox->SetSelection( 0, true );
858  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
860  }
861 }
862 
863 
865 {
866  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
867 
868  if( m_libListBox == NULL )
869  {
871  wxDefaultPosition, wxDefaultSize );
872  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(),
873  wxFONTFAMILY_MODERN,
874  wxFONTSTYLE_NORMAL,
875  wxFONTWEIGHT_NORMAL ) );
876  }
877 
878  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
879 
880  if( tbl )
881  {
882  wxArrayString libNames;
883 
884  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
885 
886  for( unsigned ii = 0; ii < libNickNames.size(); ii++ )
887  libNames.Add( libNickNames[ii] );
888 
889  m_libListBox->SetLibraryList( libNames );
890  }
891 }
892 
893 
895 {
896  int selection = m_compListBox->GetSelection();
897 
898  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
899  return m_netlist.GetComponent( selection );
900 
901  return NULL;
902 }
903 
904 
906 {
907  // returns the Footprint Viewer frame, if exists, or NULL
908  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
909  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
910 }
911 
912 
914 {
915  // returns the LIB_ID of the selected footprint in footprint listview
916  // or a empty string
918 }
919 
920 
921 void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
922 {
923  wxASSERT( aNumber < 2 );
924 
925  if( aNumber == 1 )
926  m_statusLine2->SetLabel( aText );
927  else
928  m_statusLine1->SetLabel( aText );
929 }
930 
931 
932 void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
933 {
934  DIALOG_CONFIGURE_PATHS dlg( this, Prj().Get3DCacheManager()->GetResolver() );
935  dlg.ShowModal();
936 }
937 
938 
940 {
943  DisplayStatus();
944 }
945 
946 
948 {
949  const std::string& payload = mail.GetPayload();
950 
951  //DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
952 
953  switch( mail.Command() )
954  {
956  ReadNetListAndFpFiles( payload );
957  /* @todo
958  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
959  */
960  break;
961 
962  case MAIL_STATUS:
963  SetStatusText( payload, 1 );
964  break;
965 
966  default:
967  ; // ignore most
968  }
969 }
void ToFirstNA(wxCommandEvent &event)
bool IsValid() const
Definition: lib_id.h:171
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:213
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
void SetSelectedFootprint(const LIB_ID &aFPID)
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:200
wxString GetSelectedFootprint()
virtual void RedrawScreen(const wxPoint &aCenterPoint, bool aWarpPointer)
Function RedrawScreen redraws the entire screen area by updating the scroll bars and mouse pointer in...
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:295
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...