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 Wayne Stambaugh <stambaughw@gmail.com>
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 
26 #include <bitmaps.h>
27 #include <confirm.h>
28 #include <eda_dde.h>
29 #include <fp_lib_table.h>
30 #include <kiface_i.h>
31 #include <kiway_express.h>
32 #include <macros.h>
34 #include <numeric>
35 #include <tool/action_toolbar.h>
36 #include <tool/common_control.h>
37 #include <tool/tool_dispatcher.h>
38 #include <tool/tool_manager.h>
40 #include <wx/statline.h>
41 
42 #include <cvpcb_association.h>
43 #include <cvpcb_id.h>
44 #include <cvpcb_mainframe.h>
45 #include <cvpcb_settings.h>
47 #include <listboxes.h>
48 #include <tools/cvpcb_actions.h>
50 #include <tools/cvpcb_control.h>
51 
52 wxSize const FRAME_MIN_SIZE_DU( 400, 300 );
53 wxSize const FRAME_DEFAULT_SIZE_DU( 500, 400 );
54 
55 #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
56 
57 
58 CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
59  KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, _( "Assign Footprints" ), wxDefaultPosition,
61 {
66  m_modified = false;
67  m_skipComponentSelect = false;
71  m_initialized = false;
72 
73  // Give an icon
74  wxIcon icon;
75  icon.CopyFromBitmap( KiBitmap( icon_cvpcb_xpm ) );
76  SetIcon( icon );
77 
78  SetAutoLayout( true );
79 
80  LoadSettings( config() );
81 
82  wxSize const frame_min( ConvertDialogToPixels( FRAME_MIN_SIZE_DU ) );
83 
84  SetSizeHints( frame_min );
85 
86  // Frame size and position
87  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
88 
89  setupTools();
92 
93  // Create list of available modules and components of the schematic
97 
98  m_auimgr.SetManagedWindow( this );
99 
100  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
101 
102  m_auimgr.AddPane( m_libListBox, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(1)
103  .Caption( _( "Footprint Libraries" ) )
104  .BestSize( (int) ( m_FrameSize.x * 0.20 ), m_FrameSize.y ) );
105 
106  m_auimgr.AddPane( m_compListBox, EDA_PANE().Palette().Name( "Components" ).Center().Layer(0)
107  .Caption( _( "Symbol : Footprint Assignments" ) ) );
108 
109  m_auimgr.AddPane( m_footprintListBox, EDA_PANE().Palette().Name( "Footprints" ).Right().Layer(1)
110  .Caption( _( "Filtered Footprints" ) )
111  .BestSize( (int) ( m_FrameSize.x * 0.30 ), m_FrameSize.y ) );
112 
113  // Build the bottom panel, to display 2 status texts and the buttons:
114  auto bottomPanel = new wxPanel( this );
115  auto panelSizer = new wxBoxSizer( wxVERTICAL );
116 
117  wxFlexGridSizer* fgSizerStatus = new wxFlexGridSizer( 3, 1, 0, 0 );
118  fgSizerStatus->SetFlexibleDirection( wxBOTH );
119  fgSizerStatus->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
120 
121  m_statusLine1 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
122  fgSizerStatus->Add( m_statusLine1, 0, 0, 5 );
123 
124  m_statusLine2 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
125  fgSizerStatus->Add( m_statusLine2, 0, 0, 5 );
126 
127  m_statusLine3 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
128  fgSizerStatus->Add( m_statusLine3, 0, wxBOTTOM, 3 );
129 
130  panelSizer->Add( fgSizerStatus, 1, wxEXPAND|wxLEFT, 2 );
131 
132  wxStaticLine* staticline1 = new wxStaticLine( bottomPanel );
133  panelSizer->Add( staticline1, 0, wxEXPAND, 5 );
134 
135  wxFont statusFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
136  statusFont.SetSymbolicSize( wxFONTSIZE_SMALL );
137  m_statusLine1->SetFont( statusFont );
138  m_statusLine2->SetFont( statusFont );
139  m_statusLine3->SetFont( statusFont );
140 
141  // Add buttons:
142  auto buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
143  auto sdbSizer = new wxStdDialogButtonSizer();
144 
145  m_saveAndContinue = new wxButton( bottomPanel, ID_SAVE_PROJECT,
146  _( "Apply, Save Schematic && Continue" ) );
147  buttonsSizer->Add( m_saveAndContinue, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 20 );
148 
149  auto sdbSizerOK = new wxButton( bottomPanel, wxID_OK );
150  sdbSizer->AddButton( sdbSizerOK );
151  auto sdbSizerCancel = new wxButton( bottomPanel, wxID_CANCEL );
152  sdbSizer->AddButton( sdbSizerCancel );
153  sdbSizer->Realize();
154 
155  buttonsSizer->Add( sdbSizer, 0, 0, 5 );
156  panelSizer->Add( buttonsSizer, 0, wxALIGN_RIGHT|wxALL, 5 );
157 
158  bottomPanel->SetSizer( panelSizer );
159  bottomPanel->Fit();
160 
161  sdbSizerOK->SetDefault();
162 
163  m_auimgr.AddPane( bottomPanel, EDA_PANE().HToolbar().Name( "Buttons" ).Bottom().Layer(6) );
164 
165  m_auimgr.Update();
166  m_initialized = true;
167 
168  // Connect Events
170 
171  // Start the main processing loop
172  m_toolManager->InvokeTool( "cvpcb.Control" );
173 
174  // Ensure the toolbars are sync'd properly so the filtering options display correct
175  SyncToolbars();
176 
177  SetShutdownBlockReason( _( "Symbol to footprint changes are unsaved" ) );
178 }
179 
180 
182 {
183  // Shutdown all running tools
184  if( m_toolManager )
186 
187  // Clean up the tool infrastructure
188  delete m_actions;
189  delete m_toolManager;
190  delete m_toolDispatcher;
191 
192  m_auimgr.UnInit();
193 }
194 
195 
197 {
198  // Create the manager
199  m_actions = new CVPCB_ACTIONS();
201  m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, this );
203 
204  // Register tools
209 
211 
212  // Even though these menus will open with the right-click, we treat them as a normal
213  // menu instead of a context menu because we don't care about their position and want
214  // to be able to tell the difference between a menu click and a hotkey activation.
215 
216  // Create the context menu for the component list box
217  m_componentContextMenu = new ACTION_MENU( false );
220  m_componentContextMenu->AppendSeparator();
224  m_componentContextMenu->AppendSeparator();
226 
227  // Create the context menu for the footprint list box
228  m_footprintContextMenu = new ACTION_MENU( false );
231 }
232 
234 {
235  // Connect the handlers to launch the context menus in the listboxes
236  m_footprintListBox->Bind( wxEVT_RIGHT_DOWN,
237  [this]( wxMouseEvent& )
238  {
239  PopupMenu( m_footprintContextMenu );
240  } );
241 
242  m_compListBox->Bind( wxEVT_RIGHT_DOWN,
243  [this]( wxMouseEvent& )
244  {
245  PopupMenu( m_componentContextMenu );
246  } );
247 
248  // Connect the handler for the save button
249  m_saveAndContinue->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
250  [this]( wxCommandEvent& )
251  {
252  // saveAssociations must be run immediately
254  } );
255 
256  // Connect the handlers for the ok/cancel buttons
257  Bind( wxEVT_BUTTON,
258  [this]( wxCommandEvent& )
259  {
260  // saveAssociations must be run immediately, before running Close( true )
262  Close( true );
263  }, wxID_OK );
264  Bind( wxEVT_BUTTON,
265  [this]( wxCommandEvent& )
266  {
267  Close( false );
268  }, wxID_CANCEL );
269 
270  // Connect the handlers for the close events
271  Bind( wxEVT_CLOSE_WINDOW, &CVPCB_MAINFRAME::OnCloseWindow, this );
272  Bind( wxEVT_MENU,
273  [this]( wxCommandEvent& )
274  {
275  Close( false );
276  }, wxID_CLOSE );
277  Bind( wxEVT_MENU,
278  [this]( wxCommandEvent& )
279  {
280  Close( false );
281  }, wxID_EXIT );
282 
283  // Toolbar events
285 
286  // Just skip the resize events
287  Bind( wxEVT_SIZE,
288  []( wxSizeEvent& aEvent )
289  {
290  aEvent.Skip();
291  } );
292 
293  // Attach the events to the tool dispatcher
296  Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
297 }
298 
299 
300 void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& aEvent )
301 {
302  if( m_modified )
303  {
304  // Shutdown blocks must be determined and vetoed as early as possible
305  if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION )
306  {
307  aEvent.Veto();
308  return;
309  }
310 
311  if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified. "
312  "Save changes?" ),
313  [&]()->bool { return SaveFootprintAssociation( false ); } ) )
314  {
315  aEvent.Veto();
316  return;
317  }
318  }
319 
320  // Close module display frame
322  GetFootprintViewerFrame()->Close( true );
323 
324  m_modified = false;
325 
326  // clear highlight symbol in schematic:
327  SendMessageToEESCHEMA( true );
328 
329  // Skip the close event. Looks like needed to have the close event sent to the
330  // root class EDA_BASE_FRAME, and save config
331  aEvent.Skip();
332 }
333 
334 
335 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
336 {
337  // Called when changing the filter string in main toolbar.
338  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_TEXT_PATTERN is set, update the list
339  // of available footprints which match the filter
340 
342 
344  return;
345 
346  wxListEvent l_event;
347  OnSelectComponent( l_event );
348 }
349 
350 
351 void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
352 {
354  return;
355 
356  wxString libraryName;
357  COMPONENT* component = GetSelectedComponent();
358  libraryName = m_libListBox->GetSelectedLibrary();
359 
360  m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
362 
363  if( component && component->GetFPID().IsValid() )
365  else
367 
368  refreshAfterComponentSearch( component );
369 }
370 
371 
373 {
375 
376  wxSize const frame_default( ConvertDialogToPixels( FRAME_DEFAULT_SIZE_DU ) );
377 
378  if( m_FrameSize == wxDefaultSize )
379  m_FrameSize = frame_default;
380 
381  auto cfg = static_cast<CVPCB_SETTINGS*>( aCfg );
382 
383  m_filteringOptions = cfg->m_FilterFootprint;
384 }
385 
386 
388 {
390 
391  auto cfg = static_cast<CVPCB_SETTINGS*>( aCfg );
392  cfg->m_FilterFootprint = m_filteringOptions;
393 }
394 
395 
397 {
398  if( m_undoList.size() == 0 )
399  return;
400 
401  CVPCB_UNDO_REDO_ENTRIES redoEntries;
402  CVPCB_UNDO_REDO_ENTRIES curEntry = m_undoList.back();
403  m_undoList.pop_back();
404 
405  // Iterate over the entries to undo
406  for( const auto& assoc : curEntry )
407  {
408  AssociateFootprint( assoc, true, false );
409  redoEntries.emplace_back( assoc.Reverse() );
410  }
411 
412  // Add the redo entries to the redo stack
413  m_redoList.emplace_back( redoEntries );
414 }
415 
416 
418 {
419  if( m_redoList.size() == 0 )
420  return;
421 
422  CVPCB_UNDO_REDO_ENTRIES curEntry = m_redoList.back();
423  m_redoList.pop_back();
424 
425  // Iterate over the entries to undo
426  bool firstAssoc = true;
427  for( const auto& assoc : curEntry )
428  {
429  AssociateFootprint( assoc, firstAssoc );
430  firstAssoc = false;
431  }
432 }
433 
434 
436  bool aNewEntry, bool aAddUndoItem )
437 {
438  if( m_netlist.IsEmpty() )
439  return;
440 
441  COMPONENT* component = m_netlist.GetComponent( aAssociation.GetComponentIndex() );
442 
443  if( component == NULL )
444  return;
445 
446  LIB_ID fpid = aAssociation.GetNewFootprint();
447  LIB_ID oldFpid = component->GetFPID();
448 
449  // Test for validity of the requested footprint
450  if( !fpid.empty() && !fpid.IsValid() )
451  {
452  wxString msg =
453  wxString::Format( _( "\"%s\" is not a valid footprint." ), fpid.Format().wx_str() );
454  DisplayErrorMessage( this, msg );
455  return;
456  }
457 
458  // Set the new footprint
459  component->SetFPID( fpid );
460 
461  // create the new component description and set it
462  wxString description = wxString::Format( CMP_FORMAT,
463  aAssociation.GetComponentIndex() + 1,
464  component->GetReference(),
465  component->GetValue(),
466  component->GetFPID().Format().wx_str() );
467  m_compListBox->SetString( aAssociation.GetComponentIndex(), description );
468 
469  // Mark the data as being modified
470  m_modified = true;
471 
472  // Update the statusbar and refresh the list
473  DisplayStatus();
474  m_compListBox->Refresh();
475 
476  if( !aAddUndoItem )
477  return;
478 
479  // Update the undo list
480  if ( aNewEntry )
481  {
482  // Create a new entry for this association
483  CVPCB_UNDO_REDO_ENTRIES newEntry;
484  newEntry.emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(), oldFpid,
485  aAssociation.GetNewFootprint() ) );
486  m_undoList.emplace_back( newEntry );
487 
488  // Clear the redo list
489  m_redoList.clear();
490  }
491  else
492  m_undoList.back().emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(),
493  oldFpid, aAssociation.GetNewFootprint() ) );
494 
495 }
496 
497 
498 bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
499 {
500  return true;
501 }
502 
503 
505 {
506  // Tell AuiMgr that objects are changed !
507  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
508  // (could be not the case when starting CvPcb
509  m_auimgr.Update();
510 
511  if( component == NULL )
512  {
513  DisplayStatus();
514  return;
515  }
516 
517  // Preview of the already assigned footprint.
518  // Find the footprint that was already chosen for this component and select it,
519  // but only if the selection is made from the component list or the library list.
520  // If the selection is made from the footprint list, do not change the current
521  // selected footprint.
522  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
523  {
524  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
525 
527 
528  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
529  {
530  wxString footprintName;
531  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
532  msg.Trim( true );
533  msg.Trim( false );
534  footprintName = msg.AfterFirst( wxChar( ' ' ) );
535 
536  if( module.Cmp( footprintName ) == 0 )
537  {
538  m_footprintListBox->SetSelection( ii, true );
539  break;
540  }
541  }
542 
545  }
546 
548  DisplayStatus();
549 }
550 
551 
554 {
555  int option = aFilter;
556 
557  // Extract the current search patten when needed
560 
561  // Apply the filter accordingly
562  switch( aAction )
563  {
565  m_filteringOptions &= ~option;
566  break;
567 
569  m_filteringOptions |= option;
570  break;
571 
573  m_filteringOptions ^= option;
574  break;
575  }
576 
577  wxListEvent l_event;
578  OnSelectComponent( l_event );
579 }
580 
581 
583 {
584  if( !m_initialized )
585  return;
586 
587  wxString filters, msg;
588  COMPONENT* component = GetSelectedComponent();
589 
591  {
592  msg.Empty();
593 
594  if( component )
595  {
596  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
597  {
598  if( msg.IsEmpty() )
599  msg += component->GetFootprintFilters()[ii];
600  else
601  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
602  }
603  }
604 
605  filters += _( "key words" ) + wxString::Format( wxT( " (%s)" ), msg );
606  }
607 
609  {
610  msg.Empty();
611 
612  if( component )
613  msg = wxString::Format( wxT( "%i" ), component->GetPinCount() );
614 
615  if( !filters.IsEmpty() )
616  filters += wxT( ", " );
617 
618  filters += _( "pin count" ) + wxString::Format( wxT( " (%s)" ), msg );
619  }
620 
622  {
624 
625  if( !filters.IsEmpty() )
626  filters += wxT( ", " );
627 
628  filters += _( "library" ) + wxString::Format( wxT( " (%s)" ), msg );
629  }
630 
632  {
633  if( !filters.IsEmpty() )
634  filters += wxT( ", " );
635 
636  filters += _( "search text" );
637  }
638 
639  if( filters.IsEmpty() )
640  msg = _( "No filtering" );
641  else
642  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
643 
644  msg << wxT( ": " ) << m_footprintListBox->GetCount();
645 
646  SetStatusText( msg );
647 
648 
649  msg.Empty();
650  wxString footprintName = GetSelectedFootprint();
651 
652  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
653 
654  if( module ) // can be NULL if no netlist loaded
655  {
656  msg = wxString::Format( _( "Description: %s; Key words: %s" ),
657  module->GetDescription(),
658  module->GetKeywords() );
659  }
660 
661  SetStatusText( msg, 1 );
662 
663  msg.Empty();
664  wxString lib;
665 
666  // Choose the footprint to get the information on
667  if( module )
668  {
669  // Use the footprint in the footprint viewer
670  lib = module->GetLibNickname();
671  }
673  {
674  // Use the footprint of the selected component
675  if( component )
676  lib = component->GetFPID().GetLibNickname();
677  }
679  {
680  // Use the library that is selected
682  }
683 
684  // Extract the library information
685  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
686 
687  if( fptbl->HasLibrary( lib ) )
688  msg = wxString::Format( _( "Library location: %s" ), fptbl->GetFullURI( lib ) );
689  else
690  msg = wxString::Format( _( "Library location: unknown" ) );
691 
692  SetStatusText( msg, 2 );
693 }
694 
695 
697 {
698  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
699 
700  // Check if there are footprint libraries in the footprint library table.
701  if( !fptbl || !fptbl->GetLogicalLibs().size() )
702  {
703  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
704  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
705  return false;
706  }
707 
708  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
709 
710  m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
711 
713  {
715  }
716 
717  return true;
718 }
719 
720 
721 void CVPCB_MAINFRAME::SendMessageToEESCHEMA( bool aClearHighligntOnly )
722 {
723  if( m_netlist.IsEmpty() )
724  return;
725 
726  // clear highlight of previously selected components (if any):
727  // Selecting a non existing symbol clears any previously highlighted symbols
728  std::string packet = "$CLEAR: \"HIGHLIGHTED\"";
729 
730  if( Kiface().IsSingle() )
731  SendCommand( MSG_TO_SCH, packet.c_str() );
732  else
733  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
734 
735  if( aClearHighligntOnly )
736  return;
737 
738  int selection = m_compListBox->GetSelection();
739 
740  if ( selection < 0 ) // Nothing selected
741  return;
742 
743  if( m_netlist.GetComponent( selection ) == NULL )
744  return;
745 
746  // Now highlight the selected component:
747  COMPONENT* component = m_netlist.GetComponent( selection );
748 
749  packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
750 
751  if( Kiface().IsSingle() )
752  SendCommand( MSG_TO_SCH, packet.c_str() );
753  else
754  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
755 }
756 
757 
758 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
759 {
760  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
761  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
762 
763  m_netlist.Clear();
764 
765  try
766  {
767  netrdr.LoadNetlist();
768  }
769  catch( const IO_ERROR& ioe )
770  {
771  wxString msg = wxString::Format( _( "Error loading schematic.\n%s" ),
772  ioe.What().GetData() );
773  wxMessageBox( msg, _( "Load Error" ), wxOK | wxICON_ERROR );
774  return 1;
775  }
776 
777  // We also remove footprint name if it is "$noname" because this is a dummy name,
778  // not the actual name of the footprint.
779  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
780  {
781  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
782  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
783  }
784 
785  // Sort components by reference:
787 
788  return 0;
789 }
790 
791 
793 {
794  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
795 
796  if( m_footprintListBox == NULL )
797  {
799  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
800  wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
801  }
802 
805  DisplayStatus();
806 }
807 
808 
810 {
811  wxString msg;
812  COMPONENT* component;
813  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
814 
815  if( m_compListBox == NULL )
816  {
818  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
819  wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
820  }
821 
823 
824  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
825  {
826  component = m_netlist.GetComponent( i );
827 
828  msg.Printf( CMP_FORMAT,
829  m_compListBox->GetCount() + 1,
830  component->GetReference(),
831  component->GetValue(),
832  component->GetFPID().Format().wx_str() );
833  m_compListBox->m_ComponentList.Add( msg );
834  }
835 
836  if( m_compListBox->m_ComponentList.Count() )
837  {
838  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
839  m_compListBox->SetSelection( 0, true );
840  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
842  }
843 }
844 
845 
847 {
848  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
849 
850  if( m_libListBox == NULL )
851  {
853  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
854  wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
855  }
856 
857  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
858 
859  if( tbl )
860  {
861  wxArrayString libNames;
862 
863  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
864 
865  for( const wxString& libNickName : libNickNames )
866  libNames.Add( libNickName );
867 
868  m_libListBox->SetLibraryList( libNames );
869  }
870 }
871 
872 
874 {
875  int selection = m_compListBox->GetSelection();
876 
877  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
878  return m_netlist.GetComponent( selection );
879 
880  return NULL;
881 }
882 
883 
884 void CVPCB_MAINFRAME::SetSelectedComponent( int aIndex, bool aSkipUpdate )
885 {
886  m_skipComponentSelect = aSkipUpdate;
887 
888  if( aIndex < 0 )
889  {
891  }
892  else if( aIndex < m_compListBox->GetCount() )
893  {
895  m_compListBox->SetSelection( aIndex );
897  }
898 
899  m_skipComponentSelect = false;
900 }
901 
902 
903 std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
904  CVPCB_MAINFRAME::CRITERIA aCriteria )
905 {
906  std::vector<unsigned int> idx;
907 
908  // Make sure a netlist has been loaded and the box has contents
909  if( m_netlist.IsEmpty() || m_compListBox->GetCount() == 0 )
910  return idx;
911 
912  switch( aCriteria )
913  {
915  idx.resize( m_netlist.GetCount() );
916  std::iota( idx.begin(), idx.end(), 0 );
917  break;
918 
920  {
921  // Check to see if anything is selected
922  if( m_compListBox->GetSelectedItemCount() < 1 )
923  break;
924 
925  // Get the components
926  int lastIdx = m_compListBox->GetFirstSelected();
927  idx.emplace_back( lastIdx );
928 
929  lastIdx = m_compListBox->GetNextSelected( lastIdx );
930  while( lastIdx > 0 )
931  {
932  idx.emplace_back( lastIdx );
933  lastIdx = m_compListBox->GetNextSelected( lastIdx );
934  }
935  break;
936  }
938  for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
939  {
940  if( m_netlist.GetComponent( i )->GetFPID().empty() )
941  idx.emplace_back( i );
942  }
943  break;
944 
946  for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
947  {
948  if( !m_netlist.GetComponent( i )->GetFPID().empty() )
949  idx.emplace_back( i );
950  }
951  break;
952 
953  default:
954  wxASSERT_MSG( false, "Invalid component selection criteria" );
955  }
956 
957  return idx;
958 }
959 
960 
962 {
963  // returns the Footprint Viewer frame, if exists, or NULL
964  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
965  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
966 }
967 
968 
970 {
971  if( m_libListBox->HasFocus() )
973  else if( m_compListBox->HasFocus() )
975  else if( m_footprintListBox->HasFocus() )
977 
979 }
980 
981 
983 {
984  if( m_libListBox->HasFocus() )
985  return m_libListBox;
986  else if( m_compListBox->HasFocus() )
987  return m_compListBox;
988  else if( m_footprintListBox->HasFocus() )
989  return m_footprintListBox;
990 
991  return nullptr;
992 }
993 
994 
996 {
997  switch( aLB )
998  {
999  case CVPCB_MAINFRAME::CONTROL_LIBRARY: m_libListBox->SetFocus(); break;
1000  case CVPCB_MAINFRAME::CONTROL_COMPONENT: m_compListBox->SetFocus(); break;
1001  case CVPCB_MAINFRAME::CONTROL_FOOTPRINT: m_footprintListBox->SetFocus(); break;
1002  default: break;
1003  }
1004 }
1005 
1006 
1008 {
1009  // returns the LIB_ID of the selected footprint in footprint listview
1010  // or a empty string
1012 }
1013 
1014 
1015 void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
1016 {
1017  switch( aNumber )
1018  {
1019  case 0: m_statusLine1->SetLabel( aText ); break;
1020  case 1: m_statusLine2->SetLabel( aText ); break;
1021  case 2: m_statusLine3->SetLabel( aText ); break;
1022  default: wxFAIL_MSG( "Invalid status row number" ); break;
1023  }
1024 }
1025 
1026 
1028 {
1030  ReCreateHToolbar();
1031  DisplayStatus();
1032 }
1033 
1034 
1036 {
1037  const std::string& payload = mail.GetPayload();
1038 
1039  //DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
1040 
1041  switch( mail.Command() )
1042  {
1043  case MAIL_EESCHEMA_NETLIST:
1044  ReadNetListAndFpFiles( payload );
1045  /* @todo
1046  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
1047  */
1048  break;
1049 
1050  default:
1051  ; // ignore most
1052  }
1053 }
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
static TOOL_ACTION showFootprintViewer
Open the footprint viewer.
Definition: cvpcb_actions.h:52
void SetLibraryList(const wxArrayString &aList)
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition: confirm.cpp:201
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:59
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
const BITMAP_OPAQUE icon_cvpcb_xpm[1]
Definition: icon_cvpcb.cpp:158
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
CONTROL_TYPE
The type of the controls present in the application.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
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
void SetShutdownBlockReason(const wxString &reason)
Sets the block reason why the window/application is preventing OS shutdown.
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:62
KICAD_NETLIST_READER read the new s-expression based KiCad netlist format.
CVPCB_FILTER_ACTION
The action to apply to a footprint filter when it is modified.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
FOOTPRINT_INFO * GetModuleInfo(const wxString &aFootprintId)
Get info for a module by id.
ACTION_MENU * m_footprintContextMenu
#define CMP_FORMAT
The print format to display a schematic component line.
wxControl * GetFocusedControlObject()
Get a pointer to the currently focused control.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Saves common frame parameters to a configuration data file.
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:153
void SetSelectedFootprint(const LIB_ID &aFPID)
ACTION_MENU.
Definition: action_menu.h:43
This file is part of the common library.
wxString GetLibNickname() const override
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 UndoAssociation()
Undo the most recent associations that were performed.
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
void AssociateFootprint(const CVPCB_ASSOCIATION &aAssociation, bool aNewEntry=true, bool aAddUndoItem=true)
Associate a footprint with a specific component in the list.
void setupEventHandlers()
Setup event handlers.
void SetSelection(int index, bool State=true)
void DisplayErrors(wxTopLevelWindow *aCaller=NULL)
ACTIONS * m_actions
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
wxString GetDescription() override
LIB_ID GetNewFootprint() const
Get the new footprint to associate to the component.
void RedoAssociation()
Redo the most recently undone association.
int ReadSchematicNetlist(const std::string &aNetlist)
Function ReadSchematicNetlist read the netlist (.net) file built on the fly by Eeschema.
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:254
void SetFocusedControl(CVPCB_MAINFRAME::CONTROL_TYPE aControl)
Set the focus to a specific control.
bool SendCommand(int service, const char *cmdline)
Definition: eda_dde.cpp:132
wxAuiManager m_auimgr
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
#define FOOTPRINTVIEWER_FRAME_NAME
wxStaticText * m_statusLine3
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
bool IsValid() const
Definition: lib_id.h:171
void SyncToolbars() override
Syncronize the toolbar state with the current tool state.
bool LoadFootprintFiles()
Function LoadFootprintFiles reads the list of footprint (*.mod files) and generate the list of footpr...
bool empty() const
Definition: lib_id.h:186
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.
DISPLAY_FOOTPRINTS_FRAME is used to display footprints.
This file contains miscellaneous commonly used macros and functions.
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
const char * c_str() const
Definition: utf8.h:107
void SortByReference()
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
unsigned int GetComponentIndex() const
Get the index of the component to modify the association of.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
TOOL_MANAGER.
Definition: tool_manager.h:50
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
static TOOL_ACTION copy
Definition: actions.h:70
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.
virtual void LoadNetlist() override
Function LoadNetlist loads the contents of the netlist file into aNetlist.
void refreshAfterComponentSearch(COMPONENT *component)
FP_FILTER_T
Filter setting constants.
Definition: listboxes.h:94
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:75
#define NULL
bool IsSingle() const
Function IsSingle is this KIFACE_I running under single_top?
Definition: kiface_i.h:117
void UpdateWidth(int aLine=-1)
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Function OpenProjectFiles is abstract, and opens a project or set of files given by aFileList.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void SetSelectedComponent(int aIndex, bool aSkipUpdate=false)
Set the currently selected component in the components listbox.
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.
ACTION_TOOLBAR * m_mainToolBar
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxString GetFullURI(const wxString &aLibNickname, bool aExpandEnvVars=true) const
Return the full URI of the library mapped to aLibNickname.
virtual void DispatchWxEvent(wxEvent &aEvent)
Function DispatchWxEvent() Processes wxEvents (mostly UI events), translates them to TOOL_EVENTs,...
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
wxSize const FRAME_DEFAULT_SIZE_DU(500, 400)
const wxString & GetReference() const
Definition: pcb_netlist.h:149
void KiwayMailIn(KIWAY_EXPRESS &aEvent) override
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
wxString GetSelectedLibrary()
static TOOL_ACTION cut
Definition: actions.h:69
No controls have focus.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
ACTION_MENU * m_componentContextMenu
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
void SetStatusText(const wxString &aText, int aNumber=0) override
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
CRITERIA
Criteria to use to identify sets of components.
static TOOL_ACTION deleteAssoc
Definition: cvpcb_actions.h:66
#define KICAD_DEFAULT_DRAWFRAME_STYLE
void ReCreateMenuBar() override
Recreates the menu bar.
wxSize const FRAME_MIN_SIZE_DU(400, 300)
void BuildFOOTPRINTS_LISTBOX()
CVPCB_UNDO_REDO_LIST m_undoList
CVPCB_ACTIONS.
Definition: cvpcb_actions.h:40
wxString OnGetItemText(long item, long column) const override
Function OnGetItemText this overloaded function MUST be provided for the wxLC_VIRTUAL mode because re...
static TOOL_ACTION saveAssociations
Management actions.
Definition: cvpcb_actions.h:59
COMMON_CONTROL.
TOOL_DISPATCHER * m_toolDispatcher
Specialization of the wxAuiPaneInfo class for KiCad panels.
LIBRARY_LISTBOX * m_libListBox
UTF8 Format() const
Definition: lib_id.cpp:237
TOOL_DISPATCHER.
COMPONENT is used to store components and all of their related information found in a netlist.
Definition: pcb_netlist.h:80
void SetSelection(int index, bool State=true)
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:427
wxStaticText * m_statusLine2
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:263
void OnCloseWindow(wxCloseEvent &Event)
OnCloseWindow.
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:427
wxArrayString m_ComponentList
Definition: listboxes.h:194
wxString GetSelectedFootprint()
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:248
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:101
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
virtual void DispatchWxCommand(wxCommandEvent &aEvent)
Function DispatchWxCommand() Processes wxCommands (mostly menu related events) and runs appropriate a...
#define _(s)
Definition: 3d_actions.cpp:33
CVPCB_MAINFRAME(KIWAY *aKiway, wxWindow *aParent)
CVPCB_UNDO_REDO_LIST m_redoList
void SetString(unsigned linecount, const wxString &text)
Toggle the filter state.
COMPONENT * GetSelectedComponent()
Get the selected component from the component listbox.
wxString wx_str() const
Definition: utf8.cpp:51
FOOTPRINTS_LISTBOX * m_footprintListBox
unsigned GetErrorCount() const
int GetPinCount() const
Definition: pcb_netlist.h:182
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, EDA_BASE_FRAME *aFrame)
Sets the work environment (model, view, view controls and the parent window).
A class to define a footprint association to be made in cvpcb.
wxString GetKeywords()
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:242
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...
const wxString & GetValue() const
Definition: pcb_netlist.h:151
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:175
PCB<->SCH, CVPCB->SCH cross-probing.
Definition: mail_type.h:39
CVPCB_MAINFRAME::CONTROL_TYPE GetFocusedControl()
Find out which control currently has focus.
void SetFootprintFilter(FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction)
Function SetFootprintFilter Set a filter criteria to either on/off or toggle the criteria.
std::vector< unsigned int > GetComponentIndices(CVPCB_MAINFRAME::CRITERIA aCriteria=CVPCB_MAINFRAME::ALL_COMPONENTS)
Get the indices for all the components meeting the specified criteria in the components listbox.
void OnEnterFilteringText(wxCommandEvent &event)
Function OnEnterFilteringText Is called each time the text of m_tcFilterString is changed.
TOOL_MANAGER * m_toolManager
void InitTools()
Function InitTools() Initializes all registered tools.
Not associated components.
MAIL_T Command()
Function Command returns the MAIL_T associated with this mail.
Definition: kiway_express.h:52
virtual APP_SETTINGS_BASE * config()
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
virtual void ShowChangedLanguage()
Redraw 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
void DisplayStatus()
Function DisplayStatus updates the information displayed on the status bar at bottom of the main fram...
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
CVPCB_CONTROL.
Definition: cvpcb_control.h:35
static TOOL_ACTION paste
Definition: actions.h:71
wxButton * m_saveAndContinue
void setupTools()
Setup the tool system for the CVPCB main frame.
wxStaticText * m_statusLine1
void RegisterTool(TOOL_BASE *aTool)
Function RegisterTool() Adds a tool to the manager set and sets it up.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
std::vector< CVPCB_ASSOCIATION > CVPCB_UNDO_REDO_ENTRIES
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...