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 <kiplatform/ui.h>
48 #include <listboxes.h>
49 #include <tools/cvpcb_actions.h>
51 #include <tools/cvpcb_control.h>
52 
53 #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
54 
55 
56 CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
57  KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, _( "Assign Footprints" ), wxDefaultPosition,
59 {
64  m_modified = false;
65  m_skipComponentSelect = false;
69  m_initialized = false;
70 
71  // Give an icon
72  wxIcon icon;
73  icon.CopyFromBitmap( KiBitmap( icon_cvpcb_xpm ) );
74  SetIcon( icon );
75 
76  SetAutoLayout( true );
77 
78  LoadSettings( config() );
79 
80  setupTools();
83 
84  // Create list of available modules and components of the schematic
88 
89  m_auimgr.SetManagedWindow( this );
90 
91  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
92 
93  m_auimgr.AddPane( m_libListBox, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(1)
94  .Caption( _( "Footprint Libraries" ) )
95  .BestSize( (int) ( m_FrameSize.x * 0.20 ), m_FrameSize.y ) );
96 
97  m_auimgr.AddPane( m_compListBox, EDA_PANE().Palette().Name( "Components" ).Center().Layer(0)
98  .Caption( _( "Symbol : Footprint Assignments" ) ) );
99 
100  m_auimgr.AddPane( m_footprintListBox, EDA_PANE().Palette().Name( "Footprints" ).Right().Layer(1)
101  .Caption( _( "Filtered Footprints" ) )
102  .BestSize( (int) ( m_FrameSize.x * 0.30 ), m_FrameSize.y ) );
103 
104  // Build the bottom panel, to display 2 status texts and the buttons:
105  auto bottomPanel = new wxPanel( this );
106  auto panelSizer = new wxBoxSizer( wxVERTICAL );
107 
108  wxFlexGridSizer* fgSizerStatus = new wxFlexGridSizer( 3, 1, 0, 0 );
109  fgSizerStatus->SetFlexibleDirection( wxBOTH );
110  fgSizerStatus->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
111 
112  m_statusLine1 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
113  fgSizerStatus->Add( m_statusLine1, 0, 0, 5 );
114 
115  m_statusLine2 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
116  fgSizerStatus->Add( m_statusLine2, 0, 0, 5 );
117 
118  m_statusLine3 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
119  fgSizerStatus->Add( m_statusLine3, 0, wxBOTTOM, 3 );
120 
121  panelSizer->Add( fgSizerStatus, 1, wxEXPAND|wxLEFT, 2 );
122 
123  wxStaticLine* staticline1 = new wxStaticLine( bottomPanel );
124  panelSizer->Add( staticline1, 0, wxEXPAND, 5 );
125 
126  wxFont statusFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
127  statusFont.SetSymbolicSize( wxFONTSIZE_SMALL );
128  m_statusLine1->SetFont( statusFont );
129  m_statusLine2->SetFont( statusFont );
130  m_statusLine3->SetFont( statusFont );
131 
132  // Add buttons:
133  auto buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
134  auto sdbSizer = new wxStdDialogButtonSizer();
135 
136  m_saveAndContinue = new wxButton( bottomPanel, ID_SAVE_PROJECT,
137  _( "Apply, Save Schematic && Continue" ) );
138  buttonsSizer->Add( m_saveAndContinue, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 20 );
139 
140  auto sdbSizerOK = new wxButton( bottomPanel, wxID_OK );
141  sdbSizer->AddButton( sdbSizerOK );
142  auto sdbSizerCancel = new wxButton( bottomPanel, wxID_CANCEL );
143  sdbSizer->AddButton( sdbSizerCancel );
144  sdbSizer->Realize();
145 
146  buttonsSizer->Add( sdbSizer, 0, 0, 5 );
147  panelSizer->Add( buttonsSizer, 0, wxALIGN_RIGHT|wxALL, 5 );
148 
149  bottomPanel->SetSizer( panelSizer );
150  bottomPanel->Fit();
151 
152  sdbSizerOK->SetDefault();
154 
155  m_auimgr.AddPane( bottomPanel, EDA_PANE().HToolbar().Name( "Buttons" ).Bottom().Layer(6) );
156 
157  m_auimgr.Update();
158  m_initialized = true;
159 
160  // Connect Events
162 
163  // Start the main processing loop
164  m_toolManager->InvokeTool( "cvpcb.Control" );
165 
166  // Ensure the toolbars are sync'd properly so the filtering options display correct
167  SyncToolbars();
168 
169  SetShutdownBlockReason( _( "Symbol to footprint changes are unsaved" ) );
170 }
171 
172 
174 {
175  // Shutdown all running tools
176  if( m_toolManager )
178 
179  // Clean up the tool infrastructure
180  delete m_actions;
181  delete m_toolManager;
182  delete m_toolDispatcher;
183 
184  m_auimgr.UnInit();
185 }
186 
187 
189 {
190  // Create the manager
191  m_actions = new CVPCB_ACTIONS();
193  m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this );
195 
196  // Register tools
201 
203 
204  // Even though these menus will open with the right-click, we treat them as a normal
205  // menu instead of a context menu because we don't care about their position and want
206  // to be able to tell the difference between a menu click and a hotkey activation.
207 
208  // Create the context menu for the component list box
209  m_componentContextMenu = new ACTION_MENU( false );
212  m_componentContextMenu->AppendSeparator();
216  m_componentContextMenu->AppendSeparator();
218 
219  // Create the context menu for the footprint list box
220  m_footprintContextMenu = new ACTION_MENU( false );
223 }
224 
226 {
227  // Connect the handlers to launch the context menus in the listboxes
228  m_footprintListBox->Bind( wxEVT_RIGHT_DOWN,
229  [this]( wxMouseEvent& )
230  {
231  PopupMenu( m_footprintContextMenu );
232  } );
233 
234  m_compListBox->Bind( wxEVT_RIGHT_DOWN,
235  [this]( wxMouseEvent& )
236  {
237  PopupMenu( m_componentContextMenu );
238  } );
239 
240  // Connect the handler for the save button
241  m_saveAndContinue->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
242  [this]( wxCommandEvent& )
243  {
244  // saveAssociations must be run immediately
246  } );
247 
248  // Connect the handlers for the ok/cancel buttons
249  Bind( wxEVT_BUTTON,
250  [this]( wxCommandEvent& )
251  {
252  // saveAssociations must be run immediately, before running Close( true )
254  Close( true );
255  }, wxID_OK );
256  Bind( wxEVT_BUTTON,
257  [this]( wxCommandEvent& )
258  {
259  Close( false );
260  }, wxID_CANCEL );
261 
262  // Connect the handlers for the close events
263  Bind( wxEVT_CLOSE_WINDOW, &CVPCB_MAINFRAME::OnCloseWindow, this );
264  Bind( wxEVT_MENU,
265  [this]( wxCommandEvent& )
266  {
267  Close( false );
268  }, wxID_CLOSE );
269  Bind( wxEVT_MENU,
270  [this]( wxCommandEvent& )
271  {
272  Close( false );
273  }, wxID_EXIT );
274 
275  // Toolbar events
277 
278  // Just skip the resize events
279  Bind( wxEVT_SIZE,
280  []( wxSizeEvent& aEvent )
281  {
282  aEvent.Skip();
283  } );
284 
285  // Attach the events to the tool dispatcher
288  Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
289 }
290 
291 
292 void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& aEvent )
293 {
294  if( m_modified )
295  {
296  // Shutdown blocks must be determined and vetoed as early as possible
297  if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION )
298  {
299  aEvent.Veto();
300  return;
301  }
302 
303  if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified. "
304  "Save changes?" ),
305  [&]()->bool { return SaveFootprintAssociation( false ); } ) )
306  {
307  aEvent.Veto();
308  return;
309  }
310  }
311 
312  // Close module display frame
314  GetFootprintViewerFrame()->Close( true );
315 
316  m_modified = false;
317 
318  // clear highlight symbol in schematic:
319  SendMessageToEESCHEMA( true );
320 
321  // Skip the close event. Looks like needed to have the close event sent to the
322  // root class EDA_BASE_FRAME, and save config
323  aEvent.Skip();
324 }
325 
326 
327 void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
328 {
329  // Called when changing the filter string in main toolbar.
330  // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_TEXT_PATTERN is set, update the list
331  // of available footprints which match the filter
332 
333  wxListEvent l_event;
334  OnSelectComponent( l_event );
335 }
336 
337 
338 void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
339 {
341  return;
342 
343  wxString libraryName;
344  COMPONENT* component = GetSelectedComponent();
345  libraryName = m_libListBox->GetSelectedLibrary();
346 
347  m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
348  m_tcFilterString->GetValue(), m_filteringOptions );
349 
350  if( component && component->GetFPID().IsValid() )
352  else
354 
355  refreshAfterComponentSearch( component );
356 }
357 
358 
360 {
362 
363  auto cfg = static_cast<CVPCB_SETTINGS*>( aCfg );
364 
365  m_filteringOptions = cfg->m_FilterFootprint;
366 }
367 
368 
370 {
372 
373  auto cfg = static_cast<CVPCB_SETTINGS*>( aCfg );
374  cfg->m_FilterFootprint = m_filteringOptions;
375 }
376 
377 
379 {
380  if( m_undoList.size() == 0 )
381  return;
382 
383  CVPCB_UNDO_REDO_ENTRIES redoEntries;
384  CVPCB_UNDO_REDO_ENTRIES curEntry = m_undoList.back();
385  m_undoList.pop_back();
386 
387  // Iterate over the entries to undo
388  for( const auto& assoc : curEntry )
389  {
390  AssociateFootprint( assoc, true, false );
391  redoEntries.emplace_back( assoc.Reverse() );
392  }
393 
394  // Add the redo entries to the redo stack
395  m_redoList.emplace_back( redoEntries );
396 }
397 
398 
400 {
401  if( m_redoList.size() == 0 )
402  return;
403 
404  CVPCB_UNDO_REDO_ENTRIES curEntry = m_redoList.back();
405  m_redoList.pop_back();
406 
407  // Iterate over the entries to undo
408  bool firstAssoc = true;
409  for( const auto& assoc : curEntry )
410  {
411  AssociateFootprint( assoc, firstAssoc );
412  firstAssoc = false;
413  }
414 }
415 
416 
418  bool aNewEntry, bool aAddUndoItem )
419 {
420  if( m_netlist.IsEmpty() )
421  return;
422 
423  COMPONENT* component = m_netlist.GetComponent( aAssociation.GetComponentIndex() );
424 
425  if( component == NULL )
426  return;
427 
428  LIB_ID fpid = aAssociation.GetNewFootprint();
429  LIB_ID oldFpid = component->GetFPID();
430 
431  // Test for validity of the requested footprint
432  if( !fpid.empty() && !fpid.IsValid() )
433  {
434  wxString msg =
435  wxString::Format( _( "\"%s\" is not a valid footprint." ), fpid.Format().wx_str() );
436  DisplayErrorMessage( this, msg );
437  return;
438  }
439 
440  // Set the new footprint
441  component->SetFPID( fpid );
442 
443  // create the new component description and set it
444  wxString description = wxString::Format( CMP_FORMAT,
445  aAssociation.GetComponentIndex() + 1,
446  component->GetReference(),
447  component->GetValue(),
448  component->GetFPID().Format().wx_str() );
449  m_compListBox->SetString( aAssociation.GetComponentIndex(), description );
450 
451  // Mark the data as being modified
452  m_modified = true;
453 
454  // Update the statusbar and refresh the list
455  DisplayStatus();
456  m_compListBox->Refresh();
457 
458  if( !aAddUndoItem )
459  return;
460 
461  // Update the undo list
462  if ( aNewEntry )
463  {
464  // Create a new entry for this association
465  CVPCB_UNDO_REDO_ENTRIES newEntry;
466  newEntry.emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(), oldFpid,
467  aAssociation.GetNewFootprint() ) );
468  m_undoList.emplace_back( newEntry );
469 
470  // Clear the redo list
471  m_redoList.clear();
472  }
473  else
474  m_undoList.back().emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(),
475  oldFpid, aAssociation.GetNewFootprint() ) );
476 
477 }
478 
479 
480 bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
481 {
482  return true;
483 }
484 
485 
487 {
488  // Tell AuiMgr that objects are changed !
489  if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
490  // (could be not the case when starting CvPcb
491  m_auimgr.Update();
492 
493  if( component == NULL )
494  {
495  DisplayStatus();
496  return;
497  }
498 
499  // Preview of the already assigned footprint.
500  // Find the footprint that was already chosen for this component and select it,
501  // but only if the selection is made from the component list or the library list.
502  // If the selection is made from the footprint list, do not change the current
503  // selected footprint.
504  if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
505  {
506  wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
507 
509 
510  for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
511  {
512  wxString footprintName;
513  wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
514  msg.Trim( true );
515  msg.Trim( false );
516  footprintName = msg.AfterFirst( wxChar( ' ' ) );
517 
518  if( module.Cmp( footprintName ) == 0 )
519  {
520  m_footprintListBox->SetSelection( ii, true );
521  break;
522  }
523  }
524 
527  }
528 
530  DisplayStatus();
531 }
532 
533 
536 {
537  int option = aFilter;
538 
539  // Apply the filter accordingly
540  switch( aAction )
541  {
543  m_filteringOptions &= ~option;
544  break;
545 
547  m_filteringOptions |= option;
548  break;
549 
551  m_filteringOptions ^= option;
552  break;
553  }
554 
555  wxListEvent l_event;
556  OnSelectComponent( l_event );
557 }
558 
559 
561 {
562  if( !m_initialized )
563  return;
564 
565  wxString filters, msg;
566  COMPONENT* component = GetSelectedComponent();
567 
569  {
570  msg.Empty();
571 
572  if( component )
573  {
574  for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
575  {
576  if( msg.IsEmpty() )
577  msg += component->GetFootprintFilters()[ii];
578  else
579  msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
580  }
581  }
582 
583  filters += _( "key words" );
584 
585  if( !msg.IsEmpty() )
586  filters += wxString::Format( wxT( " (%s)" ), msg );
587  }
588 
590  {
591  msg.Empty();
592 
593  if( component )
594  msg = wxString::Format( wxT( "%i" ), component->GetPinCount() );
595 
596  if( !filters.IsEmpty() )
597  filters += wxT( ", " );
598 
599  filters += _( "pin count" );
600 
601  if( !msg.IsEmpty() )
602  filters += wxString::Format( wxT( " (%s)" ), msg );
603  }
604 
606  {
608 
609  if( !filters.IsEmpty() )
610  filters += wxT( ", " );
611 
612  filters += _( "library" );
613 
614  if( !msg.IsEmpty() )
615  filters += wxString::Format( wxT( " (%s)" ), msg );
616  }
617 
618  wxString textFilter = m_tcFilterString->GetValue();
619 
620  if( !textFilter.IsEmpty() )
621  {
622  if( !filters.IsEmpty() )
623  filters += wxT( ", " );
624 
625  filters += _( "search text" ) + wxString::Format( wxT( " (%s)" ), textFilter );
626  }
627 
628  if( filters.IsEmpty() )
629  msg = _( "No filtering" );
630  else
631  msg.Printf( _( "Filtered by %s" ), GetChars( filters ) );
632 
633  msg << wxT( ": " ) << m_footprintListBox->GetCount();
634 
635  SetStatusText( msg );
636 
637 
638  msg.Empty();
639  wxString footprintName = GetSelectedFootprint();
640 
641  FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName );
642 
643  if( module ) // can be NULL if no netlist loaded
644  {
645  msg = wxString::Format( _( "Description: %s; Key words: %s" ),
646  module->GetDescription(),
647  module->GetKeywords() );
648  }
649 
650  SetStatusText( msg, 1 );
651 
652  msg.Empty();
653  wxString lib;
654 
655  // Choose the footprint to get the information on
656  if( module )
657  {
658  // Use the footprint in the footprint viewer
659  lib = module->GetLibNickname();
660  }
662  {
663  // Use the footprint of the selected component
664  if( component )
665  lib = component->GetFPID().GetLibNickname();
666  }
668  {
669  // Use the library that is selected
671  }
672 
673  // Extract the library information
674  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
675 
676  if( fptbl->HasLibrary( lib ) )
677  msg = wxString::Format( _( "Library location: %s" ), fptbl->GetFullURI( lib ) );
678  else
679  msg = wxString::Format( _( "Library location: unknown" ) );
680 
681  SetStatusText( msg, 2 );
682 }
683 
684 
686 {
687  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
688 
689  // Check if there are footprint libraries in the footprint library table.
690  if( !fptbl || !fptbl->GetLogicalLibs().size() )
691  {
692  wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
693  "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
694  return false;
695  }
696 
697  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
698 
699  m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
700 
702  {
704  }
705 
706  return true;
707 }
708 
709 
710 void CVPCB_MAINFRAME::SendMessageToEESCHEMA( bool aClearHighligntOnly )
711 {
712  if( m_netlist.IsEmpty() )
713  return;
714 
715  // clear highlight of previously selected components (if any):
716  // Selecting a non existing symbol clears any previously highlighted symbols
717  std::string packet = "$CLEAR: \"HIGHLIGHTED\"";
718 
719  if( Kiface().IsSingle() )
720  SendCommand( MSG_TO_SCH, packet.c_str() );
721  else
722  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
723 
724  if( aClearHighligntOnly )
725  return;
726 
727  int selection = m_compListBox->GetSelection();
728 
729  if ( selection < 0 ) // Nothing selected
730  return;
731 
732  if( m_netlist.GetComponent( selection ) == NULL )
733  return;
734 
735  // Now highlight the selected component:
736  COMPONENT* component = m_netlist.GetComponent( selection );
737 
738  packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( component->GetReference() ) );
739 
740  if( Kiface().IsSingle() )
741  SendCommand( MSG_TO_SCH, packet.c_str() );
742  else
743  Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
744 }
745 
746 
747 int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
748 {
749  STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
750  KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
751 
752  m_netlist.Clear();
753 
754  try
755  {
756  netrdr.LoadNetlist();
757  }
758  catch( const IO_ERROR& ioe )
759  {
760  wxString msg = wxString::Format( _( "Error loading schematic.\n%s" ),
761  ioe.What().GetData() );
762  wxMessageBox( msg, _( "Load Error" ), wxOK | wxICON_ERROR );
763  return 1;
764  }
765 
766  // We also remove footprint name if it is "$noname" because this is a dummy name,
767  // not the actual name of the footprint.
768  for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
769  {
770  if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
771  m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
772  }
773 
774  // Sort components by reference:
776 
777  return 0;
778 }
779 
780 
782 {
783  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
784 
785  if( m_footprintListBox == NULL )
786  {
788  m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
789  wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
790  }
791 
794  DisplayStatus();
795 }
796 
797 
799 {
800  wxString msg;
801  COMPONENT* component;
802  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
803 
804  if( m_compListBox == NULL )
805  {
807  m_compListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
808  wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
809  }
810 
812 
813  for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
814  {
815  component = m_netlist.GetComponent( i );
816 
817  msg.Printf( CMP_FORMAT,
818  m_compListBox->GetCount() + 1,
819  component->GetReference(),
820  component->GetValue(),
821  component->GetFPID().Format().wx_str() );
822  m_compListBox->m_ComponentList.Add( msg );
823  }
824 
825  if( m_compListBox->m_ComponentList.Count() )
826  {
827  m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
828  m_compListBox->SetSelection( 0, true );
829  m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
831  }
832 }
833 
834 
836 {
837  wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
838 
839  if( m_libListBox == NULL )
840  {
842  m_libListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
843  wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
844  }
845 
846  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
847 
848  if( tbl )
849  {
850  wxArrayString libNames;
851 
852  std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
853 
854  for( const wxString& libNickName : libNickNames )
855  libNames.Add( libNickName );
856 
857  m_libListBox->SetLibraryList( libNames );
858  }
859 }
860 
861 
863 {
864  int selection = m_compListBox->GetSelection();
865 
866  if( selection >= 0 && selection < (int) m_netlist.GetCount() )
867  return m_netlist.GetComponent( selection );
868 
869  return NULL;
870 }
871 
872 
873 void CVPCB_MAINFRAME::SetSelectedComponent( int aIndex, bool aSkipUpdate )
874 {
875  m_skipComponentSelect = aSkipUpdate;
876 
877  if( aIndex < 0 )
878  {
880  }
881  else if( aIndex < m_compListBox->GetCount() )
882  {
884  m_compListBox->SetSelection( aIndex );
886  }
887 
888  m_skipComponentSelect = false;
889 }
890 
891 
892 std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
893  CVPCB_MAINFRAME::CRITERIA aCriteria )
894 {
895  std::vector<unsigned int> idx;
896 
897  // Make sure a netlist has been loaded and the box has contents
898  if( m_netlist.IsEmpty() || m_compListBox->GetCount() == 0 )
899  return idx;
900 
901  switch( aCriteria )
902  {
904  idx.resize( m_netlist.GetCount() );
905  std::iota( idx.begin(), idx.end(), 0 );
906  break;
907 
909  {
910  // Check to see if anything is selected
911  if( m_compListBox->GetSelectedItemCount() < 1 )
912  break;
913 
914  // Get the components
915  int lastIdx = m_compListBox->GetFirstSelected();
916  idx.emplace_back( lastIdx );
917 
918  lastIdx = m_compListBox->GetNextSelected( lastIdx );
919  while( lastIdx > 0 )
920  {
921  idx.emplace_back( lastIdx );
922  lastIdx = m_compListBox->GetNextSelected( lastIdx );
923  }
924  break;
925  }
927  for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
928  {
929  if( m_netlist.GetComponent( i )->GetFPID().empty() )
930  idx.emplace_back( i );
931  }
932  break;
933 
935  for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
936  {
937  if( !m_netlist.GetComponent( i )->GetFPID().empty() )
938  idx.emplace_back( i );
939  }
940  break;
941 
942  default:
943  wxASSERT_MSG( false, "Invalid component selection criteria" );
944  }
945 
946  return idx;
947 }
948 
949 
951 {
952  // returns the Footprint Viewer frame, if exists, or NULL
953  return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
954  ( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) );
955 }
956 
957 
959 {
960  return GetFootprintViewerFrame();
961 }
962 
963 
965 {
966  if( m_libListBox->HasFocus() )
968  else if( m_compListBox->HasFocus() )
970  else if( m_footprintListBox->HasFocus() )
972 
974 }
975 
976 
978 {
979  if( m_libListBox->HasFocus() )
980  return m_libListBox;
981  else if( m_compListBox->HasFocus() )
982  return m_compListBox;
983  else if( m_footprintListBox->HasFocus() )
984  return m_footprintListBox;
985 
986  return nullptr;
987 }
988 
989 
991 {
992  switch( aLB )
993  {
994  case CVPCB_MAINFRAME::CONTROL_LIBRARY: m_libListBox->SetFocus(); break;
995  case CVPCB_MAINFRAME::CONTROL_COMPONENT: m_compListBox->SetFocus(); break;
997  default: break;
998  }
999 }
1000 
1001 
1003 {
1004  // returns the LIB_ID of the selected footprint in footprint listview
1005  // or a empty string
1007 }
1008 
1009 
1010 void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
1011 {
1012  switch( aNumber )
1013  {
1014  case 0: m_statusLine1->SetLabel( aText ); break;
1015  case 1: m_statusLine2->SetLabel( aText ); break;
1016  case 2: m_statusLine3->SetLabel( aText ); break;
1017  default: wxFAIL_MSG( "Invalid status row number" ); break;
1018  }
1019 }
1020 
1021 
1023 {
1025  ReCreateHToolbar();
1026  DisplayStatus();
1027 }
1028 
1029 
1031 {
1032  const std::string& payload = mail.GetPayload();
1033 
1034  //DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
1035 
1036  switch( mail.Command() )
1037  {
1038  case MAIL_EESCHEMA_NETLIST:
1039  ReadNetListAndFpFiles( payload );
1040  /* @todo
1041  Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
1042  */
1043  break;
1044 
1045  default:
1046  ; // ignore most
1047  }
1048 }
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
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:114
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
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
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:148
void SetSelectedFootprint(const LIB_ID &aFPID)
ACTION_MENU.
Definition: action_menu.h:44
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
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)
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
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:228
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:149
unsigned int GetComponentIndex() const
Get the index of the component to modify the association of.
TOOL_MANAGER.
Definition: tool_manager.h:51
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:91
#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.
const wxString & GetReference() const
Definition: pcb_netlist.h:144
void KiwayMailIn(KIWAY_EXPRESS &aEvent) override
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
wxString GetSelectedLibrary()
ACTIONS * m_actions
Definition: tools_holder.h:49
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.
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:284
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:237
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:428
wxArrayString m_ComponentList
Definition: listboxes.h:193
wxString GetSelectedFootprint()
void Clear()
Function Clear removes all components from the netlist.
Definition: pcb_netlist.h:222
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
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:153
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
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Sets the work environment (model, view, view controls and the parent window).
virtual void DispatchWxCommand(wxCommandEvent &aEvent)
Function DispatchWxCommand() Processes wxCommands (mostly menu related events) and runs appropriate a...
void FixupCancelButtonCmdKeyCollision(wxWindow *aWindow)
Definition: gtk/ui.cpp:38
#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:160
#define TO_UTF8(wxstring)
A class to define a footprint association to be made in cvpcb.
wxString GetKeywords()
bool IsEmpty() const
Function IsEmpty()
Definition: pcb_netlist.h:216
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:146
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:157
wxWindow * GetToolCanvas() const override
Canvas access.
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.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
void OnEnterFilteringText(wxCommandEvent &event)
Function OnEnterFilteringText Is called each time the text of m_tcFilterString is changed.
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
STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
DISPLAY_FOOTPRINTS_FRAME * GetFootprintViewerFrame() const
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
bool SaveFootprintAssociation(bool doSaveSchematic)
Function SaveFootprintAssociation saves the edits that the user has done by sending them back to eesc...