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